Spaces:
Sleeping
Sleeping
Fix: Added Step 0.5 in math-preprocessing.ts:117 immediately after Step 0: a merge pass that detects adjacent $$ blocks separated only by optional whitespace and combines them into a single block.
Browse files
web/src/math-preprocessing.ts
CHANGED
|
@@ -115,6 +115,14 @@ export function preprocessMathContent(content: string): string {
|
|
| 115 |
}).join('');
|
| 116 |
}
|
| 117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
// Step 1.5: Re-run the lone-$-on-its-own-line fix AFTER delimiter normalization.
|
| 119 |
// \(\ncontent\n\) becomes $\ncontent\n$ after Step 1, so we need another pass.
|
| 120 |
for (let _pass2 = 0; _pass2 < 2; _pass2++) {
|
|
|
|
| 115 |
}).join('');
|
| 116 |
}
|
| 117 |
|
| 118 |
+
// Step 0.5: Merge adjacent $$ blocks that are only separated by optional whitespace.
|
| 119 |
+
// This occurs when the LLM writes $$expr =$$\begin{cases}...\end{cases} — Step 0 wraps
|
| 120 |
+
// the \begin block, producing $$expr =$$$$\n\begin{cases}...\n$$. Those two consecutive
|
| 121 |
+
// $$ blocks should be one combined display math expression.
|
| 122 |
+
processed = processed.replace(/\$\$([\s\S]*?)\$\$[ \t]*\$\$\n?([\s\S]*?)\$\$/g, (_match, a, b) => {
|
| 123 |
+
return `$$\n${a.trim()} ${b.trim()}\n$$`;
|
| 124 |
+
});
|
| 125 |
+
|
| 126 |
// Step 1.5: Re-run the lone-$-on-its-own-line fix AFTER delimiter normalization.
|
| 127 |
// \(\ncontent\n\) becomes $\ncontent\n$ after Step 1, so we need another pass.
|
| 128 |
for (let _pass2 = 0; _pass2 < 2; _pass2++) {
|