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"));
23 texput ("-->", "\\rightarrow", infix);
25 '((aa or bb) and not (cc or dd));
27 with_stdout ("tmp-rtest-1.tex",
28 (latex0 ("Maxima \\TeX\\ test page"),
30 tex_text ("\\subsection*{Symbols and subscripts}"),
33 tex ([inf, minf, true, false, done]),
34 map (tex, [inf, minf, true, false, done]),
35 tex (%pi + %e + %i + %gamma),
37 tex ([alpha, beta, verbify (gamma), delta, epsilon, zeta, eta, theta, iota, kappa, lambda, mu]),
38 tex ([nu, xi, omicron, pi, rho, sigma, tau, upsilon, phi, chi, psi, omega]),
39 tex ([Alpha, Beta, Gamma, Delta, Epsilon, Zeta, Eta, Theta, Iota, Kappa, Lambda, Mu]),
40 tex ([Nu, Xi, Omicron, Pi, Rho, Sigma, Tau, Upsilon, Phi, Chi, Psi, Omega]),
41 tex (A1 + B2 + C3 + A_1 + B_2 + C_3),
42 tex (A1a + B2b + C3c + A1_a + B2_b + C3_c),
43 tex (Foo[1] + BAR[2] + baz[3]),
44 tex (Mumble[i,j] + blurf[a][b]),
45 tex (\2F1 + ?lisp_symbol),
46 tex (embedded\$dollar + embedded%percent + embedded_underscore + embedded\&ersand),
48 tex_text ("\\subsubsection*{Explicit and implicit subscripts}"),
49 tex_text ("In each of the next several lists, all items in a list should be identical."),
50 tex_text ("Variable name is ``ABC''."),
51 tex ([ABC123, ABC_123, ABC__123, ABC___123, ABC[123]]),
52 tex_text ("Variable name is ``abc''."),
53 tex ([abc123, abc_123, abc__123, abc___123, abc[123]]),
54 tex_text ("Variable name is ``Abc''."),
55 tex ([Abc123, Abc_123, Abc__123, Abc___123, Abc[123]]),
56 tex_text ("Multiple subscripts."),
57 tex ([ABC_1_2_3, ABC[1, 2, 3]]),
58 tex_text ("Ensure that the leading percent sign is preserved in this next one."),
59 tex ([%A_1_B_2_C_3, %A_1_B_2_C[3]]),
60 tex_text ("Expect subscripted ``\\%gamma'' to be displayed as math symbol."),
61 tex ([%gamma3, %gamma_3, %gamma[3]]),
63 tex_text ("\\subsubsection*{Pre- and post- superscripts and subscripts}"),
64 tex_text ("Without index properties:"),
66 tex (x[a + 1,b - 1,2*c,d^2]),
67 tex ((1 - x[a + 1,b - 1,2*c,d^2])/(1 + x[a + 1,b - 1,2*c,d^2])),
68 tex (sqrt (x[a + 1,b - 1,2*c,d^2])),
69 texput (U, "\\mathrm{U}"),
70 texput (Th, "\\mathrm{Th}"),
71 texput (Pa, "\\mathrm{Pa}"),
72 tex (U[92,238] --> Th[90,234] --> Pa[234,91] --> U[234,92]),
73 tex_text ("With index properties:"),
74 declare_index_properties (x, [postsubscript, postsuperscript, presuperscript, presubscript]),
76 tex (x[a + 1,b - 1,2*c,d^2]),
77 tex ((1 - x[a + 1,b - 1,2*c,d^2])/(1 + x[a + 1,b - 1,2*c,d^2])),
78 tex (sqrt (x[a + 1,b - 1,2*c,d^2])),
79 declare_index_properties (U, [presubscript, presuperscript]),
80 declare_index_properties (Th, [presubscript, presuperscript]),
81 declare_index_properties (Pa, [presubscript, presuperscript]),
82 tex (U[92,238] --> Th[90,234] --> Pa[234,91] --> U[234,92]),
84 tex_text ("\\subsubsection*{Gamma functions and variables}"),
85 tex_text ("Variables: \\%gamma (Euler-Mascheroni number), Gamma, nounify(gamma), verbify(gamma):"),
86 tex ([%gamma = ev (%gamma, numer), Gamma, nounify (gamma), verbify (gamma)]),
87 tex_text ("Functions: gamma(z) (gamma function), gamma\\_incomplete(a, z) (upper incomplete gamma function),
88 gamma\\_incomplete\\_regularized(a, z) (gamma\\_incomplete normalized by gamma(z)),
89 gamma\\_incomplete\\_generalized(a, z[1], z[2]) (upper minus lower incomplete gamma function),
90 gamma\\_incomplete\\_lower(a, z) (lower incomplete gamma function):"),
91 tex ([gamma (z), gamma_incomplete (a, z), gamma_incomplete_regularized (a, z),
92 gamma_incomplete_generalized (a, z[1], z[2]), gamma_incomplete_lower (a, z)]),
94 /* Maxima tex function doesn't escape special characters in symbol names,
95 * so don't bother with these unless TEX-STRIPDOLLAR is revised or something like that.
96 * tex (int\+float + int\*float + int\@float),
97 * tex (?\*lisp\-symbol\-2\*),
100 tex_text ("\\subsection*{Lisp pointers}"),
101 tex(make_array(fixnum,5)),
102 tex(gf_set_data(3,x^4+x+1)),
104 tex_text ("\\subsection*{Strings}"),
108 tex ("Riff Raff (enclosed in `quote marks')"),
110 tex ("String containing
112 tex ("String containing \\ldots \\\"Oyster sh\\'ell \\ldots some \\TeX\\ commands."),
113 tex ("Some characters \\{ \\ \\^ % _ $ \\# \\~ & \\} which might be special to \\TeX\\ and \\LaTeX."),
114 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.)"),
116 tex_text ("\\subsection*{Different kinds of numbers}"),
117 ev (tex (1 + 1/1 + 1.0 + 1e0 + 1b0), simp=false),
118 ev (tex (12345678901234567890 + 1/12345678901234567890), simp=false),
119 ev (tex (12345678901234567890e200 + 12345678901234567890b-200), simp=false, fpprec=20),
120 tex (123b456/a + 123d42/b + (123/456)/c),
121 tex (123 + 456*x + 789.0*x^2 + 987e50*x^3 + 654b-50*x^4 + 1729b+42*x^5),
122 tex (123b-456^a + 123d-45^b + sqrt (123b-456) + sqrt (123d-45)),
123 /* Next few are specifically to test for a bug in TEX-MEXPT
125 tex (1.234^m + 5.678^n - 1.234b0^m + 5.678b0^n),
126 tex (1.234^m * 5.678^n . 1.234b0^m * 5.678b0^n),
127 tex ((1.234^m) ^ (5.678^n) ^^ (1.234b0^m) ^ (5.678b0^n)),
129 tex_text ("\\subsection*{Various operators}"),
134 tex (a.b * c.d + (a*b).(c*d)),
136 ev (tex ((a/b)/(c/d)), simp=false),
143 tex (sin(a) + cos(a) + tan(a) + sec(a) + csc(a) + cot(a)),
144 tex (asin(a) + acos(a) + atan(a) + atan2(b,a) + asec(a) + acsc(a) + acot(a)),
145 tex (sinh(a) + cosh(a) + tanh(a) + sech(a) + csch(a) + coth(a)),
146 tex (asinh(a) + acosh(a) + atanh(a) + asech(a) + acsch(a) + acoth(a)),
147 tex (exp(x) + log(a) + erf(a)),
149 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)),
150 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)),
151 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)),
152 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)),
154 tex (exp(1 + x + x^2 + x^3) + exp (exp (-x))),
155 tex (log(b + a) + log((b + a)/(b - a))),
157 tex ('integrate (exp(-a*x^2), x, minf, inf)),
158 tex ('sum (1/k^2, k, 1, inf)),
159 tex ('lsum (1/k^2, k, Z)),
160 tex (diff (Omega (omega))),
162 tex ('diff (exp (-a*x), x)),
163 tex ('diff (a(x) * 'diff (F, x), x) + a(x) * 'diff (F, x, 2)),
164 tex ('limit (exp (-a*x), x, inf)),
165 tex ('limit (exp (-a*x), x, 0, plus)),
166 tex ('limit (exp (-a*x), x, 0, minus)),
171 tex ('((riff or raff) and not (roff or ruff))),
172 tex ('(not foo ((a + b)^2/(a - b)^2) or bar (x and baz (sqrt(y^n)) or z))),
174 tex_text ("\\subsection*{Lists, matrices, and sets}"),
175 tex ([a, b, c, d, e]),
176 tex ([a + b, a*b, a/b, a^b, a^b^c]),
177 tex (matrix ([a, b], [c, d])),
178 tex (matrix ([a + b, a*b], [a^b, a^b^c])),
179 tex ({a, b, c, d, e}),
180 tex ({a + b, a*b, a/b, a^b, a^b^c}),
182 tex_text ("\\subsubsection*{Binomial}"),
183 tex (xyz + binomial (foo(a)/foo(b), bar(a)/bar(b)) + abc),
185 tex_text ("\\subsection*{User-defined \\TeX\\ properties}"),
187 /* User-defined operator declarations have to be outside with_stdout.
188 * See note near top of file.
191 tex_text ("\\def\\sgn{\\mathop{\\rm sgn}}"),
192 tex ('("Before texput" : [foo, signum(x)])),
193 texput (signum, "\\sgn"),
194 texput (foo, "\\phi\\upsilon"),
195 tex ('("After texput" : [foo, signum(x)])),
197 tex ('("Before texput" : [grad(x), fooprefix x, grad (fooprefix x)])),
198 texput (grad, "\\nabla ", prefix),
199 texput ("fooprefix", "\\mathrm{foo}\\;", prefix),
200 tex ('("After texput" : [grad(x), fooprefix x, grad (fooprefix x)])),
202 tex ('("Before texput" : ((foo or bar) implies (baz or quux)))),
203 texput ("implies", "\\Rightarrow", infix),
204 tex ('("After texput" : ((foo or bar) implies (baz or quux)))),
206 tex ('("Before texput" : ((foo or bar) iff (baz or quux)))),
207 texput ("iff", "\\Leftrightarrow", infix),
208 tex ('("After texput" : ((foo or bar) iff (baz or quux)))),
210 tex ('("Before texput" : aa foonary bb foonary cc foonary dd)),
211 texput ("foonary", "\\;\\mathbf{foo}\\;", nary),
212 tex ('("After texput" : aa foonary bb foonary cc foonary dd)),
214 tex ('("Before texput" : [degrees_F(85), x foopostfix, degrees_F (x foopostfix)])),
215 texput (degrees_F, "^o\\;{\\rm F}", postfix),
216 texput ("foopostfix", "\\;\\mathit{foo}", postfix),
217 tex ('("After texput" : [degrees_F(85), x foopostfix, degrees_F (x foopostfix)])),
219 tex ('("Before texput" : <<x, y>>)),
220 texput ("<<", [" \\langle ", " \\rangle "], matchfix),
221 tex ('("After texput" : <<x, y>>)),
223 tex ('("Before texput" : foonofix)),
224 texput ("foonofix", "\\;\\mathsf{foo}\\;", nofix),
225 tex ('("After texput" : foonofix)),
227 tex ('("All together now" : <<fooprefix foo foonary foo foonary foonofix foopostfix>>)),
229 tex_text ("\\subsection*{{\\tt texput} with output function}"),
231 tex_text ("Derivatives before {\\tt texput}:"),
233 tex ('diff (y(x), x, 3) + 'diff (y(x), x, 2) + 'diff (y(x), x) + y(x) + a = 0),
234 tex ('diff (y(t), t, 3) + 'diff (y(t), t, 2) + 'diff (y(t), t) + y(t) + a = 0),
235 tex ('diff (f(x, t), x) + 'diff(f(x, t), t) = c),
237 texput (nounify (diff), lambda ([e], if not mapatom (first (e)) and length (args (first (e))) = 1 then if third (e) = 1 then sconcat (tex1 (op (first (e))), "'\\left(", tex1 (first (args (first (e)))), "\\right)"))),
238 texput (nounify (diff), lambda ([e], if second (e) = 't and third (e) =1 then sconcat ("\\dot ", tex1 (first (e))) elseif second (e) = 't and third (e) = 2 then sconcat ("\\ddot ", tex1 (first (e))))),
240 tex_text ("Derivatives after {\\tt texput}:"),
242 tex ('diff (y(x), x, 3) + 'diff (y(x), x, 2) + 'diff (y(x), x) + y(x) + a = 0),
243 tex ('diff (y(t), t, 3) + 'diff (y(t), t, 2) + 'diff (y(t), t) + y(t) + a = 0),
244 tex ('diff (f(x, t), x) + 'diff(f(x, t), t) = c),
246 tex (1/(1 + 'diff (u, t))),
247 tex (1/(1 + ('diff (u, t))^n)),
248 /* this next one should use only default typesetting for diff */
249 tex ('integrate ('diff (g(a, b), b) * 'diff (h(c - a, b), a), b, minf, inf)),
251 tex_text ("Additional {\\tt texput} examples --- no previous \\TeX\\ function:"),
253 texput (baz, lambda ([e], if mapatom (first (e)) then sconcat ("\\hat{", tex1 (first (e)), "}"))),
255 tex (%pi + %phi / baz (%gamma[2])),
256 tex (%pi + %phi / baz (3 + %gamma[2])),
258 tex_text ("Additional {\\tt texput} examples --- general and special cases:"),
260 /* general case is a catch-all -- no conditional */
261 texput (quux, lambda ([e], sconcat ("\\mathrm{", string (op (e)), "}", tex1 (subst (quux = ?mprogn, e))))),
262 /* special case applies only to mapatom argument */
263 texput (quux, lambda ([e], if mapatom (first (e)) then sconcat ("\\hat{", tex1 (first (e)), "}"))),
265 tex (%pi + %phi / quux (%gamma[2])),
266 tex (%pi + %phi / quux (3 + %gamma[2])),
268 tex_text ("\\subsection*{Miscellany}"),
270 tex_text ("Next few should all be the same."),
271 tex ('((aa or bb) and not (cc or dd))),
272 '((aa or bb) and not (cc or dd)),
274 tex (_), /* refers to the input expression immediately preceding "with_stdout" */
276 tex_text ("I forget what this one is for."),
277 '((aa or bb) and not (cc or dd)),
278 (tex (''(second (labels (%i)))), tex (''(first (labels (%o))))),
279 tex ('((tex (''(second (labels (%i)))), tex (''(first (labels (%o))))))),
281 tex_text ("A function and its output."),
283 (tex ('integrate (x^n, x, 0, inf)),
284 tex ('sum (x^n, n, 1, inf)),
285 tex ('limit (x^n, x, inf)),
286 tex ('diff (x^n, x))),
290 /* tex_text ("This one should be the whole with\\_stdout thing."),
291 * tex (''(first (labels (%i)))),
295 /* Test output options: standard output, string, file, and stream.
298 with_stdout ("tmp-rtest-2a.tex",
299 tex ("Capture standard output to tmp-rtest-2a.tex."));
301 S : tex ("Capture string output to S, then write S to tmp-rtest-2b.tex.", false);
302 s : openw ("tmp-rtest-2b.tex");
303 printf (s, "~a~%", S);
306 tex ("Write output directly to tmp-rtest-2c.tex.", "tmp-rtest-2c.tex");
308 s : openw ("tmp-rtest-2d.tex");
309 tex ("Write output to output stream opened to tmp-rtest-2d.tex.", s);
312 /* Test TeX environment functions.
315 set_tex_environment_default ("
321 set_tex_environment ("=", "$", "$");
322 set_tex_environment (":=", "$$", "$$");
324 s : openw ("tmp-rtest-3.tex");
327 print ("\\documentclass{article}"),
328 print ("\\title{A \\TeX\\ environment test}"),
329 print ("\\author{Maxim A.}"),
330 print ("\\begin{document}"),
331 print ("\\maketitle"),
332 print ("Here are some formulas. These should be numbered."),
333 tex ((a + b)/(c + d)),
334 tex (sin(x)/(1-sin(x))),
335 tex (erf(x)*gamma(x)),
336 print ("More text here. Followed by a formula embedded in the text."),
338 print ("More text here. A function definition."),
339 tex (foo(x) := 1 - 1/x));
342 tex_text ("Let's take this opportunity to test the interaction of\
343 $\\mathbf{tex}$ and $\\mathbf{ordergreat}$."),
344 tex_text ("Here are some variables before calling $\\mathbf{ordergreat}$."),
345 tex (x + y + z + t = x * y * z * t));
347 ordergreat (x, y, z, t);
350 tex_text ("After calling $\\mathbf{ordergreat}(x, y, z, t)$, which constructs alias variables.\
351 We should still see just the original variables."),
352 tex (x + y + z + t = x * y * z * t),
353 print ("That's all, folks."),
354 print ("\\end{document}"));
357 unorder (); /* undo ordergreat above */
359 s : openw ("tmp-rtest-4.tex");
361 kill (a, b, c, d, foo, bar, baz, quux, u, v, w, x, y, z);
364 print ("\\documentclass{article}"),
365 print ("\\title{More \\TeX\\ examples}"),
366 print ("\\author{Maxim B.}"),
367 print ("\\begin{document}"),
368 print ("\\maketitle"),
369 tex_text ("Here are some more examples. Trying to cover all the bases here.\
370 These were discovered by tracing all the functions named in 'TEX properties\
371 and seeing which ones were not yet called."),
374 print ("'at noun expressions."),
376 tex ('at (f (u), u = 0)),
377 tex (1 / (1 - 'at (diff (f (u), u), u = 0))),
379 print ("Bigfloats."),
381 tex ([0b0, 1b0, -1b0, 1b100]),
382 tex ((foo (0b0) + bar (1b0))/(baz (-1b0) - quux (1b100))),
384 print ("Binomials."),
386 tex ('binomial (N, M)),
387 tex ((a + 'binomial (f (u), sqrt (v)))^(1/2)),
389 print ("Cube roots."),
392 tex (sin (cubrt (1 - %pi))),
394 print ("Kronecker delta."),
396 tex (kron_delta (0, u)),
397 tex ((x - kron_delta (cos (y), sin (z)))^n),
400 * OMIT -- BOX SEEMS TO BE AMSTEX-SPECIFIC.
402 print ("Stuff in boxes."),
404 tex (sqrt (box (1 - box (tan (u))))),
407 print ("Conditional expressions (verbs)."),
409 tex (if 'a > 'b then a else b),
410 tex (if 'a > 'b then (if 'a > 'c then 'a else 'c) else b),
411 tex (if 'a > 'b then a elseif 'c > 'b then c else b),
412 tex (1 + if 'a > 'b then sqrt(a) else b^3),
414 print ("Conditional expressions (nouns)."),
416 tex ('if 'a > 'b then a else b),
417 tex ('if 'a > 'b then ('if 'a > 'c then 'a else 'c) else b),
418 tex ('if 'a > 'b then a elseif 'c > 'b then c else b),
419 tex (1 + 'if 'a > 'b then sqrt(a) else b^3),
421 print ("For-loop expressions (nouns)."),
423 tex ('for i thru n do print (i)),
424 tex (m * 'for i thru floor ((n + 1)/7) do print (i)),
426 print ("For-loop expressions (verbs)."),
428 tex ('(for i thru n do print (i))),
429 tex (m * '(for i thru floor ((n + 1)/7) do print (i))),
431 print ("For-loops over lists (verbs)."),
433 tex ('(for i in L do print (i))),
434 tex ((1 - a) / '(for i in foo (L[1], L[2]) do print (i))),
436 print ("For-loops over lists (nouns)."),
438 tex ('for i in L do print (i)),
439 tex ((1 - a) / 'for i in foo (L[1], L[2]) do print (i)),
441 /* (GET 'MLABEL 'TEX) => TEX-MLABEL */
444 /* (GET 'MLABOX 'TEX) => TEX-MLABOX */
447 print ("Subscripted functions."),
450 tex (log (F[mod (x, m)](y!))),
452 /* (GET 'TEXT-STRING 'TEX) => TEX-MTEXT */
455 /* (GET 'MTEXT 'TEX) => TEX-MTEXT */
458 print ("Rational numbers (RAT expressions)."),
460 tex (ratsimp (17/19)),
461 tex (1/(a + ratsimp (17/19))),
463 /* (GET 'SPACEOUT 'TEX) => TEX-SPACEOUT */
466 print ("Square roots."),
469 tex (z - bessel_j (0, sqrt (1/(1 - u)))),
471 print ("Typesetting exponents."),
491 tex('integrate(f(x),x,0,inf)^4),
492 tex('sum(f(x),x,0,n)^4),
493 tex('integrate(f(x)^n,x,0,inf)^4),
494 tex('sum(f(x)^x,x,0,n)^4),
496 print ("Typesetting conjugates."),
500 declare ([x, y, z], complex),
501 declare ([a, b, c], real),
504 tex (conjugate (conjugate (x))),
505 tex (conjugate (x)^2),
506 tex (conjugate (x)^(k + 2)),
507 tex (conjugate (x^2)),
508 tex (conjugate (x + y)),
509 tex (conjugate (x + y)^m),
510 tex (conjugate (x*y)),
511 tex (conjugate (x*y)^n),
512 tex (conjugate (x/y)),
513 tex (conjugate (x/y)^k),
514 tex (conjugate ((-1)^%i)),
515 tex (conjugate (sin (x))),
516 tex (sin (conjugate (x))),
517 tex (conjugate (sin (x))^n),
518 tex (sin (conjugate (x))^n),
519 tex (conjugate (sin (x)^n)),
520 tex (sin (conjugate (x)^n)),
525 print ("\\end{document}"));