Skip to content
Permalink
Browse files

Change AMsymbols handling to use push instead of concat

Add newsymbol command for adding a new symbol object
  • Loading branch information...
drlippman committed Apr 18, 2016
1 parent 953d861 commit f649ba49f639b7e5322d6552193226c03e88ba7e
Showing with 49 additions and 33 deletions.
  1. +15 −13 ASCIIMathML.js
  2. +18 −7 asciimath-based/ASCIIMathTeXImg.js
  3. +16 −13 mathjax/jax.js
@@ -187,12 +187,13 @@ function createMmlNode(t,frag) {
}

function newcommand(oldstr,newstr) {
AMsymbols = AMsymbols.concat([{input:oldstr, tag:"mo", output:newstr,
tex:null, ttype:DEFINITION}]);
// #### Added from Version 2.0.1 #### //
AMsymbols.sort(compareNames);
for (i=0; i<AMsymbols.length; i++) AMnames[i] = AMsymbols[i].input;
// #### End of Addition #### //
AMsymbols.push({input:oldstr, tag:"mo", output:newstr, tex:null, ttype:DEFINITION});
refreshSymbols();
}

function newsymbol(symbolobj) {
AMsymbols.push(symbolobj);
refreshSymbols();
}

// character lists for Mozilla/Netscape fonts
@@ -471,14 +472,15 @@ function compareNames(s1,s2) {
var AMnames = []; //list of input symbols

function initSymbols() {
var texsymbols = [], i;
for (i=0; i<AMsymbols.length; i++)
var i;
var symlen = AMsymbols.length;
for (i=0; i<symlen; i++) {
if (AMsymbols[i].tex) {
texsymbols[texsymbols.length] = {input:AMsymbols[i].tex,
AMsymbols.push({input:AMsymbols[i].tex,
tag:AMsymbols[i].tag, output:AMsymbols[i].output, ttype:AMsymbols[i].ttype,
acc:(AMsymbols[i].acc||false)};
acc:(AMsymbols[i].acc||false)});
}
AMsymbols = AMsymbols.concat(texsymbols);
}
refreshSymbols();
}

@@ -489,8 +491,7 @@ function refreshSymbols(){
}

function define(oldstr,newstr) {
AMsymbols = AMsymbols.concat([{input:oldstr, tag:"mo", output:newstr,
tex:null, ttype:DEFINITION}]);
AMsymbols.push({input:oldstr, tag:"mo", output:newstr, tex:null, ttype:DEFINITION});
refreshSymbols(); // this may be a problem if many symbols are defined!
}

@@ -1118,6 +1119,7 @@ else if(typeof window.attachEvent != 'undefined'){

//expose some functions to outside
asciimath.newcommand = newcommand;
asciimath.newsymbol = newsymbol;
asciimath.AMprocesssNode = AMprocessNode;
asciimath.parseMath = parseMath;
asciimath.translate = translate;
@@ -334,21 +334,32 @@ function compareNames(s1,s2) {
var AMnames = []; //list of input symbols

function AMinitSymbols() {
var texsymbols = [], i;
for (i=0; i<AMsymbols.length; i++)
var i;
var symlen = AMsymbols.length;
for (i=0; i<symlen; i++) {
if (AMsymbols[i].tex && !(typeof AMsymbols[i].notexcopy == "boolean" && AMsymbols[i].notexcopy)) {
texsymbols[texsymbols.length] = {input:AMsymbols[i].tex,
AMsymbols.push({input:AMsymbols[i].tex,
tag:AMsymbols[i].tag, output:AMsymbols[i].output, ttype:AMsymbols[i].ttype,
acc:(AMsymbols[i].acc||false)};
acc:(AMsymbols[i].acc||false)});
}
AMsymbols = AMsymbols.concat(texsymbols);
}
refreshSymbols();
}

function refreshSymbols(){
var i;
AMsymbols.sort(compareNames);
for (i=0; i<AMsymbols.length; i++) AMnames[i] = AMsymbols[i].input;
}

function newcommand(oldstr,newstr) {
AMsymbols = AMsymbols.concat([{input:oldstr, tag:"mo", output:newstr,
tex:null, ttype:DEFINITION}]);
AMsymbols.push({input:oldstr, tag:"mo", output:newstr, tex:null, ttype:DEFINITION});
refreshSymbols();
}

function newsymbol(symbolobj) {
AMsymbols.push(symbolobj);
refreshSymbols();
}

function AMremoveCharsAndBlanks(str,n) {
@@ -382,12 +382,13 @@ function createMmlNode(t,frag) {
}

function newcommand(oldstr,newstr) {
AMsymbols = AMsymbols.concat([{input:oldstr, tag:"mo", output:newstr,
tex:null, ttype:DEFINITION}]);
// #### Added from Version 2.0.1 #### //
AMsymbols.sort(compareNames);
for (i=0; i<AMsymbols.length; i++) AMnames[i] = AMsymbols[i].input;
// #### End of Addition #### //
AMsymbols.push({input:oldstr, tag:"mo", output:newstr, tex:null, ttype:DEFINITION});
refreshSymbols();
}

function newsymbol(symbolobj) {
AMsymbols.push(symbolobj);
refreshSymbols();
}

// character lists for Mozilla/Netscape fonts
@@ -666,14 +667,15 @@ function compareNames(s1,s2) {
var AMnames = []; //list of input symbols

function initSymbols() {
var texsymbols = [], i;
for (i=0; i<AMsymbols.length; i++)
var i;
var symlen = AMsymbols.length;
for (i=0; i<symlen; i++) {
if (AMsymbols[i].tex) {
texsymbols[texsymbols.length] = {input:AMsymbols[i].tex,
AMsymbols.push({input:AMsymbols[i].tex,
tag:AMsymbols[i].tag, output:AMsymbols[i].output, ttype:AMsymbols[i].ttype,
acc:(AMsymbols[i].acc||false)};
acc:(AMsymbols[i].acc||false)});
}
AMsymbols = AMsymbols.concat(texsymbols);
}
refreshSymbols();
}

@@ -684,8 +686,7 @@ function refreshSymbols(){
}

function define(oldstr,newstr) {
AMsymbols = AMsymbols.concat([{input:oldstr, tag:"mo", output:newstr,
tex:null, ttype:DEFINITION}]);
AMsymbols.push({input:oldstr, tag:"mo", output:newstr, tex:null, ttype:DEFINITION});
refreshSymbols(); // this may be a problem if many symbols are defined!
}

@@ -1316,6 +1317,7 @@ else if(typeof window.attachEvent != 'undefined'){
//expose some functions to outside
asciimath.newcommand = newcommand;
asciimath.newsymbol = newsymbol;
asciimath.AMprocesssNode = AMprocessNode;
asciimath.parseMath = parseMath;
asciimath.translate = translate;
@@ -1409,6 +1411,7 @@ ASCIIMATH.Augment({

define: define,
newcommand: newcommand,
newsymbol: newsymbol,
symbols: AMsymbols,
names: AMnames,

0 comments on commit f649ba4

Please sign in to comment.
You can’t perform that action at this time.