about summary refs log tree commit diff
path: root/pkgs
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/misc/tex/nix/copy-includes.pl23
-rw-r--r--pkgs/misc/tex/nix/default.nix15
-rw-r--r--pkgs/misc/tex/nix/find-includes.pl25
-rw-r--r--pkgs/misc/tex/nix/run-latex.sh18
4 files changed, 55 insertions, 26 deletions
diff --git a/pkgs/misc/tex/nix/copy-includes.pl b/pkgs/misc/tex/nix/copy-includes.pl
new file mode 100644
index 000000000000..57ae2d4a33d2
--- /dev/null
+++ b/pkgs/misc/tex/nix/copy-includes.pl
@@ -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'";
+}
diff --git a/pkgs/misc/tex/nix/default.nix b/pkgs/misc/tex/nix/default.nix
index 09e2a87fce91..73ef5e523eb4 100644
--- a/pkgs/misc/tex/nix/default.nix
+++ b/pkgs/misc/tex/nix/default.nix
@@ -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
-    };     
+    };
     
 }
\ No newline at end of file
diff --git a/pkgs/misc/tex/nix/find-includes.pl b/pkgs/misc/tex/nix/find-includes.pl
index 0066972bb921..5be9259507d9 100644
--- a/pkgs/misc/tex/nix/find-includes.pl
+++ b/pkgs/misc/tex/nix/find-includes.pl
@@ -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
     }
diff --git a/pkgs/misc/tex/nix/run-latex.sh b/pkgs/misc/tex/nix/run-latex.sh
index be99eaffe256..72fc8234bd0c 100644
--- a/pkgs/misc/tex/nix/run-latex.sh
+++ b/pkgs/misc/tex/nix/run-latex.sh
@@ -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
\ No newline at end of file
+fi