summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/string-diagrams/string-diagrams.sty
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/latex/string-diagrams/string-diagrams.sty')
-rw-r--r--Master/texmf-dist/tex/latex/string-diagrams/string-diagrams.sty145
1 files changed, 145 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/string-diagrams/string-diagrams.sty b/Master/texmf-dist/tex/latex/string-diagrams/string-diagrams.sty
new file mode 100644
index 00000000000..1606386533a
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/string-diagrams/string-diagrams.sty
@@ -0,0 +1,145 @@
+%%
+%% This is file `string-diagrams.sty',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% string-diagrams.dtx (with options: `package')
+%%
+%% =============================================================================
+%%
+%% string-diagrams 0.1.0 (2023/05/31)
+%%
+%% Copyright (C) 2023 by Paolo Brasolin <paolo.brasolin@gmail.com>
+%% SPDX-License-Identifier: LPPL-1.3c
+%%
+%% =============================================================================
+%%
+%% This work may be distributed and/or modified under the
+%% conditions of the LaTeX Project Public License, either version 1.3c
+%% of this license or (at your option) any later version.
+%% The latest version of this license is in
+%% https://www.latex-project.org/lppl.txt
+%% and version 1.3c or later is part of all distributions of LaTeX
+%% version 2008 or later.
+%%
+%% This work has the LPPL maintenance status `author-maintained'.
+%%
+%% The Current Maintainer of this work is Paolo Brasolin.
+%%
+%% This work consists of the files README.md,
+%% string-diagrams.dtx,
+%% and the derived files string-diagrams.ins,
+%% string-diagrams.sty, and
+%% string-diagrams.pdf.
+%%
+%% =============================================================================
+\RequirePackage{expl3}[2023/05/11]
+\RequirePackage{tikz}[2023/01/15]
+\ProvidesExplPackage
+ {string-diagrams}
+ {2023/05/31}
+ {0.1.0}
+ {Draw string diagrams using TikZ}
+\pgfdeclareshape{box}{
+ \inheritbackgroundpath[from=rectangle]
+ \inheritsavedanchors[from=rectangle]
+ \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
+ }
+}
+\ExplSyntaxOff
+\tikzset{
+ box/.style={
+ shape=box,
+ draw,
+ inner sep=.5em,
+ minimum width=2em,
+ minimum height=2em,
+ execute at begin node=$,
+ execute at end node=$,
+ },
+ dot/.style={
+ shape=circle,
+ fill,
+ inner sep=0,
+ minimum width=0.4em,
+ },
+}
+\ExplSyntaxOn
+\NewDocumentCommand{\wires}{ o m m }
+{
+ \prop_set_from_keyval:Nn \l_tmpa_prop { #2 }
+ \prop_map_inline:Nn \l_tmpa_prop
+ {
+ \prop_set_from_keyval:Nn \l_tmpb_prop { ##2 }
+ \prop_map_inline:Nn \l_tmpb_prop
+ {
+ \regex_match_case:nnTF
+ {
+ { \. north } { \tl_gset:Nn \g_tmpa_tl { 90 } }
+ { \. south } { \tl_gset:Nn \g_tmpa_tl { -90 } }
+ { \. west } { \tl_gset:Nn \g_tmpa_tl { 180 } }
+ { \. east } { \tl_gset:Nn \g_tmpa_tl { 0 } }
+ } { ####2 } {} {}
+ \regex_match_case:nnTF
+ {
+ { north } { \tl_gset:Nn \g_tmpb_tl { 90 } }
+ { south } { \tl_gset:Nn \g_tmpb_tl { -90 } }
+ { west } { \tl_gset:Nn \g_tmpb_tl { 180 } }
+ { east } { \tl_gset:Nn \g_tmpb_tl { 0 } }
+ } { ####1 } {} {}
+ \draw [
+ out={\tl_use:N \g_tmpb_tl},
+ in={\tl_use:N \g_tmpa_tl},
+ #1,
+ ] (##1.####1) to (####2);
+ }
+ }
+ \clist_set:Nn \l_tmpa_clist { #3 }
+ \clist_map_inline:Nn \l_tmpa_clist {
+ \regex_match_case:nnTF
+ {
+ { \. north } { \draw[#1] (##1) -- +( 0,+1); } % TODO: cleaner solution?
+ { \. south }
+ {
+ \draw[out=-90, in=0,#1] (##1)
+ to ($(\pgf@picminx, \pgf@y)$);
+ } % TODO: not sure why this works
+ { \. west } { \draw[#1] (##1) -- +(-1, 0); }
+ { \. east } { \draw[#1] (##1) -- +(+1, 0); }
+ } { ##1 } {} {}
+ }
+}
+%% =============================================================================