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