?? latex.pm
字號(hào):
unless (defined $self->lists->[-1]) { my $file = $self->input_file; warn "List has already ended by line $line_num of file $file. Missing =over?\n"; # Replace special chars# $paragraph = $self->_replace_special_chars($paragraph); $self->_output("$paragraph\n\n"); return; } # If paragraphs printing is turned off via =begin/=end or whatver # simply return immediately return if $self->{_suppress_all_para}; # Check to see whether we are starting a new lists if (scalar($self->lists->[-1]->item) == 0) { # Examine the paragraph to determine what type of list # we have $paragraph =~ s/\s+$//; $paragraph =~ s/^\s+//; my $type; if (substr($paragraph, 0,1) eq '*') { $type = 'itemize'; } elsif ($paragraph =~ /^\d/) { $type = 'enumerate'; } else { $type = 'description'; } $self->lists->[-1]->type($type); $self->_output("\\begin{$type}\n"); } my $type = $self->lists->[-1]->type; if ($type eq 'description') { # Handle long items - long items do not wrap # If the string is longer than 40 characters we split # it into a real item header and some bold text. my $maxlen = 40; my ($hunk1, $hunk2) = $self->_split_delimited( $paragraph, $maxlen ); # Print the first hunk $self->_output("\n\\item[{$hunk1}] "); # and the second hunk if it is defined if ($hunk2) { $self->_output("\\textbf{$hunk2}"); } else { # Not there so make sure we have a new line $self->_output("\\mbox{}"); } } else { # If the item was '* Something' or '\d+ something' we still need to write # out the something. Also allow 1) and 1. my $extra_info = $paragraph; $extra_info =~ s/^(\*|\d+[\.\)]?)\s*//; $self->_output("\n\\item $extra_info"); } # Store the item name in the object. Required so that # we can tell if the list is new or not $self->lists->[-1]->item($paragraph);}=back=head2 Methods for headings=over 4=item B<head>Print a heading of the required level. $parser->head($level, $paragraph, $parobj);The first argument is the pod heading level. The second argumentis the contents of the heading. The 3rd argument is a Pod::Paragraphobject so that the line number can be extracted.=cutsub head { my $self = shift; my $num = shift; my $paragraph = shift; my $parobj = shift; # If we are replace 'head1 NAME' with a section # we return immediately if we get it return if ($self->{_CURRENT_HEAD1} =~ /^NAME/i && $self->ReplaceNAMEwithSection()); # Create a label my $label = $self->_create_label($paragraph); # Create an index entry my $index = $self->_create_index($paragraph); # Work out position in the above array taking into account # that =head1 is equivalent to $self->Head1Level my $level = $self->Head1Level() - 1 + $num; # Warn if heading to large if ($num > $#LatexSections) { my $line = $parobj->file_line; my $file = $self->input_file; warn "Heading level too large ($level) for LaTeX at line $line of file $file\n"; $level = $#LatexSections; } # Check to see whether section should be unnumbered my $star = ($level >= $self->LevelNoNum ? '*' : ''); # Section $self->_output("\\" .$LatexSections[$level] .$star ."{$paragraph\\label{".$label ."}\\index{".$index."}}\n");}=back=end __PRIVATE__=begin __PRIVATE__=head2 Internal methodsInternal routines are described in this section. They do not form part of thepublic interface. All private methods start with an underscore.=over 4=item B<_output>Output text to the output filehandle. This method must be always be calledto output parsed text. $parser->_output($text);Does not write anything if a =begin is active that should beignored.=cutsub _output { my $self = shift; my $text = shift; print { $self->output_handle } $text unless $self->{_suppress_all_para};}=item B<_replace_special_chars>Subroutine to replace characters that are special in C<latex>with the escaped forms $escaped = $parser->_replace_special_chars($paragraph);Need to call this routine before interior_sequences are munged but notif verbatim. It must be called before interpolation of interiorsequences so that curly brackets and special latex characters insertedduring interpolation are not themselves escaped. This means that < and> can not be modified here since the text still contains interiorsequences.Special characters and the C<latex> equivalents are: } \} { \{ _ \_ $ \$ % \% & \& \ $\backslash$ ^ \^{} ~ \~{} # \#=cutsub _replace_special_chars { my $self = shift; my $paragraph = shift; # Replace a \ with $\backslash$ # This is made more complicated because the dollars will be escaped # by the subsequent replacement. Easiest to add \backslash # now and then add the dollars $paragraph =~ s/\\/\\backslash/g; # Must be done after escape of \ since this command adds latex escapes # Replace characters that can be escaped $paragraph =~ s/([\$\#&%_{}])/\\$1/g; # Replace ^ characters with \^{} so that $^F works okay $paragraph =~ s/(\^)/\\$1\{\}/g; # Replace tilde (~) with \texttt{\~{}} $paragraph =~ s/~/\\texttt\{\\~\{\}\}/g; # Now add the dollars around each \backslash $paragraph =~ s/(\\backslash)/\$$1\$/g; return $paragraph;}=item B<_replace_special_chars_late>Replace special characters that can not be replaced before interiorsequence interpolation. See C<_replace_special_chars> for a routineto replace special characters prior to interpolation of interiorsequences.Does the following transformation: < $<$ > $>$ | $|$=cutsub _replace_special_chars_late { my $self = shift; my $paragraph = shift; # < and > $paragraph =~ s/(<|>)/\$$1\$/g; # Replace | with $|$ $paragraph =~ s'\|'$|$'g; return $paragraph;}=item B<_create_label>Return a string that can be used as an internal referencein a C<latex> document (i.e. accepted by the C<\label> command) $label = $parser->_create_label($string)If UniqueLabels is true returns a label prefixed by Label()This can be suppressed with an optional second argument. $label = $parser->_create_label($string, $suppress);If a second argument is supplied (of any value including undef)the Label() is never prefixed. This means that this routine canbe called to create a Label() without prefixing a previous setting.=cutsub _create_label { my $self = shift; my $paragraph = shift; my $suppress = (@_ ? 1 : 0 ); # Remove latex commands $paragraph = $self->_clean_latex_commands($paragraph); # Remove non alphanumerics from the label and replace with underscores # want to protect '-' though so use negated character classes $paragraph =~ s/[^-:\w]/_/g; # Multiple underscores will look unsightly so remove repeats # This will also have the advantage of tidying up the end and # start of string $paragraph =~ s/_+/_/g; # If required need to make sure that the label is unique # since it is possible to have multiple pods in a single # document if (!$suppress && $self->UniqueLabels() && defined $self->Label) { $paragraph = $self->Label() .'_'. $paragraph; } return $paragraph;}=item B<_create_index>Similar to C<_create_label> except an index entry is created.If C<UniqueLabels> is true, the index entry is prefixed by the current C<Label> and an exclamation mark. $ind = $parser->_create_index($paragraph);An exclamation mark is used by C<makeindex> to generate sub-entries in an index.=cutsub _create_index { my $self = shift; my $paragraph = shift; my $suppress = (@_ ? 1 : 0 ); # Remove latex commands $paragraph = $self->_clean_latex_commands($paragraph); # If required need to make sure that the index entry is unique # since it is possible to have multiple pods in a single # document if (!$suppress && $self->UniqueLabels() && defined $self->Label) { $paragraph = $self->Label() .'!'. $paragraph; } # Need to replace _ with space $paragraph =~ s/_/ /g; return $paragraph;}=item B<_clean_latex_commands>Removes latex commands from text. The latex command is assumed to be of theform C<\command{ text }>. "C<text>" is retained $clean = $parser->_clean_latex_commands($text);=cutsub _clean_latex_commands { my $self = shift; my $paragraph = shift; # Remove latex commands of the form \text{ } # and replace with the contents of the { } # need to make this non-greedy so that it can handle # "\text{a} and \text2{b}" # without converting it to # "a} and \text2{b" # This match will still get into trouble if \} is present # This is not vital since the subsequent replacement of non-alphanumeric # characters will tidy it up anyway $paragraph =~ s/\\\w+{(.*?)}/$1/g; return $paragraph}=item B<_split_delimited>Split the supplied string into two parts at approximately thespecified word boundary. Special care is made to make sure that itdoes not split in the middle of some curly brackets.e.g. "this text is \textbf{very bold}" would not be split into"this text is \textbf{very" and " bold". ($hunk1, $hunk2) = $self->_split_delimited( $para, $length);The length indicates the maximum length of hunk1.=cut# initially Supplied by hsmyers@sdragons.com# 10/25/01, utility to split \hbox# busting lines. Reformatted by TimJ to match module style.sub _split_delimited { my $self = shift; my $input = shift; my $limit = shift; # Return immediately if already small return ($input, '') if length($input) < $limit; my @output; my $s = ''; my $t = ''; my $depth = 0; my $token; $input =~ s/\n/ /gm; $input .= ' '; foreach ( split ( //, $input ) ) { $token .= $_; if (/\{/) { $depth++; } elsif ( /}/ ) { $depth--; } elsif ( / / and $depth == 0) { push @output, $token if ( $token and $token ne ' ' ); $token = ''; } } foreach (@output) { if (length($s) < $limit) { $s .= $_; } else { $t .= $_; } } # Tidy up $s =~ s/\s+$//; $t =~ s/\s+$//; return ($s,$t);}=back=end __PRIVATE__=head1 NOTESCompatible with C<latex2e> only. Can not be used with C<latex> v2.09or earlier.A subclass of C<Pod::Select> so that specific pod sections can beconverted to C<latex> by using the C<select> method.Some HTML escapes are missing and many have not been tested.=head1 SEE ALSOL<Pod::Parser>, L<Pod::Select>, L<pod2latex>=head1 AUTHORSTim Jenness E<lt>tjenness@cpan.orgE<gt>Bug fixes and improvements have been received from: Simon CozensE<lt>simon@cozens.netE<gt>, Mark A. HershbergerE<lt>mah@everybody.orgE<gt>, Marcel GrunauerE<lt>marcel@codewerk.comE<gt>, Hugh S MyersE<lt>hsmyers@sdragons.comE<gt>, Peter J AcklamE<lt>jacklam@math.uio.noE<gt>, Sudhi Herle E<lt>sudhi@herle.netE<gt>,Ariel Scolnicov E<lt>ariels@compugen.co.ilE<gt>,Adriano Rodrigues Ferreira E<lt>ferreira@triang.com.brE<gt> andR. de Vries E<lt>r.de.vries@dutchspace.nlE<gt>.=head1 COPYRIGHTCopyright (C) 2000-2004 Tim Jenness. All Rights Reserved.This program is free software; you can redistribute it and/or modifyit under the same terms as Perl itself.=begin __PRIVATE__=head1 REVISION$Id: LaTeX.pm,v 1.19 2004/12/30 01:40:44 timj Exp $=end __PRIVATE__=cut1;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -