text: // CodeMirror, copyright (c) by Marijn Haverbeke and others
  // Distributed under an MIT license: http://codemirror.net/LICENSE
  
  /*
   * Author: Constantin Jucovschi (c.jucovschi@jacobs-university.de)
   * Licence: MIT
   */
  
  (function(mod) {
    if (typeof exports == "object" && typeof module == "object") // CommonJS
      mod(require("../../lib/codemirror"));
    else if (typeof define == "function" && define.amd) // AMD
      define(["../../lib/codemirror"], mod);
    else // Plain browser env
      mod(CodeMirror);
  })(function(CodeMirror) {
    "use strict";
  
    CodeMirror.defineMode("tex-mathmode", function() {
      "use strict";
  
      function setState(state, f) {
        state.f = f;
      }
  
      // we math mode only
      function normal(source, state) {
        if (source.eatSpace()) {
          return null;
        }
        if (source.match(/^\\[a-zA-Z@]+/)) {
          return "tag";
        }
        if (source.match(/^[a-zA-Z]+/)) {
          return null;
        }
        // escape characters
        if (source.match(/^\\[$&%#{}_]/)) {
          return "tag";
        }
        // white space control characters
        if (source.match(/^\\[,;!\/]/)) {
          return "tag";
        }
        // special math-mode characters
        if (source.match(/^[\^_&]/)) {
          return "tag";
        }
        // non-special characters
        if (source.match(/^[+\-<>|=,\/@!*:;'"`~#?]/)) {
          return null;
        }
        if (source.match(/^(\d+\.\d*|\d*\.\d+|\d+)/)) {
          return "number";
        }
        var ch = source.next();
        if (ch == "{" || ch == "}" || ch == "[" || ch == "]" || ch == "(" || ch == ")") {
          return "bracket";
        }
  
        if (ch == "%") {
          source.skipToEnd();
          return "comment";
        }
        return "error";
      }
  
      return {
        startState: function() {
          return {
            cmdState: [],
            f: normal
          };
        },
        copyState: function(s) {
          return {
            cmdState: s.cmdState.slice(),
            f: s.f
          };
        },
        token: function(stream, state) {
          return state.f(stream, state);
        },
        blankLine: function(state) {
          state.f = normal;
          state.cmdState.length = 0;
        },
        lineComment: "%"
      };
    });
  
    CodeMirror.defineMIME("text/inline-math", "tex-mathmode");
  
  });
  