diff options
| author | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2021-07-12 21:22:35 +0000 |
|---|---|---|
| committer | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2021-07-12 21:22:35 +0000 |
| commit | 7ab0b4bb0c16058bca3c62335290a91cf326b6df (patch) | |
| tree | 8a2334d39b3551161142a4888991a0980a3b90e3 /docutils | |
| parent | a8087752bac3129766b0db4dbf0d5c6641020928 (diff) | |
| download | docutils-7ab0b4bb0c16058bca3c62335290a91cf326b6df.tar.gz | |
math2html: support decorations under base character.
git-svn-id: https://svn.code.sf.net/p/docutils/code/trunk@8795 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'docutils')
| -rwxr-xr-x | docutils/docutils/utils/math/math2html.py | 119 | ||||
| -rw-r--r-- | docutils/docutils/writers/html5_polyglot/math.css | 26 | ||||
| -rw-r--r-- | docutils/test/functional/expected/math_output_html.html | 8 |
3 files changed, 90 insertions, 63 deletions
diff --git a/docutils/docutils/utils/math/math2html.py b/docutils/docutils/utils/math/math2html.py index 9ed814f4c..36b7efe6d 100755 --- a/docutils/docutils/utils/math/math2html.py +++ b/docutils/docutils/utils/math/math2html.py @@ -99,17 +99,18 @@ class ContainerConfig(object): u'Bracket', u'BracketCommand', u'CombiningFunction', - u'DecoratingFunction', u'EmptyCommand', u'FontFunction', u'Formula', u'FormulaNumber', u'FormulaSymbol', u'OneParamFunction', + u'OversetFunction', u'RawText', u'SpacedCommand', u'SymbolFunction', u'TextFunction', + u'UndersetFunction', ], } @@ -306,15 +307,33 @@ class FormulaConfig(object): cmddict.update(tex2unichar.space) commands.update(('\\' + key, value) for key, value in cmddict.items()) - decoratedcommand = { - } + oversetfunctions = { + # math accents (cf. combiningfunctions) + # '\\acute': u'´', + '\\bar': u'‒', # FIGURE DASH + # '\\breve': u'˘', + # '\\check': u'ˇ', + '\\dddot': u'<span class="smallsymbol">⋯</span>', + # '\\ddot': u'··', # ¨ too high + # '\\dot': u'·', + # '\\grave': u'`', + # '\\hat': u'^', + # '\\mathring': u'˚', + # '\\tilde': u'~', + '\\vec': u'<span class="smallsymbol">→</span>', + # embellishments + '\\overleftarrow': u'⟵', + '\\overleftrightarrow': u'⟷', + '\\overrightarrow': u'⟶', + '\\widehat': u'^', + '\\widetilde': u'~', + } - decoratingfunctions = {u'\\overleftarrow': u'⟵', - u'\\overrightarrow': u'⟶', - u'\\overleftrightarrow': u'⟷', - u'\\widehat': u'^', - u'\\widetilde': u'~', - } + undersetfunctions = { + '\\underleftarrow': u'⟵', + '\\underleftrightarrow': u'⟷', + '\\underrightarrow': u'⟶', + } endings = { u'bracket': u'}', @@ -456,28 +475,30 @@ class FormulaConfig(object): } onefunctions = { - '\\Big': u'span class="bigsymbol"', - '\\Bigl': u'span class="bigsymbol"', - '\\Bigr': u'span class="bigsymbol"', - '\\Bigg': u'span class="hugesymbol"', - '\\Biggl': u'span class="hugesymbol"', - '\\Biggr': u'span class="hugesymbol"', - '\\bar': u'span class="bar"', u'\\begin{array}': u'span class="arraydef"', - '\\big': u'span class="symbol"', u'\\bigg': u'span class="largesymbol"', - '\\bigl': u'span class="symbol"', - '\\bigr': u'span class="symbol"', - '\\biggl': u'span class="largesymbol"', - '\\biggr': u'span class="largesymbol"', - '\\centering': u'span class="align-center"', - '\\ensuremath': u'span class="ensuremath"', - '\\hphantom': u'span class="phantom"', - '\\noindent': u'span class="noindent"', - '\\overbrace': u'span class="overbrace"', - '\\overline': u'span class="overline"', - '\\phantom': u'span class="phantom"', - '\\underbrace': u'span class="underbrace"', - '\\underline': u'u', - '\\vphantom': u'span class="phantom"', + '\\Big': 'span class="bigsymbol"', + '\\Bigl': 'span class="bigsymbol"', + '\\Bigr': 'span class="bigsymbol"', + '\\Bigg': 'span class="hugesymbol"', + '\\Biggl': 'span class="hugesymbol"', + '\\Biggr': 'span class="hugesymbol"', + # '\\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"', + '\\noindent': 'span class="noindent"', + '\\overbrace': 'span class="overbrace"', + '\\overline': 'span class="overline"', + '\\phantom': 'span class="phantom"', + '\\underbrace': 'span class="underbrace"', + '\\underline': 'u', + '\\vphantom': 'span class="phantom"', } # relations (put additional space before and after the symbol) @@ -2697,7 +2718,6 @@ class CombiningFunction(OneParamFunction): i = 1 parameter.string = parameter.string[:i] + combining + parameter.string[i:] # Use pre-composed characters if possible: \not{=} -> ≠, say. - # TODO: use overset for mathematical accents. parameter.string = unicodedata.normalize('NFC', parameter.string) def parsesingleparameter(self, pos): @@ -2707,20 +2727,34 @@ class CombiningFunction(OneParamFunction): return None return self.parseparameter(pos) -class DecoratingFunction(OneParamFunction): - "A function that decorates some bit of text" +class OversetFunction(OneParamFunction): + "A function that decorates some bit of text with an overset." - commandmap = FormulaConfig.decoratingfunctions + commandmap = FormulaConfig.oversetfunctions def parsebit(self, pos): - "Parse a decorating function" - self.type = 'alpha' + "Parse an overset-function" + symbol = self.translated + self.symbol = TaggedBit().constant(symbol, 'sup') + self.parameter = self.parseparameter(pos) + self.output = TaggedOutput().settag('span class="embellished"') + self.contents.insert(0, self.symbol) + self.parameter.output = TaggedOutput().settag('span class="base"') + self.simplifyifpossible() + +class UndersetFunction(OneParamFunction): + "A function that decorates some bit of text with an underset." + + commandmap = FormulaConfig.undersetfunctions + + def parsebit(self, pos): + "Parse an underset-function" symbol = self.translated - self.symbol = TaggedBit().constant(symbol, 'span class="symbolover"') + self.symbol = TaggedBit().constant(symbol, 'sub') self.parameter = self.parseparameter(pos) - self.output = TaggedOutput().settag('span class="withsymbol"') + self.output = TaggedOutput().settag('span class="embellished"') self.contents.insert(0, self.symbol) - self.parameter.output = TaggedOutput().settag('span class="undersymbol"') + self.parameter.output = TaggedOutput().settag('span class="base"') self.simplifyifpossible() class LimitCommand(EmptyCommand): @@ -2899,9 +2933,8 @@ class BracketProcessor(MathsProcessor): command.contents = bracket.getcontents() -FormulaCommand.types += [ - DecoratingFunction, CombiningFunction, LimitCommand, BracketCommand, - ] +FormulaCommand.types += [OversetFunction, UndersetFunction, + CombiningFunction, LimitCommand, BracketCommand] FormulaProcessor.processors += [ LimitsProcessor(), BracketProcessor(), diff --git a/docutils/docutils/writers/html5_polyglot/math.css b/docutils/docutils/writers/html5_polyglot/math.css index af59e6d9d..47c6aeae5 100644 --- a/docutils/docutils/writers/html5_polyglot/math.css +++ b/docutils/docutils/writers/html5_polyglot/math.css @@ -25,7 +25,7 @@ /* Formulas */ .formula { text-align: center; - font-family: "Droid Serif", "DejaVu Serif", "STIX", serif; + font-family: "Droid Serif", "DejaVu Serif", STIX, serif; margin: 1.2em 0; line-height: 1.4; } @@ -179,27 +179,21 @@ span.limits { sup.limit, sub.limit { line-height: 100%; } -span.symbolover { +span.embellished, +span.embellished > .base { display: inline-block; - text-align: center; - position: relative; - float: right; - right: 100%; - bottom: 0.5em; - width: 0px; } -span.withsymbol { +span.embellished > sup, +span.embellished > sub { display: inline-block; -} -span.symbolunder { - display: inline-block; - text-align: center; + font-size: 100%; position: relative; - float: right; - right: 80%; - top: 0.3em; + bottom: 0.3em; width: 0px; } +span.embellished > sub { + top: 0.4em; +} /* Environments */ span.array, span.bracketcases, span.binomial, span.environment { diff --git a/docutils/test/functional/expected/math_output_html.html b/docutils/test/functional/expected/math_output_html.html index b85b0a713..2f58a359c 100644 --- a/docutils/test/functional/expected/math_output_html.html +++ b/docutils/test/functional/expected/math_output_html.html @@ -90,12 +90,12 @@ physical system changes in time.</p> <td><span class="formula"><i>α̃</i></span> <tt class="docutils literal"><span class="pre">\tilde{\alpha}</span></tt></td> </tr> <tr><td><span class="formula"><i>x̆</i></span> <tt class="docutils literal">\breve{x}</tt></td> -<td><span class="formula"><i>t⃛</i></span> <tt class="docutils literal">\dddot{t}</tt></td> -<td><span class="formula"><i>ı⃗</i></span> <tt class="docutils literal"><span class="pre">\vec{\imath}</span></tt></td> +<td><span class="formula"><span class="embellished"><sup><span class="smallsymbol">⋯</span></sup><span class="base"><i>t</i></span></span></span> <tt class="docutils literal">\dddot{t}</tt></td> +<td><span class="formula"><span class="embellished"><sup><span class="smallsymbol">→</span></sup><span class="base"><i>ı</i></span></span></span> <tt class="docutils literal"><span class="pre">\vec{\imath}</span></tt></td> </tr> <tr><td><span class="formula"><i>ǎ</i></span> <tt class="docutils literal">\check{a}</tt></td> -<td><span class="formula"><span class="bar"><i>a</i></span></span> <tt class="docutils literal">\bar{a}</tt></td> -<td><span class="formula"><i>R⃗</i></span> <tt class="docutils literal">\vec{R}</tt></td> +<td><span class="formula"><span class="embellished"><sup>‒</sup><span class="base"><i>a</i></span></span></span> <tt class="docutils literal">\bar{a}</tt></td> +<td><span class="formula"><span class="embellished"><sup><span class="smallsymbol">→</span></sup><span class="base"><i>R</i></span></span></span> <tt class="docutils literal">\vec{R}</tt></td> </tr> </tbody> </table> |
