summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2012-07-13 17:54:13 +0000
committerKarl Berry <karl@freefriends.org>2012-07-13 17:54:13 +0000
commit69dcd5b1b7ebc2cb506057a8546d760aef67b74d (patch)
tree3d6a7c2f84f3bc6075a86fae52f2fc31f70f661a
parent5b85326ce9004d1daee0a1cf3c2f1e0a0f8df641 (diff)
new script latexpand (8jul12)
git-svn-id: svn://tug.org/texlive/trunk@27025 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r--Build/source/texk/texlive/linked_scripts/Makefile.am1
-rw-r--r--Build/source/texk/texlive/linked_scripts/Makefile.in1
-rwxr-xr-xBuild/source/texk/texlive/linked_scripts/latexpand/latexpand243
l---------Master/bin/alpha-linux/latexpand1
l---------Master/bin/amd64-freebsd/latexpand1
l---------Master/bin/amd64-kfreebsd/latexpand1
l---------Master/bin/armel-linux/latexpand1
l---------Master/bin/i386-cygwin/latexpand1
l---------Master/bin/i386-freebsd/latexpand1
l---------Master/bin/i386-kfreebsd/latexpand1
l---------Master/bin/i386-linux/latexpand1
l---------Master/bin/i386-solaris/latexpand1
l---------Master/bin/mipsel-linux/latexpand1
l---------Master/bin/powerpc-aix/latexpand1
l---------Master/bin/powerpc-linux/latexpand1
l---------Master/bin/sparc-solaris/latexpand1
l---------Master/bin/universal-darwin/latexpand1
-rwxr-xr-xMaster/bin/win32/latexpand.exebin0 -> 1536 bytes
l---------Master/bin/x86_64-darwin/latexpand1
l---------Master/bin/x86_64-linux/latexpand1
l---------Master/bin/x86_64-solaris/latexpand1
-rw-r--r--Master/texmf-dist/doc/support/latexpand/Makefile10
-rw-r--r--Master/texmf-dist/doc/support/latexpand/README28
-rw-r--r--Master/texmf-dist/doc/support/latexpand/tests/README3
-rw-r--r--Master/texmf-dist/doc/support/latexpand/tests/foo.tex3
-rw-r--r--Master/texmf-dist/doc/support/latexpand/tests/includer.tex21
-rw-r--r--Master/texmf-dist/doc/support/latexpand/tests/just-comment.tex1
-rw-r--r--Master/texmf-dist/doc/support/latexpand/tests/my-package.sty2
-rw-r--r--Master/texmf-dist/doc/support/latexpand/tests/no-eol.tex1
-rw-r--r--Master/texmf-dist/doc/support/latexpand/tests/package-user.tex8
-rw-r--r--Master/texmf-dist/doc/support/latexpand/version.txt1
-rwxr-xr-xMaster/texmf-dist/scripts/latexpand/latexpand243
-rwxr-xr-xMaster/tlpkg/bin/tlpkg-ctan-check2
-rwxr-xr-xMaster/tlpkg/libexec/ctan2tds1
-rw-r--r--Master/tlpkg/tlpsrc/collection-binextra.tlpsrc1
-rw-r--r--Master/tlpkg/tlpsrc/latexpand.tlpsrc1
36 files changed, 587 insertions, 1 deletions
diff --git a/Build/source/texk/texlive/linked_scripts/Makefile.am b/Build/source/texk/texlive/linked_scripts/Makefile.am
index 7d0a66ce42f..3e302cf7c4b 100644
--- a/Build/source/texk/texlive/linked_scripts/Makefile.am
+++ b/Build/source/texk/texlive/linked_scripts/Makefile.am
@@ -104,6 +104,7 @@ texmf_dist_other_scripts = \
latexdiff/latexdiff-vc.pl \
latexdiff/latexrevise.pl \
latexmk/latexmk.pl \
+ latexpand/latexpand \
luaotfload/mkluatexfontdb.lua \
match_parens/match_parens \
mathspic/mathspic.pl \
diff --git a/Build/source/texk/texlive/linked_scripts/Makefile.in b/Build/source/texk/texlive/linked_scripts/Makefile.in
index 0dfd057dd47..5903be9933c 100644
--- a/Build/source/texk/texlive/linked_scripts/Makefile.in
+++ b/Build/source/texk/texlive/linked_scripts/Makefile.in
@@ -285,6 +285,7 @@ texmf_dist_other_scripts = \
latexdiff/latexdiff-vc.pl \
latexdiff/latexrevise.pl \
latexmk/latexmk.pl \
+ latexpand/latexpand \
luaotfload/mkluatexfontdb.lua \
match_parens/match_parens \
mathspic/mathspic.pl \
diff --git a/Build/source/texk/texlive/linked_scripts/latexpand/latexpand b/Build/source/texk/texlive/linked_scripts/latexpand/latexpand
new file mode 100755
index 00000000000..f024f1c1a1d
--- /dev/null
+++ b/Build/source/texk/texlive/linked_scripts/latexpand/latexpand
@@ -0,0 +1,243 @@
+#!/usr/bin/perl
+# Inspired by latexpand by D. Musliner, University of Michigan
+# 2012 Matthieu Moy <Matthieu.Moy@imag.fr>
+# BSD License
+
+use strict;
+use Cwd;
+use Getopt::Long;
+use Pod::Usage;
+use IO::Handle;
+
+my $TEXINPUTS = $ENV{'TEXINPUTS'};
+if (!$TEXINPUTS) { $TEXINPUTS = getcwd(); }
+
+my $verbose;
+my $keep_comments;
+my $keep_includes;
+my $empty_comments;
+my $help;
+my $long_help;
+my $output;
+my $explain;
+my $show_graphics;
+my $graphics_extensions = ":.pdf:.png:.jpg:.eps";
+my $expand_usepackage;
+my $expand_bbl;
+
+GetOptions (
+ 'h' => \$help,
+ 'help' => \$long_help,
+ 'verbose|v' => \$verbose,
+ 'keep-comments' => \$keep_comments,
+ 'keep-includes' => \$keep_includes,
+ 'empty-comments' => \$empty_comments,
+ 'output|o=s' => \$output,
+ 'explain' => \$explain,
+ 'show-graphics' => \$show_graphics,
+ 'graphics-extensions' => \$graphics_extensions,
+ 'expand-usepackage' => \$expand_usepackage,
+ 'expand-bbl=s' => \$expand_bbl,
+) or pod2usage(2);
+pod2usage(1) if $help;
+pod2usage(-exitstatus => 0, -verbose => 2) if $long_help;
+
+my $comment_newline;
+
+my $nl = "";
+if ($empty_comments) {
+ $nl = "%\n";
+}
+
+if ($output && $output ne "-") {
+ open OUTPUT, '>', "$output" or die $!;
+ STDOUT->fdopen(\*OUTPUT, 'w') or die $!;
+}
+
+sub say
+{
+ if ($verbose) {
+ print STDERR "$_[0]";
+ }
+}
+
+foreach my $file (@ARGV)
+{
+ say "processing $file\n";
+ process_file($file, " ");
+}
+
+sub process_file
+{
+ my $file = shift;
+ my $prefix = (shift || "");
+ local(*FILE);
+ open(FILE, $file) or die "could not open input file '$file'\n";
+ while (<FILE>) {
+ process_line($_, $prefix);
+ if (/^%.*[^\n]\z/ || /[^\\]%.*[^\n]\z/) {
+ # file ends with a comment not ending with a newline
+ print "\n";
+ }
+ }
+ close(FILE);
+}
+
+sub process_line
+{
+ my ($_, $prefix) = @_;
+ unless ($keep_comments) {
+ if ($empty_comments) {
+ s/^%.*$/%/;
+ s/([^\\])%.*$/$1%/;
+ } else {
+ s/^%.*\n//;
+ s/([^\\])%.*\n/$1/;
+ }
+ }
+
+ unless ($keep_includes) {
+ if (my ($before, $ignored, $full_filename, $after)
+ = /^(([^%]|[^\\]%)*)\\include[{\s]+(.*?)[\s}](.*)$/) {
+ $full_filename = find_tex_file($full_filename . ".tex");
+ say $prefix . "Found include for file: $full_filename\n";
+ print $before . $nl;
+ print '\clearpage{}' . $nl;
+ print '\makeatletter{}' . $nl;
+ print "% start include $full_filename\n" if ($explain);
+ process_file($full_filename, $prefix . " ");
+ print "% end include $full_filename\n" if ($explain);
+ print '\clearpage{}' . $nl;
+ print $nl . $after . "\n";
+ $_ = "";
+ } elsif (my ($before, $ignored, $full_filename, $after)
+ = /^(([^%]|[^\\]%)*)\\input[{\s]+(.*?)[\s}](.*)$/) {
+ $full_filename .= ".tex" unless $full_filename =~ m/\./;
+ $full_filename = find_tex_file($full_filename);
+ say $prefix . "Found input for file: $full_filename\n";
+ print $before . $nl;
+ print '\makeatletter{}' . $nl;
+ print "% start input $full_filename\n" if ($explain);
+ process_file($full_filename, $prefix . " ");
+ print "% end input $full_filename\n" if ($explain);
+ # LaTeX produces this space, so let's do it also
+ print " " . $nl . $after . "\n";
+ $_ = "";
+ }
+ }
+ if ($expand_usepackage) {
+ # Don't bother with before and after text, we just require the
+ # usepackage to be alone on its line.
+ if (my ($package_name) = /^\s*\\usepackage{([^}]*)}\s*$/) {
+ my $full = find_file($package_name . ".sty", $TEXINPUTS);
+ if ($full) {
+ say $prefix . "Found package file: $full\n";
+ process_file($full, $prefix . " ");
+ $_ = "";
+ } else {
+ say $prefix . "Not including external package $package_name\n";
+ }
+ }
+ }
+ if ($expand_bbl) {
+ if (my ($before, $bib_name, $after)
+ = /^(.*)\\bibliography{([^}]*)}(.*)$/) {
+ # The BBL file is not necessarily $bib_name.
+ # Take it from the command-line.
+ print $before . $nl;
+ say $prefix . "Expanding BBL file: $expand_bbl\n";
+ process_file($expand_bbl, $prefix . " ");
+ print " " . $nl . $after . "\n";
+ $_ = "";
+ }
+ }
+ if ($show_graphics) {
+ if (/\\includegraphics{([^}]*)}/) {
+ my $full = find_tex_file($1, $graphics_extensions);
+ say $prefix . "needs graphics file: ";
+ print STDERR "$full\n";
+ }
+ }
+ print;
+}
+
+# search $1 in $TEXINPUTS, with possible extensions in $2
+sub find_tex_file
+{
+ my $file = shift;
+ my $extensions = (shift || ":");
+ foreach my $ext (split(':', $extensions, -1)) {
+ my $full = find_file($file . $ext, $TEXINPUTS);
+ if ($full) {
+ return $full;
+ }
+ }
+ die "ERROR: Could not find file [$file]\n";
+}
+
+sub find_file
+{
+ my ($file, $path) = @_;
+ if (File::Spec->file_name_is_absolute($file)) {
+ if (-e "$file") {
+ return $file;
+ } else {
+ return;
+ }
+ }
+ foreach my $dir (split(':', $path)) {
+ if (-e "$dir/$file") {
+ return("$dir/$file");
+ }
+ }
+ return;
+}
+
+
+__END__
+
+=head1 NAME
+
+latexpand - Flatten LaTeX file by expanding \include and \input, remove comments
+
+=head1 SYNOPSIS
+
+latexpand [options] FILE...
+
+ Options:
+ --verbose show what's going on
+ --keep-comments don't strip comments
+ --empty-comments keep empty comments (i.e. % at end of lines) for clarity
+ --keep-includes don't expand \input and \include directives
+ --expand-usepackage
+ Expand \usepackage{...} directives if the
+ corresponding .sty file is found in
+ $TEXINPUTS
+ --help this help message
+ --output <file>, -o <file>
+ generate output in <file>
+ --explain generate explanatory comments in output
+ --show-graphics show included graphics
+ --graphics_extensions
+ colon-separated list of possible graphics extensions
+ (used by --show-graphics to find the actual graphics files)
+
+=head1 USES
+
+The most common use of latexpand is to simplify distribution of source
+LaTeX files, typically to satisfy the requirement of editors and
+archival sites (springer, arXiv.org, ...) who force the authors to
+submit sources. One does not necessarily want to submit sources with
+comments, and uploading a document made of several files including
+each other is a bit painful. By default, latexpand answers both
+problems by outputing a single LaTeX file that contain no comment.
+
+=head1 GETTING LATEXPAND
+
+The latest version of latexpand is available here:
+
+ https://gitorious.org/latexpand
+
+=head1 BUGS
+
+Please, report bugs to Matthieu Moy <Matthieu.Moy@imag.fr>.
diff --git a/Master/bin/alpha-linux/latexpand b/Master/bin/alpha-linux/latexpand
new file mode 120000
index 00000000000..1a0b6d2abaa
--- /dev/null
+++ b/Master/bin/alpha-linux/latexpand
@@ -0,0 +1 @@
+../../texmf-dist/scripts/latexpand/latexpand \ No newline at end of file
diff --git a/Master/bin/amd64-freebsd/latexpand b/Master/bin/amd64-freebsd/latexpand
new file mode 120000
index 00000000000..1a0b6d2abaa
--- /dev/null
+++ b/Master/bin/amd64-freebsd/latexpand
@@ -0,0 +1 @@
+../../texmf-dist/scripts/latexpand/latexpand \ No newline at end of file
diff --git a/Master/bin/amd64-kfreebsd/latexpand b/Master/bin/amd64-kfreebsd/latexpand
new file mode 120000
index 00000000000..1a0b6d2abaa
--- /dev/null
+++ b/Master/bin/amd64-kfreebsd/latexpand
@@ -0,0 +1 @@
+../../texmf-dist/scripts/latexpand/latexpand \ No newline at end of file
diff --git a/Master/bin/armel-linux/latexpand b/Master/bin/armel-linux/latexpand
new file mode 120000
index 00000000000..1a0b6d2abaa
--- /dev/null
+++ b/Master/bin/armel-linux/latexpand
@@ -0,0 +1 @@
+../../texmf-dist/scripts/latexpand/latexpand \ No newline at end of file
diff --git a/Master/bin/i386-cygwin/latexpand b/Master/bin/i386-cygwin/latexpand
new file mode 120000
index 00000000000..1a0b6d2abaa
--- /dev/null
+++ b/Master/bin/i386-cygwin/latexpand
@@ -0,0 +1 @@
+../../texmf-dist/scripts/latexpand/latexpand \ No newline at end of file
diff --git a/Master/bin/i386-freebsd/latexpand b/Master/bin/i386-freebsd/latexpand
new file mode 120000
index 00000000000..1a0b6d2abaa
--- /dev/null
+++ b/Master/bin/i386-freebsd/latexpand
@@ -0,0 +1 @@
+../../texmf-dist/scripts/latexpand/latexpand \ No newline at end of file
diff --git a/Master/bin/i386-kfreebsd/latexpand b/Master/bin/i386-kfreebsd/latexpand
new file mode 120000
index 00000000000..1a0b6d2abaa
--- /dev/null
+++ b/Master/bin/i386-kfreebsd/latexpand
@@ -0,0 +1 @@
+../../texmf-dist/scripts/latexpand/latexpand \ No newline at end of file
diff --git a/Master/bin/i386-linux/latexpand b/Master/bin/i386-linux/latexpand
new file mode 120000
index 00000000000..1a0b6d2abaa
--- /dev/null
+++ b/Master/bin/i386-linux/latexpand
@@ -0,0 +1 @@
+../../texmf-dist/scripts/latexpand/latexpand \ No newline at end of file
diff --git a/Master/bin/i386-solaris/latexpand b/Master/bin/i386-solaris/latexpand
new file mode 120000
index 00000000000..1a0b6d2abaa
--- /dev/null
+++ b/Master/bin/i386-solaris/latexpand
@@ -0,0 +1 @@
+../../texmf-dist/scripts/latexpand/latexpand \ No newline at end of file
diff --git a/Master/bin/mipsel-linux/latexpand b/Master/bin/mipsel-linux/latexpand
new file mode 120000
index 00000000000..1a0b6d2abaa
--- /dev/null
+++ b/Master/bin/mipsel-linux/latexpand
@@ -0,0 +1 @@
+../../texmf-dist/scripts/latexpand/latexpand \ No newline at end of file
diff --git a/Master/bin/powerpc-aix/latexpand b/Master/bin/powerpc-aix/latexpand
new file mode 120000
index 00000000000..1a0b6d2abaa
--- /dev/null
+++ b/Master/bin/powerpc-aix/latexpand
@@ -0,0 +1 @@
+../../texmf-dist/scripts/latexpand/latexpand \ No newline at end of file
diff --git a/Master/bin/powerpc-linux/latexpand b/Master/bin/powerpc-linux/latexpand
new file mode 120000
index 00000000000..1a0b6d2abaa
--- /dev/null
+++ b/Master/bin/powerpc-linux/latexpand
@@ -0,0 +1 @@
+../../texmf-dist/scripts/latexpand/latexpand \ No newline at end of file
diff --git a/Master/bin/sparc-solaris/latexpand b/Master/bin/sparc-solaris/latexpand
new file mode 120000
index 00000000000..1a0b6d2abaa
--- /dev/null
+++ b/Master/bin/sparc-solaris/latexpand
@@ -0,0 +1 @@
+../../texmf-dist/scripts/latexpand/latexpand \ No newline at end of file
diff --git a/Master/bin/universal-darwin/latexpand b/Master/bin/universal-darwin/latexpand
new file mode 120000
index 00000000000..1a0b6d2abaa
--- /dev/null
+++ b/Master/bin/universal-darwin/latexpand
@@ -0,0 +1 @@
+../../texmf-dist/scripts/latexpand/latexpand \ No newline at end of file
diff --git a/Master/bin/win32/latexpand.exe b/Master/bin/win32/latexpand.exe
new file mode 100755
index 00000000000..5777d90a17a
--- /dev/null
+++ b/Master/bin/win32/latexpand.exe
Binary files differ
diff --git a/Master/bin/x86_64-darwin/latexpand b/Master/bin/x86_64-darwin/latexpand
new file mode 120000
index 00000000000..1a0b6d2abaa
--- /dev/null
+++ b/Master/bin/x86_64-darwin/latexpand
@@ -0,0 +1 @@
+../../texmf-dist/scripts/latexpand/latexpand \ No newline at end of file
diff --git a/Master/bin/x86_64-linux/latexpand b/Master/bin/x86_64-linux/latexpand
new file mode 120000
index 00000000000..1a0b6d2abaa
--- /dev/null
+++ b/Master/bin/x86_64-linux/latexpand
@@ -0,0 +1 @@
+../../texmf-dist/scripts/latexpand/latexpand \ No newline at end of file
diff --git a/Master/bin/x86_64-solaris/latexpand b/Master/bin/x86_64-solaris/latexpand
new file mode 120000
index 00000000000..1a0b6d2abaa
--- /dev/null
+++ b/Master/bin/x86_64-solaris/latexpand
@@ -0,0 +1 @@
+../../texmf-dist/scripts/latexpand/latexpand \ No newline at end of file
diff --git a/Master/texmf-dist/doc/support/latexpand/Makefile b/Master/texmf-dist/doc/support/latexpand/Makefile
new file mode 100644
index 00000000000..2f8651ddd06
--- /dev/null
+++ b/Master/texmf-dist/doc/support/latexpand/Makefile
@@ -0,0 +1,10 @@
+all: latexpand.zip
+
+README:
+ ./latexpand --help > README
+
+.PHONY: latexpand.zip
+latexpand.zip: README
+ -$(RM) $@
+ @echo "latexpand version $$(git rev-parse HEAD)" > version.txt
+ zip $@ README version.txt $$(git ls-files)
diff --git a/Master/texmf-dist/doc/support/latexpand/README b/Master/texmf-dist/doc/support/latexpand/README
new file mode 100644
index 00000000000..332b9854a8d
--- /dev/null
+++ b/Master/texmf-dist/doc/support/latexpand/README
@@ -0,0 +1,28 @@
+LATEXPAND(1) User Contributed Perl Documentation LATEXPAND(1)
+
+
+
+NNAAMMEE
+ latexpand - Flatten LaTeX file by expanding \include and \input
+ directives
+
+SSYYNNOOPPSSIISS
+ latexpand [options] FILE...
+
+ Options:
+ --verbose show what's going on
+ --keep-comments don't strip comments
+ --empty-comments keep empty comments (i.e. % at end of lines) for clarity
+ --keep-includes don't expand \input and \include directives
+ --help this help message
+ --output <file>, -o <file>
+ generate output in <file>
+ --explain generate explanatory comments in output
+ --show-graphics show included graphics
+ --graphics_extensions
+ colon-separated list of possible graphics extensions
+ (used by --show-graphics to find the actual graphics files)
+
+
+
+perl v5.10.1 2012-07-04 LATEXPAND(1)
diff --git a/Master/texmf-dist/doc/support/latexpand/tests/README b/Master/texmf-dist/doc/support/latexpand/tests/README
new file mode 100644
index 00000000000..b43baccb369
--- /dev/null
+++ b/Master/texmf-dist/doc/support/latexpand/tests/README
@@ -0,0 +1,3 @@
+Set of files to test latexpand.
+
+Tests are currently not automated :-(.
diff --git a/Master/texmf-dist/doc/support/latexpand/tests/foo.tex b/Master/texmf-dist/doc/support/latexpand/tests/foo.tex
new file mode 100644
index 00000000000..e1bf33402dc
--- /dev/null
+++ b/Master/texmf-dist/doc/support/latexpand/tests/foo.tex
@@ -0,0 +1,3 @@
+foo content
+\def\foo@bar{foo bar}
+\foo@bar{}
diff --git a/Master/texmf-dist/doc/support/latexpand/tests/includer.tex b/Master/texmf-dist/doc/support/latexpand/tests/includer.tex
new file mode 100644
index 00000000000..29c60aa6bd9
--- /dev/null
+++ b/Master/texmf-dist/doc/support/latexpand/tests/includer.tex
@@ -0,0 +1,21 @@
+\documentclass{article}
+
+\begin{document}
+beforeinput\input{foo}afterinput
+
+beforeinput.tex\input{foo.tex}afterinput.tex
+
+before inclusion of just-comment\input just-comment.tex after inclusion of just-comment
+
+before inclusion of no-eol\input no-eol after inclusion of no-eol.
+
+before inclusion of no-eol\input{no-eol}after inclusion of no-eol (braces).
+
+beforeinclude\include{foo}afterinclude
+
+\end{document}
+
+%%% Local Variables:
+%%% mode: latex
+%%% TeX-master: t
+%%% End:
diff --git a/Master/texmf-dist/doc/support/latexpand/tests/just-comment.tex b/Master/texmf-dist/doc/support/latexpand/tests/just-comment.tex
new file mode 100644
index 00000000000..743ee4e4472
--- /dev/null
+++ b/Master/texmf-dist/doc/support/latexpand/tests/just-comment.tex
@@ -0,0 +1 @@
+%just comment (no EOL) \ No newline at end of file
diff --git a/Master/texmf-dist/doc/support/latexpand/tests/my-package.sty b/Master/texmf-dist/doc/support/latexpand/tests/my-package.sty
new file mode 100644
index 00000000000..ab135ab069f
--- /dev/null
+++ b/Master/texmf-dist/doc/support/latexpand/tests/my-package.sty
@@ -0,0 +1,2 @@
+% My package content
+\def\foo{bar}
diff --git a/Master/texmf-dist/doc/support/latexpand/tests/no-eol.tex b/Master/texmf-dist/doc/support/latexpand/tests/no-eol.tex
new file mode 100644
index 00000000000..5910948883b
--- /dev/null
+++ b/Master/texmf-dist/doc/support/latexpand/tests/no-eol.tex
@@ -0,0 +1 @@
+text without EOL \ No newline at end of file
diff --git a/Master/texmf-dist/doc/support/latexpand/tests/package-user.tex b/Master/texmf-dist/doc/support/latexpand/tests/package-user.tex
new file mode 100644
index 00000000000..87df974b679
--- /dev/null
+++ b/Master/texmf-dist/doc/support/latexpand/tests/package-user.tex
@@ -0,0 +1,8 @@
+\documentclass{article}
+
+\usepackage{lmodern}
+\usepackage{my-package}
+
+\begin{document}
+
+\end{document}
diff --git a/Master/texmf-dist/doc/support/latexpand/version.txt b/Master/texmf-dist/doc/support/latexpand/version.txt
new file mode 100644
index 00000000000..8473dc583e0
--- /dev/null
+++ b/Master/texmf-dist/doc/support/latexpand/version.txt
@@ -0,0 +1 @@
+latexpand version a4a6bbc8086e31d95c9fb45faa85c40e12c77f23
diff --git a/Master/texmf-dist/scripts/latexpand/latexpand b/Master/texmf-dist/scripts/latexpand/latexpand
new file mode 100755
index 00000000000..f024f1c1a1d
--- /dev/null
+++ b/Master/texmf-dist/scripts/latexpand/latexpand
@@ -0,0 +1,243 @@
+#!/usr/bin/perl
+# Inspired by latexpand by D. Musliner, University of Michigan
+# 2012 Matthieu Moy <Matthieu.Moy@imag.fr>
+# BSD License
+
+use strict;
+use Cwd;
+use Getopt::Long;
+use Pod::Usage;
+use IO::Handle;
+
+my $TEXINPUTS = $ENV{'TEXINPUTS'};
+if (!$TEXINPUTS) { $TEXINPUTS = getcwd(); }
+
+my $verbose;
+my $keep_comments;
+my $keep_includes;
+my $empty_comments;
+my $help;
+my $long_help;
+my $output;
+my $explain;
+my $show_graphics;
+my $graphics_extensions = ":.pdf:.png:.jpg:.eps";
+my $expand_usepackage;
+my $expand_bbl;
+
+GetOptions (
+ 'h' => \$help,
+ 'help' => \$long_help,
+ 'verbose|v' => \$verbose,
+ 'keep-comments' => \$keep_comments,
+ 'keep-includes' => \$keep_includes,
+ 'empty-comments' => \$empty_comments,
+ 'output|o=s' => \$output,
+ 'explain' => \$explain,
+ 'show-graphics' => \$show_graphics,
+ 'graphics-extensions' => \$graphics_extensions,
+ 'expand-usepackage' => \$expand_usepackage,
+ 'expand-bbl=s' => \$expand_bbl,
+) or pod2usage(2);
+pod2usage(1) if $help;
+pod2usage(-exitstatus => 0, -verbose => 2) if $long_help;
+
+my $comment_newline;
+
+my $nl = "";
+if ($empty_comments) {
+ $nl = "%\n";
+}
+
+if ($output && $output ne "-") {
+ open OUTPUT, '>', "$output" or die $!;
+ STDOUT->fdopen(\*OUTPUT, 'w') or die $!;
+}
+
+sub say
+{
+ if ($verbose) {
+ print STDERR "$_[0]";
+ }
+}
+
+foreach my $file (@ARGV)
+{
+ say "processing $file\n";
+ process_file($file, " ");
+}
+
+sub process_file
+{
+ my $file = shift;
+ my $prefix = (shift || "");
+ local(*FILE);
+ open(FILE, $file) or die "could not open input file '$file'\n";
+ while (<FILE>) {
+ process_line($_, $prefix);
+ if (/^%.*[^\n]\z/ || /[^\\]%.*[^\n]\z/) {
+ # file ends with a comment not ending with a newline
+ print "\n";
+ }
+ }
+ close(FILE);
+}
+
+sub process_line
+{
+ my ($_, $prefix) = @_;
+ unless ($keep_comments) {
+ if ($empty_comments) {
+ s/^%.*$/%/;
+ s/([^\\])%.*$/$1%/;
+ } else {
+ s/^%.*\n//;
+ s/([^\\])%.*\n/$1/;
+ }
+ }
+
+ unless ($keep_includes) {
+ if (my ($before, $ignored, $full_filename, $after)
+ = /^(([^%]|[^\\]%)*)\\include[{\s]+(.*?)[\s}](.*)$/) {
+ $full_filename = find_tex_file($full_filename . ".tex");
+ say $prefix . "Found include for file: $full_filename\n";
+ print $before . $nl;
+ print '\clearpage{}' . $nl;
+ print '\makeatletter{}' . $nl;
+ print "% start include $full_filename\n" if ($explain);
+ process_file($full_filename, $prefix . " ");
+ print "% end include $full_filename\n" if ($explain);
+ print '\clearpage{}' . $nl;
+ print $nl . $after . "\n";
+ $_ = "";
+ } elsif (my ($before, $ignored, $full_filename, $after)
+ = /^(([^%]|[^\\]%)*)\\input[{\s]+(.*?)[\s}](.*)$/) {
+ $full_filename .= ".tex" unless $full_filename =~ m/\./;
+ $full_filename = find_tex_file($full_filename);
+ say $prefix . "Found input for file: $full_filename\n";
+ print $before . $nl;
+ print '\makeatletter{}' . $nl;
+ print "% start input $full_filename\n" if ($explain);
+ process_file($full_filename, $prefix . " ");
+ print "% end input $full_filename\n" if ($explain);
+ # LaTeX produces this space, so let's do it also
+ print " " . $nl . $after . "\n";
+ $_ = "";
+ }
+ }
+ if ($expand_usepackage) {
+ # Don't bother with before and after text, we just require the
+ # usepackage to be alone on its line.
+ if (my ($package_name) = /^\s*\\usepackage{([^}]*)}\s*$/) {
+ my $full = find_file($package_name . ".sty", $TEXINPUTS);
+ if ($full) {
+ say $prefix . "Found package file: $full\n";
+ process_file($full, $prefix . " ");
+ $_ = "";
+ } else {
+ say $prefix . "Not including external package $package_name\n";
+ }
+ }
+ }
+ if ($expand_bbl) {
+ if (my ($before, $bib_name, $after)
+ = /^(.*)\\bibliography{([^}]*)}(.*)$/) {
+ # The BBL file is not necessarily $bib_name.
+ # Take it from the command-line.
+ print $before . $nl;
+ say $prefix . "Expanding BBL file: $expand_bbl\n";
+ process_file($expand_bbl, $prefix . " ");
+ print " " . $nl . $after . "\n";
+ $_ = "";
+ }
+ }
+ if ($show_graphics) {
+ if (/\\includegraphics{([^}]*)}/) {
+ my $full = find_tex_file($1, $graphics_extensions);
+ say $prefix . "needs graphics file: ";
+ print STDERR "$full\n";
+ }
+ }
+ print;
+}
+
+# search $1 in $TEXINPUTS, with possible extensions in $2
+sub find_tex_file
+{
+ my $file = shift;
+ my $extensions = (shift || ":");
+ foreach my $ext (split(':', $extensions, -1)) {
+ my $full = find_file($file . $ext, $TEXINPUTS);
+ if ($full) {
+ return $full;
+ }
+ }
+ die "ERROR: Could not find file [$file]\n";
+}
+
+sub find_file
+{
+ my ($file, $path) = @_;
+ if (File::Spec->file_name_is_absolute($file)) {
+ if (-e "$file") {
+ return $file;
+ } else {
+ return;
+ }
+ }
+ foreach my $dir (split(':', $path)) {
+ if (-e "$dir/$file") {
+ return("$dir/$file");
+ }
+ }
+ return;
+}
+
+
+__END__
+
+=head1 NAME
+
+latexpand - Flatten LaTeX file by expanding \include and \input, remove comments
+
+=head1 SYNOPSIS
+
+latexpand [options] FILE...
+
+ Options:
+ --verbose show what's going on
+ --keep-comments don't strip comments
+ --empty-comments keep empty comments (i.e. % at end of lines) for clarity
+ --keep-includes don't expand \input and \include directives
+ --expand-usepackage
+ Expand \usepackage{...} directives if the
+ corresponding .sty file is found in
+ $TEXINPUTS
+ --help this help message
+ --output <file>, -o <file>
+ generate output in <file>
+ --explain generate explanatory comments in output
+ --show-graphics show included graphics
+ --graphics_extensions
+ colon-separated list of possible graphics extensions
+ (used by --show-graphics to find the actual graphics files)
+
+=head1 USES
+
+The most common use of latexpand is to simplify distribution of source
+LaTeX files, typically to satisfy the requirement of editors and
+archival sites (springer, arXiv.org, ...) who force the authors to
+submit sources. One does not necessarily want to submit sources with
+comments, and uploading a document made of several files including
+each other is a bit painful. By default, latexpand answers both
+problems by outputing a single LaTeX file that contain no comment.
+
+=head1 GETTING LATEXPAND
+
+The latest version of latexpand is available here:
+
+ https://gitorious.org/latexpand
+
+=head1 BUGS
+
+Please, report bugs to Matthieu Moy <Matthieu.Moy@imag.fr>.
diff --git a/Master/tlpkg/bin/tlpkg-ctan-check b/Master/tlpkg/bin/tlpkg-ctan-check
index 8c5ec5b6e66..326511f421a 100755
--- a/Master/tlpkg/bin/tlpkg-ctan-check
+++ b/Master/tlpkg/bin/tlpkg-ctan-check
@@ -229,7 +229,7 @@ my @TLP_working = qw(
latex2e-help-texinfo latex2e-help-texinfo-spanish latex2man
latex4wp latex4wp-it
latexcheat latexcheat-esmx latexcheat-ptbr
- latexdiff latexfileinfo-pkgs latexfileversion latexmk latexmp
+ latexdiff latexfileinfo-pkgs latexfileversion latexmk latexmp latexpand
lato layaureo layouts lazylist
lcd lcg lcyw leading leaflet lecturer ledmac leftidx lettre lettrine
levy lewis lexikon lfb lgreek lgrx lh lhelp
diff --git a/Master/tlpkg/libexec/ctan2tds b/Master/tlpkg/libexec/ctan2tds
index e07fec69551..d8341bc48cf 100755
--- a/Master/tlpkg/libexec/ctan2tds
+++ b/Master/tlpkg/libexec/ctan2tds
@@ -2180,6 +2180,7 @@ $standardxmt='\.xmt';
'latexdiff' => 'latex(diff-so|diff-vc|revise)$',
'latexmk' => '\.pl$',
'latexfileversion' => 'latexfileversion$',
+ 'latexpand' => 'latexpand$',
'listbib' => 'listbib$',
'listings-ext' => '\.sh$',
'match_parens' => '^match_parens$',
diff --git a/Master/tlpkg/tlpsrc/collection-binextra.tlpsrc b/Master/tlpkg/tlpsrc/collection-binextra.tlpsrc
index 7a325831e3b..c0c4dafa88a 100644
--- a/Master/tlpkg/tlpsrc/collection-binextra.tlpsrc
+++ b/Master/tlpkg/tlpsrc/collection-binextra.tlpsrc
@@ -35,6 +35,7 @@ depend latex2man
depend latexdiff
depend latexfileversion
depend latexmk
+depend latexpand
depend listings-ext
depend match_parens
depend mkjobtexmf
diff --git a/Master/tlpkg/tlpsrc/latexpand.tlpsrc b/Master/tlpkg/tlpsrc/latexpand.tlpsrc
new file mode 100644
index 00000000000..613144bc0a0
--- /dev/null
+++ b/Master/tlpkg/tlpsrc/latexpand.tlpsrc
@@ -0,0 +1 @@
+binpattern f bin/${ARCH}/latexpand