diff --git a/crazy_functions/latex_fns/latex_actions.py b/crazy_functions/latex_fns/latex_actions.py index 1966a2fb..ebf7a598 100644 --- a/crazy_functions/latex_fns/latex_actions.py +++ b/crazy_functions/latex_fns/latex_actions.py @@ -343,6 +343,7 @@ def remove_buggy_lines(file_path, log_path, tex_name, tex_name_pure, n_fix, work logger.error("Fatal error occurred, but we cannot identify error, please download zip, read latex log, and compile manually.") return False, -1, [-1] + def 编译Latex(chatbot, history, main_file_original, main_file_modified, work_folder_original, work_folder_modified, work_folder, mode='default'): import os, time n_fix = 1 @@ -357,13 +358,23 @@ def 编译Latex(chatbot, history, main_file_original, main_file_modified, work_f with open(tex_path, 'r', encoding='utf-8', errors='replace') as f: content = f.read(5000) # 检查是否有使用xelatex的宏包 - return any(pkg in content for pkg in ['fontspec', 'xeCJK', 'xetex', 'unicode-math', 'xltxtra', 'xunicode']) + need_xelatex = any( + pkg in content + for pkg in ['fontspec', 'xeCJK', 'xetex', 'unicode-math', 'xltxtra', 'xunicode'] + ) + if need_xelatex: + logger.info(f"检测到宏包需要xelatex编译, 切换至xelatex编译") + else: + logger.info(f"未检测到宏包需要xelatex编译, 使用pdflatex编译") + return need_xelatex except Exception: return False # 根据编译器类型返回编译命令 def get_compile_command(compiler, filename): - return f'{compiler} -interaction=batchmode -file-line-error {filename}.tex' + compile_command = f'{compiler} -interaction=batchmode -file-line-error {filename}.tex' + logger.info('Latex 编译指令: ', compile_command) + return compile_command # 确定使用的编译器 compiler = 'pdflatex' diff --git a/crazy_functions/pdf_fns/parse_pdf_via_doc2x.py b/crazy_functions/pdf_fns/parse_pdf_via_doc2x.py index 64627d05..93d45b1a 100644 --- a/crazy_functions/pdf_fns/parse_pdf_via_doc2x.py +++ b/crazy_functions/pdf_fns/parse_pdf_via_doc2x.py @@ -1,6 +1,6 @@ from toolbox import get_log_folder, gen_time_str, get_conf from toolbox import update_ui, promote_file_to_downloadzone -from toolbox import extract_archive +from toolbox import promote_file_to_downloadzone, extract_archive from toolbox import generate_file_link, zip_folder from crazy_functions.crazy_utils import get_files_from_everything from shared_utils.colorful import * @@ -46,7 +46,7 @@ def make_request(method, url, **kwargs): return requests.request(method, url, **kwargs) -def 状态检查(response, uid=""): +def doc2x_api_response_status(response, uid=""): """ Check the status of Doc2x API response Args: @@ -95,7 +95,7 @@ def 解析PDF_DOC2X(pdf_file_path, format="tex"): headers={"Authorization": "Bearer " + doc2x_api_key}, timeout=15, ) - res_data = 状态检查(res) + res_data = doc2x_api_response_status(res) upload_url = res_data["url"] uuid = res_data["uid"] @@ -117,7 +117,7 @@ def 解析PDF_DOC2X(pdf_file_path, format="tex"): params=params, timeout=15, ) - res_data = 状态检查(res) + res_data = doc2x_api_response_status(res) if res_data["status"] == "success": break elif res_data["status"] == "processing": @@ -131,7 +131,12 @@ def 解析PDF_DOC2X(pdf_file_path, format="tex"): # < ------ 第3步:提交转化 ------ > logger.info("Doc2x 第3步:提交转化") - data = {"uid": uuid, "to": format, "formula_mode": "dollar", "filename": "output"} + data = { + "uid": uuid, + "to": format, + "formula_mode": "dollar", + "filename": "output" + } res = make_request( "POST", "https://v2.doc2x.noedgeai.com/api/v2/convert/parse", @@ -139,7 +144,7 @@ def 解析PDF_DOC2X(pdf_file_path, format="tex"): json=data, timeout=15, ) - 状态检查(res, uid=f"uid: {uuid}") + doc2x_api_response_status(res, uid=f"uid: {uuid}") # < ------ 第4步:等待结果 ------ > logger.info("Doc2x 第4步:等待结果") @@ -154,7 +159,7 @@ def 解析PDF_DOC2X(pdf_file_path, format="tex"): params=params, timeout=15, ) - res_data = 状态检查(res, uid=f"uid: {uuid}") + res_data = doc2x_api_response_status(res, uid=f"uid: {uuid}") if res_data["status"] == "success": break elif res_data["status"] == "processing": @@ -196,7 +201,6 @@ def 解析PDF_DOC2X(pdf_file_path, format="tex"): # < ------ 解压 ------ > import zipfile - with zipfile.ZipFile(zip_path, "r") as zip_ref: zip_ref.extractall(unzip_path) return zip_path, unzip_path diff --git a/main.py b/main.py index e54f6d9a..39ad9aeb 100644 --- a/main.py +++ b/main.py @@ -186,7 +186,7 @@ def main(): define_gui_floating_menu(customize_btns, functional, predefined_btns, cookies, web_cookie_cache) # 浮动时间线定义 - gr.Spark(label="", value="") + gr.Spark() # 插件二级菜单的实现 from themes.gui_advanced_plugin_class import define_gui_advanced_plugin_class