🎨 color-math (Python)
Pure Python semantic LaTeX and MathJax colorizer for Obsidian Markdown notes, KaTeX documents, and scientific workflows. Zero dependencies.
python-color-math is a fast, standalone command-line tool and Python library that automatically parses LaTeX and MathJax expressions and wraps elements in semantic \textcolor{...}{...} annotations. It works across plain Markdown, Obsidian notes, Quarto documents, Jupyter notebooks, and raw LaTeX files without modifying surrounding prose or code blocks.
[!NOTE] Looking for the Obsidian Plugin? Check out obsidian-color-math for real-time live preview math coloring directly inside Obsidian!
✨ Features
- Zero External Dependencies: Runs entirely on the Python Standard Library (Python 3.10+).
- Physical Units & Metric Prefixes: Distinguishes units (
\mu m,m/s,nm,kg) from variables, shielding algebraic variables like $m$ in $F = ma$ or $E = mc^2$. - Calculus Differentials & Derivatives: Recognizes infinitesimal differentials ($dx$, $dt$, $d\theta$) and derivative fractions ($\frac{d}{dx}$, $\frac{\partial \psi}{\partial t}$), while preserving standalone distance $d$ and relations like $d\iff e$.
- Dirac Quantum Bra-Ket Notation: Formats kets ($|\psi\rangle$), bras ($\langle\phi|$), and expectation values ($\langle\phi|\hat{H}|\psi\rangle$) while protecting absolute values ($|x| < 5$).
- Dimensionless Numbers: Identifies contiguous engineering numbers ($Re$, $Ma$, $Pr$, $Nu$) without capturing separated variables ($R,e$).
- Rainbow Delimiters: Stack-based delimiter matching that colors nested parentheses, brackets, and braces by nesting depth.
- Mathematical Symbol Taxonomy: Categorizes constants ($\pi, \hbar, \infty$), Greek parameters ($\alpha, \theta, \lambda$), functions ($\sin, \cos, \ln$), and bound summation/limit indices.
- Variable Data-Flow Hashing: Deterministically hashes identifiers across an equation so each unique variable maintains a consistent color across terms.
- Boxed Equations: Preserves
\boxed{...}wrappers while coloring internal mathematical structures. - Signature Tokyo Night Palette: Muted pastel tones calibrated for readability and reduced eye strain.
- Markdown & TeX Safety: Fenced code blocks, inline code, TeX comments, and
\verbblocks are protected and left unmodified. - Lossless & Reversible: Includes a
--undocommand to cleanly strip all injected colors back to original LaTeX notation.
🚀 Installation
Install from PyPI:
pip install python-color-math
Or install from source:
git clone https://github.com/36ty-blip/python-color-math.git
cd python-color-math
pip install .
💻 CLI Usage
Process a Markdown or LaTeX file
# Colorize equations in a single note
color-math note.md
# Colorize an entire directory of notes recursively
color-math ./vault/
# Preview changes without modifying files (Dry Run)
color-math --dry-run note.md
# Revert and clean colors back to plain LaTeX
color-math --undo note.md
Stdin / Pipe Support
Pipe equations directly through the CLI:
echo "$$\frac{d}{dx}f(g(x)) = f'(g(x)) \cdot g'(x)$$" | color-math
🐍 Python API
Use color-math directly as a library in your Python applications, scripts, or data pipelines:
from color_math import colorize_latex, ColorMathOptions
latex = r"\frac{d}{dx}f(g(x)) = f'(g(x)) \cdot g'(x)"
# Basic coloring with default Tokyo Night palette
colored = colorize_latex(latex)
print(colored)
# Enable extended features (Rainbow delimiters, Variable hashing, etc.)
opts = ColorMathOptions.all_enabled()
extended_colored = colorize_latex(latex, options=opts)
🧪 Testing
Run the comprehensive test suites (51 tests):
# Run feature test suite
python -m unittest discover tests
# Run regression self-test suite
python -m tests.self_test
📄 License
MIT License. See LICENSE for details.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python_color_math-0.1.0.tar.gz.
File metadata
- Download URL: python_color_math-0.1.0.tar.gz
- Upload date:
- Size: 45.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a0e137ca40c095f53d2fc4bd672126e97c7f290810039a626349d4beeda5be1d
|
|
| MD5 |
1ae157b84d558f83f1531c75b1963193
|
|
| BLAKE2b-256 |
ca6554256bf4bb3d3a3464163f410aa64e0575403a11c5c80fea14a59b09ed4c
|
Provenance
The following attestation bundles were made for python_color_math-0.1.0.tar.gz:
Publisher:
publish-pypi.yml on 36ty-blip/python-color-math
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
python_color_math-0.1.0.tar.gz -
Subject digest:
a0e137ca40c095f53d2fc4bd672126e97c7f290810039a626349d4beeda5be1d - Sigstore transparency entry: 2752552964
- Sigstore integration time:
-
Permalink:
36ty-blip/python-color-math@8f81739aba4fa977c03e8254819758d0fd8ebbd5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/36ty-blip
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@8f81739aba4fa977c03e8254819758d0fd8ebbd5 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file python_color_math-0.1.0-py3-none-any.whl.
File metadata
- Download URL: python_color_math-0.1.0-py3-none-any.whl
- Upload date:
- Size: 54.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f716ad870fd9c9a34cf3ba9301da116b9e5c2717c95f6f551544cb8bffcb4f77
|
|
| MD5 |
f468b7cf73d6943e4774a20c4940c69d
|
|
| BLAKE2b-256 |
079aa16cd69bf6e60a544a574f4a3b94691b491da858fd2094fb4e9c679319fe
|
Provenance
The following attestation bundles were made for python_color_math-0.1.0-py3-none-any.whl:
Publisher:
publish-pypi.yml on 36ty-blip/python-color-math
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
python_color_math-0.1.0-py3-none-any.whl -
Subject digest:
f716ad870fd9c9a34cf3ba9301da116b9e5c2717c95f6f551544cb8bffcb4f77 - Sigstore transparency entry: 2752552981
- Sigstore integration time:
-
Permalink:
36ty-blip/python-color-math@8f81739aba4fa977c03e8254819758d0fd8ebbd5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/36ty-blip
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@8f81739aba4fa977c03e8254819758d0fd8ebbd5 -
Trigger Event:
workflow_dispatch
-
Statement type: