0

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?

4
  • 2
    Are you using the AUCTeX library, or the builtin latex library, or your own custom method to generate the pdf file?
    – lawlist
    Jan 14, 2020 at 16:56
  • I'll have to look. I installed tex on my machine(macos) set up the tex-file command to build using pdflatex. I haven't done anything more than that.
    – sergio_101
    Jan 14, 2020 at 18:09
  • Try using: C-c C-v which is bound to the function tex-view defined by the function tex-define-common-keys in the built-in tex-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 type C-h m to see some of the bound keyboard shortcuts.
    – lawlist
    Jan 14, 2020 at 19:58
  • thanks, @lawlist .. I installed AUCTeX, and it looks like C-ca does the trick.
    – sergio_101
    Jan 14, 2020 at 21:40

2 Answers 2

1

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

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.