summaryrefslogtreecommitdiff
path: root/graphics/pgf/contrib/spath3/spath3_code.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/pgf/contrib/spath3/spath3_code.dtx')
-rw-r--r--graphics/pgf/contrib/spath3/spath3_code.dtx127
1 files changed, 91 insertions, 36 deletions
diff --git a/graphics/pgf/contrib/spath3/spath3_code.dtx b/graphics/pgf/contrib/spath3/spath3_code.dtx
index 031c0e7bd3..3b0178db5a 100644
--- a/graphics/pgf/contrib/spath3/spath3_code.dtx
+++ b/graphics/pgf/contrib/spath3/spath3_code.dtx
@@ -5,7 +5,7 @@
%<*readme>
----------------------------------------------------------------
spath3 --- LaTeX3 functions for manipulating PGF soft paths
-E-mail: loopspace@mathforge.org
+E-mail: Andrew Stacey <loopspace@mathforge.org>
Released under the LaTeX Project Public License v1.3c or later
See http://www.latex-project.org/lppl.txt
----------------------------------------------------------------
@@ -27,7 +27,7 @@ As applications of its use, included are a package for drawing calligraphic path
\preamble
----------------------------------------------------------------
spath3 --- Functions for manipulating PGF soft paths
-E-mail: loopspace@mathforge.org
+E-mail: Andrew Stacey <loopspace@mathforge.org>
Released under the LaTeX Project Public License v1.3c or later
See http://www.latex-project.org/lppl.txt
----------------------------------------------------------------
@@ -35,7 +35,7 @@ See http://www.latex-project.org/lppl.txt
\endpreamble
\postamble
-Copyright (C) 2011-2021 by Andrew Stacey <loopspace@mathforge.org>
+Copyright (C) 2011-2024 by Andrew Stacey <loopspace@mathforge.org>
This work may be distributed and/or modified under the
conditions of the LaTeX Project Public License (LPPL), either
@@ -60,7 +60,7 @@ and the derived files spath3.ins,
calligraphy.pdf
knots.pdf
spath3.pdf
- README
+ README.txt
\endpostamble
\usedir{tex/latex/spath3}
@@ -143,7 +143,7 @@ and the derived files spath3.ins,
%</driver>
% \fi
%
-% \CheckSum{10189}
+% \CheckSum{10278}
%
% \CharacterTable
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
@@ -171,6 +171,7 @@ and the derived files spath3.ins,
% \changes{2.4}{2021/02/21}{Rejigged how the routines for using paths were implemented, added some more routines for joining paths.}
% \changes{2.6}{2021/11/23}{Modified core routines to cope with a "true rectangle" path; added routines for splitting at a parametrised point.}
% \changes{2.7}{2022/08/24}{Bug fixes}
+% \changes{2.8}{2024/05/31}{Routine to disable arrow shortening, bug fixes}
%
% \DoNotIndex{\newcommand,\newenvironment}
%
@@ -198,7 +199,7 @@ and the derived files spath3.ins,
% It was originally not really intended for use by end users but as a foundation on which other packages can be built.
% However, over the years I've found myself using it at ever higher levels and so a set of interfaces has been designed using TikZ keys.
%
-% It also provides the engine that drives a few other packages, such as the \Verb+calligraphy+, \Verb+knot+, and \Verb+penrose+ packages.
+% It also provides the engine that drives a few other packages, such as the \Verb+calligraphy+, \Verb+knot+, and \Verb+tilings+ (formerly, \Verb+penrose+) packages.
% The first two of these are subpackages of this one.
% The \Verb+calligraphy+ package simulates a calligraphic pen stroking a path.
% The \Verb+knots+ package can be used to draw knot (and similar) diagrams.
@@ -208,7 +209,7 @@ and the derived files spath3.ins,
% \begin{itemize}
% \item \Verb+calligraphy+
% \item \Verb+knots+
-% \item \Verb+penrose+
+% \item \Verb+tilings+
% \item \Verb+spath3+ (\emph{this} document is the code, there's another which focusses on usage)
% \end{itemize}
%
@@ -259,7 +260,7 @@ and the derived files spath3.ins,
\NeedsTeXFormat{LaTeX2e}
\RequirePackage{expl3}
\RequirePackage{pgf}
-\ProvidesExplPackage {spath3} {2022/08/24} {2.7} {Functions for
+\ProvidesExplPackage {spath3} {2024/05/31} {2.8} {Functions for
manipulating PGF soft paths}
\RequirePackage{xparse}
% \end{macrocode}
@@ -375,6 +376,13 @@ manipulating PGF soft paths}
\bool_new:N \l_spath_movetorelevant_bool
% \end{macrocode}
%
+% When manipulating soft paths, we might need to separate the shortening due to an arrow from when the path is rendered.
+%
+% \begin{macrocode}
+\bool_new:N \l_spath_arrow_shortening_bool
+\bool_set_true:N \l_spath_arrow_shortening_bool
+% \end{macrocode}
+%
% The intersection routine can't happen inside a group so we need two token lists to hold the paths that we'll intersect.
%
% \begin{macrocode}
@@ -457,7 +465,7 @@ manipulating PGF soft paths}
{
\tl_set:Nx \l_@@_tmpc_tl {\tl_head:N \l_@@_tmpa_tl}
\tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
- \tl_case:NnF \l_@@_tmpc_tl
+ \token_case_meaning:NnF \l_@@_tmpc_tl
{
\c_spath_moveto_tl
{
@@ -718,7 +726,7 @@ manipulating PGF soft paths}
\int_set:Nn \l_@@_tmpa_int {0}
\tl_map_inline:nn {#1} {
\tl_set:Nn \l_@@_tmpa_tl {##1}
- \tl_case:NnT \l_@@_tmpa_tl
+ \token_case_meaning:NnT \l_@@_tmpa_tl
{
\c_spath_lineto_tl {}
\c_spath_curveto_tl {}
@@ -763,7 +771,7 @@ manipulating PGF soft paths}
\int_set:Nn \l_@@_tmpa_int {0}
\tl_map_inline:nn {#1} {
\tl_set:Nn \l_@@_tmpa_tl {##1}
- \tl_case:Nn \l_@@_tmpa_tl
+ \token_case_meaning:Nn \l_@@_tmpa_tl
{
\c_spath_moveto_tl
{
@@ -910,7 +918,7 @@ manipulating PGF soft paths}
}
{
\tl_set:Nx \l_@@_tmpb_tl {\tl_head:N \l_@@_tmpa_tl}
- \tl_case:Nn \l_@@_tmpb_tl
+ \token_case_meaning:Nn \l_@@_tmpb_tl
{
\c_spath_moveto_tl
{
@@ -1102,7 +1110,7 @@ manipulating PGF soft paths}
}
{
\tl_set:Nx \l_@@_tmpb_tl {\tl_head:N \l_@@_tmpa_tl}
- \tl_case:Nn \l_@@_tmpb_tl
+ \token_case_meaning:Nn \l_@@_tmpb_tl
{
\c_spath_moveto_tl
{
@@ -1229,7 +1237,7 @@ manipulating PGF soft paths}
\tl_set:Nx \l_@@_tmpc_tl {\tl_head:N \l_@@_tmpa_tl}
\bool_set_false:N \l_@@_rect_bool
- \tl_case:NnTF \l_@@_tmpc_tl
+ \token_case_meaning:NnTF \l_@@_tmpc_tl
{
\c_spath_moveto_tl {
@@ -1679,8 +1687,8 @@ manipulating PGF soft paths}
\tl_clear:N \l_@@_tmpa_tl
\tl_put_right:Nn \l_@@_tmpa_tl {
\ExplSyntaxOn
- \tl_clear_new:N #1
- \tl_set:Nn #1 {#2}
+ \tl_gclear_new:N #1
+ \tl_gset:Nn #1 {#2}
\ExplSyntaxOff
}
\protected@write\@auxout{}{
@@ -3054,6 +3062,35 @@ manipulating PGF soft paths}
}
\cs_generate_variant:Nn \spath_gbake_shorten:N {c}
% \end{macrocode}
+%
+% Shortening the path when it is baked can cause issues with arrows.
+% Putting an arrow in a path definition affects the path because the path gets shortened so that the arrow ends where the path was meant to end.
+% So an arrow affects the path definition, but the arrow is not itself part of the path so if an arrow is used when the path is defined and again when the path is used, the path will be shortened twice which might not be what is intended.
+% Therefore it is useful to have a way to disable the shortening and place an arrow tip at the actual end of the line.
+% The following code achieves that.
+%
+% Save the original command that computes the arrow shortening.
+% \begin{macrocode}
+\cs_set_eq:Nc \@@_pgf_arrow_compute_shortening:n {pgf@arrow@compute@shortening}
+% \end{macrocode}
+%
+% After \verb+\pgf@arrow@compute@shortening+ then \verb+\pgf@xa+ is the amount to shorten the line by, so we will be setting that to 0pt.
+% Then \verb+\pgf@xb+ is the length of the arrow head which is used to position the arrow and so before zeroing \verb+\pgf@xa+ we subtract it from \verb+\pgf@xb+ so that the arrow is placed so that its back point is at the current position.
+%
+% \begin{macrocode}
+\cs_new_nopar:Npn \@@_arrow_compute_shortening:n #1
+{
+ \@@_pgf_arrow_compute_shortening:n {#1}
+ \bool_if:NF \l_spath_arrow_shortening_bool
+ {
+ \dim_sub:cn {pgf@xb} {\dim_use:c {pgf@xa}}
+ \dim_zero:c {pgf@xa}
+ }
+}
+
+\cs_set_eq:cN {pgf@arrow@compute@shortening} \@@_arrow_compute_shortening:n
+% \end{macrocode}
+%
% \end{macro}
%
% \begin{macro}[internal]{
@@ -3209,7 +3246,7 @@ manipulating PGF soft paths}
\tl_set:Nx \l_@@_tmpc_tl {\tl_head:N \l_@@_tmpa_tl}
\tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
- \tl_case:NnF \l_@@_tmpc_tl
+ \token_case_meaning:NnF \l_@@_tmpc_tl
{
\c_spath_closepath_tl {
@@ -3930,7 +3967,7 @@ manipulating PGF soft paths}
}
{
\tl_set:Nx \l_@@_tmpc_tl {\tl_head:N \l_@@_tmpa_tl}
- \tl_case:NnF \l_@@_tmpc_tl
+ \token_case_meaning:NnF \l_@@_tmpc_tl
{
\c_spath_curvetoa_tl
{
@@ -4225,7 +4262,7 @@ manipulating PGF soft paths}
{
\tl_set:Nx \l_@@_tmpf_tl {\tl_head:N \l_@@_tmpe_tl}
\tl_set:Nx \l_@@_tmpe_tl {\tl_tail:N \l_@@_tmpe_tl }
- \tl_case:Nn \l_@@_tmpf_tl
+ \token_case_meaning:Nn \l_@@_tmpf_tl
{
\c_spath_lineto_tl
{
@@ -4279,7 +4316,7 @@ manipulating PGF soft paths}
}
{
- \tl_case:Nn \l_@@_tmpf_tl
+ \token_case_meaning:Nn \l_@@_tmpf_tl
{
\c_spath_lineto_tl
{
@@ -5018,7 +5055,7 @@ manipulating PGF soft paths}
\tl_clear:N \l_@@_tmpc_tl
- \tl_case:Nn \l_@@_tmpb_tl
+ \token_case_meaning:Nn \l_@@_tmpb_tl
{
\c_spath_moveto_tl
{
@@ -5263,7 +5300,7 @@ manipulating PGF soft paths}
\tl_clear:N \l_@@_tmpc_tl
- \tl_case:Nn \l_@@_tmpb_tl
+ \token_case_meaning:Nn \l_@@_tmpb_tl
{
\c_spath_moveto_tl
{
@@ -6383,7 +6420,7 @@ manipulating PGF soft paths}
\tl_map_inline:nn {#1}
{
\tl_set:Nn \l_@@_tmpb_tl {##1}
- \tl_case:NnF \l_@@_tmpb_tl
+ \token_case_meaning:NnF \l_@@_tmpb_tl
{
\c_spath_moveto_tl
{
@@ -6516,10 +6553,14 @@ manipulating PGF soft paths}
\cs_new_protected_nopar:Npn \spath_protocol_path:n #1
{
\spath_minbb:Nn \l_@@_tmpa_tl {#1}
- \exp_last_unbraced:NV \pgf@protocolsizes\l_@@_tmpa_tl
+ \dim_set:Nn \l_@@_tmpa_dim {\tl_item:Nn \l_@@_tmpa_tl {1}}
+ \dim_set:Nn \l_@@_tmpb_dim {\tl_item:Nn \l_@@_tmpa_tl {2}}
+ \pgf@protocolsizes\l_@@_tmpa_dim\l_@@_tmpb_dim
\spath_maxbb:Nn \l_@@_tmpa_tl {#1}
- \exp_last_unbraced:NV \pgf@protocolsizes\l_@@_tmpa_tl
+ \dim_set:Nn \l_@@_tmpa_dim {\tl_item:Nn \l_@@_tmpa_tl {1}}
+ \dim_set:Nn \l_@@_tmpb_dim {\tl_item:Nn \l_@@_tmpa_tl {2}}
+ \pgf@protocolsizes\l_@@_tmpa_dim\l_@@_tmpb_dim
}
\cs_generate_variant:Nn \spath_protocol_path:n {V}
% \end{macrocode}
@@ -6880,7 +6921,7 @@ manipulating PGF soft paths}
}
}
{
- \msg_warning:nnn { spath3 } { missing soft path } { #2 }
+ \msg_warning:nnx { spath3 } { missing soft path } { #2 }
}
\tl_use:N \l_@@_check_tl
}
@@ -9027,12 +9068,8 @@ manipulating PGF soft paths}
% This puts a conditional around the \texttt{spot weld} key because when figuring out a knot drawing then we will initially want to render it without the spot weld to keep the number of components constant.
%
% \begin{macrocode}
- draft~ mode/.is~ choice,
- draft~ mode/true/.code={
- \bool_set_true:N \l_@@_draft_bool
- },
- draft~ mode/false/.code={
- \bool_set_false:N \l_@@_draft_bool
+ draft~ mode/.code={
+ \@@_set_bool:Nn \l_@@_draft_bool {#1}
},
maybe~ spot~ weld/.code={
\bool_if:NF \l_@@_draft_bool
@@ -9113,6 +9150,12 @@ manipulating PGF soft paths}
},
% \end{macrocode}
%
+% \begin{macrocode}
+ arrow~ shortening/.code={
+ \@@_set_bool:Nn \l_spath_arrow_shortening_bool {#1}
+ },
+% \end{macrocode}
+%
% For single argument commands which take a path as their argument, set the default to be \Verb+current+ so that they use the current path.
%
% \begin{macrocode}
@@ -9616,7 +9659,7 @@ manipulating PGF soft paths}
\dim_set:Nn \l_@@_tmpb_dim {\tl_item:Nn \l_@@_tmpa_tl {3}}
\tl_set:Nx \l_@@_tmpb_tl {\tl_item:Nn \l_@@_tmpa_tl {4}}
- \tl_case:NnF \l_@@_tmpb_tl
+ \token_case_meaning:NnF \l_@@_tmpb_tl
{
\c_spath_lineto_tl
{
@@ -9668,7 +9711,7 @@ manipulating PGF soft paths}
\dim_set:Nn \l_@@_tmpb_dim {\tl_item:Nn \l_@@_tmpa_tl {-1}}
\tl_set:Nx \l_@@_tmpb_tl {\tl_item:Nn \l_@@_tmpa_tl {-3}}
- \tl_case:NnF \l_@@_tmpb_tl
+ \token_case_meaning:NnF \l_@@_tmpb_tl
{
\c_spath_lineto_tl
{
@@ -10411,6 +10454,15 @@ manipulating PGF soft paths}
}
}
+\cs_new_nopar:Npn \knot_show_strand:n #1
+{
+ \bool_if:NT \l_@@_debugging_bool
+ {
+ \iow_term:n {===Knot~ debug: #1===}
+ \spath_show:v {knot #1}
+ }
+}
+
\cs_generate_variant:Nn \knot_debug:n {x}
% \end{macrocode}
% \end{macro}
@@ -10592,6 +10644,7 @@ manipulating PGF soft paths}
knot~ diagram/only~ when~ rendering/.try,
only~ when~ rendering/.try,
}
+ \knot_show_strand:n {strand #1}
\spath_tikz_path:Vv \l_@@_tmpa_tl {knot strand #1}
\group_end:
\endpgfscope
@@ -10629,6 +10682,7 @@ manipulating PGF soft paths}
}
{
\tl_clear:N \l_@@_tmpa_tl
+ \spath_remove_empty_components:c {knot strand #1}
\spath_initialpoint:Nv \l_@@_tmpa_tl {knot strand #1}
\tl_put_left:NV \l_@@_tmpa_tl \c_spath_moveto_tl
\spath_segments_to_seq:Nv \l_@@_segments_seq {knot strand #1}
@@ -10649,7 +10703,7 @@ manipulating PGF soft paths}
{
\knot_debug:n {knot~ split~ self~ intersects}
\tl_set:Nx \l_@@_tmpc_tl {\tl_item:nn {#1} {4}}
- \tl_case:NnF \l_@@_tmpc_tl
+ \token_case_meaning:NnF \l_@@_tmpc_tl
{
\c_spath_curvetoa_tl
{
@@ -11271,6 +11325,7 @@ manipulating PGF soft paths}
\int_set_eq:NN \l_@@_component_start_int \g_@@_filaments_int
\int_incr:N \l_@@_component_start_int
\tl_set_eq:Nc \l_@@_tmpa_tl {l_@@_options_strand #1}
+ \spath_remove_empty_components:c {knot strand #1}
\spath_segments_to_seq:Nv \l_@@_segments_seq {knot strand #1}
\seq_map_function:NN \l_@@_segments_seq \knot_save_filament:N
}
@@ -11284,7 +11339,7 @@ manipulating PGF soft paths}
{
\knot_debug:n {knot~ save~ filament}
\tl_set:Nx \l_@@_tmpb_tl {\tl_item:nn {#1} {4}}
- \tl_case:NnF \l_@@_tmpb_tl
+ \token_case_meaning:NnF \l_@@_tmpb_tl
{
\c_spath_moveto_tl
{