From: dpvc v. a. <we...@ma...> - 2005-10-22 04:31:06
|
Log Message: ----------- Updated to jsMath v2.3b. See the jsMath website for the change log for this version. Modified Files: -------------- webwork-modperl/htdocs/jsMath: jsMath-controls.html jsMath-fallback-mac.js jsMath-fallback-pc.js jsMath-fallback-symbols.js jsMath-fallback-unix.js jsMath.js webwork-modperl/htdocs/jsMath/plugins: tex2math.js Revision Data ------------- Index: jsMath-fallback-symbols.js =================================================================== RCS file: /webwork/cvs/system/webwork-modperl/htdocs/jsMath/jsMath-fallback-symbols.js,v retrieving revision 1.1 retrieving revision 1.2 diff -Lhtdocs/jsMath/jsMath-fallback-symbols.js -Lhtdocs/jsMath/jsMath-fallback-symbols.js -u -r1.1 -r1.2 --- htdocs/jsMath/jsMath-fallback-symbols.js +++ htdocs/jsMath/jsMath-fallback-symbols.js @@ -33,7 +33,7 @@ * characters precomputed */ TeX: function (C,font,style,size) { - c = jsMath.TeX[font][C]; + c = jsMath.TeX[font][C]; if (!c.tclass) {c.tclass = font} if (c.img != null) {return this.TeX_orig(C,font,style,size)} if (c.h != null && c.a == null) {c.a = c.h-1.1*jsMath.TeX.x_height} var box = this.Text(c.c,c.tclass,style,size,c.a,c.d); Index: jsMath-controls.html =================================================================== RCS file: /webwork/cvs/system/webwork-modperl/htdocs/jsMath/jsMath-controls.html,v retrieving revision 1.2 retrieving revision 1.3 diff -Lhtdocs/jsMath/jsMath-controls.html -Lhtdocs/jsMath/jsMath-controls.html -u -r1.2 -r1.3 --- htdocs/jsMath/jsMath-controls.html +++ htdocs/jsMath/jsMath-controls.html @@ -197,13 +197,14 @@ </TD></TR> <TR><TD ALIGN="CENTER" COLSPAN="2"> <INPUT TYPE="BUTTON" ID="jsMath.resolution" VALUE="Hi-Res Fonts for Printing" - STYLE="width:16em" onClick="jsMath.Controls.PrintResolution()"> + STYLE="width:17em" onClick="jsMath.Controls.PrintResolution()"> </TD></TR> <TR><TD HEIGHT="5"></TD></TR> -<TR VALIGN="TOP"><TD ALIGN="LEFT"> -<INPUT TYPE="BUTTON" VALUE="Options" ID="jsMath.opts" STYLE="width:7em" onClick="jsMath.Controls.Options()"> +<TR><TD ALIGN="LEFT"> +<INPUT TYPE="BUTTON" VALUE="Options" ID="jsMath.opts" STYLE="width:8em" onClick="jsMath.Controls.Options()"> + </TD><TD ALIGN="RIGHT"> -<INPUT TYPE="BUTTON" VALUE="Done" ID="jsMath.done" STYLE="width:7em" onClick="jsMath.Controls.Close()"> +<INPUT TYPE="BUTTON" VALUE="Done" ID="jsMath.done" STYLE="width:8em" onClick="jsMath.Controls.Close()"> </TD></TR> </TABLE></TD></TR> <TR><TD HEIGHT="10"></TD></TR> Index: jsMath-fallback-unix.js =================================================================== RCS file: /webwork/cvs/system/webwork-modperl/htdocs/jsMath/jsMath-fallback-unix.js,v retrieving revision 1.2 retrieving revision 1.3 diff -Lhtdocs/jsMath/jsMath-fallback-unix.js -Lhtdocs/jsMath/jsMath-fallback-unix.js -u -r1.2 -r1.3 --- htdocs/jsMath/jsMath-fallback-unix.js +++ htdocs/jsMath/jsMath-fallback-unix.js @@ -874,7 +874,7 @@ /* * We need to replace the jsMath.Box.TeX function in order to use the - * different font metrics in thie tables above, and to handle the + * different font metrics in the tables above, and to handle the * scaling better. */ @@ -883,7 +883,7 @@ TeX_orig = jsMath.Box.TeX, TeX: function (C,font,style,size) { - c = jsMath.TeX[font][C]; + c = jsMath.TeX[font][C]; if (!c.tclass) {c.tclass = font} if (c.img != null) {return this.TeX_orig(C,font,style,size)} if (c.h != null && c.a == null) {c.a = c.h-1.1*jsMath.TeX.x_height} var box = this.Text(c.c,c.tclass,style,size,c.a,c.d); Index: jsMath.js =================================================================== RCS file: /webwork/cvs/system/webwork-modperl/htdocs/jsMath/jsMath.js,v retrieving revision 1.17 retrieving revision 1.18 diff -Lhtdocs/jsMath/jsMath.js -Lhtdocs/jsMath/jsMath.js -u -r1.17 -r1.18 --- htdocs/jsMath/jsMath.js +++ htdocs/jsMath/jsMath.js @@ -66,7 +66,7 @@ var jsMath = { - version: "2.1d", // change this if you edit the file + version: "2.3b", // change this if you edit the file // // Name of image files @@ -210,7 +210,7 @@ * Get the em size and if it has changed, reinitialize the sizes */ ReInit: function () { - var em = this.BBoxFor('<DIV STYLE="width: 10em; height: 1em"></DIV>').w/10; + var em = this.BBoxFor('<SPAN STYLE="width: 10em; height: 1em"></SPAN>').w/10; if (em != this.em) {this.Init(em)} }, @@ -288,7 +288,8 @@ * Source a jsMath JavaScript file */ Script: function (file) { - document.write('<SCRIPT SRC="'+jsMath.root+file+'"></SCRIPT>'); + if (!file.match('^([a-zA-Z]+:/)?/')) {file = jsMath.root + file} + document.write('<SCRIPT SRC="'+file+'"></SCRIPT>'); }, /* @@ -298,7 +299,6 @@ jsMath.hidden = this.TopHTML("Hidden",{'class':"normal"},{ position:"absolute", top:0, left:0, border:0, padding:0, margin:0 }); - jsMath.hiddenDIV = jsMath.hidden; return; }, @@ -764,16 +764,22 @@ '<B>No TeX fonts found</B> -- using image fonts instead.<BR>\n' + 'These may be slow and might not print well.<BR>\n' + 'Use the jsMath control panel to get additional information.', + + extra_message: + 'Extra TeX fonts not found: <B><SPAN ID="jsMath.ExtraFonts"></SPAN></B><BR>' + + 'Using image fonts instead. This may be slow and might not print well.<BR>\n' + + 'Use the jsMath control panel to get additional information.', /* * Look to see if a font is found. HACK! - * Check the character in the '|' position, and see if it is - * wider than the usual '|'. + * Check the character in a given position, and see if it is + * wider than the usual one in that position. */ Test1: function (name,n,factor) { if (n == null) {n = 124}; if (factor == null) {factor = 2} var wh1 = jsMath.BBoxFor('<SPAN STYLE="font-family: '+name+', serif">'+jsMath.TeX[name][n].c+'</SPAN>'); var wh2 = jsMath.BBoxFor('<SPAN STYLE="font-family: serif">'+jsMath.TeX[name][n].c+'</SPAN>'); + //alert([wh1.w,wh2.w,wh1.h,factor*wh2.w]); return (wh1.w > factor*wh2.w && wh1.h != 0); }, @@ -781,6 +787,7 @@ if (n == null) {n = 124}; if (factor == null) {factor = 2} var wh1 = jsMath.BBoxFor('<SPAN STYLE="font-family: '+name+', serif">'+jsMath.TeX[name][n].c+'</SPAN>'); var wh2 = jsMath.BBoxFor('<SPAN STYLE="font-family: serif">'+jsMath.TeX[name][n].c+'</SPAN>'); + //alert([wh2.w,wh1.w,wh1.h,factor*wh1.w]); return (wh2.w > factor*wh1.w && wh1.h != 0); }, @@ -843,6 +850,7 @@ * of your page. */ Message: function (message) { + if(jsMath.Element("Warning")) return; var div = jsMath.Setup.TopHTML("Warning",{'class':'jsM_Warning'},{}); div.innerHTML = '<CENTER><TABLE><TR><TD>' @@ -859,7 +867,62 @@ HideMessage: function () { var message = jsMath.Element("Warning"); if (message) {message.style.display = "none"} - } + }, + + /* + * Register an extra font so jsMath knows about it + */ + Register: function (data) { + if (typeof(data) == 'string') {data = {name: data}} + var fontname = data.name; var name = fontname.replace(/10$/,''); + var fontfam = jsMath.TeX.fam.length; + if (!data.style) {data.style = "font-family: "+fontname+", serif"} + if (!data.styles) {data.styles = {}} + if (!data.macros) {data.macros = {}} + /* + * Register font family + */ + jsMath.TeX.fam[fontfam] = fontname; + data.macros[name] = ['HandleFont',fontfam]; + jsMath.Add(jsMath.Parser.prototype.macros,data.macros); + /* + * Set up styles + */ + data.styles['.'+fontname] = data.style; + jsMath.Setup.Styles(data.styles); + jsMath.Setup.TeXfont(fontname); + /* + * Check for font and give message if missing + */ + var hasTeXfont = !jsMath.nofonts && + data.test(fontname,data.testChar,data.testFactor); + if (hasTeXfont && jsMath.Controls.cookie.font == 'tex') { + if (data.tex) {data.tex(fontname,fontfam)} + return; + } + if (!hasTeXfont && jsMath.Controls.cookie.warn && + jsMath.Controls.cookie.font == 'tex' && !jsMath.nofonts) { + if (!jsMath.Element("Warning")) this.Message(this.extra_message); + var extra = jsMath.Element("ExtraFonts"); + if (extra) { + if (extra.innerHTML != "") {extra.innerHTML += ','} + extra.innerHTML += " " + fontname; + } + } + if (jsMath.Controls.cookie.font == 'unicode') { + if (data.fallback) {data.fallback(fontname,fontfam)} + return; + } + // Image fonts + var font = {}; font[fontname] = ['all']; + jsMath.Img.SetFont(font); + jsMath.Img.LoadFont(fontname); + }, + + /* + * Load a font + */ + Load: function (name) {jsMath.Setup.Script("fonts/"+name+"/def.js")} }; @@ -1930,9 +1993,6 @@ // image fonts are loaded loaded: 0, - // temporarily force scaling of images (when jsMath.hidden can't be changed) - forceScale: 0, - // add characters to be drawn using images SetFont: function (change) { for (var font in change) { @@ -2225,7 +2285,7 @@ TeX: function (C,font,style,size) { var c = jsMath.TeX[font][C]; if (c.d == null) {c.d = 0}; if (c.h == null) {c.h = 0} - if (c.img != null) this.TeXIMG(font,C,jsMath.Typeset.StyleSize(style,size)); + if (c.img != null && c.c != '') this.TeXIMG(font,C,jsMath.Typeset.StyleSize(style,size)); var scale = jsMath.Typeset.TeX(style,size).scale; var h = c.h + jsMath.TeX[font].dh var box = new jsMath.Box('text',c.c,c.w*scale,h*scale,c.d*scale); @@ -2259,7 +2319,7 @@ var c = jsMath.TeX[font][C]; if (c.img.size != null && c.img.size == size && c.img.best != null && c.img.best == jsMath.Img.best) return; - var mustScale = (jsMath.Img.scale != 1 || jsMath.Img.forceScale); + var mustScale = (jsMath.Img.scale != 1); var id = jsMath.Img.best + size - 4; if (id < 0) {id = 0; mustScale = 1} else if (id >= jsMath.Img.fonts.length) {id = jsMath.Img.fonts.length-1; mustScale = 1} @@ -5445,22 +5505,11 @@ /* * Move hidden to the location of the math element to be * processed and reinitialize sizes for that location. - * For MSIE (which can't put a DIV inside a SPAN), - * default to the standard hidden DIV, but check to - * see if we need to scale images or not. */ ResetHidden: function (element) { - jsMath.Img.forceScale = 0; - try { - element.innerHTML = '<DIV CLASS="normal" STYLE="position:absolute; top:0; left: 0;"></DIV>'; - element.className=''; - jsMath.hidden = element.firstChild; - } catch (err) { - element.innerHTML = '<SPAN CLASS="normal">M</SPAN>'; - var w = element.offsetWidth; - jsMath.hidden = jsMath.hiddenDIV; - jsMath.Img.forceScale = (Math.abs(w-jsMath.BBoxFor("M").w) > w/10); - } + element.innerHTML = '<SPAN CLASS="normal" STYLE="position:absolute; top:0;left:0;"></SPAN>'; + element.className=''; + jsMath.hidden = element.firstChild; jsMath.ReInit(); }, @@ -5558,7 +5607,7 @@ GetMathElements: function (obj) { var element = []; if (!obj) {obj = document} - if (typeof(obj) == 'string') {obj = document.getElementById(ibj)} + if (typeof(obj) == 'string') {obj = document.getElementById(obj)} if (!obj.getElementsByTagName) return var math = obj.getElementsByTagName('DIV'); for (var k = 0; k < math.length; k++) { Index: jsMath-fallback-mac.js =================================================================== RCS file: /webwork/cvs/system/webwork-modperl/htdocs/jsMath/jsMath-fallback-mac.js,v retrieving revision 1.4 retrieving revision 1.5 diff -Lhtdocs/jsMath/jsMath-fallback-mac.js -Lhtdocs/jsMath/jsMath-fallback-mac.js -u -r1.4 -r1.5 --- htdocs/jsMath/jsMath-fallback-mac.js +++ htdocs/jsMath/jsMath-fallback-mac.js @@ -874,15 +874,15 @@ /* * We need to replace the jsMath.Box.TeX function in order to use the - * different font metrics in thie tables above, and to handle the + * different font metrics in the tables above, and to handle the * scaling better. */ jsMath.Add(jsMath.Box,{ TeX: function (C,font,style,size) { - c = jsMath.TeX[font][C]; + c = jsMath.TeX[font][C]; if (!c.tclass) {c.tclass = font} if (c.h != null && c.a == null) {c.a = c.h-1.1*jsMath.TeX.x_height} - if (c.img != null) this.TeXIMG(font,C,jsMath.Typeset.StyleSize(style,size)); + if (c.img != null && c.c != '') this.TeXIMG(font,C,jsMath.Typeset.StyleSize(style,size)); var box = this.Text(c.c,c.tclass,style,size,c.a,c.d); var scale = jsMath.Typeset.TeX(style,size).scale; if (c.bh != null) { @@ -941,7 +941,7 @@ '.vertical': "font-family: Copperplate", '.vertical1': "font-family: Copperplate; font-size: 85%; margin: .15em;", '.vertical2': "font-family: Copperplate; font-size: 85%; margin: .17em;", - '.greek': "font-family: Symbol", + '.greek': "font-family: serif", '.bigop1': "font-family: 'Hiragino Mincho Pro'; font-size: 133%; position: relative; top: .85em; margin:-.05em", '.bigop1a': "font-family: Baskerville; font-size: 100%; position: relative; top: .775em;", '.bigop1b': "font-family: 'Hiragino Mincho Pro'; font-size: 160%; position: relative; top: .7em; margin:-.1em", Index: jsMath-fallback-pc.js =================================================================== RCS file: /webwork/cvs/system/webwork-modperl/htdocs/jsMath/jsMath-fallback-pc.js,v retrieving revision 1.4 retrieving revision 1.5 diff -Lhtdocs/jsMath/jsMath-fallback-pc.js -Lhtdocs/jsMath/jsMath-fallback-pc.js -u -r1.4 -r1.5 --- htdocs/jsMath/jsMath-fallback-pc.js +++ htdocs/jsMath/jsMath-fallback-pc.js @@ -880,9 +880,9 @@ jsMath.Add(jsMath.Box,{ TeX: function (C,font,style,size) { - c = jsMath.TeX[font][C]; + c = jsMath.TeX[font][C]; if (!c.tclass) {c.tclass = font} if (c.h != null && c.a == null) {c.a = c.h-1.1*jsMath.TeX.x_height} - if (c.img != null) this.TeXIMG(font,C,jsMath.Typeset.StyleSize(style,size)); + if (c.img != null && c.c != '') this.TeXIMG(font,C,jsMath.Typeset.StyleSize(style,size)); var box = this.Text(c.c,c.tclass,style,size,c.a,c.d); var scale = jsMath.Typeset.TeX(style,size).scale; if (c.bh != null) { Index: tex2math.js =================================================================== RCS file: /webwork/cvs/system/webwork-modperl/htdocs/jsMath/plugins/tex2math.js,v retrieving revision 1.1 retrieving revision 1.2 diff -Lhtdocs/jsMath/plugins/tex2math.js -Lhtdocs/jsMath/plugins/tex2math.js -u -r1.1 -r1.2 --- htdocs/jsMath/plugins/tex2math.js +++ htdocs/jsMath/plugins/tex2math.js @@ -28,12 +28,14 @@ jsMath.Add(jsMath,{ ConvertTeX: function (element) {jsMath.tex2math.ConvertMath("tex",element)}, + ConvertTeX2: function (element) {jsMath.tex2math.ConvertMath("tex2",element)}, ConvertLaTeX: function (element) {jsMath.tex2math.ConvertMath("latex",element)}, tex2math: { pattern: { - tex: /((^|[^\\])(\\[^\[\(])*)(\\\((([^\\]|\\[^\)])*)\\\)|\\\[(([^\\]|\\[^\]])*)\\\]|(\$\$?)(([^$\\]|\\.)*)\9)/, + tex: /((^|[^\\])(\\[^\[\(])*)(\\\((([^\\]|\\[^\)])*)\\\)|\\\[(([^\\]|\\[^\]])*)\\\]|\$\$((\\.|\$[^$\\]|[^$\\])*)\$\$|\$(([^$\\]|\\.)*)\$)/, + tex2: /((^|[^\\])(\\[^\[\(])*)(\\\((([^\\]|\\[^\)])*)\\\)|\\\[(([^\\]|\\[^\]])*)\\\]|\$\$((\\.|\$[^$\\]|[^$\\])*)\$\$)/, latex: /((^|[^\\])(\\[^\[\(])*)(\\\((([^\\]|\\[^\)])*)\\\)|\\\[(([^\\]|\\[^\]])*)\\\])/ }, @@ -42,14 +44,13 @@ if (recurse) return; element = document.body; } - if (typeof(element) == 'string') - {element = document.getElementById(element)} + if (typeof(element) == 'string') {element = document.getElementById(element)} var pattern = jsMath.tex2math.pattern[method]; while (element) { if (element.nodeName == '#text') { if (!element.parentNode.tagName || - !element.parentNode.tagName.match(/^(SCRIPT|STYLE|TEXTAREA)$/i)) { + !element.parentNode.tagName.match(/^(SCRIPT|NOSCRIPT|STYLE|TEXTAREA)$/i)) { element = jsMath.tex2math.TeX2math(pattern,element); } } else { @@ -67,9 +68,15 @@ if (element.nodeValue.search(/\\\$/) >= 0) {element.nodeValue = element.nodeValue.replace(/\\\$/g,'')} math.parentNode.removeChild(math); - if (text = (result[5] || result[7] || result[10])) { + if (text = (result[5] || result[7] || result[9] || result[11])) { tag = jsMath.tex2math.createMathTag(result[4].substr(0,2),text); - rest.parentNode.insertBefore(tag,rest); + if (rest.parentNode) { + rest.parentNode.insertBefore(tag,rest); + } else if (element.nextSibling) { + element.parentNode.insertBefore(tag,element.nextSibling); + } else { + element.parentNode.appendChild(tag); + } } element = rest; } |