3
\$\begingroup\$

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}
    \addtolength{\labelwidth}{2\labelsep}
    \addtolength{\bibhang}{\labelsep}
}

% Numeric styles %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\beamer@namenumeric{numeric}
\ifx\blx@bbxfile\beamer@namenumeric
    \fixnumericstyles
\fi
%
\def\beamer@namenumericcomp{numeric-comp}
\ifx\blx@bbxfile\beamer@namenumericcomp
    \fixnumericstyles
\fi
%
\def\beamer@namenumericverb{numeric-verb}
\ifx\blx@bbxfile\beamer@namenumericverb
    \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)

\$\endgroup\$
1
\$\begingroup\$

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}
    \addtolength{\labelwidth}{2\labelsep}
    \addtolength{\bibhang}{\labelsep}
}

% 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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\edef\beamer@namenumeric{numeric}
\ifx\beamer@blxbase\beamer@namenumeric
    \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}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.