|
5 | 5 | match_code = r"(" + math_code + r"_\d+(?:_\d+)*)" |
6 | 6 | match_code_replace = math_code + r"_(\d+(?:_\d+)*)*" |
7 | 7 |
|
8 | | -options = r"\[[a-zA-Z\s,\\\*\.\+\-=_]*?\]" # ,\*.+-=_ |
| 8 | +options = r"\[[a-zA-Z\s,\\\*\.\+\-=_{}]*?\]" # ,\*.+-=_{} |
9 | 9 |
|
10 | 10 | pattern_env = r"\\begin[ \t]*\{(.*?)\}[ \t]*(options)?(.*?)\\end[ \t]*\{\1\}".replace('options', options) # \begin{xxx} \end{xxx}, group 1: name, group 2: option, group 3: content |
11 | 11 | pattern_command_full = r"\\([a-zA-Z]+\*?)[ \t]*(options)?[ \t]*(\{((?:[^{}]++|(?3))++)\})".replace('options', options) # \xxx[xxx]{xxx} and \xxx{xxx}, group 1: name, group 2: option, group 4: content |
@@ -100,7 +100,7 @@ def replace_latex_objects(text): |
100 | 100 | pattern = regex.compile(regex_symbol, regex.DOTALL) |
101 | 101 | while pattern.search(text): |
102 | 102 | latex_obj = pattern.search(text).group() |
103 | | - replaced_objs.append(f'{latex_obj}') |
| 103 | + replaced_objs.append(f' {latex_obj} ') |
104 | 104 | text = pattern.sub(' ' + variable_code(count) + ' ', text, 1) |
105 | 105 | count += 1 |
106 | 106 |
|
@@ -297,3 +297,16 @@ def replace_function(match): |
297 | 297 | text = re.compile(match_code_accent).sub(replace_function, text) |
298 | 298 |
|
299 | 299 | return text |
| 300 | + |
| 301 | + |
| 302 | +def combine_sentences(text): |
| 303 | + pattern = re.compile(r'\n(\s*([^\s]))') |
| 304 | + |
| 305 | + def process_function(match): |
| 306 | + char = match.group(2) |
| 307 | + if char == '\\': |
| 308 | + return match.group(0) |
| 309 | + else: |
| 310 | + return ' '+match.group(1) |
| 311 | + |
| 312 | + return pattern.sub(process_function, text) |
0 commit comments