ReferenceReference

CLI LaTeX rendering

Rendering math in the terminal: detection, Unicode flatten, and 2D pretty print with a raw-text fallback.

On this page
  1. The two tiers
  2. Detection heuristics
  3. Failure modes
  4. Regression suite

GEODE renders math in LLM replies readably in the terminal. The implementation is one module, core/ui/latex.py; the entry points are render_latex(src, block=...) and extract_and_render_inline, which finds math spans in streaming text. The caller is the interactive loop (core/cli/interactive_loop.py).

The two tiers

Tier 1   pylatexenc LatexNodes2Text   inline + block. LaTeX → flat Unicode, one line
Tier 2   latex2sympy2 + sympy.pretty  block only. fractions/integrals as a 2D Unicode block
fallback raw source                   when both fail. never raises

Inline (block=False) skips Tier 2 entirely so one-line flow stays predictable. Blocks try Tier 2 only when _has_tier2_construct spots a token worth 2D treatment, and fall back silently to Tier 1 when parsing or pretty-printing fails. If Tier 1 fails too, the raw input comes back unchanged.

Detection heuristics

extract_and_render_inline handles both delimited math ($...$, $$...$$) and delimiter-less candidates, with guards against false positives: markdown code spans are skipped, / in a file-path context is left alone (_looks_like_path_context), and digit-base subscripts plus nested superscripts are handled. The output contract itself is instructed to the model by with_math_output_formatting in core/llm/prompt_assembler.py.

Failure modes

SymptomCauseFix
Math shows as raw LaTeXpylatexenc missing or a Tier 1 exceptionThe dependency ships in pyproject. If it persists after a reinstall, the input was not LaTeX.
A block renders on one lineTier 2 parse failed, Tier 1 took overIntended: constructs latex2sympy2 cannot handle get flattened.
A path renders as mathDelimiter-less false positiveThe path-context guard is pinned by regression tests; add the case when found.

Regression suite

tests/core/ui/test_ui_latex.py, tests/core/ui/test_cli_latex_uiux.py, and tests/core/cli/test_interactive_loop_latex.py pin multi-line collapse, the delimiter-less heuristic, path context, and digit-base cases.

Moved from the GEODE repository’s documentation site. Source commit de077a4 · View the source on GitHub