Skip to content

Instantly share code, notes, and snippets.

@codeincontext
Created April 26, 2012 23:19
Show Gist options
  • Save codeincontext/2504064 to your computer and use it in GitHub Desktop.
Save codeincontext/2504064 to your computer and use it in GitHub Desktop.
require 'timeout'
files_to_watch = %w{FYP.txt template.tex FYP.bib}
guard :shell do
files_regex = Regexp.new(files_to_watch.join("|"))
watch(files_regex) { regenerate }
end
def regenerate
Timeout::timeout(90) do
puts 'Converting to tex'
`pandoc FYP.txt -o FYP.tex --template=template.tex`
puts 'Compiling tex (1st pass)'
`latex -interaction=nonstopmode FYP`
puts 'Executing bibtex'
`bibtex FYP.tex`
puts 'Compiling tex (2nd pass)'
`latex -interaction=nonstopmode FYP`
puts 'Compiling tex (3rd pass)'
`latex -interaction=nonstopmode FYP`
puts 'Building PDF'
`pdflatex FYP`
puts 'PDF Generated'
end
rescue Timeout::Error
puts 'It got stuck'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment