On Emacs, I am trying to get forward search with Okular. Right now, I have the following command:
okular --unique %o#src:%n`pwd`/./%b
But, this does not take me to the right line, as I'd expect. So, there is a problem here. In trying to fix this, I tried to read the manual for okular I could find.
Suspiciously, none of the %
commands appear there. The three that do appear are:
(1) %f
– file name
(2) %l
– line number of the file
(3) %c
– column number of the file
I'd be glad if you explain what are the %
commands that appear in the command I wrote and also help me find a working forward search command in this situation.
Relevant versions, you might want to know:
Emacs ——- 24.3.1
Okular ——- 0.16.2
AucTeX ——- 11.86
TeXLive —— 2012
Please feel free to ask anything that may be relevant.
P.S. In my humble opinion, this question is not a duplicate of the previous questions. I have asked a very precise question, not a working method, but a fix to what I have. :-)
But, I do agree that this is only border line TeXnical.
Best Answer
When
--synctex=1
is passed to the TeX engine, SyncTeX creates metadata that Okular can use for forward searches. To get Okular to open the PDF at the right spot, you must generate SyncTeX metadata and invoke Okular like this:As of TeX Live 2011, the syntax for
named_destination
is:Note that
<directory_containing_main_tex_file>
must be an absolute path. This requirement is new as of TeX Live 2011, which is why forward searching in AUCTeX doesn't "just work" anymore.<relative_path_to_file.tex>
is the relative path from the directory containing the main.tex
file to the file being visited in Emacs.Example
If you have the following two TeX files:
/tmp/foo/main.tex
:/tmp/foo/bar/stuff.tex
:and run:
then the following command:
should jump to page 2 (where "blah" is printed).
Enable SyncTeX in AUCTeX
To configure AUCTeX to pass
--synctex=1
to the TeX engine and generate PDFs, do the following:M-x customize-variable <RET> TeX-PDF-mode <RET>
M-x customize-variable <RET> TeX-source-correlate-mode <RET>
Configure AUCTeX to Launch Okular
To configure AUCTeX to launch Okular with the proper command-line arguments, do the following:
.tex
file:M-x customize-variable <RET> TeX-expand-list <RET>
%(masterdir)
(lambda nil (file-truename (TeX-master-directory)))
Define a new view program for Okular:
M-x customize-variable <RET> TeX-view-program-list <RET>
add a new entry to the list:
Okular
Command:
okular --unique %o#src:%n%(masterdir)./%b
Note that
%o
,%n
,%(masterdir)
, and%b
are substituted by AUCTeX before the command is executed, sookular
never sees those (it sees the expansion).%o
is the name of the generated PDF,%n
is the line number of the file you are visiting,%(masterdir)
is the absolute path of the directory containing the main.tex
file, and%b
is the relative path from the main.tex
file to the file you are visiting.M-x customize-variable <RET> TeX-view-program-selection <RET>
output-pdf
change the viewer toOkular
Or you can put the following in your
.emacs
: