mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Allow nonwrapped displaymath.
This commit is contained in:
parent
3204f83dc7
commit
aed6d94008
@ -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
|
||||
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 @@ 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
|
||||
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
|
||||
|
@ -22,6 +22,11 @@ def html_visit_math(self, node):
|
||||
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:
|
||||
|
@ -53,6 +53,7 @@ def math_directive(name, arguments, options, content, lineno,
|
||||
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,6 +68,9 @@ def latex_visit_math(self, node):
|
||||
raise nodes.SkipNode
|
||||
|
||||
def latex_visit_displaymath(self, node):
|
||||
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
|
||||
@ -131,5 +135,5 @@ def setup(app, htmlinlinevisitors, htmldisplayvisitors):
|
||||
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)
|
||||
|
@ -10,6 +10,7 @@
|
||||
"""
|
||||
|
||||
import re
|
||||
import shlex
|
||||
import shutil
|
||||
import tempfile
|
||||
import posixpath
|
||||
@ -95,9 +96,8 @@ def render_math(self, math):
|
||||
tf.write(latex)
|
||||
tf.close()
|
||||
|
||||
ltx_args = [self.builder.config.pngmath_latex,
|
||||
'--interaction=nonstopmode',
|
||||
'--output-directory=' + tempdir,
|
||||
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)
|
||||
@ -116,8 +116,8 @@ def render_math(self, math):
|
||||
|
||||
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,6 +167,9 @@ def html_visit_math(self, node):
|
||||
raise nodes.SkipNode
|
||||
|
||||
def html_visit_displaymath(self, node):
|
||||
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'))
|
||||
|
Loading…
Reference in New Issue
Block a user