summary refs log tree commit diff
path: root/pkgs/misc/tex
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2005-06-20 14:25:50 +0000
committerEelco Dolstra <eelco.dolstra@logicblox.com>2005-06-20 14:25:50 +0000
commit6b35cefbf8568c48e77b603fffdb23fb7787a62d (patch)
tree0a63f4c94a486c4c1300fc3b1db8c0ae97e09324 /pkgs/misc/tex
parent6fcee91442b3dc39cf12757fd693fb176118c1cb (diff)
downloadnixlib-6b35cefbf8568c48e77b603fffdb23fb7787a62d.tar
nixlib-6b35cefbf8568c48e77b603fffdb23fb7787a62d.tar.gz
nixlib-6b35cefbf8568c48e77b603fffdb23fb7787a62d.tar.bz2
nixlib-6b35cefbf8568c48e77b603fffdb23fb7787a62d.tar.lz
nixlib-6b35cefbf8568c48e77b603fffdb23fb7787a62d.tar.xz
nixlib-6b35cefbf8568c48e77b603fffdb23fb7787a62d.tar.zst
nixlib-6b35cefbf8568c48e77b603fffdb23fb7787a62d.zip
* Find LaTeX document dependencies automatically by scanning for
  \input and \documentclass.  Copied from Maak
  (https://svn.cs.uu.nl:12443/repos/pkgs/texwrappers/trunk/chase-latex-inputs.pl).

  TODO: support \bibliography, \usepackage, \includegraphics, etc.

svn path=/nixpkgs/trunk/; revision=3217
Diffstat (limited to 'pkgs/misc/tex')
-rw-r--r--pkgs/misc/tex/nix/find-includes.pl56
1 files changed, 56 insertions, 0 deletions
diff --git a/pkgs/misc/tex/nix/find-includes.pl b/pkgs/misc/tex/nix/find-includes.pl
new file mode 100644
index 000000000000..0066972bb921
--- /dev/null
+++ b/pkgs/misc/tex/nix/find-includes.pl
@@ -0,0 +1,56 @@
+use strict;
+use File::Basename;
+
+my $root = $ENV{"rootFile"};
+my $out = $ENV{"out"};
+
+open OUT, ">$out" or die;
+print OUT "[\n";
+
+# We search for files relative to the root file.  TODO: search
+# relative to the paths in $TEXINPUTS.
+die unless substr($root, 0, 1) eq "/";
+my ($x, $path, $y) = fileparse($root);
+
+$path =~ s/\/$//;
+
+my @workset = ();
+my %doneset = ();
+
+push @workset, $root;
+
+while (scalar @workset > 0) {
+
+    my $fn = pop @workset;
+    next if (defined $doneset{$fn});
+
+    if (!open FILE, "< $fn") {
+	print STDERR "(cannot open $fn, ignoring)\n";
+	next;
+    };
+    
+    print OUT "$fn\n";
+    $doneset{$fn} = 1;
+
+    while (<FILE>) {
+	if (/\\input\{(.*)\}/) {
+	    my $fn2 = $1;
+            if (substr($fn2, 0, 1) ne "/") {
+		$fn2 = $path . "/" . $fn2;
+	    }
+	    push @workset, $fn2;
+	} elsif (/\\documentclass(\[.*\])?\{(.*)\}/) {
+	    my $fn2 = $2;
+            if (substr($fn2, 0, 1) ne "/") {
+		$fn2 = $path . "/" . $fn2;
+	    }
+	    push @workset, $fn2 . ".cls";
+	}
+        # !!! also support \usepackage
+    }
+    
+    close FILE;
+}
+
+print OUT "]\n";
+close OUT;