[Vim-latex-devel] compiling and viewing different formats on the fly
Brought to you by:
srinathava,
tmaas
From: Vaidotas Z. <ze...@gm...> - 2005-03-22 08:05:33
|
Hi, Recently I found LateX editor with nice GUI: Kile (http://kile.sourceforge.net) . I tried it out, but returned back to using vim-latex suite. The main reason was all the nice shortcuts for fast latex typing. Yet one thing I liked is the Kile's build system. You can get pdf from latex in various different ways (tex->pdf, tex->dvi->ps->pdf, tex->dvi->pdf) by pressing appropriate keyboard shortcuts. Latex-suite on the other hand forces you to change target from dvi to pdf, or vice versa, and even then you are constrained only to one way of getting pdf, since Tex_CompileRule_pdf in texrc can have only one value. So after looking at the code in compiler.vim I wrote functions that emulates (partialy) Kile behaviour (the diffs for compiler.vim and main.vim are below). These functions should not change the default Latex-suite compiling and viewing behaviour. After applying changes you get 9 new keyboard shortcuts: Alt+1 -- tex->dvi->ps->pdf (latex,dvips,ps2pdf) Alt+2 -- tex->dvi (latex) Alt+3 -- tex->pdf (pdflatex) Alt+4 -- dvi->ps (dvips) Alt+5 -- ps->pdf (ps2pdf) Alt+6 -- dvi->pdf (dvipdfm) Alt+7 -- dvi (view dvi) Alt+8 -- ps (view ps) Alt+9 -- pdf (view pdf) These shortcuts make sense when numeric keypad is used. Then the bottom row is for compiling, the middle is for converting, and the third is for viewing. Of course you must have winaltkeys set to no. I've tested these functions on Vim 6.3.64 and up to date Debian Sid. The functions are quite simple, adapting them to your needs should be simple. Vaidotas Zemlys Here are the diffs: --- compiler_old.vim 2004-07-10 22:02:38.000000000 +0300 +++ compiler.vim 2005-03-22 09:28:31.000000000 +0200 @@ -209,6 +209,122 @@ endfunction " }}} +" +" Tex_CompileDvi{{{ +function! Tex_CompileDvi() + let initTarget = s:target + let s:target = 'dvi' + call Tex_RunLaTeX() + let s:target = initTarget +endfunction +"}}} +" +" Tex_CompilePdf{{{ +function! Tex_CompilePdf() + let initTarget = s:target + let initPdfrule = Tex_GetVarValue("Tex_CompileRule_pdf") + let initFormat = Tex_GetVarValue("Tex_FormatDependency_pdf") + call Tex_SetVarValue("Tex_FormatDependency_pdf",'') + call Tex_SetVarValue("Tex_CompileRule_pdf",'pdflatex -interaction=nonstopmode $*') + let s:target = 'pdf' + call Tex_RunLaTeX() + let s:target = initTarget + call Tex_SetVarValue("Tex_FormatDependency_pdf",initFormat) + call Tex_SetVarValue("Tex_CompileRule_pdf",initPdfrule) +endfunction " }}} + +" Tex_CompileDviPsPdf{{{ +function! Tex_CompileDviPsPdf() + let initTarget = s:target + let initPdfrule = Tex_GetVarValue("Tex_CompileRule_pdf") + let initFormat = Tex_GetVarValue("Tex_FormatDependency_pdf") + + + call Tex_SetVarValue("Tex_FormatDependency_pdf",'dvi,ps,pdf') + call Tex_SetVarValue("Tex_CompileRule_pdf",'ps2pdf $*.ps') + + let s:target = 'pdf' + call Tex_RunLaTeX() + let s:target = initTarget + call Tex_SetVarValue("Tex_FormatDependency_pdf",initFormat) + call Tex_SetVarValue("Tex_CompileRule_pdf",initPdfrule) +endfunction " }}} + +"Tex_CompileDviPs{{{ +function! Tex_CompileDviPs() + let initTarget = s:target + let initFormat = Tex_GetVarValue("Tex_FormatDependency_ps") + + call Tex_SetVarValue("Tex_FormatDependency_ps",'') + + let s:target = 'ps' + call Tex_RunLaTeX() + let s:target = initTarget + call Tex_SetVarValue("Tex_FormatDependency_ps",initFormat) +endfunction " }}} + +"Tex_CompilePsPdf{{{ +function! Tex_CompilePsPdf() + let initTarget = s:target + let initFormat = Tex_GetVarValue("Tex_FormatDependency_pdf") + let initPdfrule = Tex_GetVarValue("Tex_CompileRule_pdf") + + call Tex_SetVarValue("Tex_FormatDependency_pdf",'') + call Tex_SetVarValue("Tex_CompileRule_pdf",'ps2pdf $*.ps') + + let s:target = 'pdf' + + call Tex_RunLaTeX() + let s:target = initTarget + call Tex_SetVarValue("Tex_FormatDependency_ps",initFormat) + call Tex_SetVarValue("Tex_CompileRule_pdf",initPdfrule) +endfunction " }}} + +" Tex_CompileDviPdf{{{ +function! Tex_CompileDviPdf() + let initTarget = s:target + let initPdfrule = Tex_GetVarValue("Tex_CompileRule_pdf") + let initFormat = Tex_GetVarValue("Tex_FormatDependency_pdf") + + + call Tex_SetVarValue("Tex_FormatDependency_pdf",'') + call Tex_SetVarValue("Tex_CompileRule_pdf",'dvipdfm $*.dvi') + + let s:target = 'pdf' + call Tex_RunLaTeX() + let s:target = initTarget + call Tex_SetVarValue("Tex_FormatDependency_pdf",initFormat) + call Tex_SetVarValue("Tex_CompileRule_pdf",initPdfrule) +endfunction " }}} + +" +"Tex_ViewDvi{{{ +function! Tex_ViewDvi() + let initTarget = s:target + call Tex_SetTeXCompilerTarget('View', 'dvi') + call Tex_ViewLaTeX() + call Tex_SetTeXCompilerTarget('View', initTarget) +endfunction +"}}} +" Tex_ViewPs{{{ +function! Tex_ViewPs() + let initTarget = s:target + call Tex_SetTeXCompilerTarget('View', 'ps') + call Tex_ViewLaTeX() + call Tex_SetTeXCompilerTarget('View', initTarget) +endfunction +"}}} + +"Tex_ViewPdf{{{ +function! Tex_ViewPdf() + let initTarget = s:target + call Tex_SetTeXCompilerTarget('View', 'pdf') + call Tex_ViewLaTeX() + call Tex_SetTeXCompilerTarget('View', s:target) +endfunction +"}}} + + " Tex_ViewLaTeX: opens viewer {{{ " Description: opens the DVI viewer for the file being currently edited. " Again, if the current file is a \input in a master file, see text above @@ -779,6 +895,43 @@ vnoremap <buffer> <Plug>Tex_Compile :call Tex_PartCompile()<cr> nnoremap <buffer> <Plug>Tex_View :call Tex_ViewLaTeX()<cr> nnoremap <buffer> <Plug>Tex_ForwardSearch :call Tex_ForwardSearchLaTeX()<cr> + + inoremap <M-1> <ESC>:call Tex_CompileDviPsPdf()<cr><ESC>i + nnoremap <M-1> <ESC>:call Tex_CompileDviPsPdf()<cr> + vnoremap <M-1> <ESC>:call Tex_CompileDviPsPdf()<cr><ESC>v + + inoremap <M-2> <ESC>:call Tex_CompileDvi()<cr><ESC>i + nnoremap <M-2> <ESC>:call Tex_CompileDvi()<cr> + vnoremap <M-2> <ESC>:call Tex_CompileDvi()<cr><ESC>v + + inoremap <M-3> <ESC>:call Tex_CompilePdf()<cr><ESC>i + nnoremap <M-3> <ESC>:call Tex_CompilePdf()<cr> + vnoremap <M-3> <ESC>:call Tex_CompilePdf()<cr><ESC>v + + inoremap <M-4> <ESC>:call Tex_CompileDviPs()<cr><ESC>i + nnoremap <M-4> <ESC>:call Tex_CompileDviPs()<cr> + vnoremap <M-4> <ESC>:call Tex_CompileDviPs()<cr><ESC>v + + inoremap <M-5> <ESC>:call Tex_CompilePsPdf()<cr><ESC>i + nnoremap <M-5> <ESC>:call Tex_CompilePsPdf()<cr> + vnoremap <M-5> <ESC>:call Tex_CompilePsPdf()<cr><ESC>v + + inoremap <M-6> <ESC>:call Tex_CompileDviPdf()<cr><ESC>i + nnoremap <M-6> <ESC>:call Tex_CompileDviPdf()<cr> + vnoremap <M-6> <ESC>:call Tex_CompileDviPdf()<cr><ESC>v + + inoremap <M-7> <ESC>:call Tex_ViewDvi()<cr><ESC>i + nnoremap <M-7> <ESC>:call Tex_ViewDvi()<cr> + vnoremap <M-7> <ESC>:call Tex_ViewDvi()<cr><ESC>v + + inoremap <M-8> <ESC>:call Tex_ViewPs()<cr><ESC>i + nnoremap <M-8> <ESC>:call Tex_ViewPs()<cr> + vnoremap <M-8> <ESC>:call Tex_ViewPs()<cr><ESC>v + + inoremap <M-9> <ESC>:call Tex_ViewPdf()<cr><ESC>i + nnoremap <M-9> <ESC>:call Tex_ViewPdf()<cr> + vnoremap <M-9> <ESC>:call Tex_ViewPdf()<cr><ESC>v + call Tex_MakeMap(s:ml."ll", "<Plug>Tex_Compile", 'n', '<buffer>') call Tex_MakeMap(s:ml."ll", "<Plug>Tex_Compile", 'v', '<buffer>') Note that this diff also has the fix for a bug about FormatDependency not working mentioned in my previous letters --- main_old.vim 2004-12-19 22:07:40.000000000 +0200 +++ main.vim 2005-03-22 09:18:25.000000000 +0200 @@ -262,6 +262,25 @@ return '' endif endfunction " }}} + +" Tex_SetVarValue: sets the value of the variable {{{ +" Description: +" See if a window-local, buffer-local or global variable with the given name +" exists and if so assign given value. If none exists create global variable +" with given value. +function! Tex_SetVarValue(varname,value) + if exists('w:'.a:varname) + let w:{a:varname} = a:value + elseif exists('b:'.a:varname) + let b:{a:varname} = a:value + elseif exists('g:'.a:varname) + let g:{a:varname} = a:value + else + let g:{a:varname} = a:value + endif +endfunction " }}} + + " Tex_GetMainFileName: gets the name of the main file being compiled. {{{ " Description: returns the full path name of the main file. " This function checks for the existence of a .latexmain file @@ -541,7 +560,9 @@ redir @a | silent! clist | redir END let errlist = @a let @a = _a - + if errlist =~ 'E42: No Errors' + let errlist = "" + endif return errlist endfunction " }}} " Tex_GetTempName: get the name of a temporary file in specified directory {{{ |