Skip to main content

🎨 color-math (Python)

Pure Python semantic LaTeX and MathJax colorizer for Obsidian Markdown notes, KaTeX documents, and scientific workflows. Zero dependencies.

CI PyPI License: MIT Python: 3.10+

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 \verb blocks are protected and left unmodified.
  • Lossless & Reversible: Includes a --undo command 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

python_color_math-0.1.0.tar.gz (45.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_color_math-0.1.0-py3-none-any.whl (54.6 kB view details)

Uploaded Python 3

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

Hashes for python_color_math-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a0e137ca40c095f53d2fc4bd672126e97c7f290810039a626349d4beeda5be1d
MD5 1ae157b84d558f83f1531c75b1963193
BLAKE2b-256 ca6554256bf4bb3d3a3464163f410aa64e0575403a11c5c80fea14a59b09ed4c

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file python_color_math-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for python_color_math-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f716ad870fd9c9a34cf3ba9301da116b9e5c2717c95f6f551544cb8bffcb4f77
MD5 f468b7cf73d6943e4774a20c4940c69d
BLAKE2b-256 079aa16cd69bf6e60a544a574f4a3b94691b491da858fd2094fb4e9c679319fe

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page