From c2b32a7f43c2dee95b2a132b81d03b540c950f69 Mon Sep 17 00:00:00 2001 From: Zipper-1 Date: Sun, 3 Mar 2024 23:34:57 +0800 Subject: [PATCH 1/3] Add timeout for updater Add a timeout for checking update so users having poor connectivity with pypi.org won't keep waiting FOREVER --- mathtranslate/update.py | 2 +- mathtranslate/utils.py | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/mathtranslate/update.py b/mathtranslate/update.py index eb34014..bda00e8 100644 --- a/mathtranslate/update.py +++ b/mathtranslate/update.py @@ -5,7 +5,7 @@ def get_latest_version(): url = 'https://pypi.org/pypi/mathtranslate/json' - with urllib.request.urlopen(url) as response: + with urllib.request.urlopen(url,timeout=15) as response: data = json.loads(response.read().decode('utf-8')) latest_version = data['info']['version'] diff --git a/mathtranslate/utils.py b/mathtranslate/utils.py index 5504847..3897560 100644 --- a/mathtranslate/utils.py +++ b/mathtranslate/utils.py @@ -74,14 +74,17 @@ def check_update(require_updated=True): - latest = get_latest_version() - updated = __version__ == latest - if updated: - print("The current mathtranslate is latest") - else: - print("The current mathtranslate is not latest, please update by `pip install --upgrade mathtranslate`") - if (not config.test_environment) and require_updated: - sys.exit() + try: + latest = get_latest_version() + updated = __version__ == latest + if updated: + print("The current mathtranslate is latest") + else: + print("The current mathtranslate is not latest, please update by `pip install --upgrade mathtranslate`") + if (not config.test_environment) and require_updated: + sys.exit() + except Exception as e: + print("Checking update failed, please check your network") def add_arguments(parser): From 5ac7995b76fa081b9cd1382aa6882807e537f4db Mon Sep 17 00:00:00 2001 From: Zipper-1 Date: Mon, 4 Mar 2024 01:46:01 +0800 Subject: [PATCH 2/3] 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: From a864b26d329cc11f8801dfb87800c569089c2bcc Mon Sep 17 00:00:00 2001 From: Zipper-1 Date: Tue, 5 Mar 2024 01:26:57 +0800 Subject: [PATCH 3/3] Add fontenc into incompatible packages --- mathtranslate/process_latex.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mathtranslate/process_latex.py b/mathtranslate/process_latex.py index e2c0637..28f5fd9 100644 --- a/mathtranslate/process_latex.py +++ b/mathtranslate/process_latex.py @@ -492,8 +492,8 @@ def replace_function(match): return pattern.sub(replace_function, latex) def remove_incompatible_packages(text): - incompatible_list=['axessibility'] - #axessibility is incompatible with xeCJK and can be removed savely + incompatible_list=['axessibility','fontenc'] + #axessibility,fontenc is incompatible with xeCJK and can be removed safely #maybe more will be added for package in incompatible_list: pattern = re.compile(r'\\usepackage(\[[A-Za-z]*?\])?\{'+package+r'\}')