Spaces:
Sleeping
Sleeping
continue to fix latex
Browse files- web/src/mathjax-config.ts +15 -0
web/src/mathjax-config.ts
CHANGED
|
@@ -123,6 +123,21 @@ export function preprocessMathContent(content: string): string {
|
|
| 123 |
}
|
| 124 |
);
|
| 125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
// Step 2: Normalize various LaTeX delimiters to MathJax-compatible format
|
| 127 |
|
| 128 |
// Convert \( ... \) to $...$ (inline math)
|
|
|
|
| 123 |
}
|
| 124 |
);
|
| 125 |
|
| 126 |
+
// Step 1.7: Fix broken inline math that spans across text
|
| 127 |
+
// Pattern: $...$\ge or $...$\le followed by more math
|
| 128 |
+
// Convert to: $... \ge ... $ or continue the inline math
|
| 129 |
+
processed = processed.replace(
|
| 130 |
+
/\$([^$]+)\$\s*(\\(?:ge|le|ne|approx|equiv|sim|in|subset|supset|cup|cap|cdot|times|pm|mp))\s+([^$\n]+)/g,
|
| 131 |
+
(_match, before, operator, after) => {
|
| 132 |
+
// If 'after' contains LaTeX commands, include it in the same inline math
|
| 133 |
+
if (/\\[a-zA-Z]+/.test(after)) {
|
| 134 |
+
return `$${before} ${operator} ${after.trim()}$`;
|
| 135 |
+
}
|
| 136 |
+
// Otherwise, keep as is but ensure spacing
|
| 137 |
+
return `$${before}$ ${operator} ${after}`;
|
| 138 |
+
}
|
| 139 |
+
);
|
| 140 |
+
|
| 141 |
// Step 2: Normalize various LaTeX delimiters to MathJax-compatible format
|
| 142 |
|
| 143 |
// Convert \( ... \) to $...$ (inline math)
|