[Python-checkins] r65568 - in doctools/trunk: doc/ext/math.rst sphinx/ext/jsmath.py sphinx/ext/mathbase.py sphinx/ext/pngmath.py

georg.brandl python-checkins at python.org
Thu Aug 7 11:17:52 CEST 2008


Author: georg.brandl
Date: Thu Aug  7 11:17:50 2008
New Revision: 65568

Log:
Allow nonwrapped displaymath.


Modified:
   doctools/trunk/doc/ext/math.rst
   doctools/trunk/sphinx/ext/jsmath.py
   doctools/trunk/sphinx/ext/mathbase.py
   doctools/trunk/sphinx/ext/pngmath.py

Modified: doctools/trunk/doc/ext/math.rst
==============================================================================
--- doctools/trunk/doc/ext/math.rst	(original)
+++ doctools/trunk/doc/ext/math.rst	Thu Aug  7 11:17:50 2008
@@ -63,6 +63,18 @@
    to be issued.  See :role:`eqref` for an example.  The numbering style depends
    on the output format.
 
+   There is also an option ``nowrap`` that prevents any wrapping of the given
+   math in a math environment.  When you give this option, you must make sure
+   yourself that the math is properly set up.  For example::
+
+      .. math::
+         :nowrap:
+
+         \begin{eqnarray}
+            y    & = & ax^2 + bx + c \\
+            f(x) & = & x^2 + 2xy + y^2
+         \end{eqnarray}
+
 .. role:: eq
 
    Role for cross-referencing equations via their label.  This currently works
@@ -93,6 +105,9 @@
    may need to set this to a full path if ``latex`` not in the executable search
    path.
 
+   This string is split into words with :func:`shlex.split`, so that you can
+   include arguments as well if needed.
+
    Since this setting is not portable from system to system, it is normally not
    useful to set it in ``conf.py``; rather, giving it on the
    :program:`sphinx-build` command line via the :option:`-D` option should be

Modified: doctools/trunk/sphinx/ext/jsmath.py
==============================================================================
--- doctools/trunk/sphinx/ext/jsmath.py	(original)
+++ doctools/trunk/sphinx/ext/jsmath.py	Thu Aug  7 11:17:50 2008
@@ -22,6 +22,11 @@
     raise nodes.SkipNode
 
 def html_visit_displaymath(self, node):
+    if node['nowrap']:
+        self.body.append(self.starttag(node, 'div', CLASS='math'))
+        self.body.append(node['latex'])
+        self.body.append('</div>')
+        raise nodes.SkipNode
     for i, part in enumerate(node['latex'].split('\n\n')):
         part = self.encode(part)
         if i == 0:

Modified: doctools/trunk/sphinx/ext/mathbase.py
==============================================================================
--- doctools/trunk/sphinx/ext/mathbase.py	(original)
+++ doctools/trunk/sphinx/ext/mathbase.py	Thu Aug  7 11:17:50 2008
@@ -53,6 +53,7 @@
     node = displaymath()
     node['latex'] = latex
     node['label'] = options.get('label', None)
+    node['nowrap'] = 'nowrap' in options
     node['docname'] = state.document.settings.env.docname
     ret = [node]
     if node['label']:
@@ -67,8 +68,11 @@
     raise nodes.SkipNode
 
 def latex_visit_displaymath(self, node):
-    label = node['label'] and node['docname'] + '-' + node['label'] or None
-    self.body.append(wrap_displaymath(node['latex'], label))
+    if node['nowrap']:
+        self.body.append(node['latex'])
+    else:
+        label = node['label'] and node['docname'] + '-' + node['label'] or None
+        self.body.append(wrap_displaymath(node['latex'], label))
     raise nodes.SkipNode
 
 def latex_visit_eqref(self, node):
@@ -131,5 +135,5 @@
     app.add_role('math', math_role)
     app.add_role('eq', eq_role)
     app.add_directive('math', math_directive, 1, (0, 1, 1),
-                      label=directives.unchanged)
+                      label=directives.unchanged, nowrap=directives.flag)
     app.connect('doctree-resolved', number_equations)

Modified: doctools/trunk/sphinx/ext/pngmath.py
==============================================================================
--- doctools/trunk/sphinx/ext/pngmath.py	(original)
+++ doctools/trunk/sphinx/ext/pngmath.py	Thu Aug  7 11:17:50 2008
@@ -10,6 +10,7 @@
 """
 
 import re
+import shlex
 import shutil
 import tempfile
 import posixpath
@@ -95,10 +96,9 @@
     tf.write(latex)
     tf.close()
 
-    ltx_args = [self.builder.config.pngmath_latex,
-                '--interaction=nonstopmode',
-                '--output-directory=' + tempdir,
-                'math.tex']
+    ltx_args = shlex.split(self.builder.config.pngmath_latex)
+    ltx_args += ['--interaction=nonstopmode', '--output-directory=' + tempdir,
+                 'math.tex']
     try:
         p = Popen(ltx_args, stdout=PIPE, stderr=PIPE)
     except OSError, err:
@@ -116,8 +116,8 @@
 
     ensuredir(path.dirname(outfn))
     # use some standard dvipng arguments
-    dvipng_args = [self.builder.config.pngmath_dvipng, '-o', outfn,
-                   '-bg', 'Transparent', '-T', 'tight', '-z9']
+    dvipng_args = shlex.split(self.builder.config.pngmath_dvipng)
+    dvipng_args += ['-o', outfn, '-T', 'tight', '-z9']
     # add custom ones from config value
     dvipng_args.extend(self.builder.config.pngmath_dvipng_args)
     if use_preview:
@@ -167,7 +167,10 @@
     raise nodes.SkipNode
 
 def html_visit_displaymath(self, node):
-    latex = wrap_displaymath(node['latex'], None)
+    if node['nowrap']:
+        latex = node['latex']
+    else:
+        latex = wrap_displaymath(node['latex'], None)
     fname, depth = render_math(self, latex)
     self.body.append(self.starttag(node, 'div', CLASS='math'))
     self.body.append('<p>')


More information about the Python-checkins mailing list