lib/softcover/builders/pdf.rb in softcover-0.7.5 vs lib/softcover/builders/pdf.rb in softcover-0.7.6

- old
+ new

@@ -40,44 +40,25 @@ end end write_pygments_file(:latex) copy_polytexnic_sty - if options[:'find-overfull'] - tmp_name = book_filename.sub('.tex', '.tmp.tex') - # The way we do things, code listings show up as "Overfull", but - # they're actually fine, so filter them out. - filter_out_listings = "grep -v 3.22281pt" - # Because each chapter typically lives in a separate file, it's - # hard to correlate Overfull line numbers with lines in the source, - # so we use grep's -A flag to provide some context instead. Authors - # can then use their text editors' search function to find the - # corresponding place in the text. - show_context = 'grep -A 3 "Overfull \\\\\\\\hbox"' - cmd = "xelatex #{tmp_name} | #{filter_out_listings} | #{show_context}" - silence_stream(STDERR) { execute cmd } - return - end - - tmp_filename = Softcover::Utils.tmpify(manifest, book_filename) - build_pdf = "#{xelatex} #{tmp_filename}" - # Run the command twice (to guarantee up-to-date cross-references) - # unless explicitly overriden. # Renaming the PDF in the command is necessary because `execute` # below uses `exec` (except in tests, where it breaks). Since `exec` # causes the Ruby process to end, any Ruby code after `exec` # is ignored. # (The reason for using `exec` is so that LaTeX errors get emitted to # the screen rather than just hanging the process.) - pdf_cmd = options[:once] ? build_pdf : "#{build_pdf} ; #{build_pdf}" - cmd = "#{pdf_cmd} ; #{rename_pdf(basename)}" + cmd = "#{pdf_cmd(book_filename, options)} ; #{rename_pdf(basename)}" # Here we use `system` when making a preview because the preview command # needs to run after the main PDF build. if options[:quiet] || options[:silent] silence_stream(STDERR) do silence { options[:preview] ? system(cmd) : execute(cmd) } end + elsif options[:'find-overfull'] + silence_stream(STDERR) { execute(cmd) } else options[:preview] ? system(cmd) : execute(cmd) end end @@ -88,9 +69,38 @@ # `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) + end + + # Returns the command to build the PDF (once). + def build_pdf(book_filename, options={}) + tmp_filename = Softcover::Utils.tmpify(manifest, book_filename) + "#{xelatex} #{tmp_filename} #{options[:filters]}" + end + + # Returns the full command to build the PDF. + def pdf_cmd(book_filename, options={}) + if options[:once] + build_pdf(book_filename) + elsif options[:'find-overfull'] + # The way we do things, code listings show up as "Overfull", but + # they're actually fine, so filter them out. + filter_out_listings = "grep -v 3.22281pt" + # Because each chapter typically lives in a separate file, it's + # hard to correlate Overfull line numbers with lines in the source, + # so we use grep's -A flag to provide some context instead. Authors + # can then use their text editors' search function to find the + # corresponding place in the text. + show_context = 'grep -A 3 "Overfull \\\\\\\\hbox"' + build_pdf(book_filename, + filters: "| #{filter_out_listings} | #{show_context}" ) + else + # Run the command twice (to guarantee up-to-date cross-references). + cmd = build_pdf(book_filename) + "#{cmd} ; #{cmd}" + end end # Returns the command to rename the temp PDF. # The purpose is to match the original filename. # For example, foo_bar.tex should produce foo_bar.pdf. \ No newline at end of file