From: "Juan Manuel Macías" <maciaschain@posteo.net>
To: orgmode <emacs-orgmode@gnu.org>
Subject: [tip] Export to PDF with latexmk 'continuous preview' option
Date: Tue, 05 Mar 2024 00:58:34 +0000 [thread overview]
Message-ID: <877cihmr45.fsf@posteo.net> (raw)
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
close.
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
`org-latex-export-to-latex'):
┌────
│ (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:
<https://cloud.disroot.org/s/ztFfa27kdsnNkGc>
--
Juan Manuel Macías -- Composición tipográfica, tratamiento de datos, diseño editorial y ortotipografía
reply other threads:[~2024-03-05 0:59 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=877cihmr45.fsf@posteo.net \
--to=maciaschain@posteo.net \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
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).