diff --git a/typejax/typejax.js b/typejax/typejax.js
index 147e91c..d230813 100644
--- a/typejax/typejax.js
+++ b/typejax/typejax.js
@@ -1218,6 +1218,8 @@ window.typejax = (function($){
}
}
},
+
+ //------------------------------------------------------------------------
doEnvironment : function(node) {
var name = node.name, same = this.getGroupSame(name);
@@ -1963,7 +1965,7 @@ window.typejax = (function($){
name: "thmhead",
mode: "inline",
from: node.childs[0].from,
- value: "" + thmhead + " ",
+ value: ""+thmhead+"",
parent: node.childs[0],
childs: []
};
@@ -2006,6 +2008,11 @@ window.typejax = (function($){
}
};
+
+// ----------------------------------------------
+// Defining Latex behaviour. TODO: Place it somehow in a separate file
+// ----------------------------------------------
+
var latex = {
cmdvalues : {
documentclass: "article"
@@ -2044,6 +2051,8 @@ window.typejax = (function($){
}
};
+
+
/* group.mode
* main group could include main and block groups
* block group cuuld include inline groups and bmath elements
@@ -2080,6 +2089,9 @@ window.typejax = (function($){
"subsubsection*": "section",
"tableofcontents": {mode: "block", args: ["[]"], outs: ["par"]},
"textbf": {mode: "inline", args: ["{}"]},
+ "cite": {mode: "inline", args: ["{}"]},
+ "label": {mode: "inline", args: ["{}"]},
+ "ref": {mode: "inline", args: ["{}"]},
"thanks": {mode: "inline", args: ["{}"]},
"title": {mode: "inline", args: ["[]", "{}"]},
"usepackage": {mode: "inline", args: ["[]", "{}"]}
@@ -2087,6 +2099,7 @@ window.typejax = (function($){
environment: {
"bmath": {mode: "block"},
"center": {mode: "main", args: ["||"], outs: ["par", "center"]},
+ "abstract": {mode: "block", args: ["||"]},
"enumerate": {mode: "block", args: ["[]", "||"]},
"item": {mode: "main", args: ["<>", "||"]},
"itemize": {mode: "block", args: ["[]", "||"]},
@@ -2126,46 +2139,24 @@ window.typejax = (function($){
}
},
- cmdHline: function() {
- return;
- },
-
- cmdMaketitle: function(node) {
- if (typeof this.cmdvalues["title"] == "undefined") return;
- var result = "
" + this.cmdvalues["title"] + "
";
-
- if (typeof this.cmdvalues["author"] == "undefined") {
- this.cmdvalues["author"] = "";
- }
- result += "" + this.cmdvalues["author"] + "
";
- if (typeof this.cmdvalues["institute"] != "undefined") {
- result += "" + this.cmdvalues["institute"] + "
";
- }
- if (typeof this.cmdvalues["date"] == "undefined") {
- result += "" + (new Date()).toLocaleDateString() + "
";
- } else {
- result += "" + this.cmdvalues["date"] + "
";
- }
-
- if (node.name == "maketitle" && this.cmdvalues["documentclass"] == "beamer") {
- result = "" + result + "
";
- }
+ cmdHline: function() { return; }, // Feanor: General code cleaning
- node.childs = [];
- node.value = result;
+ cmdMaketitle: function(node) { // Feanor: General code cleaning
+ if (typeof this.cmdvalues["title"] == "undefined") return; if (typeof this.cmdvalues["author"] == "undefined") {this.cmdvalues["author"] = "";}
+ var result = "" + this.cmdvalues["title"] + "
" + "" + this.cmdvalues["author"] + "
";
+ if (typeof this.cmdvalues["institute"] != "undefined") { result += "" + this.cmdvalues["institute"] + "
"; }
+ if (typeof this.cmdvalues["date"] == "undefined") { result += "" + (new Date()).toLocaleDateString() + "
";}
+ else { result += "" + this.cmdvalues["date"] + "
"; }
+ if (node.name == "maketitle" && this.cmdvalues["documentclass"] == "beamer") {result = "" + result + "
";}
+ node.childs = []; node.value = result;
},
- cmdNewcounter: function(node) {
- var parameters = this.readParameters(node),
- name = parameters[0], parent = parameters[1] || null;
- if (name) {
- this.newCounter(name, parent);
- }
+ cmdNewcounter: function(node) { // Feanor: General code cleaning
+ var parameters = this.readParameters(node), name = parameters[0], parent = parameters[1] || null;
+ if (name) {this.newCounter(name, parent);}
},
- cmdNewline: function() {
- this.addText("
", this.place - 1);
- },
+ cmdNewline: function() { this.addText("
", this.place - 1); }, // Feanor: General code cleaning
cmdNewtheorem: function(node) {
// \newtheorem{envname}{thmname}[numberby]
@@ -2219,19 +2210,13 @@ window.typejax = (function($){
},
cmdQquad: function() {
- if (this.mathenv != "") {
- this.addText("\\" + this.value, this.place - 1);
- } else {
- this.addText("", this.place - 1);
- }
+ if (this.mathenv != "") { this.addText("\\" + this.value, this.place - 1);}
+ else { this.addText("", this.place - 1); }
},
cmdQuad: function() {
- if (this.mathenv != "") {
- this.addText("\\" + this.value, this.place - 1);
- } else {
- this.addText("", this.place -1);
- }
+ if (this.mathenv != ""){ this.addText("\\" + this.value, this.place - 1); }
+ else { this.addText("", this.place -1);}
},
cmdSection: function(node) {
@@ -2252,34 +2237,36 @@ window.typejax = (function($){
node.childs = [];
},
- cmdTableofcontents: function(node) {
- node.childs = [];
- node.value = "";
- },
-
- cmdTextbackslash: function() {
- this.addText("\\", this.place - 1);
+ cmdTableofcontents: function(node) {
+ node.childs = []; node.value = "";
},
- cmdTextbar: function() {
- this.addText("|", this.place - 1);
- },
+ cmdTextbackslash: function() { this.addText("\\", this.place - 1);},// Feanor: General code cleaning
+ cmdTextbar: function() { this.addText("|", this.place - 1);},// Feanor: General code cleaning
cmdTextbf: function(node) {
- if (node.argarray[0].childs[0]) {
- node.value = "" + node.argarray[0].childs[0].value + "";
- node.childs = [];
- }
+ if (node.argarray[0].childs[0])
+ {node.value = "" + node.argarray[0].childs[0].value + ""; node.childs = [];}
+ },
+
+ cmdCite : function(node) {
+ if (node.argarray[0].childs[0])
+ {node.value = "[" + node.argarray[0].childs[0].value + "]"; node.childs = [];}
},
- cmdTextgreater: function() {
- this.addText(">", this.place - 1);
+ cmdLabel : function(node) {
+ if (node.argarray[0].childs[0])
+ { node.value = ""; node.childs = []; }
},
- cmdTextless: function() {
- this.addText("<", this.place - 1);
+ cmdRef : function(node) {
+ if (node.argarray[0].childs[0])
+ { node.value = "^"; node.childs = []; }
},
+ cmdTextgreater: function() { this.addText(">", this.place - 1); }, // Feanor: General code cleaning
+ cmdTextless: function() { this.addText("<", this.place - 1); }, // Feanor: General code cleaning
+
cmdTitle: function(node) {
var csname = node.name, argarray = node.argarray;
var argnode, child, i, value = "";
@@ -2469,6 +2456,10 @@ window.typejax = (function($){
list: {used: [], current: [], missing: [], existing: []}
};
+// ----------------------------------------------
+// Parser
+// ----------------------------------------------
+
function start() {
console.log("---------------- start parser ----------------");
syner.analysis(input, modstart, modend);
@@ -2496,112 +2487,71 @@ window.typejax = (function($){
function load(input1, modstart1, modend1, callback1) {
input = input1; modstart = modstart1; modend = modend1; callback = callback1;
- if (time && ((new Date).getTime() - time) > 2000) {
- time = null;
- return callback(null);
- }
- done = true;
- var out = start();
- if (done) {
+ if (time && ((new Date).getTime() - time) > 2000)
+ { time = null; return callback(null); }
+ //done = true;
+ var out = start();
+ //if (done) {
callback(out);
- }
- }
-
- function reload() {
- callback(null);
- };
-
- function delayReload() {
- time = (new Date).getTime();
+ //}
}
+ function reload() {callback(null);};
+ function delayReload() {time = (new Date).getTime();}
return { latex: latex, load: load, extend: extend };
})(typejax);
- typejax.builder = function(tree, flag){
- var open, close, html = "";
+// ----------------------------------------------
+// Building "math-mode" environment from the tree
+// ----------------------------------------------
+ typejax.builder = function(tree, flag){
+ var open = ""; var close= ""; var html= ""; var editable= "";
if (tree.reset) this.builder.reset += tree.reset;
- if (flag) {
- if (tree.mode == "inline") {
- open = "", close = "";
- if (tree.name == "imath") {
- open += "" + $.escapeText(tree.value) + "";
- open += "" + close;
- }
- } else {
- open = "", close = "
";
- switch (tree.name) {
- case "bmath":
- open += "" + $.escapeText(tree.value) + "
";
- open += "" + close;
- break;
- case "enumerate":
- open += "", close = "
" + close;
- break;
- case "itemize":
- open += "" + close;
- break;
- case "item":
- open = "", close = "";
- break;
- }
- }
- } else {
- switch (tree.name) {
- case "bmath":
- open = "" + $.escapeText(tree.value) + "
";
- open += "";
- break;
- case "enumerate":
- open = "";
- break;
- case "itemize":
- open = "";
- break;
- case "item":
- open = "", close = "";
- break;
- default:
- open = "", close = "";
- }
- flag = true;
- }
- if (tree.childs.length > 0) {
- for (var i = 0; i < tree.childs.length; i++) {
- html += this.builder(tree.childs[i], flag);
- }
- } else {
- html = tree.value;
- }
- if (tree.mode == "inline" && tree.childs.length == 0 && tree.value == "") {
- return "";
- } else {
- return open + html + close;
- }
+ if (flag) {
+ if (tree.mode == "inline")
+ { open = "";}
+ if (((tree.name == "enumerate")||(tree.name == "itemize"))&&(flag==true)){open = "", close = "
";}
+
+ switch (tree.name) {
+ case "imath": open += "" + $.escapeText(tree.value) + " " + close;
+ break;
+ case "bmath": open += "" + $.escapeText(tree.value) + "
" + close;
+ break;
+ case "enumerate": open += "", close = "
" + close;
+ break;
+ case "itemize": open += "" + close;
+ break;
+ case "item": open = "", close = "";
+ break;
+ default: if (flag==false) {open = "", close = "";};
+ break;
+ }
+
+ flag = false;
+ if (tree.childs.length > 0)
+ { for (var i = 0; i < tree.childs.length; i++) { html += this.builder(tree.childs[i], flag); } }
+ else { html = tree.value; }
+
+ //editable = "";//""+ html +"
";
+ if (tree.mode == "inline" && tree.childs.length == 0 && tree.value == "") { return ""; } else { return open + html + close + editable; }
};
- typejax.message = {
- degug: "none",
-
+// ----------------------------------------------
+//
+// ----------------------------------------------
+
+ typejax.message = { degug: "none",
log: function(type) {
var msg = Array.prototype.slice.call(arguments, 1).join(" ");
var sto = this.storage;
sto[type] = sto[type] ? sto[type] + "\n" + msg : msg;
if (this.debug == "all" || this.debug.indexOf(type) > -1) console.log(msg);
},
-
- get: function(type) {
- return (this.storage[type] || "");
- },
-
- print: function(type) {
- console.log(this.storage[type] || "");
- },
-
- clear: function(type) {
- delete this.storage[type];
- },
-
+ get: function(type) { return (this.storage[type] || ""); },
+ print: function(type) { console.log(this.storage[type] || ""); },
+ clear: function(type) { delete this.storage[type]; },
storage: {}
};