]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blob - lib/LaTeX/TikZ.pm
First cut at the documentation
[perl/modules/LaTeX-TikZ.git] / lib / LaTeX / TikZ.pm
1 package LaTeX::TikZ;
2
3 use strict;
4 use warnings;
5
6 =head1 NAME
7
8 LaTeX::TikZ - Perl object model for generating PGF/TikZ code.
9
10 =head1 VERSION
11
12 Version 0.01
13
14 =cut
15
16 our $VERSION = '0.01';
17
18 =head1 SYNOPSIS
19
20     use LaTeX::TikZ;
21
22     # A couple of lines
23     my $hline = Tikz->line(-1 => 1);
24     my $vline = Tikz->line([ 0, -1 ] => [ 0, -1 ]);
25
26     # Paint them in red
27     $_->mod(Tikz->color('red')) for $hline, $vline;
28
29     # An octogon
30     use Math::Complex;
31     my $octo = Tikz->closed_polyline(
32      map Math::Complex->emake(1, ($_ * pi)/4), 0 .. 7
33     );
34
35     # Only keep a portion of it
36     $octo->clip(Tikz->rectangle(-0.5*(1+i), 2*(1+i)));
37
38     # Fill it with dots
39     $octo->mod(Tikz->pattern(class => 'Dots'));
40
41     # Create a formatter object
42     my $tikz = Tikz->formatter;
43
44     # Put those objects all together and print them
45     my $seq = Tikz->seq($octo, $hline, $vline);
46     my ($head, $decl, $body) = $tikz->render($seq);
47     print "$_\n" for map @$_, $head, $decl, $body;
48
49 =head1 DESCRIPTION
50
51 This module provides an object model for TikZ, a graphical tookit for LaTeX.
52 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.
53
54 =cut
55
56 use LaTeX::TikZ::Interface;
57
58 sub import {
59  shift;
60
61  my %args = @_;
62  my $name = $args{as};
63  $name = 'Tikz' unless defined $name;
64  unless ($name =~ /^[a-z_][a-z0-9_]*$/i) {
65   require Carp;
66   Carp::confess('Invalid name');
67  }
68
69  my $pkg   = caller;
70  my $const = sub () { 'LaTeX::TikZ::Interface' };
71  {
72   no strict 'refs';
73   *{$pkg . '::' . $name} = $const;
74  }
75
76  LaTeX::TikZ::Interface->load;
77
78  return;
79 }
80
81 =head1 SEE ALSO
82
83 PGF/TikZ - L<http://pgf.sourceforge.net>.
84
85 =head1 AUTHOR
86
87 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
88
89 You can contact me by mail or on C<irc.perl.org> (vincent).
90
91 =head1 BUGS
92
93 Please report any bugs or feature requests to C<bug-latex-tikz at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=LaTeX-TikZ>.
94 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
95
96 =head1 SUPPORT
97
98 You can find documentation for this module with the perldoc command.
99
100     perldoc LaTeX::TikZ
101
102 =head1 COPYRIGHT & LICENSE
103
104 Copyright 2010 Vincent Pit, all rights reserved.
105
106 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
107
108 =cut
109
110 1; # End of LaTeX::TikZ