diff options
| author | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2021-07-12 21:23:07 +0000 |
|---|---|---|
| committer | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2021-07-12 21:23:07 +0000 |
| commit | 8e8f07b4fcd9a106f6e02bcc485609c4773c37a0 (patch) | |
| tree | b36bac3c90d64e37c189876bfbe90cc25594fb71 /docutils | |
| parent | 7ab0b4bb0c16058bca3c62335290a91cf326b6df (diff) | |
| download | docutils-8e8f07b4fcd9a106f6e02bcc485609c4773c37a0.tar.gz | |
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.
git-svn-id: https://svn.code.sf.net/p/docutils/code/trunk@8796 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'docutils')
| -rw-r--r-- | docutils/docs/ref/rst/mathematics.txt | 1 | ||||
| -rwxr-xr-x | docutils/docutils/utils/math/math2html.py | 67 | ||||
| -rw-r--r-- | docutils/docutils/writers/html5_polyglot/math.css | 48 | ||||
| -rw-r--r-- | docutils/test/functional/expected/math_output_html.html | 8 |
4 files changed, 69 insertions, 55 deletions
diff --git a/docutils/docs/ref/rst/mathematics.txt b/docutils/docs/ref/rst/mathematics.txt index 5901d6e8e..278eb444d 100644 --- a/docutils/docs/ref/rst/mathematics.txt +++ b/docutils/docs/ref/rst/mathematics.txt @@ -989,6 +989,7 @@ with extensible delimiters. \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\ diff --git a/docutils/docutils/utils/math/math2html.py b/docutils/docutils/utils/math/math2html.py index 36b7efe6d..44d9c20fa 100755 --- a/docutils/docutils/utils/math/math2html.py +++ b/docutils/docutils/utils/math/math2html.py @@ -175,16 +175,16 @@ class FormulaConfig(object): 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 @@ class FormulaConfig(object): commands = { '\\\\': u'<br/>', + '\\\n': u' ', # escaped whitespace + '\\\t': u' ', # escaped whitespace '\\colon': u': ', '\\copyright': u'©', '\\dotminus': u'∸', @@ -382,7 +384,7 @@ class FormulaConfig(object): 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 @@ class FormulaConfig(object): 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 @@ class FormulaConfig(object): } 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 @@ class BigBracket(BigSymbol): "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): diff --git a/docutils/docutils/writers/html5_polyglot/math.css b/docutils/docutils/writers/html5_polyglot/math.css index 47c6aeae5..7b7207264 100644 --- a/docutils/docutils/writers/html5_polyglot/math.css +++ b/docutils/docutils/writers/html5_polyglot/math.css @@ -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 @@ span.radical { 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,16 +138,32 @@ span.symbol { 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.bigdelimiter { + display: inline-block; + vertical-align: text-bottom; +} +span.bigdelimiter.size1 { + transform: scale(1, 1.2); } -span.hugesymbol { - font-size: 200%; +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 { @@ -174,7 +183,7 @@ span.limits { } .limit { display: table-row; - line-height: 99%; +/* line-height: 99%; */ } sup.limit, sub.limit { line-height: 100%; @@ -211,9 +220,12 @@ span.arrayrow, span.binomrow { 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. diff --git a/docutils/test/functional/expected/math_output_html.html b/docutils/test/functional/expected/math_output_html.html index 2f58a359c..ca203bc8c 100644 --- a/docutils/test/functional/expected/math_output_html.html +++ b/docutils/test/functional/expected/math_output_html.html @@ -59,10 +59,10 @@ See <a class="reference internal" href="#eq-m">eq:M</a> and <a class="reference <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 @@ physical system changes in time.</p> \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 @@ physical system changes in time.</p> </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> |
