From 834f989ed466efd1ca28cb9f1a396fba56a781e2 Mon Sep 17 00:00:00 2001 From: qingxu fu <505030475@qq.com> Date: Sat, 3 Jun 2023 15:42:22 +0800 Subject: [PATCH] =?UTF-8?q?=E8=80=83=E8=99=91=E6=9C=89=E4=BA=BA=E7=94=A8in?= =?UTF-8?q?put=E4=B8=8D=E5=8A=A0.tex=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crazy_functions/latex_utils.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crazy_functions/latex_utils.py b/crazy_functions/latex_utils.py index 38f9f7a..8fe609d 100644 --- a/crazy_functions/latex_utils.py +++ b/crazy_functions/latex_utils.py @@ -20,8 +20,14 @@ def merge_tex_files_(project_foler, main_file, mode): for s in reversed([q for q in re.finditer(r"\\input\{(.*?)\}", main_file, re.M)]): f = s.group(1) fp = os.path.join(project_foler, f) - with open(fp, 'r', encoding='utf-8', errors='replace') as fx: - c = fx.read() + if os.path.exists(fp): + # e.g., \input{srcs/07_appendix.tex} + with open(fp, 'r', encoding='utf-8', errors='replace') as fx: + c = fx.read() + else: + # e.g., \input{srcs/07_appendix} + with open(fp+'.tex', 'r', encoding='utf-8', errors='replace') as fx: + c = fx.read() c = merge_tex_files_(project_foler, c, mode) main_file = main_file[:s.span()[0]] + c + main_file[s.span()[1]:] return main_file