Skip to content

Instantly share code, notes, and snippets.

@lucas-clemente
Created February 15, 2012 14:12
Show Gist options
  • Save lucas-clemente/1835987 to your computer and use it in GitHub Desktop.
Save lucas-clemente/1835987 to your computer and use it in GitHub Desktop.
Latex wrapper for bibtex
#!/usr/bin/env ruby -w
# Save to pdflatex to ~/bin/pdflatex
if ARGV.length == 0
puts "Usage: texify <file.tex> <tex options>"
exit 1
end
file = ARGV.select{|v| v =~ /.*\.tex/}[0]
latex = "/usr/texbin/pdflatex #{ARGV * ' '}"
if file
bibtex = "bibtex #{file[0..-4]}aux"
cite_file = file + '.cites'
contents = File.open(file) {|f| f.read}
begin
old_data = File.open(cite_file) {|f| f.read}
rescue
old_data = ''
end
new_data = contents.scan(/\\cite\{[^\}]*\}/).join("\n")
if (new_data != old_data)
File.open(cite_file, 'w') {|f| f.write(new_data)}
system(latex) and system(bibtex) and system(latex)
end
end
system(latex)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment