Spaces:
Running
on
Zero
Running
on
Zero
improve latex parsing
Browse files
app.py
CHANGED
@@ -135,30 +135,30 @@ def update_inputs(task):
|
|
135 |
def parse_latex_output(res):
|
136 |
lines = res.split('\n')
|
137 |
parsed_lines = []
|
138 |
-
|
139 |
|
140 |
for line in lines:
|
141 |
line = line.strip()
|
142 |
if not line:
|
143 |
continue
|
144 |
|
145 |
-
|
146 |
-
|
147 |
-
in_tabular = line.startswith('\\begin{tabular}')
|
148 |
-
continue
|
149 |
|
150 |
-
|
151 |
-
parsed_lines.append(f'$$ {line} $$')
|
152 |
-
continue
|
153 |
|
154 |
-
if
|
|
|
|
|
|
|
155 |
parsed_lines.append(line)
|
156 |
-
continue
|
157 |
-
|
158 |
-
if re.search(r'[\\{}$_^]', line) or any(keyword in line for keyword in ['\\hline', '\\begin', '\\end']):
|
159 |
-
parsed_lines.append(f'$$ {line} $$')
|
160 |
else:
|
|
|
|
|
|
|
161 |
parsed_lines.append(line)
|
|
|
|
|
162 |
|
163 |
return '\n'.join(parsed_lines)
|
164 |
|
|
|
135 |
def parse_latex_output(res):
|
136 |
lines = res.split('\n')
|
137 |
parsed_lines = []
|
138 |
+
in_latex = False
|
139 |
|
140 |
for line in lines:
|
141 |
line = line.strip()
|
142 |
if not line:
|
143 |
continue
|
144 |
|
145 |
+
latex_patterns = [r'\{', r'\}', r'\[', r'\]', r'\\', r'\$', r'_', r'^']
|
146 |
+
contains_latex = any(re.search(pattern, line) for pattern in latex_patterns)
|
|
|
|
|
147 |
|
148 |
+
is_key_value = ':' in line and not line.startswith('{') and not line.endswith('}')
|
|
|
|
|
149 |
|
150 |
+
if contains_latex or is_key_value:
|
151 |
+
if not in_latex:
|
152 |
+
parsed_lines.append('$$')
|
153 |
+
in_latex = True
|
154 |
parsed_lines.append(line)
|
|
|
|
|
|
|
|
|
155 |
else:
|
156 |
+
if in_latex:
|
157 |
+
parsed_lines.append('$$')
|
158 |
+
in_latex = False
|
159 |
parsed_lines.append(line)
|
160 |
+
if in_latex:
|
161 |
+
parsed_lines.append('$$')
|
162 |
|
163 |
return '\n'.join(parsed_lines)
|
164 |
|