<commit_before>pkgs:

rec {


  runLaTeX =
    { rootFile
    , generatePDF ? true # generate PDF, not DVI
    , generatePS ? false # generate PS in addition to DVI
    , extraFiles ? []
    , compressBlanksInIndex ? true
    , packages ? []
    , searchRelativeTo ? dirOf (toString rootFile) # !!! duplication
    }:

    assert generatePDF -> !generatePS;
    
    pkgs.stdenv.mkDerivation {
      name = "doc";
      
      builder = ./run-latex.sh;
      copyIncludes = ./copy-includes.pl;
      
      inherit rootFile generatePDF generatePS extraFiles
        compressBlanksInIndex;

      includes = import (findLaTeXIncludes {inherit rootFile searchRelativeTo;});
      
      buildInputs = [ pkgs.tetex pkgs.perl ] ++ packages;
    };

    
  findLaTeXIncludes =
    { rootFile
    , searchRelativeTo ? dirOf (toString rootFile)
    }:

    pkgs.stdenv.mkDerivation {
      name = "latex-includes";

      realBuilder = pkgs.perl + "/bin/perl";
      args = [ ./find-includes.pl ];

      rootFile = toString rootFile; # !!! hacky

      inherit searchRelativeTo;

      # Forces rebuilds.
      hack = __currentTime;
    };


  dot2pdf =
    { dotGraph
    }:

    pkgs.stdenv.mkDerivation {
      name = "pdf";
      builder = ./dot2pdf.sh;
      inherit dotGraph;
      buildInputs = [
        pkgs.perl pkgs.tetex pkgs.graphviz pkgs.ghostscript
      ];
    };
  

  dot2ps =
    { dotGraph
    }:

    pkgs.stdenv.mkDerivation {
      name = "ps";
      builder = ./dot2ps.sh;
      inherit dotGraph;
      buildInputs = [
        pkgs.perl pkgs.tetex pkgs.graphviz pkgs.ghostscript
      ];
    };

  
  animateDot = dotGraph: nrFrames: pkgs.stdenv.mkDerivation {
    name = "dot-frames";
    builder = ./animatedot.sh;
    inherit dotGraph nrFrames;
  };

}
<commit_msg>* A function `simpleTeXToPNG' that typesets a piece of LaTeX code   (e.g., a file containing something like `$x^2 + y^2 = z^2$') and   converts it to a PNG image with no unnecessary surrounding   whitespace.  Useful when you want to include TeX stuff in webpages /   other documents.<commit_after>pkgs:

rec {


  runLaTeX =
    { rootFile
    , generatePDF ? true # generate PDF, not DVI
    , generatePS ? false # generate PS in addition to DVI
    , extraFiles ? []
    , compressBlanksInIndex ? true
    , packages ? []
    , searchRelativeTo ? dirOf (toString rootFile) # !!! duplication
    }:

    assert generatePDF -> !generatePS;
    
    pkgs.stdenv.mkDerivation {
      name = "doc";
      
      builder = ./run-latex.sh;
      copyIncludes = ./copy-includes.pl;
      
      inherit rootFile generatePDF generatePS extraFiles
        compressBlanksInIndex;

      includes = import (findLaTeXIncludes {inherit rootFile searchRelativeTo;});
      
      buildInputs = [ pkgs.tetex pkgs.perl ] ++ packages;
    };

    
  findLaTeXIncludes =
    { rootFile
    , searchRelativeTo ? dirOf (toString rootFile)
    }:

    pkgs.stdenv.mkDerivation {
      name = "latex-includes";

      realBuilder = pkgs.perl + "/bin/perl";
      args = [ ./find-includes.pl ];

      rootFile = toString rootFile; # !!! hacky

      inherit searchRelativeTo;

      # Forces rebuilds.
      hack = __currentTime;
    };


  dot2pdf =
    { dotGraph
    }:

    pkgs.stdenv.mkDerivation {
      name = "pdf";
      builder = ./dot2pdf.sh;
      inherit dotGraph;
      buildInputs = [
        pkgs.perl pkgs.tetex pkgs.graphviz pkgs.ghostscript
      ];
    };
  

  dot2ps =
    { dotGraph
    }:

    pkgs.stdenv.mkDerivation {
      name = "ps";
      builder = ./dot2ps.sh;
      inherit dotGraph;
      buildInputs = [
        pkgs.perl pkgs.tetex pkgs.graphviz pkgs.ghostscript
      ];
    };

  
  animateDot = dotGraph: nrFrames: pkgs.stdenv.mkDerivation {
    name = "dot-frames";
    builder = ./animatedot.sh;
    inherit dotGraph nrFrames;
  };


  # Wrap a piece of TeX code in a document.  Useful when generating
  # inline images from TeX code.
  wrapSimpleTeX =
    { preamble ? null
    , body
    , name ? baseNameOf (toString body)
    }:

    pkgs.stdenv.mkDerivation {
      inherit name preamble body;
      buildCommand = "
        touch $out
        echo '\\documentclass{article}' >> $out
        echo '\\pagestyle{empty}' >> $out
        if test -n \"$preamble\"; then cat $preamble >> $out; fi
        echo '\\begin{document}' >> $out
        cat $body >> $out
        echo '\\end{document}' >> $out
      ";
    };


  # Convert a Postscript file to a PNG image, trimming it so that
  # there is no unnecessary surrounding whitespace.    
  postscriptToPNG =
    { postscript
    }:

    pkgs.stdenv.mkDerivation {
      name = "png";
      inherit postscript;
      
      buildCommand = "
        if test -d $postscript; then
          input=$(ls $postscript/*.ps)
        else
          input=$(stripHash $postscript; echo $strippedName)
          ln -s $postscript $input
        fi

        # !!! Quick hack: no ImageMagick in Nixpkgs yet!
        export PATH=/usr/bin:$PATH
        ensureDir $out
        convert -units PixelsPerInch \\
          -density 300 \\
          -trim \\
          -matte \\
          -transparent '#ffffff' \\
          -type PaletteMatte \\
          +repage \\
          $input \\
          \"$out/$(basename $input .ps).png\"
      ";
    };


  # Convert a piece of TeX code to a PNG image.
  simpleTeXToPNG =
    { preamble ? null
    , body
    , name ? baseNameOf (toString body)
    , packages ? []
    }:

    postscriptToPNG {
      postscript = runLaTeX {
        rootFile = wrapSimpleTeX {
          inherit body preamble;
        };
        inherit packages;
        generatePDF = false;
        generatePS = true;
        searchRelativeTo = dirOf (toString body);
      };
    };


      
}

{'fraction_non_alphanumeric': 0.1071490694033745, 'fraction_numerical': 0.002435206122803966, 'mean_word_length': 1.9578189300411524, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '3076719', 'n_tokens_mistral': 1954, 'n_tokens_neox': 1803, 'n_words': 439}