texlive[44751] trunk: texdirflatten (4jul17)
commits+karl at tug.org
commits+karl at tug.org
Wed Jul 5 00:07:08 CEST 2017
Revision: 44751
http://tug.org/svn/texlive?view=revision&revision=44751
Author: karl
Date: 2017-07-05 00:07:08 +0200 (Wed, 05 Jul 2017)
Log Message:
-----------
texdirflatten (4jul17)
Modified Paths:
--------------
trunk/Build/source/texk/texlive/linked_scripts/texdirflatten/texdirflatten
trunk/Master/texmf-dist/doc/man/man1/texdirflatten.1
trunk/Master/texmf-dist/doc/man/man1/texdirflatten.man1.pdf
trunk/Master/texmf-dist/doc/support/texdirflatten/README
trunk/Master/texmf-dist/scripts/texdirflatten/texdirflatten
Modified: trunk/Build/source/texk/texlive/linked_scripts/texdirflatten/texdirflatten
===================================================================
--- trunk/Build/source/texk/texlive/linked_scripts/texdirflatten/texdirflatten 2017-07-04 22:06:51 UTC (rev 44750)
+++ trunk/Build/source/texk/texlive/linked_scripts/texdirflatten/texdirflatten 2017-07-04 22:07:08 UTC (rev 44751)
@@ -14,13 +14,17 @@
=head1 SYNOPSIS
-texdirflatten [-1|--onetex] [-f|--file input.tex] [-o outputdir] [-?|--help]
+texdirflatten [-1|--onetex] [-f|--file input.tex] [-o outputdir]
+ [--imgexts .ext1,.ext2,...] [--debug] [-V|--version] [-?|--help]
=head1 DESCRIPTION
-It parses the source file, following its included children (La)TeX
-files recursively, to collect together its components, such as
-graphics and BiBTeX bibliography files in different directories.
+This Perl script parses a LaTeX file recursively, scanning all child
+files, and collects details of any included and other data files, such
+as graphics and BiBTeX bibliography files. These component files, are
+then all put into a single directory (thus "flattening" the document's
+directory tree). This is useful in distributing manuscripts to
+collaborators or in submitting to journals.
=for comment
Run without parameters to see usage.
@@ -44,6 +48,23 @@
file, graphics and bibliography file to this directory. It will be
created if it is unexistent. If unspecified, it defaults to C<flat/>.
+=item B<--imgexts> I<.ext1,.ext2[,...]>
+
+Prepends to the prioritized list of image extensions to search when
+trying to find the image to copy to output folder. The first file with
+the extension found will be copied and search stopped. Default order
+is C<"", ".eps", ".pdf", ".pstex"> (note that it includes files with
+no extension). If using pdflatex, one may want to add PDF before EPS
+with C<--imgexts .pdf>. Don't forget the dot before the extension!
+
+=item B<--debug>
+
+Enables copious amounts of debugging output - useful if something is going wrong.
+
+=item B<--version>, B<-V>
+
+Displays the current version number and the usage and exits.
+
=item B<--help>, B<-?>
Show this manual page.
@@ -84,9 +105,9 @@
=cut
# TODO:
-#
# - parse BIBINPUTS environment variable and search figures and such
# there as well.
+# - also copy bibtex style file
package texdirflatten;
@@ -99,7 +120,11 @@
# Global
my $outputdir = "flat"; # Output directory
my $file = ""; # File to read
+my @imgexts = ("", ".eps", ".pdf", ".pstex"); # Ordered list of image extensions to search and copy
+my $imgexts_pre; # Prepend to @imgexts
my $onetex = 0; # Indicates all input and include commands be expanded
+my $version = "1.3"; # 2017-02-02
+my $DEBUG = 0; # Enable debugging output
my $help;
# parse helpers
@@ -109,6 +134,10 @@
my $result = GetOptions ("output|o=s" => \$outputdir,
"onetex|1" => \$onetex,
"file|f=s" => \$file,
+ "imgexts=s" => \$imgexts_pre,
+ "debug" => \$DEBUG,
+ "version|V" => sub { print "texdirflatten version $version\n";
+ pod2usage( -section => "SYNOPSIS"); },
"help|?" => \$help );
# regexp for none or an even number of backslashes (\):
@@ -117,12 +146,16 @@
# counter for files translated (like LyX does)
$::filecount = 0;
-my $DEBUG = 1;
pod2usage( -verbose => 2 ) if ($help);
pod2usage( -section => "SYNOPSIS") if ($file eq "");
+if ($imgexts_pre) {
+ unshift(@imgexts, split(/,/, $imgexts_pre));
+ print "imgexts: ". join(",", @imgexts) . "\n" if $DEBUG;
+}
+
system "mkdir $outputdir" if (not -d $outputdir);
# start recursing
@@ -159,7 +192,7 @@
# Look for graphics include statement
if ($contents =~ /\\input\@path\{\{([^}]*)\}\}/) {
$inputdir = $1;
- print "Found input directory: $inputdir\n";
+ print "Found input directory: $inputdir\n" if $DEBUG;
}
print "Parsing '$file' in directory '$inputdir'\n";
@@ -190,12 +223,11 @@
$long =~ s/\\lyxdot /./g;
$flat =~ s/\\lyxdot /./g;
- print "Looking for graphics: '$long'\n";
+ print "Looking for graphics: '$long'\n" if $DEBUG;
- my @exts = ("", ".eps", ".pdf", ".pstex");
my @dirs = ("", "$inputdir", $inputdir . '../figures/');
- seekfile($long, $flat, ["", ".eps", ".pdf", ".pstex"],
+ seekfile($long, $flat, \@imgexts,
["", "$inputdir", $inputdir . '../figures/']);
}
@@ -220,7 +252,7 @@
foreach $long (@longs) {
$flat = shift @flats;
- print "Found Input/Include: '$long'\n";
+ print "Found Input/Include: '$long'\n" if $DEBUG;
# recurse to parse that tex file unless it's done already
if (not exists $texfiles{$flat}) {
@@ -273,15 +305,15 @@
foreach my $ext (@exts) {
my $tryfile = "$dir$file$ext";
if (-r $tryfile) {
- # add the extension to $dest only if it hasn't any dots
- my $dext = '';
- $dext = $ext if (! $dest =~ /\./);
+ # add the extension to $dest only if it hasn't have any dots
+ #(! ($dest =~ /\./)) ? $ext : ""; => better not to have this
+ my $dext = $ext;
if (system("cp $tryfile $outputdir/$dest$dext") != 0) {
die "Cannot copy $tryfile!\n";
}
# If we found it, then get out of the loop
- print "Found: '$tryfile'\n";
+ print "Copied: '$tryfile' (ext: $ext) -> '$dest$dext'\n" if $DEBUG;
last OUT;
}
}
@@ -354,7 +386,7 @@
(?{ #print "\n+++ $#::flats; $#::refs; $#::longs\n";
#push @::flats, @_flats; push @longs, @_longs; push @refs, @_refs;
#print "Refs: @::refs\n";
- })/"\\bibliography$1" . "{@::refs}"/egmx;# &&
+ })/"\\bibliography" . ($1 || "") . "{@::refs}"/egmx;# &&
#print "bib contents: $$contentsref\n";
#print "\n*** $#::flats; $#::refs; $#::longs\n";
$" = ' '; # restore list item separator
@@ -366,13 +398,13 @@
foreach $long (@::longs) {
$flat = shift @::flats;
- print "Found bib. file: '$long'\n";
+ print "Found bib. file: '$long'\n" if $DEBUG;
# recurse to parse that tex file unless it's done already
# convert LyX directory dots
$long =~ s/\\lyxdot /./g;
- seekfile($long, "$flat.bib", [".bib"],
+ seekfile($long, "$flat", [".bib"],
["", "$inputdir"]);
}
}
Modified: trunk/Master/texmf-dist/doc/man/man1/texdirflatten.1
===================================================================
--- trunk/Master/texmf-dist/doc/man/man1/texdirflatten.1 2017-07-04 22:06:51 UTC (rev 44750)
+++ trunk/Master/texmf-dist/doc/man/man1/texdirflatten.1 2017-07-04 22:07:08 UTC (rev 44751)
@@ -133,7 +133,7 @@
.\" ========================================================================
.\"
.IX Title "TEXDIRFLATTEN 1"
-.TH TEXDIRFLATTEN 1 "2017-06-26" "perl v5.22.1" "User Contributed Perl Documentation"
+.TH TEXDIRFLATTEN 1 "2017-07-03" "texdirflatten-v1.3" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
@@ -143,12 +143,16 @@
single output directory \-\- i.e., flattens its hierarchy.
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
-texdirflatten [\-1|\-\-onetex] [\-f|\-\-file input.tex] [\-o outputdir] [\-?|\-\-help]
+texdirflatten [\-1|\-\-onetex] [\-f|\-\-file input.tex] [\-o outputdir]
+ [\-\-imgexts .ext1,.ext2,...] [\-\-debug] [\-V|\-\-version] [\-?|\-\-help]
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
-It parses the source file, following its included children (La)TeX
-files recursively, to collect together its components, such as
-graphics and BiBTeX bibliography files in different directories.
+This Perl script parses a LaTeX file recursively, scanning all child
+files, and collects details of any included and other data files, such
+as graphics and BiBTeX bibliography files. These component files, are
+then all put into a single directory (thus \*(L"flattening\*(R" the document's
+directory tree). This is useful in distributing manuscripts to
+collaborators or in submitting to journals.
.SH "OPTIONS"
.IX Header "OPTIONS"
.IP "\fB\-\-file\fR, \fB\-f\fR \fIinput.tex\fR" 4
@@ -163,6 +167,20 @@
Directory to collect all files. \fBtexdirflatten\fR will copy each source
file, graphics and bibliography file to this directory. It will be
created if it is unexistent. If unspecified, it defaults to \f(CW\*(C`flat/\*(C'\fR.
+.IP "\fB\-\-imgexts\fR \fI.ext1,.ext2[,...]\fR" 4
+.IX Item "--imgexts .ext1,.ext2[,...]"
+Prepends to the prioritized list of image extensions to search when
+trying to find the image to copy to output folder. The first file with
+the extension found will be copied and search stopped. Default order
+is \f(CW"", ".eps", ".pdf", ".pstex"\fR (note that it includes files with
+no extension). If using pdflatex, one may want to add \s-1PDF\s0 before \s-1EPS\s0
+with \f(CW\*(C`\-\-imgexts .pdf\*(C'\fR. Don't forget the dot before the extension!
+.IP "\fB\-\-debug\fR" 4
+.IX Item "--debug"
+Enables copious amounts of debugging output \- useful if something is going wrong.
+.IP "\fB\-\-version\fR, \fB\-V\fR" 4
+.IX Item "--version, -V"
+Displays the current version number and the usage and exits.
.IP "\fB\-\-help\fR, \fB\-?\fR" 4
.IX Item "--help, -?"
Show this manual page.
Modified: trunk/Master/texmf-dist/doc/man/man1/texdirflatten.man1.pdf
===================================================================
(Binary files differ)
Modified: trunk/Master/texmf-dist/doc/support/texdirflatten/README
===================================================================
--- trunk/Master/texmf-dist/doc/support/texdirflatten/README 2017-07-04 22:06:51 UTC (rev 44750)
+++ trunk/Master/texmf-dist/doc/support/texdirflatten/README 2017-07-04 22:07:08 UTC (rev 44751)
@@ -4,12 +4,15 @@
SYNOPSIS
texdirflatten [-1|--onetex] [-f|--file input.tex] [-o outputdir]
- [-?|--help]
+ [--imgexts .ext1,.ext2,...] [--debug] [-V|--version] [-?|--help]
DESCRIPTION
- It parses the source file, following its included children (La)TeX files
- recursively, to collect together its components, such as graphics and
- BiBTeX bibliography files in different directories.
+ This Perl script parses a LaTeX file recursively, scanning all child
+ files, and collects details of any included and other data files, such
+ as graphics and BiBTeX bibliography files. These component files, are
+ then all put into a single directory (thus "flattening" the document's
+ directory tree). This is useful in distributing manuscripts to
+ collaborators or in submitting to journals.
OPTIONS
--file, -f *input.tex*
@@ -24,6 +27,22 @@
file, graphics and bibliography file to this directory. It will be
created if it is unexistent. If unspecified, it defaults to "flat/".
+ --imgexts *.ext1,.ext2[,...]*
+ Prepends to the prioritized list of image extensions to search when
+ trying to find the image to copy to output folder. The first file
+ with the extension found will be copied and search stopped. Default
+ order is "", ".eps", ".pdf", ".pstex" (note that it includes files
+ with no extension). If using pdflatex, one may want to add PDF
+ before EPS with "--imgexts .pdf". Don't forget the dot before the
+ extension!
+
+ --debug
+ Enables copious amounts of debugging output - useful if something is
+ going wrong.
+
+ --version, -V
+ Displays the current version number and the usage and exits.
+
--help, -?
Show this manual page.
Modified: trunk/Master/texmf-dist/scripts/texdirflatten/texdirflatten
===================================================================
--- trunk/Master/texmf-dist/scripts/texdirflatten/texdirflatten 2017-07-04 22:06:51 UTC (rev 44750)
+++ trunk/Master/texmf-dist/scripts/texdirflatten/texdirflatten 2017-07-04 22:07:08 UTC (rev 44751)
@@ -14,13 +14,17 @@
=head1 SYNOPSIS
-texdirflatten [-1|--onetex] [-f|--file input.tex] [-o outputdir] [-?|--help]
+texdirflatten [-1|--onetex] [-f|--file input.tex] [-o outputdir]
+ [--imgexts .ext1,.ext2,...] [--debug] [-V|--version] [-?|--help]
=head1 DESCRIPTION
-It parses the source file, following its included children (La)TeX
-files recursively, to collect together its components, such as
-graphics and BiBTeX bibliography files in different directories.
+This Perl script parses a LaTeX file recursively, scanning all child
+files, and collects details of any included and other data files, such
+as graphics and BiBTeX bibliography files. These component files, are
+then all put into a single directory (thus "flattening" the document's
+directory tree). This is useful in distributing manuscripts to
+collaborators or in submitting to journals.
=for comment
Run without parameters to see usage.
@@ -44,6 +48,23 @@
file, graphics and bibliography file to this directory. It will be
created if it is unexistent. If unspecified, it defaults to C<flat/>.
+=item B<--imgexts> I<.ext1,.ext2[,...]>
+
+Prepends to the prioritized list of image extensions to search when
+trying to find the image to copy to output folder. The first file with
+the extension found will be copied and search stopped. Default order
+is C<"", ".eps", ".pdf", ".pstex"> (note that it includes files with
+no extension). If using pdflatex, one may want to add PDF before EPS
+with C<--imgexts .pdf>. Don't forget the dot before the extension!
+
+=item B<--debug>
+
+Enables copious amounts of debugging output - useful if something is going wrong.
+
+=item B<--version>, B<-V>
+
+Displays the current version number and the usage and exits.
+
=item B<--help>, B<-?>
Show this manual page.
@@ -84,9 +105,9 @@
=cut
# TODO:
-#
# - parse BIBINPUTS environment variable and search figures and such
# there as well.
+# - also copy bibtex style file
package texdirflatten;
@@ -99,7 +120,11 @@
# Global
my $outputdir = "flat"; # Output directory
my $file = ""; # File to read
+my @imgexts = ("", ".eps", ".pdf", ".pstex"); # Ordered list of image extensions to search and copy
+my $imgexts_pre; # Prepend to @imgexts
my $onetex = 0; # Indicates all input and include commands be expanded
+my $version = "1.3"; # 2017-02-02
+my $DEBUG = 0; # Enable debugging output
my $help;
# parse helpers
@@ -109,6 +134,10 @@
my $result = GetOptions ("output|o=s" => \$outputdir,
"onetex|1" => \$onetex,
"file|f=s" => \$file,
+ "imgexts=s" => \$imgexts_pre,
+ "debug" => \$DEBUG,
+ "version|V" => sub { print "texdirflatten version $version\n";
+ pod2usage( -section => "SYNOPSIS"); },
"help|?" => \$help );
# regexp for none or an even number of backslashes (\):
@@ -117,12 +146,16 @@
# counter for files translated (like LyX does)
$::filecount = 0;
-my $DEBUG = 1;
pod2usage( -verbose => 2 ) if ($help);
pod2usage( -section => "SYNOPSIS") if ($file eq "");
+if ($imgexts_pre) {
+ unshift(@imgexts, split(/,/, $imgexts_pre));
+ print "imgexts: ". join(",", @imgexts) . "\n" if $DEBUG;
+}
+
system "mkdir $outputdir" if (not -d $outputdir);
# start recursing
@@ -159,7 +192,7 @@
# Look for graphics include statement
if ($contents =~ /\\input\@path\{\{([^}]*)\}\}/) {
$inputdir = $1;
- print "Found input directory: $inputdir\n";
+ print "Found input directory: $inputdir\n" if $DEBUG;
}
print "Parsing '$file' in directory '$inputdir'\n";
@@ -190,12 +223,11 @@
$long =~ s/\\lyxdot /./g;
$flat =~ s/\\lyxdot /./g;
- print "Looking for graphics: '$long'\n";
+ print "Looking for graphics: '$long'\n" if $DEBUG;
- my @exts = ("", ".eps", ".pdf", ".pstex");
my @dirs = ("", "$inputdir", $inputdir . '../figures/');
- seekfile($long, $flat, ["", ".eps", ".pdf", ".pstex"],
+ seekfile($long, $flat, \@imgexts,
["", "$inputdir", $inputdir . '../figures/']);
}
@@ -220,7 +252,7 @@
foreach $long (@longs) {
$flat = shift @flats;
- print "Found Input/Include: '$long'\n";
+ print "Found Input/Include: '$long'\n" if $DEBUG;
# recurse to parse that tex file unless it's done already
if (not exists $texfiles{$flat}) {
@@ -273,15 +305,15 @@
foreach my $ext (@exts) {
my $tryfile = "$dir$file$ext";
if (-r $tryfile) {
- # add the extension to $dest only if it hasn't any dots
- my $dext = '';
- $dext = $ext if (! $dest =~ /\./);
+ # add the extension to $dest only if it hasn't have any dots
+ #(! ($dest =~ /\./)) ? $ext : ""; => better not to have this
+ my $dext = $ext;
if (system("cp $tryfile $outputdir/$dest$dext") != 0) {
die "Cannot copy $tryfile!\n";
}
# If we found it, then get out of the loop
- print "Found: '$tryfile'\n";
+ print "Copied: '$tryfile' (ext: $ext) -> '$dest$dext'\n" if $DEBUG;
last OUT;
}
}
@@ -354,7 +386,7 @@
(?{ #print "\n+++ $#::flats; $#::refs; $#::longs\n";
#push @::flats, @_flats; push @longs, @_longs; push @refs, @_refs;
#print "Refs: @::refs\n";
- })/"\\bibliography$1" . "{@::refs}"/egmx;# &&
+ })/"\\bibliography" . ($1 || "") . "{@::refs}"/egmx;# &&
#print "bib contents: $$contentsref\n";
#print "\n*** $#::flats; $#::refs; $#::longs\n";
$" = ' '; # restore list item separator
@@ -366,13 +398,13 @@
foreach $long (@::longs) {
$flat = shift @::flats;
- print "Found bib. file: '$long'\n";
+ print "Found bib. file: '$long'\n" if $DEBUG;
# recurse to parse that tex file unless it's done already
# convert LyX directory dots
$long =~ s/\\lyxdot /./g;
- seekfile($long, "$flat.bib", [".bib"],
+ seekfile($long, "$flat", [".bib"],
["", "$inputdir"]);
}
}
More information about the tex-live-commits
mailing list