diff options
| author | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2011-06-29 16:24:09 +0000 |
|---|---|---|
| committer | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2011-06-29 16:24:09 +0000 |
| commit | 4abdb954c24afbe53b4be081fe4714450029a9be (patch) | |
| tree | 0e43b5165c187d72ade5afde668390120a7d7d2d | |
| parent | 0213b9dcba4dd54bff7c6f38bb4a04a84c4769ce (diff) | |
| download | docutils-4abdb954c24afbe53b4be081fe4714450029a9be.tar.gz | |
math update
latex2e writer: set label if node has a name attribute
html4css1 writer: do not wrap inline <math>
functional test: adapt expected output to last changes
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@7061 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
| -rw-r--r-- | docutils/docs/user/config.txt | 3 | ||||
| -rw-r--r-- | docutils/docutils/writers/html4css1/__init__.py | 8 | ||||
| -rw-r--r-- | docutils/docutils/writers/latex2e/__init__.py | 2 | ||||
| -rw-r--r-- | docutils/test/functional/expected/math_output_mathml.xhtml | 18 |
4 files changed, 27 insertions, 4 deletions
diff --git a/docutils/docs/user/config.txt b/docutils/docs/user/config.txt index 618d20dad..6bebf143b 100644 --- a/docutils/docs/user/config.txt +++ b/docutils/docs/user/config.txt @@ -737,7 +737,8 @@ _`math_output` Pro: Works 'out of the box' across multiple browsers and platforms. - Supports a large subset of LaTeX math commands and constructs. + Supports a large subset of LaTeX math commands and constructs + (see http://www.mathjax.org/docs/1.1/tex.html). Con: Requires an Internet connection or a local MathJax diff --git a/docutils/docutils/writers/html4css1/__init__.py b/docutils/docutils/writers/html4css1/__init__.py index 54376f5a8..81490d388 100644 --- a/docutils/docutils/writers/html4css1/__init__.py +++ b/docutils/docutils/writers/html4css1/__init__.py @@ -1136,7 +1136,7 @@ class HTMLTranslator(nodes.NodeVisitor): # # HTML container tags = {# math_output: (block, inline, class-arguments) - 'mathml': ('div', 'span', ''), + 'mathml': ('div', '', ''), 'html': ('div', 'span', 'formula'), 'mathjax': ('div', 'span', 'math'), 'latex': ('pre', 'tt', 'math'), @@ -1183,11 +1183,13 @@ class HTMLTranslator(nodes.NodeVisitor): self.depart_system_message(err_node) raise nodes.SkipNode # append to document body - self.body.append(self.starttag(node, tag, CLASS=clsarg)) + if tag: + self.body.append(self.starttag(node, tag, CLASS=clsarg)) self.body.append(math_code) if math_env: self.body.append('\n') - self.body.append('</%s>\n' % tag) + if tag: + self.body.append('</%s>\n' % tag) # Content already processed: raise nodes.SkipNode diff --git a/docutils/docutils/writers/latex2e/__init__.py b/docutils/docutils/writers/latex2e/__init__.py index 8de5447fd..66e2549bb 100644 --- a/docutils/docutils/writers/latex2e/__init__.py +++ b/docutils/docutils/writers/latex2e/__init__.py @@ -2431,6 +2431,8 @@ class LaTeXTranslator(nodes.NodeVisitor): self.visit_inline(node) self.requirements['amsmath'] = r'\usepackage{amsmath}' math_code = node.astext().translate(unimathsymbols2tex.uni2tex_table) + if node.get('id') == node.get('name'): # explicite label + math_code = '\n'.join([math_code] + self.ids_to_labels(node)) if math_env == '$': wrapper = u'$%s$' else: diff --git a/docutils/test/functional/expected/math_output_mathml.xhtml b/docutils/test/functional/expected/math_output_mathml.xhtml index 27d738121..1e949a0a5 100644 --- a/docutils/test/functional/expected/math_output_mathml.xhtml +++ b/docutils/test/functional/expected/math_output_mathml.xhtml @@ -18,6 +18,7 @@ role specificator, <math xmlns="http://www.w3.org/1998/Math/MathML"> <mrow><mi>π</mi></mrow> <mrow><mn>4</mn></mrow></mfrac><msup><mi>d</mi><mn>2</mn></msup></mrow></math>, as well as displayed math via the <cite>math</cite> directive:</p> +<div> <math xmlns="http://www.w3.org/1998/Math/MathML" mode="display"> <mtable> <mtr> @@ -27,14 +28,18 @@ role specificator, <math xmlns="http://www.w3.org/1998/Math/MathML"> <mrow><mfrac> <mrow><mi>ε</mi></mrow> <mrow><msub><mi>k</mi><mtext>B</mtext></msub><mi>T</mi></mrow></mfrac></mrow></mfenced></mrow></mfrac></mtd></mtr></mtable></math> +</div> <p>A display formula can also be given as directive argument, e.g.</p> +<div> <math xmlns="http://www.w3.org/1998/Math/MathML" mode="display"> <mtable> <mtr> <mtd><mi>N</mi><mo>=</mo><mfrac> <mrow><mtext>number of apples</mtext></mrow> <mrow><mn>7</mn></mrow></mfrac></mtd></mtr></mtable></math> +</div> <p>The determinant of the matrix</p> +<div> <math xmlns="http://www.w3.org/1998/Math/MathML" mode="display"> <mtable> <mtr> @@ -48,17 +53,21 @@ role specificator, <math xmlns="http://www.w3.org/1998/Math/MathML"> <mtr> <mtd><mi>c</mi></mtd> <mtd><mi>d</mi></mtd></mtr></mtable></mrow></mfenced></mtd></mtr></mtable></math> +</div> <p>is <math xmlns="http://www.w3.org/1998/Math/MathML"> <mrow><mo>|</mo><mstyle fontweight="bold"> <mrow><mi>M</mi></mrow></mstyle><mo>|</mo><mo>=</mo><mi>a</mi><mi>d</mi><mo>-</mo><mi>b</mi><mi>c</mi></mrow></math>.</p> <p>More than one display math block can be put in one math directive. For example, the following sum and integral with limits:</p> +<div> <math xmlns="http://www.w3.org/1998/Math/MathML" mode="display"> <mtable> <mtr> <mtd><munderover><mo>∫</mo><mn>0</mn><mn>1</mn></munderover><msup><mi>x</mi><mi>n</mi></msup><mi>d</mi><mi>x</mi><mo>=</mo><mfrac> <mrow><mn>1</mn></mrow> <mrow><mi>n</mi><mo>+</mo><mn>1</mn></mrow></mfrac></mtd></mtr></mtable></math> +</div> +<div> <math xmlns="http://www.w3.org/1998/Math/MathML" mode="display"> <mtable> <mtr> @@ -66,9 +75,11 @@ For example, the following sum and integral with limits:</p> <mrow><mi>n</mi><mo>=</mo><mn>1</mn></mrow><mi>m</mi></munderover><mi>n</mi><mo>=</mo><mfrac> <mrow><mi>m</mi><mo>(</mo><mi>m</mi><mo>+</mo><mn>1</mn><mo>)</mo></mrow> <mrow><mn>2</mn></mrow></mfrac></mtd></mtr></mtable></math> +</div> <p>LaTeX-supported Unicode math symbols can be used in math roles and directives:</p> <p>The Schrödinger equation</p> +<div> <math xmlns="http://www.w3.org/1998/Math/MathML" mode="display"> <mtable> <mtr> @@ -76,6 +87,7 @@ directives:</p> <mrow><mo>∂</mo></mrow> <mrow><mo>∂</mo><mi>t</mi></mrow></mfrac><mo>Ψ</mo><mo>=</mo><mover> <mrow><mi>H</mi></mrow><mo>^</mo></mover><mo>Ψ</mo><mo>,</mo></mtd></mtr></mtable></math> +</div> <p>with the <em>wave function</em> <math xmlns="http://www.w3.org/1998/Math/MathML"> <mrow><mo>Ψ</mo></mrow></math>, describes how the quantum state of a physical system changes in time.</p> @@ -135,6 +147,7 @@ physical system changes in time.</p> <!-- \widetilde{xxx} \widehat{xxx} --> <p>Modulation Transfer Function:</p> +<div> <math xmlns="http://www.w3.org/1998/Math/MathML" mode="display"> <mtable> <mtr> @@ -155,9 +168,11 @@ physical system changes in time.</p> <mrow><mo>-</mo><mo>∞</mo></mrow> <mrow><mo>∞</mo></mrow></munderover><mi>s</mi><mo>(</mo><mi>x</mi><mo>)</mo><mtext>d</mtext> <mrow><mi>x</mi></mrow></mrow></mfrac></mrow></mfenced><mo>.</mo></mtd></mtr></mtable></math> +</div> <p>Math split over two lines: If a double backslash is detected outside a <tt class="docutils literal"><span class="pre">\begin{...}</span> <span class="pre">\end{...}</span></tt> pair, the math code is wrapped in an <a class="reference external" href="ftp://ftp.ams.org/ams/doc/amsmath/short-math-guide.pdf">AMSmath</a> <tt class="docutils literal">align</tt> environment:</p> +<div> <math xmlns="http://www.w3.org/1998/Math/MathML" mode="display"> <mtable> <mtr> @@ -169,7 +184,9 @@ physical system changes in time.</p> <mtd></mtd> <mtd><mo>=</mo><mo>∫</mo><msub><mi>s</mi> <mrow><mtext>in</mtext></mrow></msub><mo>(</mo><mi>x</mi><mo>'</mo><mo>)</mo><msub><mi>s</mi><mi>δ</mi></msub><mo>(</mo><mi>x</mi><mo>-</mo><mi>x</mi><mo>'</mo><mo>)</mo><mtext>d</mtext><mi>x</mi><mo>'</mo></mtd></mtr></mtable></math> +</div> <p>Cases ("manually", with <tt class="docutils literal">matrix</tt> environment):</p> +<div> <math xmlns="http://www.w3.org/1998/Math/MathML" mode="display"> <mtable> <mtr> @@ -182,6 +199,7 @@ physical system changes in time.</p> <mtr> <mtd><mn>1</mn></mtd> <mtd><mi>x</mi><mo>></mo><mn>0</mn></mtd></mtr></mtable></mrow></mfenced></mtd></mtr></mtable></math> +</div> <p>Cases with the <a class="reference external" href="ftp://ftp.ams.org/ams/doc/amsmath/short-math-guide.pdf">AMSmath</a> <tt class="docutils literal">cases</tt> environment (not (yet) supported by HTML writers with <tt class="docutils literal"><span class="pre">--math-output=MathML</span></tt>):</p> <div class="system-message"> |
