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.
Texmaker comes with a build in PDF previewer that supports synctex. If I remember correctly, it is "embedded" by default. That is, editor and previewer is a part of the same bigger window. This might not be useful if the screen is small, say on a small laptop. Editor and previewer can be separated into two separate Windows via the Texmaker configuration (just remove the tick mark at "embedded" and restart Texmaker)
Texmakers cousin Texstudio made this even easier: there the separation is a button on the previewer.
Best Answer
Kile does not know about the structure of your project. If you do not explicitly specify a master file, it assumes that the file you are currently editing is the master file and tries to open a PDF file with the same name (and produces the error you are getting).
As a solution, you can either create a Kile project that stores the relationship between your tex files or use the
Settings > Define current document as 'Master Document'
option.