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

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