I want to run the following commands when emacs compiles a latex file.
FILE="main.tex" # currently opened buffer in the emacs
pdflatex -shell-escape -shell-escape -jobname=main_temp $FILE
mv main_temp.pdf main.pdf
open main.pdf
Goal: I am using following pdf editor (https://pdfexpert.com) to read my update tex file's generated pdf in dark mode.
By default when pdflatex -shell-escape -interaction=batchmode current_buffer.tex
is executed by emacs, during the compilation of the tex file,the pdf reader shows the following message with a white background for a few seconds, which hurts the eye when switching from black to white and then after compilation from white to black again.
So I just want to trick the pdf-reader to open the compiled pdf when emacs compiles a tex file to a different name and move it to original pdf file when it completes its operation via:
mv paper_temp.pdf paper.pdf
open paper.pdf
minimal.el
(require 'package)
(setq user-init-file (or load-file-name (buffer-file-name)))
(setq user-emacs-directory (file-name-directory user-init-file))
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
(setq frame-background-mode 'dark)
(require 'tex)
(add-to-list 'TeX-expand-list
'("%(mode)"
(lambda nil
(if TeX-interactive-mode ""
" -interaction=batchmode"))))
(setq TeX-command-extra-options " -shell-escape")
(defun my-run-latex ()
"Save all buffers and run LaTeX on the current master."
(interactive)
(let* ((inhibit-message t)
(TeX-command-force "LaTeX")
(TeX-clean-confirm t)
(TeX-save-query nil)
(master (TeX-master-file))
(process (and (stringp master) (TeX-process master))))
(TeX-save-document master)
(when (and (processp process)
(eq (process-status process) 'run))
(delete-process process))
(TeX-command-master)))
(setq LaTeX-item-indent 0)
(setq TeX-auto-save t)
(setq TeX-parse-self t)
(add-hook 'LaTeX-mode-hook 'hl-todo-mode)
(add-hook 'TeX-update-style-hook 'hl-todo-mode)
(add-hook 'LaTeX-mode-hook 'writegood-mode)
(add-hook 'LaTeX-mode-hook (lambda ()
(TeX-global-PDF-mode t)))
I'm using my-run-latex()
function to compile my tex file.