3

I’m trying to sync my .tex file with the .pdf output with a forward search on OS X using Emacs + AUCTeX and Skim.app. I have added the following code to my Emacs configuration:

(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq-default TeX-master nil)
(add-hook 'LaTeX-mode-hook 'visual-line-mode)
(add-hook 'LaTeX-mode-hook 'flyspell-mode)
(add-hook 'LaTeX-mode-hook 'LaTeX-math-mode)
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)
(setq reftex-plug-into-AUCTeX t)
(setq TeX-PDF-mode t)

;; Use Skim as viewer, enable source <-> PDF sync
;; make latexmk available via C-c C-c
;; Note: SyncTeX is setup via ~/.latexmkrc (see below)
(add-hook 'LaTeX-mode-hook (lambda ()
                             (push
                              '("latexmk" "latexmk -pdf %s" TeX-run-TeX nil t
                                :help "Run latexmk on file")
                              TeX-command-list)))
(add-hook 'LaTeX-mode-hook (lambda ()
                             (push
                              '("pdflatex" "pdflatex -synctex=1 %s" TeX-run-TeX nil t
                                :help "Run pdflatex with SyncTex on file")
                              TeX-command-list)))
(add-hook 'TeX-mode-hook '(lambda () (setq TeX-command-default "pdflatex")))

;; use Skim as default pdf viewer
;; Skim's displayline is used for forward search (from .tex to .pdf)
;; option -b highlights the current line; option -g opens Skim in the background
(setq TeX-view-program-selection '((output-pdf "PDF Viewer")))
(setq TeX-view-program-list
      '(("PDF Viewer" "/Applications/Skim.app/Contents/SharedSupport/displayline -b -g %n %o %b")))

(add-hook 'LaTeX-mode-hook
          (lambda () (local-set-key (kbd "<M-S-mouse-1>") #'TeX-view)))

(setenv "PATH" (concat "/usr/texbin" ":" "/Applications/Emacs.app/Contents/MacOS" ":" "/usr/local/bin" ":" (getenv "PATH")))
(setq exec-path (append
                 '("/usr/texbin"
                   "/Applications/Emacs.app/Contents/MacOS/libexec"
                   "/Applications/Emacs.app/Contents/MacOS/bin"
                   "/usr/local/bin") exec-path))

Everything works fine in the main document, however, when I try to use forward search in an included file, say chapter1.tex, I get an error:

Output file "chapter1.pdf" does not exist.
Lenar Hoyt
  • 1,629
  • and https://www.gnu.org/software/auctex/manual/auctex/I_002fO-Correlation.html helps? no skim to test it with, but shall be standard – doed Nov 29 '14 at 07:12
  • 1
    It seems you didn't indicate the master file of chapter1.tex, did you? – giordano Nov 29 '14 at 08:44

1 Answers1

3

Being used to TeXShop I didn’t know that I had to set the master variable manually. In the master file maindocument.tex file I added this (note the declaration of the pdflatex command in my question above):

%%% Local Variables:
%%% mode: latex
%%% TeX-engine: pdflatex
%%% End:

and at the end of each chapter file:

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "maindocument.tex"
%%% End:

It works fine now, thanks @giordano!

It seems one can alternatively specify these variables per directory in a separate file called .dir-locals.el: https://tex.stackexchange.com/a/167688/9610

Lenar Hoyt
  • 1,629
  • 1
    Indeed you don't need to do it completely manually: since you set TeX-master to nil, whenever you open a new *TeX buffer you'll be prompted for the master file. If you open an old file, issue C-c _ to set the master file. Ah, there is no such pdflatex engine, did you mean default (see http://www.gnu.org/software/auctex/manual/auctex.html#index-TeX_002dengine). – giordano Dec 03 '14 at 09:24
  • I don’t quite remember where I have these variable declarations from, but I have declared a command for using pdflatex (see the code in my question). I’m not entirely sure whether that is necessary, but it does work. – Lenar Hoyt Dec 03 '14 at 22:36