如何使用 AUCTeX 在包含的文档中执行前向搜索/同步?

如何使用 AUCTeX 在包含的文档中执行前向搜索/同步?

我正在尝试使用 Emacs + AUCTeX 和 Skim.app 在 OS X 上进行正向搜索,将我的 .tex 文件与 .pdf 输出同步。我已将以下代码添加到我的 Emacs 配置中:

(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))

主文档中的一切工作正常,但是,当我尝试在包含的文件中使用前向搜索时,chapter1.tex出现错误:

Output file "chapter1.pdf" does not exist.

答案1

由于习惯了 TeXShop,我不知道必须手动设置主变量。在主文件中,我添加了以下内容(请注意上面问题中命令maindocument.tex的声明):pdflatex

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

在每个章节文件的末尾:

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

现在运行良好,谢谢@giordano!

似乎也可以在名为.dir-locals.elhttps://tex.stackexchange.com/a/167688/9610

相关内容