From 9fb80fb72cced8cb20ab5c7384c63494bf3a3171 Mon Sep 17 00:00:00 2001 From: Daniel Felder Date: Mon, 11 Aug 2014 09:13:50 +0000 Subject: [PATCH] simplifications and different highlight for labels etc. --- lib/ace/mode/latex_highlight_rules.js | 41 ++++++++++++--------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/lib/ace/mode/latex_highlight_rules.js b/lib/ace/mode/latex_highlight_rules.js index 19d7e83a..06db18d8 100644 --- a/lib/ace/mode/latex_highlight_rules.js +++ b/lib/ace/mode/latex_highlight_rules.js @@ -8,21 +8,26 @@ var LatexHighlightRules = function() { this.$rules = { "start" : [{ - token : "keyword", - regex : "\\\\(documentclass|usepackage|label)" + // A comment. Tex comments start with % and go to + // the end of the line + token : "comment", + regex : "%.*$" },{ - // Escaped character (including new line) - token : "constant.character.escape", - regex : "\\\\[^a-zA-Z]" + // Documentclass and usepackage + token : ["keyword","lparen","variable.parameter","rparen", "lparen","storage.type","rparen"], + regex : "(\\\\(?:documentclass|usepackage))(?:(\\[)([^\\]]*)(\\]))?({)(\\w*)(})" + },{ + // A label + token : ["keyword","lparen","variable.parameter","rparen"], + regex : "(\\\\label)(?:({)([^}]*)(}))?" },{ // A block - token : "storage.type", - regex : "\\\\(:?begin|end)", - next : "block" + token : ["storage.type", "lparen","variable.parameter","rparen"], + regex : "(\\\\(?:begin|end))({)(\\w*)(})" },{ // A tex command e.g. \foo token : "storage.type", - regex : "\\\\[a-zA-Z\\d]+" + regex : "\\\\[a-zA-Z]+" }, { // Curly and square braces token : "lparen", @@ -31,26 +36,16 @@ var LatexHighlightRules = function() { // Curly and square braces token : "rparen", regex : "[\\])}]" - }, { - // A comment. Tex comments start with % and go to - // the end of the line - token : "comment", - regex : "%.*$" + },{ + // Escaped character (including new line) + token : "constant.character.escape", + regex : "\\\\[^a-zA-Z]?" },{ // An equation token : "string", regex : "\\${1,2}", next : "equation" }], - "block" : [{ - token : ["lparen","variable.parameter","rparen"], - regex : "({)([^}\\s]*)(}?)", - next : "start" - },{ - token : "", - regex : "", - next : "start" - }], "equation" : [{ token : "string", regex : "\\${1,2}",