feat: render LaTeX math as Unicode in TUI - #40867
Closed
Cl-VII wants to merge 4 commits into
Closed
Conversation
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
3 tasks
Author
|
Author requested removal of all latex-related uploads. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Related to #40508 (V2 TUI LaTeX rendering). This PR implements the TUI side for current V1/V2 TUI markdown rendering.
Type of change
What does this PR do?
The web/desktop UI already renders LaTeX math via KaTeX (packages/ui/src/context/marked-parser.tsx). The TUI had no equivalent: formulas in model replies showed raw LaTeX source (e.g.$y = \beta_0 + \beta_1 x + \varepsilon$ ), with $/*/_ interfering with markdown styling.
This PR adds a marked extension (packages/tui/src/markdown/math-extension.ts) that recognizes inline$...$ and block $$... math and converts the body to readable Unicode via the zero-dependency latex2unicode package (data-driven symbol tables generated from the official unicode-math and KaTeX sources). The extension is passed to the component in the session view through the new extensions option on MarkdownRenderable (anomalyco/opentui#1345).
Edge cases handled:
Example output: The model = \beta_0 + \beta_1 x + \varepsilon$ is linear renders as The model 𝑦 = β₀ + β₁𝑥 + ε is linear.
How did you verify your code works?
Screenshots / recordings
N/A - terminal output; verification was done via token inspection (the TUI text renderer outputs the Unicode string directly).
Checklist