This repository has been archived by the owner on Aug 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_display.py
207 lines (193 loc) · 3.75 KB
/
test_display.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#
# test of display math
#
from yalafi import parameters, parser, utils
latex_1 = r"""
\usepackage{amsmath}
A
\begin{align}
a &= b \\
-c &= d.
\end{align}
B
"""
plain_1 = r"""
A
V-V-V equal W-W-W
W-W-W equal X-X-X.
B
"""
def test_1():
p = parser.Parser(parameters.Parameters())
toks = p.parse(latex_1)
plain, pos = utils.get_txt_pos(toks)
assert plain_1 == plain
latex_2 = r"""
\usepackage{amsmath}
\begin{align}
a &= b, \\
-c &= d
\end{align}
"""
plain_2 = r"""
V-V-V equal W-W-W,
X-X-X equal Y-Y-Y
"""
def test_2():
p = parser.Parser(parameters.Parameters())
toks = p.parse(latex_2)
plain, pos = utils.get_txt_pos(toks)
assert plain_2 == plain
latex_3 = r"""
\usepackage{amsmath}
\begin{align}
a &= b \\
& \quad -c \\
& {} \cdot d \\
& \mbox{} \times e.
\end{align}
"""
plain_3 = r"""
V-V-V equal W-W-W
minus X-X-X
times Y-Y-Y
times Z-Z-Z.
"""
def test_3():
p = parser.Parser(parameters.Parameters())
toks = p.parse(latex_3)
plain, pos = utils.get_txt_pos(toks)
assert plain_3 == plain
latex_4 = r"""
\usepackage{amsmath}
\begin{align}
a &= b \text{ for all $c$.} \\
d &\ne e.
\end{align}
"""
plain_4 = r"""
V-V-V equal W-W-W for all C-C-C.
X-X-X equal Y-Y-Y.
"""
def test_4():
p = parser.Parser(parameters.Parameters())
toks = p.parse(latex_4)
plain, pos = utils.get_txt_pos(toks)
assert plain_4 == plain
latex_4a = r"""
\usepackage{amsmath}
\begin{align}
a &= b \text{ for all $c$}. \\
d &\ne e.
\end{align}
"""
plain_4a = r"""
V-V-V equal W-W-W for all C-C-C.
X-X-X equal Y-Y-Y.
"""
def test_4a():
p = parser.Parser(parameters.Parameters())
toks = p.parse(latex_4a)
plain, pos = utils.get_txt_pos(toks)
assert plain_4a == plain
latex_5 = r"""
\usepackage{amsmath}
\begin{align}
a &= b \text{ for all } c. \\
d &\ne e.
\end{align}
"""
plain_5 = r"""
V-V-V equal W-W-W for all X-X-X.
Y-Y-Y equal Z-Z-Z.
"""
def test_5():
p = parser.Parser(parameters.Parameters())
toks = p.parse(latex_5)
plain, pos = utils.get_txt_pos(toks)
assert plain_5 == plain
latex_6 = r"""
\usepackage{amsmath}
\begin{alignat}
{2}
&- b
\end{alignat}
"""
plain_6 = r"""
minus V-V-V
"""
def test_6():
p = parser.Parser(parameters.Parameters())
toks = p.parse(latex_6)
plain, pos = utils.get_txt_pos(toks)
assert plain_6 == plain
latex_7 = r"""
\begin{eqnarray}
a: &-& b
\end{eqnarray}
"""
plain_7 = r"""
V-V-V: minus W-W-W
"""
def test_7():
p = parser.Parser(parameters.Parameters())
toks = p.parse(latex_7)
plain, pos = utils.get_txt_pos(toks)
assert plain_7 == plain
latex_8 = r"""
\[
\beta
\]
A
$$
\Omega
$$
"""
plain_8 = r"""
V-V-V
A
W-W-W
"""
def test_8():
p = parser.Parser(parameters.Parameters())
toks = p.parse(latex_8)
plain, pos = utils.get_txt_pos(toks)
assert plain_8 == plain
latex_9 = r"""
\usepackage{.tests.defs}
\begin{flalign}
x
\end{flalign}
A
\begin{flalign}
y,
\end{flalign}
"""
plain_9 = r"""
relation
A
relation,
"""
def test_9():
p = parser.Parser(parameters.Parameters())
toks = p.parse(latex_9)
plain, pos = utils.get_txt_pos(toks)
assert plain_9 == plain
# simplified equation parsing
#
latex_10 = r"""
\usepackage{amsmath}
\begin{align}
a &= b.
\end{align}
"""
plain_10 = r"""
W-W-W.
"""
def test_10():
parms = parameters.Parameters()
parms.math_displayed_simple = True
p = parser.Parser(parms)
toks = p.parse(latex_10)
plain, pos = utils.get_txt_pos(toks)
assert plain_10 == plain