latex_highlight_rules.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. define(function(require, exports, module) {
  2. "use strict";
  3. var oop = require("../lib/oop");
  4. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  5. var LatexHighlightRules = function() {
  6. this.$rules = {
  7. "start" : [{
  8. // A comment. Tex comments start with % and go to
  9. // the end of the line
  10. token : "comment",
  11. regex : "%.*$"
  12. }, {
  13. // Documentclass and usepackage
  14. token : ["keyword", "lparen", "variable.parameter", "rparen", "lparen", "storage.type", "rparen"],
  15. regex : "(\\\\(?:documentclass|usepackage|input))(?:(\\[)([^\\]]*)(\\]))?({)([^}]*)(})"
  16. }, {
  17. // A label
  18. token : ["keyword","lparen", "variable.parameter", "rparen"],
  19. regex : "(\\\\(?:label|v?ref|cite(?:[^{]*)))(?:({)([^}]*)(}))?"
  20. }, {
  21. // A block
  22. token : ["storage.type", "lparen", "variable.parameter", "rparen"],
  23. regex : "(\\\\(?:begin|end))({)(\\w*)(})"
  24. }, {
  25. // A tex command e.g. \foo
  26. token : "storage.type",
  27. regex : "\\\\[a-zA-Z]+"
  28. }, {
  29. // Curly and square braces
  30. token : "lparen",
  31. regex : "[[({]"
  32. }, {
  33. // Curly and square braces
  34. token : "rparen",
  35. regex : "[\\])}]"
  36. }, {
  37. // Escaped character (including new line)
  38. token : "constant.character.escape",
  39. regex : "\\\\[^a-zA-Z]?"
  40. }, {
  41. // An equation
  42. token : "string",
  43. regex : "\\${1,2}",
  44. next : "equation"
  45. }],
  46. "equation" : [{
  47. token : "comment",
  48. regex : "%.*$"
  49. }, {
  50. token : "string",
  51. regex : "\\${1,2}",
  52. next : "start"
  53. }, {
  54. token : "constant.character.escape",
  55. regex : "\\\\(?:[^a-zA-Z]|[a-zA-Z]+)"
  56. }, {
  57. token : "error",
  58. regex : "^\\s*$",
  59. next : "start"
  60. }, {
  61. defaultToken : "string"
  62. }]
  63. };
  64. };
  65. oop.inherits(LatexHighlightRules, TextHighlightRules);
  66. exports.LatexHighlightRules = LatexHighlightRules;
  67. });