On 30/12/2025, Uwe Brauer wrote:
> And, hurray it works!!! Thanks very much, should your code somehow be
> included? I personally need this only when submitting to the ArXiv since
> they cannot deal with files generated by biber.
Here's a patch with a proposed fix. This affects all TeX-commands but I
argue in a positive and more consistent way (and similar to latexmk).

-- Al

>From 71502f0bbbcfea96fd61c9d805cdad8a9b261a3d Mon Sep 17 00:00:00 2001
From: Al Haji-Ali <[email protected]>
Date: Tue, 30 Dec 2025 21:25:34 +0000
Subject: [PATCH] Include TeX-output-dir in process env of TeX commands

* tex.el (TeX-process-environment): New function
(TeX-run-command): override `process-environment'.
---
 tex.el | 51 +++++++++++++++++++++++++++++++++++----------------
 1 file changed, 35 insertions(+), 16 deletions(-)

diff --git a/tex.el b/tex.el
index 601855bf01..7406fc37f4 100644
--- a/tex.el
+++ b/tex.el
@@ -8119,6 +8119,24 @@ requires special treatment."
 (defvar TeX-suppress-compilation-message nil
   "If non-nil, suppress \"display results of compilation\" message.")
 
+(defun TeX-process-environment ()
+  "Return a modified copy of `process-environment' with updated TeX paths.
+
+Updates the environment variables `BIBINPUTS' and `TEXINPUTS' to include
+`TeX-output-dir' if it's not already present.  Also sets `TEXMFOUTPUT'
+to the value of `TeX-output-dir'.  Returns the modified copy of
+`process-environment'."
+  (let ((process-environment (copy-sequence process-environment)))
+    (when TeX-output-dir
+      (setenv "TEXMFOUTPUT" TeX-output-dir)
+      (dolist (e '("BIBINPUTS" "TEXINPUTS"))
+        ;; Add TeX-output-dir if not already there
+        (let ((parts (split-string (or (getenv e) "") path-separator)))
+          (unless (member TeX-output-dir parts)
+            (push TeX-output-dir parts)
+            (setenv e (mapconcat #'identity parts path-separator))))))
+    process-environment))
+
 (defun TeX-run-command (name command file)
   "Create a process for NAME using COMMAND to process FILE.
 Return the new process."
@@ -8149,22 +8167,23 @@ Return the new process."
     (setq TeX-sentinel-function
           (lambda (_process name)
             (message (concat name ": done."))))
-    (if TeX-process-asynchronous
-        (let ((process (start-process name buffer TeX-shell
-                                      TeX-shell-command-option command)))
-          (if TeX-after-start-process-function
-              (funcall TeX-after-start-process-function process))
-          (TeX-command-mode-line process)
-          (set-process-filter process #'TeX-command-filter)
-          (set-process-sentinel process #'TeX-command-sentinel)
-          (set-marker (process-mark process) (point-max))
-          (require 'compile)
-          (setq compilation-in-progress (cons process compilation-in-progress))
-          process)
-      (setq mode-line-process ": run")
-      (force-mode-line-update)
-      (call-process TeX-shell nil buffer nil
-                    TeX-shell-command-option command))))
+    (let ((process-environment (TeX-process-environment)))
+      (if TeX-process-asynchronous
+          (let ((process (start-process name buffer TeX-shell
+                                        TeX-shell-command-option command)))
+            (if TeX-after-start-process-function
+                (funcall TeX-after-start-process-function process))
+            (TeX-command-mode-line process)
+            (set-process-filter process #'TeX-command-filter)
+            (set-process-sentinel process #'TeX-command-sentinel)
+            (set-marker (process-mark process) (point-max))
+            (require 'compile)
+            (setq compilation-in-progress (cons process compilation-in-progress))
+            process)
+        (setq mode-line-process ": run")
+        (force-mode-line-update)
+        (call-process TeX-shell nil buffer nil
+                      TeX-shell-command-option command)))))
 
 (defun TeX-run-set-command (name command)
   "Remember TeX command to use to NAME and set corresponding output extension."
-- 
2.39.5 (Apple Git-154)

Reply via email to