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