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*{Gamma functions and variables}"),
46 tex_text ("Variables: \\%gamma (Euler-Mascheroni number), Gamma, nounify(gamma), verbify(gamma):"),
47 tex ([%gamma = ev (%gamma, numer), Gamma, nounify (gamma), verbify (gamma)]),
48 tex_text ("Functions: gamma(z) (gamma function), gamma\\_incomplete(a, z) (upper incomplete gamma function),
49 gamma\\_incomplete\\_regularized(a, z) (gamma\\_incomplete normalized by gamma(z)),
50 gamma\\_incomplete\\_generalized(a, z[1], z[2]) (upper minus lower incomplete gamma function),
51 gamma\\_greek(a, z) (lower incomplete gamma function):"),
52 tex ([gamma (z), gamma_incomplete (a, z), gamma_incomplete_regularized (a, z),
53 gamma_incomplete_generalized (a, z[1], z[2]), gamma_greek (a, z)]),
55 /* Maxima tex function doesn't escape special characters in symbol names,
56 * so don't bother with these unless TEX-STRIPDOLLAR is revised or something like that.
57 * tex (int\+float + int\*float + int\@float),
58 * tex (?\*lisp\-symbol\-2\*),
61 tex_text ("\\subsection*{Lisp pointers}"),
62 tex(make_array(fixnum,5)),
63 tex(gf_set_data(3,x^4+x+1)),
65 tex_text ("\\subsection*{Strings}"),
69 tex ("Riff Raff (enclosed in `quote marks')"),
71 tex ("String containing
73 tex ("String containing \\ldots \\\"Oyster sh\\'ell \\ldots some \\TeX\\ commands."),
74 tex ("Some characters \\{ \\ \\^ % _ $ \\# \\~ & \\} which might be special to \\TeX\\ and \\LaTeX."),
75 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.)"),
77 tex_text ("\\subsection*{Different kinds of numbers}"),
78 ev (tex (1 + 1/1 + 1.0 + 1e0 + 1b0), simp=false),
79 ev (tex (12345678901234567890 + 1/12345678901234567890), simp=false),
80 ev (tex (12345678901234567890e200 + 12345678901234567890b-200), simp=false, fpprec=20),
81 tex (123b456/a + 123d42/b + (123/456)/c),
82 tex (123 + 456*x + 789.0*x^2 + 987e50*x^3 + 654b-50*x^4 + 1729b+42*x^5),
83 tex (123b-456^a + 123d-45^b + sqrt (123b-456) + sqrt (123d-45)),
84 /* Next few are specifically to test for a bug in TEX-MEXPT
86 tex (1.234^m + 5.678^n - 1.234b0^m + 5.678b0^n),
87 tex (1.234^m * 5.678^n . 1.234b0^m * 5.678b0^n),
88 tex ((1.234^m) ^ (5.678^n) ^^ (1.234b0^m) ^ (5.678b0^n)),
90 tex_text ("\\subsection*{Various operators}"),
95 tex (a.b * c.d + (a*b).(c*d)),
97 ev (tex ((a/b)/(c/d)), simp=false),
104 tex (sin(a) + cos(a) + tan(a) + sec(a) + csc(a) + cot(a)),
105 tex (asin(a) + acos(a) + atan(a) + atan2(b,a) + asec(a) + acsc(a) + acot(a)),
106 tex (sinh(a) + cosh(a) + tanh(a) + sech(a) + csch(a) + coth(a)),
107 tex (asinh(a) + acosh(a) + atanh(a) + asech(a) + acsch(a) + acoth(a)),
108 tex (exp(x) + log(a) + erf(a)),
110 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)),
111 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)),
112 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)),
113 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)),
115 tex (exp(1 + x + x^2 + x^3) + exp (exp (-x))),
116 tex (log(b + a) + log((b + a)/(b - a))),
118 tex ('integrate (exp(-a*x^2), x, minf, inf)),
119 tex ('sum (1/k^2, k, 1, inf)),
120 tex ('lsum (1/k^2, k, Z)),
121 tex (diff (Omega (omega))),
123 tex ('diff (exp (-a*x), x)),
124 tex ('diff (a(x) * 'diff (F, x), x) + a(x) * 'diff (F, x, 2)),
125 tex ('limit (exp (-a*x), x, inf)),
126 tex ('limit (exp (-a*x), x, 0, plus)),
127 tex ('limit (exp (-a*x), x, 0, minus)),
132 tex ('((riff or raff) and not (roff or ruff))),
133 tex ('(not foo ((a + b)^2/(a - b)^2) or bar (x and baz (sqrt(y^n)) or z))),
135 tex_text ("\\subsection*{Lists, matrices, and sets}"),
136 tex ([a, b, c, d, e]),
137 tex ([a + b, a*b, a/b, a^b, a^b^c]),
138 tex (matrix ([a, b], [c, d])),
139 tex (matrix ([a + b, a*b], [a^b, a^b^c])),
140 tex ({a, b, c, d, e}),
141 tex ({a + b, a*b, a/b, a^b, a^b^c}),
143 tex_text ("\\subsubsection*{Binomial}"),
144 tex (xyz + binomial (foo(a)/foo(b), bar(a)/bar(b)) + abc),
146 tex_text ("\\subsection*{User-defined \\TeX\\ properties}"),
148 /* User-defined operator declarations have to be outside with_stdout.
149 * See note near top of file.
152 tex_text ("\\def\\sgn{\\mathop{\\rm sgn}}"),
153 tex ('("Before texput" : [foo, signum(x)])),
154 texput (signum, "\\sgn"),
155 texput (foo, "\\phi\\upsilon"),
156 tex ('("After texput" : [foo, signum(x)])),
158 tex ('("Before texput" : [grad(x), fooprefix x, grad (fooprefix x)])),
159 texput (grad, "\\nabla ", prefix),
160 texput ("fooprefix", "\\mathrm{foo}\\;", prefix),
161 tex ('("After texput" : [grad(x), fooprefix x, grad (fooprefix x)])),
163 tex ('("Before texput" : ((foo or bar) implies (baz or quux)))),
164 texput ("implies", "\\Rightarrow", infix),
165 tex ('("After texput" : ((foo or bar) implies (baz or quux)))),
167 tex ('("Before texput" : ((foo or bar) iff (baz or quux)))),
168 texput ("iff", "\\Leftrightarrow", infix),
169 tex ('("After texput" : ((foo or bar) iff (baz or quux)))),
171 tex ('("Before texput" : aa foonary bb foonary cc foonary dd)),
172 texput ("foonary", "\\;\\mathbf{foo}\\;", nary),
173 tex ('("After texput" : aa foonary bb foonary cc foonary dd)),
175 tex ('("Before texput" : [degrees_F(85), x foopostfix, degrees_F (x foopostfix)])),
176 texput (degrees_F, "^o\\;{\\rm F}", postfix),
177 texput ("foopostfix", "\\;\\mathit{foo}", postfix),
178 tex ('("After texput" : [degrees_F(85), x foopostfix, degrees_F (x foopostfix)])),
180 tex ('("Before texput" : <<x, y>>)),
181 texput ("<<", [" \\langle ", " \\rangle "], matchfix),
182 tex ('("After texput" : <<x, y>>)),
184 tex ('("Before texput" : foonofix)),
185 texput ("foonofix", "\\;\\mathsf{foo}\\;", nofix),
186 tex ('("After texput" : foonofix)),
188 tex ('("All together now" : <<fooprefix foo foonary foo foonary foonofix foopostfix>>)),
190 tex_text ("\\subsection*{Miscellany}"),
192 tex_text ("Next few should all be the same."),
193 tex ('((aa or bb) and not (cc or dd))),
194 '((aa or bb) and not (cc or dd)),
196 tex (_), /* refers to the input expression immediately preceding "with_stdout" */
198 tex_text ("I forget what this one is for."),
199 '((aa or bb) and not (cc or dd)),
200 (tex (''(second (labels (%i)))), tex (''(first (labels (%o))))),
201 tex ('((tex (''(second (labels (%i)))), tex (''(first (labels (%o))))))),
203 tex_text ("A function and its output."),
205 (tex ('integrate (x^n, x, 0, inf)),
206 tex ('sum (x^n, n, 1, inf)),
207 tex ('limit (x^n, x, inf)),
208 tex ('diff (x^n, x))),
212 /* tex_text ("This one should be the whole with\\_stdout thing."),
213 * tex (''(first (labels (%i)))),
217 /* Test output options: standard output, string, file, and stream.
220 with_stdout ("tmp-rtest-2a.tex",
221 tex ("Capture standard output to tmp-rtest-2a.tex."));
223 S : tex ("Capture string output to S, then write S to tmp-rtest-2b.tex.", false);
224 s : openw ("tmp-rtest-2b.tex");
225 printf (s, "~a~%", S);
228 tex ("Write output directly to tmp-rtest-2c.tex.", "tmp-rtest-2c.tex");
230 s : openw ("tmp-rtest-2d.tex");
231 tex ("Write output to output stream opened to tmp-rtest-2d.tex.", s);
234 /* Test TeX environment functions.
237 set_tex_environment_default ("
243 set_tex_environment ("=", "$", "$");
244 set_tex_environment (":=", "$$", "$$");
246 s : openw ("tmp-rtest-3.tex");
249 print ("\\documentclass{article}"),
250 print ("\\title{A \\TeX\\ environment test}"),
251 print ("\\author{Maxim A.}"),
252 print ("\\begin{document}"),
253 print ("\\maketitle"),
254 print ("Here are some formulas. These should be numbered."),
255 tex ((a + b)/(c + d)),
256 tex (sin(x)/(1-sin(x))),
257 tex (erf(x)*gamma(x)),
258 print ("More text here. Followed by a formula embedded in the text."),
260 print ("More text here. A function definition."),
261 tex (foo(x) := 1 - 1/x));
264 tex_text ("Let's take this opportunity to test the interaction of\
265 $\\mathbf{tex}$ and $\\mathbf{ordergreat}$."),
266 tex_text ("Here are some variables before calling $\\mathbf{ordergreat}$."),
267 tex (x + y + z + t = x * y * z * t));
269 ordergreat (x, y, z, t);
272 tex_text ("After calling $\\mathbf{ordergreat}(x, y, z, t)$, which constructs alias variables.\
273 We should still see just the original variables."),
274 tex (x + y + z + t = x * y * z * t),
275 print ("That's all, folks."),
276 print ("\\end{document}"));
279 unorder (); /* undo ordergreat above */
281 s : openw ("tmp-rtest-4.tex");
283 kill (a, b, c, d, foo, bar, baz, quux, u, v, w, x, y, z);
286 print ("\\documentclass{article}"),
287 print ("\\title{More \\TeX\\ examples}"),
288 print ("\\author{Maxim B.}"),
289 print ("\\begin{document}"),
290 print ("\\maketitle"),
291 tex_text ("Here are some more examples. Trying to cover all the bases here.\
292 These were discovered by tracing all the functions named in 'TEX properties\
293 and seeing which ones were not yet called."),
296 print ("'at noun expressions."),
298 tex ('at (f (u), u = 0)),
299 tex (1 / (1 - 'at (diff (f (u), u), u = 0))),
301 print ("Bigfloats."),
303 tex ([0b0, 1b0, -1b0, 1b100]),
304 tex ((foo (0b0) + bar (1b0))/(baz (-1b0) - quux (1b100))),
306 print ("Binomials."),
308 tex ('binomial (N, M)),
309 tex ((a + 'binomial (f (u), sqrt (v)))^(1/2)),
311 print ("Cube roots."),
314 tex (sin (cubrt (1 - %pi))),
316 print ("Kronecker delta."),
318 tex (kron_delta (0, u)),
319 tex ((x - kron_delta (cos (y), sin (z)))^n),
322 * OMIT -- BOX SEEMS TO BE AMSTEX-SPECIFIC.
324 print ("Stuff in boxes."),
326 tex (sqrt (box (1 - box (tan (u))))),
329 print ("Conditional expressions (verbs)."),
331 tex (if 'a > 'b then a else b),
332 tex (if 'a > 'b then (if 'a > 'c then 'a else 'c) else b),
333 tex (if 'a > 'b then a elseif 'c > 'b then c else b),
334 tex (1 + if 'a > 'b then sqrt(a) else b^3),
336 print ("Conditional expressions (nouns)."),
338 tex ('if 'a > 'b then a else b),
339 tex ('if 'a > 'b then ('if 'a > 'c then 'a else 'c) else b),
340 tex ('if 'a > 'b then a elseif 'c > 'b then c else b),
341 tex (1 + 'if 'a > 'b then sqrt(a) else b^3),
343 print ("For-loop expressions (nouns)."),
345 tex ('for i thru n do print (i)),
346 tex (m * 'for i thru floor ((n + 1)/7) do print (i)),
348 print ("For-loop expressions (verbs)."),
350 tex ('(for i thru n do print (i))),
351 tex (m * '(for i thru floor ((n + 1)/7) do print (i))),
353 print ("For-loops over lists (verbs)."),
355 tex ('(for i in L do print (i))),
356 tex ((1 - a) / '(for i in foo (L[1], L[2]) do print (i))),
358 print ("For-loops over lists (nouns)."),
360 tex ('for i in L do print (i)),
361 tex ((1 - a) / 'for i in foo (L[1], L[2]) do print (i)),
363 /* (GET 'MLABEL 'TEX) => TEX-MLABEL */
366 /* (GET 'MLABOX 'TEX) => TEX-MLABOX */
369 print ("Subscripted functions."),
372 tex (log (F[mod (x, m)](y!))),
374 /* (GET 'TEXT-STRING 'TEX) => TEX-MTEXT */
377 /* (GET 'MTEXT 'TEX) => TEX-MTEXT */
380 print ("Rational numbers (RAT expressions)."),
382 tex (ratsimp (17/19)),
383 tex (1/(a + ratsimp (17/19))),
385 /* (GET 'SPACEOUT 'TEX) => TEX-SPACEOUT */
388 print ("Square roots."),
391 tex (z - bessel_j (0, sqrt (1/(1 - u)))),
394 print ("\\end{document}"));