Skip to content

Commit f649ba4

Browse files
committed
Change AMsymbols handling to use push instead of concat
Add newsymbol command for adding a new symbol object
1 parent 953d861 commit f649ba4

File tree

3 files changed

+49
-33
lines changed

3 files changed

+49
-33
lines changed

ASCIIMathML.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,13 @@ function createMmlNode(t,frag) {
187187
}
188188

189189
function newcommand(oldstr,newstr) {
190-
AMsymbols = AMsymbols.concat([{input:oldstr, tag:"mo", output:newstr,
191-
tex:null, ttype:DEFINITION}]);
192-
// #### Added from Version 2.0.1 #### //
193-
AMsymbols.sort(compareNames);
194-
for (i=0; i<AMsymbols.length; i++) AMnames[i] = AMsymbols[i].input;
195-
// #### End of Addition #### //
190+
AMsymbols.push({input:oldstr, tag:"mo", output:newstr, tex:null, ttype:DEFINITION});
191+
refreshSymbols();
192+
}
193+
194+
function newsymbol(symbolobj) {
195+
AMsymbols.push(symbolobj);
196+
refreshSymbols();
196197
}
197198

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

473474
function initSymbols() {
474-
var texsymbols = [], i;
475-
for (i=0; i<AMsymbols.length; i++)
475+
var i;
476+
var symlen = AMsymbols.length;
477+
for (i=0; i<symlen; i++) {
476478
if (AMsymbols[i].tex) {
477-
texsymbols[texsymbols.length] = {input:AMsymbols[i].tex,
479+
AMsymbols.push({input:AMsymbols[i].tex,
478480
tag:AMsymbols[i].tag, output:AMsymbols[i].output, ttype:AMsymbols[i].ttype,
479-
acc:(AMsymbols[i].acc||false)};
481+
acc:(AMsymbols[i].acc||false)});
480482
}
481-
AMsymbols = AMsymbols.concat(texsymbols);
483+
}
482484
refreshSymbols();
483485
}
484486

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

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

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

11191120
//expose some functions to outside
11201121
asciimath.newcommand = newcommand;
1122+
asciimath.newsymbol = newsymbol;
11211123
asciimath.AMprocesssNode = AMprocessNode;
11221124
asciimath.parseMath = parseMath;
11231125
asciimath.translate = translate;

asciimath-based/ASCIIMathTeXImg.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -334,21 +334,32 @@ function compareNames(s1,s2) {
334334
var AMnames = []; //list of input symbols
335335

336336
function AMinitSymbols() {
337-
var texsymbols = [], i;
338-
for (i=0; i<AMsymbols.length; i++)
337+
var i;
338+
var symlen = AMsymbols.length;
339+
for (i=0; i<symlen; i++) {
339340
if (AMsymbols[i].tex && !(typeof AMsymbols[i].notexcopy == "boolean" && AMsymbols[i].notexcopy)) {
340-
texsymbols[texsymbols.length] = {input:AMsymbols[i].tex,
341+
AMsymbols.push({input:AMsymbols[i].tex,
341342
tag:AMsymbols[i].tag, output:AMsymbols[i].output, ttype:AMsymbols[i].ttype,
342-
acc:(AMsymbols[i].acc||false)};
343+
acc:(AMsymbols[i].acc||false)});
343344
}
344-
AMsymbols = AMsymbols.concat(texsymbols);
345+
}
346+
refreshSymbols();
347+
}
348+
349+
function refreshSymbols(){
350+
var i;
345351
AMsymbols.sort(compareNames);
346352
for (i=0; i<AMsymbols.length; i++) AMnames[i] = AMsymbols[i].input;
347353
}
348354

349355
function newcommand(oldstr,newstr) {
350-
AMsymbols = AMsymbols.concat([{input:oldstr, tag:"mo", output:newstr,
351-
tex:null, ttype:DEFINITION}]);
356+
AMsymbols.push({input:oldstr, tag:"mo", output:newstr, tex:null, ttype:DEFINITION});
357+
refreshSymbols();
358+
}
359+
360+
function newsymbol(symbolobj) {
361+
AMsymbols.push(symbolobj);
362+
refreshSymbols();
352363
}
353364

354365
function AMremoveCharsAndBlanks(str,n) {

mathjax/jax.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -382,12 +382,13 @@ function createMmlNode(t,frag) {
382382
}
383383

384384
function newcommand(oldstr,newstr) {
385-
AMsymbols = AMsymbols.concat([{input:oldstr, tag:"mo", output:newstr,
386-
tex:null, ttype:DEFINITION}]);
387-
// #### Added from Version 2.0.1 #### //
388-
AMsymbols.sort(compareNames);
389-
for (i=0; i<AMsymbols.length; i++) AMnames[i] = AMsymbols[i].input;
390-
// #### End of Addition #### //
385+
AMsymbols.push({input:oldstr, tag:"mo", output:newstr, tex:null, ttype:DEFINITION});
386+
refreshSymbols();
387+
}
388+
389+
function newsymbol(symbolobj) {
390+
AMsymbols.push(symbolobj);
391+
refreshSymbols();
391392
}
392393

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

668669
function initSymbols() {
669-
var texsymbols = [], i;
670-
for (i=0; i<AMsymbols.length; i++)
670+
var i;
671+
var symlen = AMsymbols.length;
672+
for (i=0; i<symlen; i++) {
671673
if (AMsymbols[i].tex) {
672-
texsymbols[texsymbols.length] = {input:AMsymbols[i].tex,
674+
AMsymbols.push({input:AMsymbols[i].tex,
673675
tag:AMsymbols[i].tag, output:AMsymbols[i].output, ttype:AMsymbols[i].ttype,
674-
acc:(AMsymbols[i].acc||false)};
676+
acc:(AMsymbols[i].acc||false)});
675677
}
676-
AMsymbols = AMsymbols.concat(texsymbols);
678+
}
677679
refreshSymbols();
678680
}
679681

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

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

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

14101412
define: define,
14111413
newcommand: newcommand,
1414+
newsymbol: newsymbol,
14121415
symbols: AMsymbols,
14131416
names: AMnames,
14141417

0 commit comments

Comments
 (0)