Subject: Re: bug#78841: reftex-get-bibfile-list fails to detect biblatex if there's no buffer for the main file

From: Arash Esbati <[email-masked]>
Date: Sat, 21 Jun 2025 17:42:03 +0200

Tim Ruffing <[email-masked]> 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