[Vim-latex-devel] running latex
Brought to you by:
srinathava,
tmaas
|
From: Carl M. <cm...@ma...> - 2002-11-19 19:31:02
|
I have some suggestions about running latex and viewing the errors.
Once again, emacs did it right, in my opinion (in the auctex package).
After running latex, the .log file appears in its own window.
Typing C-c` will take you to the next tex error. The cursor is
placed on the exact position of the error. This is indicated in
the .log file by a split line, with the split at the postion of the
error. Also, the .log file has hints about correcting the error.
Less of that happens in quickfix mode. The cursor is not positioned
at the point of the error. (Of course, with :cn one can go to the line
of the error, but not the position within the line). Only a one-line
description of the error is given, while the .log file has lots of
information.
Another issue is with xdvi. I don't know the situation with windows.
On Unix, if you run latex within vim, the xdvi viewer does not
automatically update, and you have to click in it. But if you run
latex within an x-terminal, xdvi does automatically update the view.
Also, if you give vim the command to launch an x-term, and then tell vim
to start looking at the .log file, it will look at the .log file before
latex has finished running. With Vim-LaTex, you get to view the errors
right away, but xdvi doesn't automatically update.
I prefer automatic updating of xdvi.
For this reason, I have 2 sets of macros. One of them has xdvi
automatically updating, but the errors do not automatically show up.
In the second, you have to click in xdvi to update, but the errors
automatically show up.
I know people have put in a lot of work on the quickfix way of
displaying tex errors. Could my suggestions be considered as
an option?
Carl Mueller
I'm listing 2 sets of functions. Both allow you to run latex, view the
.log file with syntax highlighting, and automatically go to the position
of the error. There are also functions to view \ref{} and \cite{}
errors, or look at the log file, and go to the line mentioned in the file.
You might also want to consider a macro a got from Charles Campbell (and
modified), which allows you to run latex on a file or a highlighted region.
The key bindings in these files are bad; they're not the important part.
"""""""""""""""""""""""""""""""""""""""""""
" Macros with automatic updating of xdvi
" Latex command.
let b:latex_command = "! xterm -bg ivory -fn 7x14 -e latex % &"
"let b:latex_command = "! latex \\\\nonstopmode \\\\input\\{%\\}"
" Key Bindings {{{
" Run Latex; change these bindings if you like.
noremap <buffer> \ml :call <SID>RunLatex()<CR><Esc>
noremap <buffer> \mr :call <SID>CheckReferences("Reference", "ref")<CR><Space>
noremap <buffer> \mc :call <SID>CheckReferences("Citation", "cite")<CR><Space>
noremap <buffer> \mg :call <SID>LookAtLogFile()<CR>gg/LaTeX Warning\\|^!<CR>
noremap <buffer> \mn :call <SID>NextTexError()<CR><Space>
noremap <buffer> \mv :call <SID>Xdvi()<CR><Space>
noremap <buffer> \mi :w<CR>:silent ! xterm -bg ivory -fn 10x20 -e ispell %<CR>:e %<CR><Space>
noremap <buffer> K :call <SID>RunLatex()<CR><Esc>
noremap <buffer> <C-K> :call <SID>NextTexError()<CR><Space>
" Run Ispell on either the buffer, or the visually selected word.
noremap <buffer> <S-Insert> :w<CR>:silent ! xterm -bg ivory -fn 10x20 -e ispell %<CR>:e %<CR><Space>
inoremap <buffer> <S-Insert> <Esc>:w<CR>:silent ! xterm -bg ivory -fn 10x20 -e ispell %<CR>:e %<CR><Space>
vnoremap <buffer> <S-Insert> <C-C>`<v`>s<Space><Esc>mq:e ispell.tmp<CR>i<C-R>"<Esc>:w<CR>:silent ! xterm -bg ivory -fn 10x20 -e ispell %<CR>:e %<CR><CR>ggVG<Esc>`<v`>s<Esc>:bwipeout!<CR>:!rm ispell.tmp*<CR>`q"_s<C-R>"<Esc>
" }}}
" Functions {{{
function! s:RunLatex()
update
exe "silent " . b:latex_command
endfunction
" Stop warnings, since the log file is modified externally and then
" read again.
au BufRead *.log set bufhidden=unload
function! s:NextTexError()
silent only
edit +1 %<.log
syntax clear
syntax match err /! .*/
syn match err /^ l\.\d.*\n.*$/
highlight link err ToDo
if search('^l\.\d') == 0
edit #
redraw
call input("\nNo (More) Errors Found\n\nPress 'enter' to go on.")
else
let linenumber = matchstr(getline('.'), '\d\+')
let errorposition = col("$") - strlen(linenumber) - 4
"Put a space in the .log file so that you can see where you were,
"and move on to the next latex error.
s/^/ /
write
split #
exe "normal " . linenumber . "G" . errorposition . "lzz\<C-W>wzz\<C-W>w"
endif
endfunction
function! s:CheckReferences(name, ref)
"exe "noremap \<buffer> \<C-L> :call \<SID>CheckReferences(\"" . a:name . "\",\"" . a:ref . "\")\<CR>\<Space>"
only
edit +1 %<.log
syntax clear
syntax match err /LaTeX Warning/
highlight link err ToDo
if search('^LaTeX Warning: ' . a:name) == 0
edit #
redraw
call input("\nNo (More) " . a:name . " Errors Found\n\nPress 'enter' to go on.")
else
let linenumber = matchstr(getline('.'), '\d\+\.$')
let linenumber = strpart(linenumber, 0, strlen(linenumber)-1)
let reference = matchstr(getline('.'), "`.*\'")
let reference = strpart(reference, 1, strlen(reference)-2)
"Put a space in the .log file so that you can see where you were,
"and move on to the next latex error.
s/^/ /
write
split #
exe "normal " . linenumber . "Gzz\<C-W>wzz\<C-W>w"
exe "normal /\\\\" . a:ref . "{" . reference . "}\<CR>"
exe "normal /" . reference . "\<CR>"
endif
endfunction
function! s:LookAtLogFile()
only
edit +1 %<.log
syntax clear
syntax match err /LaTeX Warning/
syntax match err /! .*/
syntax match err /^Overfull/
syntax match err /^Underfull/
highlight link err ToDo
noremap <buffer> K :call <SID>GetLineFromLogFile()<CR>
split #
wincmd b
/LaTeX Warning\|^\s*!\|^Overfull\|^Underfull
let @/='LaTeX Warning\|^\s*!\|^Overfull\|^Underfull'
echo "\nGo to the line in the log file which mentions the error\nthen type K to go to the line\nn to go to the next warning\n"
endfunction
function! s:GetLineFromLogFile()
let line = matchstr(getline("."), 'line \d\+')
wincmd t
exe strpart(line, 5, strlen(line)-5)
endfunction
" }}}
" vim:fdm=marker
"""""""""""""""""""""""""""""""""""""""""""
" Macros which automatically show the errors.
" Latex command.
let b:latex_command = "! xterm -bg ivory -fn 7x14 -e latex % &"
"let b:latex_command = "! latex \\\\nonstopmode \\\\input\\{%\\}"
" Key Bindings {{{
" Run Latex; change these bindings if you like.
noremap <buffer> \ml :call <SID>RunLatex()<CR><Esc>
noremap <buffer> \mr :call <SID>CheckReferences("Reference", "ref")<CR><Space>
noremap <buffer> \mc :call <SID>CheckReferences("Citation", "cite")<CR><Space>
noremap <buffer> \mg :call <SID>LookAtLogFile()<CR>gg/LaTeX Warning\\|^!<CR>
noremap <buffer> \mn :call <SID>NextTexError()<CR><Space>
noremap <buffer> \mv :call <SID>Xdvi()<CR><Space>
noremap <buffer> \mi :w<CR>:silent ! xterm -bg ivory -fn 10x20 -e ispell %<CR>:e %<CR><Space>
noremap <buffer> K :call <SID>RunLatex()<CR><Esc>
noremap <buffer> <C-K> :call <SID>NextTexError()<CR><Space>
" Run Ispell on either the buffer, or the visually selected word.
noremap <buffer> <S-Insert> :w<CR>:silent ! xterm -bg ivory -fn 10x20 -e ispell %<CR>:e %<CR><Space>
inoremap <buffer> <S-Insert> <Esc>:w<CR>:silent ! xterm -bg ivory -fn 10x20 -e ispell %<CR>:e %<CR><Space>
vnoremap <buffer> <S-Insert> <C-C>`<v`>s<Space><Esc>mq:e ispell.tmp<CR>i<C-R>"<Esc>:w<CR>:silent ! xterm -bg ivory -fn 10x20 -e ispell %<CR>:e %<CR><CR>ggVG<Esc>`<v`>s<Esc>:bwipeout!<CR>:!rm ispell.tmp*<CR>`q"_s<C-R>"<Esc>
" }}}
" Functions {{{
function! s:RunLatex()
update
exe "silent " . b:latex_command
call <SID>NextTexError()
endfunction
" Stop warnings, since the log file is modified externally and then
" read again.
au BufRead *.log set bufhidden=unload
function! s:NextTexError()
silent only
split
wincmd j
edit +1 %<.log
if search('^l\.\d') == 0
bwipeout
redraw
call input("\nNo (More) Errors Found\n\nPress 'enter' to go on.")
else
syntax clear
syntax match err /! .*/
syn match err /^ l\.\d.*\n.*$/
highlight link err ToDo
let linenumber = matchstr(getline('.'), '\d\+')
let errorposition = col("$") - strlen(linenumber) - 4
"Put a space in the .log file so that you can see where you were,
"and move on to the next latex error.
s/^/ /
write
wincmd k
exe "normal " . linenumber . "G" . errorposition . "lzz\<C-W>wzz\<C-W>w"
endif
endfunction
function! s:CheckReferences(name, ref)
"exe "noremap \<buffer> \<C-L> :call \<SID>CheckReferences(\"" . a:name . "\",\"" . a:ref . "\")\<CR>\<Space>"
only
edit +1 %<.log
syntax clear
syntax match err /LaTeX Warning/
highlight link err ToDo
if search('^LaTeX Warning: ' . a:name) == 0
edit #
redraw
call input("\nNo (More) " . a:name . " Errors Found\n\nPress 'enter' to go on.")
else
let linenumber = matchstr(getline('.'), '\d\+\.$')
let linenumber = strpart(linenumber, 0, strlen(linenumber)-1)
let reference = matchstr(getline('.'), "`.*\'")
let reference = strpart(reference, 1, strlen(reference)-2)
"Put a space in the .log file so that you can see where you were,
"and move on to the next latex error.
s/^/ /
write
split #
exe "normal " . linenumber . "Gzz\<C-W>wzz\<C-W>w"
exe "normal /\\\\" . a:ref . "{" . reference . "}\<CR>"
exe "normal /" . reference . "\<CR>"
endif
endfunction
function! s:LookAtLogFile()
only
edit +1 %<.log
syntax clear
syntax match err /LaTeX Warning/
syntax match err /! .*/
syntax match err /^Overfull/
syntax match err /^Underfull/
highlight link err ToDo
noremap <buffer> K :call <SID>GetLineFromLogFile()<CR>
split #
wincmd b
/LaTeX Warning\|^\s*!\|^Overfull\|^Underfull
let @/='LaTeX Warning\|^\s*!\|^Overfull\|^Underfull'
echo "\nGo to the line in the log file which mentions the error\nthen type K to go to the line\nn to go to the next warning\n"
endfunction
function! s:GetLineFromLogFile()
let line = matchstr(getline("."), 'line \d\+')
wincmd t
exe strpart(line, 5, strlen(line)-5)
endfunction
" }}}
" vim:fdm=marker
|