diff --git a/doc/ext/math.rst b/doc/ext/math.rst index 3218df580..325dfd3a9 100644 --- a/doc/ext/math.rst +++ b/doc/ext/math.rst @@ -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 diff --git a/sphinx/ext/jsmath.py b/sphinx/ext/jsmath.py index f22d34fd7..de5332f90 100644 --- a/sphinx/ext/jsmath.py +++ b/sphinx/ext/jsmath.py @@ -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('') + raise nodes.SkipNode for i, part in enumerate(node['latex'].split('\n\n')): part = self.encode(part) if i == 0: diff --git a/sphinx/ext/mathbase.py b/sphinx/ext/mathbase.py index 04136652b..fc002c604 100644 --- a/sphinx/ext/mathbase.py +++ b/sphinx/ext/mathbase.py @@ -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,8 +68,11 @@ def latex_visit_math(self, node): 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 @@ 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) diff --git a/sphinx/ext/pngmath.py b/sphinx/ext/pngmath.py index 853f37de3..4e16b9f3e 100644 --- a/sphinx/ext/pngmath.py +++ b/sphinx/ext/pngmath.py @@ -10,6 +10,7 @@ """ import re +import shlex import shutil import tempfile import posixpath @@ -95,10 +96,9 @@ def render_math(self, math): 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 @@ 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,7 +167,10 @@ def html_visit_math(self, node): 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('

')