emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [tip] Export to PDF with latexmk 'continuous preview' option
@ 2024-03-05  0:58 Juan Manuel Macías
  0 siblings, 0 replies; only message in thread
From: Juan Manuel Macías @ 2024-03-05  0:58 UTC (permalink / raw)
  To: orgmode

A little-known (and sometimes very useful) latexmk option is the -pvc
option. According to the latexmk manual:

      [...] The second previewing option is the powerful -pvc option
      (mnemonic: "preview continuously"). In this case, latexmk
      runs continuously, regularly monitoring all the source files
      to see if any have changed. Every time a change is detected,
      latexmk runs all the programs necessary to generate a new
      version of the document. A good previewer will then
      automatically update its display. Thus the user can simply
      edit a file and, when the changes are written to disk,
      latexmk completely automates the cycle of updating the .dvi
      (and/or the .ps and .pdf) file, and refreshing the
      previewer's display. It's not quite WYSIWYG, but usefully

In order to use this option from Org, I have defined a simple minor mode
that runs latexmk with the -pvc option and creates a buffer to monitor
the process. Every time the document, or any file involved, is saved,
the PDF is updated. We can define in our `latexmkrc' our favorite
external PDF viewer (Atril, Okular, Evince, etc.). I have this line:

│ $pdf_previewer = "atril %O %S > /dev/null 2>&1 &";

And here's the code (for documents that are long, complex, or take a
while to export, it may be better to use the asynchronous version of

│ (defun my-org-compile-latexmk-interactive ()
│   (let* ((tex-file (org-export-output-file-name ".tex")))
│     (start-process-shell-command
│      "latexmk"
│      (format "*%s-latexmk-process*" (file-name-sans-extension tex-file))
│      (concat
│       "latexmk -f -pvc -lualatex -e '$lualatex=q/lualatex %O -shell-escape %S/' "
│       tex-file))))
│ (define-minor-mode org-interactive-compile-pdf-mode
│   "TODO"
│   :lighter " OrgInteractivePDF"
│   (if org-interactive-compile-pdf-mode
│       (progn
│       (my-org-compile-latexmk-interactive)
│       (add-hook 'after-save-hook #'org-latex-export-to-latex nil t))
│     (remove-hook 'after-save-hook #'org-latex-export-to-latex t)
│     (when (equal (process-status "latexmk") 'run)
│       (kill-process "latexmk"))))

And a screencast:


Juan Manuel Macías -- Composición tipográfica, tratamiento de datos, diseño editorial y ortotipografía

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-03-05  0:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-05  0:58 [tip] Export to PDF with latexmk 'continuous preview' option Juan Manuel Macías

Code repositories for project(s) associated with this public inbox


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).