-
Notifications
You must be signed in to change notification settings - Fork 11
Latex issue dollar signs #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -149,7 +149,18 @@ function normalizeCustomMathTags(input: string): string { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .replace(/\\{1,2}\(([\s\S]*?)\\{1,2}\)/g, (_, content) => `$$${content.trim()}$$`) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Convert \[ ... \] to $$...$$ (block math) - streamdown needs newlines for block triggers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .replace( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /\\{1,2}\[([\s\S]*?)\\{1,2}\]/g, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (_, content) => `$$\n${content.trim()}\n$$` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| )); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /\\{1,2}\[([\s\S]*?)\\{1,2}\]/g, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (_, content) => `$$\n${content.trim()}\n$$` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Convert single $ ... $ to $$...$$ (inline math), but avoid currency like $10 or $5.50 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Use lookbehind to avoid consuming characters and handle consecutive expressions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Exclude escaped dollar signs (prefixed with \) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .replace(/(?<!\\)(?<!\$)\$(?!\$)([^$\n]+?)(?<!\\)(?<!\$)\$(?!\$)/g, (match, content) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // More precise currency pattern: matches numbers like 10, 1,000, 10.50, 1,000.50 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (/^\d{1,3}(?:,\d{3})*(?:\.\d{1,2})?$/.test(content.trim())) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return match; // Keep as-is (currency) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Otherwise, convert to math | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return `$$${content.trim()}$$`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| })); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
151
to
+165
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: cat -n src/components/assistant-ui/markdown-text.tsx | head -200Repository: ThinkEx-OSS/thinkex Length of output: 7087 🏁 Script executed: rg -i "markdown|normalize.*text|normaliz.*math" --type ts --type tsx -lRepository: ThinkEx-OSS/thinkex Length of output: 90 🏁 Script executed: rg -i "markdown|normalize" --type ts -lRepository: ThinkEx-OSS/thinkex Length of output: 1596 🏁 Script executed: cat -n src/components/assistant-ui/standalone-markdown.tsxRepository: ThinkEx-OSS/thinkex Length of output: 11175 Fix escaped dollar sign handling in both math normalizers The regex pattern Suggested fix- .replace(/(^|[^\$])\$([^\$\n]+?)\$(?!\$)/g, (match, prefix, content) => {
+ .replace(/(^|[^$\\])\$([^\$\n]+?)\$(?!\$)/g, (match, prefix, content) => {Apply this change to both functions for consistency. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Currency detection regex misses 4+ digit amounts without commas (e.g.,
$1000), so those get converted to math. Widen the pattern to allow plain digit sequences or properly comma-grouped numbers.Prompt for AI agents