Skip to content

Commit

Permalink
implement markup in verbatim environments
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz authored and chromatic committed Apr 16, 2010
1 parent f5e60f6 commit 8203ae0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -3,6 +3,7 @@ Revision history for Pod-PseudoPod-LaTeX
{{$NEXT}}
- migrated build system to Dist::Zilla
- corrected escaping of the caret (^) character; closes [CPAN #50794]
- implemented markup in verbatim environments

1.000 Fri Aug 14 02:07:38 UTC 2009
- added modifications from the Parrot PIR book
Expand Down
31 changes: 28 additions & 3 deletions lib/Pod/PseudoPod/LaTeX.pm
Expand Up @@ -46,7 +46,7 @@ sub encode_text
{
my ( $self, $text ) = @_;

return $text if $self->{flags}{in_verbatim};
return $self->encode_verbatim_text($text) if $self->{flags}{in_verbatim};
return $text if $self->{flags}{in_xref};
return $text if $self->{flags}{in_figure};

Expand Down Expand Up @@ -81,6 +81,17 @@ sub encode_text
return $text;
}

# in verbatim mode, some things still need escaping - otherwise markup
# wouldn't work when the codes_in_verbatim option is enabled.
sub encode_verbatim_text {
my ($self, $text) = @_;

$text =~ s/([{}])/\\$1/g;
$text =~ s/\\(?![{}])/\\textbackslash{}/g;

return $text;
}

sub start_head0
{
my $self = shift;
Expand Down Expand Up @@ -278,14 +289,14 @@ sub start_Verbatim
# $self->{scratch} .= "\\addtolength{\\parskip}{-5pt}\n";
$self->{scratch} .= "\\vspace{-6pt}\n"
. "\\scriptsize\n"
. "\\begin{verbatim}\n";
. "\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n";
$self->{flags}{in_verbatim}++;
}

sub end_Verbatim
{
my $self = shift;
$self->{scratch} .= "\\end{verbatim}\n"
$self->{scratch} .= "\n\\end{Verbatim}\n"
. "\\vspace{-6pt}\n";

# $self->{scratch} .= "\\addtolength{\\parskip}{5pt}\n";
Expand Down Expand Up @@ -567,6 +578,20 @@ Perhaps a little code snippet.
There aren't really any user-servicable parts inside.
=head1 LATEX PRELUDE
The generated LaTeX code needs some packages to be loaded to work correctly.
Currently it needs
\usepackage{fancyvrb}
The standard font in LaTeX (Computer Modern) does not support bold and italic
variants of its monospace font, an alternative is
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage[scaled]{beramono}
=head1 AUTHOR
chromatic, C<< <chromatic at wgz.org> >>
Expand Down
2 changes: 1 addition & 1 deletion t/sections.t
Expand Up @@ -30,7 +30,7 @@ like( $text, qr/\\subsection\*{B heading}/,
like( $text, qr/\\subsubsection\*{c heading}/,
'C heads should become subsubsection titles' );

like( $text, qr/\\begin{verbatim}.+"This text.+--.+\$text."\\end{verbatim}/s,
like( $text, qr/\\begin{Verbatim}.+"This text.+--.+\$text."\n\\end{Verbatim}/s,
'programlistings should become unescaped, verbatim text' );

like( $text, qr/Blockquoted text.+``escaped''\./,
Expand Down

0 comments on commit 8203ae0

Please sign in to comment.