# biblatex - Sort cites via number (split bibliography)

This is a follow-up question to biblatex - Consistent numbering in split bibliographies.

My bibliography is split into two parts via categories. The entries are numbered consecutively and I want to sort the entries within each \cite. However, inside each \cite the entries are ordered (first) by year and, thus, entries of the first and second part of the bibliography get mixed up.

MWE:

\documentclass{article}

\usepackage[
sorting      = ynt,
bibstyle     = numeric,
defernumbers = true,
sortcites    = true
]{biblatex}
\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@book{a,
author = "I",
year = "1973"
}
@book{a2,
author = "I",
year = "1923"
}
@book{b,
author = "You",
year = "1959"
}
\end{filecontents}

\DeclareBibliographyCategory{own}

\begin{document}

\cite{a,a2,b}

\printbibliography[category=own,title={A}]
\printbibliography[notcategory=own,title={B}]

\end{document}


The cite reads [1, 3, 2] but I would like to have [1, 2, 3].

Is there a good way to achieve this?

• Now you see why I said I cheated before. For proper sorting as in the former title of the other question we need a bit more work. – moewe Oct 16 '15 at 9:20

Since we want to sort entries with a certain property before other entries and sorting is done by Biber we will have to tell Biber in the .bib which entry has this property (there is a way to get out of this limitation, see below for more details).

So we cannot use bibcategories any more, we will use keywords instead. Just add keywords = {own} to the relevant entries

@book{a,
author = "I",
year = "1973",
keywords = {own},
}


Naturally the bibliographies are filtered with keyword and notkeyword now

\printbibliography[keyword=own,title={A}]
\printbibliography[notkeyword=own,title={B}]


We then check for own and, if the keyword is present, fill the presort field with A, otherwise it gets a B.

\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\step[fieldsource=keywords, match=\regexp{(^|,)own(,|$)}, final] \step[fieldset=presort, fieldvalue = {A}] } \map{ \step[fieldset=presort, fieldvalue = {B}] } } }  MWE \documentclass{article} \usepackage[ sorting = ynt, bibstyle = numeric, defernumbers = true, sortcites = true ]{biblatex} \usepackage{filecontents} \begin{filecontents*}{\jobname.bib} @book{a, author = "I", year = "1973", keywords = {own}, } @book{a2, author = "I", year = "1923", keywords = {own}, } @book{b, author = "You", year = "1959", } @book{c, author = "You", year = "1970", keywords = {notmine}, } \end{filecontents*} \addbibresource{\jobname.bib} \DeclareSourcemap{ \maps[datatype=bibtex]{ \map{ \step[fieldsource=keywords, match=\regexp{(^|,)own(,|$)}, final]
\step[fieldset=presort, fieldvalue = {A}]
}
\map{
\step[fieldset=presort, fieldvalue = {B}]
}
}
}

\begin{document}
\cite{a,a2,b,c}

\printbibliography[keyword=own,title={A}]
\printbibliography[notkeyword=own,title={B}]
\end{document}


To do everything from within your .tex file use

\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\step[fieldsource=entrykey, match=\regexp{^(a|a2)$}, final] \step[fieldset=presort, fieldvalue = {A}] } \map[overwrite=true]{ \step[fieldsource=entrykey, match=\regexp{^(a|a2)$}, final]
\step[fieldset=keywords, fieldvalue = {own}, append]
}
\map{
\step[fieldset=presort, fieldvalue = {B}]
}
}
}


Where you replace (a|a2) in the two steps above with a list of "own" entry keys separated by |.

MWE

\documentclass{article}

\usepackage[
sorting      = ynt,
bibstyle     = numeric,
defernumbers = true,
sortcites    = true
]{biblatex}

\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@book{a,
author = "I",
year = "1973",
}
@book{a2,
author = "I",
year = "1923",
}
@book{b,
author = "You",
year = "1959",
}
@book{c,
author = "You",
year = "1970",
}
\end{filecontents*}

\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\step[fieldsource=entrykey, match=\regexp{^(a|a2)$}, final] \step[fieldset=presort, fieldvalue = {A}] } \map[overwrite=true]{ \step[fieldsource=entrykey, match=\regexp{^(a|a2)$}, final]
\step[fieldset=keywords, fieldvalue = {own}, append]
}
\map{
\step[fieldset=presort, fieldvalue = {B}]
}
}
}

\begin{document}
\cite{a,a2,b,c}

\printbibliography[keyword=own,title={A}]
\printbibliography[notkeyword=own,title={B}]
\end{document}

• Since I use the same bib-file across multiple projects, I refrain from modifying the bib-file. Is there any possibility to fill the presort-field in the tex-file by, e.g., using the category or by a \customCommand{a2}? – gerw Oct 16 '15 at 9:31
• @gerw Scrap my earlier comment, I found a solution, see the edit. – moewe Oct 16 '15 at 9:42
• Thank you for your answer! I used and modified your approach to provide a \citeown-command, which adds references to the regexp in the sourcemap. – gerw Oct 16 '15 at 11:29