A practical Markdown math cleaner for KaTeX / LaTeX parse errors. It is designed for notes generated by OCR, AI, or copy-paste workflows and fixes many broken math patterns automatically.
Keywords: markdown math, katex parse error, latex cleanup, obsidian math, typora formula, math notes converter
Typical broken input often causes errors like:
Can't use function '$' in math mode- malformed inline math such as
V$f$orf$P$
This project normalizes math-like snippets into safer Markdown math blocks/inline syntax.
Before:
$$
I(S)=$x, y$
$$After:
$$
I(S)=(x, y)
$$Before:
[
k[x_1,\dots,x_n]
]After:
$$
k[x_1, \dots, x_n]
$$- Convert standalone
[ ... ]blocks into$$ ... $$ - Convert selected inline
( ... )expressions into$...$ - Avoid modifying existing
$...$and$$...$$math regions - Reduce over-conversion that leads to KaTeX errors
- Single-file, multi-file, and drag-and-drop workflow on Windows
python tr.py input.md
python tr.py input.md -o output.md
python tr.py a.md b.md c.mdIf no positional input is provided, the script will ask for filenames interactively.
python -m pip install pyinstaller
python -m PyInstaller --onefile tr.pyOutput:
dist\\tr.exe
- Drag one or more
.mdfiles ontodist\\tr.exe - Or drag files onto
convert_drag.bat(it uses EXE first, then falls back to Python)
tr.py: converter logic + CLI entryscripts/build_exe.ps1: PowerShell build helperconvert_drag.bat: drag-and-drop launcher for Windowsdist/: packaged executable output
- Input encoding: UTF-8
- Default output:
<input_stem>_converted.md(same directory) -o/--outputis only valid with a single input file
MIT (see LICENSE)

