summaryrefslogtreecommitdiff
path: root/graphics/pgf/contrib/spath3/spath3.tex
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/pgf/contrib/spath3/spath3.tex')
-rw-r--r--graphics/pgf/contrib/spath3/spath3.tex223
1 files changed, 195 insertions, 28 deletions
diff --git a/graphics/pgf/contrib/spath3/spath3.tex b/graphics/pgf/contrib/spath3/spath3.tex
index 7621db4a28..c8e9d65af7 100644
--- a/graphics/pgf/contrib/spath3/spath3.tex
+++ b/graphics/pgf/contrib/spath3/spath3.tex
@@ -1,5 +1,5 @@
-%\RequirePackage{shellesc}
-%\immediate\write18{tex spath3_code.dtx}
+\RequirePackage{shellesc}
+\immediate\write18{tex spath3_code.dtx}
\documentclass{l3doc}
\usepackage{tikz}
\usetikzlibrary{
@@ -89,12 +89,62 @@ The best way is to open an issue at the code repository on github, at \href{http
\end{lstlisting}
The \texttt{spath3} TikZ library defines a set of keys that can be issued to muck about with soft paths.
-These are all defined in the \texttt{spath} family, so all the following keys should be prefixed by \texttt{spath/}, or the key \texttt{spath/.cd} needs to be used beforehand (but note that as yet I haven't implemented sending unknown keys back to the main \Verb+tikz+ directory).
+These are all defined in the |spath| family, so all the following keys should be prefixed by |spath/|, or the key |spath/.cd| needs to be used beforehand (but note that as yet I haven't implemented sending unknown keys back to the main |tikz| directory).
-The keys try to gracefully fail if the path doesn't exist or is empty.
+The keys try to gracefully fail if the path doesn't exist or is empty\footnote{A path that was defined inside a group will be empty if referred to outside that group rather than not existing.}.
The intention is that the document should still compile with a warning in the log file (and on the console output).
If this doesn't happen, please report it.
+\subsection{Path Names}
+
+Soft paths are stored in macros but are referred to via a name.
+The macro is constructed from the name, but there is scope for a prefix and suffix.
+By default, these are set up so to be compatible with the |intersections| library -- this package and that save their paths in the same underlying macro.
+Some packages that are built on top of this one (such as the |knot| and |penrose| packages) install their own prefixes and suffixes to avoid clashes.
+
+\begin{function}{
+ set prefix,
+ set suffix,
+ prefix,
+ suffix
+}
+\begin{syntax}
+|set prefix=|\marg{prefix}
+|set suffix=|\marg{suffix}
+|prefix=|\oarg{name}
+|suffix=|\oarg{name}
+|set name=|\oarg{name}
+\end{syntax}
+The first two keys set the prefix and suffix directly.
+The other keys allow for defining a label for a prefix and suffix for quick switching between different ones.
+The default (with key |default| or no key specified) is to match the |intersections| library.
+The |knots| library uses this to set a different prefix.
+\end{function}
+
+Using names rather than macros directly also makes it possible to link a soft path with a set of TikZ styles (this is particularly useful when splitting the path into components).
+
+\begin{variable}{current}
+\begin{syntax}
+|\path (0,0) -- (3,0) to[out=90, in=90] (1,0) [spath/adjust and close=current];|
+\end{syntax}
+
+There is a special path name, |current|, which refers to the current path being built.
+To be clear, the test for this name takes place before any prefix or suffix is applied so it depends only on what the user uses.
+
+When this name is encountered, the current path is copied into a macro and that path is used in the command.
+If the command is such that it is possible that the path is modified in some fashion then after the command is finished the old current path is replaced by the new one.
+There are several commands that take multiple paths and |current| can be used in place of any of the paths, but usually there is only one that is modified and so that is the only one that would be used to replace the old current path.
+
+It only makes sense to use it in a path-building context, and it refers to the path at the moment of invocation, so it doesn't do a lot in the main options on that path but it can be used in options later on in the process.
+
+Sometimes it isn't possible to put commands partway through a path (for example, if the path command is buried in another macro) so there is a key which can be used to delay things to the end of the construction:
+
+\begin{verbatim}
+at end path construction={code}
+\end{verbatim}
+%
+This invokes the |code| right after the path has finished being built.
+\end{variable}
\subsection{Saving and Using Soft Paths}
@@ -104,16 +154,14 @@ If this doesn't happen, please report it.
|save global=|\meta{name}
\end{syntax}
-Saves the current path with name \texttt{<name>}.
+Saves the current path with name \meta{name}.
This delays until the path is fully constructed so can be issued in the options to the main command.
Soft paths constructed this way are local to the group in which the path command is issued.
The |global| version saves the path globally which is useful when the original path is inside a scope or even another tikzpicture.
-The soft path is actually stored in a macro constructed from the name.
-There are a couple of reasons for using a \emph{name} rather than a macro directly.
-One is so that it is compatible with the \texttt{intersections} library -- by default both this package and that save their paths in the same underlying macro.
-The other is to provide a way to link a soft path with a set of TikZ styles (this is particularly useful when splitting the path into components).
+If wanting to save the border of a node then because there are extra levels of grouping, the global version of this key has to be used.
+
\end{function}
\begin{function}{clone, clone globally}
@@ -124,6 +172,22 @@ The other is to provide a way to link a soft path with a set of TikZ styles (thi
Clones one soft path into another.
In the second, the clone is global (the original need not be).
+
+By using |current| as the source name, the current soft path in its current state is copied.
+This can be used to get round the restriction whereby |save path| waits until the path is fully constructed before being saved.
+\end{function}
+
+\begin{function}{show, show current path}
+\begin{syntax}
+|show=|\meta{name}
+|show current path|
+\end{syntax}
+
+These keys display a path on the terminal and in the log file.
+They do a bit of sensible line formatting so that the paths are relatively easy to scan through.
+
+The key |show current path| delays the logging until the path is fully constructed.
+To get a view of what the path is at an intermediate stage of construction, use |show=current|.
\end{function}
\begin{function}{use}
@@ -145,20 +209,22 @@ The options is a comma separated list and can include:
\item |weld|, |no weld| determines whether to weld the inserted path to the current path.
Welding means that the |move to| at the start of the inserted path is removed.
Note that this doesn't \emph{move} the inserted path so this will usually modify the first segment of the inserted path, possibly in unexpected ways.
+The expected use is that when the |weld| key is used then the inserted path starts where the current path ends either because it already does or because the |move| key has also been invoked.
+But there's nothing \emph{stopping} anyone using this key in other circumstances.
\item |move|, |no move| determines whether the inserted path is translated so that it starts where the current path ends.
\item |transform=|\marg{transformations} applies the specified transformations to the inserted path.
-See the |transform| key in Section~\ref{sec:transform}
+See the |transform| key in Section~\ref{sec:transform}.
+\item |use current transformation| applies the current transformation to the inserted path.
+Note that because the keys are processed and then acted upon, this key is always applied \emph{before} the |transform| key.
\item Any other key is taken as the name of the path (so it doesn't have to be specified first) with the last one winning.
\end{itemize}
One thing should be noted about transformations.
By the time a soft path is built, all available transformations have been applied.
-This means that when re-inserting a soft path back into a high level command (such as |\draw|), the effect of existing transformations might produce some confusing effects.
-When restoring a path then the library tries to set up various internals of TikZ correctly, but there may be some things I've overlooked or not accounted for particularly with regard to existing transformations; if you spot anything working oddly then please report it to me.
-
-In particular, restoring a path should sets things right for positioning nodes along the path.
-Using the \Verb+pos=D+ key on a node positions that node at a particular point on the path.
+This means that when re-inserting a soft path back into a high level command (such as |\draw|), existing transformations should have no effect (other than those specified via the |transform| key).
+Where this gets a little tricky is with things like node placement -- using the \Verb+pos=D+ key on a node positions that node at a particular point on the path.
Exactly how the parameter is interpreted is the same as for the \Verb+spath+ coordinate system described in Section~\ref{sec:coordinates}.
+When restoring a path then the library tries to set up various internals of TikZ correctly, but there may be some things I've overlooked or not accounted for particularly with regard to existing transformations; if you spot anything working oddly then please report it to me.
\end{function}
\begin{function}{
@@ -183,6 +249,19 @@ The equivalences are:
\end{itemize}
\end{function}
+\begin{function}{join with}
+\begin{syntax}
+|join with=|\marg{path}\marg{path, options}
+\end{syntax}
+
+This joins the second path to the first, with applying the specified options.
+The options are the same as for the |use| key.
+The first path is modified, the second is not (the second path is copied before any modifications are applied).
+
+It is almost the case that |join with={current}{...}| is synonymous with |use={...}|.
+The difference is that |use={...}| applies an extra check to ensure that the resulting path is not empty.
+\end{function}
+
\begin{function}{to}
\begin{syntax}
|to=|\marg{name}
@@ -198,7 +277,7 @@ The path is transformed by rotation, translation, and uniform scaling so that it
\label{sec:transform}
The following keys all apply some sort of transformation to the soft path.
-They do not render the path, but simply adjust it.
+They do not render the path, but simply adjust it (but they can be used to modify the current path by invoking with the path name |current|).
The global versions apply their transformation globally, otherwise it is local to the current group (or scope).
\begin{function}{reverse, reverse global}
@@ -245,9 +324,6 @@ As with the \Verb+to+ path construction and the \Verb+splice+ method, this won't
\subsection{Intersection Routines}
To use these features you need to use the \texttt{intersections} library.
-Note that there is currently an issue with the intersections routine when trying to intersect two parallel (or near parallel) lines.
-One workaround is to replace one of the lines by a B\'ezier curve along the same path.
-The best such replacement is to put the control points at one third and two thirds between the start and end.
\begin{function}{
split at self intersections,
@@ -346,18 +422,27 @@ It applies the following styles (in this order):
\begin{function}{
insert gaps after components,
- insert gaps globally after components
+ insert gaps globally after components,
+ insert gaps after segments,
+ insert gaps globally after segments
}
\begin{syntax}
|insert gaps after components=|\marg{path}\marg{gap}\marg{components}
|insert gaps after components=|\marg{path}\marg{gap}
|insert gaps globally after components=|\marg{path}\marg{gap}\marg{components}
|insert gaps globally after components=|\marg{path}\marg{gap}
+|insert gaps after segments=|\marg{path}\marg{gap}\marg{segments}
+|insert gaps after segments=|\marg{path}\marg{gap}
+|insert gaps globally after segments=|\marg{path}\marg{gap}\marg{segments}
+|insert gaps globally after segments=|\marg{path}\marg{gap}
\end{syntax}
This inserts a gap between components of a path by shortening the end of the specified component and start of the next one.
The list of components is passed through a |\foreach| loop so that syntax like |2,4,...,16| can be used.
If the list of components is not given the gaps are inserted between all components.
+
+The \texttt{segments} versions work on the segments of the path rather than its components.
+A \emph{segment} is a minimal drawing piece, meaning a line or B\'ezier curve.
\end{function}
\begin{function}{
@@ -374,16 +459,20 @@ The list of components is processed by |\foreach|.
If the component is the first one then it is joined to the last component.
\end{function}
-\begin{function}{join components with, join components globally with, join components upright with, join components globally upright with}
+\begin{function}{join components with, join components globally with, join components upright with, join components globally upright with, join components with curve, join components globally with curve}
\begin{syntax}
|join components with=|\marg{path}\marg{splice path}
|join components with=|\marg{path}\marg{splice path}\marg{list}
|join components upright with=|\marg{path}\marg{splice path}
|join components upright with=|\marg{path}\marg{splice path}\marg{list}
+|join components with curve=|\marg{path}
+|join components with curve=|\marg{path}\marg{list}
|join components globally with=|\marg{path}\marg{splice path}
|join components globally with=|\marg{path}\marg{splice path}\marg{list}
|join components globally upright with=|\marg{path}\marg{splice path}
|join components globally upright with=|\marg{path}\marg{splice path}\marg{list}
+|join components globally with curve=|\marg{path}
+|join components globally with curve=|\marg{path}\marg{list}
\end{syntax}
This inserts the |splice path| in the gaps between components of |path| specified by a comma separated list.
@@ -396,6 +485,9 @@ This does \emph{not} close the resulting path, even if the last component is spe
Note that because there is an optional third argument to this key, the second argument must always be enclosed in braces unless it is a single token.
The |upright| versions do a little test to see if the gap is oriented upside-down and if so then they insert the reflection of the splice path.
+
+The |with curve| versions insert a single B\'ezier curve into the gap.
+The curve is chosen to match the tangents of the segments either side of the gap and uses John Hobby's construction of a B\'ezier curve from its tangent directions.
\end{function}
@@ -436,18 +528,36 @@ This removes the listed components of the path.
As with other list routines, the list is parsed via |foreach| first.
\end{function}
+\begin{function}{open, open globally}
+\begin{syntax}
+|open=|\marg{path}
+|open globally=|\marg{path}
+\end{syntax}
-\begin{function}{close, close globally, close with, close globally with}
+These open the path by removing all of the closing elements.
+If the closing elements add substantially to the path then they are replaced by a line segment.
+\end{function}
+
+
+\begin{function}{close, close globally, close with, close globally with, close with curve, close globally with curve, adjust and close, adjust and close globally}
\begin{syntax}
|close=|\marg{path}
|close globally=|\marg{path}
|close with=|\marg{path}\marg{splice path}
|close globally with=|\marg{path}\marg{splice path}
+|close with curve=|\marg{path}
+|close globally with curve=|\marg{path}
+|adjust and close=|\marg{path}
+|adjust and close globally=|\marg{path}
\end{syntax}
These all close the last component of the given path.
The first two will insert a line segment if the initial and final points of the component are not sufficiently close.
-The latter two allow you to specify another path to insert.
+The two |with| variants allow you to specify another path to insert between the end and start of the path.
+The two |with curve| variants insert a B\'ezier curve in the gap; the choice of curve depends on the tangents of the path segments being joined and uses John Hobby's B\'ezier curve construction (as used in the \texttt{hobby} TikZ library).
+The two |adjust| variants shift the end point of the path so that it is at the same place as the start of that component.
+If the last segment is a B\'ezier curve then the second control point is also shifted.
+(The intention with the |adjust| keys is where the start and end of the component are very close together so the adjustment creates a smaller visual effect than adding in a line -- see Example~\ref{ex:close}.)
\end{function}
\begin{function}{splice, splice global}
@@ -461,7 +571,7 @@ The middle path is transformed to fit (don't try this with a path whose starting
\end{function}
-\subsection{Shortening Paths}
+\subsection{Shortening and Splitting Paths}
\begin{function}{
shorten at end,
@@ -488,6 +598,42 @@ It uses the derivative at the end to work out how much to shorten by.
If wanting to shorten by a large amount it is better to shorten by a small amount a number of times.
\end{function}
+\begin{function}{
+ split at,
+ split globally at,
+ split at into,
+ split globally at into,
+ split at keep start,
+ split globally at keep start,
+ split at keep end,
+ split globally at keep end,
+ split at keep middle,
+ split globally at keep middle,
+}
+\begin{syntax}
+|split at=|\marg{path}\marg{parameter}
+|split globally at=|\marg{path}\marg{parameter}
+|split at into=|\marg{start path}\marg{end path}\marg{path}\marg{parameter}
+|split globally at into=|\marg{start path}\marg{end path}\marg{path}\marg{parameter}
+|split at keep start=|\marg{path}\marg{parameter}
+|split globally at keep start=|\marg{path}\marg{parameter}
+|split at keep end=|\marg{path}\marg{parameter}
+|split globally at keep end=|\marg{path}\marg{parameter}
+|split at keep middle=|\marg{path}\marg{parameter}\marg{parameter}
+|split globally at keep middle=|\marg{path}\marg{parameter}\marg{parameter}
+\end{syntax}
+
+These keys split a path at a point specified by a parameter.
+The interpretation of the parameter is described in Section~\ref{sec:coordinates}.
+
+The first two keys replace the path with the split path, so this introduces a break at the point specified by the parameter.
+The second two save the split path into a new path.
+
+The ones with \texttt{keep} in the name split a path and keep the designated piece (so throw away the rest).
+The ones that keep the middle need two parameters to specify the break points.
+
+\end{function}
+
\subsection{Exporting Paths}
There are two keys to export a path.
@@ -516,8 +662,8 @@ Saves the path to the file \texttt{path.svg} as an SVG document.
draft mode
}
\begin{syntax}
-|knot=|\meta{path}\meta{gap}\meta{components}
-|global knot=|\meta{path}\meta{gap}\meta{components}
+|knot=|\marg{path}\marg{gap}\marg{components}
+|global knot=|\marg{path}\marg{gap}\marg{components}
\end{syntax}
This style combines various of the above to make it simpler to draw knots and links.
@@ -679,6 +825,24 @@ The intention with the second key is that it is similar to what happens with the
\end{tikzpicture}
\end{example}
+\item Closing and adjusting paths.
+\label{ex:close}
+
+\begin{example}
+\begin{tikzpicture}
+\draw[line width=.2cm] (0,0) -- +(1,0) -- +(1,1) -- +(0,1) -- +(.01,.01);
+
+\draw[line width=.2cm] (2,0) -- +(1,0) -- +(1,1) -- +(0,1) -- +(.01,.01)
+-- cycle;
+
+\draw[line width=.2cm] (4,0) -- +(1,0) -- +(1,1) -- +(0,1) -- +(.01,.01)
+[spath/close=current];
+
+\draw[line width=.2cm] (6,0) -- +(1,0) -- +(1,1) -- +(0,1) -- +(.01,.01)
+[spath/adjust and close=current];
+\end{tikzpicture}
+\end{example}
+
\item Shortening.
\begin{example}
@@ -929,8 +1093,8 @@ sin ++(1.57,1);
}
% If used in the preamble, this needs surrounding in \AtBeginDocument
-%\AtBeginDocument{
-\tikz[overlay] \path[spath/save=arc] (0,0) arc[radius=1cm, start angle=180, delta angle=-180];
+%\AtBeginDocument{%
+\tikz[overlay] { \path[spath/save global=arc] (0,0) arc[radius=1cm, start angle=180, delta angle=-180]; }%
%}
\begin{tikzpicture}
\path[spath/save=over] (0,0) -| ++(1,1) -| ++(-1,1) -| ++(1,1) -| ++(-1,1);
@@ -941,5 +1105,8 @@ sin ++(1.57,1);
\end{tikzpicture}
\end{example}
+The command defining the arc does introduce a box which can introduce additional spacing.
+The syntax above, with the \% at the end of the lines, shouldn't add space but if for some reason it does then more sophisticated solutions to this are detailed at \href{https://tex.stackexchange.com/q/605800/86}{How to save or define a TikZ path for spath3 without introducing artifacts?}.
+
\end{enumerate}
\end{document}