I need the bibliography in my tex file to be in a custom order. So far I've only found how to sort the bibliography alphabetically or in order of appearance. How may I sort it in a custom order?
-
2Welcome to TeX.SE. Are you going to reveal what the nature of the custom sorting order is, or are you going to make us guess? (Remark: Virtually all contributors to this site appear to be appallingly bad at guessing and absolutely no good at all at divination.)– MicoCommented Aug 29, 2016 at 13:23
-
Ok, I thought that was clear, my apologies. By 'custom' sort I mean an oder chosen by me, which is neither alphabetical or in order of appearance. I'd like the bibliography to be sorted in "groups", i.e. from the first position to position A I have one topic, from position A+1 to position B I have another topic and so on so forth. Since I'm citing only some of the bibliography entries, I cannot use the "order of appearance" sorting– cholo14Commented Aug 29, 2016 at 13:34
-
2@Mico But there are some exceptions. After nearly 3 years on this site, I am absolutely convinced that egreg and David Carlisle can read minds!– samcarter_is_at_topanswers.xyzCommented Aug 29, 2016 at 13:34
-
2@cholo14 Are you willing to switch to biblatex? There might be some useful features.– samcarter_is_at_topanswers.xyzCommented Aug 29, 2016 at 13:36
-
@samcarter - Good thing I wrote "virtually all contributors..."! :-)– MicoCommented Aug 29, 2016 at 15:03
1 Answer
You haven't provided a lot of specific information regarding the custom sorting principle(s) you wish to implement. The following solution is therefore necessarily of the bare-bones, no-frills variety.
You've indicated (I think) that you're OK with the way that the
unsrt
bibliography style formats various entries of type@article
,@book
, etc. I suggest you switch to theplain
bibliography style. It applies the exact same formatting procedures asunsrt
does; the main difference is thatunsrt
provides no sorting facility at all.Insert the following instruction at the very top of your
bib
file:@preamble{ "\providecommand{\noopsort}[1]{} " }
Let's label the topics and associated groups of entries
01
,02
, etc. It's important that they be given numeric labels. The assumption is that all entries labelled01
should be listed before those with label02
, and so on.If you have more than 100 but fewer than 1000 groups, just switch the labelling system to
001
,002
, etc.For all entries that belong to topic
01
, change the author field as follows: add the prefix\noopsort{01}
to the surname of the first author in theauthor
field. E.g., if the author field of a given entry that is supposed to belong to group01
is given byauthor = "Author, Anna and Zebulon Zingales",
change it to
author = "\noopsort{01}Author, Anna and Zebulon Zingales",
Note: no space between the prefix and the first author's surname.
Ditto for all remaining entries of type
01
and for all entries that belong to topics02
,03
, etc.Since you're using a bibliography style that applies sorting, all entries whose first author's surname is prefixed with
01
will be placed before those with prefix02
which, in turn, will precede those with prefix03
, etc. Here's why it's crucial to use numeric labels: in the ASCII table, the numerals0
thru9
occur before uppercase and lowercase letters. Thus, the numeric prefixes take precedence over the subsequent letters that make up the authors' names.For instance, the entry with author field
"\noopsort{01}Author, Anna and Zebulon Zingales"
will be placed before an entry with author field"\noopsort{02}Aardvark, Alison and Sean Sheep"
.A side effect, which is presumably not unwelcome, is that within each group/topic the entries will be sorted alphabetically. Finally, because
\noopsort
doesn't "do anything" with its argument as far as LaTeX is concerned, the labels won't show up in the typeset bibliography.Then, rerun LaTeX -- you did change the argument of
\bibliographystyle
fromunsrt
toplain
, right? -- BibTeX, and LaTeX twice more.
-
Incidentally, this solution method works not only with the
plain
bibliography style. Indeed, it works with any bibliography style that performs alphabetical sorting.– MicoCommented Aug 30, 2016 at 10:48 -
@Servaes - Do please state which part of my answer "does not work." For sure, the code I provided above works just fine for the OP's use case. If my answer "does not work" for your use case, it must be because your use case is materially different from the OP's. If you don't reveal what your use case is, it's not possible to help you meaningfully, is it?– MicoCommented Dec 17, 2018 at 13:58
-
@Servaes - My answer as well as the original query were unambiguously marked as pertaining to BibTeX. I made no claim whatsoever that my answer would work with biblatex (and biber). In a way, I'm neither surprised nor bothered by the fact that my answer doesn't "work" with biblatex.– MicoCommented Dec 17, 2018 at 14:10
-
@Servaes - I refer explicitly to the
unsrt
bibliography style, and later on to theplain
bibliography style; such remarks only make sense if BibTeX is in use. The answer was "accepted" by the OP, so clearly it "worked" for that person. As you haven't indicated what exactly you were doing, I simply have no way of diagnosing why the method shown above doesn't "work" for you. But I guess that obtaining meaningful help was never your intention to begin with. Posting a useless remark and casting a downvote are evidently much more satisfying activities. Best wishes. You'll go far.– MicoCommented Dec 17, 2018 at 14:39