Spaces:
Sleeping
Sleeping
fix latex rendering for user input
Browse files- web/src/App.tsx +6 -1
web/src/App.tsx
CHANGED
|
@@ -118,7 +118,12 @@ function preprocessMathContent(content: string): string {
|
|
| 118 |
|
| 119 |
let processed = content;
|
| 120 |
|
| 121 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
// Replace $number with \$number (unless already escaped)
|
| 123 |
processed = processed.replace(/(?<!\\)\$(\d+(?:\.\d{2})?)/g, '\\$$1');
|
| 124 |
|
|
|
|
| 118 |
|
| 119 |
let processed = content;
|
| 120 |
|
| 121 |
+
// Auto-wrap common math patterns for user input (simple superscripts/subscripts)
|
| 122 |
+
// This makes "x^2 + 1" render as math automatically
|
| 123 |
+
processed = processed.replace(/\b([a-zA-Z])(\^)(\d+|[a-zA-Z]|\{[^}]+\})/g, '$$$1$2$3$$');
|
| 124 |
+
processed = processed.replace(/\b([a-zA-Z])(_)(\d+|[a-zA-Z]|\{[^}]+\})/g, '$$$1$2$3$$');
|
| 125 |
+
|
| 126 |
+
// Protect currency amounts from being parsed as math
|
| 127 |
// Replace $number with \$number (unless already escaped)
|
| 128 |
processed = processed.replace(/(?<!\\)\$(\d+(?:\.\d{2})?)/g, '\\$$1');
|
| 129 |
|