Ticket #731: latex.lib

File latex.lib, 86.1 KB (added by gorzel, 9 years ago)

bugfix for denominators

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