?? latex.pm
字號:
# Start on new page if requested $self->_output("\\clearpage\n") if $self->StartWithNewPage;}=item B<end_pod>Write the closing C<latex> code. Only writes something if AddPostambleis true. Writes a standard header unless a UserPostamble is defined.=cutsub end_pod { my $self = shift; # End string my $end = ''; # Use the user version of the postamble if defined if ($self->AddPostamble) { if (defined $self->UserPostamble) { $end = $self->UserPostamble; } else { # 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'; # Store a copy of the raw text in case we are in a =for # block and need to preserve the existing latex my $rawpara = $paragraph; # Do the latex escapes $paragraph = $self->_replace_special_chars($paragraph); # Interpolate pod sequences in paragraph $paragraph = $self->interpolate($paragraph, $line_num); $paragraph =~ s/\s+$//; # Replace characters that can only be done after # interpolation of interior sequences $paragraph = $self->_replace_special_chars_late($paragraph); # 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') { # =for latex # some latex # With =for we will get the text for the full paragraph # as well as the format name. # We do not get an additional paragraph later on. The next # paragraph is not governed by the =for # The first line contains the format and the rest is the # raw code. my ($format, $chunk) = split(/\n/, $rawpara, 2); # If we have got some latex code print it out immediately # unmodified. Else do nothing. if ($format =~ /^latex/i) { # Make sure that next paragraph is not modfied before printing $self->_output( $chunk ); } } 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 =begin block if ($self->{_dont_modify_any_para}) { # Just print as is $self->_output($paragraph); } else { return if $paragraph =~ /^\s+$/; # Clean trailing space $paragraph =~ s/\s+$//; # Clean tabs. Routine taken from Tabs.pm # by David Muir Sharnoff muir@idiom.com, # slightly modified by hsmyers@sdragons.com 10/22/01 my @l = split("\n",$paragraph); foreach (@l) { 1 while s/(^|\n)([^\t\n]*)(\t+)/ $1. $2 . (" " x (8 * length($3) - (length($2) % 8))) /sex; } $paragraph = join("\n",@l); # End of change. $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 =begin block if ($self->{_dont_modify_any_para}) { # Just print as is $self->_output($paragraph); return; } # Escape latex special characters $paragraph = $self->_replace_special_chars($paragraph); # Interpolate interior sequences my $expansion = $self->interpolate($paragraph, $line_num); $expansion =~ s/\s+$//; # Escape special characters that can not be done earlier $expansion = $self->_replace_special_chars_late($expansion); # 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}; } else { my ($file, $line) = $pod_seq->file_line(); warn "Escape sequence $seq_argument not recognised at line $line of file $file\n"; return; } } elsif ($seq_command eq 'Z') { # Zero width space return '{}'; } elsif ($seq_command eq 'C') { return "\\texttt{$seq_argument}"; } elsif ($seq_command eq 'F') { return "\\emph{$seq_argument}"; } elsif ($seq_command eq 'S') { # non breakable spaces my $nbsp = '~'; $seq_argument =~ s/\s/$nbsp/g; return $seq_argument; } elsif ($seq_command eq 'L') { my $link = new Pod::Hyperlink($seq_argument); # undef on failure unless (defined $link) { carp $@; return; } # Handle internal links differently my $type = $link->type; my $page = $link->page; if ($type eq 'section' && $page eq '') { # Use internal latex reference my $node = $link->node; # Convert to a label $node = $self->_create_label($node); return "\\S\\ref{$node}"; } else { # Use default markup for external references # (although Starlink would use \xlabel) my $markup = $link->markup; my ($file, $line) = $pod_seq->file_line(); return $self->interpolate($link->markup, $line); } } elsif ($seq_command eq 'P') { # Special markup for Pod::Hyperlink # Replace :: with / - but not sure if I want to do this # any more. my $link = $seq_argument; $link =~ s|::|/|g; my $ref = "\\emph{$seq_argument}"; return $ref; } elsif ($seq_command eq 'Q') { # Special markup for Pod::Hyperlink return "\\textsf{$seq_argument}"; } elsif ($seq_command eq 'X') { # Index entries # use \index command # I will let '!' go through for now # not sure how sub categories are handled in X<> my $index = $self->_create_index($seq_argument); return "\\index{$index}\n"; } else { carp "Unknown sequence $seq_command<$seq_argument>"; }}=back=head2 List MethodsMethods used to handle lists.=over 4=item B<begin_list>Called when a new list is found (via the C<over> directive).Creates a new C<Pod::List> object and stores it on the list stack. $parser->begin_list($indent, $line_num);=cutsub begin_list { my $self = shift; my $indent = shift; my $line_num = shift; # Indicate that a list should be started for the next item # need to do this to work out the type of list push ( @{$self->lists}, new Pod::List(-indent => $indent, -start => $line_num, -file => $self->input_file, ) );}=item B<end_list>Called when the end of a list is found (the C<back> directive).Pops the C<Pod::List> object off the stack of lists and writesthe C<latex> code required to close a list. $parser->end_list($line_num);=cutsub end_list { my $self = shift; my $line_num = shift; unless (defined $self->lists->[-1]) { my $file = $self->input_file; warn "No list is active at line $line_num (file=$file). Missing =over?\n"; return; } # What to write depends on list type my $type = $self->lists->[-1]->type; # Dont write anything if the list type is not set # iomplying that a list was created but no entries were # placed in it (eg because of a =begin/=end combination) $self->_output("\\end{$type}\n") if (defined $type && length($type) > 0); # Clear list pop(@{ $self->lists});}=item B<add_item>Add items to the list. The first time an item is encountered (determined from the state of the current C<Pod::List> object)the type of list is determined (ordered, unnumbered or description)and the relevant latex code issued. $parser->add_item($paragraph, $line_num);=cutsub add_item { my $self = shift; my $paragraph = shift; my $line_num = shift;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -