beamer biblatex add tag
samcarter
I would like to hook into `.bbx` files to apply a few fixes to correctly format bibliographies in beamer.

I tried the `scrlfile` and `filehook` packages and they work fine for `.tex` or `.sty` files, but I can't get them to work with `.bbx` files.

A short example that would change the background colour if the hook would work:

```
\documentclass{beamer}

\RequirePackage{scrlfile}
\AfterFile{numeric.bbx}{
	\setbeamercolor{background canvas}{bg=red}
}

\RequirePackage{filehook}
\AtEndOfFile{numeric.bbx}{
	\setbeamercolor{background canvas}{bg=red}
}

\usepackage[style=numeric]{biblatex}

\begin{document}

\begin{frame}
test
\end{frame}

\end{document}
```

The `.log` file shows that the `numeric.bbx` file is found:

```
Package biblatex Info: Trying to load bibliography style 'numeric'...
Package biblatex Info: ... file 'numeric.bbx' found.

(/usr/local/texlive/2019/texmf-dist/tex/latex/biblatex/bbx/numeric.bbx
File: numeric.bbx 2019/12/01 v3.14 biblatex bibliography style (PK/MW)
Package biblatex Info: Trying to load bibliography style 'standard'...
Package biblatex Info: ... file 'standard.bbx' found.

(/usr/local/texlive/2019/texmf-dist/tex/latex/biblatex/bbx/standard.bbx
File: standard.bbx 2019/12/01 v3.14 biblatex bibliography style (PK/MW)
\c@bbx:relatedcount=\count433
\c@bbx:relatedtotal=\count434
))
```

Any ideas why the above code is not working as expected?

---

### Update

For everybody interested in this, there is a related discussion going on at https://github.com/josephwright/beamer/issues/581 and it looks as if biblatex might be going to provide hooks for other packages and classes to use.
Top Answer
Skillmon
*Disclaimer:* This answer just lists why this doesn't work. The below "What could you do" is only a proof of concept, which might break things and I don't advise anybody to actually use that code!

# What is `\input`?

In LaTeX the definition of `\input` is:

```
\let\@@input\input % saving the TeX primitive
\def\input{\@ifnextchar\bgroup\@iinput\@@input}
```

# What do the packages do?

`filehook` hooks into `\@iinput` and doesn't alter `\@@input`, which still is the primitive. It also hooks into `\InputIfFileExists`.

`scrlfile` only hooks into `\InputIfFileExists` and doesn't alter LaTeX's `\input` at all.

# What is `biblatex` doing?

`biblatex` does use its own macro called `\blx@inputonce` to include styles. It is defined as:

```
\protected\long\def\blx@inputonce#1#2#3#4#5#6{%
  \ifcsundef{blx@file@#1}
    {\blx@info@noline{Trying to load #2..}%
     \IfFileExists{#1}
       {\blx@info@noline{... file '#1' found}%
        #3\@@input\@filef@und#4#5%
        \listxadd\blx@list@req@stat{#1}%
        \@addtofilelist{#1}}
       {\blx@info@noline{... file '#1' not found}#6}%
     \global\cslet{blx@file@#1}\@empty}
    {#5}}
```

The important part is, that it only uses `\@@input\@filef@und`, which is neither altered by `filehook` nor by `scrlfile`. So `biblatex` effectively circumvents any hooking mechanism.

# What could you do?

Hook into `\blx@inputonce`, but unfortunately as you need the altered behaviour amidst the package you can only hook into things that are already defined before the package gets loaded and part of `\blx@inputonce`. So the most promising insertion point would be `\IfFileExists` altering it to inject your code if the filename matches anyone you specified. The following does so by altering an `\IfFileExists` internal, use at your own risk, this might break things if some code curries arguments!

```
\documentclass{beamer}

\usepackage{etoolbox}

\makeatletter
\let\IfFileExists@ORIG\IfFileExists@
\long\def\IfFileExists@#1#2#3%
  {%
    \IfFileExists@ORIG{#1}{\blxhack@prehook{#1}#2\blxhack@posthook{#1}}{#3}%
  }
\newcommand\blxhack@prehook[1]
  {%
    \@ifundefined{blxhack@prehook@#1}{}{\csname blxhack@prehook@#1\endcsname}%
  }
\newcommand\blxhack@posthook[1]
  {%
    \@ifundefined{blxhack@posthook@#1}{}{\csname blxhack@posthook@#1\endcsname}%
  }
\newcommand\blxhackPreFile[2]
  {%
    \csgappto{blxhack@prehook@#1}{#2}%
  }
\newcommand\blxhackPostFile[2]
  {%
    \csgappto{blxhack@posthook@#1}{#2}%
  }
\makeatother

\blxhackPostFile{numeric.bbx}{%
	\setbeamercolor{background canvas}{bg=red}%
}

\usepackage{biblatex}

\begin{document}

\begin{frame}
test
\end{frame}

\end{document}
```
Answer #2
samcarter
@moewew thankfully implemented an interface for this in https://github.com/plk/biblatex/pull/973

So with the development version of biblatex this is now very easy to solve:

```
\documentclass{beamer}

\makeatletter
\csappto{blx@filehook@postload@numeric.bbx}{%
  \mode<presentation>{\setbeamercolor{background canvas}{bg=red}}%
}
\makeatother

\usepackage[style=numeric]{biblatex}

\begin{document}

\begin{frame}
test
\end{frame}

\end{document}
```
Answer #3
CrazyHorse
create your own bbx-file on-the-fly and insert your code after including the `numeric.bbx`:



```
\documentclass{beamer}
\begin{filecontents}[force]{mynumeric.bbx}
\ProvidesFile{mynumeric.bbx}[\abx@bbxid]
\RequireBibliographyStyle{numeric}
\setbeamercolor{background canvas}{bg=red}
\endinput
\end{filecontents}

\usepackage[bibstyle=mynumeric]{biblatex}
\addbibresource{biblatex-examples.bib}
\begin{document}

\begin{frame}
test
\end{frame}

\nocite{*}
\begin{frame}
\printbibliography
\end{frame}

\end{document}
```

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.