1

In my document I call the biblatex package with some given options (see MWE below). The package including all given options (as well as multiple other packages that are not subject of my question) are called via \input{...} (not displayed below, as not subject of my question either) and have to be called (to have all the required packages for my thesis).

Is it possible to change the biblatexoptions afterwards (in this case change the numeric style to the APA style)?

Uncommenting the second call of biblatex with the other options results in the error message Option clash for package biblatex.

MWE:

% !TeX program = lualatex
\documentclass{scrreprt}

\usepackage{filecontents}

\begin{filecontents}[overwrite]{Quellen.bib}
@book{Test:2023,
    address = {Test Adress},
    author = {Surname, Given Name},
    editor = {Test Editor},
    publisher = {Test Publisher},
    title = {This is a Test Entry},
    year = {2023},}
\end{filecontents}

%from here
\usepackage[%
    backend=biber,
    bibencoding=utf8,
    style=numeric,
    citestyle=numeric,
    sorting=none,
    defernumbers=true
]{biblatex}
    \addbibresource{Quellen.bib}
%to here the entries can't be changed

%\usepackage[%
%   backend=biber,
%   bibencoding=utf8,
%   style=apa,
%   defernumbers=true
%]{biblatex}
    
\begin{document}

\cite{Test:2023}

\printbibliography

\end{document}

Use case: My use case would be the following: I have a collection of packages I usually use for documents I have to write. For some documents I have to write I have to change the options for biblatex, as the cite style has to be different. If it is possible, I would like to leave this collection as it currently is and change the options as asked above. If it is not possible I would copy the entire collection of packages and change the options manually where biblatex is going to be called (so exchange the commented out version of the biblatex call with the current call of it). As (per today) this would only be for one document I have to write I think the latter would be more suitable, wouldn't it?

3
  • Do you mind editing into your question a use case for this? I have been sitting here trying to work out why the options just wouldn't be loaded initially that are required. Additionally, it appears (this may be outdated however as it is from 2013) that "If a package is loaded, the option setting code in the package is already processed and gone. Thus in general you cannot change package options later". Maybe there will be a solution but it looks challenging.
    – JamesT
    Feb 12 at 22:19
  • 1
    I added the use case as requested @JamesT
    – Lukas
    Feb 12 at 22:36
  • 1
    Not really relevant to the question, but style=numeric, citestyle=numeric, is completely equivalent to style=numeric,. If you're compiling with LuaLaTeX (or any modern LaTeX without inputenc saying otherwise), UTF-8 will be assumed, so bibencoding=utf8, is superfluous.
    – moewe
    Feb 13 at 5:57

2 Answers 2

4

As explained in Set biblatex options after loading you can use \ExecuteBibliographyOptions to change most biblatex options after loading.

The style option, however, cannot be set with \ExecuteBibliographyOptions. It needs to be set at loading time, because style code needs to be available in the preamble.


You could look into \PassOptionsToPackage (Applying options to already loaded package), but because the options of the \usepackage/\RequirePackage prevail over the options in \PassOptionsToPackage, you'd have to load biblatex without the affected options in your input file and would probably end up with a \PassOptionsToPackage in all your documents (not just the few that need a different biblatex style than your usual setup).

You could think about turning your \input file into a package, which could accept options (to avoid loading biblatex or to set specific biblatex options). See the small example in How to NOT include a package in a TeX file?.

Or you could just not load biblatex in your input file, but always load it explicitly in your document. This would be my preferred method. For the most part I'm not a big fan of all-purpose \input files. Too often they tend to accumulate vast numbers of packages that are not needed for every document in which they are loaded (impacting performance and creating risks of incompatibilities). It is usually best to only load the packages one actually needs in each document.

1
  • 1
    Thank you for your input. I will try the variant to load it without any options and pass the required options with the \PassOptionsToPackage later today!
    – Lukas
    Feb 13 at 8:28
0

You could define a macro that will act as a case-switch driver, and set it in your main document, so that, when set to 1, it produces:

option1

and when set to 2, it produces:

option2

Here, an \ifcase statement is used to switch, but other methods are also possible.

MWE

% arara: lualatex
% arara: biber
% arara: lualatex

%\usepackage{filecontents}

\begin{filecontents}[overwrite]{Quellen.bib}
@book{Test:2023,
    address = {Test Adress},
    author = {Surname, Given Name},
    editor = {Test Editor},
    publisher = {Test Publisher},
    title = {This is a Test Entry},
    year = {2023},}
\end{filecontents}




\documentclass{scrreprt}
\newcommand\mybib{2}

\ifcase\mybib \or
%from here
\usepackage[%
%    backend=biber,
%    bibencoding=utf8,
    style=numeric,
%    citestyle=numeric,
%    sorting=none,
    defernumbers=true
]{biblatex}
%to here the entries can't be changed
\or
\usepackage[%
%   backend=biber,
%   bibencoding=utf8,
   style=apa,
   defernumbers=true
]{biblatex}
\fi

    \addbibresource{Quellen.bib}

    
\begin{document}

\cite{Test:2023}

\printbibliography

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .