Randy Ridenour

LaTeX Compilation Scripts

Jul 26, 2021

I’m trying to automate \(\LaTeX\) compilation from Emacs as much as I can. Here are the shell scripts and Emacs functions that I’m using.

Shell Scripts 🔗

Here are some very simple scripts for compiling \(\LaTeX\) files with arara and the fish shell. The first, called “mkt” for “make TeX”, runs arara on the source file, then opens the resulting PDF.

function mkt
  arara $argv
  set output_file (string replace -r tex\$ pdf $argv)
  open -g $output_file
end

The second, called “mktc” for “make TeX continuously”, runs arara, opens the PDF, watches for changes, and runs arara whenever the file is saved.

function mktc
  arara $argv
  set output_file (string replace -r tex\$ pdf $argv)
  open -g $output_file
  fswatch -o $argv | xargs -n1 -I{} arara $argv
end

Emacs 🔗

Here are some functions to use in Emacs to run the scripts.

Auctex 🔗

(defun rlr/tex-mkt ()
  "Compile with arara."
  (interactive)
  (async-shell-command (concat "mkt " (buffer-file-name))))

(defun rlr/tex-mktc ()
  "Compile continuously with arara."
  (interactive)
  (start-process-shell-command (concat "mktc-" (buffer-file-name)) (concat "mktc-" (buffer-file-name)) (concat "mktc " (buffer-file-name))))

The first compiles with an asynchronous shell command, so that you can immediately return to editing the file while arara runs. I decided to use start-process-shell-command instead of async-shell-command for mktc, since mkt runs once and stops, while mktc keeps running in the background. When rlr/tex-mktc is called, a process is started that has the same name as the file with “mktc-” prepended it to it. The process is shown in a buffer that has the same name. That way, several files can be compiled at the same time.

Org Mode 🔗


(defun rlr/org-mkt ()
  "Make PDF with Arara."
  (interactive)
  (org-latex-export-to-latex)
  (async-shell-command (concat "mkt " (file-name-sans-extension (buffer-file-name))".tex")))

(defun rlr/org-mktc ()
  "Compile continuously with arara."
  (interactive)
  (org-latex-export-to-latex)
  (start-process-shell-command (concat "mktc-" (buffer-file-name)) (concat "mktc-" (buffer-file-name)) (concat "mktc " (file-name-sans-extension (buffer-file-name))".tex")))

These functions first export the org file to \(\LaTeX\), then compile the corresponding TeX files. All in all, a morning’s worth of work to save a few keystrokes. I run them using major mode hydras .

Org Export to PDF with Arara

Jul 21, 2021

I switched from latexmk to arara for compiling \(\LaTeX\) files. I like being able to embed the compilation steps into the document. That way, I can run the same command to compile, but use PDFLaTeX on some and LuaLaTeX on others. Org mode’s export to PDF uses latexmk, though. I think I managed to set it to arara with this:

(setq org-latex-pdf-process '("arara %f"))

Abbreviate Path to iCloud Files in Emacs

Jul 18, 2021

When I include everything I do over my breaks in summer and January, I probably work more from my home computer than I do my office computer. A good file synchronization service makes that much easier. For years, I really only used Dropbox, and it served my needs very well. Just like the 20 MB (as in megabytes, not a typo) hard drive that I had in my first PC, it seemed like I would never run out of Dropbox space. Two problems eventually occurred. First, I did indeed reach the limit of my free tier. Second, Dropbox began enforcing a limit on the number of different devices that could sync with the free tier. I wasn’t inclined to pay for more space, because, I was already paying for extra space in iCloud for photo syncing. So, I decided to move my working documents from Dropbox to iCloud, which has worked great except for one small thing. Here is the full path and filename for one of my typical files:

/Users/rlridenour/Library/Mobile Documents/com~apple~CloudDocs/Documents/teaching/critical-thinking/notes/probabability-presentation.tex

This line is 136 characters long, and unless I expanded the size of the Emacs frame to at least half of the size of my 32-inch desktop monitor, I couldn’t see the filename in the recent files list.

Adding this to my Doom Emacs config solved the problem:

(use-package ivy-rich
  :after counsel
  :config
  (setq ivy-rich-display-transformers-list
        (plist-put ivy-rich-display-transformers-list
'counsel-buffer-or-recentf
    '(:columns
      ((counsel-buffer-or-recentf-transformer (:width (lambda (x) (ivy-rich-switch-buffer-shorten-path x (ivy-rich-minibuffer-width 1.0))))))))))

Now, when I run counsel-buffer-or-recentf, Emacs abbreviates enough of the file paths to make each line fit into the frame. How much is abbreviated depends on how large the frame is. No matter how narrow the frame, though, I can still see the filename.