1
define('ace/mode/latex', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/latex_highlight_rules', 'ace/mode/folding/latex', 'ace/range'], function(require, exports, module) {
4
var oop = require("../lib/oop");
5
var TextMode = require("./text").Mode;
6
var Tokenizer = require("../tokenizer").Tokenizer;
7
var LatexHighlightRules = require("./latex_highlight_rules").LatexHighlightRules;
8
var LatexFoldMode = require("./folding/latex").FoldMode;
9
var Range = require("../range").Range;
11
var Mode = function() {
12
this.$tokenizer = new Tokenizer(new LatexHighlightRules().getRules());
13
this.foldingRules = new LatexFoldMode();
15
oop.inherits(Mode, TextMode);
18
this.lineCommentStart = "%";
20
}).call(Mode.prototype);
25
define('ace/mode/latex_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
28
var oop = require("../lib/oop");
29
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
31
var LatexHighlightRules = function() {
35
regex : "\\\\(?:[^a-zA-Z]|[a-zA-Z]+)"
44
regex : "\\$(?:(?:\\\\.)|(?:[^\\$\\\\]))*?\\$"
52
oop.inherits(LatexHighlightRules, TextHighlightRules);
54
exports.LatexHighlightRules = LatexHighlightRules;
58
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) {
61
var oop = require("../../lib/oop");
62
var BaseFoldMode = require("./fold_mode").FoldMode;
63
var Range = require("../../range").Range;
64
var TokenIterator = require("../../token_iterator").TokenIterator;
66
var FoldMode = exports.FoldMode = function() {};
68
oop.inherits(FoldMode, BaseFoldMode);
72
this.foldingStartMarker = /^\s*\\(begin)|(section|subsection)\b|{\s*$/;
73
this.foldingStopMarker = /^\s*\\(end)\b|^\s*}/;
75
this.getFoldWidgetRange = function(session, foldStyle, row) {
76
var line = session.doc.getLine(row);
77
var match = this.foldingStartMarker.exec(line);
80
return this.latexBlock(session, row, match[0].length - 1);
82
return this.latexSection(session, row, match[0].length - 1);
84
return this.openingBracketBlock(session, "{", row, match.index);
87
var match = this.foldingStopMarker.exec(line);
90
return this.latexBlock(session, row, match[0].length - 1);
92
return this.closingBracketBlock(session, "}", row, match.index + match[0].length);
96
this.latexBlock = function(session, row, column) {
102
var stream = new TokenIterator(session, row, column);
103
var token = stream.getCurrentToken();
104
if (!token || token.type !== "keyword")
107
var val = token.value;
108
var dir = keywords[val];
110
var getType = function() {
111
var token = stream.stepForward();
112
var type = token.type == "lparen" ?stream.stepForward().value : "";
114
stream.stepBackward();
116
stream.stepBackward();
120
var stack = [getType()];
121
var startColumn = dir === -1 ? stream.getCurrentTokenColumn() : session.getLine(row).length;
124
stream.step = dir === -1 ? stream.stepBackward : stream.stepForward;
125
while(token = stream.step()) {
126
if (token.type !== "keyword")
128
var level = keywords[token.value];
131
var type = getType();
134
else if (stack.shift() !== type || !stack.length)
141
var row = stream.getCurrentTokenRow();
143
return new Range(row, session.getLine(row).length, startRow, startColumn);
144
stream.stepBackward();
145
return new Range(startRow, startColumn, row, stream.getCurrentTokenColumn());
148
this.latexSection = function(session, row, column) {
149
var keywords = ["\\subsection", "\\section", "\\begin", "\\end"];
151
var stream = new TokenIterator(session, row, column);
152
var token = stream.getCurrentToken();
153
if (!token || token.type != "keyword")
156
var startLevel = keywords.indexOf(token.value);
160
while(token = stream.stepForward()) {
161
if (token.type !== "keyword")
163
var level = keywords.indexOf(token.value);
167
endRow = stream.getCurrentTokenRow() - 1;
168
stackDepth += level == 2 ? 1 : - 1;
171
} else if (level >= startLevel)
176
endRow = stream.getCurrentTokenRow() - 1;
178
while (endRow > row && !/\S/.test(session.getLine(endRow)))
182
row, session.getLine(row).length,
183
endRow, session.getLine(endRow).length
187
}).call(FoldMode.prototype);