Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Customizable environments

  • Loading branch information...
commit d97caa2346017e3fc6bc43326809bf2e2b927e2e 1 parent 60e92ac
@duelafn duelafn authored committed
Showing with 95 additions and 18 deletions.
  1. +52 −18 lib/Pod/PseudoPod/LaTeX.pm
  2. +37 −0 t/emit_environments.t
  3. +6 −0 t/test_file.pod
View
70 lib/Pod/PseudoPod/LaTeX.pm
@@ -24,6 +24,15 @@ sub new
return $self;
}
+sub emit_environments
+{
+ my ( $self, %env ) = @_;
+ for ( keys %env )
+ {
+ $self->{emit_environment}->{$_} = $env{$_};
+ }
+}
+
sub end_Document
{
my $self = shift;
@@ -505,30 +514,48 @@ sub start_item_text
sub start_sidebar
{
my ( $self, $flags ) = @_;
- $self->{scratch} .= "\\begin{figure}[!h]\n"
- . "\\begin{center}\n"
- . "\\framebox{\n"
- . "\\begin{minipage}{3.5in}\n"
- . "\\vspace{3pt}\n\n";
+ my $title;
+ $title = $self->encode_text( $flags->{title} ) if $flags->{title};
- if ( $flags->{title} )
+ if ( $self->{emit_environment}->{sidebar} )
{
- my $title = $self->encode_text( $flags->{title} );
- $self->{scratch} .= "\\begin{center}\n"
- . "\\large{\\bfseries{" . $title . "}}\n"
- . "\\end{center}\n\n";
+ $self->{scratch} .= "\\begin{" . $self->{emit_environment}->{sidebar} . "}";
+ $self->{scratch} .= "[$title]" if $title;
+ $self->{scratch} .= "\n";
+ }
+ else
+ {
+ $self->{scratch} .= "\\begin{figure}[!h]\n"
+ . "\\begin{center}\n"
+ . "\\framebox{\n"
+ . "\\begin{minipage}{3.5in}\n"
+ . "\\vspace{3pt}\n\n";
+
+ if ( $title )
+ {
+ $self->{scratch} .= "\\begin{center}\n"
+ . "\\large{\\bfseries{" . $title . "}}\n"
+ . "\\end{center}\n\n";
+ }
}
}
sub end_sidebar
{
my $self = shift;
- $self->{scratch} .= "\\vspace{3pt}\n"
- . "\\end{minipage}\n"
- # end framebox
- . "}\n"
- . "\\end{center}\n"
- . "\\end{figure}\n";
+ if ( $self->{emit_environment}->{sidebar} )
+ {
+ $self->{scratch} .= "\\end{" . $self->{emit_environment}->{sidebar} . "}\n\n";
+ }
+ else
+ {
+ $self->{scratch} .= "\\vspace{3pt}\n"
+ . "\\end{minipage}\n"
+ # end framebox
+ . "}\n"
+ . "\\end{center}\n"
+ . "\\end{figure}\n";
+ }
}
BEGIN
@@ -593,13 +620,12 @@ Perhaps a little code snippet.
use Pod::PseudoPod::LaTeX;
my $parser = Pod::PseudoPod::LaTeX->new();
+ $parser->emit_environments( sidebar => 'sidebar' );
$parser->output_fh( $some_fh );
$parser->parse_file( 'some_document.pod' );
...
-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.
@@ -614,6 +640,14 @@ variants of its monospace font, an alternative is
\usepackage{textcomp}
\usepackage[scaled]{beramono}
+=head1 STYLES / EMITTING ENVIRONMENTS
+
+The C<emit_environments> method accepts a hashref whose keys are POD environments
+and values are latex environments. Use this method if you would like
+C<Pod::PseudoPod::LaTeX> to emit a simple C<\begin{foo}...\end{foo}> environment
+rather than emit specific formatting codes. You must define any environemtns you
+use in this way in your latex prelude.
+
=head1 AUTHOR
chromatic, C<< <chromatic at wgz.org> >>
View
37 t/emit_environments.t
@@ -0,0 +1,37 @@
+#! perl
+
+use strict;
+use warnings;
+
+use IO::String;
+use File::Spec::Functions;
+
+use Test::More tests => 4;
+
+use_ok( 'Pod::PseudoPod::LaTeX' ) or exit;
+
+my $fh = IO::String->new();
+my $parser = Pod::PseudoPod::LaTeX->new();
+$parser->output_fh( $fh );
+$parser->parse_file( catfile( qw( t test_file.pod ) ) );
+
+$fh->setpos(0);
+my $text = join( '', <$fh> );
+
+like( $text, qr/\\vspace{3pt}\s*Hello, this is a sidebar/,
+ 'Emit formatting code when emit_environment option not set' );
+
+unlike( $text, qr/\\(?:begin|end){A?sidebar}/,
+ 'No sidebar environemnt whatsoever when emit_environment option not set' );
+
+$fh = IO::String->new();
+$parser = Pod::PseudoPod::LaTeX->new();
+$parser->emit_environments( sidebar => 'Asidebar' );
+$parser->output_fh( $fh );
+$parser->parse_file( catfile( qw( t test_file.pod ) ) );
+
+$fh->setpos(0);
+$text = join( '', <$fh> );
+
+like( $text, qr/\\begin{Asidebar}\s*Hello, this is a sidebar\s*\\end{Asidebar}/,
+ 'Emit abstract \begin{foo} when emit_environment option is set' );
View
6 t/test_file.pod
@@ -47,6 +47,12 @@ Diacritics are more difficult E<aacute> la the naE<iuml>ve attachE<egrave> and
the E<copy> caper, E<plusmn> some constant. FranE<ccedilla>aise has some fun
ones.
+=for sidebar
+
+Hello, this is a sidebar
+
+=end
+
X<Special formatting> is B<very> important, especially in C<code-like text>,
for special F<emphasis>, and I<semantic-only emphasis>N<but beware of
footnotes!>.
Please sign in to comment.
Something went wrong with that request. Please try again.