# Making adjustments based on biblatex style

The styles which are provided by the biblatex package can be categorised into a few different families, e.g. numeric (numeric, numeric-comp and numeric-verb) or authoryear (authoryear, authoryear-comp, authoryear-ibid and authoryear-icomp). I'm currently working on a mechanism for beamer to apply some adjustments based on which of these style families is used. For example for numeric styles I would like the numbers to be shown in the bibliography or for authoryear styles I would like to prevent the icon from going into the margin.

My current version of the code tests for each style individually, e.g. three if-cases for the numeric styles and another four if-cases for the authoryear styles. This feels overly complicate, so I would like to hear what you think about this approach. Can it be improved?

\documentclass{beamer}

\usepackage[
%   style=numeric,
%   style=numeric-comp,
%   style=numeric-verb,
%   style=authoryear,
style=authoryear-comp,
%   style=authoryear-ibid,
%   style=authoryear-icomp,
]{biblatex}

\addbibresource{biblatex-examples.bib}% included in full tex distributions or from http://mirrors.ctan.org/macros/latex/contrib/biblatex/doc/examples/biblatex-examples.bib

\makeatletter
\newcommand{\fixnumericstyles}{%
\setbeamertemplate{bibliography item}{\insertbiblabel}
}

\newcommand{\fixauthoryearstyles}{%
\newlength{\beamer@bibiconwidth}
\settowidth\beamer@bibiconwidth{\usebeamertemplate*{bibliography item}}
\setlength{\labelwidth}{-\beamer@bibiconwidth}
}

% Numeric styles %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\fixnumericstyles
\fi
%
\fixnumericstyles
\fi
%
\fixnumericstyles
\fi
%
% author year styles %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\beamer@nameauthoryear{authoryear}
\ifx\blx@bbxfile\beamer@nameauthoryear
\fixauthoryearstyles
\fi
\def\beamer@nameauthoryear{authoryear-comp}
\ifx\blx@bbxfile\beamer@nameauthoryear
\fixauthoryearstyles
\fi
\def\beamer@nameauthoryear{authoryear-ibid}
\ifx\blx@bbxfile\beamer@nameauthoryear
\fixauthoryearstyles
\fi
\def\beamer@nameauthoryear{authoryear-icomp}
\ifx\blx@bbxfile\beamer@nameauthoryear
\fixauthoryearstyles
\fi
\makeatother
\begin{document}

$$\begin{frame} \cite{sigfridsson} \printbibliography \end{frame}$$

\end{document}


(a variant of the above code incorporated into beamer can be found in this fork: https://github.com/samcarter/beamer/tree/PrivateCollectionBugFixes)

It seems I needed Aristotle to save my project -- with the help of Saving Aristotle: How can Biblatex redefinitions be made conditional on the style selected? the code can me massively simplified to the following example:

\documentclass{beamer}

\usepackage[
%   style=numeric,
%   style=numeric-comp,
%   style=numeric-verb,
%   style=authoryear,
%   style=authoryear-comp,
%   style=authoryear-ibid,
style=authoryear-icomp,
]{biblatex}

\addbibresource{biblatex-examples.bib}% included in full tex distributions or from http://mirrors.ctan.org/macros/latex/contrib/biblatex/doc/examples/biblatex-examples.bib

\makeatletter
\newcommand{\fixnumericstyles}{%
\setbeamertemplate{bibliography item}{\insertbiblabel}
}

\newcommand{\fixauthoryearstyles}{%
\newlength{\beamer@bibiconwidth}
\settowidth\beamer@bibiconwidth{\usebeamertemplate*{bibliography item}}
\setlength{\labelwidth}{-\beamer@bibiconwidth}
}

% from https://tex.stackexchange.com/a/365563/36296
\def\beamer@blx@splitfile#1-#2\@null{#1}
\edef\beamer@blxbase{\expandafter\beamer@blx@splitfile\blx@cbxfile-x\@null}
%
% numeric styles %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\fixnumericstyles
\fi
%
% author year styles %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\edef\beamer@nameauthoryear{authoryear}
\ifx\beamer@blxbase\beamer@nameauthoryear
\fixauthoryearstyles
\fi

\makeatother
\begin{document}

$$\begin{frame} \cite{sigfridsson} \printbibliography \end{frame}$$

\end{document}


### Update 2020

In the mean time, the biblatex developers were so nice to add some hooks which can be used for this purpose, see https://github.com/plk/biblatex/pull/973 for more details. This simplifies the solution dramatically and makes it much more versatile.

The following code was added to beamer to make the necessary adjustments:

% Adding patches to some biblatex styles
\mode<presentation>{\setbeamertemplate{bibliography item}{\insertbiblabel}}}
\mode<presentation>{\setbeamertemplate{bibliography item}{\insertbiblabel}}}
\mode<presentation>{%
\newlength{\beamer@bibiconwidth}
\settowidth\beamer@bibiconwidth{\usebeamertemplate*{bibliography item}}
\setlength{\labelwidth}{-\beamer@bibiconwidth}