Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitce1fa41

Browse files
committed
Add support for more accents in mathtext
1 parentfd4cce7 commitce1fa41

File tree

3 files changed

+40
-16
lines changed

3 files changed

+40
-16
lines changed

‎lib/matplotlib/_mathtext.py

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def _get_info(self, fontname, font_class, sym, fontsize, dpi, math=True):
223223
ifbunchisnotNone:
224224
returnbunch
225225

226-
font,num,slanted=self._get_glyph(
226+
font,num,slanted,substituted_glyph=self._get_glyph(
227227
fontname,font_class,sym,fontsize,math)
228228

229229
font.set_size(fontsize,dpi)
@@ -242,7 +242,8 @@ def _get_info(self, fontname, font_class, sym, fontsize, dpi, math=True):
242242
ymax=ymax+offset,
243243
# iceberg is the equivalent of TeX's "height"
244244
iceberg=glyph.horiBearingY/64.0+offset,
245-
slanted=slanted
245+
slanted=slanted,
246+
substituted_glyph=substituted_glyph
246247
)
247248

248249
result=self.glyphd[key]=types.SimpleNamespace(
@@ -326,7 +327,7 @@ def _get_glyph(self, fontname, font_class, sym, fontsize, math=True):
326327
iffontisnotNone:
327328
num=ord(sym)
328329
iffontisnotNoneandfont.get_char_index(num)!=0:
329-
returnfont,num,slanted
330+
returnfont,num,slanted,False
330331
else:
331332
returnself._stix_fallback._get_glyph(
332333
fontname,font_class,sym,fontsize,math)
@@ -451,6 +452,8 @@ def _get_glyph(self, fontname, font_class, sym, fontsize, math=True):
451452
found_symbol=False
452453
_log.warning("No TeX to Unicode mapping for {!a}.".format(sym))
453454

455+
substituted_glyph=False
456+
454457
fontname,uniindex=self._map_virtual_font(
455458
fontname,font_class,uniindex)
456459

@@ -502,8 +505,9 @@ def _get_glyph(self, fontname, font_class, sym, fontsize, math=True):
502505
font=self._get_font('rm')
503506
uniindex=0xA4# currency char, for lack of anything better
504507
slanted=False
508+
substituted_glyph=True
505509

506-
returnfont,uniindex,slanted
510+
returnfont,uniindex,slanted,substituted_glyph
507511

508512
defget_sized_alternatives_for_symbol(self,fontname,sym):
509513
ifself._fallback_font:
@@ -943,6 +947,9 @@ def _update_metrics(self):
943947
defis_slanted(self):
944948
returnself._metrics.slanted
945949

950+
defis_substituted(self):
951+
returnself._metrics.substituted_glyph
952+
946953
defget_kerning(self,next):
947954
"""
948955
Return the amount of kerning between this and the given character.
@@ -2011,7 +2018,7 @@ def unknown_symbol(self, s, loc, toks):
20112018
raiseParseFatalException(s,loc,f"Unknown symbol:{toks['name']}")
20122019

20132020
_accent_map= {
2014-
r'hat':r'\circumflexaccent',
2021+
r'hat':r'\combiningcircumflexaccent',
20152022
r'breve':r'\combiningbreve',
20162023
r'bar':r'\combiningoverline',
20172024
r'grave':r'\combininggraveaccent',
@@ -2027,10 +2034,13 @@ def unknown_symbol(self, s, loc, toks):
20272034
r"'":r'\combiningacuteaccent',
20282035
r'~':r'\combiningtilde',
20292036
r'.':r'\combiningdotabove',
2030-
r'^':r'\circumflexaccent',
2031-
r'overrightarrow':r'\rightarrow',
2032-
r'overleftarrow':r'\leftarrow',
2033-
r'mathring':r'\circ',
2037+
r'^':r'\combiningcircumflexaccent',
2038+
r'overrightarrow':r'\combiningrightarrowabove',
2039+
r'overleftarrow':r'\combiningleftarrowabove',
2040+
r'mathring':r'\combiningringabove',
2041+
r'=':r'\combiningoverline',
2042+
r'H':r'\combiningdoubleacuteaccent',
2043+
r'check':r'\combiningcaron',
20342044
}
20352045

20362046
_wide_accents=set(r"widehat widetilde widebar".split())
@@ -2050,10 +2060,20 @@ def accent(self, s, loc, toks):
20502060
accent_box=AutoWidthChar(
20512061
'\\'+accent,sym.width,state,char_class=Accent)
20522062
else:
2063+
# Check if accent and character can be combined
2064+
a=get_unicode_index(self._accent_map[accent])
2065+
ifisinstance(sym,Char):
2066+
c=sym.c
2067+
else:
2068+
c=sym.children[0].c
2069+
comb=unicodedata.normalize('NFC',c+chr(a))
2070+
iflen(comb)==1:# Check that they did combine
2071+
c=Char(comb,state)
2072+
# Check that glyph exists
2073+
ifnotc.is_substituted():
2074+
returnc
2075+
# Cannot be combined
20532076
accent_box=Accent(self._accent_map[accent],state)
2054-
ifaccent=='mathring':
2055-
accent_box.shrink()
2056-
accent_box.shrink()
20572077
centered=HCentered([Hbox(sym.width/4.0),accent_box])
20582078
centered.hpack(sym.width,'exactly')
20592079
returnVlist([
@@ -2137,9 +2157,6 @@ def is_slanted(self, nucleus):
21372157
returnnucleus.is_slanted()
21382158
returnFalse
21392159

2140-
defis_between_brackets(self,s,loc):
2141-
returnFalse
2142-
21432160
defsubsuper(self,s,loc,toks):
21442161
nucleus=toks.get("nucleus",Hbox(0))
21452162
subsuper=toks.get("subsuper", [])

‎lib/matplotlib/_mathtext_data.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,9 +999,14 @@
999999
'combiningdiaeresis' :776,
10001000
'combiningtilde' :771,
10011001
'combiningrightarrowabove' :8407,
1002+
'combiningleftarrowabove' :8406,
10021003
'combiningdotabove' :775,
1004+
'combiningringabove' :778,
10031005
'combiningthreedotsabove' :8411,
10041006
'combiningfourdotsabove' :8412,
1007+
'combiningdoubleacuteaccent' :779,
1008+
'combiningcaron' :780,
1009+
'combiningcircumflexaccent' :770,
10051010
'to' :8594,
10061011
'succeq' :8829,
10071012
'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)

[8]ページ先頭

©2009-2025 Movatter.jp