When/How should a class load biblatex
Unfortunately, style=...
can only be given in the optional argument to \usepackage[...]{biblatex}
, so if you want to leave the authors free to choose the style they prefer you cannot load biblatex
in the class.
What you can do is to specify the options you do want:
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myclass}[2015/12/29 My MWE class]
\LoadClassWithOptions{article}
\PassOptionsToPackage{backend=biber}{biblatex}
\endinput
I tried and, specifying backend=bibtex
in the document is ineffective. You could also add a fatal error:
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myclass}[2015/12/29 My MWE class]
\LoadClassWithOptions{article}
\PassOptionsToPackage{backend=biber}{biblatex}
\AtBeginDocument{%
\@ifpackageloaded{biblatex}{}
{\ClassError{myclass}{Fatal: biblatex not loaded}
{You must load biblatex, I'll end here}\@@end}%
}
\endinput
One option is to add an option to the class to suppress loading the biblatex package in the class. This gives a default of loading biblatex with the default values, but if the user wants to manually load biblatex, then they need to provide the class option.
% arara: pdflatex
% arara: biber
% arara: pdflatex
% arara: pdflatex
\RequirePackage{filecontents}
\begin{filecontents*}{myclass.cls}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myclass}[2015/12/29 My MWE class]
\newif\ifnobiblatex
\DeclareOption{nobiblatex}{\nobiblatextrue}
\ProcessOptions\relax
\LoadClassWithOptions{article}
\PassOptionsToPackage{backend=biber}{biblatex}
\ifnobiblatex%
\AtBeginDocument{%
\@ifpackageloaded{biblatex}{}
{\ClassError{myclass}{Fatal: biblatex not loaded}
{You must load biblatex, I'll end here}\@@end}%
}
\else\RequirePackage{biblatex}\fi
\endinput
\end{filecontents*}
\documentclass[nobiblatex]{myclass}
\usepackage[style=authoryear]{biblatex}
\addbibresource{biblatex-examples.bib}
\begin{document}
\nocite{*}
\printbibliography
\end{document}
Here's a trial solution with \DeclareOption{authoryear}{...}
(for example)
Make sure to use \LoadClassWithOptions{...}
before \DeclareOption
, otherwise myclass
will complain about authoryear
.
More sophisticated approaches require a better option handling of course, especially the option values.
\RequirePackage{filecontents}
\begin{filecontents*}{myclass.cls}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myclass}[2015/12/29 My MWE class]
\LoadClassWithOptions{article}
\DeclareOption{authoryear}{\PassOptionsToPackage{style=authoryear}{biblatex}}
\ProcessOptions
\endinput
\end{filecontents*}
\documentclass[authoryear]{myclass}
\usepackage{biblatex}
\addbibresource{biblio.bib}
\begin{document}
\cite{Lam94}
\printbibliography
\end{document}