Class: Softcover::Builders::Pdf
- Inherits:
-
Softcover::Builder
- Object
- Softcover::Builder
- Softcover::Builders::Pdf
- Defined in:
- lib/softcover/builders/pdf.rb
Constant Summary
Constants included from Utils
Instance Attribute Summary
Attributes inherited from Softcover::Builder
Instance Method Summary collapse
Methods included from Utils
#add_highlight_class!, #article?, #as_size, #book_file_lines, #chapter_label, #commands, #current_book, #dependency_filename, #digest, #executable, #execute, #filename_or_default, #first_path, #get_filename, #html_extension, #in_book_directory?, #language_labels, #linux?, #logged_in?, #master_content, #master_filename, #master_latex_header, #mkdir, #non_comment_lines, #os_x?, #path, #polytexnic_html, #raw_lines, #reset_current_book!, #rm, #rm_r, #silence, #silence_stream, #source, #template_dir, #tmpify, #unpublish_slug, #write_master_latex_file, #write_pygments_file
Methods included from Output
should_output?, silence!, silent?, #system, unsilence!
Methods inherited from Softcover::Builder
Constructor Details
This class inherits a constructor from Softcover::Builder
Instance Method Details
#build!(options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/softcover/builders/pdf.rb', line 7 def build!(={}) 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! opts = .merge({ source: :polytex, origin: :markdown}) self.manifest = Softcover::BookManifest.new(opts) end write_master_latex_file(manifest) # Build the PolyTeX filename so it accepts both 'foo' and 'foo.tex'. basename = File.basename(manifest.filename, '.tex') book_filename = basename + '.tex' # In debug mode, execute `xelatex` and exit. if [:debug] execute "#{xelatex} #{book_filename}" return # only gets called in test env end polytex_filenames = manifest.pdf_chapter_filenames << book_filename polytex_filenames.each do |filename| polytex = File.read(filename) 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 File.write(Softcover::Utils.tmpify(manifest, filename), latex) end write_pygments_file(:latex, Softcover::Directories::STYLES) copy_polytexnic_sty() # 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.) cmd = "#{pdf_cmd(book_filename, )} " + "; #{rename_pdf(basename, )}" # Here we use `system` when making a preview because the preview command # needs to run after the main PDF build. if [:quiet] || [:silent] silence_stream(STDERR) do silence { [:preview] ? system(cmd) : execute(cmd) } end elsif [:'find-overfull'] silence_stream(STDERR) { execute(cmd) } else [:preview] ? system(cmd) : execute(cmd) end end |