From: Vincent Pit Date: Thu, 22 Jul 2010 22:31:18 +0000 (+0200) Subject: First cut at the documentation X-Git-Tag: v0.01~3 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FLaTeX-TikZ.git;a=commitdiff_plain;h=e6c6fbca8df4f8df7bbce2eb98dd260ed51d9141 First cut at the documentation --- diff --git a/lib/LaTeX/TikZ.pm b/lib/LaTeX/TikZ.pm index fc0c094..a754671 100644 --- a/lib/LaTeX/TikZ.pm +++ b/lib/LaTeX/TikZ.pm @@ -15,6 +15,44 @@ Version 0.01 our $VERSION = '0.01'; +=head1 SYNOPSIS + + use LaTeX::TikZ; + + # A couple of lines + my $hline = Tikz->line(-1 => 1); + my $vline = Tikz->line([ 0, -1 ] => [ 0, -1 ]); + + # Paint them in red + $_->mod(Tikz->color('red')) for $hline, $vline; + + # An octogon + use Math::Complex; + my $octo = Tikz->closed_polyline( + map Math::Complex->emake(1, ($_ * pi)/4), 0 .. 7 + ); + + # Only keep a portion of it + $octo->clip(Tikz->rectangle(-0.5*(1+i), 2*(1+i))); + + # Fill it with dots + $octo->mod(Tikz->pattern(class => 'Dots')); + + # Create a formatter object + my $tikz = Tikz->formatter; + + # Put those objects all together and print them + my $seq = Tikz->seq($octo, $hline, $vline); + my ($head, $decl, $body) = $tikz->render($seq); + print "$_\n" for map @$_, $head, $decl, $body; + +=head1 DESCRIPTION + +This module provides an object model for TikZ, a graphical tookit for LaTeX. +It allows you to build structures representing geometrical figures, apply a wide set of modifiers on them, transform them globally with functors, and print them in the context of an existing TeX document. + +=cut + use LaTeX::TikZ::Interface; sub import { @@ -40,6 +78,10 @@ sub import { return; } +=head1 SEE ALSO + +PGF/TikZ - L. + =head1 AUTHOR Vincent Pit, C<< >>, L. diff --git a/lib/LaTeX/TikZ/Formatter.pm b/lib/LaTeX/TikZ/Formatter.pm index efa7dc6..426263f 100644 --- a/lib/LaTeX/TikZ/Formatter.pm +++ b/lib/LaTeX/TikZ/Formatter.pm @@ -15,6 +15,12 @@ Version 0.01 our $VERSION = '0.01'; +=head1 DESCRIPTION + +A formatter object turns a L tree into the actual TikZ code, depending on some parameters such as the scale, the unit or the origin. + +=cut + use Sub::Name (); use LaTeX::TikZ::Point; @@ -26,40 +32,72 @@ use LaTeX::TikZ::Tools; use Any::Moose; use Any::Moose 'Util::TypeConstraints'; +=head1 ATTRIBUTES + +=head2 C + +=cut + has 'unit' => ( is => 'ro', isa => enum([ qw/cm pt/ ]), default => 'cm', ); +=head2 C + +=cut + has 'format' => ( is => 'ro', isa => 'Str', default => '%s', ); +=head2 C + +=cut + has 'scale' => ( is => 'rw', isa => 'Num', default => 1, ); +=head2 C + +=cut + has 'width' => ( is => 'rw', isa => 'Maybe[Num]', ); +=head2 C + +=cut + has 'height' => ( is => 'rw', isa => 'Maybe[Num]', ); +=head2 C + +=cut + has 'origin' => ( is => 'rw', isa => 'LaTeX::TikZ::Point::Autocoerce', coerce => 1, ); +=head1 METHODS + +=head2 C + +=cut + sub id { my $tikz = shift; @@ -76,6 +114,10 @@ sub id { } map($tikz->$_, qw/unit format scale width height/), $origin; } +=head2 C + +=cut + my $find_mods = do { our %seen; @@ -183,6 +225,10 @@ sub render { return \@header, \@decls, @bodies; } +=head2 C + +=cut + sub len { my ($tikz, $len) = @_; @@ -191,6 +237,10 @@ sub len { sprintf $tikz->format . $tikz->unit, $len * $tikz->scale; } +=head2 C + +=cut + sub angle { my ($tikz, $a) = @_; @@ -201,6 +251,10 @@ sub angle { sprintf $tikz->format, POSIX::ceil($a); } +=head2 C