diff options
Diffstat (limited to 'docutils/utils/math/latex2mathml.py')
| -rw-r--r-- | docutils/utils/math/latex2mathml.py | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/docutils/utils/math/latex2mathml.py b/docutils/utils/math/latex2mathml.py index d4910602f..b45f15676 100644 --- a/docutils/utils/math/latex2mathml.py +++ b/docutils/utils/math/latex2mathml.py @@ -441,8 +441,10 @@ class math: # >>> math(CLASS='bold').xml_starttag() # '<math class="bold">' + class mtable(math): pass + # >>> mt = mtable(displaystyle=True) # >>> mt # mtable(displaystyle=True) @@ -476,25 +478,30 @@ class mrow(math): # >>> mrow(displaystyle=False) # mrow(displaystyle=False) + # The elements <msqrt>, <mstyle>, <merror>, <mpadded>, <mphantom>, <menclose>, # <mtd>, <mscarry>, and <math> treat their contents as a single inferred mrow # formed from all their children. class MathRowSchema(math): """Base class for elements treating content as a single inferred mrow.""" -class mtr(MathRowSchema): pass +class mtr(MathRowSchema): pass class mtd(MathRowSchema): pass + class menclose(MathRowSchema): nchildren = 1 # \boxed expects one argument or a group + class mphantom(MathRowSchema): nchildren = 1 # \phantom expects one argument or a group + class msqrt(MathRowSchema): nchildren = 1 # \sqrt expects one argument or a group + class mstyle(MathRowSchema): nchildren = 1 # \mathrm, ... expect one argument or a group @@ -513,11 +520,13 @@ class MathToken(math): def _xml_body(self, level=0): return [str(self.data).translate(self.xml_entities)] + class mtext(MathToken): pass class mi(MathToken): pass class mo(MathToken): pass class mn(MathToken): pass + # >>> mo('<') # mo('<') # >>> mo('<')._xml() @@ -544,11 +553,15 @@ class MathSchema(math): self.switch = False return current_node + class msub(MathSchema): pass class msup(MathSchema): pass + + class msubsup(MathSchema): nchildren = 3 + # >>> msub(mi('x'), mo('-')) # msub(mi('x'), mo('-')) # >>> msubsup(mi('base'), mi('sub'), mi('super')) @@ -559,6 +572,7 @@ class msubsup(MathSchema): class munder(msub): pass class mover(msup): pass + # >>> munder(mi('lim'), mo('-'), accent=False) # munder(mi('lim'), mo('-'), accent=False) # >>> mu = munder(mo('-'), accent=False, switch=True) @@ -575,12 +589,15 @@ class mover(msup): pass class munderover(msubsup): pass + class mroot(MathSchema): nchildren = 2 + class mfrac(math): nchildren = 2 + class mspace(math): nchildren = 0 @@ -607,6 +624,7 @@ def tex_cmdname(string): m = re.match(r'(.?)(.*)', string) return m.group(1), m.group(2) + # Test: # # >>> tex_cmdname('name_2') # first non-letter terminates @@ -618,6 +636,7 @@ def tex_cmdname(string): # >>> tex_cmdname('') # empty string # ('', '') + def tex_number(string): """Return leading number literal and remainder of `string`. @@ -630,6 +649,7 @@ def tex_number(string): return '', string return m.group(1), m.group(2) + # Test: # # >>> tex_number(' 23.4b') # leading whitespace -> no number @@ -643,6 +663,7 @@ def tex_number(string): # >>> tex_number('1 000.4') # ('1', ' 000.4') + def tex_token(string): """Return first simple TeX token and remainder of `string`. @@ -673,6 +694,7 @@ def tex_token(string): # >>> tex_token('\{escaped bracket') # ('\\{', 'escaped bracket') + def tex_group(string): """Return first TeX group or token and remainder of `string`. @@ -743,6 +765,7 @@ def tex_token_or_group(string): # >>> tex_token_or_group('\{no group but left bracket') # ('\\{', 'no group but left bracket') + def tex_optarg(string): """Return optional argument and remainder. @@ -1188,6 +1211,7 @@ def handle_cmd(name, node, string): # noqa: C901 TODO make this less complex # >>> handle_cmd('xleftarrow', math(), r'[\alpha=5]{10}') # (munderover(mo('⟵'), mrow(mi('α'), mo('='), mn('5'))), '{10}') + def handle_script_or_limit(node, c, limits=''): """Append script or limit element to `node`.""" child = node.children.pop() |
