Skip to content

Instantly share code, notes, and snippets.

@panterch
Created May 15, 2009 15:17
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 panterch/112246 to your computer and use it in GitHub Desktop.
Save panterch/112246 to your computer and use it in GitHub Desktop.
require 'erb'
require 'tempfile'
class Pdflatex
TEMPLATE_DIR = File.join(RAILS_ROOT, 'app', 'views', 'tex')
def self.run(template_path, locals = nil)
template = File.new(template_path).read
erb = ERB.new(template)
tex = Tempfile.new('pdflatex', WORK_DIR)
tex.puts erb.result(binding)
tex.flush
cmd = "pdflatex -interaction batchmode " +
" -output-directory #{File.dirname(tex.path)} #{tex.path}"
res = `#{cmd}`
unless (0 == $?.to_i)
raise "could not transform using #{cmd}: #{res}"
end
tex.path + '.pdf'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment