python-color-math 0.2.2__tar.gz → 0.2.13__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python_color_math-0.2.2/python_color_math.egg-info → python_color_math-0.2.13}/PKG-INFO +104 -5
- {python_color_math-0.2.2 → python_color_math-0.2.13}/README.md +96 -4
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/__init__.py +7 -1
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/adapters.py +35 -2
- python_color_math-0.2.13/color_math/colormath.default.json +57 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/config.py +184 -40
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/converters/block.py +5 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/converters/derivative.py +21 -4
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/converters/generic.py +15 -1
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/converters/matrix.py +3 -3
- python_color_math-0.2.13/color_math/converters/unicode_converter.py +279 -0
- python_color_math-0.2.13/color_math/custom_definitions.py +100 -0
- python_color_math-0.2.13/color_math/ipython.py +183 -0
- python_color_math-0.2.13/color_math/jupyter.py +99 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/main.py +114 -25
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/parsers/__init__.py +11 -1
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/parsers/braket.py +43 -9
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/parsers/constants.py +2 -2
- python_color_math-0.2.13/color_math/parsers/delimiters.py +350 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/parsers/differentials.py +4 -4
- python_color_math-0.2.13/color_math/parsers/frontmatter.py +168 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/parsers/markdown_scanner.py +16 -4
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/parsers/math_parser.py +2 -2
- python_color_math-0.2.13/color_math/parsers/physics.py +44 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/parsers/taxonomy.py +13 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/parsers/units.py +15 -9
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/parsers/variable_hash.py +4 -4
- python_color_math-0.2.13/color_math/tutorial.py +420 -0
- python_color_math-0.2.13/color_math/unicode.py +217 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/pyproject.toml +4 -2
- {python_color_math-0.2.2 → python_color_math-0.2.13/python_color_math.egg-info}/PKG-INFO +104 -5
- {python_color_math-0.2.2 → python_color_math-0.2.13}/python_color_math.egg-info/SOURCES.txt +17 -1
- python_color_math-0.2.13/python_color_math.egg-info/requires.txt +12 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/tests/test_cli.py +74 -3
- python_color_math-0.2.13/tests/test_config_tolerance.py +76 -0
- python_color_math-0.2.13/tests/test_custom_definitions.py +44 -0
- python_color_math-0.2.13/tests/test_extreme_adversarial.py +281 -0
- python_color_math-0.2.13/tests/test_features.py +784 -0
- python_color_math-0.2.13/tests/test_frontmatter.py +79 -0
- python_color_math-0.2.13/tests/test_ipython.py +89 -0
- python_color_math-0.2.13/tests/test_physics.py +72 -0
- python_color_math-0.2.13/tests/test_unicode.py +36 -0
- python_color_math-0.2.13/tests/test_unicode_converter.py +115 -0
- python_color_math-0.2.2/color_math/parsers/delimiters.py +0 -151
- python_color_math-0.2.2/color_math/tutorial.py +0 -183
- python_color_math-0.2.2/python_color_math.egg-info/requires.txt +0 -3
- python_color_math-0.2.2/tests/test_features.py +0 -363
- {python_color_math-0.2.2 → python_color_math-0.2.13}/.pre-commit-hooks.yaml +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/LICENSE +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/MANIFEST.in +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/__main__.py +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/completions.py +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/converters/__init__.py +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/converters/align.py +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/converters/equation.py +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/converters/integral.py +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/converters/limit.py +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/converters/semantic.py +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/gui.py +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/io.py +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/mcp.py +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/mcp_server.py +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/parsers/alignment.py +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/parsers/dimensionless.py +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/parsers/latex_spans.py +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/parsers/scanner.py +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/py.typed +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/self_test.py +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/undo.py +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/utils/__init__.py +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/utils/coloring.py +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/utils/latex_helpers.py +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/color_math/utils/spans.py +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/python_color_math/__init__.py +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/python_color_math/__main__.py +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/python_color_math.egg-info/dependency_links.txt +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/python_color_math.egg-info/entry_points.txt +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/python_color_math.egg-info/top_level.txt +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/setup.cfg +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/tests/test_adversarial.py +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/tests/test_fuzz.py +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/tests/test_gui.py +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/tests/test_mcp_hardcore.py +0 -0
- {python_color_math-0.2.2 → python_color_math-0.2.13}/tests/test_mcp_server.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-color-math
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.13
|
|
4
4
|
Summary: A fast, local semantic LaTeX colorizer for Markdown, Jupyter, and LaTeX math equations.
|
|
5
5
|
Author: Aditya
|
|
6
6
|
License: MIT License
|
|
@@ -53,6 +53,13 @@ Description-Content-Type: text/markdown
|
|
|
53
53
|
License-File: LICENSE
|
|
54
54
|
Provides-Extra: mcp
|
|
55
55
|
Requires-Dist: mcp>=1.0.0; extra == "mcp"
|
|
56
|
+
Provides-Extra: tutorial
|
|
57
|
+
Requires-Dist: rich>=13.0.0; extra == "tutorial"
|
|
58
|
+
Requires-Dist: questionary>=2.0.0; extra == "tutorial"
|
|
59
|
+
Provides-Extra: all
|
|
60
|
+
Requires-Dist: mcp>=1.0.0; extra == "all"
|
|
61
|
+
Requires-Dist: rich>=13.0.0; extra == "all"
|
|
62
|
+
Requires-Dist: questionary>=2.0.0; extra == "all"
|
|
56
63
|
Dynamic: license-file
|
|
57
64
|
|
|
58
65
|
# 🎨 Python Color Math
|
|
@@ -83,26 +90,36 @@ $$ \frac{d}{dx}\textcolor{#7aa2f7}{f(g(y))} \textcolor{white}{=} \textcolor{#bb9
|
|
|
83
90
|
|
|
84
91
|
```bash
|
|
85
92
|
pip install python-color-math
|
|
93
|
+
|
|
94
|
+
# Or with interactive arrow-key tutorial & rich panels:
|
|
95
|
+
pip install "python-color-math[tutorial]"
|
|
96
|
+
|
|
97
|
+
# Or with native AI Model Context Protocol (MCP) server support:
|
|
98
|
+
pip install "python-color-math[mcp]"
|
|
99
|
+
|
|
100
|
+
# Or everything:
|
|
101
|
+
pip install "python-color-math[all]"
|
|
86
102
|
```
|
|
87
103
|
|
|
88
|
-
*(Or locally from cloned source: `pip install -e .`)*
|
|
104
|
+
*(Or locally from cloned source: `pip install -e .` or `pip install -e ".[tutorial]"`, `pip install -e ".[all]"`)*
|
|
89
105
|
|
|
90
106
|
> [!TIP]
|
|
91
107
|
> **Commands & PATH**:
|
|
92
|
-
> - Registers
|
|
108
|
+
> - Registers **`color-math`**, **`python-color-math`**, and the dedicated MCP server binary **`color-math-mcp`**.
|
|
93
109
|
> - If Python's `Scripts/` folder is not on your `PATH`, run directly via Python without touching environment variables:
|
|
94
|
-
> `python -m color_math [options]` *(or `python -m
|
|
110
|
+
> `python -m color_math [options]` *(or `python -m color_math.mcp`)*.
|
|
95
111
|
> - *Linux users*: Python's standard GUI library is available via `sudo apt install python3-tk`.
|
|
96
112
|
|
|
97
113
|
---
|
|
98
114
|
|
|
99
|
-
## ⚡
|
|
115
|
+
## ⚡ Four Ways to Use
|
|
100
116
|
|
|
101
117
|
### 1. 🎓 Interactive Terminal Tutorial
|
|
102
118
|
New to Color Math? Take the 2-minute paced CLI tour with live examples:
|
|
103
119
|
```bash
|
|
104
120
|
color-math --tutorial
|
|
105
121
|
```
|
|
122
|
+
*(Runs out of the box with zero dependencies. Install `python-color-math[tutorial]` to unlock arrow-key menus, Rich panels, an interactive LaTeX sandbox, and live theme inspection!)*
|
|
106
123
|
|
|
107
124
|
### 2. 🖥️ Graphical Pop-up Window (GUI)
|
|
108
125
|
Prefer visual controls? Launch the native High-DPI pop-up window:
|
|
@@ -137,6 +154,15 @@ cat note.md | color-math -
|
|
|
137
154
|
color-math note.md --diff
|
|
138
155
|
```
|
|
139
156
|
|
|
157
|
+
### 4. 🤖 AI Agent Model Context Protocol (MCP)
|
|
158
|
+
Empower local AI assistants (Claude Desktop, Cursor, Antigravity) to semantically format and inspect LaTeX equations:
|
|
159
|
+
```bash
|
|
160
|
+
# Run stdio MCP server directly:
|
|
161
|
+
color-math-mcp
|
|
162
|
+
# or:
|
|
163
|
+
color-math --mcp
|
|
164
|
+
```
|
|
165
|
+
|
|
140
166
|
---
|
|
141
167
|
|
|
142
168
|
## 📋 Cheat Sheet (Command Reference)
|
|
@@ -155,6 +181,7 @@ color-math note.md --diff
|
|
|
155
181
|
| **Curated Themes** | `color-math note.md --theme catppuccin -w` | Select `default`, `catppuccin`, `nord`, or `light` |
|
|
156
182
|
| **Feature Preset** | `color-math note.md --preset minimal -w` | Presets: `all` (default), `minimal` |
|
|
157
183
|
| **Custom Colors** | `color-math note.md -c unit=#73daca -w` | Override any of 12 individual color roles |
|
|
184
|
+
| **AI MCP Server** | `color-math-mcp` *(or `--mcp`)* | Launch Model Context Protocol server over stdio |
|
|
158
185
|
| **Reset Palette** | `color-math --reset-colors` | Restore factory Tokyo Night palette |
|
|
159
186
|
| **Inspect Colors** | `color-math --show-colors` | Display palette, descriptions, & terminal swatches |
|
|
160
187
|
| **Undo / Strip** | `color-math note.md --undo -w` | Strip color wrappers back to plain LaTeX |
|
|
@@ -166,6 +193,9 @@ color-math note.md --diff
|
|
|
166
193
|
|
|
167
194
|
Control recognition features with `--preset {all,minimal}` (default: `all`) or individual flags:
|
|
168
195
|
|
|
196
|
+
- **Piecewise Environments (`\begin{cases}`)**: Full structural recognition of cases with multi-branch alignment (`&`), inequalities, and relations (`\ge`, `\le`, `\ne`, `<`, `>`).
|
|
197
|
+
- **Inline & Display Math**: Accurately colors both display blocks (`$$...$$`) and inline expressions (`$...$`) while strictly protecting code fences and raw backticks.
|
|
198
|
+
- **Half-Colored Auto-Completion**: Partially colored equations are automatically cleaned and re-colorized end-to-end rather than skipped.
|
|
169
199
|
- **Calculus Differentials (`--differentials`)**: Disambiguates `dx`, `dt`, `d\theta`, and derivatives (`\frac{d}{dx}`, `\frac{\partial \psi}{\partial t}`) while leaving standalone distance variables `$d$` untouched.
|
|
170
200
|
- **Physical Units (`--units`)**: Recognizes metric prefixes and unit compounds (`\mu m`, `m/s`, `kg`, `nm`).
|
|
171
201
|
- **Rainbow Delimiters (`--rainbow-delimiters`)**: Recursively colors nested brackets `()`, `[]`, `{}` by depth to eliminate delimiter blindness.
|
|
@@ -225,6 +255,75 @@ Add-Content $PROFILE "`ncolor-math --generate-completion powershell | Out-String
|
|
|
225
255
|
|
|
226
256
|
---
|
|
227
257
|
|
|
258
|
+
## 🤖 Model Context Protocol (MCP) Server
|
|
259
|
+
|
|
260
|
+
`python-color-math` includes a native Model Context Protocol (MCP) server that empowers AI assistants (**Claude Desktop**, **Cursor**, **Antigravity**, and any MCP client) to format, inspect, colorize, and uncolor LaTeX documents.
|
|
261
|
+
|
|
262
|
+
### Install MCP Extra
|
|
263
|
+
```bash
|
|
264
|
+
pip install "python-color-math[mcp]"
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### Direct Execution
|
|
268
|
+
```bash
|
|
269
|
+
# Default stdio transport
|
|
270
|
+
color-math-mcp
|
|
271
|
+
|
|
272
|
+
# Or via the main CLI / module:
|
|
273
|
+
color-math --mcp
|
|
274
|
+
python -m color_math.mcp
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### Client Configuration
|
|
278
|
+
|
|
279
|
+
Add to your assistant's MCP configuration:
|
|
280
|
+
|
|
281
|
+
#### Claude Desktop (`claude_desktop_config.json`)
|
|
282
|
+
```json
|
|
283
|
+
{
|
|
284
|
+
"mcpServers": {
|
|
285
|
+
"color-math": {
|
|
286
|
+
"command": "color-math-mcp"
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
#### Cursor (`.cursor/mcp.json`)
|
|
293
|
+
```json
|
|
294
|
+
{
|
|
295
|
+
"mcpServers": {
|
|
296
|
+
"color-math": {
|
|
297
|
+
"command": "color-math-mcp"
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
#### Antigravity / Gemini CLI (`mcp_config.json`)
|
|
304
|
+
```json
|
|
305
|
+
{
|
|
306
|
+
"mcpServers": {
|
|
307
|
+
"python-color-math": {
|
|
308
|
+
"command": "python",
|
|
309
|
+
"args": ["-m", "color_math.mcp"]
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
### Available MCP Tools
|
|
316
|
+
| Tool | Description |
|
|
317
|
+
| :--- | :--- |
|
|
318
|
+
| `colorize_math_expression` | Colorizes an individual LaTeX string (e.g. `\frac{d}{dx}f(x) = f'(x)`). |
|
|
319
|
+
| `colorize_text` | Parses and colorizes all equations (`$...$` and `$$...$$`) inside a Markdown, LaTeX, or Jupyter document. |
|
|
320
|
+
| `uncolor_text` | Losslessly removes color tags, restoring clean plain LaTeX. |
|
|
321
|
+
| `process_file` | Colorizes or uncolors files on disk in-place (`in_place=True`) or performs a safe dry-run returning a diff. |
|
|
322
|
+
| `scan_vault` | Recursively scans an entire folder/vault to report math blocks and batch-colorize/uncolor notes. |
|
|
323
|
+
| `list_themes_and_config` | Discovers available themes (Tokyo Night, Catppuccin, Nord, Light) and semantic color mappings. |
|
|
324
|
+
|
|
325
|
+
---
|
|
326
|
+
|
|
228
327
|
## 🪝 Pre-commit Integration
|
|
229
328
|
|
|
230
329
|
Integrate `color-math` into your git workflow using [pre-commit](https://pre-commit.com):
|
|
@@ -26,26 +26,36 @@ $$ \frac{d}{dx}\textcolor{#7aa2f7}{f(g(y))} \textcolor{white}{=} \textcolor{#bb9
|
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
28
|
pip install python-color-math
|
|
29
|
+
|
|
30
|
+
# Or with interactive arrow-key tutorial & rich panels:
|
|
31
|
+
pip install "python-color-math[tutorial]"
|
|
32
|
+
|
|
33
|
+
# Or with native AI Model Context Protocol (MCP) server support:
|
|
34
|
+
pip install "python-color-math[mcp]"
|
|
35
|
+
|
|
36
|
+
# Or everything:
|
|
37
|
+
pip install "python-color-math[all]"
|
|
29
38
|
```
|
|
30
39
|
|
|
31
|
-
*(Or locally from cloned source: `pip install -e .`)*
|
|
40
|
+
*(Or locally from cloned source: `pip install -e .` or `pip install -e ".[tutorial]"`, `pip install -e ".[all]"`)*
|
|
32
41
|
|
|
33
42
|
> [!TIP]
|
|
34
43
|
> **Commands & PATH**:
|
|
35
|
-
> - Registers
|
|
44
|
+
> - Registers **`color-math`**, **`python-color-math`**, and the dedicated MCP server binary **`color-math-mcp`**.
|
|
36
45
|
> - If Python's `Scripts/` folder is not on your `PATH`, run directly via Python without touching environment variables:
|
|
37
|
-
> `python -m color_math [options]` *(or `python -m
|
|
46
|
+
> `python -m color_math [options]` *(or `python -m color_math.mcp`)*.
|
|
38
47
|
> - *Linux users*: Python's standard GUI library is available via `sudo apt install python3-tk`.
|
|
39
48
|
|
|
40
49
|
---
|
|
41
50
|
|
|
42
|
-
## ⚡
|
|
51
|
+
## ⚡ Four Ways to Use
|
|
43
52
|
|
|
44
53
|
### 1. 🎓 Interactive Terminal Tutorial
|
|
45
54
|
New to Color Math? Take the 2-minute paced CLI tour with live examples:
|
|
46
55
|
```bash
|
|
47
56
|
color-math --tutorial
|
|
48
57
|
```
|
|
58
|
+
*(Runs out of the box with zero dependencies. Install `python-color-math[tutorial]` to unlock arrow-key menus, Rich panels, an interactive LaTeX sandbox, and live theme inspection!)*
|
|
49
59
|
|
|
50
60
|
### 2. 🖥️ Graphical Pop-up Window (GUI)
|
|
51
61
|
Prefer visual controls? Launch the native High-DPI pop-up window:
|
|
@@ -80,6 +90,15 @@ cat note.md | color-math -
|
|
|
80
90
|
color-math note.md --diff
|
|
81
91
|
```
|
|
82
92
|
|
|
93
|
+
### 4. 🤖 AI Agent Model Context Protocol (MCP)
|
|
94
|
+
Empower local AI assistants (Claude Desktop, Cursor, Antigravity) to semantically format and inspect LaTeX equations:
|
|
95
|
+
```bash
|
|
96
|
+
# Run stdio MCP server directly:
|
|
97
|
+
color-math-mcp
|
|
98
|
+
# or:
|
|
99
|
+
color-math --mcp
|
|
100
|
+
```
|
|
101
|
+
|
|
83
102
|
---
|
|
84
103
|
|
|
85
104
|
## 📋 Cheat Sheet (Command Reference)
|
|
@@ -98,6 +117,7 @@ color-math note.md --diff
|
|
|
98
117
|
| **Curated Themes** | `color-math note.md --theme catppuccin -w` | Select `default`, `catppuccin`, `nord`, or `light` |
|
|
99
118
|
| **Feature Preset** | `color-math note.md --preset minimal -w` | Presets: `all` (default), `minimal` |
|
|
100
119
|
| **Custom Colors** | `color-math note.md -c unit=#73daca -w` | Override any of 12 individual color roles |
|
|
120
|
+
| **AI MCP Server** | `color-math-mcp` *(or `--mcp`)* | Launch Model Context Protocol server over stdio |
|
|
101
121
|
| **Reset Palette** | `color-math --reset-colors` | Restore factory Tokyo Night palette |
|
|
102
122
|
| **Inspect Colors** | `color-math --show-colors` | Display palette, descriptions, & terminal swatches |
|
|
103
123
|
| **Undo / Strip** | `color-math note.md --undo -w` | Strip color wrappers back to plain LaTeX |
|
|
@@ -109,6 +129,9 @@ color-math note.md --diff
|
|
|
109
129
|
|
|
110
130
|
Control recognition features with `--preset {all,minimal}` (default: `all`) or individual flags:
|
|
111
131
|
|
|
132
|
+
- **Piecewise Environments (`\begin{cases}`)**: Full structural recognition of cases with multi-branch alignment (`&`), inequalities, and relations (`\ge`, `\le`, `\ne`, `<`, `>`).
|
|
133
|
+
- **Inline & Display Math**: Accurately colors both display blocks (`$$...$$`) and inline expressions (`$...$`) while strictly protecting code fences and raw backticks.
|
|
134
|
+
- **Half-Colored Auto-Completion**: Partially colored equations are automatically cleaned and re-colorized end-to-end rather than skipped.
|
|
112
135
|
- **Calculus Differentials (`--differentials`)**: Disambiguates `dx`, `dt`, `d\theta`, and derivatives (`\frac{d}{dx}`, `\frac{\partial \psi}{\partial t}`) while leaving standalone distance variables `$d$` untouched.
|
|
113
136
|
- **Physical Units (`--units`)**: Recognizes metric prefixes and unit compounds (`\mu m`, `m/s`, `kg`, `nm`).
|
|
114
137
|
- **Rainbow Delimiters (`--rainbow-delimiters`)**: Recursively colors nested brackets `()`, `[]`, `{}` by depth to eliminate delimiter blindness.
|
|
@@ -168,6 +191,75 @@ Add-Content $PROFILE "`ncolor-math --generate-completion powershell | Out-String
|
|
|
168
191
|
|
|
169
192
|
---
|
|
170
193
|
|
|
194
|
+
## 🤖 Model Context Protocol (MCP) Server
|
|
195
|
+
|
|
196
|
+
`python-color-math` includes a native Model Context Protocol (MCP) server that empowers AI assistants (**Claude Desktop**, **Cursor**, **Antigravity**, and any MCP client) to format, inspect, colorize, and uncolor LaTeX documents.
|
|
197
|
+
|
|
198
|
+
### Install MCP Extra
|
|
199
|
+
```bash
|
|
200
|
+
pip install "python-color-math[mcp]"
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Direct Execution
|
|
204
|
+
```bash
|
|
205
|
+
# Default stdio transport
|
|
206
|
+
color-math-mcp
|
|
207
|
+
|
|
208
|
+
# Or via the main CLI / module:
|
|
209
|
+
color-math --mcp
|
|
210
|
+
python -m color_math.mcp
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### Client Configuration
|
|
214
|
+
|
|
215
|
+
Add to your assistant's MCP configuration:
|
|
216
|
+
|
|
217
|
+
#### Claude Desktop (`claude_desktop_config.json`)
|
|
218
|
+
```json
|
|
219
|
+
{
|
|
220
|
+
"mcpServers": {
|
|
221
|
+
"color-math": {
|
|
222
|
+
"command": "color-math-mcp"
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
#### Cursor (`.cursor/mcp.json`)
|
|
229
|
+
```json
|
|
230
|
+
{
|
|
231
|
+
"mcpServers": {
|
|
232
|
+
"color-math": {
|
|
233
|
+
"command": "color-math-mcp"
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
#### Antigravity / Gemini CLI (`mcp_config.json`)
|
|
240
|
+
```json
|
|
241
|
+
{
|
|
242
|
+
"mcpServers": {
|
|
243
|
+
"python-color-math": {
|
|
244
|
+
"command": "python",
|
|
245
|
+
"args": ["-m", "color_math.mcp"]
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### Available MCP Tools
|
|
252
|
+
| Tool | Description |
|
|
253
|
+
| :--- | :--- |
|
|
254
|
+
| `colorize_math_expression` | Colorizes an individual LaTeX string (e.g. `\frac{d}{dx}f(x) = f'(x)`). |
|
|
255
|
+
| `colorize_text` | Parses and colorizes all equations (`$...$` and `$$...$$`) inside a Markdown, LaTeX, or Jupyter document. |
|
|
256
|
+
| `uncolor_text` | Losslessly removes color tags, restoring clean plain LaTeX. |
|
|
257
|
+
| `process_file` | Colorizes or uncolors files on disk in-place (`in_place=True`) or performs a safe dry-run returning a diff. |
|
|
258
|
+
| `scan_vault` | Recursively scans an entire folder/vault to report math blocks and batch-colorize/uncolor notes. |
|
|
259
|
+
| `list_themes_and_config` | Discovers available themes (Tokyo Night, Catppuccin, Nord, Light) and semantic color mappings. |
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
171
263
|
## 🪝 Pre-commit Integration
|
|
172
264
|
|
|
173
265
|
Integrate `color-math` into your git workflow using [pre-commit](https://pre-commit.com):
|
|
@@ -5,13 +5,19 @@ from .config import ColorMathOptions
|
|
|
5
5
|
from .converters.block import convert_text
|
|
6
6
|
from .undo import uncolor_text
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
from .ipython import ColorMath, colormath, load_ipython_extension, unload_ipython_extension
|
|
9
|
+
|
|
10
|
+
__version__ = "0.2.13"
|
|
9
11
|
|
|
10
12
|
__all__ = [
|
|
11
13
|
"__version__",
|
|
14
|
+
"ColorMath",
|
|
12
15
|
"ColorMathOptions",
|
|
16
|
+
"colormath",
|
|
13
17
|
"convert_text",
|
|
14
18
|
"detect_format",
|
|
19
|
+
"load_ipython_extension",
|
|
15
20
|
"transform_document",
|
|
16
21
|
"uncolor_text",
|
|
22
|
+
"unload_ipython_extension",
|
|
17
23
|
]
|
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
import copy
|
|
5
6
|
import json
|
|
6
7
|
import re
|
|
7
8
|
from pathlib import Path
|
|
8
9
|
|
|
9
10
|
from .config import ColorMathOptions
|
|
10
11
|
from .converters.block import convert_math_block, convert_text
|
|
12
|
+
from .parsers.frontmatter import detect_note_field
|
|
11
13
|
from .undo import uncolor_fragment, uncolor_text
|
|
12
14
|
from .utils.latex_helpers import read_comment_end, read_verb_end
|
|
13
15
|
|
|
@@ -50,6 +52,19 @@ def detect_format(path: Path | None, requested: str = "auto") -> str:
|
|
|
50
52
|
return "markdown"
|
|
51
53
|
|
|
52
54
|
|
|
55
|
+
def has_potential_math(text: str, format_name: str = "auto") -> bool:
|
|
56
|
+
"""Ultra-fast probe to bypass documents that cannot possibly contain math."""
|
|
57
|
+
if "$" in text:
|
|
58
|
+
return True
|
|
59
|
+
if r"\[" in text or r"\(" in text:
|
|
60
|
+
return True
|
|
61
|
+
if format_name in ("tex", "auto") and r"\begin{" in text:
|
|
62
|
+
return True
|
|
63
|
+
if format_name in ("anki", "auto") and ("[$]" in text or "[$$]" in text):
|
|
64
|
+
return True
|
|
65
|
+
return False
|
|
66
|
+
|
|
67
|
+
|
|
53
68
|
def transform_document(
|
|
54
69
|
text: str,
|
|
55
70
|
format_name: str,
|
|
@@ -57,10 +72,28 @@ def transform_document(
|
|
|
57
72
|
palette: dict[str, str] | None = None,
|
|
58
73
|
options: ColorMathOptions | None = None,
|
|
59
74
|
) -> str:
|
|
60
|
-
if format_name == "markdown":
|
|
61
|
-
return uncolor_text(text) if undo else convert_text(text, palette=palette, options=options)
|
|
62
75
|
if format_name == "jupyter":
|
|
63
76
|
return _transform_notebook(text, undo, palette=palette, options=options)
|
|
77
|
+
|
|
78
|
+
if undo:
|
|
79
|
+
if r"\textcolor" not in text:
|
|
80
|
+
return text
|
|
81
|
+
elif not has_potential_math(text, format_name):
|
|
82
|
+
return text
|
|
83
|
+
|
|
84
|
+
if format_name == "markdown":
|
|
85
|
+
if undo:
|
|
86
|
+
return uncolor_text(text)
|
|
87
|
+
opts = options
|
|
88
|
+
detection = detect_note_field(text)
|
|
89
|
+
if detection.is_quantum:
|
|
90
|
+
if opts is None:
|
|
91
|
+
opts = ColorMathOptions(color_quantum_operators=True, field="quantum")
|
|
92
|
+
else:
|
|
93
|
+
opts = copy.copy(opts)
|
|
94
|
+
opts.color_quantum_operators = True
|
|
95
|
+
opts.field = "quantum"
|
|
96
|
+
return convert_text(text, palette=palette, options=opts)
|
|
64
97
|
if format_name == "anki":
|
|
65
98
|
return _transform_delimited(text, ANKI_DELIMITERS, undo, palette=palette, options=options)
|
|
66
99
|
if format_name == "tex":
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_comment": "Python Color Math factory default configuration. This file serves as an immutable reference. To customize settings, edit '.colormath.json'. If '.colormath.json' has syntax errors or missing keys, Color Math safely falls back to these defaults.",
|
|
3
|
+
"theme": "default",
|
|
4
|
+
"colors": {
|
|
5
|
+
"main": "#7aa2f7",
|
|
6
|
+
"orange": "#e0af68",
|
|
7
|
+
"dot": "white",
|
|
8
|
+
"derivative": "#bb9af7",
|
|
9
|
+
"chain": "#9ece6a",
|
|
10
|
+
"upper": "#bb9af7",
|
|
11
|
+
"relation": "white",
|
|
12
|
+
"arrow": "#f7768e",
|
|
13
|
+
"set": "#bb9af7",
|
|
14
|
+
"spacing": "white",
|
|
15
|
+
"parameter": "#bb9af7",
|
|
16
|
+
"unit": "#73daca"
|
|
17
|
+
},
|
|
18
|
+
"options": {
|
|
19
|
+
"enable_taxonomy": true,
|
|
20
|
+
"rainbow_delimiters": true,
|
|
21
|
+
"variable_data_flow": false,
|
|
22
|
+
"color_units": true,
|
|
23
|
+
"color_differentials": true,
|
|
24
|
+
"color_braket": true,
|
|
25
|
+
"color_dimensionless": true,
|
|
26
|
+
"rainbow_bare_braces": false,
|
|
27
|
+
"highlight_unmatched_braces": false
|
|
28
|
+
},
|
|
29
|
+
"unicode": {
|
|
30
|
+
"greek_style": "plane1",
|
|
31
|
+
"convert_definite_integrals": false,
|
|
32
|
+
"convert_bounded_operators": false,
|
|
33
|
+
"convert_prose_to_unicode": false,
|
|
34
|
+
"convert_prose_to_latex": false
|
|
35
|
+
},
|
|
36
|
+
"_role_descriptions": {
|
|
37
|
+
"main": "Primary functions, terms, and outermost operations (e.g. f(x))",
|
|
38
|
+
"derivative": "Derivative marks and differentiated functions (e.g. f'(x))",
|
|
39
|
+
"chain": "Chain rule factors, inner differential stages (e.g. g'(x), y')",
|
|
40
|
+
"orange": "Big operators, sums, integrals, and limits (e.g. \\sum, \\int, \\lim)",
|
|
41
|
+
"dot": "Multiplication symbols, dots, and cross products (e.g. \\cdot, \\times)",
|
|
42
|
+
"relation": "Equals, inequalities, and comparison symbols (e.g. =, <, \\le)",
|
|
43
|
+
"arrow": "Implication and mapping arrows (e.g. \\to, \\implies)",
|
|
44
|
+
"set": "Set theory relations and operators (e.g. \\in, \\subset)",
|
|
45
|
+
"spacing": "LaTeX spacing and alignment commands (e.g. \\quad, \\,)",
|
|
46
|
+
"upper": "Matrix exponents, transposes, and top indices (e.g. A^T, M^{-1})",
|
|
47
|
+
"parameter": "Inner function parameters and indexed variables",
|
|
48
|
+
"unit": "Physical units and dimensions (e.g. m/s, \\mu m, ^\\circ C)"
|
|
49
|
+
},
|
|
50
|
+
"_unicode_descriptions": {
|
|
51
|
+
"greek_style": "Greek letter typography: 'plane1' (Mathematical Italic: 𝝍, 𝝰) or 'standard' (ψ, α)",
|
|
52
|
+
"convert_definite_integrals": "Convert bounded integrals like \\int_a^b to ∫_a^b (default: false to preserve vertical TeX limits)",
|
|
53
|
+
"convert_bounded_operators": "Convert bounded summations/products like \\sum_{i=1}^n to ∑_{i=1}^n (default: false)",
|
|
54
|
+
"convert_prose_to_unicode": "Convert LaTeX commands like \\psi to 𝜓 in regular prose outside math blocks (default: false to protect prose)",
|
|
55
|
+
"convert_prose_to_latex": "Convert Unicode symbols like 𝝍 back to \\psi in regular prose outside math blocks (default: false)"
|
|
56
|
+
}
|
|
57
|
+
}
|