<commit_before>module Polytexnic
  module Builders
    class Pdf < Builder

      def build!
        # Process the raw PolyTeX into LaTeX (with syntax highlighting, etc.).
        # TODO: add processing step (from polytexnic-core)
        cmd = "pdflatex #{@manifest.filename}"
        # Run the command twice to guarantee up-to-date cross-references.
        system("#{cmd} && #{cmd}")
      end

    end
  end
end<commit_msg>[Delivers #47086769] Build a PDF using the polytexnic-core pipeline<commit_after>module Polytexnic
  module Builders
    class Pdf < Builder

      def build!
        # Build the PolyTeX filename so it accepts both 'foo' and 'foo.tex'.
        basename = File.basename(@manifest.filename, '.tex')
        polytex_filename = basename + '.tex'
        latex_filename   = basename + '.tmp.tex'
        # TODO: Follow the includes to ensure polytex contains all the content.
        polytex = File.open(polytex_filename) { |f| f.read }
        latex   = Polytexnic::Core::Pipeline.new(polytex).to_latex
        File.open(latex_filename, 'w') { |f| f.write(latex) }
        cmd = "pdflatex #{latex_filename}"
        # Run the command twice to guarantee up-to-date cross-references.
        system("#{cmd} && #{cmd}")
        rename_pdf(latex_filename)
      end

      private

        # Renames the temp PDF so that it matches the original filename.
        # For example, foo_bar.tex should produce foo_bar.pdf.
        def rename_pdf(latex_filename)
          tmp_pdf = File.basename(latex_filename, '.tmp.tex') + '.tmp.pdf'
          pdf     = File.basename(latex_filename, '.tmp.tex') + '.pdf'
          File.rename(tmp_pdf, pdf)
        end

    end
  end
end
{'fraction_non_alphanumeric': 0.10485781990521327, 'fraction_numerical': 0.004739336492890996, 'mean_word_length': 2.4824742268041238, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3805211', 'n_tokens_mistral': 524, 'n_tokens_neox': 508, 'n_words': 148}