Biblatex: Two bibliographies with different styles and sortings
If you pass the option labelnumber
to biblatex
you can use numeric citations even with style=alphabetic
.
The cite command can switch based on keywords, so you can use \cite
for all entries regardless of keyword
.
For the numeric bibliography we will have to define a new bibliography environment that prints numeric citations. bibliographyNUM
is directly copied from numeric.bbx
. To set the sorting for the bibliography, just say
\newrefcontext[sorting=none]
\printbibliography[env=bibliographyNUM, title=References, keyword=secondary, resetnumbers]
before the numeric bibliography. The previous bibliography will use the global sorting scheme anyt
that is appropriate for alpha-style bibliography. In case it is necessary to keep the sorting scheme assignment local (because the numeric bibliography comes before the alpha bibliography), you would use
\begin{refcontext}[sorting=none]
\printbibliography[env=bibliographyNUM, title=References, keyword=secondary, resetnumbers]
\end{refcontext}
MWE
\documentclass{article}
\usepackage[style=alphabetic, labelnumber, defernumbers=true, backend=biber]{biblatex}
\usepackage{hyperref}
% Append keywords to identify different bibliography entries.
% appendstrict only appends if the field is nonempty,
% we use that to add a comma to avoid mushing together two keywords
\DeclareSourcemap{
\maps[datatype=bibtex, overwrite]{
\map{
\perdatasource{biblatextest1.bib}
\step[fieldset=KEYWORDS, fieldvalue={, }, appendstrict]
\step[fieldset=KEYWORDS, fieldvalue=primary, append]
}
\map{
\perdatasource{biblatextest2.bib}
\step[fieldset=KEYWORDS, fieldvalue={, }, appendstrict]
\step[fieldset=KEYWORDS, fieldvalue=secondary, append]
}
}
}
\DeclareFieldFormat{labelnumberwidth}{\mkbibbrackets{#1}}
\renewbibmacro*{cite}{%
\printtext[bibhyperref]{%
\printfield{labelprefix}%
\ifkeyword{secondary}
{\printfield{labelnumber}}
{\printfield{labelalpha}%
\printfield{extraalpha}}}}
\defbibenvironment{bibliographyNUM}
{\list
{\printtext[labelnumberwidth]{%
\printfield{labelprefix}%
\printfield{labelnumber}}}
{\setlength{\labelwidth}{\labelnumberwidth}%
\setlength{\leftmargin}{\labelwidth}%
\setlength{\labelsep}{\biblabelsep}%
\addtolength{\leftmargin}{\labelsep}%
\setlength{\itemsep}{\bibitemsep}%
\setlength{\parsep}{\bibparsep}}%
\renewcommand*{\makelabel}[1]{\hss##1}}
{\endlist}
{\item}
\begin{filecontents}{biblatextest1.bib}
@BOOK{BookA03,
author = {Author Aaa},
title = {Some Title},
publisher = {Some Publisher},
year = 2003,
keywords = {hello},
}
@BOOK{BookB02,
author = {Author Bbb},
title = {Some Title},
publisher = {Some Publisher},
year = 2002,
}
\end{filecontents}
\begin{filecontents}{biblatextest2.bib}
@MISC{LinkC04,
author = {Author Ccc},
title = {Some Title},
year = 2004,
url = {www.test1.com/bild.jpg},
keywords = {bye},
}
@MISC{LinkD01,
author = {Author Ddd},
title = {Some Title},
year = 2001,
url = {www.test2.com/bild.jpg},
}
\end{filecontents}
\addbibresource{biblatextest1.bib}
\addbibresource{biblatextest2.bib}
\begin{document}
The first two citations \cite{LinkD01} and \cite{BookB02}.
The others are \cite{LinkC04} and \cite{BookA03}.
\printbibliography[title=Bibliography, keyword=primary]
\newrefcontext[sorting=none]
\printbibliography[env=bibliographyNUM, title=References, keyword=secondary, resetnumbers]
\end{document}