summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Reichel <sre@ring0.de>2012-12-01 02:16:21 +0100
committerSebastian Reichel <sre@ring0.de>2012-12-01 02:16:21 +0100
commit0dfdc6ef0517f1818badda2f63333c2bdbe4b02d (patch)
treea06177a0cc7d892e9f942a6fad52019b3b4a4390
parent5130047a5c5b93ad822ba69bbc37d73fe3e4cb5d (diff)
downloadvim-config-0dfdc6ef0517f1818badda2f63333c2bdbe4b02d.tar.bz2
improve *.tex support
* drop dependency of external script for viewing PDFs * support building in included files in subdirectories. - create a master.tex.latexmain to indentify the main document - main latex document must be in the same directory, or in one of the its parent directories.
-rw-r--r--vim/after/ftplugin/tex.vim33
1 files changed, 31 insertions, 2 deletions
diff --git a/vim/after/ftplugin/tex.vim b/vim/after/ftplugin/tex.vim
index 91985fa..885a065 100644
--- a/vim/after/ftplugin/tex.vim
+++ b/vim/after/ftplugin/tex.vim
@@ -1,9 +1,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 :!rubber -d %<CR>
+nnoremap \rubber :call BuildLatex()<CR>
nmap <buffer> <F6> \rubber
imap <buffer> <F6> <C-O>\rubber
" open pdf via <F10>
-nnoremap \evince :!vim-open-pdf % >/dev/null 2>&1 &<CR><CR>
+nnoremap \evince :call ShowPDF()<CR><CR>
nmap <buffer> <F10> \evince
imap <buffer> <F10> <C-O>\evince