// version 16/9/03 // gnmath.txt: // a JavaScript library for writing mathematica on the web // By Giovanni Nicco. // // // ww()// writes all strings-argument passed // w(x)// write the contents of x // Functions are used for embedding HTML code in order to make a rendering of some mathematical notations // like pedix, apix, greek letters, fractions or radical simbols. // Also there is another library (gntex.txt) for a more straight use of mathematic notation in a latex way // (tags inside a string) but parsing is not very evoluted and you can have problem // for example when using fractions inside fractions //************************************************** // * // A V E R Y S H O R T M A N U A L * // * //************************************************** // First of all you need an istruction to write on your page: you could use document.write() // but ww() do the some things, is shorter and you can put inside as many argoments as you want: // Example: // ww(exists,"x",inset,"A",bar,"x",leq,"1") // you can see there are variable which name corrispond to the // symbol you want on the web page (you will need "SYMBOL" font and this could be a problem if you use macintosh) // leq for example stay for the character 'lower equal' // // // // when constructing more complex string, you will need an instruction that return a string // but doesn't write it (you will use preceding instruction to do that): these are l() and lc() // function that perform the same works like ww() and wlc() but returning and non writing // w(lc(frac(2,3),plus,frac(3,3),eq,frac(5,3)) write a fractional sum // also mat31() return the string equivalent to a matrix 3*1 (a column) // ex: /* ww( lc(agBig,mat31( lc(x,plus,y,eq,frac(1,3),plus,frac(2,3)), " ", lc(x,menus,y,eq,frac(1,3),times,frac(2,3)) ) ) ) */ // // this istruction write a sistem of 2 equation: agBig is a parentesis, mat31 has 3 arguments. // // ww() // w(x) // l() // lc() // // // // // // // // // // // // // // function ww(){w(compattaABvC("","",arguments,""))}// stampa tutte le stringhe-argomenti passate function wwl(){w(compattaABvC("","",arguments,"")+'
')}// stampa tutte le stringhe-argomenti passate function log10(x){return Math.LOG10E*Math.log(x);} function wl(){w(l(arguments))}; // idem ma forzatamente in linea function wlc(){alert(lc(arguments))}; // idem ma centrata (utile per le frazioni) function say(x){eval("ww('"+x+"=',"+x+")")} function sayl(x){eval("ww('"+x+"=',"+x+",'
')")} function w(x){document.writeln(x)} // stampa semplice function l(){return compattaABvC("","
",arguments,"
")} //restituisce in linea function lc(){return compattaABvC("","
",arguments,"
")}// idem centrata verticalmente function join(){return(compattaABvC("","",arguments,""))} function fontChar(f,c){ return ""+String.fromCharCode(c)+""} var p="+",t="*",m="-",d=":"; // operatori aritmetici var plus="+", time="*", menus="-", divide=":"; var x="x",y="y",z="z",a="a",b="b",c="c",d="d";e="e",o="o";A="A",B="B",C="C",D="D"; // variabili var sx=" x ",sy=" y ",sz=" z ",sa=" a ",sb=" b ",sc=" c ",se=" e ",so=" o ";sA=" A ",sB=" B ",sC=" C "; // variabili con spazio var comma=",";eq="="; var bar="|";var _bar=" |";var bar_="| ";var _bar_=" | " // simboli comunque accessibili da tastiera var ag="{",cg="}",aq="[",cq="]",at="(",ct=")"; // parentesi (a)perte e (c)hiuse var s=" ",sp=s+s;spa=s+s+s;spac=s+s+s+s;space=s+s+s+s+s; // spazi pił o meno lunghi // abbreviazioni di comandi html function html(){ var s=""; for(var i=0;i" } return s; } // PARENTESI GRANDI ************** var atUP = fontChar("Symbol",230);var atMIDDLE = fontChar("Symbol",231); var atBOTTOM = fontChar("Symbol",232);var ctUP = fontChar("Symbol",246); var ctMIDDLE = fontChar("Symbol",247);var ctBOTTOM = fontChar("Symbol",248); var atBig= mat31(atUP,atMIDDLE,atBOTTOM) var ctBig= mat31(ctUP,ctMIDDLE,ctBOTTOM) var aqUP = fontChar("Symbol",233);var aqMIDDLE = fontChar("Symbol",234); var aqBOTTOM = fontChar("Symbol",235);var cqUP = fontChar("Symbol",249); var cqMIDDLE = fontChar("Symbol",250);var cqBOTTOM = fontChar("Symbol",251); var aqBig = mat31(aqUP,aqMIDDLE,aqBOTTOM) var cqBig = mat31(cqUP,cqMIDDLE,cqBOTTOM) var agUP = fontChar("Symbol",236);var agMIDDLE = fontChar("Symbol",237); var agBOTTOM = fontChar("Symbol",238);var cgUP = fontChar("Symbol",252); var cgMIDDLE = fontChar("Symbol",253);var cgBOTTOM = fontChar("Symbol",254); var agBig = mat31(agUP,agMIDDLE,agBOTTOM) var cgBig = mat31(cgUP,cgMIDDLE,cgBOTTOM) var intUP = fontChar("Symbol",243);var agMIDDLE = fontChar("Symbol",237); var intOTTOM = fontChar("Symbol",244);var cgUP = fontChar("Symbol",252); var intMIDDLE = fontChar("Symbol",245);var cgBOTTOM = fontChar("Symbol",254); var intBig = mat31(agUP,agMIDDLE,agBOTTOM) var intLittle = fontChar("Symbol",242);var agMIDDLE = fontChar("Symbol",237); // ********************************************** function pow(a,b){ return a+""+b+"" } // FUNZIONI A NUMERO DI ARGOMENTI VARIABILE function toVett(){return arguments} function compatta(x){var s="";for(var i=0;i","",arguments,"")} // compatta con prefisso, infisso e suffisso function mat31(a,b,c){ // restituisce 3 dati incolonnati return "
"+a+ "
"+b+ "
"+c+"
" } function red(){return compattaABvC("","",arguments,"")} function frac(num,den){ return mat31(num,"
",den)} // frazione function overline(x){ return ""+ ""+ "

"+ x+"
" } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::// // // Here (using the 'interpret' instruction ie 'eval' ) are constructed the constants // you will use; For each of the character of the font SYMBOL either is unusefull ("a") or // it is the symbol we need, for example 'include'. The eval instructions will construct the variable // var cdot='.'; var simbols=[ "a","a","a","a","a","a","a","a","a","a" //1-10 ,"a","a","a","a","a","a","a","a","a","a" //11-20 ,"a","a","a","a","a","a","a","a","a","a" //21-30 ,"a","a","a","pe","forall","diesis","exists","pc","and","nolispe" //31-40 ,"at","ct","star","plus","comma","minus","point","slash","n0","n1" //41-50 ,"n2","n3","n4","n5","n6","n7","n8","n9","dp","pv" //51-60 ,"lt","eq","gt","qp","approx","A","B","X","Delta","E" //61-70 ,"Phi","Gamma","H","I","Jota","Kappa","Lambda","M","N","O" //71-80 ,"PI","Omega","P","Sigma","T","Y","Csi","Omega","Csi","Psi" //81-90 ,"Z","aq","tp","cq","Tr","underscore","overscore","alpha","beta","csi" //91-100 ,"delta","epsilon","phi","gamma","eta","iota","psi","kappa","lambda","mu"//101-110 ,"nu","o","pi","teta","rho","sigma","tau","nu","omegabar","omega" //111-120 ,"yupsilon","psi","zeta","ag","bar","cg","tilde","a","a","a" //121-130 ,"a","a","a","a","a","a","a","a","a","a" //131-140 ,"a","a","a","a","a","a","a","a","a","a" //141-150 ,"a","a","a","a","a","a","a","a","a","a" //151-160 ,"a","erba","apix","leq","a","infty","f","fiori","quadri","cuori" //161-170 ,"picche","bifreccia","leftarrow","a","rightarrow","downarrow","grades","pm","biapix","ge" //171-180 ,"times","prop","diff","dot","tra","ne","coincide","bitilde","dots","bar"//181-190 ,"line","ret","aleph","imm","Re","p","tx","tp","empty","cap" //191-200 ,"cup","include","includeeq","noinclude","included","includedeq","inset","notinset","angle","nablagiu"//201-210 ,"registered","cr","tm","PPI","root","dot","not","vel","lev","biimp" //211-220 ,"Lefttarrow","Uparrow","Rigtharrow","Downarrow","bra","a","a","a","SSigma",//221-230 ,"atTOP","atMIDDLE","ctBOTTOM","aqTOP","aqMIDDLE","aqBOTTOM","agTOP","agMIDDLE","agBOTTOM","a"//231-240 ,"square","ket","int","intTOP","intMIDDLE","intBOTTOM","ctTOP","ctMIDDLE","ctBOTTOM"//241-250 ,"cqTOP","cqMIDDLE","cqBOTTOM","cgTOP","cgMIDDLE","cgBOTTOM","a","a","a"//251-255?? ]; // Constructing variable (also with a space in front and/or at end for emproving printing) // _diesis will be " #" , _diesis_ will be " # " // for(var k=33;k<255;k++){ if(k==39){nolispe=fontChar("Symbol",39);continue} zz=( "var "+ simbols[k] + "='" +fontChar("Symbol",k) +"';" ) zpre=( "var _"+ simbols[k] + "= '" +fontChar("Symbol",k) +"';" ) zpost=( "var "+ simbols[k] + "_='" +fontChar("Symbol",k) +" ';" ) zprepost=( "var _"+ simbols[k] + "_=' " +fontChar("Symbol",k) +" ';" ) eval(zz);eval(zpre);eval(zpost);eval(zprepost); } // // //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // Here we define variable _a= "a" and _b="b" and _A="A" and _B="B" in order to use them without // opening and closin apix // It has been choseen to use _a to let free for the user the a variable or the i variable // hoping user is not used to use underscore!! // Here there is no multiple declaration with blank so if you want to write " a " just write " a ". var autodefined=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]; for(var k=0;k