diff --git a/lib/ace/mode/_test/tokens_latex.json b/lib/ace/mode/_test/tokens_latex.json index 0ac37725..4ae69afa 100644 --- a/lib/ace/mode/_test/tokens_latex.json +++ b/lib/ace/mode/_test/tokens_latex.json @@ -2,37 +2,37 @@ "start", ["keyword","\\usepackage"], ["lparen","{"], - ["text","amsmath"], + ["storage.type","amsmath"], ["rparen","}"] ],[ "start", - ["keyword","\\title"], + ["storage.type","\\title"], ["lparen","{"], - ["keyword","\\LaTeX"], + ["storage.type","\\LaTeX"], ["rparen","}"] ],[ "start", - ["keyword","\\date"], + ["storage.type","\\date"], ["lparen","{"], ["rparen","}"] ],[ "start", - ["keyword","\\begin"], + ["storage.type","\\begin"], ["lparen","{"], - ["text","document"], + ["variable.parameter","document"], ["rparen","}"] ],[ "start", ["text"," "], - ["keyword","\\maketitle"] + ["storage.type","\\maketitle"] ],[ "start", ["text"," "], - ["keyword","\\LaTeX"], + ["storage.type","\\LaTeX"], ["lparen","{"], ["rparen","}"], ["text"," is a document preparation system for the "], - ["keyword","\\TeX"], + ["storage.type","\\TeX"], ["lparen","{"], ["rparen","}"] ],[ @@ -50,26 +50,26 @@ ],[ "start", ["text"," and much more. "], - ["keyword","\\LaTeX"], + ["storage.type","\\LaTeX"], ["lparen","{"], ["rparen","}"], ["text"," was originally written in 1984 by Leslie"] ],[ "start", ["text"," Lamport and has become the dominant method for using "], - ["keyword","\\TeX"], + ["storage.type","\\TeX"], ["text","; few"] ],[ "start", ["text"," people write in plain "], - ["keyword","\\TeX"], + ["storage.type","\\TeX"], ["lparen","{"], ["rparen","}"], ["text"," anymore. The current version is"] ],[ "start", ["text"," "], - ["keyword","\\LaTeXe"], + ["storage.type","\\LaTeXe"], ["text","."] ],[ "start", @@ -85,26 +85,24 @@ ],[ "start", ["text"," "], - ["keyword","\\begin"], + ["storage.type","\\begin"], ["lparen","{"], - ["text","align"], + ["variable.parameter","align"], ["rparen","}"] ],[ "start", ["text"," E &= mc^2 "], - ["keyword","\\\\"] -],[ - "start", + ["constant.character.escape","\\\\"], ["text"," m &= "], - ["keyword","\\frac"], + ["storage.type","\\frac"], ["lparen","{"], ["text","m_0"], ["rparen","}"], ["lparen","{"], - ["keyword","\\sqrt"], + ["storage.type","\\sqrt"], ["lparen","{"], ["text","1-"], - ["keyword","\\frac"], + ["storage.type","\\frac"], ["lparen","{"], ["text","v^2"], ["rparen","}"], @@ -114,14 +112,14 @@ ],[ "start", ["text"," "], - ["keyword","\\end"], + ["storage.type","\\end"], ["lparen","{"], - ["text","align"], + ["variable.parameter","align"], ["rparen","}"] ],[ "start", - ["keyword","\\end"], + ["storage.type","\\end"], ["lparen","{"], - ["text","document"], + ["variable.parameter","document"], ["rparen","}"] ]] \ No newline at end of file diff --git a/lib/ace/mode/folding/latex.js b/lib/ace/mode/folding/latex.js index b80775eb..6f20b22e 100644 --- a/lib/ace/mode/folding/latex.js +++ b/lib/ace/mode/folding/latex.js @@ -42,7 +42,7 @@ oop.inherits(FoldMode, BaseFoldMode); (function() { - this.foldingStartMarker = /^\s*\\(begin)|(section|subsection)\b|{\s*$/; + this.foldingStartMarker = /^\s*\\(begin)|(section|subsection|paragraph)\b|{\s*$/; this.foldingStopMarker = /^\s*\\(end)\b|^\s*}/; this.getFoldWidgetRange = function(session, foldStyle, row) { @@ -74,7 +74,7 @@ oop.inherits(FoldMode, BaseFoldMode); var stream = new TokenIterator(session, row, column); var token = stream.getCurrentToken(); - if (!token || token.type !== "keyword") + if (!token || !(token.type == "storage.type" || token.type == "constant.character.escape")) return; var val = token.value; @@ -96,7 +96,7 @@ oop.inherits(FoldMode, BaseFoldMode); stream.step = dir === -1 ? stream.stepBackward : stream.stepForward; while(token = stream.step()) { - if (token.type !== "keyword") + if (!token || !(token.type == "storage.type" || token.type == "constant.character.escape")) continue; var level = keywords[token.value]; if (!level) @@ -119,11 +119,11 @@ oop.inherits(FoldMode, BaseFoldMode); }; this.latexSection = function(session, row, column) { - var keywords = ["\\subsection", "\\section", "\\begin", "\\end"]; + var keywords = ["\\subsection", "\\section", "\\begin", "\\end", "\\paragraph"]; var stream = new TokenIterator(session, row, column); var token = stream.getCurrentToken(); - if (!token || token.type != "keyword") + if (!token || token.type != "storage.type") return; var startLevel = keywords.indexOf(token.value); @@ -131,7 +131,7 @@ oop.inherits(FoldMode, BaseFoldMode); var endRow = row; while(token = stream.stepForward()) { - if (token.type !== "keyword") + if (token.type !== "storage.type") continue; var level = keywords.indexOf(token.value); diff --git a/lib/ace/mode/latex_highlight_rules.js b/lib/ace/mode/latex_highlight_rules.js index 3057c0de..f3238bfb 100644 --- a/lib/ace/mode/latex_highlight_rules.js +++ b/lib/ace/mode/latex_highlight_rules.js @@ -4,12 +4,30 @@ define(function(require, exports, module) { var oop = require("../lib/oop"); var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; -var LatexHighlightRules = function() { +var LatexHighlightRules = function() { + this.$rules = { "start" : [{ + // A comment. Tex comments start with % and go to + // the end of the line + token : "comment", + regex : "%.*$" + }, { + // Documentclass and usepackage + token : ["keyword", "lparen", "variable.parameter", "rparen", "lparen", "storage.type", "rparen"], + regex : "(\\\\(?:documentclass|usepackage|input))(?:(\\[)([^\\]]*)(\\]))?({)([^}]*)(})" + }, { + // A label + token : ["keyword","lparen", "variable.parameter", "rparen"], + regex : "(\\\\label)(?:({)([^}]*)(}))?" + }, { + // A block + token : ["storage.type", "lparen", "variable.parameter", "rparen"], + regex : "(\\\\(?:begin|end))({)(\\w*)(})" + }, { // A tex command e.g. \foo - token : "keyword", - regex : "\\\\(?:[^a-zA-Z]|[a-zA-Z]+)" + token : "storage.type", + regex : "\\\\[a-zA-Z]+" }, { // Curly and square braces token : "lparen", @@ -19,18 +37,35 @@ var LatexHighlightRules = function() { token : "rparen", regex : "[\\])}]" }, { - // Inline math between two $ symbols - token : "string", - regex : "\\$(?:(?:\\\\.)|(?:[^\\$\\\\]))*?\\$" + // Escaped character (including new line) + token : "constant.character.escape", + regex : "\\\\[^a-zA-Z]?" }, { - // A comment. Tex comments start with % and go to - // the end of the line + // An equation + token : "string", + regex : "\\${1,2}", + next : "equation" + }], + "equation" : [{ token : "comment", regex : "%.*$" + }, { + 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" }] + }; }; - oop.inherits(LatexHighlightRules, TextHighlightRules); exports.LatexHighlightRules = LatexHighlightRules;