From 5ac7995b76fa081b9cd1382aa6882807e537f4db Mon Sep 17 00:00:00 2001 From: Zipper-1 Date: Mon, 4 Mar 2024 01:46:01 +0800 Subject: [PATCH] Automatically remove incompatible package(s) Package axessibility is incompatible with xeCJK/xeLatex, causes compilation failure on the website. Removing it from tex file should fix that --- mathtranslate/process_latex.py | 9 +++++++++ mathtranslate/translate.py | 1 + 2 files changed, 10 insertions(+) diff --git a/mathtranslate/process_latex.py b/mathtranslate/process_latex.py index b0e6d53..e2c0637 100644 --- a/mathtranslate/process_latex.py +++ b/mathtranslate/process_latex.py @@ -490,3 +490,12 @@ def replace_function(match): else: return match.group(0) return pattern.sub(replace_function, latex) + +def remove_incompatible_packages(text): + incompatible_list=['axessibility'] + #axessibility is incompatible with xeCJK and can be removed savely + #maybe more will be added + for package in incompatible_list: + pattern = re.compile(r'\\usepackage(\[[A-Za-z]*?\])?\{'+package+r'\}') + text = re.sub(pattern,'',text) + return text \ No newline at end of file diff --git a/mathtranslate/translate.py b/mathtranslate/translate.py index 7f860a2..a033061 100644 --- a/mathtranslate/translate.py +++ b/mathtranslate/translate.py @@ -226,6 +226,7 @@ def translate_full_latex(self, latex_original, make_complete=True, nocache=False if self.complete: print('It is a full latex document') latex_original, tex_begin, tex_end = process_latex.split_latex_document(latex_original, r'\begin{document}', r'\end{document}') + tex_begin = process_latex.remove_incompatible_packages(tex_begin) tex_begin = process_latex.remove_blank_lines(tex_begin) tex_begin = process_latex.insert_macro(tex_begin, '\\usepackage{xeCJK}\n\\usepackage{amsmath}') else: