GAP (IntPic) - Chapter 4: Visualization of the pictures created

Goto Chapter: Top 1 2 3 4 5 6 Bib Ind
[Top of Book] [Contents] [Previous Chapter] [Next Chapter]

[MathJax on]

4 Visualization of the pictures created
4.1 Viewing using Viz
4.2 Viewing without using Viz
4.2-1 A complete example
4.3 Other examples of use of the IntPic package
4.3-1 Varia
4.3-2 The banner

### 4 Visualization of the pictures created

This chapter describes two easy ways to visualize the images created by using the IntPic package. Both require LaTeX and some LaTeX packages, such as Tikz and pgf, to be installed and working. One of the ways we will describe is almost completely automatic. It makes use of the function `Splash`, borrowed from the Viz 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.

#### 4.1 Viewing using Viz

Producing and displaying a picture from a `tikz` string tkz may me achieved in a simple way. (Warning: extenvive tests have only been done with Linux.) One just have to type the following:

    IP_Splash(tkz);

A picture is popped up after this use of the function `IP_Splash`.. 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 `InfoViz` to 1 or more. The following example illustrates this and the use of some options of the function `IP_Splash`. For instance, the `pdf` viewer can be changed.

    gap> SetInfoLevel(InfoViz,1);
    gap> IP_Splash(tkz,rec(viewer:="okular"));
    #I  The temporary directory used is: /tmp/tmJcpphI/

The 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 `vizpicture.pdf` are created by the `pdflatex` command that is called by the `IP_Splash` function.

`Warning:` 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.

#### 4.2 Viewing without using Viz

This section describes a way to visualize images without sing Viz. Besides being useful in the case of not having a working copy of Viz, 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 `tikz` code and let your document input it. The glogal variables `IP_Preamble` and `Closing` can be used to pruduce a complete LaTeX document rather than only the `tizk` code for the picture. The document may then be processed by using `pdflatex` and the picture viewed by using some `pdf` viewer. The `pdf` produced can be included in a LaTeX document instead of the `tizk` 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.

Note the use of the `preview` 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 `pdf` file produced in a LaTeX document to be processed with `pdflatex`.

    gap> Print(IP_Preamble);
    \documentclass{minimal}
    \usepackage{amsmath}
    \usepackage[active,tightpage]{preview}
    \setlength\PreviewBorder{1pt}
    \usepackage{pgf}
    \usepackage{tikz}
    \usepgfmodule{plot}
    \usepgflibrary{plothandlers}
    \usetikzlibrary{shapes.geometric}
    \usetikzlibrary{shadings}
    \begin{document}
    \begin{preview}

    gap> Print(IP_Closing);
    \end{preview}
    \end{document}

##### 4.2-1 A complete example

Admit you want to produce a document which contains the picture corresponding to the `tikz` code obtained through the instructions

    arr := [[1,2,3,4,5,6],[1,2,3,4,5],[1,2,3,4],[1,2,3],[1,2],[1]];;
    tkz := IP_TikzArrayOfIntegers([1..10],5,rec(highlights:=arr));;

The picture is:

The elements of the set [1,2,3,4,5,6] are highlighted using the first color (red); those of the set [1,2,3,4,5] are highlighted using the second color (green); those of the set [1,2,3,4] are highlighted using the third color (blue); those of the set [1,2,3] are highlighted using the fourth color (cyan); those of the set [1,2] are highlighted using the fifth color (magenta); those of the set [1] is highlighted using the sixth color (yellow).

Let us explain how the six colors used for the cell containing 1 are distributed: upper left corner -- red; upper right corner -- green; lower left corner -- blue; lower right corner -- cyan; the number -- magenta; the border -- yellow.

The colors of the cell containing 2 and 3 are distributed in a similar way.

The colors of the cell containing 4: left -- red; middle -- blue; right -- green.

After the session listed below, the files `tikz_pic_for_complete_document.tex` and `pic_for_complete_document.tex` 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.

    gap> tikzfile := "tikz_pic_for_complete_document.tex";;
    gap> file := "pic_for_complete_document.tex";;
    gap>
    gap> arr := [[1,2,3,4,5,6],[1,2,3,4,5],[1,2,3,4],[1,2,3],[1,2],[1]];;
    gap> tkz := IP_TikzArrayOfIntegers([1..10],5,rec(highlights:=arr));;
    gap>
    gap> FileString(tikzfile,tkz);
    642
    gap> FileString(file,Concatenation(IP_Preamble,tkz,IP_Closing));
    961

Executing something like

    pdflatex pic_for_complete_document.tex
    convert pic_for_complete_document.pdf pic_for_complete_document.jpg

the `pdf` and the `jpg` formats of the image have been created. The `jpg` format is usefull to be included into an html document, for instance.

Note that the tikz code has been saved into the file `tikz_pic_for_complete_document.tex`. A complete example of a LaTeX document follows.

    \documentclass{article}
    \usepackage{amsmath}
    %\usepackage[active,tightpage]{preview}
    %\setlength\PreviewBorder{1pt}
    \usepackage{pgf}
    \usepackage{tikz}
    \usepgfmodule{plot}
    \usepgflibrary{plothandlers}
    \usetikzlibrary{shapes.geometric}
    \usetikzlibrary{shadings}
    \usepackage{graphicx}
    \author{Author}
    \title{How to include images in a \LaTeX\ document}
    \date{June, 2013}
    \begin{document}
    %\begin{preview}
    \maketitle
    Using the pdf file:

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

    Using the PGF/TikZ code:

    \begin{center}
    \input{../images/tikz_pic_for_complete_document.tex}
    \end{center}
    If you want to scale this image, please chang the ``scale'' in the file
    \textt{tikz_pic_for_complete_document.tex}
    %\end{preview}
    \end{document}

The output, after processing with `pdflatex` is as follows:

#### 4.3 Other examples of use of the IntPic package

##### 4.3-1 Varia

The following example shows how to produce `tikz` code for a picture containing the odd integers from 801 to 999. Each line (except the highest) contains 15 cells.

    gap> rg := Filtered([801..889],u->(u mod 2)<>0);;
    gap> flen := 15;;
    gap> twins := Filtered(Primes, p -> p + 2 in Primes);;
    gap> arr := [Primes,Union(twins,twins+2),Filtered(rg,u->(u mod 3)=0)];;
    gap> tkz := IP_TikzArrayOfIntegers(rg,flen,rec(highlights:=arr));;

The picture obtained highlights the primes, the twin primes and the multiples of 3. As the twins are also primes, a gradient is used to highlight them. In this example the default list of colors is used.

The same computations, but defining other color lists.

    gap> cls := IP_ColorsCompRedTones;;
    gap> rg := Filtered([801..889],u->(u mod 2)<>0);;
    gap> flen := 15;;
    gap> twins := Filtered(Primes, p -> p + 2 in Primes);;
    gap> arr := [Primes,Union(twins,twins+2),Filtered(rg,u->(u mod 3)=0)];;
    gap> tkz := IP_TikzArrayOfIntegers(rg,flen,rec(colors := cls,highlights:=arr));;

    gap> cls := IP_ColorsDGrayTones;;
    gap> rg := Filtered([801..889],u->(u mod 2)<>0);;
    gap> flen := 15;;
    gap> twins := Filtered(Primes, p -> p + 2 in Primes);;
    gap> arr := [Primes,Union(twins,twins+2),Filtered(rg,u->(u mod 3)=0)];;
    gap> tkz := IP_TikzArrayOfIntegers(rg,flen,rec(colors := cls,highlights:=arr));;

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

The following example uses the NumericalSgps package.

    gap> #LoadPackage("numericalsgps");
    gap>
    gap> ns := NumericalSemigroup(11,19,30,42,59);;
    gap> cls := ShuffleIP_Colors([IP_ColorsGreenTones,IP_ColorsCompBlueTones]);;
    gap> flen := 20;;
    gap> #some notable elements
    gap> arr := [SmallElementsOfNumericalSemigroup(ns),
    >         GapsOfNumericalSemigroup(ns),
    >         MinimalGeneratingSystemOfNumericalSemigroup(ns),
    >         FundamentalGapsOfNumericalSemigroup(ns),
    >         [ConductorOfNumericalSemigroup(ns)],
    >         PseudoFrobeniusOfNumericalSemigroup(ns)];;
    gap>
    gap> tkz := IP_TikzArrayOfIntegers(flen,rec(colors := cls,highlights:=arr));;

Using the default colors

##### 4.3-2 The banner

The 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 5000. 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...

    gap> row_length := 100;; # the maximum length of a row
    gap> nrows := 50;; # the number of rows
    gap> n := row_length*nrows;
    5000
    gap> ##compute the primes less than n
    gap> # Primes is a GAP variable representing the list of primes less than n
    gap> mp := Maximum(Primes);
    997
    gap> newprimes := [];;
    gap> while mp < n do
    >   mp := NextPrimeInt(mp);
    >   Add(newprimes, mp);
    > od;
    gap> small_primes := Union(Primes, newprimes);;
    gap> ##compute the first element of each pair of twin primes less than n
    gap> twins := Filtered(small_primes, p -> IsPrime(p+2));;
    gap> rg := [1..n];;
    gap> arr := [Intersection(small_primes,rg),[],[],
    >         Intersection(Union(twins,twins+2),rg),[],[],[],[],[],[],[],
    >         [],[],[],[],[],[],Difference(rg,small_primes)];;
    gap> tkz:=IP_TikzArrayOfIntegers([1..n],row_length,rec(highlights:=arr,
    >              cell_width := "6",colsep:="0",rowsep:="0",inner_sep:="2",
    >              shape_only:="",line_width:="0",line_color:="black!20" ));;

[Top of Book] [Contents] [Previous Chapter] [Next Chapter]
Goto Chapter: Top 1 2 3 4 5 6 Bib Ind

generated by GAPDoc2HTML