Vincent Beffara wrote:
Dear list,

First of all, this is a great mailing list ! I am learning  lot.


So here is my question. I have a bibliography in a .bib file, which
(just in case) is just a plain text files containing entries that each
look like this :

@article{key,
  author = {Whatshisname, J.},
  title = {My paper}
}

(note the '@' at the beginning of the first line - folding a .bib file
is trivial for instance).

I would like to sort the entries according to, say, the author's last
name (though by key or even by first line is ok). What would be a good
way to do this ?

That's the last feature of AucTeX that I am missing from emacs ...


BTW, I did come up with an ugly hack, involving replacing all newlines
with <MARK>, re-splitting at the @ signs (hence one line per entry),
sorting this, and re-breaking the entries, but I felt a bit dirty doing
it like that ;-)


Thanks in advance,

  /vincent


Complex sorting is best handled by the "decorate-sort-undecorate" method:

1) add a sort key in front of each line
2) sort
3) remove the sort keys.

In this case, I guess a useful sort key would be the author's last name followed by a space, the line number padded to a fixed length, and -- let's say -- the character § (or anything else which won't happen in the sort key). (The line number is there to make sure that lines with a common author's last name will be kept in the original order; it is padded to avoid sorting 10 before 2; and the § is there to make the "undecorate" step easy.) Since not every line contains the author's name, you will probably have to write a function for step 1 above. Then (assuming the sort key is separated from the rest by a § character) step 2 would be just ":1,$sort" and step 3 would be ":1,$s/^.\{-}§//" (without the quotes in both cases, of course).


Best regards,
Tony.
--
hundred-and-one symptoms of being an internet addict:
56. You leave the modem speaker on after connecting because you think it
    sounds like the ocean wind...the perfect soundtrack for "surfing the net".

Reply via email to