Ratatex 是一个 Rust 库,通过进程内解析和 Kitty 图形占位符,将 TeX 显示数学公式渲染为高分辨率、可滚动的 PNG 图片,集成到 Ratatui 终端界面中。

Stars

7

7 天增长

暂无数据

Fork 数

1

开放 Issue

0

开源协议

MIT

最近更新

2026-07-29

AI 仓库情报摘要
FR-AI / ANALYSIS

为什么值得关注

它无需安装 TeX 即可在终端中实现高质量的数学公式渲染,采用非阻塞的进程内渲染和内容寻址缓存,并支持流式 Markdown 和可复制的 LaTeX 降级方案。

适合谁使用

  • 使用 Ratatui 的终端 UI 开发者
  • 需要在终端中使用数学公式的研究人员与数据科学家
  • 构建 AI 聊天或流式数学应用的开发者
  • 维护终端科学或教育工具的程序员

典型使用场景

  • 在基于终端的 AI 助手或聊天界面中渲染公式
  • 在 TUI 科学笔记本或 REPL 中嵌入数学
  • 在实时流式 Markdown 渲染器中显示公式
  • 在终端选择操作中提供可复制的 LaTeX 数学源码

项目优势

  • 无需外部 TeX 安装或子进程;全部使用 RaTeX 和嵌入的 KaTeX 字体在进程内完成渲染
  • 非阻塞 API,带内容寻址 PNG 缓存和可选的更新回调
  • 流式 Markdown 支持:通过修补工具逐步渲染不完整的数学表达式
  • 通过 Kitty Unicode 占位符实现无缝滚动裁剪,并支持可复制的源码降级

使用前须知

  • 需要支持 Kitty 图形协议的终端(如 Ghostty、Kitty、WezTerm、较新的 Konsole)
  • 仅支持 KaTeX/AMS 子集的 LaTeX;无法加载任意 TeX 宏包或退回到系统 TeX
  • 滚动行为依赖终端对 Unicode 占位符和图形穿透的支持(例如需配置 tmux)

README 快速开始

Ratatex

TeX-quality display math that scrolls with your Ratatui UI.

Nanocodex demo · Try it · Embed it · Streaming · Selection · Scrolling

https://github.com/user-attachments/assets/9012dcc3-b7d2-44d0-acdf-c94cc73ed5f7

A live Nanocodex low-reasoning run: render TeX, click back to source, and drag-copy the original LaTeX.

Ratatex turns Markdown display math into cell-aligned PNGs on bounded background workers:

Markdown display math
    → RaTeX parse + TeX layout in-process
    → embedded KaTeX fonts + tiny-skia at 3× resolution
    → antialiasing, padding, and cell alignment
    → content-addressed PNG cache
    → Kitty virtual placement + Unicode-placeholder cells

Rendering uses the open-source RaTeX parser, layout engine, embedded fonts, and rasterizer entirely in-process. Ratatex never invokes a system TeX installation, writes DVI, or starts a rendering subprocess. Unsupported expressions return a typed failure so the host application can keep its text representation.

The placeholder cells live in the normal Ratatui buffer. Equations therefore scroll and clip with the surrounding text instead of behaving like cursor-positioned overlays.

Install

cargo add ratatex

Requirements

  • A terminal implementing Kitty graphics Unicode placeholders.
  • Ratatui 0.29.
  • No TeX distribution or external rendering programs.

Ghostty, Kitty, WezTerm, and recent Konsole releases implement the graphics protocol. When running inside tmux, enable graphics passthrough:

set -g allow-passthrough on

Try it

From a compatible terminal:

cargo run --example demo

Press q, Esc, or Ctrl-C to leave the demo.

Embed it

Query the terminal after entering the alternate screen and before starting a competing input reader. Build one renderer for the application, not one per formula:

use std::{io::Write, time::Duration};

use ratatex::{FormulaState, FormulaWidget, Ratatex, TerminalProfile};

项目描述

TeX-quality display math for Ratatui with Kitty Unicode placeholders

相关仓库与替代方案

根据分类、Topic 和编程语言匹配的相似项目。

l0ng-ai
精选
l0ng-ai GitHub avatar

tty7

tty7 is a fast, GPU-accelerated terminal workbench with persistent sessions, built-in input tools, SSH support, and coding agent awareness.

开发者工具CLI 与终端
359
steelbrain
精选
steelbrain GitHub avatar

reims-vgpu

reims-vgpu is an experimental virtual GPU for macOS guests that uses QEMU to decode the guest's GPU command stream and execute it through Metal or Vulkan, leveraging the built-in AppleParavirtGPU driver without requiring custom kexts.

桌面应用
143
m-novotny
精选
m-novotny GitHub avatar

memguard-rs

A Rust library that provides secure memory handling primitives including zeroization on drop, memory locking, constant-time comparison, and compile-time guarded regions, with zero dependencies and no_std support.

嵌入式与物联网安全
131