sponsor Vim development Vim logo Vim Book Ad

intermediate Tip #361: Use xdvi (or kdvi) in conjunction with gvim (or vim) and converse

 tip karma   Rating 24/6, Viewed by 1373 

created:   November 5, 2002 14:07      complexity:   intermediate
author:   Christine Noot-Huyghe      as of Vim:   6.0

source: the xdvi man page

For recent xdvi versions (>= 22.38), (or recent Unix/Linux versions), xdvi can
interact with any editor provided with a client-server mode. We explain
here how to use xdvi in conjunction with vim (compiled with the client-server
option) or gvim (mostly compiled with this option). I have tested that
with Linux Mandrake 9.0. On that system, gvim is compiled with the
client-server option and vim is not.

0-Check that your xdvi version provides the "source-special" functions,
by typing 'xdvi -version' or 'man xdvi'

1-Configuration of the source file (file.tex)
Put the following line at the beginning of the latex file:
\usepackage[active]{srcltx}
or the following line at the beginning of the tex file
\include{srctex}

2-Configuration of xdvi
xdvi has to be called with the following options
xdvi -editor 'gvim --remote-wait +%l %f' file.dvi &
(or with 'xterm -e vim --remote-wait +%l %f' if vim has
been compiled with the client-server option).

To make it easier to use you can define an environement
variable XEDITOR to set the value of 'editor' or add
the following line in your .Xdefaults
xdvi.editor: gvim --remote-wait +%l %f
Launch 'xrdb -load ~/.Xdefaults' to make sure that
xdvi.editor is set to the good value.
If you have defined such a variable, xdvi will always be launched
with the -editor option. To avoid this unsafe behavior,
launch 'xdvi -safer'.

3-Conversely, if you call xdvi within gvim with the -sourceposition
option, cursor is placed in the dvi file on the corresponding position.
Syntax is:
xdvi -sourceposition l:cfile.tex file.dvi
l is the line number, c is the column number
(Be carefull: there is no space between "c" (column number) and
file.tex).
To make it easier to use, you can do the following
First create a file named for example "xdvi_source.vim"
with following lines
" This script calls xdvi source and puts cursor in xdvi viewer at
" the position corresponding to the position in the source file
"
:exec "silent !xdvi -sourceposition ".line(".").':'.col(".")."%".' '."%:r.dvi"

Then launch the following command within gvim editing the .tex
source file. Pressing simultaneously <CTRL> and -> will open
the dvi file at the right position:
:noremap <buffer> <C-Right> :so xdvi_source.vim<CR>

 rate this tip  Life Changing Helpful Unfulfilling 

<<':e <dir>' enter files and directories | matchit.vim and coldfusion (and perhaps others) >>

Additional Notes

Anonymous, November 19, 2002 23:04
Seems it doesn't work for multiple tex source files.
Anonymous, May 27, 2004 5:46
If you do not have the LaTeX package "srctex",
try compling your file with:

latex --src [your_file.tex]

which works for me

-- Matt
holzensp at gmail.com, October 30, 2005 11:55
You don't actually need to create that extra file (I prefer my directories to be 'clean' and I always forget to copy the necessary files when starting a new document in a new directory). You can just type:

:noremap <buffer> <C-Right> :exec "silent !xdvi -sourceposition ".line(".").':'.col(".")."%".' '."%:r.dvi"<CR>

The problem I run into very often, though, is that I often split my LaTeX source into multiple files (usually one per chapter). The problem is that

"%:r.dvi"

is than usually wrong (e.g. it should be book.dvi, while the file being edited is chapter1.tex). I think it should be possible to check for files in the directory containing the pattern "{include}\|{input}\{%<" in which case it is PROBABLY this file that will result in the dvi. No way to be sure though, so it is probably best to have a texrc file for every project (extra file, darn!)
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
Sponsored by Web Concept Group Inc. SourceForge Logo