📄 latex.pm
字号:
=head1 SYNOPSISis converted to the C<latex> \section{pod::name\label{pod_name}\index{pod::name}} Purpose \subsection*{SYNOPSIS\label{pod_name_SYNOPSIS}% \index{pod::name!SYNOPSIS}}(dependent on the value of C<Head1Level> and C<LevelNoNum>). Note thatsubsequent C<head1> directives translate to subsections rather thansections and that the labels and index now include the pod name (dependenton the value of C<UniqueLabels>).The C<Label> is set from the pod name regardless of any current valueof C<Label>. $mod = $parser->ReplaceNAMEwithSection; $parser->ReplaceNAMEwithSection(0);Default is to translate the pod literally.=cutsub ReplaceNAMEwithSection { my $self = shift; if (@_) { $self->{ReplaceNAMEwithSection} = shift; } return $self->{ReplaceNAMEwithSection};}=item B<StartWithNewPage>If true, each pod translation will begin with a C<latex>C<\clearpage>. $parser->StartWithNewPage(1); $newpage = $parser->StartWithNewPage;Default is false.=cutsub StartWithNewPage { my $self = shift; if (@_) { $self->{StartWithNewPage} = shift; } return $self->{StartWithNewPage};}=item B<TableOfContents>If true, a table of contents will be created.Irrelevant if C<AddPreamble> is false or C<UserPreamble>is set. $toc = $parser->TableOfContents; $parser->TableOfContents(1);Default is false.=cutsub TableOfContents { my $self = shift; if (@_) { $self->{TableOfContents} = shift; } return $self->{TableOfContents};}=item B<UniqueLabels>If true, the translator will attempt to make sure thateach C<latex> label or index entry will be uniquely identifiedby prefixing the contents of C<Label>. This allowsmultiple documents to be combined without clashing common labels such as C<DESCRIPTION> and C<SYNOPSIS> $parser->UniqueLabels(1); $unq = $parser->UniqueLabels;Default is true.=cutsub UniqueLabels { my $self = shift; if (@_) { $self->{UniqueLabels} = shift; } return $self->{UniqueLabels};}=item B<UserPreamble>User supplied C<latex> preamble. Added before the pod translationdata. If set, the contents will be prepended to the output file before the translated data regardless of the value of C<AddPreamble>.C<MakeIndex> and C<TableOfContents> will also be ignored.=cutsub UserPreamble { my $self = shift; if (@_) { $self->{UserPreamble} = shift; } return $self->{UserPreamble};}=item B<UserPostamble>User supplied C<latex> postamble. Added after the pod translationdata. If set, the contents will be prepended to the output file after the translated data regardless of the value of C<AddPostamble>.C<MakeIndex> will also be ignored.=cutsub UserPostamble { my $self = shift; if (@_) { $self->{UserPostamble} = shift; } return $self->{UserPostamble};}=begin __PRIVATE__=item B<Lists>Contains details of the currently active lists. The array contains C<Pod::List> objects. A new C<Pod::List>object is created each time a list is encountered and it ispushed onto this stack. When the list context ends, it is popped from the stack. The array will be empty if nolists are active.Returns array of list information in list contextReturns array ref in scalar context=cutsub lists { my $self = shift; return @{ $self->{_Lists} } if wantarray(); return $self->{_Lists};}=end __PRIVATE__=back=begin __PRIVATE__=head2 Subclassed methodsThe following methods override methods provided in the C<Pod::Select>base class. See C<Pod::Parser> and C<Pod::Select> for more informationon what these methods require.=over 4=cut######### END ACCESSORS #################### Opening pod=item B<begin_pod>Writes the C<latex> preamble if requested.=cutsub begin_pod { my $self = shift; # Get the pod identification # This should really come from the '=head1 NAME' paragraph my $infile = $self->input_file; my $class = ref($self); my $date = gmtime(time); # Comment message to say where this came from my $comment = << "__TEX_COMMENT__";%% Latex generated from POD in document $infile%% Using the perl module $class%% Converted on $date__TEX_COMMENT__ # Write the preamble # If the caller has supplied one then we just use that my $preamble = ''; if (defined $self->UserPreamble) { $preamble = $self->UserPreamble; # Add the description of where this came from $preamble .= "\n$comment"; } elsif ($self->AddPreamble) { # Write our own preamble # Code to initialise index making # Use an array so that we can prepend comment if required my @makeidx = ( '\usepackage{makeidx}', '\makeindex', ); unless ($self->MakeIndex) { foreach (@makeidx) { $_ = '%% ' . $_; } } my $makeindex = join("\n",@makeidx) . "\n"; # Table of contents my $tableofcontents = '\tableofcontents'; $tableofcontents = '%% ' . $tableofcontents unless $self->TableOfContents; # Roll our own $preamble = << "__TEX_HEADER__";\\documentclass{article}$comment$makeindex\\begin{document}$tableofcontents__TEX_HEADER__ } # Write the header (blank if none) $self->_output($preamble); # Start on new page if requested $self->_output("\\clearpage\n") if $self->StartWithNewPage;}=item B<end_pod>Write the closing C<latex> code.=cutsub end_pod { my $self = shift; # End string my $end = ''; # Use the user version of the postamble if deinfed if (defined $self->UserPostamble) { $end = $self->UserPostamble; $self->_output($end); } elsif ($self->AddPostamble) { # Check for index my $makeindex = '\printindex'; $makeindex = '%% '. $makeindex unless $self->MakeIndex; $end = "$makeindex\n\n\\end{document}\n"; } $self->_output($end);}=item B<command>Process basic pod commands.=cutsub command { my $self = shift; my ($command, $paragraph, $line_num, $parobj) = @_; # return if we dont care return if $command eq 'pod'; $paragraph = $self->_replace_special_chars($paragraph); # Interpolate pod sequences in paragraph $paragraph = $self->interpolate($paragraph, $line_num); $paragraph =~ s/\s+$//; # Now run the command if ($command eq 'over') { $self->begin_list($paragraph, $line_num); } elsif ($command eq 'item') { $self->add_item($paragraph, $line_num); } elsif ($command eq 'back') { $self->end_list($line_num); } elsif ($command eq 'head1') { # Store the name of the section $self->{_CURRENT_HEAD1} = $paragraph; # Print it $self->head(1, $paragraph, $parobj); } elsif ($command eq 'head2') { $self->head(2, $paragraph, $parobj); } elsif ($command eq 'head3') { $self->head(3, $paragraph, $parobj); } elsif ($command eq 'head4') { $self->head(4, $paragraph, $parobj); } elsif ($command eq 'head5') { $self->head(5, $paragraph, $parobj); } elsif ($command eq 'head6') { $self->head(6, $paragraph, $parobj); } elsif ($command eq 'begin') { # pass through if latex if ($paragraph =~ /^latex/i) { # Make sure that subsequent paragraphs are not modfied before printing $self->{_dont_modify_any_para} = 1; } else { # Suppress all subsequent paragraphs unless # it is explcitly intended for latex $self->{_suppress_all_para} = 1; } } elsif ($command eq 'for') { # pass through if latex if ($paragraph =~ /^latex/i) { # Make sure that next paragraph is not modfied before printing $self->{_dont_modify_next_para} = 1; } else { # Suppress the next paragraph unless it is latex $self->{_suppress_next_para} = 1 } } elsif ($command eq 'end') { # Reset suppression $self->{_suppress_all_para} = 0; $self->{_dont_modify_any_para} = 0; } elsif ($command eq 'pod') { # Do nothing } else { carp "Command $command not recognised at line $line_num\n"; }}=item B<verbatim>Verbatim text=cutsub verbatim { my $self = shift; my ($paragraph, $line_num, $parobj) = @_; # Expand paragraph unless in =for or =begin block if ($self->{_dont_modify_any_para} || $self->{_dont_modify_next_para}) { # Just print as is $self->_output($paragraph); # Reset flag if in =for $self->{_dont_modify_next_para} = 0; } else { return if $paragraph =~ /^\s+$/; # Clean trailing space $paragraph =~ s/\s+$//; # Clean tabs $paragraph =~ s/\t/ /g; $self->_output('\begin{verbatim}' . "\n$paragraph\n". '\end{verbatim}'."\n"); }}=item B<textblock>Plain text paragraph.=cutsub textblock { my $self = shift; my ($paragraph, $line_num, $parobj) = @_; # print Dumper($self); # Expand paragraph unless in =for or =begin block if ($self->{_dont_modify_any_para} || $self->{_dont_modify_next_para}) { # Just print as is $self->_output($paragraph); # Reset flag if in =for $self->{_dont_modify_next_para} = 0; return; } # Escape latex special characters $paragraph = $self->_replace_special_chars($paragraph); # Interpolate interior sequences my $expansion = $self->interpolate($paragraph, $line_num); $expansion =~ s/\s+$//; # If we are replacing 'head1 NAME' with a section # we need to look in the paragraph and rewrite things # Need to make sure this is called only on the first paragraph # following 'head1 NAME' and not on subsequent paragraphs that may be # present. if ($self->{_CURRENT_HEAD1} =~ /^NAME/i && $self->ReplaceNAMEwithSection()) { # Strip white space from start and end $paragraph =~ s/^\s+//; $paragraph =~ s/\s$//; # Split the string into 2 parts my ($name, $purpose) = split(/\s+-\s+/, $expansion,2); # Now prevent this from triggering until a new head1 NAME is set $self->{_CURRENT_HEAD1} = '_NAME'; # Might want to clear the Label() before doing this (CHECK) # Print the heading $self->head(1, $name, $parobj); # Set the labeling in case we want unique names later $self->Label( $self->_create_label( $name, 1 ) ); # Raise the Head1Level by one so that subsequent =head1 appear # as subsections of the main name section unless we are already # at maximum [Head1Level() could check this itself - CHECK] $self->Head1Level( $self->Head1Level() + 1) unless $self->Head1Level == $#LatexSections; # Now write out the new latex paragraph $purpose = ucfirst($purpose); $self->_output("\n\n$purpose\n\n"); } else { # Just write the output $self->_output("\n\n$expansion\n\n"); }}=item B<interior_sequence>Interior sequence expansion=cutsub interior_sequence { my $self = shift; my ($seq_command, $seq_argument, $pod_seq) = @_; if ($seq_command eq 'B') { return "\\textbf{$seq_argument}"; } elsif ($seq_command eq 'I') { return "\\textit{$seq_argument}"; } elsif ($seq_command eq 'E') { # If it is simply a number if ($seq_argument =~ /^\d+$/) { return chr($seq_argument); # Look up escape in hash table } elsif (exists $HTML_Escapes{$seq_argument}) { return $HTML_Escapes{$seq_argument};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -