# Connecting GEdit and xdvi

I'm trying to connect GEdit and xdvi. I don't use the gedit LaTeX plugin as I don't use LaTeX, but plain TeX. Well, for the inverse search I compile the TeX file with the "external tools" plugin and the following code:

``````#!/bin/bash
TEXFILE=\$GEDIT_CURRENT_DOCUMENT_NAME
DVIFILE=\${TEXFILE/%.*/.dvi}
LOGFILE=\${TEXFILE/%.*/.log}
if pdftex -output-format=dvi -src-specials -halt-on-error \$TEXFILE; then
xdvi -editor gedit \$DVIFILE
else gedit \$LOGFILE
fi
``````

and the inverse search works quite well.

BUT I'm not able to set the direct search correctly. I'm trying the following code

``````#!/bin/bash
TEXFILE=\$GEDIT_CURRENT_DOCUMENT_NAME
DVIFILE=\${TEXFILE/%.*/.dvi}
xdvi -sourceposition \$GEDIT_CURRENT_LINE_NUMBER \$DVIFILE
``````

but it doesn't work. The error message is "No reference to source file "test.dvi" in DVI file."

Where is the fault?

-
If you are happy to use Evince rather then xdvi you can checkout askubuntu.com/q/68015/19490 –  N.N. Aug 6 '12 at 16:06
@N.N. Sorry, it doesn't works. Thanks anyway. –  Jean Baldraque Aug 6 '12 at 20:15

Jean, although I don't use gedit, it's a very useful editor, readily available in GNU/Linux, that it's underrated to say the least.

Second edit

I couldn't get it to work. The first time around, the file hadn't compiled from within the editor. So, I wrongly assumed that forward search was working. To top it off, I always see the error, right after posting an answer, so it didn't surprise me.

In the end I'm disappointed with it. I'm just editing the answer, in case someone has a solution over this problem.

The parameter to `-sourceposition "nn <ref>"` had to be hard coded into it, juxtaposing perhaps, the reason that lies in your question in the first place. Moreover, better not to compile another file from within the editor, or else the xdvi window from the previous one, would take priority. (But I'm sure you've come across this issue before).

So as you know, to call a special reference, from within the document, `input srctex.sty` must be loaded. And let's say, for the sake of posting an example, that the command`\special` is invoked, three times throughout the document: in the first, and last pages. So you would have a `\special{src:blue}`, a `\special{src:red}` and a `\special{src:black}`

``````
input srctex.sty

\input linden

\vfill\break
\special{src:blue}
\input lorem

\vfill\break

\input cervantes-es

\vfill\break

\input zapf

\special{src:red}

\vfil\break

\special{src:black}

\bye
``````

With that file in place, it doesn't really matter whether you decide to run it from the terminal or from gedit, as long as it jumps, wherever it is you want it to.

`\$: xdvi -sourceposition "n:blue" <file>`

Or in external tools

First edit

I noticed in the code you posted, that the variable does not need to precede the call to the dvi file. As you know, this is already defined in the options of the the external tools plugin.

The following is the list from https://wiki.gnome.org/action/show/Apps/Gedit/Plugins/ExternalTools

You'd need to omit the `\$GEDIT_CURRENT_LINE_NUMBER` from the above code, since the current line - where you would rather have, the direct search to be performed - might as well, be selected from the aforementioned options.

The following should work:

``````#!/bin/bash
TEXFILE=\$GEDIT_CURRENT_DOCUMENT_NAME
DVIFILE=\${TEXFILE/%.*/.dvi}
xdvi -sourceposition \$DVIFILE

if pdftex -output-format=dvi -src-specials -halt-on-error \$TEXFILE; then
xdvi -editor gedit \$DVIFILE
else gedit \$LOGFILE
fi
``````
-