Merge branch 'master' into math-mappings

This commit is contained in:
Karl Yngve Lervåg 2015-06-21 21:04:39 +02:00
commit b9c438d6ee
11 changed files with 496 additions and 180 deletions

View File

@ -38,26 +38,77 @@ syntax region texRefRangeEnd
highlight link texRefRangeStart texRefZone
highlight link texRefRangeEnd texRefZone
" Support for listings package
" {{{1 Support for listings package
syntax region texZone
\ start="\\begin{lstlisting}"
\ end="\\end{lstlisting}\|%stopzone\>"
\ start="\\begin{lstlisting}"rs=s
\ end="\\end{lstlisting}\|%stopzone\>"re=e
\ keepend
\ contains=texBeginEnd
syntax match texInputFile
\ "\\lstinputlisting\s*\(\[.*\]\)\={.\{-}}"
\ contains=texStatement,texInputCurlies,texInputFileOpt
syntax match texZone "\\lstinline\s*\(\[.*\]\)\={.\{-}}"
" Nested syntax highlighting for dot
" }}}1
" {{{1 Nested syntax highlighting for dot
unlet b:current_syntax
syntax include @DOT syntax/dot.vim
syntax region texZone
\ matchgroup=texRefZone
\ start="\\begin{dot2tex}"
\ matchgroup=texRefZone
\ end="\\end{dot2tex}"
\ start="\\begin{dot2tex}"rs=s
\ end="\\end{dot2tex}"re=e
\ keepend
\ transparent
\ contains=@DOT
\ 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

View File

@ -154,7 +154,7 @@ function! s:init_buffer() " {{{1
endif
"
" Finally we define commands and mappings
" Define commands and mappings
"
" Define commands
@ -163,6 +163,16 @@ function! s:init_buffer() " {{{1
" Define mappings
nnoremap <buffer> <plug>(vimtex-info) :call vimtex#info(0)<cr>
"
" Attach autocommands
"
augroup vimtex
au!
au BufFilePre <buffer> call s:filename_changed_pre()
au BufFilePost <buffer> call s:filename_changed_post()
augroup END
endfunction
" }}}1
@ -243,6 +253,7 @@ function! s:get_main() " {{{1
return expand('%:p')
endfunction
" }}}1
function! s:get_main_recurse(file) " {{{1
"
" Check if file is readable
@ -314,6 +325,39 @@ endfunction
" }}}1
"
" Detect file name changes
"
function! s:filename_changed_pre() " {{{1
let thisfile = fnamemodify(expand('%'), ':p')
let s:filename_changed = thisfile ==# b:vimtex.tex
let s:filename_old = b:vimtex.base
endfunction
" }}}1
function! s:filename_changed_post() " {{{1
if s:filename_changed
let b:vimtex.tex = fnamemodify(expand('%'), ':p')
let b:vimtex.base = fnamemodify(b:vimtex.tex, ':t')
let b:vimtex.name = fnamemodify(b:vimtex.tex, ':t:r')
let message = ['vimtex: ',
\ ['VimtexWarning', 'Filename change detected!'],
\ "\n Old filename: ", ['VimtexInfo', s:filename_old],
\ "\n New filename: ", ['VimtexInfo', b:vimtex.base]]
if b:vimtex.pid
let message += ["\n latexmk process: ",
\ ['VimtexInfo', b:vimtex.pid],
\ ['VimtexWarning', ' killed!']]
call vimtex#latexmk#stop()
endif
call vimtex#echo#status(message)
endif
endfunction
" }}}1
"
" Simple utility features
"

View File

@ -65,6 +65,71 @@ function! vimtex#complete#init_script() " {{{1
" s:extract_inputs.
"
let s:label_cache = {}
"
" Define list for converting stuff like '\IeC{\"u}' to corresponding unicode
" symbols (with s:tex2unicode()).
"
let s:tex2unicode_list = map([
\ ['\\''A}' , 'Á'],
\ ['\\`A}' , 'À'],
\ ['\\^A}' , 'À'],
\ ['\\¨A}' , 'Ä'],
\ ['\\"A}' , 'Ä'],
\ ['\\''a}' , 'á'],
\ ['\\`a}' , 'à'],
\ ['\\^a}' , 'à'],
\ ['\\¨a}' , 'ä'],
\ ['\\"a}' , 'ä'],
\ ['\\\~a}' , 'ã'],
\ ['\\''E}' , 'É'],
\ ['\\`E}' , 'È'],
\ ['\\^E}' , 'Ê'],
\ ['\\¨E}' , 'Ë'],
\ ['\\"E}' , 'Ë'],
\ ['\\''e}' , 'é'],
\ ['\\`e}' , 'è'],
\ ['\\^e}' , 'ê'],
\ ['\\¨e}' , 'ë'],
\ ['\\"e}' , 'ë'],
\ ['\\''I}' , 'Í'],
\ ['\\`I}' , 'Î'],
\ ['\\^I}' , 'Ì'],
\ ['\\¨I}' , 'Ï'],
\ ['\\"I}' , 'Ï'],
\ ['\\''i}' , 'í'],
\ ['\\`i}' , 'î'],
\ ['\\^i}' , 'ì'],
\ ['\\¨i}' , 'ï'],
\ ['\\"i}' , 'ï'],
\ ['\\''{\?\\i }' , 'í'],
\ ['\\''O}' , 'Ó'],
\ ['\\`O}' , 'Ò'],
\ ['\\^O}' , 'Ô'],
\ ['\\¨O}' , 'Ö'],
\ ['\\"O}' , 'Ö'],
\ ['\\''o}' , 'ó'],
\ ['\\`o}' , 'ò'],
\ ['\\^o}' , 'ô'],
\ ['\\¨o}' , 'ö'],
\ ['\\"o}' , 'ö'],
\ ['\\o }' , 'ø'],
\ ['\\''U}' , 'Ú'],
\ ['\\`U}' , 'Ù'],
\ ['\\^U}' , 'Û'],
\ ['\\¨U}' , 'Ü'],
\ ['\\"U}' , 'Ü'],
\ ['\\''u}' , 'ú'],
\ ['\\`u}' , 'ù'],
\ ['\\^u}' , 'û'],
\ ['\\¨u}' , 'ü'],
\ ['\\"u}' , 'ü'],
\ ['\\`N}' , 'Ǹ'],
\ ['\\\~N}' , 'Ñ'],
\ ['\\''n}' , 'ń'],
\ ['\\`n}' , 'ǹ'],
\ ['\\\~n}' , 'ñ'],
\], '[''\C\(\\IeC\s*{\)\?'' . v:val[0], v:val[1]]')
endfunction
" The variable s:bstfile must be defined in script level in order to expand
@ -357,22 +422,26 @@ function! s:labels_extract(file) " {{{1
"
" \newlabel{name}{{number}{page}.*}.*
"
" or
"
" \newlabel{name}{{text {number}}{page}.*}.*
"
" and returns a list of [name, number, page] tuples.
"
let matches = []
let lines = readfile(a:file)
let lines = filter(lines, 'v:val =~# ''\\newlabel{''')
let lines = filter(lines, 'v:val !~# ''@cref''')
let lines = map(lines, 'vimtex#util#convert_back(v:val)')
let lines = map(lines, 's:tex2unicode(v:val)')
for line in lines
let tree = s:tex2tree(line)
if type(tree[2][0]) == type([])
\ && !empty(tree[2][0])
call add(matches, [
\ s:tree2tex(tree[1][0]),
\ s:tree2tex(tree[2][0][0]),
\ s:tree2tex(tree[2][1][0]),
\ ])
let tree = s:tex2tree(line)[1:]
let name = remove(tree, 0)[0]
if type(tree[0]) == type([]) && !empty(tree[0])
let number = len(tree[0][0]) > 1
\ ? tree[0][0][1][0]
\ : tree[0][0][0]
let page = tree[0][1][0]
call add(matches, [name, number, page])
endif
endfor
return matches
@ -433,12 +502,20 @@ function! s:tex2tree(str) " {{{1
endfunction
" }}}1
function! s:tree2tex(tree) " {{{1
if type(a:tree) == type('')
return a:tree
else
return '{' . join(map(a:tree, 's:tree2tex(v:val)'), '') . '}'
endif
function! s:tex2unicode(line) " {{{1
"
" Substitute stuff like '\IeC{\"u}' to corresponding unicode symbols
"
let line = a:line
for [pat, symbol] in s:tex2unicode_list
let line = substitute(line, pat, symbol, 'g')
endfor
"
" There might be some missing conversions, which might be fixed by the last
" substitution
"
return substitute(line, '\C\(\\IeC\s*{\)\?\\.\(.\)}', '\1', 'g')
endfunction
" }}}1

View File

@ -12,6 +12,7 @@ function! vimtex#echo#init_script() " {{{1
highlight link VimtexMsg ModeMsg
highlight link VimtexSuccess Statement
highlight link VimtexWarning WarningMsg
highlight link VimtexInfo Question
endfunction
" }}}1

View File

@ -35,19 +35,6 @@ function! vimtex#fold#init_script() " {{{1
" Define some script variables
let s:parts = '\v^\s*(\\|\% Fake)(' . join(g:vimtex_fold_parts, '|') . ')>'
let s:secs = '\v^\s*(\\|\% Fake)(' . join(g:vimtex_fold_sections, '|') . ')>'
" For automatic folding with foldmethod=expr:
" The foldexpr function returns "=" for most lines, which means it can
" become slow for large files. The following is a hack that is based on
" this reply to a discussion on the Vim Developer list:
" http://permalink.gmane.org/gmane.editors.vim.devel/14100
if g:vimtex_fold_automatic
augroup latex_fold
autocmd!
autocmd InsertEnter *.tex call FdmSave()
autocmd InsertLeave *.tex call FdmRestore()
augroup END
endif
endfunction
" }}}1
@ -66,14 +53,27 @@ function! vimtex#fold#init_buffer() " {{{1
" Define commands
command! -buffer VimtexRefreshFolds call vimtex#fold#refresh('zx')
" Set options for automatic/manual mode
" Set options for automatic/manual folding mode
if g:vimtex_fold_automatic
nnoremap <silent><buffer> u :call FdmSave()<cr>u:call FdmRestore()<cr>
" For automatic folding with foldmethod=expr:
" The foldexpr function returns "=" for most lines, which means it can
" become slow for large files. The following is a hack that is based on
" this reply to a discussion on the Vim Developer list:
" http://permalink.gmane.org/gmane.editors.vim.devel/14100
if g:vimtex_fold_automatic
augroup vimtex_fold_automatic
autocmd!
autocmd InsertEnter <buffer> call FdmSave()
autocmd InsertLeave <buffer> call FdmRestore()
augroup END
endif
else
augroup latex_fold
augroup vimtex_fold_manual
autocmd!
autocmd CursorMoved *.tex call vimtex#fold#refresh('zx')
autocmd CursorMoved *.tex autocmd! latex_fold
autocmd CursorMoved <buffer> call vimtex#fold#refresh('zx')
autocmd CursorMoved <buffer> autocmd! vimtex_fold_manual
augroup END
endif
endfunction

View File

@ -13,6 +13,8 @@ function! vimtex#latexmk#init_options() " {{{1
call vimtex#util#set_default('g:vimtex_latexmk_callback', 1)
call vimtex#util#set_default('g:vimtex_latexmk_continuous', 1)
call vimtex#util#set_default('g:vimtex_latexmk_options', '-pdf')
call vimtex#util#set_default('g:vimtex_latexmk_progname',
\ get(v:, 'progpath', get(v:, 'progname')))
call vimtex#util#set_default('g:vimtex_quickfix_autojump', '0')
call vimtex#util#set_default('g:vimtex_quickfix_ignore_all_warnings', 0)
call vimtex#util#set_default('g:vimtex_quickfix_ignored_warnings', [])
@ -28,7 +30,7 @@ function! vimtex#latexmk#init_script() " {{{1
" Ensure that all latexmk processes are stopped when vim exits
if g:vimtex_latexmk_continuous
augroup latex_latexmk
augroup vimtex_latexmk
autocmd!
autocmd VimLeave * call vimtex#latexmk#stop_all()
augroup END
@ -43,7 +45,7 @@ function! vimtex#latexmk#init_buffer() " {{{1
compiler latexmk
" Initialize system PID
let b:vimtex.pid = get(b:vimtex, 'pid', 0)
call s:latexmk_init_pid()
" Define commands
command! -buffer VimtexCompile call vimtex#latexmk#compile()
@ -73,8 +75,9 @@ function! vimtex#latexmk#init_buffer() " {{{1
" Kill running latexmk process if all buffers for a latex project are closed
if g:vimtex_latexmk_continuous
augroup latex_latexmk
autocmd BufUnload <buffer> call s:stop_buffer()
augroup vimtex_latexmk
autocmd BufLeave <buffer> call s:buffer_left()
autocmd BufDelete <buffer> call s:buffer_deleted()
augroup END
endif
endfunction
@ -206,6 +209,7 @@ endfunction
" }}}1
function! vimtex#latexmk#errors_open(force) " {{{1
if !exists('b:vimtex') | return | endif
cclose
let log = b:vimtex.log()
@ -268,7 +272,7 @@ function! vimtex#latexmk#output() " {{{1
silent exe 'split ' . tmp
" Better automatic update
augroup tmp_update
augroup vimtex_tmp_update
autocmd!
autocmd BufEnter * silent! checktime
autocmd CursorHold * silent! checktime
@ -276,7 +280,7 @@ function! vimtex#latexmk#output() " {{{1
autocmd CursorMoved * silent! checktime
autocmd CursorMovedI * silent! checktime
augroup END
silent exe 'autocmd! BufDelete ' . tmp . ' augroup! tmp_update'
silent exe 'autocmd! BufDelete ' . tmp . ' augroup! vimtex_tmp_update'
" Set some mappings
nnoremap <buffer> <silent> q :bwipeout<cr>
@ -392,10 +396,10 @@ function! s:latexmk_build_cmd() " {{{1
endif
if g:vimtex_latexmk_callback && has('clientserver')
let success = v:progname
let success = g:vimtex_latexmk_progname
let success .= ' --servername ' . v:servername
let success .= ' --remote-expr \"vimtex\#latexmk\#callback(1)\"'
let failed = v:progname
let failed = g:vimtex_latexmk_progname
let failed .= ' --servername ' . v:servername
let failed .= ' --remote-expr \"vimtex\#latexmk\#callback(0)\"'
let cmd .= vimtex#latexmk#add_option('success_cmd', success)
@ -427,13 +431,44 @@ function! s:latexmk_build_cmd() " {{{1
endfunction
" }}}1
function! s:latexmk_init_pid() " {{{1
"
" First see if the PID is already defined
"
let b:vimtex.pid = get(b:vimtex, 'pid', 0)
"
" If the PID is 0, then search for existing processes
"
if b:vimtex.pid ==# 0
if has('win32')
"
" PASS - don't know how to do this on Windows yet.
"
return
else
"
" Use pgrep combined with /proc/PID/cwd to search for existing process
"
for l:pid in split(system(
\ 'pgrep -f "^perl.*latexmk.*' . b:vimtex.base . '"'), "\n")
let path = resolve('/proc/' . l:pid . '/cwd') . '/' . b:vimtex.base
if path ==# b:vimtex.tex
let b:vimtex.pid = str2nr(l:pid)
return
endif
endfor
endif
endif
endfunction
function! s:latexmk_set_pid() " {{{1
if has('win32')
let pidcmd = 'tasklist /fi "imagename eq latexmk.exe"'
let pidinfo = split(system(pidcmd), '\n')[-1]
let b:vimtex.pid = split(pidinfo,'\s\+')[1]
let b:vimtex.pid = str2nr(split(pidinfo,'\s\+')[1])
else
let b:vimtex.pid = system('pgrep -nf "^perl.*latexmk"')[:-2]
let b:vimtex.pid = str2nr(system('pgrep -nf "^perl.*latexmk"')[:-2])
endif
endfunction
@ -454,6 +489,34 @@ endfunction
" }}}1
function! s:buffer_left() " {{{1
"
" Store buffer variables as script variables so they are available if the
" buffer is deleted. This is done in order to be able to kill remaining
" latexmk processes.
"
let s:vimtex = b:vimtex
let s:vimtex_id = b:vimtex_id
endfunction
function! s:buffer_deleted() " {{{1
if s:vimtex.pid == 0 | return | endif
"
" The buffer is deleted, so we must kill the remaining latexmk process if the
" current buffer was the last open buffer for the current LaTeX blob/project.
"
" The buffer variables has already been stored as script variables by
" s:buffer_left().
"
if len(filter(
\ map(filter(range(1, bufnr('$')), 'buflisted(v:val)'),
\ 'getbufvar(v:val, ''vimtex_id'', -1)'),
\ 'v:val == s:vimtex_id')) == 1
silent call s:latexmk_kill(s:vimtex)
endif
endfunction
function! s:log_contains_error(logfile) " {{{1
let lines = readfile(a:logfile)
let lines = filter(lines, 'v:val =~# ''^.*:\d\+: ''')
@ -463,35 +526,6 @@ function! s:log_contains_error(logfile) " {{{1
return len(lines) > 0
endfunction
function! s:stop_buffer() " {{{1
"
" Only run if latex variables are set
"
if !exists('b:vimtex') | return | endif
"
" Only stop if latexmk is running
"
if b:vimtex.pid !=# 0
"
" Count the number of buffers that point to current latex blob
"
let n = 0
for b in filter(range(1, bufnr('$')), 'buflisted(v:val)')
if b:vimtex_id == getbufvar(b, 'vimtex_id', -1)
let n += 1
endif
endfor
"
" Only stop if current buffer is the last for current latex blob
"
if n == 1
silent call vimtex#latexmk#stop()
endif
endif
endfunction
function! s:check_system_compatibility() " {{{1
"
" Check for required executables

View File

@ -17,7 +17,7 @@ function! vimtex#motion#init_script() " {{{1
" Highlight matching parens ($, (), ...)
if g:vimtex_motion_matchparen
augroup latex_motion
augroup vimtex_motion
autocmd!
" Disable matchparen autocommands
autocmd BufEnter *.tex

View File

@ -24,66 +24,6 @@ function! vimtex#util#init_script() " {{{1
\ '\\\Cright\s*\%([^\\a-zA-Z0-9]\|\\.\|\\\a*\)',
\ '\\\cbigg\?\()\|\]\|\\}\)',
\ ]
let s:convert_back_list = map([
\ ['\\''A}' , 'Á'],
\ ['\\`A}' , 'À'],
\ ['\\^A}' , 'À'],
\ ['\\¨A}' , 'Ä'],
\ ['\\"A}' , 'Ä'],
\ ['\\''a}' , 'á'],
\ ['\\`a}' , 'à'],
\ ['\\^a}' , 'à'],
\ ['\\¨a}' , 'ä'],
\ ['\\"a}' , 'ä'],
\ ['\\''E}' , 'É'],
\ ['\\`E}' , 'È'],
\ ['\\^E}' , 'Ê'],
\ ['\\¨E}' , 'Ë'],
\ ['\\"E}' , 'Ë'],
\ ['\\''e}' , 'é'],
\ ['\\`e}' , 'è'],
\ ['\\^e}' , 'ê'],
\ ['\\¨e}' , 'ë'],
\ ['\\"e}' , 'ë'],
\ ['\\''I}' , 'Í'],
\ ['\\`I}' , 'Î'],
\ ['\\^I}' , 'Ì'],
\ ['\\¨I}' , 'Ï'],
\ ['\\"I}' , 'Ï'],
\ ['\\''i}' , 'í'],
\ ['\\`i}' , 'î'],
\ ['\\^i}' , 'ì'],
\ ['\\¨i}' , 'ï'],
\ ['\\"i}' , 'ï'],
\ ['\\''{\?\\i }' , 'í'],
\ ['\\''O}' , 'Ó'],
\ ['\\`O}' , 'Ò'],
\ ['\\^O}' , 'Ô'],
\ ['\\¨O}' , 'Ö'],
\ ['\\"O}' , 'Ö'],
\ ['\\''o}' , 'ó'],
\ ['\\`o}' , 'ò'],
\ ['\\^o}' , 'ô'],
\ ['\\¨o}' , 'ö'],
\ ['\\"o}' , 'ö'],
\ ['\\o }' , 'ø'],
\ ['\\''U}' , 'Ú'],
\ ['\\`U}' , 'Ù'],
\ ['\\^U}' , 'Û'],
\ ['\\¨U}' , 'Ü'],
\ ['\\"U}' , 'Ü'],
\ ['\\''u}' , 'ú'],
\ ['\\`u}' , 'ù'],
\ ['\\^u}' , 'û'],
\ ['\\¨u}' , 'ü'],
\ ['\\"u}' , 'ü'],
\ ['\\`N}' , 'Ǹ'],
\ ['\\\~N}' , 'Ñ'],
\ ['\\''n}' , 'ń'],
\ ['\\`n}' , 'ǹ'],
\ ['\\\~n}' , 'ñ'],
\], '[''\C\(\\IeC\s*{\)\?'' . v:val[0], v:val[1]]')
endfunction
" }}}1
@ -92,23 +32,6 @@ endfunction
" }}}1
function! vimtex#util#convert_back(line) " {{{1
"
" Substitute stuff like '\IeC{\"u}' to corresponding unicode symbols
"
let line = a:line
for [pat, symbol] in s:convert_back_list
let line = substitute(line, pat, symbol, 'g')
endfor
"
" There might be some missing conversions, which might be fixed by the last
" substitution
"
return substitute(line, '\C\(\\IeC\s*{\)\?\\.\(.\)}', '\1', 'g')
endfunction
" }}}1
function! vimtex#util#execute(exe) " {{{1
" Execute the given command on the current system. Wrapper function to make
" it easier to run on both windows and unix.

View File

@ -9,6 +9,7 @@ let s:viewers = [
\ 'mupdf',
\ 'okular',
\ 'qpdfview',
\ 'skim',
\ 'sumatrapdf',
\ 'zathura',
\ ]
@ -20,17 +21,7 @@ function! vimtex#view#init_options() " {{{1
call vimtex#util#set_default('g:vimtex_view_enabled', 1)
if !g:vimtex_view_enabled | return | endif
for viewer in s:viewers
call vimtex#util#set_default('g:vimtex_view_' . viewer . '_options', '')
endfor
call vimtex#util#set_default_os_specific('g:vimtex_view_general_viewer',
\ {
\ 'linux' : 'xdg-open',
\ 'mac' : 'open',
\ })
call vimtex#util#set_default('g:vimtex_view_method', 'general')
call vimtex#util#set_default('g:vimtex_view_mupdf_send_keys', '')
endfunction
" }}}1
@ -52,6 +43,20 @@ function! vimtex#view#init_buffer() " {{{1
execute 'let b:vimtex.viewer = ' . viewer
call b:vimtex.viewer.init()
"
" Create view and/or callback hooks (if they exist)
"
for point in ['view', 'callback']
execute 'let hook = ''g:vimtex_view_'
\ . g:vimtex_view_method . '_hook_' . point . ''''
if exists(hook)
execute 'let hookfunc = ''*'' . ' . hook
if exists(hookfunc)
execute 'let b:vimtex.viewer.hook_' . point . ' = function(' . hook . ')'
endif
endif
endfor
"
" Define commands
"
@ -80,6 +85,16 @@ endfunction
"
" {{{1 General
function! s:general.init() dict " {{{2
"
" Set default options
"
call vimtex#util#set_default_os_specific('g:vimtex_view_general_viewer',
\ {
\ 'linux' : 'xdg-open',
\ 'mac' : 'open',
\ })
call vimtex#util#set_default('g:vimtex_view_general_options', '')
if !executable(g:vimtex_view_general_viewer)
echoerr 'vimtex viewer is not executable!'
echoerr 'g:vimtex_view_general_viewer = '
@ -98,6 +113,10 @@ function! s:general.view(file) dict " {{{2
let exe.cmd .= ' ' . vimtex#util#fnameescape(outfile)
call vimtex#util#execute(exe)
let self.cmd_view = exe.cmd
if has_key(self, 'hook_view')
call self.hook_view()
endif
endfunction
" }}}2
@ -117,6 +136,16 @@ function! s:mupdf.init() dict " {{{2
" Only initialize once
if has_key(self, 'xwin_id') | return | endif
"
" Default MuPDF settings
"
call vimtex#util#set_default('g:vimtex_view_mupdf_options', '')
call vimtex#util#set_default('g:vimtex_view_mupdf_send_keys', '')
call vimtex#util#set_default('g:vimtex_view_mupdf_hook_callback',
\ 's:focus_vim')
call vimtex#util#set_default('g:vimtex_view_mupdf_hook_view',
\ 's:focus_viewer')
if !executable('mupdf')
echoerr 'vimtex viewer MuPDF is not executable!'
endif
@ -144,6 +173,10 @@ function! s:mupdf.view(file) dict " {{{2
else
call self.forward_search(outfile)
endif
if has_key(self, 'hook_view')
call self.hook_view()
endif
endfunction
" }}}2
@ -231,12 +264,13 @@ endfunction
" }}}2
function! s:mupdf.latexmk_callback() dict " {{{2
" Try to get xwin ID
if !self.xwin_exists()
if self.xwin_get_id()
call self.xwin_send_keys(g:vimtex_view_mupdf_send_keys)
call self.forward_search(b:vimtex.out())
call self.focus_vim()
if has_key(self, 'hook_callback')
call self.hook_callback()
endif
endif
endif
endfunction
@ -255,6 +289,8 @@ endfunction
" {{{1 Okular
function! s:okular.init() dict " {{{2
call vimtex#util#set_default('g:vimtex_view_okular_options', '')
if !executable('okular')
echoerr 'vimtex viewer Okular is not executable!'
endif
@ -271,12 +307,18 @@ function! s:okular.view(file) dict " {{{2
let exe.cmd .= '\#src:' . line('.') . vimtex#util#fnameescape(expand('%:p'))
call vimtex#util#execute(exe)
let self.cmd_view = exe.cmd
if has_key(self, 'hook_view')
call self.hook_view()
endif
endfunction
" }}}2
" {{{1 qpdfview
function! s:qpdfview.init() dict " {{{2
call vimtex#util#set_default('g:vimtex_view_qpdfview_options', '')
if !executable('qpdfview')
echoerr 'vimtex viewer qpdfview is not executable!'
endif
@ -295,12 +337,48 @@ function! s:qpdfview.view(file) dict " {{{2
let exe.cmd .= ':' . col('.')
call vimtex#util#execute(exe)
let self.cmd_view = exe.cmd
if has_key(self, 'hook_view')
call self.hook_view()
endif
endfunction
" }}}2
" {{{1 Skim
function! s:skim.init() dict " {{{2
call vimtex#util#set_default('g:vimtex_view_skim_options', '')
if !executable('/Applications/Skim.app/Contents/SharedSupport/displayline')
echoerr 'vimtex viewer Skim is not executable!'
endif
endfunction
" }}}2
function! s:skim.view(file) dict " {{{2
let outfile = a:file !=# '' ? a:file : b:vimtex.out()
if s:output_not_readable(outfile) | return | endif
let exe = {}
let exe.cmd = '/Applications/Skim.app/Contents/SharedSupport/displayline'
let exe.cmd .= ' ' . g:vimtex_view_skim_options
let exe.cmd .= ' ' . line('.')
let exe.cmd .= ' ' . vimtex#util#fnameescape(outfile)
let exe.cmd .= ' ' . vimtex#util#fnameescape(expand('%:p'))
call vimtex#util#execute(exe)
let self.cmd_view = exe.cmd
if has_key(self, 'hook_view')
call self.hook_view()
endif
endfunction
" }}}2
" {{{1 SumatraPDF
function! s:sumatrapdf.init() dict " {{{2
call vimtex#util#set_default('g:vimtex_view_sumatrapdf_options', '')
if !executable('SumatraPDF')
echoerr 'vimtex viewer SumatraPDF is not executable!'
endif
@ -318,6 +396,10 @@ function! s:sumatrapdf.view(file) dict " {{{2
let exe.cmd .= ' ' . vimtex#util#fnameescape(outfile)
call vimtex#util#execute(exe)
let self.cmd_view = exe.cmd
if has_key(self, 'hook_view')
call self.hook_view()
endif
endfunction
" }}}2
@ -327,6 +409,15 @@ function! s:zathura.init() dict " {{{2
" Only initialize once
if has_key(self, 'xwin_id') | return | endif
"
" Default Zathura settings
"
call vimtex#util#set_default('g:vimtex_view_zathura_options', '')
call vimtex#util#set_default('g:vimtex_view_zathura_hook_callback',
\ 's:focus_vim')
call vimtex#util#set_default('g:vimtex_view_zathura_hook_view',
\ 's:focus_viewer')
if !executable('zathura')
echoerr 'vimtex viewer Zathura is not executable!'
endif
@ -339,7 +430,6 @@ function! s:zathura.init() dict " {{{2
let self.xwin_id = 0
let self.xwin_get_id = function('s:xwin_get_id')
let self.xwin_exists = function('s:xwin_exists')
let self.focus_vim = function('s:focus_vim')
endfunction
" }}}2
@ -352,6 +442,10 @@ function! s:zathura.view(file) dict " {{{2
else
call self.forward_search(outfile)
endif
if has_key(self, 'hook_view')
call self.hook_view()
endif
endfunction
" }}}2
@ -386,7 +480,9 @@ function! s:zathura.latexmk_callback() dict " {{{2
if !self.xwin_exists()
if self.xwin_get_id()
call self.forward_search(b:vimtex.out())
call self.focus_vim()
if has_key(self, 'hook_callback')
call self.hook_callback()
endif
endif
endif
endfunction
@ -460,17 +556,21 @@ function! s:xwin_send_keys(keys) dict " {{{1
if a:keys !=# ''
let cmd = 'xdotool key --window ' . self.xwin_id
let cmd .= ' ' . a:keys
call system(cmd)
silent call system(cmd)
endif
endfunction
" }}}1
"
" Hook functions (used as default hooks in some cases)
"
function! s:focus_viewer() dict " {{{1
if !executable('xdotool') | return | endif
if self.xwin_exists()
silent execute '!xdotool windowfocus ' . self.xwin_id
redraw!
if self.xwin_id > 0
silent call system('xdotool windowfocus ' . self.xwin_id . ' --sync')
silent call system('xdotool windowraise ' . self.xwin_id)
endif
endfunction
@ -478,8 +578,8 @@ endfunction
function! s:focus_vim() dict " {{{1
if !executable('xdotool') | return | endif
silent execute '!xdotool windowfocus ' . v:windowid
redraw!
silent call system('xdotool windowfocus ' . v:windowid . ' --sync')
silent call system('xdotool windowraise ' . v:windowid)
endfunction
" }}}1

View File

@ -480,6 +480,8 @@ Options~
Note 1: This feature requires |clientserver|.
Note 2: Callbacks are only possible when continuous mode is active, see
|g:vimtex_latexmk_continuous|.
Note 3: The callback is run with the vim executable defined by
|g:vimtex_latexmk_progname|.
Default value: 1
@ -507,6 +509,15 @@ Options~
Default value: '-pdf'
*g:vimtex_latexmk_progname*
Path to vim executable. This is used for the callback functionality, and it
must be set correctly in order for the callback function to work. The
default value should work correctly in most cases, but in some cases, e.g.
for MacVim, one might need to set it manually to get the callbacks to work
as expected.
Default value: |v:progpath| if it exists, else |v:progname|.
*g:vimtex_quickfix_autojump*
This option controls if vim should automatically jump to the first error
whenever the |quickfix| window is opened.
@ -659,6 +670,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 +1026,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*

View 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}