CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

| Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

Views: 418346
1
2
4 Visualization of the pictures created
3
4
This chapter describes two easy ways to visualize the images created by
5
using the IntPic package. Both require LaTeX and some LaTeX packages, such
6
as Tikz and pgf, to be installed and working. One of the ways we will
7
describe is almost completely automatic. It makes use of the function
8
Splash, borrowed from the Viz package. The other is not so automatic but has
9
the advantage of not requiring other packages, besides the LaTeX ones, and
10
should work in any operation system.
11
12
13
4.1 Viewing using Viz
14
15
Producing and displaying a picture from a tikz string tkz may me achieved in
16
a simple way. (Warning: extenvive tests have only been done with Linux.) One
17
just have to type the following:
18
19
 IP\_Splash 
20
IP_Splash(tkz);
21

22
23
A picture is popped up after this use of the function IP_Splash.. To see the
24
name of the temporary directory created to perform the computations, and
25
thus being able to copy the files involved to any other place, one should
26
set the info level InfoViz to 1 or more. The following example illustrates
27
this and the use of some options of the function IP_Splash. For instance,
28
the pdf viewer can be changed.
29
30
 infoviz: temporary directory 
31
gap> SetInfoLevel(InfoViz,1);
32
gap> IP_Splash(tkz,rec(viewer:="okular")); 
33
#I The temporary directory used is: /tmp/tmJcpphI/
34

35
36
The temporary directory /tmp/tmJcpphI/ contains the file and vizpicture.tex.
37
The file vizpicture.tex is the LaTeX document to be processed. Other files,
38
namely the vizpicture.pdf are created by the pdflatex command that is called
39
by the IP_Splash function.
40
41
Warning: In the case of large pictures, it may happen the LaTeX memory being
42
exceeded. In this case, no image is produced and the user is not warned.
43
44
45
4.2 Viewing without using Viz
46
47
This section describes a way to visualize images without sing Viz. Besides
48
being useful in the case of not having a working copy of Viz, it is rather
49
convenient when the decision of where to save the pictures is made. In this
50
case, you may start your gap session in the desired place, the working
51
directory. Furthermore, if your intention is, for instance, to include the
52
images in a document, you may just decide the name for the file containing
53
the tikz code and let your document input it. The glogal variables
54
IP_Preamble and Closing can be used to pruduce a complete LaTeX document
55
rather than only the tizk code for the picture. The document may then be
56
processed by using pdflatex and the picture viewed by using some pdf viewer.
57
The pdf produced can be included in a LaTeX document instead of the tizk
58
code. In the later case, the code is processed each time the document is
59
processed, which should perhaps be avoided in the case of large images.
60
61
Note the use of the preview package, which is used to produce the complete
62
picture without having to pay attention to the paper size nor to crop the
63
image. It is useful for viewing purposes and also to include the pdf file
64
produced in a LaTeX document to be processed with pdflatex.
65
66
 Preamble 
67
gap> Print(IP_Preamble);
68
\documentclass{minimal}
69
\usepackage{amsmath}
70
\usepackage[active,tightpage]{preview}
71
\setlength\PreviewBorder{1pt}
72
\usepackage{pgf}
73
\usepackage{tikz}
74
\usepgfmodule{plot}
75
\usepgflibrary{plothandlers}
76
\usetikzlibrary{shapes.geometric}
77
\usetikzlibrary{shadings}
78
\begin{document}
79
\begin{preview}
80

81
82
 Closing 
83
gap> Print(IP_Closing);
84
\end{preview}
85
\end{document}
86

87
88
89
4.2-1 A complete example
90
91
Admit you want to produce a document which contains the picture
92
corresponding to the tikz code obtained through the instructions
93
94
 instructions to obtain some tikz code 
95
arr := [[1,2,3,4,5,6],[1,2,3,4,5],[1,2,3,4],[1,2,3],[1,2],[1]];;
96
tkz := IP_TikzArrayOfIntegers([1..10],5,rec(highlights:=arr));;
97

98
99
The picture is: The elements of the set [1,2,3,4,5,6] are highlighted using
100
the first color (red); those of the set [1,2,3,4,5] are highlighted using
101
the second color (green); those of the set [1,2,3,4] are highlighted using
102
the third color (blue); those of the set [1,2,3] are highlighted using the
103
fourth color (cyan); those of the set [1,2] are highlighted using the fifth
104
color (magenta); those of the set [1] is highlighted using the sixth color
105
(yellow).
106
107
Let us explain how the six colors used for the cell containing 1 are
108
distributed: upper left corner -- red; upper right corner -- green; lower
109
left corner -- blue; lower right corner -- cyan; the number -- magenta; the
110
border -- yellow.
111
112
The colors of the cell containing 2 and 3 are distributed in a similar way.
113
114
The colors of the cell containing 4: left -- red; middle -- blue; right --
115
green.
116
117
After the session listed below, the files tikz_pic_for_complete_document.tex
118
and pic_for_complete_document.tex have been created in the current directory
119
(that is, the one where the GAP session has started). For other directories,
120
complete paths may have to be given.
121
122
 the GAP session 
123
gap> tikzfile := "tikz_pic_for_complete_document.tex";;
124
gap> file := "pic_for_complete_document.tex";;
125
gap> 
126
gap> arr := [[1,2,3,4,5,6],[1,2,3,4,5],[1,2,3,4],[1,2,3],[1,2],[1]];;
127
gap> tkz := IP_TikzArrayOfIntegers([1..10],5,rec(highlights:=arr));;
128
gap> 
129
gap> FileString(tikzfile,tkz);
130
642
131
gap> FileString(file,Concatenation(IP_Preamble,tkz,IP_Closing));
132
961
133

134
135
Executing something like
136
137
 the pdf and the jpg of the picture 
138
pdflatex pic_for_complete_document.tex
139
convert pic_for_complete_document.pdf pic_for_complete_document.jpg
140

141
142
the pdf and the jpg formats of the image have been created. The jpg format
143
is usefull to be included into an html document, for instance.
144
145
Note that the tikz code has been saved into the file
146
tikz_pic_for_complete_document.tex. A complete example of a LaTeX document
147
follows.
148
149
 a LaTeX document 
150
\documentclass{article}
151
\usepackage{amsmath}
152
%\usepackage[active,tightpage]{preview}
153
%\setlength\PreviewBorder{1pt}
154
\usepackage{pgf}
155
\usepackage{tikz}
156
\usepgfmodule{plot}
157
\usepgflibrary{plothandlers}
158
\usetikzlibrary{shapes.geometric}
159
\usetikzlibrary{shadings}
160
\usepackage{graphicx}
161
\author{Author}
162
\title{How to include images in a \LaTeX\ document}
163
\date{June, 2013}
164
\begin{document}
165
%\begin{preview}
166
\maketitle
167
Using the pdf file:
168

169
\begin{center}
170
 \includegraphics[width=0.80\textwidth]{../images/pic_for_complete_document.pdf}
171
\end{center}
172

173
Using the PGF/TikZ code:
174

175
\begin{center}
176
\input{../images/tikz_pic_for_complete_document.tex}
177
\end{center}
178
If you want to scale this immage, please chang the ``scale'' in the file
179
\textt{tikz_pic_for_complete_document.tex} 
180
%\end{preview}
181
\end{document}
182

183
184
The output, after processing with pdflatex is as follows:
185
186
187
4.3 Other examples of use of the IntPic package
188
189
190
4.3-1 Varia
191
192
The following example shows how to produce tikz code for a picture
193
containing the odd integers from 801 to 999. Each line (except the highest)
194
contains 15 cells.
195
196
 Example 
197
gap> rg := Filtered([801..889],u->(u mod 2)<>0);;
198
gap> flen := 15;;
199
gap> twins := Filtered(Primes, p -> p + 2 in Primes);;
200
gap> arr := [Primes,Union(twins,twins+2),Filtered(rg,u->(u mod 3)=0)];;
201
gap> tkz := IP_TikzArrayOfIntegers(rg,flen,rec(highlights:=arr));;
202

203
204
The picture obtained highlights the primes, the twin primes and the
205
multiples of 3. As the twins are also primes, a gradient is used to
206
highlight them. In this example the default list of colors is used. The same
207
computations, but defining other color lists.
208
209
 Example 
210
gap> cls := IP_ColorsCompRedTones;;
211
gap> rg := Filtered([801..889],u->(u mod 2)<>0);;
212
gap> flen := 15;;
213
gap> twins := Filtered(Primes, p -> p + 2 in Primes);;
214
gap> arr := [Primes,Union(twins,twins+2),Filtered(rg,u->(u mod 3)=0)];;
215
gap> tkz := IP_TikzArrayOfIntegers(rg,flen,rec(colors := cls,highlights:=arr));;
216

217
218
 Example 
219
gap> cls := IP_ColorsDGrayTones;;
220
gap> rg := Filtered([801..889],u->(u mod 2)<>0);;
221
gap> flen := 15;;
222
gap> twins := Filtered(Primes, p -> p + 2 in Primes);;
223
gap> arr := [Primes,Union(twins,twins+2),Filtered(rg,u->(u mod 3)=0)];;
224
gap> tkz := IP_TikzArrayOfIntegers(rg,flen,rec(colors := cls,highlights:=arr));;
225

226
227
 Example 
228
gap> cls := ["blue","-blue","black"];;
229
gap> rg := Filtered([801..889],u->(u mod 2)<>0);;
230
gap> flen := 15;;
231
gap> twins := Filtered(Primes, p -> p + 2 in Primes);;
232
gap> arr := [Primes,Union(twins,twins+2),Filtered(rg,u->(u mod 3)=0)];;
233
gap> tkz := IP_TikzArrayOfIntegers(rg,flen,rec( colors := cls,highlights:=arr));;
234

235
236
The following example uses the NumericalSgps package.
237
238
 Example 
239
gap> #LoadPackage("numericalsgps");
240
gap> 
241
gap> ns := NumericalSemigroup(11,19,30,42,59);;
242
gap> cls := ShuffleIP_Colors([IP_ColorsGreenTones,IP_ColorsCompBlueTones]);;
243
gap> flen := 20;;
244
gap> #some notable elements
245
gap> arr := [SmallElementsOfNumericalSemigroup(ns),
246
>  GapsOfNumericalSemigroup(ns),
247
>  MinimalGeneratingSystemOfNumericalSemigroup(ns),
248
>  FundamentalGapsOfNumericalSemigroup(ns),
249
>  [ConductorOfNumericalSemigroup(ns)],
250
>  PseudoFrobeniusOfNumericalSemigroup(ns)];;
251
gap> 
252
gap> tkz := IP_TikzArrayOfIntegers(flen,rec(colors := cls,highlights:=arr));;
253

254
255
Using the default colors
256
257
258
4.3-2 The banner
259
260
The code in the following example has been used to produce one possible
261
banner for the homepage of the IntPic package. It is a nice picture that
262
gives an idea about the primes less than 10000. Of course, other ranges
263
could have been chosen. I warn the user that pictures involving a large
264
amount of data may face the problem of exceeding TeX capacity...
265
266
 Example 
267
gap> row_length := 200;; # the legth of each row
268
gap> columns := 50;; # the number of colums
269
gap> n := row_length*columns;
270
10000
271
gap> 
272
gap> ##compute the primes less than n
273
gap> # Primes is a GAP variable representing the list of primes less than 1000
274
gap> mp := Maximum(Primes);
275
997
276
gap> newprimes := [];;
277
gap> while mp < n do
278
>  mp := NextPrimeInt(mp);
279
>  Add(newprimes, mp);
280
> od;
281
gap> small_primes := Union(Primes, newprimes);;
282
gap> ##compute the first element of each pair of twin primes less than n
283
gap> twins := Filtered(small_primes, p -> IsPrime(p+2));;
284
gap> 
285
gap> rg := [1..n];;
286
gap> 
287
gap> arr := [Intersection(small_primes,rg),[],[], 
288
>  Intersection(Union(twins,twins+2),rg),[],[],[],[],[],[],[],
289
>  [],[],[],[],[],[],Difference(rg,small_primes)];;
290
gap> 
291
gap> tkz:=IP_TikzArrayOfIntegers([1..n],row_length,rec(highlights:=arr,
292
>  cell_width := "6",colsep:="0",rowsep:="0",inner_sep:="2",
293
>  shape_only:=" ",line_width:="0",line_color:="black!20" ));;
294

295
296
297