source: git/Singular/LIB/latex.lib @ 08e081

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