Matplotlib
Home
Download
Installing
Screenshots
What's New
Mailing lists

Documentation
Tutorial
FAQ
Matlab interface
Class library
Backends
Fonts
Interactive
Goals

Other
Credits
License

  
 
 
matplotlib.mathtext
index
/matplotlib/mathtext.py

OVERVIEW 
 
  mathtext is a module for parsing TeX expressions and drawing them
  into a matplotlib.ft2font image buffer.  You can draw from this
  buffer into your backend.
 
  A large set of the TeX symbols are provided (see below).
  Subscripting and superscripting are supported, as well as the
  over/under style of subscripting with \sum, \int, etc.
 
  The module uses pyparsing to parse the TeX expression, an so can
  handle fairly complex TeX expressions Eg, the following renders
  correctly
 
  s = r'\cal{R}\prod_{i=\alpha\cal{B}}^\infty a_i\rm{sin}(2 \pi f x_i)'
 
  The fonts \cal, \rm, \it, and \tt are allowed.
 
  If you find TeX expressions that don't parse or render properly,
  please email me, but please check KNOWN ISSUES below first.
 
LICENSING:
 
  The computer modern fonts this package uses are part of the BaKoMa
  fonts, which are (in my understanding) free for noncommercial use.
  For commercial use, please consult the licenses in fonts/ttf and the
  author Basil K. Malyshev - see also
  http://www.mozilla.org/projects/mathml/fonts/encoding/license-bakoma.txt
 
USAGE:
 
  Any text element (xlabel, ylabel, title, text, etc) can use TeX
  markup, as in
 
    xlabel(r'$\Delta_i$')
           ^
        use raw strings
 
  The $ symbols must be the first and last symbols in the string.  Eg,
  you cannot do 
 
    r'My label $x_i$'.  
 
  But you can change fonts, as in 
 
    r'\rm{My label} x_i' 
 
  to achieve the same effect.
 
  A large set of the TeX symbols are provided (see below).
  Subscripting and superscripting are supported, as well as the
  over/under style of subscripting with \sum, \int, etc.
 
 
  Allowed TeX symbols:
 
  \Delta \Downarrow \Gamma \Im \LEFTangle \LEFTbrace \LEFTbracket
  \LEFTparen \Lambda \Leftarrow \Leftbrace \Leftbracket \Leftparen
  \Leftrightarrow \Omega \P \Phi \Pi \Psi \RIGHTangle \RIGHTbrace
  \RIGHTbracket \RIGHTparen \Re \Rightarrow \Rightbrace \Rightbracket
  \Rightparen \S \SQRT \Sigma \Sqrt \Theta \Uparrow \Updownarrow
  \Upsilon \Vert \Xi \aleph \alpha \approx \ast \asymp \backslash
  \beta \bigcap \bigcirc \bigcup \bigodot \bigoplus \bigotimes
  \bigtriangledown \bigtriangleup \biguplus \bigvee \bigwedge \bot
  \bullet \cap \cdot \chi \circ \clubsuit \coprod \cup \dag \dashv
  \ddag \delta \diamond \diamondsuit \div \downarrow \ell \emptyset
  \epsilon \equiv \eta \exists \flat \forall \frown \gamma \geq \gg
  \heartsuit \imath \in \infty \int \iota \jmath \kappa \lambda
  \langle \lbrace \lceil \leftangle \leftarrow \leftbrace \leftbracket
  \leftharpoondown \leftharpoonup \leftparen \leftrightarrow \leq
  \lfloor \ll \mid \mp \mu \nabla \natural \nearrow \neg \ni \nu
  \nwarrow \odot \oint \omega \ominus \oplus \oslash \otimes \phi \pi
  \pm \prec \preceq \prime \prod \propto \psi \rangle \rbrace \rceil
  \rfloor \rho \rightangle \rightarrow \rightbrace \rightbracket
  \rightharpoondown \rightharpoonup \rightparen \searrow \sharp \sigma
  \sim \simeq \slash \smile \spadesuit \sqcap \sqcup \sqrt \sqsubseteq
  \sqsupseteq \subset \subseteq \succ \succeq \sum \supset \supseteq
  \swarrow \tau \theta \times \top \triangleleft \triangleright
  \uparrow \updownarrow \uplus \upsilon \varepsilon \varphi \varphi
  \varrho \varsigma \vartheta \vdash \vee \wedge \wp \wr \xi \zeta
 
BACKENDS
 
  mathtext currently works with Agg, GTKAgg and TkAgg.  If David
  incorporates ft2font into paint, it will be easy to add to Paint.  I
  think I can also add it to GTK rather straightforwardly, since it's
  just a matter of rendering from the ft2font pixel buffers; ditto for
  wx.  PS will require more substantial work, doing the metrics and
  layouts with the AFM versions of the computer modern fonts.
  Backends which don't support mathtext will just render the TeX
  string as a literal.  Stay tuned.
 
 
KNOWN ISSUES:
 
 - some hackish ways I deal with a strange offset in cmex10
 - bbox is a bit large in vertical direction and small in horizontal direction
 - nested subscripts, eg, x_i_i not working
 - nesting fonts changes in sub/superscript groups not parsing
 - I would also like to add a fre more layout commands, like \frac.
 
Author    : John Hunter <jdhunter@ace.bsd.uchicago.edu>
Copyright : John Hunter (2004)
License   : matplotlib license (PSF compatible)

 
Modules
       
os
sys

 
Classes
       
Handler
MathText
Expr
Font
Grp
Single
SubSup

 
class Expr(MathText)
     Methods defined here:
__init__(self, objs)
__repr__(self)
get_children(self)

Methods inherited from MathText:
draw(self, baseline)
get_bbox(self)
load_glyphs(self)
set_fontfile(self, fontfile)
set_next(self, nx, ny)
Set the pen location where drawing should begin for the
following MathText
set_offsets(self, previous)
Set the offsets assuming previous is the symbol before
you. return a new previous
set_origin(self, ox, oy)
Set the pen location where drawing should begin
set_size(self, size)

Data and other attributes inherited from MathText:
dpi = 200
fontfile = 'cmmi10.ttf'
nx = 0
ny = 0
ox = 0
oy = 0
size = 12

 
class Font(MathText)
     Methods defined here:
__init__(self, name, grp)
__repr__(self)
get_children(self)

Data and other attributes defined here:
symmap = {r'\cal': 'cmsy10.ttf', r'\it': 'cmmi10.ttf', r'\rm': 'cmr10.ttf', r'\tt': 'cmtt10.ttf'}

Methods inherited from MathText:
draw(self, baseline)
get_bbox(self)
load_glyphs(self)
set_fontfile(self, fontfile)
set_next(self, nx, ny)
Set the pen location where drawing should begin for the
following MathText
set_offsets(self, previous)
Set the offsets assuming previous is the symbol before
you. return a new previous
set_origin(self, ox, oy)
Set the pen location where drawing should begin
set_size(self, size)

Data and other attributes inherited from MathText:
dpi = 200
fontfile = 'cmmi10.ttf'
nx = 0
ny = 0
ox = 0
oy = 0
size = 12

 
class Grp(MathText)
     Methods defined here:
__init__(self, members)
__repr__(self)
get_children(self)

Methods inherited from MathText:
draw(self, baseline)
get_bbox(self)
load_glyphs(self)
set_fontfile(self, fontfile)
set_next(self, nx, ny)
Set the pen location where drawing should begin for the
following MathText
set_offsets(self, previous)
Set the offsets assuming previous is the symbol before
you. return a new previous
set_origin(self, ox, oy)
Set the pen location where drawing should begin
set_size(self, size)

Data and other attributes inherited from MathText:
dpi = 200
fontfile = 'cmmi10.ttf'
nx = 0
ny = 0
ox = 0
oy = 0
size = 12

 
class Handler
     Methods defined here:
expr(self, s, loc, toks)
fontgrp(self, s, loc, toks)
grp(self, s, loc, toks)
singlesym(self, s, loc, toks)
subsupgrp(self, s, loc, toks)

 
class MathText
     Methods defined here:
draw(self, baseline)
get_bbox(self)
get_children(self)
load_glyphs(self)
set_fontfile(self, fontfile)
set_next(self, nx, ny)
Set the pen location where drawing should begin for the
following MathText
set_offsets(self, previous)
Set the offsets assuming previous is the symbol before
you. return a new previous
set_origin(self, ox, oy)
Set the pen location where drawing should begin
set_size(self, size)

Data and other attributes defined here:
dpi = 200
fontfile = 'cmmi10.ttf'
nx = 0
ny = 0
ox = 0
oy = 0
size = 12

 
class Single(MathText)
     Methods defined here:
__init__(self, c)
__repr__(self)
draw(self, baseline)
get_bbox(self)
get_children(self)
load_glyphs(self)
set_fontfile(self, fontfile)
set_offsets(self, previous)
set_size(self, size)

Methods inherited from MathText:
set_next(self, nx, ny)
Set the pen location where drawing should begin for the
following MathText
set_origin(self, ox, oy)
Set the pen location where drawing should begin

Data and other attributes inherited from MathText:
dpi = 200
fontfile = 'cmmi10.ttf'
nx = 0
ny = 0
ox = 0
oy = 0
size = 12

 
class SubSup(MathText)
     Methods defined here:
__init__(self, type, obj)
__repr__(self)
get_children(self)
set_offsets(self, previous)
set_size(self, size)

Methods inherited from MathText:
draw(self, baseline)
get_bbox(self)
load_glyphs(self)
set_fontfile(self, fontfile)
set_next(self, nx, ny)
Set the pen location where drawing should begin for the
following MathText
set_origin(self, ox, oy)
Set the pen location where drawing should begin

Data and other attributes inherited from MathText:
dpi = 200
fontfile = 'cmmi10.ttf'
nx = 0
ny = 0
ox = 0
oy = 0
size = 12

 
Functions
       
FT2Font(...)
FT2Font(ttffile)
 
Create a new FT2Font object; the following global font attributes
are defined
num_faces        # number of faces in file
face_flags       # the face flags as python int
style_flags      # the style flags as python int
num_glyphs       # the number of glyphs in the face
family_name      # the face family name
style_name       # the face syle name
num_fixed_sizes  # the number of embedded bitmap strikes in the current face
 
# the following are only available if face.scalable
bbox                 # the face global bounding box (xmin, ymin, xmax, ymax)
units_per_EM         # number of font units covered by the EM
ascender             # the ascender in 26.6 units
descender            # the descender in 26.6 units
height               # the height in 26.6 units; used to compute a default
                       line spacing (i.e., the baseline-to-baseline distance)  
max_advance_width    # maximum horizontal cursor advance for all glyphs
max_advance_height   # same for vertical layout
underline_position   # vertical position of the underline bar
underline_thickness  # vertical thickness of the underline
math_parse_s(s, dpi, fontsize)
Parse the math expression s, return the (bbox, fonts) tuple needed
to render it.
 
bbox: left, bottom, width, heigt
fonts: a seq of FT2Fonts

 
Data
        False = False
OFFSET_EX10 = 8.0
True = True
alphanums = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
alphas = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
binop = MatchFirst:([MatchFirst:([MatchFirst:(["+", "-"]), "*"]), "/"])
bslash = "\"
cal = "cal"
char = W:(abcd...)
div = "/"
division = _Feature((2, 2, 0, 'alpha', 2), (3, 0, 0, 'alpha', 0), 8192)
equals = "="
expr = OneOrMore:(MatchFirst:([MatchFirst:([MatchFirst:...First:([...]))]), Suppress:("}")]))]))])])))])]))
fontgrp = Group:(And:([Combine:(And:(["\", MatchFirst:([Ma...More:(MatchFirst:([...]))]), Suppress:("}")]))]))
fontname = MatchFirst:([MatchFirst:([MatchFirst:(["rm", "cal"]), "it"]), "tt"])
fonttable = {'(': ('cmex10.ttf', 'A1'), ')': ('cmex10.ttf', 'A2'), '*': ('cmsy10.ttf', 'A4'), '+': ('cmr10.ttf', '2B'), ',': ('cmmi10.ttf', '3B'), '-': ('cmsy10.ttf', 'A1'), '.': ('cmmi10.ttf', '3A'), '/': ('cmmi10.ttf', '3D'), ':': ('cmr10.ttf', '3A'), ';': ('cmr10.ttf', '3B'), ...}
group = MatchFirst:([MatchFirst:([Group:(And:([And:([Sup...tchFirst:([...]))]), Suppress:("}")]))]))])])))])
grouping = MatchFirst:([MatchFirst:([MatchFirst:(["[", "]"]), "("]), ")"])
grp = Group:(And:([And:([Suppress:("{"), OneOrMore:(MatchFirst:([...]))]), Suppress:("}")]))
handler = <matplotlib.mathtext.Handler instance>
italics = "it"
langle = "<"
lbrace = Suppress:("{")
lbrack = "["
lparen = "("
minus = "-"
nums = '0123456789'
overunder = {r'\coprod': 1, r'\int': 1, r'\prod': 1, r'\sum': 1}
plus = "+"
rangle = ">"
rbrace = Suppress:("}")
rbrack = "]"
relation = MatchFirst:([MatchFirst:(["<", ">"]), "="])
roman = "rm"
rparen = ")"
singlesym = MatchFirst:([MatchFirst:([MatchFirst:([MatchFirs...chFirst:([MatchFirst:(["[", "]"]), "("]), ")"])])
subsupgrp = Forward:(Group:(And:([MatchFirst:(["_", "^"]), M...MatchFirst:([...]))]), Suppress:("}")]))]))])])))
superscript = "^"
symbol = MatchFirst:([MatchFirst:([MatchFirst:([MatchFirs...tchFirst:([...]))]), Suppress:("}")]))]))])])))])
texsym = Combine:(And:([And:(["\", W:(abcd...)]), NotAny:(Suppress:("{"))]))
times = "*"
typewriter = "tt"
underscore = "_"


Powered by
YAPTU!
Matlab® is a registered trademark of The MathWorks