lang-tex.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright (C) 2011 Martin S.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview
  16. * Support for tex highlighting as discussed on
  17. * <a href="http://meta.tex.stackexchange.com/questions/872/text-immediate-following-double-backslashes-is-highlighted-as-macro-inside-a-code/876#876">meta.tex.stackexchange.com</a>.
  18. *
  19. * @author Martin S.
  20. */
  21. PR.registerLangHandler(
  22. PR.createSimpleLexer(
  23. [
  24. // whitespace
  25. [PR.PR_PLAIN, /^[\t\n\r \xA0]+/, null, '\t\n\r \xA0'],
  26. // all comments begin with '%'
  27. [PR.PR_COMMENT, /^%[^\r\n]*/, null, '%']
  28. ],
  29. [
  30. //[PR.PR_DECLARATION, /^\\([egx]?def|(new|renew|provide)(command|environment))\b/],
  31. // any command starting with a \ and contains
  32. // either only letters (a-z,A-Z), '@' (internal macros)
  33. [PR.PR_KEYWORD, /^\\[a-zA-Z@]+/],
  34. // or contains only one character
  35. [PR.PR_KEYWORD, /^\\./],
  36. // Highlight dollar for math mode and ampersam for tabular
  37. [PR.PR_TYPE, /^[$&]/],
  38. // numeric measurement values with attached units
  39. [PR.PR_LITERAL,
  40. /[+-]?(?:\.\d+|\d+(?:\.\d*)?)(cm|em|ex|in|pc|pt|bp|mm)/i],
  41. // punctuation usually occurring within commands
  42. [PR.PR_PUNCTUATION, /^[{}()\[\]=]+/]
  43. ]),
  44. ['latex', 'tex']);