29

I want to know if there is a way to optimize the order my citations are in, such that they output the minimum number of numbers in the text.

So, if I have citations \cite{A,B,C} and later \cite{A,C,D} it will realize that if I had instead done \cite{B,A,C} and \cite{A,C,D} it would give a shorter output. That is, the first case one of these will have (1-3) and the second (1,3,4). But if they are reordered you would instead get (1-3) and (2-4).

Another example: \cite{A,B,C}, \cite{D,E,F}, \cite{A,D,F} could be optimized to \cite{B,C,A}, \cite{D,F,E}, \cite{A,D,F}. Which would go from (1-3), (4-6), (1,4,6) to (1-3), (4-6), (3-5).

Now that way only removes one number from displaying, but I regularly have 9+ citations inside each \cite{} command (i.e. \cite{Miro2012,Ling2010,Takao2010,Unruh2009,Goff2008,Kubatko2007,DeAquino2001,Rose1994,David1993}) so an optimization like this could change thing from (1,3,5,7,9,11,13,15,17) to (1-9) at an extreme (going from 22 characters to 3).

I don't have a way to do this outside of LaTeX. If I had to do it by hand I would first make a list of every group of citations with more then 3 citations that also occur earlier in the document. Then I would find if any of those occurred in the same citation block and put them next to one another, provided that doesn't make other blocks worse. Then I would find if any of the citations that occur in earlier blocks occur in adjacent blocks, and try and move those to the ends, if I could do so without messing up other blocks. This would not generate an optimized solution, but I suspect it would generate a better one. If doing this by computer, I would also do multiple trials of optimizing the blocks in different orders so that you don't have an early reordering preventing later ones.

Potentially you could do something with a badness score so that you could mess up one citation block if it made two others better, or one a LOT better?

Rewrite inspired by @JosephWright explained well in the comments:

I think the point here is that if one has several multiple citation, \cite{A,B,C}, \cite{A,D,E}, \cite{B,D,F}, there will be an optimal approach to the ordering in each argument which places as many as possible in continuous runs so reduces the output complexity. -Joseph Wright, May 14 '16 at 5:30

The optimisation might for example spot that if you have a first use \cite{A,B,C} and later \cite{B,D,E} then reordering the first case to \cite{A,C,B} will swap two refs and go from output 1---3 (A = 1, B = 2, C = 3) and 2,4,5 (D = 4, E = 5), to 1--3 (A = 1, C = 2, B = 3) and 3--5 (D = 4, E = 5). The point here is that the refs are all still in use order, but within sets used at one time the order is optimised to globally-minimise the number of numbers which need to be printed. – Joseph Wright May 14 '16 at 13:34

Original text:

Currently, within each citation block, I'm listing citations by date. So I'll have a command with something like:\cite{Miro2012,Ling2010,Takao2010,Unruh2009,Goff2008,Kubatko2007,DeAquino2001,Rose1994,David1993}

This works quite well, LaTeX does the order for me, and gives me an output like 14,19,62,70,71,75–78

That is pretty ugly and takes up a good inch of space. However, most of those are all referenced in the same citation block earlier in the paper. So really, if I'd cited them in order I'd get something more like 14,19,62-68 Given that most of my citation order is arbitrary within each citation (date) I'm wondering if there is a citation optimizer that goes through and tries to compress your later citation references as much as possible by reordering your earlier ones? Has anyone done something like this in LaTeX?

It would be better still if I could specify times not to do this (i.e. this citation must be first within this block, if it hasn't been cited already) or if it could work with `achemso' but I'm mostly curious if this is possible at all.

(MWE removed, as they didn't add anything except making it look like I was trying to do this with a specific citation package, when I am curious if it is possible to do this at all).

20
  • 1
    @cfr I think the point here is that if one has several multiple citation, \cite{A,B,C}, \cite{A, D,E}, \cite{B,D,F}, there will be an optimal approach to the ordering in each argument which places as many as possible in continuous runs so reduces the output complexity. However, I also think this is a difficult problem (not just in TeX terms)!
    – Joseph Wright
    May 14, 2016 at 5:30
  • 1
    @JosephWright Won't that be very confusing for readers?
    – cfr
    May 14, 2016 at 13:31
  • 4
    @cfr Not if I understand correctly. The optimisation might for example spot that if you have a first use \cite{A,B,C} and later \cite{B,D,E} then reordering the first case to \cite{A,C,B} will swap two refs and go from output 1---3 (A = 1, B = 2, C = 3) and 2,4,5 (D = 4, E = 5), to 1--3 (A = 1, C = 2, B = 3) and 3--5 (D = 4, E = 5). The point here is that the refs are all still in use order, but within sets used at one time the order is optimised to globally-minimise the number of numbers which need to be printed.
    – Joseph Wright
    May 14, 2016 at 13:34
  • 1
    It looks the main question is does the bibliography sorting have access to the grouping information in citations. For bibtex, it is not clear to me: if you load the cite package, then \citation{A,B,C} is in the .aux file, but I don't know whether one can see that grouping at the .bst stage. For biber it seems biblatex does not preserve the grouping when writing to the .bcf file, so biber doesn't see it. Sep 7, 2018 at 11:04
  • 3
    I don't think there is a way to do it in LaTeX. From a programming standpoint, it sounds a lot like travelling salesman. The Graph should contain all citations and initialize the weight of the border to all other citations with the number of citations. For any paired citations, remove the border weight of the pairs by 1. Implementations can be found online. Be warned: Travelling salesman is hard. Apr 13, 2021 at 10:29

0

Your Answer

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

Browse other questions tagged or ask your own question.