1111import re
1212import types
1313import unicodedata
14+ import string
1415
1516import numpy as np
1617from pyparsing import (
@@ -1811,6 +1812,11 @@ class _MathStyle(enum.Enum):
18111812 _right_delims = set (r") ] \} > \rfloor \rangle \rceil" .split ())
18121813 _delims = _left_delims | _right_delims | _ambi_delims
18131814
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+
18141820 def __init__ (self ):
18151821 p = types .SimpleNamespace ()
18161822
@@ -1933,6 +1939,9 @@ def csnames(group, names):
19331939
19341940 p .operatorname = cmd (r"\operatorname" , "{" + ZeroOrMore (p .simple )("name" ) + "}" )
19351941
1942+ p .boldsymbol = cmd (
1943+ r"\boldsymbol" , "{" + ZeroOrMore (p .simple )("value" ) + "}" )
1944+
19361945 p .placeable <<= (
19371946 p .accent # Must be before symbol as all accents are symbols
19381947 | p .symbol # Must be second to catch all named symbols and single
@@ -1949,6 +1958,7 @@ def csnames(group, names):
19491958 | p .sqrt
19501959 | p .overline
19511960 | p .text
1961+ | p .boldsymbol
19521962 )
19531963
19541964 p .auto_delim <<= (
@@ -2597,3 +2607,29 @@ def auto_delim(self, s, loc, toks):
25972607 # if "mid" in toks ... can be removed when requiring pyparsing 3.
25982608 toks ["mid" ].asList () if "mid" in toks else [],
25992609 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