| 1 |
#+latex_class: my-article |
| 2 |
#+title: Simplenodes |
| 3 |
#+author: Bob Vergauwen |
| 4 |
#+date: 2022/03/31 |
| 5 |
|
| 6 |
| {{{examplenode(1,Simple)}}} | | | |
| 7 |
| | | {{{alertnode(2,simplenodes)}}} | |
| 8 |
| {{{simplenode(3,Nodes)}}} | | | |
| 9 |
{{{link(1,2)}}} |
| 10 |
{{{link(3,2)}}} |
| 11 |
* Introduction |
| 12 |
Creating tikz figures may be fun but after a while it becomes repetitive and you find yourself implementing the same |
| 13 |
repetitive patterns over and over again. |
| 14 |
This has a few negative effects on your daily productivity; |
| 15 |
- bad coding style by copy-pasting old solutions, |
| 16 |
- un-maintainable code, |
| 17 |
- repeating yourself over and over again, |
| 18 |
- inconsistent styles in a single document and over multiple documents. |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
This package tries to solve these issues by providing two simple commands; |
| 23 |
- one command to create simple nodes, |
| 24 |
- one command to link these nodes. |
| 25 |
Some simple styling options can be changed upon loading the package. |
| 26 |
|
| 27 |
* Usage |
| 28 |
After including the package via the command |
| 29 |
#+BEGIN_EXAMPLE |
| 30 |
\usepackage{simplenodes} |
| 31 |
#+END_EXAMPLE |
| 32 |
all package commands are available. |
| 33 |
** Creating a node |
| 34 |
Four different nodes are supported at the moment; |
| 35 |
|
| 36 |
|
| 37 |
| *Command* | *Result* | |
| 38 |
|-----------------------------+---------------------------------| |
| 39 |
| =\simplenode{name}{Normal}= | {{{simplenode(name,Normal)}}} | |
| 40 |
| =\examplenode{name}{Example}= | {{{examplenode(name,Example)}}} | |
| 41 |
| =\warnnode{name}{Warning}= | {{{warnnode(name,Warning)}}} | |
| 42 |
| =\alertnode{name}{Alert}= | {{{alertnode(name,Alert)}}} | |
| 43 |
The first parameter is the =name= used to link two nodes together. |
| 44 |
The third parameter is the =text= displayed inside the node. |
| 45 |
|
| 46 |
** Linking nodes |
| 47 |
Linking nodes is done via the command =\link{name1}{name2}=, where the |
| 48 |
name is defined upon creating the node. |
| 49 |
|
| 50 |
** Positioning nodes |
| 51 |
The intended use of this package is to position the nodes using the tabular environment. |
| 52 |
Nodes can be placed in cells of tables to create an easy and even layout. |
| 53 |
This usage is demonstrated in the examples. |
| 54 |
The usage of this package is not restricted to this usecase. |
| 55 |
|
| 56 |
* Package options |
| 57 |
A few packaged options are provided by using |
| 58 |
#+BEGIN_EXAMPLE |
| 59 |
\usepackage[name1=value1,name2=value2,...]{simplenodes} |
| 60 |
#+END_EXAMPLE |
| 61 |
The name, default value and description is provided in the following table |
| 62 |
| *Name* | *Default* | *Description* | |
| 63 |
|-----------+---------+-----------------------------------------------------| |
| 64 |
| =align= | center | Specifies the alignment of the text in the nodes. | |
| 65 |
| =width= | 25mm | The width of the nodes. | |
| 66 |
| =minheight= | 7mm | The minimum width of the nodes. | |
| 67 |
| =innersep= | 2pt | The inner separation between the text and the node. | |
| 68 |
| =outersep= | 0pt | The outer separation between the nodes. | |
| 69 |
| =thickness= | 0.4pt | The line thickness of the nodes and links. | |
| 70 |
|
| 71 |
* Examples |
| 72 |
** Hello world |
| 73 |
| {{{simplenode(hello,hello)}}} | {{{simplenode(world,world)}}} | |
| 74 |
{{{link(hello,world)}}} |
| 75 |
#+begin_src latex :tangel no :exports code |
| 76 |
\begin{tabular}{ll} |
| 77 |
\simplenode{hello}{hello} & \simplenode{world}{world}\\ |
| 78 |
\end{tabular} |
| 79 |
\link{hello}{world} |
| 80 |
#+end_src |
| 81 |
|
| 82 |
** More color |
| 83 |
| {{{simplenode(1,simple)}}} | {{{examplenode(2,example)}}} | {{{warnnode(3,warn)}}} | {{{alertnode(4,alert)}}} | |
| 84 |
{{{link(1,2)}}} |
| 85 |
{{{link(2,3)}}} |
| 86 |
{{{link(3,4)}}} |
| 87 |
|
| 88 |
#+begin_src latex :tangel no :exports code |
| 89 |
\begin{tabular}{llll} |
| 90 |
\simplenode{1}{simple} & |
| 91 |
\examplenode{2}{example} & |
| 92 |
\warnnode{3}{warn} & |
| 93 |
\alertnode{4}{alert}\\ |
| 94 |
\end{tabular} |
| 95 |
\link{1}{2} |
| 96 |
\link{2}{3} |
| 97 |
\link{3}{4} |
| 98 |
#+end_src |
| 99 |
** Order of the arrows and doule arrows |
| 100 |
| {{{simplenode(1,node 1)}}} | {{{examplenode(2,node 2)}}} | {{{warnnode(3,node 3)}}} | |
| 101 |
{{{link(1,2)}}} |
| 102 |
{{{link(2,3)}}} |
| 103 |
{{{link(3,2)}}} |
| 104 |
|
| 105 |
#+begin_src latex :tangel no :exports code |
| 106 |
\begin{tabular}{lll} |
| 107 |
\simplenode{1}{node 1} & \examplenode{2}{node 2} & \warnnode{3}{node 3}\\ |
| 108 |
\end{tabular} |
| 109 |
\end{center} |
| 110 |
\link{1}{2} |
| 111 |
\link{2}{3} |
| 112 |
\link{3}{2} |
| 113 |
#+end_src |
| 114 |
** Overly complex |
| 115 |
| {{{simplenode(11, Simple node)}}} | | | | {{{simplenode(13, Simple node)}}} | |
| 116 |
| | | | | | |
| 117 |
| {{{examplenode(21, Example node)}}} | | {{{alertnode(22,Alert node)}}} | | {{{simplenode(23, Simple node)}}} | |
| 118 |
| | | | | | |
| 119 |
| {{{warnnode(31, Warn node)}}} | | | | {{{simplenode(33, Simple node)}}} | |
| 120 |
| | | | | | |
| 121 |
{{{link(22,23)}}} |
| 122 |
{{{link(22,21)}}} |
| 123 |
{{{link(22,33)}}} |
| 124 |
{{{link(22,31)}}} |
| 125 |
{{{link(22,11)}}} |
| 126 |
{{{link(22,13)}}} |
| 127 |
{{{link(11,13)}}} |
| 128 |
{{{link(33,31)}}} |
| 129 |
{{{link(21,11)}}} |
| 130 |
{{{link(21,31)}}} |
| 131 |
{{{link(13,23)}}} |
| 132 |
{{{link(33,23)}}} |
| 133 |
|
| 134 |
#+begin_src latex :tangel no :exports code |
| 135 |
\begin{tabular}{lllll} |
| 136 |
\simplenode{11}{ Simple node} & & & & \simplenode{13}{ Simple node}\\ |
| 137 |
& & & & \\ |
| 138 |
\examplenode{21}{ Example node} & & \alertnode{22}{Alert node} |
| 139 |
& & \simplenode{23}{ Simple node}\\ |
| 140 |
& & & & \\ |
| 141 |
\warnnode{31}{ Warn node} & & & & \simplenode{33}{ Simple node}\\ |
| 142 |
& & & & \\ |
| 143 |
\end{tabular} |
| 144 |
\link{22}{23} \link{22}{21} \link{22}{33} |
| 145 |
\link{22}{31} \link{22}{11} \link{22}{13} |
| 146 |
\link{11}{13} \link{33}{31} \link{21}{11} |
| 147 |
\link{21}{31} \link{13}{23} \link{33}{23} |
| 148 |
#+end_src |
| 149 |
* Implementation |
| 150 |
|
| 151 |
#+BEGIN_SRC latex :exports code :tangle simplenodes.sty |
| 152 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 153 |
%% simplenodes.sty |
| 154 |
%% <https://github.com/user9856749/simplenodes> |
| 155 |
%% |
| 156 |
%% MIT License |
| 157 |
%% |
| 158 |
%% Copyright (c) 2022 Bob Vergauwen |
| 159 |
%% |
| 160 |
%% Permission is hereby granted, free of charge, to any person obtaining a copy |
| 161 |
%% of this software and associated documentation files (the "Software"), to deal |
| 162 |
%% in the Software without restriction, including without limitation the rights |
| 163 |
%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 164 |
%% copies of the Software, and to permit persons to whom the Software is |
| 165 |
%% furnished to do so, subject to the following conditions: |
| 166 |
%% |
| 167 |
%% The above copyright notice and this permission notice shall be included in all |
| 168 |
%% copies or substantial portions of the Software. |
| 169 |
%% |
| 170 |
%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 171 |
%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 172 |
%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 173 |
%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 174 |
%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 175 |
%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 176 |
%% SOFTWARE. |
| 177 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 178 |
|
| 179 |
\NeedsTeXFormat{LaTeX2e} |
| 180 |
\ProvidesPackage{simplenodes}[2022/03/31 A package that provides simple nodes in four colors.] |
| 181 |
|
| 182 |
\RequirePackage{kvoptions} |
| 183 |
|
| 184 |
\DeclareStringOption[25mm]{width} |
| 185 |
\DeclareStringOption[7mm]{minheight} |
| 186 |
\DeclareStringOption[center]{align} |
| 187 |
\DeclareStringOption[2pt]{innersep} |
| 188 |
\DeclareStringOption[0pt]{outersep} |
| 189 |
\DeclareStringOption[0.4pt]{thickness} |
| 190 |
\ProcessKeyvalOptions* |
| 191 |
|
| 192 |
\RequirePackage{kvoptions} |
| 193 |
\RequirePackage{tikz} |
| 194 |
\RequirePackage{color} |
| 195 |
\usetikzlibrary{math} |
| 196 |
|
| 197 |
% Coordinate manipulations |
| 198 |
|
| 199 |
|
| 200 |
\newcommand{\gettikzxy}[3]{% |
| 201 |
\tikz@scan@one@point\pgfutil@firstofone#1\relax |
| 202 |
\edef#2{\the\pgf@x}% |
| 203 |
\edef#3{\the\pgf@y}% |
| 204 |
} |
| 205 |
|
| 206 |
% Define the main color |
| 207 |
\definecolor{InvisibleRed}{rgb}{0.97, 0.92, 0.92} |
| 208 |
\definecolor{InvisibleGreen}{rgb}{0.92, 0.97, 0.92} |
| 209 |
\definecolor{InvisibleBlue}{rgb}{0.92, 0.92, 0.97} |
| 210 |
\definecolor{InvisibleYellow}{rgb}{1.0, 1.0, 0.88} |
| 211 |
|
| 212 |
\definecolor{MediumRed}{rgb}{0.925, 0.345, 0.345} |
| 213 |
\definecolor{MediumGreen}{rgb}{0.37, 0.7, 0.66} |
| 214 |
\definecolor{MediumBlue}{rgb}{0.015, 0.315, 0.45} |
| 215 |
\definecolor{MediumYellow}{rgb}{1.0, 0.75, 0.0} |
| 216 |
|
| 217 |
% Define the node |
| 218 |
\newcommand\mynode[2]{ |
| 219 |
\tikz[remember picture,baseline] |
| 220 |
\node[ |
| 221 |
draw=#1,fill=#2, |
| 222 |
rectangle, |
| 223 |
line width = \simplenodes@thickness, |
| 224 |
align=\simplenodes@align, |
| 225 |
text width=\simplenodes@width, |
| 226 |
inner sep=\simplenodes@innersep, |
| 227 |
outer sep=\simplenodes@outersep, |
| 228 |
minimum height=\simplenodes@minheight, |
| 229 |
] |
| 230 |
} |
| 231 |
|
| 232 |
% Define the line |
| 233 |
\newcommand\myline[2]{ |
| 234 |
\draw[ |
| 235 |
->, |
| 236 |
line width = \simplenodes@thickness |
| 237 |
] (#1) to (#2); |
| 238 |
} |
| 239 |
|
| 240 |
\newcommand\link[2]{ |
| 241 |
\begin{tikzpicture}[remember picture, overlay, >=stealth, shift={(0,0)}] |
| 242 |
\gettikzxy{(#1)}{\ax}{\ay} |
| 243 |
\gettikzxy{(#2)}{\bx}{\by} |
| 244 |
\tikzmath{ |
| 245 |
if \ax == \bx then { |
| 246 |
if \ay < \by then { |
| 247 |
{\myline{#1.north}{#2.south}}; |
| 248 |
}; |
| 249 |
if \ay > \by then { |
| 250 |
{\myline{#1.south}{#2.north}}; |
| 251 |
}; |
| 252 |
}; |
| 253 |
if \ax < \bx then { |
| 254 |
{\myline{#1.east}{#2.west}}; |
| 255 |
}; |
| 256 |
if \ax > \bx then { |
| 257 |
{\myline{#1.west}{#2.east}}; |
| 258 |
}; |
| 259 |
}; |
| 260 |
\end{tikzpicture} |
| 261 |
} |
| 262 |
|
| 263 |
% Provide the commands |
| 264 |
\newcommand\simplenode[2]{\mynode{MediumBlue}{InvisibleBlue} (#1){#2};} |
| 265 |
\newcommand\examplenode[2]{\mynode{MediumGreen}{InvisibleGreen} (#1){#2};} |
| 266 |
\newcommand\alertnode[2]{\mynode{MediumRed}{InvisibleRed} (#1){#2};} |
| 267 |
\newcommand\warnnode[2]{\mynode{MediumYellow}{InvisibleYellow} (#1){#2};} |
| 268 |
#+END_SRC |
| 269 |
|
| 270 |
* Read me |
| 271 |
#+begin_src markdown :exports code :tangle README.md |
| 272 |
# simplenodes – Version 2022/03/31 |
| 273 |
|
| 274 |
simplenodes is a TeX macro package for generating simple node base |
| 275 |
flow graphs or diagrams, build upon the Ti*k*Z package. |
| 276 |
The package provides two basic commands, one to generate a node and |
| 277 |
one command to create links between them. |
| 278 |
The positioning of the nodes is not handled by the package itself |
| 279 |
but is preferably done in the tabular environment. |
| 280 |
|
| 281 |
In total, 4 simple node types are defined, loosely based on the |
| 282 |
nomenclature and color patterns of the popular java script bootstrap |
| 283 |
(https://getbootstrap.com/). |
| 284 |
|
| 285 |
See the file `simplenodes.pdf` for more information on the possibilities |
| 286 |
and best use case of this package. |
| 287 |
See the file `LICENSE` for license details. |
| 288 |
|
| 289 |
## Development |
| 290 |
|
| 291 |
This package is currently maintained by Bob Vergauwen, ([email protected]). |
| 292 |
Please go to the official repository at |
| 293 |
https://github.com/user9856749/simplenodes to submit bug reports, request |
| 294 |
new features, etc. |
| 295 |
#+end_src |
| 296 |
|
| 297 |
* Licence |
| 298 |
#+begin_src markdown :exports code :tangle LICENSE |
| 299 |
Licenses for the simplenode package |
| 300 |
=================================== |
| 301 |
|
| 302 |
MIT License |
| 303 |
|
| 304 |
Copyright (c) 2022 Bob Vergauwen |
| 305 |
|
| 306 |
Permission is hereby granted, free of charge, to any person obtaining a copy |
| 307 |
of this software and associated documentation files (the "Software"), to deal |
| 308 |
in the Software without restriction, including without limitation the rights |
| 309 |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 310 |
copies of the Software, and to permit persons to whom the Software is |
| 311 |
furnished to do so, subject to the following conditions: |
| 312 |
|
| 313 |
The above copyright notice and this permission notice shall be included in all |
| 314 |
copies or substantial portions of the Software. |
| 315 |
|
| 316 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 317 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 318 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 319 |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 320 |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 321 |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 322 |
SOFTWARE. |
| 323 |
#+end_src |