Skip to content

Instantly share code, notes, and snippets.

@jokester
Last active December 16, 2015 14:48
Show Gist options
  • Save jokester/5450819 to your computer and use it in GitHub Desktop.
Save jokester/5450819 to your computer and use it in GitHub Desktop.
a Rakefile to compile tex to pdf. idea from http://rkj.github.io/LaTeX/rake/2010/01/15/LaTeX-with-Rakefile.html
#!/usr/bin/env ruby
TEX = FileList["*.tex"]
PDF = TEX.ext ".pdf"
DEP = FileList["*/*.tex"]
TEX.zip(PDF).each do |tex,pdf|
file pdf => [ tex, DEP ].flatten do
begin
sh "pdflatex -interaction=nonstopmode #{tex} > #{pdf}.log"
rescue
puts "fail. retry in 10s"
sleep 10
redo
else
puts "success"
end
end
end
desc "Removes unnecessery files"
task :clean do
rm FileList["*.aux","*.bak","*.log","*.blg", "*.bbl", "*.toc", "*.out", "*.idx", "*.ilg", "*.ind", "*.dep", "*.glo", "*.gls"]
end
desc "compile each file for once"
task :once do
PDF.each do |pdf|
t = Rake::Task[pdf]
t.reenable
if t.needed?
t.invoke
else
puts "#{pdf} is up to date"
end
end
end
desc "compile each file until die"
task :loop do
t = Rake::Task[:once]
loop do
t.reenable
t.invoke
Kernel.sleep 5
end
end
task :default => [:once]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment