feat(tui): render LaTeX as Unicode math - #45339
Merged
Merged
Conversation
Keep the Unicode parser, symbols, layout, and input limits in the TUI source tree. Remove the math package and its graphics dependencies, and retain parser and layout regression coverage.
Move the engine, Markdown adapter, plugin, and tests into a private workspace package. Remove the standalone license file and dependency patch; apply final Markdown content before completion at the TUI call site.
Preserve norm delimiters, command boundaries, empty cells, array column formats, and continued-fraction options. Size indexed radicals safely, join their strokes, and place scripts and brace annotations around the full expression.
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.
Why
LaTeX fences currently appear as source code in the terminal, making fractions, matrices, and equations difficult to read. Streaming math also needs to tolerate unfinished commands without replacing a useful preview with broken source on every chunk.
What Changes
Add a built-in Unicode-only math renderer through the same fenced-code API as Mermaid. The parser and layout engine are in-repo source, with no external math package, image generation, or special graphics protocol.
latex,math, ortexfenceColors follow the theme: subdue structural strokes and emphasize relations. Radicals use connected box-drawing stems and hooks, including nested and indexed roots. Scripts sit outside tall expressions; over/underbraces stretch and center their annotations. Matrix variants preserve their delimiters, cases are left-aligned, and simple array
l/c/rformats retain their vertical rules. Norm bars, empty alignment cells,\displaylines, and\cfracalignment options preserve their notation instead of silently changing the formula.Preview state belongs to each Markdown fence and is released when that fence is removed. The session applies final Markdown content before disabling streaming, avoiding stale parsed tokens when both values change in one batch. OpenTUI 0.5.8 is unmodified; no dependency patch is required.
Package Boundary
LaTeX follows the structure of Mermaid's
packages/merman:packages/latex/src@opencode-ai/latex/markdown@opencode-ai/latex/pluginpackages/tuiThe new private workspace package has no runtime dependency on the TUI. Its tests run in the workspace's Turbo test pipeline. There is no playground story in the PR.
Demo
latex-feature-corrected.mp4
Matched production TUI recordings at 100x36, with the same simulated response and configured pacing. Before:
fedf017e25; after:9dec8f03fd. Shows a quadratic formula, matrix, and streaming sum. Sequential clips keep the text readable; playback is not accelerated.Notation And Geometry
latex-corrections.mp4
Three matched pairs compare the pre-review renderer (
6a6d80e4da) with9dec8f03fd: connected radicals and tall powers; norms and equation rows; braces, column alignment, rules, and continued fractions. Real production TUI at 110x42 with a simulated provider. Each pair shows five seconds before, then five seconds after, without acceleration. Temporary capture scripts are not part of the PR.Scope
Fenced Unicode math only. Inline
$...$/$$...$$, full TeX documents, TikZ, and image rendering are out of scope. Unsupported array formats and command options fall back to source rather than being guessed. The package uses the existing plugin API, OpenTUI, and sharedstring-widthdependency; there are no new external dependencies or CLI build-script changes.Matched Darwin ARM64 builds with Bun 1.3.14, minified without sourcemaps and with the web UI omitted from both:
Verification