4

Following the answer https://tex.stackexchange.com/a/70183/56450, I was trying to get a correct sorting for keys in a \parencites command including pre- and post-notes. Is there an equivalent way to do it? All my attempts failed.

MWE:

%!TEX program = lualatex
\documentclass{scrbook}

\usepackage{fontspec}
\usepackage{polyglossia}
\setdefaultlanguage{german}
\usepackage{csquotes}

\usepackage[backend=biber%
           ,style=apa%
           ,maxcitenames=5%
           ,uniquename=full%
           ,sortcites%
           ]{biblatex}

\usepackage{filecontents}
\begin{filecontents}{refs.bib}
@incollection{Klieme,
    author = {Klieme, E.},
    title = {Titel},
    year = {2001},
}
@book{Clausen,
    author = {Clausen, M.},
    title = {Titel},
    year = {1998},
} 
\end{filecontents}
\addbibresource{refs.bib}

\begin{document}

\noindent
\verb+\parencite{Klieme,Clausen}+: \parencite{Klieme,Clausen}, correct sorting\\
\verb+\parencites{Klieme,Clausen}+: \parencites{Klieme,Clausen}, correct sorting\\
\verb+\parencites[vergl.][51]{Klieme}[114]{Clausen}+: \parencites[vergl.][51]{Klieme}[114]{Clausen}, wrong sorting

\end{document}

enter image description here

2

Audrey's great answer to Sorting citations using \cites command in biblatex only redefines the \cites command, but adding support for other \...cites is surprisingly (or perhaps not surprisingly) easy.

For \parencites we only need two additional lines

\DeclareMultiCiteCommand{\cbx@parencites}[\mkbibparens]{\parencite}{\multicitedelim}
\DeclareMultiCiteCommand{\parencites}[\cbx@cite@wrapper\cbx@parencites]{\cbx@cite}{}

for \textcites analogously

\DeclareMultiCiteCommand{\cbx@textcites}{\textcite}{\multicitedelim}
\DeclareMultiCiteCommand{\textcites}[\cbx@cite@wrapper\cbx@textcites]{\cbx@cite}{}

MWE

\documentclass{article}

\usepackage[backend=biber%
           ,style=authoryear%
           ,maxcitenames=5%
           ,uniquename=full%
           ,sortcites%
           ]{biblatex}

\makeatletter
\DeclareMultiCiteCommand{\cbx@parencites}[\mkbibparens]{\parencite}{\multicitedelim}
\DeclareMultiCiteCommand{\parencites}[\cbx@cite@wrapper\cbx@parencites]{\cbx@cite}{}

\DeclareMultiCiteCommand{\cbx@textcites}{\textcite}{\multicitedelim}
\DeclareMultiCiteCommand{\textcites}[\cbx@cite@wrapper\cbx@textcites]{\cbx@cite}{}

% original definition of \cites
\DeclareMultiCiteCommand{\cbx@cites}{\cite}{\multicitedelim}

% new definition
\DeclareMultiCiteCommand{\cites}[\cbx@cite@wrapper\cbx@cites]{\cbx@cite}{}

% first pass saves keys, prenotes, postnotes
\DeclareCiteCommand{\cbx@cite}
  {\csxdef{prenote:\thefield{entrykey}}{\thefield{prenote}}}
  {\listxadd\cbx@savekeys{\thefield{entrykey}}}
  {}
  {\csxdef{postnote:\thefield{entrykey}}{\thefield{postnote}}}

% second pass outputs sorted citation list
\newrobustcmd{\cbx@cite@wrapper}[2]{%
  \def\cbx@savekeys{}%
  \def\cbx@citecall{#1}%
  #2\cbx@sortkeysinit\cbx@citesort\cbx@citecall}

% internal list of saved keys => sorted argument list
\def\cbx@citesort{%
  \def\do##1{%
    \ifinlist{##1}{\cbx@savekeys}
      {\protected@xappto\cbx@citecall{%
         [\csuse{prenote:##1}][\csuse{postnote:##1}]{##1}}}
      {}}%
  \dolistloop{\cbx@sortkeys}}

% internal list of sorted entry keys
\def\cbx@sortkeysinit{%
  \ifcsundef{blx@dlist@entry@\the\c@refsection @\blx@refcontext@context}
    {}
    {\global\csletcs{cbx@sortkeys}{blx@dlist@entry@\the\c@refsection @\blx@refcontext@context}}}
\def\cbx@sortkeys{}
\makeatother

\addbibresource{biblatex-examples.bib}

\begin{document}
\noindent
\parencite{wilde,sigfridsson}\\
\parencites{wilde,sigfridsson}\\
\parencites[vergl.][51]{wilde}[114]{sigfridsson}\\
\parencites{knuth:ct:c}{knuth:ct:b}{knuth:ct:a}

\noindent
\cite{wilde,sigfridsson}\\
\cite{wilde,sigfridsson}\\
\cites[vergl.][51]{wilde}[114]{sigfridsson}\\
\cites{knuth:ct:c}{knuth:ct:b}{knuth:ct:a}

\noindent
\textcite{wilde,sigfridsson}\\
\textcite{wilde,sigfridsson}\\
\textcites[vergl.][51]{wilde}[114]{sigfridsson}\\
\textcites{knuth:ct:c}{knuth:ct:b}{knuth:ct:a}
\end{document}

output of MWE: all citations are now sorted

  • Works perfectly! Thank you. Maybe you could add a link to your answer to the original answer by Audrey. I do not have enough reputation to do so. – ccauet Oct 6 '15 at 7:29
  • @ccauet Since we mentioned the other question here quite extensively, the two questions are now linked via the "linked questions" on the right. So there is no need to add a comment to the other answer, I don't think. – moewe Oct 6 '15 at 7:30
  • Ok, I wasn't aware of that option. Fine with me. – ccauet Oct 6 '15 at 7:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.