I would like to write a custom class that loads the biblatex package, but I am having trouble with option clashes. For example, the following MWE gives me an error
% arara: pdflatex
% arara: biber
% arara: pdflatex
% arara: pdflatex
\RequirePackage{filecontents}
\begin{filecontents*}{myclass.cls}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myclass}[2015/12/29 My MWE class]
\LoadClassWithOptions{article}
\PassOptionsToPackage{backend=biber}{biblatex}
\RequirePackage{biblatex}
\endinput
\end{filecontents*}
\documentclass{myclass}
\usepackage[style=authoryear]{biblatex}
\addbibresource{biblatex-examples.bib}
\begin{document}
\nocite{*}
\printbibliography
\end{document}
LaTeX Error: Option clash for package biblatex.
The error is pretty clear. The class loads biblatex with the backend=biber option and then again in the document with the backend=biber and authoryear options.
I tried making the class only load the biblatex package with the \AtBeginDocument hook (and the \AtEndPreamble hook from the etoolbox package) if it is not loaded in the preamble.
\AtBeginDocument{\@ifpackageloaded{biblatex}{}{\RequirePackage{biblatex}}}
This apparently is too late to load the biblatex package. The only way I can get it to work is to patch the \document macro
\preto{\document}{\endgroup\@ifpackageloaded{biblatex}{}{\RequirePackage{biblatex}\begingroup}}{}{}
How should a class load the biblatex package?
biblatex. – Dec 29 '15 at 16:24\RequirePackage{biblatex}in the class. – egreg Dec 29 '15 at 16:26\PassOptionsToPackage{biblatex}{...}prior to\documentclasswhich seems strange. – StrongBad Dec 29 '15 at 16:26biberis the default back-end – egreg Dec 29 '15 at 16:27\documentclass[authoryear]{myclass}, i.e. something that is not handled byarticle(which is the effective class in the background) is then passed tobiblatex. The user should loadbiblatexthen. – Dec 29 '15 at 16:27biblatexwith\ExecuteBibliographyOptionsin the document preamble. – egreg Dec 29 '15 at 16:31biblatexsetuplike\hypersetupwould be nice, however. Joseph should be poked about this – Dec 29 '15 at 16:33bibliographystuff very often. – Dec 29 '15 at 16:40\ExecuteBibliographyOptionslater on. – moewe Dec 30 '15 at 07:52