Debian Codegraph @

texmf-dist/tex/latex/simplenodes/simplenodes.sty

raw
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 %% simplenodes.sty
3 %% <https://github.com/user9856749/simplenodes>
4 %%
5 %% MIT License
6 %%
7 %% Copyright (c) 2022 Bob Vergauwen
8 %%
9 %% Permission is hereby granted, free of charge, to any person obtaining a copy
10 %% of this software and associated documentation files (the "Software"), to deal
11 %% in the Software without restriction, including without limitation the rights
12 %% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 %% copies of the Software, and to permit persons to whom the Software is
14 %% furnished to do so, subject to the following conditions:
15 %%
16 %% The above copyright notice and this permission notice shall be included in all
17 %% copies or substantial portions of the Software.
18 %%
19 %% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 %% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 %% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 %% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 %% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 %% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 %% SOFTWARE.
26 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27
28 \NeedsTeXFormat{LaTeX2e}
29 \ProvidesPackage{simplenodes}[2022/03/31 A package that provides simple nodes in four colors.]
30
31 \RequirePackage{kvoptions}
32
33 \DeclareStringOption[25mm]{width}
34 \DeclareStringOption[7mm]{minheight}
35 \DeclareStringOption[center]{align}
36 \DeclareStringOption[2pt]{innersep}
37 \DeclareStringOption[0pt]{outersep}
38 \DeclareStringOption[0.4pt]{thickness}
39 \ProcessKeyvalOptions*
40
41 \RequirePackage{kvoptions}
42 \RequirePackage{tikz}
43 \RequirePackage{color}
44 \usetikzlibrary{math}
45
46 % Coordinate manipulations
47
48
49 \newcommand{\gettikzxy}[3]{%
50 \tikz@scan@one@point\pgfutil@firstofone#1\relax
51 \edef#2{\the\pgf@x}%
52 \edef#3{\the\pgf@y}%
53 }
54
55 % Define the main color
56 \definecolor{InvisibleRed}{rgb}{0.97, 0.92, 0.92}
57 \definecolor{InvisibleGreen}{rgb}{0.92, 0.97, 0.92}
58 \definecolor{InvisibleBlue}{rgb}{0.92, 0.92, 0.97}
59 \definecolor{InvisibleYellow}{rgb}{1.0, 1.0, 0.88}
60
61 \definecolor{MediumRed}{rgb}{0.925, 0.345, 0.345}
62 \definecolor{MediumGreen}{rgb}{0.37, 0.7, 0.66}
63 \definecolor{MediumBlue}{rgb}{0.015, 0.315, 0.45}
64 \definecolor{MediumYellow}{rgb}{1.0, 0.75, 0.0}
65
66 % Define the node
67 \newcommand\mynode[2]{
68 \tikz[remember picture,baseline]
69 \node[
70 draw=#1,fill=#2,
71 rectangle,
72 line width = \simplenodes@thickness,
73 align=\simplenodes@align,
74 text width=\simplenodes@width,
75 inner sep=\simplenodes@innersep,
76 outer sep=\simplenodes@outersep,
77 minimum height=\simplenodes@minheight,
78 ]
79 }
80
81 % Define the line
82 \newcommand\myline[2]{
83 \draw[
84 ->,
85 line width = \simplenodes@thickness
86 ] (#1) to (#2);
87 }
88
89 \newcommand\link[2]{
90 \begin{tikzpicture}[remember picture, overlay, >=stealth, shift={(0,0)}]
91 \gettikzxy{(#1)}{\ax}{\ay}
92 \gettikzxy{(#2)}{\bx}{\by}
93 \tikzmath{
94 if \ax == \bx then {
95 if \ay < \by then {
96 {\myline{#1.north}{#2.south}};
97 };
98 if \ay > \by then {
99 {\myline{#1.south}{#2.north}};
100 };
101 };
102 if \ax < \bx then {
103 {\myline{#1.east}{#2.west}};
104 };
105 if \ax > \bx then {
106 {\myline{#1.west}{#2.east}};
107 };
108 };
109 \end{tikzpicture}
110 }
111
112 % Provide the commands
113 \newcommand\simplenode[2]{\mynode{MediumBlue}{InvisibleBlue} (#1){#2};}
114 \newcommand\examplenode[2]{\mynode{MediumGreen}{InvisibleGreen} (#1){#2};}
115 \newcommand\alertnode[2]{\mynode{MediumRed}{InvisibleRed} (#1){#2};}
116 \newcommand\warnnode[2]{\mynode{MediumYellow}{InvisibleYellow} (#1){#2};}