summaryrefslogtreecommitdiff
path: root/graphics/pgf/base/doc/text-en/pgfmanual-en-tutorial-chains.tex
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-12-20 03:00:48 +0000
committerNorbert Preining <norbert@preining.info>2019-12-20 03:00:48 +0000
commit18d9ec0eba21e6b8c55cdd50afb91c56e02ce7bf (patch)
tree56de5f55a6575a68557d5a384f57e3e8566c536d /graphics/pgf/base/doc/text-en/pgfmanual-en-tutorial-chains.tex
parent3b24b0599bb35e1a3338fa33bfb24044a6125ba4 (diff)
CTAN sync 201912200300
Diffstat (limited to 'graphics/pgf/base/doc/text-en/pgfmanual-en-tutorial-chains.tex')
-rw-r--r--graphics/pgf/base/doc/text-en/pgfmanual-en-tutorial-chains.tex194
1 files changed, 120 insertions, 74 deletions
diff --git a/graphics/pgf/base/doc/text-en/pgfmanual-en-tutorial-chains.tex b/graphics/pgf/base/doc/text-en/pgfmanual-en-tutorial-chains.tex
index 023efec085..9e8dfd00ca 100644
--- a/graphics/pgf/base/doc/text-en/pgfmanual-en-tutorial-chains.tex
+++ b/graphics/pgf/base/doc/text-en/pgfmanual-en-tutorial-chains.tex
@@ -21,39 +21,37 @@ looks like this%
\footnote{The shown diagram was not scanned, but rather typeset using
\tikzname. The jittering lines were created using the |random steps|
decoration.}:
-%
-\begin{codeexample}[setup code, hidden]
-\tikzset{
- nonterminal/.style={
- % The shape:
- rectangle,
- % The size:
- minimum size=6mm,
- % The border:
- very thick,
- draw=red!50!black!50, % 50% red and 50% black,
- % and that mixed with 50% white
- % The filling:
- top color=white, % a shading that is white at the top...
- bottom color=red!50!black!20, % and something else at the bottom
- % Font
- font=\itshape
- },
- terminal/.style={
- % The shape:
- rounded rectangle,
- minimum size=6mm,
- % The rest
- very thick,draw=black!50,
- top color=white,bottom color=black!20,
- font=\ttfamily},
- skip loop/.style={to path={-- ++(0,#1) -| (\tikztotarget)}}
-}
-\end{codeexample}
{
+ \tikzset{
+ nonterminal/.style={
+ % The shape:
+ rectangle,
+ % The size:
+ minimum size=6mm,
+ % The border:
+ very thick,
+ draw=red!50!black!50, % 50% red and 50% black,
+ % and that mixed with 50% white
+ % The filling:
+ top color=white, % a shading that is white at the top...
+ bottom color=red!50!black!20, % and something else at the bottom
+ % Font
+ font=\itshape
+ },
+ terminal/.style={
+ % The shape:
+ rounded rectangle,
+ minimum size=6mm,
+ % The rest
+ very thick,draw=black!50,
+ top color=white,bottom color=black!20,
+ font=\ttfamily},
+ skip loop/.style={to path={-- ++(0,#1) -| (\tikztotarget)}}
+ }
\tikzset{terminal/.append style={text height=1.5ex,text depth=.25ex}}
\tikzset{nonterminal/.append style={text height=1.5ex,text depth=.25ex}}
+ \pgfmathsetseed{1}
\medskip
\noindent\begin{tikzpicture}[
>=latex,thick,
@@ -106,7 +104,7 @@ For her next lecture, Ilka decides to redo this diagram, but this time perhaps
a bit cleaner and perhaps also bit ``cooler''.
\medskip
-\noindent\begin{tikzpicture}[point/.style={coordinate},>=stealth',thick,draw=black!50,
+\noindent\begin{tikzpicture}[point/.style={coordinate},>={Stealth[round]},thick,draw=black!50,
tip/.style={->,shorten >=1pt},every join/.style={rounded corners},
hv path/.style={to path={-| (\tikztotarget)}},
vh path/.style={to path={|- (\tikztotarget)}}]
@@ -178,7 +176,7 @@ get a bit of red mixed in.
Ilka starts with the simpler nonterminals, as there are no rounded corners
involved. Naturally, she sets up a style:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{positioning}}]
\begin{tikzpicture}[
nonterminal/.style={
% The shape:
@@ -212,7 +210,7 @@ setting the radius to 3mm, she will get exactly what she needs: circles, when
the shapes are, indeed, exactly 6mm by 6mm and otherwise half circles on the
sides:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{positioning}}]
\begin{tikzpicture}[node distance=5mm,
terminal/.style={
% The shape:
@@ -233,7 +231,7 @@ use it). This shape gives Ilka much more control over the appearance. For
instance, she could have an arc only on the left side, but she will not need
this.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{positioning,shapes.misc}}]
\begin{tikzpicture}[node distance=5mm,
terminal/.style={
% The shape:
@@ -252,7 +250,20 @@ this.
At this point, she notices a problem. The baseline of the text in the nodes is
not aligned:
%
-\begin{codeexample}[]
+\begin{codeexample}[setup code,hidden]
+\tikzset{
+ terminal/.style={
+ % The shape:
+ rounded rectangle,
+ minimum size=6mm,
+ % The rest
+ very thick,draw=black!50,
+ top color=white,bottom color=black!20,
+ font=\ttfamily},
+}
+\end{codeexample}
+%
+\begin{codeexample}[preamble={\usetikzlibrary{calc,positioning,shapes.misc}}]
\begin{tikzpicture}[node distance=5mm]
\node (dot) [terminal] {.};
\node (digit) [terminal,right=of dot] {digit};
@@ -280,9 +291,9 @@ the same line (the |base right| option places a node right of something so that
the baseline is right of the baseline of the other object). However, this does
not have the desired effect:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{positioning,shapes.misc}}]
\begin{tikzpicture}[node distance=5mm]
- \node (dot) [terminal] {.};
+ \node (dot) [terminal] {.};
\node (digit) [terminal,base right=of dot] {digit};
\node (E) [terminal,base right=of digit] {E};
\end{tikzpicture}
@@ -296,7 +307,7 @@ all be positioned vertically in the same manner. So, all Ilka needs to do is to
use the |text height| and |text depth| options to explicitly specify a height
and depth for the nodes.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{positioning,shapes.misc}}]
\begin{tikzpicture}[node distance=5mm,
text height=1.5ex,text depth=.25ex]
\node (dot) [terminal] {.};
@@ -306,7 +317,7 @@ and depth for the nodes.
\end{codeexample}
-\subsection{Aligning the Nodes Using Positioning Options}
+\subsection{Aligning the Nodes Using Positioning Options}
Ilka now has the ``styling'' of the nodes ready. The next problem is to place
them in the right places. There are several ways to do this. The most
@@ -336,11 +347,30 @@ borders separated by |node distance|.
Ilka can use this to draw the place the nodes in a long row:
%
\begin{codeexample}[setup code,hidden]
-\tikzset{terminal/.append style={text height=1.5ex,text depth=.25ex}}
-\tikzset{nonterminal/.append style={text height=1.5ex,text
- depth=.25ex}}
+\tikzset{
+ nonterminal/.style={
+ % The shape:
+ rectangle,
+ % The size:
+ minimum size=6mm,
+ % The border:
+ very thick,
+ draw=red!50!black!50, % 50% red and 50% black,
+ % and that mixed with 50% white
+ % The filling:
+ top color=white, % a shading that is white at the top...
+ bottom color=red!50!black!20, % and something else at the bottom
+ % Font
+ font=\itshape,
+ },
+}
+\tikzset{
+ terminal/.append style={text height=1.5ex,text depth=.25ex},
+ nonterminal/.append style={text height=1.5ex,text depth=.25ex},
+}
\end{codeexample}
-\begin{codeexample}[]
+%
+\begin{codeexample}[preamble={\usetikzlibrary{positioning,shapes.misc}}]
\begin{tikzpicture}[node distance=5mm and 5mm]
\node (ui1) [nonterminal] {unsigned integer};
\node (dot) [terminal,right=of ui1] {.};
@@ -363,7 +393,7 @@ between the top of the |E| node and the bottom of the |+| node are both 5mm.
There are several ways of fixing this problem. The easiest way is to simply add
a little bit of horizontal shift by hand:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{positioning,shapes.misc}}]
\begin{tikzpicture}[node distance=5mm and 5mm]
\node (E) [terminal] {E};
\node (plus) [terminal,above right=of E,xshift=5mm] {+};
@@ -376,7 +406,7 @@ A second way is to revert back to the idea of using a normal rectangle for the
terminals, but with rounded corners. Since corner rounding does not affect
anchors, she gets the following result:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{positioning,shapes.misc}}]
\begin{tikzpicture}[node distance=5mm and 5mm,terminal/.append style={rectangle,rounded corners=3mm}]
\node (E) [terminal] {E};
\node (plus) [terminal,above right=of E] {+};
@@ -394,7 +424,7 @@ connections are more difficult than others. Consider for instance the
the left and finally ends at a point a little to the left of |digit|''. Ilka
can put this into code as follows:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{calc,positioning,shapes.misc}}]
\begin{tikzpicture}[node distance=5mm and 5mm]
\node (dot) [terminal] {.};
\node (digit) [terminal,right=of dot] {digit};
@@ -421,7 +451,7 @@ for this. Whenever the |edge| command is used, it simply adds the current value
of |to path| to the path. So, Ilka can set up a style that contains the correct
path:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{calc,positioning,shapes.misc}}]
\begin{tikzpicture}[node distance=5mm and 5mm,
skip loop/.style={to path={-- ++(0,-.5) -| (\tikztotarget)}}]
\node (dot) [terminal] {.};
@@ -435,12 +465,12 @@ path:
\end{tikzpicture}
\end{codeexample}
-Ilka can even go a step further and make her |skip look| style parameterized.
+Ilka can even go a step further and make her |skip loop| style parameterized.
For this, the skip loop's vertical offset is passed as parameter |#1|. Also, in
the following code Ilka specifies the start and targets differently, namely as
the positions that are ``in the middle between the nodes''.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{calc,positioning,shapes.misc}}]
\begin{tikzpicture}[node distance=5mm and 5mm,
skip loop/.style={to path={-- ++(0,#1) -| (\tikztotarget)}}]
\node (dot) [terminal] {.};
@@ -455,7 +485,7 @@ the positions that are ``in the middle between the nodes''.
\end{codeexample}
-\subsection{Aligning the Nodes Using Matrices}
+\subsection{Aligning the Nodes Using Matrices}
Ilka is still bothered a bit by the placement of the plus and minus nodes.
Somehow, having to add an explicit |xshift| seems too much like cheating.
@@ -470,7 +500,7 @@ In Ilka's graphic, there will be three rows: One row containing only the plus
node, one row containing the main nodes and one row containing only the minus
node.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{shapes.misc}}]
\begin{tikzpicture}
\matrix[row sep=1mm,column sep=5mm] {
% First row:
@@ -496,7 +526,7 @@ idea: She adds small nodes (they will be turned into coordinates later on and
be invisible) at all the places where she would like connections to start and
end.
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{shapes.misc}}]
\begin{tikzpicture}[point/.style={circle,inner sep=0pt,minimum size=2pt,fill=red},
skip loop/.style={to path={-- ++(0,#1) -| (\tikztotarget)}}]
\matrix[row sep=1mm,column sep=2mm] {
@@ -528,8 +558,8 @@ Now, it's only a small step to add all the missing edges.
Matrices allow Ilka to align the nodes nicely, but the connections are not
quite perfect. The problem is that the code does not really reflect the paths
that underlie the diagram. For this, it seems natural enough to Ilka to use the
-|graph| library since, after all, connecting nodes by edges is exactly what
-happens in a graph. The |graph| library can both be used to connect nodes that
+|graphs| library since, after all, connecting nodes by edges is exactly what
+happens in a graph. The |graphs| library can both be used to connect nodes that
have already been created, but it can also be used to create nodes ``on the
fly'' and these processes can also be mixed.
@@ -543,6 +573,7 @@ allows her to write down edges between them in a simple way (the macro
|\matrixcontent| contains exactly the matrix content from the previous example;
no need to repeat it here):
%
+\begin{codeexample}[setup code,hidden]
\def\matrixcontent{
% First row:
\& \& \& \& \& \& \& \& \& \& \& \node (plus) [terminal] {+};\\
@@ -558,7 +589,12 @@ no need to repeat it here):
% Third row:
\& \& \& \& \& \& \& \& \& \& \& \node (minus)[terminal] {-};\\
}
-\begin{codeexample}[pre={\tikzset{ampersand replacement=\&,point/.style={coordinate}}}]
+\end{codeexample}
+%
+\begin{codeexample}[
+ preamble={\usetikzlibrary{graphs,shapes.misc}},
+ pre={\tikzset{ampersand replacement=\&,point/.style={coordinate}}},
+]
\begin{tikzpicture}[skip loop/.style={to path={-- ++(0,#1) -| (\tikztotarget)}},
hv path/.style={to path={-| (\tikztotarget)}},
vh path/.style={to path={|- (\tikztotarget)}}]
@@ -570,8 +606,8 @@ no need to repeat it here):
(p4) ->[skip loop=-5mm] (p3);
(p2) ->[skip loop=5mm] (p5);
(p6) ->[skip loop=-11mm] (p9);
- (p7) ->[vh path] (plus) -> [hv path] (p8);
- (p7) ->[vh path] (minus) -> [hv path] (p8);
+ (p7) ->[vh path] (plus) -> [hv path] (p8);
+ (p7) ->[vh path] (minus) -> [hv path] (p8);
};
\end{tikzpicture}
\end{codeexample}
@@ -592,11 +628,17 @@ specify, as shown in the next example. Additionally, by using the
|use existing nodes| option, Ilka can also leave out all the parentheses
(again, some options have been moved outside to keep the examples shorter):
%
-\begin{codeexample}[pre={\tikzset{ampersand replacement=\&,point/.style={coordinate},
- skip loop/.style={to path={-- ++(0,##1) -| (\tikztotarget)}},
- hv path/.style={to path={-| (\tikztotarget)}},
- vh path/.style={to path={|- (\tikztotarget)}}}}]
-\begin{tikzpicture}[,>=stealth',thick,black!50,text=black,
+\begin{codeexample}[
+ preamble={\usetikzlibrary{arrows.meta,graphs,shapes.misc}},
+ pre={\tikzset{
+ ampersand replacement=\&,
+ point/.style={coordinate},
+ skip loop/.style={to path={-- ++(0,##1) -| (\tikztotarget)}},
+ hv path/.style={to path={-| (\tikztotarget)}},
+ vh path/.style={to path={|- (\tikztotarget)}},
+}},
+]
+\begin{tikzpicture}[>={Stealth[round]},thick,black!50,text=black,
every new ->/.style={shorten >=1pt},
graphs/every graph/.style={edges=rounded corners}]
\matrix[column sep=4mm] { \matrixcontent };
@@ -620,7 +662,7 @@ create nodes, not only to connect them. This is, indeed, correct: When the
by parentheses, then \tikzname\ will actually create a node whose name and text
is the node name:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs}}]
\tikz \graph [grow right=2cm] { unsigned integer -> d -> digit -> E };
\end{codeexample}
%
@@ -633,8 +675,8 @@ but got some error messages. The reason is that a node cannot be called |.| in
\tikzname, so she had to choose a different name -- which is not good, since
she wants a dot to be shown! The trick is to put the dot in quotation marks,
this allows you to use ``quite arbitrary text'' as a node name:
-
-\begin{codeexample}[]
+%
+\begin{codeexample}[preamble={\usetikzlibrary{graphs,shapes.misc}}]
\tikz \graph [grow right sep] {
unsigned integer[nonterminal] -> "."[terminal] -> digit[terminal] -> E[terminal]
};
@@ -643,7 +685,7 @@ this allows you to use ``quite arbitrary text'' as a node name:
Now comes the fork to the plus and minus signs. Here, Ilka can use the grouping
mechanism of the |graph| command to create a split:
%
-\begin{codeexample}[]
+\begin{codeexample}[preamble={\usetikzlibrary{graphs,shapes.misc}}]
\tikz \graph [grow right sep] {
unsigned integer [nonterminal] ->
"." [terminal] ->
@@ -677,11 +719,15 @@ anonymous'' node name.
Next, Ilka needs to add some coordinates in between of some nodes where the
back-loops should got and she needs to shift the nodes a bit:
%
-\begin{codeexample}[pre={\tikzset{
- skip loop/.style={to path={-- ++(0,##1) -| (\tikztotarget)}},
- hv path/.style={to path={-| (\tikztotarget)}},
- vh path/.style={to path={|- (\tikztotarget)}}}}]
-\begin{tikzpicture}[>=stealth', thick, black!50, text=black,
+\begin{codeexample}[
+ preamble={\usetikzlibrary{arrows.meta,graphs,shapes.misc}},
+ pre={\tikzset{
+ skip loop/.style={to path={-- ++(0,##1) -| (\tikztotarget)}},
+ hv path/.style={to path={-| (\tikztotarget)}},
+ vh path/.style={to path={|- (\tikztotarget)}},
+}},
+]
+\begin{tikzpicture}[>={Stealth[round]}, thick, black!50, text=black,
every new ->/.style={shorten >=1pt},
graphs/every graph/.style={edges=rounded corners}]
\graph [grow right sep, branch down=7mm] {
@@ -726,8 +772,8 @@ any two nodes. Now, if you specify an edge twice, the options of the second
specification ``win''. Thus, by adding two more lines that ``correct'' these
edges, we get the final diagram with its complete code:
%
-\begin{codeexample}[]
-\tikz [>=stealth', black!50, text=black, thick,
+\begin{codeexample}[preamble={\usetikzlibrary{arrows.meta,graphs,shapes.misc}}]
+\tikz [>={Stealth[round]}, black!50, text=black, thick,
every new ->/.style = {shorten >=1pt},
graphs/every graph/.style = {edges=rounded corners},
skip loop/.style = {to path={-- ++(0,#1) -| (\tikztotarget)}},
@@ -968,8 +1014,8 @@ edges, we get the final diagram with its complete code:
% Ilka starts with the matrix we had earlier, only with slightly adapted
% styles. Then she writes down the main chain and its branches:
%
-% \begin{codeexample}[]
-% \begin{tikzpicture}[point/.style={coordinate},>=stealth',thick,draw=black!50,
+% \begin{codeexample}[preamble={\usetikzlibrary{arrows.meta}}]
+% \begin{tikzpicture}[point/.style={coordinate},>={Stealth[round]},thick,draw=black!50,
% tip/.style={->,shorten >=1pt},every join/.style={rounded corners},
% hv path/.style={to path={-| (\tikztotarget)}},
% vh path/.style={to path={|- (\tikztotarget)}}]