11
11
import re
12
12
import types
13
13
import unicodedata
14
+ import string
14
15
15
16
import numpy as np
16
17
from pyparsing import (
@@ -1811,6 +1812,11 @@ class _MathStyle(enum.Enum):
1811
1812
_right_delims = set (r") ] \} > \rfloor \rangle \rceil" .split ())
1812
1813
_delims = _left_delims | _right_delims | _ambi_delims
1813
1814
1815
+ _small_greek = set ([unicodedata .name (chr (i )).split ()[- 1 ].lower () for i in
1816
+ range (ord ('\N{GREEK SMALL LETTER ALPHA} ' ),
1817
+ ord ('\N{GREEK SMALL LETTER OMEGA} ' ) + 1 )])
1818
+ _latin_alphabets = set (string .ascii_letters )
1819
+
1814
1820
def __init__ (self ):
1815
1821
p = types .SimpleNamespace ()
1816
1822
@@ -1933,6 +1939,9 @@ def csnames(group, names):
1933
1939
1934
1940
p .operatorname = cmd (r"\operatorname" , "{" + ZeroOrMore (p .simple )("name" ) + "}" )
1935
1941
1942
+ p .boldsymbol = cmd (
1943
+ r"\boldsymbol" , "{" + ZeroOrMore (p .simple )("value" ) + "}" )
1944
+
1936
1945
p .placeable <<= (
1937
1946
p .accent # Must be before symbol as all accents are symbols
1938
1947
| p .symbol # Must be second to catch all named symbols and single
@@ -1949,6 +1958,7 @@ def csnames(group, names):
1949
1958
| p .sqrt
1950
1959
| p .overline
1951
1960
| p .text
1961
+ | p .boldsymbol
1952
1962
)
1953
1963
1954
1964
p .auto_delim <<= (
@@ -2597,3 +2607,29 @@ def auto_delim(self, s, loc, toks):
2597
2607
# if "mid" in toks ... can be removed when requiring pyparsing 3.
2598
2608
toks ["mid" ].asList () if "mid" in toks else [],
2599
2609
toks ["right" ])
2610
+
2611
+ def boldsymbol (self , s , loc , toks ):
2612
+ self .push_state ()
2613
+ state = self .get_state ()
2614
+ hlist = []
2615
+ name = toks ["value" ]
2616
+ for c in name :
2617
+ if isinstance (c , Hlist ):
2618
+ k = c .children [1 ]
2619
+ if isinstance (k , Char ):
2620
+ k .font = "bf"
2621
+ k ._update_metrics ()
2622
+ hlist .append (c )
2623
+ elif isinstance (c , Char ):
2624
+ c .font = "bf"
2625
+ if (c .c in self ._latin_alphabets or
2626
+ c .c [1 :] in self ._small_greek ):
2627
+ c .font = "bfit"
2628
+ c ._update_metrics ()
2629
+ c ._update_metrics ()
2630
+ hlist .append (c )
2631
+ else :
2632
+ hlist .append (c )
2633
+ self .pop_state ()
2634
+
2635
+ return Hlist (hlist )
0 commit comments