0

As this is a rather specific question and in lieu of a MWE some context:

I am working on a personalized version of the tufte-book class. In the process I am now at a point where I think I need a way to sort a list of biblatex-keys in order of the number they have. This is because I have extended the cite-command. (Note: tufte-book uses bibtex in the vanilla-version, I changed that to biblatex with biber backend, in case that is relevant)

In tufte-book when you call \cite{key1,key2,..} what really gets called is something like

% Normal \cite behavior
\newcounter{@tufte@num@bibkeys}%
\newcommand{\@tufte@normal@cite}[2][0pt]{%
  \hiddencite{#2}
  % Snag the last bibentry in the list for later comparison
  \let\@temp@last@bibkey\@empty%
  \@for\@temp@bibkey:=#2\do{\let\@temp@last@bibkey\@temp@bibkey}%
  \marginnote[#1]{%
    % Loop through all the bibentries, separating them with semicolons and spaces
    \normalsize\normalfont\@tufte@citation@font%
    \setcounter{@tufte@num@bibkeys}{0}%
    \@for\@temp@bibkeyx:=#2\do{%
      \ifthenelse{\equal{\@temp@last@bibkey}{\@temp@bibkeyx}}%
        {\ifthenelse{\equal{\value{@tufte@num@bibkeys}}{0}}{}{and\ }%
         \@tufte@trim@spaces\@temp@bibkeyx% trim spaces around bibkey
         \hiddencite{\@temp@bibkeyx}\bibentry{\@temp@bibkeyx}}%
        {\@tufte@trim@spaces\@temp@bibkeyx% trim spaces around bibkey
         \hiddencite{\@temp@bibkeyx}\bibentry{\@temp@bibkeyx};\ }%
      \stepcounter{@tufte@num@bibkeys}%
    }%
  }%
}

This already includes some changes from me (the goal is to have the full citation not as a footnote but as a marginnote with the citation number visible, see picture below). Hiddencite is nothing but the original cite which I stored because it gets changed from tufte-book. However, this does not work as good as the original cite command, because the list (#2) is not sorted.

here's an exemplary result to show my problem citations

generated by

some citations\cite{Tufte2001,Tufte1990,Tufte1997,Tufte2006}
same citations in different ordering \cite{Tufte2001,Tufte2006,Tufte1990,Tufte1997}

My goal is to find a way that both calls generate the same output (in the main text and the marginnote)

and now the actual question: How would I achieve a sorting of the list of citation keys I have? I want something that turns the argument key1,key3,key2,key4 into key1,key2,key3,key4. (Assuming that is the correct order).

What I did try is to look into the natbib and biblatex packages how they handle this, but I frankly failed to understand the code.

Final remark: I was asked how one would achieve such behaviour, this is not my idea (Personally I would be fine with a plain bibliography at the end)

8
  • biblatex does have an option sortcites which sorts citations according to the applicable sorting scheme if activated. See order of multiple keys in \cite-command and In-text references are not alphabetically ordered.
    – moewe
    Commented Aug 6, 2015 at 17:26
  • @moewe maybe i am misunderstanding you, but the part that is actually handled by biblatex (the [1-4] in the main text) is handled correctly. The problem here is that the list of keys gets separated (so as to call bibentry with each key individually) and then each key is passed on its own to biblatex
    – Bort
    Commented Aug 6, 2015 at 17:32
  • If the above does not work, a short MWE would be very much appreciated to investigate why it doesn't do the right thing. (Did you have to do a lot of modifications to get tufte-book to work with biblatex? In the current version it should not take a lot more than loading the documentclass with the nobib option and then loading biblatex later. Of course, your citation style looks non-standard, but that should not be a Tufte issue.)
    – moewe
    Commented Aug 6, 2015 at 17:33
  • I think one could probably come up with a way to do what you want on a level closer to biblatex which then allows sorting. The way you do it now I don't see how you could possibly do proper sorting: Only biblatex knows about the order and can do sorting, but your wrapper passes the bibkeys to biblatex one by one at which point the sorting feature is somewhat pointless.
    – moewe
    Commented Aug 6, 2015 at 17:38
  • @moewe Well, you could do it outside of the tufte framework, but I thought it might be worth doing it inside (the definition of \cite changes when called inside a sidenote), but I have spent some time on this, so any suggestions are appreciated. I am going to try to come up with a presentation that is less cluttered about with tufte-specifics,. With respect to the sorting: My idea was that i have access to \citenum, so I could do a string comparison on that
    – Bort
    Commented Aug 6, 2015 at 17:39

1 Answer 1

1

moewe in the comments was right this can be achieved easily using biblatex only

 \usepackage[
  style=numeric-comp,
  backend=biber,
  sorting=none
  ]{biblatex}

\addbibresource{sample-handout.bib}
\let\truecite\cite
\DeclareCiteCommand{\footcite}[\marginnote]%
  {\usebibmacro{prenote}}
{\truecite{\thefield{entrykey}} \printnames{author},\
\printfield{title},\printfield{year}}
  {\multicitedelim}
  {\usebibmacro{postnote}}
\renewcommand{\cite}[1]{\truecite{#1}\footcite{#1}}

i will deal with citations in sidenotes separately (moved to an answer as suggested in the comments)

You must log in to answer this question.

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