PageSourceSearch

https://www.minimath.net/main.js

js minimath.net collected 2026-09-24 12:43:43 UTC 25,982 bytes, 731 lines download raw bytes

1function displayPreview() {
2	var exp = document.getElementById("InputExp");
3
4	var prw = document.getElementById("InputPreview");
5	prw.innerHTML = exp.value.toLowerCase(); // In order to avoid ambiguity, upper case variables are converted to lower case
6	
7	// Manage bad chars
8	prw.innerHTML = prw.innerHTML.replace(/(\x7C|\x02|\x03|\x04|\x05|\x08|\x09|\x20|\x22|\x27|\x3F|\x5C|\uFE0F|\u25AF)/g, ''); // pipe char (as cursor) and bad chars to be removed
9	prw.innerHTML = prw.innerHTML.replace(/(\xD7|\xB7|\u2022|\u22C5|\u2716)/g, '*'); // bad char of multiplication
10	prw.innerHTML = prw.innerHTML.replace(/\xF7/g, ':'); // bad char of division
11	prw.innerHTML = prw.innerHTML.replace(/(\u2212|\u2013|\u23AF|\x5F|\xAD)/g, '-'); // bad char of subtraction
12	prw.innerHTML = prw.innerHTML.replace(/\u02C6/g, '^');  // bad char of raising to a power
13	prw.innerHTML = prw.innerHTML.replace(/=>/g, '>=');  // bad inequalities
14	prw.innerHTML = prw.innerHTML.replace(/=&lt;/g, '<=');  // bad inequalities
15	
16	// Manage not useful signs
17	prw.innerHTML = prw.innerHTML.replace(/\x5e+/g, '^'); // ^^
18	prw.innerHTML = prw.innerHTML.replace(/\x2a+/g, '*'); // **
19	prw.innerHTML = prw.innerHTML.replace(/\x2f+/g, '/'); // //
20	prw.innerHTML = prw.innerHTML.replace(/\x2b+/g, '+'); // ++
21	prw.innerHTML = prw.innerHTML.replace(/\x5e\x2b/g, '^'); // ^+
22	prw.innerHTML = prw.innerHTML.replace(/\x2a\x2b/g, '*'); // *+
23	prw.innerHTML = prw.innerHTML.replace(/\x2f\x2b/g, '/'); // /+
24	prw.innerHTML = prw.innerHTML.replace(/\x3a\x2b/g, ':'); // :+
25	prw.innerHTML = prw.innerHTML.replace(/\x24\x2b/g, '$'); // $+
26	prw.innerHTML = prw.innerHTML.replace(/\x26\x2b/g, '&'); // &+
27		
28	// Manage monomials
29	patt = /[a-z][0-9]/i;
30	s = new String(patt.exec(prw.innerHTML));
31	while (s.valueOf()!="null") {
32		a = s.charAt(0)+"^"+s.charAt(1);
33		prw.innerHTML = prw.innerHTML.replace(s.valueOf(), a);
34		s = new String(patt.exec(prw.innerHTML));
35	}
36
37	// Manage some MathJax's displays
38	prw.innerHTML = prw.innerHTML.replace(/xx/g, 'x*x'); // xx is not displayed as wanted
39	prw.innerHTML = prw.innerHTML.replace(/bb/g, 'b*b'); // bb is not displayed as wanted
40	prw.innerHTML = prw.innerHTML.replace(/cc/g, 'c*c'); // cc is not displayed as wanted
41	
42	// Typeset preview
43	prw.innerHTML = "`" + prw.innerHTML + "`";
44	MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
45}
46
47function generateDefaultExample() {
48	// Generate a random default example if it's not provided by the MTH_INPUT parameter in the URL
49	var exp = document.getElementById("InputExp");
50	exp.value = "";
51	
52	s = location.toString().split("?");
53	if (s.length > 1) {
54		s = s[1].split("&");
55		for(var i = 0; i < s.length; i++) {
56			u = s[i].split("=");
57			if (u[0] == "MTH_INPUT") 
58				exp.value = decodeURIComponent(u[1]);
59		}
60	}
61		
62	if (exp.value == "") {
63		var Examples = [
64			"(x+1+(2x+2)/(x-1))*(x/(x2+x))",
65			"{(2/3-1/9)^2:[3/5:(2-1/5)]^4}*(1/5)^3+3",
66			"x2-5x+6=0",
67			"-ba^2-2ba+b^2-b+x^2+2xb=0",
68			"(a4-b4)/(a2-b2)-(a+b)^4/(a+b)^2+1/2a*root(3)(b3+3b2+3b+1)"
69		];
70		
71		exp.value = Examples[Math.floor(Math.random() * 5)];
72	}
73	
74	hideKeyboard();
75	displayPreview();
76}
77
78function generateExample() {
79	var Examples = [
80		"[(m2-9)/(m2+5m+6)]:[(-m+3)/(m+2)]",
81		"{[(1/4)^-4]^-5*16^3:(1/8)^10}^-5",
82		"[(1/2)^4*(1/2)^5:(1/2)^7]*{1/4:[(10/3-7/6-7/4)*9/5]}^2",
83		"a/(a+1)+1/(a-1)+(2a)/(a2-1)",
84		"(1/(x-2y)+1/(x+2y)):x/(x2-4y2)",
85		"((x-y)/(5xy2)-(x-y)/(10x2y)):(1/(10x2y)-1/(5xy2))",
86		"(x+y)/(x-y)+(x-y)/(x+y)+(x2+y2)/(x2-y2)",
87		"(a4-b4)/(a2-b2)-(a+b)^4/(a+b)^2+1/2a*sqrt(16b2+8b+1)",
88		"(2x)/(x2-9)-1/(x+3)-2/(x-3)",
89		"(x4-9x2-4x+12)/(x3+5x2+2x-8)",
90		"[-(3/2a2-1/2b)^2+1/4b2]^2:(-3/2a2)-3/2a2b*(3a2-b)",
91		"(x-2-5/(x+2))*(x2-4)/(x-3)",
92		"(1/9a2b-1/3ab2):(-1/4b)-2b*(a2+b)+(a2+b)^2+1/9*(2a-3b)^2",
93		"(4x*(x2y2-3y3))/(2x*(5y2-y)-2y*(5xy+2x))",
94		"(1+a/x)*(1-a/x)*(2x2)/(a2-x2)+(2x)/(x2-4)*(4+4/x+x)",
95		"(a+b-4ab/(a+b)):(a-b)",
96		"(a-1)/(5a2-6a+1)*((5a2+9a-2)/(a+2))*((a+5)/(5a2+21a-20))",
97		"(1+(2xy)/(x-y)^2)/(x2+y2)",
98		"(x+1+(2x+2)/(x-1))*(x/(x2+x))",
99		"(2ab/(3xy))^2*(3x/(2a))^3*(y/b)^4",
100		"(m/z-z/m)/(m+z)",
101		"(xy^(-1)+yx^(-1))/(x^(-1)+y^(-1))",
102		"(2z-1/(2z+1)+1):(1+1/(2z+1))",
103		"(x2-25)/(x2-5x)-1",
104		"1/(4a)-2/(3a)+1/(12a)",
105		"x/(x-1)+2/(x-2)-1/(x-1)",
106		"(1/(2x2)-1/(2y2)):(1/x+1/y)",
107		"(y-z2/y):(1-z/y)",
108		"((x2+3)/(x+3)-x)*((x+3)/(1-x))",
109		"(1/y+1/(y+1))*(1-y/(2y+1))",
110		"(x-x/(x+1)):(1-(2x)/(x-1))*(1/x2+2/x+1)",
111		"(1/(4a2)-1/(4b2)):(1/(2a)+1/(2b))*4ab",
112		"[(4/3-1/6):(1/4+1/3)]^2:[(7/6+6/8-3/2):(1+1/4)]^2",
113		"{(2/3-1/9)^2:[3/5:(2-1/5)]^4}*(1/5)^3+3",
114		"[(11/14+1/4)+(33/14-3/7)]*{(4/5+1/4-1/20)-[3-(1/4+1/3)*6/7]*2/5}",
115		"[(3/7+2/14)*(5/6-1/3):5/14]*[9/4-3/8+3/4*(5/4-1/2)-2/8]-3/4",
116		"1/3b*(-2a2-3/4a2+1/2a2)+(3/2a2b2+1/4a2b2):(7/2b)-5/4a2b",
117		"[-3/2xy2*1/9x4y3-3/5x3y*(-5/6x2y4)]:(8/6x4y4)-1/3xy",
118		"[(4/5x3y2z)*(5/12yz2)+5/6x3y3z3]:(7/3xy2z3)-3/4x2y",
119		"(-3/5a7b7c3)/(-3ab)-(3/4a2b2c)*(5/3a4b4c2)",
120		"(x+2)^2-3(x+2)*(x-2)+(x-2)^3-x^2(x-8)",
121		"2(y-3x)^2+2(2x+y)*(y-2x)-9x^2-2xy-(2y-x)^2",
122		"(12^2)^5/(12^2)^4-(5^3)^5*5^2/(5^5)^3+[(4^2)^3]^5/2^56-3*(3^2-2^2)",
123		"(-5^5)^5:[(-125)^2*(-25^3)]^2+[(-5)^5]^5:(-125)^8",
124		"sqrt(25x^4+20x^3+34x^2+12x+9)",
125		"(x-b)*(x+b)+a(a-2x)=0",
126		"x+y*(a+b)-a^2+b^2=x",
127		"2(x-1)^2/3+(x+2)^2=5x*(x-2)/3+4x+1",
128		"(x+m)^2+(x-m)*(x+n)-2n2=1/2x(2x-m)+7/2m(m+n)",
129		"(a-b)*(x+b)-(a+b)*(x-a)=(x-a)*(x+b)+a2-ab-5b2",
130		"(x-3)^2+(x+3)^2=(x-3)*(x+3)+30",
131		"x-3(x+2)^2=-3x2",
132		"32+x=10*(5+x)",
133		"(m2-1)x2-2mx+1=0",
134		"(11x)/12+5/12=x-2",
135		"x2-x-11=0",
136		"x2-5x+6=0",
137		"-ba^2-2ba+b^2-b+x^2+2xb=0"
138	];
139	
140	var exp = document.getElementById("InputExp");
141	exp.value = Examples[Math.floor(Math.random() * 58)];
142	hideKeyboard();
143	displayPreview();
144}
145
146function generateEquation() {
147	var Examples = [
148		"(x-b)*(x+b)+a(a-2x)=0",
149		"x+y*(a+b)-a^2+b^2=x",
150		"2(x-1)^2/3+(x+2)^2=5x*(x-2)/3+4x+1",
151		"(x+m)^2+(x-m)*(x+n)-2n2=1/2x(2x-m)+7/2m(m+n)",
152		"(a-b)*(x+b)-(a+b)*(x-a)=(x-a)*(x+b)+a2-ab-5b2",
153		"(x-3)^2+(x+3)^2=(x-3)*(x+3)+30",
154		"x-3(x+2)^2=-3x2",
155		"32+x=10*(5+x)",
156		"(m2-1)x2-2mx+1=0",
157		"(11x)/12+5/12=x-2",
158		"x2-x-11=0",
159		"x2-5x+6=0",
160		"-ba^2-2ba+b^2-b+x^2+2xb=0"
161	];
162
163	var exp = document.getElementById("InputExp");
164	exp.value = Examples[Math.floor(Math.random() * 13)];
165	hideKeyboard();
166	displayPreview();
167}
168
169function generateExpression() {
170	var Examples = [
171		"{[(1/4)^-4]^-5*16^3:(1/8)^10}^-5",
172		"[(1/2)^4*(1/2)^5:(1/2)^7]*{1/4:[(10/3-7/6-7/4)*9/5]}^2",
173		"[(4/3-1/6):(1/4+1/3)]^2:[(7/6+6/8-3/2):(1+1/4)]^2",
174		"{(2/3-1/9)^2:[3/5:(2-1/5)]^4}*(1/5)^3+3",
175		"[(11/14+1/4)+(33/14-3/7)]*{(4/5+1/4-1/20)-[3-(1/4+1/3)*6/7]*2/5}",
176		"[(3/7+2/14)*(5/6-1/3):5/14]*[9/4-3/8+3/4*(5/4-1/2)-2/8]-3/4",
177		"(12^2)^5/(12^2)^4-(5^3)^5*5^2/(5^5)^3+[(4^2)^3]^5/2^56-3*(3^2-2^2)",
178		"(-5^5)^5:[(-125)^2*(-25^3)]^2+[(-5)^5]^5:(-125)^8",
179		"2/3+sqrt(2/5*20/18)",
180		"(7/2-1)-[(1/7+1/35)*(2-15/4)+1/5]:(-1/5)"
181	];
182
183	var exp = document.getElementById("InputExp");
184	exp.value = Examples[Math.floor(Math.random() * 10)];
185	hideKeyboard();
186	displayPreview();
187}
188
189function toggleHelp() {
190	var help = document.getElementById("dropdownhelp");
191	if(help.style.display == "block")
192		{ help.style.display = "none";}
193	else
194		{ help.style.display = "block";}
195}
196
197function toggleKeyboard() {
198	var keyboard = document.getElementById("keyboard_buttons");
199	var exp = document.getElementById("InputExp");
200
201	if(keyboard.style.display == "block") {
202		keyboard.style.display = "none";
203		exp.value = exp.value.replace(/\u25AF/g, '');
204	}
205	else {
206		keyboard.style.display = "block";
207		exp.value = exp.value.replace(/\u25AF/g, '');
208		exp.value = exp.value + "▯";
209	}
210}
211
212function hideKeyboard() {
213	var keyboard = document.getElementById("keyboard_buttons");
214
215	if(keyboard.style.display == "block") {
216		var exp = document.getElementById("InputExp");
217
218		keyboard.style.display = "none";
219		exp.value = exp.value.replace(/\u25AF/g, '');
220	}
221}
222
223function differentiateBrackets() {
224	var exp = document.getElementById("InputExp");
225	var opened_bracket_level = []; var is_bracket_closed = [];
226	var i = new Number(); var j = new Number(); var k = new Number(); var current_open_brackets = new Number(0);
227	
228	for (i = 0; i < exp.value.length; i++) {
229		if (exp.value.charAt(i) == "(" || exp.value.charAt(i) == "[" || exp.value.charAt(i) == "{") {
230			current_open_brackets++;
231			opened_bracket_level.push(1);
232			is_bracket_closed.push(false);
233			k = 1;
234			for (j = opened_bracket_level.length - 2; j >= 0; j--) {
235				if (!is_bracket_closed[j]) {
236					opened_bracket_level[j] = ++k;
237				}
238			}
239		}
240		
241		if (exp.value.charAt(i) == ")" || exp.value.charAt(i) == "]" || exp.value.charAt(i) == "}") {
242			current_open_brackets--;
243			if (current_open_brackets >= 0) {
244				j = opened_bracket_level.length - 1;
245				while (j >= 0 && is_bracket_closed[j]) { j--; }
246				if (j >= 0) {
247					is_bracket_closed[j] = true;
248				}
249			}
250			else {
251				break;
252			}
253		}
254	}
255
256	if (opened_bracket_level.length > 0 && current_open_brackets >= 0) {
257		var opening_br = ["{", "(", "["];
258		var closing_br = ["}", ")", "]"];
259		var brackets_to_be_closed = [];
260		var s = new String("");
261
262		for (i = j = 0; i < exp.value.length; i++) {
263			if (exp.value.charAt(i) == "(" || exp.value.charAt(i) == "[" || exp.value.charAt(i) == "{") {
264				s = s + opening_br[opened_bracket_level[j] % 3];
265				brackets_to_be_closed.push(closing_br[opened_bracket_level[j] % 3]);
266				j++;
267			}
268			else
269				if (exp.value.charAt(i) == ")" || exp.value.charAt(i) == "]" || exp.value.charAt(i) == "}") {
270					s = s + brackets_to_be_closed.pop();
271				}
272				else {
273					s = s + exp.value.charAt(i);
274				}
275		}
276		exp.value = s.valueOf();
277	}
278}
279
280function insertExpString(s) {
281	var exp = document.getElementById("InputExp");
282	exp.value = exp.value.replace(/\u25AF/g, s + '▯');
283	
284	displayPreview();
285}
286
287function insertExpCharOpenBracket() {
288	insertExpString("(");
289	
290	differentiateBrackets();	
291	displayPreview();
292}
293
294function insertExpCharCloseBracket() {
295	insertExpString(")");
296	
297	differentiateBrackets();	
298	displayPreview();
299}
300
301function deleteLastExpChar() {
302	var exp = document.getElementById("InputExp");
303	var splittedExp = exp.value.split("▯");
304
305	exp.value = splittedExp[0].valueOf().substr(0, splittedExp[0].length-1) + "▯" + splittedExp[1];
306	
307	displayPreview();
308}
309
310function moveCursorToLeft() {
311	var exp = document.getElementById("InputExp");
312	var splittedExp = exp.value.split("▯");
313
314	exp.value = splittedExp[0].valueOf().substr(0, splittedExp[0].length-1) + "▯" + splittedExp[0].charAt(splittedExp[0].length - 1) + splittedExp[1];
315	
316	displayPreview();
317}
318
319function moveCursorToRight() {
320	var exp = document.getElementById("InputExp");
321	var splittedExp = exp.value.split("▯");
322
323	exp.value = splittedExp[0] + splittedExp[1].charAt(0) + "▯" + splittedExp[1].valueOf().substr(1, splittedExp[1].length-1);
324	
325	displayPreview();
326}
327
328function resetExp() {
329	var exp = document.getElementById("InputExp");
330	exp.value = "▯";
331	
332	displayPreview();
333}
334
335function insertExpCharOne()				{ insertExpString("1");}
336function insertExpCharTwo()				{ insertExpString("2");}
337function insertExpCharThree()			{ insertExpString("3");}
338function insertExpCharFour()			{ insertExpString("4");}
339function insertExpCharFive()			{ insertExpString("5");}
340function insertExpCharSix()				{ insertExpString("6");}
341function insertExpCharSeven()			{ insertExpString("7");}
342function insertExpCharEight()			{ insertExpString("8");}
343function insertExpCharNine()			{ insertExpString("9");}
344function insertExpCharZero()			{ insertExpString("0");}
345function insertExpCharOpenRound()		{ insertExpString("(");}
346function insertExpCharCloseRound()		{ insertExpString(")");}
347function insertExpCharOpenSquare()		{ insertExpString("[");}
348function insertExpCharCloseSquare()		{ insertExpString("]");}
349function insertExpCharOpenBrace()		{ insertExpString("{");}
350function insertExpCharCloseBrace()		{ insertExpString("}");}
351function insertExpCharPlus()			{ insertExpString("+");}
352function insertExpCharMinus()			{ insertExpString("-");}
353function insertExpCharMultiplication()	{ insertExpString("*");}
354function insertExpCharFraction()		{ insertExpString("/");}
355function insertExpCharDivision()		{ insertExpString(":");}
356function insertExpCharRaising()			{ insertExpString("^");}
357function insertSQRT() 					{ insertExpString("sqrt(4)");}
358function insertROOT() 					{ insertExpString("root(3)(8)");}
359function insertExpCharSemicolon()		{ insertExpString(";");}
360function insertExpCharDot()				{ insertExpString(".");}
361function insertExpCharComma()			{ insertExpString(",");}
362function insertExpCharA()				{ insertExpString("a");}
363function insertExpCharB()				{ insertExpString("b");}
364function insertExpCharC()				{ insertExpString("c");}
365function insertExpCharD()				{ insertExpString("d");}
366function insertExpCharE()				{ insertExpString("e");}
367function insertExpCharH()				{ insertExpString("h");}
368function insertExpCharK()				{ insertExpString("k");}
369function insertExpCharM()				{ insertExpString("m");}
370function insertExpCharN()				{ insertExpString("n");}
371function insertExpCharX()				{ insertExpString("x");}
372function insertExpCharZ()				{ insertExpString("z");}
373function insertExpCharY()				{ insertExpString("y");}
374function insertExpCharGCD()				{ insertExpString("$");}
375function insertExpCharLCM()				{ insertExpString("&");}
376function insertExpCharEqual()			{ insertExpString("=");}
377function insertExpCharDecimal()			{ insertExpString(".");}
378
379function submitCalculation(language) {
380	// Hide the keyboard buttons
381	hideKeyboard();
382	
383	// Not used; for future developments
384	// Show the copyToClipboard button
385	// var copyToClipboard = document.getElementById("copyToClipboard");
386	// copyToClipboard.style.display = "block";
387
388	// Hide the help texts
389	var help = document.getElementById("dropdownhelp");
390	help.style.display = "none";
391
392	// Set-up calculation
393	var exp = document.getElementById("InputExp");
394	var mth = document.getElementById("MthInput");
395	mth.value = exp.value.toLowerCase(); // In order to avoid ambiguity, upper case variables are converted to lower case
396
397	// Manage bad chars
398	mth.value = mth.value.replace(/(\x02|\x03|\x04|\x05|\x08|\x09|\x20|\x22|\x27|\x3F|\x5C|\uFE0F)/g, ''); // bad chars to be removed
399	mth.value = mth.value.replace(/(\xD7|\xB7|\u2022|\u22C5|\u2716)/g, '*'); // bad char of multiplication
400	mth.value = mth.value.replace(/\xF7/g, ':'); // bad char of division
401	mth.value = mth.value.replace(/(\u2212|\u2013|\u23AF|\x5F|\xAD)/g, '-'); // bad char of subtraction
402	mth.value = mth.value.replace(/\u02C6/g, '^');  // bad char of raising to a power 
403	mth.value = mth.value.replace(/=>/g, '>=');  // bad inequalities
404	mth.value = mth.value.replace(/=</g, '<=');  // bad inequalities
405	
406	// Only managed when submitting calculation - begin
407	mth.value = mth.value.replace(/(\xBA|\xB0)/g, '^0');	// 0 superscript
408	mth.value = mth.value.replace(/\xB9/g, '^1');			// 1 superscript
409	mth.value = mth.value.replace(/\xB2/g, '^2');			// 2 superscript
410	mth.value = mth.value.replace(/\xB3/g, '^3');			// 3 superscript
411	mth.value = mth.value.replace(/\u2074/g, '^4');			// 4 superscript
412	mth.value = mth.value.replace(/\u207F/g, '^n');			// n superscript
413	mth.value = mth.value.replace(/\xAA/g, '^a');			// a superscript
414	mth.value = mth.value.replace(/\xBC/g, '(1/4)');  // bad fractions
415	mth.value = mth.value.replace(/\xBD/g, '(1/2)');  // bad fractions
416	mth.value = mth.value.replace(/\xBE/g, '(3/4)');  // bad fractions
417	mth.value = mth.value.replace(/\u2154/g, '(2/3)');  // bad fractions
418	// end
419
420	// Manage not useful signs
421	mth.value = mth.value.replace(/\x5e+/g, '^'); // ^^
422	mth.value = mth.value.replace(/\x2a+/g, '*'); // **
423	mth.value = mth.value.replace(/\x2f+/g, '/'); // //
424	mth.value = mth.value.replace(/\x2b+/g, '+'); // ++
425	mth.value = mth.value.replace(/\x5e\x2b/g, '^'); // ^+
426	mth.value = mth.value.replace(/\x2a\x2b/g, '*'); // *+
427	mth.value = mth.value.replace(/\x2f\x2b/g, '/'); // /+
428	mth.value = mth.value.replace(/\x3a\x2b/g, ':'); // :+
429	mth.value = mth.value.replace(/\x24\x2b/g, '$'); // $+
430	mth.value = mth.value.replace(/\x26\x2b/g, '&'); // &+
431	
432	// Deletion of = at the end of expression
433	mth.value = mth.value.replace(/=$/, '');
434
435	// Manage decimals
436	var patt = /[0-9]+(\x2e|\x2c)[0-9]*\x28[0-9]+\x29/;
437	var s = new String(patt.exec(mth.value));
438	while (s.valueOf()!="null") {
439	  s = s.valueOf().substr(0, s.length-2);
440	  var i1 = s.valueOf().search(/(\x2e|\x2c)/);
441	  var i2 = s.valueOf().search(/\x28/);
442	  var i3 = s.valueOf().search(/\x29/);
443	  var int_part = s.valueOf().substring(0,i1);
444	  var ante_period = s.valueOf().substring(i1+1,i2);
445	  var period = s.valueOf().substring(i2+1,i3);
446	  var a = "((" + int_part + ante_period + period + "-" + int_part + ante_period + ")/";
447	  i3 = period.length;
448	  while (i3-->0) a = a + "9";
449	  i2 = ante_period.length;
450	  while (i2-->0) a = a + "0";
451	  a = a + ")";
452	  mth.value = mth.value.replace(s.valueOf(), a);
453      var s = new String(patt.exec(mth.value));
454	}
455
456	patt = /[0-9]+(\x2e|\x2c)[0-9]+/;
457	s = new String(patt.exec(mth.value));
458	while (s.valueOf()!="null") {
459	  s = s.valueOf().substr(0, s.length-2);
460	  i1 = s.valueOf().search(/(\x2e|\x2c)/);
461	  int_part = s.valueOf().substring(0,i1);
462	  ante_period = s.valueOf().substring(i1+1);
463	  a = "((" + int_part + ante_period + ")/";
464      a = a + "1";
465	  i2 = ante_period.length;
466	  while (i2-->0) a = a + "0";
467	  a = a + ")";
468	  mth.value = mth.value.replace(s.valueOf(), a);
469      s = new String(patt.exec(mth.value));
470	}
471	
472	// Interpret . as a multiplication, if not used for decimals
473	mth.value = mth.value.replace(/\x2e/g, '*');
474
475	// Insert closing brackets at the bottom of expression, if missed
476	var brackets_balance = 0;
477	var strmatch = mth.value.match(/[\x28\x5b\x7b]/g);
478	if (strmatch != null) {
479		brackets_balance = strmatch.length;
480		strmatch = mth.value.match(/[\x29\x5d\x7d]/g);
481		if (strmatch != null) brackets_balance -= strmatch.length;
482	}
483	while (brackets_balance-- > 0) mth.value = mth.value + ")";
484	
485	// Generate errors for the CGI (if any)
486	var InputError = document.getElementById("InputError");
487	InputError.value = "0"; // NO_ERRORS
488	
489	if (!mth.value)
490		InputError.value = "-17"; // EMPTY_EXPRESSION
491	else {
492		var n = mth.value.search(/(#|arccos|arcsin|arctan|cos|cosh|cot|coth|csc|csch|det|dim|exp|gcd|glb|lcm|ln|log|lub|max|min|mod|sec|sech|sin|sinh|tan|tanh|abs|floor|ceil|int|\u221A|\x7C|\x21|\x40)/i);
493		if (n>=0) InputError.value = "-13"; // FUNCTION_NOT_SUPPORTED
494	}
495	
496	// Set the input type
497	var InputType = document.getElementById("InputType");
498	InputType.value = "1"; // Expression
499
500	if (InputError.value == "0") {
501		// Manage SQRT and ROOT
502		mth.value = mth.value.replace(/sqrt/gi, '@');
503		mth.value = mth.value.replace(/root/gi, '|');
504
505		// Manage ROOT operator - Begin
506		var i = -1;
507		var brackets_level = 0;
508		while (++i < mth.value.length)
509			if (mth.value.charAt(i) == "|" && i+1 < mth.value.length && (mth.value.charAt(i+1) == "(" || mth.value.charAt(i+1) == "[" || mth.value.charAt(i+1) == "{")) {
510				brackets_level = 1;
511				i++;
512			}
513			else
514				if (brackets_level > 0 && (mth.value.charAt(i) == "(" || mth.value.charAt(i) == "[" || mth.value.charAt(i) == "{"))
515					++brackets_level;
516				else
517					if (brackets_level > 0 && (mth.value.charAt(i) == ")" || mth.value.charAt(i) == "]" || mth.value.charAt(i) == "}"))
518						if (brackets_level-1 == 0 && i+1 < mth.value.length && (mth.value.charAt(i+1) == "(" || mth.value.charAt(i+1) == "[" || mth.value.charAt(i+1) == "{"))  {
519							mth.value = mth.value.substring(0, i) + ";" + mth.value.substring(i+2);
520							brackets_level = 0;
521						}
522						else
523							--brackets_level;
524		// Manage ROOT operator - End
525
526		// Manage equations and inequalities
527		n = -1;
528		if (n==-1) n = mth.value.search(/>=/);
529		if (n>=0) {
530			mth.value = mth.value.replace(/>=/, "-{");
531			mth.value = mth.value + "}";
532			InputType.value = "2"; // Inequality 2 ">="
533			n = -2;
534		}
535		if (n==-1) n = mth.value.search(/<=/);
536		if (n>=0) {
537			mth.value = mth.value.replace(/<=/, "-{");
538			mth.value = mth.value + "}";
539			InputType.value = "3"; // Inequality 3 "<="
540			n = -2;
541		}
542		if (n==-1) n = mth.value.search(/=/);
543		if (n>=0) {
544			mth.value = mth.value.replace(/=/, "-{");
545			mth.value = mth.value + "}";
546			InputType.value = "4"; // Equation
547			n = -2;
548		}
549		if (n==-1) n = mth.value.search(/>/);
550		if (n>=0) {
551			mth.value = mth.value.replace(/>/, "-{");
552			mth.value = mth.value + "}";
553			InputType.value = "5"; // Inequality 5 ">"
554			n = -2;
555		}
556		if (n==-1) n = mth.value.search(/</);
557		if (n>=0) {
558			mth.value = mth.value.replace(/</, "-{");
559			mth.value = mth.value + "}";
560			InputType.value = "6"; // Inequality 6 "<"
561			n = -2;
562		}
563		mth.value = mth.value.replace(/-\x7b0\x7d/, ""); // Remove "-{0}"
564		
565		// Manage monomials
566		patt = /[0-9][a-z]/i;
567		s = new String(patt.exec(mth.value));
568		a = "";
569		while (s.valueOf()!="null") {
570			a = s.charAt(0)+"#"+s.charAt(1);
571			mth.value = mth.value.replace(s.valueOf(), a);
572			s = new String(patt.exec(mth.value));
573		}
574
575		patt = /[a-z][a-z]/i;
576		s = new String(patt.exec(mth.value));
577		while (s.valueOf()!="null") {
578			a = s.charAt(0)+"#"+s.charAt(1);
579			mth.value = mth.value.replace(s.valueOf(), a);
580			s = new String(patt.exec(mth.value));
581		}
582
583		patt = /[a-z][0-9]/i;
584		s = new String(patt.exec(mth.value));
585		while (s.valueOf()!="null") {
586			a = s.charAt(0)+"^"+s.charAt(1);
587			mth.val
587ue = mth.value.replace(s.valueOf(), a);
588			s = new String(patt.exec(mth.value));
589		}
590
591		// Manage implicit multiplications
592		patt = /[0-9][\x28\x5b\x7b]/i;
593		s = new String(patt.exec(mth.value));
594		while (s.valueOf()!="null") {
595			a = s.charAt(0)+"*"+s.charAt(1);
596			mth.value = mth.value.replace(s.valueOf(), a);
597			s = new String(patt.exec(mth.value));
598		}
599
600		patt = /[a-z][\x28\x5b\x7b]/i;
601		s = new String(patt.exec(mth.value));
602		while (s.valueOf()!="null") {
603			a = s.charAt(0)+"*"+s.charAt(1);
604			mth.value = mth.value.replace(s.valueOf(), a);
605			s = new String(patt.exec(mth.value));
606		}
607
608		patt = /[\x29\x5d\x7d][\x28\x5b\x7b]/i;
609		s = new String(patt.exec(mth.value));
610		while (s.valueOf()!="null") {
611			a = s.charAt(0)+"*"+s.charAt(1);
612			mth.value = mth.value.replace(s.valueOf(), a);
613			s = new String(patt.exec(mth.value));
614		}
615
616		patt = /[\x29\x5d\x7d][a-z]/i;
617		s = new String(patt.exec(mth.value));
618		while (s.valueOf()!="null") {
619			a = s.charAt(0)+"*"+s.charAt(1);
620			mth.value = mth.value.replace(s.valueOf(), a);
621			s = new String(patt.exec(mth.value));
622		}
623
624		patt = /[\x29\x5d\x7d][0-9]/i;
625		s = new String(patt.exec(mth.value));
626		while (s.valueOf()!="null") {
627			a = s.charAt(0)+"*"+s.charAt(1);
628			mth.value = mth.value.replace(s.valueOf(), a);
629			s = new String(patt.exec(mth.value));
630		}
631
632		// Manage implicit multiplications in relation to roots
633		patt = /[0-9][\x40\x7c]/i;
634		s = new String(patt.exec(mth.value));
635		while (s.valueOf()!="null") {
636			a = s.charAt(0)+"*"+s.charAt(1);
637			mth.value = mth.value.replace(s.valueOf(), a);
638			s = new String(patt.exec(mth.value));
639		}
640		
641		patt = /[a-z][\x40\x7c]/i;
642		s = new String(patt.exec(mth.value));
643		while (s.valueOf()!="null") {
644			a = s.charAt(0)+"*"+s.charAt(1);
645			mth.value = mth.value.replace(s.valueOf(), a);
646			s = new String(patt.exec(mth.value));
647		}
648
649		patt = /[\x29\x5d\x7d][\x40\x7c]/i;
650		s = new String(patt.exec(mth.value));
651		while (s.valueOf()!="null") {
652			a = s.charAt(0)+"*"+s.charAt(1);
653			mth.value = mth.value.replace(s.valueOf(), a);
654			s = new String(patt.exec(mth.value));
655		}
656	}
657	else InputType.value = "0"; // Error input type
658}
659
660function loadFrame(language) {
661	var iframe = document.getElementById("myframe");
662	var doc = iframe.contentWindow.document;
663	var res = document.getElementById("resultPrint");
664
665	res.innerHTML = doc.body.innerHTML;
666	
667	// Change default html tag of result
668	res.innerHTML = res.innerHTML.replace(/<pre/g, "<p");
669	res.innerHTML = res.innerHTML.replace(/pre>/g, "p>");
670
671	// Format result in html for MathJax (ASCII MATH)
672	res.innerHTML = res.innerHTML.replace(/`\n`/g, "`</p><p>`");
673	res.innerHTML = res.innerHTML.replace(/=`\n/g, "`</p><p>");
674	res.innerHTML = res.innerHTML.replace(/`\n/g, "`</p><p>");
675	res.innerHTML = res.innerHTML.replace(/\n<\x2fp/g, "</p");
676	
677	// Manage monomials
678	var patt = /[0-9]\x2a[a-z]/i;
679	var s = new String(patt.exec(res.innerHTML));
680	var a = "";
681	while (s.valueOf()!="null") {
682		a = s.charAt(0)+s.charAt(2);
683		res.innerHTML = res.innerHTML.replace(s.valueOf(), a);
684		s = new String(patt.exec(res.innerHTML));
685	}		
686	
687	/* Removed as MathJax does not display correctly xx, bb, cc ...
688	patt = /[a-z]\x2a[a-z]/i;
689	s = new String(patt.exec(res.innerHTML));
690	while (s.valueOf()!="null") {
691		a = s.charAt(0)+s.charAt(2);
692		res.innerHTML = res.innerHTML.replace(s.valueOf(), a);
693		s = new String(patt.exec(res.innerHTML));
694	}
695	*/
696
697	patt = /[a-z][0-9]/i;
698	s = new String(patt.exec(res.innerHTML));
699	while (s.valueOf()!="null") {
700		a = s.charAt(0)+"^"+s.charAt(1);
701		res.innerHTML = res.innerHTML.replace(s.valueOf(), a);
702		s = new String(patt.exec(res.innerHTML));
703	}
704
705	// Manage ROOT operator
706	res.innerHTML = res.innerHTML.replace(/;/g, ")(");
707	res.innerHTML = res.innerHTML.replace(/&gt;\x29\x28/g, ">");
708	res.innerHTML = res.innerHTML.replace(/&ge;\x29\x28/g, ">=");
709	res.innerHTML = res.innerHTML.replace(/&lt;\x29\x28/g, "<");
710	res.innerHTML = res.innerHTML.replace(/&le;\x29\x28/g, "<=");
711	res.innerHTML = res.innerHTML.replace(/&amp;\x29\x28/g, "&");
712
713	// Manage some MathJax's displays
714	res.innerHTML = res.innerHTML.replace(/xx/g, 'x*x'); // xx is not displayed as wanted
715	res.innerHTML = res.innerHTML.replace(/bb/g, 'b*b'); // bb is not displayed as wanted
716	res.innerHTML = res.innerHTML.replace(/cc/g, 'c*c'); // cc is not displayed as wanted
717}
718
719// To be used only if InputType.value = 1 (i.e an expression)
720
721function copyToClipboardExpResult() {
722	var iframe = document.getElementById("myframe");
723	var doc = iframe.contentWindow.document;
724	var copyable_res = doc.body.innerHTML;
725
726	copyable_res = copyable_res.replace(/`\n</g, "`<");
727	copyable_res = copyable_res.replace(/`.*`\n/g, "");
728	copyable_res = copyable_res.replace(/<pre.*>`=/g, "");
729	copyable_res = copyable_res.replace(/=`.*pre>/g, "");
730	alert (copyable_res);
731}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.