Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updater timeout & Remove incompatible latex packages #93

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions mathtranslate/process_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions mathtranslate/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion mathtranslate/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down
19 changes: 11 additions & 8 deletions mathtranslate/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down