TeXPatch converts LLM-flavored Markdown math into renderer-safe Markdown for Obsidian, KaTeX, MathJax, Quarto, Pandoc, and GitHub-oriented workflows.
It is not a symbolic algebra system. It is a deterministic cleanup and validation pipeline for malformed TeX/Markdown boundaries that commonly appear in copied model output.
- Convert bracket display math such as
[...],# [...], and\[...\]into explicit display math. - Preserve code fences, inline code, and Markdown links.
- Repair common renderer failures: repeated relation separators, unescaped literal set braces, bad
\left{...\right}delimiters, split suffixes, row spacing, and text macro underscores. - Validate transformed files locally with real KaTeX and MathJax engines before trusting large outputs.
- Bundle the same core transformer into a Chrome MV3 extension.
packages/core: TypeScript library and CLI packagetexpatch.packages/extension: Chrome MV3 extension that bundles the core transformer.packages/clip: local clipboard helper.tools: validation and development utilities.docs: design log, validation policy, and extension release notes.
npm install
npm --workspace packages/core run buildnode packages/core/dist/bin/texpatch.js --profile katex < input.md > output.mdProfiles:
katex: default strict web/Obsidian-oriented cleanup.mathjax: alias ofkatexfor now; use validation gates to check MathJax compatibility.pandoc: skips rules that are too renderer-specific for LaTeX/Pandoc output.github: fences display math aslatexcode blocks.
For serious documents, do not trust transform output until it passes the gates:
npm run validate:katex -- output.md
npm run validate:mathjax -- output.mdThe gates check for:
- leftover bracket math blocks;
- bare TeX commands outside math spans;
- malformed standalone equality separators;
- KaTeX parse failures;
- MathJax error nodes.
KaTeX is stricter and catches many syntax errors early. MathJax is closer to Obsidian's rendering family and catches compatibility failures that appear as MathJax error nodes. Use both for high-value documents.
Build:
npm run build:extLoad unpacked:
- Open Chrome Extensions.
- Enable Developer mode.
- Load
packages/extension.
Package:
EXT_VERSION=v0.1.1 bash scripts/pack-extension.shThe extension uses the same core rules as the CLI. It should remain a thin UI over tested deterministic rules; rule discovery and corpus validation should happen in the repo, not inside the extension.
Recommended workflow for a new failure:
node packages/core/dist/bin/texpatch.js < sample.in.md > /tmp/sample.out.md
npm run validate:katex -- /tmp/sample.out.md
npm run validate:mathjax -- /tmp/sample.out.mdThen add a focused golden fixture under tests/golden/ and update the transformer only as narrowly as the failure requires.
Core checks:
npm --workspace packages/core run golden
npm --workspace packages/core run idempotence
npm --workspace packages/core run profiles
npm run typecheck
npm run build:ext- Core release is handled through GitHub releases and npm publishing.
- Extension release builds a version-stamped zip artifact; Chrome Web Store submission is manual.
- See docs/extension.md for the extension workflow.