tex.vim 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353
  1. " Vim syntax file
  2. " Language: TeX
  3. " Maintainer: Charles E. Campbell <NcampObell@SdrPchip.AorgM-NOSPAM>
  4. " Last Change: Apr 22, 2022
  5. " Version: 121
  6. " URL: http://www.drchip.org/astronaut/vim/index.html#SYNTAX_TEX
  7. "
  8. " Notes: {{{1
  9. "
  10. " 1. If you have a \begin{verbatim} that appears to overrun its boundaries,
  11. " use %stopzone.
  12. "
  13. " 2. Run-on equations ($..$ and $$..$$, particularly) can also be stopped
  14. " by suitable use of %stopzone.
  15. "
  16. " 3. If you have a slow computer, you may wish to modify
  17. "
  18. " syn sync maxlines=200
  19. " syn sync minlines=50
  20. "
  21. " to values that are more to your liking.
  22. "
  23. " 4. There is no match-syncing for $...$ and $$...$$; hence large
  24. " equation blocks constructed that way may exhibit syncing problems.
  25. " (there's no difference between begin/end patterns)
  26. "
  27. " 5. If you have the variable "g:tex_no_error" defined then none of the
  28. " lexical error-checking will be done.
  29. "
  30. " ie. let g:tex_no_error=1
  31. "
  32. " 6. Please see :help latex-syntax for information on
  33. " syntax folding :help tex-folding
  34. " spell checking :help tex-nospell
  35. " commands and mathzones :help tex-runon
  36. " new command highlighting :help tex-morecommands
  37. " error highlighting :help tex-error
  38. " new math groups :help tex-math
  39. " new styles :help tex-style
  40. " using conceal mode :help tex-conceal
  41. " Version Clears: {{{1
  42. " quit when a syntax file was already loaded
  43. if exists("b:current_syntax")
  44. finish
  45. endif
  46. let s:keepcpo= &cpo
  47. set cpo&vim
  48. scriptencoding utf-8
  49. " by default, enable all region-based highlighting
  50. let s:tex_fast= "bcmMprsSvV"
  51. if exists("g:tex_fast")
  52. if type(g:tex_fast) != 1
  53. " g:tex_fast exists and is not a string, so
  54. " turn off all optional region-based highighting
  55. let s:tex_fast= ""
  56. else
  57. let s:tex_fast= g:tex_fast
  58. endif
  59. endif
  60. " let user determine which classes of concealment will be supported
  61. " a=accents/ligatures d=delimiters m=math symbols g=Greek s=superscripts/subscripts
  62. if !exists("g:tex_conceal")
  63. let s:tex_conceal= 'abdmgsS'
  64. else
  65. let s:tex_conceal= g:tex_conceal
  66. endif
  67. if !exists("g:tex_superscripts")
  68. let s:tex_superscripts= '[0-9a-zA-W.,:;+-<>/()=]'
  69. else
  70. let s:tex_superscripts= g:tex_superscripts
  71. endif
  72. if !exists("g:tex_subscripts")
  73. let s:tex_subscripts= '[0-9aehijklmnoprstuvx,+-/().]'
  74. else
  75. let s:tex_subscripts= g:tex_subscripts
  76. endif
  77. " Determine whether or not to use "*.sty" mode {{{1
  78. " The user may override the normal determination by setting
  79. " g:tex_stylish to 1 (for "*.sty" mode)
  80. " or to 0 else (normal "*.tex" mode)
  81. " or on a buffer-by-buffer basis with b:tex_stylish
  82. let s:extfname=expand("%:e")
  83. if exists("g:tex_stylish")
  84. let b:tex_stylish= g:tex_stylish
  85. elseif !exists("b:tex_stylish")
  86. if s:extfname == "sty" || s:extfname == "cls" || s:extfname == "clo" || s:extfname == "dtx" || s:extfname == "ltx"
  87. let b:tex_stylish= 1
  88. else
  89. let b:tex_stylish= 0
  90. endif
  91. endif
  92. " handle folding {{{1
  93. if !exists("g:tex_fold_enabled")
  94. let s:tex_fold_enabled= 0
  95. elseif g:tex_fold_enabled && !has("folding")
  96. let s:tex_fold_enabled= 0
  97. echomsg "Ignoring g:tex_fold_enabled=".g:tex_fold_enabled."; need to re-compile vim for +fold support"
  98. else
  99. let s:tex_fold_enabled= 1
  100. endif
  101. if s:tex_fold_enabled && &fdm == "manual"
  102. setl fdm=syntax
  103. endif
  104. if s:tex_fold_enabled && has("folding")
  105. com! -nargs=* TexFold <args> fold
  106. else
  107. com! -nargs=* TexFold <args>
  108. endif
  109. " (La)TeX keywords: uses the characters 0-9,a-z,A-Z,192-255 only... {{{1
  110. " but _ is the only one that causes problems.
  111. " One may override this iskeyword setting by providing
  112. " g:tex_isk
  113. if exists("g:tex_isk")
  114. if b:tex_stylish && g:tex_isk !~ '@'
  115. let b:tex_isk= '@,'.g:tex_isk
  116. else
  117. let b:tex_isk= g:tex_isk
  118. endif
  119. elseif b:tex_stylish
  120. let b:tex_isk="@,48-57,a-z,A-Z,192-255"
  121. else
  122. let b:tex_isk="48-57,a-z,A-Z,192-255"
  123. endif
  124. if (v:version == 704 && has("patch-7.4.1142")) || v:version > 704
  125. exe "syn iskeyword ".b:tex_isk
  126. else
  127. exe "setl isk=".b:tex_isk
  128. endif
  129. if exists("g:tex_no_error") && g:tex_no_error
  130. let s:tex_no_error= 1
  131. else
  132. let s:tex_no_error= 0
  133. endif
  134. if exists("g:tex_comment_nospell") && g:tex_comment_nospell
  135. let s:tex_comment_nospell= 1
  136. else
  137. let s:tex_comment_nospell= 0
  138. endif
  139. if exists("g:tex_nospell") && g:tex_nospell
  140. let s:tex_nospell = 1
  141. else
  142. let s:tex_nospell = 0
  143. endif
  144. if exists("g:tex_matchcheck")
  145. let s:tex_matchcheck= g:tex_matchcheck
  146. else
  147. let s:tex_matchcheck= '[({[]'
  148. endif
  149. if exists("g:tex_excludematcher")
  150. let s:tex_excludematcher= g:tex_excludematcher
  151. else
  152. let s:tex_excludematcher= 0
  153. endif
  154. " Clusters: {{{1
  155. " --------
  156. syn cluster texCmdGroup contains=texCmdBody,texComment,texDefParm,texDelimiter,texDocType,texInput,texLength,texLigature,texMathDelim,texMathOper,texNewCmd,texNewEnv,texRefZone,texSection,texBeginEnd,texBeginEndName,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,@texMathZones
  157. if !s:tex_no_error
  158. syn cluster texCmdGroup add=texMathError
  159. endif
  160. syn cluster texEnvGroup contains=texMatcher,texMathDelim,texSpecialChar,texStatement
  161. syn cluster texFoldGroup contains=texAccent,texBadMath,texComment,texDefCmd,texDelimiter,texDocType,texInput,texInputFile,texLength,texLigature,texMatcher,texMathZoneV,texMathZoneW,texMathZoneX,texMathZoneY,texMathZoneZ,texNewCmd,texNewEnv,texOnlyMath,texOption,texParen,texRefZone,texSection,texBeginEnd,texSectionZone,texSpaceCode,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,texZone,@texMathZones,texTitle,texAbstract,texBoldStyle,texItalStyle,texEmphStyle,texNoSpell
  162. syn cluster texBoldGroup contains=texAccent,texBadMath,texComment,texDefCmd,texDelimiter,texDocType,texInput,texInputFile,texLength,texLigature,texMathZoneV,texMathZoneW,texMathZoneX,texMathZoneY,texMathZoneZ,texNewCmd,texNewEnv,texOnlyMath,texOption,texParen,texRefZone,texSection,texBeginEnd,texSectionZone,texSpaceCode,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,texZone,@texMathZones,texTitle,texAbstract,texBoldStyle,texBoldItalStyle,texNoSpell
  163. syn cluster texItalGroup contains=texAccent,texBadMath,texComment,texDefCmd,texDelimiter,texDocType,texInput,texInputFile,texLength,texLigature,texMathZoneV,texMathZoneW,texMathZoneX,texMathZoneY,texMathZoneZ,texNewCmd,texNewEnv,texOnlyMath,texOption,texParen,texRefZone,texSection,texBeginEnd,texSectionZone,texSpaceCode,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,texZone,@texMathZones,texTitle,texAbstract,texItalStyle,texEmphStyle,texItalBoldStyle,texNoSpell
  164. if !s:tex_excludematcher
  165. syn cluster texBoldGroup add=texMatcher
  166. syn cluster texItalGroup add=texMatcher
  167. endif
  168. if !s:tex_nospell
  169. if !s:tex_no_error
  170. syn cluster texMatchGroup contains=texAccent,texBadMath,texComment,texDefCmd,texDelimiter,texDocType,texError,texInput,texLength,texLigature,texMatcher,texNewCmd,texNewEnv,texOnlyMath,texParen,texRefZone,texSection,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,texBoldStyle,texBoldItalStyle,texItalStyle,texItalBoldStyle,texZone,texInputFile,texOption,@Spell
  171. syn cluster texMatchNMGroup contains=texAccent,texBadMath,texComment,texDefCmd,texDelimiter,texDocType,texError,texInput,texLength,texLigature,texMatcherNM,texNewCmd,texNewEnv,texOnlyMath,texParen,texRefZone,texSection,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,texBoldStyle,texBoldItalStyle,texItalStyle,texItalBoldStyle,texZone,texInputFile,texOption,@Spell
  172. syn cluster texStyleGroup contains=texAccent,texBadMath,texComment,texDefCmd,texDelimiter,texDocType,texError,texInput,texLength,texLigature,texNewCmd,texNewEnv,texOnlyMath,texParen,texRefZone,texSection,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,texBoldStyle,texBoldItalStyle,texItalStyle,texItalBoldStyle,texZone,texInputFile,texOption,texStyleStatement,texStyleMatcher,@Spell
  173. else
  174. syn cluster texMatchGroup contains=texAccent,texBadMath,texComment,texDefCmd,texDelimiter,texDocType,texInput,texLength,texLigature,texMatcher,texNewCmd,texNewEnv,texOnlyMath,texParen,texRefZone,texSection,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,texBoldStyle,texBoldItalStyle,texItalStyle,texItalBoldStyle,texZone,texInputFile,texOption,@Spell
  175. syn cluster texMatchNMGroup contains=texAccent,texBadMath,texComment,texDefCmd,texDelimiter,texDocType,texInput,texLength,texLigature,texMatcherNM,texNewCmd,texNewEnv,texOnlyMath,texParen,texRefZone,texSection,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,texBoldStyle,texBoldItalStyle,texItalStyle,texItalBoldStyle,texZone,texInputFile,texOption,@Spell
  176. syn cluster texStyleGroup contains=texAccent,texBadMath,texComment,texDefCmd,texDelimiter,texDocType,texInput,texLength,texLigature,texNewCmd,texNewEnv,texOnlyMath,texParen,texRefZone,texSection,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,texBoldStyle,texBoldItalStyle,texItalStyle,texItalBoldStyle,texZone,texInputFile,texOption,texStyleStatement,texStyleMatcher,@Spell
  177. endif
  178. else
  179. if !s:tex_no_error
  180. syn cluster texMatchGroup contains=texAccent,texBadMath,texComment,texDefCmd,texDelimiter,texDocType,texError,texInput,texLength,texLigature,texMatcher,texNewCmd,texNewEnv,texOnlyMath,texParen,texRefZone,texSection,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,texZone,texInputFile,texOption
  181. syn cluster texMatchNMGroup contains=texAccent,texBadMath,texComment,texDefCmd,texDelimiter,texDocType,texError,texInput,texLength,texLigature,texMatcherNM,texNewCmd,texNewEnv,texOnlyMath,texParen,texRefZone,texSection,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,texZone,texInputFile,texOption
  182. syn cluster texStyleGroup contains=texAccent,texBadMath,texComment,texDefCmd,texDelimiter,texDocType,texError,texInput,texLength,texLigature,texNewCmd,texNewEnv,texOnlyMath,texParen,texRefZone,texSection,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,texZone,texInputFile,texOption,texStyleStatement,texStyleMatcher
  183. else
  184. syn cluster texMatchGroup contains=texAccent,texBadMath,texComment,texDefCmd,texDelimiter,texDocType,texInput,texLength,texLigature,texMatcher,texNewCmd,texNewEnv,texOnlyMath,texParen,texRefZone,texSection,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,texZone,texInputFile,texOption
  185. syn cluster texMatchNMGroup contains=texAccent,texBadMath,texComment,texDefCmd,texDelimiter,texDocType,texInput,texLength,texLigature,texMatcherNM,texNewCmd,texNewEnv,texOnlyMath,texParen,texRefZone,texSection,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,texZone,texInputFile,texOption
  186. syn cluster texStyleGroup contains=texAccent,texBadMath,texComment,texDefCmd,texDelimiter,texDocType,texInput,texLength,texLigature,texNewCmd,texNewEnv,texOnlyMath,texParen,texRefZone,texSection,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,texZone,texInputFile,texOption,texStyleStatement,texStyleMatcher
  187. endif
  188. endif
  189. syn cluster texPreambleMatchGroup contains=texAccent,texBadMath,texComment,texDefCmd,texDelimiter,texDocType,texInput,texLength,texLigature,texMatcherNM,texNewCmd,texNewEnv,texOnlyMath,texParen,texRefZone,texSection,texSpecialChar,texStatement,texString,texTitle,texTypeSize,texTypeStyle,texZone,texInputFile,texOption,texMathZoneZ
  190. syn cluster texRefGroup contains=texMatcher,texComment,texDelimiter
  191. if !exists("g:tex_no_math")
  192. syn cluster texPreambleMatchGroup contains=texAccent,texBadMath,texComment,texDefCmd,texDelimiter,texDocType,texInput,texLength,texLigature,texMatcherNM,texNewCmd,texNewEnv,texOnlyMath,texParen,texRefZone,texSection,texSpecialChar,texStatement,texString,texTitle,texTypeSize,texTypeStyle,texZone,texInputFile,texOption,texMathZoneZ
  193. syn cluster texMathZones contains=texMathZoneV,texMathZoneW,texMathZoneX,texMathZoneY,texMathZoneZ
  194. syn cluster texMatchGroup add=@texMathZones
  195. syn cluster texMathDelimGroup contains=texMathDelimBad,texMathDelimKey,texMathDelimSet1,texMathDelimSet2
  196. syn cluster texMathMatchGroup contains=@texMathZones,texComment,texDefCmd,texDelimiter,texDocType,texInput,texLength,texLigature,texMathDelim,texMathMatcher,texMathOper,texNewCmd,texNewEnv,texRefZone,texSection,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,texZone
  197. syn cluster texMathZoneGroup contains=texBadPar,texComment,texDelimiter,texLength,texMathDelim,texMathMatcher,texMathOper,texMathSymbol,texMathText,texRefZone,texSpecialChar,texStatement,texTypeSize,texTypeStyle
  198. if !s:tex_no_error
  199. syn cluster texMathMatchGroup add=texMathError
  200. syn cluster texMathZoneGroup add=texMathError
  201. endif
  202. syn cluster texMathZoneGroup add=@NoSpell
  203. " following used in the \part \chapter \section \subsection \subsubsection
  204. " \paragraph \subparagraph \author \title highlighting
  205. syn cluster texDocGroup contains=texPartZone,@texPartGroup
  206. syn cluster texPartGroup contains=texChapterZone,texSectionZone,texParaZone
  207. syn cluster texChapterGroup contains=texSectionZone,texParaZone
  208. syn cluster texSectionGroup contains=texSubSectionZone,texParaZone
  209. syn cluster texSubSectionGroup contains=texSubSubSectionZone,texParaZone
  210. syn cluster texSubSubSectionGroup contains=texParaZone
  211. syn cluster texParaGroup contains=texSubParaZone
  212. if has("conceal") && &enc == 'utf-8'
  213. syn cluster texMathZoneGroup add=texGreek,texSuperscript,texSubscript,texMathSymbol
  214. syn cluster texMathMatchGroup add=texGreek,texSuperscript,texSubscript,texMathSymbol
  215. endif
  216. endif
  217. " Try to flag {}, [], and () mismatches: {{{1
  218. if s:tex_fast =~# 'm'
  219. if !s:tex_no_error
  220. if s:tex_matchcheck =~ '{'
  221. syn region texMatcher matchgroup=texDelimiter start="{" skip="\\\\\|\\[{}]" end="}" transparent contains=@texMatchGroup,texError
  222. syn region texMatcherNM matchgroup=texDelimiter start="{" skip="\\\\\|\\[{}]" end="}" transparent contains=@texMatchNMGroup,texError
  223. endif
  224. if s:tex_matchcheck =~ '\['
  225. syn region texMatcher matchgroup=texDelimiter start="\[" end="]" transparent contains=@texMatchGroup,texError,@NoSpell
  226. syn region texMatcherNM matchgroup=texDelimiter start="\[" end="]" transparent contains=@texMatchNMGroup,texError,@NoSpell
  227. endif
  228. else
  229. if s:tex_matchcheck =~ '{'
  230. syn region texMatcher matchgroup=texDelimiter start="{" skip="\\\\\|\\[{}]" end="}" transparent contains=@texMatchGroup
  231. syn region texMatcherNM matchgroup=texDelimiter start="{" skip="\\\\\|\\[{}]" end="}" transparent contains=@texMatchNMGroup
  232. endif
  233. if s:tex_matchcheck =~ '\['
  234. syn region texMatcher matchgroup=texDelimiter start="\[" end="]" transparent contains=@texMatchGroup
  235. syn region texMatcherNM matchgroup=texDelimiter start="\[" end="]" transparent contains=@texMatchNMGroup
  236. endif
  237. endif
  238. if s:tex_matchcheck =~ '('
  239. if !s:tex_nospell
  240. syn region texParen start="(" end=")" transparent contains=@texMatchGroup,@Spell
  241. else
  242. syn region texParen start="(" end=")" transparent contains=@texMatchGroup
  243. endif
  244. endif
  245. endif
  246. if !s:tex_no_error
  247. if s:tex_matchcheck =~ '('
  248. syn match texError "[}\]]"
  249. else
  250. syn match texError "[}\])]"
  251. endif
  252. endif
  253. if s:tex_fast =~# 'M'
  254. if !exists("g:tex_no_math")
  255. if !s:tex_no_error
  256. syn match texMathError "}" contained
  257. endif
  258. syn region texMathMatcher matchgroup=texDelimiter start="{" skip="\%(\\\\\)*\\}" end="}" end="%stopzone\>" contained contains=@texMathMatchGroup
  259. endif
  260. endif
  261. " TeX/LaTeX keywords: {{{1
  262. " Instead of trying to be All Knowing, I just match \..alphameric..
  263. " Note that *.tex files may not have "@" in their \commands
  264. if exists("g:tex_tex") || b:tex_stylish
  265. syn match texStatement "\\[a-zA-Z@]\+"
  266. else
  267. syn match texStatement "\\\a\+"
  268. if !s:tex_no_error
  269. syn match texError "\\\a*@[a-zA-Z@]*"
  270. endif
  271. endif
  272. " TeX/LaTeX delimiters: {{{1
  273. syn match texDelimiter "&"
  274. syn match texDelimiter "\\\\"
  275. " Tex/Latex Options: {{{1
  276. syn match texOption "[^\\]\zs#\d\+\|^#\d\+"
  277. " texAccent (tnx to Karim Belabas) avoids annoying highlighting for accents: {{{1
  278. if b:tex_stylish
  279. syn match texAccent "\\[bcdvuH][^a-zA-Z@]"me=e-1
  280. syn match texLigature "\\\([ijolL]\|ae\|oe\|ss\|AA\|AE\|OE\)[^a-zA-Z@]"me=e-1
  281. else
  282. syn match texAccent "\\[bcdvuH]\A"me=e-1
  283. syn match texLigature "\\\([ijolL]\|ae\|oe\|ss\|AA\|AE\|OE\)\A"me=e-1
  284. endif
  285. syn match texAccent "\\[bcdvuH]$"
  286. syn match texAccent +\\[=^.\~"`']+
  287. syn match texAccent +\\['=t'.c^ud"vb~Hr]{\a}+
  288. syn match texLigature "\\\([ijolL]\|ae\|oe\|ss\|AA\|AE\|OE\)$"
  289. " \begin{}/\end{} section markers: {{{1
  290. syn match texBeginEnd "\\begin\>\|\\end\>" nextgroup=texBeginEndName
  291. if s:tex_fast =~# 'm'
  292. syn region texBeginEndName matchgroup=texDelimiter start="{" end="}" contained nextgroup=texBeginEndModifier contains=texComment
  293. syn region texBeginEndModifier matchgroup=texDelimiter start="\[" end="]" contained contains=texComment,@texMathZones,@NoSpell
  294. endif
  295. " \documentclass, \documentstyle, \usepackage: {{{1
  296. syn match texDocType "\\documentclass\>\|\\documentstyle\>\|\\usepackage\>" nextgroup=texBeginEndName,texDocTypeArgs
  297. if s:tex_fast =~# 'm'
  298. syn region texDocTypeArgs matchgroup=texDelimiter start="\[" end="]" contained nextgroup=texBeginEndName contains=texComment,@NoSpell
  299. endif
  300. " Preamble syntax-based folding support: {{{1
  301. if s:tex_fold_enabled && has("folding")
  302. syn region texPreamble transparent fold start='\zs\\documentclass\>' end='\ze\\begin{document}' contains=texStyle,@texPreambleMatchGroup
  303. endif
  304. " TeX input: {{{1
  305. syn match texInput "\\input\s\+[a-zA-Z/.0-9_^]\+"hs=s+7 contains=texStatement
  306. syn match texInputFile "\\include\(graphics\|list\)\=\(\[.\{-}\]\)\=\s*{.\{-}}" contains=texStatement,texInputCurlies,texInputFileOpt
  307. syn match texInputFile "\\\(epsfig\|input\|usepackage\)\s*\(\[.*\]\)\={.\{-}}" contains=texStatement,texInputCurlies,texInputFileOpt
  308. syn match texInputCurlies "[{}]" contained
  309. if s:tex_fast =~# 'm'
  310. syn region texInputFileOpt matchgroup=texDelimiter start="\[" end="\]" contained contains=texComment
  311. endif
  312. " Type Styles (LaTeX 2.09): {{{1
  313. syn match texTypeStyle "\\rm\>"
  314. syn match texTypeStyle "\\em\>"
  315. syn match texTypeStyle "\\bf\>"
  316. syn match texTypeStyle "\\it\>"
  317. syn match texTypeStyle "\\sl\>"
  318. syn match texTypeStyle "\\sf\>"
  319. syn match texTypeStyle "\\sc\>"
  320. syn match texTypeStyle "\\tt\>"
  321. " Type Styles: attributes, commands, families, etc (LaTeX2E): {{{1
  322. if s:tex_conceal !~# 'b'
  323. syn match texTypeStyle "\\textbf\>"
  324. syn match texTypeStyle "\\textit\>"
  325. syn match texTypeStyle "\\emph\>"
  326. endif
  327. syn match texTypeStyle "\\textmd\>"
  328. syn match texTypeStyle "\\textrm\>"
  329. syn match texTypeStyle "\\mathbf\>"
  330. syn match texTypeStyle "\\mathcal\>"
  331. syn match texTypeStyle "\\mathit\>"
  332. syn match texTypeStyle "\\mathnormal\>"
  333. syn match texTypeStyle "\\mathrm\>"
  334. syn match texTypeStyle "\\mathsf\>"
  335. syn match texTypeStyle "\\mathtt\>"
  336. syn match texTypeStyle "\\rmfamily\>"
  337. syn match texTypeStyle "\\sffamily\>"
  338. syn match texTypeStyle "\\ttfamily\>"
  339. syn match texTypeStyle "\\itshape\>"
  340. syn match texTypeStyle "\\scshape\>"
  341. syn match texTypeStyle "\\slshape\>"
  342. syn match texTypeStyle "\\upshape\>"
  343. syn match texTypeStyle "\\bfseries\>"
  344. syn match texTypeStyle "\\mdseries\>"
  345. " Some type sizes: {{{1
  346. syn match texTypeSize "\\tiny\>"
  347. syn match texTypeSize "\\scriptsize\>"
  348. syn match texTypeSize "\\footnotesize\>"
  349. syn match texTypeSize "\\small\>"
  350. syn match texTypeSize "\\normalsize\>"
  351. syn match texTypeSize "\\large\>"
  352. syn match texTypeSize "\\Large\>"
  353. syn match texTypeSize "\\LARGE\>"
  354. syn match texTypeSize "\\huge\>"
  355. syn match texTypeSize "\\Huge\>"
  356. " Spacecodes (TeX'isms): {{{1
  357. " \mathcode`\^^@="2201 \delcode`\(="028300 \sfcode`\)=0 \uccode`X=`X \lccode`x=`x
  358. syn match texSpaceCode "\\\(math\|cat\|del\|lc\|sf\|uc\)code`"me=e-1 nextgroup=texSpaceCodeChar
  359. syn match texSpaceCodeChar "`\\\=.\(\^.\)\==\(\d\|\"\x\{1,6}\|`.\)" contained
  360. " Sections, subsections, etc: {{{1
  361. if s:tex_fast =~# 'p'
  362. if !s:tex_nospell
  363. TexFold syn region texDocZone matchgroup=texSection start='\\begin\s*{\s*document\s*}' end='\\end\s*{\s*document\s*}' contains=@texFoldGroup,@texDocGroup,@Spell
  364. TexFold syn region texPartZone matchgroup=texSection start='\\part\>' end='\ze\s*\\\%(part\>\|end\s*{\s*document\s*}\)' contains=@texFoldGroup,@texPartGroup,@Spell
  365. TexFold syn region texChapterZone matchgroup=texSection start='\\chapter\>' end='\ze\s*\\\%(chapter\>\|part\>\|end\s*{\s*document\s*}\)' contains=@texFoldGroup,@texChapterGroup,@Spell
  366. TexFold syn region texSectionZone matchgroup=texSection start='\\section\>' end='\ze\s*\\\%(section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)' contains=@texFoldGroup,@texSectionGroup,@Spell
  367. TexFold syn region texSubSectionZone matchgroup=texSection start='\\subsection\>' end='\ze\s*\\\%(\%(sub\)\=section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)' contains=@texFoldGroup,@texSubSectionGroup,@Spell
  368. TexFold syn region texSubSubSectionZone matchgroup=texSection start='\\subsubsection\>' end='\ze\s*\\\%(\%(sub\)\{,2}section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)' contains=@texFoldGroup,@texSubSubSectionGroup,@Spell
  369. TexFold syn region texParaZone matchgroup=texSection start='\\paragraph\>' end='\ze\s*\\\%(paragraph\>\|\%(sub\)*section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)' contains=@texFoldGroup,@texParaGroup,@Spell
  370. TexFold syn region texSubParaZone matchgroup=texSection start='\\subparagraph\>' end='\ze\s*\\\%(\%(sub\)\=paragraph\>\|\%(sub\)*section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)' contains=@texFoldGroup,@Spell
  371. TexFold syn region texTitle matchgroup=texSection start='\\\%(author\|title\)\>\s*{' end='}' contains=@texFoldGroup,@Spell
  372. TexFold syn region texAbstract matchgroup=texSection start='\\begin\s*{\s*abstract\s*}' end='\\end\s*{\s*abstract\s*}' contains=@texFoldGroup,@Spell
  373. else
  374. TexFold syn region texDocZone matchgroup=texSection start='\\begin\s*{\s*document\s*}' end='\\end\s*{\s*document\s*}' contains=@texFoldGroup,@texDocGroup
  375. TexFold syn region texPartZone matchgroup=texSection start='\\part\>' end='\ze\s*\\\%(part\>\|end\s*{\s*document\s*}\)' contains=@texFoldGroup,@texPartGroup
  376. TexFold syn region texChapterZone matchgroup=texSection start='\\chapter\>' end='\ze\s*\\\%(chapter\>\|part\>\|end\s*{\s*document\s*}\)' contains=@texFoldGroup,@texChapterGroup
  377. TexFold syn region texSectionZone matchgroup=texSection start='\\section\>' end='\ze\s*\\\%(section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)' contains=@texFoldGroup,@texSectionGroup
  378. TexFold syn region texSubSectionZone matchgroup=texSection start='\\subsection\>' end='\ze\s*\\\%(\%(sub\)\=section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)' contains=@texFoldGroup,@texSubSectionGroup
  379. TexFold syn region texSubSubSectionZone matchgroup=texSection start='\\subsubsection\>' end='\ze\s*\\\%(\%(sub\)\{,2}section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)' contains=@texFoldGroup,@texSubSubSectionGroup
  380. TexFold syn region texParaZone matchgroup=texSection start='\\paragraph\>' end='\ze\s*\\\%(paragraph\>\|\%(sub\)*section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)' contains=@texFoldGroup,@texParaGroup
  381. TexFold syn region texSubParaZone matchgroup=texSection start='\\subparagraph\>' end='\ze\s*\\\%(\%(sub\)\=paragraph\>\|\%(sub\)*section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)' contains=@texFoldGroup
  382. TexFold syn region texTitle matchgroup=texSection start='\\\%(author\|title\)\>\s*{' end='}' contains=@texFoldGroup
  383. TexFold syn region texAbstract matchgroup=texSection start='\\begin\s*{\s*abstract\s*}' end='\\end\s*{\s*abstract\s*}' contains=@texFoldGroup
  384. endif
  385. endif
  386. " particular support for bold and italic {{{1
  387. if s:tex_fast =~# 'b'
  388. if s:tex_conceal =~# 'b'
  389. if !exists("g:tex_nospell") || !g:tex_nospell
  390. syn region texBoldStyle matchgroup=texTypeStyle start="\\textbf\s*{" matchgroup=texTypeStyle end="}" concealends contains=@texBoldGroup,@Spell
  391. syn region texBoldItalStyle matchgroup=texTypeStyle start="\\textit\s*{" matchgroup=texTypeStyle end="}" concealends contains=@texItalGroup,@Spell
  392. syn region texItalStyle matchgroup=texTypeStyle start="\\textit\s*{" matchgroup=texTypeStyle end="}" concealends contains=@texItalGroup,@Spell
  393. syn region texItalBoldStyle matchgroup=texTypeStyle start="\\textbf\s*{" matchgroup=texTypeStyle end="}" concealends contains=@texBoldGroup,@Spell
  394. syn region texEmphStyle matchgroup=texTypeStyle start="\\emph\s*{" matchgroup=texTypeStyle end="}" concealends contains=@texItalGroup,@Spell
  395. syn region texEmphStyle matchgroup=texTypeStyle start="\\texts[cfl]\s*{" matchgroup=texTypeStyle end="}" concealends contains=@texBoldGroup,@Spell
  396. syn region texEmphStyle matchgroup=texTypeStyle start="\\textup\s*{" matchgroup=texTypeStyle end="}" concealends contains=@texBoldGroup,@Spell
  397. syn region texEmphStyle matchgroup=texTypeStyle start="\\texttt\s*{" matchgroup=texTypeStyle end="}" concealends contains=@texBoldGroup,@Spell
  398. else
  399. syn region texBoldStyle matchgroup=texTypeStyle start="\\textbf\s*{" matchgroup=texTypeStyle end="}" concealends contains=@texBoldGroup
  400. syn region texBoldItalStyle matchgroup=texTypeStyle start="\\textit\s*{" matchgroup=texTypeStyle end="}" concealends contains=@texItalGroup
  401. syn region texItalStyle matchgroup=texTypeStyle start="\\textit\s*{" matchgroup=texTypeStyle end="}" concealends contains=@texItalGroup
  402. syn region texItalBoldStyle matchgroup=texTypeStyle start="\\textbf\s*{" matchgroup=texTypeStyle end="}" concealends contains=@texBoldGroup
  403. syn region texEmphStyle matchgroup=texTypeStyle start="\\emph\s*{" matchgroup=texTypeStyle end="}" concealends contains=@texItalGroup
  404. syn region texEmphStyle matchgroup=texTypeStyle start="\\texts[cfl]\s*{" matchgroup=texTypeStyle end="}" concealends contains=@texEmphGroup
  405. syn region texEmphStyle matchgroup=texTypeStyle start="\\textup\s*{" matchgroup=texTypeStyle end="}" concealends contains=@texEmphGroup
  406. syn region texEmphStyle matchgroup=texTypeStyle start="\\texttt\s*{" matchgroup=texTypeStyle end="}" concealends contains=@texEmphGroup
  407. endif
  408. endif
  409. endif
  410. " Bad Math (mismatched): {{{1
  411. if !exists("g:tex_no_math") && !s:tex_no_error
  412. syn match texBadMath "\\end\s*{\s*\(array\|[bBpvV]matrix\|split\|smallmatrix\)\s*}"
  413. syn match texBadMath "\\end\s*{\s*\(displaymath\|equation\|eqnarray\|math\)\*\=\s*}"
  414. syn match texBadMath "\\[\])]"
  415. syn match texBadPar contained "\%(\\par\>\|^\s*\n.\)"
  416. endif
  417. " Math Zones: {{{1
  418. if !exists("g:tex_no_math")
  419. " TexNewMathZone: function creates a mathzone with the given suffix and mathzone name. {{{2
  420. " Starred forms are created if starform is true. Starred
  421. " forms have syntax group and synchronization groups with a
  422. " "S" appended. Handles: cluster, syntax, sync, and highlighting.
  423. fun! TexNewMathZone(sfx,mathzone,starform)
  424. let grpname = "texMathZone".a:sfx
  425. let syncname = "texSyncMathZone".a:sfx
  426. if s:tex_fold_enabled
  427. let foldcmd= " fold"
  428. else
  429. let foldcmd= ""
  430. endif
  431. exe "syn cluster texMathZones add=".grpname
  432. if s:tex_fast =~# 'M'
  433. exe 'syn region '.grpname.' start='."'".'\\begin\s*{\s*'.a:mathzone.'\s*}'."'".' end='."'".'\\end\s*{\s*'.a:mathzone.'\s*}'."'".' keepend contains=@texMathZoneGroup'.foldcmd
  434. exe 'syn sync match '.syncname.' grouphere '.grpname.' "\\begin\s*{\s*'.a:mathzone.'\*\s*}"'
  435. exe 'syn sync match '.syncname.' grouphere '.grpname.' "\\begin\s*{\s*'.a:mathzone.'\*\s*}"'
  436. endif
  437. exe 'hi def link '.grpname.' texMath'
  438. if a:starform
  439. let grpname = "texMathZone".a:sfx.'S'
  440. let syncname = "texSyncMathZone".a:sfx.'S'
  441. exe "syn cluster texMathZones add=".grpname
  442. if s:tex_fast =~# 'M'
  443. exe 'syn region '.grpname.' start='."'".'\\begin\s*{\s*'.a:mathzone.'\*\s*}'."'".' end='."'".'\\end\s*{\s*'.a:mathzone.'\*\s*}'."'".' keepend contains=@texMathZoneGroup'.foldcmd
  444. exe 'syn sync match '.syncname.' grouphere '.grpname.' "\\begin\s*{\s*'.a:mathzone.'\*\s*}"'
  445. exe 'syn sync match '.syncname.' grouphere '.grpname.' "\\begin\s*{\s*'.a:mathzone.'\*\s*}"'
  446. endif
  447. exe 'hi def link '.grpname.' texMath'
  448. endif
  449. endfun
  450. " Standard Math Zones: {{{2
  451. call TexNewMathZone("A","displaymath",1)
  452. call TexNewMathZone("B","eqnarray",1)
  453. call TexNewMathZone("C","equation",1)
  454. call TexNewMathZone("D","math",1)
  455. " Inline Math Zones: {{{2
  456. if s:tex_fast =~# 'M'
  457. if has("conceal") && &enc == 'utf-8' && s:tex_conceal =~# 'd'
  458. syn region texMathZoneV matchgroup=texDelimiter start="\\(" matchgroup=texDelimiter end="\\)\|%stopzone\>" keepend concealends contains=@texMathZoneGroup
  459. syn region texMathZoneW matchgroup=texDelimiter start="\\\[" matchgroup=texDelimiter end="\\]\|%stopzone\>" keepend concealends contains=@texMathZoneGroup
  460. syn region texMathZoneX matchgroup=texDelimiter start="\$" skip="\\\\\|\\\$" matchgroup=texDelimiter end="\$" end="%stopzone\>" concealends contains=@texMathZoneGroup
  461. syn region texMathZoneY matchgroup=texDelimiter start="\$\$" matchgroup=texDelimiter end="\$\$" end="%stopzone\>" keepend concealends contains=@texMathZoneGroup
  462. else
  463. syn region texMathZoneV matchgroup=texDelimiter start="\\(" matchgroup=texDelimiter end="\\)\|%stopzone\>" keepend contains=@texMathZoneGroup
  464. syn region texMathZoneW matchgroup=texDelimiter start="\\\[" matchgroup=texDelimiter end="\\]\|%stopzone\>" keepend contains=@texMathZoneGroup
  465. syn region texMathZoneX matchgroup=texDelimiter start="\$" skip="\%(\\\\\)*\\\$" matchgroup=texDelimiter end="\$" end="%stopzone\>" contains=@texMathZoneGroup
  466. syn region texMathZoneY matchgroup=texDelimiter start="\$\$" matchgroup=texDelimiter end="\$\$" end="%stopzone\>" keepend contains=@texMathZoneGroup
  467. endif
  468. syn region texMathZoneZ matchgroup=texStatement start="\\ensuremath\s*{" matchgroup=texStatement end="}" end="%stopzone\>" contains=@texMathZoneGroup
  469. endif
  470. syn match texMathOper "[_^=]" contained
  471. " Text Inside Math Zones: {{{2
  472. if s:tex_fast =~# 'M'
  473. if !exists("g:tex_nospell") || !g:tex_nospell
  474. syn region texMathText matchgroup=texStatement start='\\\(\(inter\)\=text\|mbox\)\s*{' end='}' contains=@texFoldGroup,@Spell
  475. else
  476. syn region texMathText matchgroup=texStatement start='\\\(\(inter\)\=text\|mbox\)\s*{' end='}' contains=@texFoldGroup
  477. endif
  478. endif
  479. " \left..something.. and \right..something.. support: {{{2
  480. syn match texMathDelimBad contained "\S"
  481. if has("conceal") && &enc == 'utf-8' && s:tex_conceal =~# 'm'
  482. syn match texMathDelim contained "\\left\["
  483. syn match texMathDelim contained "\\left\\{" skipwhite nextgroup=texMathDelimSet1,texMathDelimSet2,texMathDelimBad contains=texMathSymbol cchar={
  484. syn match texMathDelim contained "\\right\\}" skipwhite nextgroup=texMathDelimSet1,texMathDelimSet2,texMathDelimBad contains=texMathSymbol cchar=}
  485. let s:texMathDelimList=[
  486. \ ['<' , '<'] ,
  487. \ ['>' , '>'] ,
  488. \ ['(' , '('] ,
  489. \ [')' , ')'] ,
  490. \ ['\[' , '['] ,
  491. \ [']' , ']'] ,
  492. \ ['\\{' , '{'] ,
  493. \ ['\\}' , '}'] ,
  494. \ ['|' , '|'] ,
  495. \ ['\\|' , '‖'] ,
  496. \ ['\\backslash' , '\'] ,
  497. \ ['\\downarrow' , '↓'] ,
  498. \ ['\\Downarrow' , '⇓'] ,
  499. \ ['\\lbrace' , '['] ,
  500. \ ['\\lceil' , '⌈'] ,
  501. \ ['\\lfloor' , '⌊'] ,
  502. \ ['\\lgroup' , '⌊'] ,
  503. \ ['\\lmoustache' , '⎛'] ,
  504. \ ['\\rbrace' , ']'] ,
  505. \ ['\\rceil' , '⌉'] ,
  506. \ ['\\rfloor' , '⌋'] ,
  507. \ ['\\rgroup' , '⌋'] ,
  508. \ ['\\rmoustache' , '⎞'] ,
  509. \ ['\\uparrow' , '↑'] ,
  510. \ ['\\Uparrow' , '↑'] ,
  511. \ ['\\updownarrow', '↕'] ,
  512. \ ['\\Updownarrow', '⇕']]
  513. if &ambw == "double" || exists("g:tex_usedblwidth")
  514. let s:texMathDelimList= s:texMathDelimList + [
  515. \ ['\\langle' , '〈'] ,
  516. \ ['\\rangle' , '〉']]
  517. else
  518. let s:texMathDelimList= s:texMathDelimList + [
  519. \ ['\\langle' , '<'] ,
  520. \ ['\\rangle' , '>']]
  521. endif
  522. syn match texMathDelim '\\[bB]igg\=[lr]' contained nextgroup=texMathDelimBad
  523. for texmath in s:texMathDelimList
  524. exe "syn match texMathDelim '\\\\[bB]igg\\=[lr]\\=".texmath[0]."' contained conceal cchar=".texmath[1]
  525. endfor
  526. else
  527. syn match texMathDelim contained "\\\(left\|right\)\>" skipwhite nextgroup=texMathDelimSet1,texMathDelimSet2,texMathDelimBad
  528. syn match texMathDelim contained "\\[bB]igg\=[lr]\=\>" skipwhite nextgroup=texMathDelimSet1,texMathDelimSet2,texMathDelimBad
  529. syn match texMathDelimSet2 contained "\\" nextgroup=texMathDelimKey,texMathDelimBad
  530. syn match texMathDelimSet1 contained "[<>()[\]|/.]\|\\[{}|]"
  531. syn keyword texMathDelimKey contained backslash lceil lVert rgroup uparrow
  532. syn keyword texMathDelimKey contained downarrow lfloor rangle rmoustache Uparrow
  533. syn keyword texMathDelimKey contained Downarrow lgroup rbrace rvert updownarrow
  534. syn keyword texMathDelimKey contained langle lmoustache rceil rVert Updownarrow
  535. syn keyword texMathDelimKey contained lbrace lvert rfloor
  536. endif
  537. syn match texMathDelim contained "\\\(left\|right\)arrow\>\|\<\([aA]rrow\|brace\)\=vert\>"
  538. syn match texMathDelim contained "\\lefteqn\>"
  539. endif
  540. " Special TeX characters ( \$ \& \% \# \{ \} \_ \S \P ) : {{{1
  541. syn match texSpecialChar "\\[$&%#{}_]"
  542. if b:tex_stylish
  543. syn match texSpecialChar "\\[SP@][^a-zA-Z@]"me=e-1
  544. else
  545. syn match texSpecialChar "\\[SP@]\A"me=e-1
  546. endif
  547. syn match texSpecialChar "\\\\"
  548. if !exists("g:tex_no_math")
  549. syn match texOnlyMath "[_^]"
  550. endif
  551. syn match texSpecialChar "\^\^[0-9a-f]\{2}\|\^\^\S"
  552. if s:tex_conceal !~# 'S'
  553. syn match texSpecialChar '\\glq\>' contained conceal cchar=‚
  554. syn match texSpecialChar '\\grq\>' contained conceal cchar=‘
  555. syn match texSpecialChar '\\glqq\>' contained conceal cchar=„
  556. syn match texSpecialChar '\\grqq\>' contained conceal cchar=“
  557. syn match texSpecialChar '\\hyp\>' contained conceal cchar=-
  558. endif
  559. " Comments: {{{1
  560. " Normal TeX LaTeX : %....
  561. " Documented TeX Format: ^^A... -and- leading %s (only)
  562. if !s:tex_comment_nospell
  563. syn cluster texCommentGroup contains=texTodo,@Spell
  564. else
  565. syn cluster texCommentGroup contains=texTodo,@NoSpell
  566. endif
  567. syn case ignore
  568. syn keyword texTodo contained combak fixme todo xxx
  569. syn case match
  570. if s:extfname == "dtx"
  571. syn match texComment "\^\^A.*$" contains=@texCommentGroup
  572. syn match texComment "^%\+" contains=@texCommentGroup
  573. else
  574. if s:tex_fold_enabled
  575. " allows syntax-folding of 2 or more contiguous comment lines
  576. " single-line comments are not folded
  577. syn match texComment "%.*$" contains=@texCommentGroup
  578. if s:tex_fast =~# 'c'
  579. TexFold syn region texComment start="^\zs\s*%.*\_s*%" skip="^\s*%" end='^\ze\s*[^%]' contains=@texCommentGroup
  580. TexFold syn region texNoSpell contained matchgroup=texComment start="%\s*nospell\s*{" end="%\s*nospell\s*}" contains=@texFoldGroup,@NoSpell
  581. endif
  582. else
  583. syn match texComment "%.*$" contains=@texCommentGroup
  584. if s:tex_fast =~# 'c'
  585. syn region texNoSpell contained matchgroup=texComment start="%\s*nospell\s*{" end="%\s*nospell\s*}" contains=@texFoldGroup,@NoSpell
  586. endif
  587. endif
  588. endif
  589. " %begin-include ... %end-include acts like a texDocZone for \include'd files. Permits spell checking, for example, in such files.
  590. if !s:tex_nospell
  591. TexFold syn region texDocZone matchgroup=texSection start='^\s*%begin-include\>' end='^\s*%end-include\>' contains=@texFoldGroup,@texDocGroup,@Spell
  592. else
  593. TexFold syn region texDocZone matchgroup=texSection start='^\s*%begin-include\>' end='^\s*%end-include\>' contains=@texFoldGroup,@texDocGroup
  594. endif
  595. " Separate lines used for verb` and verb# so that the end conditions {{{1
  596. " will appropriately terminate.
  597. " If g:tex_verbspell exists, then verbatim texZones will permit spellchecking there.
  598. if s:tex_fast =~# 'v'
  599. if exists("g:tex_verbspell") && g:tex_verbspell
  600. syn region texZone start="\\begin{[vV]erbatim}" end="\\end{[vV]erbatim}\|%stopzone\>" contains=@Spell
  601. " listings package:
  602. if b:tex_stylish
  603. syn region texZone start="\\verb\*\=\z([^\ta-zA-Z@]\)" end="\z1\|%stopzone\>" contains=@Spell
  604. else
  605. syn region texZone start="\\verb\*\=\z([^\ta-zA-Z]\)" end="\z1\|%stopzone\>" contains=@Spell
  606. endif
  607. else
  608. syn region texZone start="\\begin{[vV]erbatim}" end="\\end{[vV]erbatim}\|%stopzone\>"
  609. if b:tex_stylish
  610. syn region texZone start="\\verb\*\=\z([^\ta-zA-Z@]\)" end="\z1\|%stopzone\>"
  611. else
  612. syn region texZone start="\\verb\*\=\z([^\ta-zA-Z]\)" end="\z1\|%stopzone\>"
  613. endif
  614. endif
  615. endif
  616. " Tex Reference Zones: {{{1
  617. if s:tex_fast =~# 'r'
  618. syn region texZone matchgroup=texStatement start="@samp{" end="}\|%stopzone\>" contains=@texRefGroup
  619. syn region texRefZone matchgroup=texStatement start="\\nocite{" end="}\|%stopzone\>" contains=@texRefGroup
  620. syn region texRefZone matchgroup=texStatement start="\\bibliography{" end="}\|%stopzone\>" contains=@texRefGroup
  621. syn region texRefZone matchgroup=texStatement start="\\label{" end="}\|%stopzone\>" contains=@texRefGroup
  622. syn region texRefZone matchgroup=texStatement start="\\\(page\|eq\)ref{" end="}\|%stopzone\>" contains=@texRefGroup
  623. syn region texRefZone matchgroup=texStatement start="\\v\=ref{" end="}\|%stopzone\>" contains=@texRefGroup
  624. syn region texRefOption contained matchgroup=texDelimiter start='\[' end=']' contains=@texRefGroup,texRefZone nextgroup=texRefOption,texCite
  625. syn region texCite contained matchgroup=texDelimiter start='{' end='}' contains=@texRefGroup,texRefZone,texCite
  626. endif
  627. syn match texRefZone '\\cite\%([tp]\*\=\)\=\>' nextgroup=texRefOption,texCite
  628. " Handle (re)newcommand, (re)newenvironment : {{{1
  629. syn match texNewCmd "\\\%(re\)\=newcommand\>" nextgroup=texCmdName skipwhite skipnl
  630. if s:tex_fast =~# 'V'
  631. syn region texCmdName contained matchgroup=texDelimiter start="{"rs=s+1 end="}" nextgroup=texCmdArgs,texCmdBody skipwhite skipnl
  632. syn region texCmdArgs contained matchgroup=texDelimiter start="\["rs=s+1 end="]" nextgroup=texCmdBody skipwhite skipnl
  633. syn region texCmdBody contained matchgroup=texDelimiter start="{"rs=s+1 skip="\\\\\|\\[{}]" matchgroup=texDelimiter end="}" contains=@texCmdGroup
  634. endif
  635. syn match texNewEnv "\\\%(re\)\=newenvironment\>" nextgroup=texEnvName skipwhite skipnl
  636. if s:tex_fast =~# 'V'
  637. syn region texEnvName contained matchgroup=texDelimiter start="{"rs=s+1 end="}" nextgroup=texEnvBgn skipwhite skipnl
  638. syn region texEnvBgn contained matchgroup=texDelimiter start="{"rs=s+1 end="}" nextgroup=texEnvEnd skipwhite skipnl contains=@texEnvGroup
  639. syn region texEnvEnd contained matchgroup=texDelimiter start="{"rs=s+1 end="}" skipwhite skipnl contains=@texEnvGroup
  640. endif
  641. " Definitions/Commands: {{{1
  642. syn match texDefCmd "\\def\>" nextgroup=texDefName skipwhite skipnl
  643. if b:tex_stylish
  644. syn match texDefName contained "\\[a-zA-Z@]\+" nextgroup=texDefParms,texCmdBody skipwhite skipnl
  645. syn match texDefName contained "\\[^a-zA-Z@]" nextgroup=texDefParms,texCmdBody skipwhite skipnl
  646. else
  647. syn match texDefName contained "\\\a\+" nextgroup=texDefParms,texCmdBody skipwhite skipnl
  648. syn match texDefName contained "\\\A" nextgroup=texDefParms,texCmdBody skipwhite skipnl
  649. endif
  650. syn match texDefParms contained "#[^{]*" contains=texDefParm nextgroup=texCmdBody skipwhite skipnl
  651. syn match texDefParm contained "#\d\+"
  652. " TeX Lengths: {{{1
  653. syn match texLength "\<\d\+\([.,]\d\+\)\=\s*\(true\)\=\s*\(bp\|cc\|cm\|dd\|em\|ex\|in\|mm\|pc\|pt\|sp\)\>"
  654. " TeX String Delimiters: {{{1
  655. syn match texString "\(``\|''\|,,\)"
  656. " makeatletter -- makeatother sections
  657. if !s:tex_no_error
  658. if s:tex_fast =~# 'S'
  659. syn region texStyle matchgroup=texStatement start='\\makeatletter' end='\\makeatother' contains=@texStyleGroup contained
  660. endif
  661. syn match texStyleStatement "\\[a-zA-Z@]\+" contained
  662. if s:tex_fast =~# 'S'
  663. syn region texStyleMatcher matchgroup=texDelimiter start="{" skip="\\\\\|\\[{}]" end="}" contains=@texStyleGroup,texError contained
  664. syn region texStyleMatcher matchgroup=texDelimiter start="\[" end="]" contains=@texStyleGroup,texError contained
  665. endif
  666. endif
  667. " Conceal mode support (supports set cole=2) {{{1
  668. if has("conceal") && &enc == 'utf-8'
  669. " Math Symbols {{{2
  670. " (many of these symbols were contributed by Björn Winckler)
  671. if s:tex_conceal =~# 'm'
  672. let s:texMathList=[
  673. \ ['|' , '‖'],
  674. \ ['aleph' , 'ℵ'],
  675. \ ['amalg' , '∐'],
  676. \ ['angle' , '∠'],
  677. \ ['approx' , '≈'],
  678. \ ['ast' , '∗'],
  679. \ ['asymp' , '≍'],
  680. \ ['backslash' , '∖'],
  681. \ ['bigcap' , '∩'],
  682. \ ['bigcirc' , '○'],
  683. \ ['bigcup' , '∪'],
  684. \ ['bigodot' , '⊙'],
  685. \ ['bigoplus' , '⊕'],
  686. \ ['bigotimes' , '⊗'],
  687. \ ['bigsqcup' , '⊔'],
  688. \ ['bigtriangledown', '∇'],
  689. \ ['bigtriangleup' , '∆'],
  690. \ ['bigvee' , '⋁'],
  691. \ ['bigwedge' , '⋀'],
  692. \ ['bot' , '⊥'],
  693. \ ['bowtie' , '⋈'],
  694. \ ['bullet' , '•'],
  695. \ ['cap' , '∩'],
  696. \ ['cdot' , '·'],
  697. \ ['cdots' , '⋯'],
  698. \ ['circ' , '∘'],
  699. \ ['clubsuit' , '♣'],
  700. \ ['cong' , '≅'],
  701. \ ['coprod' , '∐'],
  702. \ ['copyright' , '©'],
  703. \ ['cup' , '∪'],
  704. \ ['dagger' , '†'],
  705. \ ['dashv' , '⊣'],
  706. \ ['ddagger' , '‡'],
  707. \ ['ddots' , '⋱'],
  708. \ ['diamond' , '⋄'],
  709. \ ['diamondsuit' , '♢'],
  710. \ ['div' , '÷'],
  711. \ ['doteq' , '≐'],
  712. \ ['dots' , '…'],
  713. \ ['downarrow' , '↓'],
  714. \ ['Downarrow' , '⇓'],
  715. \ ['ell' , 'ℓ'],
  716. \ ['emptyset' , '∅'],
  717. \ ['equiv' , '≡'],
  718. \ ['exists' , '∃'],
  719. \ ['flat' , '♭'],
  720. \ ['forall' , '∀'],
  721. \ ['frown' , '⁔'],
  722. \ ['ge' , '≥'],
  723. \ ['geq' , '≥'],
  724. \ ['gets' , '←'],
  725. \ ['gg' , '⟫'],
  726. \ ['hbar' , 'ℏ'],
  727. \ ['heartsuit' , '♡'],
  728. \ ['hookleftarrow' , '↩'],
  729. \ ['hookrightarrow' , '↪'],
  730. \ ['iff' , '⇔'],
  731. \ ['Im' , 'ℑ'],
  732. \ ['imath' , 'ɩ'],
  733. \ ['in' , '∈'],
  734. \ ['infty' , '∞'],
  735. \ ['int' , '∫'],
  736. \ ['jmath' , '𝚥'],
  737. \ ['land' , '∧'],
  738. \ ['lceil' , '⌈'],
  739. \ ['ldots' , '…'],
  740. \ ['le' , '≤'],
  741. \ ['left|' , '|'],
  742. \ ['left\\|' , '‖'],
  743. \ ['left(' , '('],
  744. \ ['left\[' , '['],
  745. \ ['left\\{' , '{'],
  746. \ ['leftarrow' , '←'],
  747. \ ['Leftarrow' , '⇐'],
  748. \ ['leftharpoondown', '↽'],
  749. \ ['leftharpoonup' , '↼'],
  750. \ ['leftrightarrow' , '↔'],
  751. \ ['Leftrightarrow' , '⇔'],
  752. \ ['leq' , '≤'],
  753. \ ['leq' , '≤'],
  754. \ ['lfloor' , '⌊'],
  755. \ ['ll' , '≪'],
  756. \ ['lmoustache' , '╭'],
  757. \ ['lor' , '∨'],
  758. \ ['mapsto' , '↦'],
  759. \ ['mid' , '∣'],
  760. \ ['models' , '╞'],
  761. \ ['mp' , '∓'],
  762. \ ['nabla' , '∇'],
  763. \ ['natural' , '♮'],
  764. \ ['ne' , '≠'],
  765. \ ['nearrow' , '↗'],
  766. \ ['neg' , '¬'],
  767. \ ['neq' , '≠'],
  768. \ ['ni' , '∋'],
  769. \ ['notin' , '∉'],
  770. \ ['nwarrow' , '↖'],
  771. \ ['odot' , '⊙'],
  772. \ ['oint' , '∮'],
  773. \ ['ominus' , '⊖'],
  774. \ ['oplus' , '⊕'],
  775. \ ['oslash' , '⊘'],
  776. \ ['otimes' , '⊗'],
  777. \ ['owns' , '∋'],
  778. \ ['P' , '¶'],
  779. \ ['parallel' , '║'],
  780. \ ['partial' , '∂'],
  781. \ ['perp' , '⊥'],
  782. \ ['pm' , '±'],
  783. \ ['prec' , '≺'],
  784. \ ['preceq' , '⪯'],
  785. \ ['prime' , '′'],
  786. \ ['prod' , '∏'],
  787. \ ['propto' , '∝'],
  788. \ ['rceil' , '⌉'],
  789. \ ['Re' , 'ℜ'],
  790. \ ['quad' , ' '],
  791. \ ['qquad' , ' '],
  792. \ ['rfloor' , '⌋'],
  793. \ ['right|' , '|'],
  794. \ ['right\\|' , '‖'],
  795. \ ['right)' , ')'],
  796. \ ['right]' , ']'],
  797. \ ['right\\}' , '}'],
  798. \ ['rightarrow' , '→'],
  799. \ ['Rightarrow' , '⇒'],
  800. \ ['rightleftharpoons', '⇌'],
  801. \ ['rmoustache' , '╮'],
  802. \ ['S' , '§'],
  803. \ ['searrow' , '↘'],
  804. \ ['setminus' , '∖'],
  805. \ ['sharp' , '♯'],
  806. \ ['sim' , '∼'],
  807. \ ['simeq' , '⋍'],
  808. \ ['smile' , '‿'],
  809. \ ['spadesuit' , '♠'],
  810. \ ['sqcap' , '⊓'],
  811. \ ['sqcup' , '⊔'],
  812. \ ['sqsubset' , '⊏'],
  813. \ ['sqsubseteq' , '⊑'],
  814. \ ['sqsupset' , '⊐'],
  815. \ ['sqsupseteq' , '⊒'],
  816. \ ['star' , '✫'],
  817. \ ['subset' , '⊂'],
  818. \ ['subseteq' , '⊆'],
  819. \ ['succ' , '≻'],
  820. \ ['succeq' , '⪰'],
  821. \ ['sum' , '∑'],
  822. \ ['supset' , '⊃'],
  823. \ ['supseteq' , '⊇'],
  824. \ ['surd' , '√'],
  825. \ ['swarrow' , '↙'],
  826. \ ['times' , '×'],
  827. \ ['to' , '→'],
  828. \ ['top' , '⊤'],
  829. \ ['triangle' , '∆'],
  830. \ ['triangleleft' , '⊲'],
  831. \ ['triangleright' , '⊳'],
  832. \ ['uparrow' , '↑'],
  833. \ ['Uparrow' , '⇑'],
  834. \ ['updownarrow' , '↕'],
  835. \ ['Updownarrow' , '⇕'],
  836. \ ['vdash' , '⊢'],
  837. \ ['vdots' , '⋮'],
  838. \ ['vee' , '∨'],
  839. \ ['wedge' , '∧'],
  840. \ ['wp' , '℘'],
  841. \ ['wr' , '≀']]
  842. if &ambw == "double" || exists("g:tex_usedblwidth")
  843. let s:texMathList= s:texMathList + [
  844. \ ['right\\rangle' , '〉'],
  845. \ ['left\\langle' , '〈']]
  846. else
  847. let s:texMathList= s:texMathList + [
  848. \ ['right\\rangle' , '>'],
  849. \ ['left\\langle' , '<']]
  850. endif
  851. for texmath in s:texMathList
  852. if texmath[0] =~# '\w$'
  853. exe "syn match texMathSymbol '\\\\".texmath[0]."\\>' contained conceal cchar=".texmath[1]
  854. else
  855. exe "syn match texMathSymbol '\\\\".texmath[0]."' contained conceal cchar=".texmath[1]
  856. endif
  857. endfor
  858. if &ambw == "double"
  859. syn match texMathSymbol '\\gg\>' contained conceal cchar=≫
  860. syn match texMathSymbol '\\ll\>' contained conceal cchar=≪
  861. else
  862. syn match texMathSymbol '\\gg\>' contained conceal cchar=⟫
  863. syn match texMathSymbol '\\ll\>' contained conceal cchar=⟪
  864. endif
  865. syn match texMathSymbol '\\hat{a}' contained conceal cchar=â
  866. syn match texMathSymbol '\\hat{A}' contained conceal cchar=Â
  867. syn match texMathSymbol '\\hat{c}' contained conceal cchar=ĉ
  868. syn match texMathSymbol '\\hat{C}' contained conceal cchar=Ĉ
  869. syn match texMathSymbol '\\hat{e}' contained conceal cchar=ê
  870. syn match texMathSymbol '\\hat{E}' contained conceal cchar=Ê
  871. syn match texMathSymbol '\\hat{g}' contained conceal cchar=ĝ
  872. syn match texMathSymbol '\\hat{G}' contained conceal cchar=Ĝ
  873. syn match texMathSymbol '\\hat{i}' contained conceal cchar=î
  874. syn match texMathSymbol '\\hat{I}' contained conceal cchar=Î
  875. syn match texMathSymbol '\\hat{o}' contained conceal cchar=ô
  876. syn match texMathSymbol '\\hat{O}' contained conceal cchar=Ô
  877. syn match texMathSymbol '\\hat{s}' contained conceal cchar=ŝ
  878. syn match texMathSymbol '\\hat{S}' contained conceal cchar=Ŝ
  879. syn match texMathSymbol '\\hat{u}' contained conceal cchar=û
  880. syn match texMathSymbol '\\hat{U}' contained conceal cchar=Û
  881. syn match texMathSymbol '\\hat{w}' contained conceal cchar=ŵ
  882. syn match texMathSymbol '\\hat{W}' contained conceal cchar=Ŵ
  883. syn match texMathSymbol '\\hat{y}' contained conceal cchar=ŷ
  884. syn match texMathSymbol '\\hat{Y}' contained conceal cchar=Ŷ
  885. " syn match texMathSymbol '\\bar{a}' contained conceal cchar=a̅
  886. syn match texMathSymbol '\\dot{B}' contained conceal cchar=Ḃ
  887. syn match texMathSymbol '\\dot{b}' contained conceal cchar=ḃ
  888. syn match texMathSymbol '\\dot{D}' contained conceal cchar=Ḋ
  889. syn match texMathSymbol '\\dot{d}' contained conceal cchar=ḋ
  890. syn match texMathSymbol '\\dot{F}' contained conceal cchar=Ḟ
  891. syn match texMathSymbol '\\dot{f}' contained conceal cchar=ḟ
  892. syn match texMathSymbol '\\dot{H}' contained conceal cchar=Ḣ
  893. syn match texMathSymbol '\\dot{h}' contained conceal cchar=ḣ
  894. syn match texMathSymbol '\\dot{M}' contained conceal cchar=Ṁ
  895. syn match texMathSymbol '\\dot{m}' contained conceal cchar=ṁ
  896. syn match texMathSymbol '\\dot{N}' contained conceal cchar=Ṅ
  897. syn match texMathSymbol '\\dot{n}' contained conceal cchar=ṅ
  898. syn match texMathSymbol '\\dot{P}' contained conceal cchar=Ṗ
  899. syn match texMathSymbol '\\dot{p}' contained conceal cchar=ṗ
  900. syn match texMathSymbol '\\dot{R}' contained conceal cchar=Ṙ
  901. syn match texMathSymbol '\\dot{r}' contained conceal cchar=ṙ
  902. syn match texMathSymbol '\\dot{S}' contained conceal cchar=Ṡ
  903. syn match texMathSymbol '\\dot{s}' contained conceal cchar=ṡ
  904. syn match texMathSymbol '\\dot{T}' contained conceal cchar=Ṫ
  905. syn match texMathSymbol '\\dot{t}' contained conceal cchar=ṫ
  906. syn match texMathSymbol '\\dot{W}' contained conceal cchar=Ẇ
  907. syn match texMathSymbol '\\dot{w}' contained conceal cchar=ẇ
  908. syn match texMathSymbol '\\dot{X}' contained conceal cchar=Ẋ
  909. syn match texMathSymbol '\\dot{x}' contained conceal cchar=ẋ
  910. syn match texMathSymbol '\\dot{Y}' contained conceal cchar=Ẏ
  911. syn match texMathSymbol '\\dot{y}' contained conceal cchar=ẏ
  912. syn match texMathSymbol '\\dot{Z}' contained conceal cchar=Ż
  913. syn match texMathSymbol '\\dot{z}' contained conceal cchar=ż
  914. syn match texMathSymbol '\\dot{C}' contained conceal cchar=Ċ
  915. syn match texMathSymbol '\\dot{c}' contained conceal cchar=ċ
  916. syn match texMathSymbol '\\dot{E}' contained conceal cchar=Ė
  917. syn match texMathSymbol '\\dot{e}' contained conceal cchar=ė
  918. syn match texMathSymbol '\\dot{G}' contained conceal cchar=Ġ
  919. syn match texMathSymbol '\\dot{g}' contained conceal cchar=ġ
  920. syn match texMathSymbol '\\dot{I}' contained conceal cchar=İ
  921. syn match texMathSymbol '\\dot{A}' contained conceal cchar=Ȧ
  922. syn match texMathSymbol '\\dot{a}' contained conceal cchar=ȧ
  923. syn match texMathSymbol '\\dot{O}' contained conceal cchar=Ȯ
  924. syn match texMathSymbol '\\dot{o}' contained conceal cchar=ȯ
  925. endif
  926. " Greek {{{2
  927. if s:tex_conceal =~# 'g'
  928. fun! s:Greek(group,pat,cchar)
  929. exe 'syn match '.a:group." '".a:pat."' contained conceal cchar=".a:cchar
  930. endfun
  931. call s:Greek('texGreek','\\alpha\>' ,'α')
  932. call s:Greek('texGreek','\\beta\>' ,'β')
  933. call s:Greek('texGreek','\\gamma\>' ,'γ')
  934. call s:Greek('texGreek','\\delta\>' ,'δ')
  935. call s:Greek('texGreek','\\epsilon\>' ,'ϵ')
  936. call s:Greek('texGreek','\\varepsilon\>' ,'ε')
  937. call s:Greek('texGreek','\\zeta\>' ,'ζ')
  938. call s:Greek('texGreek','\\eta\>' ,'η')
  939. call s:Greek('texGreek','\\theta\>' ,'θ')
  940. call s:Greek('texGreek','\\vartheta\>' ,'ϑ')
  941. call s:Greek('texGreek','\\iota\>' ,'ι')
  942. call s:Greek('texGreek','\\kappa\>' ,'κ')
  943. call s:Greek('texGreek','\\lambda\>' ,'λ')
  944. call s:Greek('texGreek','\\mu\>' ,'μ')
  945. call s:Greek('texGreek','\\nu\>' ,'ν')
  946. call s:Greek('texGreek','\\xi\>' ,'ξ')
  947. call s:Greek('texGreek','\\pi\>' ,'π')
  948. call s:Greek('texGreek','\\varpi\>' ,'ϖ')
  949. call s:Greek('texGreek','\\rho\>' ,'ρ')
  950. call s:Greek('texGreek','\\varrho\>' ,'ϱ')
  951. call s:Greek('texGreek','\\sigma\>' ,'σ')
  952. call s:Greek('texGreek','\\varsigma\>' ,'ς')
  953. call s:Greek('texGreek','\\tau\>' ,'τ')
  954. call s:Greek('texGreek','\\upsilon\>' ,'υ')
  955. call s:Greek('texGreek','\\phi\>' ,'ϕ')
  956. call s:Greek('texGreek','\\varphi\>' ,'φ')
  957. call s:Greek('texGreek','\\chi\>' ,'χ')
  958. call s:Greek('texGreek','\\psi\>' ,'ψ')
  959. call s:Greek('texGreek','\\omega\>' ,'ω')
  960. call s:Greek('texGreek','\\Gamma\>' ,'Γ')
  961. call s:Greek('texGreek','\\Delta\>' ,'Δ')
  962. call s:Greek('texGreek','\\Theta\>' ,'Θ')
  963. call s:Greek('texGreek','\\Lambda\>' ,'Λ')
  964. call s:Greek('texGreek','\\Xi\>' ,'Ξ')
  965. call s:Greek('texGreek','\\Pi\>' ,'Π')
  966. call s:Greek('texGreek','\\Sigma\>' ,'Σ')
  967. call s:Greek('texGreek','\\Upsilon\>' ,'Υ')
  968. call s:Greek('texGreek','\\Phi\>' ,'Φ')
  969. call s:Greek('texGreek','\\Chi\>' ,'Χ')
  970. call s:Greek('texGreek','\\Psi\>' ,'Ψ')
  971. call s:Greek('texGreek','\\Omega\>' ,'Ω')
  972. delfun s:Greek
  973. endif
  974. " Superscripts/Subscripts {{{2
  975. if s:tex_conceal =~# 's'
  976. if s:tex_fast =~# 's'
  977. syn region texSuperscript matchgroup=texDelimiter start='\^{' skip="\\\\\|\\[{}]" end='}' contained concealends contains=texSpecialChar,texSuperscripts,texStatement,texSubscript,texSuperscript,texMathMatcher
  978. syn region texSubscript matchgroup=texDelimiter start='_{' skip="\\\\\|\\[{}]" end='}' contained concealends contains=texSpecialChar,texSubscripts,texStatement,texSubscript,texSuperscript,texMathMatcher
  979. endif
  980. " s:SuperSub:
  981. fun! s:SuperSub(group,leader,pat,cchar)
  982. if a:pat =~# '^\\' || (a:leader == '\^' && a:pat =~# s:tex_superscripts) || (a:leader == '_' && a:pat =~# s:tex_subscripts)
  983. " call Decho("SuperSub: group<".a:group."> leader<".a:leader."> pat<".a:pat."> cchar<".a:cchar.">")
  984. exe 'syn match '.a:group." '".a:leader.a:pat."' contained conceal cchar=".a:cchar
  985. exe 'syn match '.a:group."s '".a:pat ."' contained conceal cchar=".a:cchar.' nextgroup='.a:group.'s'
  986. endif
  987. endfun
  988. call s:SuperSub('texSuperscript','\^','0','⁰')
  989. call s:SuperSub('texSuperscript','\^','1','¹')
  990. call s:SuperSub('texSuperscript','\^','2','²')
  991. call s:SuperSub('texSuperscript','\^','3','³')
  992. call s:SuperSub('texSuperscript','\^','4','⁴')
  993. call s:SuperSub('texSuperscript','\^','5','⁵')
  994. call s:SuperSub('texSuperscript','\^','6','⁶')
  995. call s:SuperSub('texSuperscript','\^','7','⁷')
  996. call s:SuperSub('texSuperscript','\^','8','⁸')
  997. call s:SuperSub('texSuperscript','\^','9','⁹')
  998. call s:SuperSub('texSuperscript','\^','a','ᵃ')
  999. call s:SuperSub('texSuperscript','\^','b','ᵇ')
  1000. call s:SuperSub('texSuperscript','\^','c','ᶜ')
  1001. call s:SuperSub('texSuperscript','\^','d','ᵈ')
  1002. call s:SuperSub('texSuperscript','\^','e','ᵉ')
  1003. call s:SuperSub('texSuperscript','\^','f','ᶠ')
  1004. call s:SuperSub('texSuperscript','\^','g','ᵍ')
  1005. call s:SuperSub('texSuperscript','\^','h','ʰ')
  1006. call s:SuperSub('texSuperscript','\^','i','ⁱ')
  1007. call s:SuperSub('texSuperscript','\^','j','ʲ')
  1008. call s:SuperSub('texSuperscript','\^','k','ᵏ')
  1009. call s:SuperSub('texSuperscript','\^','l','ˡ')
  1010. call s:SuperSub('texSuperscript','\^','m','ᵐ')
  1011. call s:SuperSub('texSuperscript','\^','n','ⁿ')
  1012. call s:SuperSub('texSuperscript','\^','o','ᵒ')
  1013. call s:SuperSub('texSuperscript','\^','p','ᵖ')
  1014. call s:SuperSub('texSuperscript','\^','r','ʳ')
  1015. call s:SuperSub('texSuperscript','\^','s','ˢ')
  1016. call s:SuperSub('texSuperscript','\^','t','ᵗ')
  1017. call s:SuperSub('texSuperscript','\^','u','ᵘ')
  1018. call s:SuperSub('texSuperscript','\^','v','ᵛ')
  1019. call s:SuperSub('texSuperscript','\^','w','ʷ')
  1020. call s:SuperSub('texSuperscript','\^','x','ˣ')
  1021. call s:SuperSub('texSuperscript','\^','y','ʸ')
  1022. call s:SuperSub('texSuperscript','\^','z','ᶻ')
  1023. call s:SuperSub('texSuperscript','\^','A','ᴬ')
  1024. call s:SuperSub('texSuperscript','\^','B','ᴮ')
  1025. call s:SuperSub('texSuperscript','\^','D','ᴰ')
  1026. call s:SuperSub('texSuperscript','\^','E','ᴱ')
  1027. call s:SuperSub('texSuperscript','\^','G','ᴳ')
  1028. call s:SuperSub('texSuperscript','\^','H','ᴴ')
  1029. call s:SuperSub('texSuperscript','\^','I','ᴵ')
  1030. call s:SuperSub('texSuperscript','\^','J','ᴶ')
  1031. call s:SuperSub('texSuperscript','\^','K','ᴷ')
  1032. call s:SuperSub('texSuperscript','\^','L','ᴸ')
  1033. call s:SuperSub('texSuperscript','\^','M','ᴹ')
  1034. call s:SuperSub('texSuperscript','\^','N','ᴺ')
  1035. call s:SuperSub('texSuperscript','\^','O','ᴼ')
  1036. call s:SuperSub('texSuperscript','\^','P','ᴾ')
  1037. call s:SuperSub('texSuperscript','\^','R','ᴿ')
  1038. call s:SuperSub('texSuperscript','\^','T','ᵀ')
  1039. call s:SuperSub('texSuperscript','\^','U','ᵁ')
  1040. call s:SuperSub('texSuperscript','\^','V','ⱽ')
  1041. call s:SuperSub('texSuperscript','\^','W','ᵂ')
  1042. call s:SuperSub('texSuperscript','\^',',','︐')
  1043. call s:SuperSub('texSuperscript','\^',':','︓')
  1044. call s:SuperSub('texSuperscript','\^',';','︔')
  1045. call s:SuperSub('texSuperscript','\^','+','⁺')
  1046. call s:SuperSub('texSuperscript','\^','-','⁻')
  1047. call s:SuperSub('texSuperscript','\^','<','˂')
  1048. call s:SuperSub('texSuperscript','\^','>','˃')
  1049. call s:SuperSub('texSuperscript','\^','/','ˊ')
  1050. call s:SuperSub('texSuperscript','\^','(','⁽')
  1051. call s:SuperSub('texSuperscript','\^',')','⁾')
  1052. call s:SuperSub('texSuperscript','\^','\.','˙')
  1053. call s:SuperSub('texSuperscript','\^','=','˭')
  1054. call s:SuperSub('texSubscript','_','0','₀')
  1055. call s:SuperSub('texSubscript','_','1','₁')
  1056. call s:SuperSub('texSubscript','_','2','₂')
  1057. call s:SuperSub('texSubscript','_','3','₃')
  1058. call s:SuperSub('texSubscript','_','4','₄')
  1059. call s:SuperSub('texSubscript','_','5','₅')
  1060. call s:SuperSub('texSubscript','_','6','₆')
  1061. call s:SuperSub('texSubscript','_','7','₇')
  1062. call s:SuperSub('texSubscript','_','8','₈')
  1063. call s:SuperSub('texSubscript','_','9','₉')
  1064. call s:SuperSub('texSubscript','_','a','ₐ')
  1065. call s:SuperSub('texSubscript','_','e','ₑ')
  1066. call s:SuperSub('texSubscript','_','h','ₕ')
  1067. call s:SuperSub('texSubscript','_','i','ᵢ')
  1068. call s:SuperSub('texSubscript','_','j','ⱼ')
  1069. call s:SuperSub('texSubscript','_','k','ₖ')
  1070. call s:SuperSub('texSubscript','_','l','ₗ')
  1071. call s:SuperSub('texSubscript','_','m','ₘ')
  1072. call s:SuperSub('texSubscript','_','n','ₙ')
  1073. call s:SuperSub('texSubscript','_','o','ₒ')
  1074. call s:SuperSub('texSubscript','_','p','ₚ')
  1075. call s:SuperSub('texSubscript','_','r','ᵣ')
  1076. call s:SuperSub('texSubscript','_','s','ₛ')
  1077. call s:SuperSub('texSubscript','_','t','ₜ')
  1078. call s:SuperSub('texSubscript','_','u','ᵤ')
  1079. call s:SuperSub('texSubscript','_','v','ᵥ')
  1080. call s:SuperSub('texSubscript','_','x','ₓ')
  1081. call s:SuperSub('texSubscript','_',',','︐')
  1082. call s:SuperSub('texSubscript','_','+','₊')
  1083. call s:SuperSub('texSubscript','_','-','₋')
  1084. call s:SuperSub('texSubscript','_','/','ˏ')
  1085. call s:SuperSub('texSubscript','_','(','₍')
  1086. call s:SuperSub('texSubscript','_',')','₎')
  1087. call s:SuperSub('texSubscript','_','\.','‸')
  1088. call s:SuperSub('texSubscript','_','r','ᵣ')
  1089. call s:SuperSub('texSubscript','_','v','ᵥ')
  1090. call s:SuperSub('texSubscript','_','x','ₓ')
  1091. call s:SuperSub('texSubscript','_','\\beta\>' ,'ᵦ')
  1092. call s:SuperSub('texSubscript','_','\\delta\>','ᵨ')
  1093. call s:SuperSub('texSubscript','_','\\phi\>' ,'ᵩ')
  1094. call s:SuperSub('texSubscript','_','\\gamma\>','ᵧ')
  1095. call s:SuperSub('texSubscript','_','\\chi\>' ,'ᵪ')
  1096. delfun s:SuperSub
  1097. endif
  1098. " Accented characters and Ligatures: {{{2
  1099. if s:tex_conceal =~# 'a'
  1100. if b:tex_stylish
  1101. syn match texAccent "\\[bcdvuH][^a-zA-Z@]"me=e-1
  1102. syn match texLigature "\\\([ijolL]\|ae\|oe\|ss\|AA\|AE\|OE\)[^a-zA-Z@]"me=e-1
  1103. syn match texLigature '--'
  1104. syn match texLigature '---'
  1105. else
  1106. fun! s:Accents(chr,...)
  1107. let i= 1
  1108. for accent in ["`","\\'","^",'"','\~','\.','=',"c","H","k","r","u","v"]
  1109. if i > a:0
  1110. break
  1111. endif
  1112. if strlen(a:{i}) == 0 || a:{i} == ' ' || a:{i} == '?'
  1113. let i= i + 1
  1114. continue
  1115. endif
  1116. if accent =~# '\a'
  1117. exe "syn match texAccent '".'\\'.accent.'\(\s*{'.a:chr.'}\|\s\+'.a:chr.'\)'."' conceal cchar=".a:{i}
  1118. else
  1119. exe "syn match texAccent '".'\\'.accent.'\s*\({'.a:chr.'}\|'.a:chr.'\)'."' conceal cchar=".a:{i}
  1120. endif
  1121. let i= i + 1
  1122. endfor
  1123. endfun
  1124. " \` \' \^ \" \~ \. \= \c \H \k \r \u \v
  1125. call s:Accents('a','à','á','â','ä','ã','ȧ','ā',' ',' ','ą','å','ă','ǎ')
  1126. call s:Accents('A','À','Á','Â','Ä','Ã','Ȧ','Ā',' ',' ','Ą','Å','Ă','Ǎ')
  1127. call s:Accents('c',' ','ć','ĉ',' ',' ','ċ',' ','ç',' ',' ',' ',' ','č')
  1128. call s:Accents('C',' ','Ć','Ĉ',' ',' ','Ċ',' ','Ç',' ',' ',' ',' ','Č')
  1129. call s:Accents('d',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','ď')
  1130. call s:Accents('D',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','Ď')
  1131. call s:Accents('e','è','é','ê','ë','ẽ','ė','ē','ȩ',' ','ę',' ','ĕ','ě')
  1132. call s:Accents('E','È','É','Ê','Ë','Ẽ','Ė','Ē','Ȩ',' ','Ę',' ','Ĕ','Ě')
  1133. call s:Accents('g',' ','ǵ','ĝ',' ',' ','ġ',' ','ģ',' ',' ',' ','ğ','ǧ')
  1134. call s:Accents('G',' ','Ǵ','Ĝ',' ',' ','Ġ',' ','Ģ',' ',' ',' ','Ğ','Ǧ')
  1135. call s:Accents('h',' ',' ','ĥ',' ',' ',' ',' ',' ',' ',' ',' ',' ','ȟ')
  1136. call s:Accents('H',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','Ȟ')
  1137. call s:Accents('i','ì','í','î','ï','ĩ','į','ī',' ',' ','į',' ','ĭ','ǐ')
  1138. call s:Accents('I','Ì','Í','Î','Ï','Ĩ','İ','Ī',' ',' ','Į',' ','Ĭ','Ǐ')
  1139. call s:Accents('J',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','ǰ')
  1140. call s:Accents('k',' ',' ',' ',' ',' ',' ',' ','ķ',' ',' ',' ',' ','ǩ')
  1141. call s:Accents('K',' ',' ',' ',' ',' ',' ',' ','Ķ',' ',' ',' ',' ','Ǩ')
  1142. call s:Accents('l',' ','ĺ','ľ',' ',' ',' ',' ','ļ',' ',' ',' ',' ','ľ')
  1143. call s:Accents('L',' ','Ĺ','Ľ',' ',' ',' ',' ','Ļ',' ',' ',' ',' ','Ľ')
  1144. call s:Accents('n',' ','ń',' ',' ','ñ',' ',' ','ņ',' ',' ',' ',' ','ň')
  1145. call s:Accents('N',' ','Ń',' ',' ','Ñ',' ',' ','Ņ',' ',' ',' ',' ','Ň')
  1146. call s:Accents('o','ò','ó','ô','ö','õ','ȯ','ō',' ','ő','ǫ',' ','ŏ','ǒ')
  1147. call s:Accents('O','Ò','Ó','Ô','Ö','Õ','Ȯ','Ō',' ','Ő','Ǫ',' ','Ŏ','Ǒ')
  1148. call s:Accents('r',' ','ŕ',' ',' ',' ',' ',' ','ŗ',' ',' ',' ',' ','ř')
  1149. call s:Accents('R',' ','Ŕ',' ',' ',' ',' ',' ','Ŗ',' ',' ',' ',' ','Ř')
  1150. call s:Accents('s',' ','ś','ŝ',' ',' ',' ',' ','ş',' ','ȿ',' ',' ','š')
  1151. call s:Accents('S',' ','Ś','Ŝ',' ',' ',' ',' ','Ş',' ',' ',' ',' ','Š')
  1152. call s:Accents('t',' ',' ',' ',' ',' ',' ',' ','ţ',' ',' ',' ',' ','ť')
  1153. call s:Accents('T',' ',' ',' ',' ',' ',' ',' ','Ţ',' ',' ',' ',' ','Ť')
  1154. call s:Accents('u','ù','ú','û','ü','ũ',' ','ū',' ','ű','ų','ů','ŭ','ǔ')
  1155. call s:Accents('U','Ù','Ú','Û','Ü','Ũ',' ','Ū',' ','Ű','Ų','Ů','Ŭ','Ǔ')
  1156. call s:Accents('w',' ',' ','ŵ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ')
  1157. call s:Accents('W',' ',' ','Ŵ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ')
  1158. call s:Accents('y','ỳ','ý','ŷ','ÿ','ỹ',' ',' ',' ',' ',' ',' ',' ',' ')
  1159. call s:Accents('Y','Ỳ','Ý','Ŷ','Ÿ','Ỹ',' ',' ',' ',' ',' ',' ',' ',' ')
  1160. call s:Accents('z',' ','ź',' ',' ',' ','ż',' ',' ',' ',' ',' ',' ','ž')
  1161. call s:Accents('Z',' ','Ź',' ',' ',' ','Ż',' ',' ',' ',' ',' ',' ','Ž')
  1162. call s:Accents('\\i','ì','í','î','ï','ĩ','į',' ',' ',' ',' ',' ','ĭ',' ')
  1163. " \` \' \^ \" \~ \. \= \c \H \k \r \u \v
  1164. delfun s:Accents
  1165. syn match texAccent '\\aa\>' conceal cchar=å
  1166. syn match texAccent '\\AA\>' conceal cchar=Å
  1167. syn match texAccent '\\o\>' conceal cchar=ø
  1168. syn match texAccent '\\O\>' conceal cchar=Ø
  1169. syn match texLigature '\\AE\>' conceal cchar=Æ
  1170. syn match texLigature '\\ae\>' conceal cchar=æ
  1171. syn match texLigature '\\oe\>' conceal cchar=œ
  1172. syn match texLigature '\\OE\>' conceal cchar=Œ
  1173. syn match texLigature '\\ss\>' conceal cchar=ß
  1174. syn match texLigature '--' conceal cchar=–
  1175. syn match texLigature '---' conceal cchar=—
  1176. endif
  1177. endif
  1178. endif
  1179. " ---------------------------------------------------------------------
  1180. " LaTeX synchronization: {{{1
  1181. syn sync maxlines=200
  1182. syn sync minlines=50
  1183. syn sync match texSyncStop groupthere NONE "%stopzone\>"
  1184. " Synchronization: {{{1
  1185. " The $..$ and $$..$$ make for impossible sync patterns
  1186. " (one can't tell if a "$$" starts or stops a math zone by itself)
  1187. " The following grouptheres coupled with minlines above
  1188. " help improve the odds of good syncing.
  1189. if !exists("g:tex_no_math")
  1190. syn sync match texSyncMathZoneA groupthere NONE "\\end{abstract}"
  1191. syn sync match texSyncMathZoneA groupthere NONE "\\end{center}"
  1192. syn sync match texSyncMathZoneA groupthere NONE "\\end{description}"
  1193. syn sync match texSyncMathZoneA groupthere NONE "\\end{enumerate}"
  1194. syn sync match texSyncMathZoneA groupthere NONE "\\end{itemize}"
  1195. syn sync match texSyncMathZoneA groupthere NONE "\\end{table}"
  1196. syn sync match texSyncMathZoneA groupthere NONE "\\end{tabular}"
  1197. syn sync match texSyncMathZoneA groupthere NONE "\\\(sub\)*section\>"
  1198. endif
  1199. " ---------------------------------------------------------------------
  1200. " Highlighting: {{{1
  1201. " Define the default highlighting. {{{1
  1202. if !exists("skip_tex_syntax_inits")
  1203. " TeX highlighting groups which should share similar highlighting
  1204. if !exists("g:tex_no_error")
  1205. if !exists("g:tex_no_math")
  1206. hi def link texBadMath texError
  1207. hi def link texBadPar texBadMath
  1208. hi def link texMathDelimBad texError
  1209. hi def link texMathError texError
  1210. if !b:tex_stylish
  1211. hi def link texOnlyMath texError
  1212. endif
  1213. endif
  1214. hi def link texError Error
  1215. endif
  1216. hi texBoldStyle gui=bold cterm=bold
  1217. hi texItalStyle gui=italic cterm=italic
  1218. hi texBoldItalStyle gui=bold,italic cterm=bold,italic
  1219. hi texItalBoldStyle gui=bold,italic cterm=bold,italic
  1220. hi def link texEmphStyle texItalStyle
  1221. hi def link texCite texRefZone
  1222. hi def link texDefCmd texDef
  1223. hi def link texDefName texDef
  1224. hi def link texDocType texCmdName
  1225. hi def link texDocTypeArgs texCmdArgs
  1226. hi def link texInputFileOpt texCmdArgs
  1227. hi def link texInputCurlies texDelimiter
  1228. hi def link texLigature texSpecialChar
  1229. if !exists("g:tex_no_math")
  1230. hi def link texMathDelimSet1 texMathDelim
  1231. hi def link texMathDelimSet2 texMathDelim
  1232. hi def link texMathDelimKey texMathDelim
  1233. hi def link texMathMatcher texMath
  1234. hi def link texAccent texStatement
  1235. hi def link texGreek texStatement
  1236. hi def link texSuperscript texStatement
  1237. hi def link texSubscript texStatement
  1238. hi def link texSuperscripts texSuperscript
  1239. hi def link texSubscripts texSubscript
  1240. hi def link texMathSymbol texStatement
  1241. hi def link texMathZoneV texMath
  1242. hi def link texMathZoneW texMath
  1243. hi def link texMathZoneX texMath
  1244. hi def link texMathZoneY texMath
  1245. hi def link texMathZoneV texMath
  1246. hi def link texMathZoneZ texMath
  1247. endif
  1248. hi def link texBeginEnd texCmdName
  1249. hi def link texBeginEndName texSection
  1250. hi def link texSpaceCode texStatement
  1251. hi def link texStyleStatement texStatement
  1252. hi def link texTypeSize texType
  1253. hi def link texTypeStyle texType
  1254. " Basic TeX highlighting groups
  1255. hi def link texCmdArgs Number
  1256. hi def link texCmdName Statement
  1257. hi def link texComment Comment
  1258. hi def link texDef Statement
  1259. hi def link texDefParm Special
  1260. hi def link texDelimiter Delimiter
  1261. hi def link texInput Special
  1262. hi def link texInputFile Special
  1263. hi def link texLength Number
  1264. hi def link texMath Special
  1265. hi def link texMathDelim Statement
  1266. hi def link texMathOper Operator
  1267. hi def link texNewCmd Statement
  1268. hi def link texNewEnv Statement
  1269. hi def link texOption Number
  1270. hi def link texRefZone Special
  1271. hi def link texSection PreCondit
  1272. hi def link texSpaceCodeChar Special
  1273. hi def link texSpecialChar SpecialChar
  1274. hi def link texStatement Statement
  1275. hi def link texString String
  1276. hi def link texTodo Todo
  1277. hi def link texType Type
  1278. hi def link texZone PreCondit
  1279. endif
  1280. " Cleanup: {{{1
  1281. delc TexFold
  1282. unlet s:extfname
  1283. let b:current_syntax = "tex"
  1284. let &cpo = s:keepcpo
  1285. unlet s:keepcpo
  1286. " vim: ts=8 fdm=marker