4 use File::Basename qw(&basename &dirname);
7 # List explicitly here the variables you want Configure to
8 # generate. Metaconfig only looks for shell variables, so you
9 # have to mention them as if they were shell variables, not
10 # %Config entries. Thus you write
12 # to ensure Configure will look for $Config{startperl}.
14 # This forces PL files to create target in same directory as PL file.
15 # This is so that make depend always knows where to find PL derivatives.
18 $file = basename($0, '.PL');
19 $file .= '.com' if $^O eq 'VMS';
21 open OUT,">$file" or die "Can't create $file: $!";
23 print "Extracting $file (with variable substitutions)\n";
25 # In this section, perl variables will be expanded during extraction.
26 # You can use $Config{...} to use Configure variables.
28 print OUT <<"!GROK!THIS!";
30 eval 'exec $Config{perlpath} -S \$0 \${1+"\$@"}'
31 if \$running_under_some_shell;
34 # In the following, perl variables are not expanded during extraction.
36 print OUT <<'!NO!SUBS!';
38 # pod2latex conversion program
42 use Pod::Find qw/ pod_find /;
50 # return the entire contents of a text file
51 # whose name is given as argument
56 or die "Could not open file $fn: $!\n";
61 # Read command line arguments
71 "h1level" => 1, # section is equivalent to H1
75 # "prefile" is just like "preamble", but the argument
76 # comes from the file named by the argument
77 $options{"prefile"} = sub { shift; push @{$options{"preamble"}}, _get(shift) };
78 # the same between "postfile" and "postamble"
79 $options{"postfile"} = sub { shift; push @{$options{"postamble"}}, _get(shift) };
96 pod2usage(1) if ($options{help});
97 pod2usage(-verbose => 2) if ($options{man});
100 # Read all the files from the command line
103 # Now find which ones are real pods and convert
104 # directories to their contents.
106 # Extract the pods from each arg since some of them might
108 # This is not as efficient as using pod_find to search through
109 # everything at once but it allows us to preserve the order
110 # supplied by the user
113 foreach my $arg (@files) {
114 my %pods = pod_find($arg);
115 push(@pods, sort keys %pods);
118 # Abort if nothing to do
120 warn "None of the supplied Pod files actually exist\n";
124 # Only want to override the preamble and postamble if we have
127 $User{UserPreamble} = join("\n", @{$options{'preamble'}})
128 if ($options{preamble} && @{$options{preamble}});
129 $User{UserPostamble} = join("\n", @{$options{'postamble'}})
130 if ($options{postamble} && @{$options{postamble}});
134 # If $options{'out'} is set we are processing to a single output file
136 if (exists $options{'out'} && defined $options{'out'}) {
137 $multi_documents = 0;
139 $multi_documents = 1;
142 # If the output file is not specified it is assumed that
143 # a single output file is required per input file using
144 # a .tex extension rather than any exisiting extension
146 if ($multi_documents) {
148 # Case where we just generate one input per output
150 foreach my $pod (@pods) {
155 $output = basename($output, '.pm', '.pod','.pl') . '.tex';
157 # Create a new parser object
158 my $parser = new Pod::LaTeX(
159 AddPreamble => $options{'full'},
160 AddPostamble => $options{'full'},
161 MakeIndex => $options{'full'},
162 TableOfContents => $options{'full'},
163 ReplaceNAMEwithSection => $options{'modify'},
164 UniqueLabels => $options{'modify'},
165 Head1Level => $options{'h1level'},
166 LevelNoNum => $options{'h1level'} + 1,
170 # Select sections if supplied
171 $parser->select(@{ $options{'sections'}})
172 if @{$options{'sections'}};
174 # Derive the input file from the output file
175 $parser->parse_from_file($pod, $output);
177 print "Written output to $output\n" if $options{'verbose'};
180 warn "File $pod not found\n";
186 # Case where we want everything to be in a single document
188 # Need to open the output file ourselves
189 my $output = $options{'out'};
190 $output .= '.tex' unless $output =~ /\.tex$/;
192 # Use auto-vivified file handle in perl 5.6
194 open ($outfh, ">$output") || die "Could not open output file: $!\n";
196 # Flag to indicate whether we have converted at least one file
197 # indicates how many files have been converted
200 # Loop over the input files
201 foreach my $pod (@pods) {
205 warn "Converting $pod\n" if $options{'verbose'};
207 # Open the file (need the handle)
208 # Use auto-vivified handle in perl 5.6
210 open ($podfh, "<$pod") || die "Could not open pod file $pod: $!\n";
212 # if this is the first file to be converted we may want to add
213 # a preamble (controlled by command line option)
215 $preamble = 1 if ($converted == 0 && $options{'full'});
217 # if this is the last file to be converted may want to add
218 # a postamble (controlled by command line option)
219 # relies on a previous pass to check existence of all pods we
221 my $postamble = ( ($converted == $#pods && $options{'full'}) ? 1 : 0 );
224 # May want to start with a preamble for the first one and
225 # end with an index for the last
226 my $parser = new Pod::LaTeX(
227 MakeIndex => $options{'full'},
228 TableOfContents => $preamble,
229 ReplaceNAMEwithSection => $options{'modify'},
230 UniqueLabels => $options{'modify'},
231 StartWithNewPage => $options{'full'},
232 AddPreamble => $preamble,
233 AddPostamble => $postamble,
234 Head1Level => $options{'h1level'},
235 LevelNoNum => $options{'h1level'} + 1,
239 # Store the file name for error messages
240 # This is a kluge that breaks the data hiding of the object
241 $parser->{_INFILE} = $pod;
243 # Select sections if supplied
244 $parser->select(@{ $options{'sections'}})
245 if @{$options{'sections'}};
248 $parser->parse_from_filehandle($podfh, $outfh);
250 # We have converted at least one file
254 warn "File $pod not found\n";
259 # Should unlink the file if we didn't convert anything!
260 # dont check for return status of unlink
261 # since there is not a lot to be done if the unlink failed
262 # and the program does not rely upon it.
263 unlink "$output" unless $converted;
266 warn "Converted $converted files\n" if $options{'verbose'};
276 pod2latex - convert pod documentation to latex format
282 pod2latex -out mytex.tex *.pod
284 pod2latex -full -sections 'DESCRIPTION|NAME' SomeDir
286 pod2latex -prefile h.tex -postfile t.tex my.pod
290 C<pod2latex> is a program to convert POD format documentation
291 (L<perlpod>) into latex. It can process multiple input documents at a
292 time and either generate a latex file per input document or a single
293 combined output file.
295 =head1 OPTIONS AND ARGUMENTS
297 This section describes the supported command line options. Minimum
298 matching is supported.
304 Name of the output file to be used. If there are multiple input pods
305 it is assumed that the intention is to write all translated output
306 into a single file. C<.tex> is appended if not present. If the
307 argument is not supplied, a single document will be created for each
312 Creates a complete C<latex> file that can be processed immediately
313 (unless C<=for/=begin> directives are used that rely on extra packages).
314 Table of contents and index generation commands are included in the
315 wrapper C<latex> code.
319 Specify pod sections to include (or remove if negated) in the
320 translation. See L<Pod::Select/"SECTION SPECIFICATIONS"> for the
321 format to use for I<section-spec>. This option may be given multiple
322 times on the command line.This is identical to the similar option in
323 the C<podselect()> command.
327 This option causes the output C<latex> to be slightly
328 modified from the input pod such that when a C<=head1 NAME>
329 is encountered a section is created containing the actual
330 pod name (rather than B<NAME>) and all subsequent C<=head1>
331 directives are treated as subsections. This has the advantage
332 that the description of a module will be in its own section
333 which is helpful for including module descriptions in documentation.
334 Also forces C<latex> label and index entries to be prefixed by the
339 Specifies the C<latex> section that is equivalent to a C<H1> pod
340 directive. This is an integer between 0 and 5 with 0 equivalent to a
341 C<latex> chapter, 1 equivalent to a C<latex> section etc. The default
342 is 1 (C<H1> equivalent to a latex section).
346 Print a brief help message and exit.
350 Print the manual page and exit.
354 Print information messages as each document is processed.
358 A user-supplied preamble for the LaTeX code. Multiple values
359 are supported and appended in order separated by "\n".
360 See B<-prefile> for reading the preamble from a file.
364 A user supplied postamble for the LaTeX code. Multiple values
365 are supported and appended in order separated by "\n".
366 See B<-postfile> for reading the postamble from a file.
370 A user-supplied preamble for the LaTeX code to be read from the
371 named file. Multiple values are supported and appended in
372 order. See B<-preamble>.
376 A user-supplied postamble for the LaTeX code to be read from the
377 named file. Multiple values are supported and appended in
378 order. See B<-postamble>.
390 Cross references between documents are not resolved when multiple
391 pod documents are converted into a single output C<latex> file.
395 Functions and variables are not automatically recognized
396 and they will therefore not be marked up in any special way
397 unless instructed by an explicit pod command.
407 Tim Jenness E<lt>tjenness@cpan.orgE<gt>
409 This program is free software; you can redistribute it
410 and/or modify it under the same terms as Perl itself.
412 Copyright (C) 2000, 2003, 2004 Tim Jenness. All Rights Reserved.
418 close OUT or die "Can't close $file: $!";
419 chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
420 exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';