@header@
matplotlib.mathtext | index /usr/local/lib/python2.3/site-packages/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.
The spacing elements \/ and \hspace{num} are provided. \/ inserts a
small space, and \hspace{num} inserts a fraction of the current
fontsize. Eg, if num=0.5 and the fontsize is 12.0, hspace{0.5}
inserts 6 points of space
If you find TeX expressions that don't parse or render properly,
please email me, but please check KNOWN ISSUES below first.
REQUIREMENTS
mathtext requires matplotlib.ft2font. Set BUILD_FT2FONT=True in
setup.py. See BACKENDS below for a summary of availability by
backend.
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
and the file BaKoMa-CM.Fonts in the matplotlib fonts dir.
Note that all the code in this module is distributed under the
matplotlib license, and a truly free implementation of mathtext for
either freetype or ps would simply require deriving another concrete
implementation from the Fonts class defined in this module which
used free fonts.
USAGE:
See http://matplotlib.sourceforge.net/tutorial.html#mathtext for a
tutorial introduction.
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. 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 \angstrom \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 \hspace \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 GTK, Agg, GTKAgg, TkAgg and WxAgg. If
David incorporates ft2font into paint, it will be easy to add to
Paint. WX can follow the lead of GTK and use pixels API calls to
use mathtext.
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:
- FIXED in 0.54 - some hackish ways I deal with a strange offset in cmex10
- nested subscripts, eg, x_i_j not working; but you can do x_{i_j}
- nesting fonts changes in sub/superscript groups not parsing
- I would also like to add a few more layout commands, like \frac.
Author : John Hunter <jdhunter@ace.bsd.uchicago.edu>
Copyright : John Hunter (2004)
License : matplotlib license (PSF compatible)
Modules | ||||||
|
Classes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Functions | ||
|
Data | ||
False = False True = True absolute = <ufunc 'absolute'> alphanums = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' alphas = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' ampersand = "&" ams_type1 = {'(': ('cmex10', '28'), ')': ('cmex10', '29'), '*': ('cmsy10', '03'), '+': ('cmex10', '2B'), ',': ('cmmi10', '3B'), '-': ('cmsy10', '00'), '.': ('cmmi10', '3A'), '/': ('cmmi10', '3D'), '0': ('cmex10', '30'), '1': ('cmex10', '31'), ...} at = "@" bakoma_truetype = {'(': ('cmr10', '28'), ')': ('cmr10', '29'), '*': ('cmsy10', 'A4'), '+': ('cmr10', '2B'), ',': ('cmmi10', '3B'), '-': ('cmsy10', 'A1'), '.': ('cmmi10', '3A'), '/': ('cmmi10', '3D'), '0': ('cmr10', '30'), '1': ('cmr10', '31'), ...} binop = {{{"+" | "-"} | "*"} | "/"} bslash = "\" cal = "cal" char = W:(abcd...) charOverChars = {r'\angstrom': (('rm', 'A', 1.0), (None, r'\circ', 0.5), 0.0)} colon = ":" comma = "," div = "/" division = _Feature((2, 2, 0, 'alpha', 2), (3, 0, 0, 'alpha', 0), 8192) equals = "=" exclamation = "!" expression = expression font = font fontname = {{{"rm" | "cal"} | "it"} | "tt"} group = group grouping = {{{"[" | "]"} | "("} | ")"} handler = <matplotlib.mathtext.Handler instance> italics = "it" langle = "<" lbrace = Suppress:("{") lbrack = "[" lparen = "(" minus = "-" misc = {{{"!" | "@"} | "%"} | "&"} number = Combine:({{W:(0123...) ["."]} [W:(0123...)]}) nums = '0123456789' overunder = {r'\coprod': 1, r'\int': 1, r'\prod': 1, r'\sum': 1} percent = "%" period = "." plus = "+" punctuation = {{{":" | ","} | "."} | ";"} rangle = ">" rbrace = Suppress:("}") rbrack = "]" relation = {{"<" | ">"} | "="} roman = "rm" rparen = ")" semicolon = ";" space = space subscript = subscript subsuperscript = subsuperscript superscript = superscript symbol = {{{{{{Combine:({{"\" W:(abcd...)} ~{Suppress:("{...@"} | "%"} | "&"}} ^ {{{"[" | "]"} | "("} | ")"}} symgroup = {{{{{{{Combine:({{"\" W:(abcd...)} ~{Suppress:("...} | "&"}} ^ {{{"[" | "]"} | "("} | ")"}} ^ group} texsym = Combine:({{"\" W:(abcd...)} ~{Suppress:("{")}}) times = "*" typewriter = "tt" |