Spaces:
Sleeping
Sleeping
fix user input latex rendering
Browse files- web/src/App.tsx +21 -0
web/src/App.tsx
CHANGED
|
@@ -361,6 +361,27 @@ const normalizeUserLatex = (content: string): string => {
|
|
| 361 |
}
|
| 362 |
|
| 363 |
let normalized = content;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 364 |
|
| 365 |
// Convert simple 2D array literals into LaTeX matrices, e.g. [[2,1],[1,2]].
|
| 366 |
normalized = normalized.replace(
|
|
|
|
| 361 |
}
|
| 362 |
|
| 363 |
let normalized = content;
|
| 364 |
+
const trimmed = normalized.trim();
|
| 365 |
+
|
| 366 |
+
// Support bare display-style square-bracket wrappers used by some users,
|
| 367 |
+
// e.g.:
|
| 368 |
+
// [y = (3x^2 - 2x + 1)e^x.]
|
| 369 |
+
// or multi-line:
|
| 370 |
+
// [
|
| 371 |
+
// y = (3x^2 - 2x + 1)e^x.
|
| 372 |
+
// ]
|
| 373 |
+
// Avoid converting JSON-like arrays or matrix literals handled elsewhere.
|
| 374 |
+
if (
|
| 375 |
+
trimmed.startsWith('[') &&
|
| 376 |
+
trimmed.endsWith(']') &&
|
| 377 |
+
!/^\[\s*\[/.test(trimmed) &&
|
| 378 |
+
/(?:=|\^|_|\\|[+\-*/]|\b(?:sin|cos|tan|log|ln|exp)\b)/.test(trimmed.slice(1, -1))
|
| 379 |
+
) {
|
| 380 |
+
const inner = trimmed.slice(1, -1).trim();
|
| 381 |
+
if (inner) {
|
| 382 |
+
return `$$${inner}$$`;
|
| 383 |
+
}
|
| 384 |
+
}
|
| 385 |
|
| 386 |
// Convert simple 2D array literals into LaTeX matrices, e.g. [[2,1],[1,2]].
|
| 387 |
normalized = normalized.replace(
|