Advertisement
anjishnu

tex_makelatex.vim

Sep 15th, 2011
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 2.21 KB | None | 0 0
  1. "" For makelatex and forward search
  2. "" Author: Anjishnu Sarkar
  3. "" Version: 0.5
  4. "" Runs latex or pdflatex via latemk (requires the shell script makelatex2
  5. "" and the perl script latexmk)
  6. "" Communicates with okular for forward search. Shortcut "Shift+f".
  7.  
  8. " To load the file only once
  9. if exists("s:loaded_makelatex")
  10.     finish
  11. else
  12.     let s:loaded_makelatex = 1
  13. endif
  14.  
  15. "" Define the document viewer
  16. let b:DocumentViewer = "okular --unique"
  17.  
  18. "" The function FindRoot() is from the script
  19. "" live-latex-preview.vim by Kevin C. Klement
  20. "" klement <at> philos <dot> umass <dot> edu
  21. "" Search for root file
  22. function! FindRoot()
  23.     let b:RootFile = expand("%")
  24.     for linenum in range(1,5)
  25.         let linecontents = getline(linenum)
  26.         if linecontents =~ 'root\s*='
  27.            let b:RootFile = substitute(linecontents, '.*root\s*=\s*', "", "")
  28.            let b:RootFile = substitute(b:RootFile, '\s*$', "", "")
  29.         endif
  30.     endfor
  31.     let b:RootFileName = substitute(b:RootFile, '\.tex$', "", "")
  32. endfunction
  33. call FindRoot()
  34.  
  35. "" Find the output format
  36. function! FindExt()
  37.     let b:Ext = system("makelatex2 -E \"". expand("%") ."\"")
  38.     let b:Ext = substitute(b:Ext, '\n', "", "")
  39. endfunction
  40.  
  41. " Run Latex or variants
  42. function! RunLaTeX(func)
  43.     " First save it
  44.     update
  45.  
  46.     if a:func =~ '\<tex\>'
  47.         echo "Compiling..."
  48.         silent call system("makelatex2 -e -v -w -l " .line('.'). " \"" . expand('%') . "\" &")
  49.     elseif a:func =~ '\<remove\>'
  50.         echo "Deleting junk files..."
  51.         silent! call system("deljunk -b-")
  52. "         silent! call system("deljunk -b- -n")
  53.     endif
  54.  
  55. endfunction
  56.  
  57. " Forward search
  58. function! PDFForward()
  59.     call FindExt()
  60.     if filereadable(b:RootFileName.".".b:Ext)
  61.  
  62. "         silent! call system("okular --unique \"".b:RootFileName.".".b:Ext."\"\#src:".line('.').expand("%")." &")
  63.         silent! call system(b:DocumentViewer . " \"".b:RootFileName.".".b:Ext."\"\#src:".line('.').expand("%")." &")
  64.     else
  65.         echo "Output file not readable."
  66.     endif
  67. endfunction
  68.  
  69. nnoremap <silent> <A-1>     :call RunLaTeX("tex")<CR>
  70. nnoremap <silent> <A-3>     :call RunLaTeX("remove")<CR>
  71. nnoremap <silent> <S-f>     :call PDFForward()<CR>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement