source: git/Singular/LIB/latex.lib @ 8c2815d

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