latex.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. require(['libs/google-code-prettify/prettify'], function($) {
  22. PR['registerLangHandler'](
  23. PR['createSimpleLexer'](
  24. [
  25. // whitespace
  26. [PR['PR_PLAIN'], /^[\t\n\r \xA0]+/, null, '\t\n\r \xA0'],
  27. // all comments begin with '%'
  28. [PR['PR_COMMENT'], /^%[^\r\n]*/, null, '%']
  29. ],
  30. [
  31. //[PR['PR_DECLARATION'], /^\\([egx]?def|(new|renew|provide)(command|environment))\b/],
  32. // any command starting with a \ and contains
  33. // either only letters (a-z,A-Z), '@' (internal macros)
  34. [PR['PR_KEYWORD'], /^\\[a-zA-Z@]+/],
  35. // or contains only one character
  36. [PR['PR_KEYWORD'], /^\\./],
  37. // Highlight dollar for math mode and ampersam for tabular
  38. [PR['PR_TYPE'], /^[$&]/],
  39. // numeric measurement values with attached units
  40. [PR['PR_LITERAL'],
  41. /[+-]?(?:\.\d+|\d+(?:\.\d*)?)(cm|em|ex|in|pc|pt|bp|mm)/i],
  42. // punctuation usually occurring within commands
  43. [PR['PR_PUNCTUATION'], /^[{}()\[\]=]+/]
  44. ]),
  45. ['latex', 'tex']);
  46. })