Created
March 30, 2017 07:05
-
-
Save dluciv/ba5ffa28502e07c998783e3d4d48e7c5 to your computer and use it in GitHub Desktop.
LaTeX `\cite{...}` order
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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