|
From: <mi...@us...> - 2021-07-12 21:23:11
|
Revision: 8796
http://sourceforge.net/p/docutils/code/8796
Author: milde
Date: 2021-07-12 21:23:07 +0000 (Mon, 12 Jul 2021)
Log Message:
-----------
math2html: Improve handling of big symbols.
Scale variable sized operators with CSS instead of constructing from pieces.
Fix Unicode translations for N-ary operators.
Scale stretch big delimiters instead of scaling.
Modified Paths:
--------------
trunk/docutils/docs/ref/rst/mathematics.txt
trunk/docutils/docutils/utils/math/math2html.py
trunk/docutils/docutils/writers/html5_polyglot/math.css
trunk/docutils/test/functional/expected/math_output_html.html
Modified: trunk/docutils/docs/ref/rst/mathematics.txt
===================================================================
--- trunk/docutils/docs/ref/rst/mathematics.txt 2021-07-12 21:22:35 UTC (rev 8795)
+++ trunk/docutils/docs/ref/rst/mathematics.txt 2021-07-12 21:23:07 UTC (rev 8796)
@@ -989,6 +989,7 @@
\left.\vert \frac{b}{a}\right\Vert\ \bigl\vert b\Bigr\Vert\ \biggl\vert b\Biggr\Vert
\quad
+
Variable-sized operators:
Inline: `\sum\ \int\ \oint\ \smallint\ \prod\ \coprod\ \bigwedge\
Modified: trunk/docutils/docutils/utils/math/math2html.py
===================================================================
--- trunk/docutils/docutils/utils/math/math2html.py 2021-07-12 21:22:35 UTC (rev 8795)
+++ trunk/docutils/docutils/utils/math/math2html.py 2021-07-12 21:23:07 UTC (rev 8796)
@@ -175,16 +175,16 @@
u'∥': [u'∥',],
}
- bigsymbols = {u'∑': [u'⎲', u'⎳',], # ⎲ ⌠ ┌
- u'∫': [u'⌠', u'⌡',], # ⎳ ⎮ │
- u'√': [u'┌', u'⎷',], # ⌡ ⎷
+ bigsymbols = {# u'∑': [u'⎲', u'⎳',], # ⎲ ⌠ ┌
+ # u'∫': [u'⌠', u'⌡',], # ⎳ ⎮ │
+ # u'√': [u'┌', u'⎷',], # ⌡ ⎷
}
bracketcommands = {
- u'\\left': u'span class="symbol"',
+ u'\\left': u'span class="bigdelimiter size2"',
u'\\left.': u'<span class="leftdot"></span>',
- u'\\middle': u'span class="symbol"',
- u'\\right': u'span class="symbol"',
+ u'\\middle': u'span class="bigdelimiter size2"',
+ u'\\right': u'span class="bigdelimiter size2"',
u'\\right.': u'<span class="rightdot"></span>',
}
@@ -206,6 +206,8 @@
commands = {
'\\\\': u'<br/>',
+ '\\\n': u' ', # escaped whitespace
+ '\\\t': u' ', # escaped whitespace
'\\colon': u': ',
'\\copyright': u'©',
'\\dotminus': u'∸',
@@ -382,7 +384,7 @@
u'\\addcontentsline': [u'{$p!}{$q!}{$r!}', u'f0{}', u'ignored',],
u'\\addtocontents': [u'{$p!}{$q!}', u'f0{}', u'ignored',],
u'\\backmatter': [u'', u'f0{}', u'ignored',],
- u'\\binom': [u'{$1}{$2}', u'f2{(}f0{f1{$1}f1{$2}}f2{)}', u'span class="binom"', u'span class="binomstack"', u'span class="bigsymbol"',],
+ u'\\binom': [u'{$1}{$2}', u'f2{(}f0{f1{$1}f1{$2}}f2{)}', u'span class="binom"', u'span class="binomstack"', u'span class="bigdelimiter size2"',],
u'\\boxed': [u'{$1}', u'f0{$1}', u'span class="boxed"',],
u'\\cfrac': [u'[$p!]{$1}{$2}', u'f0{f3{(}f1{$1}f3{)/(}f2{$2}f3{)}}', u'span class="fullfraction"', u'span class="numerator align-$p"', u'span class="denominator"', u'span class="ignored"',],
u'\\color': [u'{$p!}{$1}', u'f0{$1}', u'span style="color: $p;"',],
@@ -437,31 +439,30 @@
limitcommands = {
'\\biginterleave': u'⫼',
'\\inf': u'inf',
- '\\intop': u'∫', # large operator via pieces from bigsymbols
'\\lim': u'lim',
'\\max': u'max',
'\\min': u'min',
- '\\sum': u'∑', # large operator via pieces from bigsymbols
'\\sup': u'sup',
'\\ointop': u'<span class="bigoperator">∮</span>',
- '\\bigcap': u'<span class="bigoperator">∩</span>',
- '\\bigcup': u'<span class="bigoperator">∪</span>',
- '\\bigodot': u'<span class="bigoperator">⊙</span>',
- '\\bigoplus': u'<span class="bigoperator">⊕</span>',
- '\\bigotimes': u'<span class="bigoperator">⊗</span>',
+ '\\bigcap': u'<span class="bigoperator">⋂</span>',
+ '\\bigcup': u'<span class="bigoperator">⋃</span>',
+ '\\bigodot': u'<span class="bigoperator">⨀</span>',
+ '\\bigoplus': u'<span class="bigoperator">⨁</span>',
+ '\\bigotimes': u'<span class="bigoperator">⨂</span>',
'\\bigsqcap': u'<span class="bigoperator">⨅</span>',
- '\\bigsqcup': u'<span class="bigoperator">⊔</span>',
- '\\biguplus': u'<span class="bigoperator">⊎</span>',
- '\\bigvee': u'<span class="bigoperator">∨</span>',
- '\\bigwedge': u'<span class="bigoperator">∧</span>',
+ '\\bigsqcup': u'<span class="bigoperator">⨆</span>',
+ '\\biguplus': u'<span class="bigoperator">⨄</span>',
+ '\\bigvee': u'<span class="bigoperator">⋁</span>',
+ '\\bigwedge': u'<span class="bigoperator">⋀</span>',
'\\coprod': u'<span class="bigoperator">∐</span>',
+ '\\intop': u'<span class="bigoperator">∫</span>',
'\\prod': u'<span class="bigoperator">∏</span>',
+ '\\sum': u'<span class="bigoperator">∑</span>',
'\\varprod': u'<span class="bigoperator">⨉</span>',
'\\zcmp': u'⨟', '\\zhide': u'⧹', '\\zpipe': u'⨠', '\\zproject': u'⨡',
# integrals have limits in index position with LaTeX default settings
# TODO: move to commands?
- '\\int': u'∫',
- '\\smallint': u'∫',
+ '\\int': u'<span class="bigoperator">∫</span>',
'\\fint': u'<span class="bigoperator">⨏</span>',
'\\iiiint': u'<span class="bigoperator">⨌</span>',
'\\sqint': u'<span class="bigoperator">⨖</span>',
@@ -475,20 +476,20 @@
}
onefunctions = {
- '\\Big': 'span class="bigsymbol"',
- '\\Bigl': 'span class="bigsymbol"',
- '\\Bigr': 'span class="bigsymbol"',
- '\\Bigg': 'span class="hugesymbol"',
- '\\Biggl': 'span class="hugesymbol"',
- '\\Biggr': 'span class="hugesymbol"',
+ '\\big': 'span class="bigdelimiter size1"',
+ '\\bigl': 'span class="bigdelimiter size1"',
+ '\\bigr': 'span class="bigdelimiter size1"',
+ '\\Big': 'span class="bigdelimiter size2"',
+ '\\Bigl': 'span class="bigdelimiter size2"',
+ '\\Bigr': 'span class="bigdelimiter size2"',
+ '\\bigg': 'span class="bigdelimiter size3"',
+ '\\biggl': 'span class="bigdelimiter size3"',
+ '\\biggr': 'span class="bigdelimiter size3"',
+ '\\Bigg': 'span class="bigdelimiter size4"',
+ '\\Biggl': 'span class="bigdelimiter size4"',
+ '\\Biggr': 'span class="bigdelimiter size4"',
# '\\bar': 'span class="bar"',
'\\begin{array}': 'span class="arraydef"',
- '\\big': 'span class="symbol"',
- '\\bigl': 'span class="symbol"',
- '\\bigr': 'span class="symbol"',
- '\\bigg': 'span class="largesymbol"',
- '\\biggl': 'span class="largesymbol"',
- '\\biggr': 'span class="largesymbol"',
'\\centering': 'span class="align-center"',
'\\ensuremath': 'span class="ensuremath"',
'\\hphantom': 'span class="phantom"',
@@ -2489,7 +2490,7 @@
"Return the bracket as a single sign."
if self.original == '.':
return [TaggedBit().constant('', 'span class="emptydot"')]
- return [TaggedBit().constant(self.original, 'span class="symbol"')]
+ return [TaggedBit().constant(self.original, 'span class="bigdelimiter size2"')]
class FormulaEquation(CommandBit):
Modified: trunk/docutils/docutils/writers/html5_polyglot/math.css
===================================================================
--- trunk/docutils/docutils/writers/html5_polyglot/math.css 2021-07-12 21:22:35 UTC (rev 8795)
+++ trunk/docutils/docutils/writers/html5_polyglot/math.css 2021-07-12 21:23:07 UTC (rev 8796)
@@ -25,7 +25,8 @@
/* Formulas */
.formula {
text-align: center;
- font-family: "Droid Serif", "DejaVu Serif", STIX, serif;
+ font-family: "DejaVu Serif", STIX, serif;
+ /* "DejaVu Math TeX Gyre", (brace pieces don't fit) */
margin: 1.2em 0;
line-height: 1.4;
}
@@ -126,14 +127,6 @@
vertical-align: middle;
}
-/* div.formula span.sqrt span.radical:before { */
-/* writing-mode: vertical-lr; */
-/* text-orientation: upright; */
-/* content: "┌│⎷"; */
-/* } */
-/* or use "transform" property */
-/* https://developer.mozilla.org/en-US/docs/Web/CSS/transform */
-
span.root {
display: inline-block;
border-top: thin solid;
@@ -145,17 +138,33 @@
line-height: 125%;
font-size: 125%;
}
-/* TODO: use transform matrix to stretch fences */
-span.bigsymbol, div.formula span.bigoperator {
- line-height: 150%;
+div.formula .bigoperator,
+.displaystyle .bigoperator,
+.displaystyle .bigoperator {
+ line-height: 150%;
font-size: 150%;
}
-span.largesymbol {
- font-size: 175%;
+span.fraction .bigoperator,
+span.scriptstyle .bigoperator{
+ line-height: inherit;
+ font-size: inherit;
}
-span.hugesymbol {
- font-size: 200%;
+span.bigdelimiter {
+ display: inline-block;
+ vertical-align: text-bottom;
}
+span.bigdelimiter.size1 {
+ transform: scale(1, 1.2);
+}
+span.bigdelimiter.size2 {
+ transform: scale(1, 1.62);
+}
+span.bigdelimiter.size3 {
+ transform: scale(1, 2.05);
+}
+span.bigdelimiter.size4 {
+ transform: scale(1, 2.47);
+}
/* vertically stacked sub and superscript */
span.scripts {
display: inline-flex;
@@ -174,7 +183,7 @@
}
.limit {
display: table-row;
- line-height: 99%;
+/* line-height: 99%; */
}
sup.limit, sub.limit {
line-height: 100%;
@@ -211,9 +220,12 @@
span.arraycell, span.bracket, span.case, span.binomcell, span.environmentcell {
display: table-cell;
padding: 0ex 0.2ex;
- line-height: 99%;
+ line-height: 1; /* 99%; */
border: 0ex;
}
+.environment.align > .arrayrow > .arraycell.align-l {
+ padding-right: 2em;
+}
/*
* CSS file for LaTeX formulas, extra stuff:
* binomials, vertical braces, stackrel, fonts and colors.
Modified: trunk/docutils/test/functional/expected/math_output_html.html
===================================================================
--- trunk/docutils/test/functional/expected/math_output_html.html 2021-07-12 21:22:35 UTC (rev 8795)
+++ trunk/docutils/test/functional/expected/math_output_html.html 2021-07-12 21:23:07 UTC (rev 8796)
@@ -59,10 +59,10 @@
<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 class="formula">
-<span class="limits"><sup class="limit">1</sup><span class="limit">⌠</span><span class="limit">⌡</span><sub class="limit">0</sub></span><i>x</i><sup><i>n</i></sup><i>dx</i> = <span class="fraction"><span class="ignored">(</span><span class="numerator">1</span><span class="ignored">)/(</span><span class="denominator"><i>n</i> + 1</span><span class="ignored">)</span></span>
+<span class="limits"><sup class="limit">1</sup><span class="limit"><span class="bigoperator">∫</span></span><sub class="limit">0</sub></span><i>x</i><sup><i>n</i></sup><i>dx</i> = <span class="fraction"><span class="ignored">(</span><span class="numerator">1</span><span class="ignored">)/(</span><span class="denominator"><i>n</i> + 1</span><span class="ignored">)</span></span>
</div>
<div class="formula">
-<span class="limits"><sup class="limit"><i>m</i></sup><span class="limit">⎲</span><span class="limit">⎳</span><sub class="limit"><i>n</i> = 1</sub></span><i>n</i> = <span class="fraction"><span class="ignored">(</span><span class="numerator"><i>m</i>(<i>m</i> + 1)</span><span class="ignored">)/(</span><span class="denominator">2</span><span class="ignored">)</span></span>
+<span class="limits"><sup class="limit"><i>m</i></sup><span class="limit"><span class="bigoperator">∑</span></span><sub class="limit"><i>n</i> = 1</sub></span><i>n</i> = <span class="fraction"><span class="ignored">(</span><span class="numerator"><i>m</i>(<i>m</i> + 1)</span><span class="ignored">)/(</span><span class="denominator">2</span><span class="ignored">)</span></span>
</div>
<p>LaTeX-supported Unicode math symbols can be used in math roles and
directives:</p>
@@ -105,7 +105,7 @@
\widehat{xxx} -->
<p>Modulation Transfer Function:</p>
<div class="formula">
-<span class="text">MTF</span> = <span class="array"><span class="arrayrow"><span class="bracket align-left">|</span></span><span class="arrayrow"><span class="bracket align-left">|</span></span></span><span class="fraction"><span class="ignored">(</span><span class="numerator">ℱ{<i>s</i>(<i>x</i>)}</span><span class="ignored">)/(</span><span class="denominator">ℱ{<i>s</i>(<i>x</i>)}|<sub><i>ω</i><sub><i>x</i></sub> = 0</sub></span><span class="ignored">)</span></span><span class="array"><span class="arrayrow"><span class="bracket align-right">|</span></span><span class="arrayrow"><span class="bracket align-right">|</span></span></span> = <span class="mathrm"> abs</span><span class="array"><span class="arrayrow"><span class="bracket align-left">⎛</span></span><span class="arrayrow"><span class="bracket align-left">⎝</span></span></span><span class="fraction"><span class="ignored">(</span><span class="numerator"><span class="limits"><span class="limit">⌠</span><span class="limit">⌡</span></span><span class="scripts"><sup class="script">∞</sup><sub class="script"> − ∞</sub></span><i>s</i>(<i>x</i>)<span class="mathrm">e</span><sup><span class="mathrm">i</span><i>ω</i><sub><i>x</i></sub><i>x</i></sup><span class="mathrm">d</span><i>x</i></span><span class="ignored">)/(</span><span class="denominator"><span class="limits"><span class="limit">⌠</span><span class="limit">⌡</span></span><span class="scripts"><sup class="script">∞</sup><sub class="script"> − ∞</sub></span><i>s</i>(<i>x</i>)<span class="mathrm">d</span><i>x</i></span><span class="ignored">)</span></span><span class="array"><span class="arrayrow"><span class="bracket align-right">⎞</span></span><span class="arrayrow"><span class="bracket align-right">⎠</span></span></span>.
+<span class="text">MTF</span> = <span class="array"><span class="arrayrow"><span class="bracket align-left">|</span></span><span class="arrayrow"><span class="bracket align-left">|</span></span></span><span class="fraction"><span class="ignored">(</span><span class="numerator">ℱ{<i>s</i>(<i>x</i>)}</span><span class="ignored">)/(</span><span class="denominator">ℱ{<i>s</i>(<i>x</i>)}|<sub><i>ω</i><sub><i>x</i></sub> = 0</sub></span><span class="ignored">)</span></span><span class="array"><span class="arrayrow"><span class="bracket align-right">|</span></span><span class="arrayrow"><span class="bracket align-right">|</span></span></span> = <span class="mathrm"> abs</span><span class="array"><span class="arrayrow"><span class="bracket align-left">⎛</span></span><span class="arrayrow"><span class="bracket align-left">⎝</span></span></span><span class="fraction"><span class="ignored">(</span><span class="numerator"><span class="limits"><span class="limit"><span class="bigoperator">∫</span></span></span><span class="scripts"><sup class="script">∞</sup><sub class="script"> − ∞</sub></span><i>s</i>(<i>x</i>)<span class="mathrm">e</span><sup><span class="mathrm">i</span><i>ω</i><sub><i>x</i></sub><i>x</i></sup><span class="mathrm">d</span><i>x</i></span><span class="ignored">)/(</span><span class="denominator"><span class="limits"><span class="limit"><span class="bigoperator">∫</span></span></span><span class="scripts"><sup class="script">∞</sup><sub class="script"> − ∞</sub></span><i>s</i>(<i>x</i>)<span class="mathrm">d</span><i>x</i></span><span class="ignored">)</span></span><span class="array"><span class="arrayrow"><span class="bracket align-right">⎞</span></span><span class="arrayrow"><span class="bracket align-right">⎠</span></span></span>.
</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>
@@ -134,7 +134,7 @@
</span>
<span class="arraycell align-l">
- = <span class="limits"><span class="limit">⌠</span><span class="limit">⌡</span></span><i>s</i><sub><span class="mathrm">in</span></sub>(<i>x</i>’)<i>s</i><sub><i>δ</i></sub>(<i>x</i> − <i>x</i>’)<span class="mathrm">d</span><i>x</i>’
+ = <span class="limits"><span class="limit"><span class="bigoperator">∫</span></span></span><i>s</i><sub><span class="mathrm">in</span></sub>(<i>x</i>’)<i>s</i><sub><i>δ</i></sub>(<i>x</i> − <i>x</i>’)<span class="mathrm">d</span><i>x</i>’
</span>
</span>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|