1 | // $Id: tex.lib,v 1.5 1998-04-03 22:47:15 krueger Exp $ |
---|
2 | // |
---|
3 | // author : Christian Gorzel email: gorzelc@math.uni-muenster.de |
---|
4 | // created ....18.4.97 (lastchange 13.6.97) |
---|
5 | /////////////////////////////////////////////////////////////////////////////// |
---|
6 | |
---|
7 | version="$Id: tex.lib,v 1.5 1998-04-03 22:47:15 krueger Exp $"; |
---|
8 | info=" |
---|
9 | LIBRARY: tex.lib PROCEDURES FOR TYPESET OF SINGULAROBJECTS IN TEX |
---|
10 | by Christian Gorzel, send bugs and |
---|
11 | comments to gorzelc@math.uni-muenster.de |
---|
12 | |
---|
13 | closetex(s); writes closing line for TeX-document |
---|
14 | opentex(s); writes header for TeX-file s |
---|
15 | tex(s); call latex for TeX-file s |
---|
16 | texdemo(); produces a latex file explaining the features of this lib |
---|
17 | texfactorize(fnm,f); create string in TeX-Symbolformat for factors of poly f |
---|
18 | texmap(fnm,m,r1,r2); create string in TeX-Symbolformat for map m:r1->r2 |
---|
19 | texname(fnm,s); create string in TeX-Symbolformat for identifier |
---|
20 | texobj(l); creates string in TeX-Symbolformat for any (basic) type |
---|
21 | texpoly(f,n[,l]); creates string in TeX-Symbolformat for poly |
---|
22 | texproc(fnm,p); create string in TeX-Symbolformat of text from proc p |
---|
23 | texring(fnm,r[,l]); create string in TeX-Symbolformat for ring/qring |
---|
24 | rmx(s); remove .aux and .log files of TeXfile s |
---|
25 | xdvi(s); call xdvi for dvi-file s |
---|
26 | (parameters in square brackets [] are optional) |
---|
27 | |
---|
28 | Global Variables: |
---|
29 | TeXwidth, TeXnofrac, TeXbrack, TeXproj, TeXaligned, TeXreplace, NoDollars |
---|
30 | are used to control the typesetting |
---|
31 | Call example texdemo; to become familiar with the features of tex.lib |
---|
32 | |
---|
33 | |
---|
34 | TeXwidth : int: -1,0,1..9, >9 controls the breaking of long polynomials |
---|
35 | TeXnofrac : (int) flag, write 1/2 instead of \\frac{1}{2} |
---|
36 | TeXbrack : string: possible values {,(,<,|, \"\" |
---|
37 | controls brackets around ideals and matrices |
---|
38 | TeXproj : (int) flag, write : instead of , in intvecs and vectors |
---|
39 | TeXaligned : (int) flag, write mappings (and ideals) aligned |
---|
40 | TeXreplace : list, entries twoelemented list for replacing symbols |
---|
41 | NoDollars : (int) flag, suppresses surrounding \"$\" signs |
---|
42 | "; |
---|
43 | |
---|
44 | /////////////////////////////////////////////////////////////////////////////// |
---|
45 | |
---|
46 | proc closetex(string fname, list #) |
---|
47 | USAGE: closetex(fname[,style]); fname,style = string |
---|
48 | RETURN: nothing; writes a LaTeX2e closing line into file fname |
---|
49 | NOTE: style overwrites the default setting latex2e; maybe latex,amstex,tex |
---|
50 | preceeding ">>" end ending ".tex" may miss in fname; |
---|
51 | overwriting an existing file is not possible |
---|
52 | EXAMPLE: example closetex; shows an example |
---|
53 | { |
---|
54 | string default = "latex2e"; // may be changed appropriatly (C.G.) |
---|
55 | int i = 1; |
---|
56 | |
---|
57 | if (size(#)) { default = #[1];} |
---|
58 | if (not(size(fname))) // filename is the empty string |
---|
59 | { print("-- Error: need a filename"); |
---|
60 | return(); |
---|
61 | } |
---|
62 | while (fname[i]==">"){i++;} |
---|
63 | fname = fname[i,size(fname)-i+1]; |
---|
64 | |
---|
65 | if (size(fname)>=4) // check if filename is ending with ".tex" |
---|
66 | { if(fname[size(fname)-3,4]!=".tex") {fname = fname +".tex"; } |
---|
67 | } |
---|
68 | else {fname = fname + ".tex";} |
---|
69 | |
---|
70 | if (default=="tex") {write(fname,"\\bye");} |
---|
71 | else { write(fname,"\\end{document}");} |
---|
72 | return(); |
---|
73 | } |
---|
74 | example |
---|
75 | { "EXAMPLE:"; echo=2; |
---|
76 | opentex("exmpl"); |
---|
77 | texobj("exmpl","{\\large \\bf hello}"); |
---|
78 | closetex("exmpl"); |
---|
79 | } |
---|
80 | /////////////////////////////////////////////////////////////////////////////// |
---|
81 | |
---|
82 | proc tex(string fname, list #) |
---|
83 | USAGE: tex(fname[,style]); fname,style = string |
---|
84 | RETURN: nothing; calls latex2e for compiling the file fname |
---|
85 | NOTE: style overwrites the default setting latex2e; maybe latex,amstex,tex |
---|
86 | ending ".tex" may miss in fname |
---|
87 | EXAMPLE: example tex; shows an example |
---|
88 | { |
---|
89 | string default = "latex2e"; // may be changed appropriatly (C.G.) |
---|
90 | int i=1; |
---|
91 | |
---|
92 | while (fname[i]==">"){i++;} |
---|
93 | fname = fname[i,size(fname)-i+1]; |
---|
94 | |
---|
95 | if (size(fname)>=4) // check if filename is ending with ".tex" |
---|
96 | { if(fname[size(fname)-3,4]!=".tex") {fname = fname +".tex"; } |
---|
97 | } |
---|
98 | else {fname = fname + ".tex";} |
---|
99 | if (size(#)) {default = #[1];} |
---|
100 | "calling ",default, " for :",fname,newline; |
---|
101 | |
---|
102 | system("sh",default + " " + fname); |
---|
103 | return(); |
---|
104 | } |
---|
105 | example |
---|
106 | { "EXAMPLE:"; echo =2; |
---|
107 | ring r; |
---|
108 | ideal I = maxideal(7); |
---|
109 | opentex("exp001"); // defaulted latex2e document |
---|
110 | texobj("exp001","An ideal ",I); |
---|
111 | closetex("exp001"); |
---|
112 | tex("exp001"); |
---|
113 | |
---|
114 | opentex("exp002","tex"); // create a texdocument |
---|
115 | texobj("exp002","An ideal",I); |
---|
116 | closetex("exp002"); |
---|
117 | tex("exp002","tex"); |
---|
118 | echo = 0; |
---|
119 | print("the created files will be deleted after pressing <RETURN> "); |
---|
120 | pause; |
---|
121 | echo = 2; |
---|
122 | system("sh","rm -i exp00?.*"); |
---|
123 | } |
---|
124 | /////////////////////////////////////////////////////////////////////////////// |
---|
125 | |
---|
126 | proc opentex(string fname, list #) |
---|
127 | USAGE: opentex(fname[,style]); fname,style = string |
---|
128 | RETURN: nothing; writes as LaTeX2e header into a new file fname |
---|
129 | NOTE: suffix .tex may miss in fname |
---|
130 | style overwrites the default setting latex2e; may be latex,amstex,tex |
---|
131 | EXAMPLE: example opentex; shows an example |
---|
132 | { |
---|
133 | int i =1; |
---|
134 | |
---|
135 | while (fname[i]==">"){i++;} |
---|
136 | fname = fname[i,size(fname)-i+1]; |
---|
137 | |
---|
138 | if (size(fname)>=4) // check if filename is ending with ".tex" |
---|
139 | { if(fname[size(fname)-3,4]!=".tex") {fname = fname +".tex"; } |
---|
140 | } |
---|
141 | else {fname = fname + ".tex";} |
---|
142 | |
---|
143 | fname = ">" + fname; |
---|
144 | write(fname, "\\documentstyle[12pt,amstex]{article}"); |
---|
145 | fname = ">" + fname; // aendern |
---|
146 | write(fname, "\\parindent=0pt"); |
---|
147 | write(fname, |
---|
148 | "\\newcommand{\\C}{{\\Bbb C}}", |
---|
149 | "\\newcommand{\\F}{{\\Bbb F}}", |
---|
150 | "\\newcommand{\\N}{{\\Bbb N}}", |
---|
151 | // "\\newcommand{\\P}{{\\Bbb P}}", |
---|
152 | "\\newcommand{\\Q}{{\\Bbb Q}}", |
---|
153 | "\\newcommand{\\R}{{\\Bbb R}}", |
---|
154 | "\\newcommand{\\T}{{\\Bbb T}}", |
---|
155 | "\\newcommand{\\Z}{{\\Bbb Z}}",newline); |
---|
156 | write(fname, "\\begin{document}"); |
---|
157 | return(); |
---|
158 | } |
---|
159 | example |
---|
160 | { "EXAMPLE:"; echo=2; |
---|
161 | opentex("exmpl"); |
---|
162 | texobj("exmpl","hello"); |
---|
163 | closetex("exmpl"); |
---|
164 | } |
---|
165 | /////////////////////////////////////////////////////////////////////////////// |
---|
166 | |
---|
167 | proc texdemo(list #) |
---|
168 | USAGE: texdemo(); |
---|
169 | RETURN: nothing; generates automatically a LaTeX2e file called: texlibdemo.tex |
---|
170 | explaining the features of tex.lib and its gloabl variables |
---|
171 | NOTE: this proc takes some minutes |
---|
172 | EXAMPLE: example texdemo; executes the generation |
---|
173 | { int make_demo = size(#); |
---|
174 | |
---|
175 | print(" Not implemeted yet"); |
---|
176 | return(); |
---|
177 | if (make_demo) {make_demo=(#[1]=="yes");} |
---|
178 | if(make_demo) |
---|
179 | { |
---|
180 | int TeXdemopart = sytem("sh","sh"); |
---|
181 | system("random",TeXdemopart); |
---|
182 | |
---|
183 | part0(); |
---|
184 | part1(); |
---|
185 | part2(); |
---|
186 | part3(); |
---|
187 | print(" tldemo.tex generated ..."); |
---|
188 | exitall; |
---|
189 | } |
---|
190 | else |
---|
191 | { print("Enter texdemo(\"yes\") to generate the demofile."); |
---|
192 | return(); |
---|
193 | } |
---|
194 | } |
---|
195 | example |
---|
196 | { "EXAMPLE:"; |
---|
197 | print("Enter texdemo(\"yes\") to generate the demofile."); |
---|
198 | } |
---|
199 | /////////////////////////////////////////////////////////////////////////////// |
---|
200 | |
---|
201 | proc texfactorize(string fname, poly f, list #) |
---|
202 | USAGE: opentex(fname,f); fname = string; f = poly |
---|
203 | RETURN: string, the poly as as product of its irreducible factors |
---|
204 | in TeX-typesetting if fname == empty string; |
---|
205 | otherwise append this to file fname.tex; return nothing |
---|
206 | NOTE: preceeding ">>" end ending ".tex" may miss in fname |
---|
207 | EXAMPLE: example texfactorize; shows an example |
---|
208 | { |
---|
209 | def @r = basering; |
---|
210 | list l; |
---|
211 | int i,j,k,Tw,TW,ND;; |
---|
212 | intvec v; |
---|
213 | string s,t; |
---|
214 | string D = "$"; |
---|
215 | poly g; |
---|
216 | |
---|
217 | ND = defined(NoDollars); |
---|
218 | if (!(ND)) {int NoDollars; export NoDollars;} |
---|
219 | else { D = ""; } |
---|
220 | TW = defined(TeXwidth); |
---|
221 | if (TW) {Tw = TeXwidth; TeXwidth = -1;} |
---|
222 | else {int TeXwidth = -1; export TeXwidth;} |
---|
223 | |
---|
224 | if (f==0) {s= D + "0" + D;} |
---|
225 | else |
---|
226 | { |
---|
227 | l = factorize(f); // sollte auch fuer f== 0 direkt funktionieren |
---|
228 | if (l[1][1]<>1){s = texpoly("",l[1][1]);} |
---|
229 | for(i=2;i<=size(l[1]);i++) |
---|
230 | { |
---|
231 | if(size(s)){s = s+"\\cdot ";} |
---|
232 | g = l[1][i]; |
---|
233 | v = leadexp(g); |
---|
234 | k=0; |
---|
235 | for(j=1;j<=size(v);j++){k = k + v[j];} |
---|
236 | if(size(g)>1 or (size(g)==1 and k>1)) |
---|
237 | { t = "(" + texpoly("",l[1][i]) + ")";} |
---|
238 | else { t = texpoly("",l[1][i]);} |
---|
239 | if (l[2][i]>1) |
---|
240 | { t = t+"^{" +string(l[2][i]) + "}";} |
---|
241 | s = s + t; |
---|
242 | } |
---|
243 | if (!(ND)) { kill NoDollars;} |
---|
244 | s = D + s + D; |
---|
245 | if (TW) {TeXwidth = Tw;} |
---|
246 | } |
---|
247 | if(size(fname)) |
---|
248 | { i=1; |
---|
249 | while (fname[i]==">"){i++;} |
---|
250 | fname = fname[i,size(fname)-i+1]; |
---|
251 | |
---|
252 | if (size(fname)>=4) // check if filename is ending with ".tex" |
---|
253 | { if(fname[size(fname)-3,4]!=".tex") {fname = fname +".tex"; } |
---|
254 | } |
---|
255 | else {fname = fname + ".tex";} |
---|
256 | write(fname,s); |
---|
257 | } |
---|
258 | else{return(s);} |
---|
259 | } |
---|
260 | example |
---|
261 | { "EXAMPLE:"; echo=2; |
---|
262 | ring r2=13,(x,y),dp; |
---|
263 | poly f = (x+1+y)^2*x3y*(2x -2y)*y12; |
---|
264 | texfactorize("",f); |
---|
265 | ring R49 = (7,a),x,dp; |
---|
266 | minpoly = a2 +a +3; |
---|
267 | poly f = (a24x5 + x3)*a2x6*(x+1)^2; |
---|
268 | f; |
---|
269 | texfactorize("",f); |
---|
270 | } |
---|
271 | /////////////////////////////////////////////////////////////////////////////// |
---|
272 | |
---|
273 | proc texmap(string fname, def m, def @r1, def @r2, list #) |
---|
274 | USAGE: texmap(fname,f); fname = string; m = string/map, @r1,@r2 = ring |
---|
275 | RETURN: string, the map m from @r1 to @r2 preeceded by its name if m = string |
---|
276 | in TeX-typesetting if fname == empty string; |
---|
277 | otherwise append this to file fname.tex; return nothing |
---|
278 | NOTE: preceeding ">>" end ending ".tex" may miss in fname |
---|
279 | EXAMPLE: example texmap; shows an example |
---|
280 | { |
---|
281 | int saveDollars= defined(NoDollars); |
---|
282 | int TX = defined(TeXwidth); |
---|
283 | int Tw; |
---|
284 | int i,n; |
---|
285 | string r1str,r2str, varr1str, varr2str; |
---|
286 | string mapname,t,s; |
---|
287 | string D,DD,vrg = "$","$$",","; |
---|
288 | def @r = basering; |
---|
289 | def themap; |
---|
290 | list l1,l2; |
---|
291 | string rr1,rr2 = "@r1","@r2"; |
---|
292 | |
---|
293 | proc rp(string s) |
---|
294 | { int i; |
---|
295 | |
---|
296 | for(i=1;i<=size(TeXreplace);i++) |
---|
297 | { if (TeXreplace[i][1]==s) {s= TeXreplace[i][2]; break;}} |
---|
298 | return(s); |
---|
299 | } |
---|
300 | |
---|
301 | // --- store all actual informations |
---|
302 | if(TX) { Tw = TeXwidth; TeXwidth = -1;} |
---|
303 | else { int TeXwidth = -1; export TeXwidth;} |
---|
304 | if (!(saveDollars)) { int NoDollars; export NoDollars;} |
---|
305 | if (defined(TeXproj)) {vrg = ":";} |
---|
306 | |
---|
307 | if (size(#)) |
---|
308 | { if (typeof(#[1])=="list") |
---|
309 | { l1 = #[1]; |
---|
310 | if(size(#)==2) { l2 = #[2];} |
---|
311 | } |
---|
312 | else {l1=#; l2 =#;} |
---|
313 | } |
---|
314 | // --- tex the information in preimring r1 |
---|
315 | |
---|
316 | setring(@r1); |
---|
317 | r1str = texring("",@r1,l1); |
---|
318 | // --- avoid an execute; hence construct an ideal |
---|
319 | |
---|
320 | n = nvars(@r1); |
---|
321 | if (n>1) { t = "\\left(";} |
---|
322 | ideal @I = var(1); |
---|
323 | t = t + texpoly("",var(1)); |
---|
324 | for(i=2;i<=n;i++) |
---|
325 | { @I = @I + var(i); |
---|
326 | t = t + vrg + texpoly("",var(i)); |
---|
327 | } |
---|
328 | if (n>1) { t = t + "\\right)";} |
---|
329 | varr1str = t; |
---|
330 | |
---|
331 | // --- now the things in ring ring r2 |
---|
332 | |
---|
333 | setring(@r2); |
---|
334 | // listvar(); |
---|
335 | |
---|
336 | if (typeof(m)=="string") |
---|
337 | { themap = `m`; |
---|
338 | mapname = m; |
---|
339 | if (defined(TeXreplace)) |
---|
340 | { mapname = rp(mapname); // rp ausschreiben ! |
---|
341 | } |
---|
342 | mapname = mapname + ":"; |
---|
343 | } |
---|
344 | if (typeof(m)=="map") { themap = m;} |
---|
345 | |
---|
346 | r2str = texring("",@r2,l2); |
---|
347 | ideal @J = themap(@I); |
---|
348 | n = size(matrix(@J)); |
---|
349 | if (n>1) { t = " \\left(";} |
---|
350 | if (!(defined(TeXaligned)) and (n>1)) |
---|
351 | { t = t + newline + "\\begin{array}{c}" + newline;} |
---|
352 | t = t + texpoly("",@J[1]); |
---|
353 | for (i=2;i<=n; i++) |
---|
354 | {if(defined(TeXaligned)) |
---|
355 | { t = t + vrg + texpoly("",@J[i]); } |
---|
356 | else { t = t + "\\\\" + newline + texpoly("",@J[i]);} |
---|
357 | } |
---|
358 | if (!(defined(TeXaligned)) and (n>1)) |
---|
359 | { t = t + newline + "\\end{array}" + newline;} |
---|
360 | if (n>1) {t = t + "\\right)";} |
---|
361 | varr2str = t; |
---|
362 | |
---|
363 | // --- go back to ring r1 to kill @I |
---|
364 | |
---|
365 | setring(@r1); |
---|
366 | kill @I; |
---|
367 | |
---|
368 | // --- now reset the old settings and stick all the information together |
---|
369 | |
---|
370 | setring(@r); |
---|
371 | if (!(saveDollars)) { kill NoDollars;} |
---|
372 | if (TX) {TeXwidth = Tw;} |
---|
373 | else { kill TeXwidth;} |
---|
374 | if (defined(NoDollars)) |
---|
375 | { D,DD = "",""; } |
---|
376 | |
---|
377 | if (defined(TeXaligned)) |
---|
378 | { s = D + mapname; |
---|
379 | s = s + r1str + "\\longrightarrow" + r2str + ", \\ " + |
---|
380 | varr1str + "\\longmapsto" + varr2str + D; } |
---|
381 | else |
---|
382 | { s = DD; |
---|
383 | s = s + newline + "\\begin{array}{rcc}" + newline; |
---|
384 | s = s + mapname + r1str + " & \\longrightarrow & " + r2str + "\\\\[2mm]" |
---|
385 | + newline; |
---|
386 | s = s + varr1str + " & \\longmapsto & " + newline + varr2str + newline; |
---|
387 | s = s + "\\end{array}" + newline; |
---|
388 | s = s + DD; |
---|
389 | } |
---|
390 | |
---|
391 | if (size(fname)) |
---|
392 | { i=1; |
---|
393 | while (fname[i]==">"){i++;} |
---|
394 | fname = fname[i,size(fname)-i+1]; |
---|
395 | |
---|
396 | if (size(fname)>=4) // check if filename is ending with ".tex" |
---|
397 | { if(fname[size(fname)-3,4]!=".tex") {fname = fname +".tex"; } |
---|
398 | } |
---|
399 | else {fname = fname + ".tex";} |
---|
400 | write(fname,s); |
---|
401 | } |
---|
402 | else {return(s);} |
---|
403 | } |
---|
404 | example |
---|
405 | { "EXAMPLE:"; echo = 2; |
---|
406 | string fname = "tldemo"; |
---|
407 | ring r1=0,(x,y,z),dp; export r1; |
---|
408 | ring r2=0,(u,v),dp; |
---|
409 | map phi =(r1,u2,uv -v,v2); export phi; |
---|
410 | list TeXreplace; |
---|
411 | TeXreplace[1] = list("phi","\\phi"); |
---|
412 | export TeXreplace; |
---|
413 | texmap("","phi",r1,r2); |
---|
414 | int TeXaligned; export TeXaligned; |
---|
415 | texmap("",phi,r1,r2,"\\C"); |
---|
416 | kill r1,r2,TeXreplace,TeXaligned; |
---|
417 | } |
---|
418 | /////////////////////////////////////////////////////////////////////////////// |
---|
419 | |
---|
420 | proc texname(string fname, string s) |
---|
421 | USAGE: texname(fname,s); fname,s = string |
---|
422 | RETURN: the string s if fname == the empty string "" ; |
---|
423 | otherwise append s to file fname.tex; return nothing |
---|
424 | NOTE: preceeding ">>" end ending ".tex" may miss in fname; |
---|
425 | EXAMPLE: example texname; shows an example |
---|
426 | { |
---|
427 | string st, extr; |
---|
428 | int i,anf,end,op,bigch; |
---|
429 | int n; |
---|
430 | |
---|
431 | if (s[1]=="{") { return(s[2,size(s)-2]);} |
---|
432 | if (s=="") { return(s);} |
---|
433 | s = s + newline; // add a terminating sign |
---|
434 | anf=1; |
---|
435 | while(s[i]!=newline) |
---|
436 | { |
---|
437 | i =anf; |
---|
438 | |
---|
439 | while(s[i]<"0" or s[i]>"9" and s[i]!="'" and s[i]!= "_" and s[i]!="~" and |
---|
440 | s[i]!="(" and s[i]!=")" and s[i]!= "[" and s[i]!=newline) {i++;} |
---|
441 | if (s[i]==newline){st = st + s[anf,i-anf]; n = n +10*(i-anf); return(st);} |
---|
442 | st = st + s[anf,i-anf]; // the starting letters |
---|
443 | if (s[anf]>="A" and s[anf]<="Z") {bigch=1;} |
---|
444 | if (s[i]=="'") { st = st + "'";i++;} |
---|
445 | if (s[i]=="~") { st = "\\tilde{" + st + "}"; i++;} |
---|
446 | if (s[i]=="_") { i++;} |
---|
447 | if (s[i]=="(") { op =1;i++;} |
---|
448 | if (s[i]=="[") { anf = i+1; |
---|
449 | while(s[i]!="]"){i++;} // matrices and vectors |
---|
450 | st = st + "_{" + s[anf,i-anf] + "}"; n = n+ 5*(i-anf); i++; |
---|
451 | // besser: while s[i]<> nwline : scan forward: end, return |
---|
452 | } |
---|
453 | if (s[i]==newline) {return(st);} |
---|
454 | anf =i; |
---|
455 | while (s[i]>="0" and s[i]<="9") {i++;} // parse the number after the letters |
---|
456 | if (bigch and not(op)) { st = st + "^{" + s[anf,i-anf] + "}"; bigch =0;} |
---|
457 | else { st = st + "_{" + s[anf,i-anf] + "}";} |
---|
458 | n = n+5*(i-anf); |
---|
459 | anf =i; // the next text in ( , ) as exponent |
---|
460 | if (op) { if (s[i]== ","){anf = anf+1;} |
---|
461 | while(s[i] !=")"){ i++;} |
---|
462 | if (i<>anf){st = st + "^{" + s[anf,i-anf] + "}"; n = n +5*(i-anf);} |
---|
463 | i++; |
---|
464 | } |
---|
465 | anf =i; |
---|
466 | } |
---|
467 | if (size(fname)) |
---|
468 | { i=1; |
---|
469 | while (fname[i]==">"){i++;} |
---|
470 | fname = fname[i,size(fname)-i+1]; |
---|
471 | |
---|
472 | if (size(fname)>=4) // check if filename is ending with ".tex" |
---|
473 | { if(fname[size(fname)-3,4]!=".tex") {fname = fname +".tex"; } |
---|
474 | } |
---|
475 | else {fname = fname + ".tex";} |
---|
476 | write(fname,st); |
---|
477 | } |
---|
478 | else {return(st);} |
---|
479 | } |
---|
480 | example |
---|
481 | { "EXAMPLE:"; echo =2; |
---|
482 | ring r = 0,(x,y),lp; |
---|
483 | poly f = 3xy4 + 2xy2 + x5y3 + x + y6; |
---|
484 | texname("","{f(10)}"); |
---|
485 | texname("","f(10) ="); |
---|
486 | texname("","n1"); |
---|
487 | texname("","T1_12"); |
---|
488 | texname("","g'_11"); |
---|
489 | texname("","f23"); |
---|
490 | texname("","M[2,3]"); |
---|
491 | texname("","A(0,3);"); |
---|
492 | texname("","E~(3)"); |
---|
493 | } |
---|
494 | /////////////////////////////////////////////////////////////////////////////// |
---|
495 | |
---|
496 | proc texobj(string fname, list #) |
---|
497 | USAGE: texobj(fname,l); fname = string,l = list of Singular dataypes |
---|
498 | RETURN: string, the objects in TeX-typesetting if fname == empty string; |
---|
499 | otherwise append this to file fname.tex; return nothing |
---|
500 | NOTE: preceeding ">>" end ending ".tex" may miss in fname; |
---|
501 | EXAMPLE: example texobj; shows an example |
---|
502 | { |
---|
503 | int i,j,k,nr,nc,linear,Tw,Dollars; |
---|
504 | int ND = defined(NoDollars); |
---|
505 | int TW = defined(TeXwidth); |
---|
506 | |
---|
507 | if(defined(basering)){ poly g,h; matrix M;} |
---|
508 | string s,t,l,ineq,sg,Iname; |
---|
509 | string sep= ","; |
---|
510 | string D,DA,DE = "$","\\begin{equation*}","\\end{equation*}"+ newline; |
---|
511 | string OB,CB = "(",")"; |
---|
512 | if (defined(TeXbrack)) |
---|
513 | {// if (TeXbrack=="(") {OB = "("; CB = ")";} |
---|
514 | if (TeXbrack=="<") {OB = "<"; CB = ">";} |
---|
515 | if (TeXbrack=="{") {OB = "{"; CB = "}";} |
---|
516 | if (TeXbrack=="|") {OB = "|"; CB = "|";} |
---|
517 | if (TeXbrack=="" ) {OB = ""; CB = "";} |
---|
518 | } |
---|
519 | |
---|
520 | |
---|
521 | if (!(TW)) { int TeXwidth = -1; export TeXwidth; } |
---|
522 | Tw = TeXwidth; |
---|
523 | |
---|
524 | if (defined(TeXproj)){ sep = ":";} |
---|
525 | if(ND) { D,DA,DE="","","";} |
---|
526 | else {int NoDollars; export NoDollars;} |
---|
527 | |
---|
528 | proc absterm(poly f) |
---|
529 | { int k; |
---|
530 | |
---|
531 | for (k=1; k<=nvars(basering); k++) |
---|
532 | { f = subst(f,var(k),0); } |
---|
533 | return(f); |
---|
534 | } |
---|
535 | |
---|
536 | |
---|
537 | if (size(#)==1) |
---|
538 | { if (typeof(#[1])=="int" or typeof(#[1])=="intvec" or typeof(#[1])=="vector" |
---|
539 | or typeof(#[1])=="number" or defined(TeXaligned)) { DA = D; DE = D; } } |
---|
540 | |
---|
541 | s = DA + newline; |
---|
542 | |
---|
543 | for (k=1; k<=size(#); k++) |
---|
544 | { def obj = #[k]; |
---|
545 | if (typeof(obj) == "string") |
---|
546 | { if (defined(`obj`)) |
---|
547 | { if (typeof(`obj`)=="ideal") |
---|
548 | { Iname = obj; def e = `obj`; |
---|
549 | kill obj; def obj = e; kill e;} |
---|
550 | else {s = s + obj + newline;} |
---|
551 | } |
---|
552 | else { s = s + obj + newline;} |
---|
553 | } |
---|
554 | if (typeof(obj) == "int") { s = s + " " + string(obj) + " ";} |
---|
555 | |
---|
556 | if (typeof(obj) == "intvec") |
---|
557 | { s = s + " ("; |
---|
558 | for(j=1; j<size(obj);j++) { s = s + string(obj[j]) + sep;} |
---|
559 | s = s + string(obj[j]) + ") "; |
---|
560 | } |
---|
561 | |
---|
562 | if (typeof(obj) == "number" ) |
---|
563 | { s = s + texpoly("",obj) + newline; |
---|
564 | } |
---|
565 | |
---|
566 | if (typeof(obj) == "poly") |
---|
567 | { int TeXdisplay; export TeXdisplay; |
---|
568 | s = s + "\\begin{split}" + newline; |
---|
569 | s = s + texpoly("",obj) + "\\\\" + newline; |
---|
570 | s = s + "\\end{split}" + newline; |
---|
571 | kill TeXdisplay; |
---|
572 | } |
---|
573 | |
---|
574 | if (typeof(obj) == "vector") |
---|
575 | { if (obj==0) { s = s + D + "0" + D;} |
---|
576 | else |
---|
577 | { |
---|
578 | s = s + "\\left" + OB; |
---|
579 | for(j=1; j<nrows(obj); j++) {s = s + texpoly("",obj[j]) + sep;} |
---|
580 | s = s + texpoly("",obj[j]) + "\\right" + CB + newline;; |
---|
581 | } |
---|
582 | } |
---|
583 | |
---|
584 | if (typeof(obj) == "ideal") |
---|
585 | { if (size(Iname)) // verwende hier align |
---|
586 | { if (Tw==0) {TeXwidth = -1;} |
---|
587 | s = s + "\\begin{array}{rcl}" + newline; |
---|
588 | for (i=1;i<=size(matrix(obj));i++) |
---|
589 | { s = s + Iname+ "_{" + string(i) + "} & = & " |
---|
590 | + texpoly("",obj[i]); |
---|
591 | if (i<size(matrix(obj))){ s = s + "\\\\" + newline;} |
---|
592 | } |
---|
593 | s = s + newline; |
---|
594 | s = s + "\\end{array}" + newline; |
---|
595 | TeXwidth = Tw; |
---|
596 | Iname =""; |
---|
597 | } |
---|
598 | else |
---|
599 | { |
---|
600 | if (TeXwidth==0) |
---|
601 | { obj= simplify(obj,2); |
---|
602 | linear = 1; |
---|
603 | for (j=1;j<=size(obj);j++) |
---|
604 | { if (deg(obj[j])>1){linear =0; break;} |
---|
605 | } |
---|
606 | if (!(linear)) |
---|
607 | { s = s + "\\begin{array}{rcl}" + newline; |
---|
608 | for(j=1;j<=size(obj);j++) |
---|
609 | { h = absterm(obj[j]); |
---|
610 | ineq = attrib(obj[j],"ineq"); |
---|
611 | if(!(size(ineq))) { ineq = "=" ; } |
---|
612 | l = texpoly("",obj[j]-h) + " & " + ineq + " & " + texpoly("",-h); |
---|
613 | if(j<size(obj)) { l = l + " \\\\";} |
---|
614 | s =s+ l + newline; |
---|
615 | } |
---|
616 | s = s + "\\end{array}" + newline; |
---|
617 | } |
---|
618 | else // linear |
---|
619 | { s = s + |
---|
620 | "\\begin{array}{*{" + string(2*nvars(basering)-1) + "}{c}cr}" + newline; |
---|
621 | for(j=1; j<=size(obj);j++) |
---|
622 | { h = absterm(obj[j]); |
---|
623 | ineq = attrib(obj[j],"ineq"); |
---|
624 | if(!(size(ineq))) { ineq = "=" ; } |
---|
625 | l = ""; nc = 0; |
---|
626 | for (i=1; i<=nvars(basering);i++) |
---|
627 | { t = " "; sg =""; |
---|
628 | g = obj[j]-subst(obj[j],var(i),0); |
---|
629 | if (g!=0) { t = texpoly("",g);} |
---|
630 | if (i>1) |
---|
631 | { if (t[1]!="-" and t[1]!= " " and nc ){sg = "+";} |
---|
632 | if (t[1]=="-") { sg = "-"; nc =1; t=t[2,size(t)-1];} |
---|
633 | if (t==" ") {sg ="";} |
---|
634 | l = l + " & " + sg + " & " + t; |
---|
635 | } |
---|
636 | else { l = t;} |
---|
637 | if (g!=0) {nc = 1;} |
---|
638 | } |
---|
639 | |
---|
640 | l = l + " & " + ineq + " & " + texpoly("",-h); |
---|
641 | if (j < size(obj)) { l = l + " \\\\";} |
---|
642 | s = s + l + newline; |
---|
643 | } // end for (j) |
---|
644 | s = s + "\\end{array}"; |
---|
645 | } // end else linear |
---|
646 | } // end TeXwidth == 0 |
---|
647 | else // TeXwidth <> 0 |
---|
648 | { s = s + "\\left"+ OB; |
---|
649 | if (defined(TeXaligned)) |
---|
650 | { s = s + texpoly("",obj,","); |
---|
651 | } |
---|
652 | else |
---|
653 | { s = s + newline + "\\begin{array}{c}" + newline + |
---|
654 | texpoly("",obj,", \\\\" + newline) + |
---|
655 | newline + "\\end{array}" + newline; |
---|
656 | } |
---|
657 | s = s + "\\right" + CB; |
---|
658 | } // end TeXwidth <> 0 |
---|
659 | } // not Iname |
---|
660 | // s; |
---|
661 | } |
---|
662 | |
---|
663 | if (typeof(obj) == "module") |
---|
664 | { M = matrix(obj); |
---|
665 | if (Tw ==0 or Tw > 9) { TeXwidth = -1;} |
---|
666 | s = s + "\\left" + OB + newline; |
---|
667 | if (!(defined(TeXaligned))) |
---|
668 | { // Naechste Zeile nicht notwendig ! |
---|
669 | // s = s + "\\begin{array}{*{"+ string(ncols(M)) + "}{c}}" + newline; |
---|
670 | for(j=1;j<=ncols(M);j++) |
---|
671 | { l = "\\left" + OB + newline + "\\begin{array}{c}" + newline; |
---|
672 | l = l + texpoly("",ideal(M[j]), " \\\\" + newline) |
---|
673 | + newline + "\\end{array}" +newline + "\\right" + CB + newline; |
---|
674 | if (j< ncols(M)) { l = l + " , " + newline;} |
---|
675 | s = s + l ; |
---|
676 | } |
---|
677 | } |
---|
678 | else // TeXaligned |
---|
679 | { |
---|
680 | for(j=1;j<=ncols(M);j++) |
---|
681 | { s = s + "\\left" + OB + newline + |
---|
682 | texpoly("",ideal(M[j]),",") + newline + "\\right" + CB; |
---|
683 | if (j<ncols(M)) { s = s + "," + newline; } |
---|
684 | } |
---|
685 | } |
---|
686 | s = s + "\\right" + CB + newline; |
---|
687 | } // module part |
---|
688 | |
---|
689 | |
---|
690 | if (typeof(obj) == "matrix") |
---|
691 | { if (Tw==0 or Tw > 9) {TeXwidth = -1;} |
---|
692 | M = transpose(obj); |
---|
693 | s = s + "\\left" + OB + newline + |
---|
694 | "\\begin{array}{*{"+ string(ncols(obj)) + "}{c}" + "}"+ newline; |
---|
695 | for(i=1;i<=ncols(M);i++) |
---|
696 | { l = l + texpoly("",ideal(M[i])," & "); |
---|
697 | if (i<ncols(M)) { l = l + " \\\\" + newline;} |
---|
698 | } |
---|
699 | l = l + newline; |
---|
700 | s = s + l + "\\end{array}" + newline + |
---|
701 | "\\right" + CB + newline; |
---|
702 | TeXwidth = Tw; |
---|
703 | } |
---|
704 | |
---|
705 | if (typeof(obj) == "intmat") |
---|
706 | { nr,nc = nrows(obj),ncols(obj); |
---|
707 | l = ""; |
---|
708 | l = "\\left" + OB + newline + |
---|
709 | "\\begin{array}{*{"+ string(nc) + "}{r}}"+ newline; |
---|
710 | for(i=1;i<=nr;i++) |
---|
711 | { for(j=1;j<=nc;j++) |
---|
712 | { l = l + string(obj[i,j]); |
---|
713 | if (j <nc ) { l = l + " & ";} |
---|
714 | else {if( i < nr) { l = l + "\\\\" + newline;}} |
---|
715 | } |
---|
716 | } |
---|
717 | l = l + newline + "\\end{array}" + newline + |
---|
718 | "\\right" + CB + newline; |
---|
719 | s = s + l; |
---|
720 | } |
---|
721 | |
---|
722 | if (typeof(obj) == "ring" or |
---|
723 | typeof(obj) == "qring") { s = s + D + texring("",obj) + D + newline;} |
---|
724 | |
---|
725 | kill obj; |
---|
726 | } |
---|
727 | |
---|
728 | s = s + DE + newline; |
---|
729 | |
---|
730 | if(!(ND)) { kill NoDollars;} |
---|
731 | |
---|
732 | // s; |
---|
733 | if(size(fname)) |
---|
734 | { i=1; |
---|
735 | while (fname[i]==">"){i++;} |
---|
736 | fname = fname[i,size(fname)-i+1]; |
---|
737 | if (size(fname)>=4) // check if filename is ending with ".tex" |
---|
738 | { if(fname[size(fname)-3,4]!=".tex") {fname = fname +".tex"; } |
---|
739 | } |
---|
740 | else {fname = fname + ".tex";} |
---|
741 | write(fname,s); |
---|
742 | } |
---|
743 | else {return(s);} |
---|
744 | } |
---|
745 | example |
---|
746 | { "EXAMPLE:"; echo =2; |
---|
747 | ring r = 0,(x,y),lp; |
---|
748 | poly f = 3xy4 + 2xy2 + x5y3 + x + y6; |
---|
749 | ideal G = jacob(f); |
---|
750 | texobj("",G); |
---|
751 | matrix J = jacob(G); |
---|
752 | texobj("",J); |
---|
753 | intmat m[3,4] = 9,2,4,5,2,5,-2,4,-6,10,-1,2,7; |
---|
754 | texobj("",m); |
---|
755 | ring r0 = 0,(x,y,z),dp; |
---|
756 | ideal I = 2x2-4yz3+2-4,zy2+2x,y5z-6x2+7y4z2 +5; |
---|
757 | } |
---|
758 | /////////////////////////////////////////////////////////////////////////////// |
---|
759 | |
---|
760 | proc texproc(string fname,string pname) |
---|
761 | USAGE: opentex(fname,pname); fname,pname = string |
---|
762 | RETURN: string, the proc in a verbatim environment in TeX-typesetting |
---|
763 | if fname == empty string; |
---|
764 | otherwise append this to file fname.tex; return nothing |
---|
765 | NOTE: preceeding ">>" end ending ".tex" may miss in fname; |
---|
766 | CAUTION: texproc cannot applied on itself correctly |
---|
767 | EXAMPLE: example texproc; shows an example |
---|
768 | { |
---|
769 | int i,j=1,1; |
---|
770 | string p,s,t; |
---|
771 | |
---|
772 | if (defined(pname)) |
---|
773 | { if (typeof(`pname`)=="proc") |
---|
774 | { p = string(`pname`); |
---|
775 | s = "\\begin{verbatim}" + newline; |
---|
776 | s = s + "proc " + pname + "("; |
---|
777 | i = find(p,"parameter"); // collecting the parameters |
---|
778 | while(i) |
---|
779 | { j=find(p,";",i); |
---|
780 | t = p[i+10,j-i-10]; |
---|
781 | if(i>1){s = s + ",";}; |
---|
782 | s = s + t; |
---|
783 | i = find(p,"parameter",j); |
---|
784 | } |
---|
785 | s = s + ")" + newline; |
---|
786 | j++; // skip one for the newline |
---|
787 | i = find(p,";RETURN();",j); // j kann hier weg |
---|
788 | s = s + "{" + p[j,i-j-1] + "}" + newline; |
---|
789 | s = s + "\\end{verbatim}" + newline; |
---|
790 | } |
---|
791 | } |
---|
792 | else |
---|
793 | { print("--Error: No such proc defined"); |
---|
794 | return(); |
---|
795 | } |
---|
796 | if(size(fname)) |
---|
797 | { i=1; |
---|
798 | while (fname[i]==">"){i++;} |
---|
799 | fname = fname[i,size(fname)-i+1]; |
---|
800 | if (size(fname)>=4) // check if filename is ending with ".tex" |
---|
801 | { if(fname[size(fname)-3,4]!=".tex") {fname = fname +".tex"; } |
---|
802 | } |
---|
803 | else {fname = fname + ".tex";} |
---|
804 | write(fname,s); |
---|
805 | } |
---|
806 | else{return(s);} |
---|
807 | } |
---|
808 | example |
---|
809 | { "EXAMPLE:"; echo=2; |
---|
810 | proc exp(int i,int j,list #) |
---|
811 | { string s; |
---|
812 | |
---|
813 | if (size(#)) |
---|
814 | { |
---|
815 | for(i;i<=j;i++) |
---|
816 | { s = s + string(j) + string(#); } |
---|
817 | } |
---|
818 | return(s); |
---|
819 | } |
---|
820 | export exp; |
---|
821 | texproc("","exp"); |
---|
822 | } |
---|
823 | |
---|
824 | /////////////////////////////////////////////////////////////////////////////// |
---|
825 | |
---|
826 | proc texring(string fname, def r, list #) |
---|
827 | USAGE: texring(fname, r[,l]); fname = string; r = ring; |
---|
828 | l=list of strings : controls the symbol for |
---|
829 | coefficint field etc. see example texdemo(); |
---|
830 | RETURN: string, the ring in TeX-typesetting if fname == empty string; |
---|
831 | otherwise append this to file fname.tex; return nothing |
---|
832 | NOTE: preceeding ">>" end ending ".tex" may miss in fname; |
---|
833 | EXAMPLE: example texring; shows an example |
---|
834 | { |
---|
835 | int i,galT,flag,mipo,nopar,Dollars,TB,TA; |
---|
836 | string ob,cb,cf,en,s,t,savebrack; //opening bracket, closing br, coef.field |
---|
837 | intvec v; |
---|
838 | |
---|
839 | |
---|
840 | proc tvar(intvec v) |
---|
841 | { |
---|
842 | int i,j,ldots; |
---|
843 | string s; |
---|
844 | |
---|
845 | j = 1; |
---|
846 | s = texpoly("",var(1)); |
---|
847 | |
---|
848 | if (nvars(basering)==1) { return(s);} |
---|
849 | if (nvars(basering)==2) { return(s + "," + texpoly("",var(2)));} |
---|
850 | if (size(v)==1 and v[1] == 1) |
---|
851 | {return(s + ",\\ldots,"+ texpoly("",var(nvars(basering))));} |
---|
852 | if (v[1]==1 and size(v) >1) {j++;} |
---|
853 | |
---|
854 | for(i=2;i<nvars(basering);i++) |
---|
855 | { if (i<v[j] and !(ldots)) |
---|
856 | { s = s + ",\\ldots"; |
---|
857 | ldots =1; |
---|
858 | } |
---|
859 | if (i== v[j]) |
---|
860 | { s = s + "," + texpoly("",var(i)); |
---|
861 | ldots =0; |
---|
862 | if (j< size(v)) {j++;} |
---|
863 | } |
---|
864 | } |
---|
865 | if (v[j]<nvars(basering)-1) { s = s + ",\\dotsc";} |
---|
866 | return(s + "," + texpoly("",var(nvars(basering)))); |
---|
867 | } |
---|
868 | |
---|
869 | |
---|
870 | setring r; |
---|
871 | if (!(defined(NoDollars))){ Dollars = 1; int NoDollars; export NoDollars;} |
---|
872 | ob,cb = "[","]"; |
---|
873 | if (find(ordstr(r),"s")) { ob,cb="\\{","\\}";} |
---|
874 | if(char(r)==0){cf="\\Q";} |
---|
875 | if(charstr(r)=="real"){cf="\\R";} |
---|
876 | if(char(r)==prime(char(r))){cf="\\Z_{"+string(char(r))+"}";} |
---|
877 | if(char(r)>0) |
---|
878 | { i = find(charstr(r),","); |
---|
879 | if(i) |
---|
880 | { t= charstr(r)[1,i-1]; |
---|
881 | galT = (t <> string(char(r))); |
---|
882 | if (galT) { cf = "\\F_{"+ t + "}";} |
---|
883 | } |
---|
884 | } // all other cases are cover already by char(r)=? prime(char) |
---|
885 | |
---|
886 | if (size(#)) |
---|
887 | { if (typeof(#[1])=="list") { # = #[1];} |
---|
888 | } |
---|
889 | for (i=1;i<=size(#);i++) |
---|
890 | { flag =0; |
---|
891 | if(typeof(#[i])=="string") |
---|
892 | { |
---|
893 | if(#[i][1]=="^" or #[i][1]=="_"){en=en+#[i];flag = 1;} |
---|
894 | if(#[i]=="mipo"){mipo=1; flag = 1;} |
---|
895 | if(#[i]=="{"){ob,cb="\\{","\\}";flag=1;} |
---|
896 | if(#[i]=="{{"){ob,cb="\\{\\{","\\}\\}";flag=1;} |
---|
897 | if(#[i]=="["){ob,cb="[","]";flag=1;} |
---|
898 | if(#[i]=="[["){ob,cb="[[","]]";flag=1;} |
---|
899 | if(#[i]=="<"){ob,cb="<",">";flag=1;} |
---|
900 | if(#[i]=="<<"){ob,cb="{\\ll}","{\\gg}";flag=1;} |
---|
901 | if(#[i]=="C"){cf="\\C";flag=1;} |
---|
902 | if(#[i]=="Q"){cf="\\Q";flag=1;} |
---|
903 | if((#[i]=="k" or #[i]=="K" or #[i]=="R") and !(galT)) |
---|
904 | {cf=#[i]; flag=1; nopar=1;} |
---|
905 | if (flag!=1) {cf = #[i];} // for all the cases not covered here e.g Z_(p) |
---|
906 | } // or Q[i] |
---|
907 | |
---|
908 | if ((typeof(#[i])=="intvec") or |
---|
909 | (typeof(#[i])=="int")){v=#[i];} |
---|
910 | } |
---|
911 | s = cf; |
---|
912 | if (!(galT) and mipo and minpoly!=0) { s = s + "/" + texpoly("",minpoly);} |
---|
913 | // now the parameters |
---|
914 | // t; |
---|
915 | if(npars(r) and ((t==string(char(r))) or char(r)==0) and !(nopar)) |
---|
916 | { |
---|
917 | s = s + "("; // !! mit ideal !! |
---|
918 | for(i=1;i<npars(r);i++) {s = s + texpoly("",par(i)) + ",";} |
---|
919 | s = s + texpoly("",par(npars(r))) + ")"; |
---|
920 | } // paramters done |
---|
921 | s = s + ob; |
---|
922 | if (v!=0 and size(nvars(r))>3) |
---|
923 | { s = s + tvar(v);} |
---|
924 | else |
---|
925 | { for(i=1;i<nvars(r);i++) {s = s + texpoly("",var(i)) + ",";} |
---|
926 | s = s + texpoly("",var(nvars(r))); |
---|
927 | } |
---|
928 | s = s + cb + en; |
---|
929 | |
---|
930 | if (typeof(r)=="qring") |
---|
931 | { ideal @I = ideal(r); |
---|
932 | if (defined(TeXbrack)) |
---|
933 | { |
---|
934 | TB =1; savebrack = TeXbrack; |
---|
935 | if (TeXbrack!= "<" and TeXbrack!="(") { TeXbrack = "<";} |
---|
936 | } |
---|
937 | TA = defined(TeXaligned); |
---|
938 | if (!(TA)) { int TeXaligned; export TeXaligned; } |
---|
939 | t = texobj("",@I); |
---|
940 | @I; |
---|
941 | t; |
---|
942 | if (TB) { TeXbrack = savebrack;} |
---|
943 | if (!(TA)) { kill TeXaligned;} |
---|
944 | s = s + "/" + t; |
---|
945 | } |
---|
946 | |
---|
947 | if (Dollars) |
---|
948 | { kill NoDollars; |
---|
949 | s = "$" + s + "$"; |
---|
950 | } |
---|
951 | if (size(fname)) |
---|
952 | { i=1; |
---|
953 | while (fname[i]==">"){i++;} |
---|
954 | fname = fname[i,size(fname)-i+1]; |
---|
955 | |
---|
956 | if (size(fname)>=4) // check if filename is ending with ".tex" |
---|
957 | { if(fname[size(fname)-3,4]!=".tex") {fname = fname +".tex"; } |
---|
958 | } |
---|
959 | else {fname = fname + ".tex";} |
---|
960 | write(fname,s); |
---|
961 | } |
---|
962 | else{return(s);} |
---|
963 | } |
---|
964 | example |
---|
965 | { "EXAMPLE:"; echo=2; |
---|
966 | ring r0 = 0,(x,y,z),dp; // short varnames polynomial ordering |
---|
967 | texring("",r0); |
---|
968 | ring r7 =0,(x(0..2)),ds; // char =7, long varnames |
---|
969 | texring("",r7); |
---|
970 | ring r1 = 0,(x1,x2,y1,y2),wp(1,2,3,4); |
---|
971 | texring("",r1); |
---|
972 | ring r2= 0,(x_10,x_11),M(1,2,3,4); |
---|
973 | texring("",r2); |
---|
974 | ring rr = real,(x),dp; // real numbers |
---|
975 | texring("",rr); |
---|
976 | ring r; |
---|
977 | texring("",r); |
---|
978 | ring rabc =(0,t1,t2,t3),(x,y),dp; // parameters |
---|
979 | texring("",rabc); |
---|
980 | ring ralg = (7,a),(x1,x2),(ds,dp); // algebraic extension |
---|
981 | minpoly = a2-a+3; |
---|
982 | texring("",ralg); |
---|
983 | // texring("",ralg,"mipo"); |
---|
984 | ring r49=(49,a),x,dp; // Galoisfield |
---|
985 | texring("",r49); |
---|
986 | setring r0; |
---|
987 | ideal i = x2-z,xy2+1; |
---|
988 | qring q = std(i); |
---|
989 | q; |
---|
990 | texring("",q); |
---|
991 | // -------- additional features ------------- |
---|
992 | ring r10 =0,(x(0..10)),dp; |
---|
993 | texring("",r10,1); |
---|
994 | ring rxy = 0,(x(1..5),y(1..6)),ds; |
---|
995 | intvec v = 5,6; |
---|
996 | texring("",rxy,v); |
---|
997 | texring("",r0,"C","{"); |
---|
998 | texring("",ralg,"k"); |
---|
999 | texring("",r7,"^G"); |
---|
1000 | list TeXreplace; |
---|
1001 | TeXreplace[1] = list("x","\\xi"); |
---|
1002 | TeXreplace[2] = list ("t","\\lambda"); |
---|
1003 | export TeXreplace; |
---|
1004 | texring("",rabc); |
---|
1005 | texring("",r7); |
---|
1006 | kill TeXreplace; |
---|
1007 | } |
---|
1008 | |
---|
1009 | /////////////////////////////////////////////////////////////////////////////// |
---|
1010 | |
---|
1011 | proc rmx(string fname) |
---|
1012 | USAGE: rmx(fname); fname = string |
---|
1013 | RETURN: nothing; removes .log and .aux files associated to file <fname> |
---|
1014 | removes tex and xdvi file too, if suffix ".tex" or ".dvi" is given |
---|
1015 | NOTE: if fname ends by .dvi or .tex |
---|
1016 | fname.dvi or fname.dvi and fname.tex will be deleted, too |
---|
1017 | EXAMPLE: example rmx; shows an example |
---|
1018 | { |
---|
1019 | int i,suffix= 1,0; |
---|
1020 | |
---|
1021 | while (fname[i]==">"){i++;} |
---|
1022 | fname = fname[i,size(fname)-i+1]; |
---|
1023 | |
---|
1024 | if (!(size(fname))) { return();} |
---|
1025 | if (size(fname)>4) |
---|
1026 | { if (fname[size(fname)-3,4]==".tex") { suffix = 2;} |
---|
1027 | if (fname[size(fname)-3,4]==".dvi") { suffix = 1; } |
---|
1028 | fname = fname[1,size(fname)-4]; |
---|
1029 | } |
---|
1030 | system("sh","rm " + fname + ".aux"); |
---|
1031 | system("sh","rm " + fname + ".log"); |
---|
1032 | if (suffix==2) {system("sh","\bin\rm -i " + ".tex");} |
---|
1033 | if (suffix>=1) {system("sh","\bin\rm -i " + ".dvi");} |
---|
1034 | return(); |
---|
1035 | } |
---|
1036 | example |
---|
1037 | { "EXAMPLE:"; echo =2; |
---|
1038 | ring r; |
---|
1039 | poly f = maxideal(7); |
---|
1040 | opentex("exp001"); // defaulted latex2e document |
---|
1041 | texobj("exp001","A polynom",f); |
---|
1042 | closetex("exp001"); |
---|
1043 | tex("exp001"); |
---|
1044 | rmx("exp001"); // removes aux and log file of exp001 |
---|
1045 | |
---|
1046 | opentex("exp002","tex"); // create a texdocument |
---|
1047 | texobj("exp002","A polynom",f); |
---|
1048 | closetex("exp002"); |
---|
1049 | tex("exp002","tex"); |
---|
1050 | rmx("exp002.tex"); // removes aux, log, dvi and tex file of exp002 |
---|
1051 | echo = 0; |
---|
1052 | print("remaining files will be deleted after pressing <RETURN> "); |
---|
1053 | pause; |
---|
1054 | echo = 2; |
---|
1055 | system("sh","rm -i exp00?.*"); |
---|
1056 | } |
---|
1057 | /////////////////////////////////////////////////////////////////////////////// |
---|
1058 | |
---|
1059 | proc xdvi(string fname, list #) |
---|
1060 | USAGE: xdvi(fname[,style]); fname,style = string |
---|
1061 | RETURN: nothing; displays dvi-file fname.dvi with previewer xdvi |
---|
1062 | NOTE: ending .dvi may miss in fname |
---|
1063 | style overwrites the default setting xdvi |
---|
1064 | EXAMPLE: example xdvi ; shows an example |
---|
1065 | { |
---|
1066 | int i=1; |
---|
1067 | string default = "xdvi"; // may be changed appropriatly (C.G.) |
---|
1068 | |
---|
1069 | while (fname[i]==">") {i++;} |
---|
1070 | fname = fname[i,size(fname)-i+1]; |
---|
1071 | |
---|
1072 | if (size(fname)>=4) |
---|
1073 | { if(fname[size(fname)-3,4]==".tex") {fname = fname[1,size(fname)-4];}} |
---|
1074 | if (size(#)) {default = #[1];} |
---|
1075 | "calling ",default, " for :",fname,newline; |
---|
1076 | |
---|
1077 | system("sh",default + " " + fname + " &"); |
---|
1078 | return(); |
---|
1079 | } |
---|
1080 | example |
---|
1081 | { "EXAMPLE:"; echo = 2; |
---|
1082 | ring r; |
---|
1083 | ideal i = maxideal(7); |
---|
1084 | opentex("exp001"); // defaulted latex2e document |
---|
1085 | texobj("exp001","A ideal",i); |
---|
1086 | closetex("exp001"); |
---|
1087 | tex("exp001"); |
---|
1088 | xdvi("exp001"); |
---|
1089 | echo = 0; |
---|
1090 | print("the created files will be deleted after pressing <RETURN> "); |
---|
1091 | pause; |
---|
1092 | echo = 2; |
---|
1093 | system("sh","rm -i exp00?.*"); |
---|
1094 | } |
---|
1095 | /////////////////////////////////////////////////////////////////////////////// |
---|
1096 | |
---|
1097 | proc texpoly(string fname,def p,list #) |
---|
1098 | { |
---|
1099 | def @r = basering; |
---|
1100 | |
---|
1101 | poly f,monom; |
---|
1102 | ideal I; |
---|
1103 | number cfm; |
---|
1104 | string sign,cfmt,pt,s,bg,t,monomt; |
---|
1105 | string sep = newline; |
---|
1106 | int i,b,b2,n, msz,linesz, count,k; |
---|
1107 | int realT, parT, galT; |
---|
1108 | int C = 2 + defined(TeXdisplay); |
---|
1109 | |
---|
1110 | |
---|
1111 | |
---|
1112 | proc parsr(string s) // parse real |
---|
1113 | { string t; |
---|
1114 | |
---|
1115 | if (s==" Inf") { return("\\infty",3);} |
---|
1116 | if (s==" -Inf") { return("\\-infty",6);} |
---|
1117 | if (s[7]=="-"){t ="-";} |
---|
1118 | if (s[8]<>"0"){t = t + s[8];} |
---|
1119 | if (s[9]<>"0" or s[8]<>"0"){t = t + s[9];} |
---|
1120 | if (size(t)) |
---|
1121 | { if (t=="1") {return(s[1,5]+"*10",21);} |
---|
1122 | if (size(t)>1) {return(s[1,5]+"*10^{"+t+"}",21+2*size(t));} |
---|
1123 | else {return(s[1,5]+"*10^"+t,23);} |
---|
1124 | } |
---|
1125 | else {return(s[1,5],12);} |
---|
1126 | } |
---|
1127 | |
---|
1128 | proc parsg(string s) // parse Galoisfield |
---|
1129 | { int i,j = 1,1; |
---|
1130 | string t; |
---|
1131 | |
---|
1132 | if (short) |
---|
1133 | { t =s[1]; |
---|
1134 | if(size(s)>1) {return(t+"^{" + s[2,size(s)-1] + "}",3+2*(size(s)-1));} |
---|
1135 | else{return(t,5);} |
---|
1136 | } |
---|
1137 | else |
---|
1138 | { return(parselong(s+"!"));} |
---|
1139 | } |
---|
1140 | |
---|
1141 | if (defined(TeXdisplay)) { bg = "& ";} |
---|
1142 | if (!(defined(TeXwidth))) { int TeXwidth = -1; export TeXwidth;} |
---|
1143 | if (typeof(p)=="poly" or typeof(p)=="number") {I = p;} |
---|
1144 | if (typeof(p)=="ideal") |
---|
1145 | { I = p; |
---|
1146 | if(size(#)){ sep = #[1];} |
---|
1147 | } |
---|
1148 | |
---|
1149 | if (I==0) |
---|
1150 | { if (!(defined(NoDollars))){return("$0$");} |
---|
1151 | else {return("0");} |
---|
1152 | } |
---|
1153 | |
---|
1154 | //--------------------- |
---|
1155 | |
---|
1156 | |
---|
1157 | //------- set flags: -------------------------------------------------------- |
---|
1158 | |
---|
1159 | if (size(#)) |
---|
1160 | { if (typeof(#[1])=="int") { linesz = #[1];} |
---|
1161 | // if (typeof(#[1])=="string") { linesz = #[1];} |
---|
1162 | } |
---|
1163 | |
---|
1164 | parT = npars(@r); |
---|
1165 | realT = (charstr(@r)=="real"); |
---|
1166 | i = find(charstr(@r),","); |
---|
1167 | if (i) |
---|
1168 | { t = charstr(@r)[1,i-1]; |
---|
1169 | galT = (t <> string(char(@r))); // the char is not the same as the ... |
---|
1170 | } |
---|
1171 | i = 0; |
---|
1172 | |
---|
1173 | //------- parse the polynom |
---|
1174 | pt = bg; |
---|
1175 | |
---|
1176 | for(k=1;k<=size(matrix(I));k++) |
---|
1177 | { i = 0; linesz = 0; count =0; |
---|
1178 | sign =""; |
---|
1179 | f = I[k]; |
---|
1180 | if (f==0) { pt = pt + "0";} |
---|
1181 | while(f<>0) |
---|
1182 | { count++; msz = 0; |
---|
1183 | |
---|
1184 | // ------ tex the coefficient |
---|
1185 | monom = lead(f); |
---|
1186 | f = f - monom; |
---|
1187 | cfm = leadcoef(monom); |
---|
1188 | monom = monom/cfm; // the normalized monom |
---|
1189 | s = string(monom) + "!"; // add an terminating sign |
---|
1190 | cfmt = ""; |
---|
1191 | |
---|
1192 | if (defined(TeXreplace)) { short =0;} // this is essential |
---|
1193 | cfmt = string(cfm); |
---|
1194 | if (size(cfmt)>1) // check if sign is < 0 |
---|
1195 | { if (cfmt[2]=="-") { cfm = (-1) *cfm; sign = "-";}} |
---|
1196 | if (cfmt[1] == "-") { cfm = (-1) * cfm; sign = "-";} |
---|
1197 | if (cfm!=1 or monom==1) {cfmt = string(cfm);} |
---|
1198 | else {cfmt="";} |
---|
1199 | |
---|
1200 | if (defined(TeXwidth) and TeXwidth > 0 and TeXwidth <9 and count> TeXwidth) |
---|
1201 | { pt = pt + sign + "\\dotsb"; break;} |
---|
1202 | // ---------------------------------------- linesz ?? |
---|
1203 | |
---|
1204 | if (size(cfmt)) // parse the coefficient |
---|
1205 | { |
---|
1206 | monomt = cfmt; // (already a good choice for integers) |
---|
1207 | msz = size(cfmt); |
---|
1208 | |
---|
1209 | if(realT) { monomt,msz = parsr(cfmt);} |
---|
1210 | if (galT) { monomt,msz = parsg(cfmt);} |
---|
1211 | b = find(cfmt,")/("); // look if fraction |
---|
1212 | b2 = find(cfmt,"/"); |
---|
1213 | if (b) {b++;} |
---|
1214 | n = size(cfmt); |
---|
1215 | if (!(parT) and !(realT) and !(galT)) |
---|
1216 | { if( !(b2) or defined(TeXnofrac)) |
---|
1217 | {monomt = cfmt; msz = size(monomt);} |
---|
1218 | else |
---|
1219 | { monomt = "\\frac{" + cfmt[1,b2-1] + "}{" + cfmt[b2+1,n-b2] + "}"; |
---|
1220 | if (n-2*b2>0) {msz = C*(n-b2);} |
---|
1221 | else {msz = C*b2;} |
---|
1222 | } |
---|
1223 | } |
---|
1224 | if (parT and !(galT)) |
---|
1225 | { monomt,msz = parsp(cfmt,b);} |
---|
1226 | } |
---|
1227 | |
---|
1228 | // -- now parse the monom |
---|
1229 | if (monom <> 1) |
---|
1230 | { i = 1; |
---|
1231 | if(short) |
---|
1232 | { while(s[i]<>"!") |
---|
1233 | { monomt = monomt + s[i]; i++; |
---|
1234 | b = i; |
---|
1235 | msz = msz + 3; //the was the single lettered var |
---|
1236 | while(s[i]!="!" and s[i]>="0" and s[i]<="9"){i++;} |
---|
1237 | if (i-b) |
---|
1238 | { monomt = monomt + "^{" + s[b,i-b] + "}"; |
---|
1239 | msz = msz + 2*(i-b); |
---|
1240 | } |
---|
1241 | } |
---|
1242 | } |
---|
1243 | else // not short |
---|
1244 | { t,i = parselong(s); |
---|
1245 | monomt = monomt + t; |
---|
1246 | msz = msz + i; |
---|
1247 | } |
---|
1248 | } |
---|
1249 | |
---|
1250 | |
---|
1251 | |
---|
1252 | if (TeXwidth > 10 and (linesz + msz > 2*TeXwidth) and linesz) { |
---|
1253 | pt = pt + "\\\\" + newline +bg; linesz = 0; } |
---|
1254 | else { linesz = linesz + msz; } |
---|
1255 | pt = pt + sign + monomt; |
---|
1256 | sign = "+"; |
---|
1257 | monomt = ""; |
---|
1258 | } |
---|
1259 | |
---|
1260 | if (k<size(matrix(I))){ pt = pt + sep;} |
---|
1261 | } |
---|
1262 | |
---|
1263 | if (not(defined(NoDollars))) { pt = "$"+pt+"$";} |
---|
1264 | |
---|
1265 | if (size(fname)) |
---|
1266 | { i=1; |
---|
1267 | while (fname[i]==">"){i++;} |
---|
1268 | fname = fname[i,size(fname)-i+1]; |
---|
1269 | |
---|
1270 | if (size(fname)>=4) // check if filename is ending with ".tex" |
---|
1271 | { if(fname[size(fname)-3,4]!=".tex") {fname = fname +".tex"; } |
---|
1272 | } |
---|
1273 | else {fname = fname + ".tex";} |
---|
1274 | write(fname,pt); |
---|
1275 | } |
---|
1276 | else {return(pt);} |
---|
1277 | } |
---|
1278 | example |
---|
1279 | { "EXAMPLE:"; echo =2; |
---|
1280 | ring r0=0,(x,y,z),dp; |
---|
1281 | poly f = -1x^2 + 2; |
---|
1282 | texpoly("",f); |
---|
1283 | texpoly("",2x2y23z); |
---|
1284 | |
---|
1285 | |
---|
1286 | ring rr= real,(x,y),dp; |
---|
1287 | |
---|
1288 | ring r7= 7,(x,y,z),dp; |
---|
1289 | poly f = 2x2y23z; |
---|
1290 | texpoly("",f); |
---|
1291 | ring rab =(0,a,b),(x,y,z),dp; |
---|
1292 | poly f = (-2a2 +b3 -2)/a * x2y4z5 + (a2+1)*x + a+1; |
---|
1293 | f; |
---|
1294 | texpoly("",f); |
---|
1295 | } |
---|
1296 | |
---|
1297 | proc parsp(string cfmt, int b) |
---|
1298 | { string mt, nom,denom; |
---|
1299 | int fl1,fl2,sz1,sz2,msz; |
---|
1300 | |
---|
1301 | if (!(b)) |
---|
1302 | { mt,fl1 = parst(cfmt,0); msz = size(cfmt)-2; |
---|
1303 | if (fl1) { mt = "(" + mt + ")"; msz = msz +1; } |
---|
1304 | } |
---|
1305 | else |
---|
1306 | { nom,fl1 = parst(cfmt[1,b-1],1); |
---|
1307 | denom,fl2 = parst(cfmt[b+1,size(cfmt)-b],1); |
---|
1308 | if (defined(TeXnofrac)) |
---|
1309 | { if(fl1) { nom = "(" + nom + ")"; sz1++;} |
---|
1310 | if(fl2) {denom = "(" + denom + ")"; sz2++;} |
---|
1311 | mt = nom+ "/"+ denom; msz = sz1+sz2 +1; |
---|
1312 | } |
---|
1313 | else |
---|
1314 | { mt = "\\frac{" + nom + "}{" + denom + "}"; |
---|
1315 | if (sz1-sz2) { msz = 5*sz1;} |
---|
1316 | else {msz = 5*sz2;} |
---|
1317 | } |
---|
1318 | } |
---|
1319 | return(mt,msz); |
---|
1320 | } |
---|
1321 | example |
---|
1322 | {"EXAMPLE:"; echo =2; |
---|
1323 | ring r=(0,a,b),x,dp; |
---|
1324 | int i; |
---|
1325 | poly f = (a2b12 + 23a2 -b13-1)/(a2+2b -1); |
---|
1326 | f; |
---|
1327 | string s; |
---|
1328 | s= string(f); |
---|
1329 | i = find(s,")/("); |
---|
1330 | parsp(s,i); |
---|
1331 | } |
---|
1332 | |
---|
1333 | proc parst(string s,int sec) // parse parameter |
---|
1334 | // sec parameter to see if in parsp a fraction follows |
---|
1335 | { int i,j =1,-1; |
---|
1336 | int b,k,jj,mz; // begin and end |
---|
1337 | int saveshort=short; |
---|
1338 | string t,c,vn,nom,denom,sg; |
---|
1339 | |
---|
1340 | s = s[2,size(s)-2]; s = s + "!"; |
---|
1341 | |
---|
1342 | if(defined(TeXreplace)){ short =0;} // only then replacing works correctly |
---|
1343 | if (short) |
---|
1344 | { while(s[i]<>"!") |
---|
1345 | { b=i; j++; |
---|
1346 | while(s[i]>="0" and s[i]<="9" or (s[i]=="+" or s[i]=="-") and s[i]!="!") |
---|
1347 | {i++;} // scan the number |
---|
1348 | t =s[b,i-b]; |
---|
1349 | // if (t=="-1" and s[i]!="!" and s[i]!="-" and s[i]!="+"){t = "-";} |
---|
1350 | if (t=="-1" and (s[i]<="0" or s[i]>="9") and s[i]!= "/" and s[i]!="!") |
---|
1351 | { |
---|
1352 | t = "-";} |
---|
1353 | if (s[i]=="/") |
---|
1354 | { i++; |
---|
1355 | sg = ""; |
---|
1356 | if (t[1]=="+" or t[1]=="-") |
---|
1357 | { nom = t[2,size(t)-1]; |
---|
1358 | sg = t[1]; |
---|
1359 | } |
---|
1360 | else { nom = t;} |
---|
1361 | b =i; |
---|
1362 | while(s[i]>="0" and s[i]<="9") {i++;} |
---|
1363 | denom = s[b,i-b]; |
---|
1364 | if (!(sec) and (!(defined(TeXaligned)))) |
---|
1365 | { t = sg + "\\frac{" + nom + "}{" + denom + "}";} |
---|
1366 | else |
---|
1367 | { t = sg + "(" + nom + "/" + denom + ")"; |
---|
1368 | } |
---|
1369 | } |
---|
1370 | c = c + t; |
---|
1371 | if(s[i]!="!"){c = c + s[i]; i++;} // the parameter |
---|
1372 | b=i; |
---|
1373 | while(s[i]>="0" and s[i]<="9") |
---|
1374 | {i++;} //the exponent |
---|
1375 | if(i-b){ c = c + "^{" + s[b,i-b]+"}";} |
---|
1376 | } |
---|
1377 | } |
---|
1378 | else // if not short .... |
---|
1379 | { while (s[i] <> "!") |
---|
1380 | { b=i; j++; |
---|
1381 | while(s[i]=="-" or s[i]=="+" or (s[i]>="0" and s[i]<="9")){i++;} |
---|
1382 | t = s[b,i-b]; |
---|
1383 | if (t=="-1" and s[i]=="*" ) {t="-";} |
---|
1384 | if (s[i]=="/") |
---|
1385 | { i++; |
---|
1386 | sg = ""; |
---|
1387 | if (t[1]=="+" or t[1]=="-") |
---|
1388 | { nom = t[2,size(t)-1]; |
---|
1389 | sg = t[1]; |
---|
1390 | } |
---|
1391 | else { nom = t;} |
---|
1392 | b =i; |
---|
1393 | while(s[i]>="0" and s[i]<="9") {i++;} |
---|
1394 | denom = s[b,i-b]; |
---|
1395 | if (!(sec) and (!(defined(TeXaligned)))) |
---|
1396 | { t = sg + "\\frac{" + nom + "}{" + denom + "}";} |
---|
1397 | else |
---|
1398 | { t = sg + "(" + nom + "/" + denom + ")"; |
---|
1399 | } |
---|
1400 | } |
---|
1401 | c = c+t; t=""; |
---|
1402 | if (s[i]=="*"){i++;} |
---|
1403 | b=i; |
---|
1404 | while(s[i]!="+" and s[i]!="-" and s[i]!="!") //pass a monom |
---|
1405 | { // start with letters |
---|
1406 | // alternativ: |
---|
1407 | while((s[i]>="a" and s[i]<="z") or (s[i]>="A" and s[i]<="Z")){i++;} |
---|
1408 | k = i-b; |
---|
1409 | vn = s[b,k]; |
---|
1410 | if (defined(TeXreplace)) |
---|
1411 | { for (jj=1; jj<= size(TeXreplace);jj++) |
---|
1412 | { if (vn == TeXreplace[jj][1]) |
---|
1413 | {vn = TeXreplace[jj][2]; k=1; |
---|
1414 | if (s[i]=="*") {vn = vn + " ";} |
---|
1415 | break;} //suppose replacing by a single sign |
---|
1416 | } |
---|
1417 | } |
---|
1418 | t = t + vn; |
---|
1419 | mz = mz + 10*k; |
---|
1420 | if (s[i]=="_" or s[i]=="(") { i++;} // the index is coming |
---|
1421 | b = i; |
---|
1422 | while(s[i]>="0" and s[i]<="9"){ i++;} |
---|
1423 | k = i-b; |
---|
1424 | if (k){ t = t + "_{" +s[b,k] + "}";} |
---|
1425 | if(s[i]==")") {i++;} |
---|
1426 | if (s[i]=="^") |
---|
1427 | { i++; b = i; |
---|
1428 | while(s[i]>="0" and s[i]<="9"){ i++;} // for neg. expon. |
---|
1429 | if (b-i) { t = t + "^{" + s[b,i-b] + "}";} |
---|
1430 | } |
---|
1431 | if (i-b > k) { mz = mz + 5*(i-b);} |
---|
1432 | else {mz = mz + 5*k;} |
---|
1433 | if (s[i]=="*"){i++;} |
---|
1434 | b=i; |
---|
1435 | } |
---|
1436 | c =c+t; |
---|
1437 | } |
---|
1438 | } |
---|
1439 | short = saveshort; |
---|
1440 | return(c,j); |
---|
1441 | } |
---|
1442 | example |
---|
1443 | { "EXAMPLE:"; echo =2; |
---|
1444 | ring r=(0,a,b),x,dp; |
---|
1445 | poly f = (a2b12 + 23a2 -b13-1); |
---|
1446 | f; |
---|
1447 | parst(string(f)); |
---|
1448 | |
---|
1449 | f =(-a +4b2 -2); |
---|
1450 | f; |
---|
1451 | parst(string(f)); |
---|
1452 | |
---|
1453 | f = a23; |
---|
1454 | f; |
---|
1455 | parst(string(f)); |
---|
1456 | f = 2a12b3 -4ab15 +2a4b12 -2; |
---|
1457 | short =0; |
---|
1458 | f; |
---|
1459 | parst(string(f)); |
---|
1460 | ring r2=(0,a1,b1),x,dp; |
---|
1461 | poly f = 2*a1^12*b1^3 -4*a1*b1^15 +2*a1^4*b1^12 -2; |
---|
1462 | f; |
---|
1463 | parst(string(f)); |
---|
1464 | } |
---|
1465 | |
---|
1466 | |
---|
1467 | proc parselong(string s) |
---|
1468 | { |
---|
1469 | int i,j,k,b,mz; |
---|
1470 | string t,vn; // varname |
---|
1471 | |
---|
1472 | // "s=" + s; |
---|
1473 | i = 1; |
---|
1474 | while (s[i] <> "!") |
---|
1475 | { b=i; |
---|
1476 | |
---|
1477 | // -- scan now the letter ... |
---|
1478 | |
---|
1479 | // while(s[i]!="!" and ) |
---|
1480 | |
---|
1481 | // alternativ: |
---|
1482 | while((s[i]>="a" and s[i]<="z") or (s[i]>="A" and s[i]<="Z")) |
---|
1483 | { i++;} |
---|
1484 | // s[i]; i; |
---|
1485 | k = i-b; |
---|
1486 | vn = s[b,k]; |
---|
1487 | |
---|
1488 | if (defined(TeXreplace)) |
---|
1489 | { for (j=1; j<= size(TeXreplace);j++) |
---|
1490 | { if (vn == TeXreplace[j][1]) |
---|
1491 | {vn = TeXreplace[j][2]; k=1; |
---|
1492 | if (s[i]=="*") {vn = vn + " ";} |
---|
1493 | break;} //suppose replacing by a single sign |
---|
1494 | } |
---|
1495 | } |
---|
1496 | t = t + vn; |
---|
1497 | mz = mz + 10*k; |
---|
1498 | if (s[i]=="_" or s[i]=="(") { i++;} // the index is coming |
---|
1499 | b = i; |
---|
1500 | while(s[i]>="0" and s[i]<="9"){ i++;} |
---|
1501 | j = i-b; |
---|
1502 | if (j){ t = t + "_{" +s[b,j] + "}";} |
---|
1503 | if(s[i]==")") {i++;} |
---|
1504 | if (s[i]=="^") |
---|
1505 | { i++; b = i; |
---|
1506 | while(s[i]>="0" and s[i]<="9" or s[i]=="-") |
---|
1507 | { i++;} // for neg. expon. |
---|
1508 | if (b-i) { t = t + "^{" + s[b,i-b] + "}";} |
---|
1509 | } |
---|
1510 | if (i-b > j) { mz = mz + 5*(i-b);} |
---|
1511 | else {mz = mz + 5*j;} |
---|
1512 | if (s[i]=="*"){i++;} |
---|
1513 | } |
---|
1514 | return(t,mz); |
---|
1515 | } |
---|
1516 | example |
---|
1517 | { "EXAMPLE:"; echo =2; |
---|
1518 | ring r =(49,a),x,dp; |
---|
1519 | number f = a13; |
---|
1520 | parsg(string(f)); |
---|
1521 | list TeXreplace; export TeXreplace; |
---|
1522 | TeXreplace[1] = list("b","\\beta"); |
---|
1523 | TeXreplace[2] = list("a","\\alpha"); |
---|
1524 | TeXreplace[3] = list("c","\\gamma"); |
---|
1525 | parselong(string(f)+"!"); |
---|
1526 | } |
---|
1527 | /////////////////////////////////////////////////////////////////////////////// |
---|
1528 | |
---|