<commit_before>require_relative '../extensions'
require_relative '../util/cli_generator'
require_relative '../util/platform'
require_relative '../util/which'

module Asciidoctor
  module Diagram
    # @private
    module TikZ
      include CliGenerator
      include Which

      def self.included(mod)
        [:pdf, :svg].each do |f|
          mod.register_format(f, :image) do |parent, source|
            tikz(parent, source, f)
          end
        end
      end

      def tikz(parent, source, format)
        latexpath = which(parent, 'pdflatex')

        if format == :svg
          svgpath = which(parent, 'pdf2svg')
        else
          svgpath = nil
        end

        latex = <<'END'
\documentclass[border=2bp]{standalone}
\usepackage{tikz}
\begin{document}
\begingroup
\tikzset{every picture/.style={scale=1}}
END
        latex << source.to_s
        latex << <<'END'
\endgroup
\end{document}
END

        pdf = generate_file(latexpath, 'tex', 'pdf', latex) do |tool_path, input_path, output_path|
          {
              :args => [tool_path, '-shell-escape', '-file-line-error', '-interaction=nonstopmode', '-output-directory', Platform.native_path(File.dirname(output_path)), Platform.native_path(input_path)],
              :out_file => "#{File.dirname(input_path)}/#{File.basename(input_path, '.*')}.pdf"
          }
        end

        if svgpath<commit_msg>Fix tikz crop issues (preventing extraneous whitespace)<commit_after>require_relative '../extensions'
require_relative '../util/cli_generator'
require_relative '../util/platform'
require_relative '../util/which'

module Asciidoctor
  module Diagram
    # @private
    module TikZ
      include CliGenerator
      include Which

      def self.included(mod)
        [:pdf, :svg].each do |f|
          mod.register_format(f, :image) do |parent, source|
            tikz(parent, source, f)
          end
        end
      end

      def tikz(parent, source, format)
        latexpath = which(parent, 'pdflatex')

        if format == :svg
          svgpath = which(parent, 'pdf2svg')
        else
          svgpath = nil
        end

        latex = <<'END'
\documentclass[border=2bp, tikz]{standalone}
\usepackage{tikz}
\begin{document}
\begingroup
\tikzset{every picture/.style={scale=1}}
END
        latex << source.to_s
        latex << <<'END'
\endgroup
\end{document}
END

        pdf = generate_file(latexpath, 'tex', 'pdf', latex) do |tool_path, input_path, output_path|
          {
              :args => [tool_path, '-shell-escape', '-file-line-error', '-interaction=nonstopmode', '-output-directory', Platform.native_path(File.dirname(output_path)), Platform.native_path(input_path)],
              :out_file => "#{File.dirname(input_path)}/#{File.basename(input_path, '.*')}.pdf"
          }
        end

        if svgpath
{'fraction_non_alphanumeric': 0.13529829545454544, 'fraction_numerical': 0.002130681818181818, 'mean_word_length': 2.5658227848101265, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 7, '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': '920436', 'n_tokens_mistral': 902, 'n_tokens_neox': 866, 'n_words': 190}