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*{Miscellany}"),
231 tex_text ("Next few should all be the same."),
232 tex ('((aa or bb) and not (cc or dd))),
233 '((aa or bb) and not (cc or dd)),
235 tex (_), /* refers to the input expression immediately preceding "with_stdout" */
237 tex_text ("I forget what this one is for."),
238 '((aa or bb) and not (cc or dd)),
239 (tex (''(second (labels (%i)))), tex (''(first (labels (%o))))),
240 tex ('((tex (''(second (labels (%i)))), tex (''(first (labels (%o))))))),
242 tex_text ("A function and its output."),
244 (tex ('integrate (x^n, x, 0, inf)),
245 tex ('sum (x^n, n, 1, inf)),
246 tex ('limit (x^n, x, inf)),
247 tex ('diff (x^n, x))),
251 /* tex_text ("This one should be the whole with\\_stdout thing."),
252 * tex (''(first (labels (%i)))),
256 /* Test output options: standard output, string, file, and stream.
259 with_stdout ("tmp-rtest-2a.tex",
260 tex ("Capture standard output to tmp-rtest-2a.tex."));
262 S : tex ("Capture string output to S, then write S to tmp-rtest-2b.tex.", false);
263 s : openw ("tmp-rtest-2b.tex");
264 printf (s, "~a~%", S);
267 tex ("Write output directly to tmp-rtest-2c.tex.", "tmp-rtest-2c.tex");
269 s : openw ("tmp-rtest-2d.tex");
270 tex ("Write output to output stream opened to tmp-rtest-2d.tex.", s);
273 /* Test TeX environment functions.
276 set_tex_environment_default ("
282 set_tex_environment ("=", "$", "$");
283 set_tex_environment (":=", "$$", "$$");
285 s : openw ("tmp-rtest-3.tex");
288 print ("\\documentclass{article}"),
289 print ("\\title{A \\TeX\\ environment test}"),
290 print ("\\author{Maxim A.}"),
291 print ("\\begin{document}"),
292 print ("\\maketitle"),
293 print ("Here are some formulas. These should be numbered."),
294 tex ((a + b)/(c + d)),
295 tex (sin(x)/(1-sin(x))),
296 tex (erf(x)*gamma(x)),
297 print ("More text here. Followed by a formula embedded in the text."),
299 print ("More text here. A function definition."),
300 tex (foo(x) := 1 - 1/x));
303 tex_text ("Let's take this opportunity to test the interaction of\
304 $\\mathbf{tex}$ and $\\mathbf{ordergreat}$."),
305 tex_text ("Here are some variables before calling $\\mathbf{ordergreat}$."),
306 tex (x + y + z + t = x * y * z * t));
308 ordergreat (x, y, z, t);
311 tex_text ("After calling $\\mathbf{ordergreat}(x, y, z, t)$, which constructs alias variables.\
312 We should still see just the original variables."),
313 tex (x + y + z + t = x * y * z * t),
314 print ("That's all, folks."),
315 print ("\\end{document}"));
318 unorder (); /* undo ordergreat above */
320 s : openw ("tmp-rtest-4.tex");
322 kill (a, b, c, d, foo, bar, baz, quux, u, v, w, x, y, z);
325 print ("\\documentclass{article}"),
326 print ("\\title{More \\TeX\\ examples}"),
327 print ("\\author{Maxim B.}"),
328 print ("\\begin{document}"),
329 print ("\\maketitle"),
330 tex_text ("Here are some more examples. Trying to cover all the bases here.\
331 These were discovered by tracing all the functions named in 'TEX properties\
332 and seeing which ones were not yet called."),
335 print ("'at noun expressions."),
337 tex ('at (f (u), u = 0)),
338 tex (1 / (1 - 'at (diff (f (u), u), u = 0))),
340 print ("Bigfloats."),
342 tex ([0b0, 1b0, -1b0, 1b100]),
343 tex ((foo (0b0) + bar (1b0))/(baz (-1b0) - quux (1b100))),
345 print ("Binomials."),
347 tex ('binomial (N, M)),
348 tex ((a + 'binomial (f (u), sqrt (v)))^(1/2)),
350 print ("Cube roots."),
353 tex (sin (cubrt (1 - %pi))),
355 print ("Kronecker delta."),
357 tex (kron_delta (0, u)),
358 tex ((x - kron_delta (cos (y), sin (z)))^n),
361 * OMIT -- BOX SEEMS TO BE AMSTEX-SPECIFIC.
363 print ("Stuff in boxes."),
365 tex (sqrt (box (1 - box (tan (u))))),
368 print ("Conditional expressions (verbs)."),
370 tex (if 'a > 'b then a else b),
371 tex (if 'a > 'b then (if 'a > 'c then 'a else 'c) else b),
372 tex (if 'a > 'b then a elseif 'c > 'b then c else b),
373 tex (1 + if 'a > 'b then sqrt(a) else b^3),
375 print ("Conditional expressions (nouns)."),
377 tex ('if 'a > 'b then a else b),
378 tex ('if 'a > 'b then ('if 'a > 'c then 'a else 'c) else b),
379 tex ('if 'a > 'b then a elseif 'c > 'b then c else b),
380 tex (1 + 'if 'a > 'b then sqrt(a) else b^3),
382 print ("For-loop expressions (nouns)."),
384 tex ('for i thru n do print (i)),
385 tex (m * 'for i thru floor ((n + 1)/7) do print (i)),
387 print ("For-loop expressions (verbs)."),
389 tex ('(for i thru n do print (i))),
390 tex (m * '(for i thru floor ((n + 1)/7) do print (i))),
392 print ("For-loops over lists (verbs)."),
394 tex ('(for i in L do print (i))),
395 tex ((1 - a) / '(for i in foo (L[1], L[2]) do print (i))),
397 print ("For-loops over lists (nouns)."),
399 tex ('for i in L do print (i)),
400 tex ((1 - a) / 'for i in foo (L[1], L[2]) do print (i)),
402 /* (GET 'MLABEL 'TEX) => TEX-MLABEL */
405 /* (GET 'MLABOX 'TEX) => TEX-MLABOX */
408 print ("Subscripted functions."),
411 tex (log (F[mod (x, m)](y!))),
413 /* (GET 'TEXT-STRING 'TEX) => TEX-MTEXT */
416 /* (GET 'MTEXT 'TEX) => TEX-MTEXT */
419 print ("Rational numbers (RAT expressions)."),
421 tex (ratsimp (17/19)),
422 tex (1/(a + ratsimp (17/19))),
424 /* (GET 'SPACEOUT 'TEX) => TEX-SPACEOUT */
427 print ("Square roots."),
430 tex (z - bessel_j (0, sqrt (1/(1 - u)))),
432 print ("Typesetting exponents."),
448 tex('integrate(f(x),x,0,inf)^4),
449 tex('sum(f(x),x,0,n)^4),
450 tex('integrate(f(x)^n,x,0,inf)^4),
451 tex('sum(f(x)^x,x,0,n)^4),
454 print ("\\end{document}"));