source: git/Singular/LIB/latex.lib @ 63be42

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