Skip to content

feat: LaTeX rendering #36233

Closed
Closed

Description

@haskallcurry

What variant of Codex are you using?

CLI

What feature would you like to see?

Proposal: render LaTeX in the Codex TUI

Image

Background

LaTeX rendering has been requested previously. I recently shared a prototype on twitter, which was positively received, and @fcoury invited me to contribute it.

I cannot open a PR as it is restricted to collaborators, however my implementation can be found here:

https://github.com/haskallcurry/codex/tree/feat/kitty-latex-ratex

Implementation

The implementation:

  • recognizes explicitly delimited display and inline math while excluding Markdown code;
  • renders it in-process using RaTeX, a Rust implementation of KaTeX-style mathematical layout;
  • displays the resulting images using the Kitty graphics protocol, similar to the existing /pets feature;
  • does not require an external TeX installation or renderer process.

Using KaTeX directly would require an HTML/CSS layout and rasterization engine.

Known limitations

  • Inline images must fit terminal-cell geometry, and their baseline alignment varies somewhat between terminal implementations. Inline math is therefore rendered in Unicode whenever possible.
  • Native terminal selection copies the Kitty Unicode-placeholder cells rather than the original LaTeX source.

Additional information

No response

Activity

  1. added
    enhancement
    on Jul 30, 2026
  2. added
    CLI
    TUI
    on Jul 30, 2026
  3. github-actions commented on Jul 30, 2026

    @github-actions
    Contributor

    Potential duplicates detected. Please review them and close your issue if it is a duplicate.

    Powered by Codex Action

  4. fcoury-oai commented on Jul 30, 2026

    @fcoury-oai
    Contributor

    Thank you very much for taking the time @haskallcurry! In the next days I will be reviewing the PR and trying to land an adaptation soon. I will fully credit you when I do!

  5. imvladikon commented on Jul 31, 2026

    @imvladikon

    Funny, because I did it too (but in a different way)
    #32828 (comment)
    @fcoury-oai FYI

  6. nullbio commented on Aug 22, 2026

    @nullbio

    +1. Super annoying seeing raw Latex.

    It should be switchable with alt+r by the way, not sure if you implemented that?

  7. FacuVCanale commented on Aug 30, 2026

    @FacuVCanale

    I built and live-tested a RaTeX/Kitty variant focused on scrollback behavior and would like to share the implementation and one load-bearing finding for the upstream adaptation.

    Implementation: https://github.com/FacuVCanale/codex-ratex
    Release/demo binary: https://github.com/FacuVCanale/codex-ratex/releases/tag/v0.1.0-ratex.1
    Commit: FacuVCanale@36a4620

    Key experiment

    On Ghostty via HERDR:

    • 18 separate PNGs / 18 Kitty placements: visible staggered scroll lag.
    • 1 shared PNG atlas / 18 cropped placements: same staggered lag.
    • 1 response-sized transparent PNG / 1 Kitty placement: smooth, uniform scroll.

    The important unit is therefore the placement, not the uploaded texture. Even when all cropped a=p commands are emitted in one synchronized-output batch, Ghostty currently recomposes multiple placements progressively. The working design computes the finalized Markdown layout first, paints every display formula at its real terminal-row offset in one transparent response canvas, and emits exactly one a=t plus one a=p with z=-1. Text between equations remains terminal-native/selectable above transparent canvas regions.

    Upstream-shaped behavior

    • Experimental inline_latex feature, default off.
    • Activates only for the existing true inline-Kitty capability (ImageProtocol::Kitty); iTerm2 generic/local-file mode is excluded.
    • Display blocks are parsed before CommonMark destroys source delimiters.
    • Rendering happens asynchronously only after message finalization.
    • Unsupported terminals, disabled flag, parse/render failure, or size limits preserve the exact original LaTeX.
    • Canvas limits: 8192 px per axis and 8 MP.
    • Initial width is frozen for the MVP so reflow cannot silently desynchronize formula offsets.
    • Content digest is used only for raster cache; Kitty image/placement IDs are session-unique so identical answers do not delete earlier scrollback placements.
    • Full clears, resize/reflow, and /clear invalidate upload state and replay the canvas.
    • Row-cap truncation preserves complete canvases; a partially retained canvas falls back to raw LaTeX instead of blank reserved rows.
    • Resume/hydration/pagination use the same gated scheduling path as live messages.

    Validation

    • math block parser: 10 tests
    • renderer/cache/limits: 7 tests
    • one upload/one placement transport: 2 tests
    • resize/reflow/truncation: 22 tests
    • feature/capability/hydration gate: 3 tests
    • dedicated regressions for identical responses, clear/replay, partial truncation, and resume
    • cargo check -p codex-tui, debug build, release build, fmt, and diff-check pass
    • two independent review passes; final review found no blocking/high/medium issues

    I read the contribution policy and am intentionally not opening an unsolicited PR. The fork is rebased onto current main and is available as implementation evidence for the maintainer-owned adaptation. The single-canvas/single-placement result is the main recommendation I would carry upstream; using one placement per formula looked correct while stationary but was unusable during real scroll testing.

  8. etraut-openai commented on Oct 12, 2026

    @etraut-openai
    Contributor

    Basic LaTeX rendering is now in place. More complex equations — those that can't feasibly be rendered in text — fall back on raw LaTeX still.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLITUIenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions