diff --git a/crazy_functions/latex_fns/latex_toolbox.py b/crazy_functions/latex_fns/latex_toolbox.py index c733c81..e5484ca 100644 --- a/crazy_functions/latex_fns/latex_toolbox.py +++ b/crazy_functions/latex_fns/latex_toolbox.py @@ -342,10 +342,33 @@ def merge_tex_files(project_foler, main_file, mode): pattern_opt2 = re.compile(r"\\abstract\{(.*?)\}", flags=re.DOTALL) match_opt1 = pattern_opt1.search(main_file) match_opt2 = pattern_opt2.search(main_file) + if (match_opt1 is None) and (match_opt2 is None): + # "Cannot find paper abstract section!" + main_file = insert_abstract(main_file) + match_opt1 = pattern_opt1.search(main_file) + match_opt2 = pattern_opt2.search(main_file) assert (match_opt1 is not None) or (match_opt2 is not None), "Cannot find paper abstract section!" return main_file +insert_missing_abs_str = r""" +\begin{abstract} +The GPT-Academic program cannot find abstract section in this paper. +\end{abstract} +""" + +def insert_abstract(tex_content): + if "\\maketitle" in tex_content: + # find the position of "\maketitle" + find_index = tex_content.index("\\maketitle") + # find the nearest ending line + end_line_index = tex_content.find("\n", find_index) + # insert "abs_str" on the next line + modified_tex = tex_content[:end_line_index+1] + '\n\n' + insert_missing_abs_str + '\n\n' + tex_content[end_line_index+1:] + return modified_tex + else: + return tex_content + """ =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Post process diff --git a/tests/test_plugins.py b/tests/test_plugins.py index d9f78d6..5998bc4 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -9,7 +9,9 @@ validate_path() # 返回项目根路径 if __name__ == "__main__": from tests.test_utils import plugin_test - plugin_test(plugin='crazy_functions.函数动态生成->函数动态生成', main_input='交换图像的蓝色通道和红色通道', advanced_arg={"file_path_arg": "./build/ants.jpg"}) + # plugin_test(plugin='crazy_functions.函数动态生成->函数动态生成', main_input='交换图像的蓝色通道和红色通道', advanced_arg={"file_path_arg": "./build/ants.jpg"}) + + plugin_test(plugin='crazy_functions.Latex输出PDF结果->Latex翻译中文并重新编译PDF', main_input="2307.07522") # plugin_test(plugin='crazy_functions.虚空终端->虚空终端', main_input='修改api-key为sk-jhoejriotherjep')