Update app.py
Browse files
app.py
CHANGED
|
@@ -109,31 +109,21 @@ def create_math_system_message():
|
|
| 109 |
Always be precise, educational, and encourage mathematical thinking."""
|
| 110 |
|
| 111 |
def render_latex(text):
|
| 112 |
-
"""
|
| 113 |
-
if not text
|
| 114 |
return text
|
| 115 |
|
| 116 |
try:
|
| 117 |
-
#
|
| 118 |
-
text = re.sub(r'(
|
| 119 |
-
text = re.sub(r'
|
| 120 |
-
text = re.sub(r'\\\[([^\\]+)\\\]', r'$$\1$$', text) # Display math alternative
|
| 121 |
-
text = re.sub(r'\\\(([^\\]+)\\\)', r'$\1$', text) # Inline math alternative
|
| 122 |
|
| 123 |
-
# Fix
|
| 124 |
-
text
|
| 125 |
-
|
| 126 |
-
# Ensure boxed answers and fractions render correctly
|
| 127 |
-
text = re.sub(r'\\boxed\{([^}]+)\}', r'$$\boxed{\1}$$', text)
|
| 128 |
-
text = re.sub(r'\\frac\{([^}]+)\}\{([^}]+)\}', r'$\frac{\1}{\2}$', text)
|
| 129 |
-
|
| 130 |
-
# Clean extra spaces and escape issues
|
| 131 |
-
text = re.sub(r'\s+([\$\\])\s+', r'\1', text)
|
| 132 |
-
text = text.replace(r'frac', r'\frac') # Catch any unescaped frac
|
| 133 |
|
| 134 |
except Exception as e:
|
| 135 |
-
print(f"⚠️ LaTeX
|
| 136 |
-
return text # Return original text if formatting fails
|
| 137 |
|
| 138 |
return text
|
| 139 |
|
|
|
|
| 109 |
Always be precise, educational, and encourage mathematical thinking."""
|
| 110 |
|
| 111 |
def render_latex(text):
|
| 112 |
+
"""Minimal LaTeX cleanup - let the model do the work"""
|
| 113 |
+
if not text:
|
| 114 |
return text
|
| 115 |
|
| 116 |
try:
|
| 117 |
+
# Convert LaTeX bracket notation to dollar signs
|
| 118 |
+
text = re.sub(r'\\\[(.*?)\\\]', r'$$\1$$', text, flags=re.DOTALL)
|
| 119 |
+
text = re.sub(r'\\\((.*?)\\\)', r'$\1$', text, flags=re.DOTALL)
|
|
|
|
|
|
|
| 120 |
|
| 121 |
+
# Fix boxed answers ONLY if not already in math mode
|
| 122 |
+
if '\\boxed' in text and not re.search(r'\$.*\\boxed.*\$', text):
|
| 123 |
+
text = re.sub(r'\\boxed\{([^}]+)\}', r'$\\boxed{\1}$', text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
except Exception as e:
|
| 126 |
+
print(f"⚠️ LaTeX error: {e}")
|
|
|
|
| 127 |
|
| 128 |
return text
|
| 129 |
|