diff --git a/crazy_functions/latex_utils.py b/crazy_functions/latex_utils.py index d3d7b9c..afaae22 100644 --- a/crazy_functions/latex_utils.py +++ b/crazy_functions/latex_utils.py @@ -29,7 +29,15 @@ def split_worker_reverse_caption(text, mask, pattern, flags=0): """ pattern_compile = re.compile(pattern, flags) for res in pattern_compile.finditer(text): - mask[res.regs[1][0]:res.regs[1][1]] = TRANSFORM + brace_level = 0 + p = begin = end = res.regs[1][0] + for _ in range(1024*16): + if text[p] == '}' and brace_level == 0: break + elif text[p] == '}': brace_level -= 1 + elif text[p] == '{': brace_level += 1 + p += 1 + end = p + mask[begin:end] = TRANSFORM return text, mask def split_worker_begin_end(text, mask, pattern, flags=0, limit_n_lines=42): @@ -97,6 +105,7 @@ def 寻找Latex主文件(file_manifest, mode): else: continue raise RuntimeError('无法找到一个主Tex文件(包含documentclass关键字)') + def rm_comments(main_file): new_file_remove_comment_lines = [] for l in main_file.splitlines(): @@ -108,6 +117,7 @@ def rm_comments(main_file): main_file = '\n'.join(new_file_remove_comment_lines) main_file = re.sub(r'(? 0 and node_string.count('\_') > final_tex.count('\_'): # walk and replace any _ without \ final_tex = re.sub(r"(? lps = LatexPaperSplit() - res = lps.split(merged_content, project_folder) # 消耗时间的函数 + res = lps.split(merged_content, project_folder, opts) # 消耗时间的函数 # <-------- 拆分过长的latex片段 ----------> pfg = LatexPaperFileGroup()