|
From: <mi...@us...> - 2024-01-15 16:10:58
|
Revision: 9515
http://sourceforge.net/p/docutils/code/9515
Author: milde
Date: 2024-01-15 16:10:55 +0000 (Mon, 15 Jan 2024)
Log Message:
-----------
Add MathML support for "aligned" environment, fix "align*" in Chrome.
Use CSS rules instead of the deprecated "columnalign" attribute
to style <mtable> as "align*" or "aligned" environment.
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/docs/ref/rst/mathematics.txt
trunk/docutils/docutils/utils/math/latex2mathml.py
trunk/docutils/docutils/writers/html5_polyglot/minimal.css
trunk/docutils/docutils/writers/html5_polyglot/plain.css
trunk/docutils/docutils/writers/html5_polyglot/responsive.css
trunk/docutils/test/functional/expected/math_output_mathml.html
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2024-01-15 16:10:42 UTC (rev 9514)
+++ trunk/docutils/HISTORY.txt 2024-01-15 16:10:55 UTC (rev 9515)
@@ -97,6 +97,9 @@
- Elimitate side-effect of importing "latex2mathml" on "tex2unichar".
- Sort ℏ (`\hslash`) as "mathord", not "mathalpha".
- Use MathML element <mi> instead of <mo> for character class "mathord".
+ - Use CSS rules instead of the deprecated "columnalign" attribute
+ to style <mtable> as "align" environment. Fixes rendering in Crome.
+ - Support "aligned" environment.
* docutils/utils/roman.py
@@ -113,6 +116,10 @@
- Support video inclusion via `<object>` tags.
+* docutils/writers/html5_polyglot/*.css
+
+ - Move MathML styles to "minimal.css" (required for correct rendering).
+
* docutils/writers/_html_base.py
- Stop setting the "footnote-reference" class value for footnote references.
Modified: trunk/docutils/docs/ref/rst/mathematics.txt
===================================================================
--- trunk/docutils/docs/ref/rst/mathematics.txt 2024-01-15 16:10:42 UTC (rev 9514)
+++ trunk/docutils/docs/ref/rst/mathematics.txt 2024-01-15 16:10:55 UTC (rev 9515)
@@ -80,10 +80,33 @@
.. math::
- a &= (x + y)^2 & b &= (x - y)^2 \\
- &= x^2 + 2xy + y^2 & &= x^2 - 2xy + y^2
+ a & = (x + y)^2 & b & = (x - y)^2 \\
+ & = x^2 + 2xy + y^2 & & = x^2 - 2xy + y^2
+The ``aligned`` environment can be used as a component in a containing
+expression. E.g., ::
+ .. math::
+ \left.
+ \begin{aligned}
+ B' & = -\partial\times E, \\
+ E' & = \partial\times B - 4\pi j,
+ \end{aligned}
+ \right\}
+ \qquad \text{Maxwell’s equations}
+
+results in
+
+.. math::
+ \left.
+ \begin{aligned}
+ B' & = -\partial\times E \\
+ E' & = \partial\times B - 4\pi j
+ \end{aligned}
+ \;\right\}
+ \qquad \text{Maxwell’s equations.}
+
+
.. [#math-syntax] The supported LaTeX commands include AMS extensions
(see, e.g., the `Short Math Guide`_). Some of the shown symbols
require the "amssymb" `LaTeX package`_ (or another package providing
@@ -925,7 +948,7 @@
`Math alphabet`_ macros change the default alphabet, leaving some symbols
unchanged. In MathML core, the corresponding *Mathematical Alphanumeric
-Symbols* should be used.
+Symbols* are used.
:default: `V_R x \pm \cos(\alpha) \approx 3 \Gamma \quad \forall x \in \mathbb{R}`
:mathbb: `\mathbb{V_R x \pm \cos(\alpha) \approx 3 \Gamma \quad \forall x \in \mathbb{R}}`
@@ -950,7 +973,7 @@
Unicode supports also small Latin letters, some Greek letters, and digits:
`\mathbb{A \ldots Z a \ldots z}
\mathbb\Gamma \mathbb{\Pi} \mathbb {\Sigma} \mathbb\gamma \mathbb \pi
-\mathbb{0 \ldots 9}` but no italic numbers.
+\mathbb{0 \ldots 9}` but no italic digits.
Inferred <mrow>s in MathML
Modified: trunk/docutils/docutils/utils/math/latex2mathml.py
===================================================================
--- trunk/docutils/docutils/utils/math/latex2mathml.py 2024-01-15 16:10:42 UTC (rev 9514)
+++ trunk/docutils/docutils/utils/math/latex2mathml.py 2024-01-15 16:10:55 UTC (rev 9515)
@@ -283,6 +283,7 @@
'Bmatrix': ('{', '}'),
'vmatrix': ('|', '|'),
'Vmatrix': ('\u2016', '\u2016'), # ‖
+ 'aligned': ('', ''),
'cases': ('{', ''),
}
@@ -445,7 +446,8 @@
xml.extend(['\n', ' ' * level])
return xml
- # display mode
+ # auxiliary methods:
+
def is_block(self):
"""Return true, if `self` or a parent has ``display='block'``."""
try:
@@ -1340,6 +1342,7 @@
if name == 'cases':
wrapper = mrow(mo(left_delimiter, rspace='0.17em'))
attributes['columnalign'] = 'left'
+ attributes['class'] = 'cases'
node.append(wrapper)
node = wrapper
elif name == 'smallmatrix':
@@ -1348,8 +1351,9 @@
wrapper = mstyle(scriptlevel='1')
node.append(wrapper)
node = wrapper
- # TODO: aligned, alignedat
- # take an optional [t], [b] or the default [c]
+ elif name == 'aligned':
+ attributes['class'] = 'ams-align'
+ # TODO: array, aligned & alignedat take an optional [t], [b], or [c].
entry = mtd()
node.append(mtable(mtr(entry), **attributes))
node = entry
@@ -1392,13 +1396,12 @@
# Return dictionary with attributes to style an <mtable> as align environment:
-# TODO: "columnalign" disregarded by Chromium and webkit.
-# Use style="text-align: (right|left|center)" in the <mtd> elements
-# or a (complex) CSS rule for "mtable.align"
+# Not used with HTML. Replaced by CSS rule for "mtable.ams-align" in
+# "minimal.css" as "columnalign" is disregarded by Chromium and webkit.
def align_attributes(rows):
- atts = {'class': 'align',
+ atts = {'class': 'ams-align',
'displaystyle': True}
- # get maximal number of (non-escaped) "next column" markup instances:
+ # get maximal number of non-escaped "next column" markup characters:
tabs = max(row.count('&') - row.count(r'\&') for row in rows)
if tabs:
aligns = ['right', 'left'] * tabs
@@ -1408,17 +1411,17 @@
return atts
# >>> align_attributes(['a = b'])
-# {'class': 'align', 'displaystyle': True}
+# {'class': 'ams-align', 'displaystyle': True}
# >>> align_attributes(['a &= b'])
-# {'class': 'align', 'displaystyle': True, 'columnalign': 'right left', 'columnspacing': '0'}
+# {'class': 'ams-align', 'displaystyle': True, 'columnalign': 'right left', 'columnspacing': '0'}
# >>> align_attributes(['a &= b & a \in S'])
-# {'class': 'align', 'displaystyle': True, 'columnalign': 'right left right', 'columnspacing': '0 2em'}
+# {'class': 'ams-align', 'displaystyle': True, 'columnalign': 'right left right', 'columnspacing': '0 2em'}
# >>> align_attributes(['a &= b & c &= d'])
-# {'class': 'align', 'displaystyle': True, 'columnalign': 'right left right left', 'columnspacing': '0 2em 0'}
+# {'class': 'ams-align', 'displaystyle': True, 'columnalign': 'right left right left', 'columnspacing': '0 2em 0'}
# >>> align_attributes([r'a &= b & c &= d \& e'])
-# {'class': 'align', 'displaystyle': True, 'columnalign': 'right left right left', 'columnspacing': '0 2em 0'}
+# {'class': 'ams-align', 'displaystyle': True, 'columnalign': 'right left right left', 'columnspacing': '0 2em 0'}
# >>> align_attributes([r'a &= b & c &= d & e'])
-# {'class': 'align', 'displaystyle': True, 'columnalign': 'right left right left right', 'columnspacing': '0 2em 0 2em'}
+# {'class': 'ams-align', 'displaystyle': True, 'columnalign': 'right left right left right', 'columnspacing': '0 2em 0 2em'}
def tex2mathml(tex_math, as_block=False):
@@ -1435,8 +1438,8 @@
if len(rows) > 1:
# emulate "align*" environment with a math table
node = mtd()
- math_tree.append(mtable(mtr(node),
- **align_attributes(rows)))
+ math_tree.append(mtable(mtr(node), CLASS='ams-align',
+ displaystyle=True))
parse_latex_math(node, tex_math)
return math_tree.toprettyxml()
@@ -1450,7 +1453,7 @@
# </math>
# >>> print(tex2mathml(r'a & b \\ c & d', as_block=True))
# <math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
-# <mtable class="align" displaystyle="true" columnalign="right left" columnspacing="0">
+# <mtable class="ams-align" displaystyle="true">
# <mtr>
# <mtd>
# <mi>a</mi>
@@ -1471,7 +1474,7 @@
# </math>
# >>> print(tex2mathml(r'a \\ b', as_block=True))
# <math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
-# <mtable class="align" displaystyle="true">
+# <mtable class="ams-align" displaystyle="true">
# <mtr>
# <mtd>
# <mi>a</mi>
Modified: trunk/docutils/docutils/writers/html5_polyglot/minimal.css
===================================================================
--- trunk/docutils/docutils/writers/html5_polyglot/minimal.css 2024-01-15 16:10:42 UTC (rev 9514)
+++ trunk/docutils/docutils/writers/html5_polyglot/minimal.css 2024-01-15 16:10:55 UTC (rev 9515)
@@ -265,6 +265,19 @@
caption-side: bottom;
}
+/* MathML (see "math.css" for --math-output=HTML) */
+math .boldsymbol { font-weight: bold; }
+/* style table similar to AMS "align" or "aligned" environment: */
+mtable.cases > mtr > mtd { text-align: left; }
+mtable.ams-align > mtr > mtd { padding-left: 0; padding-right: 0; }
+mtable.ams-align > mtr > mtd:nth-child(2n) { text-align: left; }
+mtable.ams-align > mtr > mtd:nth-child(2n+1) { text-align: right; }
+mtable.ams-align > mtr > mtd:nth-child(2n+3) { padding-left: 2em; }
+mstyle.mathscr, mi.mathscr {
+ font-family: STIX, XITSMathJax_Script, rsfs10,
+ "Asana Math", Garamond, cursive;
+}
+
/* Document Header and Footer */
header { border-bottom: 1px solid black; }
footer { border-top: 1px solid black; }
Modified: trunk/docutils/docutils/writers/html5_polyglot/plain.css
===================================================================
--- trunk/docutils/docutils/writers/html5_polyglot/plain.css 2024-01-15 16:10:42 UTC (rev 9514)
+++ trunk/docutils/docutils/writers/html5_polyglot/plain.css 2024-01-15 16:10:55 UTC (rev 9515)
@@ -279,15 +279,6 @@
pre.code .deleted, code .deleted { background-color: #DEB0A1}
pre.code .inserted, code .inserted { background-color: #A3D289}
-/* Math */
-/* for math-output=MathML (for math-output=HTML, see math.css) */
-math .boldsymbol {
- font-weight: bold;
-}
-mstyle.mathscr, mi.mathscr {
- font-family: STIX, XITSMathJax_Script, rsfs10,
- "Asana Math", Garamond, cursive;
-}
/* Epigraph */
/* Highlights */
Modified: trunk/docutils/docutils/writers/html5_polyglot/responsive.css
===================================================================
--- trunk/docutils/docutils/writers/html5_polyglot/responsive.css 2024-01-15 16:10:42 UTC (rev 9514)
+++ trunk/docutils/docutils/writers/html5_polyglot/responsive.css 2024-01-15 16:10:55 UTC (rev 9515)
@@ -351,16 +351,6 @@
width: 40%;
}
-/* Math */
-/* for math-output=MathML (for math-output=HTML, see math.css) */
-math .boldsymbol {
- font-weight: bold;
-}
-mstyle.mathscr, mi.mathscr {
- font-family: STIX, XITSMathJax_Script, rsfs10,
- "Asana Math", Garamond, cursive;
-}
-
/* Adaptive page layout */
/* ==================== */
Modified: trunk/docutils/test/functional/expected/math_output_mathml.html
===================================================================
--- trunk/docutils/test/functional/expected/math_output_mathml.html 2024-01-15 16:10:42 UTC (rev 9514)
+++ trunk/docutils/test/functional/expected/math_output_mathml.html 2024-01-15 16:10:55 UTC (rev 9515)
@@ -392,7 +392,7 @@
<span class="docutils literal">align</span> environment:</p>
<div>
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
- <mtable class="align" displaystyle="true" columnalign="right left" columnspacing="0">
+ <mtable class="ams-align" displaystyle="true">
<mtr>
<mtd>
<msub>
@@ -468,7 +468,7 @@
<mo>=</mo>
<mrow>
<mo rspace="0.17em">{</mo>
- <mtable columnalign="left">
+ <mtable columnalign="left" class="cases">
<mtr>
<mtd>
<mo>−</mo>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|