7

I recently switched to BibLaTeX to realize a multilanguage bibliography. Everything worked out fine -- however I get the error "Can be used only in preamble." when using the command \DeclareLanguageMapping{english}{english-apa} to declare the respective apa-file as the language file for english. Strangly enough it works if I compile the file without the line in question and compile it a second time with the command. Does anyone know how to fix this?

Here is my MWE:

\begin{filecontents}{\jobname.bib}

@article{Grimberg.2012,
 author = {Grimberg, Steffen},
 year = {2012},
 title = "{Sherlock Holmes in der ARD: Gefährliche Gefühle}",
 journal = {taz.de \textnormal{am 17.05.2012}},
 url = {http://www.taz.de/!5093806/},
 urldate = {2015-06-06},
 hyphenation = {english}
}


@book{Weller.1994,
author = {Philip Weller},
year = {1994},
title = "{Alphabetically, My Dear Watson. A Compilation of Canonical Characters. Sherlock Holmes from A to Z}",
edition = {3},
address = {Portsmouth},
publisher = {Sherlock Publications},
}

@incollection{Moriarty.2011,
author = {Moriarty, James},
title = "{The Role of Supervillains in Modern Democracy.}",
pages = {79-107},
publisher = {{Villainy Press}},
editor = {Moriarty, James},
booktitle = {Supervillainy in the 21st Century},
volume = {5},
edition = {3},
year = {2011},
address = {London},
hyphenation = {english}, 
}
\end{filecontents} 
\documentclass[12pt,parskip=half]{scrartcl}

\usepackage[english,ngerman]{babel} 
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp}

\usepackage{csquotes}
\usepackage[
backend=biber,
style=apa,
natbib=true,
autolang=other]{biblatex}
\DeclareLanguageMapping{ngerman}{ngerman-apa}
\DeclareLanguageMapping{english}{english-apa}

\addbibresource{\jobname.bib}

\begin{document}
\citet{Grimberg.2012, Weller.1994, Moriarty.2011}

\printbibliography
\end{document}
cfr
  • 198,882
JKR
  • 351
  • @JKR Have you reported the issue to the author? The author of this package really should know how to fix it properly. – cfr Aug 09 '15 at 00:12
  • 1
    @cfr I've deleted all my comments in this thread. Given Ulrike's answer I don't think our comments add too much to the question any more. – Alan Munn Aug 09 '15 at 13:54

1 Answers1

8

The language files are loaded the first time they are "needed". At the first compilation this is when the \cite commands are seen and so in the middle of the document. As \DefineBibliographyExtras is an "only preamble" command you get an error.

At the next compilation the aux files calls the english language and so the language files are loaded earlier.

You can force the early loading of the language files by using

\AtBeginDocument{\selectlanguage{english}\selectlanguage{ngerman}}

Edit

It is imho a bug in the apa-files. It uses DefineBibliographyExtras instead of \DeclareBibliographyExtras. I made a bug report: https://github.com/plk/biblatex-apa/issues/12

Ulrike Fischer
  • 327,261