|
From: <md...@us...> - 2008-06-16 17:39:14
|
Revision: 5564
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5564&view=rev
Author: mdboom
Date: 2008-06-16 10:38:08 -0700 (Mon, 16 Jun 2008)
Log Message:
-----------
Support using STIX fonts in math expressions. Use this functionality
to generate a png that used to be static.
Modified Paths:
--------------
trunk/matplotlib/doc/sphinxext/mathpng.py
trunk/matplotlib/doc/users/mathtext.rst
Removed Paths:
-------------
trunk/matplotlib/doc/_static/stix_fonts.png
Deleted: trunk/matplotlib/doc/_static/stix_fonts.png
===================================================================
(Binary files differ)
Modified: trunk/matplotlib/doc/sphinxext/mathpng.py
===================================================================
--- trunk/matplotlib/doc/sphinxext/mathpng.py 2008-06-16 17:21:39 UTC (rev 5563)
+++ trunk/matplotlib/doc/sphinxext/mathpng.py 2008-06-16 17:38:08 UTC (rev 5564)
@@ -5,6 +5,7 @@
from md5 import md5
from docutils import nodes
+from docutils.parsers.rst import directives
from docutils.writers.html4css1 import HTMLTranslator
from sphinx.latexwriter import LaTeXTranslator
@@ -12,14 +13,27 @@
class latex_math(nodes.General, nodes.Element):
pass
+def fontset_choice(arg):
+ return directives.choice(arg, ['cm', 'stix', 'stixsans'])
+
+options_spec = {'fontset': fontset_choice}
+
def math_role(role, rawtext, text, lineno, inliner,
options={}, content=[]):
i = rawtext.find('`')
latex = rawtext[i+1:-1]
node = latex_math(rawtext)
node['latex'] = latex
+ node['fontset'] = options.get('fontset', 'cm')
return [node], []
+math_role.options = options_spec
+def math_directive_run(content, block_text, options):
+ latex = ''.join(content)
+ node = latex_math(block_text)
+ node['latex'] = latex
+ node['fontset'] = options.get('fontset', 'cm')
+ return [node]
try:
from docutils.parsers.rst import Directive
@@ -28,22 +42,19 @@
from docutils.parsers.rst.directives import _directives
def math_directive(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine):
- latex = ''.join(content)
- node = latex_math(block_text)
- node['latex'] = latex
- return [node]
+ return math_directive_run(content, block_text, options)
math_directive.arguments = None
- math_directive.options = {}
+ math_directive.options = options_spec
math_directive.content = 1
_directives['math'] = math_directive
else:
class math_directive(Directive):
has_content = True
+ option_spec = options_spec
+
def run(self):
- latex = ' '.join(self.content)
- node = latex_math(self.block_text)
- node['latex'] = latex
- return [node]
+ return math_directive_run(self.content, self.block_text,
+ self.options)
from docutils.parsers.rst import directives
directives.register_directive('math', math_directive)
@@ -100,12 +111,14 @@
# This uses mathtext to render the expression
-def latex2png(latex, filename):
+def latex2png(latex, filename, fontset='cm'):
if os.path.exists(filename):
return
+ orig_fontset = rcParams['mathtext.fontset']
+ rcParams['mathtext.fontset'] = fontset
mathtext_parser.to_png(filename, "$%s$" % latex, dpi=120)
+ rcParams['mathtext.fontset'] = orig_fontset
-
# LaTeX to HTML translation stuff:
def latex2html(node, source):
inline = isinstance(node.parent, nodes.TextElement)
@@ -114,7 +127,7 @@
name = 'math-%s' % md5(latex).hexdigest()[-10:]
dest = '_static/%s.png' % name
if not isfile(dest):
- latex2png(latex, dest)
+ latex2png(latex, dest, node['fontset'])
path = '_static'
count = source.split('/doc/')[-1].count('/')
Modified: trunk/matplotlib/doc/users/mathtext.rst
===================================================================
--- trunk/matplotlib/doc/users/mathtext.rst 2008-06-16 17:21:39 UTC (rev 5563)
+++ trunk/matplotlib/doc/users/mathtext.rst 2008-06-16 17:38:08 UTC (rev 5564)
@@ -147,22 +147,39 @@
The choices available with all fonts are:
- =============== =================================
- Command Result
- =============== =================================
- ``\mathrm`` :math:`\mathrm{Roman}`
- ``\mathit`` :math:`\mathit{Italic}`
- ``\mathtt`` :math:`\mathtt{Typewriter}`
- ``\mathcal`` :math:`\mathcal{CALLIGRAPHY}`
- =============== =================================
+ ============================ ==================================
+ Command Result
+ ============================ ==================================
+ ``\mathrm{Roman}`` :math:`\mathrm{Roman}`
+ ``\mathit{Italic}`` :math:`\mathit{Italic}`
+ ``\mathtt{Typewriter}`` :math:`\mathtt{Typewriter}`
+ ``\mathcal{CALLIGRAPHY}`` :math:`\mathcal{CALLIGRAPHY}`
+ ============================ ==================================
+.. role:: math-stix(math)
+ :fontset: stix
+
When using the STIX fonts, you also have the choice of:
-.. image:: ../_static/stix_fonts.png
+ ====================================== =========================================
+ Command Result
+ ====================================== =========================================
+ ``\mathbb{blackboard}`` :math-stix:`\mathbb{blackboard}`
+ ``\mathrm{\mathbb{blackboard}}`` :math-stix:`\mathrm{\mathbb{blackboard}}`
+ ``\mathfrak{Fraktur}`` :math-stix:`\mathfrak{Fraktur}`
+ ``\mathsf{sansserif}`` :math-stix:`\mathsf{sansserif}`
+ ``\mathrm{\mathsf{sansserif}}`` :math-stix:`\mathrm{\mathsf{sansserif}}`
+ ====================================== =========================================
+.. htmlonly::
+
+ ====================================== =========================================
+ ``\mathcircled{circled}`` :math-stix:`\mathcircled{circled}`
+ ====================================== =========================================
+
There are also three global "font sets" to choose from, which are
selected using the ``mathtext.fontset`` parameter in
-::ref:`matplotlibrc <matplotlibrc-sample>`.
+:ref:`matplotlibrc <matplotlibrc-sample>`.
``cm``: **Computer Modern (TeX)**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|