Subject: bug#64768: biblatex detection in reftex is too naive, multiple bib files are problematic

From: Arash Esbati <[email-masked]>
Date: Mon, 31 Jul 2023 09:40:03 +0200

"Philipp G. Haselwarter" <[email-masked]> writes:

> In main.tex, I have the line "\input{mypreamble}", and in
> mypreamble.tex, there's a line with "\usepackage{biblatex}". I also
> have several "\addbibresource{foo.bib}", "\addbibresource{bar.bib}",
> etc, either in main.tex or in mypreamble.tex . I would want reftex to
> be aware of the references in foo.bib and bar.bib whenever main.tex is
> set as TeX-master, i.e. either while editing main.tex directly or
> while editing some-section.tex, where some-section.tex sets TeX-master
> to main.tex.

Thanks the clarification.  \addbibresource is a preamble only command
and AFAIU, RefTeX looks for this macro only in the main file; it doesn't
go through each \input'ed file in order to find any \addbibresource.

I'd suggest you change your setup a little and rename your
mypreamble.tex to mypreamble.sty and replace there:

  \usepackage{biblatex}

with

  \RequirePackage{biblatex}

and delete any \addbibresource calls.  Now you do this in your main.tex:

  \usepackage{mypreamble}
  \addbibresource{foo.bib}
  \addbibresource{bar.bib}

Now the final step is to write a small AUCTeX style file for your
mypreamble.sty called mypreamble.el which looks like this:

  (TeX-add-style-hook
   "mypreamble"
   (lambda ()
     (TeX-run-style-hooks "biblatex"))
   :latex)

and save this file in the directory specified in the variable
`TeX-style-private' (or adjust it accordingly first).

Now restart Emacs and open your main.tex.  AUCTeX should load
mypreamble.el and biblatex.el subsequently which gets an entry in
`TeX-active-styles' and you should be done.

Best, Arash