docutils.utils.math.latex2mathml module
Convert LaTex maths code into presentational MathML.
This module is provisional: the API is not settled and may change with any minor Docutils version.
- class math(*children, **attributes)[source]
Bases:
objectBase class for MathML elements and root of MathML trees.
- nchildren = None
Expected number of children or None
- parent = None
Parent node in MathML DOM tree.
- _level = 0
- xml_entities = {38: '&', 60: '<', 62: '>', 8289: '⁡'}
- _boolstrings = {False: 'false', True: 'true'}
String representation of boolean MathML attribute values.
- html_tagname = 'span'
Tag name for HTML representation.
- __init__(*children, **attributes)[source]
Set up node with children and attributes.
Attributes are downcased: Use CLASS to set “class” value. >>> math(mn(3), CLASS=’test’) math(mn(3), class=’test’) >>> math(CLASS=’test’).toprettyxml() ‘<math class=”test”>
</math>’
- class MathRowSchema(*children, **attributes)[source]
Bases:
mathBase class for elements treating content as a single inferred mrow.
- class mtr(*children, **attributes)[source]
Bases:
MathRowSchema
- class mtd(*children, **attributes)[source]
Bases:
MathRowSchema
- class menclose(*children, **attributes)[source]
Bases:
MathRowSchema- nchildren = 1
Expected number of children or None
- class mphantom(*children, **attributes)[source]
Bases:
MathRowSchema- nchildren = 1
Expected number of children or None
- class msqrt(*children, **attributes)[source]
Bases:
MathRowSchema- nchildren = 1
Expected number of children or None
- class mstyle(*children, **attributes)[source]
Bases:
MathRowSchema- nchildren = 1
Expected number of children or None
- class MathToken(data, **attributes)[source]
Bases:
mathToken Element: contains textual data instead of children.
Base class for mo, mi, and mn.
- nchildren = 0
Expected number of children or None
- class MathSchema(*children, **kwargs)[source]
Bases:
mathBase class for schemata expecting 2 or more children.
The special attribute switch indicates that the last two child elements are in reversed order and must be switched before XML-export.
- nchildren = 2
Expected number of children or None
- class msub(*children, **kwargs)[source]
Bases:
MathSchema
- class msup(*children, **kwargs)[source]
Bases:
MathSchema
- class msubsup(*children, **kwargs)[source]
Bases:
MathSchema- nchildren = 3
Expected number of children or None
- class mroot(*children, **kwargs)[source]
Bases:
MathSchema- nchildren = 2
Expected number of children or None
- class mfrac(*children, **attributes)[source]
Bases:
math- nchildren = 2
Expected number of children or None
- class mspace(*children, **attributes)[source]
Bases:
math- nchildren = 0
Expected number of children or None
- tex_cmdname(string)[source]
Return leading TeX command name and remainder of string.
>>> tex_cmdname('mymacro2') # up to first non-letter ('mymacro', '2') >>> tex_cmdname('name 2') # strip trailing whitespace ('name', '2') >>> tex_cmdname('_2') # single non-letter character ('_', '2')
- tex_number(string)[source]
Return leading number literal and remainder of string.
>>> tex_number('123.4') ('123.4', '')
- tex_token(string)[source]
Return first simple TeX token and remainder of string.
>>> tex_token('\command{without argument}') ('\command', '{without argument}') >>> tex_token('or first character') ('o', 'r first character')
- tex_group(string)[source]
Return first TeX group or token and remainder of string.
>>> tex_group('{first group} returned without brackets') ('first group', ' returned without brackets')
- tex_token_or_group(string)[source]
Return first TeX group or token and remainder of string.
>>> tex_token_or_group('\command{without argument}') ('\command', '{without argument}') >>> tex_token_or_group('first character') ('f', 'irst character') >>> tex_token_or_group(' also whitespace') (' ', 'also whitespace') >>> tex_token_or_group('{first group} keep rest') ('first group', ' keep rest')
- tex_optarg(string)[source]
Return optional argument and remainder.
>>> tex_optarg('[optional argument] returned without brackets') ('optional argument', ' returned without brackets') >>> tex_optarg('{empty string, if there is no optional arg}') ('', '{empty string, if there is no optional arg}')
- parse_latex_math(node, string)[source]
Append MathML conversion of string to node and return it.
>>> parse_latex_math(math(), r'lpha') math(mi('α')) >>> parse_latex_math(mrow(), r'x_{n}') mrow(msub(mi('x'), mi('n')))
- handle_cmd(name, node, string)[source]
Process LaTeX command name followed by string.
Append result to node. If needed, parse string for command argument. Return new current node and remainder of string:
>>> handle_cmd('hbar', math(), r'
- rac’)
(math(mi(‘ℏ’)), ‘ frac’) >>> handle_cmd(‘hspace’, math(), r’{1ex} (x)’) (math(mspace(width=’1ex’)), ‘ (x)’)