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