Add support for minted package
Supports c, csharp and python out of the box. More languages may be added to the list `g:vimtex_syntax_minted` (see help for more info). Resolves: #167
This commit is contained in:
parent
0698403dfc
commit
5a4664ff41
@ -61,6 +61,54 @@ syntax region texZone
|
||||
\ contains=texBeginEnd,@DOT
|
||||
let b:current_syntax = 'tex'
|
||||
|
||||
" }}}1
|
||||
" {{{1 Nested syntax highlighting for minted
|
||||
let s:minted = get(g:, 'vimtex_syntax_minted', [
|
||||
\ {
|
||||
\ 'lang' : 'c',
|
||||
\ },
|
||||
\ {
|
||||
\ 'lang' : 'csharp',
|
||||
\ 'syntax' : 'cs'
|
||||
\ },
|
||||
\ {
|
||||
\ 'lang' : 'python',
|
||||
\ 'ignore' : [
|
||||
\ 'pythonEscape',
|
||||
\ 'pythonBEscape',
|
||||
\ ],
|
||||
\ }
|
||||
\])
|
||||
|
||||
for entry in s:minted
|
||||
let lang = entry.lang
|
||||
let syntax = get(entry, 'syntax', lang)
|
||||
|
||||
unlet b:current_syntax
|
||||
execute 'syntax include @' . toupper(lang) 'syntax/' . syntax . '.vim'
|
||||
|
||||
if has_key(entry, 'ignore')
|
||||
execute 'syntax cluster' toupper(lang)
|
||||
\ 'remove=' . join(entry.ignore, ',')
|
||||
endif
|
||||
|
||||
execute 'syntax region texZone'
|
||||
\ 'start="\\begin{minted}\_[^}]\{-}{' . lang . '}"rs=s'
|
||||
\ 'end="\\end{minted}"re=e'
|
||||
\ 'keepend'
|
||||
\ 'transparent'
|
||||
\ 'contains=texMinted,@' . toupper(lang)
|
||||
endfor
|
||||
let b:current_syntax = 'tex'
|
||||
|
||||
syntax match texMinted "\\begin{minted}\_[^}]\{-}{\w\+}"
|
||||
\ contains=texBeginEnd,texMintedName
|
||||
syntax match texMinted "\\end{minted}"
|
||||
\ contains=texBeginEnd
|
||||
syntax match texMintedName "{\w\+}"
|
||||
|
||||
highlight link texMintedName texBeginEndName
|
||||
|
||||
" }}}1
|
||||
|
||||
" vim: fdm=marker sw=2
|
||||
|
@ -659,6 +659,23 @@ Options~
|
||||
|
||||
Default value: ''
|
||||
|
||||
*g:vimtex_syntax_minted*
|
||||
A list that contains dictionaries for each supported language. A language
|
||||
dictionary should be something similar to the following: >
|
||||
|
||||
{
|
||||
'lang' : NAME,
|
||||
'syntax' : SYNTAX-FILE-NAME,
|
||||
'ignored' : IGNORED-GROUPS
|
||||
}
|
||||
<
|
||||
If the `syntax` entry is not present, then the `lang` entry is used as name of
|
||||
the syntax file. The `ignored` entry is also optional, and is used to name
|
||||
syntax groups to ignore in the minted region.
|
||||
|
||||
Default value:
|
||||
Please see `VIMTEX/after/syntax/tex.vim` for the default value.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
Commands~
|
||||
*vimtex-commands*
|
||||
@ -998,8 +1015,9 @@ highlighting. However, |vimtex| does add some minor improvements:
|
||||
|
||||
- Support for `biblatex` and `natbib` package
|
||||
- Support for `cleveref` package
|
||||
- Support for `listings` package
|
||||
- Improved highlighting of `listings` package
|
||||
- Nested syntax highlighting for `dot2tex`
|
||||
- Nested syntax highlighting for `minted` (see |g:vimtex_syntax_minted|)
|
||||
|
||||
==============================================================================
|
||||
NAVIGATION *vimtex-navigation*
|
||||
|
57
test/test-syntax/test-syntax.tex
Normal file
57
test/test-syntax/test-syntax.tex
Normal file
@ -0,0 +1,57 @@
|
||||
\documentclass{article}
|
||||
\usepackage{minted}
|
||||
\begin{document}
|
||||
|
||||
\begin{lstlisting}
|
||||
testing
|
||||
\end{lstlisting}
|
||||
|
||||
\begin{align}
|
||||
f(x) = 0
|
||||
\end{align}
|
||||
|
||||
\begin{equation}
|
||||
f(x) = 0
|
||||
\end{equation}
|
||||
|
||||
\begin{quote}
|
||||
test
|
||||
\end{quote}
|
||||
|
||||
\begin{dot2tex}
|
||||
graph graphname {
|
||||
a -- b;
|
||||
b -- c;
|
||||
b -- d;
|
||||
d -- a;
|
||||
}
|
||||
\end{dot2tex}
|
||||
|
||||
\begin{minted}{python}
|
||||
def function(arg):
|
||||
pass
|
||||
\end{minted}
|
||||
|
||||
\begin{minted}{c}
|
||||
int main() {
|
||||
printf("hello, world");
|
||||
return 0;
|
||||
}
|
||||
\end{minted}
|
||||
|
||||
\begin{minted}[mathescape,
|
||||
linenos,
|
||||
numbersep=5pt,
|
||||
gobble=2,
|
||||
frame=lines,
|
||||
framesep=2mm]{csharp}
|
||||
string title = "This is a Unicode π in the sky"
|
||||
/*
|
||||
Defined as $\pi=\lim_{n\to\infty}\frac{P_n}{d}$ where $P$ is the perimeter
|
||||
of an $n$-sided regular polygon circumscribing a
|
||||
circle of diameter $d$.
|
||||
*/
|
||||
const double pi = 3.1415926535
|
||||
\end{minted}
|
||||
|
||||
\end{document}
|
Loading…
Reference in New Issue
Block a user