Skip to content

feat: render LaTeX math as Unicode in TUI - #40867

Closed
Cl-VII wants to merge 4 commits into
anomalyco:devfrom
Cl-VII:feat/latex-unicode-rendering
Closed

feat: render LaTeX math as Unicode in TUI#40867
Cl-VII wants to merge 4 commits into
anomalyco:devfrom
Cl-VII:feat/latex-unicode-rendering

Conversation

@Cl-VII

@Cl-VII Cl-VII commented Aug 6, 2026

Copy link
Copy Markdown

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

  • New feature

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:

  • $ followed by digits or whitespace ($0.02, $5) is treated as currency/placeholder, not math
  • Unclosed $ does not swallow the rest of the text
  • Escaped $ inside math works
  • Unrecognized LaTeX commands fall back to plain text, so no content is lost

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?

  • Tokenizer unit tests: �un test src/markdown/math-extension.test.ts (6 tests: inline math, currency guard, escaped dollar, block math, empty body, start positions) - all pass
  • End-to-end: built opentui core locally (incl. native Zig build on Windows) and verified MarkdownRenderable with the math extension produces a math token with the converted Unicode text
  • latex2unicode package: 82 tests pass (greek letters, sub/superscripts, fractions, roots, matrices, display-preference relations, econometrics formulas)

Screenshots / recordings

N/A - terminal output; verification was done via token inspection (the TUI text renderer outputs the Unicode string directly).

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Aug 6, 2026
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@Cl-VII

Cl-VII commented Aug 6, 2026

Copy link
Copy Markdown
Author

Author requested removal of all latex-related uploads.

@Cl-VII Cl-VII closed this Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant