From ab9b0a4bdab9509bb22d48c0f6231105eb686b96 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Tue, 13 Jun 2023 20:17:59 +0000 Subject: string-diagrams (13jun23) git-svn-id: svn://tug.org/texlive/trunk@67354 c570f23f-e606-0410-a88d-b1316a301751 --- .../tex/latex/string-diagrams/string-diagrams.sty | 119 ++++++++++++++------- 1 file changed, 81 insertions(+), 38 deletions(-) (limited to 'Master/texmf-dist/tex') diff --git a/Master/texmf-dist/tex/latex/string-diagrams/string-diagrams.sty b/Master/texmf-dist/tex/latex/string-diagrams/string-diagrams.sty index 1606386533a..236913671ca 100644 --- a/Master/texmf-dist/tex/latex/string-diagrams/string-diagrams.sty +++ b/Master/texmf-dist/tex/latex/string-diagrams/string-diagrams.sty @@ -8,7 +8,7 @@ %% %% ============================================================================= %% -%% string-diagrams 0.1.0 (2023/05/31) +%% string-diagrams 0.2.0 (2023/06/12) %% %% Copyright (C) 2023 by Paolo Brasolin %% SPDX-License-Identifier: LPPL-1.3c @@ -34,54 +34,93 @@ %% string-diagrams.pdf. %% %% ============================================================================= +%% \RequirePackage{expl3}[2023/05/11] \RequirePackage{tikz}[2023/01/15] \ProvidesExplPackage {string-diagrams} - {2023/05/31} - {0.1.0} + {2023/06/12} + {0.2.0} {Draw string diagrams using TikZ} +\pgfkeys{ + /pgf/box~ports~north/.initial=1, + /pgf/box~ports~east/.initial=1, + /pgf/box~ports~south/.initial=1, + /pgf/box~ports~west/.initial=1, + /pgf/box~ports/.style~args={#1/#2/#3/#4}{ + /pgf/box~ports~north=#1, + /pgf/box~ports~east=#2, + /pgf/box~ports~south=#3, + /pgf/box~ports~west=#4, + }, +} +\cs_new:Nn \__stridi_intersect_hv_lines_through:NN { + \pgfextractx { \pgf@xa } { #1 } + \pgfextracty { \pgf@ya } { #2 } + \pgfpoint { \pgf@xa } { \pgf@ya } +} +\cs_new:Nn \__stridi_subdivide_segment:nNNNNN { + \int_step_inline:nnnn { #2 } { -1 } { 1 } { + \cs_if_exist:cTF + { #1.##1 } + { \prg_break: } + { \prg_do_nothing: } + \cs_new_nopar:cpn + { #1.##1 } + { + \pgfmathdivide + { 2 * ##1 - 1 } + { 2 * #2 } + \pgfpointlineattime + { \pgfmathresult } + { \__stridi_intersect_hv_lines_through:NN { #3 } { #4 } } + { \__stridi_intersect_hv_lines_through:NN { #5 } { #6 } } + } + } +} \pgfdeclareshape{box}{ - \inheritbackgroundpath[from=rectangle] + + % Inherit all the structure of rectangle \inheritsavedanchors[from=rectangle] + \clist_map_inline:nn + { + north~west, north, north~east, + west, center, east, + mid~west, mid, mid~east, + base~west, base, base~east, + south~west, south, south~east, + } + { \inheritanchor[from=rectangle]{#1} } \inheritanchorborder[from=rectangle] - \inheritanchor[from=rectangle]{center} - \inheritanchor[from=rectangle]{north} - \inheritanchor[from=rectangle]{south} - \inheritanchor[from=rectangle]{west} - \inheritanchor[from=rectangle]{east} - \anchor{east0}{ - \pgf@process{\southwest} - \pgf@ya=0.25\pgf@y - \pgf@process{\northeast} - \pgf@y=0.75\pgf@y - \advance\pgf@y by \pgf@ya - } - \anchor{east1}{ - \pgf@process{\southwest} - \pgf@ya=0.75\pgf@y - \pgf@process{\northeast} - \pgf@y=0.25\pgf@y - \advance\pgf@y by \pgf@ya - } - \anchor{west0}{ - \pgf@process{\northeast} - \pgf@ya=0.75\pgf@y - \pgf@process{\southwest} - \pgf@y=0.25\pgf@y - \advance\pgf@y by \pgf@ya - } - \anchor{west1}{ - \pgf@process{\northeast} - \pgf@ya=0.25\pgf@y - \pgf@process{\southwest} - \pgf@y=0.75\pgf@y - \advance\pgf@y by \pgf@ya + \inheritbackgroundpath[from=rectangle] + + % Dump port counts into saved macros + \savedmacro\portsnorth + {\pgfmathtruncatemacro\portsnorth{\pgfkeysvalueof{/pgf/box~ports~north}}} + \savedmacro\portseast + {\pgfmathtruncatemacro\portseast{\pgfkeysvalueof{/pgf/box~ports~east}}} + \savedmacro\portssouth + {\pgfmathtruncatemacro\portssouth{\pgfkeysvalueof{/pgf/box~ports~south}}} + \savedmacro\portswest + {\pgfmathtruncatemacro\portswest{\pgfkeysvalueof{/pgf/box~ports~west}}} + + % Add ports definitions to shape definition + \expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@box\endcsname{ + \__stridi_subdivide_segment:nNNNNN { pgf@anchor@box@north } { \portsnorth } + { \southwest } { \northeast } { \northeast } { \northeast } + \__stridi_subdivide_segment:nNNNNN { pgf@anchor@box@east } { \portseast } + { \northeast } { \northeast } { \northeast } { \southwest } + \__stridi_subdivide_segment:nNNNNN { pgf@anchor@box@south } { \portssouth } + { \southwest } { \southwest } { \northeast } { \southwest } + \__stridi_subdivide_segment:nNNNNN { pgf@anchor@box@west } { \portswest } + { \southwest } { \northeast } { \southwest } { \southwest } } + } \ExplSyntaxOff \tikzset{ - box/.style={ + box/.default={0/0/0/0}, + box/.style args={#1}{ shape=box, draw, inner sep=.5em, @@ -89,7 +128,12 @@ minimum height=2em, execute at begin node=$, execute at end node=$, + /pgf/box ports=#1, }, +} +\ExplSyntaxOn +\ExplSyntaxOff +\tikzset{ dot/.style={ shape=circle, fill, @@ -142,4 +186,3 @@ } { ##1 } {} {} } } -%% ============================================================================= -- cgit v1.2.3