[ Cc: Al Haji-Ali ]

Hi Michael,

>>>>> "Braun, Michael" <[email protected]> writes:
> I just upgraded to AucTeX 13.1.3, and want to use the new feature of
> putting intermediate and preview files in a subdirectory. So I set
> TeX-output-dir to “build”, and all works well for compiling pdf
> documents with the default and LuaTeX engines, and all preview
> functions with the default engine. With luatex, preview-document also
> works. But if TeX-engine is luatex, and I run preview-at-point or
> preview-buffer, I get the following error:
> Running `Preview-LaTeX' on `~/Documents/build/_region_' with ``lualatex 
> --jobname=build/_region_  -file-line-error  --output-directory="build/" 
> --synctex=1 
> "\nonstopmode\nofiles\PassOptionsToPackage{active,tightpage,auctex}{preview}\AtBeginDocument{\ifx\ifPreview\undefined\RequirePackage[displaymath,floats,graphics,textmath,sections,footnotes]{preview}[2004/11/05]\fi}"
>  "\input" "\detokenize{" _region_.tex "}"''
> This is LuaHBTeX, Version 1.15.0 (TeX Live 2022) 
>  restricted system commands enabled.
> LaTeX2e <2022-06-01> pre-release-0 (develop 2022-6-12 branch)
> L3 programming layer <2022-06-02>
> No auxiliary output files.

> ./build//_region_.tex:0: I can't write on file `build/_region_.log'.
> Please type another transcript file name
> ./build//_region_.tex:0: Emergency stop
> ./build//_region_.tex:0:  ==> Fatal error occurred, no output PDF file 
> produced!
> TeX Output exited as expected with code 1 at Sun Jun 12 16:42:15
> LaTeX: LaTeX found no preview images

> There is a build subdirectory, and in it there is a _region_.tex file,
> but no _region_.log file is generated. The error occurs whether or not
> I cache the preamble. If TeX-output-dir is nil, everything works well,
> as expected.

> Here’s a minimal working example that generates the error.

> -----
> \documentclass{article}
> \begin{document}

> test $\alpha + \beta$.  %% preview should appear here.

> \end{document}

> % Local Variables: %
> % TeX-engine: luatex  %
> % TeX-output-dir: "build" %
> % End: %
> ――

> Any idea about what’s going on, and/or how to fix this?

Thanks for your report. When TeX-output-dir option is enabled,
preview-latex have to omit subdirectory name from the parameter
"--jobname" in invocation of lualatex, which wasn't implemented.

I think the attached patch fixes the problem. I'd like you to test it if
possible.

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine

>From cb1876d9acbeb934873305e268c2fb48adc0e29c Mon Sep 17 00:00:00 2001
From: Ikumi Keita <[email protected]>
Date: Mon, 13 Jun 2022 18:30:34 +0900
Subject: [PATCH] Fix region preview with TeX-output-dir feature

* tex.el (TeX-expand-list-builtin): Add a new directive
"%(s-filename-only)".
(TeX-engine-alist-builtin): Use it for --jobname parameter for
lualatex.
; (TeX-active-master-with-quotes): Adjust word spacing and refill doc
string.
---
 tex.el | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/tex.el b/tex.el
index ea5fbbda..86f04e1c 100644
--- a/tex.el
+++ b/tex.el
@@ -592,6 +592,7 @@ string."
     ;; adds suitable quotes for use in shell command line.
     ("%s" TeX-active-master-with-quotes nil t)
     ("%t" TeX-active-master-with-quotes t t)
+    ("%(s-filename-only)" TeX-active-master-with-quotes nil t nil nil file-name-nondirectory)
     ("%(t-filename-only)" TeX-active-master-with-quotes t t nil nil file-name-nondirectory)
     ;; If any TeX codes appear in the interval between %` and %', move
     ;; all of them after the interval and supplement " \input".  The
@@ -1511,7 +1512,7 @@ Check the `TeX-view-program-selection' variable" viewer)))
     (xetex "XeTeX" "xetex" "xelatex" "xetex")
     ;; Some lualatex versions before 0.71 would use "texput" as file
     ;; name if --jobname were not supplied
-    (luatex "LuaTeX" "luatex" "lualatex --jobname=%s" "luatex")
+    (luatex "LuaTeX" "luatex" "lualatex --jobname=%(s-filename-only)" "luatex")
     (omega "Omega" TeX-Omega-command LaTeX-Omega-command ConTeXt-Omega-engine))
   "Alist of built-in TeX engines and associated commands.
 For a description of the format see `TeX-engine-alist'.")
@@ -7316,19 +7317,19 @@ Pass arguments EXTENSION NONDIRECTORY ASK to `TeX-active-master'.
 If the returned file name contains space, enclose it within
 quotes `\"' when \" \\input\" is supplemented (indicated by
 dynamically bound variable `TeX-command-text' having string
-value.) Also enclose the file name within \\detokenize{} when
+value.)  Also enclose the file name within \\detokenize{} when
 the following three conditions are met:
   1. compiling with standard (pdf)LaTeX or upLaTeX
   2. \" \\input\" is supplemented
   3. EXTRA is non-nil (default when expanding \"%T\")
-Adjust dynamically bound variable `TeX-expand-pos' to avoid possible
-infinite loop in `TeX-command-expand'.
+Adjust dynamically bound variable `TeX-expand-pos' to avoid
+possible infinite loop in `TeX-command-expand'.
 If PREPROCESS-FN is non-nil then it is called with the filename
 as an argument and the result is enclosed instead of the
 filename.
 
-Helper function of `TeX-command-expand'. Use only within entries in
-`TeX-expand-list-builtin' and `TeX-expand-list'."
+Helper function of `TeX-command-expand'. Use only within entries
+in `TeX-expand-list-builtin' and `TeX-expand-list'."
   (let* ((raw (TeX-active-master extension nondirectory ask))
          ;; String `TeX-command-text' means that the file name is
          ;; given through \input command.
-- 
2.35.2

Reply via email to