python-color-math 0.2.20__py3-none-any.whl → 0.2.22__py3-none-any.whl

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.
color_math/__init__.py CHANGED
@@ -13,7 +13,7 @@ from .undo import uncolor_text
13
13
 
14
14
  from .ipython import ColorMath, colormath, load_ipython_extension, unload_ipython_extension
15
15
 
16
- __version__ = "0.2.20"
16
+ __version__ = "0.2.22"
17
17
 
18
18
  __all__ = [
19
19
  "__version__",
@@ -18,7 +18,7 @@
18
18
  "options": {
19
19
  "enable_taxonomy": true,
20
20
  "rainbow_delimiters": true,
21
- "variable_data_flow": false,
21
+ "variable_data_flow": true,
22
22
  "color_units": true,
23
23
  "color_differentials": true,
24
24
  "color_braket": true,
color_math/config.py CHANGED
@@ -610,26 +610,82 @@ RAINBOW_DELIMITER_COLORS: list[str] = [
610
610
 
611
611
 
612
612
  VARIABLE_HASH_PALETTE: list[str] = [
613
- "#7aa2f7", # Tokyo Blue
614
- "#7dcfff", # Tokyo Cyan
615
- "#bb9af7", # Tokyo Purple
616
- "#f7768e", # Tokyo Pink
617
- "#e0af68", # Tokyo Orange/Gold
618
- "#9ece6a", # Tokyo Green
619
- "#2ac3de", # Light Cyan
620
- "#ff9e64", # Peach
613
+ "#7aa2f7", # 0: Tokyo Blue
614
+ "#7dcfff", # 1: Tokyo Cyan
615
+ "#bb9af7", # 2: Tokyo Purple
616
+ "#f7768e", # 3: Tokyo Pink
617
+ "#e0af68", # 4: Tokyo Orange/Gold
618
+ "#9ece6a", # 5: Tokyo Green
619
+ "#2ac3de", # 6: Light Cyan/Teal
620
+ "#ff9e64", # 7: Peach
621
621
  ]
622
622
 
623
+ CANONICAL_VARIABLE_SLOTS: dict[str, int] = {
624
+ # 1. Spatial 3D Cartesian coordinates: guaranteed maximum pairwise separation
625
+ "x": 0, # Tokyo Blue
626
+ "y": 4, # Tokyo Gold
627
+ "z": 5, # Tokyo Green
628
+
629
+ # 2. Coefficients: high-contrast against (x, y, z) and within the group
630
+ "a": 2, # Tokyo Purple
631
+ "b": 3, # Tokyo Pink
632
+ "c": 6, # Light Cyan/Teal
633
+ "d": 7, # Peach
634
+
635
+ # 3. Parameters / Velocity / Substitutions
636
+ "u": 1, # Tokyo Cyan
637
+ "v": 2, # Tokyo Purple
638
+ "w": 4, # Tokyo Gold
639
+
640
+ # 4. Discrete summation & matrix indices
641
+ "i": 4, # Tokyo Gold
642
+ "j": 0, # Tokyo Blue
643
+ "k": 3, # Tokyo Pink
644
+ "l": 5, # Tokyo Green
645
+ "m": 2, # Tokyo Purple
646
+ "n": 6, # Light Cyan/Teal
647
+
648
+ # 5. Calculus & Analysis duals
649
+ "s": 3, # Tokyo Pink
650
+ "t": 1, # Tokyo Cyan
651
+ "p": 0, # Tokyo Blue
652
+ "q": 7, # Peach
653
+
654
+ # 6. Thermodynamics & State
655
+ "P": 3, # Tokyo Pink
656
+ "V": 0, # Tokyo Blue
657
+ "T": 4, # Tokyo Gold
658
+
659
+ # 7. Greek letters & canonical duals
660
+ "\\theta": 4, "θ": 4, "𝜗": 4, "ϑ": 4,
661
+ "\\phi": 2, "\\varphi": 2, "ϕ": 2, "φ": 2, "𝜙": 2, "𝜑": 2,
662
+ "\\psi": 2, "ψ": 2, "𝜓": 2,
663
+ "\\epsilon": 2, "\\varepsilon": 2, "ε": 2, "𝜀": 2,
664
+ "\\delta": 5, "δ": 5, "𝛿": 5,
665
+ "\\alpha": 2, "α": 2, "𝛼": 2,
666
+ "\\beta": 3, "β": 3, "𝛽": 3,
667
+ "\\gamma": 5, "γ": 5, "𝛾": 5,
668
+ "\\omega": 7, "ω": 7, "𝜔": 7,
669
+ "\\lambda": 6, "λ": 6, "𝜆": 6,
670
+ }
623
671
 
624
- def hash_string_to_color(s: str, palette: list[str] = VARIABLE_HASH_PALETTE) -> str:
625
- """Deterministic string hashing for variable data-flow coloring."""
672
+
673
+ def hash_string_to_slot(s: str, num_slots: int = 8) -> int:
674
+ """Dispersive hash mapping identifiers to palette slots with golden ratio dispersion."""
675
+ if s in CANONICAL_VARIABLE_SLOTS:
676
+ return CANONICAL_VARIABLE_SLOTS[s] % num_slots
677
+
678
+ # Knuth 32-bit multiplicative hash with golden ratio constant 2654435761 (0x9E3779B9)
626
679
  h = 0
627
680
  for char in s:
628
- h = (h * 31 + ord(char)) & 0xFFFFFFFF
629
- if h >= 0x80000000:
630
- h -= 0x100000000
631
- idx = abs(h) % len(palette)
632
- return palette[idx]
681
+ h = ((h << 5) - h + ord(char)) & 0xFFFFFFFF
682
+ return ((h * 2654435761) & 0xFFFFFFFF) % num_slots
683
+
684
+
685
+ def hash_string_to_color(s: str, palette: list[str] = VARIABLE_HASH_PALETTE) -> str:
686
+ """Deterministic string hashing for variable data-flow coloring with harmonic disambiguation."""
687
+ slot = hash_string_to_slot(s, len(palette))
688
+ return palette[slot]
633
689
 
634
690
 
635
691
  @dataclass
@@ -656,7 +712,7 @@ class ColorMathOptions:
656
712
  return cls(
657
713
  enable_taxonomy=True,
658
714
  rainbow_delimiters=True,
659
- variable_data_flow=False,
715
+ variable_data_flow=True,
660
716
  color_units=True,
661
717
  color_differentials=True,
662
718
  color_braket=True,
@@ -871,7 +927,7 @@ def get_bundled_default_config() -> dict[str, object]:
871
927
  "_comment": "Python Color Math factory default configuration",
872
928
  "theme": "default",
873
929
  "colors": dict(DEFAULT_COLORS),
874
- "options": asdict(ColorMathOptions()),
930
+ "options": asdict(ColorMathOptions.extended()),
875
931
  "unicode": dict(DEFAULT_UNICODE_CONFIG),
876
932
  "_role_descriptions": ROLE_DESCRIPTIONS,
877
933
  }
@@ -887,7 +943,7 @@ def load_config(
887
943
  Returns (palette_dict, ColorMathOptions, unicode_config_dict).
888
944
  """
889
945
  palette = dict(DEFAULT_COLORS)
890
- options = ColorMathOptions()
946
+ options = ColorMathOptions.extended()
891
947
  unicode_config = dict(DEFAULT_UNICODE_CONFIG)
892
948
 
893
949
  target = path
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-color-math
3
- Version: 0.2.20
3
+ Version: 0.2.22
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
@@ -1,9 +1,9 @@
1
- color_math/__init__.py,sha256=QC26ZMkEe8pqXYZeJnc2s3dVlftaLvkyOom1Ew0MZx8,786
1
+ color_math/__init__.py,sha256=fVckjdNrbmf9xuE_1i1AvOeNvR7Sf_xEerwD3Zo5V8I,786
2
2
  color_math/__main__.py,sha256=lU6t3BklI-5H9EdprlceWLr0UcDmfXUu3Th0tjk2ANA,81
3
3
  color_math/adapters.py,sha256=glMvD8Bma_865jmOvIGGkCRxQLIEGjToFDOqJy_WeWA,12293
4
- color_math/colormath.default.json,sha256=KmQb7BV7sMMIqPxR4x6i9RwuXuUqkpyiy4yHw84GxPQ,2756
4
+ color_math/colormath.default.json,sha256=CE3L1BF9xXgPj0_t4uu5Y-xvV9fCDND_ZEjwX4doevE,2755
5
5
  color_math/completions.py,sha256=Q63B8GNn71vdNohbcNs5WmXY8qFGy2T7qT9W-v8XUuQ,11010
6
- color_math/config.py,sha256=tCOnGDqPlPhwBihBQVPddZaao2hxU52RNtS2MGFpDNQ,24607
6
+ color_math/config.py,sha256=pk6JkwxRaADrlS2K-Fo-Qn5CAn6jE8SMM_8Y8qcNF6g,26501
7
7
  color_math/custom_definitions.py,sha256=IYJ_L51d1vyFf5frbJoFMIagKRcI7TiNzELfoewZyjk,2392
8
8
  color_math/gui.py,sha256=cBsgNToQdZ7mNQ9JA5_jEv7QbELc4NGtgXowTxZ-IWQ,21413
9
9
  color_math/io.py,sha256=iCWMY1ufPZzFCwuHTn_axNetek8PRXGNnrmz59CrlGw,1591
@@ -50,9 +50,9 @@ color_math/utils/latex_helpers.py,sha256=1cFj0zqv68mD-p0vej6yPrhwgqLfAWcIV1rX15F
50
50
  color_math/utils/spans.py,sha256=3Lq1_bN0s4vSYnS8Rz9tCHoFoJDY6Ff9CzawWWws3YE,3938
51
51
  python_color_math/__init__.py,sha256=Dj5YZXXjmNgbyhHKX2YQXvVggtB9UZy9zotLiV2j5So,329
52
52
  python_color_math/__main__.py,sha256=cqUM_fV0E6mtuHeBn2MjuozR2rlpev9AfXfcm2hSpi8,90
53
- python_color_math-0.2.20.dist-info/licenses/LICENSE,sha256=hveQNxqYFqK9Brs_ruH-8shF2D61hIVKYdCjiE-1wMY,1063
54
- python_color_math-0.2.20.dist-info/METADATA,sha256=9My67JDGkNrwYafVaiydGSeG6D23n3YG45nMytGpbLo,14469
55
- python_color_math-0.2.20.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
56
- python_color_math-0.2.20.dist-info/entry_points.txt,sha256=ZgzGbO_D3csr693Fd-tVGhls6WzsZiOhCau-liSkE_M,130
57
- python_color_math-0.2.20.dist-info/top_level.txt,sha256=dkfmCdtILDAgX4wwDW5DKHh9YRLt9Mh2RU0gh1mBDDA,29
58
- python_color_math-0.2.20.dist-info/RECORD,,
53
+ python_color_math-0.2.22.dist-info/licenses/LICENSE,sha256=hveQNxqYFqK9Brs_ruH-8shF2D61hIVKYdCjiE-1wMY,1063
54
+ python_color_math-0.2.22.dist-info/METADATA,sha256=QJmmtYqrHMXkzATYy0Gx2mJ-XrXpC4BRJ_dauZtlDgY,14469
55
+ python_color_math-0.2.22.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
56
+ python_color_math-0.2.22.dist-info/entry_points.txt,sha256=ZgzGbO_D3csr693Fd-tVGhls6WzsZiOhCau-liSkE_M,130
57
+ python_color_math-0.2.22.dist-info/top_level.txt,sha256=dkfmCdtILDAgX4wwDW5DKHh9YRLt9Mh2RU0gh1mBDDA,29
58
+ python_color_math-0.2.22.dist-info/RECORD,,