X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FLaTeX%2FTikZ.pm;h=b035f0068ae6c5047748acd569dfd003cf3050c4;hb=0d5ae2762e7ad488479169d1df3be89d23a3b190;hp=c91ea8ca8dd341f80513185481b625d9ecda4dbc;hpb=c872d62c868ae84bbfe6f6abe6210920cd10c9fd;p=perl%2Fmodules%2FLaTeX-TikZ.git diff --git a/lib/LaTeX/TikZ.pm b/lib/LaTeX/TikZ.pm index c91ea8c..b035f00 100644 --- a/lib/LaTeX/TikZ.pm +++ b/lib/LaTeX/TikZ.pm @@ -9,11 +9,11 @@ LaTeX::TikZ - Perl object model for generating PGF/TikZ code. =head1 VERSION -Version 0.01 +Version 0.02 =cut -our $VERSION = '0.01'; +our $VERSION = '0.02'; =head1 SYNOPSIS @@ -21,7 +21,7 @@ our $VERSION = '0.01'; # A couple of lines my $hline = Tikz->line(-1 => 1); - my $vline = Tikz->line([ 0, -1 ] => [ 0, -1 ]); + my $vline = Tikz->line([ 0, -1 ] => [ 0, 1 ]); # Paint them in red $_->mod(Tikz->color('red')) for $hline, $vline; @@ -39,7 +39,7 @@ our $VERSION = '0.01'; $octo->mod(Tikz->pattern(class => 'Dots')); # Create a formatter object - my $tikz = Tikz->formatter; + my $tikz = Tikz->formatter(scale => 5); # Put those objects all together and print them my $seq = Tikz->seq($octo, $hline, $vline); @@ -48,33 +48,33 @@ our $VERSION = '0.01'; =head1 DESCRIPTION -This module provides an object model for TikZ, a graphical tookit for LaTeX. +This module provides an object model for TikZ, a graphical toolkit 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. =head1 CONCEPTS -Traditionnaly, in TikZ, there are two ways of grouping elements, or I, together : +Traditionally, in TikZ, there are two ways of grouping paths together : =over 4 =item * -either as a I, where each element is drawn in its own line : +either as a I, where each path is drawn in its own line : \draw (0cm,0cm) -- (0cm,1cm) ; \draw (0cm,0cm) -- (1cm,0cm) ; =item * -or as a I, where elements are all drawn as one line : +or as an I, where paths are all drawn as one line : \draw (0cm,0cm) -- (0cm,1cm) (0cm,0cm) -- (1cm,0cm) ; =back -This distinction is important because there are some primitves that only apply to paths but not to sequences, and vice versa. +This distinction is important because there are some primitives that only apply to paths but not to sequences, and vice versa. -Figures are made of ops, path or sequence I assembled together in a tree. +Figures are made of path or sequence I assembled together in a tree. I can be applied onto any set to alter the way in which it is generated. The two TikZ concepts of I and I have been unified with the modifiers. @@ -83,12 +83,12 @@ The two TikZ concepts of I and I have been unified with the modif =head2 Containers -=head3 C<< Tikz->path(@ops) >> +=head3 C<< Tikz->union(@seq) >> -Creates a L object out of the ops C<@ops>. +Creates a L object out of the paths C<@kids>. # A path made of two circles - Tikz->path( + Tikz->union( Tikz->circle(0, 1), Tikz->circle(1, 1), ) @@ -97,9 +97,26 @@ Creates a L object out of the ops C<@ops>. 'even odd rule', ); +=head3 C<< Tikz->join($connector, @kids) >> + +Creates a L object that joins the paths C<@kinds> with the given C<$connector> which can be, according to L, a string, an array reference or a code reference. + + # A stair + Tikz->join('-|', map [ $_, $_ ], 0 .. 5); + +=head3 C<< Tikz->chain($kid0, $link0, $kid1, $link1, ... $kidn) >> + +Creates a L object that chains C<$kid0> to C<$kid1> with the string C<$link0>, C<$kid1> to C<$kid2> with C<$link1>, and so on. + + # An heart-like shape + Tikz->chain([ 0, 1 ] + => '.. controls (-1, 1.5) and (-0.75, 0.25) ..' => [ 0, 0 ] + => '.. controls (0.75, 0.25) and (1, 1.5) ..' => [ 0, 1 ] + ); + =head3 C<< Tikz->seq(@kids) >> -Creates a L object out of the sequences, paths or ops C<@kids>. +Creates a L object out of the sequences or paths C<@kids>. my $bag = Tikz->seq($sequence, $path, $circle, $raw, $point); @@ -146,7 +163,7 @@ If C<$point> is a L object, the L by writing your own L class. +You can define automatic coercions from your user point types to L by writing your own C class. See L for the rationale and L for an example. =head3 C<< Tikz->line($from => $to) >> @@ -169,7 +186,7 @@ Creates a L object that links the successive element =head3 C<< Tikz->closed_polyline(@points) >> -Creates a L object that cycles through successive eleemnts of C<@points>. +Creates a L object that cycles through successive elements of C<@points>. my $diamond = Tikz->closed_polyline( Tikz->point(0, 1), @@ -243,7 +260,7 @@ Creates a L object with name C<$name> and optional rela The default layer is C
. -Layers are stored into a global hash, so that when you refer to them by their name, you get the existing layer object. +Layers are stored into a global hash, so that when you refer to them by their name, you get the existing layer object. Layers can also be directly applied to sets with the C<< ->layer >> method. @@ -251,6 +268,13 @@ Layers can also be directly applied to sets with the C<< ->layer >> method. ->mod(Tikz->pattern(class => 'Dots')) ->layer('top'); +=head3 C<< Tikz->scale($factor) >> + +Creates a L object that scales the sets onto which it apply by the given C<$factor>. + + my $circle_of_radius_2 = Tikz->circle(0 => 1) + ->mod(Tikz->scale(2)); + =head3 C<< Tikz->width($line_width) >> Creates a L object that sets the line width to C<$line_width> when applied. @@ -260,7 +284,7 @@ Creates a L object that sets the line width to C<$line_ =head3 C<< Tikz->color($color) >> -Creates a Lobject that sets the line color to C<$color> (given in the C syntax). +Creates a L object that sets the line color to C<$color> (given in the C syntax). # Paint the previous $thick_arrow in red. $thick_arrow->mod(Tikz->color('red')); @@ -300,7 +324,7 @@ Creates a L object that can render a L =head3 C<< Tikz->functor(@rules) >> Creates a L anonymous subroutine that can be called against L trees to clone them according to the given rules. -C<@rules> should be made of array references whose first element is the class/role to match against and the second the handler to run. +C<@rules> should be a list of array references whose first element is the class/role to match against and the second the handler to execute. # The default is a clone method my $clone = Tikz->functor; @@ -325,7 +349,7 @@ C<@rules> should be made of array references whose first element is the class/ro # A mod stripper my $strip = Tikz->functor( - 'LaTeX::TikZ::Mod' => sub { return }, + '+LaTeX::TikZ::Mod' => sub { return }, ); my $naked = $set->$strip; @@ -358,12 +382,10 @@ sub import { =head1 DEPENDENCIES -L with L 0.63 or greater. +L with L 0.80 or greater. L. -L. - L, L. L, L, L.