Created
February 24, 2014 00:20
-
-
Save theirix/9179430 to your computer and use it in GitHub Desktop.
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 | |
# Experimentally checks bibtex database for warnings. | |
# latexmk and pdflatex required | |
require 'fileutils' | |
require 'ruby-progressbar' | |
raise 'Usage: inspectbibtex.rb BIBFILE [start_citation]' unless ARGV[0] | |
bibfile = ARGV[0] | |
raise 'No bibfile' unless File.exists?(bibfile) | |
start = ARGV[1] | |
cites = IO.readlines(bibfile).map { |s| $1 if s.strip.force_encoding('koi8-r') =~ /^@[a-z]+{(.*),/ }.compact | |
cites = cites.drop_while { |cite| cite != start } if start | |
puts "Read #{cites.size} cites" | |
progressbar = ProgressBar.create(:title => "Cites", :format => '%t: |%B| %p%% %E ', :total => cites.size) | |
cites.each do |cite| | |
progressbar.increment | |
progressbar.log cite | |
IO.write 'test.tex', <<EOF | |
\\documentclass{article} | |
\\usepackage[english,russian]{babel} | |
\\usepackage[utf8x]{inputenc} | |
\\begin{document} | |
\\selectlanguage{russian} | |
\\cite{#{cite}} | |
\\inputencoding{koi8-r} | |
\\bibliographystyle{gost2008} | |
\\bibliography{bibliogr} | |
\\end{document} | |
EOF | |
FileUtils.rm_f %w{aux bbl blg fdb_latexmk fls log pdf}.map { |ext| 'test.'+ext} | |
`latexmk -dvi- -ps- -pdf -pdflatex='pdflatex -interaction=batchmode %O %S' test.tex 2>/dev/null | grep '^Warning'`. | |
encode("utf-8", invalid: :replace, undef: :replace, replace: '').split("\n").each { |s| progressbar.log s } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment