Qucs-S S-parameter Viewer & RF Synthesis Tools
Loading...
Searching...
No Matches
Functions | Variables
docutils.utils.math.latex2mathml Namespace Reference

Functions

 tex_cmdname (string)
 
 tex_number (string)
 
 tex_token (string)
 
 tex_group (string)
 
 tex_token_or_group (string)
 
 tex_optarg (string)
 
 parse_latex_math (root, source)
 
 handle_cmd (name, node, string)
 
 handle_math_alphabet (name, node, string)
 
 handle_script_or_limit (node, c, limits='')
 
 begin_environment (node, string)
 
 end_environment (node, string)
 
 tex_equation_columns (rows)
 
 align_attributes (rows)
 
 tex2mathml (tex_math, as_block=False)
 

Variables

dict letters = {'hbar': 'ℏ'}
 
 ordinary = tex2unichar.mathord
 
dict greek_capitals
 
dict functions
 
dict modulo_functions
 
dict math_alphabets
 
dict stretchables
 
dict operators
 
dict thick_operators
 
dict small_operators
 
tuple movablelimits
 
dict spaces
 
dict accents
 
dict over
 
dict under
 
dict anomalous_chars
 
dict mathbb
 
dict matrices
 
dict layout_styles
 
dict fractions
 
list delimiter_sizes = ['', '1.2em', '1.623em', '2.047em', '2.470em']
 
dict bigdelimiters
 

Detailed Description

Convert LaTex maths code into presentational MathML.

This module is provisional:
the API is not settled and may change with any minor Docutils version.

Function Documentation

◆ handle_cmd()

docutils.utils.math.latex2mathml.handle_cmd (   name,
  node,
  string 
)
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' \frac')
(math(mi('ℏ')), ' \\frac')
>>> handle_cmd('hspace', math(), r'{1ex} (x)')
(math(mspace(width='1ex')), ' (x)')

◆ handle_script_or_limit()

docutils.utils.math.latex2mathml.handle_script_or_limit (   node,
  c,
  limits = '' 
)
Append script or limit element to `node`.

◆ parse_latex_math()

docutils.utils.math.latex2mathml.parse_latex_math (   root,
  source 
)
Append MathML conversion of `string` to `node` and return it.

>>> parse_latex_math(math(), r'\alpha')
math(mi('α'))
>>> parse_latex_math(mrow(), r'x_{n}')
mrow(msub(mi('x'), mi('n')))

◆ tex2mathml()

docutils.utils.math.latex2mathml.tex2mathml (   tex_math,
  as_block = False 
)
Return string with MathML code corresponding to `tex_math`.

Set `as_block` to ``True`` for displayed formulas.

◆ tex_cmdname()

docutils.utils.math.latex2mathml.tex_cmdname (   string)
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_group()

docutils.utils.math.latex2mathml.tex_group (   string)
Return first TeX group or token and remainder of `string`.

>>> tex_group('{first group} returned without brackets')
('first group', ' returned without brackets')

◆ tex_number()

docutils.utils.math.latex2mathml.tex_number (   string)
Return leading number literal and remainder of `string`.

>>> tex_number('123.4')
('123.4', '')

◆ tex_optarg()

docutils.utils.math.latex2mathml.tex_optarg (   string)
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}')

◆ tex_token()

docutils.utils.math.latex2mathml.tex_token (   string)
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_token_or_group()

docutils.utils.math.latex2mathml.tex_token_or_group (   string)
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')

Variable Documentation

◆ accents

dict docutils.utils.math.latex2mathml.accents
Initial value:
1= {
2 # TeX: spacing combining
3 'acute': '´', # '\u0301'
4 'bar': 'ˉ', # '\u0304'
5 'breve': '˘', # '\u0306'
6 'check': 'ˇ', # '\u030C'
7 'dot': '˙', # '\u0307'
8 'ddot': '¨', # '\u0308'
9 'dddot': '˙˙˙', # '\u20DB' # or … ?
10 'ddddot': '˙˙˙˙', # '\u20DC' # or ¨¨ ?
11 'grave': '`', # '\u0300'
12 'hat': 'ˆ', # '\u0302'
13 'mathring': '˚', # '\u030A'
14 'tilde': '~', # '\u0303' # tilde ~ or small tilde ˜?
15 'vec': '→', # '\u20d7' # → too heavy, use scriptlevel="+1"
16}

◆ anomalous_chars

dict docutils.utils.math.latex2mathml.anomalous_chars
Initial value:
1= {'-': '\u2212', # HYPHEN-MINUS -> MINUS SIGN
2 ':': '\u2236', # COLON -> RATIO
3 '~': '\u00a0', # NO-BREAK SPACE
4 }

◆ bigdelimiters

dict docutils.utils.math.latex2mathml.bigdelimiters
Initial value:
1= {'left': 0,
2 'right': 0,
3 'bigl': 1,
4 'bigr': 1,
5 'Bigl': 2,
6 'Bigr': 2,
7 'biggl': 3,
8 'biggr': 3,
9 'Biggl': 4,
10 'Biggr': 4,
11 }

◆ fractions

dict docutils.utils.math.latex2mathml.fractions
Initial value:
1= {
2 # name: attributes
3 'frac': {},
4 'cfrac': {'displaystyle': True, 'scriptlevel': 0,
5 'class': 'cfrac'}, # in LaTeX with padding
6 'dfrac': layout_styles['displaystyle'],
7 'tfrac': layout_styles['textstyle'],
8 'binom': {'linethickness': 0},
9 'dbinom': layout_styles['displaystyle'] | {'linethickness': 0},
10 'tbinom': layout_styles['textstyle'] | {'linethickness': 0},
11}

◆ functions

dict docutils.utils.math.latex2mathml.functions
Initial value:
1= {
2 # functions with a space in the name
3 'liminf': 'lim\u202finf',
4 'limsup': 'lim\u202fsup',
5 'injlim': 'inj\u202flim',
6 'projlim': 'proj\u202flim',
7 # embellished function names (see handle_cmd() below)
8 'varlimsup': 'lim',
9 'varliminf': 'lim',
10 'varprojlim': 'lim',
11 'varinjlim': 'lim',
12 # custom function name
13 'operatorname': None,
14}

◆ greek_capitals

dict docutils.utils.math.latex2mathml.greek_capitals
Initial value:
1= {
2 'Phi': '\u03a6', 'Xi': '\u039e', 'Sigma': '\u03a3',
3 'Psi': '\u03a8', 'Delta': '\u0394', 'Theta': '\u0398',
4 'Upsilon': '\u03d2', 'Pi': '\u03a0', 'Omega': '\u03a9',
5 'Gamma': '\u0393', 'Lambda': '\u039b'}

◆ layout_styles

dict docutils.utils.math.latex2mathml.layout_styles
Initial value:
1= {
2 'displaystyle': {'displaystyle': True, 'scriptlevel': 0},
3 'textstyle': {'displaystyle': False, 'scriptlevel': 0},
4 'scriptstyle': {'displaystyle': False, 'scriptlevel': 1},
5 'scriptscriptstyle': {'displaystyle': False, 'scriptlevel': 2},
6 }

◆ math_alphabets

dict docutils.utils.math.latex2mathml.math_alphabets
Initial value:
1= {
2 # 'cmdname': 'mathvariant value' # package
3 'mathbb': 'double-struck', # amssymb
4 'mathbf': 'bold',
5 'mathbfit': 'bold-italic', # isomath
6 'mathcal': 'script',
7 'mathfrak': 'fraktur', # amssymb
8 'mathit': 'italic',
9 'mathrm': 'normal',
10 'mathscr': 'script', # mathrsfs et al
11 'mathsf': 'sans-serif',
12 'mathbfsfit': 'sans-serif-bold-italic', # unicode-math
13 'mathsfbfit': 'sans-serif-bold-italic', # isomath
14 'mathsfit': 'sans-serif-italic', # isomath
15 'mathtt': 'monospace',
16 # unsupported: bold-fraktur
17 # bold-script
18 # bold-sans-serif
19}

◆ mathbb

dict docutils.utils.math.latex2mathml.mathbb
Initial value:
1= {'Γ': '\u213E', # ℾ
2 'Π': '\u213F', # ℿ
3 'Σ': '\u2140', # ⅀
4 'γ': '\u213D', # ℽ
5 'π': '\u213C', # ℼ
6 }

◆ matrices

dict docutils.utils.math.latex2mathml.matrices
Initial value:
1= {
2 # name: fences
3 'matrix': ('', ''),
4 'smallmatrix': ('', ''), # smaller, see begin_environment()!
5 'pmatrix': ('(', ')'),
6 'bmatrix': ('[', ']'),
7 'Bmatrix': ('{', '}'),
8 'vmatrix': ('|', '|'),
9 'Vmatrix': ('\u2016', '\u2016'), # ‖
10 'aligned': ('', ''),
11 'cases': ('{', ''),
12}

◆ modulo_functions

dict docutils.utils.math.latex2mathml.modulo_functions
Initial value:
1= {
2 # cmdname: (binary, named, parentheses, padding)
3 'bmod': (True, True, False, '0.278em'), # a mod n
4 'pmod': (False, True, True, '0.444em'), # a (mod n)
5 'mod': (False, True, False, '0.667em'), # a mod n
6 'pod': (False, False, True, '0.444em'), # a (n)
7 }

◆ movablelimits

tuple docutils.utils.math.latex2mathml.movablelimits
Initial value:
1= ('bigcap', 'bigcup', 'bigodot', 'bigoplus', 'bigotimes',
2 'bigsqcup', 'biguplus', 'bigvee', 'bigwedge',
3 'coprod', 'intop', 'ointop', 'prod', 'sum',
4 'lim', 'max', 'min', 'sup', 'inf')

◆ operators

dict docutils.utils.math.latex2mathml.operators
Initial value:
1= {
2 # negated symbols without pre-composed Unicode character
3 'nleqq': '\u2266\u0338', # ≦̸
4 'ngeqq': '\u2267\u0338', # ≧̸
5 'nleqslant': '\u2a7d\u0338', # ⩽̸
6 'ngeqslant': '\u2a7e\u0338', # ⩾̸
7 'ngtrless': '\u2277\u0338', # txfonts
8 'nlessgtr': '\u2276\u0338', # txfonts
9 'nsubseteqq': '\u2AC5\u0338', # ⫅̸
10 'nsupseteqq': '\u2AC6\u0338', # ⫆̸
11 # compatibility definitions:
12 'centerdot': '\u2B1D', # BLACK VERY SMALL SQUARE | mathbin
13 'varnothing': '\u2300', # ⌀ DIAMETER SIGN | empty set
14 'varpropto': '\u221d', # ∝ PROPORTIONAL TO | sans serif
15 'triangle': '\u25B3', # WHITE UP-POINTING TRIANGLE | mathord
16 'triangledown': '\u25BD', # WHITE DOWN-POINTING TRIANGLE | mathord
17 # alias commands:
18 'dotsb': '\u22ef', # ⋯ with binary operators/relations
19 'dotsc': '\u2026', # … with commas
20 'dotsi': '\u22ef', # ⋯ with integrals
21 'dotsm': '\u22ef', # ⋯ multiplication dots
22 'dotso': '\u2026', # … other dots
23 # functions with movable limits (requires <mo>)
24 'lim': 'lim',
25 'sup': 'sup',
26 'inf': 'inf',
27 'max': 'max',
28 'min': 'min',
29}

◆ over

dict docutils.utils.math.latex2mathml.over
Initial value:
1= {
2 # TeX: (char, offset-correction/em)
3 'overbrace': ('\u23DE', -0.2), # DejaVu Math -0.6
4 'overleftarrow': ('\u2190', -0.2),
5 'overleftrightarrow': ('\u2194', -0.2),
6 'overline': ('_', -0.2), # \u2012 does not stretch
7 'overrightarrow': ('\u2192', -0.2),
8 'widehat': ('^', -0.5),
9 'widetilde': ('~', -0.3),
10}

◆ small_operators

dict docutils.utils.math.latex2mathml.small_operators
Initial value:
1= {
2 # mathsize='75%'
3 'shortmid': '\u2223', # ∣
4 'shortparallel': '\u2225', # ∥
5 'nshortmid': '\u2224', # ∤
6 'nshortparallel': '\u2226', # ∦
7 'smallfrown': '\u2322', # ⌢ FROWN
8 'smallsmile': '\u2323', # ⌣ SMILE
9 'smallint': '\u222b', # ∫ INTEGRAL
10}

◆ spaces

dict docutils.utils.math.latex2mathml.spaces
Initial value:
1= {'qquad': '2em', # two \quad
2 'quad': '1em', # 18 mu
3 'thickspace': '0.2778em', # 5mu = 5/18em
4 ';': '0.2778em', # 5mu thickspace
5 ' ': '0.25em', # inter word space
6 '\n': '0.25em', # inter word space
7 'medspace': '0.2222em', # 4mu = 2/9em
8 ':': '0.2222em', # 4mu medspace
9 'thinspace': '0.1667em', # 3mu = 1/6em
10 ',': '0.1667em', # 3mu thinspace
11 'negthinspace': '-0.1667em', # -3mu = -1/6em
12 '!': '-0.1667em', # negthinspace
13 'negmedspace': '-0.2222em', # -4mu = -2/9em
14 'negthickspace': '-0.2778em', # -5mu = -5/18em
15 }

◆ stretchables

dict docutils.utils.math.latex2mathml.stretchables
Initial value:
1= {
2 # extensible delimiters allowed in left/right cmds
3 'backslash': '\\',
4 'uparrow': '\u2191', # ↑ UPWARDS ARROW
5 'downarrow': '\u2193', # ↓ DOWNWARDS ARROW
6 'updownarrow': '\u2195', # ↕ UP DOWN ARROW
7 'Uparrow': '\u21d1', # ⇑ UPWARDS DOUBLE ARROW
8 'Downarrow': '\u21d3', # ⇓ DOWNWARDS DOUBLE ARROW
9 'Updownarrow': '\u21d5', # ⇕ UP DOWN DOUBLE ARROW
10 'lmoustache': '\u23b0', # ⎰ … CURLY BRACKET SECTION
11 'rmoustache': '\u23b1', # ⎱ … LEFT CURLY BRACKET SECTION
12 'arrowvert': '\u23d0', # ⏐ VERTICAL LINE EXTENSION
13 'bracevert': '\u23aa', # ⎪ CURLY BRACKET EXTENSION
14 'lvert': '|', # left |
15 'lVert': '\u2016', # left ‖
16 'rvert': '|', # right |
17 'rVert': '\u2016', # right ‖
18 'Arrowvert': '\u2016', # ‖
19}

◆ thick_operators

dict docutils.utils.math.latex2mathml.thick_operators
Initial value:
1= {
2 # style='font-weight: bold;'
3 'thicksim': '\u223C', # ∼
4 'thickapprox': '\u2248', # ≈
5}

◆ under

dict docutils.utils.math.latex2mathml.under
Initial value:
1= {'underbrace': ('\u23DF', 0.1), # DejaVu Math -0.7
2 'underleftarrow': ('\u2190', -0.2),
3 'underleftrightarrow': ('\u2194', -0.2),
4 'underline': ('_', -0.8),
5 'underrightarrow': ('\u2192', -0.2),
6 }