source: git/Singular/LIB/latex.lib @ 8afd58

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