GNU bug report logs - #78841
reftex-get-bibfile-list fails to detect biblatex if there's no buffer for the main file

Previous Next

Package: auctex;

Reported by: Tim Ruffing <dev <at> real-or-random.org>

Date: Thu, 19 Jun 2025 19:29:04 UTC

Severity: normal

To reply to this bug, email your comments to 78841 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-auctex <at> gnu.org:
bug#78841; Package auctex. (Thu, 19 Jun 2025 19:29:04 GMT) Full text and rfc822 format available.

Acknowledgement sent to Tim Ruffing <dev <at> real-or-random.org>:
New bug report received and forwarded. Copy sent to bug-auctex <at> gnu.org. (Thu, 19 Jun 2025 19:29:04 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Tim Ruffing <dev <at> real-or-random.org>
To: bug-auctex <at> gnu.org
Subject: reftex-get-bibfile-list fails to detect biblatex if there's no
 buffer for the main file
Date: Thu, 19 Jun 2025 21:28:10 +0200
With (default) settings

(setq reftex-initialize-temporary-buffers nil)
(setq reftex-keep-temporary-buffers 1)

assume you call (reftex-get-bibfile-list) in a chapter.tex buffer but
there's no buffer yet for the main file main.tex that looks like this:

\documentclass{standalone}
\usepackage{biblatex}
\addbibresource{1.bib}
\addbibresource{2.bib}
\begin{document}
\input{chapter.tex} 
\end{document}

Then reftex-get-bibfile-list will return only the first bib file but it
is supposed to return both bib files.

The problem is that reftex-locate-bibliography-files tries to figure
out whether biblatex is used, i.e., whether it needs to continue
searching after the first bibliography command. It does so (also) in
main.tex, which has beem opened only as a temp buffer in fundamental
mode. Whether biblatex is used is determined in reftex-using-biblatex-
p, which relies on the value of TeX-active-styles if (boundp 'TeX-
active-styles). 

But the latter is the wrong condition: (boundp 'TeX-active-styles) is
true in fundamental mode because 'Tex-active-styles has a (global)
binding of nil.

Replacing
(boundp 'TeX-active-styles)
by
(local-variable-p 'TeX-active-styles)
fixes this check for me. Then reftex-using-biblatex-p will fall back on
a "poor-man's check" (according to the comment in the code), which
looks for \usepackage{biblatex} using some regex.

However, while this patch would fix the problem for me, I still don't
like the resulting code:

 * In fact, checking TeX-active-styles would work if only the check was
   done in the chapter.tex buffer from which reftex-get-bibfile-list is
   called, but it's instead done in each buffer separately. 
 * Similarly, the poor man's check is done in each buffer separately. I
   think this means that also the poor man's check will only work for
   any \addbibresource command which happens to be in the same buffer
   as \usepackage{biblatex}.  

I think this logic is broken. Whether biblatex is used or not should
not be judged in each file of a multifile document separately. Either
the entire document uses biblatex, or it doesn't. As a result,
replacing boundp by local-variable-p is only my second best suggestion.

My best suggestion is to get rid of reftex-using-biblatex-p entirely,
and assume it's always true. In other words, never stop after the first
\addbibresource (or rather \bibliography) command has been found. This
gets rid of the broken logic and both imperfect heuristics. I assume
this is fine performance-wise, and I assume this is what one would do
when asked to reimplement this from scratch. 

A look at the history shows that the initial code that stops after the
first value is is >25 years old (and this is just how far back git
goes). Back then there was only bibtex and it was okay to stop after
the first \bibliography, and CPUs were way slower. Then in 2013, the
fix for biblatex was added, but it was done in an attempt to keep the
early return if biblatex is not used.

I'm happy to provide a proper patch for either suggestion, but they're
both trivial enough that you'll probably do the changes yourself
quicker than asking me for the patch.

Best,
Tim




Information forwarded to bug-auctex <at> gnu.org:
bug#78841; Package auctex. (Sat, 21 Jun 2025 15:43:02 GMT) Full text and rfc822 format available.

Message #8 received at 78841 <at> debbugs.gnu.org (full text, mbox):

From: Arash Esbati <arash <at> gnu.org>
To: Tim Ruffing <dev <at> real-or-random.org>
Cc: 78841 <at> debbugs.gnu.org
Subject: Re: bug#78841: reftex-get-bibfile-list fails to detect biblatex if
 there's no buffer for the main file
Date: Sat, 21 Jun 2025 17:42:03 +0200
Tim Ruffing <dev <at> real-or-random.org> writes:

> With (default) settings
>
> (setq reftex-initialize-temporary-buffers nil)
> (setq reftex-keep-temporary-buffers 1)
>
> assume you call (reftex-get-bibfile-list) in a chapter.tex buffer but
> there's no buffer yet for the main file main.tex that looks like this:
>
> \documentclass{standalone}
> \usepackage{biblatex}
> \addbibresource{1.bib}
> \addbibresource{2.bib}
> \begin{document}
> \input{chapter.tex} 
> \end{document}

Is this with AUCTeX?  I'm asking because AUCTeX opens the master file in
the background when you visit a subfile.  So your chapter.tex should
look like this:

--8<---------------cut here---------------start------------->8---
Content of chapter.tex

%%% Local Variables:
%%% mode: LaTeX
%%% TeX-master: "main.tex"
%%% End:
--8<---------------cut here---------------end--------------->8---

> Then reftex-get-bibfile-list will return only the first bib file but it
> is supposed to return both bib files.
>
> The problem is that reftex-locate-bibliography-files tries to figure
> out whether biblatex is used, i.e., whether it needs to continue
> searching after the first bibliography command. It does so (also) in
> main.tex, which has beem opened only as a temp buffer in fundamental
> mode.

Can you come up with couple of minimal files and an exact recipe how to
do this?  In my case, main.tex if opened, see above.

> Whether biblatex is used is determined in reftex-using-biblatex-p,
> which relies on the value of TeX-active-styles if (boundp
> 'TeX-active-styles).
>
> But the latter is the wrong condition: (boundp 'TeX-active-styles) is
> true in fundamental mode because 'Tex-active-styles has a (global)
> binding of nil.
>
> Replacing
> (boundp 'TeX-active-styles)
> by
> (local-variable-p 'TeX-active-styles)
> fixes this check for me.

I think the correct fix is to replace (boundp 'TeX-active-styles) with:

(and (fboundp 'TeX-style-list)
     (TeX-style-list))

> Then reftex-using-biblatex-p will fall back on a "poor-man's check"
> (according to the comment in the code), which looks for
> \usepackage{biblatex} using some regex.
>
> I think this logic is broken. Whether biblatex is used or not should
> not be judged in each file of a multifile document separately. Either
> the entire document uses biblatex, or it doesn't. As a result,
> replacing boundp by local-variable-p is only my second best suggestion.

I'm not sure I follow: `TeX-style-list' returns all active styles for
the entire document, the test is done on a per file basis, but the final
result goes for the entire document.

> My best suggestion is to get rid of reftex-using-biblatex-p entirely,
> and assume it's always true.

I'm not convinced yet that this a good idea.  The way around, the
current code is in place for >25 years now and the number of complaints
were low :-)

Best, Arash




Information forwarded to bug-auctex <at> gnu.org:
bug#78841; Package auctex. (Sat, 21 Jun 2025 20:06:02 GMT) Full text and rfc822 format available.

Message #11 received at 78841 <at> debbugs.gnu.org (full text, mbox):

From: Tim Ruffing <dev <at> real-or-random.org>
To: Arash Esbati <arash <at> gnu.org>
Cc: 78841 <at> debbugs.gnu.org
Subject: Re: bug#78841: reftex-get-bibfile-list fails to detect biblatex if
 there's no buffer for the main file
Date: Sat, 21 Jun 2025 22:05:38 +0200
On Sat, 2025-06-21 at 17:42 +0200, Arash Esbati wrote:
> Is this with AUCTeX?  I'm asking because AUCTeX opens the master file
> in
> the background when you visit a subfile.  So your chapter.tex should
> look like this:
> 
> --8<---------------cut here---------------start------------->8---
> Content of chapter.tex
> 
> %%% Local Variables:
> %%% mode: LaTeX
> %%% TeX-master: "main.tex"
> %%% End:
> --8<---------------cut here---------------end--------------->8---
> 

Oh, that's interesting. I didn't use a local variables section, but I
have this in my config instead:

(setq-default TeX-master "main")

And this works, at least in principle. In chapter.tex, (TeX-master-
file) returns "main". And also compilation works properly and uses the
main file.

But this appears to make a difference for reftex-get-bibfile-list! I
get both bib files 1.bib and 2.bib with this chapter.tex as you
suggested:

%%% Local Variables:
%%% mode: LaTeX
%%% TeX-master: "main.tex"
%%% End:

But only 1.bib with this chapter.tex (and still setting TeX-master in
my config).
 
%%% Local Variables:
%%% mode: LaTeX
%%% End:

(When testing, make sure to restart emacs first.)

This shouldn't happen, (setq-default TeX-master "main") is suggested in
the docs, so it should not make a difference whether it's set as a
local variable in the file or as a default in the config.

But okay, this is probably the reason why noone has discovered this
before. I haven't investigated the root cause for this, but let me know
if you can reproduce it now. 

> I think the correct fix is to replace (boundp 'TeX-active-styles)
> with:
> 
> (and (fboundp 'TeX-style-list)
>      (TeX-style-list))
> 

Sure, sounds better, yes. I think that change should be applied in any
case (unless the code is removed entirely).

> > Then reftex-using-biblatex-p will fall back on a "poor-man's check"
> > (according to the comment in the code), which looks for
> > \usepackage{biblatex} using some regex.
> > 
> > I think this logic is broken. Whether biblatex is used or not
> > should
> > not be judged in each file of a multifile document separately.
> > Either
> > the entire document uses biblatex, or it doesn't. As a result,
> > replacing boundp by local-variable-p is only my second best
> > suggestion.
> 
> I'm not sure I follow: `TeX-style-list' returns all active styles for
> the entire document, the test is done on a per file basis, but the
> final
> result goes for the entire document.

Well okay, if AUCTeX is used, then you're right: the result is the same
for all files. But if the poor man's check is used, the regexp is
really checked separately in each file (if I'm not mistaken). One could
argue that this is good enough for a poor man's check. It will work as
long as the bib files are loaded in the same file that contains
\usepackage{biblatex}, which is probably the common case even for
multifile docs. But still, the behavior is a bit erratic. Then, in the
above examples, loading two bib files will work in main.tex but not in
chapter.tex. 

> 
> > My best suggestion is to get rid of reftex-using-biblatex-p
> > entirely,
> > and assume it's always true.
> 
> I'm not convinced yet that this a good idea.  The way around, the
> current code is in place for >25 years now and the number of
> complaints
> were low :-)

Not exactly, the biblatex support has been there only for 12 years. ;)
But yeah, I agree it's still a very long time for code.

Best,
Tim




Information forwarded to bug-auctex <at> gnu.org:
bug#78841; Package auctex. (Sun, 22 Jun 2025 12:54:04 GMT) Full text and rfc822 format available.

Message #14 received at 78841 <at> debbugs.gnu.org (full text, mbox):

From: Tim Ruffing <dev <at> real-or-random.org>
To: Arash Esbati <arash <at> gnu.org>
Cc: 78841 <at> debbugs.gnu.org
Subject: Re: bug#78841: reftex-get-bibfile-list fails to detect biblatex if
 there's no buffer for the main file
Date: Sun, 22 Jun 2025 14:52:44 +0200
On Sat, 2025-06-21 at 22:05 +0200, Tim Ruffing wrote:
> I haven't investigated the root cause for this, but let me know
> if you can reproduce it now. 

Update: 
If you have the "%%% TeX-master: "main.tex" line, what will open and
keep open the main.tex buffer when opening chapter.tex is *not* AUCTeX
but the built-in latexenc.el. This is what debug-on-entry find-file-
noselect tells me, and you can confirm it by setting
  (setq latexenc-dont-use-TeX-master-flag nil),
and just to make sure, also
  (setq latexenc-dont-use-tex-guess-main-file-flag nil).

And this makes exactly the bug. So another reproducer is:

config:
(setq latexenc-dont-use-TeX-master-flag nil)  ; this is new
(setq latexenc-dont-use-tex-guess-main-file-flag nil)  ; why not 
(setq reftex-initialize-temporary-buffers nil) ; default
(setq reftex-keep-temporary-buffers 1)  ;  default

chapter.tex:

%%% Local Variables:
%%% mode: LaTeX
%%% TeX-master: "main.tex"
%%% End:

main.tex:

\documentclass{standalone}
\usepackage{biblatex}
\addbibresource{1.bib}
\addbibresource{2.bib}
\begin{document}
\input{chapter.tex}
\end{document}

However, you're still right. AUCTeX will *also* open main.tex when it's
initialized in chapter.tex. And in particular, even with the above
reproducer, i.e., even with latexenc-dont-use-TeX-master-flag set to
nil, "biblatex" will be in (TeX-style-list) when called in chapter.tex.
That means that AUCTeX correctly figures out the main file and parses
it (but it won't keep the main.tex buffer open unlike latexenc). 

What happens then is what I described in my initial email. reftex will
open main.tex as a temp buffer in fundamental mode, and so on...   

The thing is: As I said above, chapter.tex already knows that biblatex
is used (because "biblatex" is in the list returned by (TeX-style-list)
when called in chapter.tex). But the real issue is that this
information will simply not be used when the main.tex buffer is checked
in fundamental mode. 

And I believe that this analysis now really shows that either the call
to (TeX-style-list) should be performed in the buffer in which (reftex-
get-bibfile-list) is called (instead of calling it separately in each
searched buffer). Or simpler, as I've initially suggested, just never
stop after the first occurrence of a bibliography command, and the
problem will just disappear entirely. 




Information forwarded to bug-auctex <at> gnu.org:
bug#78841; Package auctex. (Sun, 22 Jun 2025 12:55:04 GMT) Full text and rfc822 format available.

Message #17 received at 78841 <at> debbugs.gnu.org (full text, mbox):

From: Tim Ruffing <dev <at> real-or-random.org>
To: Arash Esbati <arash <at> gnu.org>
Cc: 78841 <at> debbugs.gnu.org
Subject: Re: bug#78841: reftex-get-bibfile-list fails to detect biblatex if
 there's no buffer for the main file
Date: Sun, 22 Jun 2025 14:53:58 +0200
Sorry for another email. Just for completeness, this is on
AUCTeX 14.0.9 and Emacs 30.1, and I use Doom Emacs.

Tim




Information forwarded to bug-auctex <at> gnu.org:
bug#78841; Package auctex. (Mon, 23 Jun 2025 10:13:02 GMT) Full text and rfc822 format available.

Message #20 received at 78841 <at> debbugs.gnu.org (full text, mbox):

From: Arash Esbati <arash <at> gnu.org>
To: Tim Ruffing <dev <at> real-or-random.org>
Cc: 78841 <at> debbugs.gnu.org
Subject: Re: bug#78841: reftex-get-bibfile-list fails to detect biblatex if
 there's no buffer for the main file
Date: Mon, 23 Jun 2025 12:11:56 +0200
[Message part 1 (text/plain, inline)]
Tim Ruffing <dev <at> real-or-random.org> writes:

> The thing is: As I said above, chapter.tex already knows that biblatex
> is used (because "biblatex" is in the list returned by (TeX-style-list)
> when called in chapter.tex). But the real issue is that this
> information will simply not be used when the main.tex buffer is checked
> in fundamental mode. 

I assembled a minimal set of files and tried to understand this.  The
files are attached, just save them in a temp directory, open
biblatex-main.tex and hit 'C-c C-n' to parse the file.  Now open a new
Emacs instance with 'emacs -Q' and eval this in scratch:

--8<---------------cut here---------------start------------->8---
(progn
  (package-initialize t)
  (package-activate 'auctex)

  ;; Alternatively adjust the path below and eval this if the above
  ;; doesn't work with Doom-Emacs:
  ;; (load "~/path/to/auctex/auctex-autoloads.el" nil t t)
  (setq-default TeX-master nil)
  (setq TeX-parse-self t)
  (add-hook 'LaTeX-mode-hook #'reftex-mode)
  (setq reftex-plug-into-AUCTeX t) )
--8<---------------cut here---------------end--------------->8---

I admit I have no idea how Doom manages its packages, so you can load
auctex-autoloads.el if the package-... functions don't work with Doom.
Once done, visit biblatex-sub.tex with this setup.  For me, all works as
expected and RefTeX finds both databases.  This is what I see when I hit
'C-c C-m cite RET . RET':
[snap.png (image/png, inline)]
[Message part 3 (text/plain, inline)]
Can we please take this now from here?  Otherwise it's too confusing.
Thanks.

Best, Arash
[biblatex-main.tex (application/x-tex, attachment)]
[biblatex-sub.tex (application/x-tex, attachment)]
[biblatex-bib1.bib (application/octet-stream, attachment)]
[biblatex-bib2.bib (application/octet-stream, attachment)]

Information forwarded to bug-auctex <at> gnu.org:
bug#78841; Package auctex. (Mon, 23 Jun 2025 19:56:02 GMT) Full text and rfc822 format available.

Message #23 received at 78841 <at> debbugs.gnu.org (full text, mbox):

From: Tim Ruffing <dev <at> real-or-random.org>
To: Arash Esbati <arash <at> gnu.org>
Cc: 78841 <at> debbugs.gnu.org
Subject: Re: bug#78841: reftex-get-bibfile-list fails to detect biblatex if
 there's no buffer for the main file
Date: Mon, 23 Jun 2025 21:55:09 +0200
Hi again, thanks for taking the time and sorry that my instructions
were still unclear. I can't reproduce the bug with your commands only,
but I can reproduce it if I add this line
(setq latexenc-dont-use-TeX-master-flag nil)
as mentioned in my previous email.

Consider this "init.el" file:
--8<---------------cut here---------------start------------->8---
(package-initialize t)
(package-activate 'auctex)

;; I use this:
;(add-to-list 'load-path "~/.config/emacs/.local/straight/build-30.1/auctex")
;(load "auctex-autoloads.el" nil t t)

(setq TeX-parse-self t)
(add-hook 'LaTeX-mode-hook #'reftex-mode)
(setq reftex-plug-into-AUCTeX t)

;; Either uncomment this and keep the "TeX-master" line in biblatex-sub.tex
(setq-default TeX-master nil)
(setq latexenc-dont-use-TeX-master-flag t)

;; Or uncomment this and remove the TeX-master-line in biblatex-sub.tex
;(setq latexenc-dont-use-TeX-master-flag nil)
;(setq-default TeX-master "biblatex-main")

(find-file "./biblatex-sub.tex")

;; Print to stdout for quicker debugging
(print (reftex-get-bibfile-list) 'external-debugging-output)
--8<---------------cut here---------------end------------->8---

Here are step-by-step instructions:
 * Save your minimal set of files in a temp directory
 * Add an init.el file as above to the directory
 * cd to the temp directory
 * Run: emacs --init-directory=. --no-splash

Expected outcome:
 * Two file paths are printed to stdout
 * If you try to add a citation, both entries are found 

Actual outcome:
 * Only one file paths is printed to stdout
 * If you try to add a citation, only one entry is found

Best,
Tim




Information forwarded to bug-auctex <at> gnu.org:
bug#78841; Package auctex. (Tue, 24 Jun 2025 08:16:02 GMT) Full text and rfc822 format available.

Message #26 received at 78841 <at> debbugs.gnu.org (full text, mbox):

From: Arash Esbati <arash <at> gnu.org>
To: Tim Ruffing <dev <at> real-or-random.org>
Cc: 78841 <at> debbugs.gnu.org
Subject: Re: bug#78841: reftex-get-bibfile-list fails to detect biblatex if
 there's no buffer for the main file
Date: Tue, 24 Jun 2025 10:14:53 +0200
Tim Ruffing <dev <at> real-or-random.org> writes:

> Hi again, thanks for taking the time and sorry that my instructions
> were still unclear.

Thanks for checking, and no problem 👍

> I can't reproduce the bug with your commands only,

Good.

> but I can reproduce it if I add this line (setq
> latexenc-dont-use-TeX-master-flag nil) as mentioned in my previous
> email.

Ok.  But this is not a real requirement, right?  This is just to
showcase the issue.  Your setup involves setting `TeX-master' to a
constant string, right?  If so, can you please delete this line:

%%% TeX-master: "biblatex-main"

in biblatex-sub.tex and save it, start a new Emacs with 'emacs -Q', eval
this in scratch:

--8<---------------cut here---------------start------------->8---
(progn
  (load "~/.config/emacs/.local/straight/build-30.1/auctex/auctex-autoloads.el" nil t t)
  (setq-default TeX-master "biblatex-main")
  (setq TeX-parse-self t)
  (add-hook 'LaTeX-mode-hook #'reftex-mode)
  (setq reftex-plug-into-AUCTeX t)
  (defun latexenc-find-file-coding-system (arg-list)
    "Determine the coding system of a LaTeX file if it uses \"inputenc.sty\".
The mapping from LaTeX's \"inputenc.sty\" encoding names to Emacs
coding system names is determined from `latex-inputenc-coding-alist'."
    (if (eq (car arg-list) 'insert-file-contents)
        (save-excursion
          ;; try to find the coding system in this file
          (goto-char (point-min))
          (if (catch 'cs
                (let ((case-fold-search nil))
                  (while (search-forward "inputenc" nil t)
                    (goto-char (match-beginning 0))
                    (beginning-of-line)
                    (if (or (looking-at "[^%\n]*\\\\usepackage\\[\\([^]]*\\)\\]{\\([^}]*,\\)?inputenc\\(,[^}]*\\)?}")
                            (looking-at "[^%\n]*\\\\inputencoding{\\([^}]*\\)}"))
                        (throw 'cs t)
                      (goto-char (match-end 0))))))
              (let* ((match (match-string 1))
                     (sym (or (latexenc-inputenc-to-coding-system match)
                              (intern match))))
                (cond
                 ((coding-system-p sym) sym)
                 ((and (require 'code-pages nil t) (coding-system-p sym)) sym)
                 (t 'undecided)))
            ;; else try to find it in the master/main file

            ;; Fixme: If the current file is in an archive (e.g. tar,
            ;; zip), we should find the master file in that archive.
            ;; But, that is not yet implemented.   -- K.Handa
            (let ((default-directory (if (stringp (nth 1 arg-list))
                                         (file-name-directory (nth 1 arg-list))
                                       default-directory))
                  latexenc-main-file)
              ;; Is there a TeX-master or tex-main-file in the local variables
              ;; section?
              (unless latexenc-dont-use-TeX-master-flag
                (goto-char (point-max))
                (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
                                 'move)
                (search-forward "Local Variables:" nil t)
                (when (or (re-search-forward
                           "^%+ *\\(TeX-master\\|tex-main-file\\): *\"\\(.+\\)\""
                           nil t)
                          ;; Addition start
                          (and (boundp 'TeX-master)
                               (stringp (default-value 'TeX-master)))
                          ;; Addition end
                          )
                  (let ((file
                         ;; Addition start
                         (or (match-string 2)
                             (and (boundp 'TeX-master)
                                  (default-value 'TeX-master))
                             ;; Addition end
                             )))
                    (dolist (ext `("" ,(if (boundp 'TeX-default-extension)
                                           (concat "." TeX-default-extension)
                                         "")
                                   ".tex" ".ltx" ".dtx" ".drv"))
                      (if (and (null latexenc-main-file) ;Stop at first.
                               (file-exists-p (concat file ext)))
                          (setq latexenc-main-file (concat file ext)))))))
              ;; try tex-modes tex-guess-main-file
              (when (and (not latexenc-dont-use-tex-guess-main-file-flag)
                         (not latexenc-main-file))
                ;; Use a separate `when' so the byte-compiler sees the fboundp.
                (when (fboundp 'tex-guess-main-file)
                  (let ((tex-start-of-header "\\\\document\\(style\\|class\\)"))
                    (setq latexenc-main-file (tex-guess-main-file)))))
              ;; if we found a master/main file get the coding system from it
              (if (and latexenc-main-file
                       (file-regular-p latexenc-main-file)
                       (file-readable-p latexenc-main-file))
                  (let* ((latexenc-dont-use-tex-guess-main-file-flag t)
                         (latexenc-dont-use-TeX-master-flag t)
                         (latexenc-main-buffer
                          (find-file-noselect latexenc-main-file t)))
                    (coding-system-base   ;Disregard the EOL part of the CS.
                     (with-current-buffer latexenc-main-buffer
                       (or coding-system-for-write buffer-file-coding-system
                           'undecided))))
                'undecided))))
      'undecided)) )
--8<---------------cut here---------------end--------------->8---

and try it again?  IIUC, `latexenc-find-file-coding-system' isn't
prepared to deal with `TeX-master' set to a string top-level.  My change
above adds that.

Best, Arash




Information forwarded to bug-auctex <at> gnu.org:
bug#78841; Package auctex. (Tue, 24 Jun 2025 08:52:02 GMT) Full text and rfc822 format available.

Message #29 received at 78841 <at> debbugs.gnu.org (full text, mbox):

From: Tim Ruffing <dev <at> real-or-random.org>
To: Arash Esbati <arash <at> gnu.org>
Cc: 78841 <at> debbugs.gnu.org
Subject: Re: bug#78841: reftex-get-bibfile-list fails to detect biblatex if
 there's no buffer for the main file
Date: Tue, 24 Jun 2025 10:50:49 +0200
[Message part 1 (text/plain, inline)]
Thanks for the quick reply!

On Tue, 2025-06-24 at 10:14 +0200, Arash Esbati wrote:
> Ok.  But this is not a real requirement, right?  This is just to
> showcase the issue.  Your setup involves setting `TeX-master' to a
> constant string, right?  If so, can you please delete this line:
> 

Indeed, this is just to showcase the issue. See the comments in my
"init.el" snippet from my previous mail which have instructions to
reproduce the issue without the "%%% TeX-master:" line.


> (IIUC, `latexenc-find-file-coding-system' isn't
> prepared to deal with `TeX-master' set to a string top-level.  My
> change
> above adds that.

I've tested this, and this works in this specific case. But are you
really suggesting this as a fix? 

I feel this is building a hack on top of another. If AUCTeX needs the
master file to be open, then it just should open it and not rely on
latexenc to open it.

Your change doesn't solve the issue if any of the following happens:
 * latexenc-dont-use-TeX-master-flag is t
 * latexenc will be removed or changed in the future
 * the \addbibresource commands is not in the same file as
   \usepackage{biblatex}, see the test case in the attached zip.
   (Again, extract it to some folder, cd into the folder with the tex
   files, and run `emacs --init-directory=. --no-splash`)

[reftex-bug.zip (application/zip, attachment)]

Information forwarded to bug-auctex <at> gnu.org:
bug#78841; Package auctex. (Wed, 25 Jun 2025 07:16:03 GMT) Full text and rfc822 format available.

Message #32 received at 78841 <at> debbugs.gnu.org (full text, mbox):

From: Arash Esbati <arash <at> gnu.org>
To: Tim Ruffing <dev <at> real-or-random.org>
Cc: 78841 <at> debbugs.gnu.org
Subject: Re: bug#78841: reftex-get-bibfile-list fails to detect biblatex if
 there's no buffer for the main file
Date: Wed, 25 Jun 2025 09:15:18 +0200
Tim Ruffing <dev <at> real-or-random.org> writes:

> I've tested this, and this works in this specific case.

Thanks.

> But are you really suggesting this as a fix?

The way I see it this is a bug in latexenc.el which we should try to fix
anyway.  That would basically improve the current state.

> I feel this is building a hack on top of another.

Maybe, OTOH, mule-conf.el which adds

  ("\\.\\(tex\\|ltx\\|dtx\\|drv\\)\\'" . latexenc-find-file-coding-system)

to `file-coding-system-alist' is pre-loaded in Emacs.  So I would argue
we're relying on Emacs' default behavior here.  And if people remove
that entry, they should know what they're doing.

> If AUCTeX needs the master file to be open, then it just should open
> it and not rely on latexenc to open it.

Will take a closer look at this later, but remember that RefTeX should
also work without AUCTeX, so this point isn't much relevant.

> Your change doesn't solve the issue if any of the following happens:
>  * latexenc-dont-use-TeX-master-flag is t
>  * latexenc will be removed or changed in the future
>  * the \addbibresource commands is not in the same file as
>    \usepackage{biblatex}, see the test case in the attached zip.
>    (Again, extract it to some folder, cd into the folder with the tex
>    files, and run `emacs --init-directory=. --no-splash`)

I see your point, but I think these are sort of corner cases, given how
many times they were raised in the past.  I currently don't have the
time and energy to solve this issue in a way which can deal with all the
cases above, but I'll be happy to review and install such a change.
Patches are welcome.

Best, Arash




Information forwarded to bug-auctex <at> gnu.org:
bug#78841; Package auctex. (Wed, 25 Jun 2025 19:12:02 GMT) Full text and rfc822 format available.

Message #35 received at 78841 <at> debbugs.gnu.org (full text, mbox):

From: Arash Esbati <arash <at> gnu.org>
To: arne <at> arnested.dk, Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Tim Ruffing <dev <at> real-or-random.org>, 78841 <at> debbugs.gnu.org
Subject: Re: bug#78841: reftex-get-bibfile-list fails to detect biblatex if
 there's no buffer for the main file
Date: Wed, 25 Jun 2025 21:11:35 +0200
Tim Ruffing <dev <at> real-or-random.org> writes:

>> IIUC, `latexenc-find-file-coding-system' isn't prepared to deal with
>> `TeX-master' set to a string top-level.  My change above adds that.
>
> I've tested this, and this works in this specific case.

Arne, we have a bug report for AUCTeX where I found that the function
`latexenc-find-file-coding-system' can't deal with `TeX-master' or
`tex-main-file' set to a constant string in the init file and not as
file local variable.  I'm not really familiar with your code, but the
following small change is reported to fix the issue, at least for
AUCTeX:

--8<---------------cut here---------------start------------->8---
diff --git a/lisp/international/latexenc.el b/lisp/international/latexenc.el
index 1b735810ee4..b7b022e68c4 100644
--- a/lisp/international/latexenc.el
+++ b/lisp/international/latexenc.el
@@ -144,17 +144,26 @@ latexenc-find-file-coding-system
                                       (file-name-directory (nth 1 arg-list))
                                     default-directory))
                latexenc-main-file)
-            ;; Is there a TeX-master or tex-main-file in the local variables
-            ;; section?
+            ;; Is there a TeX-master or tex-main-file in the local
+            ;; variables section or is it globally set to a constant
+            ;; string?
             (unless latexenc-dont-use-TeX-master-flag
               (goto-char (point-max))
              (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
                                'move)
              (search-forward "Local Variables:" nil t)
-              (when (re-search-forward
-                     "^%+ *\\(TeX-master\\|tex-main-file\\): *\"\\(.+\\)\""
-                     nil t)
-                (let ((file (match-string 2)))
+              (when (or (re-search-forward
+                         "^%+ *\\(TeX-master\\|tex-main-file\\): *\"\\(.+\\)\""
+                         nil t)
+                        (and (bound-and-true-p 'TeX-master)
+                             (stringp (default-value 'TeX-master)))
+                        (and (bound-and-true-p 'tex-main-file)
+                             (stringp (default-value 'tex-main-file))))
+                (let ((file (or (match-string 2)
+                                (and (boundp 'TeX-master)
+                                     (default-value 'TeX-master))
+                                (and (boundp 'tex-main-file)
+                                     (default-value 'tex-main-file)))))
                   (dolist (ext `("" ,(if (boundp 'TeX-default-extension)
                                          (concat "." TeX-default-extension)
                                        "")
@@ -180,7 +189,7 @@ latexenc-find-file-coding-system
                   (coding-system-base   ;Disregard the EOL part of the CS.
                    (with-current-buffer latexenc-main-buffer
                      (or coding-system-for-write buffer-file-coding-system
-                        'undecided))))
+                        'undecided))))
               'undecided))))
     'undecided))
--8<---------------cut here---------------end--------------->8---

Do you have any comments on this?

@Stefan: FYI, I'm not familiar with tex-mode.el and what `tex-main-file'
does, maybe you can review the change above for tex-mode.el.  TIA.

Best, Arash




Information forwarded to bug-auctex <at> gnu.org:
bug#78841; Package auctex. (Thu, 26 Jun 2025 09:52:01 GMT) Full text and rfc822 format available.

Message #38 received at 78841 <at> debbugs.gnu.org (full text, mbox):

From: Arash Esbati <arash <at> gnu.org>
To: arne <at> arnested.dk
Cc: Tim Ruffing <dev <at> real-or-random.org>,
 Stefan Monnier <monnier <at> iro.umontreal.ca>, 78841 <at> debbugs.gnu.org
Subject: Re: bug#78841: reftex-get-bibfile-list fails to detect biblatex if
 there's no buffer for the main file
Date: Thu, 26 Jun 2025 11:51:32 +0200
[Message part 1 (text/plain, inline)]
Arash Esbati <arash <at> gnu.org> writes:

> Arne, we have a bug report for AUCTeX where I found that the function
> `latexenc-find-file-coding-system' can't deal with `TeX-master' or
> `tex-main-file' set to a constant string in the init file and not as
> file local variable.  I'm not really familiar with your code, but the
> following small change is reported to fix the issue, at least for
> AUCTeX:

My apologies, my last proposal was broken, please consider the one
attached.

Best, Arash
[latexenc.patch (text/x-patch, attachment)]

This bug report was last modified today.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.