Skip to content

Commit

Permalink
Merge pull request #16 from SUSYUSTC/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
SUSYUSTC authored Mar 28, 2023
2 parents b88b5f7 + 4eb30de commit 856c003
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion mathtranslate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "2.1.0"
__version__ = "2.1.1"
__author__ = "Jiace Sun"

import os
Expand Down
2 changes: 1 addition & 1 deletion mathtranslate/process_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
match_code = r"(" + math_code + r"_\d+(?:_\d+)*)"
match_code_replace = math_code + r"_(\d+(?:_\d+)*)*"
pattern_env = r"\\begin\{(.*?)\}(.*?)\\end\{\1\}" # \begin{xxx} \end{xxx}, group 1: name, group 2: content
pattern_command_full = r"\\([a-zA-Z]+\*?)?(\[[a-zA-Z\s,]*?\])?(\{((?:[^{}]++|(?3))++)\})" # \xxx[xxx]{xxx} and \xxx{xxx}, group 1: name, group 2: option, group 4: content
pattern_command_full = r"\\([a-zA-Z]+\*?)(\[[a-zA-Z\s,]*?\])?(\{((?:[^{}]++|(?3))++)\})" # \xxx[xxx]{xxx} and \xxx{xxx}, group 1: name, group 2: option, group 4: content
pattern_command_simple = r"\\([a-zA-Z]+)" # \xxx, group 1: name


Expand Down
9 changes: 5 additions & 4 deletions mathtranslate/translate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
from . import process_latex
from . import process_text
from .config import math_code
from .process_text import char_limit
import time

Expand Down Expand Up @@ -163,8 +164,8 @@ def translate_full_latex(self, latex_original):
tex_end = default_end

# It is difficult for regex to exclude \{ during match so I replace it to something else and then replace back
latex_original = latex_original.replace(r'\{', 'XMATH_LB')
latex_original = latex_original.replace(r'\}', 'XMATH_RB')
latex_original = latex_original.replace(r'\{', f'{math_code}LB')
latex_original = latex_original.replace(r'\}', f'{math_code}RB')

latex_original_paragraphs = self.split_latex_to_paragraphs(latex_original)
latex_translated_paragraphs = []
Expand All @@ -190,8 +191,8 @@ def translate_full_latex(self, latex_original):
print('processing title')
latex_translated = self.translate_latex_commands(latex_translated, ['title'], complete)

latex_translated = latex_translated.replace('XMATH_LB', r'\{')
latex_translated = latex_translated.replace('XMATH_RB', r'\}')
latex_translated = latex_translated.replace(f'{math_code}LB', r'\{')
latex_translated = latex_translated.replace(f'{math_code}RB', r'\}')

latex_translated = tex_begin + '\n' + latex_translated + '\n' + tex_end

Expand Down

0 comments on commit 856c003

Please sign in to comment.