2.6. PGF/TikZ LaTeX Pictures

Attention

Only practicable and usable for HTML and LaTeX builder.

PyPI Package

https://pypi.org/project/sphinxcontrib-tikz/

Documentation

http://sphinxcontrib-tikz.readthedocs.io/

Git Repository

https://bitbucket.org/philexander/tikz

Sphinx extension, which enables the use of the PGF/TikZ LaTeX package to draw nice pictures.

This extension relies on two software packages being installed on your computer:

  1. latex with the tikz and the amsmath packages

  2. A software package that is able to convert a PDF to an image. Currently, four different ways of doing this conversion are supported, called conversion “suites”. Below is a list for each suite what must be installed on your computer. Only one such suite need to be installed:

    • pdf2svg suite: pdf2svg (preferred, default)

    • Netpbm suite: pdftoppm (part of the Poppler PDF library) and pnmtopng (part of the Netpbm package)

    • ImageMagick suite: pdftoppm (part of the Poppler PDF library) and convert (part of the ImageMagick package)

    • GhostScript suite: ghostscript

See Configuration in the extension documentation for more details.

:tikz:

For more details, see Usage in the extension documentation.

inline content

The example
1
2
An example role :tikz:`[thick] \node[blue,draw] (a) {㎁};
\node[draw,dotted,right of=a] {㏈} edge[<-] (a);`
Which gives

An example role [thick] \node[blue,draw] (a) {㎁};
\node[draw,dotted,right of=a] {㏈} edge[<-] (a);

.. tikz::

For more details, see Usage in the extension documentation.

explicit markup

The example
1
2
3
4
.. rst-class:: centered
.. tikz:: [dotted,thick,>=latex'] \draw[->] (0,0) -- (1,1) -- (1,0)
   -- (2,0);
   :libs: arrows
Which gives

[dotted,thick,>=latex'] \draw[->] (0,0) -- (1,1) -- (1,0)
-- (2,0);

from source file

The example
1
2
3
4
5
.. _tikz/srcfile/ctrloop:
.. rst-class:: centered
.. tikz:: Control system principles (PGF/TikZ example)
   :include: /extensions/tikz/srcfile/ctrloop.tex
   :libs: arrows,shapes
Which gives

\begin{tikzpicture}[
    auto,
    node distance = 2cm,
    >=latex'
]

    \tikzstyle{block} = [
        draw,
	rectangle,
	fill = blue!20,
        minimum height = 3em,
        minimum width = 6em
    ]
    \tikzstyle{sum} = [
        draw,
        circle,
        fill = blue!20,
        node distance = 1cm
    ]
    \tikzstyle{input} = [
        coordinate
    ]
    \tikzstyle{output} = [
        coordinate
    ]
    \tikzstyle{pinstyle} = [
        pin edge={
            to-,
            thin,
            black
        }
    ]

    % placing the blocks
    \node [input, name=input] {};
    \node [sum, right of=input] (sum) {};
    \node [block, right of=sum] (controller) {Controller};
    \node [block, right of=controller,
           pin={[pinstyle]above:Disturbances},
           node distance=3cm] (system) {System};

    % draw an edge between the controller and system block
    % to calculate the coordinate -- need it to place the
    % measurement block
    \draw [->] (controller) -- node[name=u] {$u$} (system);
    \node [output, right of=system] (output) {};
    \node [block, below of=u] (measurements) {Measurements};
    % once the nodes are placed, connecting them is easy
    \draw [draw,->] (input) -- node {$r$} (sum);
    \draw [->] (sum) -- node {$e$} (controller);
    \draw [->] (system) -- node [name=y] {$y$}(output);
    \draw [->] (y) |- (measurements);
    \draw [->] (measurements) -|
        node[pos=0.99] {$-$}
        node [near end] {$y_m$} (sum);

\end{tikzpicture}

%Local variables:
% coding: utf-8
% mode: text
% mode: rst
% End:
% vim: fileencoding=utf-8 filetype=tex :

Figure 2.1 Control system principles (PGF/TikZ example)

Which needs

The example above comes from the Control system principles web page and processed the following TikZ file content:

Listing 2.4 TikZ example file (tikz/srcfile/ctrloop.tex)
 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
\begin{tikzpicture}[
    auto,
    node distance = 2cm,
    >=latex'
]

    \tikzstyle{block} = [
        draw,
	rectangle,
	fill = blue!20,
        minimum height = 3em,
        minimum width = 6em
    ]
    \tikzstyle{sum} = [
        draw,
        circle,
        fill = blue!20,
        node distance = 1cm
    ]
    \tikzstyle{input} = [
        coordinate
    ]
    \tikzstyle{output} = [
        coordinate
    ]
    \tikzstyle{pinstyle} = [
        pin edge={
            to-,
            thin,
            black
        }
    ]

    % placing the blocks
    \node [input, name=input] {};
    \node [sum, right of=input] (sum) {};
    \node [block, right of=sum] (controller) {Controller};
    \node [block, right of=controller,
           pin={[pinstyle]above:Disturbances},
           node distance=3cm] (system) {System};

    % draw an edge between the controller and system block
    % to calculate the coordinate -- need it to place the
    % measurement block
    \draw [->] (controller) -- node[name=u] {$u$} (system);
    \node [output, right of=system] (output) {};
    \node [block, below of=u] (measurements) {Measurements};
    % once the nodes are placed, connecting them is easy
    \draw [draw,->] (input) -- node {$r$} (sum);
    \draw [->] (sum) -- node {$e$} (controller);
    \draw [->] (system) -- node [name=y] {$y$}(output);
    \draw [->] (y) |- (measurements);
    \draw [->] (measurements) -|
        node[pos=0.99] {$-$}
        node [near end] {$y_m$} (sum);

\end{tikzpicture}