2014-07-16 06:07:18 -04:00
|
|
|
ace.define("ace/mode/latex_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module) {
|
2014-07-09 12:59:04 -04:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var oop = require("../lib/oop");
|
|
|
|
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
|
|
|
|
|
2014-08-19 16:33:09 -04:00
|
|
|
var LatexHighlightRules = function() {
|
|
|
|
|
2014-07-09 12:59:04 -04:00
|
|
|
this.$rules = {
|
|
|
|
"start" : [{
|
2014-08-19 16:33:09 -04:00
|
|
|
token : "comment",
|
|
|
|
regex : "%.*$"
|
|
|
|
}, {
|
|
|
|
token : ["keyword", "lparen", "variable.parameter", "rparen", "lparen", "storage.type", "rparen"],
|
2015-02-12 05:36:57 -05:00
|
|
|
regex : "(\\\\(?:documentclass|usepackage|input))(?:(\\[)([^\\]]*)(\\]))?({)([^}]*)(})"
|
2014-08-19 16:33:09 -04:00
|
|
|
}, {
|
|
|
|
token : ["keyword","lparen", "variable.parameter", "rparen"],
|
2014-11-28 08:58:27 -05:00
|
|
|
regex : "(\\\\(?:label|v?ref|cite(?:[^{]*)))(?:({)([^}]*)(}))?"
|
2014-08-19 16:33:09 -04:00
|
|
|
}, {
|
|
|
|
token : ["storage.type", "lparen", "variable.parameter", "rparen"],
|
|
|
|
regex : "(\\\\(?:begin|end))({)(\\w*)(})"
|
|
|
|
}, {
|
|
|
|
token : "storage.type",
|
|
|
|
regex : "\\\\[a-zA-Z]+"
|
2014-07-09 12:59:04 -04:00
|
|
|
}, {
|
|
|
|
token : "lparen",
|
|
|
|
regex : "[[({]"
|
|
|
|
}, {
|
|
|
|
token : "rparen",
|
|
|
|
regex : "[\\])}]"
|
|
|
|
}, {
|
2014-08-19 16:33:09 -04:00
|
|
|
token : "constant.character.escape",
|
|
|
|
regex : "\\\\[^a-zA-Z]?"
|
2014-07-09 12:59:04 -04:00
|
|
|
}, {
|
2014-08-19 16:33:09 -04:00
|
|
|
token : "string",
|
|
|
|
regex : "\\${1,2}",
|
|
|
|
next : "equation"
|
|
|
|
}],
|
|
|
|
"equation" : [{
|
2014-07-09 12:59:04 -04:00
|
|
|
token : "comment",
|
|
|
|
regex : "%.*$"
|
2014-08-19 16:33:09 -04:00
|
|
|
}, {
|
|
|
|
token : "string",
|
|
|
|
regex : "\\${1,2}",
|
|
|
|
next : "start"
|
|
|
|
}, {
|
|
|
|
token : "constant.character.escape",
|
|
|
|
regex : "\\\\(?:[^a-zA-Z]|[a-zA-Z]+)"
|
|
|
|
}, {
|
|
|
|
token : "error",
|
|
|
|
regex : "^\\s*$",
|
|
|
|
next : "start"
|
|
|
|
}, {
|
|
|
|
defaultToken : "string"
|
2014-07-09 12:59:04 -04:00
|
|
|
}]
|
2014-08-19 16:33:09 -04:00
|
|
|
|
2014-07-09 12:59:04 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
oop.inherits(LatexHighlightRules, TextHighlightRules);
|
|
|
|
|
|
|
|
exports.LatexHighlightRules = LatexHighlightRules;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2014-07-16 06:07:18 -04:00
|
|
|
ace.define("ace/mode/folding/latex",["require","exports","module","ace/lib/oop","ace/mode/folding/fold_mode","ace/range","ace/token_iterator"], function(require, exports, module) {
|
2014-02-12 05:23:40 -05:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var oop = require("../../lib/oop");
|
|
|
|
var BaseFoldMode = require("./fold_mode").FoldMode;
|
|
|
|
var Range = require("../../range").Range;
|
|
|
|
var TokenIterator = require("../../token_iterator").TokenIterator;
|
|
|
|
|
|
|
|
var FoldMode = exports.FoldMode = function() {};
|
|
|
|
|
|
|
|
oop.inherits(FoldMode, BaseFoldMode);
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
2014-08-19 16:33:09 -04:00
|
|
|
this.foldingStartMarker = /^\s*\\(begin)|(section|subsection|paragraph)\b|{\s*$/;
|
2014-02-12 05:23:40 -05:00
|
|
|
this.foldingStopMarker = /^\s*\\(end)\b|^\s*}/;
|
|
|
|
|
|
|
|
this.getFoldWidgetRange = function(session, foldStyle, row) {
|
|
|
|
var line = session.doc.getLine(row);
|
|
|
|
var match = this.foldingStartMarker.exec(line);
|
|
|
|
if (match) {
|
|
|
|
if (match[1])
|
|
|
|
return this.latexBlock(session, row, match[0].length - 1);
|
|
|
|
if (match[2])
|
|
|
|
return this.latexSection(session, row, match[0].length - 1);
|
|
|
|
|
|
|
|
return this.openingBracketBlock(session, "{", row, match.index);
|
|
|
|
}
|
|
|
|
|
|
|
|
var match = this.foldingStopMarker.exec(line);
|
|
|
|
if (match) {
|
|
|
|
if (match[1])
|
|
|
|
return this.latexBlock(session, row, match[0].length - 1);
|
|
|
|
|
|
|
|
return this.closingBracketBlock(session, "}", row, match.index + match[0].length);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.latexBlock = function(session, row, column) {
|
|
|
|
var keywords = {
|
|
|
|
"\\begin": 1,
|
|
|
|
"\\end": -1
|
|
|
|
};
|
|
|
|
|
|
|
|
var stream = new TokenIterator(session, row, column);
|
|
|
|
var token = stream.getCurrentToken();
|
2014-08-19 16:33:09 -04:00
|
|
|
if (!token || !(token.type == "storage.type" || token.type == "constant.character.escape"))
|
2014-02-12 05:23:40 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
var val = token.value;
|
|
|
|
var dir = keywords[val];
|
|
|
|
|
|
|
|
var getType = function() {
|
|
|
|
var token = stream.stepForward();
|
|
|
|
var type = token.type == "lparen" ?stream.stepForward().value : "";
|
|
|
|
if (dir === -1) {
|
|
|
|
stream.stepBackward();
|
|
|
|
if (type)
|
|
|
|
stream.stepBackward();
|
|
|
|
}
|
|
|
|
return type;
|
|
|
|
};
|
|
|
|
var stack = [getType()];
|
|
|
|
var startColumn = dir === -1 ? stream.getCurrentTokenColumn() : session.getLine(row).length;
|
|
|
|
var startRow = row;
|
|
|
|
|
|
|
|
stream.step = dir === -1 ? stream.stepBackward : stream.stepForward;
|
|
|
|
while(token = stream.step()) {
|
2014-08-19 16:33:09 -04:00
|
|
|
if (!token || !(token.type == "storage.type" || token.type == "constant.character.escape"))
|
2014-02-12 05:23:40 -05:00
|
|
|
continue;
|
|
|
|
var level = keywords[token.value];
|
|
|
|
if (!level)
|
|
|
|
continue;
|
|
|
|
var type = getType();
|
|
|
|
if (level === dir)
|
|
|
|
stack.unshift(type);
|
|
|
|
else if (stack.shift() !== type || !stack.length)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stack.length)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var row = stream.getCurrentTokenRow();
|
|
|
|
if (dir === -1)
|
|
|
|
return new Range(row, session.getLine(row).length, startRow, startColumn);
|
|
|
|
stream.stepBackward();
|
|
|
|
return new Range(startRow, startColumn, row, stream.getCurrentTokenColumn());
|
|
|
|
};
|
|
|
|
|
|
|
|
this.latexSection = function(session, row, column) {
|
2014-08-19 16:33:09 -04:00
|
|
|
var keywords = ["\\subsection", "\\section", "\\begin", "\\end", "\\paragraph"];
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
var stream = new TokenIterator(session, row, column);
|
|
|
|
var token = stream.getCurrentToken();
|
2014-08-19 16:33:09 -04:00
|
|
|
if (!token || token.type != "storage.type")
|
2014-02-12 05:23:40 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
var startLevel = keywords.indexOf(token.value);
|
|
|
|
var stackDepth = 0
|
|
|
|
var endRow = row;
|
|
|
|
|
|
|
|
while(token = stream.stepForward()) {
|
2014-08-19 16:33:09 -04:00
|
|
|
if (token.type !== "storage.type")
|
2014-02-12 05:23:40 -05:00
|
|
|
continue;
|
|
|
|
var level = keywords.indexOf(token.value);
|
|
|
|
|
|
|
|
if (level >= 2) {
|
|
|
|
if (!stackDepth)
|
|
|
|
endRow = stream.getCurrentTokenRow() - 1;
|
|
|
|
stackDepth += level == 2 ? 1 : - 1;
|
|
|
|
if (stackDepth < 0)
|
|
|
|
break
|
|
|
|
} else if (level >= startLevel)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!stackDepth)
|
|
|
|
endRow = stream.getCurrentTokenRow() - 1;
|
|
|
|
|
|
|
|
while (endRow > row && !/\S/.test(session.getLine(endRow)))
|
|
|
|
endRow--;
|
|
|
|
|
|
|
|
return new Range(
|
|
|
|
row, session.getLine(row).length,
|
|
|
|
endRow, session.getLine(endRow).length
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
}).call(FoldMode.prototype);
|
|
|
|
|
|
|
|
});
|
2014-07-09 12:59:04 -04:00
|
|
|
|
2016-09-14 10:17:50 -04:00
|
|
|
ace.define("ace/mode/latex",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/latex_highlight_rules","ace/mode/folding/latex","ace/range","ace/worker/worker_client"], function(require, exports, module) {
|
2014-07-09 12:59:04 -04:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var oop = require("../lib/oop");
|
|
|
|
var TextMode = require("./text").Mode;
|
|
|
|
var LatexHighlightRules = require("./latex_highlight_rules").LatexHighlightRules;
|
|
|
|
var LatexFoldMode = require("./folding/latex").FoldMode;
|
|
|
|
var Range = require("../range").Range;
|
2016-09-14 10:17:50 -04:00
|
|
|
var WorkerClient = require("ace/worker/worker_client").WorkerClient;
|
2014-07-09 12:59:04 -04:00
|
|
|
|
2016-09-14 10:17:50 -04:00
|
|
|
|
2014-07-09 12:59:04 -04:00
|
|
|
var Mode = function() {
|
|
|
|
this.HighlightRules = LatexHighlightRules;
|
|
|
|
this.foldingRules = new LatexFoldMode();
|
2016-09-14 10:17:50 -04:00
|
|
|
this.createWorker = function(session) {
|
|
|
|
var worker = new WorkerClient(["ace"], "ace/mode/latex_worker", "LatexWorker");
|
|
|
|
var savedRange = {};
|
|
|
|
|
|
|
|
worker.attachToDocument(session.getDocument());
|
|
|
|
|
|
|
|
worker.on("lint", function(results) {
|
|
|
|
var newRange = {};
|
|
|
|
for (var i = 0; i<results.data.length; i++) {
|
|
|
|
var start_row = results.data[i].start_row;
|
|
|
|
var end_row = results.data[i].end_row;
|
|
|
|
var key = start_row + ":" + end_row;
|
|
|
|
newRange[key] = results.data[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
var newKeys = Object.keys(newRange);
|
|
|
|
var oldKeys = Object.keys(savedRange);
|
|
|
|
|
|
|
|
for (i = 0; i < newKeys.length; i++) {
|
|
|
|
key = newKeys[i];
|
|
|
|
if (!savedRange[key]) {
|
|
|
|
var new_range = newRange[key];
|
|
|
|
var range = new Range(new_range.start_row, 0, new_range.end_row, Infinity);
|
|
|
|
range.id = session.addMarker(range, "ace_error-marker", "fullLine");
|
|
|
|
savedRange[key] = range;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < oldKeys.length; i++) {
|
|
|
|
key = oldKeys[i];
|
|
|
|
if (!newRange[key]) {
|
|
|
|
range = savedRange[key];
|
|
|
|
session.removeMarker(range.id);
|
|
|
|
delete savedRange[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
worker.on("terminate", function() {
|
|
|
|
var oldKeys = Object.keys(savedRange);
|
|
|
|
for (var i = 0; i < oldKeys.length; i++) {
|
|
|
|
var key = oldKeys[i];
|
|
|
|
var range = savedRange[key];
|
|
|
|
session.removeMarker(range.id);
|
|
|
|
delete savedRange[key];
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
return worker;
|
|
|
|
};
|
2014-07-09 12:59:04 -04:00
|
|
|
};
|
|
|
|
oop.inherits(Mode, TextMode);
|
|
|
|
|
|
|
|
(function() {
|
2014-07-28 05:40:35 -04:00
|
|
|
this.type = "text";
|
2014-08-19 16:33:09 -04:00
|
|
|
|
2014-07-09 12:59:04 -04:00
|
|
|
this.lineCommentStart = "%";
|
|
|
|
|
|
|
|
this.$id = "ace/mode/latex";
|
|
|
|
}).call(Mode.prototype);
|
|
|
|
|
|
|
|
exports.Mode = Mode;
|
|
|
|
|
|
|
|
});
|