feat(export): route all exports to ~/exports/<type>/, cleanup LaTeX aux files

- my/org-export-directory: returns ~/exports/<ext>/, creates dir if needed
- my/org-export-output-file-name: advice on org-export-output-file-name
  routes .pdf/.html/.odt etc to ~/exports/pdf/ ~/exports/html/ etc
  .tex (intermediate for PDF) routed to same ~/exports/pdf/
- org-latex-remove-logfiles t + extended logfiles-extensions list
  covers all latexmk outputs: bbl, fdb_latexmk, fls, synctex.gz, run.xml...
This commit is contained in:
2026-02-23 20:47:42 +01:00
parent b2e3e82995
commit 299689c687

View File

@@ -389,6 +389,32 @@ Bound to cmd+v in org-mode and markdown-mode."
(setq org-latex-pdf-process (setq org-latex-pdf-process
'("latexmk -f -pdf -%latex -interaction=nonstopmode -output-directory=%o %f"))) '("latexmk -f -pdf -%latex -interaction=nonstopmode -output-directory=%o %f")))
;;; LaTeX aux file cleanup after export
;; org-latex-remove-logfiles t is the default; extend the list to cover all
;; latexmk output files (bbl, fdb_latexmk, fls, synctex.gz, run.xml, etc.)
(with-eval-after-load 'ox-latex
(setq org-latex-remove-logfiles t
org-latex-logfiles-extensions
'("aux" "bbl" "bcf" "blg" "fdb_latexmk" "fls" "idx" "log"
"nav" "out" "ptc" "run.xml" "snm" "synctex.gz" "toc" "vrb" "xdv")))
;;; Export directory routing
;; All exports go to ~/exports/<type>/ (created automatically if absent).
;; .tex is intermediate for PDF export -- both routed to exports/pdf/.
(defun my/org-export-directory (extension)
"Return ~/exports/<type>/ directory for file EXTENSION, creating it if needed."
(let* ((ext (downcase (string-trim-left extension "\\.")))
(subdir (if (string= ext "tex") "pdf" ext))
(dir (expand-file-name (concat "exports/" subdir "/") "~")))
(make-directory dir t)
dir))
(defun my/org-export-output-file-name (orig extension &optional subtreep pub-dir)
"Route org exports to ~/exports/<type>/ unless pub-dir is already set."
(funcall orig extension subtreep (or pub-dir (my/org-export-directory extension))))
(advice-add 'org-export-output-file-name :around #'my/org-export-output-file-name)
;;; ============================================================ ;;; ============================================================
;;; ORG MODE — CUSTOM BEHAVIOR ;;; ORG MODE — CUSTOM BEHAVIOR