* Automatically Generate PDFs upon Save :emacs: :PROPERTIES: :CREATED: [2025-12-03 Wed 09:25] :SLUG: automatically-generate-pdfs-upon-save :MODIFIED: 2026-10-01 :DESCRIPTION: Live preview when writing LaTeX! :IMAGE: ./resources/emacs-birthday-present.png 350 350 :CUSTOM_ID: automatically-generate-pdfs-upon-save :END: Here is my =~/.latexmkrc= file: It previews PDFs using Emacs, uses LuaLaTeX for making PDFs, and to update the PDF viewer please change focus to the PDF file. #+begin_src shell :tangle "~/.latexmkrc" $pdf_previewer="emacsclient %S"; $pdflatex = 'lualatex -interaction=nonstopmode -synctex=1 %O %S'; $pdf_update_method = 4; $pdf_update_command = "emacsclient %S &"; #+end_src # $pdf_update_command = "emacsclient -e '(progn (switch-to-buffer-other-window (find-buffer-visiting %S)) (pdf-view-revert-buffer nil t))'"; Then files that want to have this feature should end with: #+begin_src org :tangle no ,* Local Variables :ignore: # Ensure EmacsClient can connect to running emacs, enable automatic reverts for whenever PDFs change. # Local Variables: # eval: (server-start) # eval: (global-auto-revert-mode) # eval: (add-hook 'after-save-hook 'org-latex-export-to-latex nil t) # eval: (compile "latexmk -pdf -pvc -pdflatex='lualatex -shell-escape -interaction nonstopmode'") # End: #+end_src # alias emacsclient="/usr/local/Cellar/emacs-plus@29/29.0.90/bin/emacsclient" # export PATH="/usr/local/Cellar/emacs-plus@29/29.0.90/bin/:$PATH" # emacs & emacsclient