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?
[Tex/LaTex] How to set up inverse search with Okular and Kile
editorsforward-inverse-searchkilesrcltx
Related Solutions
Well, you are actually describing two problems:
1) Using okular with kile for forward and reverse search.
Forward search works, as you describe, reverse search does not work for you. Unfortunately, you don't describe what doesn't work.
In particular, in xdvi reverse search is triggered by Ctrl+Click
, while in Okular reverse search is triggered by Shift+Click!
Apart from that, forward and backward search in Okular and Kile is already fully set up here on Ubuntu maverick.
2) Using xdvi
for forward searching (reverse search works for you)
While Kile has a "ForwardDVI" build class, this is not directly suited for xdvi, since it sets the %target
variable to something like
'file:/home/reinhold/remove-dash.dvi#src:64 ./remove-dash.tex'
which is the exact form needed by okular. However, xdvi doesn't know how to handle this target and thus fails. xdvi
needs to be invoked instead as
xdvi -sourceposition "linenumber filename.tex" filename.dvi
Unfortunately, kile does not provide any format string for the command to indicate the line number. The only solution is to tell kile to call xdvi not directly but through a helper script that takes the "dvifile#src:line texfile" string mentioned above, extracts the linenumber and then calls xdvi with those extracted values. One such script is kile2xdvi, which can be found at http://ubuntuforums.org/archive/index.php/t-1134500.html
Here's a copy of that script. Simply save it to ~/bin/kile2xdvi
and set that file to executable. Then you can configure kile to use it for forward search in xdvi:
- Menu item "Settings - Configure Kile...", "Tools - Build" entry in the list.
- Select "ForwardDVI", create a new configuration ("New..." button near the top of the dialog") named xdvi
- Set Command to
~/bin/kile2xdvi
and Options to'%target'
- Make sure the target extension is set to
dvi
- Press OK.
That's it, forward dvi search will now use xdvi and jump to the correct output.
If you still get errors, then take a look at the "Output" tab (lower right, next to "Log and messages"), because there you will get more detailled error messages.
Here is the kile2xdvi
script:
#!/usr/bin/perl
# kile2xdvi. (c) Juerg Wullschleger, 2009
if($ARGV[0] =~ m/file:(\S*)#src:(\S*) (\S*)/){
$dviFile = $1;
$line = $2;
$sourceFile = $3;
$sourcePos = '-sourceposition "'.$line.' '.$sourceFile.'"';
}else{
if((!$ARGV[0]) || ($ARGV[0] == "--help") || ($ARGV[0] == "-h")){
print 'usage: 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;
}
open(DVITYPE, "dvitype $dviFile|");
$firstline = <DVITYPE>;
$minH = 300*15; $maxH = -300*3;
$minV = 300*20; $maxV = -300*3;
$dpi = 0;
#find min/max of all "hh" and "vv" in $dviFile
while (<DVITYPE>) {
if(m/h:=(\S*)=(\S*), hh:=(\S*)/){
if($3 < $minH){ $minH = $3; }
if($3 > $maxH){ $maxH = $3; }
}elsif(m/v:=(\S*)=(\S*), vv:=(\S*)/){
if($3 < $minV){ $minV = $3; }
if($3 > $maxV){ $maxV = $3; }
}elsif(m/Resolution = (\S*) pixels per inch/){
$dpi = $1;
}
}
$offsetx = -int(100*$minH/$dpi - 10)/100; $paperx = int(100*($maxH - $minH)/$dpi + 20)/100;
$offsety = -int(100*$minV/$dpi - 10)/100; $papery = int(100*($maxV - $minV)/$dpi + 20)/100;
$bb = "-xoffset ".$offsetx."in -yoffset ".$offsety."in -paper +".$paperx."x".$papery."in";
$options = '-watchfile 0.5 -postscript 1 -expertmode 0 -mousemode 0 -s 6 -editor "kile --line %l %f" -nofork';
print "Executing: xdvi $options $bb $sourcePos $dviFile\n";
`xdvi $options $bb $sourcePos $dviFile\n`;
You can probably remove all the resolution and offset handling (all the lines between open
and $bb=...
, so this script is actually more complex then it needs to.
Okay, I found the error. Indeed .synctex.gz
was not written anymore. That happened because I specified an additional argument to latexmk
. I'll address this in another post, it's too specific and not related to this problem anymore.
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: