Spaces:
Sleeping
Sleeping
fix latex render
Browse files- src/App.js +19 -3
src/App.js
CHANGED
|
@@ -145,11 +145,27 @@ function normalizeLatex(text) {
|
|
| 145 |
// Replace \(...\) with $...$
|
| 146 |
normalized = normalized.replace(/\\\((.+?)\\\)/gs, (_, inner) => `$${inner}$`);
|
| 147 |
|
| 148 |
-
// Fix
|
| 149 |
-
normalized = normalized.replace(/\$\$\$/g, '$$');
|
| 150 |
-
|
| 151 |
// Fix quadruple dollar signs $$$$ back to $$
|
| 152 |
normalized = normalized.replace(/\$\$\$\$/g, '$$');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
return normalized;
|
| 155 |
}
|
|
|
|
| 145 |
// Replace \(...\) with $...$
|
| 146 |
normalized = normalized.replace(/\\\((.+?)\\\)/gs, (_, inner) => `$${inner}$`);
|
| 147 |
|
| 148 |
+
// Fix multiple dollar signs issues
|
|
|
|
|
|
|
| 149 |
// Fix quadruple dollar signs $$$$ back to $$
|
| 150 |
normalized = normalized.replace(/\$\$\$\$/g, '$$');
|
| 151 |
+
|
| 152 |
+
// Fix triple dollar signs $$$ back to $$
|
| 153 |
+
normalized = normalized.replace(/\$\$\$/g, '$$');
|
| 154 |
+
|
| 155 |
+
// Fix standalone $ with $x$ patterns that might be broken
|
| 156 |
+
// Ensure proper spacing around inline math
|
| 157 |
+
normalized = normalized.replace(/\$([^\$\n]+?)\$/g, (match, inner) => {
|
| 158 |
+
// Trim whitespace from the math expression
|
| 159 |
+
const trimmed = inner.trim();
|
| 160 |
+
return `$${trimmed}$`;
|
| 161 |
+
});
|
| 162 |
+
|
| 163 |
+
// Fix display math with extra whitespace
|
| 164 |
+
normalized = normalized.replace(/\$\$([^\$]+?)\$\$/gs, (match, inner) => {
|
| 165 |
+
// Preserve internal structure but trim outer whitespace
|
| 166 |
+
const trimmed = inner.trim();
|
| 167 |
+
return `$$${trimmed}$$`;
|
| 168 |
+
});
|
| 169 |
|
| 170 |
return normalized;
|
| 171 |
}
|