Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm aware of the existence of another thread with almost the same title "How to set up inverse search with Okular and Kile", but it doesn't solve my problem (at least I think so).

I'm using Kile (on Ubuntu 10.4, with gnome), in default setting Okular is defined as a viewer for both options (viewDVI and forwardDVI). I've changed LaTeX form default to modern and forward search works, reverse not.

With the help of instructions found on http://www.latex-community.org/forum/:

go to: Settings -> Configure Kile -> Tools -> Build and select ViewDVI

on the General tab fill in the following values:

Command: xdvi

Options: -editor 'kile %f --line %l' '%target'

With that, reverse search works with xdvi, but forward search still opens okular. When I've tried to use the same way to set xdvi as a viewer for forwardDVI, the compilation results with:

[forwardDVI] finished with exit code 1

I was looking for the meaning of it and I've found that this is a catchall for general errors, which doesn't help me a lot...

The mentioned thread: I've performed steps one and two, I haven't use the script because I was not sure if I know how to do it and in any case I don't have problems with froward search with Okular, but with reverse search.

Thanks in advance for any tips

P.S.

I was trying to look into the Okular help, but I can't connect to it. When I enter F1 to acces Okular Handbook, appears the message Could not Launch the KDE Help Center: Could not find the service khelpcenter. The same happens when I try to look into the Kile Handbook. Might it be related with reverse search problem? Is it possible that it happens because I'm using Kile on Gnome?

Thanks

share|improve this question
1  
Does the answer in tex.stackexchange.com/questions/419/… help you? –  Caramdir Feb 19 '11 at 22:07
    
Unfortunatly no. Forward search works (and it was working anyway), but reverse - still works only with xdvi (and for it I don't know how to enable forwad search). Thanks anyway –  maria Feb 19 '11 at 23:23
    
Are you sure you have set the editor in okular correctly as in that link? ups this was supposed to be comment -.- –  user3722 Feb 20 '11 at 18:31
    
@Bort: Thank you for informing, I converted it into a comment. –  Stefan Kottwitz Feb 20 '11 at 18:33
    
@Bort: Yes, I'm sure. I've done it once again, by copy-paste. Editor is set on custom text editor, command is: `kile %f --line %l. Still forward search works, but reverse - not. –  maria Feb 20 '11 at 22:13

1 Answer 1

up vote 3 down vote accepted

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:

  1. Menu item "Settings - Configure Kile...", "Tools - Build" entry in the list.
  2. Select "ForwardDVI", create a new configuration ("New..." button near the top of the dialog") named xdvi
  3. Set Command to ~/bin/kile2xdvi and Options to '%target'
  4. Make sure the target extension is set to dvi
  5. 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.

share|improve this answer
    
thanks a lot. I was trying with Ctrl+click, so that's why it didn't work. As for xdvi it seems too complicate for me, I was trying to use your solution, but I think I'll stay with Okular. Thanks again. –  maria Sep 28 '11 at 16:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.