diff options
Diffstat (limited to 'Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tikz-paths.tex')
-rw-r--r-- | Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tikz-paths.tex | 532 |
1 files changed, 223 insertions, 309 deletions
diff --git a/Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tikz-paths.tex b/Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tikz-paths.tex index ea8d3f1bcb9..700d15208e2 100644 --- a/Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tikz-paths.tex +++ b/Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tikz-paths.tex @@ -100,19 +100,20 @@ present section. step. The following style influences scopes: - \begin{itemize} - \itemstyle{every path} + \begin{stylekey}{/tikz/every path (initially \normalfont empty)} This style is installed at the beginning of every path. This can be useful for (temporarily) adding, say, the |draw| option to everything in a scope. \begin{codeexample}[] -\begin{tikzpicture}[fill=examplefill] % only sets the color - \tikzstyle{every path}=[draw] % all paths are drawn +\begin{tikzpicture} + [fill=examplefill, % only sets the color + every path/.style={draw}] % all paths are drawn \fill (0,0) rectangle +(1,1); \shade (2,0) rectangle +(1,1); \end{tikzpicture} \end{codeexample} - \end{itemize} + \end{stylekey} + \end{command} @@ -208,251 +209,6 @@ construction operations. } -\subsubsection{Snaked Lines} -\label{section-tikz-snakes} - -The line-to operation can not only be used to append straight lines to -the path, but also ``snaked'' lines (called thus because they look a -little bit like snakes seen from above). - -\tikzname\ and \pgfname\ use a concept that I termed \emph{snakes} -for appending such ``squiggly'' lines. A snake specifies a way of -extending a path between two points in a ``fancy manner.'' - -Normally, a snake will just connect the start point to the end point -without starting new subpaths. Thus, a path containing a snaked line -can, nevetheless, still be used for filling. However, this is not -always the case. Some snakes consist of numerous unconnected -segments. ``Lines'' consisting of such snakes cannot be used as the -borders of enclosed areas. - -Here are some examples of snakes in action: - -\begin{codeexample}[] -\begin{tikzpicture}[thick] - \draw (0,3) -- (3,3); - \draw[snake=zigzag] (0,2.5) -- (3,2.5); - \draw[snake=brace] (0,2) -- (3,2); - \draw[snake=triangles] (0,1.5) -- (3,1.5); - \draw[snake=coil,segment length=4pt] (0,1) -- (3,1); - \draw[snake=coil,segment aspect=0] (0,.5) -- (3,.5); - \draw[snake=expanding waves,segment angle=7] (0,0) -- (3,0); -\end{tikzpicture} -\end{codeexample} - -\begin{codeexample}[] -\begin{tikzpicture} - \filldraw[fill=red!20,snake=bumps] (0,0) rectangle (3,2); -\end{tikzpicture} -\end{codeexample} - -\begin{codeexample}[] -\begin{tikzpicture} - \filldraw[fill=blue!20] (0,3) - [snake=saw] -- (3,3) - [snake=coil,segment aspect=0] -- (2,1) - [snake=bumps] -| (0,3); -\end{tikzpicture} -\end{codeexample} - -No special path operation is needed to use a snake. Instead, you use -the following option to ``switch on'' snaking: - -\begin{itemize} - \itemoption{snake}\opt{|=|\meta{snake name}} - This option causes the snake \meta{snake name} to be used for - subsequent line-to operations. So, whenever you use the |--| syntax - to specify that a straight line should be added to the path, a snake - to this path will be added instead. Snakes will also be used when - you use the \verb!-|! and \verb!|-! syntax and also when you use the - |rectangle| operation. Snakes will \emph{not} be used when you use - the curve-to operation nor when any other ``curved'' line is added - to the path. - - This option has to be given anew for each path. However, you can - also leave out the \meta{snake name}. In this case, the enclosing - scope's \meta{snake name} is used. Thus, you can specify a - ``standard'' snake name for scope and then just say |\draw[snake]| - every time this snake should actually be used. - - The \meta{snake name} |none| is special. It can be used to switch - off snaking after it has been switched on on a path. - - A bit strangely, no valid \meta{snake names} are defined by - \tikzname\ by default. Instead, you have to include the library - package |pgflibrarysnakes|. This package defines numerous snakes, - see Section~\ref{section-library-snakes} for the complete list. -\end{itemize} - -Most snakes can be configured. For example, for a snake that looks -like a sine curve, you might wish to change the amplitude or the -frequency. There are numerous options that influence these -parameters. Not all options apply to all snakes, see -Section~\ref{section-library-snakes} once more for details. - -\begin{itemize} - \itemoption{gap before snakes}|=|\meta{dimension} - This option allows you to add a certain ``gap'' to the snake at its - beginning. The snake will not start at the current point; instead - the start point of the snake is move be \meta{dimension} in the - direction of the target. -\begin{codeexample}[] -\begin{tikzpicture} - \draw[help lines] (0,0) grid (3,2); - \draw[snake=zigzag] (0,1) -- ++(3,1); - \draw[snake=zigzag,gap before snake=1cm] (0,0) -- ++(3,1); -\end{tikzpicture} -\end{codeexample} - \itemoption{gap after snake}|=|\meta{dimension} - This option has the same effect as |gap before snake|, only it - affects the end of the snake, which will ``end early.'' - \itemoption{gap around snake}|=|\meta{dimension} - This option sets the gap before and after the gap to - \meta{dimension}. -\begin{codeexample}[] -\begin{tikzpicture} - \draw[help lines] (0,0) grid (3,2); - \draw[snake=brace] (0,1) -- ++(3,1); - \draw[snake=brace,gap around snake=5mm] (0,0) -- ++(3,1); -\end{tikzpicture} -\end{codeexample} - \itemoption{line before snake}|=|\meta{dimension} - This option works like |gap before snake|, only it will connect the - current point with a straight line to the start of the snake. -\begin{codeexample}[] -\begin{tikzpicture} - \draw[help lines] (0,0) grid (3,2); - \draw[snake=zigzag] (0,1) -- ++(3,1); - \draw[snake=zigzag,line before snake=1cm] (0,0) -- ++(3,1); -\end{tikzpicture} -\end{codeexample} - \itemoption{line after snake}|=|\meta{dimension} - Works line |gap after snake|, only it adds a straight line. - \itemoption{line around snake}|=|\meta{dimension} - Works line |gap around snake|, only it adds straight lines. - \itemoption{raise snake}|=|\meta{dimension} - This option can be used with all snakes. It will offset the snake by - ``raising'' it by \meta{dimension}. A negative \meta{dimension} will - lower the snake. Raising and lowering is always relative to the line - along which the snake is drawn. Here is an example: -\begin{codeexample}[] -\begin{tikzpicture} - \node (a) {A}; - \node (b) at (2,1) {B}; - \draw (a) -- (b); - \draw[snake=brace] (a) -- (b); - \draw[snake=brace,raise snake=5pt,red] (a) -- (b); -\end{tikzpicture} -\end{codeexample} - \itemoption{mirror snake} - This option causes the snake to be ``reflected along the path.'' - This is best understood by looking at an example: -\begin{codeexample}[] -\begin{tikzpicture} - \node (a) {A}; - \node (b) at (2,1) {B}; - \draw (a) -- (b); - \draw[snake=brace] (a) -- (b); - \draw[snake=brace,mirror snake,red,thick] (a) -- (b); -\end{tikzpicture} -\end{codeexample} - This option can be used with every snake and can be combined with - the |raise snake| option. - \itemoption{segment amplitude}|=|\meta{dimension} - This option sets the ``amplitude'' of the snake. For a snake that is - a sine wave this would be the amplitude of this line. For other - snakes this value typically describes how far the snakes ``rises - above'' or ``falls below'' the path. For some snakes, this value is - ignored. -\begin{codeexample}[] -\begin{tikzpicture} - \node (a) {A} node (b) at (2,1) {B} node (c) at (2,-1) {C}; - \draw[snake=zigzag] (a) -- (b); - \draw[snake=zigzag,segment amplitude=5pt,red,thick] (a) -- (c); -\end{tikzpicture} -\end{codeexample} - \itemoption{segment length}|=|\meta{dimension} - This option sets the length of each ``segment'' of a snake. For a - sine wave this would be the wave length, for other snakes it is the - length of each ``repetitive part'' of the snake. -\begin{codeexample}[] -\begin{tikzpicture} - \node (a) {A} node (b) at (2,1) {B} node (c) at (2,-1) {C}; - \draw[snake=zigzag] (a) -- (b); - \draw[snake=zigzag,segment length=20pt,red,thick] (a) -- (c); -\end{tikzpicture} -\end{codeexample} -\begin{codeexample}[] -\begin{tikzpicture} - \node (a) {A} node (b) at (2,1) {B} node (c) at (2,-1) {C}; - \draw[snake=bumps] (a) -- (b); - \draw[snake=bumps,segment length=20pt,red,thick] (a) -- (c); -\end{tikzpicture} -\end{codeexample} - \itemoption{segment object length}|=|\meta{dimension} - This option sets the length of the objects inside each segment of a - snake. This option is only used for snakes in which each segment - contains an object like a triangle or a star. -\begin{codeexample}[] -\begin{tikzpicture} - \node (a) {A} node (b) at (2,1) {B} node (c) at (2,-1) {C}; - \draw[snake=triangles] (a) -- (b); - \draw[snake=triangles,segment object length=8pt,red,thick] (a) -- (c); -\end{tikzpicture} -\end{codeexample} - \itemoption{segment angle}|=|\meta{degrees} - This option sets an angle that is interpreted in a snake-specific - way. For example, the |waves| and |expanding waves| snakes interpret - this as (half the) opening angle of the wave. The |border| snake - uses this value for the angle of the little ticks. -\begin{codeexample}[] -\begin{tikzpicture}[segment amplitude=10pt] - \node (a) {A} node (b) at (2,0) {B}; - \draw[snake=border] (a) -- (b); - \draw[snake=border,segment angle=20,red,thick] (a) -- (b); -\end{tikzpicture} -\end{codeexample} -\begin{codeexample}[] -\begin{tikzpicture}[segment amplitude=10pt] - \node (a) {A} node (b) at (2,0) {B}; - \node (a') at (0,-1) {A} node (b') at (2,-1) {B}; - \draw[snake=expanding waves] (a) -- (b); - \draw[snake=expanding waves,segment angle=20,red,thick] (a') -- (b'); -\end{tikzpicture} -\end{codeexample} - \itemoption{segment aspect}|=|\meta{ratio} - This option sets an aspect ratio that is interpreted in a - snake-specific way. For example, for the |coils| snake this - describes the ``direction'' from which the coil is viewed. -\begin{codeexample}[] -\begin{tikzpicture}[segment amplitude=5pt,segment length=5pt] - \node (a) {A} node (b) at (2,1) {B} node (c) at (2,-1) {C}; - \draw[snake=coil] (a) -- (b); - \draw[snake=coil,segment aspect=0,red,thick] (a) -- (c); -\end{tikzpicture} -\end{codeexample} -\end{itemize} - -It is possible to define new snakes, but this cannot be done inside -\tikzname. You need to use the command |\pgfdeclaresnake| from the -basic level directly, see Section~\ref{section-base-snakes}. - -The following styles define combinations of segment settings that may -be useful: -\begin{itemize} - \itemstyle{snake triangles 45} - Installs a snake the consists of little triangles with an opening - angle of $45^\circ$. - \itemstyle{snake triangles 60} - Installs a snake the consists of little triangles with an opening - angle of $60^\circ$. - \itemstyle{snake triangles 90} - Installs a snake the consists of little triangles with an opening - angle of $90^\circ$. -\end{itemize} - - - \subsection{The Curve-To Operation} The curve-to operation allows you to extend a path using a Bézier @@ -542,8 +298,7 @@ special syntax is available for them. All of the path construction operations mentioned up to now are influenced by the following option: -\begin{itemize} - \itemoption{rounded corners}\opt{|=|\meta{inset}} +\begin{key}{/tikz/rounded corners=\meta{inset} (default 4pt)} When this option is in force, all corners (places where a line is continued either via line-to or a curve-to operation) are replaced by little arcs so that the corner becomes smooth. @@ -590,11 +345,12 @@ Here is a rectangle with rounded corners: ``rounding'' may cause inadverted effects. In such case it may be necessary to temporarily switch off the rounding using |sharp corners|. +\end{key} - \itemoption{sharp corners} +\begin{key}{/tikz/sharp corners} This options switches off any rounding on subsequent corners of the path. -\end{itemize} +\end{key} @@ -662,7 +418,7 @@ You can add a grid to the current path using the |grid| path operation. \begin{pathoperation}{grid}{\opt{\oarg{options}}\meta{corner}} - This operations adss a grid filling a rectangle whose two corners + This operations adds a grid filling a rectangle whose two corners are given by \meta{corner} and by the previous coordinate. Thus, the typical way in which a grid is drawn is |\draw (1,1) grid (3,3);|, which yields a grid filling the rectangle whose corners are at @@ -677,8 +433,9 @@ operation. used to influence the appearance of the grid. The stepping of the grid is governed by the following options: -\begin{itemize} - \itemoption{step}|=|\meta{number or dimension or coordinate} sets the stepping in both the +\begin{key}{/tikz/step=\meta{number or dimension or coordinate} + (initially 1cm)} + Sets the stepping in both the $x$ and $y$-direction. If a dimension is provided, this is used directly. If a number is provided, this number is interpreted in the $xy$-coordinate system. For example, if you provide the number |2|, @@ -707,15 +464,18 @@ operation. or $(\meta{x-grid-step-dimension},0\mathrm{pt})$, the second vector is $(0,\meta{y-grid-step-number})$ or $(0\mathrm{pt},\meta{x-grid-step-dimension})$. - - \itemoption{xstep}|=|\meta{dimension or number} sets the stepping in the - $x$-direction. +\end{key} + +\begin{key}{/tikz/xstep=\meta{dimension or number} (initially 1cm)} + Sets the stepping in the $x$-direction. \begin{codeexample}[] \tikz \draw (0,0) grid [xstep=.5,ystep=.75] (3,2); \end{codeexample} -\itemoption{ystep}|=|\meta{dimension or number} sets the stepping in the - $y$-direction. -\end{itemize} +\end{key} + +\begin{key}{/tikz/ystep=\meta{dimension or number} (initially 1cm)} + Sets the stepping in the $y$-direction. +\end{key} It is important to note that the grid is always ``phased'' such that it contains the point $(0,0)$ if that point happens to be inside the @@ -726,15 +486,15 @@ operation. add an epsilon to the corner points. The following style is useful for drawing grids: -\begin{itemize} - \itemstyle{help lines} +\begin{stylekey}{/tikz/help lines (initially {line width=0.2pt,gray})} This style makes lines ``subdued'' by using thin gray lines for them. However, this style is not installed automatically and you have to say for example: \begin{codeexample}[] -\tikz \draw[style=help lines] (0,0) grid (3,3); +\tikz \draw[help lines] (0,0) grid (3,3); \end{codeexample} -\end{itemize} +\end{stylekey} + \end{pathoperation} @@ -765,8 +525,7 @@ parabola[parabola height=-1.5ex] +(2ex,0ex);. \end{codeexample} The following options influence parabolas: -\begin{itemize} - \itemoption{bend}|=|\meta{coordinate} +\begin{key}{/tikz/bend=\meta{coordinate}} Has the same effect as saying |bend|\meta{coordinate} outside the \meta{options}. The option specifies that the bend of the parabola should be at the given \meta{coordinate}. You have to take care @@ -781,8 +540,9 @@ parabola[parabola height=-1.5ex] +(2ex,0ex);. position lies somewhere on a line from the old current point to the new current point. The exact position depends on the next option. +\end{key} - \itemoption{bend pos}|=|\meta{fraction} +\begin{key}{/tikz/bend pos=\meta{fraction}} Specifies where the ``previous'' point is relative to which the bend is calculated. The previous point will be at the \meta{fraction}th part of the line from the old current point to the new current @@ -805,25 +565,29 @@ parabola[parabola height=-1.5ex] +(2ex,0ex);. parabola that is 2cm high'' and |+(3,0)| means ``and 3cm wide.'' Since this situation arises often, there is a special shortcut option: - \itemoption{parabola height}|=|\meta{dimension} This option has the - same effect as if you had written the following instead: - |[bend pos=0.5,bend={+(0pt,|\meta{dimension}|)}]|. + \begin{key}{/tikz/parabola height=\meta{dimension}} + This option has the same effect as + |[bend pos=0.5,bend={+(0pt,|\meta{dimension}|)}]|. \begin{codeexample}[] \begin{tikzpicture} \draw[help lines] (0,0) grid (3,2); \draw (-1,0) parabola[parabola height=2cm] +(3,0); \end{tikzpicture} \end{codeexample} -\end{itemize} + \end{key} +\end{key} The following styles are useful shortcuts: -\begin{itemize} - \itemstyle{bend at start} This places the bend at the start of a +\begin{stylekey}{/tikz/bend at start} + This places the bend at the start of a parabola. It is a shortcut for the following options: - |bend pos=0,bend={+(0,0)}|. - \itemstyle{bend at end} This places the bend at the end of a - parabola. -\end{itemize} + |bend pos=0,bend={+(0,0)}|. +\end{stylekey} + +\begin{stylekey}{/tikz/bend at end} + This places the bend at the end of a parabola. +\end{stylekey} + \end{pathoperation} @@ -902,7 +666,7 @@ trigger a special path to be used instead of the straight line. \textbf{Start and Target Coordinates.}\ \ The |to| operation is always followed by a \meta{coordinate}, called the target coordinate. The macro |\tikztotarget| is set to this - coordinate (without the parantheses). There is also a \emph{start + coordinate (without the parentheses). There is also a \emph{start coordinate}, which is the coordinate preceding the |to| operation. This coordinate can be accessed via the macro |\tikztostart|. In the following example, for the first |to|, the @@ -943,17 +707,14 @@ trigger a special path to be used instead of the straight line. \textbf{Styles for nodes.}\ \ In addition to the \meta{options} given after the |to| operation, the following style is also set at the beginning of the to path: - \begin{itemize} - \itemstyle{every to} + \begin{stylekey}{/tikz/every to (initially \normalfont empty)} This style is installed at the beginning of every to. By default, it is set to |draw|. \begin{codeexample}[] -\begin{tikzpicture} - \tikzstyle{every to}=[draw,dashed] +\tikz[every to/.style={draw,dashed}] \path (0,0) to (3,2); -\end{tikzpicture} \end{codeexample} - \end{itemize} + \end{stylekey} \medskip \textbf{Options.}\ \ @@ -963,8 +724,7 @@ trigger a special path to be used instead of the straight line. straight line to, say, a curve. The path used is set using the following option: - \begin{itemize} - \itemoption{to path}|=|\meta{path} + \begin{key}{/tikz/to path=\meta{path}} Whenever an |to| operation is used, the \meta{path} is inserted. More precisely, the following path is added: @@ -979,7 +739,7 @@ trigger a special path to be used instead of the straight line. from- and to-coordinates. In detail, these are: \begin{itemize} \item \declare{|\tikztostart|} will expand to the from-coordinate - (without the parantheses). + (without the parentheses). \item \declare{|\tikztotarget|} will expand to the to-coordinate. \item \declare{|\tikztonodes|} will expand to the nodes between the |to| operation and the coordinate. Furthermore, these @@ -1029,9 +789,10 @@ trigger a special path to be used instead of the straight line. Here is another example: \begin{codeexample}[] -\tikzstyle{my loop}=[->,to path={ - .. controls +(80:1) and +(100:1) .. (\tikztotarget) \tikztonodes}] -\tikzstyle{my state}= [circle,draw] +\tikzset{ + my loop/.style={->,to path={ + .. controls +(80:1) and +(100:1) .. (\tikztotarget) \tikztonodes}}, + my state/.style={circle,draw}} \begin{tikzpicture}[shorten >=2pt] \node [my state] (a) at (210:1) {$q_a$}; @@ -1042,26 +803,176 @@ trigger a special path to be used instead of the straight line. \end{tikzpicture} \end{codeexample} - \itemoption{execute at begin to}|=|\meta{code} - The \meta{code} is executed prior to the to. This can be used to - draw one or more additional paths or to do additional - computations. + \begin{key}{/tikz/execute at begin to=\meta{code}} + The \meta{code} is executed prior to the to. This can be used to + draw one or more additional paths or to do additional + computations. + \end{key} + + \begin{key}{/tikz/executed at end to=\meta{code}} + Works like the previous option, only this code is executed after + the to path has been added. + \end{key} - \itemoption{executed at end to}|=|\meta{code} - Works like the previous option, only this code is executed after - the to path has been added. - \itemstyle{every to} - This style is installed at the beginning of every to. It is empty - by default. - \end{itemize} + \begin{stylekey}{/tikz/every to (initially \normalfont empty)} + This style is installed at the beginning of every to. + \end{stylekey} + \end{key} \end{pathoperation} There are a number of predefined |to path|s, see Section~\ref{library-to-paths} for a reference. - +\subsection{The Let Operation} + +The \emph{let operation} is the first of a number of path operations +that do not actually extend that path, but have different, mostly +local, effects. + +\begin{pathoperation}{let}{\meta{assignment} + \opt{|,|\meta{assignment}}% + \opt{|,|\meta{assignment}\dots}\declare{| in |}} + When this path operation is encountered, the \meta{assignment}s are + evaluated, one by one. This will store coordinate and number in + special \emph{registers} (which are local to \tikzname, they have + nothing to do with \TeX\ registers). Subsequently, one can access the + contents of these registers using the macros |\p|, |\x|, |\y|, and + |\n|. + + The first kind of permissible \meta{assignment}s have the following + form: + \begin{quote} + |\n|\meta{number register}|={|\meta{formula}|}| + \end{quote} + When an assignment has this form, the \meta{formula} is evaluated + using the |\pgfmathparse| operation. The result stored in the + \meta{number register}. If the \meta{formula} involves a dimension + anywhere (as in |2*3cm/2|), then the \meta{number register} stores + the resulting dimension with a trailing |pt|. A \meta{number register} can + be named arbitrarily and is a normal \TeX\ parameter to the |\n| + macro. Possible names are |{left corner}|, but also just a single + digit like~|5|. + + Let us call the path that follows a let operation its + \emph{body}. Inside the body, the |\n| macro can be used to access + the register. + \begin{command}{\n\marg{number register}} + When this macro is used on the left-hand side of an |=|-sign in a + let operation, it has no effect and is just there for + readability. When the macro is used on the right-hand side of an + |=|-sign or in the body of the let operation, then it expands to + the value stored in the \meta{number register}. This will either + be a dimensionless number like |2.0| or a dimension like |5.6pt|. + + For instance, if we say |let \n1={1pt+2pt}, \n2={1+2} in ...|, then + inside the |...| part the macro |\n1| will expand to |3pt| and + |\n2| expands to |3|. + \end{command} + + The second kind of \meta{assignements} have the following form: + \begin{quote} + |\p|\meta{point register}|={|\meta{formula}|}| + \end{quote} + Point position registers store a single point, consisting + of an $x$-part and a $y$-part measured in \TeX\ points (|pt|). In + particular, point registers do not stored nodes or node names. + Here is an example: +\begin{codeexample}[] +\begin{tikzpicture} + \draw [help lines] (0,0) grid (3,2); + + \draw let \p{foo} = (1,1), \p2 = (2,0) in + (0,0) -- (\p2) -- (\p{foo}); +\end{tikzpicture} +\end{codeexample} + + \begin{command}{\p\marg{point register}} + When this macro is used on the left-hand side of an |=|-sign in a + let operation, it has no effect and is just there for + readability. When the macro is used on the right-hand side of an + |=|-sign or in the body of the let operation, then it expands to + the $x$-part (measured in \TeX\ points) of the coordinate stored + in the \meta{register}, followed, by a comma, followed by the + $y$-part. + + For instance, if we say |let \p1=(1pt,1pt+2pt) in ...|, then + inside the |...| part the macro |\p1| will expand to exactly the + seven characters ``1pt,3pt''. This means that you when you write + |(\p1)|, this expands to |(1pt,3pt)|, which is presumably exactly + what you intended. + \end{command} + \begin{command}{\x\marg{point register}} + This macro expand just to the $x$-part of the point + register. If we say as above, as we did above, + |let \p1=(1pt,1pt+2pt) in ...|, then + inside the |...| part the macro |\x1| expands to |1pt|. + \end{command} + \begin{command}{\y\marg{point register}} + Works like |\x|, only for the $y$-part. + \end{command} + Note that the above macros are available only inside a let + operation. + + Here is an example where let clauses are used to assemble a coordinate + from the $x$-coordinate of a first point and the $y$-coordinate of a + second point. Naturally, using the \verb!|-! notation, this could be + written much more compactly. +\begin{codeexample}[] +\begin{tikzpicture} + \draw [help lines] (0,0) grid (3,2); + + \draw (1,0) coordinate (first point) + -- (3,2) coordinate (second point); + + \fill[red] let \p1 = (first point), + \p2 = (second point) in + (\x1,\y2) circle (2pt); +\end{tikzpicture} +\end{codeexample} + + Note that the effect of a let operation is local to the body of the + let operation. If you wish to access a computed coordinate outside + the body, you must use a |coordinate| path operation: +\begin{codeexample}[] +\begin{tikzpicture} + \draw [help lines] (0,0) grid (3,2); + + \path % let's define some points: + let + \p1 = (1,0), + \p2 = (3,2), + \p{center} = ($ (\p1) !.5! (\p2) $) % center + in + coordinate (p1) at (\p1) + coordinate (p2) at (\p2) + coordinate (center) at (\p{center}); + + \draw (p1) -- (p2); + \fill[red] (center) circle (2pt); +\end{tikzpicture} +\end{codeexample} + + For a more useful application of the let operation, let use draw a + circle that touches a given line: +\begin{codeexample}[] +\begin{tikzpicture} + \draw [help lines] (0,0) grid (3,3); + + \coordinate (a) at (rnd,rnd); + \coordinate (b) at (3-rnd,3-rnd); + \draw (a) -- (b); + + \node (c) at (1,2) {x}; + + \draw let \p1 = ($ (a)!(c)!(b) - (c) $), + \n1 = {veclen(\x1,\y1)} + in (c) circle (\n1); +\end{tikzpicture} +\end{codeexample} +\end{pathoperation} + \subsection{The Scoping Operation} @@ -1072,18 +983,21 @@ inside the scope. For example, if you apply a transformation like |[xshift=1cm]| inside the scoped area, the shifting only applies to the scope. On the other hand, an option like |color=red| does not have any effect inside a scope since it can only be applied to the path as -a whole. +a whole. + +Concerning the effect of scopes on relative coordinates, +please see Section~\ref{section-scopes-relative}. -\subsection{The Node Operation} +\subsection{The Node and Edge Operations} -There are teo more operations that can be found in paths: +There are two more operations that can be found in paths: |node| and |edge|. The first is used to add a so-called node to a path. This operation is special in the following sense: It does not change the current path in any way. In other words, this operation is not really a path operation, but has an effect that is ``external'' to the path. The |edge| operation has similar effect in -that it adds something \emph{after} the main parth has been +that it adds something \emph{after} the main path has been drawn. However, it works like the |to| operation, that is, it adds a |to| path to the picture after the main path has been drawn. |