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

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