2

Is it possible to sort the order of references using the order in the .bib file?

4
  • Could you provide some background information to this proposed approach? Eg, are the entries in the bib file sorted in some special, non-alphabetical way that needs to be preserved in the printed bibliography?
    – Mico
    Sep 25, 2014 at 4:38
  • @Mico Yes you are right, I want to preserve the special ordering in bib file.
    – william007
    Sep 25, 2014 at 5:04
  • And what would this special ordering be? Is it based on the values of one or more fields (presumably not the author and year fields)? I ask these questions because, by design, BibTeX makes no assumptions about the ordering of the entries in the bib file(s), and it does not keep track of the input ordering. Hence, if the ordering of the entries does turn out to be important, one has to provide BibTeX with some information so that it can reconstruct that ordering during the sorting phase. Please start by indicating the sorting criteria, if any, that were applied to the bib file.
    – Mico
    Sep 25, 2014 at 5:33
  • @Mico In such case, I would wish to ordering by authoring name, in reverse order. That is z comes before y, and so on.
    – william007
    Sep 25, 2014 at 5:38

2 Answers 2

5

Here's a solution that should work with any bib file, including one in which the entries have been sorted in reverse alphabetical order.

First, insert the following instruction at the top of the bib file:

@preamble{ "\newcommand{\noop}[1]{}" }

At first blush, the \noop instruction would seem to be pointless as it doesn't do anything with its argument. While this is true for the LaTeX typesetting run, it is not true for the BibTeX sorting phase. In fact, for the sorting phase of its job, BibTeX will replace \noop{abc} with abc and consider "abc" to be a part of the material that needs to be sorted alphabetically.

Second, assuming you have fewer than 26*26=676 entries in the bib file, insert \noop{aa}, \noop{ab}, ..., \noop{az}, \noop{ba}, \noop{bb}, ... instructions immediately (without space) before the surname of the first author in the author field of each and every entry:

@article{xyz,
   author  = "Dane \noop{aa}Miller and Jane Smith",
   ...
}
@book{123,
   author = "Jill \noop{ab}Anderson and Bill Carlson",
   ...
}
...
@techreport{johnson:2012,
   author = "\noop{ac}Johnson, Jimmy",
   ...
}

(If you have more than 676 entries, just expand the string length of the argument of \noop suitably, e.g, to aaaa, aaab, etc.)

Third, be sure to use a bibliography style file that sorts the bib entries alphabetically. The point of the \noop instructions should now be clear: For sorting purposes, the relevant surnames are "aaMiller", "abAnderson", and "acJohnson", and hence the three entries will be sorted in the same way they occur in the bib file (rather than Anderson followed by Johnson followed by Miller). Later, when LaTeX does its typesetting thing, it discards the aa, ab, etc prefixes, and the names will be typeset correctly.

0

A solution by @egreg has been provided in this thread: https://tex.stackexchange.com/a/56640/204235

\nocite{*}can be added at the top of documents before any citations, your bibliography will be printed in the order of your .bib and you can still add citations that will use the numbering from your .bib.

You must log in to answer this question.

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