diff options
author | Karl Berry <karl@freefriends.org> | 2023-05-31 19:58:20 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2023-05-31 19:58:20 +0000 |
commit | c7bccd70b5233d348da0630474b0af626386f6cf (patch) | |
tree | 21ae73293525c892eb73fcb887093a5410b366b8 /Master/texmf-dist | |
parent | 974abbb14deba9b41674b990e6008cb7216ec7bc (diff) |
string-diagrams (31may23)
git-svn-id: svn://tug.org/texlive/trunk@67251 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist')
-rw-r--r-- | Master/texmf-dist/doc/latex/string-diagrams/README.md | 77 | ||||
-rw-r--r-- | Master/texmf-dist/doc/latex/string-diagrams/string-diagrams.pdf | bin | 0 -> 475723 bytes | |||
-rw-r--r-- | Master/texmf-dist/source/latex/string-diagrams/string-diagrams.dtx | 370 | ||||
-rw-r--r-- | Master/texmf-dist/source/latex/string-diagrams/string-diagrams.ins | 49 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/string-diagrams/string-diagrams.sty | 145 |
5 files changed, 641 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/latex/string-diagrams/README.md b/Master/texmf-dist/doc/latex/string-diagrams/README.md new file mode 100644 index 00000000000..fc1505021ad --- /dev/null +++ b/Master/texmf-dist/doc/latex/string-diagrams/README.md @@ -0,0 +1,77 @@ +# string-diagrams + +[![CTAN release][ctan-shield]][ctan-link] +[![GitHub release][release-shield]][release-link] +[![Project licence][licence-shield]][licence-link] + +[ctan-shield]: https://img.shields.io/ctan/v/string-diagrams?label=CTAN +[ctan-link]: https://ctan.org/pkg/string-diagrams +[release-shield]: https://img.shields.io/github/v/release/paolobrasolin/string-diagrams?display_name=release&include_prereleases +[release-link]: https://github.com/paolobrasolin/string-diagrams/releases/ +[licence-shield]: https://img.shields.io/github/license/paolobrasolin/string-diagrams +[licence-link]: https://www.latex-project.org/lppl.txt + +Create string diagrams with LaTeX! + +`string-diagrams` is a LaTeX package designed for effortless and aesthetically pleasing creation of string diagrams. + +## Getting Started + +### Prerequisites + +The only thing you need is an up-to-date LaTeX distribution including TikZ. + +### Installation + +The fastest way to hit the ground running is to download `string-diagrams` from CTAN via your package manager. For instance, TeXLive users can run `tlmgr install string-diagrams` or select `string-diagrams` from the GUI. + +Alternatively, you can download the package from the [CTAN page](https://www.ctan.org/pkg/string-diagrams), unzip the archive, and place `string-diagrams.sty` in your working directory. + +For those who always live on the edge, unreleased versions are available on the [releases page](https://github.com/paolobrasolin/string-diagrams/releases). + +### Usage + +After including the package in your preamble, you can craft your string diagrams in a `tikzpicture` environment: + +```latex +\usepackage{string-diagrams} + +%... + +\begin{tikzpicture} + \node[box] (a) {a}; + \node[box] (b) at (0,-2) {b}; + \node[dot] (x) at (1,-1) {}; + \node[dot] (y) at (-1,-1) {}; + \wires[]{ + a = { east = x.north }, + b = { east0 = x.south }, + y = { north = a.west1, south = b.west }, + }{ + a.west0, b.east1, x.east, y.west + } +\end{tikzpicture} +``` + +Detailed instructions are available in the [documentation](http://mirrors.ctan.org/graphics/pgf/contrib/string-diagrams/string-diagrams.pdf). + +## Contributing + +Got a fantastic idea? Noticed a bug? Contributions are more than welcome! Please feel free to share your thoughts via the [issue tracker](https://github.com/paolobrasolin/string-diagrams/issues). + +For the adventurous, you can [fork the repository](https://github.com/paolobrasolin/string-diagrams/fork), create some magic, and [submit a pull request](https://github.com/paolobrasolin/string-diagrams/pulls). + +## License + +This project is licensed under the LPPL-1.3c License. + +## Acknowledgements + +Special gratitude goes to the [Laboratory for Compositional Systems and Methods](https://compose.ioc.ee/) of [Tallin University of Technology](https://taltech.ee/). My stay with them in May 2023 set the stage for the birth and primary development of this work, fueled by their warm hospitality and vibrant scholarly atmosphere. + +This work is built upon the collaborative efforts of two exceptional contributors: + +- [tetrapharmakon](https://github.com/tetrapharmakon), my partner in crime for [moirai](https://github.com/tetrapharmakon/moirai), the projects' first iteration. +- [iwilare](https://github.com/iwilare), who saw potential in our initial idea and pushed it forward with their own fork [moirphism](https://github.com/iwilare/moirphism). + +Without them, their shared enthusiasm, and our fruitful discussions, `string-diagrams` simply wouldn't be. diff --git a/Master/texmf-dist/doc/latex/string-diagrams/string-diagrams.pdf b/Master/texmf-dist/doc/latex/string-diagrams/string-diagrams.pdf Binary files differnew file mode 100644 index 00000000000..fc46a7812b5 --- /dev/null +++ b/Master/texmf-dist/doc/latex/string-diagrams/string-diagrams.pdf diff --git a/Master/texmf-dist/source/latex/string-diagrams/string-diagrams.dtx b/Master/texmf-dist/source/latex/string-diagrams/string-diagrams.dtx new file mode 100644 index 00000000000..d219d79d1fc --- /dev/null +++ b/Master/texmf-dist/source/latex/string-diagrams/string-diagrams.dtx @@ -0,0 +1,370 @@ +% \iffalse meta-comment +%% ============================================================================= +%% +%% 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. +%% +%% ============================================================================= +% +% %%%=[ INSTALL ]=============================================================== +% +%<*internal> +\def\nameofplainTeX{plain} +\ifx\fmtname\nameofplainTeX\else + \expandafter\begingroup +\fi +%</internal> +% +%<*install> +\input l3docstrip.tex +\keepsilent +\askforoverwritefalse + +% NOTE: to avoid redundancy we use `%%'-lines instead of pre/postambles +\preamble +\endpreamble +\nopostamble + +\usedir{tex/latex/string-diagrams} +\generate{\file{\jobname.sty}{\from{\jobname.dtx}{package}}} + +%</install> +%<*internal> + +\usedir{source/latex/string-diagrams} +\generate{\file{\jobname.ins}{\from{\jobname.dtx}{install}}} + +%</internal> +% +%<*internal> +\ifx\fmtname\nameofplainTeX + \expandafter\endbatchfile +\else + \expandafter\endgroup +\fi +%</internal> +% +%<install>\endbatchfile +% +% %%%=[ DRIVER ]================================================================ +% +%<*driver> +\documentclass[a4paper,full]{l3doc} +\EnableCrossrefs +\CodelineIndex +\RecordChanges +\usepackage{string-diagrams} +\usetikzlibrary{calc} +\usepackage{snapshot} + +\usepackage{tcolorbox} +\tcbuselibrary{listings, skins} + +\lstset{ + language=[LaTeX]TeX, + basicstyle=\ttfamily\small, + columns=flexible, + ^^A keywordstyle=\color{red}, + ^^A morekeywords={}, + texcsstyle=*\color{violet}, + moretexcs={node,wires}, + breaklines=true, +} + +\tcbset{example/.style={ + listing engine=listings, + verbatim ignore percent=true, + listing side text, + size=minimal, + skin=bicolor, + colback=black!5!white, + colbacklower=white, + sidebyside, + lefthand ratio=0.62, + listing options={ + xleftmargin=-0.6em, % poor man's gobble=4 + }, +}} + +\begin{document} + \DocInput{\jobname.dtx} + \PrintChanges + \PrintIndex +\end{document} +%</driver> +% +% \fi +% +% \changes{0.1.0}{2023/05/31}{Initial version} +% +% \GetFileInfo{\jobname.sty} +% +% \title{^^A +% The \pkg{\jobname} package^^A +% \thanks{Thanks!}\\^^A +% \fileinfo^^A +% } +% +% \author{^^A +% Paolo Brasolin\\^^A +% \texttt{\href{mailto:paolo.brasolin@gmail.com}{paolo.brasolin@gmail.com}}^^A +% } +% +% \date{\fileversion~(\filedate)} +% +% \maketitle +% +% ^^A=[ DOCUMENTATION ]========================================================= +% +% \begin{documentation} +% +% \begin{tcolorbox}[ +% colback=red!5!white, +% colframe=red, +% sharp corners, +% boxrule=1pt, +% ] +% Please note this is the \href{https://semver.org/#spec-item-4}{major version zero}, meant for initial development: \emph{anything MAY change at any time}. +% The upside is that this is the best time to \href{https://github.com/paolobrasolin/string-diagrams#contributing}{contribute}! +% Of course you can also just keep the \texttt{sty} along with your code and not care at all. +% \end{tcolorbox} +% +% +% \section{Documentation} +% +% Let's walk through the features by example. +% +% +% To draw boxes, you use the \texttt{box} style on a node. +% +% \begin{tcblisting}{example} +% \begin{tikzpicture} +% \node[box] {A}; +% \end{tikzpicture} +% \end{tcblisting} +% +% You can draw multiple boxes using any of your standard Ti\emph{k}Z positioning techniques. +% Don't forget to label the nodes so you can easily reference them. +% +% \begin{tcblisting}{example} +% \begin{tikzpicture} +% \node[box] (A) at (0,0) {A}; +% \node[box, right of=A] (B) {B}; +% \node[box] (C) at ($(B)+(2cm,1em)$) {C}; +% \end{tikzpicture} +% \end{tcblisting} +% +% To connect boxes, you can use the \cmd\wires\ macro. +% The first argument is Ti\emph{k}Z styling for the wires; the second argument is a nested dicionary specifying the connectivity; the third argument is a list of the loose ends to draw. +% \texttt{box}es have the following anchors: \texttt{west}, \texttt{west0}, \texttt{west1}, \texttt{east}, \texttt{east0}, and \texttt{east1}. +% +% \begin{tcblisting}{example} +% \begin{tikzpicture}[scale=0.6] +% \node[box] (A) at (-2, 0) {A}; +% \node[box] (B) at (+2, 0) {B}; +% \node[box] (C) at ( 0,+1) {C}; +% \node[box] (D) at ( 0,-1) {D}; +% \wires[]{ +% A = { east0 = C.west, east1 = D.west }, +% C = { east = B.west0 }, +% D = { east = B.west1 }, +% }{ A.west, B.east } +% \end{tikzpicture} +% \end{tcblisting} +% +% To split and join wires, you can use \texttt{dot}s and their anchors \texttt{north}, \texttt{east}, \texttt{south}, and \texttt{west}. +% Remember to have fun with styling wires. +% +% \begin{tcblisting}{example} +% \begin{tikzpicture} +% \node[box] (A) at ( 0,+1) {A}; +% \node[box] (B) at ( 0,-1) {B}; +% \node[dot] (x) at (+1, 0) {}; +% \node[dot] (y) at (-1, 0) {}; +% \wires[looseness=1.5, dashed]{ +% A = { east = x.north }, +% B = { east0 = x.south }, +% y = { north = A.west1, south = B.west }, +% }{ +% A.west0, B.east1, x.east, y.west +% } +% \end{tikzpicture} +% \end{tcblisting} +% +% That's it. This is the package, for now. +% +% \end{documentation} +% +% ^^A=[ PACKAGE ]=============================================================== +% +% \begin{implementation} +% +% \section{Implementation} +% +% Open the \pkg{DocStrip} guards. +% \begin{macrocode} +%<*package> +% \end{macrocode} +% +% Identify the internal prefix (\LaTeX3 \pkg{DocStrip} convention). +% \begin{macrocode} +%<@@=stridi> +% \end{macrocode} +% +% Load the essential support (\pkg{expl3}) \enquote{up-front}. +% +% \begin{macrocode} +\RequirePackage{expl3}[2023/05/11] +\RequirePackage{tikz}[2023/01/15] +% \end{macrocode} +% +% Identify the package and give the over all version information. +% \begin{macrocode} +\ProvidesExplPackage + {string-diagrams} + {2023/05/31} + {0.1.0} + {Draw string diagrams using TikZ} +% \end{macrocode} +% +% Define a shape with useful anchor points. +% \begin{macrocode} +\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 + } +} +% \end{macrocode} +% Define styles to draw boxes and dots. +% \begin{macrocode} +\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 +% \end{macrocode} +% +% Define our main actor. +% \begin{macro}{\wires} +% \begin{macrocode} +\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 } {} {} + } +} +% \end{macrocode} +% \end{macro} +% +% \iffalse +%</package> +% \fi +% \end{implementation} +%% ============================================================================= diff --git a/Master/texmf-dist/source/latex/string-diagrams/string-diagrams.ins b/Master/texmf-dist/source/latex/string-diagrams/string-diagrams.ins new file mode 100644 index 00000000000..1a9137df9e4 --- /dev/null +++ b/Master/texmf-dist/source/latex/string-diagrams/string-diagrams.ins @@ -0,0 +1,49 @@ +%% +%% This is file `string-diagrams.ins', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% string-diagrams.dtx (with options: `install') +%% +%% ============================================================================= +%% +%% 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. +%% +%% ============================================================================= +\input l3docstrip.tex +\keepsilent +\askforoverwritefalse + +\preamble +\endpreamble +\nopostamble + +\usedir{tex/latex/string-diagrams} +\generate{\file{\jobname.sty}{\from{\jobname.dtx}{package}}} + +\endbatchfile +%% ============================================================================= 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 } {} {} + } +} +%% ============================================================================= |