source: git/Singular/LIB/latex.lib @ a5a8a1

spielwiese
Last change on this file since a5a8a1 was 1057ab5, checked in by Hans Schoenemann <hannes@…>, 14 years ago
new version git-svn-id: file:///usr/local/Singular/svn/trunk@13477 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 86.0 KB
Line 
1///////////////////////////////////////////////////////////////////////////////
2version="$Id$";
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 = attrib(obj[j],"ineq");
766            if(!(size(ineq))) { ineq = "=" ; }
767            l = texpoly("",obj[j]-h) + " & " + ineq + " & " + texpoly("",-h);
768            if(j<size(obj)) { l = l + " \\\\";}
769            s =s+ l + newline;
770           }
771          s = s + "\\end{array}" + newline;
772        }
773        else   // linear
774        { s = s +
775   "\\begin{array}{*{" + string(2*nvars(basering)-1) + "}{c}cr}" + newline;
776           for(j=1; j<=size(obj);j++)
777           { h = jet(obj[j],0);   // absterm
778             ineq = attrib(obj[j],"ineq");
779             if(!(size(ineq))) { ineq = "=" ; }
780              l = ""; nc = 0;
781              for (i=1; i<=nvars(basering);i++)
782              { t = " "; sg ="";
783                g = obj[j]-subst(obj[j],var(i),0);
784                if (g!=0) { t = texpoly("",g);}
785                if (i>1)
786                { if (t[1]!="-" and t[1]!= " " and nc ){sg = "+";}
787                  if  (t[1]=="-") { sg = "-"; nc =1; t=t[2,size(t)-1];}
788                  if (t==" ") {sg ="";}
789                  l = l + " & " + sg + " & " + t;
790                }
791                else { l = t;}
792                if (g!=0) {nc = 1;}
793               }
794
795               l = l + " & " + ineq + " & " + texpoly("",-h);
796             if (j < size(obj)) { l = l + " \\\\";}
797             s = s + l + newline;
798            } // end for (j)
799          s = s + "\\end{array}";
800         }  // end else linear
801        TeXwidth = 0;
802       } // end TeXwidth == 0
803   else // TeXwidth <> 0
804   { s =  s + "\\left"+ OB;
805     if (defined(TeXaligned))
806     { s = s + texpoly("",obj,",");
807     }
808     else
809     { s = s + newline + "\\begin{array}{c}" + newline +
810               texpoly("",obj,", \\\\" + newline) +
811                newline + "\\end{array}" + newline;
812     }
813    s = s + "\\right" + CB;
814    } // end TeXwidth <> 0
815   }  // not Iname
816// s;
817  }
818
819   if (typeof(obj) == "module")
820   { M = matrix(obj);
821     if (Tw ==0 or Tw > 9) { TeXwidth = -1;}
822     s = s + "\\left" + OB + newline;
823     if (!(defined(TeXaligned)))
824     {  // Naechste Zeile nicht notwendig !
825     // s = s + "\\begin{array}{*{"+ string(ncols(M)) + "}{c}}" + newline;
826      for(j=1;j<=ncols(M);j++)
827      { l = "\\left" + OB + newline + "\\begin{array}{c}" + newline;
828        l = l + texpoly("",ideal(M[1..nrows(M),j]), " \\\\" + newline)
829              + newline + "\\end{array}" +newline + "\\right" + CB + newline;
830        if (j< ncols(M)) { l = l + " , " + newline;}
831        s = s + l ;
832      }
833     }
834     else    // TeXaligned
835     {
836      for(j=1;j<=ncols(M);j++)
837      { s = s + "\\left" + OB + newline +
838           texpoly("",ideal(M[1..nrows(M),j]),",") + newline + "\\right" + CB;
839        if (j<ncols(M)) { s = s + "," + newline; }
840      }
841     }
842    s = s  + "\\right" + CB + newline;
843   } // module part
844
845   if (typeof(obj) == "matrix")
846   { if (Tw==0 or Tw > 9) {TeXwidth = -1;}
847     l = "";
848   //  M = transpose(obj);
849     s = s + "\\left" + OB + newline +
850             "\\begin{array}{*{"+ string(ncols(obj)) + "}{c}" + "}"+ newline;
851     for(i=1;i<=nrows(obj);i++)
852     { l = l + texpoly("",ideal(obj[i,1..ncols(obj)])," & ");
853       if (i<nrows(obj)) { l = l + " \\\\" + newline;}
854     }
855     l = l + newline;
856     s = s + l + "\\end{array}" + newline +
857                 "\\right" + CB + newline;
858    TeXwidth = Tw;
859  }
860
861   if (typeof(obj) == "intmat")
862   { nr,nc = nrows(obj),ncols(obj);
863     l = "";
864     l =  "\\left" + OB + newline +
865          "\\begin{array}{*{"+ string(nc) + "}{r}}"+ newline;
866     for(i=1;i<=nr;i++)
867     { for(j=1;j<=nc;j++)
868       { l = l + string(obj[i,j]);
869         if (j <nc ) { l = l + " & ";}
870         else {if( i < nr) { l = l + "\\\\" + newline;}}
871       }
872     }
873     l = l + newline + "\\end{array}" + newline +
874             "\\right" + CB + newline;
875    s = s + l;
876  }
877
878  if (typeof(obj) == "ring" or
879      typeof(obj) == "qring") { s = s + D + texring("",obj) + D + newline;}
880
881  kill obj;
882 }
883
884 s = s +  DE;// + newline;
885
886 if(!(ND)) { kill NoDollars;}  // kill Latex::
887 if(!(TW)) { kill TeXwidth;}   // kill Latex::
888
889 if(size(fname))
890 { i=1;
891  while (fname[i]==">"){i++;}
892  fname = fname[i,size(fname)-i+1];
893  if (size(fname)>=4)               // check if filename is ending with ".tex"
894  { if(fname[size(fname)-3,4]!=".tex") {fname = fname +".tex"; }
895  }
896  else {fname = fname + ".tex";}
897  write(fname,s);
898 }
899 else {return(s);}
900}
901example
902{
903   echo=0;
904   // -------- prepare for example ---------
905   if (defined(TeXaligned)) {int Teali=TeXaligned; kill TeXaligned;}
906   if (defined(TeXbrack)){string Tebra=TeXbrack; kill TeXbrack;}
907   "EXAMPLE:"; echo = 2;
908   //
909   //  --------------  typesetting for polynomials ----------
910   ring r = 0,(x,y),lp;
911   poly f = x5y3 + 3xy4 + 2xy2 + y6;
912   f;
913   texobj("",f);
914   pause();
915   //  --------------  typesetting for ideals ----------
916   ideal G = jacob(f);
917   G;
918   texobj("",G);
919   pause();
920   //  --------------  variation of typesetting for ideals ----------
921   int TeXaligned = 1; export TeXaligned;
922   string TeXbrack = "<"; export TeXbrack;
923   texobj("",G);
924   pause();
925   kill TeXaligned, TeXbrack;
926   //  --------------  typesetting for matrices ----------
927   matrix J = jacob(G);
928   texobj("",J);
929   pause();
930   //  --------------  typesetting for intmats ----------
931   intmat m[3][4] = 9,2,4,5,2,5,-2,4,-6,10,-1,2,7;
932   texobj("",m);
933   echo=0;
934   //
935   // --- restore global variables if previously defined ---
936   if (defined(Teali)){int TeXaligned=Teali; export TeXaligned; kill Teali;}
937   if (defined(Tebra)){string TeXbrack=Tebra; export TeXbrack; kill Tebra;}
938}
939///////////////////////////////////////////////////////////////////////////////
940
941proc texproc(string fname,string pname)
942"USAGE:   texproc(fname,pname); fname,pname strings
943ASSUME:  @code{`pname`} is a procedure.
944RETURN:  if @code{fname=\"\"}: string, the proc @code{`pname`} in a verbatim
945         environment in LaTeX-typesetting;@*
946         otherwise: append this string to the file @code{<fname>}, and
947         return nothing.
948NOTE:    preceding \">>\" are deleted in @code{fname}, and suffix \".tex\"
949         (if not given) is added to @code{fname}.@*
950EXAMPLE: example texproc; shows an example
951"
952{
953  int i,j,k,nl;
954  string @p,s,t;
955
956  j = 1;
957
958  if (defined(`pname`))
959  { if (typeof(`pname`)=="proc")
960    { @p = string(`pname`);
961      nl = find(@p,newline);
962      s = "\\begin{verbatim}" + newline;
963      s = s + "proc " + pname + "(";
964      i = find(@p,"parameter");       // collecting the parameters
965      k = find(@p,"alias");           // and the alias arguments
966      while((i and i < nl) or (k and k < nl))
967      {
968        if (i and (k==0  or i<k))
969        {
970         j=find(@p,";",i);
971         t = @p[i+10,j-i-10];
972         if(i>1){s = s + ",";};
973         s = s + t;
974        }
975        if (k and (i==0  or k<i))
976        {
977         j=find(@p,";",k);
978         t = @p[k,j-k];
979         if(k>1){s = s + ",";};
980         s = s + t;
981        }
982        i = find(@p,"parameter",j);
983        k = find(@p,"alias",j);
984      }
985      s = s + ")" + newline;
986     j++;                      // skip one for the newline
987     i = find(@p,";"+"return();"+newline,j);
988     if (!(i))
989     { i = find(@p,";"+"RETURN();"+newline,j); }  // j kann hier weg
990     s = s + "{" + @p[j,i-j-1] + "}" + newline;
991     s = s + "\\end{verbatim}" + newline;
992   }
993  }
994  else
995  { print(" // -- Error: No such proc defined");
996    return();
997  }
998  if(size(fname))
999  { i=1;
1000    while (fname[i]==">"){i++;}
1001    fname = fname[i,size(fname)-i+1];
1002    if (size(fname)>=4)        // check if filename is ending with ".tex"
1003    { if(fname[size(fname)-3,4]!=".tex") {fname = fname +".tex"; }
1004    }
1005    else {fname = fname + ".tex";}
1006    write(fname,s);
1007  }
1008  else{return(s);}
1009}
1010example
1011{ "EXAMPLE:"; echo=2;
1012  texproc("","texproc");
1013}
1014
1015///////////////////////////////////////////////////////////////////////////////
1016
1017static proc tvar(intvec v)
1018{
1019  int i,j,ldots;
1020  string s;
1021  j = 1;
1022  s = texpoly("",var(1));
1023
1024  if (nvars(basering)==1) { return(s);}
1025  if (nvars(basering)==2) { return(s + "," + texpoly("",var(2)));}
1026  if (size(v)==1 and v[1] == 1)
1027     {return(s + ",\\ldots,"+ texpoly("",var(nvars(basering))));}
1028  if (v[1]==1 and size(v) >1) {j++;}
1029  for(i=2;i<nvars(basering);i++)
1030  { if (i<v[j]  and !(ldots))
1031    { s = s + ",\\ldots";
1032      ldots =1;
1033    }
1034    if (i== v[j])
1035    { s = s + "," + texpoly("",var(i));
1036      ldots =0;
1037      if (j< size(v)) {j++;}
1038    }
1039  }
1040  if (v[j]<nvars(basering)-1) { s = s + ",\\ldots";}
1041  return(s + "," + texpoly("",var(nvars(basering))));
1042}
1043///////////////////////////////////////////////////////////////////////////////
1044
1045proc texring(string fname, def r, list #)
1046"USAGE:   texring(fname, r[,L]); fname string, r ring, L list
1047RETURN:  if @code{fname=\"\"}: string, the ring in TeX-typesetting;@*
1048         otherwise: append this string to the file @code{<fname>} and
1049         return nothing.
1050NOTE:    preceding \">>\" are deleted and suffix \".tex\" (if not given)
1051         is added to @code{fname}.@*
1052         The optional list L is assumed to be a list of strings which control,
1053         for instance the symbol for the field of coefficients.@*
1054         For more details call @code{texdemo();} (generates a LaTeX2e
1055         file called @code{texlibdemo.tex} which explains all features of
1056         @code{texring}).
1057EXAMPLE: example texring; shows an example
1058"
1059{
1060  int i,galT,intT,flag,mipo,nopar,Dollars,TB,TA;
1061  string ob,cb,cf,en,s,t,savebrack; //opening bracket, closing br, coef.field
1062  intvec v;
1063
1064  setring r;
1065  if (!(defined(NoDollars))){ Dollars = 1; int NoDollars; export NoDollars;}
1066  ob,cb = "[","]";
1067  if (find(ordstr(r),"s")) { ob,cb="[[","]]";}
1068  if(char(r)==0){cf="\\Q";}
1069  if(find(charstr(r),"integer"))    // 4.10.10
1070  {
1071    intT=1;
1072    cf="\\Z";
1073    if (char(r)>0) { cf=cf+"_{"+string(char(r))+"}";}
1074  }
1075  if(find(charstr(r),"real")){cf="\\R";}
1076  if(find(charstr(r),"complex")){cf="\\C"; nopar=1;}   // 28.10.06
1077  if(char(r)==prime(char(r))){cf="\\Z_{"+string(char(r))+"}";}
1078  if(char(r)>0 and !intT)
1079  { i = find(charstr(r),",");
1080    if(i)
1081    { t= charstr(r)[1,i-1];
1082      galT = (t <> string(char(r)));
1083      if (galT) { cf = "\\F_{"+ t + "}";}
1084    }
1085  }     // all other cases are cover already by char(r)=? prime(char)
1086
1087  if (size(#))
1088  { if (typeof(#[1])=="list") { # = #[1];}
1089  }
1090  for (i=1;i<=size(#);i++)
1091  { flag =0;
1092    if(typeof(#[i])=="string")
1093    {
1094     if(#[i][1]=="^" or #[i][1]=="_"){en=en+#[i];flag = 1;}
1095     if(#[i]=="mipo"){mipo=1; 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="[[","]]";flag=1;}
1100     if(#[i]=="<"){ob,cb="<",">";flag=1;}
1101     if(#[i]=="<<"){ob,cb="{\\ll}","{\\gg}";flag=1;}
1102     if(#[i]=="C"){cf="\\C";flag=1;}
1103     if(#[i]=="Q"){cf="\\Q";flag=1;}
1104     if((#[i]=="k" or #[i]=="K" or #[i]=="R") and !(galT))
1105                   {cf=#[i]; flag=1; nopar=1;}
1106     if (flag!=1) {cf = #[i];}  // for all the cases not covered here e.g Z_(p)
1107    }                           // or Q[i]
1108
1109    if ((typeof(#[i])=="intvec") or
1110        (typeof(#[i])=="int")){v=#[i];}
1111   }
1112  s = cf;
1113 // now the parameters
1114 // t;
1115  if(npars(r) and ((t==string(char(r))) or char(r)==0) and !(nopar))
1116  {
1117   s = s + "(";                      // !! mit ideal !!
1118   for(i=1;i<npars(r);i++) {s = s + texpoly("",par(i)) + ",";}
1119   s = s + texpoly("",par(npars(r))) + ")";
1120  }                               // parameters done
1121  if (!(galT) and mipo and minpoly!=0)
1122  { s = s + "/" + list(parsp(string(minpoly),0))[1];}
1123  s = s + ob;
1124  if (v!=0 and nvars(r)>3)
1125  { s = s + tvar(v);}
1126  else
1127  { s = s + texpoly("",maxideal(1),","); }
1128   s = s + cb + en;
1129
1130  if (typeof(r)=="qring")
1131  { ideal @I = ideal(r);
1132    if (defined(TeXbrack))
1133    {
1134      TB =1; savebrack = TeXbrack;
1135      if (TeXbrack!= "<" and TeXbrack!="(") { TeXbrack = "<";}
1136    }
1137    TA = defined(TeXaligned);
1138    if (!(TA)) { int TeXaligned; export TeXaligned; }
1139    t = texobj("",@I);
1140 //   @I;
1141 //   t;
1142    if (TB) { TeXbrack = savebrack;}
1143    if (!(TA)) { kill TeXaligned;}  // kill Latex::
1144    s = s + "/" + t;
1145  }
1146
1147  if (Dollars)
1148  { kill NoDollars;   // kill Latex::
1149    s =  "$" + s + "$";
1150  }
1151  if (size(fname))
1152  { i=1;
1153     while (fname[i]==">"){i++;}
1154     fname = fname[i,size(fname)-i+1];
1155
1156     if (size(fname)>=4)           // check if filename is ending with ".tex"
1157     { if(fname[size(fname)-3,4]!=".tex") {fname = fname +".tex"; }
1158     }
1159     else {fname = fname + ".tex";}
1160     write(fname,s);
1161  }
1162  else{return(s);}
1163}
1164example
1165{ "EXAMPLE:"; echo=2;
1166  ring r0 = 0,(x,y),dp;                // char = 0, polynomial ordering
1167  texring("",r0);
1168  //
1169  ring r7 =7,(x(0..2)),ds;             // char = 7, local ordering
1170  texring("",r7);
1171  //
1172  ring r1 = 0,(x1,x2,y1,y2),wp(1,2,3,4);
1173  texring("",r1);
1174  //
1175  ring rr = real,(x),dp;               // real numbers
1176  texring("",rr);
1177  //
1178  ring rC = complex,x,dp;              // complex coefficients
1179  texring("",rC);
1180  //
1181  pause();
1182
1183  ring rabc =(0,t1,t2,t3),(x,y),dp;    // ring with parameters
1184  texring("",rabc);
1185  //
1186  ring ralg = (7,a),(x1,x2),ds;        // algebraic extension
1187  minpoly = a2-a+3;
1188  texring("",ralg);
1189  texring("",ralg,"mipo");
1190  //
1191  ring r49=(49,a),x,dp;                // Galois field
1192  texring("",r49);
1193  //
1194  setring r0;                          // quotient ring
1195  ideal i = x2-y3;
1196  qring q = std(i);
1197  texring("",q);
1198  //
1199  pause();
1200
1201  // ------------------ additional features -------------------
1202  ring r9 =0,(x(0..9)),ds;
1203  texring("",r9,1);
1204  texring("",r9,"C","{","^G");
1205  //
1206  ring rxy = 0,(x(1..5),y(1..6)),ds;
1207  intvec v = 5,6;
1208  texring("",rxy,v);
1209}
1210///////////////////////////////////////////////////////////////////////////////
1211
1212proc rmx(string fname)
1213"USAGE:   rmx(fname); fname string
1214RETURN:  nothing; removes the @code{.log} and @code{.aux} files associated to
1215         the LaTeX file <fname>.@*
1216NOTE:    If @code{fname} ends by @code{\".dvi\"} or @code{\".tex\"}, the
1217         @code{.dvi} or @code{.tex} file will be deleted, too.
1218EXAMPLE: example rmx; shows an example
1219"
1220{
1221  int i,suffix= 1,0;
1222  int retval;
1223
1224  if (size(fname))
1225  {
1226   while (fname[i]==">"){i++;}
1227   fname = fname[i,size(fname)-i+1];
1228   if (size(fname)>4)
1229   { if (fname[size(fname)-3,4]==".tex") { suffix = 2;}
1230     if (fname[size(fname)-3,4]==".dvi") { suffix = 1; }
1231     if (suffix) { fname = fname[1,size(fname)-4]; }
1232   }
1233   retval = system("sh","rm " + fname + ".aux");
1234   retval = system("sh","rm " + fname + ".log");
1235   if (suffix==2) {retval = system("sh","/bin/rm -i " + fname +".tex");}
1236   if (suffix>=1) {retval = system("sh","/bin/rm -i " + fname +".dvi");}
1237  }
1238  else
1239  {" -- Need a filename ";
1240    return();
1241  }
1242}
1243example
1244{ "EXAMPLE:"; echo =2;
1245  ring r;
1246  poly f = x+y+z;
1247  opentex("exp001");              // defaulted latex2e document
1248  texobj("exp001","A polynom",f);
1249  closetex("exp001");
1250  tex("exp001");
1251  rmx("exp001");   // removes aux and log file of exp001
1252  echo = 0;
1253  pause("remaining files will be deleted after pressing <RETURN>");
1254  echo = 2;
1255  system("sh","rm exp001.*");
1256}
1257///////////////////////////////////////////////////////////////////////////////
1258
1259proc xdvi(string fname, list #)
1260"USAGE:   xdvi(fname[,style]); fname,style = string
1261RETURN:  nothing; displays dvi-file fname.dvi with previewer xdvi
1262NOTE:    suffix .dvi may be omitted in fname
1263         style captures the program that will be called instead of the default (xdvi)
1264EXAMPLE: example xdvi; shows an example
1265"
1266{
1267  int i=1;
1268  int retval;
1269  string default = "xdvi";
1270
1271  if (size(#)) {default = string(#[1]);}
1272
1273  if (size(fname))
1274  {
1275   while (fname[i]==">") {i++;}
1276   fname = fname[i,size(fname)-i+1];
1277
1278   if (size(fname)>=4)
1279   { if(fname[size(fname)-3,4]==".tex") {fname = fname[1,size(fname)-4];}}
1280
1281   "calling ",default, " for :",fname,newline;
1282
1283   if (default=="latex2e")
1284   {
1285     retval = system("sh","latex " +  fname +" &");
1286   }
1287   else
1288   {
1289     retval = system("sh",default + " " +  fname +" &");
1290   }
1291  }
1292  else
1293  { " -- Need a filename ";
1294    return();
1295  }
1296}
1297example
1298{ "EXAMPLE:"; echo = 2;
1299  intmat m[3][4] = 9,2,4,5,2,5,-2,4,-6,10,-1,2,7;
1300  opentex("exp001");
1301  texobj("exp001","An intmat:  ",m);
1302  closetex("exp001");
1303  tex("exp001");
1304  xdvi("exp001");
1305  echo = 0;
1306  pause("the created files will be deleted after pressing <RETURN>");
1307  echo = 2;
1308  system("sh","rm exp001.*");
1309}
1310///////////////////////////////////////////////////////////////////////////////
1311
1312static proc parsr(string s)                     // parse real
1313{
1314  string t;
1315  if (s=="      Inf") { return("\\infty",3);}
1316  if (s=="     -Inf") { return("\\-infty",6);}
1317  if (s[7]=="-"){t ="-";}
1318  if (s[8]<>"0"){t = t + s[8];}
1319  if (s[9]<>"0" or s[8]<>"0"){t = t + s[9];}
1320  if (size(t))
1321  { if (t=="1") {return(s[1,5]+"*10",21);}
1322    if (size(t)>1) {return(s[1,5]+"*10^{"+t+"}",21+2*size(t));}
1323    else {return(s[1,5]+"*10^"+t,23);}
1324  }
1325  else
1326  {
1327    return(s[1,5],12);
1328  }
1329}
1330///////////////////////////////////////////////////////////////////////////////
1331
1332static proc parsg(string s)                  // parse Galois field
1333{
1334  string t;
1335
1336  if (s=="1") {return("1",5);}
1337  if (short)
1338  {
1339    t =s[1];
1340    if(size(s)>1) {return(t+"^{" + s[2,size(s)-1] + "}",3+2*(size(s)-1));}
1341    else{return(t,5);}
1342  }
1343  else
1344  {
1345    return(parselong(s+"!"));
1346  }
1347}
1348///////////////////////////////////////////////////////////////////////////////
1349
1350proc texpoly(string fname,def p,list #)
1351"USAGE:   texpoly(fname,p); fname string, p poly
1352RETURN:  if @code{fname=\"\"}: string, the polynomial p in LaTeX-typesetting;@*
1353         otherwise: append this string to the file @code{<fname>}, and
1354         return nothing.
1355NOTE:    preceding \">>\" are deleted in @code{fname}, and suffix \".tex\"
1356         (if not given) is added to @code{fname}.
1357EXAMPLE: example texpoly; shows an example
1358"
1359{
1360  def @r = basering;
1361
1362  poly f,monom;
1363  ideal I;
1364  number cfm;
1365  string sign,cfmt,pt,s,bg,t,monomt,lnbreak;
1366  string sep = newline;
1367  int i,b,b2,n, msz,linesz, count,k;
1368  int realT, parT, galT, complT;
1369  int TW = defined(TeXwidth);
1370
1371  int C = 2 + defined(TeXdisplay);
1372
1373  string notvalid = "intvec intmat vector matrix module map";
1374
1375  if (typeof(p) == "int") { return(p);}
1376  if (typeof(p)  == "ring" or typeof(p) == "qring")
1377  { " -- Call  texring  instead "; return();}
1378  if (find(notvalid,typeof(p)))
1379  { " -- Call  texobj  instead "; return();}
1380  if (typeof(p)  == "map")
1381  { " -- Call  texmap  instead "; return();}
1382  if (typeof(p)  == "proc")
1383  { " -- Call  texmap  instead "; return();}
1384  if (typeof(p)  == "link" or typeof(p) == "list" or typeof(p) == "resolution")
1385  { ERROR(" // -- Object cannot translated into tex "); return();}
1386
1387  if (!(defined(TeXdisplay))){ lnbreak = "\\\\[2mm]" + newline;}
1388  else { lnbreak = "\\\\" + newline;}
1389
1390
1391  if (defined(TeXdisplay)) { bg = "& ";}
1392  if (!TW) { int TeXwidth = -1; export TeXwidth;}
1393
1394// -- Type check
1395
1396 if (typeof(p)=="string")
1397  { if(defined(`p`))
1398    { pt = p + " = ";
1399      p = `p`;
1400    }
1401  }
1402  if (typeof(p)=="poly" or typeof(p)=="number") {I = p;}
1403
1404  if (typeof(p)=="ideal")
1405  { I = p;
1406    if(size(#)){ sep = #[1];}
1407  }
1408
1409  if (I==0)
1410  { if (!(defined(NoDollars))){return("$0$");}
1411    else {return("0");}
1412  }
1413
1414// -- Type check ende
1415
1416//---------------------
1417
1418//------- set flags: --------------------------------------------------------
1419
1420  if (size(#))
1421  { if (typeof(#[1])=="int") { linesz = #[1];}
1422 //   if (typeof(#[1])=="string") { linesz = #[1];}
1423  }
1424
1425  parT = npars(@r);
1426  realT = (charstr(@r)=="real");
1427  complT = find(charstr(@r),"complex");   // 28.10.06
1428  if (complT) {parT=0;}
1429  i = find(charstr(@r),",");
1430  if (i and !realT and !complT)
1431  { t = charstr(@r)[1,i-1];
1432    galT = (t <> string(char(@r)));  // the char is not the same as the ...
1433  }
1434  i = 0;
1435
1436//------- parse the polynomial
1437  pt = bg;
1438
1439 for(k=1;k<=ncols(I);k++)
1440 { i = 0; linesz = 0; count =0;
1441   sign ="";
1442   f = I[k];
1443   if (f==0) { pt = pt + "0";}
1444  while(f<>0)
1445  { count++; msz = 0;
1446
1447// ------ tex the coefficient
1448    monom = lead(f);
1449    f = f - monom;
1450    cfm = leadcoef(monom);
1451    if (cfm*1 != 0) { monom = leadmonom(monom);} // to conform with integer
1452    if (defined(TeXreplace)) { short =0;}  // this is essential //31.5.07
1453    s = string(monom) + "!";              // add a terminating sign
1454    cfmt = "";
1455
1456    cfmt = string(cfm);
1457    if (size(cfmt)>1)                   // check if sign is < 0
1458    { if (cfmt[2]=="-") { cfm = (-1) *cfm; sign = "-";}}
1459    if (cfmt[1] == "-") { cfm = (-1) * cfm; sign = "-";}
1460    if  (cfm!=1 or monom==1) {cfmt = string(cfm);}
1461    else {cfmt="";}
1462
1463    if (defined(TeXwidth) and TeXwidth > 0 and TeXwidth <9 and count> TeXwidth)
1464    { pt = pt + sign + "\\ldots"; break;}
1465   // ----------------------------------------  linesz ??
1466
1467    if (size(cfmt))                            // parse the coefficient
1468    {
1469     monomt = cfmt;                   // (already a good choice for integers)
1470     msz = 3*size(cfmt);
1471
1472     if(realT) { monomt,msz = parsr(cfmt);}
1473     if (galT) { monomt,msz = parsg(cfmt);}
1474     b = find(cfmt,"/(");                     // look if fraction  // 31.5.07
1475     b2 = find(cfmt,"/");
1476     // if (b) {b++;}                         // 31.5.07
1477     n = size(cfmt);
1478     if (!(parT) and  !(realT) and !(galT))
1479     { if( !(b2) or defined(TeXnofrac))
1480       { monomt = cfmt; msz = 3*size(monomt);}
1481       else
1482       { monomt = "\\frac{" + cfmt[1,b2-1] + "}{" + cfmt[b2+1,n-b2] + "}";
1483          if (n-2*b2>0) {msz = C*(n-b2);}
1484          else {msz = C*b2;}
1485       }
1486     }
1487     if (parT and !(galT))
1488     { monomt,msz = parsp(cfmt,b);}
1489    }
1490    if (monom!=1 and monomt!="" and parT) // 21.4.10
1491    { monomt = monomt+"\\cdot ";} // at least a blank is needed for TeXreplace
1492
1493// -- now parse the monom
1494    if (monom <> 1)
1495    { i = 1;
1496      if(short)
1497      { while(s[i]<>"!")
1498        { monomt = monomt + s[i]; i++;
1499          b = i;
1500          msz = msz + 3; // it was a single lettered var
1501          while(s[i]!="!" and s[i]>="0" and s[i]<="9"){i++;}
1502          if (i-b)
1503          { monomt = monomt + "^{" + s[b,i-b] + "}";
1504            msz = msz + 2*(i-b);
1505          }
1506        }
1507      }
1508      else          //  not short
1509      { t,i = parselong(s);
1510        monomt = monomt + t;
1511        msz = msz + i;
1512      }
1513    }
1514
1515   msz = msz + 6*size(sign);   // Wieso mal 6 ??
1516//  string(msz) + "  ," + string(linesz) + "  " + string(cfm*monom);
1517
1518   if (TeXwidth > 10 and (linesz + msz > 3*TeXwidth) and linesz)
1519   { pt = pt + lnbreak + bg;
1520     linesz = msz;
1521   }
1522   else { linesz = linesz + msz; }  // 3 for sign
1523    pt = pt + sign + monomt;
1524   sign = "+";
1525   monomt = "";
1526  }
1527
1528  if (k<ncols(I)){ pt = pt + sep;}
1529 }
1530
1531  if (TeXwidth==0 and typeof(p)=="poly"){ pt = pt + "= 0";}
1532  if (!TW) { kill TeXwidth;}    // kill Latex::
1533  if (not(defined(NoDollars))) { pt = "$"+pt+"$";}
1534
1535  if (size(fname))
1536  { i=1;
1537    while (fname[i]==">"){i++;}
1538    fname = fname[i,size(fname)-i+1];
1539
1540    if (size(fname)>=4)         // check if filename is ending with ".tex"
1541    { if(fname[size(fname)-3,4]!=".tex") {fname = fname +".tex"; }
1542    }
1543    else {fname = fname + ".tex";}
1544    write(fname,pt);
1545   }
1546  else {return(pt);}
1547}
1548example
1549{ "EXAMPLE:"; echo =2;
1550  ring r0=0,(x,y,z),dp;
1551  poly f = -1x^2 + 2;
1552  texpoly("",f);
1553  ring rr= real,(x,y,z),dp;
1554  texpoly("",2x2y23z);
1555  ring r7= 7,(x,y,z),dp;
1556  poly f = 2x2y23z;
1557  texpoly("",f);
1558  ring rab =(0,a,b),(x,y,z),dp;
1559  poly f = (-2a2 +b3 -2)/a * x2y4z5 + (a2+1)*x + a+1;
1560  f;
1561  texpoly("",f);
1562  texpoly("",1/(a2+2)*x+2/b);
1563}
1564///////////////////////////////////////////////////////////////////////////////
1565
1566static proc parsp(string cfmt, int b)
1567{ string mt, nom,denom;
1568  int fl1,fl2,sz1,sz2,msz;
1569
1570  if (!(b))
1571  { mt,fl1 = parst(cfmt,0); msz = size(cfmt)-2;
1572    if (fl1) { mt = "(" + mt + ")"; msz = msz +1; }
1573  }
1574  else
1575  { nom,fl1 = parst(cfmt[1,b-1],1);
1576    denom,fl2 = parst(cfmt[b+1,size(cfmt)-b],1);
1577    if (defined(TeXnofrac))
1578    { if(fl1) { nom = "(" + nom + ")"; sz1++;}
1579      if(fl2) {denom = "(" + denom + ")"; sz2++;}
1580      mt = "(" + nom+ "/"+ denom+ ")"; msz = sz1+sz2 +1;   //31.5.07
1581    }
1582    else
1583    { mt = "\\frac{" + nom + "}{" + denom + "}";
1584      if (sz1-sz2) { msz = 5*sz1;}
1585      else {msz = 5*sz2;}
1586    }
1587   }
1588  return(mt,msz);
1589}
1590example
1591{"EXAMPLE:"; echo =2;
1592  ring r=(0,a,b),x,dp;
1593  int i;
1594  poly f = (a2b12 + 23a2 -b13-1)/(a2+2b -1);
1595  f;
1596  string s;
1597  s= string(f);
1598  i = find(s,")/(");
1599  parsp(s,i);
1600}
1601///////////////////////////////////////////////////////////////////////////////
1602
1603static proc parst(string s,int sec)                // parse parameter
1604// sec parameter to see if in parsp a fraction follows
1605{
1606  int i,j =1,-1;
1607  int b,k,jj,mz,in;                         // begin and end, in for index
1608  int saveshort=short;
1609  string t,c,vn,nom,denom,sg;
1610
1611  if (s[1]=="(") { s = s[2,size(s)-2]; }
1612  s = s + "!";
1613
1614  if (short)
1615  { j = 0;  // 31.5.07
1616    while(s[i]<>"!")
1617    { b=i; if (s[i]=="+" or s[i]=="-") {j++;}  // 31.5.07
1618      while(s[i]>="0" and s[i]<="9" or (s[i]=="+" or s[i]=="-") and s[i]!="!")
1619      {i++;}     // scan the number
1620        t =s[b,i-b];
1621    //  if (t=="-1" and s[i]!="!" and s[i]!="-" and s[i]!="+"){t = "-";}
1622      if (t=="-1" and (s[i]<="0" or s[i]>="9") and s[i]!= "/" and s[i]!="!")
1623      {t = "-";}
1624      if (s[i]=="/")
1625      { i++;
1626        sg = "";
1627        if (t[1]=="+" or t[1]=="-")
1628        { nom = t[2,size(t)-1];
1629          sg = t[1];
1630        }
1631        else { nom = t;}
1632        b =i;
1633        while(s[i]>="0" and s[i]<="9") {i++;}
1634        denom = s[b,i-b];
1635        if (!(sec) and (!(defined(TeXaligned))))
1636        { t = sg + "\\frac{" + nom + "}{" + denom + "}";}
1637        else
1638        { t = sg + "(" + nom + "/" + denom + ")";
1639        }
1640      }
1641      c = c + t;
1642      if(s[i]!="!"){c = c + s[i]; i++;}      // the parameter
1643      b=i;
1644      while(s[i]>="0" and s[i]<="9")
1645      {i++;}  //the exponent
1646      if(i-b){ c = c + "^{" + s[b,i-b]+"}";}
1647     }
1648   }
1649   else                         // if not short ....
1650   { while (s[i] <> "!")
1651   { b=i; j++; in=0;         // 4.10.10
1652       while(s[i]=="-" or s[i]=="+" or (s[i]>="0" and s[i]<="9")){i++;}
1653       t = s[b,i-b];
1654       if (t=="-1" and s[i]=="*" ) {t="-";}
1655       if (s[i]=="/")
1656       { i++;
1657         sg = "";
1658         if (t[1]=="+" or t[1]=="-")
1659         { nom = t[2,size(t)-1];
1660           sg = t[1];
1661         }
1662         else { nom = t;}
1663         b =i;
1664         while(s[i]>="0" and s[i]<="9") {i++;}
1665         denom = s[b,i-b];
1666         if (!(sec) and (!(defined(TeXaligned))))
1667         { t = sg + "\\frac{" + nom + "}{" + denom + "}";}
1668         else
1669         { t = sg + "(" + nom + "/" + denom + ")";
1670         }
1671       }
1672       c = c+t; t="";
1673       if (s[i]=="*"){i++;}
1674       b=i;
1675      //  string(s[1,b]);
1676
1677       while(s[i]!="+" and s[i]!="-" and s[i]!="!")  //pass a monom
1678       { // start with letters
1679        // alternativ:
1680        //in=0;         // 4.10.10
1681        while((s[i]>="a" and s[i]<="z") or (s[i]>="A" and s[i]<="Z")){i++;}
1682        k = i-b;
1683        vn = s[b,k];
1684        if (defined(TeXreplace))
1685        { for (jj=1; jj<= size(TeXreplace);jj++)
1686         { if (vn == TeXreplace[jj][1])
1687           {vn = TeXreplace[jj][2]; k=1;
1688             if (s[i]=="*") {vn = vn + " ";}
1689            break;} //suppose replacing by a single sign
1690         }
1691        }
1692        t = t + vn;
1693        mz = mz + 10*k;
1694        if (s[i]=="_"  or s[i]=="(") {in++; i++;}    // the index is coming
1695        b = i;
1696        while(s[i]>="0" and s[i]<="9"){ i++;}
1697        k = i-b;
1698        if (k and in<=1) {t = t + "_{";in++;} //and k  i.e. there was an index
1699        if (k){ t = t +s[b,k];}
1700        if(s[i]==")") {i++;}
1701        if(k and s[i]!="(" and s[i]!="_"){ t = t + "}";} // index closed
1702        if(s[i]=="(" or s[i]=="_") {i++; t = t + ",";in++;}
1703        if (s[i]=="^")
1704        { i++; b = i;
1705          while(s[i]>="0" and s[i]<="9"){ i++;} // for neg. expon.
1706          if (b-i) { t = t + "^{" + s[b,i-b] + "}";}
1707        }
1708        if (i-b > k) { mz = mz + 5*(i-b);}
1709        else {mz = mz + 5*k;}
1710        if (s[i]=="*"){i++;in=0;}
1711        b=i;
1712       }
1713       c =c+t;
1714      }
1715   }
1716   short = saveshort;
1717   return(c,j);
1718}
1719example
1720{ "EXAMPLE:"; echo =2;
1721  ring r=(0,a,b),x,dp;
1722  poly f = (a2b12 + 23a2 -b13-1);
1723  f;
1724  parst(string(f),0);
1725
1726  f =(-a +4b2 -2);
1727  f;
1728  parst(string(f),0);
1729
1730  f = a23;
1731  f;
1732  parst(string(f),0);
1733  f = 2a12b3 -4ab15 +2a4b12 -2;
1734  short =0;
1735  f;
1736  parst(string(f),0);
1737   ring r2=(0,a1,b1),x,dp;
1738  poly f = 2*a1^12*b1^3 -4*a1*b1^15 +2*a1^4*b1^12 -2;
1739  f;
1740  parst(string(f),0);
1741}
1742///////////////////////////////////////////////////////////////////////////////
1743
1744static proc parselong(string s)
1745{
1746  int i,j,k,b,mz,in;    // in is a counter for indices
1747  string t,vn;              // varname
1748
1749  i = 1;
1750  while (s[i] <> "!")
1751  { b=i;
1752
1753  // -- scan now the letter ...
1754  //  while(s[i]!="!" and )
1755
1756// alternativ:
1757 while((s[i]>="a" and s[i]<="z") or (s[i]>="A" and s[i]<="Z"))
1758 { i++;}
1759 // s[i]; i;
1760   k = i-b;
1761   vn = s[b,k];
1762
1763   if (defined(TeXreplace))
1764   { for (j=1; j<= size(TeXreplace);j++)
1765     { if (vn == TeXreplace[j][1])
1766       {vn = TeXreplace[j][2]; k=1;
1767        if (s[i]=="*") {vn = vn + " ";}
1768         break;} //suppose replacing by a single sign
1769     }
1770   }
1771   t = t + vn;
1772   mz = mz + 10*k;
1773   if (s[i]=="_"  or s[i]=="(") { in++;i++;}    // the index is coming
1774   b = i;
1775   while(s[i]>="0" and s[i]<="9" or s[i]=="-"){ i++;}  // "-" for neg indices
1776   j = i-b;
1777   // if (j){ t = t + "_{" +s[b,j] + "}";}  // formely
1778   if (j and in<=1) {t = t + "_{";in++;}  // and j  i.e. there was an index
1779   if (j){ t = t  +s[b,j];}
1780   if(s[i]==")") {i++;}
1781   if(j and s[i]!="(" and s[i]!="_"){ t = t + "}";} // index closed
1782   if(s[i]=="(" or s[i]=="_") {i++; t = t + ",";in++;}
1783   if (s[i]=="^")
1784   { i++; b = i;
1785     while(s[i]>="0" and s[i]<="9" or s[i]=="-")
1786     { i++;}  // for neg. expon.
1787     if (b-i) { t = t + "^{" + s[b,i-b] + "}";}
1788   }
1789   if (i-b > j) { mz = mz + 5*(i-b);}
1790   else {mz = mz + 5*j;}
1791   if (s[i]=="*"){i++;in=0;}
1792  }
1793  return(t,mz);
1794}
1795example
1796{ "EXAMPLE:"; echo =2;
1797  ring r =(49,a),x,dp;
1798  number f = a13;
1799  parsg(string(f));
1800  list TeXreplace; export TeXreplace;
1801  TeXreplace[1] = list("b","\\beta");
1802  TeXreplace[2] = list("a","\\alpha");
1803  TeXreplace[3] = list("c","\\gamma");
1804  parselong(string(f)+"!");
1805}
1806///////////////////////////////////////////////////////////////////////////////
1807
1808/* obsolete
1809static proc tktex (def d)
1810{
1811 // calls appropriate proc from latex lib
1812
1813 string typeofd =typeof(d);
1814 if (typeofd=="int" or typeofd=="string" or typeofd=="resolution" or typeofd=="map" or typeofd =="list"){ return(d);}
1815
1816 if (typeofd=="intvec" or typeofd == "intmat" or typeofd =="vector" or
1817     typeofd=="matrix" or typeofd == "module")   { return(texobj("",d));}
1818 if (typeofd=="ring" or typeofd=="qring") { return(texring("",d));}
1819 if (typeofd =="ideal") { return(texobj("",d));}
1820 if (typeofd=="number" or typeofd=="poly" or typeofd=="ideal")
1821                                                 { return(texpoly("",d));}
1822 if (typeofd=="link") {return(d);}
1823
1824}
1825*/
1826/////////////////////////////  PART0 //////////////////////////////////////////
1827
1828static proc part0(string fname)
1829{
1830 int texdemopart =0;
1831 export texdemopart;
1832
1833
1834// Singular script for generating tldemo.tex
1835
1836 string nl = newline;
1837 string nl2 = newline + newline;
1838 string lb = "\\\\";
1839 string bv = "\\begin{verbatim}" + newline ;
1840 string ev = newline + "\\end{verbatim}" +newline ;
1841
1842// "generating part0 of " + fname  + nl;
1843
1844 opentex(fname);
1845
1846write(fname,"\\newcommand{\\Line}{{}\\par\\noindent\\rule{\\textwidth}{0.25mm}\\\\[1mm]}");
1847
1848   write(fname,"\\centerline{\\textbf{\\large Demo file for latex.lib }}");
1849   //  write(fname,"\\centerline{\\textbf{\\large Christian Gorzel }}");
1850   write(fname,"\\centerline{07/10/2010}");
1851   write(fname,"\\vspace{1cm}");
1852
1853//--
1854
1855 write(fname,"","\\section{Introduction}");
1856 write(fname,"The procedures in \\verb|latex.lib| translate the output of
1857 {\\sc Singular} into \\LaTeX \\ text.
1858 This document illustrates the functionality of the library."+"\\\\" +  nl);
1859 write(fname,"\\begin{tabular}{ll}" + nl +
1860"LIBRARY: {\\tt latex.lib} &   PROCEDURES FOR TYPESETTING SINGULAR" +
1861"\\\\" +  nl +
1862" & OBJECTS IN LATEX2E"+
1863"\\\\" +  nl +
1864"{\\tt closetex(fnm);} & writes closing line for \\LaTeX-document"+
1865"\\\\" +  nl +
1866"{\\tt  opentex(fnm);} & writes header for \\LaTeX-file fnm"+
1867"\\\\" +  nl +
1868"{\\tt  tex(fnm);} & calls \\LaTeX2e for file fnm"+
1869"\\\\" +  nl +
1870"{\\tt  texdemo([n]);} & produces a file explaining the features of this lib"+
1871"\\\\" +  nl +
1872"{\\tt  texfactorize(fnm,f);} & creates string in \\LaTeX-format for
1873factors of polynomial f"+ "\\\\" +  nl +
1874"{\\tt  texmap(fnm,m,r1,r2);} & creates string in \\LaTeX-format for
1875map m:r1$\\rightarrow$r2"+ "\\\\" +  nl +
1876"{\\tt  texname(fnm,s);} &      creates string in \\LaTeX-format for
1877identifier"+ "\\\\" +  nl +
1878"{\\tt  texobj(l);} &           creates string in \\LaTeX-format for
1879any (basic) type"+ "\\\\" +  nl +
1880"{\\tt  texpoly(f,n[,l]);} &    creates string in \\LaTeX-format for poly"+
1881"\\\\" +  nl +
1882"{\\tt  texproc(fnm,p);} &      creates string in \\LaTeX-format of
1883text from proc p"+ "\\\\" +  nl +
1884"{\\tt  texring(fnm,r[,l]);} &  creates string in \\LaTeX-format for
1885ring/qring"+ "\\\\" +  nl +
1886"{\\tt  rmx(s);} &              removes .aux and .log files of \\LaTeX-files"+
1887"\\\\" +  nl +
1888"{\\tt  xdvi(s);} &             calls xdvi for dvi-files"+
1889"\\\\" +  nl +
1890" \\end{tabular} " + nl2 + "\\vspace{0.2cm}" + nl2 +
1891"(parameters in square brackets {\\tt [ ]} are optional)"+
1892"\\\\" +  nl2 + "\\vspace{0.2cm}" + nl2 +
1893"The global variables {\\tt TeXwidth}, {\\tt TeXnofrac}, {\\tt
1894 TeXbrack}, {\\tt TeXproj}, {\\tt TeXaligned}, {\\tt TeXreplace}, {\\tt
1895 NoDollars} are used to control the typesetting: "
1896);
1897
1898write(fname,
1899bv +
1900"
1901  TeXwidth   (int) -1, 0, 1..9, >9:  controls breaking of long polynomials
1902  TeXnofrac  (int) flag:  write 1/2 instead of \\frac{1}{2}
1903  TeXbrack   (string) \"{\", \"(\", \"<\", \"|\", empty string:
1904                            controls brackets around ideals and matrices
1905  TeXproj    (int) flag:  write \":\" instead of \",\" in vectors
1906  TeXaligned (int) flag:  write mappings (and ideals) aligned
1907  TeXreplace (list) list entries = 2 strings:  replacing symbols
1908  NoDollars  (int) flag:  suppresses surrounding $ signs
1909
1910" +
1911ev);
1912write(fname,"Notice that none of these global variables are defined when
1913loading \\verb|latex.lib|. A flag variable is set as soon as it is defined.");
1914
1915
1916//% The procs and
1917//% the global variables
1918
1919//----------------------- opentex -----------------------------
1920   write(fname,"","\\section{Opening a \\LaTeX\\ file}");
1921   write(fname,"","In order to create a \\LaTeX\\ document and write a standard
1922header into it, use the following command."+ nl +
1923bv+
1924"> string fname = \"" + fname + "\";" + nl +
1925"> texopen(fname);" +
1926ev);
1927
1928write(fname,"The variable \\verb|fname| is always the first argument when
1929calling one of the procedures of \\verb|latex.lib|. If this string is the
1930empty string, then the output in not written into a file but displayed on
1931the screen.");
1932
1933 //% opentex, defaulted to latex, possibly extension are ... and
1934 //% ``own''
1935
1936
1937pagewidth = 65;
1938int TeXwidth = 100; export TeXwidth;
1939// "part 0 generated " + nl;
1940} //part0
1941
1942
1943/////////////////////////////  PART1 //////////////////////////////////////////
1944
1945static proc part1(string fname)
1946{
1947
1948  int st = defined(texdemopart);
1949  string nl = newline;
1950  string nl2 = newline + newline;
1951  string lb = "\\\\";
1952  string bv = "\\begin{verbatim}" + newline ;
1953  string ev = newline + "\\end{verbatim}" + newline ;
1954
1955  if (not(st) or texdemopart>=1)
1956  { print(" Call part0 first");
1957    return();
1958  }
1959  else { texdemopart=1; }
1960
1961//"Continuing part1 of " + fname + nl;
1962
1963write(fname,"","\\section{Rings, polynomials and ideals}","");
1964
1965// -1a------ a ring in char 0, short varnames and poly. ordering ----------
1966write(fname,
1967" A ring in characteristic 0 with short names of variables and polynomial
1968ordering." +nl);
1969 ring r0=0,(x,y,z),dp;
1970 poly g=-x2y+2y13z+1;
1971write(fname,
1972bv +
1973"> ring r0=0,(x,y,z),dp;" +nl+
1974"> texring(fname,r0);" +
1975ev);
1976  texring(fname,r0);
1977  write(fname,nl2);
1978write(fname,
1979bv +
1980"> poly g=-x2y+2y13z+1;  g;" + nl +
1981"> texpoly(fname,g);" +
1982ev);
1983  texpoly(fname,g);
1984  write(fname,"\\\\"+nl);
1985
1986// write(fname,"\\Line");
1987
1988// -1b------ still in the same ring, a polynomial with rational coefs --------
1989write(fname,
1990""," A polynomial with rational coefficients." +nl);
1991write(fname,
1992bv +
1993"> texpoly(fname,g/280);" +
1994ev
1995);
1996  texpoly(fname,g/280);
1997  kill r0;
1998
1999write(fname,"\\Line","%-----------------------------------------------------");
2000// -2-------- a ring in char 7, indexed varnames and series ordering ----------
2001write(fname,
2002" A ring in characteristic 7 with indexed names of variables and local
2003ordering.","");
2004 ring r1=7,(x1,x2,x3,x4),Ds;
2005 poly g=-2*x1+x4-1;
2006write(fname,
2007bv +
2008"> ring r1=7,(x1,x2,x3,x4),Ds;" +nl +
2009"> texring(fname,r1);" +
2010ev);
2011texring(fname,r1);
2012
2013
2014write(fname, bv +
2015"> poly g=-2*x1+x4-1;  g;" +nl +
2016"> texpoly(fname,g);" +
2017ev);
2018
2019  texpoly(fname,g);
2020
2021write(fname,"\\Line","%-----------------------------------------------------");
2022
2023// -3-------- a ring in char 0, indexed varnames and local ordering ----------
2024write(fname,
2025" A ring in characteristic 0 with indexed names of variables and local
2026ordering.
2027" +nl);
2028 ring r2=0,(x(1..5),y(1..2)),(ds(5),ls(2));
2029 poly g=-y(1)^3*x(5) +y(1)*x(2);
2030write(fname,
2031bv +
2032"> ring r2=0,(x(1..5),y(1..2)),(ds(5),ls(2));" + nl +
2033"> texring(fname,r2);" +
2034ev);
2035  texring(fname,r2);
2036
2037write(fname,
2038bv +
2039"> poly g=-y(1)^3*x(5)+y(1)*x(2);  g;" +nl+
2040 string(g) + nl +
2041"> texpoly(fname,g);"  +
2042ev
2043);
2044  texpoly(fname,g);
2045
2046write(fname,"\\Line","%-----------------------------------------------------");
2047
2048// -4-------- a ring in char 0, indexed varnames and weighted ordering ------
2049write(fname,
2050" A ring in characteristic 0 with indexed names of variables and weighted
2051 ordering." +nl);
2052 ring r3=0,(x_1,x_2,x_3),wp(3,2,1);
2053 poly g=-x_1*x_2+2*x_2*x_3+x_1*x_3;
2054write(fname,
2055bv +
2056"> ring r3=0,(x_1,x_2,x_3),wp(3,2,1);" +nl+
2057"> texring(fname,r3);" +
2058ev);
2059  texring(fname,r3);
2060write(fname,
2061bv +
2062"> poly g=-x_1*x_2+2*x_2*x_3+x_1*x_3;  g;" +nl+
2063  string(g) + nl +
2064"> texpoly(fname,g);"  +
2065ev
2066);
2067texpoly(fname,g);
2068
2069write(fname,"\\Line","%-----------------------------------------------------");
2070
2071// -5-------- a ring with real coeff and matrix ordering -------------------
2072write(fname,
2073" A ring with real coefficients and matrix ordering.
2074" +nl);
2075 ring rr=real,(x,y),M(1,2,3,4);
2076 poly g =-1.2e-10*x2+y+1;
2077write(fname,
2078bv +
2079"> ring rr=real,(x,y),M(1,2,3,4);"+nl+
2080"> texring(fname,rr);"+
2081ev);
2082  texring(fname,rr);
2083
2084write(fname,
2085bv +
2086"> poly g=-1.2e-10*x2+y+1;  g;"+nl+
2087  string(g) + nl +
2088"> texpoly(fname,g);" +
2089ev);
2090  texpoly(fname,g);
2091
2092write(fname,"\\Line","%-----------------------------------------------------");
2093
2094// -6a-------- a ring in char 0, and indexed parameters --------- ----------
2095write(fname,
2096" A ring in characteristic 0 with parameters.
2097" +nl);
2098 ring r0t=(0,s,t),(x,y),dp;
2099 poly g=8*(-s+2t)/(st+t3)*x+t2*x-1;
2100write(fname,
2101bv +
2102"> ring r0t=(0,s,t),(x,y),dp;" +nl +
2103"> texring(fname,r0t);" +
2104ev);
2105 texring(fname,r0t);
2106write(fname,
2107bv +
2108"> poly g=8*(-s+2t)/(st+t3)*x+t2*x-1;  g;"+nl+
2109  string(g) +nl +
2110"> texpoly(fname,g);" +
2111ev);
2112  texpoly(fname,g);
2113write(fname,"\\Line","%-----------------------------------------------------");
2114write(fname,"\\newpage");
2115
2116// -6b------- a ring in char 11003, and indexed parameters --------- ----------
2117write(fname,
2118" A ring in characteristic 11 and indexed parameters.
2119" +nl);
2120 ring rt=(11003,t1,t2,t3),(X,Y),dp;
2121 poly g=8*(-t1+t2)/(t1+t3)*X+t2*Y-1;
2122write(fname,
2123bv +
2124"> ring rt=(11003,t1,t2,t3),(X,Y),dp;" +nl +
2125"> texring(fname,rt);" +
2126ev);
2127  texring(fname,rt);
2128
2129write(fname,
2130bv +
2131"> poly g=8*(-t1+t2)/(t1+t3)*X+t2*Y-1;  g;" + nl+
2132 string(g) +nl +
2133"> texpoly(fname,g);" +
2134ev);
2135  texpoly(fname,g);
2136
2137write(fname,"\\Line","%-----------------------------------------------------");
2138
2139// -7-------- a ring over an algebraic extension in char 7 ---------------
2140write(fname," A ring over an algebraic extension in char 7.");
2141
2142  ring ralg = (7,a),x,dp;
2143  minpoly = a2-a+3;
2144  poly g = -(2a13+a)*x2+a2*x-a+1;
2145
2146write(fname,
2147bv +
2148"> ring ralg=(7,a),x,dp;" +nl +
2149"> minpoly=a2-a+3;" +nl +
2150"> texring(fname,ralg);" +
2151ev);
2152 texring(fname,ralg);
2153
2154write(fname,
2155bv +
2156"> poly g=-(2a13+a)*x2+a2*x-a+1;  g;"+nl+
2157 string(g) +nl +
2158"> texpoly(fname,g);" +
2159ev
2160);
2161  texpoly(fname,g);
2162
2163write(fname,"\\Line","%-----------------------------------------------------");
2164
2165// -8-------- the same ring a in 7 ralg, defined with gftables -- F_49 -------
2166write(fname,
2167" A ring defined with \\verb|gftables|, the same as \\verb|ralg| before, but
2168with primitive element in the Galois field $\\F_{49}$." +nl);
2169 ring r49 =(49,a),x,dp;
2170 poly g=-(2a13+a)*x2+a2*x-a+1;
2171write(fname,
2172bv +
2173"> ring r49 =(49,a),x,dp;" +nl+
2174"> texring(fname,r49);" +
2175ev);
2176 texring(fname,r49);
2177
2178write(fname,
2179bv +
2180"> poly g=-(2a13+a)*x2+a2*x-a+1;  g;" +nl+
2181 string(g) +nl +
2182"> texpoly(fname,g);" +
2183ev);
2184  texpoly(fname,g);
2185
2186write(fname,"\\Line","%-----------------------------------------------------");
2187
2188// -9-------- a ring over the Gaussian numbers  ----------
2189write(fname,
2190" A ring over the Gaussian numbers.
2191" +nl);
2192 ring ri=(0,i),(x,y,z),ls;
2193 minpoly=i2+1;
2194 poly g=-(i+1)*x+2i2y2+i+x;
2195write(fname,
2196bv +
2197"> ring ri=(0,i),(x,y,z),ls;" +nl +
2198"> minpoly=i2+1;" +nl +
2199"> texring(fname,ri);" +
2200ev);
2201 texring(fname,ri);
2202
2203write(fname,
2204bv +
2205"> poly g=-(i+1)*x+2i2y2+i+x;  g;" +nl+
2206 string(g) +nl +
2207"> texpoly(fname,g);" +
2208ev
2209);
2210  texpoly(fname,g);
2211
2212write(fname,"\\Line","%-----------------------------------------------------");
2213
2214// -10--------- a quotient ring performed from  ----------
2215write(fname," A quotient ring performed of \\verb|r0| by an ideal.");
2216 ring r0=0,(x,y,z),dp;
2217 ideal I = x2-y, y+z2, xy;
2218 I = std(I);
2219string sI = string(I);
2220 qring qr = I;
2221write(fname,
2222bv +
2223"> setring r0;
2224> ideal I=x2-y,y+z2, xy;
2225> I=std(I);
2226> string(I);" + nl +
2227string(sI) + nl +
2228"> qring qr=I;
2229> texring(fname,qr);" +
2230ev
2231);
2232texring(fname,qr);
2233
2234//write(fname,"\\Line","%-----------------------------------------------------");
2235
2236// ------------------------- Features for rings
2237
2238write(fname,"","\\subsection{Features for rings}");
2239
2240write(fname,
2241"In many cases it might be convenient to change the standard typesetting
2242of rings. This can be done by passing additional arguments to \\verb|texring|."
2243+nl);
2244
2245// changing the brackets
2246
2247write(fname,nl,"In order to change the displayed brackets one has to give
2248the desired ones as additional argument (accepted brackets are: \\verb|\"\{\"|,
2249\\verb|\"\{\{\"|,\\verb|\"[\"|,\\verb|\"[[\"|,\\verb|\"<\"|,\\verb|\"<<\"|).");
2250
2251write(fname,
2252bv +
2253"> texring(fname,rr,\"{{\");" +
2254ev
2255);
2256
2257texring(fname,rr,"{{");
2258
2259write(fname,
2260bv +
2261"> texring(fname,r2,\"[\");" +
2262ev
2263);
2264
2265texring(fname,r2,"[");
2266
2267write(fname,nl+"\\vspace{0.2cm}" + nl2);
2268
2269write(fname,"The brackets around the ideal in a quotient ring can be
2270changed by setting  the global variable \\verb|TeXbrack| (see section
2271{\\tt Ideals}).",nl);
2272
2273write(fname,
2274bv +
2275"> string TeXbrack = \"<\";" +nl +
2276"> texring(fname,qr);" +
2277ev
2278);
2279
2280  string TeXbrack = "<"; export TeXbrack;
2281  texring(fname,qr);
2282  kill TeXbrack;
2283
2284write(fname,
2285bv +
2286"> kill TeXbrack;" +
2287ev);
2288
2289//write(fname,"\\Line","%-----------------------------------------------------");
2290
2291// changing the ground field
2292// -------------------------------------------------
2293
2294write(fname,
2295"It is possible to display a ground field different from the
2296actual one by passing any letter in \\LaTeX \\ notation as additional
2297argument.  Predefined values are \\verb|\"\\\\C\"|, \\verb|\"\\\\R\"|,
2298\\verb|\"k\"|, \\verb|\"K\"| and \\verb|\"R\"|."+nl+
2299"If for example a ground field of characteristic 0 should be written as
2300$\\C$ instead of $\\Q$ use this as additional argument.",nl);
2301
2302write(fname,
2303bv +
2304"> texring(fname,r3,\"\\\\C\");" +
2305ev);
2306
2307texring(fname,r3,"\\C");
2308write(fname,nl+ "\\vspace{0.2cm}" + nl2);
2309
2310write(fname,"The values \\verb|\"k\"|, \\verb|\"K\"|, \\verb|\"R\"| play a
2311 special role when the ground field is an algebraic extension. In this case
2312the parameters will be omitted.");
2313
2314write(fname,
2315bv +
2316"> texring(fname,ralg,\"k\");" +
2317ev
2318);
2319
2320texring(fname, ralg,"k");
2321write(fname,nl+"\\vspace{0.2cm}" + nl2);
2322
2323write(fname,"If an algebraic extension should be displayed together with
2324its minimal polynomial the optional parameter \\verb|mipo| has to be used.");
2325
2326write(fname,
2327bv +
2328"> texring(fname,ralg,\"mipo\");" +
2329ev
2330);
2331
2332texring(fname, ralg,"mipo");
2333write(fname,"\\Line","%-----------------------------------------------------");
2334
2335// displaying only certain vars
2336
2337write(fname,"By default all variables of a ring will be displayed. It is
2338possible to print only certain variables with $\\ldots$ between
2339them. The positions of the variables which should be displayed have to be
2340passed to \\verb|texring| as an \\verb|intvec|.");
2341
2342write(fname,
2343bv +
2344"> intvec v=5,6;
2345> texring(fname,r2,v);" +
2346ev
2347);
2348
2349  intvec v = 5,6;
2350  texring(fname,r2,v);
2351  kill v;
2352
2353write(fname,
2354bv +
2355"> kill v;" +
2356ev
2357);
2358
2359write(fname,nl+ "\\vspace{0.2cm}" + nl2);
2360
2361write(fname,"The first and the last variable will always be printed.
2362In order to print only these it is sufficient to give a 1 as third argument.");
2363
2364write(fname,
2365bv +
2366"> texring(fname,r1,1);" +
2367ev
2368);
2369texring(fname,r1,1);
2370
2371write(fname,"\\Line","%-----------------------------------------------------");
2372
2373// invariant ring under a group action
2374
2375write(fname,"If you want for example to display a ring as the invariant ring
2376under a group, additional information starting with \\verb|^| may be added.");
2377
2378write(fname,
2379bv +
2380"> texring(fname,r0,\"^G\");" +
2381ev
2382);
2383
2384texring(fname, r0,"^G");
2385write(fname,"\\Line","%-----------------------------------------------------");
2386
2387// passing several optional arguments at once
2388
2389write(fname,"It is also possible to pass several of the arguments described
2390above at once (in any order).");
2391
2392
2393write(fname,
2394bv +
2395"> texring(fname,r3,\"\\\\R\",\"{{\",\"^G\");" +
2396ev
2397);
2398
2399texring(fname, r3,"\\R","{{","^G");
2400//"end part 1" + nl;
2401}
2402
2403
2404/////////////////////////////  PART2 //////////////////////////////////////////
2405
2406
2407static proc part2(string fname)
2408{
2409
2410  int st = defined(texdemopart);
2411  string nl = newline;
2412  string nl2 = newline + newline;
2413  string lb = "\\\\";
2414  string bv = "\\begin{verbatim}" + newline ;
2415  string ev = newline + "\\end{verbatim}" + newline ;
2416//  string ev = "\\end{verbatim}" ;
2417
2418  if (not(st) or texdemopart>=2)
2419  { print(" Call part1 first");
2420    return();
2421  }
2422  else { texdemopart=2; }
2423
2424// "Continuing Part2 of " + fname + nl;
2425
2426//-------------------- texfactorize ------------------------------
2427write(fname,"","\\subsection{Factorized polynomials}");
2428
2429write(fname,"The command \\verb|texfactorize| calls internally the
2430{\\sc Singular} command \\verb|factorize| and returns the product of the
2431irreducible factors. Note that, at the moment, it is not possible to pass
2432any optional arguments for \\verb|factorize| through \\verb|texfactorize|.");
2433
2434  ring r0=0,(x,y,z),dp;
2435  poly h=(x+1+y)^2*x3y*(2x-2y)*y12;
2436
2437write(fname,
2438bv +
2439"> setring r0;
2440> poly h=(x+1+y)^2*x3y*(2x-2y)*y12;   h;" +nl+
2441 string(h) + nl +
2442"> texfactorize(fname,h);" +
2443ev);
2444texfactorize(fname,h);
2445
2446//  setring ralg;
2447  ring ralg = (7,a),x,dp;
2448  minpoly = a2-a+3;
2449  poly h = (a24x5+x3)*a2x6*(x+1)^2;
2450
2451write(fname,
2452bv +
2453"> setring ralg;
2454> poly h=(a24x5+x3)*a2x6*(x+1)^2;  h;"+ nl +
2455 string(h) + nl +
2456"> texfactorize(fname,h);"+
2457ev);
2458texfactorize(fname,h);
2459
2460//--------------------- features for polynomials -----------------
2461write(fname,"","\\subsection{Features for polynomials}");
2462
2463// TeXreplace
2464// ---------------------------------------------
2465write(fname,"By setting the global variable \\verb|TeXreplace| it is possible
2466to define rules for replacing strings or variable names.
2467\\verb|TeXreplace| has to be a list of twoelemented lists where the first
2468entry is the text which should be replaced by the second entry.
2469This may be applied to replace names of variables, but is also used
2470when calling \\verb|texname| or \\verb|texmap|. Note that it
2471is necessary to write a double backslash \\verb|\\\\\| at the beginning of
2472a \\TeX \\ symbol.","");
2473
2474write(fname,"Let us denote the primitive element of an algebraic extension
2475by $\\xi$.");
2476
2477list TeXreplace; export TeXreplace;
2478TeXreplace[1] = list("a","\\xi");
2479// setring r49;
2480  ring r49 =(49,a),x,dp;
2481  poly g=-(2a13 +a)*x2+a2*x-a+1;
2482write(fname,
2483bv +
2484"> list TeXreplace;" +nl +
2485"> TeXreplace[1]=list(\"a\",\"\\\\xi\");" +nl+
2486"> setring r49;" +nl+
2487"> texpoly(fname,g);"+
2488ev);
2489
2490texpoly(fname,g);
2491
2492write(fname,nl+ "\\vspace{0.2cm}" + nl2);
2493write(fname,"Now let us write $\\lambda$ and $\\mu$ for deformation
2494parameters.");
2495TeXreplace[2]= list("s","\\lambda");
2496TeXreplace[3]= list("t","\\mu");
2497// setring(r0t);
2498  ring r0t=(0,s,t),(x,y),dp;
2499  poly g=8*(-s+2t)/(st+t3)*x+t2*x-1;
2500write(fname,
2501bv +
2502"> TeXreplace[2]=list(\"s\",\"\\\\lambda\");"+nl+
2503"> TeXreplace[3]=list(\"t\",\"\\\\mu\");"+nl+
2504"> setring(r0t);"+nl+
2505"> texpoly(fname,g);"+
2506ev);
2507texpoly(fname,g);
2508
2509kill TeXreplace;
2510write(fname,nl+ "\\vspace{0.4cm}");
2511write(fname,nl+"Note that, if \\verb|TeXreplace| is defined, the translation
2512into \\LaTeX  code runs a little bit slower, because every polynomial is
2513compiled in the \\verb|non short| mode."+ lb );
2514
2515write(fname,nl,"\\Line","%-----------------------------------------------------");
2516
2517//linebreaking   TeXwdith
2518//-----------------------------------------------------------------------
2519write(fname,"The global variable \\verb|TeXwidth| controls the wrapping of
2520polynomials; possible values are:" + lb);
2521
2522write(fname,
2523"\\[ " + nl +
2524"\\text{\\tt TeXwidth} = ",
2525"\\begin{cases} ",
2526" -1 & \\text{no line-breaking} \\\\ ",
2527"  0 & \\text{print the polynomial as equation } f=0 \\\\ ",
2528" 1,\\dots,9 & \\text{the first n terms followed by the sign of the next
2529term} \\\\ ",
2530" > 9 & \\text{line break after terms of length n (see below)} ",
2531"\\end{cases}",
2532"\\]",nl);
2533
2534write(fname,"Note that the size of terms is calculated with certain
2535multiplicities.",nl);
2536
2537//----------------------------------------------------------
2538
2539write(fname,"\\begin{itemize}");
2540write(fname,"\\item");
2541
2542write(fname,
2543bv +
2544"> TeXwidth=-1;"+nl+
2545"> setring r0;"+nl+
2546"> poly f=g^2;"+nl+
2547"> texpoly(fname,f);" +
2548ev);
2549
2550  setring r0;
2551  poly g=-x2y+2y13z+1;
2552  poly f=g^2;
2553  texpoly(fname,f);
2554
2555write(fname,"\\item");
2556
2557write(fname,
2558bv +
2559"> TeXwidth=0;
2560> texpoly(fname,f);"+
2561ev);
2562TeXwidth = 0;
2563texpoly(fname,f);
2564
2565write(fname,"\\item");
2566write(fname,
2567bv +
2568"> TeXwidth=2;
2569> texpoly(fname,f);"+
2570ev);
2571TeXwidth=2;
2572texpoly(fname,f);
2573
2574write(fname,"\\item");
2575write(fname,
2576bv +
2577"> TeXwidth=20;"+nl+
2578"> texpoly(fname,f);"+
2579ev);
2580TeXwidth=20;
2581texpoly(fname,f);
2582TeXwidth=-1;
2583
2584write(fname,"\\end{itemize}");
2585
2586write(fname,"\\Line","%-----------------------------------------------------");
2587
2588write(fname,"There are two possibilities to convert a polynomial into
2589\\LaTeX{} code: either by using \\verb|texpoly| or by calling \\verb|texobj|.
2590The difference is that \\verb|texpoly| puts the polynomial in text-mode
2591while \\verb|texobj| uses the display mode."+nl+
2592"The following examples show the different outputs:");
2593
2594write(fname,
2595bv +
2596"> setring r3;
2597> texpoly(fname,g/180);" +
2598ev);
2599
2600// setring r3;
2601
2602  ring r3=0,(x_1,x_2,x_3),wp(3,2,1);
2603  poly g=-x_1*x_2+2*x_2*x_3+x_1*x_3;
2604  texpoly(fname,g/180);
2605
2606write(fname,
2607bv +
2608"> texobj(fname,g/180);
2609" +
2610ev);
2611
2612texobj(fname,g/180);
2613
2614//write(fname,"Some explanation how it works: if \\verb|texobj| is called for
2615//a polynomial, then it defines a global variable \\verb|TeXdisp| which forces
2616//\\verb|texpoly| to count fraction with space corresponding
2617//the displaymode."+lb,nl2);
2618//---------------------texobj for ideal ---------------
2619
2620write(fname,"","\\subsection{Ideals}");
2621write(fname,"By default, ideals are displayed as column vectors.");
2622
2623  ring r;
2624  ideal I=3xz5+x2y3-3z,7xz5+y3z+x-z,-xyz2+4yz+2x;
2625
2626write(fname,
2627bv +
2628"> ring r;   // the default ring"+nl+
2629"> ideal I=3xz5+x2y3-3z,7xz5+y3z+x-z,-xyz2+4yz+2x;"+nl+
2630"> texobj(fname,I);" +
2631ev);
2632
2633texobj(fname,I);
2634
2635write(fname,"\\Line","%-----------------------------------------------------");
2636//----------------------------------------------------------------------
2637write(fname,"If the global variable \\verb|Texaligned| is set then the ideal
2638is displayed as a row vector.");
2639
2640write(fname,
2641bv +
2642"> int TeXaligned;
2643> texobj(fname,I);" +
2644ev);
2645
2646int TeXaligned; export TeXaligned;
2647texobj(fname,I);
2648
2649 write(fname,nl+"\\Line","%-----------------------------------------------------");
2650//----------------------------------------------------------------------
2651write(fname,"By setting the global variable \\verb|TeXbrack| it is possible
2652to change the brackets.");
2653
2654write(fname,
2655bv +
2656"> string TeXbrack=\"<\";"+nl+
2657"> texobj(fname,I);"+
2658ev);
2659
2660string TeXbrack="<";  export TeXbrack;
2661texobj(fname,I);
2662
2663write(fname,
2664bv +
2665"> kill TeXbrack, TeXaligned;" +
2666ev);
2667
2668kill TeXbrack,TeXaligned;
2669write(fname,"\\Line","%-----------------------------------------------------");
2670//----------------------------------------------------------------------
2671write(fname,
2672" If \\verb|TeXwidth| is 0, an ideal is displayed as a system of
2673equations.");
2674
2675// ------------- a linear equation system
2676
2677  ring r5=0,x(1..5),dp;
2678  ideal I=-x(1)+2*x(3)+x(5), x(2)-x(4)+2*x(5)-1, 8*x(1)+x(4)+2;
2679  TeXwidth=0;
2680
2681write(fname,
2682bv +
2683"> ring r5=0,x(1..5),dp;"+nl+
2684"> ideal I=-x(1)+2*x(3)+x(5), x(2)-x(4)+2*x(5)-1, 8*x(1)+x(4)+2;"+nl+
2685"> TeXwidth=0;"+nl+
2686"> texobj(fname,I);" +
2687ev);
2688
2689  texobj(fname,I);
2690
2691  setring r;
2692  ideal J=4x4y21+z25y7-y2,x3+y2,y2-z4;
2693
2694write(fname,
2695bv +
2696"> setring r;"+nl+
2697"> ideal J=4x4y21+z25y7-y2,x3+y2,y2-z4;"+nl+
2698"> texobj(fname,J);" +
2699ev
2700);
2701  texobj(fname,J);
2702
2703write(fname,"\\Line","%-----------------------------------------------------");
2704//-----------------------------------------------------------------------
2705write(fname,"Call the ideal by its name and it is printed as follows");
2706
2707write(fname,
2708bv +
2709"> setring r;
2710> ideal I=3xz5+x2y3-3z,7xz5+y3z+x-z,-xyz2+4yz+2x;
2711> texobj(fname,\"I\");" +
2712ev);
2713
2714 setring r; export(I);
2715 texobj(fname,"I");
2716 kill I,r;
2717//" end part 2 " + nl;
2718}
2719
2720/////////////////////////////  PART3 //////////////////////////////////////////
2721
2722static proc part3(string fname)
2723{
2724  int st=defined(texdemopart);
2725  string nl=newline;
2726  string nl2=newline + newline;
2727  string lb="\\\\";
2728  string bv=newline+"\\begin{verbatim}";
2729//  string ev = newline + "\\end{verbatim}" + newline ;
2730  string ev="\\end{verbatim}" ;
2731
2732  if (not(st) or st>=3)
2733
2734  {
2735    print(" Call part2 first");
2736    return();
2737  }
2738  else { texdemopart=3; }
2739
2740// " Continuing part 3 of " + fname +
2741// " : map,matrices,vectors,intvec,intmats,proc";
2742
2743//---------------------- texmap ------------------------------
2744write(fname,"","\\section{Typesetting maps between rings}");
2745write(fname,"By default, maps are displayed in the following way:");
2746
2747write(fname,
2748bv,
2749"> ring r4=0,(x,y,z),dp;
2750> ring r5=0,(u,v),dp;
2751> map phi=r1,u2,uv -v,v2;
2752> texmap(fname,phi,r4,r5);",
2753ev);
2754
2755  ring @r4_h=0,(x,y,z),dp;
2756  export @r4_h;
2757  ring r5=0,(u,v),dp;
2758  map @phi_h=@r4_h,u2,uv -v,v2;  export @phi_h;
2759  texmap(fname,@phi_h,@r4_h,r5);
2760
2761write(fname,"\\Line","%-----------------------------------------------------");
2762//--------------------------------------------------------------------
2763
2764write(fname,"If the global variable \\verb|TeXaligned| is set, then the
2765map is displayed in one line.");
2766
2767write(fname,
2768bv,
2769"> int TeXaligned;
2770> texmap(fname,phi,r4,r5,\"\\\\C\");",
2771ev );
2772
2773  int TeXaligned; export TeXaligned;
2774  texmap(fname,@phi_h,@r4_h,r5,"\\C");
2775
2776write(fname,nl+"\\Line","%-----------------------------------------------------");
2777//--------------------------------------------------------------------
2778
2779write(fname,"It is possible to pass the same additional arguments to
2780\\verb|texmap| as to \\verb|texring| (see section {\\tt Rings}). This can
2781be done by calling \\verb|texmap| with two lists as additional parameters,
2782where the first list contains the optional parameters for the source and
2783the second one contains the parameters for the domain. Note that if only one
2784list is present then it is applied to both of the rings.");
2785
2786write(fname,
2787bv,
2788"> texmap(fname,phi,r4,r5,\"\\\\C\",\"{\");",
2789ev );
2790  texmap(fname,@phi_h,@r4_h,r5,"\\C","{");
2791
2792write(fname,nl+ "\\vspace{0.2cm}" + nl);
2793write(fname,"The next example shows how to format the two rings in different
2794ways.");
2795
2796write(fname,
2797bv,
2798"> texmap(fname,phi,r4,r5,list(),list(\"{\"));",
2799ev );
2800
2801 texmap(fname,@phi_h,@r4_h,r5,list(),list("{"));
2802
2803write(fname,"\\Line","%-----------------------------------------------------");
2804//--------------------------------------------------------------------
2805
2806write(fname,"If the map is called by its name then \\verb|texmap| displays,
2807in addition, also the name of the map.");
2808
2809write(fname,
2810bv,
2811"> list TeXreplace;
2812> TeXreplace[1]=list(\"phi\",\"\\\\phi\");
2813> texmap(fname,\"phi\",r4,r5);",
2814ev);
2815
2816  list TeXreplace;
2817  TeXreplace[1]=list("@phi_h","\\phi");
2818  export TeXreplace;
2819  texmap(fname,"@phi_h",@r4_h,r5);
2820  kill @phi_h,@r4_h,r5,TeXreplace,TeXaligned;
2821
2822write(fname,
2823bv,
2824      "> kill phi,r4,r5,TeXreplace,TeXaligned;",
2825ev);
2826
2827
2828//% the texobj part
2829write(fname,"","\\section{Typesetting composed data structures}");
2830//=======================================================================
2831
2832write(fname, "Complex data structures such as matrices, vectors or modules
2833can be displayed by using the procedure \\verb|texobj|.");
2834
2835write(fname,"","\\subsection{Matrices and vectors}");
2836//=======================================================================
2837
2838write(fname,"The following example shows how to typeset the Hessian of a
2839polynomial.");
2840
2841write(fname,
2842bv,
2843"> ring r;
2844> poly h=2xy3-x2z+x4z7+y4z2;
2845> matrix H=jacob(jacob(h));
2846> texobj(fname,H);",
2847ev );
2848
2849ring r;
2850poly h=2xy3-x2z+x4z7+y4z2;
2851matrix H=jacob(jacob(h));
2852texobj(fname,H);
2853
2854write(fname,"By default, \\verb|vectors| are written as row vectors:");
2855
2856vector V = H[2];
2857
2858write(fname,
2859bv,
2860"> vector V=H[2];
2861> texobj(fname,V);",
2862ev );
2863
2864texobj(fname,V);
2865
2866write(fname,nl+"\\vspace{0.2cm}"+nl);
2867write(fname,"In order to transpose it, it has to be converted into a
2868matrix.");
2869write(fname,
2870bv,
2871"> texobj(fname,matrix(V));",
2872ev );
2873
2874texobj(fname,matrix(V));
2875
2876write(fname,nl+"\\Line","%-----------------------------------------------------");
2877//------------------------------------------------------------------------
2878
2879write(fname,"All the features for typesetting polynomials work also for
2880matrices or vectors with polynomial entries.");
2881write(fname,nl+ "\\vspace{0.2cm}" + nl);
2882write(fname,"By setting the global variable \\verb|TeXwidth| it is possible
2883to display only the first terms of the polynomials.");
2884
2885write(fname,bv,
2886"> TeXwidth=1;
2887> texobj(fname,H);
2888> TeXwidth=-1;",
2889ev );
2890
2891TeXwidth = 1;
2892texobj(fname,H);
2893TeXwidth = -1;
2894
2895write(fname,nl,"\\Line","%-----------------------------------------------------");
2896//------------------------------------------------------------------------
2897write(fname,"The flag variable \\verb|TeXnofrac| controls the typesetting
2898of fractions.");
2899
2900write(fname,
2901bv,
2902"> ring R0=0,x,dp;
2903> matrix M[2][3]=1/2, 0, 1/2, 0, 1/3, 2/3;
2904> texobj(fname,M);",
2905ev);
2906
2907
2908ring R0 = 0,x,dp;
2909matrix M[2][3] = 1/2, 0, 1/2, 0, 1/3, 2/3;
2910texobj(fname,M);
2911
2912write(fname,bv,
2913"> int TeXnofrac;
2914> texobj(fname,M);",
2915ev );
2916
2917  int TeXnofrac; export TeXnofrac;
2918  texobj(fname,M);
2919  kill TeXnofrac;
2920
2921write(fname,bv,
2922"> kill TeXnofrac;",
2923ev );
2924
2925write(fname,nl,"\\Line","%-----------------------------------------------------");
2926//------------------------------------------------------------------------
2927
2928write(fname,"Printing a vector with homogeneous coordinates can be done by
2929setting \\verb|TeXproj|.");
2930write(fname,bv +
2931"> setring r;
2932> int TeXproj;
2933> texobj(fname,V);",
2934ev );
2935
2936  setring r;
2937  ideal I=3xz5+x2y3-3z,7xz5+y3z+x-z,-xyz2+4yz+2x;
2938  int TeXproj; export TeXproj;
2939
2940  texobj(fname,V);
2941  kill TeXproj;
2942
2943write(fname,
2944bv,
2945      "> kill TeXproj;",
2946ev);
2947
2948write(fname,"","\\subsection{Modules}");
2949
2950write(fname,"By default, modules are displayed in the following way:");
2951write(fname,
2952bv,
2953"> setring r;
2954> module md=module(H);
2955> texobj(fname,md);",
2956ev );
2957
2958setring r;
2959module md = module(H);
2960texobj(fname,md);
2961
2962write(fname,"\\Line","%-----------------------------------------------------");
2963//------------------------------------------------------------------------
2964
2965write(fname,"In order to write the generators of a module aligned, the flag
2966variable \\verb|TeXaligned| has to be defined.");
2967
2968write(fname,bv,
2969"> int TeXaligned;
2970> texobj(fname,md);",
2971ev );
2972
2973int TeXaligned; export TeXaligned;
2974texobj(fname,md);
2975kill TeXaligned;
2976write(fname,bv,
2977"> kill TeXaligned;",
2978ev );
2979
2980//----------------------------------------------------------------
2981write(fname,"","\\subsection{Integer matrices and vectors}");
2982
2983write(fname,"Integer matrices are displayed in the following way.");
2984
2985intmat m[3][4]=-1,3,5,2,-2,8,6,0,2,5,8,7;
2986
2987write(fname,
2988bv,
2989"> intmat m[3][4]=-1,3,5,2,-2,8,6,0,2,5,8,7;
2990> m;" + nl +
2991string(m) + nl +
2992"> texobj(fname,m);",
2993ev );
2994
2995texobj(fname,m);
2996write(fname,nl+ "\\vspace{0.2cm}" + nl);
2997write(fname,"Integer vectors are displayed as row vectors.");
2998intvec v = 1..4;
2999write(fname,
3000bv,
3001"> intvec v=1..4;
3002> v;" + nl +
3003string(v) + nl +
3004"> texobj(fname,v);",
3005ev );
3006
3007texobj(fname,v);
3008
3009write(fname,nl+ "\\vspace{0.2cm}" + nl);
3010write(fname,"To typeset the transposed vector, it has to be converted into
3011an integer matrix."+
3012bv,
3013"> texobj(fname,intmat(v));",
3014ev );
3015
3016texobj(fname,intmat(v));
3017
3018write(fname,nl+ "\\vspace{0.2cm}" + nl);
3019
3020write(fname,"The following example shows how to typeset the multiplication of
3021a matrix with a vector.");
3022write(fname,
3023bv,
3024"> texobj(fname,intmat(m*v),\"=\",m,\"*\",intmat(v));",
3025ev );
3026
3027texobj(fname,intmat(m*v),"=",m,"*",intmat(v));
3028
3029//-----------------------------------------------------------------
3030write(fname,"\\Line","%-----------------------------------------------------");
3031
3032write(fname,"Of course, the brackets of a \\verb|intmat| can be changed
3033by setting \\verb|TeXbrack|.");
3034
3035write(fname,
3036bv,
3037"> intmat mat[3][3]=1,2,3,4,5,6,7,8,9;
3038> string TeXbrack=\"|\";
3039> texobj(fname,mat,\" = \",det(mat)); ",
3040ev );
3041
3042intmat mat[3][3] = 1,2,3,4,5,6,7,8,9;
3043string TeXbrack = "|"; export TeXbrack;
3044texobj(fname,mat," = ",det(mat));
3045kill TeXbrack;
3046
3047//----------------------------------texname-------------------
3048
3049//write(fname,"\\section{Names of identifiers}");
3050
3051
3052//write(fname,"The proc \\verb|texname| is used to write indexed names in a
3053//correct way"+lb,nl);
3054
3055
3056
3057// ------------------------------- texproc -------------------------------
3058  proc milnor_number (poly p)
3059  {
3060    ideal i = std(jacob(p));
3061    int m_nr = vdim(i);
3062    if (m_nr<0)
3063    {
3064      "//--  not an isolated singularity";
3065    }
3066    return(m_nr);
3067  }
3068  export(milnor_number);
3069
3070write(fname,"","\\section{Typesetting procedures}");
3071write(fname,"The following procedure allows to include the source code
3072of procedures into a \\LaTeX document.");
3073write(fname,
3074bv,
3075"> texproc(fname,\"milnor\_number\");",
3076ev);
3077
3078 texproc(fname,"milnor_number");
3079
3080  kill milnor_number;
3081
3082// ------------------------------ closing the tex file -------------------
3083write(fname,"","\\section{Closing the \\LaTeX\\ file}");
3084write(fname,"To close the file use \\verb|closetex(fname);|. It should now
3085contain pure \\LaTeX \\ code and may be compiled with " +
3086"\\verb|tex(fname)| and displayed with \\verb|xdvi(fname)|.");
3087
3088// write(fname,"\\section{Remarks}");
3089closetex(fname);
3090//"end of part3" + nl;
3091
3092pagewidth =80;
3093kill texdemopart,TeXwidth;
3094}
3095///////////////////////////////////////////////////////////////////////////////
3096
3097/*
3098
3099   texring extended for Z,Z_m,real,complex
3100
3101// Test for new functionality:
3102// texring:
3103  ring rZ = integer,x,dp;
3104  texring("",rZ);
3105  ring rZ8 = (integer,8),x,dp;
3106  texring("",rZ8);
3107
3108  ring rR = real,x,dp;
3109  texring("",rR);
3110
3111  ring rR2010 = (real,20,10),x,dp;
3112  texring("",rR2010);
3113
3114  ring rC = complex,x,dp;
3115  texring("",rC);
3116
3117  ring rC2010 = (complex,20,10),x,dp;
3118  texring("",rC2010);
3119
3120// multi-indexed parameters and variables
3121
3122  ring rmultind34 = 0,(a(1..3)(1..4)),dp;
3123  texring("",r34);
3124  matrix A[3][4] = maxideal(1);
3125  texobj("",A);
3126
3127  ring rmultind2 = 0,(x1_2,y_1_1,z),ds;
3128  texring("",rmultind2);
3129
3130  ring rmultind3 = 0,(x(-1..1)(0)(3..4)),ds;
3131  texobj("",maxideal(1));
3132
3133  ring rmultind4 = (0,b1(0..2),b2_1(3)),x,ds;
3134  texpoly("",par(1)*par(2)*par(3)+par(4)*x);
3135
3136*/
3137// last changed 10/10/10
3138///////////////////////// end of latex.lib ////////////////////////////////////
3139
Note: See TracBrowser for help on using the repository browser.