define('app/ace/mode/latex', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/latex_highlight_rules', 'ace/range'], function(require, exports, module) {
"use strict";

debugger;

var oop = require("../.././lib/oop");
var TextMode = require("../.././mode/text").Mode;
var Tokenizer = require("../.././tokenizer").Tokenizer;
var LatexHighlightRules = require("../.././mode/latex_highlight_rules").LatexHighlightRules;
var Range = require("../.././range").Range;
var WorkerClient = require("./worker_client").WorkerClient;

var Mode = function()
{
    this.$tokenizer = new Tokenizer(new LatexHighlightRules().getRules());
};
oop.inherits(Mode, TextMode);

(function() {
    this.toggleCommentLines = function(state, doc, startRow, endRow) {
        // This code is adapted from ruby.js
        var outdent = true;

        // LaTeX comments begin with % and go to the end of the line
        var commentRegEx = /^(\s*)\%/;

        for (var i = startRow; i <= endRow; i++) {
            if (!commentRegEx.test(doc.getLine(i))) {
                outdent = false;
                break;
            }
        }

        if (outdent) {
            var deleteRange = new Range(0, 0, 0, 0);
            for (var i = startRow; i <= endRow; i++) {
                var line = doc.getLine(i);
                var m = line.match(commentRegEx);
                deleteRange.start.row = i;
                deleteRange.end.row = i;
                deleteRange.end.column = m[0].length;
                doc.replace(deleteRange, m[1]);
            }
        }
        else {
            doc.indentRows(startRow, endRow, "%");
        }
    };

    // There is no universally accepted way of indenting a tex document
    // so just maintain the indentation of the previous line
    this.getNextLineIndent = function(state, line, tab) {
        return this.$getIndent(line);
    };

    this.createWorker = function(session) {
        debugger;
        var worker = new WorkerClient(["ace"], "./latex_worker", "LatexWorker");
            worker.attachToDocument(session.getDocument());

            worker.on("outline", function(e) {
                session._emit("outline", e.data);
            });

            return worker;
        };

}).call(Mode.prototype);

exports.Mode = Mode;

});
define('ace/mode/latex_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
"use strict";

var oop = require("../lib/oop");
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;

var LatexHighlightRules = function() {
    this.$rules = {
        "start": [{
            token : "comment",
            merge : true,
            regex : "\\\\begin{comment}",
            next : "comment"
        }, {
            // A tex command e.g. \foo
            token : "keyword",
            regex : "\\\\(?:[^a-zA-Z]|[a-zA-Z]+)",
        }, {
            // Curly and square braces
            token : "lparen",
            regex : "[[({]"
        }, {
            // Curly and square braces
            token : "rparen",
            regex : "[\\])}]"
        }, {
            // Inline math between two $ symbols
            token : "string",
            regex : "\\$(?:(?:\\\\.)|(?:[^\\$\\\\]))*?\\$"
        }, {
            // A comment. Tex comments start with % and go to
            // the end of the line
            token : "comment",
            regex : "%.*$"
        }],
        "comment" : [{
            token : "comment", // closing comment
            regex : ".*?\\\\end{comment}",
            merge : true,
            next : "start"
        }, {
            token : "comment", // comment spanning whole line
            merge : true,
            regex : ".+"
        }]
    };
};

oop.inherits(LatexHighlightRules, TextHighlightRules);

exports.LatexHighlightRules = LatexHighlightRules;


});
;
            (function() {
                window.require(["ace/ace"], function(a) {
                    if (!window.ace)
                        window.ace = {};
                    for (var key in a) if (a.hasOwnProperty(key))
                        ace[key] = a[key];
                });
            })();
        