|
1 | 1 | \NeedsTeXFormat{LaTeX2e} |
2 | | -\ProvidesPackage{causets}[2020/12/13 v1.1 Package to draw causal set diagrams] |
3 | | -%% Copyright 2020 by C. Minz |
| 2 | +\ProvidesPackage{causets}[2022/02/07 v1.2 Package to draw causal set diagrams] |
| 3 | +%% Copyright 2020-2022 by C. Minz |
4 | 4 | % |
5 | 5 | % This work may be distributed and/or modified under the |
6 | 6 | % conditions of the LaTeX Project Public License, either version 1.3 |
|
10 | 10 | % |
11 | 11 | % This work has the LPPL maintenance status "maintained". |
12 | 12 | % |
13 | | -% The current version of this package is 1.1. |
| 13 | +% The current version of this package is 1.2. |
14 | 14 | % |
15 | 15 | % The current maintainer of this work is C. Minz. |
16 | 16 | % https://github.com/c-minz |
|
20 | 20 | % causet_tikz_example2.tex, causet_tikz_example2.pdf |
21 | 21 |
|
22 | 22 | \RequirePackage{tikz} |
| 23 | +\usepgflibrary{arrows.meta} |
23 | 24 |
|
24 | 25 | %% PGF keys: |
25 | 26 | \def\tikzcausetsset#1{\pgfqkeys{/tikz/causets}{#1}} |
|
36 | 37 | event size/.value required, |
37 | 38 | link width/.store in=\causetLinkWidth, |
38 | 39 | link width/.value required, |
| 40 | + broken link gap/.store in=\causetBrokenLinkGap, |
| 41 | + broken link gap/.value required, |
39 | 42 | text scale/.store in=\causetTextScale, |
40 | 43 | text scale/.value required, |
41 | 44 | tiny/.value forbidden, |
|
49 | 52 | grid line width=0.01ex, |
50 | 53 | event size=0.16ex, |
51 | 54 | link width=0.05ex, |
| 55 | + broken link gap=0.15ex, |
52 | 56 | text scale=0.16}, |
53 | 57 | small/.style={% |
54 | 58 | tile size=0.60ex, |
55 | 59 | region line width=0.04ex, |
56 | 60 | grid line width=0.02ex, |
57 | 61 | event size=0.32ex, |
58 | 62 | link width=0.10ex, |
| 63 | + broken link gap=0.30ex, |
59 | 64 | text scale=0.32}, |
60 | 65 | normal/.style={% |
61 | 66 | tile size=0.90ex, |
62 | 67 | region line width=0.06ex, |
63 | 68 | grid line width=0.03ex, |
64 | 69 | event size=0.48ex, |
65 | 70 | link width=0.15ex, |
| 71 | + broken link gap=0.45ex, |
66 | 72 | text scale=0.48}, |
67 | 73 | large/.style={% |
68 | 74 | tile size=1.35ex, |
69 | 75 | region line width=0.09ex, |
70 | 76 | grid line width=0.05ex, |
71 | 77 | event size=0.75ex, |
72 | 78 | link width=0.20ex, |
| 79 | + broken link gap=0.60ex, |
73 | 80 | text scale=0.75}, |
74 | 81 | huge/.style={% |
75 | 82 | tile size=1.80ex, |
76 | 83 | region line width=0.12ex, |
77 | 84 | grid line width=0.07ex, |
78 | 85 | event size=1.00ex, |
79 | 86 | link width=0.25ex, |
| 87 | + broken link gap=0.75ex, |
80 | 88 | text scale=1.00} |
81 | 89 | } |
82 | 90 | % color options: |
|
113 | 121 | blue colors/.style={% |
114 | 122 | region color=black!75, |
115 | 123 | grid color=black!25, |
116 | | - tile color=yellow!75!black!50!white, |
| 124 | + tile color=cyan!25!black!25!white, |
117 | 125 | event color=blue!50!black, |
118 | 126 | label color=blue!50!black, |
119 | 127 | link color=cyan!75!black, |
120 | | - spatial link color=red!65!black, |
| 128 | + spatial link color=blue!75!white, |
121 | 129 | ulabel color=black!50, |
122 | 130 | vlabel color=black!50}, |
123 | 131 | neon colors/.style={% |
|
134 | 142 | % styles: |
135 | 143 | \newif\ifcausetsDrawPermutation |
136 | 144 | \newif\ifcausetsDrawLinks |
| 145 | +\newif\ifcausetsBreakLinks |
137 | 146 | \newif\ifcausetsDrawSpatialLinks |
138 | 147 | \newif\ifcausetsDrawLabels |
139 | 148 | \newif\ifcausetsDrawULabels |
140 | 149 | \newif\ifcausetsDrawVLabels |
141 | 150 | \tikzcausetsset{% |
142 | 151 | show permutation/.is if=causetsDrawPermutation, |
143 | 152 | show links/.is if=causetsDrawLinks, |
| 153 | + break links/.is if=causetsBreakLinks, |
144 | 154 | show spatial links/.is if=causetsDrawSpatialLinks, |
145 | 155 | show labels/.is if=causetsDrawLabels, |
146 | 156 | show ulabels/.is if=causetsDrawULabels, |
147 | 157 | show vlabels/.is if=causetsDrawVLabels, |
148 | 158 | permutation/.code={\causetsDrawPermutationtrue}, |
149 | 159 | linked/.code={\causetsDrawLinkstrue}, |
150 | 160 | unlinked/.code={\causetsDrawLinksfalse}, |
| 161 | + brokenly linked/.code={\causetsBreakLinkstrue}, |
| 162 | + continuously linked/.code={\causetsBreakLinksfalse}, |
151 | 163 | spatially linked/.code={\causetsDrawSpatialLinkstrue}, |
152 | 164 | spatially unlinked/.code={\causetsDrawSpatialLinksfalse}, |
153 | 165 | labeled/.code={\causetsDrawLabelstrue}, |
|
159 | 171 | every region/.value forbidden, |
160 | 172 | every region/.style={color=\pgfkeysvalueof{/tikz/causets/region color}, line width=\causetRegionLine}, |
161 | 173 | region/.style={show permutation, every region/.append style={#1}}, |
| 174 | + every grid/.value forbidden, |
162 | 175 | every grid/.style={color=\pgfkeysvalueof{/tikz/causets/grid color}, line width=\causetGridLine, step=\causetTileSize}, |
163 | 176 | grid/.style={show permutation, every grid/.append style={#1}}, |
| 177 | + every tile/.value forbidden, |
164 | 178 | every tile/.style={color=\pgfkeysvalueof{/tikz/causets/tile color}, line width=\causetGridLine, fill}, |
165 | 179 | tiles/.style={show permutation, every tile/.append style={#1}}, |
| 180 | + every event/.value forbidden, |
166 | 181 | every event/.style={color=\pgfkeysvalueof{/tikz/causets/event color}, circle, fill, inner sep=0pt, minimum size=\causetEventSize}, |
167 | 182 | events/.value required, |
168 | 183 | events/.style={every event/.append style={#1}}, |
169 | | - every link/.style={color=\pgfkeysvalueof{/tikz/causets/link color}, line width=\causetLinkWidth, arrows=-}, |
| 184 | + Link Start/.tip={}, |
| 185 | + Link Pause/.tip={Triangle Cap[] . Fast Triangle[] . Fast Triangle[]}, |
| 186 | + Link Resume/.tip={Triangle Cap[reversed] . Fast Triangle[reversed] . Fast Triangle[reversed]}, |
| 187 | + Link End/.tip={}, |
| 188 | + every link/.value forbidden, |
| 189 | + every link/.style={color=\pgfkeysvalueof{/tikz/causets/link color}, line width=\causetLinkWidth, {Link Start[]}-{Link End[]}}, |
170 | 190 | links/.style={show links, every link/.append style={#1}}, |
| 191 | + link starts/.value required, |
| 192 | + link starts/.style={Link Start/.tip={#1}}, |
| 193 | + link pauses/.value required, |
| 194 | + link pauses/.style={Link Pause/.tip={#1}}, |
| 195 | + link resumes/.value required, |
| 196 | + link resumes/.style={Link Resume/.tip={#1}}, |
| 197 | + link ends/.value required, |
| 198 | + link ends/.style={Link End/.tip={#1}}, |
| 199 | + cap links/.value forbidden, |
| 200 | + cap links/.style={link starts={Triangle Cap[reversed]}, link ends={Triangle Cap[]}}, |
| 201 | + arrow links/.value forbidden, |
| 202 | + arrow links/.style={link ends={Stealth[round, open, length=4*\causetLinkWidth, line width=\causetLinkWidth/3]}}, |
| 203 | + every spatial link/.value forbidden, |
171 | 204 | every spatial link/.style={every link, color=\pgfkeysvalueof{/tikz/causets/spatial link color}, dashed}, |
172 | 205 | spatial links/.style={show spatial links, every spatial link/.append style={#1}}, |
| 206 | + every label base/.value forbidden, |
173 | 207 | every label base/.style={text opacity=1.0, scale=\causetTextScale, inner sep=0.5*\causetTextScale ex}, |
174 | 208 | all labels/.style={every label base/.append style={#1}}, |
175 | | - every label/.style={every label base, color=\pgfkeysvalueof{/tikz/causets/label color}, below left, inner sep=0pt}, |
| 209 | + every label/.value forbidden, |
| 210 | + every label/.style={every label base, color=\pgfkeysvalueof{/tikz/causets/label color}, below left}, |
176 | 211 | labels/.style={show labels, every label/.append style={#1}}, |
| 212 | + every ulabel/.value forbidden, |
177 | 213 | every ulabel/.style={every label base, color=\pgfkeysvalueof{/tikz/causets/ulabel color}, right, rotate=-45, align=left}, |
178 | 214 | ulabels/.style={show ulabels, every ulabel/.append style={#1}}, |
| 215 | + every vlabel/.value forbidden, |
179 | 216 | every vlabel/.style={every label base, color=\pgfkeysvalueof{/tikz/causets/vlabel color}, left, rotate=45, align=right}, |
180 | 217 | vlabels/.style={show vlabels, every vlabel/.append style={#1}}, |
| 218 | + every causet/.value forbidden, |
181 | 219 | every causet/.style={baseline=-0.707*\causetTileSize} |
182 | 220 | } |
183 | 221 |
|
184 | 222 | %% delare and execute options: |
185 | 223 | \tikzcausetsset{normal} |
186 | 224 | \causetsDrawLinkstrue |
| 225 | +\causetsBreakLinkstrue |
187 | 226 | \causetsDrawULabelstrue |
188 | 227 | \causetsDrawVLabelstrue |
189 | 228 | \DeclareOption{tiny}{\tikzcausetsset{tiny}} |
|
200 | 239 | \DeclareOption{neon colors}{\tikzcausetsset{neon colors}} |
201 | 240 | \DeclareOption{linked}{\causetsDrawLinkstrue} |
202 | 241 | \DeclareOption{unlinked}{\causetsDrawLinksfalse} |
| 242 | +\DeclareOption{cap linked}{\tikzcausetsset{cap links}} |
| 243 | +\DeclareOption{arrow linked}{\tikzcausetsset{arrow links}} |
| 244 | +\DeclareOption{brokenly linked}{\causetsBreakLinkstrue} |
| 245 | +\DeclareOption{continuously linked}{\causetsBreakLinksfalse} |
203 | 246 | \DeclareOption{spatially linked}{\causetsDrawSpatialLinkstrue} |
204 | 247 | \DeclareOption{spatially unlinked}{\causetsDrawSpatialLinksfalse} |
205 | 248 | \DeclareOption{permutation}{\causetsDrawPermutationtrue} |
|
270 | 313 | \fi |
271 | 314 | } |
272 | 315 |
|
| 316 | +% draw the spatial links from the permutation: |
| 317 | +\newcommand*{\causets@drawSpatialLinks}[1]{% |
| 318 | +\ifcausetsDrawSpatialLinks |
| 319 | + \setcounter{causet@i}{0} |
| 320 | + \foreach \causet@p in {#1}{% |
| 321 | + \stepcounter{causet@i} |
| 322 | + \edef\causet@qBound{0} |
| 323 | + \setcounter{causet@j}{0} |
| 324 | + \foreach \causet@q in {#1}{% |
| 325 | + \stepcounter{causet@j} |
| 326 | + \ifnum\value{causet@j}>\value{causet@i} |
| 327 | + \ifnum\causet@q>\causet@qBound |
| 328 | + \ifnum\causet@p>\causet@q |
| 329 | + \draw[causets/.cd, every spatial link] (E\causet@q) -- (E\causet@p); |
| 330 | + \xdef\causet@qBound{\causet@q} |
| 331 | + \fi |
| 332 | + \fi |
| 333 | + \fi |
| 334 | + } |
| 335 | + } |
| 336 | +\fi |
| 337 | +} |
| 338 | + |
273 | 339 | % draw event labels: |
274 | 340 | \newcommand*{\causets@drawEventLabels}[1]{% |
275 | 341 | \ifcausetsDrawLabels |
276 | 342 | \foreach \causet@p in {#1}{% |
277 | 343 | \node[causets/.cd, every label] (EL\causet@p) |
278 | | - at (E\causet@p.south west) {\causet@p}; |
| 344 | + at (E\causet@p) {\causet@p}; |
279 | 345 | } |
280 | 346 | \fi |
281 | 347 | } |
|
307 | 373 | } |
308 | 374 | } |
309 | 375 | \fi |
310 | | - \ifcausetsDrawSpatialLinks |
311 | | - \setcounter{causet@i}{0} |
312 | | - \foreach \causet@p in {#1}{% |
313 | | - \stepcounter{causet@i} |
314 | | - \edef\causet@qBound{0} |
315 | | - \setcounter{causet@j}{0} |
316 | | - \foreach \causet@q in {#1}{% |
317 | | - \stepcounter{causet@j} |
318 | | - \ifnum\value{causet@j}>\value{causet@i} |
319 | | - \ifnum\causet@q>\causet@qBound |
320 | | - \ifnum\causet@p>\causet@q |
321 | | - \draw[causets/.cd, every spatial link] (E\causet@q) -- (E\causet@p); |
322 | | - \xdef\causet@qBound{\causet@q} |
323 | | - \fi |
324 | | - \fi |
325 | | - \fi |
326 | | - } |
327 | | - } |
328 | | - \fi |
| 376 | + \causets@drawSpatialLinks{#1} |
329 | 377 | \causets@drawEventLabels{#1} |
330 | 378 | \end{scope} |
331 | 379 | \end{scope} |
|
340 | 388 | \causets@drawEvents{#1} |
341 | 389 | \causets@drawPermutation{#1} |
342 | 390 | \ifcausetsDrawLinks |
343 | | - \foreach \causet@From/\causet@To in {#2}{% |
344 | | - \draw[causets/.cd, every link] (E\causet@From) -- (E\causet@To); |
345 | | - } |
| 391 | + \ifcausetsBreakLinks |
| 392 | + \foreach \causet@From/\causet@To in {#2}{% |
| 393 | + \pgfmathsetmacro\causet@dU{int(\causet@To) - int(\causet@From)} |
| 394 | + \setcounter{causet@i}{0} |
| 395 | + \foreach \causet@p in {#1}{% |
| 396 | + \ifnum\causet@p=\causet@To |
| 397 | + \pgfmathparse{int(\value{causet@i})} |
| 398 | + \xdef\causet@dV{\pgfmathresult} |
| 399 | + \fi |
| 400 | + \ifnum\value{causet@i}>0 |
| 401 | + \stepcounter{causet@i} |
| 402 | + \fi |
| 403 | + \ifnum\causet@p=\causet@From |
| 404 | + \stepcounter{causet@i} |
| 405 | + \fi |
| 406 | + } |
| 407 | + \def\causet@LastBreak{0} |
| 408 | + \setcounter{causet@i}{0} |
| 409 | + \foreach \causet@p in {#1}{% |
| 410 | + \ifnum\causet@p=\causet@To |
| 411 | + \setcounter{causet@i}{0} |
| 412 | + \fi |
| 413 | + \pgfmathparse{and(\value{causet@i} > 0, int((\causet@p - \causet@From) * \causet@dV) == int(\causet@dU * \value{causet@i}))} |
| 414 | + \ifnum\pgfmathresult=1 |
| 415 | + \ifnum\causet@LastBreak=0 |
| 416 | + \draw[causets/.cd, every link, {Link Start}-{Link Pause}, shorten >=\causetBrokenLinkGap] |
| 417 | + (E\causet@From) -- (E\causet@p); |
| 418 | + \else |
| 419 | + \draw[causets/.cd, every link, {Link Resume}-{Link Pause}, shorten <=\causetBrokenLinkGap, shorten >=\causetBrokenLinkGap] |
| 420 | + (E\causet@LastBreak) -- (E\causet@p); |
| 421 | + \fi |
| 422 | + \xdef\causet@LastBreak{\causet@p} |
| 423 | + \fi |
| 424 | + \ifnum\value{causet@i}>0 |
| 425 | + \stepcounter{causet@i} |
| 426 | + \fi |
| 427 | + \ifnum\causet@p=\causet@From |
| 428 | + \setcounter{causet@i}{1} |
| 429 | + \fi |
| 430 | + } |
| 431 | + \ifnum\causet@LastBreak>0 |
| 432 | + \draw[causets/.cd, every link, {Link Resume}-{Link End}, shorten <=\causetBrokenLinkGap] |
| 433 | + (E\causet@LastBreak) -- (E\causet@To); |
| 434 | + \else |
| 435 | + \draw[causets/.cd, every link] |
| 436 | + (E\causet@From) -- (E\causet@To); |
| 437 | + \fi |
| 438 | + } |
| 439 | + \else |
| 440 | + \foreach \causet@From/\causet@To in {#2}{% |
| 441 | + \draw[causets/.cd, every link] (E\causet@From) -- (E\causet@To); |
| 442 | + } |
| 443 | + \fi |
346 | 444 | \fi |
347 | 445 | \causets@drawEventLabels{#1} |
348 | 446 | \end{scope} |
|
370 | 468 | \ifnum\causet@p<\causet@q |
371 | 469 | \global\causet@ItemFoundInListfalse |
372 | 470 | \foreach \causet@From/\causet@To in {#2}{% |
373 | | - \pgfmathparse{and( equal( int(\causet@From), int(\causet@p) ), equal( int(\causet@To), int(\causet@q) ) )} |
| 471 | + \pgfmathparse{and(int(\causet@From) == int(\causet@p), int(\causet@To) == int(\causet@q))} |
374 | 472 | \ifnum\pgfmathresult=1 |
375 | 473 | \global\causet@ItemFoundInListtrue |
376 | 474 | \fi |
|
387 | 485 | } |
388 | 486 | } |
389 | 487 | \fi |
| 488 | + \causets@drawSpatialLinks{#1} |
| 489 | + \ifcausetsDrawSpatialLinks |
| 490 | + \foreach \causet@From/\causet@To in {#2}{% |
| 491 | + \draw[causets/.cd, every spatial link] (E\causet@From) -- (E\causet@To); |
| 492 | + } |
| 493 | + \fi |
390 | 494 | \causets@drawEventLabels{#1} |
391 | 495 | \end{scope} |
392 | 496 | \end{scope} |
|
0 commit comments