You can tell auctex use absolute path by changing the LaTeX command. First, you need an updated version of auctex, as Richard Hansen points out. I've installed the CVS version, but I think it should be enough updating tex.el(c)
.
Then, go to the "Customize AUCTex" menu:
LaTeX → Customize AUCTeX → Extend this Menu
LaTeX → Customize AUCTeX → TeX Command → TeX expand list
and add a new item:
Key: %(dir)
Expander: (lambda nil default-directory)
and save for future sessions (if you wish)
Now, go to "TeX command list" (LaTeX → Customize AUCTeX → TeX Command → TeX command list) and edit the "LaTeX" item:
Command: %`%l%(mode)%' %(dir)%t
save and, you got it!
This way works fine for me, in Ubuntu 11.10, auctex from CVS (2012-01-11), evince 3.2.1, TeX Live 2011 and emacs 23.3.
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:
okular document_name#named_destination
As of TeX Live 2011, the syntax for named_destination
is:
src:<line_number><directory_containing_main_tex_file>/./<relative_path_to_file.tex>
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:
and run:
cd /tmp/foo
pdflatex --synctex=1 main
then the following command:
okular 'main.pdf#src:3/tmp/foo/./bar/stuff.tex' &
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:
- Enable PDF mode:
- type
M-x customize-variable <RET> TeX-PDF-mode <RET>
- toggle "Tex Pdf Mode" on (non-nil)
- click "State" and choose "Save for Future Sessions"
- Enable SyncTeX:
- type
M-x customize-variable <RET> TeX-source-correlate-mode <RET>
- toggle "Tex Source Correlate Mode" on (non-nil)
- click "State" and choose "Save for Future Sessions"
Configure AUCTeX to Launch Okular
To configure AUCTeX to launch Okular with the proper command-line arguments, do the following:
- Define new expander to get the directory of the main
.tex
file:
- type
M-x customize-variable <RET> TeX-expand-list <RET>
- add a new entry to the list:
- Key:
%(masterdir)
- Expander:
(lambda nil (file-truename (TeX-master-directory)))
- Arguments: none
- click "State" and choose "Save for Future Sessions"
Define a new view program for Okular:
- type
M-x customize-variable <RET> TeX-view-program-list <RET>
add a new entry to the list:
- Name:
Okular
- Choice: Command
Command: okular --unique %o#src:%n%(masterdir)./%b
Note that %o
, %n
, %(masterdir)
, and %b
are substituted by AUCTeX before the command is executed, so okular
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.
- click "State" and choose "Save for Future Sessions"
- Configure Okular as the PDF viewer:
- type
M-x customize-variable <RET> TeX-view-program-selection <RET>
- for
output-pdf
change the viewer to Okular
- click "State" and choose "Save for Future Sessions"
Or you can put the following in your .emacs
:
;; use Okular to view AUCTeX-generated PDFs
(when (require 'latex nil t)
(push '("%(masterdir)" (lambda nil (file-truename (TeX-master-directory))))
TeX-expand-list)
(push '("Okular" "okular --unique %o#src:%n%(masterdir)./%b")
TeX-view-program-list)
(push '(output-pdf "Okular") TeX-view-program-selection))
Best Answer
Add the following code, taken from https://lists.gnu.org/archive/html/bug-auctex/2013-04/msg00004.html, to your
.emacs
Current version of AUCTeX supports forward/inverse search with Evince out-of-the-box, there is no more need to use old hacks.