lib/softcover/builders/pdf.rb in softcover-0.8.9 vs lib/softcover/builders/pdf.rb in softcover-0.9.0

- old
+ new

@@ -3,10 +3,11 @@ class Pdf < Builder include Softcover::Output include Softcover::Utils def build!(options={}) + make_png_from_gif if manifest.markdown? # Build the HTML to produce PolyTeX as a side-effect, # then update the manifest to reduce PDF generation # to a previously solved problem. Softcover::Builders::Html.new.build! @@ -27,11 +28,13 @@ end polytex_filenames = manifest.pdf_chapter_filenames << book_filename polytex_filenames.each do |filename| polytex = File.read(filename) - latex = Polytexnic::Pipeline.new(polytex).to_latex + latex = Polytexnic::Pipeline.new(polytex, + language_labels: language_labels). + to_latex if filename == book_filename latex.gsub!(/\\include{(.*?)}/) do "\\include{#{Softcover::Utils.tmpify(manifest, $1)}.tmp}" end end @@ -65,12 +68,28 @@ # Returns the `xelatex` executable. # The `xelatex` program is roughly equivalent to the more standard # `pdflatex`, but has better support for Unicode. def xelatex - filename = `which xelatex`.chomp - message = "Install LaTeX (http://latex-project.org/ftp.html)" - @xelatex ||= executable(filename, message) + @xelatex ||= executable(dependency_filename(:latex)) + end + + # Make a PNG for each GIF in the images/ directory. + def make_png_from_gif + gif_pattern = File.join('images', '**', '*.gif') + gif_files = Dir.glob(gif_pattern).reject { |f| File.directory?(f) } + gif_files.each do |gif| + dir = File.dirname(gif) + ext = File.extname(gif) + img = File.basename(gif, ext) + png = File.join(dir, "#{img}.png") + system "#{convert} #{gif} #{png}" + end + end + + # Returns the executable to ImageMagick's `convert` program. + def convert + @convert ||= executable(dependency_filename(:convert)) end # Returns the command to build the PDF (once). def build_pdf(book_filename, options={}) tmp_filename = Softcover::Utils.tmpify(manifest, book_filename) \ No newline at end of file