class CurriculumGenerator::Util::LatexToPdf

Public Class Methods

new( input_file_name, input_dir, resources_pths, out_dir, log_file, halt_on_error=true, shell_enabled=true, interpreter='xelatex', additional_args=[]) click to toggle source
# File lib/curriculum-generator/util/latex_to_pdf.rb, line 5
def initialize(
    input_file_name, input_dir, resources_pths, out_dir, log_file,
    halt_on_error=true, shell_enabled=true, interpreter='xelatex', additional_args=[])
  @interpreter = interpreter
  @halt_on_error = !!halt_on_error
  @shell_enabled = !!shell_enabled
  @out_dir = out_dir
  @input_file_name = input_file_name
  @input_dir = input_dir
  @resources_pths = resources_pths
  @log_file = log_file
  @additional_args = additional_args.is_a?(Array) ? additional_args : []
end

Public Instance Methods

generate() click to toggle source
# File lib/curriculum-generator/util/latex_to_pdf.rb, line 19
def generate

  # Store the starting resources for later cleanup
  starting_resources = resources_files

  # Create the command used to generate the PDF
  gen_pdf_cmd = ShellCommand.new(get_tex_cmd, @input_dir, @log_file)
  # Create the command used to generate the bibliography
  gen_bib_cmd = ShellCommand.new(get_bibtex_cmd, @out_dir, @log_file)

  Either.chain do
    bind -> { gen_pdf_cmd.run }
    bind -> { gen_bib_cmd.run }
    bind -> { gen_pdf_cmd.run }
    bind -> { gen_pdf_cmd.run }
    bind -> {
      # ==> Cleanup resources files
      dirty_files = resources_files - starting_resources
      dirty_files.length > 0 ? system("rm #{dirty_files.join(' ')}") : false
    }
  end
end

Protected Instance Methods

get_bibtex_cmd() click to toggle source
# File lib/curriculum-generator/util/latex_to_pdf.rb, line 55
def get_bibtex_cmd
  "BIBINPUTS=\"#{@input_dir}\" " + "bibtex #{@input_file_name}" # build the bibtex command and return it
end
get_tex_cmd() click to toggle source
# File lib/curriculum-generator/util/latex_to_pdf.rb, line 44
def get_tex_cmd
  args = %w(-synctex=1 -interaction=batchmode)                 # default arguments
  args << '-halt-on-error' if @halt_on_error                   # halt on error
  args += %w(-shell-escape --enable-write18) if @shell_enabled # shell escape
  args << "-output-directory=#{@out_dir}"                      # output directory
  args += @additional_args                                     # add the additional arguments to the computed ones
  args << @input_file_name

  "#{@interpreter} #{args.join(' ')}"                          # build the tex command and return it
end
resources_files() click to toggle source
# File lib/curriculum-generator/util/latex_to_pdf.rb, line 59
def resources_files
  Dir.glob(@resources_pths)
end