-
Notifications
You must be signed in to change notification settings - Fork 12
/
amsmath.py
79 lines (60 loc) · 2.4 KB
/
amsmath.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#
# YaLafi module for LaTeX package amsmath
#
from yalafi.defs import Macro, InitModule, EquEnv, SpecialToken
require_packages = []
#
# Please note:
# - For all undeclared maths macros, which are not blacklisted in
# Parameters.math_ignore (yalafi/parameters.py), we assume that
# a part of a mathematical term or an operator is left.
# - The spacing macros and \notag are imporant for correct parsing
# of maths material.
#
def init_module(parser, options, position):
parms = parser.parms
parms.math_text_macros.append('\\text')
macros_latex = r"""
\newcommand{\eqref}[1]{(0)}
\newcommand{\medspace}{\:}
\newcommand{\negmedspace}{}
\newcommand{\negthickspace}{}
\newcommand{\negthinspace}{}
\newcommand{\notag}{}
\newcommand{\numberwithin}[2]{}
\newcommand{\thickspace}{\;}
\newcommand{\thinspace}{\,}
"""
macros_python = [
Macro(parms, '\\DeclareMathOperator', args='*AA'),
Macro(parms, '\\substack', args='A', repl=h_substack),
]
environments = [
EquEnv(parms, 'align'),
EquEnv(parms, 'align*'),
EquEnv(parms, 'alignat', args='A'),
EquEnv(parms, 'alignat*', args='A'),
EquEnv(parms, 'equation'),
EquEnv(parms, 'equation*'),
EquEnv(parms, 'flalign'),
EquEnv(parms, 'flalign*'),
EquEnv(parms, 'gather'),
EquEnv(parms, 'gather*'),
EquEnv(parms, 'multline', no_first_section=True),
EquEnv(parms, 'multline*', no_first_section=True),
EquEnv(parms, 'multlined', args='O', no_first_section=True),
# Add aligned such that its begin cycles the replacements:
EquEnv(parms, 'aligned', args='O'),
]
inject_tokens = [] # this list of tokens is used as replacement
# for '\documentclass...' or '\usepackage...'
return InitModule(macros_latex=macros_latex, macros_python=macros_python,
environments=environments, inject_tokens=inject_tokens)
# macro \substack: replace \\ tokens with space
#
def h_substack(parser, buf, mac, args, delim, pos):
def f(tok, lev):
if tok.txt == r'\\' and lev == 0:
return SpecialToken(tok.pos, r'\;')
return tok
return [f(tok, lev) for tok, lev in parser.iter_token_levels(args[0])]