python-color-math 0.2.14__tar.gz → 0.2.16__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.
Files changed (80) hide show
  1. {python_color_math-0.2.14/python_color_math.egg-info → python_color_math-0.2.16}/PKG-INFO +1 -1
  2. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/__init__.py +1 -1
  3. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/ipython.py +117 -21
  4. {python_color_math-0.2.14 → python_color_math-0.2.16}/pyproject.toml +1 -1
  5. {python_color_math-0.2.14 → python_color_math-0.2.16/python_color_math.egg-info}/PKG-INFO +1 -1
  6. {python_color_math-0.2.14 → python_color_math-0.2.16}/tests/test_ipython.py +2 -2
  7. {python_color_math-0.2.14 → python_color_math-0.2.16}/.pre-commit-hooks.yaml +0 -0
  8. {python_color_math-0.2.14 → python_color_math-0.2.16}/LICENSE +0 -0
  9. {python_color_math-0.2.14 → python_color_math-0.2.16}/MANIFEST.in +0 -0
  10. {python_color_math-0.2.14 → python_color_math-0.2.16}/README.md +0 -0
  11. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/__main__.py +0 -0
  12. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/adapters.py +0 -0
  13. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/colormath.default.json +0 -0
  14. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/completions.py +0 -0
  15. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/config.py +0 -0
  16. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/converters/__init__.py +0 -0
  17. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/converters/align.py +0 -0
  18. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/converters/block.py +0 -0
  19. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/converters/derivative.py +0 -0
  20. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/converters/equation.py +0 -0
  21. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/converters/generic.py +0 -0
  22. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/converters/integral.py +0 -0
  23. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/converters/limit.py +0 -0
  24. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/converters/matrix.py +0 -0
  25. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/converters/semantic.py +0 -0
  26. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/converters/unicode_converter.py +0 -0
  27. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/custom_definitions.py +0 -0
  28. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/gui.py +0 -0
  29. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/io.py +0 -0
  30. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/jupyter.py +0 -0
  31. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/main.py +0 -0
  32. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/mcp.py +0 -0
  33. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/mcp_server.py +0 -0
  34. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/parsers/__init__.py +0 -0
  35. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/parsers/alignment.py +0 -0
  36. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/parsers/braket.py +0 -0
  37. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/parsers/constants.py +0 -0
  38. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/parsers/delimiters.py +0 -0
  39. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/parsers/differentials.py +0 -0
  40. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/parsers/dimensionless.py +0 -0
  41. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/parsers/frontmatter.py +0 -0
  42. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/parsers/latex_spans.py +0 -0
  43. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/parsers/markdown_scanner.py +0 -0
  44. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/parsers/math_parser.py +0 -0
  45. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/parsers/physics.py +0 -0
  46. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/parsers/scanner.py +0 -0
  47. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/parsers/taxonomy.py +0 -0
  48. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/parsers/units.py +0 -0
  49. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/parsers/variable_hash.py +0 -0
  50. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/py.typed +0 -0
  51. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/self_test.py +0 -0
  52. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/tutorial.py +0 -0
  53. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/undo.py +0 -0
  54. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/unicode.py +0 -0
  55. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/utils/__init__.py +0 -0
  56. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/utils/coloring.py +0 -0
  57. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/utils/latex_helpers.py +0 -0
  58. {python_color_math-0.2.14 → python_color_math-0.2.16}/color_math/utils/spans.py +0 -0
  59. {python_color_math-0.2.14 → python_color_math-0.2.16}/python_color_math/__init__.py +0 -0
  60. {python_color_math-0.2.14 → python_color_math-0.2.16}/python_color_math/__main__.py +0 -0
  61. {python_color_math-0.2.14 → python_color_math-0.2.16}/python_color_math.egg-info/SOURCES.txt +0 -0
  62. {python_color_math-0.2.14 → python_color_math-0.2.16}/python_color_math.egg-info/dependency_links.txt +0 -0
  63. {python_color_math-0.2.14 → python_color_math-0.2.16}/python_color_math.egg-info/entry_points.txt +0 -0
  64. {python_color_math-0.2.14 → python_color_math-0.2.16}/python_color_math.egg-info/requires.txt +0 -0
  65. {python_color_math-0.2.14 → python_color_math-0.2.16}/python_color_math.egg-info/top_level.txt +0 -0
  66. {python_color_math-0.2.14 → python_color_math-0.2.16}/setup.cfg +0 -0
  67. {python_color_math-0.2.14 → python_color_math-0.2.16}/tests/test_adversarial.py +0 -0
  68. {python_color_math-0.2.14 → python_color_math-0.2.16}/tests/test_cli.py +0 -0
  69. {python_color_math-0.2.14 → python_color_math-0.2.16}/tests/test_config_tolerance.py +0 -0
  70. {python_color_math-0.2.14 → python_color_math-0.2.16}/tests/test_custom_definitions.py +0 -0
  71. {python_color_math-0.2.14 → python_color_math-0.2.16}/tests/test_extreme_adversarial.py +0 -0
  72. {python_color_math-0.2.14 → python_color_math-0.2.16}/tests/test_features.py +0 -0
  73. {python_color_math-0.2.14 → python_color_math-0.2.16}/tests/test_frontmatter.py +0 -0
  74. {python_color_math-0.2.14 → python_color_math-0.2.16}/tests/test_fuzz.py +0 -0
  75. {python_color_math-0.2.14 → python_color_math-0.2.16}/tests/test_gui.py +0 -0
  76. {python_color_math-0.2.14 → python_color_math-0.2.16}/tests/test_mcp_hardcore.py +0 -0
  77. {python_color_math-0.2.14 → python_color_math-0.2.16}/tests/test_mcp_server.py +0 -0
  78. {python_color_math-0.2.14 → python_color_math-0.2.16}/tests/test_physics.py +0 -0
  79. {python_color_math-0.2.14 → python_color_math-0.2.16}/tests/test_unicode.py +0 -0
  80. {python_color_math-0.2.14 → python_color_math-0.2.16}/tests/test_unicode_converter.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-color-math
3
- Version: 0.2.14
3
+ Version: 0.2.16
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
@@ -7,7 +7,7 @@ from .undo import uncolor_text
7
7
 
8
8
  from .ipython import ColorMath, colormath, load_ipython_extension, unload_ipython_extension
9
9
 
10
- __version__ = "0.2.14"
10
+ __version__ = "0.2.16"
11
11
 
12
12
  __all__ = [
13
13
  "__version__",
@@ -7,10 +7,17 @@ Notebook, and Google Colab via `%load_ext color_math`.
7
7
  from __future__ import annotations
8
8
 
9
9
  import shlex
10
+ from pathlib import Path
10
11
  from typing import Any
11
12
 
12
13
  from .adapters import transform_document
13
- from .config import ColorMathOptions, THEMES
14
+ from .config import (
15
+ ColorMathOptions,
16
+ THEMES,
17
+ load_config,
18
+ get_global_config_path,
19
+ save_default_config,
20
+ )
14
21
  from .converters.block import convert_math_block, convert_text
15
22
 
16
23
  try:
@@ -37,10 +44,11 @@ def colormath(
37
44
  If is_fragment is True, text is treated as raw math without $ delimiters.
38
45
  """
39
46
  active_palette = THEMES.get(theme) if theme else palette
47
+ opts = options if options is not None else ColorMathOptions.extended()
40
48
  if is_fragment:
41
- converted = convert_math_block(f"$${text}$$", palette=active_palette, options=options)
49
+ converted = convert_math_block(f"$${text}$$", palette=active_palette, options=opts)
42
50
  return converted[2:-2]
43
- return convert_text(text, palette=active_palette, options=options)
51
+ return convert_text(text, palette=active_palette, options=opts)
44
52
 
45
53
 
46
54
  if HAS_IPYTHON:
@@ -68,6 +76,51 @@ if HAS_IPYTHON:
68
76
  super().__init__(shell)
69
77
  self._auto_hook_active = False
70
78
  self._orig_math_repr = None
79
+ palette, options, _ = load_config()
80
+ local_or_global = Path(".colormath.json").exists() or bool(
81
+ get_global_config_path() and get_global_config_path().exists()
82
+ )
83
+ self._palette = palette
84
+ self._options = options if local_or_global else ColorMathOptions.extended()
85
+
86
+ def _parse_magic_args(self, arg_str: str) -> tuple[str | None, ColorMathOptions, str]:
87
+ """Parse leading flags (--theme, -v, --variables) without corrupting LaTeX backslashes."""
88
+ theme = None
89
+ opts = ColorMathOptions(
90
+ enable_taxonomy=self._options.enable_taxonomy,
91
+ rainbow_delimiters=self._options.rainbow_delimiters,
92
+ variable_data_flow=self._options.variable_data_flow,
93
+ color_units=self._options.color_units,
94
+ color_differentials=self._options.color_differentials,
95
+ color_braket=self._options.color_braket,
96
+ color_dimensionless=self._options.color_dimensionless,
97
+ color_alignment=self._options.color_alignment,
98
+ color_single_constants=self._options.color_single_constants,
99
+ normalize_braces=self._options.normalize_braces,
100
+ extended_functions=self._options.extended_functions,
101
+ color_quantum_operators=self._options.color_quantum_operators,
102
+ rainbow_bare_braces=self._options.rainbow_bare_braces,
103
+ highlight_unmatched_braces=self._options.highlight_unmatched_braces,
104
+ field=self._options.field,
105
+ )
106
+ raw = arg_str.strip()
107
+ while raw.startswith("-"):
108
+ if raw.startswith("--theme "):
109
+ parts = raw.split(maxsplit=2)
110
+ theme = parts[1]
111
+ raw = parts[2].strip() if len(parts) > 2 else ""
112
+ elif raw.startswith("--variables") or raw.startswith("-v"):
113
+ opts.variable_data_flow = True
114
+ parts = raw.split(maxsplit=1)
115
+ raw = parts[1].strip() if len(parts) > 1 else ""
116
+ elif raw.startswith("--no-variables") or raw.startswith("-nv"):
117
+ opts.variable_data_flow = False
118
+ parts = raw.split(maxsplit=1)
119
+ raw = parts[1].strip() if len(parts) > 1 else ""
120
+ else:
121
+ break
122
+
123
+ return theme, opts, raw
71
124
 
72
125
  @line_magic("color_math")
73
126
  @line_magic("colormath")
@@ -77,21 +130,14 @@ if HAS_IPYTHON:
77
130
  Usage:
78
131
  %color_math \int_0^1 x^2 dx = \frac{1}{3}
79
132
  %color_math --theme catppuccin \hat{H}\psi = E\psi
133
+ %color_math -v \hat{H}\psi = E\psi
80
134
  """
81
- theme = None
82
- raw_line = line.strip()
83
- if raw_line.startswith("--theme "):
84
- parts = shlex.split(raw_line)
85
- if len(parts) >= 3 and parts[0] == "--theme":
86
- theme = parts[1]
87
- raw_line = " ".join(parts[2:])
88
-
135
+ theme, opts, raw_line = self._parse_magic_args(line)
89
136
  if not raw_line:
90
137
  display(Markdown("*Color Math: please provide a LaTeX expression.*"))
91
138
  return None
92
139
 
93
- # Render as display math
94
- colored = colormath(raw_line, theme=theme, is_fragment=True)
140
+ colored = colormath(raw_line, theme=theme, options=opts, is_fragment=True)
95
141
  return Math(colored)
96
142
 
97
143
  @cell_magic("color_math")
@@ -101,17 +147,67 @@ if HAS_IPYTHON:
101
147
 
102
148
  Usage:
103
149
  %%color_math
104
- Here is the equation:
105
- $$ \frac{df}{dx} = f'(x) $$
106
- """
107
- theme = None
108
- args = shlex.split(line.strip()) if line.strip() else []
109
- if len(args) >= 2 and args[0] == "--theme":
110
- theme = args[1]
150
+ The equation is:
151
+ $$ \hat{H}\psi = E\psi $$
111
152
 
112
- converted = colormath(cell, theme=theme, is_fragment=False)
153
+ %%color_math -v
154
+ $$ \hat{H}\psi = E\psi $$
155
+ """
156
+ theme, opts, _ = self._parse_magic_args(line)
157
+ converted = colormath(cell, theme=theme, options=opts, is_fragment=False)
113
158
  display(Markdown(converted))
114
159
 
160
+ @line_magic("color_math_variables")
161
+ def color_math_variables(self, line: str) -> None:
162
+ """Toggle variable data-flow hash coloring for Latin symbols (E, m, x, etc.).
163
+
164
+ Usage:
165
+ %color_math_variables on
166
+ %color_math_variables off
167
+ """
168
+ cmd = line.strip().lower()
169
+ if cmd in ("on", "enable", "1", "true"):
170
+ self._options.variable_data_flow = True
171
+ print("Color Math: Variable data-flow coloring enabled.")
172
+ elif cmd in ("off", "disable", "0", "false"):
173
+ self._options.variable_data_flow = False
174
+ print("Color Math: Variable data-flow coloring disabled.")
175
+ else:
176
+ status = "ENABLED" if self._options.variable_data_flow else "DISABLED"
177
+ print(f"Color Math: Variable data-flow coloring is currently {status}.")
178
+
179
+ @line_magic("color_math_config")
180
+ def color_math_config(self, line: str) -> None:
181
+ """Inspect or initialize Color Math configuration.
182
+
183
+ Usage:
184
+ %color_math_config
185
+ %color_math_config --init
186
+ %color_math_config --reload
187
+ """
188
+ raw = line.strip().lower()
189
+ if "--init" in raw:
190
+ target = Path(".colormath.json")
191
+ save_default_config(target)
192
+ print(f"Color Math: Created config template at '{target.resolve()}'.")
193
+ self._palette, self._options, _ = load_config(target)
194
+ return
195
+ if "--reload" in raw:
196
+ self._palette, self._options, _ = load_config()
197
+ print("Color Math: Configuration reloaded.")
198
+ return
199
+
200
+ local_path = Path(".colormath.json")
201
+ global_path = get_global_config_path()
202
+ print("Color Math Configuration:")
203
+ print(f" Local config: {local_path.resolve()} ({'exists' if local_path.exists() else 'not found'})")
204
+ if global_path:
205
+ print(f" Global config: {global_path} ({'exists' if global_path.exists() else 'not found'})")
206
+ print(f" Variables: {'ENABLED' if self._options.variable_data_flow else 'DISABLED'}")
207
+ print(f" Taxonomy: {'ENABLED' if self._options.enable_taxonomy else 'DISABLED'}")
208
+ print(f" Delimiters: {'ENABLED' if self._options.rainbow_delimiters else 'DISABLED'}")
209
+ print(f" Auto-display: {'ENABLED' if self._auto_hook_active else 'DISABLED'}")
210
+
115
211
  @line_magic("color_math_auto")
116
212
  def color_math_auto(self, line: str) -> None:
117
213
  """Toggle automatic semantic colorization for all IPython.display.Math outputs.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "python-color-math"
7
- version = "0.2.14"
7
+ version = "0.2.16"
8
8
  description = "A fast, local semantic LaTeX colorizer for Markdown, Jupyter, and LaTeX math equations."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-color-math
3
- Version: 0.2.14
3
+ Version: 0.2.16
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
@@ -25,12 +25,12 @@ class TestIPythonIntegration(unittest.TestCase):
25
25
 
26
26
  # Full markdown test
27
27
  md = colormath("Let $f(x) = x^2$.")
28
- self.assertIn(r"$\textcolor{#7aa2f7}{f}(x)", md)
28
+ self.assertIn(r"\textcolor{#7aa2f7}{f}", md)
29
29
 
30
30
  def test_colormath_display_object(self):
31
31
  obj = ColorMath(r"\frac{df}{dx} = f'(x)")
32
32
  self.assertIsInstance(obj, Math)
33
- self.assertIn(r"\textcolor{#7aa2f7}{f'}(x)", obj.data)
33
+ self.assertIn(r"\textcolor{#7aa2f7}{f'}", obj.data)
34
34
 
35
35
  def test_load_and_unload_extension(self):
36
36
  load_ipython_extension(self.shell)