GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
<?xml version="1.0" encoding="UTF-8"?>12<Chapter Label="visualisation">3<Heading>Visualization of the pictures created</Heading>4This chapter describes two easy ways to visualize the images created by using the &IntPic; package. Both require &LaTeX; and some &LaTeX; packages, such as <Package>Tikz</Package> and <Package>pgf</Package>, to be installed and working. One of the ways we will describe is almost completely automatic. It makes use of the function <C>Splash</C>, borrowed from the <Package>Viz</Package> package. The other is not so automatic but has the advantage of not requiring other packages, besides the &LaTeX; ones, and should work in any operation system.56<P />7<!-- <Section>8<Heading>Visualization</Heading>-->9<Section>10<Heading>Viewing using <Package>Viz</Package></Heading>11Producing and displaying a picture from a <C>tikz</C> string <A>tkz</A> may me achieved in a simple way. (Warning: extenvive tests have only been done with Linux.) One just have to type the following:12<P />13<P />14<Listing Type="IP\_Splash"><![CDATA[15IP_Splash(tkz);16]]></Listing>17A picture is popped up after this use of the function <C>IP_Splash</C>.<!--<Ref Func="Splash" BookName="viz"/>-->. To see the name of the temporary directory created to perform the computations, and thus being able to copy the files involved to any other place, one should set the info level <C>InfoViz</C> to <M>1</M> or more. The following example illustrates this and the use of some options of the function <C>IP_Splash</C>.<!--<Ref Func="Splash" BookName="viz"/> function of the <Package>Viz</Package> package. -->18<!--19Setting the option <C>papersize</C> to "a0paper" may be convenient for the visualization of large images.20-->21For instance, the <C>pdf</C> viewer can be changed.2223<Listing Type="infoviz: temporary directory"><![CDATA[24gap> SetInfoLevel(InfoViz,1);25gap> IP_Splash(tkz,rec(viewer:="okular"));26#I The temporary directory used is: /tmp/tmJcpphI/27]]></Listing>2829The temporary directory /tmp/tmJcpphI/ contains the file and vizpicture.tex. The file vizpicture.tex is the &LaTeX; document to be processed. Other files, namely the <C>vizpicture.pdf</C> are created by the <C>pdflatex</C> command that is called by the <C>IP_Splash</C><!--<Ref Func="Splash" BookName="viz"/>--> function.30<P/>31<C>Warning:</C> In the case of large pictures, it may happen the &LaTeX; memory being exceeded. In this case, no image is produced and the user is not warned.32</Section>33<Section>34<Heading>Viewing without using <Package>Viz</Package></Heading>35This section describes a way to visualize images without sing <Package>Viz</Package>. Besides being useful in the case of not having a working copy of <Package>Viz</Package>, it is rather convenient when the decision of where to save the pictures is made. In this case, you may start your gap session in the desired place, the working directory. Furthermore, if your intention is, for instance, to include the images in a document, you may just decide the name for the file containing the <C>tikz</C> code and let your document input it.3637The glogal variables <C>IP_Preamble</C> and <C>Closing</C> can be used to pruduce a complete &LaTeX; document rather than only the <C>tizk</C> code for the picture. The document may then be processed by using <C>pdflatex</C> and the picture viewed by using some <C>pdf</C> viewer. The <C>pdf</C> produced can be included in a &LaTeX; document instead of the <C>tizk</C> code. In the later case, the code is processed each time the document is processed, which should perhaps be avoided in the case of large images.38<P/>39Note the use of the <C>preview</C> package, which is used to produce the complete picture without having to pay attention to the paper size nor to crop the image. It is useful for viewing purposes and also to include the <C>pdf</C> file produced in a &LaTeX; document to be processed with <C>pdflatex</C>.40<Listing Type="Preamble"><![CDATA[41gap> Print(IP_Preamble);42\documentclass{minimal}43\usepackage{amsmath}44\usepackage[active,tightpage]{preview}45\setlength\PreviewBorder{1pt}46\usepackage{pgf}47\usepackage{tikz}48\usepgfmodule{plot}49\usepgflibrary{plothandlers}50\usetikzlibrary{shapes.geometric}51\usetikzlibrary{shadings}52\begin{document}53\begin{preview}54]]></Listing>55<Listing Type="Closing"><![CDATA[56gap> Print(IP_Closing);57\end{preview}58\end{document}59]]></Listing>60<Subsection>61<Heading>A complete example</Heading>62Admit you want to produce a document which contains the picture corresponding to the <C>tikz</C> code obtained through the instructions63<Listing Type="instructions to obtain some tikz code"><![CDATA[64arr := [[1,2,3,4,5,6],[1,2,3,4,5],[1,2,3,4],[1,2,3],[1,2],[1]];;65tkz := IP_TikzArrayOfIntegers([1..10],5,rec(highlights:=arr));;66]]></Listing>67The picture is:68<Alt Only="LaTeX">69\begin{center}70\includegraphics[width=0.95\textwidth]{../images/pic_for_complete_document.pdf}71\end{center}72</Alt>73<Alt Only="HTML">74<br><center><img src="../images/pic_for_complete_document.jpg"></center><br>75</Alt>76The elements of the set77<M>[1,2,3,4,5,6]</M> are highlighted using the first color (red); those of the set78<M>[1,2,3,4,5]</M> are highlighted using the second color (green); those of the set79<M>[1,2,3,4]</M> are highlighted using the third color (blue); those of the set80<M>[1,2,3]</M> are highlighted using the fourth color (cyan); those of the set81<M>[1,2]</M> are highlighted using the fifth color (magenta); those of the set82<M>[1]</M> is highlighted using the sixth color (yellow).83<P/>84Let us explain how the six colors used for the cell containing <M>1</M> are distributed:85upper left corner -- red;86upper right corner -- green;87lower left corner -- blue;88lower right corner -- cyan;89the number -- magenta;90the border -- yellow.91<P/>92The colors of the cell containing <M>2</M> and <M>3</M> are distributed in a similar way.93<P/>94The colors of the cell containing <M>4</M>:95left -- red;96middle -- blue;97right -- green.98<P/>99After the session listed below, the files <C>tikz_pic_for_complete_document.tex</C> and <C>pic_for_complete_document.tex</C> have been created in the current directory (that is, the one where the &GAP; session has started). For other directories, complete paths may have to be given.100<Listing Type="the GAP session"><![CDATA[101gap> tikzfile := "tikz_pic_for_complete_document.tex";;102gap> file := "pic_for_complete_document.tex";;103gap>104gap> arr := [[1,2,3,4,5,6],[1,2,3,4,5],[1,2,3,4],[1,2,3],[1,2],[1]];;105gap> tkz := IP_TikzArrayOfIntegers([1..10],5,rec(highlights:=arr));;106gap>107gap> FileString(tikzfile,tkz);108642109gap> FileString(file,Concatenation(IP_Preamble,tkz,IP_Closing));110961111]]></Listing>112Executing something like113<Listing Type="the pdf and the jpg of the picture"><![CDATA[114pdflatex pic_for_complete_document.tex115convert pic_for_complete_document.pdf pic_for_complete_document.jpg116]]></Listing>117the <C>pdf</C> and the <C>jpg</C> formats of the image have been created. The <C>jpg</C> format is usefull to be included into an html document, for instance.118<P/>119Note that the tikz code has been saved into the file <C>tikz_pic_for_complete_document.tex</C>. A complete example of a &LaTeX; document follows.120<Listing Type="a LaTeX document"><![CDATA[121\documentclass{article}122\usepackage{amsmath}123%\usepackage[active,tightpage]{preview}124%\setlength\PreviewBorder{1pt}125\usepackage{pgf}126\usepackage{tikz}127\usepgfmodule{plot}128\usepgflibrary{plothandlers}129\usetikzlibrary{shapes.geometric}130\usetikzlibrary{shadings}131\usepackage{graphicx}132\author{Author}133\title{How to include images in a \LaTeX\ document}134\date{June, 2013}135\begin{document}136%\begin{preview}137\maketitle138Using the pdf file:139140\begin{center}141\includegraphics[width=0.80\textwidth]{../images/pic_for_complete_document.pdf}142\end{center}143144Using the PGF/TikZ code:145146\begin{center}147\input{../images/tikz_pic_for_complete_document.tex}148\end{center}149If you want to scale this immage, please chang the ``scale'' in the file150\textt{tikz_pic_for_complete_document.tex}151%\end{preview}152\end{document}153]]></Listing>154The output, after processing with <C>pdflatex</C> is as follows:155<Alt Only="LaTeX">156\begin{center}157\includegraphics[width=0.95\textwidth]{../images/complete_latex_document.pdf}158\end{center}159</Alt>160<Alt Only="HTML">161<br><center><img src="../images/complete_latex_document.jpg"></center><br>162</Alt>163164165</Subsection>166</Section>167<Section>168<Heading>Other examples of use of the <Package>IntPic</Package> package</Heading>169170<Subsection>171<Heading>Varia</Heading>172173The following example shows how to produce <C>tikz</C> code for a picture containing the odd integers from <M>801</M> to <M>999</M>. Each line (except the highest) contains <M>15</M> cells.174<Example><![CDATA[175gap> rg := Filtered([801..889],u->(u mod 2)<>0);;176gap> flen := 15;;177gap> twins := Filtered(Primes, p -> p + 2 in Primes);;178gap> arr := [Primes,Union(twins,twins+2),Filtered(rg,u->(u mod 3)=0)];;179gap> tkz := IP_TikzArrayOfIntegers(rg,flen,rec(highlights:=arr));;180]]></Example>181The picture obtained highlights the primes, the twin primes and the multiples of <M>3</M>. As the twins are also primes, a gradient is used to highlight them. In this example the default list of colors is used.182<Alt Only="LaTeX">183\begin{center}184\includegraphics[width=0.95\textwidth]{../images/primesandtwinsamongodd}185\end{center}186</Alt>187<Alt Only="HTML">188<br><center><img src="../images/primesandtwinsamongodd.jpg"></center><br>189</Alt>190The same computations, but defining other color lists.191<Example><![CDATA[192gap> cls := IP_ColorsCompRedTones;;193gap> rg := Filtered([801..889],u->(u mod 2)<>0);;194gap> flen := 15;;195gap> twins := Filtered(Primes, p -> p + 2 in Primes);;196gap> arr := [Primes,Union(twins,twins+2),Filtered(rg,u->(u mod 3)=0)];;197gap> tkz := IP_TikzArrayOfIntegers(rg,flen,rec(colors := cls,highlights:=arr));;198]]></Example>199<Alt Only="LaTeX">200\begin{center}201\includegraphics[width=0.95\textwidth]{../images/primesandtwinsamongodd_comp_red}202\end{center}203</Alt>204<Alt Only="HTML">205<br><center><img src="../images/primesandtwinsamongodd_comp_red.jpg"></center><br>206</Alt>207<Example><![CDATA[208gap> cls := IP_ColorsDGrayTones;;209gap> rg := Filtered([801..889],u->(u mod 2)<>0);;210gap> flen := 15;;211gap> twins := Filtered(Primes, p -> p + 2 in Primes);;212gap> arr := [Primes,Union(twins,twins+2),Filtered(rg,u->(u mod 3)=0)];;213gap> tkz := IP_TikzArrayOfIntegers(rg,flen,rec(colors := cls,highlights:=arr));;214]]></Example>215<Alt Only="LaTeX">216\begin{center}217\includegraphics[width=0.95\textwidth]{../images/primesandtwinsamongodd_dark_gray}218\end{center}219</Alt>220<Alt Only="HTML">221<br><center><img src="../images/primesandtwinsamongodd_dark_gray.jpg"></center><br>222</Alt>223<Example><![CDATA[224gap> cls := ["blue","-blue","black"];;225gap> rg := Filtered([801..889],u->(u mod 2)<>0);;226gap> flen := 15;;227gap> twins := Filtered(Primes, p -> p + 2 in Primes);;228gap> arr := [Primes,Union(twins,twins+2),Filtered(rg,u->(u mod 3)=0)];;229gap> tkz := IP_TikzArrayOfIntegers(rg,flen,rec( colors := cls,highlights:=arr));;230]]></Example>231<Alt Only="LaTeX">232\begin{center}233\includegraphics[width=0.95\textwidth]{../images/primesandtwinsamongodd_other}234\end{center}235</Alt>236<Alt Only="HTML">237<br><center><img src="../images/primesandtwinsamongodd_other.jpg"></center><br>238</Alt>239The following example uses the240<Alt Not='Text'>241<URL242Text='NumericalSgps'>http://www.fc.up.pt/cmup/mdelgado/numericalsgps</URL>243</Alt>244<Alt Only='Text'>245<Package>NumericalSgps</Package>246</Alt>247package.248<Example><![CDATA[249gap> #LoadPackage("numericalsgps");250gap>251gap> ns := NumericalSemigroup(11,19,30,42,59);;252gap> cls := ShuffleIP_Colors([IP_ColorsGreenTones,IP_ColorsCompBlueTones]);;253gap> flen := 20;;254gap> #some notable elements255gap> arr := [SmallElementsOfNumericalSemigroup(ns),256> GapsOfNumericalSemigroup(ns),257> MinimalGeneratingSystemOfNumericalSemigroup(ns),258> FundamentalGapsOfNumericalSemigroup(ns),259> [ConductorOfNumericalSemigroup(ns)],260> PseudoFrobeniusOfNumericalSemigroup(ns)];;261gap>262gap> tkz := IP_TikzArrayOfIntegers(flen,rec(colors := cls,highlights:=arr));;263]]></Example>264<Alt Only="LaTeX">265\begin{center}266\includegraphics[width=0.95\textwidth]{../images/numericalsgp_notable}267\end{center}268</Alt>269<Alt Only="HTML">270<br><center><img src="../images/numericalsgp_notable.jpg"></center><br>271</Alt>272Using the default colors273<Alt Only="LaTeX">274\begin{center}275\includegraphics[width=0.95\textwidth]{../images/numericalsgp_notable_df_colors}276\end{center}277</Alt>278<Alt Only="HTML">279<br><center><img src="../images/numericalsgp_notable_df_colors.jpg"></center><br>280</Alt>281</Subsection>282<Subsection>283<Heading>The banner</Heading>284The code in the following example has been used to produce one possible banner for the homepage of the &IntPic; package. It is a nice picture that gives an idea about the primes less than <M>10000</M>. Of course, other ranges could have been chosen. I warn the user that pictures involving a large amount of data may face the problem of exceeding &TeX; capacity...285<Example><![CDATA[286gap> row_length := 200;; # the legth of each row287gap> columns := 50;; # the number of colums288gap> n := row_length*columns;28910000290gap>291gap> ##compute the primes less than n292gap> # Primes is a GAP variable representing the list of primes less than 1000293gap> mp := Maximum(Primes);294997295gap> newprimes := [];;296gap> while mp < n do297> mp := NextPrimeInt(mp);298> Add(newprimes, mp);299> od;300gap> small_primes := Union(Primes, newprimes);;301gap> ##compute the first element of each pair of twin primes less than n302gap> twins := Filtered(small_primes, p -> IsPrime(p+2));;303gap>304gap> rg := [1..n];;305gap>306gap> arr := [Intersection(small_primes,rg),[],[],307> Intersection(Union(twins,twins+2),rg),[],[],[],[],[],[],[],308> [],[],[],[],[],[],Difference(rg,small_primes)];;309gap>310gap> tkz:=IP_TikzArrayOfIntegers([1..n],row_length,rec(highlights:=arr,311> cell_width := "6",colsep:="0",rowsep:="0",inner_sep:="2",312> shape_only:=" ",line_width:="0",line_color:="black!20" ));;313]]></Example>314<Alt Only="LaTeX">315\begin{center}316\includegraphics[width=0.99\textwidth]{../images/intpic_banner.pdf}317\end{center}318</Alt>319<Alt Only="HTML">320<br><center><img src="../images/intpic_banner.jpg"></center><br>321</Alt>322323</Subsection>324</Section>325</Chapter>326327328