Skip to main content

Crate ratatex

Crate ratatex 

Source
Expand description

TeX-quality display math inside scrolling Ratatui interfaces.

ratatex turns completed Markdown display-math regions into cell-aligned PNGs on a bounded background worker. It parses, lays out, and rasterizes math in-process with embedded fonts—without a system TeX installation or rendering subprocess. The PNGs are cached on disk, uploaded through the Kitty graphics protocol, and placed with Unicode-placeholder cells. Because the placeholders are ordinary terminal cells, equations naturally scroll, clip, and redraw with the rest of a Ratatui buffer.

The crate deliberately leaves surrounding Markdown rendering to the application. Use display_math to find renderable regions, call Ratatex::request for each expression, reserve Formula::rows lines, flush terminal commands when the update callback fires, and render a FormulaWidget over the reserved cells.

For a streaming document, pass a temporary heal_streaming_display_math view to display_math and retain the latest ready Formula while a newer prefix renders. When a formula is partially outside the viewport, use SignedPosition rather than slicing its placeholder grid; this preserves the Kitty source-tile coordinates. FormulaWidget::compact_source_fallback swaps the same reserved cells back to selectable LaTeX for a native terminal-selection pass.

Structs§

Availability
Runtime capability summary.
ColorScheme
Foreground/background colors used by raster post-processing.
DisplayMath
One closed Markdown display-math region.
Formula
One immutable prepared formula.
FormulaWidget
A clipping Ratatui widget for one prepared formula.
Limits
Resource and input bounds owned by the renderer.
PixelPadding
Extra pixels around the tight TeX bounding box.
PixelSize
Pixel dimensions of one terminal cell.
Ratatex
Cloneable request/cache handle.
RatatexBuilder
Builder for a background renderer.
RenderFailure
Cloneable, typed rendering failure retained by the memory cache.
Rgb
An RGB color used by the raster post-processor.
SignedPosition
Signed formula origin relative to a widget viewport.
TerminalCommand
Bytes that must be written to the terminal outside the Ratatui buffer.
TerminalProfile
Everything about the terminal that affects a rendered formula.

Enums§

Antialiasing
Formula antialiasing mode.
DisplayMathDelimiter
Delimiter that introduced a display-math region.
FormulaState
Current state of a formula request.
GraphicsSupport
Terminal support for the image-placement half of the pipeline.
MarkdownSegment
Alternating prose and display-math regions from a Markdown document.
RenderFailureKind
Why a formula could not be rendered.

Functions§

compact_latex
Collapses runs of source whitespace into single spaces.
display_math
Finds completed display math while ignoring fenced and inline code.
heal_streaming_display_math
Completes a trailing, currently open display-math region for previewing a streaming Markdown document.
is_formula_placeholder
Returns whether a Ratatui cell symbol is a Kitty graphics placeholder.
markdown_segments
Splits Markdown into ordinary text and completed display formulas.