Update:
Okular will jump to the right document section if you invoke it like this:
okular --unique test.dvi#src:33test.tex
okular --unique test-main.dvi#src:33test-intro.tex
The %target macro in Kile's forwardDVI options produces output in the right form except with a space between the line number and file, which breaks it into two arguments and okular dies. (in fact, I had 3 since there's a space in the path to my directory).
So I used quotes around '%target', except then the # turns into %26 and okular dies.
Then I hit another problem: okular is run in the latex source code directory, and prepends the path to it's arguments: one of my 3 arguments above also had the path repeated!
At this point I nearly gave up, but stumbled across Juerg Wullschleger's post on May 28 09 here. He wrote a perl script to get xdvi working (which, by the way, isn't in lucid ubuntu yet, nor kdvi). A little editing of his script and I came up with the one below, which is working for me! Yay! Way too much time wasted on this!
I put the script in a folder somewhere, used chmod to make it executable and put it's full path as a new forwardDVI configuration:
Settings -> configure kile -> Build -> forwardDVI then:
- "new..." button on the right
- give it a name, perhaps "My Okular"
- put the full path to your perl script as the command (don't forget to escape==[put backslash in front of] any spaces)
- put '%target' as Options (the single quotes are important: the script gets it all as one argument that way, otherwise it's broken up at spaces, one of which Kile puts in there for you)
Don't forget to setup inverse search from Okular: Settings -> Configure Okular .. -> Editor -> editor dropdown: "custom text editor", command: "kile %f --line %l"
And set up Kile to tell LaTeX to add source info: Settings -> configure kile -> Build -> LaTeX -> "Modern" in the dropdown
Code:
#!/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;
Bookmarks