|
From: <mi...@us...> - 2021-07-12 21:22:59
|
Revision: 8795
http://sourceforge.net/p/docutils/code/8795
Author: milde
Date: 2021-07-12 21:22:35 +0000 (Mon, 12 Jul 2021)
Log Message:
-----------
math2html: support decorations under base character.
Modified Paths:
--------------
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/docutils/utils/math/math2html.py
===================================================================
--- trunk/docutils/docutils/utils/math/math2html.py 2021-07-12 21:22:20 UTC (rev 8794)
+++ trunk/docutils/docutils/utils/math/math2html.py 2021-07-12 21:22:35 UTC (rev 8795)
@@ -99,7 +99,6 @@
u'Bracket',
u'BracketCommand',
u'CombiningFunction',
- u'DecoratingFunction',
u'EmptyCommand',
u'FontFunction',
u'Formula',
@@ -106,10 +105,12 @@
u'FormulaNumber',
u'FormulaSymbol',
u'OneParamFunction',
+ u'OversetFunction',
u'RawText',
u'SpacedCommand',
u'SymbolFunction',
u'TextFunction',
+ u'UndersetFunction',
],
}
@@ -306,15 +307,33 @@
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 @@
}
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 @@
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,22 +2727,36 @@
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, 'span class="symbolover"')
+ self.symbol = TaggedBit().constant(symbol, 'sup')
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 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, 'sub')
+ 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 LimitCommand(EmptyCommand):
"A command which accepts limits above and below, in display mode."
@@ -2899,9 +2933,8 @@
command.contents = bracket.getcontents()
-FormulaCommand.types += [
- DecoratingFunction, CombiningFunction, LimitCommand, BracketCommand,
- ]
+FormulaCommand.types += [OversetFunction, UndersetFunction,
+ CombiningFunction, LimitCommand, BracketCommand]
FormulaProcessor.processors += [
LimitsProcessor(), BracketProcessor(),
Modified: trunk/docutils/docutils/writers/html5_polyglot/math.css
===================================================================
--- trunk/docutils/docutils/writers/html5_polyglot/math.css 2021-07-12 21:22:20 UTC (rev 8794)
+++ trunk/docutils/docutils/writers/html5_polyglot/math.css 2021-07-12 21:22:35 UTC (rev 8795)
@@ -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 @@
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 {
Modified: trunk/docutils/test/functional/expected/math_output_html.html
===================================================================
--- trunk/docutils/test/functional/expected/math_output_html.html 2021-07-12 21:22:20 UTC (rev 8794)
+++ trunk/docutils/test/functional/expected/math_output_html.html 2021-07-12 21:22:35 UTC (rev 8795)
@@ -90,12 +90,12 @@
<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>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|