Forward and inverse search

If you use gvim and xdvi to edit and view your latex and corresponding dvi files then you can set it up so that you can jump effortlessly back and forth between the location in the dvi viewer and the location in the editor. This is explained on this webpage, but I wanted to rephrase it here.

Firstly, in order for inverse search to work you have to use
latex -src filename.tex
when compiling your latex files. The make command in the stacks project does this automatically for you. The default is that control + left button in the xdvi window brings you to the corresponding place in the editor. If this isn’t working you need to check if a line such as
xdvi.editor: gvim --servername xdvi --remote +%l %f
occurs in the file .xdvirc (which is probably somewhere in your home directory). If not then try to see if your xdvi lets you set it (in the options/preferences), else you can edit .xdvirc directly.

Secondly, to use forward search place the following line
map <F3> :execute "!xdvi -sourceposition " . line(".") . expand("%") . " " . expand("%:r") . ".dvi"<CR><CR>
in your .gvimrc file (in your home directory). Having done this then when you press F3 in gvim you will jump to the corresponding place in xdvi.

There is still a minor issue with this if you are editing multiple files concurrently (in tabs of gvim). Namely, in that case case a new instance of xdvi pops up if you use F3 after you switch to editing another file in gvim. (If you switch files using ctrl-click in the corresponding xdvi window this doesn’t happen.) This is a small price to pay for the convenience.

1 thought on “Forward and inverse search

  1. Actually, the correct thing to do is to add xdvi.editor: gvim --servername xdvi --remote +%l %f to you .Xdefaults file.

Comments are closed.