Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit df3add6

Browse files
committed
Add support for more accents in mathtext
1 parent fd4cce7 commit df3add6

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

lib/matplotlib/_mathtext.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,6 +2031,9 @@ def unknown_symbol(self, s, loc, toks):
20312031
r'overrightarrow': r'\rightarrow',
20322032
r'overleftarrow': r'\leftarrow',
20332033
r'mathring': r'\circ',
2034+
r'=': r'\combiningoverline',
2035+
r'H': r'\combiningdoubleacuteaccent',
2036+
r'check': r'\combiningcaron',
20342037
}
20352038

20362039
_wide_accents = set(r"widehat widetilde widebar".split())
@@ -2050,8 +2053,18 @@ def accent(self, s, loc, toks):
20502053
accent_box = AutoWidthChar(
20512054
'\\' + accent, sym.width, state, char_class=Accent)
20522055
else:
2056+
# Check if accent and character can be combined
2057+
a = get_unicode_index(self._accent_map[accent])
2058+
if isinstance(sym, Char):
2059+
c = sym.c
2060+
else:
2061+
c = sym.children[0].c
2062+
comb = unicodedata.normalize('NFC', c + chr(a))
2063+
if len(comb) == 1:
2064+
return Char(comb, state)
2065+
# Cannot be combined
20532066
accent_box = Accent(self._accent_map[accent], state)
2054-
if accent == 'mathring':
2067+
if accent in ('mathring', 'r'):
20552068
accent_box.shrink()
20562069
accent_box.shrink()
20572070
centered = HCentered([Hbox(sym.width / 4.0), accent_box])
@@ -2137,9 +2150,6 @@ def is_slanted(self, nucleus):
21372150
return nucleus.is_slanted()
21382151
return False
21392152

2140-
def is_between_brackets(self, s, loc):
2141-
return False
2142-
21432153
def subsuper(self, s, loc, toks):
21442154
nucleus = toks.get("nucleus", Hbox(0))
21452155
subsuper = toks.get("subsuper", [])

lib/matplotlib/_mathtext_data.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,8 @@
10021002
'combiningdotabove' : 775,
10031003
'combiningthreedotsabove' : 8411,
10041004
'combiningfourdotsabove' : 8412,
1005+
'combiningdoubleacuteaccent' : 779,
1006+
'combiningcaron' : 780,
10051007
'to' : 8594,
10061008
'succeq' : 8829,
10071009
'emptyset' : 8709,

tutorials/text/mathtext.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@
306306
Command Result
307307
============================== =================================
308308
``\acute a`` or ``\'a`` :mathmpl:`\acute a`
309-
``\bar a`` :mathmpl:`\bar a`
309+
``\bar a`` or ``\= a`` :mathmpl:`\bar a`
310310
``\breve a`` :mathmpl:`\breve a`
311311
``\dot a`` or ``\.a`` :mathmpl:`\dot a`
312312
``\ddot a`` or ``\''a`` :mathmpl:`\ddot a`
@@ -316,6 +316,8 @@
316316
``\hat a`` or ``\^a`` :mathmpl:`\hat a`
317317
``\tilde a`` or ``\~a`` :mathmpl:`\tilde a`
318318
``\vec a`` :mathmpl:`\vec a`
319+
``\check a`` :mathmpl:`\check a`
320+
``\H a`` :mathmpl:`\H a`
319321
``\overline{abc}`` :mathmpl:`\overline{abc}`
320322
============================== =================================
321323

0 commit comments

Comments
 (0)