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 ? []
|
2008-05-16 12:48:46 +01:00
|
|
|
, copySources ? false
|
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
|
2008-05-16 12:48:46 +01:00
|
|
|
compressBlanksInIndex copySources;
|
2005-06-20 15:26:07 +01:00
|
|
|
|
2009-07-17 16:10:01 +01:00
|
|
|
includes = map (x: [x.key (baseNameOf (toString x.key))])
|
|
|
|
(findLaTeXIncludes {inherit rootFile;});
|
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
|
|
|
};
|
|
|
|
|
2009-07-17 16:10:01 +01:00
|
|
|
|
|
|
|
# Returns the closure of the "dependencies" of a LaTeX source file.
|
|
|
|
# Dependencies are other LaTeX source files (e.g. included using
|
|
|
|
# \input{}), images (e.g. \includegraphics{}), bibliographies, and
|
|
|
|
# so on.
|
2005-06-20 15:26:07 +01:00
|
|
|
findLaTeXIncludes =
|
|
|
|
{ rootFile
|
|
|
|
}:
|
|
|
|
|
2009-07-17 16:10:01 +01:00
|
|
|
builtins.genericClosure {
|
|
|
|
startSet = [{key = rootFile;}];
|
|
|
|
|
|
|
|
operator =
|
|
|
|
{key, ...}:
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
# `find-includes.pl' returns the dependencies of the current
|
|
|
|
# source file (`key') as a list, e.g. [{type = "tex"; name =
|
|
|
|
# "introduction.tex";} {type = "img"; name = "example"}].
|
|
|
|
# The type denotes the kind of dependency, which determines
|
|
|
|
# what extensions we use to look for it.
|
|
|
|
deps = import (pkgs.runCommand "latex-includes"
|
2009-08-13 09:37:00 +01:00
|
|
|
{ src = key; }
|
2009-07-17 16:10:01 +01:00
|
|
|
"${pkgs.perl}/bin/perl ${./find-includes.pl}");
|
|
|
|
|
|
|
|
# Look for the dependencies of `key', trying various
|
|
|
|
# extensions determined by the type of each dependency.
|
|
|
|
# TODO: support a search path.
|
|
|
|
foundDeps = dep: xs:
|
|
|
|
let
|
|
|
|
exts =
|
|
|
|
if dep.type == "img" then [".pdf" ".png" ".ps" ".jpg"]
|
|
|
|
else if dep.type == "tex" then [".tex" ""]
|
|
|
|
else [""];
|
|
|
|
fn = pkgs.lib.findFirst (fn: builtins.pathExists fn) null
|
|
|
|
(map (ext: "${dirOf key}/${dep.name}${ext}") exts);
|
|
|
|
in if fn != null then [{key = fn;}] ++ xs
|
2009-08-13 09:37:00 +01:00
|
|
|
else xs;
|
2009-07-17 16:10:01 +01:00
|
|
|
|
|
|
|
in pkgs.lib.fold foundDeps [] deps;
|
2005-06-20 16:06:58 +01:00
|
|
|
};
|
2009-07-17 16:10:01 +01:00
|
|
|
|
2005-06-20 23:43:35 +01:00
|
|
|
|
2009-07-23 15:13:09 +01:00
|
|
|
findLhs2TeXIncludes =
|
|
|
|
{ rootFile
|
|
|
|
}:
|
|
|
|
|
|
|
|
builtins.genericClosure {
|
|
|
|
startSet = [{key = rootFile;}];
|
|
|
|
|
|
|
|
operator =
|
|
|
|
{key, ...}:
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
deps = import (pkgs.runCommand "lhs2tex-includes"
|
2009-08-13 09:37:00 +01:00
|
|
|
{ src = key; }
|
2009-07-23 15:13:09 +01:00
|
|
|
"${pkgs.stdenv.bash}/bin/bash ${./find-lhs2tex-includes.sh}");
|
|
|
|
|
2009-08-13 09:37:00 +01:00
|
|
|
in pkgs.lib.concatMap (x : if builtins.pathExists x then [{key = x;}] else [])
|
|
|
|
(map (x : "${dirOf key}/${x}") deps);
|
2009-07-23 15:13:09 +01:00
|
|
|
};
|
|
|
|
|
2005-06-20 23:43:35 +01:00
|
|
|
dot2pdf =
|
|
|
|
{ dotGraph
|
|
|
|
}:
|
|
|
|
|
|
|
|
pkgs.stdenv.mkDerivation {
|
|
|
|
name = "pdf";
|
|
|
|
builder = ./dot2pdf.sh;
|
2008-07-03 15:27:19 +01:00
|
|
|
inherit dotGraph fontsConf;
|
2005-06-20 23:43:35 +01:00
|
|
|
buildInputs = [
|
2008-07-03 15:27:19 +01:00
|
|
|
pkgs.perl pkgs.tetex pkgs.graphviz
|
2005-06-20 23:43:35 +01:00
|
|
|
];
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2009-07-23 15:13:09 +01:00
|
|
|
lhs2tex =
|
|
|
|
{ source, flags ? null } :
|
|
|
|
pkgs.stdenv.mkDerivation {
|
|
|
|
name = "tex";
|
|
|
|
builder = ./lhs2tex.sh;
|
|
|
|
inherit source flags;
|
|
|
|
buildInputs = [ pkgs.lhs2tex pkgs.perl ];
|
|
|
|
copyIncludes = ./copy-includes.pl;
|
|
|
|
includes = map (x: [x.key (baseNameOf (toString x.key))])
|
|
|
|
(findLhs2TeXIncludes {rootFile = source;});
|
|
|
|
};
|
2006-04-11 14:27:01 +01:00
|
|
|
|
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;
|
2008-05-16 12:26:23 +01:00
|
|
|
buildCommand = ''
|
2007-03-12 18:06:31 +00:00
|
|
|
touch $out
|
2008-05-16 12:26:23 +01: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 18:06:31 +00:00
|
|
|
cat $body >> $out
|
2008-05-16 12:26:23 +01:00
|
|
|
echo '\end{document}' >> $out
|
|
|
|
'';
|
2007-03-12 18:06:31 +00: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 12:26:23 +01:00
|
|
|
|
|
|
|
buildInputs = [pkgs.imagemagick pkgs.ghostscript];
|
2007-03-12 18:06:31 +00:00
|
|
|
|
2008-05-16 12:26:23 +01:00
|
|
|
buildCommand = ''
|
2007-03-12 18:06:31 +00: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 12:26:23 +01:00
|
|
|
convert -units PixelsPerInch \
|
2008-05-20 12:57:40 +01:00
|
|
|
-density 600 \
|
2008-05-16 12:26:23 +01:00
|
|
|
-trim \
|
|
|
|
-matte \
|
|
|
|
-transparent '#ffffff' \
|
|
|
|
-type PaletteMatte \
|
|
|
|
+repage \
|
|
|
|
$input \
|
|
|
|
"$out/$(basename $input .ps).png"
|
|
|
|
''; # */
|
2007-03-12 18:06:31 +00: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;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-05-16 12:26:23 +01: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;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:27:19 +01: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 14:27:01 +01:00
|
|
|
}
|