|
From: <mi...@us...> - 2021-05-20 12:19:54
|
Revision: 8740
http://sourceforge.net/p/docutils/code/8740
Author: milde
Date: 2021-05-20 12:19:54 +0000 (Thu, 20 May 2021)
Log Message:
-----------
MathML: Implement "cases" environment in latex2mathml.
Modified Paths:
--------------
trunk/docutils/docutils/utils/math/latex2mathml.py
trunk/docutils/test/functional/expected/latex_memoir.tex
trunk/docutils/test/functional/expected/math_output_html.html
trunk/docutils/test/functional/expected/math_output_latex.html
trunk/docutils/test/functional/expected/math_output_mathjax.html
trunk/docutils/test/functional/expected/math_output_mathml.html
trunk/docutils/test/functional/expected/standalone_rst_latex.tex
trunk/docutils/test/functional/expected/standalone_rst_xetex.tex
trunk/docutils/test/functional/input/data/math.txt
Modified: trunk/docutils/docutils/utils/math/latex2mathml.py
===================================================================
--- trunk/docutils/docutils/utils/math/latex2mathml.py 2021-05-20 12:19:35 UTC (rev 8739)
+++ trunk/docutils/docutils/utils/math/latex2mathml.py 2021-05-20 12:19:54 UTC (rev 8740)
@@ -222,12 +222,10 @@
self.children = []
if children is not None:
- if isinstance(children, list):
- for child in children:
- self.append(child)
- else:
- # Only one child:
- self.append(children)
+ if not isinstance(children, list):
+ children = [children]
+ for child in children:
+ self.append(child)
self.attributes = collections.OrderedDict()
if inline is not None:
@@ -547,19 +545,31 @@
string = string[1:]
skip = 1
if name == 'begin':
- if not string.startswith('{matrix}'):
+ if string.startswith('{matrix}'):
+ skip += 8
+ entry = mtd()
+ table = mtable(mtr(entry))
+ node.append(table)
+ node = entry
+ elif string.startswith('{cases}'):
+ skip += 7
+ entry = mtd()
+ cases = mrow([mo('{'), mtable(mtr(entry))])
+ node.append(cases)
+ node = entry
+ else:
raise SyntaxError(u'Environment not supported! '
- u'Supported environment: "matrix".')
- skip += 8
- entry = mtd()
- table = mtable(mtr(entry))
- node.append(table)
- node = entry
+ u'Supported environments: "matrix", "cases".')
elif name == 'end':
- if not string.startswith('{matrix}'):
- raise SyntaxError(u'Expected "\\end{matrix}"!')
- skip += 8
- node = node.close().close().close()
+ if string.startswith('{matrix}'):
+ skip += 8
+ node = node.close().close().close()
+ elif string.startswith('{cases}'):
+ skip += 7
+ node = node.close().close().close().close()
+ else:
+ raise SyntaxError(u'Environment not supported! '
+ u'Supported environments: "matrix", "cases".')
elif name in ('text', 'mathrm'):
if string[0] != '{':
raise SyntaxError(u'Expected "\\text{...}"!')
@@ -585,7 +595,8 @@
row = mrow()
node.append(row)
node = row
- node.append(mo(fence_args[par]))
+ if par != '.':
+ node.append(mo(fence_args[par]))
skip += len(par)
elif name == 'right':
for par in fence_args.keys():
@@ -593,7 +604,8 @@
break
else:
raise SyntaxError(u'Missing right-brace!')
- node.append(mo(fence_args[par]))
+ if par != '.':
+ node.append(mo(fence_args[par]))
node = node.close()
skip += len(par)
elif name == 'not':
Modified: trunk/docutils/test/functional/expected/latex_memoir.tex
===================================================================
--- trunk/docutils/test/functional/expected/latex_memoir.tex 2021-05-20 12:19:35 UTC (rev 8739)
+++ trunk/docutils/test/functional/expected/latex_memoir.tex 2021-05-20 12:19:54 UTC (rev 8740)
@@ -1908,18 +1908,9 @@
s_{\mathrm{out}}(x) & = s_{\mathrm{in}}(x') * s_\delta (x-x') \\
& = \int s_{\mathrm{in}}(x')s_\delta (x-x')\mathrm{d}x'
\end{align*}
-Cases (\textquotedbl{}manually\textquotedbl{}, with \texttt{matrix} environment):
+Cases with the \href{ftp://ftp.ams.org/ams/doc/amsmath/short-math-guide.pdf}{AMSmath}\DUfootnotemark{footnote-reference-15}{footnote-8}{7} \texttt{cases} environment:
%
\begin{equation*}
-\mathrm{sgn}(x) = \left\{\begin{matrix}
- -1 & x<0\\
- 1 & x>0
- \end{matrix}\right.
-\end{equation*}
-Cases with the \href{ftp://ftp.ams.org/ams/doc/amsmath/short-math-guide.pdf}{AMSmath}\DUfootnotemark{footnote-reference-15}{footnote-8}{7} \texttt{cases} environment (not (yet) supported by
-HTML writers with \texttt{-{}-math-output=MathML}):
-%
-\begin{equation*}
\mathrm{sgn}(x) = \begin{cases}
-1 & x<0\\
1 & x>0
Modified: trunk/docutils/test/functional/expected/math_output_html.html
===================================================================
--- trunk/docutils/test/functional/expected/math_output_html.html 2021-05-20 12:19:35 UTC (rev 8739)
+++ trunk/docutils/test/functional/expected/math_output_html.html 2021-05-20 12:19:54 UTC (rev 8740)
@@ -140,40 +140,8 @@
</span>
</span>
</div>
-<p>Cases ("manually", with <tt class="docutils literal">matrix</tt> environment):</p>
+<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:</p>
<div class="formula">
-<span class="mathrm">sgn</span>(<i>x</i>) = <span class="array"><span class="arrayrow"><span class="bracket align-left">⎧</span></span><span class="arrayrow"><span class="bracket align-left">⎨</span></span><span class="arrayrow"><span class="bracket align-left">⎩</span></span></span><span class="array"><span class="arrayrow">
-<span class="arraycell align-c">
- − 1
-</span>
-<span class="arraycell align-c">
-<i>x</i> < 0
-</span>
-
-</span>
-<span class="arrayrow">
-<span class="arraycell align-c">
-
-</span>
-<span class="arraycell align-c">
-
-</span>
-
-</span>
-<span class="arrayrow">
-<span class="arraycell align-c">
-1
-</span>
-<span class="arraycell align-c">
-<i>x</i> > 0
-</span>
-
-</span>
-</span><span class="emptydot"></span>
-</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="formula">
<span class="mathrm">sgn</span>(<i>x</i>) = <span class="array"><span class="arrayrow"><span class="bracket align-l">⎧</span></span><span class="arrayrow"><span class="bracket align-l">⎨</span></span><span class="arrayrow"><span class="bracket align-l">⎩</span></span></span><span class="bracketcases">
<span class="arrayrow">
<span class="case align-l">
Modified: trunk/docutils/test/functional/expected/math_output_latex.html
===================================================================
--- trunk/docutils/test/functional/expected/math_output_latex.html 2021-05-20 12:19:35 UTC (rev 8739)
+++ trunk/docutils/test/functional/expected/math_output_latex.html 2021-05-20 12:19:54 UTC (rev 8740)
@@ -92,16 +92,8 @@
s_{\mathrm{out}}(x) & = s_{\mathrm{in}}(x') * s_\delta (x-x') \\
& = \int s_{\mathrm{in}}(x')s_\delta (x-x')\mathrm{d}x'
</pre>
-<p>Cases ("manually", with <tt class="docutils literal">matrix</tt> environment):</p>
+<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:</p>
<pre class="math">
-\mathrm{sgn}(x) = \left\{\begin{matrix}
- -1 & x<0\\
- 1 & x>0
- \end{matrix}\right.
-</pre>
-<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>
-<pre class="math">
\mathrm{sgn}(x) = \begin{cases}
-1 & x<0\\
1 & x>0
Modified: trunk/docutils/test/functional/expected/math_output_mathjax.html
===================================================================
--- trunk/docutils/test/functional/expected/math_output_mathjax.html 2021-05-20 12:19:35 UTC (rev 8739)
+++ trunk/docutils/test/functional/expected/math_output_mathjax.html 2021-05-20 12:19:54 UTC (rev 8740)
@@ -109,19 +109,9 @@
& = \int s_{\mathrm{in}}(x')s_\delta (x-x')\mathrm{d}x'
\end{align*}
</div>
-<p>Cases ("manually", with <tt class="docutils literal">matrix</tt> environment):</p>
+<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:</p>
<div class="math">
\begin{equation*}
-\mathrm{sgn}(x) = \left\{\begin{matrix}
- -1 & x<0\\
- 1 & x>0
- \end{matrix}\right.
-\end{equation*}
-</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="math">
-\begin{equation*}
\mathrm{sgn}(x) = \begin{cases}
-1 & x<0\\
1 & x>0
Modified: trunk/docutils/test/functional/expected/math_output_mathml.html
===================================================================
--- trunk/docutils/test/functional/expected/math_output_mathml.html 2021-05-20 12:19:35 UTC (rev 8739)
+++ trunk/docutils/test/functional/expected/math_output_mathml.html 2021-05-20 12:19:54 UTC (rev 8740)
@@ -515,7 +515,7 @@
</mtable>
</math>
</div>
-<p>Cases ("manually", with <span class="docutils literal">matrix</span> environment):</p>
+<p>Cases with the <a class="reference external" href="ftp://ftp.ams.org/ams/doc/amsmath/short-math-guide.pdf">AMSmath</a> <span class="docutils literal">cases</span> environment:</p>
<div>
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mtable class="align" displaystyle="true">
@@ -542,7 +542,6 @@
</mtd>
</mtr>
</mtable>
- <mo></mo>
</mrow>
</mtd>
</mtr>
@@ -549,19 +548,6 @@
</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> <span class="docutils literal">cases</span> environment (not (yet) supported by
-HTML writers with <span class="docutils literal"><span class="pre">--math-output=MathML</span></span>):</p>
-<div class="system-message">
-<p class="system-message-title">System Message: ERROR/3 (<span class="docutils literal">functional/input/data/math.txt</span>, line 108)</p>
-<p>
-Environment not supported! Supported environment: "matrix".</p>
-<pre class="literal-block">
-\mathrm{sgn}(x) = \begin{cases}
- -1 & x<0\\
- 1 & x>0
- \end{cases}
-</pre>
-</div>
</main>
</body>
</html>
Modified: trunk/docutils/test/functional/expected/standalone_rst_latex.tex
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_latex.tex 2021-05-20 12:19:35 UTC (rev 8739)
+++ trunk/docutils/test/functional/expected/standalone_rst_latex.tex 2021-05-20 12:19:54 UTC (rev 8740)
@@ -1930,18 +1930,9 @@
s_{\mathrm{out}}(x) & = s_{\mathrm{in}}(x') * s_\delta (x-x') \\
& = \int s_{\mathrm{in}}(x')s_\delta (x-x')\mathrm{d}x'
\end{align*}
-Cases (“manually”, with \texttt{matrix} environment):
+Cases with the \href{ftp://ftp.ams.org/ams/doc/amsmath/short-math-guide.pdf}{AMSmath}\DUfootnotemark{footnote-reference-15}{footnote-8}{7} \texttt{cases} environment:
%
\begin{equation*}
-\mathrm{sgn}(x) = \left\{\begin{matrix}
- -1 & x<0\\
- 1 & x>0
- \end{matrix}\right.
-\end{equation*}
-Cases with the \href{ftp://ftp.ams.org/ams/doc/amsmath/short-math-guide.pdf}{AMSmath}\DUfootnotemark{footnote-reference-15}{footnote-8}{7} \texttt{cases} environment (not (yet) supported by
-HTML writers with \texttt{-{}-math-output=MathML}):
-%
-\begin{equation*}
\mathrm{sgn}(x) = \begin{cases}
-1 & x<0\\
1 & x>0
Modified: trunk/docutils/test/functional/expected/standalone_rst_xetex.tex
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_xetex.tex 2021-05-20 12:19:35 UTC (rev 8739)
+++ trunk/docutils/test/functional/expected/standalone_rst_xetex.tex 2021-05-20 12:19:54 UTC (rev 8740)
@@ -1796,18 +1796,9 @@
s_{\mathrm{out}}(x) & = s_{\mathrm{in}}(x') * s_\delta (x-x') \\
& = \int s_{\mathrm{in}}(x')s_\delta (x-x')\mathrm{d}x'
\end{align*}
-Cases (“manually”, with \texttt{matrix} environment):
+Cases with the \href{ftp://ftp.ams.org/ams/doc/amsmath/short-math-guide.pdf}{AMSmath}\DUfootnotemark{footnote-reference-15}{footnote-8}{7} \texttt{cases} environment:
%
\begin{equation*}
-\mathrm{sgn}(x) = \left\{\begin{matrix}
- -1 & x<0\\
- 1 & x>0
- \end{matrix}\right.
-\end{equation*}
-Cases with the \href{ftp://ftp.ams.org/ams/doc/amsmath/short-math-guide.pdf}{AMSmath}\DUfootnotemark{footnote-reference-15}{footnote-8}{7} \texttt{cases} environment (not (yet) supported by
-HTML writers with \texttt{--math-output=MathML}):
-%
-\begin{equation*}
\mathrm{sgn}(x) = \begin{cases}
-1 & x<0\\
1 & x>0
Modified: trunk/docutils/test/functional/input/data/math.txt
===================================================================
--- trunk/docutils/test/functional/input/data/math.txt 2021-05-20 12:19:35 UTC (rev 8739)
+++ trunk/docutils/test/functional/input/data/math.txt 2021-05-20 12:19:54 UTC (rev 8740)
@@ -91,20 +91,10 @@
s_{\mathrm{out}}(x) & = s_{\mathrm{in}}(x') * s_δ(x-x') \\
& = ∫ s_{\mathrm{in}}(x')s_δ(x-x')\mathrm{d}x'
-Cases ("manually", with ``matrix`` environment):
+Cases with the AMSmath_ ``cases`` environment:
.. math::
- \mathrm{sgn}(x) = \left\{\begin{matrix}
- -1 & x<0\\
- 1 & x>0
- \end{matrix}\right.
-
-Cases with the AMSmath_ ``cases`` environment (not (yet) supported by
-HTML writers with ``--math-output=MathML``):
-
-.. math::
-
\mathrm{sgn}(x) = \begin{cases}
-1 & x<0\\
1 & x>0
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|