1 | /////////////////////////////////////////////////////////////////////////////// |
---|
2 | version="$Id: latex.lib,v 1.24 2005-05-09 15:55:10 Singular Exp $"; |
---|
3 | category="Visualization"; |
---|
4 | info=" |
---|
5 | LIBRARY: latex.lib Typesetting of Singular-Objects in LaTeX2e |
---|
6 | AUTHOR: Christian Gorzel, gorzelc@math.uni-muenster.de |
---|
7 | |
---|
8 | PROCEDURES: |
---|
9 | closetex(fnm); writes closing line for LaTeX-document |
---|
10 | opentex(fnm); writes header for LaTeX-file fnm |
---|
11 | tex(fnm); calls LaTeX2e for LaTeX-file fnm |
---|
12 | texdemo([n]); produces a file explaining the features of this lib |
---|
13 | texfactorize(fnm,f); creates string in LaTeX-format for factors of poly f |
---|
14 | texmap(fnm,m,r1,r2); creates string in LaTeX-format for map m:r1->r2 |
---|
15 | texname(fnm,s); creates string in LaTeX-format for identifier |
---|
16 | texobj(l); creates string in LaTeX-format for any (basic) type |
---|
17 | texpoly(f,n[,l]); creates string in LaTeX-format for poly |
---|
18 | texproc(fnm,p); creates string in LaTeX-format of text from proc p |
---|
19 | texring(fnm,r[,l]); creates string in LaTeX-format for ring/qring |
---|
20 | rmx(s); removes .aux and .log files of LaTeX-files |
---|
21 | xdvi(s); calls xdvi for dvi-files |
---|
22 | (parameters in square brackets [] are optional) |
---|
23 | |
---|
24 | GLOBAL VARIABLES: |
---|
25 | TeXwidth, TeXnofrac, TeXbrack, TeXproj, TeXaligned, TeXreplace, NoDollars |
---|
26 | are used to control the typesetting. |
---|
27 | Call @code{texdemo();} to obtain a LaTeX2e file @code{texlibdemo.tex} |
---|
28 | explaining the features of @code{latex.lib} and its global variables. |
---|
29 | @format |
---|
30 | @code{TeXwidth} (int) -1, 0, 1..9, >9: controls breaking of long polynomials |
---|
31 | @code{TeXnofrac} (int) flag: write 1/2 instead of \\frac@{1@}@{2@} |
---|
32 | @code{TeXbrack} (string) \"@{\", \"(\", \"<\", \"|\", empty string: |
---|
33 | controls brackets around ideals and matrices |
---|
34 | @code{TeXproj} (int) flag: write \":\" instead of \",\" in vectors |
---|
35 | @code{TeXaligned} (int) flag: write maps (and ideals) aligned |
---|
36 | @code{TeXreplace} (list) list entries = 2 strings: replacing symbols |
---|
37 | @code{NoDollars} (int) flag: suppresses surrounding $ signs |
---|
38 | @end format |
---|
39 | "; |
---|
40 | |
---|
41 | LIB "inout.lib"; |
---|
42 | |
---|
43 | /////////////////////////////////////////////////////////////////////////////// |
---|
44 | |
---|
45 | proc closetex(string fname, list #) |
---|
46 | "USAGE: closetex(fname); fname string |
---|
47 | RETURN: nothing; writes a LaTeX2e closing line into file @code{<fname>}. |
---|
48 | NOTE: preceding \">>\" are deleted and suffix \".tex\" (if not given) |
---|
49 | is added to @code{fname}. |
---|
50 | EXAMPLE: example closetex; shows an example |
---|
51 | " |
---|
52 | { |
---|
53 | string default = "latex2e"; |
---|
54 | string s; |
---|
55 | int i = 1; |
---|
56 | int flag; |
---|
57 | |
---|
58 | if (size(#)) { default = #[1];} |
---|
59 | |
---|
60 | if (default=="latex2e" or default == "latex") |
---|
61 | { s = "\\end{document}"; flag = 1;} |
---|
62 | if (default=="amstex") {s = "\\enddocument"; flag = 1;} |
---|
63 | if (default=="tex") {s = "\\bye"; flag = 1;} |
---|
64 | if (not(flag)) { s = "";} |
---|
65 | |
---|
66 | if (size(fname)) |
---|
67 | { |
---|
68 | while (fname[i]==">"){i++;} |
---|
69 | fname = fname[i,size(fname)-i+1]; |
---|
70 | |
---|
71 | if (size(fname)>=4) // check if filename is ending with ".tex" |
---|
72 | { if(fname[size(fname)-3,4]!=".tex") {fname = fname +".tex"; } |
---|
73 | } |
---|
74 | else {fname = fname + ".tex";} |
---|
75 | write(fname, s); |
---|
76 | write(fname," - Thanks latex.lib and Singular - "); |
---|
77 | } |
---|
78 | else {return(s);} |
---|
79 | } |
---|
80 | example |
---|
81 | { "EXAMPLE:"; echo=2; |
---|
82 | opentex("exmpl"); |
---|
83 | texobj("exmpl","{\\large \\bf hello}"); |
---|
84 | closetex("exmpl"); |
---|
85 | echo=0; |
---|
86 | } |
---|
87 | /////////////////////////////////////////////////////////////////////////////// |
---|
88 | |
---|
89 | proc tex(string fname, list #) |
---|
90 | "USAGE: tex(fname); fname string |
---|
91 | RETURN: nothing; calls latex (LaTeX2e) for compiling the file fname |
---|
92 | NOTE: preceding \">>\" are deleted and suffix \".tex\" (if not given) |
---|
93 | is added to @code{fname}. |
---|
94 | EXAMPLE: example tex; shows an example |
---|
95 | " |
---|
96 | { |
---|
97 | string default = "latex2e"; |
---|
98 | int retval; |
---|
99 | int i=1; |
---|
100 | if (size(#)) {default = string(#[1]);} |
---|
101 | if (size(fname)) |
---|
102 | { |
---|
103 | while (fname[i]==">"){i++;} |
---|
104 | fname = fname[i,size(fname)-i+1]; |
---|
105 | |
---|
106 | if (size(fname)>=4) // check if filename is ending with ".tex" |
---|
107 | { if(fname[size(fname)-3,4]!=".tex") {fname = fname +".tex"; } |
---|
108 | } |
---|
109 | else {fname = fname + ".tex";} |
---|
110 | "calling ",default, " for :",fname,newline; |
---|
111 | |
---|
112 | if (default=="latex2e") |
---|
113 | { |
---|
114 | retval = system("sh","latex " + fname); |
---|
115 | } |
---|
116 | else |
---|
117 | { |
---|
118 | retval = system("sh",default + " " + fname); |
---|
119 | } |
---|
120 | } |
---|
121 | else |
---|
122 | { " -- Need a filename "; |
---|
123 | return(); |
---|
124 | } |
---|
125 | } |
---|
126 | example |
---|
127 | { "EXAMPLE:"; echo =2; |
---|
128 | ring r; |
---|
129 | ideal I = maxideal(7); |
---|
130 | opentex("exp001"); // open latex2e document |
---|
131 | texobj("exp001","An ideal ",I); |
---|
132 | closetex("exp001"); |
---|
133 | tex("exp001"); |
---|
134 | echo=0; |
---|
135 | pause("the created files will be deleted after pressing <RETURN>"); |
---|
136 | system("sh","rm exp001.*"); |
---|
137 | } |
---|
138 | /////////////////////////////////////////////////////////////////////////////// |
---|
139 | |
---|
140 | proc opentex(string fname, list #) |
---|
141 | "USAGE: opentex(fname); fname string |
---|
142 | RETURN: nothing; writes a LaTeX2e header into a new file @code{<fname>}. |
---|
143 | NOTE: preceding \">>\" are deleted and suffix \".tex\" (if not given) |
---|
144 | is added to @code{fname}. |
---|
145 | EXAMPLE: example opentex; shows an example |
---|
146 | " |
---|
147 | { |
---|
148 | string default = "latex2e"; |
---|
149 | string s; |
---|
150 | int i =1; |
---|
151 | int flag; |
---|
152 | |
---|
153 | if (size(#)) { default = #[1];} |
---|
154 | |
---|
155 | if (default == "latex2e") // the default latex2e header |
---|
156 | { s = |
---|
157 | "\\documentclass{article}" + newline + |
---|
158 | "\\usepackage{amsmath,amssymb}" + newline + |
---|
159 | "\\setlength{\\textwidth}{390pt}" + newline + |
---|
160 | "\\parindent=0pt" + newline + |
---|
161 | "\\newcommand{\\C}{\\mathbb{C}}" + newline + |
---|
162 | "\\newcommand{\\F}{\\mathbb{F}}" + newline + |
---|
163 | "\\newcommand{\\N}{\\mathbb{N}}" + newline + |
---|
164 | // "\\newcommand{\\P}{{\\Bbb P}}" + newline + |
---|
165 | "\\newcommand{\\Q}{\\mathbb{Q}}" + newline + |
---|
166 | "\\newcommand{\\R}{\\mathbb{R}}" + newline + |
---|
167 | "\\newcommand{\\T}{\\mathbb{T}}" + newline + |
---|
168 | "\\newcommand{\\Z}{\\mathbb{Z}}" + newline + newline + |
---|
169 | "\\begin{document}"; |
---|
170 | flag = 1; |
---|
171 | } |
---|
172 | if (default == "latex") |
---|
173 | { s = |
---|
174 | "\\documentstyle[12pt,amstex]{article}" + newline + |
---|
175 | "\\parindent=0pt" + newline + |
---|
176 | "\\newcommand{\\C}{{\\Bbb C}}" + newline + |
---|
177 | "\\newcommand{\\F}{{\\Bbb F}}" + newline + |
---|
178 | "\\newcommand{\\N}{{\\Bbb N}}" + newline + |
---|
179 | // "\\newcommand{\\P}{{\\Bbb P}}" + newline + |
---|
180 | "\\newcommand{\\Q}{{\\Bbb Q}}" + newline + |
---|
181 | "\\newcommand{\\R}{{\\Bbb R}}" + newline + |
---|
182 | "\\newcommand{\\T}{{\\Bbb T}}" + newline + |
---|
183 | "\\newcommand{\\Z}{{\\Bbb Z}}" + newline + newline + |
---|
184 | "\\begin{document}"; |
---|
185 | flag = 1; |
---|
186 | } |
---|
187 | if (default == "amstex") |
---|
188 | { s = |
---|
189 | "\\documentstyle{amsppt} " + newline + newline + |
---|
190 | "\\document"; |
---|
191 | flag = 1; |
---|
192 | } |
---|
193 | |
---|
194 | if (default == "tex") |
---|
195 | { s = |
---|
196 | ""; |
---|
197 | flag = 1; |
---|
198 | } |
---|
199 | if (default == "own") // the proper own header |
---|
200 | { s = ""; |
---|
201 | flag = 1; |
---|
202 | } |
---|
203 | if (not(flag)) { s = "";} |
---|
204 | |
---|
205 | if (size(fname)) |
---|
206 | { |
---|
207 | while (fname[i]==">"){i++;} |
---|
208 | fname = fname[i,size(fname)-i+1]; |
---|
209 | |
---|
210 | if (size(fname)>=4) // check if filename is ending with ".tex" |
---|
211 | { if(fname[size(fname)-3,4]!=".tex") {fname = fname +".tex"; } |
---|
212 | } |
---|
213 | else {fname = fname + ".tex";} |
---|
214 | fname = ">" + fname; |
---|
215 | write(fname,s); |
---|
216 | } |
---|
217 | else {return(s);} |
---|
218 | } |
---|
219 | example |
---|
220 | { "EXAMPLE:"; echo=2; |
---|
221 | opentex("exmpl"); |
---|
222 | texobj("exmpl","hello"); |
---|
223 | closetex("exmpl"); |
---|
224 | } |
---|
225 | /////////////////////////////////////////////////////////////////////////////// |
---|
226 | |
---|
227 | proc texdemo(list #) |
---|
228 | "USAGE: texdemo(); |
---|
229 | RETURN: nothing; generates a LaTeX2e file called @code{texlibdemo.tex} |
---|
230 | explaining the features of @code{latex.lib} and its global variables. |
---|
231 | NOTE: this proc may take some time. |
---|
232 | " |
---|
233 | { int TeXdemostart = system("pid"); |
---|
234 | string fname = "texlibdemo"; |
---|
235 | |
---|
236 | if (size(#)) |
---|
237 | { if (typeof(#[1])=="int") {TeXdemostart = #[1];} |
---|
238 | } |
---|
239 | system("--random",TeXdemostart); |
---|
240 | |
---|
241 | if (size(#) ==2) |
---|
242 | { if (typeof(#[2]) == "string") { fname = #[2];} |
---|
243 | } |
---|
244 | |
---|
245 | if (size(fname)) |
---|
246 | { |
---|
247 | if (size(fname)>=4) // check if filename is ending with ".tex" |
---|
248 | { if(fname[size(fname)-3,4]!=".tex") {fname = fname +".tex"; } |
---|
249 | } else {fname = fname + ".tex";} |
---|
250 | } |
---|
251 | |
---|
252 | // -------- save global variables --------- |
---|
253 | if (defined(TeXaligned)) {int Teali=TeXaligned; kill TeXaligned;} |
---|
254 | if (defined(TeXreplace)) {list Terep=TeXreplace; kill TeXreplace;} |
---|
255 | if (defined(TeXwidth)) {int Tewid=TeXwidth; kill TeXwidth;} |
---|
256 | if (defined(TeXbrack)) {string Tebra=TeXbrack; kill TeXbrack;} |
---|
257 | if (defined(TeXnofrac)) {int Tenof=TeXnofrac; kill TeXnofrac;} |
---|
258 | if (defined(TeXproj)) {int Tepro=TeXproj; kill TeXproj;} |
---|
259 | // ---------------------------------------- |
---|
260 | |
---|
261 | part0(fname); |
---|
262 | part1(fname); |
---|
263 | part2(fname); |
---|
264 | part3(fname); |
---|
265 | print(" Demofile generated ..."); |
---|
266 | if (size(fname)) |
---|
267 | { |
---|
268 | print(" call latex now by tex(\"" + fname + "\");" ); |
---|
269 | print(" .log and .aux files may be deleted with rmx(\"texlibdemo\");"); |
---|
270 | } |
---|
271 | // -------- save global variables --------- |
---|
272 | if (defined(Teali)) {int TeXaligned=Teali; export TeXaligned; kill Teali;} |
---|
273 | if (defined(Terep)) {list TeXreplace=Terep; export TeXreplace; kill Terep;} |
---|
274 | if (defined(Tewid)) {int TeXwidth=Tewid; export TeXwidth; kill Tewid;} |
---|
275 | if (defined(Tebra)) {string TeXbrack=Tebra; export TeXbrack; kill Tebra;} |
---|
276 | if (defined(Tenof)) {int TeXnofrac=Tenof; export TeXnofrac; kill Tenof;} |
---|
277 | if (defined(Tepro)) {int TeXproj=Tepro; export TeXproj; kill Tepro;} |
---|
278 | // ---------------------------------------- |
---|
279 | |
---|
280 | return(); |
---|
281 | } |
---|
282 | /////////////////////////////////////////////////////////////////////////////// |
---|
283 | |
---|
284 | proc texfactorize(string fname, poly f, list #) |
---|
285 | "USAGE: texfactorize(fname,f); fname string, f poly |
---|
286 | RETURN: if @code{fname=\"\"}: string, f as a product of its irreducible |
---|
287 | factors@* |
---|
288 | otherwise: append this string to the file @code{<fname>}, and |
---|
289 | return nothing. |
---|
290 | NOTE: preceding \">>\" are deleted and suffix \".tex\" (if not given) |
---|
291 | is added to @code{fname}. |
---|
292 | EXAMPLE: example texfactorize; shows an example |
---|
293 | " |
---|
294 | { |
---|
295 | def @r = basering; |
---|
296 | list l; |
---|
297 | int i,j,k,Tw,TW,ND;; |
---|
298 | intvec v; |
---|
299 | string s,t; |
---|
300 | string D = "$"; |
---|
301 | poly g; |
---|
302 | |
---|
303 | ND = defined(NoDollars); |
---|
304 | if (!(ND)) {int NoDollars; export NoDollars;} |
---|
305 | else { D = ""; } |
---|
306 | TW = defined(TeXwidth); |
---|
307 | if (TW) {Tw = TeXwidth; TeXwidth = -1;} |
---|
308 | else {int TeXwidth = -1; export TeXwidth;} |
---|
309 | |
---|
310 | if (f==0) {s= D + "0" + D;} |
---|
311 | else |
---|
312 | { |
---|
313 | l = factorize(f); // sollte auch fuer f== 0 direkt funktionieren |
---|
314 | if (l[1][1]<>1){s = texpoly("",l[1][1]);} |
---|
315 | for(i=2;i<=size(l[1]);i++) |
---|
316 | { |
---|
317 | if(size(s)){s = s+"\\cdot ";} |
---|
318 | g = l[1][i]; |
---|
319 | v = leadexp(g); |
---|
320 | k=0; |
---|
321 | for(j=1;j<=size(v);j++){k = k + v[j];} |
---|
322 | if(size(g)>1 or (size(g)==1 and k>1)) |
---|
323 | { t = "(" + texpoly("",l[1][i]) + ")";} |
---|
324 | else { t = texpoly("",l[1][i]);} |
---|
325 | if (l[2][i]>1) |
---|
326 | { t = t+"^{" +string(l[2][i]) + "}";} |
---|
327 | s = s + t; |
---|
328 | } |
---|
329 | if (!(ND)) { kill NoDollars;} |
---|
330 | s = D + s + D; |
---|
331 | if (TW) {TeXwidth = Tw;} |
---|
332 | } |
---|
333 | if(size(fname)) |
---|
334 | { i=1; |
---|
335 | while (fname[i]==">"){i++;} |
---|
336 | fname = fname[i,size(fname)-i+1]; |
---|
337 | |
---|
338 | if (size(fname)>=4) // check if filename is ending with ".tex" |
---|
339 | { if(fname[size(fname)-3,4]!=".tex") {fname = fname +".tex"; } |
---|
340 | } |
---|
341 | else {fname = fname + ".tex";} |
---|
342 | write(fname,s); |
---|
343 | } |
---|
344 | else{return(s);} |
---|
345 | } |
---|
346 | example |
---|
347 | { "EXAMPLE:"; echo=2; |
---|
348 | ring r2 = 13,(x,y),dp; |
---|
349 | poly f = (x+1+y)^2*x3y*(2x-2y)*y12; |
---|
350 | texfactorize("",f); |
---|
351 | ring R49 = (7,a),x,dp; |
---|
352 | minpoly = a2+a+3; |
---|
353 | poly f = (a24x5+x3)*a2x6*(x+1)^2; |
---|
354 | f; |
---|
355 | texfactorize("",f); |
---|
356 | } |
---|
357 | |
---|
358 | /////////////////////////////////////////////////////////////////////////////// |
---|
359 | static proc rp(string s) |
---|
360 | { int i; |
---|
361 | |
---|
362 | for(i=1;i<=size(TeXreplace);i++) |
---|
363 | { if (TeXreplace[i][1]==s) {s= TeXreplace[i][2]; break;}} |
---|
364 | return(s); |
---|
365 | } |
---|
366 | /////////////////////////////////////////////////////////////////////////////// |
---|
367 | |
---|
368 | |
---|
369 | proc texmap(string fname, def m, def @r1, def @r2, list #) |
---|
370 | "USAGE: texmap(fname,m,@r1,@r2); fname string, m string/map, @r1,@r2 rings |
---|
371 | RETURN: if @code{fname=\"\"}: string, the map m from @r1 to @r2 (preceded |
---|
372 | by its name if m = string) in TeX-typesetting;@* |
---|
373 | otherwise: append this string to the file @code{<fname>}, and |
---|
374 | return nothing. |
---|
375 | NOTE: preceding \">>\" are deleted in @code{fname}, and suffix \".tex\" |
---|
376 | (if not given) is added to @code{fname}. |
---|
377 | If m is a string then it has to be the name of an existing map |
---|
378 | from @r1 to @r2. |
---|
379 | EXAMPLE: example texmap; shows an example |
---|
380 | " |
---|
381 | { |
---|
382 | int saveDollars= defined(NoDollars); |
---|
383 | int TX = defined(TeXwidth); |
---|
384 | int Tw; |
---|
385 | int i,n; |
---|
386 | string r1str,r2str, varr1str, varr2str; |
---|
387 | string mapname,t,s; |
---|
388 | string D,DD,vrg = "$","$$",","; |
---|
389 | def @r = basering; |
---|
390 | def themap; |
---|
391 | list l1,l2; |
---|
392 | string rr1,rr2 = "@r1","@r2"; |
---|
393 | |
---|
394 | // --- store all actual informations |
---|
395 | if(TX) { Tw = TeXwidth; TeXwidth = -1;} |
---|
396 | else { int TeXwidth = -1; export TeXwidth;} |
---|
397 | if (!(saveDollars)) { int NoDollars; export NoDollars;} |
---|
398 | if (defined(TeXproj)) {vrg = ":";} |
---|
399 | |
---|
400 | if (size(#)) |
---|
401 | { if (typeof(#[1])=="list") |
---|
402 | { l1 = #[1]; |
---|
403 | if(size(#)==2) { l2 = #[2];} |
---|
404 | } |
---|
405 | else {l1=#; l2 =#;} |
---|
406 | } |
---|
407 | // --- tex the information in preimring r1 |
---|
408 | |
---|
409 | setring(@r1); |
---|
410 | r1str = texring("",@r1,l1); |
---|
411 | // --- avoid an execute; hence construct an ideal |
---|
412 | |
---|
413 | n = nvars(@r1); |
---|
414 | if (n>1) { t = "\\left(";} |
---|
415 | ideal @I = var(1); |
---|
416 | t = t + texpoly("",var(1)); |
---|
417 | for(i=2;i<=n;i++) |
---|
418 | { @I = @I + var(i); |
---|
419 | t = t + vrg + texpoly("",var(i)); |
---|
420 | } |
---|
421 | if (n>1) { t = t + "\\right)";} |
---|
422 | varr1str = t; |
---|
423 | |
---|
424 | // --- now the things in ring ring r2 |
---|
425 | |
---|
426 | setring(@r2); |
---|
427 | // listvar(); |
---|
428 | |
---|
429 | if (typeof(m)=="string") |
---|
430 | { themap = `m`; |
---|
431 | mapname = m; |
---|
432 | if (defined(TeXreplace)) |
---|
433 | { mapname = rp(mapname); // rp ausschreiben ! |
---|
434 | } |
---|
435 | mapname = mapname + ":"; |
---|
436 | } |
---|
437 | if (typeof(m)=="map") { themap = m;} |
---|
438 | |
---|
439 | r2str = texring("",@r2,l2); |
---|
440 | ideal @J = themap(@I); |
---|
441 | n = size(matrix(@J)); |
---|
442 | if (n>1) { t = " \\left(";} |
---|
443 | if (!(defined(TeXaligned)) and (n>1)) |
---|
444 | { t = t + newline + "\\begin{array}{c}" + newline;} |
---|
445 | t = t + texpoly("",@J[1]); |
---|
446 | for (i=2;i<=n; i++) |
---|
447 | {if(defined(TeXaligned)) |
---|
448 | { t = t + vrg + texpoly("",@J[i]); } |
---|
449 | else { t = t + "\\\\" + newline + texpoly("",@J[i]);} |
---|
450 | } |
---|
451 | if (!(defined(TeXaligned)) and (n>1)) |
---|
452 | { t = t + newline + "\\end{array}" + newline;} |
---|
453 | if (n>1) {t = t + "\\right)";} |
---|
454 | varr2str = t; |
---|
455 | |
---|
456 | // --- go back to ring r1 to kill @I |
---|
457 | |
---|
458 | setring(@r1); |
---|
459 | kill @I; |
---|
460 | |
---|
461 | // --- now reset the old settings and stick all the information together |
---|
462 | |
---|
463 | setring(@r); |
---|
464 | if (!(saveDollars)) { kill NoDollars;} |
---|
465 | if (TX) {TeXwidth = Tw;} |
---|
466 | else { kill TeXwidth;} |
---|
467 | if (defined(NoDollars)) |
---|
468 | { D,DD = "",""; } |
---|
469 | |
---|
470 | if (defined(TeXaligned)) |
---|
471 | { s = D + mapname; |
---|
472 | s = s + r1str + "\\longrightarrow" + r2str + ", \\ " + |
---|
473 | varr1str + "\\longmapsto" + varr2str + D; } |
---|
474 | else |
---|
475 | { s = DD; |
---|
476 | s = s + newline + "\\begin{array}{rcc}" + newline; |
---|
477 | s = s + mapname + r1str + " & \\longrightarrow & " + r2str + "\\\\[2mm]" |
---|
478 | + newline; |
---|
479 | s = s + varr1str + " & \\longmapsto & " + newline + varr2str + newline; |
---|
480 | s = s + "\\end{array}" + newline; |
---|
481 | s = s + DD; |
---|
482 | } |
---|
483 | |
---|
484 | if (size(fname)) |
---|
485 | { i=1; |
---|
486 | while (fname[i]==">"){i++;} |
---|
487 | fname = fname[i,size(fname)-i+1]; |
---|
488 | |
---|
489 | if (size(fname)>=4) // check if filename is ending with ".tex" |
---|
490 | { if(fname[size(fname)-3,4]!=".tex") {fname = fname +".tex"; } |
---|
491 | } |
---|
492 | else {fname = fname + ".tex";} |
---|
493 | write(fname,s); |
---|
494 | } |
---|
495 | else {return(s);} |
---|
496 | } |
---|
497 | example |
---|
498 | { |
---|
499 | echo=0; |
---|
500 | // -------- prepare for example --------- |
---|
501 | if (defined(TeXaligned)) {int Teali=TeXaligned; kill TeXaligned;} |
---|
502 | if (defined(TeXreplace)) {list Terep=TeXreplace; kill TeXreplace;} |
---|
503 | // -------- the example starts here --------- |
---|
504 | // |
---|
505 | "EXAMPLE:"; echo = 2; |
---|
506 | string fname = "tldemo"; |
---|
507 | ring @r1=0,(x,y,z),dp; |
---|
508 | if(system("with","Namespaces")) { exportto(Current,@r1); } |
---|
509 | else { export @r1; } |
---|
510 | ring r2=0,(u,v),dp; |
---|
511 | map @phi =(@r1,u2,uv -v,v2); export @phi; |
---|
512 | list TeXreplace; |
---|
513 | TeXreplace[1] = list("@phi","\\phi"); // @phi --> \phi |
---|
514 | export TeXreplace; |
---|
515 | texmap("","@phi",@r1,r2); // standard form |
---|
516 | // |
---|
517 | int TeXaligned; export TeXaligned; // map in one line |
---|
518 | texmap("",@phi,@r1,r2); |
---|
519 | // |
---|
520 | kill @r1,TeXreplace,TeXaligned; |
---|
521 | echo = 0; |
---|
522 | // |
---|
523 | // --- restore global variables if previously defined --- |
---|
524 | if (defined(Teali)) {int TeXaligned=Teali; export TeXaligned; kill Teali;} |
---|
525 | if (defined(Terep)) {list TeXreplace=Terep; export TeXreplace; kill Terep;} |
---|
526 | } |
---|
527 | |
---|
528 | |
---|
529 | /////////////////////////////////////////////////////////////////////////////// |
---|
530 | static proc manipul(string s) |
---|
531 | { |
---|
532 | string st; |
---|
533 | int i,anf,end,op,bigch; |
---|
534 | int n; |
---|
535 | if (s[1]=="{") { return(s[2,size(s)-2]);} |
---|
536 | if (s=="") { return(s);} |
---|
537 | s = s + newline; // add a terminating sign |
---|
538 | anf=1; |
---|
539 | while(s[i]!=newline) |
---|
540 | { |
---|
541 | i =anf; |
---|
542 | while(s[i]<"0" or s[i]>"9" and s[i]!="'" and s[i]!= "_" and s[i]!="~" and |
---|
543 | s[i]!="(" and s[i]!=")" and s[i]!= "[" and s[i]!=newline) {i++;} |
---|
544 | if (s[i]==newline){st = st + s[anf,i-anf]; n = n+10*(i-anf); return(st);} |
---|
545 | st = st + s[anf,i-anf]; // the starting letters |
---|
546 | if (s[anf]>="A" and s[anf]<="Z") {bigch=1;} |
---|
547 | if (s[i]=="'") { st = st + "'";i++;} |
---|
548 | if (s[i]=="~") { st = "\\tilde{" + st + "}"; i++;} |
---|
549 | if (s[i]=="_") { i++;} |
---|
550 | if (s[i]=="(") { op =1;i++;} |
---|
551 | if (s[i]=="[") { anf = i+1; |
---|
552 | while(s[i]!="]"){i++;} // matrices and vectors |
---|
553 | st = st + "_{" + s[anf,i-anf] + "}"; n = n+ 5*(i-anf); i++; |
---|
554 | // besser: while s[i]<> nwline : scan forward: end, return |
---|
555 | } |
---|
556 | if (s[i]==newline) {return(st);} |
---|
557 | anf =i; |
---|
558 | while (s[i]>="0" and s[i]<="9") {i++;} // parse number after the letters |
---|
559 | if (bigch and not(op)) { st = st + "^{" + s[anf,i-anf] + "}"; bigch =0;} |
---|
560 | else { st = st + "_{" + s[anf,i-anf] + "}";} |
---|
561 | n = n+5*(i-anf); |
---|
562 | anf =i; // the next text in ( , ) as exponent |
---|
563 | if (op) |
---|
564 | { |
---|
565 | if (s[i]== ","){anf = anf+1;} |
---|
566 | while(s[i] !=")"){ i++;} |
---|
567 | if (i<>anf) |
---|
568 | { |
---|
569 | st = st + "^{" + s[anf,i-anf] + "}"; n = n +5*(i-anf);} |
---|
570 | i++; |
---|
571 | } |
---|
572 | anf =i; |
---|
573 | } |
---|
574 | return(st); |
---|
575 | } |
---|
576 | |
---|
577 | /////////////////////////////////////////////////////////////////////////////// |
---|
578 | |
---|
579 | proc texname(string fname, string s) |
---|
580 | "USAGE: texname(fname,s); fname,s strings |
---|
581 | RETURN: if @code{fname=\"\"}: string, the transformed string s, where the |
---|
582 | following rules apply: |
---|
583 | @example |
---|
584 | s' + \"~\" --> \"\\tilde@{\"+ s' +\"@}\" |
---|
585 | \"_\" + int --> \"_@{\" + int +\"@}\" |
---|
586 | \"[\" + s' + \"]\" --> \"_@{\" + s' + \"@}\" |
---|
587 | \"A..Z\" + int --> \"A..Z\" + \"^@{\" + int + \"@}\" |
---|
588 | \"a..z\" + int --> \"a..z\" + \"_@{\" + int + \"@}\" |
---|
589 | \"(\" + int + \",\" + s' + \")\" --> \"_@{\"+ int +\"@}\" + \"^@{\" + s'+\"@}\" |
---|
590 | @end example |
---|
591 | Anyhow, strings which begin with a @code{\"@{\"} are only changed |
---|
592 | by deleting the first and last character (intended to remove the |
---|
593 | surrounding curly brackets). |
---|
594 | |
---|
595 | if @code{fname!=\"\"}: append the transformed string s to the file |
---|
596 | @code{<fname>}, and return nothing. |
---|
597 | NOTE: preceding \">>\" are deleted in @code{fname}, and suffix \".tex\" |
---|
598 | (if not given) is added to @code{fname}. |
---|
599 | EXAMPLE: example texname; shows an example |
---|
600 | " |
---|
601 | { |
---|
602 | string st, extr; |
---|
603 | st=manipul(s); |
---|
604 | if (size(fname)) |
---|
605 | { |
---|
606 | int i=1; |
---|
607 | while (fname[i]==">"){i++;} |
---|
608 | fname = fname[i,size(fname)-i+1]; |
---|
609 | if (size(fname)>=4) // check if filename is ending with ".tex" |
---|
610 | { |
---|
611 | if(fname[size(fname)-3,4]!=".tex") {fname = fname +".tex"; } |
---|
612 | } |
---|
613 | else {fname = fname + ".tex";} |
---|
614 | write(fname,st); |
---|
615 | } |
---|
616 | else {return(st);} |
---|
617 | } |
---|
618 | example |
---|
619 | { "EXAMPLE:"; echo =2; |
---|
620 | ring r = 0,(x,y),lp; |
---|
621 | poly f = 3xy4 + 2xy2 + x5y3 + x + y6; |
---|
622 | texname("","{f(10)}"); |
---|
623 | texname("","f(10) ="); |
---|
624 | texname("","n1"); |
---|
625 | texname("","T1_12"); |
---|
626 | texname("","g'_11"); |
---|
627 | texname("","f23"); |
---|
628 | texname("","M[2,3]"); |
---|
629 | texname("","A(0,3);"); |
---|
630 | texname("","E~(3)"); |
---|
631 | } |
---|
632 | |
---|
633 | /////////////////////////////////////////////////////////////////////////////// |
---|
634 | |
---|
635 | static proc absterm(poly f) |
---|
636 | { |
---|
637 | int k; |
---|
638 | for (k=1; k<=nvars(basering); k++) |
---|
639 | { f = subst(f,var(k),0); } |
---|
640 | return(f); |
---|
641 | } |
---|
642 | /////////////////////////////////////////////////////////////////////////////// |
---|
643 | |
---|
644 | proc texobj(string fname, list #) |
---|
645 | "USAGE: texobj(fname,l); fname string, l list |
---|
646 | RETURN: if @code{fname=\"\"}: string, the entries of l in LaTeX-typesetting;@* |
---|
647 | otherwise: append this string to the file @code{<fname>}, and |
---|
648 | return nothing. |
---|
649 | NOTE: preceding \">>\" are deleted in @code{fname}, and suffix \".tex\" |
---|
650 | (if not given) is added to @code{fname}. |
---|
651 | EXAMPLE: example texobj; shows an example |
---|
652 | " |
---|
653 | { |
---|
654 | int i,j,k,nr,nc,linear,Tw,Dollars; |
---|
655 | int ND = defined(NoDollars); |
---|
656 | int TW = defined(TeXwidth); |
---|
657 | |
---|
658 | if(defined(basering)){ poly g,h; matrix M;} |
---|
659 | string s,t,l,ineq,sg,Iname; |
---|
660 | string sep= ","; |
---|
661 | string D,DA,DE = "$","$$","$$"; |
---|
662 | string OB,CB = "(",")"; |
---|
663 | if (defined(TeXbrack)) |
---|
664 | {// if (TeXbrack=="(") {OB = "("; CB = ")";} |
---|
665 | if (TeXbrack=="<") {OB = "<"; CB = ">";} |
---|
666 | if (TeXbrack=="{") {OB = "{"; CB = "}";} |
---|
667 | if (TeXbrack=="|") {OB = "|"; CB = "|";} |
---|
668 | if (TeXbrack=="" ) {OB = "."; CB = ".";} |
---|
669 | } |
---|
670 | |
---|
671 | if (!(TW)) { int TeXwidth = -1; export TeXwidth; } |
---|
672 | Tw = TeXwidth; |
---|
673 | |
---|
674 | if (defined(TeXproj)){ sep = ":";} |
---|
675 | if(ND) { D,DA,DE="","","";} |
---|
676 | else {int NoDollars; export NoDollars;} |
---|
677 | |
---|
678 | if (size(#)==1) |
---|
679 | { if (typeof(#[1])=="int" or typeof(#[1])=="intvec" or typeof(#[1])=="vector" |
---|
680 | or typeof(#[1])=="number" or defined(TeXaligned)) { DA = D; DE = D; } } |
---|
681 | |
---|
682 | s = DA; |
---|
683 | |
---|
684 | for (k=1; k<=size(#); k++) |
---|
685 | { def obj = #[k]; |
---|
686 | if (typeof(obj) == "string") |
---|
687 | { if (defined(`obj`)) |
---|
688 | { if (typeof(`obj`)=="ideal") |
---|
689 | { |
---|
690 | Iname = obj; def e = `obj`; //convert to correct type ideal |
---|
691 | kill obj; def obj = e; kill e; |
---|
692 | } |
---|
693 | else {s = s + obj + newline;} |
---|
694 | } |
---|
695 | else {s = s + obj + newline;} |
---|
696 | } |
---|
697 | if (typeof(obj) == "int") { s = s + " " + string(obj) + " ";} |
---|
698 | |
---|
699 | if (typeof(obj) == "intvec") |
---|
700 | { s = s + " ("; |
---|
701 | for(j=1; j<size(obj);j++) { s = s + string(obj[j]) + sep;} |
---|
702 | s = s + string(obj[j]) + ") "; |
---|
703 | } |
---|
704 | |
---|
705 | if (typeof(obj) == "number" ) |
---|
706 | { s = s + texpoly("",obj) + newline; |
---|
707 | } |
---|
708 | |
---|
709 | if (typeof(obj) == "poly") |
---|
710 | { int TeXdisplay; export TeXdisplay; |
---|
711 | s = s + "\\begin{array}{rl}" + newline; |
---|
712 | s = s + texpoly("",obj) + "\\\\" + newline; |
---|
713 | s = s + "\\end{array}" + newline; |
---|
714 | kill TeXdisplay; |
---|
715 | } |
---|
716 | |
---|
717 | if (typeof(obj) == "vector") |
---|
718 | { if (obj==0) { s = s + "0" ;} |
---|
719 | else |
---|
720 | { if (Tw==0) { TeXwidth = -1;} |
---|
721 | s = s + "\\left" + OB; |
---|
722 | for(j=1; j<nrows(obj); j++) {s = s + texpoly("",obj[j]) + sep;} |
---|
723 | s = s + texpoly("",obj[j]) + "\\right" + CB + newline; |
---|
724 | TeXwidth = Tw; |
---|
725 | } |
---|
726 | } |
---|
727 | |
---|
728 | if (typeof(obj) == "ideal") |
---|
729 | { if (size(Iname)) // verwende hier align |
---|
730 | { if (Tw==0) {TeXwidth = -1;} |
---|
731 | |
---|
732 | // Lasse hier TeXwidth == 0 zu ! |
---|
733 | // if (!(defined(TeXaligned))) |
---|
734 | // { untereinander } |
---|
735 | // else { hintereinander } |
---|
736 | // |
---|
737 | // |
---|
738 | // s = s + Iname + "=" + texpoly("",obj,","); |
---|
739 | // siehe ebenso noch einmal am Ende : ! (TeXwidth <> 0 !? ) |
---|
740 | |
---|
741 | s = s + "\\begin{array}{rcl}" + newline; |
---|
742 | for (i=1;i<=size(matrix(obj));i++) |
---|
743 | { s = s + Iname+ "_{" + string(i) + "} & = & " |
---|
744 | + texpoly("",obj[i]); |
---|
745 | if (i<size(matrix(obj))){ s = s + "\\\\" + newline;} |
---|
746 | } |
---|
747 | s = s + newline; |
---|
748 | s = s + "\\end{array}" + newline; |
---|
749 | TeXwidth = Tw; |
---|
750 | Iname =""; |
---|
751 | } |
---|
752 | else |
---|
753 | { |
---|
754 | if (TeXwidth==0) |
---|
755 | { TeXwidth = -1; |
---|
756 | obj= simplify(obj,2); |
---|
757 | linear = 1; |
---|
758 | for (j=1;j<=size(obj);j++) |
---|
759 | { if (deg(obj[j])>1){linear =0; break;} |
---|
760 | } |
---|
761 | if (!(linear)) |
---|
762 | { s = s + "\\begin{array}{rcl}" + newline; |
---|
763 | for(j=1;j<=size(obj);j++) |
---|
764 | { h = absterm(obj[j]); |
---|
765 | ineq = attrib(obj[j],"ineq"); |
---|
766 | if(!(size(ineq))) { ineq = "=" ; } |
---|
767 | l = texpoly("",obj[j]-h) + " & " + ineq + " & " + texpoly("",-h); |
---|
768 | if(j<size(obj)) { l = l + " \\\\";} |
---|
769 | s =s+ l + newline; |
---|
770 | } |
---|
771 | s = s + "\\end{array}" + newline; |
---|
772 | } |
---|
773 | else // linear |
---|
774 | { s = s + |
---|
775 | "\\begin{array}{*{" + string(2*nvars(basering)-1) + "}{c}cr}" + newline; |
---|
776 | for(j=1; j<=size(obj);j++) |
---|
777 | { h = absterm(obj[j]); |
---|
778 | ineq = attrib(obj[j],"ineq"); |
---|
779 | if(!(size(ineq))) { ineq = "=" ; } |
---|
780 | l = ""; nc = 0; |
---|
781 | for (i=1; i<=nvars(basering);i++) |
---|
782 | { t = " "; sg =""; |
---|
783 | g = obj[j]-subst(obj[j],var(i),0); |
---|
784 | if (g!=0) { t = texpoly("",g);} |
---|
785 | if (i>1) |
---|
786 | { if (t[1]!="-" and t[1]!= " " and nc ){sg = "+";} |
---|
787 | if (t[1]=="-") { sg = "-"; nc =1; t=t[2,size(t)-1];} |
---|
788 | if (t==" ") {sg ="";} |
---|
789 | l = l + " & " + sg + " & " + t; |
---|
790 | } |
---|
791 | else { l = t;} |
---|
792 | if (g!=0) {nc = 1;} |
---|
793 | } |
---|
794 | |
---|
795 | l = l + " & " + ineq + " & " + texpoly("",-h); |
---|
796 | if (j < size(obj)) { l = l + " \\\\";} |
---|
797 | s = s + l + newline; |
---|
798 | } // end for (j) |
---|
799 | s = s + "\\end{array}"; |
---|
800 | } // end else linear |
---|
801 | TeXwidth = 0; |
---|
802 | } // end TeXwidth == 0 |
---|
803 | else // TeXwidth <> 0 |
---|
804 | { s = s + "\\left"+ OB; |
---|
805 | if (defined(TeXaligned)) |
---|
806 | { s = s + texpoly("",obj,","); |
---|
807 | } |
---|
808 | else |
---|
809 | { s = s + newline + "\\begin{array}{c}" + newline + |
---|
810 | texpoly("",obj,", \\\\" + newline) + |
---|
811 | newline + "\\end{array}" + newline; |
---|
812 | } |
---|
813 | s = s + "\\right" + CB; |
---|
814 | } // end TeXwidth <> 0 |
---|
815 | } // not Iname |
---|
816 | // s; |
---|
817 | } |
---|
818 | |
---|
819 | if (typeof(obj) == "module") |
---|
820 | { M = matrix(obj); |
---|
821 | if (Tw ==0 or Tw > 9) { TeXwidth = -1;} |
---|
822 | s = s + "\\left" + OB + newline; |
---|
823 | if (!(defined(TeXaligned))) |
---|
824 | { // Naechste Zeile nicht notwendig ! |
---|
825 | // s = s + "\\begin{array}{*{"+ string(ncols(M)) + "}{c}}" + newline; |
---|
826 | for(j=1;j<=ncols(M);j++) |
---|
827 | { l = "\\left" + OB + newline + "\\begin{array}{c}" + newline; |
---|
828 | l = l + texpoly("",ideal(M[1..nrows(M),j]), " \\\\" + newline) |
---|
829 | + newline + "\\end{array}" +newline + "\\right" + CB + newline; |
---|
830 | if (j< ncols(M)) { l = l + " , " + newline;} |
---|
831 | s = s + l ; |
---|
832 | } |
---|
833 | } |
---|
834 | else // TeXaligned |
---|
835 | { |
---|
836 | for(j=1;j<=ncols(M);j++) |
---|
837 | { s = s + "\\left" + OB + newline + |
---|
838 | texpoly("",ideal(M[1..nrows(M),j]),",") + newline + "\\right" + CB; |
---|
839 | if (j<ncols(M)) { s = s + "," + newline; } |
---|
840 | } |
---|
841 | } |
---|
842 | s = s + "\\right" + CB + newline; |
---|
843 | } // module part |
---|
844 | |
---|
845 | if (typeof(obj) == "matrix") |
---|
846 | { if (Tw==0 or Tw > 9) {TeXwidth = -1;} |
---|
847 | l = ""; |
---|
848 | // M = transpose(obj); |
---|
849 | s = s + "\\left" + OB + newline + |
---|
850 | "\\begin{array}{*{"+ string(ncols(obj)) + "}{c}" + "}"+ newline; |
---|
851 | for(i=1;i<=nrows(obj);i++) |
---|
852 | { l = l + texpoly("",ideal(obj[i,1..ncols(obj)])," & "); |
---|
853 | if (i<nrows(obj)) { l = l + " \\\\" + newline;} |
---|
854 | } |
---|
855 | l = l + newline; |
---|
856 | s = s + l + "\\end{array}" + newline + |
---|
857 | "\\right" + CB + newline; |
---|
858 | TeXwidth = Tw; |
---|
859 | } |
---|
860 | |
---|
861 | if (typeof(obj) == "intmat") |
---|
862 | { nr,nc = nrows(obj),ncols(obj); |
---|
863 | l = ""; |
---|
864 | l = "\\left" + OB + newline + |
---|
865 | "\\begin{array}{*{"+ string(nc) + "}{r}}"+ newline; |
---|
866 | for(i=1;i<=nr;i++) |
---|
867 | { for(j=1;j<=nc;j++) |
---|
868 | { l = l + string(obj[i,j]); |
---|
869 | if (j <nc ) { l = l + " & ";} |
---|
870 | else {if( i < nr) { l = l + "\\\\" + newline;}} |
---|
871 | } |
---|
872 | } |
---|
873 | l = l + newline + "\\end{array}" + newline + |
---|
874 | "\\right" + CB + newline; |
---|
875 | s = s + l; |
---|
876 | } |
---|
877 | |
---|
878 | if (typeof(obj) == "ring" or |
---|
879 | typeof(obj) == "qring") { s = s + D + texring("",obj) + D + newline;} |
---|
880 | |
---|
881 | kill obj; |
---|
882 | } |
---|
883 | |
---|
884 | s = s + DE + newline; |
---|
885 | |
---|
886 | if(!(ND)) { kill NoDollars;} |
---|
887 | |
---|
888 | // s; |
---|
889 | if(size(fname)) |
---|
890 | { i=1; |
---|
891 | while (fname[i]==">"){i++;} |
---|
892 | fname = fname[i,size(fname)-i+1]; |
---|
893 | if (size(fname)>=4) // check if filename is ending with ".tex" |
---|
894 | { if(fname[size(fname)-3,4]!=".tex") {fname = fname +".tex"; } |
---|
895 | } |
---|
896 | else {fname = fname + ".tex";} |
---|
897 | write(fname,s); |
---|
898 | } |
---|
899 | else {return(s);} |
---|
900 | } |
---|
901 | example |
---|
902 | { |
---|
903 | echo=0; |
---|
904 | // -------- prepare for example --------- |
---|
905 | if (defined(TeXaligned)) {int Teali=TeXaligned; kill TeXaligned;} |
---|
906 | if (defined(TeXbrack)){string Tebra=TeXbrack; kill TeXbrack;} |
---|
907 | "EXAMPLE:"; echo = 2; |
---|
908 | // |
---|
909 | // -------------- typesetting for polynomials ---------- |
---|
910 | ring r = 0,(x,y),lp; |
---|
911 | poly f = x5y3 + 3xy4 + 2xy2 + y6; |
---|
912 | f; |
---|
913 | texobj("",f); |
---|
914 | pause(); |
---|
915 | // -------------- typesetting for ideals ---------- |
---|
916 | ideal G = jacob(f); |
---|
917 | G; |
---|
918 | texobj("",G); |
---|
919 | pause(); |
---|
920 | // -------------- variation of typesetting for ideals ---------- |
---|
921 | int TeXaligned = 1; export TeXaligned; |
---|
922 | string TeXbrack = "<"; export TeXbrack; |
---|
923 | texobj("",G); |
---|
924 | pause(); |
---|
925 | kill TeXaligned, TeXbrack; |
---|
926 | // -------------- typesetting for matrices ---------- |
---|
927 | matrix J = jacob(G); |
---|
928 | texobj("",J); |
---|
929 | pause(); |
---|
930 | // -------------- typesetting for intmats ---------- |
---|
931 | intmat m[3][4] = 9,2,4,5,2,5,-2,4,-6,10,-1,2,7; |
---|
932 | texobj("",m); |
---|
933 | echo=0; |
---|
934 | // |
---|
935 | // --- restore global variables if previously defined --- |
---|
936 | if (defined(Teali)){int TeXaligned=Teali; export TeXaligned; kill Teali;} |
---|
937 | if (defined(Tebra)){string TeXbrack=Tebra; export TeXbrack; kill Tebra;} |
---|
938 | } |
---|
939 | /////////////////////////////////////////////////////////////////////////////// |
---|
940 | |
---|
941 | proc texproc(string fname,string pname) |
---|
942 | "USAGE: texproc(fname,pname); fname,pname strings |
---|
943 | ASSUME: @code{`pname`} is a procedure. |
---|
944 | RETURN: if @code{fname=\"\"}: string, the proc @code{`pname`} in a verbatim |
---|
945 | environment in LaTeX-typesetting;@* |
---|
946 | otherwise: append this string to the file @code{<fname>}, and |
---|
947 | return nothing. |
---|
948 | NOTE: preceding \">>\" are deleted in @code{fname}, and suffix \".tex\" |
---|
949 | (if not given) is added to @code{fname}.@* |
---|
950 | @code{texproc} cannot be applied to itself correctly. |
---|
951 | EXAMPLE: example texproc; shows an example |
---|
952 | " |
---|
953 | { |
---|
954 | int i,j=1,1; |
---|
955 | string p,s,t; |
---|
956 | |
---|
957 | if (defined(pname)) |
---|
958 | { if (typeof(`pname`)=="proc") |
---|
959 | { p = string(`pname`); |
---|
960 | s = "\\begin{verbatim}" + newline; |
---|
961 | s = s + "proc " + pname + "("; |
---|
962 | i = find(p,"parameter"); // collecting the parameters |
---|
963 | while(i) |
---|
964 | { j=find(p,";",i); |
---|
965 | t = p[i+10,j-i-10]; |
---|
966 | if(i>1){s = s + ",";}; |
---|
967 | s = s + t; |
---|
968 | i = find(p,"parameter",j); |
---|
969 | } |
---|
970 | s = s + ")" + newline; |
---|
971 | j++; // skip one for the newline |
---|
972 | i = find(p,"return();",j); |
---|
973 | if (!(i)) |
---|
974 | { i = find(p,";RETURN();",j); } // j kann hier weg |
---|
975 | s = s + "{" + p[j,i-j-2] + "}" + newline; |
---|
976 | s = s + "\\end{verbatim}" + newline; |
---|
977 | } |
---|
978 | } |
---|
979 | else |
---|
980 | { print(" --Error: No such proc defined"); |
---|
981 | return(); |
---|
982 | } |
---|
983 | if(size(fname)) |
---|
984 | { i=1; |
---|
985 | while (fname[i]==">"){i++;} |
---|
986 | fname = fname[i,size(fname)-i+1]; |
---|
987 | if (size(fname)>=4) // check if filename is ending with ".tex" |
---|
988 | { if(fname[size(fname)-3,4]!=".tex") {fname = fname +".tex"; } |
---|
989 | } |
---|
990 | else {fname = fname + ".tex";} |
---|
991 | write(fname,s); |
---|
992 | } |
---|
993 | else{return(s);} |
---|
994 | } |
---|
995 | example |
---|
996 | { "EXAMPLE:"; echo=2; |
---|
997 | proc exp(int i,int j,list #) |
---|
998 | { string s; |
---|
999 | |
---|
1000 | if (size(#)) |
---|
1001 | { |
---|
1002 | for(i;i<=j;i++) |
---|
1003 | { s = s + string(j) + string(#); } |
---|
1004 | } |
---|
1005 | return(s); |
---|
1006 | } |
---|
1007 | export exp; |
---|
1008 | texproc("","exp"); |
---|
1009 | kill exp; |
---|
1010 | } |
---|
1011 | |
---|
1012 | /////////////////////////////////////////////////////////////////////////////// |
---|
1013 | |
---|
1014 | static proc tvar(intvec v) |
---|
1015 | { |
---|
1016 | int i,j,ldots; |
---|
1017 | string s; |
---|
1018 | j = 1; |
---|
1019 | s = texpoly("",var(1)); |
---|
1020 | |
---|
1021 | if (nvars(basering)==1) { return(s);} |
---|
1022 | if (nvars(basering)==2) { return(s + "," + texpoly("",var(2)));} |
---|
1023 | if (size(v)==1 and v[1] == 1) |
---|
1024 | {return(s + ",\\ldots,"+ texpoly("",var(nvars(basering))));} |
---|
1025 | if (v[1]==1 and size(v) >1) {j++;} |
---|
1026 | for(i=2;i<nvars(basering);i++) |
---|
1027 | { if (i<v[j] and !(ldots)) |
---|
1028 | { s = s + ",\\ldots"; |
---|
1029 | ldots =1; |
---|
1030 | } |
---|
1031 | if (i== v[j]) |
---|
1032 | { s = s + "," + texpoly("",var(i)); |
---|
1033 | ldots =0; |
---|
1034 | if (j< size(v)) {j++;} |
---|
1035 | } |
---|
1036 | } |
---|
1037 | if (v[j]<nvars(basering)-1) { s = s + ",\\ldots";} |
---|
1038 | return(s + "," + texpoly("",var(nvars(basering)))); |
---|
1039 | } |
---|
1040 | |
---|
1041 | /////////////////////////////////////////////////////////////////////////////// |
---|
1042 | |
---|
1043 | proc texring(string fname, def r, list #) |
---|
1044 | "USAGE: texring(fname, r[,L]); fname string, r ring, L list |
---|
1045 | RETURN: if @code{fname=\"\"}: string, the ring in TeX-typesetting;@* |
---|
1046 | otherwise: append this string to the file @code{<fname>} and |
---|
1047 | return nothing. |
---|
1048 | NOTE: preceding \">>\" are deleted and suffix \".tex\" (if not given) |
---|
1049 | is added to @code{fname}.@* |
---|
1050 | The optional list L is assumed to be a list of strings which control, |
---|
1051 | e.g., the symbol for the field of coefficients.@* |
---|
1052 | For more details call @code{texdemo();} (generates a LaTeX2e |
---|
1053 | file called @code{texlibdemo.tex} which explains all features of |
---|
1054 | @code{texring}). |
---|
1055 | EXAMPLE: example texring; shows an example |
---|
1056 | " |
---|
1057 | { |
---|
1058 | int i,galT,flag,mipo,nopar,Dollars,TB,TA; |
---|
1059 | string ob,cb,cf,en,s,t,savebrack; //opening bracket, closing br, coef.field |
---|
1060 | intvec v; |
---|
1061 | |
---|
1062 | setring r; |
---|
1063 | if (!(defined(NoDollars))){ Dollars = 1; int NoDollars; export NoDollars;} |
---|
1064 | ob,cb = "[","]"; |
---|
1065 | if (find(ordstr(r),"s")) { ob,cb="[[","]]";} |
---|
1066 | if(char(r)==0){cf="\\Q";} |
---|
1067 | if(charstr(r)=="real"){cf="\\R";} |
---|
1068 | if(char(r)==prime(char(r))){cf="\\Z_{"+string(char(r))+"}";} |
---|
1069 | if(char(r)>0) |
---|
1070 | { i = find(charstr(r),","); |
---|
1071 | if(i) |
---|
1072 | { t= charstr(r)[1,i-1]; |
---|
1073 | galT = (t <> string(char(r))); |
---|
1074 | if (galT) { cf = "\\F_{"+ t + "}";} |
---|
1075 | } |
---|
1076 | } // all other cases are cover already by char(r)=? prime(char) |
---|
1077 | |
---|
1078 | if (size(#)) |
---|
1079 | { if (typeof(#[1])=="list") { # = #[1];} |
---|
1080 | } |
---|
1081 | for (i=1;i<=size(#);i++) |
---|
1082 | { flag =0; |
---|
1083 | if(typeof(#[i])=="string") |
---|
1084 | { |
---|
1085 | if(#[i][1]=="^" or #[i][1]=="_"){en=en+#[i];flag = 1;} |
---|
1086 | if(#[i]=="mipo"){mipo=1; flag = 1;} |
---|
1087 | if(#[i]=="{"){ob,cb="\\{","\\}";flag=1;} |
---|
1088 | if(#[i]=="{{"){ob,cb="\\{\\{","\\}\\}";flag=1;} |
---|
1089 | if(#[i]=="["){ob,cb="[","]";flag=1;} |
---|
1090 | if(#[i]=="[["){ob,cb="[[","]]";flag=1;} |
---|
1091 | if(#[i]=="<"){ob,cb="<",">";flag=1;} |
---|
1092 | if(#[i]=="<<"){ob,cb="{\\ll}","{\\gg}";flag=1;} |
---|
1093 | if(#[i]=="C"){cf="\\C";flag=1;} |
---|
1094 | if(#[i]=="Q"){cf="\\Q";flag=1;} |
---|
1095 | if((#[i]=="k" or #[i]=="K" or #[i]=="R") and !(galT)) |
---|
1096 | {cf=#[i]; flag=1; nopar=1;} |
---|
1097 | if (flag!=1) {cf = #[i];} // for all the cases not covered here e.g Z_(p) |
---|
1098 | } // or Q[i] |
---|
1099 | |
---|
1100 | if ((typeof(#[i])=="intvec") or |
---|
1101 | (typeof(#[i])=="int")){v=#[i];} |
---|
1102 | } |
---|
1103 | s = cf; |
---|
1104 | // now the parameters |
---|
1105 | // t; |
---|
1106 | if(npars(r) and ((t==string(char(r))) or char(r)==0) and !(nopar)) |
---|
1107 | { |
---|
1108 | s = s + "("; // !! mit ideal !! |
---|
1109 | for(i=1;i<npars(r);i++) {s = s + texpoly("",par(i)) + ",";} |
---|
1110 | s = s + texpoly("",par(npars(r))) + ")"; |
---|
1111 | } // parameters done |
---|
1112 | if (!(galT) and mipo and minpoly!=0) |
---|
1113 | { s = s + "/" + list(parsp(string(minpoly),0))[1];} |
---|
1114 | s = s + ob; |
---|
1115 | if (v!=0 and nvars(r)>3) |
---|
1116 | { s = s + tvar(v);} |
---|
1117 | else |
---|
1118 | { s = s + texpoly("",maxideal(1),","); } |
---|
1119 | s = s + cb + en; |
---|
1120 | |
---|
1121 | if (typeof(r)=="qring") |
---|
1122 | { ideal @I = ideal(r); |
---|
1123 | if (defined(TeXbrack)) |
---|
1124 | { |
---|
1125 | TB =1; savebrack = TeXbrack; |
---|
1126 | if (TeXbrack!= "<" and TeXbrack!="(") { TeXbrack = "<";} |
---|
1127 | } |
---|
1128 | TA = defined(TeXaligned); |
---|
1129 | if (!(TA)) { int TeXaligned; export TeXaligned; } |
---|
1130 | t = texobj("",@I); |
---|
1131 | // @I; |
---|
1132 | // t; |
---|
1133 | if (TB) { TeXbrack = savebrack;} |
---|
1134 | if (!(TA)) { kill TeXaligned;} |
---|
1135 | s = s + "/" + t; |
---|
1136 | } |
---|
1137 | |
---|
1138 | if (Dollars) |
---|
1139 | { kill NoDollars; |
---|
1140 | s = "$" + s + "$"; |
---|
1141 | } |
---|
1142 | if (size(fname)) |
---|
1143 | { i=1; |
---|
1144 | while (fname[i]==">"){i++;} |
---|
1145 | fname = fname[i,size(fname)-i+1]; |
---|
1146 | |
---|
1147 | if (size(fname)>=4) // check if filename is ending with ".tex" |
---|
1148 | { if(fname[size(fname)-3,4]!=".tex") {fname = fname +".tex"; } |
---|
1149 | } |
---|
1150 | else {fname = fname + ".tex";} |
---|
1151 | write(fname,s); |
---|
1152 | } |
---|
1153 | else{return(s);} |
---|
1154 | } |
---|
1155 | example |
---|
1156 | { "EXAMPLE:"; echo=2; |
---|
1157 | ring r0 = 0,(x,y),dp; // char = 0, polynomial ordering |
---|
1158 | texring("",r0); |
---|
1159 | // |
---|
1160 | ring r7 =7,(x(0..2)),ds; // char = 7, local ordering |
---|
1161 | texring("",r7); |
---|
1162 | // |
---|
1163 | ring r1 = 0,(x1,x2,y1,y2),wp(1,2,3,4); |
---|
1164 | texring("",r1); |
---|
1165 | // |
---|
1166 | ring rr = real,(x),dp; // real numbers |
---|
1167 | texring("",rr); |
---|
1168 | // |
---|
1169 | pause(); |
---|
1170 | |
---|
1171 | ring rabc =(0,t1,t2,t3),(x,y),dp; // ring with parameters |
---|
1172 | texring("",rabc); |
---|
1173 | // |
---|
1174 | ring ralg = (7,a),(x1,x2),ds; // algebraic extension |
---|
1175 | minpoly = a2-a+3; |
---|
1176 | texring("",ralg); |
---|
1177 | texring("",ralg,"mipo"); |
---|
1178 | // |
---|
1179 | ring r49=(49,a),x,dp; // Galois field |
---|
1180 | texring("",r49); |
---|
1181 | // |
---|
1182 | setring r0; // quotient ring |
---|
1183 | ideal i = x2-y3; |
---|
1184 | qring q = std(i); |
---|
1185 | texring("",q); |
---|
1186 | // |
---|
1187 | pause(); |
---|
1188 | // ------------------ additional features ------------------- |
---|
1189 | ring r9 =0,(x(0..9)),ds; |
---|
1190 | texring("",r9,1); |
---|
1191 | texring("",r9,"C","{","^G"); |
---|
1192 | // |
---|
1193 | ring rxy = 0,(x(1..5),y(1..6)),ds; |
---|
1194 | intvec v = 5,6; |
---|
1195 | texring("",rxy,v); |
---|
1196 | } |
---|
1197 | |
---|
1198 | /////////////////////////////////////////////////////////////////////////////// |
---|
1199 | |
---|
1200 | proc rmx(string fname) |
---|
1201 | "USAGE: rmx(fname); fname string |
---|
1202 | RETURN: nothing; removes the @code{.log} and @code{.aux} files associated to |
---|
1203 | the LaTeX file <fname>.@* |
---|
1204 | NOTE: If @code{fname} ends by @code{\".dvi\"} or @code{\".tex\"}, the |
---|
1205 | @code{.dvi} or @code{.tex} file will be deleted, too. |
---|
1206 | EXAMPLE: example rmx; shows an example |
---|
1207 | " |
---|
1208 | { |
---|
1209 | int i,suffix= 1,0; |
---|
1210 | int retval; |
---|
1211 | |
---|
1212 | if (size(fname)) |
---|
1213 | { |
---|
1214 | while (fname[i]==">"){i++;} |
---|
1215 | fname = fname[i,size(fname)-i+1]; |
---|
1216 | if (size(fname)>4) |
---|
1217 | { if (fname[size(fname)-3,4]==".tex") { suffix = 2;} |
---|
1218 | if (fname[size(fname)-3,4]==".dvi") { suffix = 1; } |
---|
1219 | if (suffix) { fname = fname[1,size(fname)-4]; } |
---|
1220 | } |
---|
1221 | retval = system("sh","rm " + fname + ".aux"); |
---|
1222 | retval = system("sh","rm " + fname + ".log"); |
---|
1223 | if (suffix==2) {retval = system("sh","/bin/rm -i " + fname +".tex");} |
---|
1224 | if (suffix>=1) {retval = system("sh","/bin/rm -i " + fname +".dvi");} |
---|
1225 | } |
---|
1226 | else |
---|
1227 | {" -- Need a filename "; |
---|
1228 | return(); |
---|
1229 | } |
---|
1230 | } |
---|
1231 | example |
---|
1232 | { "EXAMPLE:"; echo =2; |
---|
1233 | ring r; |
---|
1234 | poly f = x+y+z; |
---|
1235 | opentex("exp001"); // defaulted latex2e document |
---|
1236 | texobj("exp001","A polynom",f); |
---|
1237 | closetex("exp001"); |
---|
1238 | tex("exp001"); |
---|
1239 | rmx("exp001"); // removes aux and log file of exp001 |
---|
1240 | echo = 0; |
---|
1241 | pause("remaining files will be deleted after pressing <RETURN>"); |
---|
1242 | echo = 2; |
---|
1243 | system("sh","rm exp001.*"); |
---|
1244 | } |
---|
1245 | /////////////////////////////////////////////////////////////////////////////// |
---|
1246 | |
---|
1247 | proc xdvi(string fname, list #) |
---|
1248 | "USAGE: xdvi(fname[,style]); fname,style = string |
---|
1249 | RETURN: nothing; displays dvi-file fname.dvi with previewer xdvi |
---|
1250 | NOTE: ending .dvi may miss in fname |
---|
1251 | style overwrites the default setting xdvi |
---|
1252 | EXAMPLE: example xdvi; shows an example |
---|
1253 | " |
---|
1254 | { |
---|
1255 | int i=1; |
---|
1256 | int retval; |
---|
1257 | string default = "xdvi"; |
---|
1258 | |
---|
1259 | if (size(#)) {default = string(#[1]);} |
---|
1260 | |
---|
1261 | if (size(fname)) |
---|
1262 | { |
---|
1263 | while (fname[i]==">") {i++;} |
---|
1264 | fname = fname[i,size(fname)-i+1]; |
---|
1265 | |
---|
1266 | if (size(fname)>=4) |
---|
1267 | { if(fname[size(fname)-3,4]==".tex") {fname = fname[1,size(fname)-4];}} |
---|
1268 | |
---|
1269 | "calling ",default, " for :",fname,newline; |
---|
1270 | |
---|
1271 | if (default=="latex2e") |
---|
1272 | { |
---|
1273 | retval = system("sh","latex " + fname +" &"); |
---|
1274 | } |
---|
1275 | else |
---|
1276 | { |
---|
1277 | retval = system("sh",default + " " + fname +" &"); |
---|
1278 | } |
---|
1279 | } |
---|
1280 | else |
---|
1281 | { " -- Need a filename "; |
---|
1282 | return(); |
---|
1283 | } |
---|
1284 | } |
---|
1285 | example |
---|
1286 | { "EXAMPLE:"; echo = 2; |
---|
1287 | intmat m[3][4] = 9,2,4,5,2,5,-2,4,-6,10,-1,2,7; |
---|
1288 | opentex("exp001"); |
---|
1289 | texobj("exp001","An intmat: ",m); |
---|
1290 | closetex("exp001"); |
---|
1291 | tex("exp001"); |
---|
1292 | xdvi("exp001"); |
---|
1293 | echo = 0; |
---|
1294 | pause("the created files will be deleted after pressing <RETURN>"); |
---|
1295 | echo = 2; |
---|
1296 | system("sh","rm exp001.*"); |
---|
1297 | } |
---|
1298 | |
---|
1299 | /////////////////////////////////////////////////////////////////////////////// |
---|
1300 | |
---|
1301 | static proc parsr(string s) // parse real |
---|
1302 | { |
---|
1303 | string t; |
---|
1304 | if (s==" Inf") { return("\\infty",3);} |
---|
1305 | if (s==" -Inf") { return("\\-infty",6);} |
---|
1306 | if (s[7]=="-"){t ="-";} |
---|
1307 | if (s[8]<>"0"){t = t + s[8];} |
---|
1308 | if (s[9]<>"0" or s[8]<>"0"){t = t + s[9];} |
---|
1309 | if (size(t)) |
---|
1310 | { if (t=="1") {return(s[1,5]+"*10",21);} |
---|
1311 | if (size(t)>1) {return(s[1,5]+"*10^{"+t+"}",21+2*size(t));} |
---|
1312 | else {return(s[1,5]+"*10^"+t,23);} |
---|
1313 | } |
---|
1314 | else |
---|
1315 | { |
---|
1316 | return(s[1,5],12); |
---|
1317 | } |
---|
1318 | } |
---|
1319 | |
---|
1320 | static proc parsg(string s) // parse Galois field |
---|
1321 | { |
---|
1322 | int i,j = 1,1; |
---|
1323 | string t; |
---|
1324 | if (short) |
---|
1325 | { |
---|
1326 | t =s[1]; |
---|
1327 | if(size(s)>1) {return(t+"^{" + s[2,size(s)-1] + "}",3+2*(size(s)-1));} |
---|
1328 | else{return(t,5);} |
---|
1329 | } |
---|
1330 | else |
---|
1331 | { |
---|
1332 | return(parselong(s+"!")); |
---|
1333 | } |
---|
1334 | } |
---|
1335 | /////////////////////////////////////////////////////////////////////////////// |
---|
1336 | |
---|
1337 | proc texpoly(string fname,def p,list #) |
---|
1338 | "USAGE: texpoly(fname,p); fname string, p poly |
---|
1339 | RETURN: if @code{fname=\"\"}: string, the poly p in LaTeX-typesetting;@* |
---|
1340 | otherwise: append this string to the file @code{<fname>}, and |
---|
1341 | return nothing. |
---|
1342 | NOTE: preceding \">>\" are deleted in @code{fname}, and suffix \".tex\" |
---|
1343 | (if not given) is added to @code{fname}. |
---|
1344 | EXAMPLE: example texpoly; shows an example |
---|
1345 | " |
---|
1346 | { |
---|
1347 | def @r = basering; |
---|
1348 | |
---|
1349 | poly f,monom; |
---|
1350 | ideal I; |
---|
1351 | number cfm; |
---|
1352 | string sign,cfmt,pt,s,bg,t,monomt, lnbreak; |
---|
1353 | string sep = newline; |
---|
1354 | int i,b,b2,n, msz,linesz, count,k; |
---|
1355 | int realT, parT, galT; |
---|
1356 | int C = 2 + defined(TeXdisplay); |
---|
1357 | |
---|
1358 | string notvalid = "intvec intmat vector matrix module map "; |
---|
1359 | |
---|
1360 | if (typeof(p) == "int") { return(p);} |
---|
1361 | if (typeof(p) == "ring" or typeof(p) == "qring") |
---|
1362 | { " -- Call texring instead "; return();} |
---|
1363 | if (find(notvalid,typeof(p))) |
---|
1364 | { " -- Call texobj instead "; return();} |
---|
1365 | if (typeof(p) == "map") |
---|
1366 | { " -- Call texmap instead "; return();} |
---|
1367 | if (typeof(p) == "proc") |
---|
1368 | { " -- Call texmap instead "; return();} |
---|
1369 | if (typeof(p) == "link" or typeof(p) == "list" or typeof(p) == "resolution") |
---|
1370 | { " -- Object can not translated into tex "; return();} |
---|
1371 | |
---|
1372 | if (!(defined(TeXdisplay))){ lnbreak = "\\\\[2mm]" + newline;} |
---|
1373 | else { lnbreak = "\\\\" + newline;} |
---|
1374 | |
---|
1375 | |
---|
1376 | if (defined(TeXdisplay)) { bg = "& ";} |
---|
1377 | if (!(defined(TeXwidth))) { int TeXwidth = -1; export TeXwidth;} |
---|
1378 | |
---|
1379 | |
---|
1380 | // -- Type check |
---|
1381 | |
---|
1382 | if (typeof(p)=="string") |
---|
1383 | { if(defined(`p`)) |
---|
1384 | { pt = p + " = "; |
---|
1385 | p = `p`; |
---|
1386 | } |
---|
1387 | } |
---|
1388 | if (typeof(p)=="poly" or typeof(p)=="number") {I = p;} |
---|
1389 | |
---|
1390 | if (typeof(p)=="ideal") |
---|
1391 | { I = p; |
---|
1392 | if(size(#)){ sep = #[1];} |
---|
1393 | } |
---|
1394 | |
---|
1395 | if (I==0) |
---|
1396 | { if (!(defined(NoDollars))){return("$0$");} |
---|
1397 | else {return("0");} |
---|
1398 | } |
---|
1399 | |
---|
1400 | // -- Type check ende |
---|
1401 | |
---|
1402 | //--------------------- |
---|
1403 | |
---|
1404 | |
---|
1405 | //------- set flags: -------------------------------------------------------- |
---|
1406 | |
---|
1407 | if (size(#)) |
---|
1408 | { if (typeof(#[1])=="int") { linesz = #[1];} |
---|
1409 | // if (typeof(#[1])=="string") { linesz = #[1];} |
---|
1410 | } |
---|
1411 | |
---|
1412 | parT = npars(@r); |
---|
1413 | realT = (charstr(@r)=="real"); |
---|
1414 | i = find(charstr(@r),","); |
---|
1415 | if (i) |
---|
1416 | { t = charstr(@r)[1,i-1]; |
---|
1417 | galT = (t <> string(char(@r))); // the char is not the same as the ... |
---|
1418 | } |
---|
1419 | i = 0; |
---|
1420 | |
---|
1421 | //------- parse the polynomial |
---|
1422 | pt = bg; |
---|
1423 | |
---|
1424 | for(k=1;k<=size(matrix(I));k++) |
---|
1425 | { i = 0; linesz = 0; count =0; |
---|
1426 | sign =""; |
---|
1427 | f = I[k]; |
---|
1428 | if (f==0) { pt = pt + "0";} |
---|
1429 | while(f<>0) |
---|
1430 | { count++; msz = 0; |
---|
1431 | |
---|
1432 | // ------ tex the coefficient |
---|
1433 | monom = lead(f); |
---|
1434 | f = f - monom; |
---|
1435 | cfm = leadcoef(monom); |
---|
1436 | if (cfm*1 != 0) { monom = monom/cfm;} // the normalized monom |
---|
1437 | s = string(monom) + "!"; // add a terminating sign |
---|
1438 | cfmt = ""; |
---|
1439 | |
---|
1440 | if (defined(TeXreplace)) { short =0;} // this is essential |
---|
1441 | cfmt = string(cfm); |
---|
1442 | if (size(cfmt)>1) // check if sign is < 0 |
---|
1443 | { if (cfmt[2]=="-") { cfm = (-1) *cfm; sign = "-";}} |
---|
1444 | if (cfmt[1] == "-") { cfm = (-1) * cfm; sign = "-";} |
---|
1445 | if (cfm!=1 or monom==1) {cfmt = string(cfm);} |
---|
1446 | else {cfmt="";} |
---|
1447 | |
---|
1448 | if (defined(TeXwidth) and TeXwidth > 0 and TeXwidth <9 and count> TeXwidth) |
---|
1449 | { pt = pt + sign + "\\ldots"; break;} |
---|
1450 | // ---------------------------------------- linesz ?? |
---|
1451 | |
---|
1452 | if (size(cfmt)) // parse the coefficient |
---|
1453 | { |
---|
1454 | monomt = cfmt; // (already a good choice for integers) |
---|
1455 | msz = 3*size(cfmt); |
---|
1456 | |
---|
1457 | if(realT) { monomt,msz = parsr(cfmt);} |
---|
1458 | if (galT) { monomt,msz = parsg(cfmt);} |
---|
1459 | b = find(cfmt,")/("); // look if fraction |
---|
1460 | b2 = find(cfmt,"/"); |
---|
1461 | if (b) {b++;} |
---|
1462 | n = size(cfmt); |
---|
1463 | if (!(parT) and !(realT) and !(galT)) |
---|
1464 | { if( !(b2) or defined(TeXnofrac)) |
---|
1465 | { monomt = cfmt; msz = 3*size(monomt);} |
---|
1466 | else |
---|
1467 | { monomt = "\\frac{" + cfmt[1,b2-1] + "}{" + cfmt[b2+1,n-b2] + "}"; |
---|
1468 | if (n-2*b2>0) {msz = C*(n-b2);} |
---|
1469 | else {msz = C*b2;} |
---|
1470 | } |
---|
1471 | } |
---|
1472 | if (parT and !(galT)) |
---|
1473 | { monomt,msz = parsp(cfmt,b);} |
---|
1474 | } |
---|
1475 | |
---|
1476 | // -- now parse the monom |
---|
1477 | if (monom <> 1) |
---|
1478 | { i = 1; |
---|
1479 | if(short) |
---|
1480 | { while(s[i]<>"!") |
---|
1481 | { monomt = monomt + s[i]; i++; |
---|
1482 | b = i; |
---|
1483 | msz = msz + 3; // it was a single lettered var |
---|
1484 | while(s[i]!="!" and s[i]>="0" and s[i]<="9"){i++;} |
---|
1485 | if (i-b) |
---|
1486 | { monomt = monomt + "^{" + s[b,i-b] + "}"; |
---|
1487 | msz = msz + 2*(i-b); |
---|
1488 | } |
---|
1489 | } |
---|
1490 | } |
---|
1491 | else // not short |
---|
1492 | { t,i = parselong(s); |
---|
1493 | monomt = monomt + t; |
---|
1494 | msz = msz + i; |
---|
1495 | } |
---|
1496 | } |
---|
1497 | |
---|
1498 | msz = msz + 6*size(sign); // Wieso mal 6 ?? |
---|
1499 | // string(msz) + " ," + string(linesz) + " " + string(cfm*monom); |
---|
1500 | |
---|
1501 | if (TeXwidth > 10 and (linesz + msz > 3*TeXwidth) and linesz) |
---|
1502 | { pt = pt + lnbreak + bg; |
---|
1503 | linesz = msz; |
---|
1504 | } |
---|
1505 | else { linesz = linesz + msz; } // 3 for sign |
---|
1506 | pt = pt + sign + monomt; |
---|
1507 | sign = "+"; |
---|
1508 | monomt = ""; |
---|
1509 | } |
---|
1510 | |
---|
1511 | if (k<size(matrix(I))){ pt = pt + sep;} |
---|
1512 | } |
---|
1513 | |
---|
1514 | if (TeXwidth==0 and typeof(p)=="poly"){ pt = pt + "= 0";} |
---|
1515 | if (not(defined(NoDollars))) { pt = "$"+pt+"$";} |
---|
1516 | |
---|
1517 | if (size(fname)) |
---|
1518 | { i=1; |
---|
1519 | while (fname[i]==">"){i++;} |
---|
1520 | fname = fname[i,size(fname)-i+1]; |
---|
1521 | |
---|
1522 | if (size(fname)>=4) // check if filename is ending with ".tex" |
---|
1523 | { if(fname[size(fname)-3,4]!=".tex") {fname = fname +".tex"; } |
---|
1524 | } |
---|
1525 | else {fname = fname + ".tex";} |
---|
1526 | write(fname,pt); |
---|
1527 | } |
---|
1528 | else {return(pt);} |
---|
1529 | } |
---|
1530 | example |
---|
1531 | { "EXAMPLE:"; echo =2; |
---|
1532 | ring r0=0,(x,y,z),dp; |
---|
1533 | poly f = -1x^2 + 2; |
---|
1534 | texpoly("",f); |
---|
1535 | ring rr= real,(x,y,z),dp; |
---|
1536 | texpoly("",2x2y23z); |
---|
1537 | ring r7= 7,(x,y,z),dp; |
---|
1538 | poly f = 2x2y23z; |
---|
1539 | texpoly("",f); |
---|
1540 | ring rab =(0,a,b),(x,y,z),dp; |
---|
1541 | poly f = (-2a2 +b3 -2)/a * x2y4z5 + (a2+1)*x + a+1; |
---|
1542 | f; |
---|
1543 | texpoly("",f); |
---|
1544 | } |
---|
1545 | |
---|
1546 | static proc parsp(string cfmt, int b) |
---|
1547 | { string mt, nom,denom; |
---|
1548 | int fl1,fl2,sz1,sz2,msz; |
---|
1549 | |
---|
1550 | if (!(b)) |
---|
1551 | { mt,fl1 = parst(cfmt,0); msz = size(cfmt)-2; |
---|
1552 | if (fl1) { mt = "(" + mt + ")"; msz = msz +1; } |
---|
1553 | } |
---|
1554 | else |
---|
1555 | { nom,fl1 = parst(cfmt[1,b-1],1); |
---|
1556 | denom,fl2 = parst(cfmt[b+1,size(cfmt)-b],1); |
---|
1557 | if (defined(TeXnofrac)) |
---|
1558 | { if(fl1) { nom = "(" + nom + ")"; sz1++;} |
---|
1559 | if(fl2) {denom = "(" + denom + ")"; sz2++;} |
---|
1560 | mt = nom+ "/"+ denom; msz = sz1+sz2 +1; |
---|
1561 | } |
---|
1562 | else |
---|
1563 | { mt = "\\frac{" + nom + "}{" + denom + "}"; |
---|
1564 | if (sz1-sz2) { msz = 5*sz1;} |
---|
1565 | else {msz = 5*sz2;} |
---|
1566 | } |
---|
1567 | } |
---|
1568 | return(mt,msz); |
---|
1569 | } |
---|
1570 | example |
---|
1571 | {"EXAMPLE:"; echo =2; |
---|
1572 | ring r=(0,a,b),x,dp; |
---|
1573 | int i; |
---|
1574 | poly f = (a2b12 + 23a2 -b13-1)/(a2+2b -1); |
---|
1575 | f; |
---|
1576 | string s; |
---|
1577 | s= string(f); |
---|
1578 | i = find(s,")/("); |
---|
1579 | parsp(s,i); |
---|
1580 | } |
---|
1581 | |
---|
1582 | static proc parst(string s,int sec) // parse parameter |
---|
1583 | // sec parameter to see if in parsp a fraction follows |
---|
1584 | { int i,j =1,-1; |
---|
1585 | int b,k,jj,mz; // begin and end |
---|
1586 | int saveshort=short; |
---|
1587 | string t,c,vn,nom,denom,sg; |
---|
1588 | if (s[1]=="(") { s = s[2,size(s)-2]; } |
---|
1589 | s = s + "!"; |
---|
1590 | |
---|
1591 | if(defined(TeXreplace)){ short =0;} // only then replacing works correctly |
---|
1592 | if (short) |
---|
1593 | { while(s[i]<>"!") |
---|
1594 | { b=i; j++; |
---|
1595 | while(s[i]>="0" and s[i]<="9" or (s[i]=="+" or s[i]=="-") and s[i]!="!") |
---|
1596 | {i++;} // scan the number |
---|
1597 | t =s[b,i-b]; |
---|
1598 | // if (t=="-1" and s[i]!="!" and s[i]!="-" and s[i]!="+"){t = "-";} |
---|
1599 | if (t=="-1" and (s[i]<="0" or s[i]>="9") and s[i]!= "/" and s[i]!="!") |
---|
1600 | { |
---|
1601 | t = "-";} |
---|
1602 | if (s[i]=="/") |
---|
1603 | { i++; |
---|
1604 | sg = ""; |
---|
1605 | if (t[1]=="+" or t[1]=="-") |
---|
1606 | { nom = t[2,size(t)-1]; |
---|
1607 | sg = t[1]; |
---|
1608 | } |
---|
1609 | else { nom = t;} |
---|
1610 | b =i; |
---|
1611 | while(s[i]>="0" and s[i]<="9") {i++;} |
---|
1612 | denom = s[b,i-b]; |
---|
1613 | if (!(sec) and (!(defined(TeXaligned)))) |
---|
1614 | { t = sg + "\\frac{" + nom + "}{" + denom + "}";} |
---|
1615 | else |
---|
1616 | { t = sg + "(" + nom + "/" + denom + ")"; |
---|
1617 | } |
---|
1618 | } |
---|
1619 | c = c + t; |
---|
1620 | if(s[i]!="!"){c = c + s[i]; i++;} // the parameter |
---|
1621 | b=i; |
---|
1622 | while(s[i]>="0" and s[i]<="9") |
---|
1623 | {i++;} //the exponent |
---|
1624 | if(i-b){ c = c + "^{" + s[b,i-b]+"}";} |
---|
1625 | } |
---|
1626 | } |
---|
1627 | else // if not short .... |
---|
1628 | { while (s[i] <> "!") |
---|
1629 | { b=i; j++; |
---|
1630 | while(s[i]=="-" or s[i]=="+" or (s[i]>="0" and s[i]<="9")){i++;} |
---|
1631 | t = s[b,i-b]; |
---|
1632 | if (t=="-1" and s[i]=="*" ) {t="-";} |
---|
1633 | if (s[i]=="/") |
---|
1634 | { i++; |
---|
1635 | sg = ""; |
---|
1636 | if (t[1]=="+" or t[1]=="-") |
---|
1637 | { nom = t[2,size(t)-1]; |
---|
1638 | sg = t[1]; |
---|
1639 | } |
---|
1640 | else { nom = t;} |
---|
1641 | b =i; |
---|
1642 | while(s[i]>="0" and s[i]<="9") {i++;} |
---|
1643 | denom = s[b,i-b]; |
---|
1644 | if (!(sec) and (!(defined(TeXaligned)))) |
---|
1645 | { t = sg + "\\frac{" + nom + "}{" + denom + "}";} |
---|
1646 | else |
---|
1647 | { t = sg + "(" + nom + "/" + denom + ")"; |
---|
1648 | } |
---|
1649 | } |
---|
1650 | c = c+t; t=""; |
---|
1651 | if (s[i]=="*"){i++;} |
---|
1652 | b=i; |
---|
1653 | while(s[i]!="+" and s[i]!="-" and s[i]!="!") //pass a monom |
---|
1654 | { // start with letters |
---|
1655 | // alternativ: |
---|
1656 | while((s[i]>="a" and s[i]<="z") or (s[i]>="A" and s[i]<="Z")){i++;} |
---|
1657 | k = i-b; |
---|
1658 | vn = s[b,k]; |
---|
1659 | if (defined(TeXreplace)) |
---|
1660 | { for (jj=1; jj<= size(TeXreplace);jj++) |
---|
1661 | { if (vn == TeXreplace[jj][1]) |
---|
1662 | {vn = TeXreplace[jj][2]; k=1; |
---|
1663 | if (s[i]=="*") {vn = vn + " ";} |
---|
1664 | break;} //suppose replacing by a single sign |
---|
1665 | } |
---|
1666 | } |
---|
1667 | t = t + vn; |
---|
1668 | mz = mz + 10*k; |
---|
1669 | if (s[i]=="_" or s[i]=="(") { i++;} // the index is coming |
---|
1670 | b = i; |
---|
1671 | while(s[i]>="0" and s[i]<="9"){ i++;} |
---|
1672 | k = i-b; |
---|
1673 | if (k){ t = t + "_{" +s[b,k] + "}";} |
---|
1674 | if(s[i]==")") {i++;} |
---|
1675 | if (s[i]=="^") |
---|
1676 | { i++; b = i; |
---|
1677 | while(s[i]>="0" and s[i]<="9"){ i++;} // for neg. expon. |
---|
1678 | if (b-i) { t = t + "^{" + s[b,i-b] + "}";} |
---|
1679 | } |
---|
1680 | if (i-b > k) { mz = mz + 5*(i-b);} |
---|
1681 | else {mz = mz + 5*k;} |
---|
1682 | if (s[i]=="*"){i++;} |
---|
1683 | b=i; |
---|
1684 | } |
---|
1685 | c =c+t; |
---|
1686 | } |
---|
1687 | } |
---|
1688 | short = saveshort; |
---|
1689 | return(c,j); |
---|
1690 | } |
---|
1691 | example |
---|
1692 | { "EXAMPLE:"; echo =2; |
---|
1693 | ring r=(0,a,b),x,dp; |
---|
1694 | poly f = (a2b12 + 23a2 -b13-1); |
---|
1695 | f; |
---|
1696 | parst(string(f)); |
---|
1697 | |
---|
1698 | f =(-a +4b2 -2); |
---|
1699 | f; |
---|
1700 | parst(string(f)); |
---|
1701 | |
---|
1702 | f = a23; |
---|
1703 | f; |
---|
1704 | parst(string(f)); |
---|
1705 | f = 2a12b3 -4ab15 +2a4b12 -2; |
---|
1706 | short =0; |
---|
1707 | f; |
---|
1708 | parst(string(f)); |
---|
1709 | ring r2=(0,a1,b1),x,dp; |
---|
1710 | poly f = 2*a1^12*b1^3 -4*a1*b1^15 +2*a1^4*b1^12 -2; |
---|
1711 | f; |
---|
1712 | parst(string(f)); |
---|
1713 | } |
---|
1714 | |
---|
1715 | |
---|
1716 | static proc parselong(string s) |
---|
1717 | { |
---|
1718 | int i,j,k,b,mz; |
---|
1719 | string t,vn; // varname |
---|
1720 | |
---|
1721 | // "s=" + s; |
---|
1722 | i = 1; |
---|
1723 | while (s[i] <> "!") |
---|
1724 | { b=i; |
---|
1725 | |
---|
1726 | // -- scan now the letter ... |
---|
1727 | |
---|
1728 | // while(s[i]!="!" and ) |
---|
1729 | |
---|
1730 | // alternativ: |
---|
1731 | while((s[i]>="a" and s[i]<="z") or (s[i]>="A" and s[i]<="Z")) |
---|
1732 | { i++;} |
---|
1733 | // s[i]; i; |
---|
1734 | k = i-b; |
---|
1735 | vn = s[b,k]; |
---|
1736 | |
---|
1737 | if (defined(TeXreplace)) |
---|
1738 | { for (j=1; j<= size(TeXreplace);j++) |
---|
1739 | { if (vn == TeXreplace[j][1]) |
---|
1740 | {vn = TeXreplace[j][2]; k=1; |
---|
1741 | if (s[i]=="*") {vn = vn + " ";} |
---|
1742 | break;} //suppose replacing by a single sign |
---|
1743 | } |
---|
1744 | } |
---|
1745 | t = t + vn; |
---|
1746 | mz = mz + 10*k; |
---|
1747 | if (s[i]=="_" or s[i]=="(") { i++;} // the index is coming |
---|
1748 | b = i; |
---|
1749 | while(s[i]>="0" and s[i]<="9"){ i++;} |
---|
1750 | j = i-b; |
---|
1751 | if (j){ t = t + "_{" +s[b,j] + "}";} |
---|
1752 | if(s[i]==")") {i++;} |
---|
1753 | if (s[i]=="^") |
---|
1754 | { i++; b = i; |
---|
1755 | while(s[i]>="0" and s[i]<="9" or s[i]=="-") |
---|
1756 | { i++;} // for neg. expon. |
---|
1757 | if (b-i) { t = t + "^{" + s[b,i-b] + "}";} |
---|
1758 | } |
---|
1759 | if (i-b > j) { mz = mz + 5*(i-b);} |
---|
1760 | else {mz = mz + 5*j;} |
---|
1761 | if (s[i]=="*"){i++;} |
---|
1762 | } |
---|
1763 | return(t,mz); |
---|
1764 | } |
---|
1765 | example |
---|
1766 | { "EXAMPLE:"; echo =2; |
---|
1767 | ring r =(49,a),x,dp; |
---|
1768 | number f = a13; |
---|
1769 | parsg(string(f)); |
---|
1770 | list TeXreplace; export TeXreplace; |
---|
1771 | TeXreplace[1] = list("b","\\beta"); |
---|
1772 | TeXreplace[2] = list("a","\\alpha"); |
---|
1773 | TeXreplace[3] = list("c","\\gamma"); |
---|
1774 | parselong(string(f)+"!"); |
---|
1775 | } |
---|
1776 | /////////////////////////////////////////////////////////////////////////////// |
---|
1777 | |
---|
1778 | |
---|
1779 | static proc tktex (def d) |
---|
1780 | { |
---|
1781 | // calls appropriate proc from latex lib |
---|
1782 | |
---|
1783 | string typeofd =typeof(d); |
---|
1784 | if (typeofd=="int" or typeofd=="string" or typeofd=="resolution" or typeofd=="map" or typeofd =="list"){ return(d);} |
---|
1785 | |
---|
1786 | if (typeofd=="intvec" or typeofd == "intmat" or typeofd =="vector" or |
---|
1787 | typeofd=="matrix" or typeofd == "module") { return(texobj("",d));} |
---|
1788 | if (typeofd=="ring" or typeofd=="qring") { return(texring("",d));} |
---|
1789 | if (typeofd =="ideal") { return(texobj("",d));} |
---|
1790 | if (typeofd=="number" or typeofd=="poly" or typeofd=="ideal") |
---|
1791 | { return(texpoly("",d));} |
---|
1792 | if (typeofd=="link") {return(d);} |
---|
1793 | |
---|
1794 | } |
---|
1795 | |
---|
1796 | /////////////////////////////////////////////////////////////////////////////// |
---|
1797 | static proc splt(string s) |
---|
1798 | { int n,i= size(s),1; |
---|
1799 | int p; |
---|
1800 | string t; |
---|
1801 | |
---|
1802 | while(n-i+1 >pagewidth) |
---|
1803 | { p = find(s,newline,i); |
---|
1804 | if (p and (p-i)<pagewidth) |
---|
1805 | { t = t + s[i,p]; |
---|
1806 | i = i + p; |
---|
1807 | } |
---|
1808 | else |
---|
1809 | { |
---|
1810 | t = t+ s[i,pagewidth] + newline; |
---|
1811 | i = i + pagewidth; |
---|
1812 | } |
---|
1813 | } |
---|
1814 | if (n) { t= t + s[i,n-i+1];} |
---|
1815 | return(t); |
---|
1816 | } |
---|
1817 | |
---|
1818 | ///////////////////////////// PART0 ////////////////////////////////////////// |
---|
1819 | static proc part0(string fname) |
---|
1820 | { |
---|
1821 | int texdemopart =0; |
---|
1822 | export texdemopart; |
---|
1823 | |
---|
1824 | |
---|
1825 | // Singular script for generating tldemo.tex |
---|
1826 | |
---|
1827 | string nl = newline; |
---|
1828 | string nl2 = newline + newline; |
---|
1829 | string lb = "\\\\"; |
---|
1830 | string bv = "\\begin{verbatim}" + newline ; |
---|
1831 | string ev = "\\end{verbatim}" ; |
---|
1832 | |
---|
1833 | // "generating part0 of " + fname + nl; |
---|
1834 | |
---|
1835 | opentex(fname); |
---|
1836 | |
---|
1837 | write(fname,"\\newcommand{\\Line}{\\rule{\\textwidth}{0.25mm}\\\\[5mm]}"); |
---|
1838 | |
---|
1839 | write(fname,"\\centerline{\\large \\bf Demo file for latex.lib 2.0}"); |
---|
1840 | write(fname,"\\vspace{1cm}"); |
---|
1841 | |
---|
1842 | //-- |
---|
1843 | |
---|
1844 | write(fname,"\\section{Introduction}"); |
---|
1845 | write(fname,"The procedures in \\verb|latex.lib| translate the output of |
---|
1846 | {\\sc Singular} into \\LaTeX \\ text. |
---|
1847 | This document illustrates the functionality of the library."+"\\\\" + nl); |
---|
1848 | write(fname,"\\begin{tabular}{ll}" + nl + |
---|
1849 | "LIBRARY: {\\tt latex.lib} & PROCEDURES FOR TYPESETTING SINGULAR" + |
---|
1850 | "\\\\" + nl + |
---|
1851 | " & OBJECTS IN LATEX2E"+ |
---|
1852 | "\\\\" + nl + |
---|
1853 | "{\\tt closetex(fnm);} & writes closing line for \\LaTeX-document"+ |
---|
1854 | "\\\\" + nl + |
---|
1855 | "{\\tt opentex(fnm);} & writes header for \\LaTeX-file fnm"+ |
---|
1856 | "\\\\" + nl + |
---|
1857 | "{\\tt tex(fnm);} & calls \\LaTeX2e for file fnm"+ |
---|
1858 | "\\\\" + nl + |
---|
1859 | "{\\tt texdemo([n]);} & produces a file explaining the features of this lib"+ |
---|
1860 | "\\\\" + nl + |
---|
1861 | "{\\tt texfactorize(fnm,f);} & creates string in \\LaTeX-format for |
---|
1862 | factors of poly f"+ "\\\\" + nl + |
---|
1863 | "{\\tt texmap(fnm,m,r1,r2);} & creates string in \\LaTeX-format for |
---|
1864 | map m:r1$\\rightarrow$r2"+ "\\\\" + nl + |
---|
1865 | "{\\tt texname(fnm,s);} & creates string in \\LaTeX-format for |
---|
1866 | identifier"+ "\\\\" + nl + |
---|
1867 | "{\\tt texobj(l);} & creates string in \\LaTeX-format for |
---|
1868 | any (basic) type"+ "\\\\" + nl + |
---|
1869 | "{\\tt texpoly(f,n[,l]);} & creates string in \\LaTeX-format for poly"+ |
---|
1870 | "\\\\" + nl + |
---|
1871 | "{\\tt texproc(fnm,p);} & creates string in \\LaTeX-format of |
---|
1872 | text from proc p"+ "\\\\" + nl + |
---|
1873 | "{\\tt texring(fnm,r[,l]);} & creates string in \\LaTeX-lformat for |
---|
1874 | ring/qring"+ "\\\\" + nl + |
---|
1875 | "{\\tt rmx(s);} & removes .aux and .log files of \\LaTeX-files"+ |
---|
1876 | "\\\\" + nl + |
---|
1877 | "{\\tt xdvi(s);} & calls xdvi for dvi-files"+ |
---|
1878 | "\\\\" + nl + |
---|
1879 | " \\end{tabular} " + nl2 + "\\vspace{0.2cm}" + nl2 + |
---|
1880 | "(parameters in square brackets {\\tt [ ]} are optional)"+ |
---|
1881 | "\\\\" + nl2 + "\\vspace{0.2cm}" + nl2 + |
---|
1882 | "The global variables {\\tt TeXwidth}, {\\tt TeXnofrac}, {\\tt |
---|
1883 | TeXbrack}, {\\tt TeXproj}, {\\tt TeXaligned}, {\\tt TeXreplace}, {\\tt |
---|
1884 | NoDollars} are used to control the typesetting: " |
---|
1885 | ); |
---|
1886 | |
---|
1887 | write(fname, |
---|
1888 | bv + |
---|
1889 | " |
---|
1890 | TeXwidth (int) -1, 0, 1..9, >9: controls breaking of long polynomials |
---|
1891 | TeXnofrac (int) flag: write 1/2 instead of \\frac{1}{2} |
---|
1892 | TeXbrack (string) \"{\", \"(\", \"<\", \"|\", empty string: |
---|
1893 | controls brackets around ideals and matrices |
---|
1894 | TeXproj (int) flag: write \":\" instead of \",\" in vectors |
---|
1895 | TeXaligned (int) flag: write mappings (and ideals) aligned |
---|
1896 | TeXreplace (list) list entries = 2 strings: replacing symbols |
---|
1897 | NoDollars (int) flag: suppresses surrounding $ signs |
---|
1898 | |
---|
1899 | " + |
---|
1900 | ev); |
---|
1901 | write(fname,"Notice that none of these global variables are defined when |
---|
1902 | loading \\verb|latex.lib|. A flag variable is set as soon as it is defined."); |
---|
1903 | |
---|
1904 | |
---|
1905 | //% The procs and |
---|
1906 | //% the global variables |
---|
1907 | |
---|
1908 | //----------------------- opentex ----------------------------- |
---|
1909 | write(fname,"\\section{Opening a \\LaTeX\\ file}"); |
---|
1910 | write(fname,"In order to create a \\LaTeX\\ document and write a standard |
---|
1911 | header into it, use the following command."+ |
---|
1912 | bv+ |
---|
1913 | "> string fname = \"" + fname + "\";" + nl + |
---|
1914 | "> texopen(fname);" + |
---|
1915 | ev + nl); |
---|
1916 | |
---|
1917 | write(fname,"The variable \\verb|fname| is always the first argument when |
---|
1918 | calling one of the procedures of \\verb|latex.lib|. If this string is the |
---|
1919 | empty string, then the output in not written into a file but displayed on |
---|
1920 | the screen."); |
---|
1921 | |
---|
1922 | //% opentex, defaulted to latex, possibly extension are ... and |
---|
1923 | //% ``own'' |
---|
1924 | |
---|
1925 | |
---|
1926 | pagewidth = 65; |
---|
1927 | int TeXwidth = 100; export TeXwidth; |
---|
1928 | // "part 0 generated " + nl; |
---|
1929 | } //part0 |
---|
1930 | |
---|
1931 | |
---|
1932 | ///////////////////////////// PART1 ////////////////////////////////////////// |
---|
1933 | |
---|
1934 | |
---|
1935 | static proc part1(string fname) |
---|
1936 | { |
---|
1937 | |
---|
1938 | int st = defined(texdemopart); |
---|
1939 | string nl = newline; |
---|
1940 | string nl2 = newline + newline; |
---|
1941 | string lb = "\\\\"; |
---|
1942 | string bv = "\\begin{verbatim}" + newline ; |
---|
1943 | string ev = "\\end{verbatim}" ; |
---|
1944 | |
---|
1945 | if (not(st) or texdemopart>=1) |
---|
1946 | { print(" Call part0 first"); |
---|
1947 | return(); |
---|
1948 | } |
---|
1949 | else { texdemopart=1; } |
---|
1950 | |
---|
1951 | //"Continuing part1 of " + fname + nl; |
---|
1952 | |
---|
1953 | write(fname, |
---|
1954 | "\\section{Rings, polynomials and ideals}"+nl2); |
---|
1955 | |
---|
1956 | // -1a------ a ring in char 0, short varnames and poly. ordering ---------- |
---|
1957 | write(fname, |
---|
1958 | " A ring in characteristic 0 with short names of variables and polynomial |
---|
1959 | ordering." +nl); |
---|
1960 | ring r0=0,(x,y,z),dp; |
---|
1961 | poly g=-x2y+2y13z+1; |
---|
1962 | write(fname, |
---|
1963 | bv + |
---|
1964 | "> ring r0=0,(x,y,z),dp;" +nl+ |
---|
1965 | "> texring(fname,r0);" + |
---|
1966 | ev); |
---|
1967 | texring(fname,r0); |
---|
1968 | write(fname,nl2); |
---|
1969 | write(fname, |
---|
1970 | bv + |
---|
1971 | "> poly g=-x2y+2y13z+1; g;" + nl + |
---|
1972 | "> texpoly(fname,g);" +nl + |
---|
1973 | ev); |
---|
1974 | texpoly(fname,g); |
---|
1975 | write(fname,"\\\\"+nl2); |
---|
1976 | |
---|
1977 | // write(fname,"\\Line"); |
---|
1978 | |
---|
1979 | // -1b------ still in the same ring, a poly with rational coefs -------- |
---|
1980 | write(fname, |
---|
1981 | " A polynomial with rational coefficients. |
---|
1982 | " +nl); |
---|
1983 | write(fname, |
---|
1984 | bv + |
---|
1985 | "> texpoly(fname,g/280);" +nl + |
---|
1986 | ev |
---|
1987 | ); |
---|
1988 | texpoly(fname,g/280); |
---|
1989 | kill r0; |
---|
1990 | |
---|
1991 | write(fname,"\\\\"+nl2); |
---|
1992 | write(fname,"\\Line"); |
---|
1993 | // -2-------- a ring in char 7, indexed varnames and series ordering ---------- |
---|
1994 | write(fname, |
---|
1995 | " A ring in characteristic 7 with indexed names of variables and local |
---|
1996 | ordering." +nl); |
---|
1997 | ring r1=7,(x1,x2,x3,x4),Ds; |
---|
1998 | poly g=-2*x1+x4-1; |
---|
1999 | write(fname, |
---|
2000 | bv + |
---|
2001 | "> ring r1=7,(x1,x2,x3,x4),Ds;" +nl + |
---|
2002 | "> texring(fname,r1);" +nl + |
---|
2003 | ev); |
---|
2004 | texring(fname,r1); |
---|
2005 | write(fname,lb); |
---|
2006 | |
---|
2007 | write(fname, bv + |
---|
2008 | "> poly g=-2*x1+x4-1; g;" +nl + |
---|
2009 | "> texpoly(fname,g);" +nl + |
---|
2010 | ev); |
---|
2011 | |
---|
2012 | texpoly(fname,g); |
---|
2013 | |
---|
2014 | write(fname,lb); |
---|
2015 | write(fname,"\\Line"); |
---|
2016 | |
---|
2017 | // -3-------- a ring in char 0, indexed varnames and local ordering ---------- |
---|
2018 | write(fname, |
---|
2019 | " A ring in characteristic 0 with indexed names of variables and local |
---|
2020 | ordering. |
---|
2021 | " +nl); |
---|
2022 | ring r2=0,(x(1..5),y(1..2)),(ds(5),ls(2)); |
---|
2023 | poly g=-y(1)^3*x(5) +y(1)*x(2); |
---|
2024 | write(fname, |
---|
2025 | bv + |
---|
2026 | "> ring r2=0,(x(1..5),y(1..2)),(ds(5),ls(2));" + nl + |
---|
2027 | "> texring(fname,r2);" +nl + |
---|
2028 | ev); |
---|
2029 | texring(fname,r2); |
---|
2030 | |
---|
2031 | write(fname, |
---|
2032 | bv + |
---|
2033 | "> poly g=-y(1)^3*x(5)+y(1)*x(2); g;" +nl+ |
---|
2034 | string(g) + nl + |
---|
2035 | "> texpoly(fname,g);" +nl + |
---|
2036 | ev |
---|
2037 | ); |
---|
2038 | texpoly(fname,g); |
---|
2039 | write(fname,lb); |
---|
2040 | |
---|
2041 | write(fname,"\\Line"); |
---|
2042 | |
---|
2043 | // -4-------- a ring in char 0, indexed varnames and weighted ordering ------ |
---|
2044 | write(fname, |
---|
2045 | " A ring in characteristic 0 with indexed names of variables and weighted |
---|
2046 | ordering." +nl); |
---|
2047 | ring r3=0,(x_1,x_2,x_3),wp(3,2,1); |
---|
2048 | poly g=-x_1*x_2+2*x_2*x_3+x_1*x_3; |
---|
2049 | write(fname, |
---|
2050 | bv + |
---|
2051 | "> ring r3=0,(x_1,x_2,x_3),wp(3,2,1);" +nl+ |
---|
2052 | "> texring(fname,r3);" +nl + |
---|
2053 | ev); |
---|
2054 | texring(fname,r3); |
---|
2055 | write(fname, |
---|
2056 | bv + |
---|
2057 | "> poly g=-x_1*x_2+2*x_2*x_3+x_1*x_3; g;" +nl+ |
---|
2058 | string(g) + nl + |
---|
2059 | "> texpoly(fname,g);" +nl + |
---|
2060 | ev |
---|
2061 | ); |
---|
2062 | texpoly(fname,g); write(fname,lb); |
---|
2063 | |
---|
2064 | write(fname,"\\Line"); |
---|
2065 | |
---|
2066 | // -5-------- a ring with real coeff and matrix ordering ------------------- |
---|
2067 | write(fname, |
---|
2068 | " A ring with real coefficients and matrix ordering. |
---|
2069 | " +nl); |
---|
2070 | ring rr=real,(x,y),M(1,2,3,4); |
---|
2071 | poly g =-1.2e-10*x2+y+1; |
---|
2072 | write(fname, |
---|
2073 | bv + |
---|
2074 | "> ring rr=real,(x,y),M(1,2,3,4);"+nl+ |
---|
2075 | "> texring(fname,rr);"+nl+ |
---|
2076 | ev); |
---|
2077 | texring(fname,rr); |
---|
2078 | |
---|
2079 | write(fname, |
---|
2080 | bv + |
---|
2081 | "> poly g=-1.2e-10*x2+y+1; g;"+nl+ |
---|
2082 | string(g) + nl + |
---|
2083 | "> texpoly(fname,g);" +nl + |
---|
2084 | ev); |
---|
2085 | texpoly(fname,g); write(fname,lb); |
---|
2086 | |
---|
2087 | write(fname,"\\Line"); |
---|
2088 | |
---|
2089 | // -6a-------- a ring in char 0, and indexed parameters --------- ---------- |
---|
2090 | write(fname, |
---|
2091 | " A ring in characteristic 0 and indexed parameters. |
---|
2092 | " +nl); |
---|
2093 | ring r0t=(0,s,t),(x,y),dp; |
---|
2094 | poly g=8*(-s+2t)/(st+t3)*x+t2*x-1; |
---|
2095 | write(fname, |
---|
2096 | bv + |
---|
2097 | "> ring r0t=(0,s,t),(x,y),dp;" +nl + |
---|
2098 | "> texring(fname,r0t);" +nl + |
---|
2099 | ev); |
---|
2100 | texring(fname,r0t); |
---|
2101 | write(fname, |
---|
2102 | bv + |
---|
2103 | "> poly g=8*(-s+2t)/(st+t3)*x+t2*x-1; g;"+nl+ |
---|
2104 | string(g) +nl + |
---|
2105 | "> texpoly(fname,g);" +nl + |
---|
2106 | ev); |
---|
2107 | texpoly(fname,g); write(fname,lb); |
---|
2108 | write(fname,"\\Line"); |
---|
2109 | |
---|
2110 | // -6b------- a ring in char 11003, and indexed parameters --------- ---------- |
---|
2111 | write(fname, |
---|
2112 | " A ring in characteristic 11 and indexed parameters. |
---|
2113 | " +nl); |
---|
2114 | ring rt=(11003,t1,t2,t3),(X,Y),dp; |
---|
2115 | poly g=8*(-t1+t2)/(t1+t3)*X+t2*Y-1; |
---|
2116 | write(fname, |
---|
2117 | bv + |
---|
2118 | "> ring rt=(11003,t1,t2,t3),(X,Y),dp;" +nl + |
---|
2119 | "> texring(fname,rt);" +nl+ |
---|
2120 | ev); |
---|
2121 | texring(fname,rt); |
---|
2122 | |
---|
2123 | write(fname, |
---|
2124 | bv + |
---|
2125 | "> poly g=8*(-t1+t2)/(t1+t3)*X+t2*Y-1; g;" + nl+ |
---|
2126 | string(g) +nl + |
---|
2127 | "> texpoly(fname,g);" +nl + |
---|
2128 | ev); |
---|
2129 | texpoly(fname,g); write(fname,lb); |
---|
2130 | |
---|
2131 | write(fname,"\\Line"); |
---|
2132 | |
---|
2133 | // -7-------- a ring over an algebraic extension in char 7 --------------- |
---|
2134 | write(fname, |
---|
2135 | " A ring over an algebraic extension in char 7. |
---|
2136 | " +nl); |
---|
2137 | |
---|
2138 | ring ralg = (7,a),x,dp; |
---|
2139 | minpoly = a2-a+3; |
---|
2140 | poly g = -(2a13+a)*x2+a2*x-a+1; |
---|
2141 | |
---|
2142 | write(fname, |
---|
2143 | bv + |
---|
2144 | "> ring ralg=(7,a),x,dp;" +nl + |
---|
2145 | "> minpoly=a2-a+3;" +nl + |
---|
2146 | "> texring(fname,ralg);" +nl+ |
---|
2147 | ev); |
---|
2148 | texring(fname,ralg); |
---|
2149 | |
---|
2150 | write(fname, |
---|
2151 | bv + |
---|
2152 | "> poly g=-(2a13+a)*x2+a2*x-a+1; g;"+nl+ |
---|
2153 | string(g) +nl + |
---|
2154 | "> texpoly(fname,g);" +nl + |
---|
2155 | ev |
---|
2156 | ); |
---|
2157 | texpoly(fname,g); write(fname,lb); |
---|
2158 | |
---|
2159 | write(fname,"\\Line"); |
---|
2160 | |
---|
2161 | // -8-------- the same ring a in 7 ralg, defined with gftables -- F_49 ------- |
---|
2162 | write(fname, |
---|
2163 | " A ring defined with \\verb|gftables|, the same as \\verb|ralg| before, but |
---|
2164 | with primitive element in the Galois field $\\F_{49}$." +nl); |
---|
2165 | ring r49 =(49,a),x,dp; |
---|
2166 | poly g=-(2a13+a)*x2+a2*x-a+1; |
---|
2167 | write(fname, |
---|
2168 | bv + |
---|
2169 | "> ring r49 =(49,a),x,dp;" +nl+ |
---|
2170 | "> texring(fname,r49);" +nl+ |
---|
2171 | ev); |
---|
2172 | texring(fname,r49); |
---|
2173 | |
---|
2174 | write(fname, |
---|
2175 | bv + |
---|
2176 | "> poly g=-(2a13+a)*x2+a2*x-a+1; g;" +nl+ |
---|
2177 | string(g) +nl + |
---|
2178 | "> texpoly(fname,g);" +nl + |
---|
2179 | ev); |
---|
2180 | texpoly(fname,g); write(fname,lb); |
---|
2181 | |
---|
2182 | write(fname,"\\Line"); |
---|
2183 | |
---|
2184 | // -9-------- a ring over the Gaussian numbers ---------- |
---|
2185 | write(fname, |
---|
2186 | " A ring over the Gaussian numbers. |
---|
2187 | " +nl); |
---|
2188 | ring ri=(0,i),(x,y,z),ls; |
---|
2189 | minpoly=i2+1; |
---|
2190 | poly g=-(i+1)*x+2i2y2+i+x; |
---|
2191 | write(fname, |
---|
2192 | bv + |
---|
2193 | "> ring ri=(0,i),(x,y,z),ls;" +nl + |
---|
2194 | "> minpoly=i2+1;" +nl + |
---|
2195 | "> texring(fname,ri);" +nl+ |
---|
2196 | ev); |
---|
2197 | texring(fname,ri); |
---|
2198 | |
---|
2199 | write(fname, |
---|
2200 | bv + |
---|
2201 | "> poly g=-(i+1)*x+2i2y2+i+x; g;" +nl+ |
---|
2202 | string(g) +nl + |
---|
2203 | "> texpoly(fname,g);" +nl + |
---|
2204 | ev |
---|
2205 | ); |
---|
2206 | texpoly(fname,g); write(fname,lb); |
---|
2207 | |
---|
2208 | write(fname,"\\Line"); |
---|
2209 | |
---|
2210 | // -10--------- a quotient ring performed from ---------- |
---|
2211 | write(fname, |
---|
2212 | " A quotient ring performed of \\verb|r0| by an ideal |
---|
2213 | " +nl); |
---|
2214 | ring r0=0,(x,y,z),dp; |
---|
2215 | ideal I = x2-y,y+z2, xy; |
---|
2216 | I = std(I); |
---|
2217 | string sI = string(I); |
---|
2218 | qring qr = I; |
---|
2219 | write(fname, |
---|
2220 | bv + |
---|
2221 | "> setring r0;" +nl + |
---|
2222 | "> ideal I=x2-y,y+z2, xy;" +nl + |
---|
2223 | "> I=std(I);" +nl + |
---|
2224 | "> string(I);" + nl + |
---|
2225 | splt(sI) + nl + |
---|
2226 | "> qring qr=I;"+ nl+ |
---|
2227 | "> texring(fname,qr);" + |
---|
2228 | ev |
---|
2229 | ); |
---|
2230 | texring(fname,qr); write(fname,lb); |
---|
2231 | |
---|
2232 | write(fname,"\\Line"); |
---|
2233 | |
---|
2234 | // ------------------------- Features for rings |
---|
2235 | |
---|
2236 | write(fname,"\\subsection{Features for rings}"); |
---|
2237 | |
---|
2238 | write(fname, |
---|
2239 | "In many cases it might be convenient to change the standard typesetting |
---|
2240 | of rings. This can be done by passing additional arguments to \\verb|texring|." |
---|
2241 | +nl); |
---|
2242 | |
---|
2243 | // changing the brackets |
---|
2244 | |
---|
2245 | write(fname,nl,"In order to change the displayed brackets one has to give |
---|
2246 | the desired ones as additional argument (accepted brackets are: \\verb|\"\{\"|, |
---|
2247 | \\verb|\"\{\{\"|,\\verb|\"[\"|,\\verb|\"[[\"|,\\verb|\"<\"|,\\verb|\"<<\"|)."); |
---|
2248 | |
---|
2249 | write(fname, |
---|
2250 | bv + |
---|
2251 | "> texring(fname,rr,\"{{\");" + nl + |
---|
2252 | ev |
---|
2253 | ); |
---|
2254 | |
---|
2255 | texring(fname,rr,"{{"); |
---|
2256 | |
---|
2257 | write(fname, |
---|
2258 | bv + |
---|
2259 | "> texring(fname,r2,\"[\");" + nl + |
---|
2260 | ev |
---|
2261 | ); |
---|
2262 | |
---|
2263 | texring(fname,r2,"["); |
---|
2264 | |
---|
2265 | write(fname,nl+"\\vspace{0.2cm}" + nl2); |
---|
2266 | |
---|
2267 | write(fname,"The brackets around the ideal in a quotient ring can be |
---|
2268 | changed by setting the global variable \\verb|TeXbrack| (see section |
---|
2269 | {\\tt Ideals}).",nl); |
---|
2270 | |
---|
2271 | |
---|
2272 | write(fname, |
---|
2273 | bv + |
---|
2274 | "> string TeXbrack = \"<\";" +nl + |
---|
2275 | "> texring(fname,qr);" +nl + |
---|
2276 | ev |
---|
2277 | ); |
---|
2278 | |
---|
2279 | string TeXbrack = "<"; export TeXbrack; |
---|
2280 | texring(fname,qr); |
---|
2281 | kill TeXbrack; |
---|
2282 | |
---|
2283 | write(fname, |
---|
2284 | bv + |
---|
2285 | "> kill TeXbrack;" + nl + |
---|
2286 | ev); |
---|
2287 | |
---|
2288 | |
---|
2289 | write(fname,nl2,"\\Line"); |
---|
2290 | |
---|
2291 | // changing the ground field |
---|
2292 | // ------------------------------------------------- |
---|
2293 | |
---|
2294 | write(fname, |
---|
2295 | "It is possible to display a ground field different from the |
---|
2296 | actual one by passing any letter in \\LaTeX \\ notation as additional |
---|
2297 | argument. Predefined values are \\verb|\"\\\\C\"|, \\verb|\"\\\\R\"|, |
---|
2298 | \\verb|\"k\"|, \\verb|\"K\"| and \\verb|\"R\"|."+nl+ |
---|
2299 | "If for example a ground field of characteristic 0 should be written as |
---|
2300 | $\\C$ instead of $\\Q$ use this as additonal argument.",nl); |
---|
2301 | |
---|
2302 | write(fname, |
---|
2303 | bv + |
---|
2304 | "> texring(fname,r3,\"\\\\C\");" + nl + |
---|
2305 | ev); |
---|
2306 | |
---|
2307 | texring(fname,r3,"\\C"); |
---|
2308 | write(fname,nl+ "\\vspace{0.2cm}" + nl2); |
---|
2309 | |
---|
2310 | write(fname,"The values \\verb|\"k\"|, \\verb|\"K\"|, \\verb|\"R\"| play a |
---|
2311 | special role when the ground field is an algebraic extension. In this case |
---|
2312 | the parameters will be omitted."); |
---|
2313 | |
---|
2314 | write(fname, |
---|
2315 | bv + |
---|
2316 | "> texring(fname,ralg,\"k\");" + nl + |
---|
2317 | ev |
---|
2318 | ); |
---|
2319 | |
---|
2320 | texring(fname, ralg,"k"); |
---|
2321 | write(fname,nl+"\\vspace{0.2cm}" + nl2); |
---|
2322 | |
---|
2323 | write(fname,"If an algebraic extension should be displayed together with |
---|
2324 | its minimal polynomial the optional parameter \\verb|mipo| has to be used."); |
---|
2325 | |
---|
2326 | write(fname, |
---|
2327 | bv + |
---|
2328 | "> texring(fname,ralg,\"mipo\");" + nl + |
---|
2329 | ev |
---|
2330 | ); |
---|
2331 | |
---|
2332 | texring(fname, ralg,"mipo"); |
---|
2333 | write(fname,nl,"\\Line"); |
---|
2334 | |
---|
2335 | // displaying only certain vars |
---|
2336 | |
---|
2337 | write(fname,"By default all variables of a ring will be displayed. It is |
---|
2338 | possible to print only certain variables with $\\ldots$ between |
---|
2339 | them. The positions of the variables which should be displayed have to be |
---|
2340 | passed to \\verb|texring| as an \\verb|intvec|."); |
---|
2341 | |
---|
2342 | write(fname, |
---|
2343 | bv + |
---|
2344 | "> intvec v=5,6; |
---|
2345 | > texring(fname,r2,v);" +nl + |
---|
2346 | ev |
---|
2347 | ); |
---|
2348 | |
---|
2349 | intvec v = 5,6; |
---|
2350 | texring(fname,r2,v); |
---|
2351 | kill v; |
---|
2352 | |
---|
2353 | write(fname, |
---|
2354 | bv + |
---|
2355 | "> kill v;" + nl + |
---|
2356 | ev |
---|
2357 | ); |
---|
2358 | |
---|
2359 | write(fname,nl+ "\\vspace{0.2cm}" + nl2); |
---|
2360 | |
---|
2361 | write(fname,"The first and the last variable will always be printed. |
---|
2362 | In order to print only these it is sufficient to give a 1 as third argument."); |
---|
2363 | |
---|
2364 | write(fname, |
---|
2365 | bv + |
---|
2366 | "> texring(fname,r1,1);" + nl + |
---|
2367 | ev |
---|
2368 | ); |
---|
2369 | texring(fname,r1,1); |
---|
2370 | |
---|
2371 | write(fname,nl2,"\\Line"); |
---|
2372 | |
---|
2373 | // invariant ring under a group action |
---|
2374 | |
---|
2375 | write(fname,"If you want for example to display a ring as the invariant ring |
---|
2376 | under a group, additional information starting with \\verb|^| may be added."); |
---|
2377 | |
---|
2378 | write(fname, |
---|
2379 | bv + |
---|
2380 | "> texring(fname,r0,\"^G\");" + nl + |
---|
2381 | ev |
---|
2382 | ); |
---|
2383 | |
---|
2384 | texring(fname, r0,"^G"); |
---|
2385 | write(fname,nl2,"\\Line"); |
---|
2386 | |
---|
2387 | // passing several optional arguments at once |
---|
2388 | |
---|
2389 | write(fname,"It is also possible to pass several of the arguments described |
---|
2390 | above at once (in any order)."); |
---|
2391 | |
---|
2392 | |
---|
2393 | write(fname, |
---|
2394 | bv + |
---|
2395 | "> texring(fname,r3,\"\\\\R\",\"{{\",\"^G\");" + nl + |
---|
2396 | ev |
---|
2397 | ); |
---|
2398 | |
---|
2399 | texring(fname, r3,"\\R","{{","^G"); |
---|
2400 | write(fname,nl2); |
---|
2401 | //"end part 1" + nl; |
---|
2402 | } |
---|
2403 | |
---|
2404 | |
---|
2405 | ///////////////////////////// PART2 ////////////////////////////////////////// |
---|
2406 | |
---|
2407 | |
---|
2408 | static proc part2(string fname) |
---|
2409 | { |
---|
2410 | |
---|
2411 | int st = defined(texdemopart); |
---|
2412 | string nl = newline; |
---|
2413 | string nl2 = newline + newline; |
---|
2414 | string lb = "\\\\"; |
---|
2415 | string bv = "\\begin{verbatim}" + newline ; |
---|
2416 | string ev = "\\end{verbatim}" ; |
---|
2417 | |
---|
2418 | if (not(st) or texdemopart>=2) |
---|
2419 | { print(" Call part1 first"); |
---|
2420 | return(); |
---|
2421 | } |
---|
2422 | else { texdemopart=2; } |
---|
2423 | |
---|
2424 | // "Continuing Part2 of " + fname + nl; |
---|
2425 | |
---|
2426 | //-------------------- texfactorize ------------------------------ |
---|
2427 | write(fname,"\\subsection{Factorized polynomials}"); |
---|
2428 | |
---|
2429 | write(fname,"The command \\verb|texfactorize| calls internally the |
---|
2430 | {\\sc Singular} command \\verb|factorize| and returns the product of the |
---|
2431 | irreducible factors. Note that, at the moment, it is not possible to pass |
---|
2432 | any optional arguments for \\verb|factorize| through \\verb|texfactorize|."); |
---|
2433 | |
---|
2434 | ring r0=0,(x,y,z),dp; |
---|
2435 | poly h=(x+1+y)^2*x3y*(2x-2y)*y12; |
---|
2436 | |
---|
2437 | write(fname, |
---|
2438 | bv + |
---|
2439 | "> setring r0;"+nl+ |
---|
2440 | "> poly h=(x+1+y)^2*x3y*(2x-2y)*y12;"+nl+ |
---|
2441 | "> h;" +nl+ |
---|
2442 | splt(string(h)) + nl + |
---|
2443 | "> texfactorize(fname,h);" + |
---|
2444 | ev); |
---|
2445 | texfactorize(fname,h); |
---|
2446 | |
---|
2447 | // setring ralg; |
---|
2448 | ring ralg = (7,a),x,dp; |
---|
2449 | minpoly = a2-a+3; |
---|
2450 | poly h = (a24x5+x3)*a2x6*(x+1)^2; |
---|
2451 | |
---|
2452 | write(fname, |
---|
2453 | bv + |
---|
2454 | "> setring ralg;"+nl+ |
---|
2455 | "> poly h=(a24x5+x3)*a2x6*(x+1)^2;" +nl+ |
---|
2456 | "> h;"+ nl + |
---|
2457 | splt(string(h)) + nl + |
---|
2458 | "> texfactorize(fname,h);"+ nl + |
---|
2459 | ev); |
---|
2460 | texfactorize(fname,h); |
---|
2461 | |
---|
2462 | //--------------------- features for polynomials ----------------- |
---|
2463 | write(fname,"\\subsection{Features for polynomials}"); |
---|
2464 | |
---|
2465 | // TeXreplace |
---|
2466 | // --------------------------------------------- |
---|
2467 | write(fname,"By setting the global variable \\verb|TeXreplace| it is possible |
---|
2468 | to define rules for replacing strings or variable names. |
---|
2469 | \\verb|TeXreplace| has to be a list of twoelemented lists where the first |
---|
2470 | entry is the text which should be replaced by the second entry. |
---|
2471 | This may be applied to replace names of variables, but is also used |
---|
2472 | when calling \\verb|texname| or \\verb|texmap|. Note that it |
---|
2473 | is necessary to write a double backslash \\verb|\\\\\| at the beginning of |
---|
2474 | a \\TeX \\ symbol." + lb+nl); |
---|
2475 | |
---|
2476 | write(fname,"Let us denote the primitive element of an algebraic extension |
---|
2477 | by $\\xi$."); |
---|
2478 | |
---|
2479 | list TeXreplace; export TeXreplace; |
---|
2480 | TeXreplace[1] = list("a","\\xi"); |
---|
2481 | // setring r49; |
---|
2482 | ring r49 =(49,a),x,dp; |
---|
2483 | poly g=-(2a13 +a)*x2+a2*x-a+1; |
---|
2484 | write(fname, |
---|
2485 | bv + |
---|
2486 | "> list TeXreplace;" +nl + |
---|
2487 | "> TeXreplace[1]=list(\"a\",\"\\\\xi\");" +nl+ |
---|
2488 | "> setring r49;" +nl+ |
---|
2489 | "> texpoly(fname,g);"+ nl + |
---|
2490 | ev); |
---|
2491 | |
---|
2492 | texpoly(fname,g); |
---|
2493 | |
---|
2494 | write(fname,nl+ "\\vspace{0.2cm}" + nl2); |
---|
2495 | write(fname,"Now let us write $\\lambda$ and $\\mu$ for deformation |
---|
2496 | parameters."); |
---|
2497 | TeXreplace[2]= list("s","\\lambda"); |
---|
2498 | TeXreplace[3]= list("t","\\mu"); |
---|
2499 | // setring(r0t); |
---|
2500 | ring r0t=(0,s,t),(x,y),dp; |
---|
2501 | poly g=8*(-s+2t)/(st+t3)*x+t2*x-1; |
---|
2502 | write(fname, |
---|
2503 | bv + |
---|
2504 | "> TeXreplace[2]=list(\"s\",\"\\\\lambda\");"+nl+ |
---|
2505 | "> TeXreplace[3]=list(\"t\",\"\\\\mu\");"+nl+ |
---|
2506 | "> setring(r0t);"+nl+ |
---|
2507 | "> texpoly(fname,g);"+ nl + |
---|
2508 | ev); |
---|
2509 | texpoly(fname,g); |
---|
2510 | |
---|
2511 | kill TeXreplace; |
---|
2512 | write(fname,nl+ "\\vspace{0.4cm}" + nl2); |
---|
2513 | write(fname,nl2+"Note that, if \\verb|TeXreplace| is defined, the translation |
---|
2514 | into \\LaTeX code runs significantly slower, because every polynomial will be |
---|
2515 | compiled in the \\verb|non short| mode."+ lb ); |
---|
2516 | |
---|
2517 | write(fname,nl,"\\Line"); |
---|
2518 | |
---|
2519 | //linebreaking TeXwdith |
---|
2520 | //----------------------------------------------------------------------- |
---|
2521 | write(fname,"The global variable \\verb|TeXwidth| controls the wrapping of |
---|
2522 | polynomials; possible values are:" + lb); |
---|
2523 | |
---|
2524 | write(fname, |
---|
2525 | "\\[ " + nl + |
---|
2526 | "\\text{TeXwidth} = ", |
---|
2527 | "\\begin{cases} ", |
---|
2528 | " -1 & \\text{no linebreaking} \\\\ ", |
---|
2529 | " 0 & \\text{print the polynomial as equation } f=0 \\\\ ", |
---|
2530 | " 1,\\dots,9 & \\text{the first n terms followed by the sign of the next |
---|
2531 | term} \\\\ ", |
---|
2532 | " > 9 & \\text{line break after terms of length n (see below)} ", |
---|
2533 | "\\end{cases}", |
---|
2534 | "\\]",nl); |
---|
2535 | |
---|
2536 | write(fname,"Note that the size of terms is calculated with certain |
---|
2537 | multiplicities.",nl); |
---|
2538 | |
---|
2539 | //---------------------------------------------------------- |
---|
2540 | |
---|
2541 | write(fname,"\\begin{itemize}",nl); |
---|
2542 | write(fname,"\\item",nl); |
---|
2543 | |
---|
2544 | write(fname, |
---|
2545 | bv + |
---|
2546 | "> TeXwidth=-1;"+nl+ |
---|
2547 | "> setring r0;"+nl+ |
---|
2548 | "> poly f=g^2;"+nl+ |
---|
2549 | "> texpoly(fname,f);" + nl + |
---|
2550 | ev); |
---|
2551 | |
---|
2552 | setring r0; |
---|
2553 | poly g=-x2y+2y13z+1; |
---|
2554 | poly f=g^2; |
---|
2555 | texpoly(fname,f); |
---|
2556 | |
---|
2557 | write(fname,"\\item",nl); |
---|
2558 | |
---|
2559 | write(fname, |
---|
2560 | bv + |
---|
2561 | "> TeXwidth=0;"+nl+ |
---|
2562 | "> texpoly(fname,f);"+nl+ |
---|
2563 | ev); |
---|
2564 | TeXwidth = 0; |
---|
2565 | texpoly(fname,f); |
---|
2566 | |
---|
2567 | write(fname,"\\item",nl); |
---|
2568 | |
---|
2569 | write(fname, |
---|
2570 | bv + |
---|
2571 | "> TeXwidth=2;"+nl+ |
---|
2572 | "> texpoly(fname,f);"+nl+ |
---|
2573 | ev); |
---|
2574 | TeXwidth=2; |
---|
2575 | texpoly(fname,f); |
---|
2576 | |
---|
2577 | write(fname,"\\item",nl); |
---|
2578 | |
---|
2579 | write(fname, |
---|
2580 | bv + |
---|
2581 | "> TeXwidth=20;"+nl+ |
---|
2582 | "> texpoly(fname,f);"+nl+ |
---|
2583 | ev); |
---|
2584 | TeXwidth=20; |
---|
2585 | texpoly(fname,f); |
---|
2586 | TeXwidth=-1; |
---|
2587 | |
---|
2588 | write(fname,"\\end{itemize}",nl); |
---|
2589 | |
---|
2590 | write(fname,nl2,"\\Line"); |
---|
2591 | |
---|
2592 | write(fname,"There are two possibilities to convert a polynomial into |
---|
2593 | \\LaTeX \\ code: either by using \\verb|texpoly| or by calling \\verb|texobj|. |
---|
2594 | The difference is that \\verb|texpoly| puts the polynomial in textmode |
---|
2595 | while \\verb|texobj| uses the display mode."+nl+ |
---|
2596 | "The following examples show the different outputs:"); |
---|
2597 | |
---|
2598 | write(fname, |
---|
2599 | bv + |
---|
2600 | "> setring r3; |
---|
2601 | > texpoly(fname,g/180);" + nl + |
---|
2602 | ev); |
---|
2603 | |
---|
2604 | // setring r3; |
---|
2605 | |
---|
2606 | ring r3=0,(x_1,x_2,x_3),wp(3,2,1); |
---|
2607 | poly g=-x_1*x_2+2*x_2*x_3+x_1*x_3; |
---|
2608 | texpoly(fname,g/180); |
---|
2609 | |
---|
2610 | write(fname, |
---|
2611 | bv + |
---|
2612 | "> texobj(fname,g/180); |
---|
2613 | " + nl + |
---|
2614 | ev); |
---|
2615 | |
---|
2616 | texobj(fname,g/180); |
---|
2617 | |
---|
2618 | //write(fname,"Some explanation how it works: if \\verb|texobj| is called for |
---|
2619 | //a polynomial, then it defines a global variable \\verb|TeXdisp| which forces |
---|
2620 | //\\verb|texpoly| to count fraction with space corresponding |
---|
2621 | //the displaymode."+lb,nl2); |
---|
2622 | //---------------------texobj for ideal --------------- |
---|
2623 | |
---|
2624 | write(fname,"\\subsection{Ideals}"); |
---|
2625 | write(fname,"By default, ideals are displayed as column vectors."); |
---|
2626 | |
---|
2627 | ring r; |
---|
2628 | ideal I=3xz5+x2y3-3z,7xz5+y3z+x-z,-xyz2+4yz+2x; |
---|
2629 | |
---|
2630 | write(fname, |
---|
2631 | bv + |
---|
2632 | "> ring r; // the default ring"+nl+ |
---|
2633 | "> ideal I=3xz5+x2y3-3z,7xz5+y3z+x-z,-xyz2+4yz+2x;"+nl+ |
---|
2634 | "> texobj(fname,I);" + nl + |
---|
2635 | ev); |
---|
2636 | |
---|
2637 | texobj(fname,I); |
---|
2638 | |
---|
2639 | write(fname,"\\Line"); |
---|
2640 | //---------------------------------------------------------------------- |
---|
2641 | write(fname,"If the global variable \\verb|Texaligned| is set then the ideal |
---|
2642 | is displayed as a row vector."); |
---|
2643 | |
---|
2644 | write(fname, |
---|
2645 | bv + |
---|
2646 | "> int TeXaligned; |
---|
2647 | > texobj(fname,I);" + nl + |
---|
2648 | ev); |
---|
2649 | |
---|
2650 | int TeXaligned; export TeXaligned; |
---|
2651 | texobj(fname,I); |
---|
2652 | |
---|
2653 | write(fname,"\\Line"); |
---|
2654 | //---------------------------------------------------------------------- |
---|
2655 | write(fname,"By setting the global variable \\verb|TeXbrack| it is possible |
---|
2656 | to change the brackets."); |
---|
2657 | |
---|
2658 | write(fname, |
---|
2659 | bv + |
---|
2660 | "> string TeXbrack=\"<\";"+nl+ |
---|
2661 | "> texobj(fname,I);"+nl+ |
---|
2662 | ev); |
---|
2663 | |
---|
2664 | string TeXbrack="<"; export TeXbrack; |
---|
2665 | texobj(fname,I); |
---|
2666 | |
---|
2667 | write(fname, |
---|
2668 | bv + |
---|
2669 | "> kill TeXbrack, TeXaligned;" + nl + |
---|
2670 | ev); |
---|
2671 | |
---|
2672 | kill TeXbrack,TeXaligned; |
---|
2673 | write(fname,"\\Line"); |
---|
2674 | //---------------------------------------------------------------------- |
---|
2675 | write(fname, |
---|
2676 | " If \\verb|TeXwidth| is 0, an ideal is displayed as a system of |
---|
2677 | equations."); |
---|
2678 | |
---|
2679 | // ------------- a linear equation system |
---|
2680 | |
---|
2681 | ring r5=0,x(1..5),dp; |
---|
2682 | ideal I=-x(1)+2*x(3)+x(5), x(2)-x(4)+2*x(5)-1, 8*x(1)+x(4)+2; |
---|
2683 | TeXwidth=0; |
---|
2684 | |
---|
2685 | write(fname, |
---|
2686 | bv + |
---|
2687 | "> ring r5=0,x(1..5),dp;"+nl+ |
---|
2688 | "> ideal I=-x(1)+2*x(3)+x(5), x(2)-x(4)+2*x(5)-1, 8*x(1)+x(4)+2;"+nl+ |
---|
2689 | "> TeXwidth=0;"+nl+ |
---|
2690 | "> texobj(fname,I);" +nl+ |
---|
2691 | ev); |
---|
2692 | |
---|
2693 | texobj(fname,I); |
---|
2694 | |
---|
2695 | setring r; |
---|
2696 | ideal J=4x4y21+z25y7-y2,x3+y2,y2-z4; |
---|
2697 | |
---|
2698 | write(fname, |
---|
2699 | bv + |
---|
2700 | "> setring r;"+nl+ |
---|
2701 | "> ideal J=4x4y21+z25y7-y2,x3+y2,y2-z4;"+nl+ |
---|
2702 | "> texobj(fname,J);" +nl+ |
---|
2703 | ev |
---|
2704 | ); |
---|
2705 | texobj(fname,J); |
---|
2706 | |
---|
2707 | write(fname,"\\Line"); |
---|
2708 | //----------------------------------------------------------------------- |
---|
2709 | write(fname,"Call the ideal by its name and it is printed as follows"); |
---|
2710 | |
---|
2711 | write(fname, |
---|
2712 | bv + |
---|
2713 | "> setring r; |
---|
2714 | > ideal I=3xz5+x2y3-3z,7xz5+y3z+x-z,-xyz2+4yz+2x; |
---|
2715 | > texobj(fname,\"I\");" + nl + |
---|
2716 | ev); |
---|
2717 | |
---|
2718 | setring r; export(I); |
---|
2719 | texobj(fname,"I"); |
---|
2720 | kill I,r; |
---|
2721 | //" end part 2 " + nl; |
---|
2722 | } |
---|
2723 | |
---|
2724 | ///////////////////////////// PART3 ////////////////////////////////////////// |
---|
2725 | |
---|
2726 | static proc part3(string fname) |
---|
2727 | { |
---|
2728 | int st=defined(texdemopart); |
---|
2729 | string nl=newline; |
---|
2730 | string nl2=newline + newline; |
---|
2731 | string lb="\\\\"; |
---|
2732 | string bv="\\begin{verbatim}" + newline ; |
---|
2733 | string ev="\\end{verbatim}" ; |
---|
2734 | |
---|
2735 | if (not(st) or st>=3) |
---|
2736 | { |
---|
2737 | print(" Call part2 first"); |
---|
2738 | return(); |
---|
2739 | } |
---|
2740 | else { texdemopart=3; } |
---|
2741 | |
---|
2742 | // " Continuing part 3 of " + fname + |
---|
2743 | // " : map,matrices,vectors,intvec,intmats,proc"; |
---|
2744 | |
---|
2745 | //---------------------- texmap ------------------------------ |
---|
2746 | write(fname,"\\section{Typeseting maps between rings}"); |
---|
2747 | write(fname,"By default, maps are displayed in the following way:"); |
---|
2748 | |
---|
2749 | write(fname, |
---|
2750 | bv + |
---|
2751 | "> ring r4=0,(x,y,z),dp;"+nl+ |
---|
2752 | "> ring r5=0,(u,v),dp;"+nl+ |
---|
2753 | "> map phi=r1,u2,uv -v,v2;"+nl+ |
---|
2754 | "> texmap(fname,phi,r4,r5);" + nl + |
---|
2755 | ev); |
---|
2756 | |
---|
2757 | ring @r4_h=0,(x,y,z),dp; |
---|
2758 | if(system("with","Namespaces")) { exportto(Current,@r4_h); } |
---|
2759 | else { export @r4_h; } |
---|
2760 | ring r5=0,(u,v),dp; |
---|
2761 | map @phi_h=@r4_h,u2,uv -v,v2; export @phi_h; |
---|
2762 | texmap(fname,@phi_h,@r4_h,r5); |
---|
2763 | |
---|
2764 | write(fname,"\\Line"); |
---|
2765 | //-------------------------------------------------------------------- |
---|
2766 | |
---|
2767 | write(fname,"If the global variable \\verb|TeXaligned| is set, then the |
---|
2768 | map is displayed in one line."); |
---|
2769 | |
---|
2770 | write(fname, |
---|
2771 | bv + |
---|
2772 | "> int TeXaligned;"+nl+ |
---|
2773 | "> texmap(fname,phi,r4,r5,\"\\\\C\");" + nl + |
---|
2774 | ev ); |
---|
2775 | |
---|
2776 | int TeXaligned; export TeXaligned; |
---|
2777 | texmap(fname,@phi_h,@r4_h,r5,"\\C"); |
---|
2778 | |
---|
2779 | write(fname,nl+"\\Line"); |
---|
2780 | //-------------------------------------------------------------------- |
---|
2781 | |
---|
2782 | write(fname,"It is possible to pass the same additional arguments to |
---|
2783 | \\verb|texmap| as to \\verb|texring| (see section {\\tt Rings}). This can |
---|
2784 | be done by calling \\verb|texmap| with two lists as additional parameters, |
---|
2785 | where the first list contains the optional parameters for the source and |
---|
2786 | the second one contains the parameters for the domain. Note that if only one |
---|
2787 | list is present then it is applied to both of the rings."); |
---|
2788 | |
---|
2789 | write(fname, |
---|
2790 | bv + |
---|
2791 | "> texmap(fname,phi,r4,r5,\"\\\\C\",\"{\");" + nl + |
---|
2792 | ev ); |
---|
2793 | texmap(fname,@phi_h,@r4_h,r5,"\\C","{"); |
---|
2794 | |
---|
2795 | write(fname,nl+ "\\vspace{0.2cm}" + nl); |
---|
2796 | write(fname,"The next example shows how to format the two rings in different |
---|
2797 | ways."); |
---|
2798 | |
---|
2799 | write(fname, |
---|
2800 | bv + |
---|
2801 | "> texmap(fname,phi,r4,r5,list(),list(\"{\"));"+nl+ |
---|
2802 | ev ); |
---|
2803 | |
---|
2804 | texmap(fname,@phi_h,@r4_h,r5,list(),list("{")); |
---|
2805 | |
---|
2806 | write(fname,nl+"\\Line"); |
---|
2807 | //-------------------------------------------------------------------- |
---|
2808 | |
---|
2809 | write(fname,"If the map is called by its name then \\verb|texmap| displays, |
---|
2810 | in addition, also the name of the map."); |
---|
2811 | |
---|
2812 | write(fname, |
---|
2813 | bv + |
---|
2814 | "> list TeXreplace;" +nl+ |
---|
2815 | "> TeXreplace[1]=list(\"phi\",\"\\\\phi\")" +nl+ |
---|
2816 | "> texmap(fname,\"phi\",r4,r5);" + nl + |
---|
2817 | ev); |
---|
2818 | |
---|
2819 | list TeXreplace; |
---|
2820 | TeXreplace[1]=list("@phi_h","\\phi"); |
---|
2821 | export TeXreplace; |
---|
2822 | texmap(fname,"@phi_h",@r4_h,r5); |
---|
2823 | kill @phi_h,@r4_h,r5,TeXreplace,TeXaligned; |
---|
2824 | |
---|
2825 | |
---|
2826 | write(fname, |
---|
2827 | bv + |
---|
2828 | "> kill phi,r4,r5,TeXreplace,TeXaligned;" + nl + |
---|
2829 | ev); |
---|
2830 | |
---|
2831 | |
---|
2832 | //% the texobj part |
---|
2833 | write(fname,"\\section{Typesetting composed data structures}"); |
---|
2834 | //======================================================================= |
---|
2835 | |
---|
2836 | write(fname, "Complex data structures such as matrices, vectors or modules |
---|
2837 | can be displayed by using the procedure \\verb|texobj|."); |
---|
2838 | |
---|
2839 | write(fname,"\\subsection{Matrices and vectors}"); |
---|
2840 | //======================================================================= |
---|
2841 | |
---|
2842 | write(fname,"The following example shows how to typeset the hessian of a |
---|
2843 | polynomial."+ |
---|
2844 | bv + |
---|
2845 | "> ring r;", |
---|
2846 | "> poly h=2xy3-x2z+x4z7+y4z2;", |
---|
2847 | "> matrix H=jacob(jacob(h));", |
---|
2848 | "> texobj(fname,H);", |
---|
2849 | ev ); |
---|
2850 | |
---|
2851 | ring r; |
---|
2852 | poly h=2xy3-x2z+x4z7+y4z2; |
---|
2853 | matrix H=jacob(jacob(h)); |
---|
2854 | |
---|
2855 | texobj(fname,H); |
---|
2856 | |
---|
2857 | write(fname,"By default, \\verb|vectors| are written as row vectors:"); |
---|
2858 | |
---|
2859 | vector V = H[2]; |
---|
2860 | |
---|
2861 | write(fname, |
---|
2862 | bv + |
---|
2863 | "> vector V=H[2];", |
---|
2864 | "> texobj(fname,V);", |
---|
2865 | ev ); |
---|
2866 | |
---|
2867 | texobj(fname,V); |
---|
2868 | |
---|
2869 | write(fname,nl2+"\\vspace{0.2cm}"+nl); |
---|
2870 | write(fname,"In order to transpose it, it has to be converted into a |
---|
2871 | matrix."); |
---|
2872 | write(fname, |
---|
2873 | bv + |
---|
2874 | "> texobj(fname,matrix(V));", |
---|
2875 | ev ); |
---|
2876 | |
---|
2877 | texobj(fname,matrix(V)); |
---|
2878 | |
---|
2879 | write(fname,nl+"\\Line"); |
---|
2880 | //------------------------------------------------------------------------ |
---|
2881 | |
---|
2882 | write(fname,"All the features for typesetting polynomials work also for |
---|
2883 | matrices or vectors with polynomial entries."); |
---|
2884 | write(fname,nl+ "\\vspace{0.2cm}" + nl); |
---|
2885 | write(fname,"By setting the global variable \\verb|TeXwidth| it is possible |
---|
2886 | to display only the first terms of the polynomials."); |
---|
2887 | |
---|
2888 | write(fname,bv + |
---|
2889 | "> TeXwidth=1;", |
---|
2890 | "> texobj(fname,H);", |
---|
2891 | "> TeXwidth=-1;", |
---|
2892 | ev ); |
---|
2893 | |
---|
2894 | TeXwidth = 1; |
---|
2895 | texobj(fname,H); |
---|
2896 | TeXwidth = -1; |
---|
2897 | |
---|
2898 | write(fname,nl,"\\Line"); |
---|
2899 | //------------------------------------------------------------------------ |
---|
2900 | write(fname,"The flag variable \\verb|TeXnofrac| controls the typesetting |
---|
2901 | of fractions."); |
---|
2902 | |
---|
2903 | write(fname, |
---|
2904 | bv + |
---|
2905 | "> ring R0=0,x,dp;", |
---|
2906 | "> matrix M[2][3]=1/2, 0, 1/2, 0, 1/3, 2/3;", |
---|
2907 | "> texobj(fname,M);", |
---|
2908 | ev); |
---|
2909 | |
---|
2910 | |
---|
2911 | ring R0 = 0,x,dp; |
---|
2912 | matrix M[2][3] = 1/2, 0, 1/2, 0, 1/3, 2/3; |
---|
2913 | texobj(fname,M); |
---|
2914 | |
---|
2915 | write(fname,bv + |
---|
2916 | "> int TeXnofrac;", |
---|
2917 | "> texobj(fname,M);", |
---|
2918 | ev ); |
---|
2919 | |
---|
2920 | int TeXnofrac; export TeXnofrac; |
---|
2921 | texobj(fname,M); |
---|
2922 | kill TeXnofrac; |
---|
2923 | |
---|
2924 | write(fname,bv + |
---|
2925 | "> kill TeXnofrac;", |
---|
2926 | ev ); |
---|
2927 | |
---|
2928 | write(fname,nl,"\\Line"); |
---|
2929 | //------------------------------------------------------------------------ |
---|
2930 | |
---|
2931 | write(fname,"Printing a vector with homogeneous coordinates can be done by |
---|
2932 | setting \\verb|TeXproj|."); |
---|
2933 | write(fname,bv + |
---|
2934 | "> setring r;", |
---|
2935 | "> int TeXproj;", |
---|
2936 | "> texobj(fname,V);", |
---|
2937 | ev ); |
---|
2938 | |
---|
2939 | setring r; |
---|
2940 | ideal I=3xz5+x2y3-3z,7xz5+y3z+x-z,-xyz2+4yz+2x; |
---|
2941 | int TeXproj; export TeXproj; |
---|
2942 | |
---|
2943 | texobj(fname,V); |
---|
2944 | kill TeXproj; |
---|
2945 | |
---|
2946 | write(fname, |
---|
2947 | bv + |
---|
2948 | "> kill TeXproj;"+nl+ |
---|
2949 | ev); |
---|
2950 | |
---|
2951 | write(fname,"\\subsection{Modules}",nl2); |
---|
2952 | |
---|
2953 | write(fname,"By default, modules are displayed in the following way:"+ |
---|
2954 | bv + |
---|
2955 | "> setring r;", |
---|
2956 | "> module md=module(H);", |
---|
2957 | "> texobj(fname,md);", |
---|
2958 | ev ); |
---|
2959 | |
---|
2960 | setring r; |
---|
2961 | module md = module(H); |
---|
2962 | texobj(fname,md); |
---|
2963 | |
---|
2964 | write(fname,nl,"\\Line"); |
---|
2965 | //------------------------------------------------------------------------ |
---|
2966 | |
---|
2967 | write(fname,"In order to write the generators of a module aligned, the flag |
---|
2968 | variable \\verb|TeXaligned| has to be defined.",nl2); |
---|
2969 | |
---|
2970 | write(fname,bv + |
---|
2971 | "> int TeXaligned;", |
---|
2972 | "> texobj(fname,md);", |
---|
2973 | ev ); |
---|
2974 | |
---|
2975 | int TeXaligned; export TeXaligned; |
---|
2976 | texobj(fname,md); |
---|
2977 | kill TeXaligned; |
---|
2978 | write(fname,bv + |
---|
2979 | "> kill TeXaligned;", |
---|
2980 | ev ); |
---|
2981 | |
---|
2982 | //---------------------------------------------------------------- |
---|
2983 | write(fname,"\\subsection{Integer matrices and vectors}"); |
---|
2984 | |
---|
2985 | write(fname,"Integer matrices are displayed in the following way."); |
---|
2986 | |
---|
2987 | intmat m[3][4]=-1,3,5,2,-2,8,6,0,2,5,8,7; |
---|
2988 | |
---|
2989 | write(fname, |
---|
2990 | bv + |
---|
2991 | "> intmat m[3][4]=-1,3,5,2,-2,8,6,0,2,5,8,7;" + nl + |
---|
2992 | "> m;" + nl + |
---|
2993 | string(m) + nl + |
---|
2994 | "> texobj(fname,m);" + nl2 + |
---|
2995 | ev ); |
---|
2996 | |
---|
2997 | texobj(fname,m); |
---|
2998 | write(fname,nl+ "\\vspace{0.2cm}" + nl); |
---|
2999 | write(fname,"Integer vectors are displayed as row vectors."); |
---|
3000 | intvec v = 1..4; |
---|
3001 | write(fname, |
---|
3002 | bv + |
---|
3003 | "> intvec v=1..4;"+nl+ |
---|
3004 | "> v;" + nl + |
---|
3005 | string(v) + nl + |
---|
3006 | "> texobj(fname,v);"+nl+ |
---|
3007 | ev ); |
---|
3008 | |
---|
3009 | texobj(fname,v); |
---|
3010 | |
---|
3011 | write(fname,nl+ "\\vspace{0.2cm}" + nl); |
---|
3012 | write(fname,"To typeset the transposed vector, it has to be converted into |
---|
3013 | an integer matrix."+ |
---|
3014 | bv + |
---|
3015 | "> texobj(fname,intmat(v));" + nl2 + |
---|
3016 | ev ); |
---|
3017 | |
---|
3018 | texobj(fname,intmat(v)); |
---|
3019 | |
---|
3020 | write(fname,nl+ "\\vspace{0.2cm}" + nl); |
---|
3021 | |
---|
3022 | write(fname,"The following example shows how to typeset the multiplication of |
---|
3023 | a matrix with a vector."+ |
---|
3024 | bv + |
---|
3025 | "> texobj(fname,intmat(m*v),\"=\",m,\"*\",intmat(v));" + nl2 + |
---|
3026 | ev ); |
---|
3027 | |
---|
3028 | texobj(fname,intmat(m*v),"=",m,"*",intmat(v)); |
---|
3029 | |
---|
3030 | //----------------------------------------------------------------- |
---|
3031 | write(fname,"\\Line"); |
---|
3032 | |
---|
3033 | write(fname,"Of course, the brackets of a \\verb|intmat| can be changed |
---|
3034 | by setting \\verb|TeXbrack|."); |
---|
3035 | |
---|
3036 | write(fname, |
---|
3037 | bv + |
---|
3038 | "> intmat mat[3][3]=1,2,3,4,5,6,7,8,9;" + nl + |
---|
3039 | "> string TeXbrack=\"|\";" + nl + |
---|
3040 | "> texobj(fname,mat,\" = \",det(mat)); " + nl2 + |
---|
3041 | ev ); |
---|
3042 | |
---|
3043 | intmat mat[3][3] = 1,2,3,4,5,6,7,8,9; |
---|
3044 | string TeXbrack = "|"; export TeXbrack; |
---|
3045 | texobj(fname,mat," = ",det(mat)); |
---|
3046 | kill TeXbrack; |
---|
3047 | |
---|
3048 | //----------------------------------texname------------------- |
---|
3049 | |
---|
3050 | //write(fname,"\\section{Names of identifiers}"); |
---|
3051 | |
---|
3052 | |
---|
3053 | //write(fname,"The proc \\verb|texname| is used to write indexed names in a |
---|
3054 | //correct way"+lb,nl); |
---|
3055 | |
---|
3056 | |
---|
3057 | |
---|
3058 | // ------------------------------- texproc ------------------------------- |
---|
3059 | proc milnor_number (poly p) |
---|
3060 | { |
---|
3061 | ideal i= std(jacob(p)); |
---|
3062 | int m_nr=vdim(i); |
---|
3063 | if (m_nr<0) |
---|
3064 | { |
---|
3065 | "// not an isolated singularity"; |
---|
3066 | } |
---|
3067 | return(m_nr); |
---|
3068 | } |
---|
3069 | export(milnor_number); |
---|
3070 | |
---|
3071 | write(fname,"\\section{Typesetting procedures}"); |
---|
3072 | write(fname,"The following procedure allows to include the source code |
---|
3073 | of procedures into a \\LaTeX document."); |
---|
3074 | write(fname, |
---|
3075 | bv + |
---|
3076 | "> texproc(fname,\"milnor\_number\");" +nl+ |
---|
3077 | ev); |
---|
3078 | |
---|
3079 | texproc(fname,"milnor_number"); |
---|
3080 | |
---|
3081 | kill(milnor_number); |
---|
3082 | |
---|
3083 | // ------------------------------ closing the tex file ------------------- |
---|
3084 | write(fname,"\\section{Closing the \\LaTeX\\ file}"); |
---|
3085 | write(fname,"To close the file use \\verb|closetex(fname);|. It should now |
---|
3086 | contain pure \\LaTeX \\ code and may be compiled with " + |
---|
3087 | "\\verb|tex(fname)| and displayed with \\verb|xdvi(fname)|."); |
---|
3088 | |
---|
3089 | // write(fname,"\\section{Remarks}"); |
---|
3090 | closetex(fname); |
---|
3091 | //"end of part3" + nl; |
---|
3092 | |
---|
3093 | pagewidth =80; |
---|
3094 | kill texdemopart,TeXwidth; |
---|
3095 | } |
---|
3096 | |
---|
3097 | /////////////////////////////////////////////////////////////////////////////// |
---|