Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "" For makelatex and forward search
- "" Author: Anjishnu Sarkar
- "" Version: 0.5
- "" Runs latex or pdflatex via latemk (requires the shell script makelatex2
- "" and the perl script latexmk)
- "" Communicates with okular for forward search. Shortcut "Shift+f".
- " To load the file only once
- if exists("s:loaded_makelatex")
- finish
- else
- let s:loaded_makelatex = 1
- endif
- "" Define the document viewer
- let b:DocumentViewer = "okular --unique"
- "" The function FindRoot() is from the script
- "" live-latex-preview.vim by Kevin C. Klement
- "" klement <at> philos <dot> umass <dot> edu
- "" Search for root file
- function! FindRoot()
- let b:RootFile = expand("%")
- for linenum in range(1,5)
- let linecontents = getline(linenum)
- if linecontents =~ 'root\s*='
- let b:RootFile = substitute(linecontents, '.*root\s*=\s*', "", "")
- let b:RootFile = substitute(b:RootFile, '\s*$', "", "")
- endif
- endfor
- let b:RootFileName = substitute(b:RootFile, '\.tex$', "", "")
- endfunction
- call FindRoot()
- "" Find the output format
- function! FindExt()
- let b:Ext = system("makelatex2 -E \"". expand("%") ."\"")
- let b:Ext = substitute(b:Ext, '\n', "", "")
- endfunction
- " Run Latex or variants
- function! RunLaTeX(func)
- " First save it
- update
- if a:func =~ '\<tex\>'
- echo "Compiling..."
- silent call system("makelatex2 -e -v -w -l " .line('.'). " \"" . expand('%') . "\" &")
- elseif a:func =~ '\<remove\>'
- echo "Deleting junk files..."
- silent! call system("deljunk -b-")
- " silent! call system("deljunk -b- -n")
- endif
- endfunction
- " Forward search
- function! PDFForward()
- call FindExt()
- if filereadable(b:RootFileName.".".b:Ext)
- " silent! call system("okular --unique \"".b:RootFileName.".".b:Ext."\"\#src:".line('.').expand("%")." &")
- silent! call system(b:DocumentViewer . " \"".b:RootFileName.".".b:Ext."\"\#src:".line('.').expand("%")." &")
- else
- echo "Output file not readable."
- endif
- endfunction
- nnoremap <silent> <A-1> :call RunLaTeX("tex")<CR>
- nnoremap <silent> <A-3> :call RunLaTeX("remove")<CR>
- nnoremap <silent> <S-f> :call PDFForward()<CR>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement