Allow nonwrapped displaymath.

This commit is contained in:
Georg Brandl 2008-08-07 09:17:50 +00:00
parent 3204f83dc7
commit aed6d94008
4 changed files with 37 additions and 10 deletions

View File

@ -63,6 +63,18 @@ further translation is necessary when building LaTeX output.
to be issued. See :role:`eqref` for an example. The numbering style depends to be issued. See :role:`eqref` for an example. The numbering style depends
on the output format. 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:: eq
Role for cross-referencing equations via their label. This currently works Role for cross-referencing equations via their label. This currently works
@ -93,6 +105,9 @@ There are various config values you can set to influence how the images are buil
may need to set this to a full path if ``latex`` not in the executable search may need to set this to a full path if ``latex`` not in the executable search
path. 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 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 useful to set it in ``conf.py``; rather, giving it on the
:program:`sphinx-build` command line via the :option:`-D` option should be :program:`sphinx-build` command line via the :option:`-D` option should be

View File

@ -22,6 +22,11 @@ def html_visit_math(self, node):
raise nodes.SkipNode raise nodes.SkipNode
def html_visit_displaymath(self, node): 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')): for i, part in enumerate(node['latex'].split('\n\n')):
part = self.encode(part) part = self.encode(part)
if i == 0: if i == 0:

View File

@ -53,6 +53,7 @@ def math_directive(name, arguments, options, content, lineno,
node = displaymath() node = displaymath()
node['latex'] = latex node['latex'] = latex
node['label'] = options.get('label', None) node['label'] = options.get('label', None)
node['nowrap'] = 'nowrap' in options
node['docname'] = state.document.settings.env.docname node['docname'] = state.document.settings.env.docname
ret = [node] ret = [node]
if node['label']: if node['label']:
@ -67,8 +68,11 @@ def latex_visit_math(self, node):
raise nodes.SkipNode raise nodes.SkipNode
def latex_visit_displaymath(self, node): def latex_visit_displaymath(self, node):
label = node['label'] and node['docname'] + '-' + node['label'] or None if node['nowrap']:
self.body.append(wrap_displaymath(node['latex'], label)) 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 raise nodes.SkipNode
def latex_visit_eqref(self, node): def latex_visit_eqref(self, node):
@ -131,5 +135,5 @@ def setup(app, htmlinlinevisitors, htmldisplayvisitors):
app.add_role('math', math_role) app.add_role('math', math_role)
app.add_role('eq', eq_role) app.add_role('eq', eq_role)
app.add_directive('math', math_directive, 1, (0, 1, 1), 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) app.connect('doctree-resolved', number_equations)

View File

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