Hi Ikumi,
On 07/03/2021, Ikumi Keita wrote:
>> I just pushed a new version of the patch to my public repo (rebased to
>> master) https://github.com/haji-ali/auctex
>
> I encountered other problems, even when `TeX-output-dir' is nil:
Thank you again for taking the time and teasing out these issues. I am
dog-fooding this patch but I never thought of setting TeX-master to nil (I
actually just learned it's a valid value in AUCTeX) and I don't usually open
compressed files.
> Obviously the remaining cross dependency between `TeX-master-file' and
> `TeX-master-output-dir' is the origin of these troubles. I recommend to
> restrict call on `TeX-master-output-dir' in `TeX-master-file' within
> cases that the extension matches output files.
> Or it would be much nice if it is possible to remove the cross
> dependency completely. Isn't it possible to implement
> `TeX-master-output-dir' without calling `TeX-master-file' at all?
The inter-dependency between `TeX-master-output-dir' and `TeX-master-file` is
not real, as you previously pointed out. Since `TeX-master-file` calls
`TeX-master-output-dir' with a non-nil second argument and TeX-master-file in
then never called inside `TeX-master-output-dir'. I only kept the call to
TeX-master-file inside `TeX-master-output-dir' so that when the function is
called from other functions one does not have to provide the master file as an
argument and it is obtained from TeX-master-file.
The reason `TeX-master-output-dir' needs the name of master file (and the
buffer of the master file) is because the value of TeX-output-dir should be
obtained from that file and not from other sub-files. The issue previously is
that when TeX-master was nil, TeX-master-file returned "<none>.tex" and I
didn't account for this case. Similar wrong behaviour occurs when the returned
master file does not exist (like in the case of the compressed file). In any
case, I fixed this by checking that the file exists before opening it. I also
changed the behaviour so that such checks are only done when the extension is
an output extension as you suggested. Please find a patch to the
`tex-build-only` branch attached. If you think the changes are reasonable, I
will push them to my local repo so that Tassilo can pull them.
>
>> BTW, I added a note in `TeX-command-default` where the filename `name`
>> is compared to the output of `TeX-region-file` to determine if the
>> file comes from TeX-region-file or TeX-master-file. This is another
>> reason why I believe passing file-fn to TeX-command-default is more
>> appropriate.
>
> Agreed. The current (unmodified) implementation is ugly, IMHO.
>
I am happy to change it to a comparison based on the `file-fn` argument
instead, if there's no better solution.
> It seems a bit redundant for me. As discussed previously, the
> "--output-directory" feature would have a limited scope of application
> because it can't handle \include on sub directories. Users who enable
> `TeX-output-dir' option should regard it as an auxiliary tool valid for
> only simple cases in the first place.
I see your point.
My intention is to increase the number of cases in which `--output-directory`
works, if such improvement is not difficult.
In any case, if changing environment variables in AUCTeX is not desirable, then
maybe we can just mention in the eventual documentation of TeX-output-dir that
adding the output directory to `TEXINPUTS` and `BIBINPUTS` might be needed in
some cases (I personally do this in my private configuration).
Best regards,
-- Al
diff --git a/tex.el b/tex.el
index c6228917..d1069688 100644
--- a/tex.el
+++ b/tex.el
@@ -2423,15 +2423,14 @@ name of master file if it cannot be determined otherwise."
;; Otherwise drop it.
(setq name (TeX-strip-extension name))))
- (let* ((output-dir (and (or (stringp TeX-master)
- (buffer-file-name)) ;; otherwise `name' is "<none>"
- (TeX-master-output-dir nondirectory
- (concat name "." TeX-default-extension))))
- (reg (and output-dir (TeX--clean-extensions-regexp t)))
- (is-output-ext
- (and reg (or (string-match-p reg (concat "." extension))
- (string= "prv" extension)))))
- (if is-output-ext
+ (let* ((reg (TeX--clean-extensions-regexp t))
+ (is-output-ext (and reg
+ (or (string-match-p reg (concat "." extension))
+ (string= "prv" extension))))
+ (output-dir (and is-output-ext
+ (TeX-master-output-dir nondirectory
+ (concat name "." TeX-default-extension)))))
+ (if output-dir
;; If output extesnion, use output-dir (directory is already removed)
;; in TeX-master-output-dir
(setq name (concat output-dir (file-name-nondirectory name)))
@@ -2535,22 +2534,27 @@ directory is the same as the directory of TeX-master."
:type 'string)
(defun TeX-master-output-dir (&optional relative-to-master master-file)
- (with-current-buffer
- (find-file-noselect (or master-file (TeX-master-file t)) t)
- (let ((out-dir (and TeX-output-dir
- (file-name-as-directory
- (abbreviate-file-name
- (substitute-in-file-name
- (expand-file-name
- TeX-output-dir
- (file-name-directory buffer-file-name))))))))
- ;; Make sure the directory exists
- (when out-dir
- (unless (file-exists-p out-dir)
- (make-directory (file-name-as-directory out-dir) t))
- (if relative-to-master
- (file-relative-name out-dir)
- out-dir)))))
+ (let* ((master-file (or master-file (TeX-master-file t)))
+ (master-buffer
+ (or (get-file-buffer master-file)
+ (and (file-exists-p master-file)
+ (find-file-noselect master-file t)))))
+ (when master-buffer
+ (with-current-buffer master-buffer
+ (let ((out-dir (and TeX-output-dir
+ (file-name-as-directory
+ (abbreviate-file-name
+ (substitute-in-file-name
+ (expand-file-name
+ TeX-output-dir
+ (file-name-directory buffer-file-name))))))))
+ ;; Make sure the directory exists
+ (when out-dir
+ (unless (file-exists-p out-dir)
+ (make-directory (file-name-as-directory out-dir) t))
+ (if relative-to-master
+ (file-relative-name out-dir)
+ out-dir)))))))
(defcustom TeX-style-local "style"
"Directory containing hand generated TeX information.