2005-06-20 14:51:48 +01:00
|
|
|
pkgs:
|
|
|
|
|
|
|
|
rec {
|
|
|
|
|
2005-06-20 15:26:07 +01:00
|
|
|
|
2005-06-20 14:51:48 +01:00
|
|
|
runLaTeX =
|
|
|
|
{ rootFile
|
2007-03-12 17:55:08 +00:00
|
|
|
, generatePDF ? true # generate PDF, not DVI
|
|
|
|
, generatePS ? false # generate PS in addition to DVI
|
2005-06-20 23:43:35 +01:00
|
|
|
, extraFiles ? []
|
2005-11-28 14:19:46 +00:00
|
|
|
, compressBlanksInIndex ? true
|
2007-03-10 23:51:59 +00:00
|
|
|
, packages ? []
|
2007-03-12 17:55:08 +00:00
|
|
|
, searchRelativeTo ? dirOf (toString rootFile) # !!! duplication
|
2005-06-20 14:51:48 +01:00
|
|
|
}:
|
2007-03-12 17:55:08 +00:00
|
|
|
|
|
|
|
assert generatePDF -> !generatePS;
|
2005-06-20 14:51:48 +01:00
|
|
|
|
|
|
|
pkgs.stdenv.mkDerivation {
|
|
|
|
name = "doc";
|
2005-06-20 16:06:58 +01:00
|
|
|
|
2005-06-20 14:51:48 +01:00
|
|
|
builder = ./run-latex.sh;
|
2005-06-20 16:06:58 +01:00
|
|
|
copyIncludes = ./copy-includes.pl;
|
2005-06-20 14:51:48 +01:00
|
|
|
|
2007-03-12 17:55:08 +00:00
|
|
|
inherit rootFile generatePDF generatePS extraFiles
|
2005-11-28 14:19:46 +00:00
|
|
|
compressBlanksInIndex;
|
2005-06-20 15:26:07 +01:00
|
|
|
|
2007-03-12 17:55:08 +00:00
|
|
|
includes = import (findLaTeXIncludes {inherit rootFile searchRelativeTo;});
|
2005-06-20 14:51:48 +01:00
|
|
|
|
2007-03-10 23:51:59 +00:00
|
|
|
buildInputs = [ pkgs.tetex pkgs.perl ] ++ packages;
|
2005-06-20 14:51:48 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-06-20 15:26:07 +01:00
|
|
|
findLaTeXIncludes =
|
|
|
|
{ rootFile
|
2007-03-12 17:55:08 +00:00
|
|
|
, searchRelativeTo ? dirOf (toString rootFile)
|
2005-06-20 15:26:07 +01:00
|
|
|
}:
|
|
|
|
|
2005-06-20 16:06:58 +01:00
|
|
|
pkgs.stdenv.mkDerivation {
|
2005-06-20 15:26:07 +01:00
|
|
|
name = "latex-includes";
|
2005-06-20 16:06:58 +01:00
|
|
|
|
2006-10-17 15:06:18 +01:00
|
|
|
realBuilder = pkgs.perl + "/bin/perl";
|
2005-06-20 15:26:07 +01:00
|
|
|
args = [ ./find-includes.pl ];
|
|
|
|
|
|
|
|
rootFile = toString rootFile; # !!! hacky
|
2005-06-20 16:20:37 +01:00
|
|
|
|
2007-03-12 17:55:08 +00:00
|
|
|
inherit searchRelativeTo;
|
|
|
|
|
2005-06-20 16:20:37 +01:00
|
|
|
# Forces rebuilds.
|
|
|
|
hack = __currentTime;
|
2005-06-20 16:06:58 +01:00
|
|
|
};
|
2005-06-20 23:43:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
dot2pdf =
|
|
|
|
{ dotGraph
|
|
|
|
}:
|
|
|
|
|
|
|
|
pkgs.stdenv.mkDerivation {
|
|
|
|
name = "pdf";
|
|
|
|
builder = ./dot2pdf.sh;
|
|
|
|
inherit dotGraph;
|
|
|
|
buildInputs = [
|
|
|
|
pkgs.perl pkgs.tetex pkgs.graphviz pkgs.ghostscript
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2005-06-27 10:44:27 +01:00
|
|
|
|
2006-04-11 14:27:01 +01:00
|
|
|
dot2ps =
|
|
|
|
{ dotGraph
|
|
|
|
}:
|
|
|
|
|
|
|
|
pkgs.stdenv.mkDerivation {
|
|
|
|
name = "ps";
|
|
|
|
builder = ./dot2ps.sh;
|
|
|
|
inherit dotGraph;
|
|
|
|
buildInputs = [
|
|
|
|
pkgs.perl pkgs.tetex pkgs.graphviz pkgs.ghostscript
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-06-27 10:44:27 +01:00
|
|
|
animateDot = dotGraph: nrFrames: pkgs.stdenv.mkDerivation {
|
|
|
|
name = "dot-frames";
|
|
|
|
builder = ./animatedot.sh;
|
|
|
|
inherit dotGraph nrFrames;
|
|
|
|
};
|
|
|
|
|
2007-03-12 18:06:31 +00:00
|
|
|
|
|
|
|
# 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);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-04-11 14:27:01 +01:00
|
|
|
}
|