Instantly share code, notes, and snippets.

Embed
What would you like to do?
LaTeX `\cite{...}` order
#!/usr/bin/env ruby
# Author: Dmitry V. Luciv
# License: WTFPL 2.0 http://wtfpl.net
=begin
When typing many \bibitem's manually, instead of using BibTeX and friends,
it often becomes a pain to sort the bibliography in case when it should
appear in order of citations.
Use it as `citeorder.rb <my_lovely_article.tex >ordering.txt`
This tool is not unique, but at least is very lightweight.
=end
src = STDIN.read
cites = src.scan /\\cite\{(.+?)\}/m
refs = cites.map {|v| v[0].split ','}.flatten.map {|v| v.gsub('%', '').strip}.uniq
refs.each &method(:puts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment