From dd3739410cca217dc1e7022f22451ef47e0bcff3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marek=20Fel=C5=A1=C3=B6ci?= <marek.felsoci@inria.fr>
Date: Thu, 2 Feb 2023 16:19:56 +0100
Subject: [PATCH] Add function for removing a package from list of default
 LaTeX packages

---
 compose-publish.el | 12 ++++++++++++
 latex-publish.el   | 12 ++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/compose-publish.el b/compose-publish.el
index c192f1c..b8fba36 100644
--- a/compose-publish.el
+++ b/compose-publish.el
@@ -75,6 +75,18 @@
                  ("\\subsection{%s}" . "\\subsection*{%s}")
                  ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))))
 
+(defun remove-from-org-latex-default-packages-alist (package)
+  "Removes `package' from the list of packages that are included
+by default when exporting from Org to LaTeX, i.e. from
+`org-latex-default-packages-alist'. This is useful for controlling the order in
+which some of the packages are loaded in order to prevent conflicts or other
+undesirable behavior."
+  (let ((output '()))
+    (dolist (pkg org-latex-default-packages-alist)
+      (unless (string= package (nth 1 pkg))
+          (add-to-list 'output pkg t)))
+    (setq org-latex-default-packages-alist output)))
+
 ;; Load languages for code block evaluation.
 (org-babel-do-load-languages
  'org-babel-load-languages
diff --git a/latex-publish.el b/latex-publish.el
index 4d0fb43..ba1a13e 100644
--- a/latex-publish.el
+++ b/latex-publish.el
@@ -6,6 +6,18 @@
 ;; Preserve user-defined labels during the export to PDF via LaTeX.
 (setq org-latex-prefer-user-labels t)
 
+(defun remove-from-org-latex-default-packages-alist (package)
+  "Removes `package' from the list of packages that are included
+by default when exporting from Org to LaTeX, i.e. from
+`org-latex-default-packages-alist'. This is useful for controlling the order in
+which some of the packages are loaded in order to prevent conflicts or other
+undesirable behavior."
+  (let ((output '()))
+    (dolist (pkg org-latex-default-packages-alist)
+      (unless (string= package (nth 1 pkg))
+          (add-to-list 'output pkg t)))
+    (setq org-latex-default-packages-alist output)))
+
 ;; Custom publishing function for LaTeX files. This is useful when we need to
 ;; publish a manually written LaTeX file to PDF (e. g. a poster).
 (defun latex-publish-to-pdf (plist filename pub-dir)
-- 
GitLab