source: git/Singular/LIB/latex.lib @ 7de8e4

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