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

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