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 /;
49 # Read command line arguments
59 "h1level" => 1, # section is equivalent to H1
73 pod2usage(1) if ($options{help});
74 pod2usage(-verbose => 2) if ($options{man});
77 # Read all the files from the command line
80 # Now find which ones are real pods and convert
81 # directories to their contents.
83 # Extract the pods from each arg since some of them might
85 # This is not as efficient as using pod_find to search through
86 # everything at once but it allows us to preserve the order
87 # supplied by the user
90 foreach my $arg (@files) {
91 my %pods = pod_find($arg);
92 push(@pods, sort keys %pods);
95 # Abort if nothing to do
97 warn "None of the supplied Pod files actually exist\n";
103 # If $options{'out'} is set we are processing to a single output file
105 if (exists $options{'out'} && defined $options{'out'}) {
106 $multi_documents = 0;
108 $multi_documents = 1;
111 # If the output file is not specified it is assumed that
112 # a single output file is required per input file using
113 # a .tex extension rather than any exisiting extension
115 if ($multi_documents) {
117 # Case where we just generate one input per output
119 foreach my $pod (@pods) {
124 $output = basename($output, '.pm', '.pod','.pl') . '.tex';
126 # Create a new parser object
127 my $parser = new Pod::LaTeX(
128 AddPreamble => $options{'full'},
129 AddPostamble => $options{'full'},
130 MakeIndex => $options{'full'},
131 TableOfContents => $options{'full'},
132 ReplaceNAMEwithSection => $options{'modify'},
133 UniqueLabels => $options{'modify'},
134 Head1Level => $options{'h1level'},
135 LevelNoNum => $options{'h1level'} + 1,
138 # Select sections if supplied
139 $parser->select(@{ $options{'sections'}})
140 if @{$options{'sections'}};
142 # Derive the input file from the output file
143 $parser->parse_from_file($pod, $output);
145 print "Written output to $output\n" if $options{'verbose'};
148 warn "File $pod not found\n";
154 # Case where we want everything to be in a single document
156 # Need to open the output file ourselves
157 my $output = $options{'out'};
158 $output .= '.tex' unless $output =~ /\.tex$/;
160 # Use auto-vivified file handle in perl 5.6
163 open ($outfh, ">$output") || die "Could not open output file: $!\n";
165 # Flag to indicate whether we have converted at least one file
166 # indicates how many files have been converted
169 # Loop over the input files
170 foreach my $pod (@pods) {
174 warn "Converting $pod\n" if $options{'verbose'};
176 # Open the file (need the handle)
177 # Use auto-vivified handle in perl 5.6
179 open ($podfh, "<$pod") || die "Could not open pod file $pod: $!\n";
181 # if this is the first file to be converted we may want to add
182 # a preamble (controlled by command line option)
184 $preamble = 1 if ($converted == 0 && $options{'full'});
186 # if this is the last file to be converted may want to add
187 # a postamble (controlled by command line option)
188 # relies on a previous pass to check existence of all pods we
190 my $postamble = ( ($converted == $#pods && $options{'full'}) ? 1 : 0 );
193 # May want to start with a preamble for the first one and
194 # end with an index for the last
195 my $parser = new Pod::LaTeX(
196 MakeIndex => $options{'full'},
197 TableOfContents => $preamble,
198 ReplaceNAMEwithSection => $options{'modify'},
199 UniqueLabels => $options{'modify'},
200 StartWithNewPage => $options{'full'},
201 AddPreamble => $preamble,
202 AddPostamble => $postamble,
203 Head1Level => $options{'h1level'},
204 LevelNoNum => $options{'h1level'} + 1,
207 # Store the file name for error messages
208 # This is a kluge that breaks the data hiding of the object
209 $parser->{_INFILE} = $pod;
211 # Select sections if supplied
212 $parser->select(@{ $options{'sections'}})
213 if @{$options{'sections'}};
216 $parser->parse_from_filehandle($podfh, $outfh);
218 # We have converted at least one file
222 warn "File $pod not found\n";
227 # Should unlink the file if we didn't convert anything!
228 # dont check for return status of unlink
229 # since there is not a lot to be done if the unlink failed
230 # and the program does not rely upon it.
231 unlink "$output" unless $converted;
234 warn "Converted $converted files\n" if $options{'verbose'};
244 pod2latex - convert pod documentation to latex format
250 pod2latex -out mytex.tex *.pod
252 pod2latex -full -sections 'DESCRIPTION|NAME' SomeDir
256 C<pod2latex> is a program to convert POD format documentation
257 (L<perlpod>) into latex. It can process multiple input documents at a
258 time and either generate a latex file per input document or a single
259 combined output file.
261 =head1 OPTIONS AND ARGUMENTS
263 This section describes the supported command line options. Minium
264 matching is supported.
270 Name of the output file to be used. If there are multiple input pods
271 it is assumed that the intention is to write all translated output
272 into a single file. C<.tex> is appended if not present. If the
273 argument is not supplied, a single document will be created for each
278 Creates a complete C<latex> file that can be processed immediately
279 (unless C<=for/=begin> directives are used that rely on extra packages).
280 Table of contents and index generation commands are included in the
281 wrapper C<latex> code.
285 Specify pod sections to include (or remove if negated) in the
286 translation. See L<Pod::Select/"SECTION SPECIFICATIONS"> for the
287 format to use for I<section-spec>. This option may be given multiple
288 times on the command line.This is identical to the similar option in
289 the C<podselect()> command.
293 This option causes the output C<latex> to be slightly
294 modified from the input pod such that when a C<=head1 NAME>
295 is encountered a section is created containing the actual
296 pod name (rather than B<NAME>) and all subsequent C<=head1>
297 directives are treated as subsections. This has the advantage
298 that the description of a module will be in its own section
299 which is helpful for including module descriptions in documentation.
300 Also forces C<latex> label and index entries to be prefixed by the
305 Specifies the C<latex> section that is equivalent to a C<H1> pod
306 directive. This is an integer between 0 and 5 with 0 equivalent to a
307 C<latex> chapter, 1 equivalent to a C<latex> section etc. The default
308 is 1 (C<H1> equivalent to a latex section).
312 Print a brief help message and exit.
316 Print the manual page and exit.
320 Print information messages as each document is processed.
332 Cross references between documents are not resolved when multiple
333 pod documents are converted into a single output C<latex> file.
337 Functions and variables are not automatically recognized
338 and they will therefore not be marked up in any special way
339 unless instructed by an explicit pod command.
349 Tim Jenness E<lt>t.jenness@jach.hawaii.eduE<gt>
351 This program is free software; you can redistribute it
352 and/or modify it under the same terms as Perl itself.
354 Copyright (C) 2000 Tim Jenness.
360 close OUT or die "Can't close $file: $!";
361 chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
362 exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';