[LON-CAPA-cvs] cvs: loncom /homework units.json /homework/math_parser Tokenizer.pm /html/adm/LC_math_editor/dist LC_math_editor.min.js /html/adm/LC_math_editor/src tokenizer.js

damieng damieng at source.lon-capa.org
Thu Aug 13 14:30:42 EDT 2015


damieng		Thu Aug 13 18:30:42 2015 EDT

  Modified files:              
    /loncom/homework	units.json 
    /loncom/homework/math_parser	Tokenizer.pm 
    /loncom/html/adm/LC_math_editor/dist	LC_math_editor.min.js 
    /loncom/html/adm/LC_math_editor/src	tokenizer.js 
  Log:
  added support for ° as units in lcmath
  
-------------- next part --------------
Index: loncom/homework/units.json
diff -u loncom/homework/units.json:1.1 loncom/homework/units.json:1.2
--- loncom/homework/units.json:1.1	Mon Jun 29 15:42:07 2015
+++ loncom/homework/units.json	Thu Aug 13 18:30:24 2015
@@ -88,6 +88,7 @@
         { "name": "henry",           "symbol": "H",    "convert": "V*s/A",                   "comment": "inductance" },
         { "name": "radian",          "symbol": "rad",  "convert": "m/m",                     "comment": "plane angle" },
         { "name": "degree",          "symbol": "deg",  "convert": "1.745329E-2 rad",         "comment": "plane angle (Pi rad=180 deg)" },
+        { "name": "degree",          "symbol": "°",    "convert": "1.745329E-2 rad",         "comment": "same as deg" },
         { "name": "steradian",       "symbol": "sr",   "convert": "m^2 /m^2",                "comment": "solid angle" },
         { "name": "lumen",           "symbol": "lm",   "convert": "cd*sr",                   "comment": "luminous flux" },
         { "name": "lux",             "symbol": "lx",   "convert": "cd*sr/m^2",               "comment": "illuminance" },
Index: loncom/homework/math_parser/Tokenizer.pm
diff -u loncom/homework/math_parser/Tokenizer.pm:1.1 loncom/homework/math_parser/Tokenizer.pm:1.2
--- loncom/homework/math_parser/Tokenizer.pm:1.1	Mon Jun 29 15:42:13 2015
+++ loncom/homework/math_parser/Tokenizer.pm	Thu Aug 13 18:30:30 2015
@@ -182,7 +182,7 @@
         
         # names
         if (($c ge 'a' && $c le 'z') || ($c ge 'A' && $c le 'Z') ||
-                ($c ge 'α' && $c le 'ω') || ($c ge 'Α' && $c le 'Ω') || $c eq 'µ') {
+                ($c ge 'α' && $c le 'ω') || ($c ge 'Α' && $c le 'Ω') || $c eq 'µ' || $c eq '°') {
             $value = $c;
             $i++;
             for (;;) {
Index: loncom/html/adm/LC_math_editor/dist/LC_math_editor.min.js
diff -u loncom/html/adm/LC_math_editor/dist/LC_math_editor.min.js:1.4 loncom/html/adm/LC_math_editor/dist/LC_math_editor.min.js:1.5
--- loncom/html/adm/LC_math_editor/dist/LC_math_editor.min.js:1.4	Wed Apr 15 16:50:37 2015
+++ loncom/html/adm/LC_math_editor/dist/LC_math_editor.min.js	Thu Aug 13 18:30:36 2015
@@ -43,8 +43,8 @@
 s=0;s<l.length;s++)if(h.value==l[s]){e=!1;break}}e?(d=new k(k.OPERATOR,d.from,d.from,a.id,a),c=!0):d=new k(k.OPERATOR,d.from,d.from,b.id,b);this.tokens.splice(f+1,0,d)}}};r.prototype.parse=function(b){this.tokens=(new t(this.defs,b)).tokenize();if(0==this.tokens.length)return null;this.implicit_operators&&this.addHiddenOperators();this.token_nr=0;this.current_token=this.tokens[this.token_nr];this.advance();b=this.expression(0);if(null!=this.current_token)throw new n("Expected the end",this.current_token.from);
 return b};"use strict";t.prototype.tokenize=function(){var b,a,c,g,f;a=0;b=this.text.charAt(a);f=[];a:for(;b;)if(g=a," ">=b)a++,b=this.text.charAt(a);else{if("0"<=b&&"9">=b||(b===l.DECIMAL_SIGN_1||b===l.DECIMAL_SIGN_2)&&"0"<=this.text.charAt(a+1)&&"9">=this.text.charAt(a+1)){c="";if(b!==l.DECIMAL_SIGN_1&&b!==l.DECIMAL_SIGN_2)for(a++,c+=b;;){b=this.text.charAt(a);if("0">b||"9"<b)break;a++;c+=b}if(b===l.DECIMAL_SIGN_1||b===l.DECIMAL_SIGN_2)for(a++,c+=b;;){b=this.text.charAt(a);if("0">b||"9"<b)break;
 a+=1;c+=b}if("e"===b||"E"===b){a++;c+=b;b=this.text.charAt(a);if("-"===b||"+"===b)a++,c+=b,b=this.text.charAt(a);if("0">b||"9"<b)throw new n("syntax error in number exponent",g,a);do a++,c+=b,b=this.text.charAt(a);while("0"<=b&&"9">=b)}var e=+c.replace(l.DECIMAL_SIGN_1,".").replace(l.DECIMAL_SIGN_2,".");if(isFinite(e)){f.push(new k(k.NUMBER,g,a-1,c,null));continue}else throw new n("syntax error in number",g,a);}for(c=0;c<this.defs.operators.length;c++)if(e=this.defs.operators[c],this.text.substring(a,
-a+e.id.length)===e.id){a+=e.id.length;b=this.text.charAt(a);f.push(new k(k.OPERATOR,g,a-1,e.id,e));continue a}if("a"<=b&&"z">=b||"A"<=b&&"Z">=b||"\u03b1"<=b&&"\u03c9">=b||"\u0391"<=b&&"\u03a9">=b||"\u00b5"==b){c=b;for(a++;;)if(b=this.text.charAt(a),"a"<=b&&"z">=b||"A"<=b&&"Z">=b||"\u03b1"<=b&&"\u03c9">=b||"\u0391"<=b&&"\u03a9">=b||"\u00b5"==b||"0"<=b&&"9">=b||"_"===b)c+=b,a++;else break;f.push(new k(k.NAME,g,a-1,c,null))}else throw new n("unrecognized operator",g,a);}return f};"use strict";k.UNKNOWN=
-0;k.NAME=1;k.NUMBER=2;k.OPERATOR=3;"use strict";var u=function(b){var a,c,e,f,m;a=b.ta;c=b.output_node;a=a.value;f="";for(m=a;m!=f;)f=m,m=f.replace(/\[[^\[\]]*\]/g,"");if(m.split("[").length==m.split("]").length){for(f="";m!=f;)f=m,m=f.replace(/\([^\(\)]*\)/g,"");if(m.split("(").length==m.split(")").length){for(f="";m!=f;)f=m,m=f.replace(/\{[^\{\}]*\}/g,"");m.split("{").length==m.split("}").length&&-1!=m.indexOf(l.ARG_SEPARATOR)&&(a="["+a+"]")}}if(a!=b.oldtxt){for(b.oldtxt=a;null!=c.firstChild;)c.removeChild(c.firstChild);
+a+e.id.length)===e.id){a+=e.id.length;b=this.text.charAt(a);f.push(new k(k.OPERATOR,g,a-1,e.id,e));continue a}if("a"<=b&&"z">=b||"A"<=b&&"Z">=b||"\u03b1"<=b&&"\u03c9">=b||"\u0391"<=b&&"\u03a9">=b||"\u00b5"==b||"\u00b0"==b){c=b;for(a++;;)if(b=this.text.charAt(a),"a"<=b&&"z">=b||"A"<=b&&"Z">=b||"\u03b1"<=b&&"\u03c9">=b||"\u0391"<=b&&"\u03a9">=b||"\u00b5"==b||"0"<=b&&"9">=b||"_"===b)c+=b,a++;else break;f.push(new k(k.NAME,g,a-1,c,null))}else throw new n("unrecognized operator",g,a);}return f};"use strict";
+k.UNKNOWN=0;k.NAME=1;k.NUMBER=2;k.OPERATOR=3;"use strict";var u=function(b){var a,c,e,f,m;a=b.ta;c=b.output_node;a=a.value;f="";for(m=a;m!=f;)f=m,m=f.replace(/\[[^\[\]]*\]/g,"");if(m.split("[").length==m.split("]").length){for(f="";m!=f;)f=m,m=f.replace(/\([^\(\)]*\)/g,"");if(m.split("(").length==m.split(")").length){for(f="";m!=f;)f=m,m=f.replace(/\{[^\{\}]*\}/g,"");m.split("{").length==m.split("}").length&&-1!=m.indexOf(l.ARG_SEPARATOR)&&(a="["+a+"]")}}if(a!=b.oldtxt){for(b.oldtxt=a;null!=c.firstChild;)c.removeChild(c.firstChild);
 c.removeAttribute("title");if(""!=a){b=b.parser;try{if(e=b.parse(a),null!=e){var d=document.createElement("math");d.setAttribute("display","block");d.appendChild(e.toMathML());c.appendChild(d);MathJax.Hub.Queue(["Typeset",MathJax.Hub,c])}}catch(h){e="error: "+h,c.setAttribute("title",e),h instanceof n?(c.appendChild(document.createTextNode(a.substring(0,h.from))),e=document.createElement("span"),e.appendChild(document.createTextNode(a.substring(h.from,h.to+1))),e.style.border="solid 1px red",e.style.minWidth=
 "1px",c.appendChild(e),h.to<a.length-1&&c.appendChild(document.createTextNode(a.substring(h.to+1)))):(a=document.createTextNode(e),c.appendChild(a))}}}},q=[];return{Definitions:l,ENode:e,Operator:p,ParseException:n,Parser:r,initEditors:function(){MathJax.Hub.Config({messageStyle:"none"});for(var b=document.getElementsByClassName("math"),a=0;a<q.length;a++){for(var c=q[a].ta,e=!1,f=0;f<b.length;f++)if(b[f]==c){e=!0;break}e||(f=q[a].output_node,f.parentNode&&f.parentNode.removeChild(f),q.splice(a,1),
 a--)}for(a=0;a<b.length;a++)if(c=b[a],"TEXTAREA"==c.nodeName||"INPUT"==c.nodeName){e=-1;for(f=0;f<q.length;f++)if(q[f].ta==c){e=f;break}var m="true"===c.getAttribute("data-implicit_operators"),d="true"===c.getAttribute("data-unit_mode"),h=c.getAttribute("data-constants");h&&(h=h.split(/[\s,]+/));if(-1==e){f=document.createElement("span");f.style.display="none";f.style.position="absolute";f.style.backgroundColor="rgba(255,255,224,0.9)";f.style.color="black";f.style.border="1px solid #A0A0A0";f.style.padding=
Index: loncom/html/adm/LC_math_editor/src/tokenizer.js
diff -u loncom/html/adm/LC_math_editor/src/tokenizer.js:1.2 loncom/html/adm/LC_math_editor/src/tokenizer.js:1.3
--- loncom/html/adm/LC_math_editor/src/tokenizer.js:1.2	Tue Feb 24 15:20:44 2015
+++ loncom/html/adm/LC_math_editor/src/tokenizer.js	Thu Aug 13 18:30:42 2015
@@ -144,7 +144,7 @@
         
         // names
         if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
-                (c >= 'α' && c <= 'ω') || (c >= 'Α' && c <= 'Ω') || c == 'µ') {
+                (c >= 'α' && c <= 'ω') || (c >= 'Α' && c <= 'Ω') || c == 'µ' || c == '°') {
             value = c;
             i++;
             for (;;) {


More information about the LON-CAPA-cvs mailing list