
1. Before We Begin
LaTeX is the digital language of mathematics — the bridge for bringing mathematical ideas into the digital world. The rewards are endless, but it seems to have a certain barrier to entry.
Using two models, MiniCPM5-1B + MiniCPM-V 4.6, I built a desktop app that can actually be installed and used every day.
TeXada is an on-device Agent for structured math formula input.
This Agent can:
- Turn natural language (e.g. "the sum of k squared for k from 1 to n") into compile-verified LaTeX;
- OCR handwritten formulas or screenshots into LaTeX;
- Repair broken LaTeX and render it with KaTeX so it can be copied — what you see is what you get.
The whole process runs on your own computer: Ollama loads the two MiniCPM models, so it works offline, and the FastAPI backend is bundled as a sidecar with the Tauri desktop app, keeping it small and lightweight. It's currently at v0.3.8, with DMG packages for macOS (Apple Silicon / Intel) and an installer for Windows x64, open-sourced under AGPL-3.0.
This article answers two questions: what real results can such small models actually achieve when combined, and what did I learn while turning them into an Agent.
2. Use Cases and Real Results
2.1 What Is TeXada
In one sentence: not a wrapper chatbot, but a math input-method tool Agent that calls deterministic tools.
I didn't use any of the complex, popular Agent frameworks; instead, it calls tools based on the characteristics and needs of TeX. The main loop is:
输入(自然语言 / 图片 / 残缺 LaTeX)
↓
MiniCPM5-1B Planner(规划下一步用哪个工具)
↓
TeX 工具执行(parse / compile / repair / diff / render / export)
↓
Observation(真实执行结果,回给 Planner)
↓
通过编译校验的结构化公式
The two models each have their own job, and these are the only two inference entry points:
| Role | Model | Responsible for | Explicitly not responsible for |
|---|---|---|---|
| Planner / text | hf.co/openbmb/MiniCPM5-1B-GGUF:Q4_K_M (Ollama) | Planning, tool selection, NL candidates, complex completion | Directly repairing invalid LaTeX, simulating tool results |
| Vision / OCR | openbmb/minicpm-v4.6:latest | Proposing LaTeX candidates from images | Final verification, semantic diff, rendering |
The two models together have fewer than 2.5B parameters and run on a laptop with 16GB or even 8GB of memory. They handle the uncertain natural-language parts.
Everything else — parsing, verification, repair, comparison, rendering and export — uses rule-based deterministic tools.
2.2 Three Real Product Paths
Natural Language → Structured Formula
Input: probability density function
Output, compile-verified:
f_X(x)\ge 0,\quad \int_{-\infty}^{\infty}f_X(x)\,dx=1
Input: 求 k 从 1 到 n 的 k 平方 (sum of k squared for k from 1 to n)
Output:
\sum_{k=1}^{n} k^2
Handwritten Formula OCR:
MiniCPM-V 4.6 recognizes a handwritten definite integral and produces a candidate, which is only marked as valid after the shared Agent runtime compiles and renders it. The vision model only proposes candidates and does not have its own planning loop, so failures are easy to localize: recognition problems belong to OCR, tool-selection problems belong to the Planner, and syntax problems belong to the validator.
Repairing Broken LaTeX:
Input: A Gaussian probability density missing its closing braces
Output:
f(x)=\frac{1}{\sigma\sqrt{2\pi}}e^{-\frac{(x-\mu)^2}{2\sigma^2
repair_tex uses deterministic rules to complete the groups, re-verify and render.
What I'm rather proud of here is a divide-and-conquer sense of boundaries: this tool only does reproducible syntax repairs like adding a missing brace, and will not invent a missing denominator for the user — that's a semantic issue.
2.3 Measured Data
Measurements with local Ollama + the default models (on-device latency varies by device; the point here is mainly the difference between paths):
| Scenario | Result |
|---|---|
| High-confidence NL hot path | About 5~25 ms, 0 tokens (uses a deterministic candidate, but still goes through the compile/render tools) |
| NL UI case with punctuation/synonyms | About 142 ms |
| Completing x+\alp | Outputs x+\alpha, 1 step / 2 tool calls / 0 tokens |
| OCR of a handwritten integral image | Recognized correctly, about 3.6~10.1 s end to end |
Zero tokens yet a complete tool trace — that's the design I'm personally most pleased with in this architecture.
Being an Agent doesn't mean every input has to burn an inference call, but every candidate must pass through the same compile and render gates.
The fast path is an accelerator; it doesn't mean lower-quality generation.
