|
From: <mi...@us...> - 2021-05-20 12:20:22
|
Revision: 8741
http://sourceforge.net/p/docutils/code/8741
Author: milde
Date: 2021-05-20 12:20:20 +0000 (Thu, 20 May 2021)
Log Message:
-----------
MathML: make delimiters "non-strechy" by default. Fixes bug #407.
LaTeX lets delimiters grow to the size of the enclosed content
only, when they are arguments to ``\left`` or `\right``.
MathML streches delimiters inside ``mrow`` by default.
Add ``stretchy="false"`` to keep LaTeX and MathML appearance in sync.
Modified Paths:
--------------
trunk/docutils/docutils/utils/math/latex2mathml.py
trunk/docutils/test/functional/expected/math_output_mathml.html
Modified: trunk/docutils/docutils/utils/math/latex2mathml.py
===================================================================
--- trunk/docutils/docutils/utils/math/latex2mathml.py 2021-05-20 12:19:54 UTC (rev 8740)
+++ trunk/docutils/docutils/utils/math/latex2mathml.py 2021-05-20 12:20:20 UTC (rev 8741)
@@ -175,35 +175,37 @@
r'\equiv': u'\u2262'}
# cmds/characters allowed in left/right cmds
-fence_args = {'(': '(',
- ')': ')',
- '[': '[',
- ']': ']',
- '/': '/',
- r'\backslash': '\\',
- '|': '|',
- '.': '', # emty fence
- r'\uparrow': u'\u2191', # ↑ UPWARDS ARROW
- r'\downarrow': u'\u2193', # ↓ DOWNWARDS ARROW
- r'\updownarrow': u'\u2195', # ↕ UP DOWN ARROW
- r'\Uparrow': u'\u21d1', # ⇑ UPWARDS DOUBLE ARROW
- r'\Downarrow': u'\u21d3', # ⇓ DOWNWARDS DOUBLE ARROW
- r'\Updownarrow': u'\u21d5', # ⇕ UP DOWN DOUBLE ARROW
+stretchables = {'(': '(',
+ ')': ')',
+ '[': '[',
+ ']': ']',
+ '/': '/',
+ r'\backslash': '\\',
+ '|': '|',
+ '.': '', # emty fence
+ r'\uparrow': u'\u2191', # ↑ UPWARDS ARROW
+ r'\downarrow': u'\u2193', # ↓ DOWNWARDS ARROW
+ r'\updownarrow': u'\u2195', # ↕ UP DOWN ARROW
+ r'\Uparrow': u'\u21d1', # ⇑ UPWARDS DOUBLE ARROW
+ r'\Downarrow': u'\u21d3', # ⇓ DOWNWARDS DOUBLE ARROW
+ r'\Updownarrow': u'\u21d5', # ⇕ UP DOWN DOUBLE ARROW
}
for (key, value) in tex2unichar.mathfence.items():
- fence_args['\\'+key] = value
+ stretchables['\\'+key] = value
for (key, value) in tex2unichar.mathopen.items():
- fence_args['\\'+key] = value
+ stretchables['\\'+key] = value
for (key, value) in tex2unichar.mathclose.items():
- fence_args['\\'+key] = value
+ stretchables['\\'+key] = value
# shorter with {**something} syntax, new in 3.5
# if sys.version_info >= (3, 5):
# for (key, value) in {**tex2unichar.mathclose,
# **tex2unichar.mathopen,
# **tex2unichar.mathfence}.items():
-# fence_args['\\'+key] = value
+# stretchables['\\'+key] = value
+# >>> print(' '.join(sorted(set(l2m.stretchables.values()))))
+# ( ) / [ \ ] { | } ‖ ↑ ↓ ↕ ⇑ ⇓ ⇕ ⌈ ⌉ ⌊ ⌋ ⌜ ⌝ ⌞ ⌟ ⟅ ⟆ ⟦ ⟧ ⟨ ⟩ ⟮ ⟯ ⦇ ⦈
# MathML element classes
# ----------------------
@@ -361,8 +363,9 @@
nchildren = 0
entity_table = {ord('<'): u'<', ord('>'): u'>'}
- def __init__(self, data):
+ def __init__(self, data, **kwargs):
self.data = data
+ super(mx, self).__init__(**kwargs)
def xml_body(self):
return [unicode(self.data).translate(self.entity_table)]
@@ -498,7 +501,9 @@
node = node.append(mi(c))
elif c.isdigit():
node = node.append(mn(c))
- elif c in "+-*/=()[]|<>,.!?':;@":
+ elif c in "/()[]|":
+ node = node.append(mo(c, stretchy='false'))
+ elif c in "+-*=<>,.!?':;@":
node = node.append(mo(c))
elif c == '_':
child = node.delete_child()
@@ -587,7 +592,7 @@
node.append(frac)
node = frac
elif name == 'left':
- for par in fence_args.keys():
+ for par in stretchables.keys():
if string.startswith(par):
break
else:
@@ -596,16 +601,16 @@
node.append(row)
node = row
if par != '.':
- node.append(mo(fence_args[par]))
+ node.append(mo(stretchables[par]))
skip += len(par)
elif name == 'right':
- for par in fence_args.keys():
+ for par in stretchables.keys():
if string.startswith(par):
break
else:
raise SyntaxError(u'Missing right-brace!')
if par != '.':
- node.append(mo(fence_args[par]))
+ node.append(mo(stretchables[par]))
node = node.close()
skip += len(par)
elif name == 'not':
Modified: trunk/docutils/test/functional/expected/math_output_mathml.html
===================================================================
--- trunk/docutils/test/functional/expected/math_output_mathml.html 2021-05-20 12:19:54 UTC (rev 8740)
+++ trunk/docutils/test/functional/expected/math_output_mathml.html 2021-05-20 12:20:20 UTC (rev 8741)
@@ -15,11 +15,11 @@
<p>Docutils supports inline math with the prefix or postfix <span class="docutils literal">:math:</span>
role specificator, <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
- <mi>n</mi><mo>!</mo><mo>+</mo><mo>sin</mo><mo>(</mo>
+ <mi>n</mi><mo>!</mo><mo>+</mo><mo>sin</mo><mo stretchy="false">(</mo>
<msubsup>
<mi>x</mi><mi>n</mi><mn>2</mn>
</msubsup>
- <mo>)</mo>
+ <mo stretchy="false">)</mo>
</mrow>
</math> and <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
@@ -46,7 +46,7 @@
<mtable class="align" displaystyle="true">
<mtr>
<mtd>
- <mi>f</mi><mo>(</mo><mi>ϵ</mi><mo>)</mo><mo>=</mo>
+ <mi>f</mi><mo stretchy="false">(</mo><mi>ϵ</mi><mo stretchy="false">)</mo><mo>=</mo>
<mfrac>
<mrow>
<mn>1</mn>
@@ -138,13 +138,13 @@
</div>
<p>is <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
- <mo>|</mo>
+ <mo stretchy="false">|</mo>
<mstyle mathvariant="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>
+ <mo stretchy="false">|</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.
@@ -189,7 +189,7 @@
<mi>n</mi><mo>=</mo>
<mfrac>
<mrow>
- <mi>m</mi><mo>(</mo><mi>m</mi><mo>+</mo><mn>1</mn><mo>)</mo>
+ <mi>m</mi><mo stretchy="false">(</mo><mi>m</mi><mo>+</mo><mn>1</mn><mo stretchy="false">)</mo>
</mrow>
<mrow>
<mn>2</mn>
@@ -386,12 +386,12 @@
<mo>|</mo>
<mfrac>
<mrow>
- <mi>ℱ</mi><mo>{</mo><mi>s</mi><mo>(</mo><mi>x</mi><mo>)</mo><mo>}</mo>
+ <mi>ℱ</mi><mo>{</mo><mi>s</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>}</mo>
</mrow>
<mrow>
- <mi>ℱ</mi><mo>{</mo><mi>s</mi><mo>(</mo><mi>x</mi><mo>)</mo><mo>}</mo>
+ <mi>ℱ</mi><mo>{</mo><mi>s</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>}</mo>
<msub>
- <mo>|</mo>
+ <mo stretchy="false">|</mo>
<mrow>
<msub>
<mi>ω</mi>
@@ -420,7 +420,7 @@
<mo>∞</mo>
</mrow>
</munderover>
- <mi>s</mi><mo>(</mo><mi>x</mi><mo>)</mo>
+ <mi>s</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo>
<msup>
<mtext>e</mtext>
<mrow>
@@ -449,7 +449,7 @@
<mo>∞</mo>
</mrow>
</munderover>
- <mi>s</mi><mo>(</mo><mi>x</mi><mo>)</mo><mtext>d</mtext>
+ <mi>s</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mtext>d</mtext>
<mrow>
<mi>x</mi>
</mrow>
@@ -477,7 +477,7 @@
<mtext>out</mtext>
</mrow>
</msub>
- <mo>(</mo><mi>x</mi><mo>)</mo>
+ <mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo>
</mtd>
<mtd>
<mo>=</mo>
@@ -487,11 +487,11 @@
<mtext>in</mtext>
</mrow>
</msub>
- <mo>(</mo><mi>x</mi><mo>'</mo><mo>)</mo><mo>*</mo>
+ <mo stretchy="false">(</mo><mi>x</mi><mo>'</mo><mo stretchy="false">)</mo><mo>*</mo>
<msub>
<mi>s</mi><mi>δ</mi>
</msub>
- <mo>(</mo><mi>x</mi><mo>-</mo><mi>x</mi><mo>'</mo><mo>)</mo>
+ <mo stretchy="false">(</mo><mi>x</mi><mo>-</mo><mi>x</mi><mo>'</mo><mo stretchy="false">)</mo>
</mtd>
</mtr>
<mtr>
@@ -505,11 +505,11 @@
<mtext>in</mtext>
</mrow>
</msub>
- <mo>(</mo><mi>x</mi><mo>'</mo><mo>)</mo>
+ <mo stretchy="false">(</mo><mi>x</mi><mo>'</mo><mo stretchy="false">)</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>
+ <mo stretchy="false">(</mo><mi>x</mi><mo>-</mo><mi>x</mi><mo>'</mo><mo stretchy="false">)</mo><mtext>d</mtext><mi>x</mi><mo>'</mo>
</mtd>
</mtr>
</mtable>
@@ -521,7 +521,7 @@
<mtable class="align" displaystyle="true">
<mtr>
<mtd>
- <mtext>sgn</mtext><mo>(</mo><mi>x</mi><mo>)</mo><mo>=</mo>
+ <mtext>sgn</mtext><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo>
<mrow>
<mo>{</mo>
<mtable>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|