3

Is it possible to assign the citation style with a command? (such as \ExecuteBibliographyOptions{...})

I'm getting all \usepackage{...} in one file and settings in another. But I can not do:

\ExecuteBibliographyOptions{style=numeric-comp}

Because it gives the following error:

! Package keyval Error: style undefined.

MWE:

\documentclass{scrbook}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
    @misc{K1, author={A 1}, title={T 1}}
    @misc{K2, author={A 2}, title={T 2}}
    @misc{K3, author={A 3}, title={T 3}}
\end{filecontents}
\usepackage{biblatex}
\ExecuteBibliographyOptions{%
    backend = biber,
    %style = numeric-comp,   <---   this fails!
}
\addbibresource{\jobname.bib}
\begin{document}
Some text \cite{K1, K2, K3}.
\printbibliography%
\end{document}

Using \usepackage[style=numeric-comp]{biblatex} works perfectly, but I would like to set the style in another file (in the preamble). I can not find how, or at least confirm that it is not possible.

I've also tried with citestyle=numeric-comp and gives the same result.

Thanks in advance!


UPDATE

The idea is to separate into multiple files all the preamble of the document, because this is long (it's for my graduation thesis). And I have distributed this way (they are more files):

File: Settings/Packages.tex

%[...more packages...]
\usepackage{biblatex}   % space for a brief description
%[...more packages...]

File: Settings/Config.tex

%[...more configs...]
\ExecuteBibliographyOptions{%
    backend = biber,
    sortcites = true,
}
%[...more configs...]

File: Main.tex

\documentclass{scrbook}
\input{Settings/Packages}
\input{Settings/Config}
%[...more inputs...]
\loadglsentries{Glossary.tex}
\addbibresource{Bibliography.bib}
\begin{document}
\include{Chapters/Chapter1}
%[...more chapters...]
\end{document}

So I need to apply the style after the \usepackage, because many of the other packages are made this way (koma-script, glossaries, amsmath, graphicx, PGF-TikZ, siunitx, hyperref, etc.).

3
  • You can pass the options in the \documentclass line (as long as two packages don't have the same option names, so not always possible.) Or you could use \PassOptionsToPackage{<options>}{<package>}.
    – Alan Munn
    Aug 6, 2015 at 21:35
  • Thanks @christian-hupfer. @alan-munn I unknown the command \PassOptionsToPackage{...} (thanks) the problem is that I change the order of the rest of the document, so I put "after the \usepackage{biblatex}" (I update my question).
    – Schcriher
    Aug 6, 2015 at 22:42
  • @Schcriher For the biblatex options listed it is not possible to do this way.
    – Alan Munn
    Aug 6, 2015 at 23:16

1 Answer 1

1

I'm not completely sure what you are planning to do is a good idea, since it's much easier to see what's going on if the options are listed with the package, but if you really want to do this, you have two options. (Pun intended).

  1. Pass all options as global options to the \documentclass

By default, global options (i.e., those given in the \documentclass command) will be available to any package loaded, so as long as there aren't conflicting package options, you could pass your biblatex options (or any other options) as global options. This won't work for all package options.

  1. Use \PassOptionsToPackage

For a more finegrained approach, you can use the \PassOptionsToPackage command before you load the package.

Here's an example of this technique. In this example, I deliberately used the backend=bibtex option because it it not the default in biblatex. In your sample code, it only appeared that that option was working.

You can also see the effects of the placement of the command. If you load biblatex first and then execute \PassOptionsToPackage the backend option will not work correctly. (Make sure you delete all your .aux files between each run as you test.)

% !BIB TS-program = bibtex

\documentclass[]{scrbook}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
    @misc{K1, author={A 1}, title={T 1}}
    @misc{K2, author={A 2}, title={T 2}}
    @misc{K3, author={A 3}, title={T 3}}
\end{filecontents}
\PassOptionsToPackage{style=numeric-comp,backend=bibtex}{biblatex}

\usepackage{biblatex}

\addbibresource{\jobname.bib}
\begin{document}
Some text \cite{K1, K2, K3}.
\printbibliography%
\end{document}

Specifically for the biblatex options it is not possible to load them after you load the package. Section 3.1.1 of the biblatex documentation lists the following options that must be loaded at package loading time (i.e., with the \usepackage command or passed as described above):

  • backend
  • style, bibstyle, citestyle
  • natbib
  • mcite

So for these options there is no way to load the package and then set the option.

8
  • The reason for separating the inclusions and settings is the extension of the same. Not all options can be global (I remember reading in some packages this restriction). Yes, biber option works for me perfectly. I tried putting "before" and "after" usepackage and only works by putting it before (for style and backend). I will update my question to show the structure I'm doing. Thank you very much for your reply.
    – Schcriher
    Aug 6, 2015 at 23:04
  • Thank you very much @alan-munn, Yes. the manual is somewhat inaccurate to say The following options must be used as Biblatex is loaded, i. e., in the optional argument to \usepackage, even says This means that you can't set the backend with, for example, \ExecuteBibliographyOptions in the preamble. and to me it worked (although I think I'll put it next to usepackage to avoid strange errors).
    – Schcriher
    Aug 6, 2015 at 23:26
  • @Schcriher No, the manual is not inaccurate. It only appeared that you were setting the backend option in your example code. It wasn't actually working, but appeared to work because you used biber which is the default.
    – Alan Munn
    Aug 6, 2015 at 23:28
  • With "inaccurate" I meant the first part gives the example put options in the usepackage, it sounds like a "possibility" but is required to do so (or the shortcut PassOptionsToPackage). I may sound like me in that way, since English is not my native language. What the backend if possible I worked for it.
    – Schcriher
    Aug 6, 2015 at 23:36
  • 1
    @Schcriher I'm a bit confused. The part of the manual you quote is quite explicit that the backend option can only be passed at package loading time, and this is in fact correct.
    – Alan Munn
    Aug 6, 2015 at 23:44

You must log in to answer this question.

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