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

Skip to content

Commit 4711427

Browse files
committed
Add support for \overline in mathtext syntax -- contributed by Marshall Ward
svn path=/trunk/matplotlib/; revision=8806
1 parent a4e57e2 commit 4711427

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

doc/users/mathtext.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ There are long and short forms for some of them.
299299
``\hat a`` or ``\^a`` :math:`\hat a`
300300
``\tilde a`` or ``\~a`` :math:`\tilde a`
301301
``\vec a`` :math:`\vec a`
302+
``\overline{abc}`` :math:`\overline{abc}`
302303
============================== =================================
303304

304305
In addition, there are two special accents that automatically adjust

lib/matplotlib/mathtext.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2251,7 +2251,6 @@ def __init__(self):
22512251
| Error(r"Expected \genfrac{ldelim}{rdelim}{rulesize}{style}{num}{den}"))
22522252
).setParseAction(self.genfrac).setName("genfrac")
22532253

2254-
22552254
sqrt = Group(
22562255
Suppress(Literal(r"\sqrt"))
22572256
+ Optional(
@@ -2263,6 +2262,11 @@ def __init__(self):
22632262
+ (group | Error("Expected \sqrt{value}"))
22642263
).setParseAction(self.sqrt).setName("sqrt")
22652264

2265+
overline = Group(
2266+
Suppress(Literal(r"\overline"))
2267+
+ (group | Error("Expected \overline{value}"))
2268+
).setParseAction(self.overline).setName("overline")
2269+
22662270
placeable <<(function
22672271
^ (c_over_c | symbol)
22682272
^ accent
@@ -2272,6 +2276,7 @@ def __init__(self):
22722276
^ binom
22732277
^ genfrac
22742278
^ sqrt
2279+
^ overline
22752280
)
22762281

22772282
simple <<(space
@@ -2845,6 +2850,33 @@ def sqrt(self, s, loc, toks):
28452850
rightside]) # Body
28462851
return [hlist]
28472852

2853+
def overline(self, s, loc, toks):
2854+
assert(len(toks)==1)
2855+
assert(len(toks[0])==1)
2856+
2857+
body = toks[0][0]
2858+
2859+
state = self.get_state()
2860+
thickness = state.font_output.get_underline_thickness(
2861+
state.font, state.fontsize, state.dpi)
2862+
2863+
height = body.height - body.shift_amount + thickness * 3.0
2864+
depth = body.depth + body.shift_amount
2865+
2866+
# Put a little extra space to the left and right of the body
2867+
padded_body = Hlist([Hbox(thickness * 2.0),
2868+
body,
2869+
Hbox(thickness * 2.0)])
2870+
rightside = Vlist([Hrule(state),
2871+
Fill(),
2872+
padded_body])
2873+
# Stretch the glue between the hrule and the body
2874+
rightside.vpack(height + (state.fontsize * state.dpi) / (100.0 * 12.0),
2875+
depth, 'exactly')
2876+
2877+
hlist = Hlist([rightside])
2878+
return [hlist]
2879+
28482880
def _auto_sized_delimiter(self, front, middle, back):
28492881
state = self.get_state()
28502882
height = max([x.height for x in middle])

0 commit comments

Comments
 (0)