prism-latex.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. (function (Prism) {
  2. var funcPattern = /\\(?:[^a-z()[\]]|[a-z*]+)/i;
  3. var insideEqu = {
  4. 'equation-command': {
  5. pattern: funcPattern,
  6. alias: 'regex'
  7. }
  8. };
  9. Prism.languages.latex = {
  10. 'comment': /%.*/,
  11. // the verbatim environment prints whitespace to the document
  12. 'cdata': {
  13. pattern: /(\\begin\{((?:lstlisting|verbatim)\*?)\})[\s\S]*?(?=\\end\{\2\})/,
  14. lookbehind: true
  15. },
  16. /*
  17. * equations can be between $$ $$ or $ $ or \( \) or \[ \]
  18. * (all are multiline)
  19. */
  20. 'equation': [
  21. {
  22. pattern: /\$\$(?:\\[\s\S]|[^\\$])+\$\$|\$(?:\\[\s\S]|[^\\$])+\$|\\\([\s\S]*?\\\)|\\\[[\s\S]*?\\\]/,
  23. inside: insideEqu,
  24. alias: 'string'
  25. },
  26. {
  27. pattern: /(\\begin\{((?:align|eqnarray|equation|gather|math|multline)\*?)\})[\s\S]*?(?=\\end\{\2\})/,
  28. lookbehind: true,
  29. inside: insideEqu,
  30. alias: 'string'
  31. }
  32. ],
  33. /*
  34. * arguments which are keywords or references are highlighted
  35. * as keywords
  36. */
  37. 'keyword': {
  38. pattern: /(\\(?:begin|cite|documentclass|end|label|ref|usepackage)(?:\[[^\]]+\])?\{)[^}]+(?=\})/,
  39. lookbehind: true
  40. },
  41. 'url': {
  42. pattern: /(\\url\{)[^}]+(?=\})/,
  43. lookbehind: true
  44. },
  45. /*
  46. * section or chapter headlines are highlighted as bold so that
  47. * they stand out more
  48. */
  49. 'headline': {
  50. pattern: /(\\(?:chapter|frametitle|paragraph|part|section|subparagraph|subsection|subsubparagraph|subsubsection|subsubsubparagraph)\*?(?:\[[^\]]+\])?\{)[^}]+(?=\})/,
  51. lookbehind: true,
  52. alias: 'class-name'
  53. },
  54. 'function': {
  55. pattern: funcPattern,
  56. alias: 'selector'
  57. },
  58. 'punctuation': /[[\]{}&]/
  59. };
  60. Prism.languages.tex = Prism.languages.latex;
  61. Prism.languages.context = Prism.languages.latex;
  62. }(Prism));