Skip to content

Instantly share code, notes, and snippets.

@michaelbarton
Created October 10, 2008 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelbarton/16034 to your computer and use it in GitHub Desktop.
Save michaelbarton/16034 to your computer and use it in GitHub Desktop.
require 'fileutils'
require 'find'
class Latex < Thor
desc "build","builds thesis document"
method_options :src => 'src',
:dest => 'out',
:tmp => 'tmp'
def build(file)
src = options[:src]
dest = options[:dest]
tmp = options[:tmp]
log = 'latex.log'
# Make directories
FileUtils.makedirs dest unless File.exists?(dest)
FileUtils.makedirs tmp unless File.exists?(tmp)
# Copy all files to a temporary directory
copy_all_files(File.expand_path(src),File.expand_path(tmp))
FileUtils.cd(tmp) do
error_free = true
error_free = system("yes X | latex #{file} > #{log}")
error_free = system("yes X | bibtex #{file} >> #{log}") if error_free
error_free = system("yes X | latex #{file} >> #{log}") if error_free
error_free = system("yes X | latex #{file} >> #{log}") if error_free
end
if error_free
puts "Document built successfully"
else
puts "Error building document"
end
end
private
def copy_all_files(src,dest)
Find.find(src) do |path|
FileUtils.cp(path,dest) if FileTest.file?(path)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment