fraudTech commited on
Commit
06dbf86
·
1 Parent(s): ce97d7f

fix latex rendering issue for $$...$$

Browse files
Files changed (1) hide show
  1. web/src/math-preprocessing.ts +11 -3
web/src/math-preprocessing.ts CHANGED
@@ -46,9 +46,17 @@ export function preprocessMathContent(content: string): string {
46
  processed = processed.replace(/\\right(?![)\]}|])/g, '');
47
 
48
  // Step 5: Fix list markers contaminating delimiters
49
- processed = processed.replace(/(\d+)\$\$/g, '$1. $$');
50
- processed = processed.replace(/\$\$(\d+)\$/g, '$$ $1.');
51
- processed = processed.replace(/\$(\d+)\$/g, '$ $1. $');
 
 
 
 
 
 
 
 
52
 
53
  // Step 6: Ensure display math is on its own lines
54
  processed = processed.replace(/\$\$([\s\S]*?)\$\$/g, (_match, math) => {
 
46
  processed = processed.replace(/\\right(?![)\]}|])/g, '');
47
 
48
  // Step 5: Fix list markers contaminating delimiters
49
+ const displayMathSplit = processed.split(/(\$\$[\s\S]*?\$\$)/g);
50
+ processed = displayMathSplit.map(segment => {
51
+ if (segment.startsWith('$$') && segment.endsWith('$$')) {
52
+ return segment;
53
+ }
54
+ let cleaned = segment;
55
+ cleaned = cleaned.replace(/(\d+)\$\$/g, '$1. $$');
56
+ cleaned = cleaned.replace(/\$\$(\d+)\$/g, '$$ $1.');
57
+ cleaned = cleaned.replace(/\$(\d+)\$/g, '$ $1. $');
58
+ return cleaned;
59
+ }).join('');
60
 
61
  // Step 6: Ensure display math is on its own lines
62
  processed = processed.replace(/\$\$([\s\S]*?)\$\$/g, (_match, math) => {