[Tex/LaTex] How to set up inverse search with Okular and Kile

editorsforward-inverse-searchkilesrcltx

The title pretty much sums it up. I use the package srcltx in my documents. I am running Ubuntu with Kile 2.1 and Okular 0.8.2 as a viewer. I am pretty sure that inverse search should work, but I haven't been able to set it up. How does one configure the viewer and editor to make this feature work?

Best Answer

Check this Ubuntu forums thread: How can I do an inverse search between okular and kile?

Here is a summary of the required steps (not tested):

  • Setup inverse search from Okular:

    Settings -> Configure Okular .. -> Editor -> Editor dropdown: "custom text editor"

    command: kile %f --line %l

  • Set up Kile to tell LaTeX to add source info, i.e., set LaTeX build tools from Default to Modern:

    Settings -> Configure kile -> Build -> LaTeX -> "Modern" in the dropdown menu

  • Add a new forwardDVI configuration:

    Settings -> Configure kile -> Build -> forwardDVI

    then:

    1. "new..." button on the right
    2. choose a name
    3. put the full path to the perl script (see below) as the command (don't forget to escape, i.e., put a backslash in front of any spaces)
    4. put '%target' as Options (the single quotes are important)

#!/usr/bin/perl
# kile2okular. (c) Ian Wood, 2010
# based on:
# kile2xdvi. (c) Juerg Wullschleger, 2009

if($ARGV[0] =~ m/file:(.*)#src:(\S*) (\S*)/){
$dviFile = $1;
$line = $2;
$sourceFile = $3;
$sourcePos = '--unique "'.$line.' '.$sourceFile.'"';
if($dviFile =~ m|.*/([^/]*.dvi)|){
$dviFile = $1;
}else{
print 'usage1: kile2xdvi <dvifile> or kile2xdvi "file:<dvifile>#src:<line> <sourcefile>"'."\n";
exit;
}
}else{
if((!$ARGV[0]) || ($ARGV[0] == "--help") || ($ARGV[0] == "-h")){
print 'usage2: kile2xdvi <dvifile> or kile2xdvi "file:<dvifile>#src:<line> <sourcefile>"'."\n";
exit;
}
$dviFile = $ARGV[0];
$sourcePos = '';
}
if (!(-e $dviFile)){
print "$dviFile: No such file.\n";
exit -1;
}

`okular --unique "$dviFile#src:$line$sourceFile"\n`;
exit;