Spaces:
Sleeping
Sleeping
continue to fix latex
Browse files- web/src/mathjax-config.ts +13 -2
web/src/mathjax-config.ts
CHANGED
|
@@ -80,8 +80,19 @@ export function preprocessMathContent(content: string): string {
|
|
| 80 |
});
|
| 81 |
|
| 82 |
// Step 0.25: Clean up delimiter stacking ($$$$, $$$, etc.)
|
| 83 |
-
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
// Step 0.3: Fix markdown table pipes interfering with math
|
| 87 |
// Replace $$|$ patterns (table separator after display math) with proper spacing
|
|
|
|
| 80 |
});
|
| 81 |
|
| 82 |
// Step 0.25: Clean up delimiter stacking ($$$$, $$$, etc.)
|
| 83 |
+
// Must run multiple times to handle all cases
|
| 84 |
+
while (processed.includes('$$$')) {
|
| 85 |
+
processed = processed.replace(/\$\$\$\$+/g, '$$'); // Four or more $ → $$
|
| 86 |
+
processed = processed.replace(/\$\$\$/g, '$$'); // Three $ → $$
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
// Step 0.26: Fix \left and \right without proper grouping
|
| 90 |
+
// Replace \left\frac with just \frac (common LLM mistake)
|
| 91 |
+
processed = processed.replace(/\\left\\frac/g, '\\frac');
|
| 92 |
+
processed = processed.replace(/\\right\\frac/g, '\\frac');
|
| 93 |
+
// Fix orphaned \left and \right (remove them if not followed by delimiter)
|
| 94 |
+
processed = processed.replace(/\\left(?![(\[{|])/g, '');
|
| 95 |
+
processed = processed.replace(/\\right(?![)\]}|])/g, '');
|
| 96 |
|
| 97 |
// Step 0.3: Fix markdown table pipes interfering with math
|
| 98 |
// Replace $$|$ patterns (table separator after display math) with proper spacing
|