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

Skip to content

Commit cf513c8

Browse files
committed
Add support for \widehat and \widetilde
svn path=/trunk/matplotlib/; revision=3666
1 parent f068dad commit cf513c8

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

examples/mathtext_examples.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
r'$\frac{x_2888}{y}$',
3737
r"$\sqrt[3]{\frac{X_2}{Y}}=5$",
3838
r"$\sqrt[3]{x}=5$",
39-
r'$\frac{X}{\frac{X}{Y}}$'
39+
r'$\frac{X}{\frac{X}{Y}}$',
40+
r'$\widehat{abc}\widetilde{def}$'
4041
]
4142

4243
from pylab import *

lib/matplotlib/_mathtext_data.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
r'\}' : ('cmex10', 130),
4040
r'\leftangle' : ('cmex10', 97),
4141
r'\rightangle' : ('cmex10', 64),
42+
r'\widehat' : ('cmex10', 15),
43+
r'\widetilde' : ('cmex10', 52),
4244

4345
r'\omega' : ('cmmi10', 29),
4446
r'\varepsilon' : ('cmmi10', 20),

lib/matplotlib/mathtext.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,15 +1437,15 @@ class AutoWidthChar(Hlist):
14371437
of some characters (such as the BaKoMa fonts), the correct glyph will
14381438
be selected, otherwise this will always just return a scaled version
14391439
of the glyph."""
1440-
def __init__(self, c, width, state, always=False):
1440+
def __init__(self, c, width, state, always=False, char_class=Char):
14411441
alternatives = state.font_output.get_sized_alternatives_for_symbol(
14421442
state.font, c)
14431443

14441444
state = state.copy()
14451445
big_enough = False
14461446
for fontname, sym in alternatives:
14471447
state.font = fontname
1448-
char = Char(sym, state)
1448+
char = char_class(sym, state)
14491449
if char.width > width:
14501450
big_enough = True
14511451
break
@@ -1455,7 +1455,7 @@ def __init__(self, c, width, state, always=False):
14551455
if not big_enough:
14561456
factor = width / char.width
14571457
state.fontsize *= factor
1458-
char = Char(sym, state)
1458+
char = char_class(sym, state)
14591459

14601460
Hlist.__init__(self, [char])
14611461

@@ -1969,12 +1969,15 @@ def accent(self, s, loc, toks):
19691969
raise ParseFatalException("Error parsing accent")
19701970
accent, sym = toks[0]
19711971
if accent in self._wide_accents:
1972-
accent = AutoWidthChar(accent, sym.width, state)
1972+
accent = AutoWidthChar(
1973+
accent, sym.width, state, char_class=Accent)
1974+
shift_amount = 0.
19731975
else:
19741976
accent = Accent(self._accent_map[accent], state)
1977+
shift_amount = accent._metrics.xmin
19751978
centered = HCentered([accent])
19761979
centered.hpack(sym.width, 'exactly')
1977-
centered.shift_amount = accent._metrics.xmin
1980+
centered.shift_amount = shift_amount
19781981
return Vlist([
19791982
centered,
19801983
Vbox(0., thickness * 2.0),

0 commit comments

Comments
 (0)