File: tikz.rules

package info (click to toggle)
polymake 3.0r2-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 19,752 kB
  • ctags: 30,928
  • sloc: cpp: 151,785; perl: 32,510; ansic: 3,597; java: 2,654; python: 278; makefile: 181; xml: 103; sh: 79
file content (250 lines) | stat: -rw-r--r-- 6,368 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#  Copyright (c) 1997-2015
#  Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
#  http://www.polymake.org
#
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by the
#  Free Software Foundation; either version 2, or (at your option) any
#  later version: http://www.gnu.org/licenses/gpl.txt.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#-------------------------------------------------------------------------------


package TikZ;

CREDIT tikz
  TikZ, a graphical toolkit for LaTeX.
  http://pgf.sourceforge.net.
  
# pdflatex executable
custom $pdflatex;

# pdf viewer
custom $pdfviewer;

CONFIGURE_OPT {
   find_program($pdflatex, qw( pdflatex ), { prompt => "the PDFLaTeX executable" });
   find_program($pdfviewer, qw( evince acroread xpdf ), { prompt => "executable of some PDF viewer" });
}


package TikZ::default;

# coordinates of the viewpoint
custom @view_point=(10,11,9);

# coordinates of a point on the view axis: default is the origin
custom @view_direction=(0,0,0);

# camera orientation: default is y-axis towards zenith
custom @view_up=(0,1,0);

# scaling factor
custom $scale=2;


package TikZ::Viewer;

use TikZ;
use BackgroundViewer;
use Visual::Transformation;

# The default behavior is to produce a LaTeX output, then call PDFLaTeX
# and finally a PDF viewer.

use Polymake::Struct [ '@ISA' => 'SimpleViewer' ];

sub file_suffix { ".tikz" }

sub new {
   unless (defined($pdflatex) && defined($pdfviewer)) {
      die <<'.';
requires PDFLaTeX and a PDF viewer;
please specify the output File option or call reconfigure("common::tikz.rules");
.
   }
   my $self = &_new;
   $self->tempfile->descend_dir();
   $self;
}

sub command {
   my ($self, $filename)=@_;
   my $latextemplate = $self->tempfile.".tex";
   open my $fh, ">", $latextemplate;
   print $fh write_latextemplate("$filename");
   
   my $pdfout = $self->tempfile.".pdf";
   my $pdfout_dir = $self->tempfile->dir;
   my $pdfout_name = $self->tempfile->basename;
   "$pdflatex --output-directory=$pdfout_dir --jobname=$pdfout_name $latextemplate 1>/dev/null ; $pdfviewer $pdfout 1>/dev/null 2>/dev/null";
}

sub new_drawing {
   my ($self, $title, $vis)=@_;
   $self->SUPER::new_drawing($title);
   if (defined (my $rep=$vis->representative)) {
      $self->graphics->transform=Visual::Transformation->get_transformation_matrix($rep);
   }
   $self;
}

sub append {
   my $self=shift;
   $self->graphics->append(@_);
}

sub write_latextemplate_old {
my $tikzfilename=shift;
my $text = <<'|';
%
%---------------------------------------------------------------------------------
%
% Polymake LaTeX template for TikZ-Output
% Copyright (c) 1997-2015
% Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
% http://www.polymake.org
\documentclass[12pt]{article}
\usepackage[x11names,rgb]{xcolor}
\usepackage{tikz}
\usepackage{ifthen}
\usepackage{amsmath}

\usetikzlibrary{3d}
\usetikzlibrary{snakes}
\usetikzlibrary{arrows}
\usetikzlibrary{shapes}
\usetikzlibrary{backgrounds}

\pagestyle{empty}

\usepackage[papersize={640pt, 480pt}, margin=0pt, marginratio=1:1]{geometry}

\newsavebox{\tikzoutput}
\savebox{\tikzoutput}{
|
    $text .= "\\input{$tikzfilename}\n";
$text .= <<'|';
}
\newlength{\scaledwidth}
\settowidth{\scaledwidth}{\resizebox{!}{400pt}{\usebox{\tikzoutput}}}

\begin{document}
|
#\rlap{\smash{\raisebox{-2.5\baselineskip}{\includegraphics[height=3\baselineskip]{%
#  $text .= $InstallTop."/resources/logo/png/logo.png";
#}} }}
#\vspace*{37.5pt}
$text .=<<'|';
\centering
\ifthenelse{\lengthtest{\scaledwidth < 500pt}}{
  \resizebox{!}{400pt}{\usebox{\tikzoutput}}
}{
  \resizebox{500pt}{!}{\usebox{\tikzoutput}}
}
\end{document}
|
return $text;
}

sub write_latextemplate {

my $tikzfilename=shift;
my $text = <<'|';
%
%---------------------------------------------------------------------------------
%
% Polymake LaTeX template for TikZ-Output
% Copyright (c) 1997-2015
% Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
% http://www.polymake.org
\documentclass[tikz,x11names,border=10pt]{standalone}

\usetikzlibrary{3d}
\usetikzlibrary{snakes}
\usetikzlibrary{arrows}
\usetikzlibrary{shapes}
\usetikzlibrary{backgrounds}

\begin{document}
|
    $text .= "\\input{$tikzfilename}\n";
    $text .= <<'|';
\end{document}
|
return $text;
}


# @category Visualization
# Create a tikz drawing, write it to a file suitable for LaTeX.
label tikz

# The following are rarely used.
# Much more common are the methods in apps/{graph,polytope,...}/rules/tikz.rules

global_method tikz.geometry: draw(Visual::PointSet, @) {
   my ($self, $PointSet)=@_;
   $self->append(new TikZ::PointSet($PointSet));
}

global_method tikz.geometry: draw(Visual::Wire, @) {
   my ($self, $G)=@_;
   $self->append(new TikZ::Wire($G));
}

global_method tikz.geometry: draw(Visual::Polygon, @) {
   my ($self, $P)=@_;
   $self->append(new TikZ::Solid($P));
}

global_method tikz.geometry: draw(Visual::Polygons, @) {
   my ($self, $P)=@_;
   $self->append(new TikZ::Solid($P));
}


package TikZ::File::Writer;
import Visual::FileWriter;

sub file_suffix { ".tikz" }

sub new_drawing {
   my ($self, $title, $vis)=@_;
   if (defined (my $rep=$vis->representative)) {
      $self->graphics->transform=Visual::Transformation->get_transformation_matrix($rep);
   }
   $self->title=$title;
   $self;
}

sub DESTROY { }


package application;

# @Category Visualization
# Produce a TikZ file with given visual objects.
# @param Visual::Object vis_obj object to display
#
# @option String File "filename" or "AUTO"
#
#  For the file name you can use any expression allowed for the ''open'' function,
#  including "-" for terminal output, "&HANDLE" for an already opened file handle,
#  or "| program" for a pipe.  Real file names are automatically completed with the ''.tikz'' suffix if needed.
#
#  An automatically generated file name is displayed in the verbose mode.

user_function tikz(Visual::Object+, { File => undef }) {
   visualize_explicit(@_, "TikZ");
}


# Local Variables:
# mode: perl
# cperl-indent-level:3
# End: