Revision: 8806
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8806&view=rev
Author:   mdboom
Date:     2010-11-18 13:29:00 +0000 (Thu, 18 Nov 2010)

Log Message:
-----------
Add support for \overline in mathtext syntax -- contributed by Marshall Ward

Modified Paths:
--------------
    trunk/matplotlib/doc/users/mathtext.rst
    trunk/matplotlib/lib/matplotlib/mathtext.py

Modified: trunk/matplotlib/doc/users/mathtext.rst
===================================================================
--- trunk/matplotlib/doc/users/mathtext.rst     2010-11-17 15:31:27 UTC (rev 
8805)
+++ trunk/matplotlib/doc/users/mathtext.rst     2010-11-18 13:29:00 UTC (rev 
8806)
@@ -299,6 +299,7 @@
     ``\hat a`` or ``\^a``          :math:`\hat a`
     ``\tilde a`` or ``\~a``        :math:`\tilde a`
     ``\vec a``                     :math:`\vec a`
+    ``\overline{abc}``             :math:`\overline{abc}`
     ============================== =================================
 
 In addition, there are two special accents that automatically adjust

Modified: trunk/matplotlib/lib/matplotlib/mathtext.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/mathtext.py 2010-11-17 15:31:27 UTC (rev 
8805)
+++ trunk/matplotlib/lib/matplotlib/mathtext.py 2010-11-18 13:29:00 UTC (rev 
8806)
@@ -2251,7 +2251,6 @@
                         | Error(r"Expected 
\genfrac{ldelim}{rdelim}{rulesize}{style}{num}{den}"))
                      ).setParseAction(self.genfrac).setName("genfrac")
 
-
         sqrt         = Group(
                        Suppress(Literal(r"\sqrt"))
                      + Optional(
@@ -2263,6 +2262,11 @@
                      + (group | Error("Expected \sqrt{value}"))
                      ).setParseAction(self.sqrt).setName("sqrt")
 
+        overline    = Group(
+                      Suppress(Literal(r"\overline"))
+                    + (group | Error("Expected \overline{value}"))
+                    ).setParseAction(self.overline).setName("overline")
+
         placeable   <<(function
                      ^ (c_over_c | symbol)
                      ^ accent
@@ -2272,6 +2276,7 @@
                      ^ binom
                      ^ genfrac
                      ^ sqrt
+                     ^ overline
                      )
 
         simple      <<(space
@@ -2845,6 +2850,33 @@
                        rightside])               # Body
         return [hlist]
 
+    def overline(self, s, loc, toks):
+        assert(len(toks)==1)
+        assert(len(toks[0])==1)
+
+        body = toks[0][0]
+
+        state = self.get_state()
+        thickness = state.font_output.get_underline_thickness(
+            state.font, state.fontsize, state.dpi)
+
+        height = body.height - body.shift_amount + thickness * 3.0
+        depth = body.depth + body.shift_amount
+
+        # Put a little extra space to the left and right of the body
+        padded_body = Hlist([Hbox(thickness * 2.0),
+                             body,
+                             Hbox(thickness * 2.0)])
+        rightside = Vlist([Hrule(state),
+                           Fill(),
+                           padded_body])
+        # Stretch the glue between the hrule and the body
+        rightside.vpack(height + (state.fontsize * state.dpi) / (100.0 * 12.0),
+                        depth, 'exactly')
+
+        hlist = Hlist([rightside])
+        return [hlist]
+
     def _auto_sized_delimiter(self, front, middle, back):
         state = self.get_state()
         height = max([x.height for x in middle])


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev
_______________________________________________
Matplotlib-checkins mailing list
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to