* Handle subdirectories (e.g., \input{foo/bar.tex}). We don't yet
handle relative paths to parent directories (../foo/bar.tex). This can be handled as was done in https://svn.cs.uu.nl:12443/repos/trace/nix/trunk/make/lib/compile-c.sh. The `copy-includes.pl' script is generic (not LaTeX specific), so it should eventually replace most of compile-c.sh and any future builders that have to set up a tree of symlinks to simulate the original directory hierarchy of the sources. svn path=/nixpkgs/trunk/; revision=3220
This commit is contained in:
parent
5b15f75a13
commit
6ce80304a5
23
pkgs/misc/tex/nix/copy-includes.pl
Normal file
23
pkgs/misc/tex/nix/copy-includes.pl
Normal file
|
@ -0,0 +1,23 @@
|
|||
use strict;
|
||||
use File::Basename;
|
||||
|
||||
sub createDirs;
|
||||
sub createDirs {
|
||||
my $path = shift;
|
||||
return unless $path =~ /^(.*)\/([^\/]*)$/;
|
||||
print "$1 BLA $2\n";
|
||||
return if -d $1;
|
||||
createDirs $1;
|
||||
mkdir $1 or die "cannot create directory `$1'";
|
||||
}
|
||||
|
||||
for (my $n = 0; $n < @ARGV; $n += 2) {
|
||||
my $fullPath = $ARGV[$n];
|
||||
my $relPath = $ARGV[$n + 1];
|
||||
|
||||
print "$fullPath <- $relPath\n";
|
||||
|
||||
createDirs $relPath;
|
||||
|
||||
symlink $fullPath, $relPath or die "cannot create symlink `$relPath'";
|
||||
}
|
|
@ -10,13 +10,15 @@ rec {
|
|||
|
||||
pkgs.stdenv.mkDerivation {
|
||||
name = "doc";
|
||||
|
||||
builder = ./run-latex.sh;
|
||||
copyIncludes = ./copy-includes.pl;
|
||||
|
||||
inherit rootFile generatePDF;
|
||||
|
||||
includes = import (findLaTeXIncludes {inherit rootFile;});
|
||||
|
||||
buildInputs = [ pkgs.tetex ];
|
||||
buildInputs = [ pkgs.tetex pkgs.perl ];
|
||||
};
|
||||
|
||||
|
||||
|
@ -24,16 +26,13 @@ rec {
|
|||
{ rootFile
|
||||
}:
|
||||
|
||||
derivation {
|
||||
inherit (pkgs) stdenv;
|
||||
|
||||
pkgs.stdenv.mkDerivation {
|
||||
name = "latex-includes";
|
||||
system = pkgs.stdenv.system;
|
||||
|
||||
builder = (pkgs.perl ~ /bin/perl);
|
||||
|
||||
realBuilder = pkgs.perl ~ "bin/perl";
|
||||
args = [ ./find-includes.pl ];
|
||||
|
||||
rootFile = toString rootFile; # !!! hacky
|
||||
};
|
||||
};
|
||||
|
||||
}
|
|
@ -24,27 +24,32 @@ while (scalar @workset > 0) {
|
|||
my $fn = pop @workset;
|
||||
next if (defined $doneset{$fn});
|
||||
|
||||
$doneset{$fn} = 1;
|
||||
|
||||
if (!open FILE, "< $fn") {
|
||||
print STDERR "(cannot open $fn, ignoring)\n";
|
||||
next;
|
||||
};
|
||||
|
||||
print OUT "$fn\n";
|
||||
$doneset{$fn} = 1;
|
||||
|
||||
|
||||
# Print out the full path *and* its relative path to $root.
|
||||
|
||||
die if substr($fn, 0, length $path) ne $path;
|
||||
my $relFN = substr($fn, (length $path) + 1);
|
||||
|
||||
print OUT "$fn \"$relFN\"\n";
|
||||
|
||||
|
||||
# Recursively find include in $fn.
|
||||
while (<FILE>) {
|
||||
if (/\\input\{(.*)\}/) {
|
||||
my $fn2 = $1;
|
||||
if (substr($fn2, 0, 1) ne "/") {
|
||||
$fn2 = $path . "/" . $fn2;
|
||||
}
|
||||
push @workset, $fn2;
|
||||
die "absolute path! $fn2" if substr($fn2, 0, 1) eq "/";
|
||||
push @workset, $path . "/" . $fn2;
|
||||
} elsif (/\\documentclass(\[.*\])?\{(.*)\}/) {
|
||||
my $fn2 = $2;
|
||||
if (substr($fn2, 0, 1) ne "/") {
|
||||
$fn2 = $path . "/" . $fn2;
|
||||
}
|
||||
push @workset, $fn2 . ".cls";
|
||||
die "absolute path! $fn2" if substr($fn2, 0, 1) eq "/";
|
||||
push @workset, $path . "/" . $fn2 . ".cls";
|
||||
}
|
||||
# !!! also support \usepackage
|
||||
}
|
||||
|
|
|
@ -2,13 +2,15 @@
|
|||
|
||||
ensureDir $out
|
||||
|
||||
for i in $includes; do
|
||||
if test -d $i; then
|
||||
cp $i/* .
|
||||
else
|
||||
cp $i $(stripHash $i; echo $strippedName)
|
||||
fi
|
||||
done
|
||||
perl $copyIncludes $includes
|
||||
|
||||
#for i in $includes; do
|
||||
# if test -d $i; then
|
||||
# cp $i/* .
|
||||
# else
|
||||
# cp $i $(stripHash $i; echo $strippedName)
|
||||
# fi
|
||||
#done
|
||||
|
||||
rootName=$(basename $(stripHash "$rootFile"; echo $strippedName))
|
||||
echo "root name is $rootName"
|
||||
|
@ -37,4 +39,4 @@ if test -n "$generatePDF"; then
|
|||
cp $rootNameBase.pdf $out
|
||||
else
|
||||
cp $rootNameBase.dvi $out
|
||||
fi
|
||||
fi
|
||||
|
|
Loading…
Reference in a new issue