Subversion Repositories wimsdev

Rev

Rev 12148 | Rev 12150 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 12148 Rev 12149
Line 84... Line 84...
84
                </td>
84
                </td>
85
                <td class="exercise_m">
85
                <td class="exercise_m">
86
                    &nbsp;$m_rightarrow&nbsp;
86
                    &nbsp;$m_rightarrow&nbsp;
87
                </td>
87
                </td>
88
                !endif
88
                !endif
89
                <td id="math_out" style="font-size:1.1em;text-align:left"></td>
89
                <td id="math_out"></td>
90
                </tr>
90
                </tr>
91
            </table>
91
            </table>
92
            <textarea id="JSMathView" style="color:black;background-color:#e8ffff;border:1px solid #ff0000;width:400px;webkit-box-sizing:border-box;moz-box-sizing:border-box;box-sizing:border-box;"></textarea>
92
            <textarea id="JSMathView" style="color:black;background-color:#e8ffff;border:1px solid #ff0000;width:400px;webkit-box-sizing:border-box;moz-box-sizing:border-box;box-sizing:border-box;"></textarea>
93
        </td>
93
        </td>
94
        </tr>
94
        </tr>
Line 255... Line 255...
255
 function displayroot(t){var power;var sqrt;var begin;var end;var mod;var tot;var wait;var got;var chr;var t1;var t2;var t3;var t4;var test;var org;t2=t.indexOf("](");if(t2==-1){return;};org=t;t=t.replace(/sqrt\(/g,"SQRT(");t=t.replace(/log\[/g,"LOG~");t=t.replace(/sqrt\[/g,"@[");test=t.replace(/[a-z]\[/g,"#");if(test.indexOf("#")!=-1){return;};t2=t.indexOf("[");var trouble=0;while(t2 != -1){begin=t.indexOf("@");t2=t.indexOf("[");t3=t.indexOf("]");if(t2==begin+1 && t3>t2){power=t.substring(t2+1,t3);if(power.length==0){return t;};if(power<2){return;}t4="["+power+"]";t=t.replace(t4,'');tot=t.length;wait=0;got=0;end=0;for(var s=begin;s<tot;s++){if(end==0){chr=t.charAt(s);if(chr=="("){wait=wait+1;};if(chr==")"){got=got+1;};if(got!=0){if(wait==got){end=s;}}}};begin=begin+2;sqrt=t.substring(begin,end);mod=(power % 2);if(sqrt<0 && mod!=1){return;};t=t.replace("@("+sqrt+")","{^"+power+"&radic;#"+sqrt+"!}");}else{t=t.replace("]","?");}trouble++;if(trouble>100){setAlarm(r20);t="error";return t;}};t=t.replace(/SQRT\(/g,"&radic;#");t=t.replace(/LOG~/g,"log[");t=t.replace(/~/g,"[");t=t.replace(/\?/g,"]");t=t.replace(/@/g,"&radic;");return t;}
255
 function displayroot(t){var power;var sqrt;var begin;var end;var mod;var tot;var wait;var got;var chr;var t1;var t2;var t3;var t4;var test;var org;t2=t.indexOf("](");if(t2==-1){return;};org=t;t=t.replace(/sqrt\(/g,"SQRT(");t=t.replace(/log\[/g,"LOG~");t=t.replace(/sqrt\[/g,"@[");test=t.replace(/[a-z]\[/g,"#");if(test.indexOf("#")!=-1){return;};t2=t.indexOf("[");var trouble=0;while(t2 != -1){begin=t.indexOf("@");t2=t.indexOf("[");t3=t.indexOf("]");if(t2==begin+1 && t3>t2){power=t.substring(t2+1,t3);if(power.length==0){return t;};if(power<2){return;}t4="["+power+"]";t=t.replace(t4,'');tot=t.length;wait=0;got=0;end=0;for(var s=begin;s<tot;s++){if(end==0){chr=t.charAt(s);if(chr=="("){wait=wait+1;};if(chr==")"){got=got+1;};if(got!=0){if(wait==got){end=s;}}}};begin=begin+2;sqrt=t.substring(begin,end);mod=(power % 2);if(sqrt<0 && mod!=1){return;};t=t.replace("@("+sqrt+")","{^"+power+"&radic;#"+sqrt+"!}");}else{t=t.replace("]","?");}trouble++;if(trouble>100){setAlarm(r20);t="error";return t;}};t=t.replace(/SQRT\(/g,"&radic;#");t=t.replace(/LOG~/g,"log[");t=t.replace(/~/g,"[");t=t.replace(/\?/g,"]");t=t.replace(/@/g,"&radic;");return t;}
256
 function displayfun(t,fun,alias){var cnt=0;var chk = [];var ti = t.indexOf(fun);while( ti !=-1 ){ var to = t.indexOf(fun+'[');t = t.replace(fun,"@");;if( to < ti+3  ){ chk.push(cnt);}else{chk.push(-1);};ti = t.indexOf(fun);cnt++;};var idx=null;var tot=t.length;var wait=0;var got=0;var end=0;var arg;var begin;var s1;var s2;var chr;var found;var i;var ii;var idx;for(var p=0 ; p < cnt; p++ ){tot = t.length;idx=null;begin = t.indexOf('@');i=t.indexOf('[');if( chk[p] != -1 ){ii=t.indexOf(']');idx=t.substring(i+1,ii);s1 = t.substring(0,i);s2 = t.substring(ii+1,tot);t=s1+s2;};found=false;wait=0;got=0;for(var s = begin; s < tot && found==false; s++){chr = t.charAt(s);if(chr == "("){wait = wait + 1;};if(chr == ")"){got = got + 1;};if(got != 0){ if( wait == got ){ end = s;found = true;};};};begin=begin+2;arg=t.substring(begin,end);if(idx != null ){if(lang == "fr" ){t = t.replace("@("+arg+")","{"+alias+"_{"+idx+"}#"+arg+"!}");}else{t = t.replace("@("+arg+")","{^{"+idx+"}"+alias+"#"+arg+"!}");};}else{t = t.replace("@("+arg+")","{"+alias+"#"+arg+"!}");};};return t;};
256
 function displayfun(t,fun,alias){var cnt=0;var chk = [];var ti = t.indexOf(fun);while( ti !=-1 ){ var to = t.indexOf(fun+'[');t = t.replace(fun,"@");;if( to < ti+3  ){ chk.push(cnt);}else{chk.push(-1);};ti = t.indexOf(fun);cnt++;};var idx=null;var tot=t.length;var wait=0;var got=0;var end=0;var arg;var begin;var s1;var s2;var chr;var found;var i;var ii;var idx;for(var p=0 ; p < cnt; p++ ){tot = t.length;idx=null;begin = t.indexOf('@');i=t.indexOf('[');if( chk[p] != -1 ){ii=t.indexOf(']');idx=t.substring(i+1,ii);s1 = t.substring(0,i);s2 = t.substring(ii+1,tot);t=s1+s2;};found=false;wait=0;got=0;for(var s = begin; s < tot && found==false; s++){chr = t.charAt(s);if(chr == "("){wait = wait + 1;};if(chr == ")"){got = got + 1;};if(got != 0){ if( wait == got ){ end = s;found = true;};};};begin=begin+2;arg=t.substring(begin,end);if(idx != null ){if(lang == "fr" ){t = t.replace("@("+arg+")","{"+alias+"_{"+idx+"}#"+arg+"!}");}else{t = t.replace("@("+arg+")","{^{"+idx+"}"+alias+"#"+arg+"!}");};}else{t = t.replace("@("+arg+")","{"+alias+"#"+arg+"!}");};};return t;};
257
 function button(myValue){if(document.selection){JSMathView.focus();var sel = document.selection.createRange();sel.text = myValue;}else{ if(JSMathView.selectionStart || JSMathView.selectionStart == '0'){var startPos =JSMathView.selectionStart;var endPos = JSMathView.selectionEnd;JSMathView.value = JSMathView.value.substring(0,startPos) + myValue + JSMathView.value.substring(endPos,JSMathView.value.length);} else {JSMathView.value += myValue;};};if(myValue.indexOf('()') != -1){JSMathView.setSelectionRange(startPos+myValue.length - 1,startPos+myValue.length - 1);};doMathSrc(1);};
257
 function button(myValue){if(document.selection){JSMathView.focus();var sel = document.selection.createRange();sel.text = myValue;}else{ if(JSMathView.selectionStart || JSMathView.selectionStart == '0'){var startPos =JSMathView.selectionStart;var endPos = JSMathView.selectionEnd;JSMathView.value = JSMathView.value.substring(0,startPos) + myValue + JSMathView.value.substring(endPos,JSMathView.value.length);} else {JSMathView.value += myValue;};};if(myValue.indexOf('()') != -1){JSMathView.setSelectionRange(startPos+myValue.length - 1,startPos+myValue.length - 1);};doMathSrc(1);};
258
 function change_fontsize(t){math_font_size = math_font_size+t;math_out.setAttribute('style','font-size:'+math_font_size+'em');for(var i=0 ; i < num_button_tabs; i++){;if(document.getElementById('mypanel'+i)){ document.getElementById('mypanel'+i).setAttribute('style','font-size:'+math_font_size+'em');};};JSMathView.setAttribute('style','font-size:'+math_font_size+'em');for(var i=0 ;i < my_wims_mathml.length; i++){ my_wims_mathml[i].setAttribute('mathsize',math_font_size+'em');};adapt_width();};
258
 function change_fontsize(t){math_font_size = math_font_size+t;math_out.setAttribute('style','font-size:'+math_font_size+'em');for(var i=0 ; i < num_button_tabs; i++){;if(document.getElementById('mypanel'+i)){ document.getElementById('mypanel'+i).setAttribute('style','font-size:'+math_font_size+'em');};};JSMathView.setAttribute('style','font-size:'+math_font_size+'em');for(var i=0 ;i < my_wims_mathml.length; i++){ my_wims_mathml[i].setAttribute('mathsize',math_font_size+'em');};adapt_width();};
259
 function rewrite(input){if(input.indexOf("sqrt[") != -1){ input = displayroot(input);};var rep1 = ["sqrt(","pi",">=","<="," and "," or "," isin "," in "," notin "," R "," N ","dy","dx","\ ","dv","dt"];var rep2 = ["&radic;(","\\pi","\\ge "," \\le "," \\wedge "," \\vee "," \\in "," \\in "," \\notin ","\\R","\\N","\\dy","\\dx","\\;","\\dv","\\dt"];for(var i=0; i < rep1.length ; i++){input = input.split(rep1[i]).join(rep2[i]);};var math = ["asin","acos","atan","sqrt","sin","tan","log","cos"];var rep_math = ["\\asin","\\acos","\\atan","\\sqrt","\\sin","\\tan","\\log","\\cos"];var subst=["|A|","|B|","|C|","|D|","|E|","|F|","|G|","|H|","|K|","|L|","|M|","|N|","|O|","|P|","|Q|","|R|"];var repindex=[16];var mathindex=[16];var idx;var found=false;for(var i=0;i < math.length ; i++){idx = input.indexOf(math[i]);while( idx != -1 ){found=true;repindex.push(subst[i]);mathindex.push(rep_math[i]);input = input.replace(math[i],subst[i]);idx = input.indexOf(math[i]);};};if( found ){for(var i=0;i < repindex.length ; i++){input = displayfun(input,repindex[i],mathindex[i]);};};input=input.replace(/#/g,'(');input=input.replace(/!/g,')');return input;}var ents_ = { nwarr: '\u2196', swarr: '\u2199' };show_it.addEventListener('click',function(e){doMathSrc(1);},false);clear_it.addEventListener('click',function(e){JSMathView.value="";doMathSrc(3);},false);JSMathView.addEventListener('keyup',function(e){doMathSrc(1);},false);var ents_ = { nwarr: '\u2196', swarr: '\u2199' };
259
 function rewrite(input){if(input.indexOf("sqrt[") != -1){ input = displayroot(input);};var rep1 = ["sqrt(","pi",">=","<="," and "," or "," isin "," in "," notin "," R "," N ","dy","dx","\ ","dv","dt"];var rep2 = ["&radic;(","\\pi","\\ge "," \\le "," \\wedge "," \\vee "," \\in "," \\in "," \\notin ","\\R","\\N","\\dy","\\dx","\\;","\\dv","\\dt"];for(var i=0; i < rep1.length ; i++){input = input.split(rep1[i]).join(rep2[i]);};var math = ["asin","acos","atan","sqrt","sin","tan","log","cos"];var rep_math = ["\\asin","\\acos","\\atan","\\sqrt","\\sin","\\tan","\\log","\\cos"];var subst=["|A|","|B|","|C|","|D|","|E|","|F|","|G|","|H|","|K|","|L|","|M|","|N|","|O|","|P|","|Q|","|R|"];var repindex=[16];var mathindex=[16];var idx;var found=false;for(var i=0;i < math.length ; i++){idx = input.indexOf(math[i]);while( idx != -1 ){found=true;repindex.push(subst[i]);mathindex.push(rep_math[i]);input = input.replace(math[i],subst[i]);idx = input.indexOf(math[i]);};};if( found ){for(var i=0;i < repindex.length ; i++){input = displayfun(input,repindex[i],mathindex[i]);};};input=input.replace(/#/g,'(');input=input.replace(/!/g,')');return input;}var ents_ = { nwarr: '\u2196', swarr: '\u2199' };show_it.addEventListener('click',function(e){doMathSrc(1);},false);clear_it.addEventListener('click',function(e){JSMathView.value="";doMathSrc(3);},false);JSMathView.addEventListener('keyup',function(e){doMathSrc(1);},false);var ents_ = { nwarr: '\u2196', swarr: '\u2199' };
260
 function doMathSrc(n){if( n == 3){ while(math_out.firstChild){ math_out.removeChild(math_out.firstChild);};return;};var org = JSMathView.value;var editline= org.substr(0,JSMathView.selectionStart).split('\n').length-1 ;var lineno = math_out.childNodes.length;var orig = org.split('\n');var ms = rewrite(orig[editline]);if(ms.length < 1 ){ try{math_out.removeChild(math_out.childNodes[editline]);}catch(e){};return;};if(ms.indexOf('@')!= -1){return;};if(!ms){return;};ms = ms.replace(/&([-#.\w]+);|\\([a-z]+)(?: |(?=[^a-z]))/ig,function(s, e, m){if (m && (M.macros_[m] || M.macro1s_[m])){ return s;};var t = '&'+(e || m)+';', res = $$('<span>'+t+'</span>').text();return res != t ? res : ents_[e || m] || s;});try { var t = M.sToMathE(ms, true);if( editline >= lineno ){math_out.removeChild[editline];math_out.appendChild(t); }else{var newChild = document.createElement('math');newChild.appendChild(t);var oldChild = math_out.childNodes[editline];math_out.replaceChild(newChild, oldChild);};} catch(e){setAlarm(e)};JSMathView.value = org;JSMathView.focus();};
260
 function doMathSrc(n){if( n == 3){ while(math_out.firstChild){ math_out.removeChild(math_out.firstChild);};return;};var org = JSMathView.value;var editline= org.substr(0,JSMathView.selectionStart).split('\n').length-1 ;var lineno = math_out.childNodes.length;var orig = org.split('\n');var ms = rewrite(orig[editline]);if(ms.length < 1 ){ try{math_out.removeChild(math_out.childNodes[editline]);}catch(e){};return;};if(ms.indexOf('@')!= -1){return;};if(!ms){return;};ms = ms.replace(/&([-#.\w]+);|\\([a-z]+)(?: |(?=[^a-z]))/ig,function(s, e, m){if (m && (M.macros_[m] || M.macro1s_[m])){ return s;};var t = '&'+(e || m)+';', res = $$('<span>'+t+'</span>').text();return res != t ? res : ents_[e || m] || s;});try { var t = M.sToMathE(ms, true);if( editline >= lineno ){math_out.removeChild[editline];math_out.appendChild(t); }else{var newChild = document.createElement('span');var br =  document.createElement('br');newChild.appendChild(t); newChild.appendChild(br);var oldChild = math_out.childNodes[editline];math_out.replaceChild(newChild, oldChild);};} catch(e){setAlarm(e)};JSMathView.value = org;JSMathView.focus();};
261
 function adapt_width(){try{var inp_width=document.getElementById('control_1').offsetWidth;JSMathView.style.width = inp_width+'px';} catch(e){};};
261
 function adapt_width(){try{var inp_width=document.getElementById('control_1').offsetWidth;JSMathView.style.width = inp_width+'px';} catch(e){};};
262
 function conv_wims2uni(u){for(var p in uni2wims){if( uni2wims[p] == u ){return p;};};return u;};
262
 function conv_wims2uni(u){for(var p in uni2wims){if( uni2wims[p] == u ){return p;};};return u;};
263
 function conv_uni2wims(input){for(var p in uni2wims){input = input.split(p).join(' '+uni2wims[p]);};return input;};
263
 function conv_uni2wims(input){for(var p in uni2wims){input = input.split(p).join(' '+uni2wims[p]);};return input;};
264
 adapt_width();
264
 adapt_width();
265
//]]>
265
//]]>
Line 268... Line 268...
268
   
268
   
269
!! # 3/6/2016 : added " pm " as option:  y = ± 5*t
269
!! # 3/6/2016 : added " pm " as option:  y = ± 5*t
270
!! # 7/7/2017 : added more unitcode <-> wims [for logic module]
270
!! # 7/7/2017 : added more unitcode <-> wims [for logic module]
271
!! # 24/7/2017: rewrite "latexing" of function...  log(...) -> { \log(...) } log[3](...) -> {^{3}\log(...)} or in case lang=fr {\log_{3}(...)}
271
!! # 24/7/2017: rewrite "latexing" of function...  log(...) -> { \log(...) } log[3](...) -> {^{3}\log(...)} or in case lang=fr {\log_{3}(...)}
272
!! # 15/12/2017: "multiline" Mathml output (using enter in textarea)
272
!! # 15/12/2017: "multiline" Mathml output (using enter in textarea)
273
!! # 16/12/2017: removed stretchy left brace code in case of mult-line  : not working for IE...
273
!! # 16/12/2017: removed stretchy left brace code in case of multi-line  : not working for IE...
-
 
274
!! # 17/12/2016: changed jqmath.css : ma-block "display:block;text-align:center--> display:inline;text-align:left"
-
 
275
!! # 17/12/2016: added child 'p' and 'br' inorder to get a left-align of multi-lines
-
 
276