diff --git a/mathtranslate/process_latex.py b/mathtranslate/process_latex.py index b0e6d53..28f5fd9 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','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'\}') + 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: 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):