I am able to run pdflatex
via tex-file
, and the PDF generates just fine. How would I go about automatically opening the resultant PDF file after generation?
2 Answers
you can use the latex-preview-pane-mode
included in the auctex
package.
start it whenever you want to see the pdf generated, and then as you type latex and save it you see in the other pane the result
you can run TeX-view
(vanilla emacs C-c C-v
), but it might require some configuration to get working as you want it.
something like the following got me going recently:
;; Use emacs' pdf-tools to open PDF files:
(setq TeX-view-program-selection '((output-pdf "PDF Tools"))
TeX-source-correlate-start-server t)
;; use synctex for click on pdf to jump to that point in tex file, and vice versa:
(setq TeX-source-correlate-mode t)
(setq TeX-source-correlate-method 'synctex)
;; Update PDF buffers after successful LaTeX runs
;; does this actually work tho?
(add-hook 'TeX-after-compilation-finished-functions
#'TeX-revert-document-buffer)
if you want the pdf display to update on save, you can use latexmk
:
(add-hook 'LaTeX-mode-hook
(lambda ()
(push
'("latexmk" "latexmk -pvc -pdf --synctex=1 %s" TeX-run-TeX nil t
:help "Run latexmk on file")
TeX-command-list)))
(add-hook 'TeX-mode-hook '(lambda () (setq TeX-command-default "latexmk")))
the -pvc
flag is for continuous (live-updating) preview.
then you need to edit ~/.latexmkrc
to tell it to use pdf-tools as your previewer:
$pdf_previewer="emacsclient -e '(find-file-other-window %S)'";
$pdflatex='pdflatex %O -interaction=nonstopmode %S';
$pdf_update_method = 4;
$pdf_update_command = "emacsclient -e '(with-current-buffer (find-buffer-visiting %S) (pdf-view-revert-buffer nil t))'";
this presumes you're running emacs in daemon/server mode (emacsclient
).
if this works you don't have to haggle with C-c C-c
or C-c C-a
and answer yes three times in order to update your preview.
syntex
and latexmk
need to be installed, but are often bundled with tex packages.
source: some reddit, etc. harvestings i recently did.
disclaimer: i'm not running macOS.
C-c C-v
which is bound to the functiontex-view
defined by the functiontex-define-common-keys
in the built-intex-mode.el
library. This comment assumes that you are using a generic version of Emacs for OSX/MacOS without having installed the AUCTeX library. While focus is within the *.tex buffer you can typeC-h m
to see some of the bound keyboard shortcuts.