source: git/Singular/LIB/latex.lib @ 917fb5

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