source: git/Singular/LIB/latex.lib @ 1c1d96b

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