feat(tui): preview inline math in TUI - #107
Open
ompugao wants to merge 6 commits into
Open
Conversation
- Add DocElement::InlineMathLine with InlineSegment (Text/Math) to tui_renderer.rs; render_ast gains an inline_math: bool parameter - render_latex_inline uses Typst text/inline style ($formula$, no spaces) at 14pt so fractions are compact but readable, like LaTeX \textstyle - image_cache: load_inline_math computes natural row height (ceil(img.height / cell_h)) instead of hardcoding 1; stores column width in new elem_widths field - wrap: InlineMathLine height = max math-segment height from elem_heights - ui: InlineMathLine render arm lays out segments with x_cursor; text is vertically centred (row_y + elem_h/2), math images anchor to top - Fix column calculation to use UnicodeWidthStr::width() instead of chars().count() so CJK/Japanese text does not cause overlap - Add inline_math_rendering: bool config flag to TuiConfig (default true); when false, inline math falls back to plain magenta text Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…r clipping Denominator descenders in fractions were trimmed at 2pt bottom margin. Increase to 4pt (matching block math) so the full fraction is visible. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Text segments after inline math were treated as atomic units — if the remaining text didn't fit in the space after a math image, the whole block jumped to the next row, leaving visible gaps and making lines appear to break "right after the inline math". Fix: iterate text character-by-character in both the render arm (ui.rs) and the height calculator (wrap.rs/inline_math_line_wrap_height). When a character would overflow the right edge the accumulated text is flushed and a new row begins, exactly like regular TextLine wrapping. Math segments remain atomic — if an image doesn't fit it is moved to the next row as a whole. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Five surgical refactors with no behavioral changes: 1. Extract draw_inline_math_line() from draw_content's 155-line match arm 2. Consolidate three pre-load viewport-scan loops into one pass (~50 lines removed) 3. Unify math_render.rs: MathStyle enum replaces four duplicated render functions 4. RenderConfig struct replaces (syntax_theme, inline_math) threaded through 17 call sites 5. ElemSizeCache struct replaces (elem_heights, elem_widths) HashMap pair everywhere Net result: -85 lines, cleaner APIs, easier to extend. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Summary
patto-preview-tuivia Typst-backed imagesNotes