Skip to content

Commit 393c81d

Browse files
author
dpvc
committed
Bring up to version 3.6. Changes include:
* Added a new eqn-number extension that allows you to add equation numbers to displayed equations via \label{xxx} and refer to those numbers at other locations in the HTML page via \ref{xxx}. See the eqn-number documentation for more details. * Fixed more problems with Firefox3 and their new single-source security policy for loading local files. (Previous attempts worked with pre-release versions of Firefox3, but this works with the release version.) * Worked around a print bug with Firefox3 where thin horizontal rules could disappear in the printed version even though they appear on screen. * Added CSS styles to make images in hypertext links within mathematics be underlines when one of the image modes is in use. * Added CSS to help isolate the control panel width from the CSS of the main page. * Added ability to put the mathematics within CDATA to help avoid problems with <, > and & within the mathematics. For example: <SPAN CLASS="math"><!--[CDATA[ x > y ]]--></SPAN> Using <![CDATA[ ... ]]> without the -- does not work in some browsers. * The tex2math plugin now processes the tex2math_ignore and tex2math_process directives on an element even if there are other class names included on the element as well. * Fixed a bug with the autobold plugin in MSIE when certain fonts are used as the default font. * Enhanced the ability to preset the styles used by jsMath by making the jsMath.styles entries be associative arrays rather than strings. This makes it easy to change a single style setting: instead of retyping the entire string, you simply set the style value that you are interested in changing. * Fixed a problem where Safari3 would not be able to drag the TeX source window produced by double-clicking on typeset mathematics. * Added an option to control whether the @(...) construct is processed within \hbox{} or not. This would allow arbitrary HTML tags to be inserted, which poses a security risk for content-management systems where untrusted users are entering data. The easy/load.js file now has a setting to control this, and it is off by default, though it is on by default when loading jsMath.js by hand. To turn it off by hand, set jsMath.safeHBoxes to 1. * Added checks within the HTML extension that prevent the insertion of raw HTML into jsMath equations. * Added a jsMath.ProcessElement() call that allows you to process the contents of a single element (of class "math") as TeX code directly. Note that this call may return before the mathematics is actually finished typesetting. See the page on dynamic math for more details. * Modified the way jsMath works around the lack of support for position:fixed in MSIE so that style changes for where the jsMath button and control panel appear should work properly in MSIE. * Removed the "Check for Updates" button from the jsMath Control Panel and moved it to the jsMath/test/index.html page (since it is really an administrator function, not a user function). git-svn-id: http://svn.webwork.maa.org/system/trunk/webwork2@5911 c0722133-6baf-4dd8-8699-98d999cd4f06
1 parent d32ba09 commit 393c81d

18 files changed

+641
-220
lines changed

htdocs/jsMath/easy/load.js

+9
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ jsMath.Easy = {
7272
// '[display]','[/display]' // to begin and end display math
7373
//],
7474

75+
//
76+
// Disallow the use of the @(...) mechanism for including raw HTML
77+
// in the contents of \hbox{}? (If used in a content-management system
78+
// where users are allowed to enter mathematics, setting this to 0
79+
// would allow them to enter arbitrary HTML code within their
80+
// math formulas, and that poses a security risk.)
81+
//
82+
safeHBoxes: 1,
83+
7584
//
7685
// Show TeX source when mathematics is double-clicked?
7786
//

htdocs/jsMath/extensions/HTML.js

+11
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ jsMath.Package(jsMath.Parser,{
4444
*/
4545
Color: function (name) {
4646
var color = this.GetArgument(this.cmd+name); if (this.error) return;
47+
this.CheckHTML(color,name); if (this.error) return;
4748
// check that it looks like a color?
4849
this.AddHTML(name,['<span style="color: '+color+'">','</span>']);
4950
},
@@ -53,6 +54,7 @@ jsMath.Package(jsMath.Parser,{
5354
*/
5455
Href: function (name) {
5556
var href = this.GetArgument(this.cmd+name); if (this.error) return;
57+
this.CheckHTML(href,name); if (this.error) return;
5658
this.AddHTML(name,['<a class="link" href="'+href+'">','</a>']);
5759
},
5860

@@ -61,6 +63,7 @@ jsMath.Package(jsMath.Parser,{
6163
*/
6264
Class: function (name) {
6365
var clss = this.GetArgument(this.cmd+name); if (this.error) return;
66+
this.CheckHTML(clss,name); if (this.error) return;
6467
this.AddHTML(name,['<span class="'+clss+'">','</span>']);
6568
},
6669

@@ -69,6 +72,7 @@ jsMath.Package(jsMath.Parser,{
6972
*/
7073
Style: function (name) {
7174
var style = this.GetArgument(this.cmd+name); if (this.error) return;
75+
this.CheckHTML(style,name); if (this.error) return;
7276
this.AddHTML(name,['<span style="'+style+'">','</span>']);
7377
},
7478

@@ -77,6 +81,7 @@ jsMath.Package(jsMath.Parser,{
7781
*/
7882
CSSId: function (name) {
7983
var id = this.GetArgument(this.cmd+name); if (this.error) return;
84+
this.CheckHTML(id,name); if (this.error) return;
8085
this.AddHTML(name,['<span id="'+id+'">','</span>']);
8186
},
8287

@@ -94,6 +99,11 @@ jsMath.Package(jsMath.Parser,{
9499
this.mlist.Add(jsMath.mItem.HTML(params[1]));
95100
},
96101

102+
CheckHTML: function (data,name) {
103+
if (data.match(/[<>&"]/))
104+
{this.Error("Can't include raw HTML in first argument of "+this.cmd+name)}
105+
},
106+
97107
/*
98108
* Insert a unicode reference as an Ord atom. Its argument should
99109
* be the unicode code point, e.g. \unicode{8211}, or \unicode{x203F}.
@@ -103,6 +113,7 @@ jsMath.Package(jsMath.Parser,{
103113
*/
104114
Unicode: function (name) {
105115
var arg = this.GetArgument(this.cmd+name); if (this.error) return;
116+
this.CheckHTML(arg,name); if (this.error) return;
106117
arg = arg.split(','); arg[0] = '&#'+arg[0]+';';
107118
if (!arg[1]) {arg[1] = 'normal'}
108119
this.mlist.Add(jsMath.mItem.TextAtom('ord',arg[0],arg[1],arg[2],arg[3]));

htdocs/jsMath/extensions/autobold.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ jsMath.Extension.Require("boldsymbol");
4343

4444
jsMath.Translate.OldParse = jsMath.Translate.Parse;
4545
jsMath.Translate.Parse = function (style,text,noCache) {
46-
if (jsMath.BBoxFor('</SPAN></SPAN>MMMMMMMMMM<SPAN><SPAN>').w >
47-
jsMath.BBoxFor('</SPAN></SPAN><SPAN STYLE="font-weight:normal">MMMMMMMMMM</SPAN><SPAN><SPAN>').w) {
46+
if (jsMath.BBoxFor('</SPAN></SPAN><SPAN STYLE="font-family:Times,serif">MMMMMMMMMM</SPAN><SPAN><SPAN>').w >
47+
jsMath.BBoxFor('</SPAN></SPAN><SPAN STYLE="font-family:Times,serif; font-weight:normal">MMMMMMMMMM</SPAN><SPAN><SPAN>').w) {
4848
text = '\\boldsymbol{' + text + '}';
4949
}
5050
return jsMath.Translate.OldParse(style,text,noCache);

htdocs/jsMath/extensions/double-click.js

+37-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
* ---------------------------------------------------------------------
1313
*
14-
* Copyright 2005-2006 by Davide P. Cervone
14+
* Copyright 2005-2008 by Davide P. Cervone
1515
*
1616
* Licensed under the Apache License, Version 2.0 (the "License");
1717
* you may not use this file except in compliance with the License.
@@ -28,14 +28,44 @@
2828

2929
/********************************************************************/
3030

31+
if (jsMath.Click && jsMath.Click.styles)
32+
{jsMath.Click.oldStyles = jsMath.Click.styles}
33+
3134
jsMath.Add(jsMath.Click,{
3235

3336
dragging: 0,
3437

38+
styles: {
39+
// Floating windows for displaying TeX source
40+
'#jsMath_float': {
41+
position: 'absolute', top: '0px', left: '0px', 'z-index': '101',
42+
'max-width': '80%', width: 'auto', height: 'auto',
43+
padding: '0px', margin: '0px', 'font-size': '100%'
44+
},
45+
'#jsMath_float .drag': {
46+
'background-color': '#DDDDDD',
47+
border: 'outset 1px', padding: '0px', margin: '0px',
48+
width: 'auto', height: '12px', 'font-size': '1px'
49+
},
50+
'#jsMath_float .close': {
51+
'background-color': '#E6E6E6',
52+
border: 'inset 1px', margin: '1px 2px', padding: '0px',
53+
width: '8px', height: '8px'
54+
},
55+
'#jsMath_float .source': {
56+
'background-color': '#E2E2E2',
57+
border: 'outset 1px', margin: '0px', padding: '8px 15px',
58+
width: 'auto', height: 'auto',
59+
'font-family': 'courier, fixed', 'font-size': '90%'
60+
}
61+
},
62+
3563
/*
3664
* Create the hidden DIV used for the tex source window
3765
*/
3866
Init: function () {
67+
if (this.oldStyles) {jsMath.Insert(this.styles,this.oldStyles)}
68+
jsMath.Setup.Styles(this.styles);
3969
this.source = jsMath.Setup.DIV("float",{display:'none'});
4070
this.source.innerHTML =
4171
'<div class="drag"><div class="close"></div></div>'
@@ -177,10 +207,10 @@ jsMath.Add(jsMath.Click,{
177207
jsMath.Click.dragging = 1;
178208
jsMath.Click.x = event.x + 2*event.X - jsMath.Click.left;
179209
jsMath.Click.y = event.y + 2*event.Y - jsMath.Click.top;
180-
jsMath.Click.oldonmousemove = jsMath.document.body.onmousemove;
181-
jsMath.Click.oldonmouseup = jsMath.document.body.onmouseup;
182-
jsMath.document.body.onmousemove = jsMath.Click.DragSource;
183-
jsMath.document.body.onmouseup = jsMath.Click.StopDragging;
210+
jsMath.Click.oldonmousemove = jsMath.document.onmousemove;
211+
jsMath.Click.oldonmouseup = jsMath.document.onmouseup;
212+
jsMath.document.onmousemove = jsMath.Click.DragSource;
213+
jsMath.document.onmouseup = jsMath.Click.StopDragging;
184214
return false;
185215
},
186216

@@ -189,8 +219,8 @@ jsMath.Add(jsMath.Click,{
189219
*/
190220
StopDragging: function (event) {
191221
if (jsMath.Click.dragging) {
192-
jsMath.document.body.onmousemove = jsMath.Click.oldonmousemove;
193-
jsMath.document.body.onmouseup = jsMath.Click.oldonmouseup;
222+
jsMath.document.onmousemove = jsMath.Click.oldonmousemove;
223+
jsMath.document.onmouseup = jsMath.Click.oldonmouseup;
194224
jsMath.Click.oldonmousemove = null;
195225
jsMath.Click.oldonmouseup = null;
196226
jsMath.Click.dragging = 0;
+199
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
/*
2+
* extensions/eqn-number.js
3+
*
4+
* Part of the jsMath package for mathematics on the web.
5+
*
6+
* This file causes jsMath to add equation numbers to displayed
7+
* equations. These are displayed at the right, but the styles can
8+
* be controlled through the jsMath.EqnNumber object. Equations
9+
* are numbered if they include a \label{xxx} call, and the macro
10+
* \ref{xxx} can be used to refer to the equation number elsewhere
11+
* in the document (it must appear by itself in a math formula,
12+
* e.g., $\ref{xxx}$). The "label-ref" CSS style can be used to
13+
* style the references.
14+
*
15+
* If jsMath.EqnNumber.autonumber is set to 1, then ALL displayed
16+
* equations will be numberd. Use the \nolabel macro to prevent
17+
* equation numbering on an equation.
18+
*
19+
* You can activate eqn-numbering by calling
20+
*
21+
* jsMath.Extension.Require('eqn-number');
22+
*
23+
* once jsMath.js has been loaded, or by adding "extensions/eqn-number.js"
24+
* to the loadFiles array in jsMath/easy/load.js.
25+
*
26+
* ---------------------------------------------------------------------
27+
*
28+
* Copyright 2008 by Davide P. Cervone
29+
*
30+
* Licensed under the Apache License, Version 2.0 (the "License");
31+
* you may not use this file except in compliance with the License.
32+
* You may obtain a copy of the License at
33+
*
34+
* http://www.apache.org/licenses/LICENSE-2.0
35+
*
36+
* Unless required by applicable law or agreed to in writing, software
37+
* distributed under the License is distributed on an "AS IS" BASIS,
38+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
39+
* See the License for the specific language governing permissions and
40+
* limitations under the License.
41+
*/
42+
43+
/********************************************************************/
44+
45+
if (jsMath.EqnNumber) {jsMath.EqnNumber_old = jsMath.EqnNumber}
46+
47+
jsMath.EqnNumber = {
48+
49+
styles: {
50+
'.jsMath_displayBox, .tex2math_div': {position: 'relative'},
51+
'.jsMath_number': {
52+
position: 'absolute',
53+
right: '2em', top: '50%', 'margin-top': '-.5em',
54+
height: 'auto', width: 'auto'
55+
},
56+
'.jsMath_ref': {'text-decoration': 'none'}
57+
},
58+
59+
autonumber: 0, // set to 1 to have ALL equations numbered
60+
61+
number: 0,
62+
format: function (n) {return n},
63+
formatLabel: function (n) {return '<A NAME="eqn-'+n+'">('+n+')</A>'},
64+
formatRef: function (n) {return '(<A CLASS="jsMath_ref" HREF="#eqn-'+n+'">'+n+'</A>)'},
65+
66+
_label: null, // flag set when \label{x} is used
67+
_labels: {}, // stores label-name => label-value pairs
68+
_refs: {}, // stores elements referring to undefined labels
69+
_nolabel: 0, // set by \nolabel
70+
71+
nextNumber: function () {
72+
var ref = this.format(++this.number);
73+
if (this._label) {
74+
this._labels[this._label] = ref;
75+
if (this._refs[this._label]) this.fixRefs(this._label);
76+
}
77+
return this.formatLabel(ref);
78+
},
79+
80+
isRef: function (element) {
81+
var tex = element.innerHTML;
82+
var result = tex.match(/^\s*\\ref\s*\{([^\}]+)\}\s*$/);
83+
if (!result) {return 0}
84+
var ref = result[1];
85+
if (this._labels[ref]) {
86+
this.setRef(element,ref);
87+
} else {
88+
if (!this._refs[ref]) {this._refs[ref] = []}
89+
this._refs[ref][this._refs[ref].length] = element;
90+
}
91+
return 1;
92+
},
93+
94+
setRef: function (element,ref) {
95+
element.innerHTML = this.formatRef(this._labels[ref]);
96+
element.className = "label-ref";
97+
},
98+
99+
fixRefs: function (label) {
100+
for (var i = 0; i < this._refs[label].length; i++)
101+
{this.setRef(this._refs[label][i],label)}
102+
delete this._refs[label];
103+
},
104+
105+
badRefs: function () {
106+
for (var label in this._refs) {
107+
for (var i = 0; i < this._refs[label].length; i++) {
108+
var element = this._refs[label][i];
109+
element.className = "typeset";
110+
element.innerHTML = "<span class='error'>Reference '"+label+"' is undefined</span>";
111+
}
112+
}
113+
},
114+
115+
makeDIV: function (element) {
116+
var div = document.createElement('div');
117+
div.className = 'jsMath_displayBox';
118+
div.innerHTML = '<div class="jsMath_number">' + this.nextNumber() + '</div>';
119+
element.parentNode.insertBefore(div,element);
120+
element.parentNode.removeChild(element);
121+
div.appendChild(element);
122+
},
123+
124+
makeSPAN: function (element) {
125+
var span = document.createElement('span');
126+
span.className = 'jsMath_number';
127+
span.style.display = 'inline-block';
128+
span.innerHTML = jsMath.EqnNumber.nextNumber();
129+
element.parentNode.insertBefore(span,element);
130+
},
131+
132+
ConvertMath: function (style,element,nocache) {
133+
var EqnNumber = jsMath.EqnNumber;
134+
if (EqnNumber.isRef(element)) return;
135+
EqnNumber._label = null; EqnNumber._nolabel = 0;
136+
this.ConvertMath_old(style,element,nocache);
137+
if (EqnNumber._label || (EqnNumber.autonumber && !EqnNumber._nolabel)) {
138+
if (element.tagName.toLowerCase() == 'div') {
139+
EqnNumber.makeDIV(element);
140+
} else if (element.parentNode.className == 'tex2math_div') {
141+
EqnNumber.makeSPAN(element);
142+
}
143+
}
144+
},
145+
146+
ProcessComplete: function () {
147+
jsMath.EqnNumber.badRefs();
148+
this.ProcessComplete_old.apply(this,arguments);
149+
},
150+
151+
Init: function () {
152+
jsMath.Setup.Styles(this.styles);
153+
jsMath.Translate.ConvertMath_old = jsMath.Translate.ConvertMath;
154+
jsMath.Translate.ConvertMath = this.ConvertMath;
155+
jsMath.Translate.ProcessComplete_old = jsMath.Translate.ProcessComplete;
156+
jsMath.Translate.ProcessComplete = this.ProcessComplete;
157+
}
158+
159+
};
160+
161+
if (jsMath.EqnNumber_old) {
162+
jsMath.Insert(jsMath.EqnNumber,jsMath.EqnNumber_old);
163+
delete jsMath.EqnNumber_old;
164+
}
165+
166+
jsMath.Package(jsMath.Parser,{
167+
macros: {
168+
label: 'Label',
169+
nolabel: 'NoLabel',
170+
ref: 'Ref'
171+
},
172+
173+
Label: function (name) {
174+
var label = this.GetArgument(this.cmd+name); if (this.error) return;
175+
var EqnNumber = jsMath.EqnNumber;
176+
if (!EqnNumber._label) {
177+
if (!EqnNumber._labels[label]) {
178+
EqnNumber._label = label;
179+
EqnNumber._nolabel = 0;
180+
} else {
181+
this.Error("Label '"+label+"' is already defined");
182+
}
183+
} else {
184+
this.Error(this.cmd+name+' can only be used once in an equation');
185+
}
186+
},
187+
188+
NoLabel: function (name) {
189+
var EqnNumber = jsMath.EqnNumber;
190+
EqnNumber._label = null; EqnNumber._nolabel = 1;
191+
},
192+
193+
Ref: function (name) {
194+
this.Error(this.cmd+name+' must be used by itself');
195+
}
196+
197+
});
198+
199+
jsMath.EqnNumber.Init();

htdocs/jsMath/extensions/underset-overset.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
jsMath.Package(jsMath.Parser,{
3131

3232
macros: {
33-
overset: 'Overset',
34-
underset: 'Underset'
33+
overset: 'Overset',
34+
underset: 'Underset'
3535
},
3636

3737
Overset: function (name) {

htdocs/jsMath/jsMath-BaKoMa-fonts.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -418,11 +418,11 @@ if (jsMath.browser == "Mozilla" && jsMath.platform != "mac") {
418418
}
419419

420420
jsMath.Setup.Styles({
421-
'.typeset .cmr10': 'font-family: cmr10, serif',
422-
'.typeset .cmbx10': 'font-family: cmbx10, cmr10',
423-
'.typeset .cmti10': 'font-family: cmti10, cmr10',
424-
'.typeset .cmmi10': 'font-family: cmmi10',
425-
'.typeset .cmsy10': 'font-family: cmsy10',
426-
'.typeset .cmex10': 'font-family: cmex10',
421+
'.typeset .cmr10': 'font-family: CMR10, serif',
422+
'.typeset .cmbx10': 'font-family: CMBX10, CMR10',
423+
'.typeset .cmti10': 'font-family: CMTI10, CMR10',
424+
'.typeset .cmmi10': 'font-family: CMMI10',
425+
'.typeset .cmsy10': 'font-family: CMSY10',
426+
'.typeset .cmex10': 'font-family: CMEX10',
427427
'.typeset .arial': "font-family: 'Arial unicode MS'"
428428
});

0 commit comments

Comments
 (0)