[PR #110] [MERGED] Fix LaTeX dollar sign escaping breaking code blocks #129

Closed
opened 2026-02-16 03:15:18 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/run-llama/chat-ui/pull/110
Author: @thucpn
Created: 6/3/2025
Status: Merged
Merged: 6/3/2025
Merged by: @thucpn

Base: mainHead: tp/fix-release-0.5.0


📝 Commits (10+)

📊 Changes

6 files changed (+162 additions, -8 deletions)

View changed files

.changeset/cool-shirts-call.md (+5 -0)
apps/web/app/demo/latex/page.tsx (+98 -0)
📝 apps/web/app/page.tsx (+5 -0)
📝 examples/nextjs/app/api/chat/advanced/route.ts (+15 -6)
📝 packages/chat-ui/src/widgets/markdown.tsx (+38 -2)
📝 packages/config-eslint/next.js (+1 -0)

📄 Description

The preprocessLaTeX function is escaping ALL dollar signs to prevent them from being treated as math delimiters, but this breaks code blocks. This PR help preserve dollar signs in code contexts while still handling LaTeX properly

To reproduce, run dev in apps/web and go to http://localhost:3000/demo/simple page to ask a question to generate code. Eg:
Write js code that accept a location and console log Hello from location

image

Notice that the $ in the code has been prefixed with /:

function greetFromLocation(location) {
    console.log(`Hello from \${location}`); // should be `Hello from ${location}`
}

This issue also caused inline annotation parsing to fail


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/run-llama/chat-ui/pull/110 **Author:** [@thucpn](https://github.com/thucpn) **Created:** 6/3/2025 **Status:** ✅ Merged **Merged:** 6/3/2025 **Merged by:** [@thucpn](https://github.com/thucpn) **Base:** `main` ← **Head:** `tp/fix-release-0.5.0` --- ### 📝 Commits (10+) - [`b457592`](https://github.com/run-llama/chat-ui/commit/b4575920dabd161bd301597f985f7de4a6e3746d) fix: dollar sign in code make json parse fail - [`efe6488`](https://github.com/run-llama/chat-ui/commit/efe648885ad57ab429e34ad582912eb60982bf28) remove log - [`677884b`](https://github.com/run-llama/chat-ui/commit/677884b9c0624bebcdf11c037f1f5ba219882a8c) Create cool-shirts-call.md - [`e5c3779`](https://github.com/run-llama/chat-ui/commit/e5c37792fed5c85b9b5e8b791dec3878e3233264) remove unused inline in example - [`771ffe5`](https://github.com/run-llama/chat-ui/commit/771ffe5a6919b521c5c3f78289684e9f9ee13e48) keep parse code inline as it is - [`fc603e8`](https://github.com/run-llama/chat-ui/commit/fc603e83611f947129e2c628d9ac8d392c4e0720) Fix LaTeX dollar sign escaping breaking code blocks - [`11e2a25`](https://github.com/run-llama/chat-ui/commit/11e2a2555799f0bebc315c412403c0fb4fb383cb) protect code block - [`38511cb`](https://github.com/run-llama/chat-ui/commit/38511cb1a3877dc04e229855f9d6d7c92e092b2d) update example - [`676924f`](https://github.com/run-llama/chat-ui/commit/676924f092e5336503f2da1fe84d6ea20ea9eb92) demo latex - [`dabdcc3`](https://github.com/run-llama/chat-ui/commit/dabdcc309f4bd26aa434eb3df95872cd9e2d13bd) update doc ### 📊 Changes **6 files changed** (+162 additions, -8 deletions) <details> <summary>View changed files</summary> ➕ `.changeset/cool-shirts-call.md` (+5 -0) ➕ `apps/web/app/demo/latex/page.tsx` (+98 -0) 📝 `apps/web/app/page.tsx` (+5 -0) 📝 `examples/nextjs/app/api/chat/advanced/route.ts` (+15 -6) 📝 `packages/chat-ui/src/widgets/markdown.tsx` (+38 -2) 📝 `packages/config-eslint/next.js` (+1 -0) </details> ### 📄 Description The `preprocessLaTeX` function is escaping ALL dollar signs to prevent them from being treated as math delimiters, but this breaks code blocks. This PR help preserve dollar signs in code contexts while still handling LaTeX properly To reproduce, run dev in apps/web and go to http://localhost:3000/demo/simple page to ask a question to generate code. Eg: `Write js code that accept a location and console log Hello from location` ![image](https://github.com/user-attachments/assets/6d2a8c40-766f-49e3-b591-60bcbe7880b3) Notice that the $ in the code has been prefixed with /: ``` function greetFromLocation(location) { console.log(`Hello from \${location}`); // should be `Hello from ${location}` } ``` This issue also caused inline annotation parsing to fail --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-16 03:15:18 -05:00
yindo closed this issue 2026-02-16 03:15:18 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: run-llama/chat-ui#129