summaryrefslogtreecommitdiffstats
path: root/vim/after/ftplugin/tex.vim
blob: 885a065e9ee9c677d05a1efb2abb71b68571c28b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function! GetMainLatexFile()
	let p = expand('%:p:h')
	while simplify(p) != "/"
		let main = globpath(p, '*.latexmain')
		if main != ''
			return fnamemodify(main, ":p:r")
		endif
		let p = globpath(p, '..')
	endwhile

	" no root document found, use current one
	return expand('%:p')
endfunction

function! BuildLatex()
	let oldcwd = getcwd()
	let file = GetMainLatexFile()
	let newcwd = fnamemodify(file, ":p:h")
	exec "lcd" . newcwd
	exe "! rubber -d" file
	exec "lcd" . oldcwd
endfunction

function! ShowPDF()
	let texfile = GetMainLatexFile()
	let pdffile = fnamemodify(texfile, ":p:r") . ".pdf"
	exe "! evince" pdffile ">/dev/null 2>&1 &"
endfunction

" compile latex via <F6>
nnoremap \rubber :call BuildLatex()<CR>
nmap <buffer> <F6> \rubber
imap <buffer> <F6> <C-O>\rubber

" open pdf via <F10>
nnoremap \evince :call ShowPDF()<CR><CR>
nmap <buffer> <F10> \evince
imap <buffer> <F10> <C-O>\evince