1 /* Various tests of TeX output. Run it via batch("tests/rtest_tex.mac").
2 * This program is not organized (at present) in actual result -- expected result pairs.
6 (print ("\\documentclass{article}"),
7 print (concat ("\\title{", s, "}")),
8 print ("\\author{by Maxim A.}"),
9 print ("\\begin{document}"),
10 print ("\\maketitle"));
12 latex1 () := print ("\\end{document}");
14 tex_text (s) := block ([linel: 2^16], print (s));
16 /* These declarations must precede the first expression in which they occur.
17 * Maxima doesn't know how to parse "a foo b" in with_stdout (... infix("foo"), a foo b, ...).
19 (prefix ("fooprefix"), infix ("implies"), infix ("iff"), nary ("foonary"),
20 postfix ("foopostfix"), matchfix ("<<", ">>"), nofix ("foonofix"));
22 '((aa or bb) and not (cc or dd));
24 with_stdout ("tmp-rtest-1.tex",
25 (latex0 ("Maxima \\TeX\\ test page"),
27 tex_text ("\\subsection*{Symbols and subscripts}"),
30 tex ([inf, minf, true, false, done]),
31 map (tex, [inf, minf, true, false, done]),
32 tex (%pi + %e + %i + %gamma),
34 tex ([alpha, beta, verbify (gamma), delta, epsilon, zeta, eta, theta, iota, kappa, lambda, mu]),
35 tex ([nu, xi, omicron, pi, rho, sigma, tau, upsilon, phi, chi, psi, omega]),
36 tex ([Alpha, Beta, Gamma, Delta, Epsilon, Zeta, Eta, Theta, Iota, Kappa, Lambda, Mu]),
37 tex ([Nu, Xi, Omicron, Pi, Rho, Sigma, Tau, Upsilon, Phi, Chi, Psi, Omega]),
38 tex (A1 + B2 + C3 + A_1 + B_2 + C_3),
39 tex (A1a + B2b + C3c + A1_a + B2_b + C3_c),
40 tex (Foo[1] + BAR[2] + baz[3]),
41 tex (Mumble[i,j] + blurf[a][b]),
42 tex (\2F1 + ?lisp_symbol),
43 tex (embedded\$dollar + embedded%percent + embedded_underscore + embedded\&ersand),
45 tex_text ("\\subsubsection*{Explicit and implicit subscripts}"),
46 tex_text ("In each of the next several lists, all items in a list should be identical."),
47 tex_text ("Variable name is ``ABC''."),
48 tex ([ABC123, ABC_123, ABC__123, ABC___123, ABC[123]]),
49 tex_text ("Variable name is ``abc''."),
50 tex ([abc123, abc_123, abc__123, abc___123, abc[123]]),
51 tex_text ("Variable name is ``Abc''."),
52 tex ([Abc123, Abc_123, Abc__123, Abc___123, Abc[123]]),
53 tex_text ("Multiple subscripts."),
54 tex ([ABC_1_2_3, ABC[1, 2, 3]]),
55 tex_text ("Ensure that the leading percent sign is preserved in this next one."),
56 tex ([%A_1_B_2_C_3, %A_1_B_2_C[3]]),
57 tex_text ("Expect subscripted ``\\%gamma'' to be displayed as math symbol."),
58 tex ([%gamma3, %gamma_3, %gamma[3]]),
60 tex_text ("\\subsubsection*{Gamma functions and variables}"),
61 tex_text ("Variables: \\%gamma (Euler-Mascheroni number), Gamma, nounify(gamma), verbify(gamma):"),
62 tex ([%gamma = ev (%gamma, numer), Gamma, nounify (gamma), verbify (gamma)]),
63 tex_text ("Functions: gamma(z) (gamma function), gamma\\_incomplete(a, z) (upper incomplete gamma function),
64 gamma\\_incomplete\\_regularized(a, z) (gamma\\_incomplete normalized by gamma(z)),
65 gamma\\_incomplete\\_generalized(a, z[1], z[2]) (upper minus lower incomplete gamma function),
66 gamma\\_incomplete\\_lower(a, z) (lower incomplete gamma function):"),
67 tex ([gamma (z), gamma_incomplete (a, z), gamma_incomplete_regularized (a, z),
68 gamma_incomplete_generalized (a, z[1], z[2]), gamma_incomplete_lower (a, z)]),
70 /* Maxima tex function doesn't escape special characters in symbol names,
71 * so don't bother with these unless TEX-STRIPDOLLAR is revised or something like that.
72 * tex (int\+float + int\*float + int\@float),
73 * tex (?\*lisp\-symbol\-2\*),
76 tex_text ("\\subsection*{Lisp pointers}"),
77 tex(make_array(fixnum,5)),
78 tex(gf_set_data(3,x^4+x+1)),
80 tex_text ("\\subsection*{Strings}"),
84 tex ("Riff Raff (enclosed in `quote marks')"),
86 tex ("String containing
88 tex ("String containing \\ldots \\\"Oyster sh\\'ell \\ldots some \\TeX\\ commands."),
89 tex ("Some characters \\{ \\ \\^ % _ $ \\# \\~ & \\} which might be special to \\TeX\\ and \\LaTeX."),
90 tex_text ("String containing \\ldots \\\"Oyster sh\\'ell \\ldots some \\TeX\\ commands. Some characters \\{ \\ \\^ \\% \\_ \\$ \\# \\~ \\& \\} which might be special to \\TeX\\ and \\LaTeX. (Same as the preceding example, but output {\\it via} {\\bf print} instead of {\\bf tex}; should make a paragraph instead of an equation.)"),
92 tex_text ("\\subsection*{Different kinds of numbers}"),
93 ev (tex (1 + 1/1 + 1.0 + 1e0 + 1b0), simp=false),
94 ev (tex (12345678901234567890 + 1/12345678901234567890), simp=false),
95 ev (tex (12345678901234567890e200 + 12345678901234567890b-200), simp=false, fpprec=20),
96 tex (123b456/a + 123d42/b + (123/456)/c),
97 tex (123 + 456*x + 789.0*x^2 + 987e50*x^3 + 654b-50*x^4 + 1729b+42*x^5),
98 tex (123b-456^a + 123d-45^b + sqrt (123b-456) + sqrt (123d-45)),
99 /* Next few are specifically to test for a bug in TEX-MEXPT
101 tex (1.234^m + 5.678^n - 1.234b0^m + 5.678b0^n),
102 tex (1.234^m * 5.678^n . 1.234b0^m * 5.678b0^n),
103 tex ((1.234^m) ^ (5.678^n) ^^ (1.234b0^m) ^ (5.678b0^n)),
105 tex_text ("\\subsection*{Various operators}"),
110 tex (a.b * c.d + (a*b).(c*d)),
112 ev (tex ((a/b)/(c/d)), simp=false),
119 tex (sin(a) + cos(a) + tan(a) + sec(a) + csc(a) + cot(a)),
120 tex (asin(a) + acos(a) + atan(a) + atan2(b,a) + asec(a) + acsc(a) + acot(a)),
121 tex (sinh(a) + cosh(a) + tanh(a) + sech(a) + csch(a) + coth(a)),
122 tex (asinh(a) + acosh(a) + atanh(a) + asech(a) + acsch(a) + acoth(a)),
123 tex (exp(x) + log(a) + erf(a)),
125 tex (sin(%pi*a/n) + cos(%pi*a/n) + tan(%pi*a/n) + sec(%pi*a/n) + csc(%pi*a/n) + cot(%pi*a/n)),
126 tex (asin(%pi*a/n) + acos(%pi*a/n) + atan(%pi*a/n) + atan2(%pi*a/n,%pi*b/n) + asec(%pi*a/n) + acsc(%pi*a/n) + acot(%pi*a/n)),
127 tex (sinh(%pi*a/n) + cosh(%pi*a/n) + tanh(%pi*a/n) + sech(%pi*a/n) + csch(%pi*a/n) + coth(%pi*a/n)),
128 tex (asinh(%pi*a/n) + acosh(%pi*a/n) + atanh(%pi*a/n) + asech(%pi*a/n) + acsch(%pi*a/n) + acoth(%pi*a/n)),
130 tex (exp(1 + x + x^2 + x^3) + exp (exp (-x))),
131 tex (log(b + a) + log((b + a)/(b - a))),
133 tex ('integrate (exp(-a*x^2), x, minf, inf)),
134 tex ('sum (1/k^2, k, 1, inf)),
135 tex ('lsum (1/k^2, k, Z)),
136 tex (diff (Omega (omega))),
138 tex ('diff (exp (-a*x), x)),
139 tex ('diff (a(x) * 'diff (F, x), x) + a(x) * 'diff (F, x, 2)),
140 tex ('limit (exp (-a*x), x, inf)),
141 tex ('limit (exp (-a*x), x, 0, plus)),
142 tex ('limit (exp (-a*x), x, 0, minus)),
147 tex ('((riff or raff) and not (roff or ruff))),
148 tex ('(not foo ((a + b)^2/(a - b)^2) or bar (x and baz (sqrt(y^n)) or z))),
150 tex_text ("\\subsection*{Lists, matrices, and sets}"),
151 tex ([a, b, c, d, e]),
152 tex ([a + b, a*b, a/b, a^b, a^b^c]),
153 tex (matrix ([a, b], [c, d])),
154 tex (matrix ([a + b, a*b], [a^b, a^b^c])),
155 tex ({a, b, c, d, e}),
156 tex ({a + b, a*b, a/b, a^b, a^b^c}),
158 tex_text ("\\subsubsection*{Binomial}"),
159 tex (xyz + binomial (foo(a)/foo(b), bar(a)/bar(b)) + abc),
161 tex_text ("\\subsection*{User-defined \\TeX\\ properties}"),
163 /* User-defined operator declarations have to be outside with_stdout.
164 * See note near top of file.
167 tex_text ("\\def\\sgn{\\mathop{\\rm sgn}}"),
168 tex ('("Before texput" : [foo, signum(x)])),
169 texput (signum, "\\sgn"),
170 texput (foo, "\\phi\\upsilon"),
171 tex ('("After texput" : [foo, signum(x)])),
173 tex ('("Before texput" : [grad(x), fooprefix x, grad (fooprefix x)])),
174 texput (grad, "\\nabla ", prefix),
175 texput ("fooprefix", "\\mathrm{foo}\\;", prefix),
176 tex ('("After texput" : [grad(x), fooprefix x, grad (fooprefix x)])),
178 tex ('("Before texput" : ((foo or bar) implies (baz or quux)))),
179 texput ("implies", "\\Rightarrow", infix),
180 tex ('("After texput" : ((foo or bar) implies (baz or quux)))),
182 tex ('("Before texput" : ((foo or bar) iff (baz or quux)))),
183 texput ("iff", "\\Leftrightarrow", infix),
184 tex ('("After texput" : ((foo or bar) iff (baz or quux)))),
186 tex ('("Before texput" : aa foonary bb foonary cc foonary dd)),
187 texput ("foonary", "\\;\\mathbf{foo}\\;", nary),
188 tex ('("After texput" : aa foonary bb foonary cc foonary dd)),
190 tex ('("Before texput" : [degrees_F(85), x foopostfix, degrees_F (x foopostfix)])),
191 texput (degrees_F, "^o\\;{\\rm F}", postfix),
192 texput ("foopostfix", "\\;\\mathit{foo}", postfix),
193 tex ('("After texput" : [degrees_F(85), x foopostfix, degrees_F (x foopostfix)])),
195 tex ('("Before texput" : <<x, y>>)),
196 texput ("<<", [" \\langle ", " \\rangle "], matchfix),
197 tex ('("After texput" : <<x, y>>)),
199 tex ('("Before texput" : foonofix)),
200 texput ("foonofix", "\\;\\mathsf{foo}\\;", nofix),
201 tex ('("After texput" : foonofix)),
203 tex ('("All together now" : <<fooprefix foo foonary foo foonary foonofix foopostfix>>)),
205 tex_text ("\\subsection*{Miscellany}"),
207 tex_text ("Next few should all be the same."),
208 tex ('((aa or bb) and not (cc or dd))),
209 '((aa or bb) and not (cc or dd)),
211 tex (_), /* refers to the input expression immediately preceding "with_stdout" */
213 tex_text ("I forget what this one is for."),
214 '((aa or bb) and not (cc or dd)),
215 (tex (''(second (labels (%i)))), tex (''(first (labels (%o))))),
216 tex ('((tex (''(second (labels (%i)))), tex (''(first (labels (%o))))))),
218 tex_text ("A function and its output."),
220 (tex ('integrate (x^n, x, 0, inf)),
221 tex ('sum (x^n, n, 1, inf)),
222 tex ('limit (x^n, x, inf)),
223 tex ('diff (x^n, x))),
227 /* tex_text ("This one should be the whole with\\_stdout thing."),
228 * tex (''(first (labels (%i)))),
232 /* Test output options: standard output, string, file, and stream.
235 with_stdout ("tmp-rtest-2a.tex",
236 tex ("Capture standard output to tmp-rtest-2a.tex."));
238 S : tex ("Capture string output to S, then write S to tmp-rtest-2b.tex.", false);
239 s : openw ("tmp-rtest-2b.tex");
240 printf (s, "~a~%", S);
243 tex ("Write output directly to tmp-rtest-2c.tex.", "tmp-rtest-2c.tex");
245 s : openw ("tmp-rtest-2d.tex");
246 tex ("Write output to output stream opened to tmp-rtest-2d.tex.", s);
249 /* Test TeX environment functions.
252 set_tex_environment_default ("
258 set_tex_environment ("=", "$", "$");
259 set_tex_environment (":=", "$$", "$$");
261 s : openw ("tmp-rtest-3.tex");
264 print ("\\documentclass{article}"),
265 print ("\\title{A \\TeX\\ environment test}"),
266 print ("\\author{Maxim A.}"),
267 print ("\\begin{document}"),
268 print ("\\maketitle"),
269 print ("Here are some formulas. These should be numbered."),
270 tex ((a + b)/(c + d)),
271 tex (sin(x)/(1-sin(x))),
272 tex (erf(x)*gamma(x)),
273 print ("More text here. Followed by a formula embedded in the text."),
275 print ("More text here. A function definition."),
276 tex (foo(x) := 1 - 1/x));
279 tex_text ("Let's take this opportunity to test the interaction of\
280 $\\mathbf{tex}$ and $\\mathbf{ordergreat}$."),
281 tex_text ("Here are some variables before calling $\\mathbf{ordergreat}$."),
282 tex (x + y + z + t = x * y * z * t));
284 ordergreat (x, y, z, t);
287 tex_text ("After calling $\\mathbf{ordergreat}(x, y, z, t)$, which constructs alias variables.\
288 We should still see just the original variables."),
289 tex (x + y + z + t = x * y * z * t),
290 print ("That's all, folks."),
291 print ("\\end{document}"));
294 unorder (); /* undo ordergreat above */
296 s : openw ("tmp-rtest-4.tex");
298 kill (a, b, c, d, foo, bar, baz, quux, u, v, w, x, y, z);
301 print ("\\documentclass{article}"),
302 print ("\\title{More \\TeX\\ examples}"),
303 print ("\\author{Maxim B.}"),
304 print ("\\begin{document}"),
305 print ("\\maketitle"),
306 tex_text ("Here are some more examples. Trying to cover all the bases here.\
307 These were discovered by tracing all the functions named in 'TEX properties\
308 and seeing which ones were not yet called."),
311 print ("'at noun expressions."),
313 tex ('at (f (u), u = 0)),
314 tex (1 / (1 - 'at (diff (f (u), u), u = 0))),
316 print ("Bigfloats."),
318 tex ([0b0, 1b0, -1b0, 1b100]),
319 tex ((foo (0b0) + bar (1b0))/(baz (-1b0) - quux (1b100))),
321 print ("Binomials."),
323 tex ('binomial (N, M)),
324 tex ((a + 'binomial (f (u), sqrt (v)))^(1/2)),
326 print ("Cube roots."),
329 tex (sin (cubrt (1 - %pi))),
331 print ("Kronecker delta."),
333 tex (kron_delta (0, u)),
334 tex ((x - kron_delta (cos (y), sin (z)))^n),
337 * OMIT -- BOX SEEMS TO BE AMSTEX-SPECIFIC.
339 print ("Stuff in boxes."),
341 tex (sqrt (box (1 - box (tan (u))))),
344 print ("Conditional expressions (verbs)."),
346 tex (if 'a > 'b then a else b),
347 tex (if 'a > 'b then (if 'a > 'c then 'a else 'c) else b),
348 tex (if 'a > 'b then a elseif 'c > 'b then c else b),
349 tex (1 + if 'a > 'b then sqrt(a) else b^3),
351 print ("Conditional expressions (nouns)."),
353 tex ('if 'a > 'b then a else b),
354 tex ('if 'a > 'b then ('if 'a > 'c then 'a else 'c) else b),
355 tex ('if 'a > 'b then a elseif 'c > 'b then c else b),
356 tex (1 + 'if 'a > 'b then sqrt(a) else b^3),
358 print ("For-loop expressions (nouns)."),
360 tex ('for i thru n do print (i)),
361 tex (m * 'for i thru floor ((n + 1)/7) do print (i)),
363 print ("For-loop expressions (verbs)."),
365 tex ('(for i thru n do print (i))),
366 tex (m * '(for i thru floor ((n + 1)/7) do print (i))),
368 print ("For-loops over lists (verbs)."),
370 tex ('(for i in L do print (i))),
371 tex ((1 - a) / '(for i in foo (L[1], L[2]) do print (i))),
373 print ("For-loops over lists (nouns)."),
375 tex ('for i in L do print (i)),
376 tex ((1 - a) / 'for i in foo (L[1], L[2]) do print (i)),
378 /* (GET 'MLABEL 'TEX) => TEX-MLABEL */
381 /* (GET 'MLABOX 'TEX) => TEX-MLABOX */
384 print ("Subscripted functions."),
387 tex (log (F[mod (x, m)](y!))),
389 /* (GET 'TEXT-STRING 'TEX) => TEX-MTEXT */
392 /* (GET 'MTEXT 'TEX) => TEX-MTEXT */
395 print ("Rational numbers (RAT expressions)."),
397 tex (ratsimp (17/19)),
398 tex (1/(a + ratsimp (17/19))),
400 /* (GET 'SPACEOUT 'TEX) => TEX-SPACEOUT */
403 print ("Square roots."),
406 tex (z - bessel_j (0, sqrt (1/(1 - u)))),
408 print ("Typesetting exponents."),
424 tex('integrate(f(x),x,0,inf)^4),
425 tex('sum(f(x),x,0,n)^4),
426 tex('integrate(f(x)^n,x,0,inf)^4),
427 tex('sum(f(x)^x,x,0,n)^4),
430 print ("\\end{document}"));