2005-06-20 15:51:48 +02:00
|
|
|
pkgs:
|
|
|
|
|
|
|
|
rec {
|
|
|
|
|
2005-06-20 16:26:07 +02:00
|
|
|
|
2005-06-20 15:51:48 +02:00
|
|
|
runLaTeX =
|
|
|
|
{ rootFile
|
2007-03-12 18:55:08 +01:00
|
|
|
, generatePDF ? true # generate PDF, not DVI
|
|
|
|
, generatePS ? false # generate PS in addition to DVI
|
2005-06-21 00:43:35 +02:00
|
|
|
, extraFiles ? []
|
2005-11-28 15:19:46 +01:00
|
|
|
, compressBlanksInIndex ? true
|
2007-03-11 00:51:59 +01:00
|
|
|
, packages ? []
|
2007-03-12 18:55:08 +01:00
|
|
|
, searchRelativeTo ? dirOf (toString rootFile) # !!! duplication
|
2008-05-16 13:48:46 +02:00
|
|
|
, copySources ? false
|
2005-06-20 15:51:48 +02:00
|
|
|
}:
|
2007-03-12 18:55:08 +01:00
|
|
|
|
|
|
|
assert generatePDF -> !generatePS;
|
2005-06-20 15:51:48 +02:00
|
|
|
|
|
|
|
pkgs.stdenv.mkDerivation {
|
|
|
|
name = "doc";
|
2005-06-20 17:06:58 +02:00
|
|
|
|
2005-06-20 15:51:48 +02:00
|
|
|
builder = ./run-latex.sh;
|
2005-06-20 17:06:58 +02:00
|
|
|
copyIncludes = ./copy-includes.pl;
|
2005-06-20 15:51:48 +02:00
|
|
|
|
2007-03-12 18:55:08 +01:00
|
|
|
inherit rootFile generatePDF generatePS extraFiles
|
2008-05-16 13:48:46 +02:00
|
|
|
compressBlanksInIndex copySources;
|
2005-06-20 16:26:07 +02:00
|
|
|
|
2007-03-12 18:55:08 +01:00
|
|
|
includes = import (findLaTeXIncludes {inherit rootFile searchRelativeTo;});
|
2005-06-20 15:51:48 +02:00
|
|
|
|
2007-03-11 00:51:59 +01:00
|
|
|
buildInputs = [ pkgs.tetex pkgs.perl ] ++ packages;
|
2005-06-20 15:51:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-06-20 16:26:07 +02:00
|
|
|
findLaTeXIncludes =
|
|
|
|
{ rootFile
|
2007-03-12 18:55:08 +01:00
|
|
|
, searchRelativeTo ? dirOf (toString rootFile)
|
2005-06-20 16:26:07 +02:00
|
|
|
}:
|
|
|
|
|
2005-06-20 17:06:58 +02:00
|
|
|
pkgs.stdenv.mkDerivation {
|
2005-06-20 16:26:07 +02:00
|
|
|
name = "latex-includes";
|
2005-06-20 17:06:58 +02:00
|
|
|
|
2006-10-17 16:06:18 +02:00
|
|
|
realBuilder = pkgs.perl + "/bin/perl";
|
2005-06-20 16:26:07 +02:00
|
|
|
args = [ ./find-includes.pl ];
|
|
|
|
|
|
|
|
rootFile = toString rootFile; # !!! hacky
|
2005-06-20 17:20:37 +02:00
|
|
|
|
2007-03-12 18:55:08 +01:00
|
|
|
inherit searchRelativeTo;
|
|
|
|
|
2005-06-20 17:20:37 +02:00
|
|
|
# Forces rebuilds.
|
|
|
|
hack = __currentTime;
|
2005-06-20 17:06:58 +02:00
|
|
|
};
|
2005-06-21 00:43:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
dot2pdf =
|
|
|
|
{ dotGraph
|
|
|
|
}:
|
|
|
|
|
|
|
|
pkgs.stdenv.mkDerivation {
|
|
|
|
name = "pdf";
|
|
|
|
builder = ./dot2pdf.sh;
|
2008-07-03 16:27:19 +02:00
|
|
|
inherit dotGraph fontsConf;
|
2005-06-21 00:43:35 +02:00
|
|
|
buildInputs = [
|
2008-07-03 16:27:19 +02:00
|
|
|
pkgs.perl pkgs.tetex pkgs.graphviz
|
2005-06-21 00:43:35 +02:00
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2005-06-27 11:44:27 +02:00
|
|
|
|
2006-04-11 15:27:01 +02: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 11:44:27 +02:00
|
|
|
animateDot = dotGraph: nrFrames: pkgs.stdenv.mkDerivation {
|
|
|
|
name = "dot-frames";
|
|
|
|
builder = ./animatedot.sh;
|
|
|
|
inherit dotGraph nrFrames;
|
|
|
|
};
|
|
|
|
|
2007-03-12 19:06:31 +01: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;
|
2008-05-16 13:26:23 +02:00
|
|
|
buildCommand = ''
|
2007-03-12 19:06:31 +01:00
|
|
|
touch $out
|
2008-05-16 13:26:23 +02:00
|
|
|
echo '\documentclass{article}' >> $out
|
|
|
|
echo '\pagestyle{empty}' >> $out
|
|
|
|
if test -n "$preamble"; then cat $preamble >> $out; fi
|
|
|
|
echo '\begin{document}' >> $out
|
2007-03-12 19:06:31 +01:00
|
|
|
cat $body >> $out
|
2008-05-16 13:26:23 +02:00
|
|
|
echo '\end{document}' >> $out
|
|
|
|
'';
|
2007-03-12 19:06:31 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
# 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;
|
2008-05-16 13:26:23 +02:00
|
|
|
|
|
|
|
buildInputs = [pkgs.imagemagick pkgs.ghostscript];
|
2007-03-12 19:06:31 +01:00
|
|
|
|
2008-05-16 13:26:23 +02:00
|
|
|
buildCommand = ''
|
2007-03-12 19:06:31 +01:00
|
|
|
if test -d $postscript; then
|
|
|
|
input=$(ls $postscript/*.ps)
|
|
|
|
else
|
|
|
|
input=$(stripHash $postscript; echo $strippedName)
|
|
|
|
ln -s $postscript $input
|
|
|
|
fi
|
|
|
|
|
|
|
|
ensureDir $out
|
2008-05-16 13:26:23 +02:00
|
|
|
convert -units PixelsPerInch \
|
2008-05-20 13:57:40 +02:00
|
|
|
-density 600 \
|
2008-05-16 13:26:23 +02:00
|
|
|
-trim \
|
|
|
|
-matte \
|
|
|
|
-transparent '#ffffff' \
|
|
|
|
-type PaletteMatte \
|
|
|
|
+repage \
|
|
|
|
$input \
|
|
|
|
"$out/$(basename $input .ps).png"
|
|
|
|
''; # */
|
2007-03-12 19:06:31 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
# 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);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-05-16 13:26:23 +02:00
|
|
|
# Convert a piece of TeX code to a PDF.
|
|
|
|
simpleTeXToPDF =
|
|
|
|
{ preamble ? null
|
|
|
|
, body
|
|
|
|
, name ? baseNameOf (toString body)
|
|
|
|
, packages ? []
|
|
|
|
}:
|
|
|
|
|
|
|
|
runLaTeX {
|
|
|
|
rootFile = wrapSimpleTeX {
|
|
|
|
inherit body preamble;
|
|
|
|
};
|
|
|
|
inherit packages;
|
|
|
|
searchRelativeTo = dirOf (toString body);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 16:27:19 +02:00
|
|
|
# Some tools (like dot) need a fontconfig configuration file.
|
|
|
|
# This should be extended to allow the called to add additional
|
|
|
|
# fonts.
|
|
|
|
fontsConf = pkgs.makeFontsConf {
|
|
|
|
fontDirectories = [
|
|
|
|
"${pkgs.ghostscript}/share/ghostscript/fonts"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2006-04-11 15:27:01 +02:00
|
|
|
}
|