├── .gitignore ├── README.md ├── cryptocode-2018-11-11.sty ├── cryptocode-2020-04-24.sty ├── cryptocode.dtx ├── cryptocode.ins ├── cryptocode.pdf ├── cryptocode.sty └── ctan_packages ├── v0.40 └── cryptocode.tar.gz └── v0.44 └── cryptocode.tar.gz /.gitignore: -------------------------------------------------------------------------------- 1 | *.aux 2 | *.fdb_latexmk 3 | *.fls 4 | *.idx 5 | *.ilg 6 | *.ind 7 | *.log 8 | *.out 9 | *.toc 10 | *.glo 11 | *.gls 12 | *.hd 13 | *.DS_Store 14 | tmp.* -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cryptocode 2 | The cryptocode package provides a set of macros to ease the typesetting of pseudocode, algorithms and protocols. In addition it comes with a wide range of tools to typeset cryptographic papers. This includes simple predefined commands for concepts such as a security parameter or advantage terms but also flexible and powerful environments to layout game-based proofs or black-box reductions. 3 | 4 | # Installation 5 | 6 | Extract the *cryptocode.sty* file via 7 | 8 | pdflatex cryptocode.ins 9 | 10 | # Documentation 11 | 12 | Create the documentation via 13 | 14 | pdflatex cryptocode.dtx 15 | pdflatex cryptocode.dtx 16 | makeindex -s gind.ist -o cryptocode.idx cryptocode 17 | makeindex -s gglo.ist -o cryptocode.gls cryptocode.glo 18 | pdflatex cryptocode.dtx 19 | 20 | A prebuilt version of the documentation is available in the repository. 21 | 22 | # Versioning 23 | 24 | Cryptocode supports LaTeX' rollback mechanism. To load a particular version of cryptocode use 25 | 26 | \usepackage[options]{cryptocode}[=2018-11-11] 27 | 28 | Besides the current version 0.44, the following deprecated versions are available via 29 | the rollback mechanism. 30 | 31 | - v0.32 (2020-04-24) 32 | - v0.30 (2018-11-11) 33 | 34 | # Contribution 35 | 36 | Contributions to *cryptocode* are very welcome. 37 | 38 | # Attribution 39 | 40 | If you use cryptocode in your work, consider starring the repository on GitHub and/or rating it on CTAN. 41 | 42 | # License 43 | 44 | [LaTeX Project Public License](http://www.latex-project.org/lppl.txt) 45 | 46 | -------------------------------------------------------------------------------- /cryptocode-2018-11-11.sty: -------------------------------------------------------------------------------- 1 | %% Copyright 2018 Arno Mittelbach 2 | % 3 | % This work may be distributed and/or modified under the 4 | % conditions of the LaTeX Project Public License, either version 1.3 5 | % of this license or (at your option) any later version. 6 | % The latest version of this license is in 7 | % http://www.latex-project.org/lppl.txt 8 | % and version 1.3 or later is part of all distributions of LaTeX 9 | % version 2005/12/01 or later. 10 | % 11 | % This work has the LPPL maintenance status `maintained'. 12 | % 13 | % The Current Maintainer of this work is Arno Mittelbach. 14 | % 15 | % This work consists of the files cryptocode.tex and cryptocode.sty 16 | % 17 | % Changelog 18 | % 19 | % 2016/11/30 20 | % - changed \pckeystyle to ensure that subscripts on \sk and \pk are aligned the same 21 | % before, $(\sk_R, \pk_R)$ had slightly misaligned subscripts due to Tex treating 22 | % subscripts on composite objects with descenders differently than without. 23 | % see https://groups.google.com/forum/#!msg/comp.text.tex/IaXu_xBG06Q/CibRPH5GCAAJ 24 | % - added \NAND 25 | % - added pcmbox environment for matrices in pseudocode 26 | % 27 | % 2016/12/02 28 | % - changed minheight for bbrbox environment to actually reflect a minimum height in tikz 29 | % the old minheight which added space at the bottom was preserved as addheight 30 | % - added namepos middle for bbrbox 31 | % - added pcfail 32 | % - added valign to pseudocode to allow minipage vertical alignment 33 | % - added \setgameproceduredefaultstyle 34 | % - ensure line numbers are right aligned to allow for two digit linenumbers having the same width 35 | % 36 | % 2017/08/26 37 | % - added \pcabort 38 | % - better control whitespace for \pcif, \pcelse, \pcelseif 39 | % 40 | % 2017/10/02 41 | % - side and oside support to \bbroracleqryto and \bbroracleqryfrom 42 | % - add bottom to namepos in bbrbox 43 | % - names for brrinput and bbroutput 44 | % - angle for bbrloop 45 | % - fix length for bbrinput 46 | % - introduce hoffset for bbrinput 47 | % 48 | % 2017/12/21 49 | % - added \pcunless 50 | % 51 | % 2018/11/11 52 | % replace obsolete l3regex 53 | % 54 | \NeedsTeXFormat{LaTeX2e} 55 | \ProvidesPackage{cryptocode} 56 | [2018/11/11 v0.3.0 Cryptocode LaTeX package for typesetting pseudocode, algorithms and protocols as well as cryptographic proofs.] 57 | 58 | 59 | \def\hi{Hello, this is cryptocode.} 60 | \let\myDate\date 61 | 62 | \RequirePackage{amsmath} 63 | \RequirePackage{mathtools} 64 | %\usepackage{l3tl-analysis} % uncomment for debugging 65 | 66 | %%% 67 | % option modes 68 | \newif\ifpc@orderofgrowth 69 | \newif\ifpc@algorithmstyle 70 | \newif\ifpc@amsfonts 71 | \newif\ifpc@advantage 72 | \newif\ifpc@primitives 73 | 74 | %%% 75 | % 76 | \DeclareOption{operators}{ 77 | \providecommand{\sample}{\hskip2.3pt{\gets\!\!\mbox{\tiny${\$}$\normalsize}}\,} 78 | 79 | \providecommand{\floor}[1]{\ensuremath{\left\lfloor #1\right\rfloor}} 80 | \providecommand{\ceil}[1]{\ensuremath{\left\lceil #1\right\rceil}} 81 | \providecommand{\Angle}[1]{\ensuremath{\left\langle #1\right\rangle}} 82 | \providecommand{\abs}[1]{\ensuremath{\left\lvert #1 \right\rvert}} 83 | \providecommand{\norm}[1]{\ensuremath{\left\|#1\right\|}} 84 | \providecommand{\concat}{\ensuremath{\|}} 85 | 86 | \providecommand{\emptystring}{\ensuremath{\varepsilon}} 87 | } 88 | 89 | \DeclareOption{adversary}{ 90 | \providecommand{\pcadvstyle}[1]{\mathcal{#1}} 91 | 92 | \providecommand{\adv}{\ensuremath{\pcadvstyle{A}}} 93 | \providecommand{\bdv}{\ensuremath{\pcadvstyle{B}}} 94 | \providecommand{\cdv}{\ensuremath{\pcadvstyle{C}}} 95 | \providecommand{\ddv}{\ensuremath{\pcadvstyle{D}}} 96 | \providecommand{\mdv}{\ensuremath{\pcadvstyle{M}}} 97 | \providecommand{\pdv}{\ensuremath{\pcadvstyle{P}}} 98 | \providecommand{\rdv}{\ensuremath{\pcadvstyle{R}}} 99 | \providecommand{\sdv}{\ensuremath{\pcadvstyle{S}}} 100 | } 101 | 102 | \DeclareOption{landau}{ 103 | \pc@orderofgrowthtrue 104 | 105 | \providecommand{\bigO}[1]{\ensuremath{\mathcal{O}\olrk{#1}}} 106 | \providecommand{\smallO}[1]{\ensuremath{\text{o}\olrk{#1}}} 107 | \providecommand{\bigOmega}[1]{\ensuremath{\Omega\olrk{#1}}} 108 | \providecommand{\smallOmega}[1]{\ensuremath{\omega\olrk{#1}}} 109 | \providecommand{\bigsmallO}[1]{\ensuremath{\Theta\olrk{#1}}} 110 | } 111 | 112 | \DeclareOption{probability}{ 113 | \pc@orderofgrowthtrue 114 | \pc@amsfontstrue 115 | 116 | \providecommand{\probname}{Pr} 117 | \providecommand{\expectationname}{\ensuremath{\mathbb{E}}} 118 | \providecommand{\supportname}{Supp} 119 | 120 | \providecommand{\prob}[1]{\ensuremath{\operatorname{\probname}\elrk{#1}}} 121 | \providecommand{\probsub}[2]{\ensuremath{\operatorname{\probname}_{#1}\elrk{#2}}} 122 | \providecommand{\condprob}[2]{\ensuremath{\prob{#1\,\left|\,#2\vphantom{#1}\right.}}} 123 | \providecommand{\condprobsub}[3]{\ensuremath{\probsub{#1}{#2\,\left|\,#3\vphantom{#1}\right.}}} 124 | 125 | \providecommand{\expect}[1]{\ensuremath{\operatorname{\expectationname}\elrk{#1}}} 126 | \providecommand{\expsub}[2]{\ensuremath{\operatorname{\expectationname}_{#1}\elrk{#2}}} 127 | \providecommand{\condexp}[2]{\ensuremath{\expect{#1\,\left|\,#2\vphantom{#1}\right.}}} 128 | \providecommand{\condexpsub}[3]{\ensuremath{\expsub{#1}{#2\,\left|\,#3\vphantom{#1}\right.}}} 129 | 130 | \providecommand{\supp}[1]{ \ensuremath{\operatorname{Supp}\olrk{#1}}} 131 | 132 | \providecommand{\entropy}[1]{\ensuremath{\operatorname{H}\olrk{#1}}} 133 | \providecommand{\condentropy}[2]{\ensuremath{\operatorname{H}\olrk{#1\,\left|\,#2\vphantom{#1}\right.}}} 134 | \providecommand{\minentropy}[1]{\ensuremath{\operatorname{H_\infty}\olrk{#1}}} 135 | \providecommand{\condminentropy}[2]{\ensuremath{\operatorname{H_\infty}\olrk{#1\,\left|\,#2\vphantom{#1}\right.}}} 136 | \providecommand{\condavgminentropy}[2]{\ensuremath{\operatorname{\tilde{H}_\infty}\olrk{#1\,\left|\,#2\vphantom{#1}\right.}}} 137 | } 138 | 139 | \DeclareOption{sets}{ 140 | \pc@orderofgrowthtrue 141 | \pc@amsfontstrue 142 | 143 | \providecommand\NN{\mathbb{N}} 144 | \providecommand\ZZ{\mathbb{Z}} 145 | \providecommand\CC{\mathbb{C}} 146 | \providecommand\QQ{\mathbb{Q}} 147 | \providecommand\RR{\mathbb{R}} 148 | \providecommand\PP{\mathbb{P}} 149 | \providecommand\FF{\mathbb{F}} 150 | \providecommand\GG{\mathbb{G}} 151 | 152 | \providecommand{\set}[1]{\ensuremath{\clrk{#1}}} 153 | \providecommand{\sequence}[1]{\ensuremath{\olrk{#1}}} 154 | \providecommand{\bin}{\ensuremath{\{0,1\}}} 155 | } 156 | 157 | \DeclareOption{noamsfonts}{ 158 | \pc@amsfontsfalse 159 | } 160 | 161 | 162 | \DeclareOption{notions}{ 163 | \providecommand{\pcnotionstyle}[1]{\ensuremath{\mathrm{#1}}} 164 | 165 | \providecommand{\indcpa}{\pcnotionstyle{IND\pcmathhyphen{}CPA}} 166 | \providecommand{\indcca}{\pcnotionstyle{IND\pcmathhyphen{}CCA}} 167 | \providecommand{\indccai}{\pcnotionstyle{IND\pcmathhyphen{}CCA1}} 168 | \providecommand{\indccaii}{\pcnotionstyle{IND\pcmathhyphen{}CCA2}} 169 | \providecommand{\priv}{\pcnotionstyle{PRIV}} 170 | \providecommand{\ind}{\pcnotionstyle{IND}} 171 | \providecommand{\indcda}{\pcnotionstyle{IND\pcmathhyphen{}CDA}} 172 | \providecommand{\prvcda}{\pcnotionstyle{PRV\pcmathhyphen{}CDA}} 173 | \providecommand{\prvrcda}{\pcnotionstyle{PRV\$\pcmathhyphen{}CDA}} 174 | \providecommand{\kiae}{\pcnotionstyle{KIAE}} 175 | \providecommand{\kdae}{\pcnotionstyle{KDAE}} 176 | \providecommand{\mle}{\pcnotionstyle{MLE}} 177 | \providecommand{\uce}{\pcnotionstyle{UCE}} 178 | } 179 | 180 | \DeclareOption{logic}{ 181 | \providecommand{\AND}{\ensuremath{\mathrm{AND}}} 182 | \providecommand{\OR}{\ensuremath{\mathrm{OR}}} 183 | \providecommand{\NOR}{\ensuremath{\mathrm{NOR}}} 184 | \providecommand{\NOT}{\ensuremath{\mathrm{NOT}}} 185 | \providecommand{\NAND}{\ensuremath{\mathrm{NAND}}} 186 | \providecommand{\XOR}{\ensuremath{\mathrm{XOR}}} 187 | \providecommand{\XNOR}{\ensuremath{\mathrm{XNOR}}} 188 | \providecommand{\xor}{\ensuremath{\oplus}} 189 | \providecommand{\false}{\mathsf{false}} 190 | \providecommand{\true}{\mathsf{true}} 191 | } 192 | 193 | 194 | % Function Families 195 | \DeclareOption{ff}{ 196 | \pc@algorithmstyletrue 197 | 198 | \providecommand{\kgen}{\pcalgostyle{KGen}} 199 | \providecommand{\pgen}{\pcalgostyle{Pgen}} 200 | \providecommand{\eval}{\pcalgostyle{Eval}} 201 | \providecommand{\invert}{\pcalgostyle{Inv}} 202 | 203 | \providecommand{\il}{\pcalgostyle{il}} 204 | \providecommand{\ol}{\pcalgostyle{ol}} 205 | \providecommand{\kl}{\pcalgostyle{kl}} 206 | \providecommand{\nl}{\pcalgostyle{nl}} 207 | \providecommand{\rl}{\pcalgostyle{rl}} 208 | } 209 | 210 | % Machine Model 211 | \DeclareOption{mm}{ 212 | \pc@algorithmstyletrue 213 | 214 | \providecommand{\pcmachinemodelstyle}[1]{\ensuremath{\mathsf{#1}}} 215 | 216 | \providecommand{\CRKT}{\pcmachinemodelstyle{C}} 217 | \providecommand{\TM}{\pcmachinemodelstyle{M}} 218 | \providecommand{\PROG}{\pcmachinemodelstyle{P}} 219 | 220 | \providecommand{\uTM}{\pcmachinemodelstyle{UM}} 221 | \providecommand{\uC}{\pcmachinemodelstyle{UC}} 222 | \providecommand{\uP}{\pcmachinemodelstyle{UEval}} 223 | 224 | \providecommand{\csize}{\pcmachinemodelstyle{size}} 225 | \providecommand{\tmtime}{\pcmachinemodelstyle{time}} 226 | \providecommand{\ppt}{\pcalgostyle{PPT}} 227 | } 228 | 229 | \DeclareOption{advantage}{ 230 | \pc@advantagetrue 231 | } 232 | 233 | \DeclareOption{primitives}{ 234 | \pc@primitivestrue 235 | \pc@algorithmstyletrue 236 | } 237 | 238 | \DeclareOption{events}{ 239 | \providecommand{\event}[1]{\ensuremath{\mathsf{#1}}} 240 | \providecommand{\nevent}[1]{\ensuremath{\overline{\event{#1}}}} 241 | 242 | \providecommand{\bad}{\ensuremath{\event{bad}}} 243 | } 244 | 245 | \DeclareOption{complexity}{ 246 | \providecommand{\pccomplexitystyle}[1]{\ensuremath{\mathsf{#1}}} 247 | 248 | \providecommand{\npol}{\pccomplexitystyle{NP}} 249 | \providecommand{\conpol}{\ensuremath{\mathsf{co}}\pccomplexitystyle{NP}} 250 | \providecommand{\pol}{\pccomplexitystyle{P}} 251 | \providecommand{\bpp}{\pccomplexitystyle{BPP}} 252 | \providecommand{\ppoly}{\ensuremath{\pol/\mathrm{poly}}} 253 | 254 | \providecommand{\AM}{\pccomplexitystyle{AM}} 255 | \providecommand{\coAM}{\ensuremath{\mathsf{co}}\pccomplexitystyle{AM}} 256 | 257 | \providecommand{\AC}[1]{\ensuremath{\ifthenelse{\equal{#1}{}}{\pccomplexitystyle{AC}}{\pccomplexitystyle{AC}^{#1}}}} 258 | \providecommand{\NC}[1]{\ensuremath{\ifthenelse{\equal{#1}{}}{\pccomplexitystyle{NC}}{\pccomplexitystyle{NC}^{#1}}}} 259 | \providecommand{\TC}[1]{\ensuremath{\ifthenelse{\equal{#1}{}}{\pccomplexitystyle{TC}}{\pccomplexitystyle{TC}^{#1}}}} 260 | } 261 | 262 | \DeclareOption{asymptotics}{ 263 | \pc@orderofgrowthtrue 264 | 265 | \providecommand{\pcpolynomialstyle}[1]{\mathsf{#1}} 266 | 267 | \providecommand{\negl}[1][\secpar]{\ensuremath{\pcpolynomialstyle{negl}\ifthenelse{\equal{#1}{}}{}{\olrk{#1}}}} 268 | \providecommand{\poly}[1][\secpar]{\ensuremath{\pcpolynomialstyle{poly}\ifthenelse{\equal{#1}{}}{}{\olrk{#1}}}} 269 | 270 | \providecommand{\pp}{\ensuremath{\pcpolynomialstyle{p}}} 271 | \providecommand{\qq}{\ensuremath{\pcpolynomialstyle{q}}} 272 | } 273 | 274 | \DeclareOption{keys}{ 275 | \providecommand{\pckeystyle}[1]{\ensuremath{\mathsf{\protect\vphantom{p}#1}}} 276 | 277 | \providecommand{\pk}{\pckeystyle{pk}} 278 | \providecommand{\vk}{\pckeystyle{vk}} 279 | \providecommand{\sk}{\pckeystyle{sk}} 280 | \providecommand{\key}{\pckeystyle{k}} 281 | \providecommand{\hk}{\pckeystyle{hk}} 282 | \providecommand{\gk}{\pckeystyle{gk}} 283 | \providecommand{\fk}{\pckeystyle{fk}} 284 | 285 | \providecommand{\st}{\pckeystyle{st}} 286 | \providecommand{\state}{\pckeystyle{state}} 287 | } 288 | 289 | \DeclareOption{n}{ 290 | \providecommand{\secpar}{\ensuremath{n}} 291 | \providecommand{\secparam}{\ensuremath{1^\secpar}} 292 | } 293 | 294 | \DeclareOption{lambda}{ 295 | \renewcommand{\secpar}{\ensuremath{\lambda}} 296 | \renewcommand{\secparam}{\ensuremath{1^\secpar}} 297 | } 298 | 299 | \DeclareOption*{% 300 | \PackageError{crypto code}{Unknown option ‘\CurrentOption’}% 301 | } 302 | 303 | \ExecuteOptions{n} 304 | 305 | \ProcessOptions\relax 306 | 307 | \RequirePackage{etex} 308 | 309 | %amsfonts 310 | \ifpc@amsfonts 311 | \RequirePackage{amsfonts} 312 | \fi 313 | \RequirePackage{xcolor} 314 | \RequirePackage{calc} 315 | \RequirePackage{tikz} 316 | \usetikzlibrary{positioning,calc} 317 | \RequirePackage{ifthen} 318 | \RequirePackage{xargs} 319 | \RequirePackage{pgf} 320 | %\RequirePackage{mathabx} 321 | \RequirePackage{forloop} 322 | \RequirePackage{array} 323 | \RequirePackage{xparse} 324 | \RequirePackage{expl3} 325 | \RequirePackage{pbox} 326 | \RequirePackage{varwidth} 327 | \RequirePackage{suffix} 328 | \RequirePackage{etoolbox} 329 | \RequirePackage{environ} 330 | %\RequirePackage{xspace} 331 | \RequirePackage{xkeyval} 332 | 333 | \ifpc@advantage 334 | \newcommand{\pcadvantagesuperstyle}[1]{\mathrm{\MakeLowercase{#1}}} 335 | \newcommand{\pcadvantagesubstyle}[1]{#1} 336 | \newcommandx*{\advantage}[3][3=(\secpar)]{\ensuremath{\mathsf{Adv}^{\pcadvantagesuperstyle{#1}}_{\pcadvantagesubstyle{#2}}#3}} 337 | \fi 338 | 339 | \ifpc@primitives 340 | % zero knowledge 341 | \providecommand{\prover}{\pcalgostyle{P}} 342 | \providecommand{\verifier}{\pcalgostyle{V}} 343 | \providecommand{\nizk}{\pcalgostyle{NIZK}} 344 | 345 | % hash 346 | \providecommand{\hash}{\pcalgostyle{H}} 347 | \providecommand{\gash}{\pcalgostyle{G}} 348 | \providecommand{\fash}{\pcalgostyle{F}} 349 | 350 | % encryption 351 | \providecommand{\enc}{\pcalgostyle{Enc}} 352 | \providecommand{\dec}{\pcalgostyle{Dec}} 353 | 354 | % signatures 355 | \providecommand{\sig}{\pcalgostyle{Sig}} 356 | \providecommand{\verify}{\pcalgostyle{Vf}} 357 | 358 | % obfuscation 359 | \providecommand{\obf}{\pcalgostyle{O}} 360 | \providecommand{\iO}{\pcalgostyle{iO}} 361 | \providecommand{\diO}{\pcalgostyle{diO}} 362 | 363 | % PRF, PRG 364 | \providecommand{\prf}{\pcalgostyle{PRF}} 365 | \providecommand{\prg}{\pcalgostyle{PRG}} 366 | 367 | % Mac 368 | \providecommand{\mac}{\pcalgostyle{MAC}} 369 | 370 | % puncture 371 | \providecommand{\puncture}{\pcalgostyle{Puncture}} 372 | 373 | % Misc 374 | \providecommand{\source}{\pcalgostyle{S}} 375 | \providecommand{\predictor}{\pcalgostyle{P}} 376 | \providecommand{\sam}{\pcalgostyle{Sam}} 377 | \providecommand{\dist}{\pcalgostyle{D}} 378 | \providecommand{\distinguisher}{\pcalgostyle{Dist}} 379 | \providecommand{\simulator}{\pcalgostyle{Sim}} 380 | \providecommand{\ext}{\pcalgostyle{Ext}} 381 | \providecommand{\extractor}{\ext} 382 | \fi 383 | 384 | %% 385 | % math hyphen 386 | \mathchardef\pcmathhyphen ="2D 387 | 388 | %%% 389 | % order of growth helper 390 | \ifpc@orderofgrowth 391 | \providecommand{\olrk}[1]{\ifx\nursymbol#1\else\!\!\mskip4.5mu plus 0.5mu\left(\mskip0.5mu plus0.5mu #1\mskip1.5mu plus0.5mu \right)\fi} 392 | 393 | \providecommand{\elrk}[1]{\ifx\nursymbol#1\else\!\!\mskip4.5mu plus0.5mu\left[\mskip0.5mu plus0.5mu #1\mskip1.5mu plus0.5mu \right]\fi} 394 | 395 | \providecommand{\clrk}[1]{\ifx\nursymbol#1\else\!\!\mskip4.5mu plus0.5mu\left\{\mskip0.5mu plus0.5mu #1\mskip1.5mu plus0.5mu \right\}\fi} 396 | \fi 397 | 398 | \ifpc@algorithmstyle 399 | \providecommand{\pcalgostyle}[1]{\ensuremath{\mathsf{#1}}} 400 | \fi 401 | 402 | %%% 403 | % create command to measure width of align 404 | % 405 | \newcommand{\@settowidthofalign}[2]{% 406 | \setbox\z@=\vbox{\@pseudocodecodesize 407 | \begin{flalign*} 408 | #2 409 | \ifmeasuring@\else\global\let\got@maxcolwd\maxcolumn@widths\fi 410 | \end{flalign*} 411 | }% 412 | \begingroup 413 | \def\or{+}\edef\x{\endgroup#1=\dimexpr\got@maxcolwd\relax}\x} 414 | 415 | \newcommand{\@settowidthofaligned}[2]{% 416 | \settowidth{#1}{\@pseudocodesubcodesize$\begin{aligned}#2\end{aligned}$}} 417 | 418 | % check for draft mode 419 | \def\@pc@ifdraft{\ifdim\overfullrule>\z@ 420 | \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi} 421 | 422 | % run stuff in an empty box 423 | \newcommand{\@pcexecuteblindly}[1]{% 424 | \setbox\z@=\vbox{#1 }} 425 | 426 | % copy label command 427 | \AtBeginDocument{ 428 | \let\pc@original@label\ltx@label 429 | } 430 | 431 | 432 | %%%%%% 433 | \newcommand*{\@pc@globaladdtolength}[2]{% 434 | \addtolength{#1}{#2}% 435 | \global#1=#1\relax} 436 | 437 | \newcommand*{\@pc@globalsetlength}[2]{% 438 | \setlength{#1}{#2}% 439 | \global#1=#1\relax} 440 | 441 | 442 | 443 | %%%%% 444 | % spaces before and after pseudo codes (left and right) 445 | \providecommand{\beforepcskip}{2pt} 446 | \providecommand{\afterpcskip}{0pt} 447 | 448 | %%% 449 | % a global counter of the number of times the pseudocode command was triggered 450 | \newcounter{@pc@global@pc@cnt} 451 | \newcounter{@pc@global@pc@nestcnt} 452 | 453 | %%% 454 | % Fix hyperref package.. gnarl http://tex.stackexchange.com/questions/130319/incompatibility-between-etoolbox-and-hyperref 455 | \providecommand{\pcfixhyperref}{ 456 | \global\let\textlabel\label 457 | \global\let\pc@original@label\textlabel 458 | %\global\let\pc@original@label\relax 459 | %\global\let\label\relax 460 | } 461 | 462 | \newcounter{@spacecounter} 463 | \providecommand{\spacetoindent}{1} 464 | \newenvironment{@withspaces} 465 | {\obeyspaces\begingroup\lccode`~=` \lowercase{\endgroup\let~}\ } 466 | {} 467 | 468 | %%%%%%%%%%%%%% 469 | % a latex3 string substitution. 470 | \ExplSyntaxOn 471 | \tl_new:N \l_pc_strsub_input_tl 472 | \tl_new:N \l_pc_strsub_search_tl 473 | \tl_new:N \l_pc_strsub_replace_tl 474 | 475 | \NewDocumentCommand{\@pc@stringsubstitution}{mmm} 476 | { 477 | \tl_set:Nn \l_pc_strsub_input_tl { #1 } 478 | \tl_set:Nn \l_pc_strsub_search_tl { #2 } 479 | \tl_set:Nn \l_pc_strsub_replace_tl { #3 } 480 | % \tl_show_analysis:N \l_pc_strsub_input_tl % uncomment for debugging 481 | % \tl_show_analysis:N \l_pc_strsub_search_tl % uncomment for debugging 482 | % \tl_show_analysis:N \l_pc_strsub_replace_tl % uncomment for debugging 483 | \regex_replace_all:nnN 484 | { (\W)\u{l_pc_strsub_search_tl} } %only match if keyword does not have a word character preceding 485 | { \1\u{l_pc_strsub_replace_tl} } 486 | \l_pc_strsub_input_tl 487 | % \tl_show_analysis:N \l_tmpa_tl % uncomment for debugging 488 | \tl_use:N \l_pc_strsub_input_tl 489 | } 490 | 491 | % same as \@pc@stringsubstitution but without requiring the extra non word character 492 | \NewDocumentCommand{\@pc@spacesubstitution}{mmm} 493 | { 494 | \tl_set:Nn \l_pc_strsub_input_tl { #1 } 495 | \tl_set:Nn \l_pc_strsub_search_tl { #2 } 496 | \tl_set:Nn \l_pc_strsub_replace_tl { #3 } 497 | % \tl_show_analysis:N \l_pc_strsub_input_tl % uncomment for debugging 498 | % \tl_show_analysis:N \l_pc_strsub_search_tl % uncomment for debugging 499 | % \tl_show_analysis:N \l_pc_strsub_replace_tl % uncomment for debugging 500 | \regex_replace_all:nnN 501 | { \u{l_pc_strsub_search_tl} } 502 | { \u{l_pc_strsub_replace_tl} } 503 | \l_pc_strsub_input_tl 504 | % \tl_show_analysis:N \l_tmpa_tl % uncomment for debugging 505 | \tl_use:N \l_pc_strsub_input_tl 506 | } 507 | 508 | \NewDocumentCommand{\@pc@centercolifnec}{m}% 509 | {% 510 | #1% 511 | } 512 | 513 | 514 | 515 | \ExplSyntaxOff 516 | 517 | %%%%%%%% 518 | % line numbers 519 | %%%%%%%% 520 | % The following commands handle line numbering within the pseudocode command. The 521 | % pseudocode command itself does need to do some counter magic 522 | \newcounter{pclinenumber} 523 | \newcounter{Hpclinenumber} % make hyperref happy 524 | \newcounter{@pclinenumber} 525 | \newcounter{H@pclinenumber} % make hyperref happy 526 | \newcounter{@pclinenumbertmp} 527 | \newcounter{pcgamecounter} 528 | \newcounter{Hpcgamecounter} 529 | \newcounter{pcrlinenumber} 530 | \newcounter{Hpcrlinenumber} 531 | \newcounter{@pcrlinenumbertmp} 532 | 533 | % separators 534 | \providecommand{\pclnseparator}{:} 535 | \providecommand{\pcrlnseparator}{\hspace{1pt}} 536 | 537 | % spacing for linenumbers 538 | \providecommand{\pclnspace}{0pt} 539 | \providecommand{\pclnrspace}{5pt} 540 | 541 | \renewcommand{\the@pclinenumber}{\thepclinenumber} 542 | \providecommand{\@pcln}{% 543 | \refstepcounter{@pclinenumber}% 544 | \stepcounter{H@pclinenumber}% 545 | } 546 | 547 | % left align line numbers 548 | \providecommand{\pcln}[1][]{% 549 | \refstepcounter{pclinenumber}% 550 | \stepcounter{Hpclinenumber}% 551 | \ifthenelse{\equal{#1}{}}{}{% 552 | %keep hyperref happy 553 | \ifmeasuring@\else\pc@original@label{#1}\fi% 554 | }% 555 | \ifthenelse{\value{pclinenumber}<10}{\hspace{1ex}}{}% 556 | \hspace{\pclnspace}\text{\scriptsize\arabic{pclinenumber}}\pclnseparator\quad}% 557 | 558 | % allow to skip numbering single lines if linenumbering=on 559 | \providecommand{\pcnoln}{% 560 | } 561 | 562 | % right align line numbers (same counter) 563 | \providecommand{\pclnr}{% 564 | \refstepcounter{pclinenumber}% 565 | \quad\text{\scriptsize\pcrlnseparator\arabic{pclinenumber}}\hspace{5pt}} 566 | 567 | % right align line numbers different counter 568 | \providecommand{\pcrln}{ 569 | \refstepcounter{pcrlinenumber}% 570 | \stepcounter{Hpcrlinenumber}% 571 | \text{\scriptsize\pcrlnseparator\arabic{pcrlinenumber}}\hspace{\pclnrspace}} 572 | 573 | 574 | %%% 575 | % indentation 576 | \newlength{\@pcindentwidth} 577 | \providecommand{\pcind}[1][1]{% 578 | \setlength{\@pcindentwidth}{\widthof{\ensuremath{\quad}}*#1}% 579 | \ensuremath{\mathmakebox[\@pcindentwidth]{}}} 580 | 581 | 582 | % create length 583 | \newlength{\@pc@minipage@length} 584 | \newlength{\@pc@alt@minipage@length} 585 | 586 | % backward games 587 | \newcommand{\@withingame}{false} 588 | \newcommand{\@withinbxgame}{false} 589 | \newcommand{\@bxgameheader}{} 590 | \newcommand{\@withingamedescription}{false} 591 | 592 | 593 | %%%%%%%%%%%% 594 | % The pseudocode Command 595 | %%%%% 596 | \newlength{\@pc@length@tmp@width@vstack} 597 | 598 | 599 | \newcommand{\@pc@beginnewline}{% 600 | \@pseudocodecodeatbeginline\@pseudocodelinenumber\@pc@and\@pcln% 601 | %checkspace 602 | \ifthenelse{\equal{\@pseudocodespace}{auto}}% 603 | {\expandafter\pcind\expandafter[\value{@pc@indentationlevel}]}% 604 | {}% 605 | %reset column counter 606 | \setcounter{pccolumncounter}{2}% 607 | %beginmode 608 | \@pc@modebegin} 609 | \newcommand{\@pc@and}{&} 610 | \newcommand{\@pc@and@wrap@end}{\@pc@modeend&\@pseudocodecodeatendline} 611 | \newcommand{\@pc@and@wrap@start}{\@pc@beginnewline} 612 | \newcommand{\pctabname}{>} 613 | \newcommand{\pcdbltabname}{<} 614 | \newcommand{\pcindentname}{t} 615 | 616 | 617 | 618 | \newcommand*\@pseudocodehead{} 619 | \newcommand*\@pseudocodewidth{} 620 | \newcommand*\@pseudocodexshift{0pt} 621 | \newcommand*\@pseudocodeyshift{0pt} 622 | \newcommand*\@pseudocodelinenumber{} 623 | \newcommand*\@pseudocodebeforeskip{0ex} 624 | \newcommand*\@pseudocodeafterskip{0ex} 625 | \newcommand*\@pseudocodelnstart{0} 626 | \newcommand*\@pseudocodelnstartright{0} 627 | \newcommand*\@pseudocodesyntaxhighlighting{} 628 | \newcommand*\@pseudocodenodraft{false} 629 | \newcommand*\@pseudocodecolspace{} % empty per default, use length, 630 | 631 | \newcommand*\@pseudocodeheadlinesep{0em} 632 | \newcommand*\@pseudocodebodylinesep{-0.5\baselineskip} 633 | 634 | \newcommand*\@pseudocodecolsep{0em} 635 | \newcommand*\@pseudocodeaddtolength{2pt} 636 | 637 | \newcommand*\@pseudocodecodeatbeginline{} 638 | \newcommand*\@pseudocodecodeatendline{} 639 | \newcommand*\@pseudocodecodejot{0em} 640 | \newcommand*\@pseudocodecodesize{\small} 641 | \newcommand*\@pseudocodesubcodesize{\footnotesize} 642 | 643 | \newcommand*\@pseudocodeminipagealign{t} 644 | 645 | %%%%%%%%%%%%%% 646 | % Define keywords for the automatic syntax highlighting 647 | % the accompanying add provides additional keywords. 648 | % The space version for automatic spacing 649 | \newcommand*\@pseudocodekeywordsindent{for ,foreach ,if ,repeat ,while } 650 | \newcommand*\@pseudocodekeywordsunindent{endfor,endforeach,fi,endif,until ,endwhile} 651 | \newcommand*\@pseudocodekeywordsuninindent{else if,elseif, else} 652 | \newcommand*\@pseudocodekeywords{return ,{ do }, in ,new ,null ,null,true ,true,{ to },false ,false,{ then },done ,done} 653 | \newcommand*\@pseudocodeaddkeywords{} 654 | \newcommand*\@pseudocodealtkeywords{} 655 | \begin{@withspaces} 656 | \global\def\@pseudocodekeywordsspace{for,endfor,foreach,endforeach,return,do,in,new,if,null,true,until,to,false,then,repeat,else if,elseif,while,endwhile,else,done,fi,endif} 657 | \end{@withspaces} 658 | 659 | 660 | \define@key{pseudocode}{beginline}[]{\renewcommand*\@pseudocodecodeatbeginline{#1}} 661 | \define@key{pseudocode}{endline}[]{\renewcommand*\@pseudocodecodeatendline{#1}} 662 | \define@key{pseudocode}{jot}[0em]{\renewcommand*\@pseudocodecodejot{#1}} 663 | \define@key{pseudocode}{codesize}[\small]{\renewcommand*\@pseudocodecodesize{#1}} 664 | \define@key{pseudocode}{subcodesize}[\small]{\renewcommand*\@pseudocodesubcodesize{#1}} 665 | \define@key{pseudocode}{head}[]{\renewcommand*\@pseudocodehead{#1}} 666 | \define@key{pseudocode}{width}[]{\renewcommand*\@pseudocodewidth{#1}} 667 | \define@key{pseudocode}{valign}[t]{\renewcommand*\@pseudocodeminipagealign{#1}} 668 | \define@key{pseudocode}{xshift}[]{\renewcommand*\@pseudocodexshift{#1}} 669 | \define@key{pseudocode}{yshift}[]{\renewcommand*\@pseudocodeyshift{#1}} 670 | \define@key{pseudocode}{colspace}[]{\renewcommand*\@pseudocodecolspace{#1}} 671 | \define@key{pseudocode}{linenumbering}[on]{\ifthenelse{\equal{#1}{on}}{\renewcommand*\@pseudocodelinenumber{\pcln}}{\renewcommand*\@pseudocodelinenumber{}}} 672 | \define@key{pseudocode}{beforeskip}[]{\renewcommand*\@pseudocodebeforeskip{#1}} 673 | \define@key{pseudocode}{afterskip}[]{\renewcommand*\@pseudocodeafterskip{#1}} 674 | \define@key{pseudocode}{lnstart}[0]{\renewcommand*\@pseudocodelnstart{#1}} 675 | \define@key{pseudocode}{lnstartright}[0]{\renewcommand*\@pseudocodelnstartright{#1}} 676 | \define@key{pseudocode}{colsep}[0em]{\renewcommand*\@pseudocodecolsep{#1}} 677 | \define@key{pseudocode}{headlinesep}[0em]{\renewcommand*\@pseudocodeheadlinesep{#1}} 678 | \define@key{pseudocode}{bodylinesep}[0em]{\renewcommand*\@pseudocodebodylinesep{#1}} 679 | \define@key{pseudocode}{addtolength}[2pt]{\renewcommand*\@pseudocodeaddtolength{#1}} 680 | \define@key{pseudocode}{mode}[math]{% 681 | \ifthenelse{\equal{#1}{text}}{% 682 | \renewcommand*\@pc@modebegin{\begin{varwidth}{\textwidth}% 683 | %introduce line magic for text mode 684 | \let\@pc@lb\\% 685 | \renewcommandx*{\\}[2][1=,2=]{\@pc@modeend\@pc@and \@pseudocodecodeatendline\ifthenelse{\equal{####1}{}}{\@pc@lb}{\@pc@lb[####1]}####2 \@pc@beginnewline}% 686 | \def\pclb{\let\\\@pc@lb\relax\@pc@modeend\\}% 687 | \def\pcolb{\let\\\@pc@lb\relax\@pc@modeend\\}% 688 | }% 689 | \renewcommand*\@pc@modeend{\end{varwidth}} 690 | }{}% 691 | } 692 | \define@key{pseudocode}{nodraft}[true]{\renewcommand*\@pseudocodenodraft{#1}} 693 | \define@key{pseudocode}{keywords}[]{\renewcommand*\@pseudocodekeywords{#1}} 694 | \define@key{pseudocode}{keywordsindent}[]{\renewcommand*\@pseudocodekeywordsindent{#1}} 695 | \define@key{pseudocode}{keywordsunindent}[]{\renewcommand*\@pseudocodekeywordsunindent{#1}} 696 | \define@key{pseudocode}{keywordsuninindent}[]{\renewcommand*\@pseudocodekeywordsuninindent{#1}} 697 | \define@key{pseudocode}{addkeywords}[]{\renewcommand*\@pseudocodeaddkeywords{#1}} 698 | \define@key{pseudocode}{altkeywords}[]{\renewcommand*\@pseudocodealtkeywords{#1}} 699 | \define@key{pseudocode}{syntaxhighlight}[]{\renewcommand*\@pseudocodesyntaxhighlighting{#1}} 700 | 701 | \newcommand{\@pc@modebegin}{} 702 | \newcommand{\@pc@modeend}{} 703 | \newcommand{\@pc@thecontent}{} 704 | 705 | \newcommand{\@pc@syntaxhighlight}[1]{% 706 | \ifthenelse{\equal{\@pseudocodesyntaxhighlighting}{auto}}{% 707 | \def\@shtmp{#1}% first step 708 | \ifthenelse{\equal{\@pseudocodespace}{keep}} 709 | {\edef\@tmpkeywords{\@pseudocodekeywordsspace,\@pseudocodeaddkeywords}} 710 | {\ifthenelse{\equal{\@pseudocodespace}{auto}} 711 | {\edef\@tmpkeywords{\@pseudocodekeywords,\@pseudocodeaddkeywords}} 712 | {\edef\@tmpkeywords{\@pseudocodekeywords,\@pseudocodekeywordsindent,\@pseudocodekeywordsunindent,\@pseudocodekeywordsuninindent,\@pseudocodeaddkeywords}}} 713 | \foreach \@pckw in \@tmpkeywords{% 714 | \ifthenelse{\equal{\@pckw}{}}{}{% 715 | % we are doing a simple strsub and storing the result (globally) in @shtmp 716 | \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 717 | \gdef\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 718 | \@shtmp\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 719 | {\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 720 | \@pc@stringsubstitution\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 721 | {\expandafter\expandafter\expandafter\@shtmp\expandafter\expandafter\expandafter 722 | }\expandafter\expandafter\expandafter{\expandafter\@pckw\expandafter}\expandafter{\expandafter\@pc@highlight\expandafter{\@pckw}}}% 723 | }% alt keywords 724 | }% 725 | \foreach \@pckw in \@pseudocodealtkeywords{% 726 | \ifthenelse{\equal{\@pckw}{}}{}{% 727 | % we are doing a simple strsub and storing the result (globally) in @shtmp 728 | \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 729 | \gdef\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 730 | \@shtmp\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 731 | {\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 732 | \@pc@stringsubstitution\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 733 | {\expandafter\expandafter\expandafter\@shtmp\expandafter\expandafter\expandafter 734 | }\expandafter\expandafter\expandafter{\expandafter\@pckw\expandafter}\expandafter{\expandafter\@pc@althighlight\expandafter{\@pckw}}}% 735 | }% 736 | }% 737 | %%%% 738 | % if automatic spacing 739 | \ifthenelse{\equal{\@pseudocodespace}{auto}} 740 | {% 741 | \foreach \@pckw in \@pseudocodekeywordsindent{% indentation keywords 742 | \ifthenelse{\equal{\@pckw}{}}{}{% 743 | % we are doing a simple strsub and storing the result (globally) in @shtmp 744 | \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 745 | \gdef\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 746 | \@shtmp\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 747 | {\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 748 | \@pc@stringsubstitution\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 749 | {\expandafter\expandafter\expandafter\@shtmp\expandafter\expandafter\expandafter 750 | }\expandafter\expandafter\expandafter{\expandafter\@pckw\expandafter}\expandafter{\expandafter\@pc@highlightindent\expandafter{\@pckw}}}% 751 | }}% 752 | \foreach \@pckw in \@pseudocodekeywordsunindent{% unindentation keywords 753 | \ifthenelse{\equal{\@pckw}{}}{}{% 754 | % we are doing a simple strsub and storing the result (globally) in @shtmp 755 | \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 756 | \gdef\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 757 | \@shtmp\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 758 | {\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 759 | \@pc@stringsubstitution\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 760 | {\expandafter\expandafter\expandafter\@shtmp\expandafter\expandafter\expandafter 761 | }\expandafter\expandafter\expandafter{\expandafter\@pckw\expandafter}\expandafter{\expandafter\@pc@highlightunindent\expandafter{\@pckw}}}% 762 | }}% 763 | \foreach \@pckw in \@pseudocodekeywordsuninindent{% uninindentation keywords 764 | \ifthenelse{\equal{\@pckw}{}}{}{% 765 | % we are doing a simple strsub and storing the result (globally) in @shtmp 766 | \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 767 | \gdef\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 768 | \@shtmp\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 769 | {\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 770 | \@pc@stringsubstitution\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 771 | {\expandafter\expandafter\expandafter\@shtmp\expandafter\expandafter\expandafter 772 | }\expandafter\expandafter\expandafter{\expandafter\@pckw\expandafter}\expandafter{\expandafter\@pc@highlightuninindent\expandafter{\@pckw}}}% 773 | }}% 774 | }{}% 775 | % return result 776 | \@shtmp% 777 | }{#1}% nothing to highlight 778 | } 779 | 780 | \newcommand{\@pc@highlight}[1]{% 781 | \ifthenelse{\equal{\@pseudocodespace}{keep}} 782 | {\highlightkeyword[]{#1}}% 783 | {\highlightkeyword[]{\@pc@spacesubstitution{#1}{ }{~}}}% 784 | } 785 | 786 | \newcommand{\@pc@highlightindent}[1]{% 787 | \@pc@increaseindent\@pc@highlight{#1}% 788 | } 789 | 790 | \newcommand{\@pc@highlightunindent}[1]{% 791 | \@pc@decreaseindent\@pc@highlight{#1}% 792 | } 793 | 794 | \newcommand{\@pc@highlightuninindent}[1]{% 795 | \@pc@tmpdecreaseindent\@pc@highlight{#1}% 796 | } 797 | 798 | \newcommand{\@pc@althighlight}[1]{% 799 | \ifthenelse{\equal{\@pseudocodespace}{keep}} 800 | {\highlightaltkeyword{#1}}% 801 | {\highlightaltkeyword{\@pc@spacesubstitution{#1}{ }{~}}}% 802 | } 803 | 804 | \newcommand{\@pc@colspace}{} 805 | 806 | %%%%%%%%%%%%%%%%% 807 | % Allow for spacing 808 | \newcommand{\@withinspaces}{false}% 809 | \newcommand{\@keepspaces}{% 810 | \renewcommand{\@withinspaces}{true}\@withspaces% 811 | } 812 | \newcommand{\@pc@endgroupafterpc}{} 813 | 814 | \newcommand*\@pseudocodespace{} 815 | \define@key{pcspace}{space}[]{\ifthenelse{\equal{#1}{keep}}{\@keepspaces}{}\renewcommand*\@pseudocodespace{#1}} 816 | 817 | %%% automatic indentation 818 | \newcounter{@pc@indentationlevel} 819 | \newcommand{\@pc@increaseindent}{\addtocounter{@pc@indentationlevel}{1}} 820 | \newcommand{\@pc@decreaseindent}{\ifthenelse{\equal{\@pseudocodespace}{auto}}{\pcind[-1]}{}\addtocounter{@pc@indentationlevel}{-1}} 821 | \newcommand{\@pc@tmpdecreaseindent}{\ifthenelse{\equal{\@pseudocodespace}{auto}}{\pcind[-1]}{}} 822 | 823 | \newcounter{pccolumncounter} 824 | \setcounter{pccolumncounter}{2} 825 | 826 | % store original halign 827 | \let\@pc@halign\halign% 828 | 829 | %% Check if the pseudocode command is called with an optional argument 830 | \providecommand{\pseudocode}{% 831 | \begingroup% 832 | \renewcommand{\@withinspaces}{false}% 833 | \@ifnextchar[%] 834 | {\@pseudocodeA}% 835 | {\@pseudocode[]}% 836 | } 837 | 838 | \def\@pseudocodeA[#1]{% 839 | \setkeys*{pcspace}{#1}%test if there is a space assignment within the keys .. make the necessary arrangements and call the actual method 840 | \@pseudocode[#1]% 841 | } 842 | 843 | \def\@pseudocode[#1]#2{% 844 | \begingroup% 845 | \setkeys{pseudocode}[space]{#1}%ignore the space key. 846 | % check draft mode and disable syntax highlighting 847 | \@pc@ifdraft{\ifthenelse{\equal{\@pseudocodenodraft}{true}}{}{\renewcommand\@pseudocodesyntaxhighlighting{}}}{}% 848 | % 849 | % 850 | \addtocounter{@pc@global@pc@nestcnt}{1}% 851 | % allow for tikz usage 852 | \@pc@ensureremember% 853 | % 854 | % create tabbing command 855 | \ifcsname \pctabname\endcsname% 856 | \expandafter\renewcommand\csname \pctabname\endcsname{\@pc@modeend&\@pc@colspace\@pc@modebegin}% 857 | \else% 858 | \expandafter\newcommand\csname \pctabname\endcsname{\@pc@modeend&\@pc@colspace\@pc@modebegin}% 859 | \fi% 860 | \ifcsname \pcdbltabname\endcsname% 861 | \expandafter\renewcommand\csname \pcdbltabname\endcsname{\@pc@modeend&&\@pc@colspace\@pc@modebegin}% 862 | \else% 863 | \expandafter\newcommand\csname \pcdbltabname\endcsname{\@pc@modeend&&\@pc@colspace\@pc@modebegin}% 864 | \fi% 865 | % create colspace command if necessary (must be empty for multicolumns 866 | \ifthenelse{\equal{\@pseudocodecolspace}{}} 867 | {} 868 | {\renewcommand{\@pc@colspace}{\hspace{\@pseudocodecolspace}}}% 869 | % 870 | %adjust row width 871 | \addtolength{\jot}{\@pseudocodecodejot}% 872 | % create indent command 873 | \expandafter\let\csname \pcindentname\endcsname\pcind% 874 | % 875 | %store and wrap (do syntax highlighting) argument 876 | \renewcommand{\@pc@thecontent}{\@pc@and@wrap@start\@pc@syntaxhighlight{#2}\@pc@and@wrap@end}% 877 | % 878 | %take care of counters 879 | \stepcounter{@pc@global@pc@cnt}% 880 | \setcounter{pclinenumber}{\@pseudocodelnstart}% 881 | \setcounter{pcrlinenumber}{\@pseudocodelnstartright}% 882 | \setlength{\@pc@minipage@length}{0pt}% 883 | \setlength{\@pc@alt@minipage@length}{0pt}% 884 | \setcounter{@pclinenumbertmp}{\value{pclinenumber}}% 885 | \setcounter{@pcrlinenumbertmp}{\value{pcrlinenumber}}% 886 | %reset column counter 887 | \setcounter{pccolumncounter}{2}% 888 | % 889 | % vertical space 890 | \vspace{\@pseudocodeyshift}% 891 | %\setlength{\abovedisplayskip}{0pt}% 892 | %\setlength{\belowdisplayskip}{0pt}% 893 | %\setlength{\abovedisplayshortskip}{0pt}% 894 | %\setlength{\belowdisplayshortskip}{0pt}% 895 | % 896 | % 897 | % line magic 898 | \ifthenelse{\value{@pc@global@pc@nestcnt}=1}{% 899 | \let\@pc@halign\halign% 900 | \newenvironment{pcmbox}{\let\halign\@pc@halign}{}% 901 | \def\halign{% 902 | \renewcommand{\label}[1]{\ifmeasuring@\else\pc@original@label{####1}\fi}% 903 | \let\@pc@lb\\% 904 | \renewcommandx*{\\}[2][1=,2=]{\@pc@modeend\@pc@and\@pseudocodecodeatendline \ifthenelse{\equal{####1}{}}{\@pc@lb}{\@pc@lb[####1]}####2 \@pc@beginnewline}% 905 | \def\pclb{\let\\\@pc@lb\relax\@pc@modeend\\}% 906 | \@pc@halign}% 907 | }{}% 908 | % 909 | %align column separation 910 | \renewcommand*{\minalignsep}{\@pseudocodecolsep}% 911 | % 912 | % if no width is set compute width and store in circuitlength 913 | \ifthenelse{\equal{\@pseudocodewidth}{}}{% 914 | % compute length of pseudocode 915 | \ifthenelse{\value{@pcsubprogstep}=0}{% 916 | \@settowidthofalign{\@pc@minipage@length}{\@pc@thecontent}% 917 | }{% 918 | \@settowidthofaligned{\@pc@minipage@length}{\@pc@thecontent}% 919 | }% 920 | %compute length of header 921 | \addtolength{\@pc@alt@minipage@length}{\widthof{\@pseudocodehead}}% 922 | % use header length if longer and add some points for good measure 923 | \ifdim\@pc@alt@minipage@length>\@pc@minipage@length% 924 | \setlength{\@pc@minipage@length}{\@pc@alt@minipage@length}% 925 | \fi% 926 | \addtolength{\@pc@minipage@length}{\@pseudocodeaddtolength}% 927 | }{\addtolength{\@pc@minipage@length}{\@pseudocodewidth}}% 928 | % reset counter 929 | \setcounter{pclinenumber}{\value{@pclinenumbertmp}}% 930 | \setcounter{pcrlinenumber}{\value{@pcrlinenumbertmp}}% 931 | \setcounter{@pc@indentationlevel}{0}% 932 | % begin actual output 933 | % 934 | % 935 | %do the actual mini page 936 | \hspace{\@pseudocodexshift}% 937 | \begin{minipage}[\@pseudocodeminipagealign]{\@pc@minipage@length}% 938 | \ifthenelse{\value{@pcsubprogstep}=0}{% 939 | \pc@display@pseudocode{\@pseudocodehead}{\@pc@thecontent}% 940 | }{% if sub procedure 941 | \pc@display@subcode{\@pseudocodehead}{\@pc@thecontent}% 942 | }% 943 | \end{minipage}% 944 | \hspace{\afterpcskip}% 945 | % tikz usage 946 | \@pc@releaseremember% 947 | \addtocounter{@pc@global@pc@nestcnt}{-1}% 948 | \endgroup% 949 | % close spacing and potentially a single group generated by the space tester 950 | \ifthenelse{\equal{\@withinspaces}{true}}{\end@withspaces}{}% 951 | \endgroup% 952 | } 953 | 954 | \newcommand{\@pc@gameheader}[2]{% 955 | \tikz{\gdef\i{\thepcgamecounter}% 956 | \node[anchor=base,#2,inner sep=0.05em,outer sep=0] (gamenode\i) {#1\vphantom{$\sum^A_{A_b}$}}; 957 | \ifthenelse{\equal{\@withinbxgame}{true}} 958 | {\node[draw,anchor=base, above=0.1cm of gamenode\i] (bgamenode\i) {\@bxgameheader\vphantom{$\sum^A_{A_b}$}};} 959 | {}% 960 | }% 961 | } 962 | 963 | \let\pclb\relax 964 | % 965 | \newcommand{\pc@display@pseudocode}[2]{% 966 | \ifthenelse{\equal{#1}{}}{\vspace{-1\baselineskip}\@pseudocodecodesize}{% 967 | \ifthenelse{\equal{\@withingame}{true}}{% 968 | \@pc@gameheader{#1}{}\ifthenelse{\equal{\@pc@secondheader}{true}}{\addtocounter{pcgamecounter}{1}\@pc@gameheader{#1}{draw}}{}% 969 | \vspace{0.2em}% 970 | }{#1\vphantom{$\sum^A_{A_b}$}}% 971 | \vspace{\@pseudocodeheadlinesep}\hrule\vspace{\@pseudocodebodylinesep}\@pseudocodecodesize}% 972 | \begin{flalign*}#2\end{flalign*}% 973 | } 974 | 975 | 976 | \newcommand{\pc@display@subcode}[2]{% 977 | \begingroup% 978 | \ifthenelse{\equal{#1}{}}{}{#1\vphantom{$\sum^A_{A_b}$} % 979 | \vspace{\@pseudocodeheadlinesep}\hrule \vspace{\baselineskip}\vspace{\@pseudocodebodylinesep}}% 980 | \@pseudocodesubcodesize% 981 | $\begin{aligned}#2\end{aligned}$% 982 | \endgroup% 983 | } 984 | 985 | 986 | \newcommand{\@pc@gettikzwidth}[2]{ % #1 = width, #2 = height 987 | \pgfextractx{\@tempdima}{\pgfpointdiff{\pgfpointanchor{current bounding box}{south west}} 988 | {\pgfpointanchor{current bounding box}{north east}}} 989 | \global#1=\@tempdima 990 | \pgfextracty{\@tempdima}{\pgfpointdiff{\pgfpointanchor{current bounding box}{south west}} 991 | {\pgfpointanchor{current bounding box}{north east}}} 992 | \global#2=\@tempdima 993 | } 994 | 995 | 996 | %%%%%%%%%%%%%%%%%%% 997 | % remember pictues 998 | \newcounter{@pc@remember} 999 | 1000 | \newcommand{\@pc@ensureremember}{% 1001 | \ifthenelse{\value{@pc@remember}=0}{\tikzstyle{every picture}+=[remember picture]}{}% 1002 | \addtocounter{@pc@remember}{1}} 1003 | 1004 | \newcommand{\@pc@releaseremember}{% 1005 | \addtocounter{@pc@remember}{-1}% 1006 | \ifthenelse{\value{@pc@remember}=0}{\tikzstyle{every picture}-=[remember picture]}{}% 1007 | } 1008 | 1009 | 1010 | %%%%%%%%%%%%%%%%%%% 1011 | % pcimage 1012 | \newenvironment{pcimage}{% 1013 | \begingroup\@pc@ensureremember% 1014 | }{% 1015 | \@pc@releaseremember\endgroup% 1016 | } 1017 | 1018 | \newcommand*\@pcnodecontent{} 1019 | \newcommand*\@pcnodestyle{} 1020 | \newcommand*\@pcnodedraw{} 1021 | \define@key{pcnode}{content}[]{\renewcommand*\@pcnodecontent{#1}} 1022 | \define@key{pcnode}{style}[]{\renewcommand*\@pcnodestyle{#1}} 1023 | \define@key{pcnode}{draw}[]{\renewcommand*\@pcnodedraw{#1}} 1024 | 1025 | \newcommandx*{\pcnode}[2][2=]{% 1026 | \begingroup\setkeys{pcnode}{#2}% 1027 | \tikzset{PCNODE-STYLE/.style/.expand once=\@pcnodestyle}% 1028 | \begin{tikzpicture}[inner sep=0ex,baseline=0pt]% 1029 | \node[PCNODE-STYLE] (#1) {\@pcnodecontent}; % 1030 | \end{tikzpicture}% 1031 | \ifdefempty{\@pcnodedraw}{}{% 1032 | \begin{tikzpicture}[overlay,inner sep=0ex,baseline=0pt]\@pcnodedraw\end{tikzpicture} 1033 | }% 1034 | \endgroup} 1035 | 1036 | \newcommandx*{\pcdraw}[2][2=]{% 1037 | \begin{tikzpicture}[overlay,inner sep=0ex,baseline=0pt,#2] 1038 | #1 1039 | \end{tikzpicture}} 1040 | 1041 | 1042 | %%%%%%%%%%%%%%%%%%%%%%%%% 1043 | % Reductions 1044 | \newcommand{\@bb@lastbox}{} 1045 | \newcommand{\@bb@lastoracle}{} 1046 | \newcommand{\@bb@lastchallenger}{} 1047 | 1048 | 1049 | \newlength{\@bb@message@hoffset} 1050 | \newlength{\@bb@query@hoffset} 1051 | \newlength{\@bb@oraclequery@hoffset} 1052 | \newlength{\@bb@challengerquery@hoffset} 1053 | 1054 | \newcounter{@bb@oracle@cnt} 1055 | \newcounter{@bb@oracle@nestcnt} 1056 | \newcounter{@bb@challenger@cnt} 1057 | \newcounter{@bb@challenger@nestcnt} 1058 | 1059 | \newcounter{@bb@env@nestcnt} 1060 | 1061 | \newcommand{\bbroraclenodenameprefix}{ora-} 1062 | \newcommand{\bbrchallengernodenameprefix}{challenger-} 1063 | \newcommand{\bbrenvnodenameprefix}{env-} 1064 | 1065 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 1066 | % Black Box Reduction Environment 1067 | \newenvironmentx{bbrenv}[3][1=0pt,3=0pt]{% 1068 | \addtocounter{@bb@env@nestcnt}{1}% 1069 | \renewcommand{\@bb@lastbox}{#2}% 1070 | % 1071 | % reset lengths 1072 | \@pc@globalsetlength{\@bb@message@hoffset}{0pt}% 1073 | \@pc@globalsetlength{\@bb@query@hoffset}{0pt}% 1074 | \@pc@globalsetlength{\@bb@oraclequery@hoffset}{0pt}% 1075 | \@pc@globalsetlength{\@bb@challengerquery@hoffset}{0pt}% 1076 | % 1077 | %reset oracle counter and oracle query offset 1078 | \ifthenelse{\value{@bb@oracle@nestcnt}=0} 1079 | {\setcounter{@bb@oracle@cnt}{0}}{}% 1080 | \ifthenelse{\value{@bb@challenger@nestcnt}=0} 1081 | {\setcounter{@bb@challenger@cnt}{0}}{}% 1082 | % 1083 | \def\@bbendskip{#3}% 1084 | \vspace{#1}% 1085 | \ifthenelse{\value{@bb@env@nestcnt}=1} 1086 | {\@pc@ensureremember% 1087 | \begin{tikzpicture} 1088 | }{\tikz\bgroup} 1089 | }{% 1090 | \ifthenelse{\value{@bb@env@nestcnt}=1} 1091 | {\end{tikzpicture}% 1092 | \@pc@releaseremember% 1093 | }{\egroup}% 1094 | \vspace{\@bbendskip}% 1095 | \addtocounter{@bb@env@nestcnt}{-1}% 1096 | % reset lengths 1097 | \@pc@globalsetlength{\@bb@message@hoffset}{0pt}% 1098 | \@pc@globalsetlength{\@bb@query@hoffset}{0pt}% 1099 | \@pc@globalsetlength{\@bb@oraclequery@hoffset}{0pt}% 1100 | \@pc@globalsetlength{\@bb@challengerquery@hoffset}{0pt}% 1101 | } 1102 | 1103 | %%%%%%%%%%%%%%%%%%%%%%%%%%%% 1104 | % black box reduction box 1105 | % option keys 1106 | \newcommand*\bbrboxname{} 1107 | \newcommand*\bbrboxnamepos{right} 1108 | \newcommand*\bbrboxnamestyle{} 1109 | \newcommand*\@bbrboxnamepos{below right=0.5ex and -0.5ex of \@bb@lastbox.north east,anchor=north east} 1110 | \newcommand*\bbrboxabovesep{\baselineskip} 1111 | \newcommand*\@bbrboxnameposoffset{below left=\bbrboxabovesep of phantomname.south west} 1112 | \newcommand*\bbrboxstyle{draw} 1113 | \newcommand*\bbrboxafterskip{} 1114 | \newcommand*\bbrboxminheight{0cm} 1115 | \newcommand*\bbrboxminwidth{2cm} 1116 | \newcommand*\bbrboxxshift{0cm} 1117 | \newcommand*\bbrboxyshift{0cm} 1118 | \define@key{bbrbox}{abovesep}[]{\renewcommand*\bbrboxabovesep{#1}} 1119 | \define@key{bbrbox}{name}[]{\renewcommand*\bbrboxname{#1}} 1120 | \define@key{bbrbox}{namestyle}[]{\renewcommand*\bbrboxnamestyle{#1}} 1121 | \define@key{bbrbox}{namepos}[]{\renewcommand*\bbrboxnamepos{#1}} 1122 | \define@key{bbrbox}{style}[draw]{\renewcommand*\bbrboxstyle{#1}} 1123 | \define@key{bbrbox}{minwidth}[]{\renewcommand*\bbrboxminwidth{#1}} 1124 | \define@key{bbrbox}{addheight}[]{\renewcommand*\bbrboxafterskip{#1}} 1125 | \define@key{bbrbox}{minheight}[]{\renewcommand*\bbrboxminheight{#1}} 1126 | \define@key{bbrbox}{xshift}[]{\renewcommand*\bbrboxxshift{#1}} 1127 | \define@key{bbrbox}{yshift}[]{\renewcommand*\bbrboxyshift{#1}} 1128 | 1129 | 1130 | \NewEnviron{bbrbox}[1][]{% 1131 | \setkeys{bbrbox}{#1}% 1132 | 1133 | \ifthenelse{\equal{\bbrboxnamepos}{center}} 1134 | {\renewcommand{\@bbrboxnamepos}{below=0.5ex of \@bb@lastbox.north,anchor=north}}{} 1135 | \ifthenelse{\equal{\bbrboxnamepos}{left}} 1136 | {\renewcommand{\@bbrboxnamepos}{below=0.5ex of \@bb@lastbox.north west,anchor=north west}}{} 1137 | \ifthenelse{\equal{\bbrboxnamepos}{top right}} 1138 | {\renewcommand{\@bbrboxnamepos}{above=0cm of \@bb@lastbox.north east,anchor=south east}\renewcommand{\@bbrboxnameposoffset}{below left=0cm of phantomname.north west}}{} 1139 | \ifthenelse{\equal{\bbrboxnamepos}{top center}} 1140 | {\renewcommand{\@bbrboxnamepos}{above=0cm of \@bb@lastbox.north,anchor=south}\renewcommand{\@bbrboxnameposoffset}{below left=0cm of phantomname.north west}}{} 1141 | \ifthenelse{\equal{\bbrboxnamepos}{top left}} 1142 | {\renewcommand{\@bbrboxnamepos}{above=0cm of \@bb@lastbox.north west,anchor=south west}\renewcommand{\@bbrboxnameposoffset}{below left=0cm of phantomname.north west}}{} 1143 | \ifthenelse{\equal{\bbrboxnamepos}{middle}} 1144 | {\renewcommand{\@bbrboxnamepos}{above=0.5ex of \@bb@lastbox.base,anchor=south}}{} 1145 | \ifthenelse{\equal{\bbrboxnamepos}{bottom}} 1146 | {\renewcommand{\@bbrboxnamepos}{above=0.5ex of \@bb@lastbox.base,anchor=north}}{} 1147 | 1148 | 1149 | \tikzset{BBRBOXSTYLE/.style/.expand once=\bbrboxstyle}% 1150 | \tikzset{BBRBOXNAMEPOS/.style/.expand once=\@bbrboxnamepos}% 1151 | \tikzset{BBRBOXNAMESTYLE/.style/.expand once=\bbrboxnamestyle}% 1152 | \tikzset{BBRBOXNAMEPOSOFFSET/.style/.expand once=\@bbrboxnameposoffset}% 1153 | 1154 | \node[inner sep=0pt,outer sep=0pt] (\@bb@lastbox-tmpouter) {}; 1155 | \node[inner sep=.3333em,anchor=north,BBRBOXSTYLE,minimum height=\bbrboxminheight,below right=\bbrboxyshift and \bbrboxxshift of \@bb@lastbox-tmpouter] (\@bb@lastbox) \bgroup 1156 | \tikz{ 1157 | \node[inner sep=0pt,outer sep=0pt,minimum height=0cm] (phantomname) {}; %minimum width 1158 | \node[BBRBOXNAMEPOSOFFSET,minimum height=0cm] (\@bb@lastbox-inner) {\begin{varwidth}{2\linewidth}\BODY\end{varwidth}}; 1159 | \ifthenelse{\equal{\bbrboxafterskip}{}}{}{ 1160 | \node[below=0cm of \@bb@lastbox-inner,minimum height=\bbrboxafterskip] {}; 1161 | } 1162 | \node[inner sep=0pt,outer sep=0pt,at=(\@bb@lastbox-inner.south west),minimum height=0cm] () {\phantom{\hspace{\bbrboxminwidth}}}; %minimum width 1163 | } 1164 | \egroup; 1165 | \ifthenelse{\equal{\bbrboxnamepos}{none}} 1166 | {}{\node[BBRBOXNAMEPOS,BBRBOXNAMESTYLE, inner sep=0.2ex, outer sep=0pt, overlay] () {\bbrboxname};} 1167 | } 1168 | 1169 | 1170 | \newcommand*\bbroraclevdistance{\baselineskip} 1171 | \newcommand*\bbroraclehdistance{1.5cm} 1172 | \define@key{bbroracle}{distance}[]{\renewcommand*\bbroraclehdistance{#1}} 1173 | \define@key{bbroracle}{hdistance}[]{\renewcommand*\bbroraclehdistance{#1}} 1174 | \define@key{bbroracle}{vdistance}[]{\renewcommand*\bbroraclevdistance{#1}} 1175 | 1176 | 1177 | % ORACLES 1178 | \newenvironmentx{bbroracle}[2][2=]{% 1179 | \begingroup 1180 | \setkeys{bbroracle}{#2} 1181 | %add to nesting cout 1182 | \addtocounter{@bb@oracle@nestcnt}{1} 1183 | %if first oracle, then put it to the right, else stack them vertically 1184 | \addtocounter{@bb@oracle@cnt}{1} 1185 | \ifthenelse{\value{@bb@oracle@cnt}=1}{ 1186 | \setlength{\@bb@tmplength@b}{\bbroraclevdistance-\baselineskip} 1187 | \node[inner sep=0pt,below right=\@bb@tmplength@b and \bbroraclehdistance of \@bb@lastbox.north east,anchor=north west] (\bbroraclenodenameprefix#1) \bgroup 1188 | }{ 1189 | % compute distance of top of last box to bottom of last oracle 1190 | \coordinate (@bbtmpcoord) at (\@bb@lastbox.north east); 1191 | \path (@bbtmpcoord); 1192 | \pgfgetlastxy{\XCoord}{\YCoordA} 1193 | \coordinate (@bbtmpcoord) at (\bbroraclenodenameprefix \@bb@lastoracle.south west); 1194 | \path (@bbtmpcoord); 1195 | \pgfgetlastxy{\XCoord}{\YCoordB} 1196 | \setlength{\@bb@tmplength@b}{\YCoordA-\YCoordB+\bbroraclevdistance} 1197 | \node[inner sep=0pt,below right=\@bb@tmplength@b and \bbroraclehdistance of \@bb@lastbox.north east,anchor=north west] (\bbroraclenodenameprefix#1) \bgroup 1198 | } 1199 | \global\def\@bb@lastoracle{#1} 1200 | \begin{bbrenv}{#1} 1201 | }{ 1202 | \end{bbrenv} 1203 | \egroup; 1204 | 1205 | \addtocounter{@bb@oracle@nestcnt}{-1} 1206 | \endgroup 1207 | } 1208 | 1209 | 1210 | \newcommand*\bbrchallengerhdistance{1.5cm} 1211 | \newcommand*\bbrchallengervdistance{\baselineskip} 1212 | \define@key{bbrchallenger}{distance}[]{\renewcommand*\bbrchallengerhdistance{#1}} 1213 | \define@key{bbrchallenger}{hdistance}[]{\renewcommand*\bbrchallengerhdistance{#1}} 1214 | \define@key{bbrchallenger}{vdistance}[]{\renewcommand*\bbrchallengervdistance{#1}} 1215 | 1216 | 1217 | % Challenger 1218 | \newenvironmentx{bbrchallenger}[2][2=]{% 1219 | \begingroup% 1220 | \setkeys{bbrchallenger}{#2}% 1221 | %add to nesting cout 1222 | \addtocounter{@bb@challenger@nestcnt}{1}% 1223 | %if first oracle, then put it to the right, else stack them vertically 1224 | \addtocounter{@bb@challenger@cnt}{1}% 1225 | \ifthenelse{\value{@bb@challenger@cnt}=1}{% 1226 | \setlength{\@bb@tmplength@b}{\bbrchallengervdistance-\baselineskip}% 1227 | \node[inner sep=0pt,below left=\@bb@tmplength@b and \bbrchallengerhdistance of \@bb@lastbox.north west,anchor=north east] (\bbrchallengernodenameprefix#1) \bgroup% 1228 | }{% 1229 | \coordinate (@bbtmpcoord) at (\@bb@lastbox.north west);% 1230 | \path (@bbtmpcoord);% 1231 | \pgfgetlastxy{\XCoord}{\YCoordA}% 1232 | \coordinate (@bbtmpcoord) at (\bbrchallengernodenameprefix \@bb@lastchallenger.south east);% 1233 | \path (@bbtmpcoord);% 1234 | \pgfgetlastxy{\XCoord}{\YCoordB}% 1235 | \setlength{\@bb@tmplength@b}{\YCoordA-\YCoordB+\bbrchallengervdistance}% 1236 | \node[inner sep=0pt,below left=\@bb@tmplength@b and \bbrchallengerhdistance of \@bb@lastbox.north west,anchor=north east] (\bbrchallengernodenameprefix#1) \bgroup% 1237 | }% 1238 | \global\def\@bb@lastchallenger{#1} 1239 | \begin{bbrenv}{#1}% 1240 | }{ 1241 | \end{bbrenv}% 1242 | \egroup;% 1243 | \addtocounter{@bb@challenger@nestcnt}{-1}% 1244 | \endgroup% 1245 | \let\msgfrom\bbrchallengerqueryto% 1246 | } 1247 | 1248 | 1249 | \newcommand*\bbrinputlength{0.5cm} 1250 | \newcommand*\bbrinputhoffset{0.5cm} 1251 | \newcommand*\bbrinputbottom{} 1252 | \newcommand*\bbrinputtop{} 1253 | \newcommand*\bbrinputedgestyle{} 1254 | \newcommand*\bbrinputtopstyle{} 1255 | \newcommand*\bbrinputbottomstyle{} 1256 | \newcommand*\bbrinputnodestyle{} 1257 | \newcommand*\bbrinputnodename{} 1258 | \define@key{bbrinput}{length}[]{\renewcommand*\bbrinputlength{#1}} 1259 | \define@key{bbrinput}{hoffset}[]{\renewcommand*\bbrinputhoffset{#1}} 1260 | \define@key{bbrinput}{name}[]{\renewcommand*\bbrinputnodename{#1}} 1261 | \define@key{bbrinput}{top}[]{\renewcommand*\bbrinputtop{#1}} 1262 | \define@key{bbrinput}{bottom}[]{\renewcommand*\bbrinputbottom{#1}} 1263 | 1264 | 1265 | \newcommand{\@bb@inputsetup}[1]{ 1266 | %load keys 1267 | \begingroup % for local keys 1268 | 1269 | \setkeys{bbrinput}{#1}% 1270 | 1271 | \tikzset{BBRINPUT-NODESTYLE/.style/.expand once=\bbrinputedgestyle}% 1272 | \tikzset{BBRINPUT-TOPSTYLE/.style/.expand once=\bbrinputtopstyle}% 1273 | \tikzset{BBRINPUT-BOTTOMSTYLE/.style/.expand once=\bbrinputbottomstyle}% 1274 | \tikzset{BBRINPUT-EDGESTYLE/.style/.expand once=\bbrinputedgestyle}% 1275 | 1276 | } 1277 | 1278 | \newcommand{\@bb@inputfinalize}{ 1279 | \endgroup 1280 | } 1281 | 1282 | \newcommandx*{\bbrinput}[2][2=]{% 1283 | \@bb@inputsetup{#2} 1284 | \ifthenelse{\equal{\bbrinputnodename}{}} 1285 | {\renewcommand{\bbrinputnodename}{\@bb@lastbox-input}}{} 1286 | 1287 | \node[overlay,above right={\bbrinputlength} and {\bbrinputhoffset} of \@bb@lastbox.north west, anchor=south,BBRINPUT-NODESTYLE] (\bbrinputnodename) {#1}; 1288 | \path[->] (\bbrinputnodename.south) edge[BBRINPUT-EDGESTYLE] node[above,anchor=east,BBRINPUT-TOPSTYLE] () {\bbrinputtop} node[below,anchor=west,BBRINPUT-BOTTOMSTYLE] () {\bbrinputbottom} (\bbrinputnodename.south|-\@bb@lastbox.north); 1289 | \@bb@inputfinalize 1290 | } 1291 | 1292 | \newcommandx*{\bbroutput}[2][2=]{% 1293 | \@bb@inputsetup{#2} 1294 | \ifthenelse{\equal{\bbrinputnodename}{}} 1295 | {\renewcommand{\bbrinputnodename}{\@bb@lastbox-output}}{} 1296 | 1297 | \node[overlay,below right={\bbrinputlength} and {\bbrinputhoffset} of \@bb@lastbox.south west, anchor=north] (\bbrinputnodename) {#1}; 1298 | \draw[->] (\bbrinputnodename.north|-\@bb@lastbox.south) -- (\bbrinputnodename.north|-\bbrinputnodename.north); 1299 | \@bb@inputfinalize 1300 | } 1301 | 1302 | \newenvironment{bbrpic}[1][]{% 1303 | \begin{tikzpicture}[overlay,inner sep=0ex,baseline=0pt,#1]% 1304 | }{% 1305 | \end{tikzpicture}} 1306 | 1307 | %%%%%%%%%%% 1308 | % communication 1309 | %temporary lengths 1310 | \newlength{\@bb@com@tmpoffset} 1311 | \newlength{\@bb@tmplength@b} 1312 | \newcommand{\@bb@firstmessageheight}{0.25\baselineskip} 1313 | \newcommand{\@bb@msglength}{1.25cm} 1314 | \newcommand{\@bb@qrylength}{1.5cm} 1315 | 1316 | %keys 1317 | \newcommand*\bbrcomnsidestyle{} 1318 | \newcommand*\bbrcomtopstyle{} 1319 | \newcommand*\bbrcombottomstyle{} 1320 | \newcommand*\bbrcomside{} 1321 | \newcommand*\bbrcomoside{} 1322 | \newcommand*\bbrcomtop{} 1323 | \newcommand*\bbrcombottom{} 1324 | \newcommand*\bbrcomedgestyle{} 1325 | \newcommand*\bbrcomlength{1.25cm} 1326 | \newcommand*\bbrcomtopname{bbrcomtop} 1327 | \newcommand*\bbrcombottomname{bbrcombottom} 1328 | \newcommand*\bbrcomsidename{bbrcomside} 1329 | \newcommand*\bbrcomosidename{bbrcomoside} 1330 | \newcommand*\bbrcombeforeskip{0pt} 1331 | \newcommand*\bbrcomafterskip{0pt} 1332 | \define@key{bbrcom}{sidestyle}[]{\renewcommand*\bbrcomnsidestyle{#1}} 1333 | \define@key{bbrcom}{topstyle}[]{\renewcommand*\bbrcomtopstyle{#1}} 1334 | \define@key{bbrcom}{bottomstyle}[]{\renewcommand*\bbrcombottomstyle{#1}} 1335 | \define@key{bbrcom}{side}[]{\renewcommand*\bbrcomside{#1}} 1336 | \define@key{bbrcom}{oside}[]{\renewcommand*\bbrcomoside{#1}} 1337 | \define@key{bbrcom}{top}[]{\renewcommand*\bbrcomtop{#1}} 1338 | \define@key{bbrcom}{bottom}[]{\renewcommand*\bbrcombottom{#1}} 1339 | \define@key{bbrcom}{edgestyle}[]{\renewcommand*\bbrcomedgestyle{#1}} 1340 | \define@key{bbrcom}{length}[]{\renewcommand*\bbrcomlength{#1}} 1341 | \define@key{bbrcom}{topname}[]{\renewcommand*\bbrcomtopname{#1}} 1342 | \define@key{bbrcom}{bottomname}[]{\renewcommand*\bbrcombottomname{#1}} 1343 | \define@key{bbrcom}{sidename}[]{\renewcommand*\bbrcomsidename{#1}} 1344 | \define@key{bbrcom}{osidename}[]{\renewcommand*\bbrcomosidename{#1}} 1345 | \define@key{bbrcom}{beforeskip}[]{\renewcommand*\bbrcombeforeskip{#1}} 1346 | \define@key{bbrcom}{afterskip}[]{\renewcommand*\bbrcomafterskip{#1}} 1347 | 1348 | \newcommand*\bbrbasenodestyle{} 1349 | \newcommand*\bbrbasenodename{bbrtmpname} 1350 | \define@key{bbrabase}{nodestyle}[]{\renewcommand*\bbrbasenodestyle{#1}} 1351 | \define@key{bbrabase}{nodename}[]{\renewcommand*\bbrbasenodename{#1}} 1352 | 1353 | 1354 | \newcommand{\@bb@comsetup}[3]{ 1355 | %load keys 1356 | \begingroup % for local keys 1357 | 1358 | \setkeys{bbrcom}{#1}% 1359 | 1360 | %set styles 1361 | \tikzset{BBRCOM-SIDESTYLE/.style/.expand once=\bbrcomnsidestyle}% 1362 | \tikzset{BBRCOM-TOPSTYLE/.style/.expand once=\bbrcomtopstyle}% 1363 | \tikzset{BBRCOM-BOTTOMSTYLE/.style/.expand once=\bbrcombottomstyle}% 1364 | \tikzset{BBRCOM-EDGESTYLE/.style/.expand once=\bbrcomedgestyle}% 1365 | 1366 | % increase space 1367 | \ifthenelse{\lengthtest{#2<\@bb@firstmessageheight}} 1368 | {#3{\@bb@firstmessageheight}} 1369 | { 1370 | #3{1.25\baselineskip} 1371 | \ifthenelse{\equal{\bbrcomtop}{}}{}{#3{0.5\baselineskip}} 1372 | } 1373 | 1374 | #3{\bbrcombeforeskip} 1375 | 1376 | \setlength{\@bb@com@tmpoffset}{#2}% 1377 | } 1378 | 1379 | \newcommand{\@bb@comfinalize}[1]{ 1380 | \ifthenelse{\equal{\bbrcombottom}{}}{}{#1{\baselineskip}} 1381 | #1{\bbrcomafterskip} 1382 | \endgroup 1383 | } 1384 | 1385 | \newcommand{\@bbrmsg}[8]{ 1386 | \@bb@comsetup{#1}{#7}{#8} 1387 | % 1388 | \node[#3=\@bb@com@tmpoffset and \bbrcomlength of \@bb@lastbox.#4,anchor=#6,BBRCOM-SIDESTYLE] (\bbrcomsidename) {\bbrcomside}; 1389 | \path[#2] (\bbrcomsidename.#6) edge[BBRCOM-EDGESTYLE] node[above,BBRCOM-TOPSTYLE] (\bbrcomtopname) {\bbrcomtop} node[below,BBRCOM-BOTTOMSTYLE] (\bbrcombottomname) {\bbrcombottom} (\@bb@lastbox.#5|-\bbrcomsidename) node[inner sep=0pt,outer sep=0pt] (\bbrcomosidename) {}; 1390 | % 1391 | \@bb@comfinalize{#8} 1392 | } 1393 | 1394 | \newcommandx{\bbrmsgto}[1]{% 1395 | \@bbrmsg{#1}{->}{below left}{north west}{west}{east}{\@bb@message@hoffset}{\bbrmsgspace} 1396 | } 1397 | \newcommandx{\bbrmsgfrom}[1]{% 1398 | \@bbrmsg{#1}{<-}{below left}{north west}{west}{east}{\@bb@message@hoffset}{\bbrmsgspace} 1399 | } 1400 | \newcommandx{\bbrmsgvdots}{% 1401 | \bbrmsgtxt[xshift=\bbrcomlength/2,beforeskip=-0.5\baselineskip,afterskip=-0.5\baselineskip]{$\vdots$} 1402 | } 1403 | 1404 | 1405 | \newcommandx{\bbrqryto}[1]{% 1406 | \@bbrmsg{#1}{<-}{below right}{north east}{east}{west}{\@bb@query@hoffset}{\bbrqryspace} 1407 | } 1408 | \newcommandx{\bbrqryfrom}[1]{% 1409 | \@bbrmsg{#1}{->}{below right}{north east}{east}{west}{\@bb@query@hoffset}{\bbrqryspace} 1410 | } 1411 | 1412 | \newcommand{\@bbroracleqry}[4]{ 1413 | \@bb@comsetup{#1}{#3}{#4} 1414 | % 1415 | 1416 | \path[#2] (\@bb@lastoracle.north west) -- ++ (0,-\@bb@com@tmpoffset) node[inner sep=0pt,outer sep=0pt] (\bbrcomsidename){\bbrcomside} edge[BBRCOM-EDGESTYLE] node[above,BBRCOM-TOPSTYLE] (\bbrcomtopname) {\bbrcomtop} node[below,BBRCOM-BOTTOMSTYLE] (\bbrcombottomname) {\bbrcombottom} (\@bb@lastbox.east|-\bbrcomsidename) node[inner sep=0pt,outer sep=0pt] (\bbrcomosidename) {\bbrcomoside}; 1417 | % 1418 | \@bb@comfinalize{#4} 1419 | } 1420 | 1421 | \newcommand{\bbroracleqryfrom}[1]{ 1422 | \@bbroracleqry{#1}{->}{\@bb@oraclequery@hoffset}{\bbroracleqryspace} 1423 | } 1424 | 1425 | \newcommand{\bbroracleqryto}[1]{ 1426 | \@bbroracleqry{#1}{<-}{\@bb@oraclequery@hoffset}{\bbroracleqryspace} 1427 | } 1428 | 1429 | \newcommand{\@bbrchallengerqry}[4]{ 1430 | \@bb@comsetup{#1}{#3}{#4} 1431 | % 1432 | 1433 | \path[#2] (\@bb@lastchallenger.north east) -- ++ (0,-\@bb@com@tmpoffset) node[inner sep=0pt,outer sep=0pt] (\bbrcomsidename){\bbrcomside} edge[BBRCOM-EDGESTYLE] node[above,BBRCOM-TOPSTYLE] (\bbrcomtopname) {\bbrcomtop} node[below,BBRCOM-BOTTOMSTYLE] (\bbrcombottomname) {\bbrcombottom} (\@bb@lastbox.west|-\bbrcomsidename) node[inner sep=0pt,outer sep=0pt] (\bbrcomosidename) {\bbrcomoside}; 1434 | % 1435 | \@bb@comfinalize{#4} 1436 | } 1437 | 1438 | \newcommand{\bbrchallengerqryfrom}[1]{ 1439 | \@bbrchallengerqry{#1}{<-}{\@bb@challengerquery@hoffset}{\bbrchallengerqryspace} 1440 | } 1441 | 1442 | \newcommand{\bbrchallengerqryto}[1]{ 1443 | \@bbrchallengerqry{#1}{->}{\@bb@challengerquery@hoffset}{\bbrchallengerqryspace} 1444 | } 1445 | 1446 | 1447 | 1448 | \newcommand*\bbrcomloopleft{} 1449 | \newcommand*\bbrcomloopright{} 1450 | \newcommand*\bbrcomloopcenter{} 1451 | \newcommand*\bbrcomloopangle{50} 1452 | \define@key{bbrcomloop}{left}[]{\renewcommand*\bbrcomloopleft{#1}} 1453 | \define@key{bbrcomloop}{right}[]{\renewcommand*\bbrcomloopright{#1}} 1454 | \define@key{bbrcomloop}{center}[]{\renewcommand*\bbrcomloopcenter{#1}} 1455 | \define@key{bbrcomloop}{angle}[]{\renewcommand*\bbrcomloopangle{#1}} 1456 | 1457 | \newcommand{\bbrloop}[3]{ 1458 | \begingroup % for local keys 1459 | \setkeys{bbrcomloop}{#3}% 1460 | 1461 | \path[->] (#1) edge[bend right=\bbrcomloopangle] node[midway,left] (bbrleft) {\bbrcomloopleft} (#2); 1462 | \path[->] (#2) edge[bend right=\bbrcomloopangle] node[midway,right] (bbrright) {\bbrcomloopright} (#1); 1463 | \node[at=($(bbrleft.north west)!0.5!(bbrright.north east)$),anchor=north]() {\bbrcomloopcenter}; 1464 | 1465 | \endgroup 1466 | } 1467 | 1468 | \newcommand*\bbrintertexthoffset{1.5cm} 1469 | \define@key{bbrintertext}{xshift}[]{\renewcommand*\bbrintertexthoffset{#1}} 1470 | 1471 | \newcommand{\@bb@intertextsetup}[1]{ 1472 | %load keys 1473 | \begingroup % for local keys 1474 | 1475 | \setkeys{bbrcom,bbrabase,bbrintertext}{#1}% 1476 | 1477 | \tikzset{BBRBASE-NODESTYLE/.style/.expand once=\bbrbasenodestyle}% 1478 | } 1479 | 1480 | \newcommand{\@bb@intertextfinalize}[1]{ 1481 | #1{\bbrcomafterskip} 1482 | \endgroup 1483 | } 1484 | 1485 | \newcommand{\@bbrintertext}[6]{ 1486 | \@bb@intertextsetup{#1} 1487 | 1488 | % increase space 1489 | \ifthenelse{\lengthtest{#4<\@bb@firstmessageheight}} 1490 | {#5{\@bb@firstmessageheight}} 1491 | {#5{1\baselineskip}} 1492 | 1493 | \setlength{\@bb@com@tmpoffset}{#4+\bbrcombeforeskip}% 1494 | 1495 | % 1496 | \node[#2=\@bb@com@tmpoffset and \bbrintertexthoffset of \@bb@lastbox.#3,BBRBASE-NODESTYLE] (\bbrbasenodename) {#6}; 1497 | % 1498 | % compute height of node 1499 | \coordinate (@bbtmpcoord) at (\bbrbasenodename.north); 1500 | \path (@bbtmpcoord); 1501 | \pgfgetlastxy{\XCoord}{\YCoordA} 1502 | \coordinate (@bbtmpcoord) at (\bbrbasenodename.south); 1503 | \path (@bbtmpcoord); 1504 | \pgfgetlastxy{\XCoord}{\YCoordB} 1505 | 1506 | % update hoffset 1507 | \setlength{\@bb@tmplength@b}{\YCoordA-\YCoordB} 1508 | #5{\the\@bb@tmplength@b} 1509 | 1510 | \@bb@intertextfinalize{#5} 1511 | } 1512 | 1513 | \newcommand{\bbrmsgtxt}[2][]{ 1514 | \@bbrintertext{#1}{below left}{north west}{\@bb@message@hoffset}{\bbrmsgspace}{#2} 1515 | } 1516 | 1517 | \newcommand{\bbrqrytxt}[2][]{ 1518 | \@bbrintertext{#1}{below right}{north east}{\@bb@query@hoffset}{\bbrqryspace}{#2} 1519 | } 1520 | 1521 | \newcommand{\bbrchallengertxt}[2][]{ 1522 | \begingroup 1523 | \setlength{\@bb@tmplength@b}{\bbrchallengerhdistance/2}% 1524 | \renewcommand{\bbrintertexthoffset}{\the\@bb@tmplength@b}% 1525 | \@bbrintertext{#1}{below left}{north west}{\@bb@challengerquery@hoffset}{\bbrchallengerqryspace}{#2} 1526 | \endgroup 1527 | } 1528 | 1529 | \newcommand{\bbroracletxt}[2][]{ 1530 | \begingroup 1531 | \setlength{\@bb@tmplength@b}{\bbroraclehdistance/2}% 1532 | \renewcommand{\bbrintertexthoffset}{\the\@bb@tmplength@b}% 1533 | \@bbrintertext{#1}{below left}{north west}{\@bb@oraclequery@hoffset}{\bbroracleqryspace}{#2} 1534 | \endgroup 1535 | } 1536 | 1537 | \newcommand{\bbrmsgspace}[1]{ 1538 | \@pc@globaladdtolength{\@bb@message@hoffset}{#1} 1539 | } 1540 | 1541 | \newcommand{\bbrqryspace}[1]{ 1542 | \@pc@globaladdtolength{\@bb@query@hoffset}{#1} 1543 | } 1544 | 1545 | \newcommand{\bbroracleqryspace}[1]{ 1546 | \@pc@globaladdtolength{\@bb@oraclequery@hoffset}{#1} 1547 | } 1548 | 1549 | \newcommand{\bbrchallengerqryspace}[1]{ 1550 | \@pc@globaladdtolength{\@bb@challengerquery@hoffset}{#1} 1551 | } 1552 | 1553 | 1554 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 1555 | % stacking 1556 | \providecommand{\pccenteraboveskip}{0.5\baselineskip plus 0.25\baselineskip minus 0.25\baselineskip} 1557 | \providecommand{\pccenterbelowskip}{0.5\baselineskip plus 0.25\baselineskip minus 0.25\baselineskip} 1558 | \newenvironment{pccenter}{% 1559 | \setlength\topsep{0pt}\setlength\parskip{0pt}% 1560 | \begin{center}\vspace{\pccenteraboveskip}% 1561 | }{% 1562 | \vspace{\pccenteraboveskip}% 1563 | \end{center}} 1564 | 1565 | 1566 | %%%%%%%%%%%%%%%%%%%%% 1567 | % horizontal stacking 1568 | % space before hstacks 1569 | \newlength{\pcbeforehstackskip} 1570 | 1571 | \NewEnviron{pchstack}[1][]{% 1572 | % write out content 1573 | \ifthenelse{\equal{#1}{center}}{% 1574 | \begin{pccenter}\mbox{\hspace{\pcbeforehstackskip}\BODY}\end{pccenter}}{% 1575 | \mbox{\hspace{\pcbeforehstackskip}\BODY}}% 1576 | } 1577 | 1578 | 1579 | %%%%%%%%%%%%%%%%%%%%%%% 1580 | \NewEnviron{pcvstack}[1][]{% 1581 | % display minipage 1582 | \ifthenelse{\equal{#1}{center}}{\begin{pccenter}}{}% 1583 | \begin{varwidth}[t]{2\linewidth}\hspace{0pt}\BODY\end{varwidth}% hspace needed for proper vertical positioning .. strange as it is. 1584 | \ifthenelse{\equal{#1}{center}}{\end{pccenter}}{}% 1585 | } 1586 | 1587 | 1588 | % spacing for stacking 1589 | \newcommand{\pchspace}[1][1em]{\hspace{#1}} 1590 | \newcommand{\pcvspace}[1][\baselineskip]{\par\vspace{#1}} 1591 | 1592 | 1593 | 1594 | 1595 | 1596 | %%%% 1597 | % subprocedures 1598 | \newcounter{@pcsubprogcnt1} 1599 | \newcounter{@pcrsubprogcnt1} 1600 | \newcounter{@pcsubprogcnt2} 1601 | \newcounter{@pcrsubprogcnt2} 1602 | \newcounter{@pcsubprogcnt3} 1603 | \newcounter{@pcrsubprogcnt3} 1604 | \newcounter{@pcsubprogcnt4} 1605 | \newcounter{@pcrsubprogcnt4} 1606 | \newcounter{@pcsubprogcnt5} 1607 | \newcounter{@pcrsubprogcnt5} 1608 | \newcounter{@pcsubprogcnt6} 1609 | \newcounter{@pcrsubprogcnt6} 1610 | \newcounter{@pcsubprogcnt7} 1611 | \newcounter{@pcrsubprogcnt7} 1612 | \newcounter{@pcsubprogcnt8} 1613 | \newcounter{@pcrsubprogcnt8} 1614 | \newcounter{@pcsubprogcnt9} 1615 | \newcounter{@pcrsubprogcnt9} 1616 | \newcounter{@pcsubprogstep} 1617 | 1618 | \newenvironment{subprocedure}{% 1619 | \addtocounter{@pcsubprogstep}{1}% 1620 | % store old counter values 1621 | \setcounter{@pcsubprogcnt\the@pcsubprogstep}{\value{pclinenumber}}% 1622 | \setcounter{@pcrsubprogcnt\the@pcsubprogstep}{\value{pcrlinenumber}}% 1623 | }{% 1624 | \setcounter{pclinenumber}{\value{@pcsubprogcnt\the@pcsubprogstep}}% 1625 | \setcounter{pcrlinenumber}{\value{@pcrsubprogcnt\the@pcsubprogstep}}% 1626 | \addtocounter{@pcsubprogstep}{-1}} 1627 | 1628 | 1629 | %%%%% 1630 | % parameter reordering 1631 | \def\@pseudocodeB#1#2[#3]#4{\setkeys*{pcspace}{#2,#3}\@pseudocode[head={#1#4},#2,#3]} 1632 | \def\@pseudocodeC#1#2#3{\setkeys*{pcspace}{#2}\@pseudocode[head={#1#3},#2]} 1633 | %for no headers 1634 | \def\@pseudocodeE#1#2[#3]{\setkeys*{pcspace}{#2,#3}\@pseudocode[head={#1},#2,#3]} 1635 | \def\@pseudocodeF#1#2{\setkeys*{pcspace}{#2}\@pseudocode[head={#1},#2]} 1636 | 1637 | %%%%%%%%% 1638 | % Define pseudocode command: 1639 | % #1 name 1640 | % #2 code to execute after begingroup 1641 | % #3 head prefix 1642 | % #4 other config 1643 | \newcommand{\createprocedurecommand}[4]{ 1644 | \expandafter\gdef\csname #1\endcsname{% 1645 | \begingroup% 1646 | \renewcommand{\@withinspaces}{false}% 1647 | #2% 1648 | \@ifnextchar[%] 1649 | {\@pseudocodeB{#3}{#4}} 1650 | {\@pseudocodeC{#3}{#4}}% 1651 | }% 1652 | } 1653 | 1654 | \newcommand{\createpseudocodecommand}[4]{ 1655 | \expandafter\gdef\csname #1\endcsname{% 1656 | \begingroup% 1657 | \renewcommand{\@withinspaces}{false}% 1658 | #2% 1659 | \@ifnextchar[%] 1660 | {\@pseudocodeE{#3}{#4}} 1661 | {\@pseudocodeF{#3}{#4}}% 1662 | }% 1663 | } 1664 | 1665 | 1666 | %%%%%% 1667 | % create procedure 1668 | \createprocedurecommand{procedure}{}{}{} 1669 | 1670 | 1671 | 1672 | 1673 | %%% 1674 | % send message 1675 | \newcommand{\pcshortmessageoffset}{0.5cm} 1676 | \newcommand{\pcdefaultmessagelength}{3.5cm} 1677 | \newcommand{\pcdefaultlongmessagelength}{6cm} 1678 | \newcommand{\pcbeforemessageskip}{0pt} 1679 | \newcommand{\pcaftermessageskip}{10pt} 1680 | \newlength{\pcmessagearrow} 1681 | 1682 | \newcommand*\@pcsendmessagelength{\pcdefaultmessagelength} 1683 | \newcommand*\@pcsendmessagecol{} 1684 | \newcommand*\@pcsendmessagewidth{} 1685 | \newcommand*\@pcsendmessagestyle{} 1686 | \newcommand*\@pcsendmessagetop{} 1687 | \newcommand*\@pcsendmessagebottom{} 1688 | \newcommand*\@pcsendmessageright{} 1689 | \newcommand*\@pcsendmessageleft{} 1690 | \newcommand*\@pcsendmessagetopname{t} 1691 | \newcommand*\@pcsendmessagebottomname{b} 1692 | \newcommand*\@pcsendmessagerightname{r} 1693 | \newcommand*\@pcsendmessageleftname{l} 1694 | \newcommand*\@pcsendmessagetopstyle{} 1695 | \newcommand*\@pcsendmessagebottomstyle{} 1696 | \newcommand*\@pcsendmessagerightstyle{} 1697 | \newcommand*\@pcsendmessageleftstyle{} 1698 | \newcommand*\@pcsendmessagebeforeskip{\pcbeforemessageskip} 1699 | \newcommand*\@pcsendmessageafterskip{\pcaftermessageskip} 1700 | \define@key{pcsendmessage}{centercol}[]{\renewcommand*\@pcsendmessagecol{#1}} 1701 | \define@key{pcsendmessage}{width}[]{\renewcommand*\@pcsendmessagewidth{#1}} 1702 | \define@key{pcsendmessage}{style}[]{\renewcommand*\@pcsendmessagestyle{#1}} 1703 | \define@key{pcsendmessage}{length}[]{\renewcommand*\@pcsendmessagelength{#1}} 1704 | \define@key{pcsendmessage}{top}[]{\renewcommand*\@pcsendmessagetop{#1}} 1705 | \define@key{pcsendmessage}{bottom}[]{\renewcommand*\@pcsendmessagebottom{#1}} 1706 | \define@key{pcsendmessage}{right}[]{\renewcommand*\@pcsendmessageright{#1}} 1707 | \define@key{pcsendmessage}{left}[]{\renewcommand*\@pcsendmessageleft{#1}} 1708 | \define@key{pcsendmessage}{topname}[]{\renewcommand*\@pcsendmessagetopname{#1}} 1709 | \define@key{pcsendmessage}{bottomname}[]{\renewcommand*\@pcsendmessagebottomname{#1}} 1710 | \define@key{pcsendmessage}{rightname}[]{\renewcommand*\@pcsendmessagerightname{#1}} 1711 | \define@key{pcsendmessage}{leftname}[]{\renewcommand*\@pcsendmessageleftname{#1}} 1712 | \define@key{pcsendmessage}{topstyle}[]{\renewcommand*\@pcsendmessagetopstyle{#1}} 1713 | \define@key{pcsendmessage}{bottomstyle}[]{\renewcommand*\@pcsendmessagebottomstyle{#1}} 1714 | \define@key{pcsendmessage}{rightstyle}[]{\renewcommand*\@pcsendmessagerightstyle{#1}} 1715 | \define@key{pcsendmessage}{leftstyle}[]{\renewcommand*\@pcsendmessageleftstyle{#1}} 1716 | \define@key{pcsendmessage}{beforeskip}[]{\renewcommand*\@pcsendmessagebeforeskip{#1}} 1717 | \define@key{pcsendmessage}{afterskip}[]{\renewcommand*\@pcsendmessageafterskip{#1}} 1718 | 1719 | 1720 | \newcommand{\@pc@centerincol}[2]{% 1721 | \ifmeasuring@% 1722 | #2% 1723 | \else% 1724 | \makebox[\ifcase\expandafter #1\maxcolumn@widths\fi]{$\displaystyle#2$}% 1725 | \fi% 1726 | } 1727 | 1728 | \newcommand{\centerincol}[1]{\@pc@centerincol{\thepccolumncounter}{#1}} 1729 | 1730 | \newcommand{\@do@sendmessage}[1]{% 1731 | \ifthenelse{\equal{\@pcsendmessagecol}{}}{% 1732 | \ifthenelse{\equal{\@pcsendmessagewidth}{}}{#1}{% we have some width 1733 | \makebox[\@pcsendmessagewidth]{$\displaystyle#1$}% 1734 | }}{%we know the column to center on 1735 | \@pc@centerincol{\@pcsendmessagecol}{#1}% 1736 | }% 1737 | } 1738 | 1739 | \newcommandx*{\sendmessage}[2]{% 1740 | \begingroup\setkeys{pcsendmessage}{#2}% 1741 | \tikzset{PCSENDMSG-PATH-STYLE/.style/.expand once=\@pcsendmessagestyle}% 1742 | \tikzset{PCSENDMSG-TOP-STYLE/.style/.expand once=\@pcsendmessagetopstyle}% 1743 | \tikzset{PCSENDMSG-BOTTOM-STYLE/.style/.expand once=\@pcsendmessagebottomstyle}% 1744 | \tikzset{PCSENDMSG-LEFT-STYLE/.style/.expand once=\@pcsendmessageleftstyle}% 1745 | \tikzset{PCSENDMSG-RIGHT-STYLE/.style/.expand once=\@pcsendmessagerightstyle}% 1746 | %restore halign 1747 | % 1748 | \hspace{\@pcsendmessagebeforeskip}% 1749 | \begin{varwidth}{\linewidth} 1750 | \@do@sendmessage{ 1751 | \begin{tikzpicture}% 1752 | \node[PCSENDMSG-LEFT-STYLE] (\@pcsendmessageleftname) {\@pcsendmessageleft}; 1753 | \node[right=\@pcsendmessagelength of \@pcsendmessageleftname,PCSENDMSG-RIGHT-STYLE] (\@pcsendmessagerightname) {\@pcsendmessageright}; 1754 | \path[#1,PCSENDMSG-PATH-STYLE] (\@pcsendmessageleftname) edge[] node[above,PCSENDMSG-TOP-STYLE] (\@pcsendmessagetopname) {\@pcsendmessagetop} node[below,PCSENDMSG-BOTTOM-STYLE] (\@pcsendmessagebottomname) {\@pcsendmessagebottom} (\@pcsendmessagerightname); 1755 | \end{tikzpicture}% 1756 | }% 1757 | \end{varwidth} 1758 | \hspace{\@pcsendmessageafterskip}% 1759 | \endgroup% 1760 | } 1761 | 1762 | \newcommandx*{\sendmessageright}[2][1=->]{% 1763 | \sendmessage{#1}{#2}% 1764 | } 1765 | 1766 | \newcommandx*{\sendmessageleft}[2][1=<-]{% 1767 | \sendmessage{#1}{#2}% 1768 | } 1769 | 1770 | \WithSuffix\newcommand\sendmessageleft*[2][\pcdefaultmessagelength]{% 1771 | \begingroup% 1772 | \renewcommand{\@pcsendmessagetop}{\let\halign\@pc@halign$\begin{aligned}#2\end{aligned}$}% 1773 | \sendmessage{<-}{length=#1}% 1774 | \endgroup% 1775 | } 1776 | 1777 | 1778 | \WithSuffix\newcommand\sendmessageright*[2][\pcdefaultmessagelength]{% 1779 | \begingroup% 1780 | \renewcommand{\@pcsendmessagetop}{\let\halign\@pc@halign$\begin{aligned}#2\end{aligned}$}% 1781 | \sendmessage{->}{length=#1}% 1782 | \endgroup% 1783 | } 1784 | 1785 | 1786 | 1787 | \DeclareExpandableDocumentCommand{\sendmessagerightx}{O{\pcdefaultlongmessagelength}mO{}m}{% 1788 | \multicolumn{#2}{c}{\ensuremath{\hspace{\pcbeforemessageskip}\xrightarrow[\begin{aligned}#3\end{aligned}]{\mathmakebox[#1]{\begin{aligned}#4\end{aligned}}}\hspace{\pcaftermessageskip}}} 1789 | } 1790 | 1791 | \DeclareExpandableDocumentCommand{\sendmessageleftx}{O{\pcdefaultlongmessagelength}mO{}m}{% 1792 | \multicolumn{#2}{c}{\ensuremath{\hspace{\pcbeforemessageskip}\xleftarrow[\begin{aligned}#3\end{aligned}]{\mathmakebox[#1]{\begin{aligned}#4\end{aligned}}}\hspace{\pcaftermessageskip}}} 1793 | } 1794 | 1795 | %%% 1796 | % Division 1797 | \DeclareExpandableDocumentCommand{\pcintertext}{O{}m}{\intertext{% 1798 | \ifthenelse{\equal{#1}{center}}{\makebox[\linewidth][c]{#2}}{}% 1799 | \ifthenelse{\equal{#1}{dotted}}{\dotfill#2\dotfill}{}% 1800 | \ifthenelse{\equal{#1}{}}{#2}{}% 1801 | }\@pc@beginnewline} 1802 | 1803 | 1804 | 1805 | %%% 1806 | % Games 1807 | % 1808 | \newcounter{pcstartgamecounter} 1809 | 1810 | 1811 | \newcommand*{\pcgameprocedurestyle}{} % define pseudocode arguments for game procedures 1812 | 1813 | \newcommand*{\pcgamename}{\ensuremath{\mathsf{Game}}} 1814 | \newcommand*{\gameprocedurearg}{\ensuremath{(\secpar)}} 1815 | \newcommand*\@pcgameproofgamenr{0} 1816 | \define@key{pcgameproof}{nr}[]{\renewcommand*\@pcgameproofgamenr{#1}} 1817 | \define@key{pcgameproof}{name}[]{\renewcommand*\pcgamename{\ensuremath{#1}}} 1818 | \define@key{pcgameproof}{arg}[]{\renewcommand*\gameprocedurearg{\ensuremath{#1}}} 1819 | 1820 | \newenvironment{gameproof}[1][]{% 1821 | \begingroup% 1822 | \setkeys{pcgameproof}{#1}% 1823 | \@pc@ensureremember% 1824 | \setcounter{pcgamecounter}{\@pcgameproofgamenr}% 1825 | \setcounter{pcstartgamecounter}{\@pcgameproofgamenr}\stepcounter{pcstartgamecounter}% 1826 | }{\@pc@releaseremember\endgroup} 1827 | 1828 | \newcommand{\setgameproceduredefaultstyle}[1]{% 1829 | \createpseudocodecommand{gameprocedure} 1830 | {\addtocounter{pcgamecounter}{1}\renewcommand{\@withingame}{true}} 1831 | {\ensuremath{\pcgamename_{\thepcgamecounter}\gameprocedurearg}} 1832 | {#1} 1833 | } 1834 | \setgameproceduredefaultstyle{} 1835 | 1836 | \def\@bxgame@pseudocodeA[#1]#2#3{\setkeys*{pcspace}{#1}\renewcommand{\@bxgameheader}{$\pcgamename_{#2}$\gameprocedurearg}% 1837 | \@pseudocode[head=\ensuremath{\pcgamename_{\thepcgamecounter}\gameprocedurearg},#1]{#3}} 1838 | \def\@bxgame@pseudocodeB#1#2{\renewcommand{\@bxgameheader}{$\pcgamename_{#1}$\gameprocedurearg}% 1839 | \@pseudocode[head=\ensuremath{\pcgamename_{\thepcgamecounter}\gameprocedurearg}]{#2}} 1840 | 1841 | \newcommand{\bxgameprocedure}{ 1842 | \begingroup% 1843 | \renewcommand{\@withinspaces}{false}% 1844 | \renewcommand{\@withingame}{true}% 1845 | \renewcommand{\@withinbxgame}{true}% 1846 | \stepcounter{pcgamecounter}% 1847 | \@ifnextchar[%] 1848 | {\@bxgame@pseudocodeA} 1849 | {\@bxgame@pseudocodeB}% 1850 | } 1851 | 1852 | \newcommand{\@pc@secondheader}{} 1853 | 1854 | %tbx top boxed 1855 | \createpseudocodecommand{tbxgameprocedure} 1856 | {\addtocounter{pcgamecounter}{1}\renewcommand{\@withingame}{true}%% 1857 | \renewcommand{\@pc@secondheader}{true}} 1858 | {\ensuremath{\pcgamename_{\thepcgamecounter}\gameprocedurearg}} 1859 | {} 1860 | 1861 | 1862 | \newcommand*\@pcgamehopnodestyle{} 1863 | \newcommand*\@pcgamehopedgestyle{bend left} 1864 | \newcommand*\@pcgamehoppathestyle{} 1865 | \newcommand*\@pcgamehophint{} 1866 | \newcommand*\@pcgamehophintbelow{} 1867 | \newcommand*\@pcgamehopinhint{} 1868 | \newcommand*\@pcgamehoplength{1.5cm} 1869 | \define@key{pcgamehop}{nodestyle}[]{\renewcommand*\@pcgamehopnodestyle{#1}} 1870 | \define@key{pcgamehop}{edgestyle}[]{\renewcommand*\@pcgamehopedgestyle{#1}} 1871 | \define@key{pcgamehop}{pathstyle}[]{\renewcommand*\@pcgamehoppathestyle{#1}} 1872 | \define@key{pcgamehop}{hint}[]{\renewcommand*\@pcgamehophint{#1}} 1873 | \define@key{pcgamehop}{belowhint}[]{\renewcommand*\@pcgamehophintbelow{#1}} 1874 | \define@key{pcgamehop}{inhint}[]{\renewcommand*\@pcgamehopinhint{#1}} 1875 | \define@key{pcgamehop}{length}[]{\renewcommand*\@pcgamehoplength{#1}} 1876 | 1877 | 1878 | \newcommand{\@pc@setupgamehop}[1]{ 1879 | \begingroup\setkeys{pcgamehop}{#1}% 1880 | \tikzset{GAMEHOP-PATH-STYLE/.style/.expand once=\@pcgamehoppathestyle}% 1881 | \tikzset{GAMEHOP-NODE-STYLE/.style/.expand once=\@pcgamehopnodestyle}% 1882 | \tikzset{GAMEHOP-EDGE-STYLE/.style/.expand once=\@pcgamehopedgestyle}% 1883 | } 1884 | 1885 | \newcommand{\@pc@finalizegamehop}{ 1886 | \endgroup 1887 | } 1888 | 1889 | \newcommandx*{\addgamehop}[3]{% 1890 | \begingroup% 1891 | \ifthenelse{#1<#2}% 1892 | {\ifthenelse{\equal{\@withingamedescription}{true}}% 1893 | {\renewcommand*\@pcgamehopedgestyle{bend right=20}\renewcommand*\@pcgamehopnodestyle{rotate=90}}{}% 1894 | }% 1895 | {\renewcommand*\@pcgamehopedgestyle{bend right}}% 1896 | \@pc@setupgamehop{#3}% 1897 | \begin{tikzpicture}[overlay]% 1898 | \ifthenelse{#1<#2}{% 1899 | \path[->,GAMEHOP-PATH-STYLE] (gamenode#1) edge[GAMEHOP-EDGE-STYLE] node[above,GAMEHOP-NODE-STYLE] {\@pcgamehophint} 1900 | node[below,GAMEHOP-NODE-STYLE] {\@pcgamehophintbelow} (gamenode#2); 1901 | }{% 1902 | \path[->,GAMEHOP-PATH-STYLE] (bgamenode#1) edge[GAMEHOP-EDGE-STYLE] node[above,GAMEHOP-NODE-STYLE] {\@pcgamehophint} 1903 | node[above,GAMEHOP-NODE-STYLE] {\@pcgamehophintbelow} (bgamenode#2); 1904 | }% 1905 | \end{tikzpicture}% 1906 | \@pc@finalizegamehop% 1907 | \endgroup% 1908 | } 1909 | \newcommandx*{\addstartgamehop}[2][1=\thepcstartgamecounter]{% 1910 | \@pc@setupgamehop{#2} 1911 | \begin{tikzpicture}[overlay] 1912 | \node[left=\@pcgamehoplength of gamenode#1] (tmpgamenode0) {}; 1913 | \path[->,GAMEHOP-PATH-STYLE] (tmpgamenode0) edge[GAMEHOP-EDGE-STYLE] node[above,GAMEHOP-NODE-STYLE] {\@pcgamehophint} 1914 | node[below,GAMEHOP-NODE-STYLE] {\@pcgamehophintbelow} (gamenode#1); 1915 | \end{tikzpicture} 1916 | \@pc@finalizegamehop 1917 | } 1918 | \newcommandx*{\addendgamehop}[2][1=\thepcgamecounter]{% 1919 | \@pc@setupgamehop{#2} 1920 | \begin{tikzpicture}[overlay] 1921 | \node[right=\@pcgamehoplength of gamenode#1] (tmpgamenode#1) {}; 1922 | \path[->,GAMEHOP-PATH-STYLE] (gamenode#1) edge[GAMEHOP-EDGE-STYLE] node[above,GAMEHOP-NODE-STYLE] {\@pcgamehophint} 1923 | node[below,GAMEHOP-NODE-STYLE] {\@pcgamehophintbelow} (tmpgamenode#1); 1924 | \end{tikzpicture} 1925 | \@pc@finalizegamehop 1926 | } 1927 | \newcommandx*{\addbxgamehop}[3]{% 1928 | \@pc@setupgamehop{#3} 1929 | \begin{tikzpicture}[overlay] 1930 | \path[->,GAMEHOP-PATH-STYLE] (bgamenode#1) edge[GAMEHOP-EDGE-STYLE] node[above,GAMEHOP-NODE-STYLE]] {\@pcgamehophint} 1931 | node[below,GAMEHOP-NODE-STYLE] {\@pcgamehophintbelow} (bgamenode#2); 1932 | \end{tikzpicture} 1933 | \@pc@finalizegamehop 1934 | } 1935 | \newcommandx*{\addloopgamehop}[2][1=\thepcgamecounter]{% 1936 | \@pc@setupgamehop{#2} 1937 | \begin{tikzpicture}[overlay] 1938 | \node (looptemp1) [right=0.5cm of gamenode#1] {}; 1939 | \draw[->,GAMEHOP-PATH-STYLE] (gamenode#1) -- (looptemp1|-gamenode#1) -- node[right,GAMEHOP-NODE-STYLE] {\@pcgamehophint} 1940 | node[left,GAMEHOP-NODE-STYLE] {\@pcgamehophintbelow} (looptemp1|-bgamenode#1)-- (bgamenode#1); 1941 | \end{tikzpicture} 1942 | \@pc@finalizegamehop 1943 | } 1944 | 1945 | 1946 | %%%%%%%% 1947 | % game description 1948 | \newenvironment{gamedescription}[1][]{% 1949 | \begingroup% 1950 | \setkeys{pcgameproof}{#1} 1951 | \renewcommand{\@withingamedescription}{true}% 1952 | \@pc@ensureremember% 1953 | \setcounter{pcgamecounter}{\@pcgameproofgamenr}% 1954 | \setcounter{pcstartgamecounter}{\@pcgameproofgamenr}\stepcounter{pcstartgamecounter}% 1955 | \begin{description}% 1956 | }{\end{description}\@pc@releaseremember\endgroup} 1957 | 1958 | \newcommandx*{\describegame}[1][1=]{% 1959 | \addtocounter{pcgamecounter}{1}% 1960 | \item[% 1961 | \pcdraw{ 1962 | \gdef\i{\thepcgamecounter}% 1963 | \node[inner sep=0.0em,outer sep=0, xshift=-1ex, yshift=0.5ex] (gamenode\i) {}; 1964 | }% 1965 | \ensuremath{\pcgamename_{\thepcgamecounter}\gameprocedurearg}:]% 1966 | \begingroup\setkeys{pcgamehop}{#1}% 1967 | \ifthenelse{\equal{}{\@pcgamehophint}} 1968 | {} 1969 | {\hspace{-0.7ex}\pcdraw{%the -0.7ex is a horrible hack to fix a whitespace issue with tikz (see http://tex.stackexchange.com/questions/22873/tikzpicture-with-overlay-takes-up-space 1970 | \tikzset{GAMEHOP-PATH-STYLE/.style/.expand once=\@pcgamehoppathestyle}% 1971 | \tikzset{GAMEHOP-NODE-STYLE/.style/.expand once=\@pcgamehopnodestyle}% 1972 | \draw[->,GAMEHOP-PATH-STYLE] (gamenode\thepcgamecounter) --++ (0,-\@pcgamehoplength) node[midway,above,xshift=-1mm,rotate=90,GAMEHOP-NODE-STYLE] {\@pcgamehophint}; 1973 | }}% 1974 | \ifthenelse{\equal{}{\@pcgamehopinhint}} 1975 | {} 1976 | {\hspace{-0.7ex}\pcdraw{%the -0.7ex is a horrible hack to fix a whitespace issue with tikz (see http://tex.stackexchange.com/questions/22873/tikzpicture-with-overlay-takes-up-space 1977 | \tikzset{GAMEHOP-PATH-STYLE/.style/.expand once=\@pcgamehoppathestyle}% 1978 | \tikzset{GAMEHOP-NODE-STYLE/.style/.expand once=\@pcgamehopnodestyle}% 1979 | \draw[<-,GAMEHOP-PATH-STYLE] (gamenode\thepcgamecounter) --++ (0,\@pcgamehoplength) node[midway,above,xshift=-1mm,rotate=90,GAMEHOP-NODE-STYLE] {\@pcgamehopinhint}; 1980 | }% 1981 | }% 1982 | \endgroup% 1983 | } 1984 | 1985 | 1986 | 1987 | 1988 | 1989 | 1990 | %%%%%%%% 1991 | % basic pseudocode constants 1992 | 1993 | \newcommand{\highlightkeyword}[2][\ ]{\ensuremath{\mathbf{#2}}#1} 1994 | \newcommand{\highlightaltkeyword}[1]{\ensuremath{\mathsf{#1}}} 1995 | 1996 | \newcommand{\pcglobvar}{\highlightkeyword{gbl}} 1997 | \newcommand{\pcnew}{\highlightkeyword{new}} 1998 | \newcommand{\pcwhile}{\@pc@increaseindent\highlightkeyword{while}} 1999 | \newcommand{\pcendwhile}{\@pc@decreaseindent\highlightkeyword{endwhile}} 2000 | \newcommandx*{\pcdo}[2][1=\ ,2=]{#1\highlightkeyword[#2]{do}} 2001 | \newcommandx*{\pcif}[1][1=\ ]{\@pc@increaseindent\highlightkeyword[#1]{if}} 2002 | \newcommandx*{\pcunless}[1][1=\ ]{\@pc@increaseindent\highlightkeyword[#1]{unless}} 2003 | \newcommandx*{\pcelse}[1][1=\ ]{\@pc@tmpdecreaseindent\highlightkeyword[#1]{else}} 2004 | \newcommandx*{\pcelseif}[1][1=\ ]{\@pc@tmpdecreaseindent\highlightkeyword[#1]{else if}} 2005 | \newcommand{\pcfi}{\@pc@decreaseindent\highlightkeyword{fi}} 2006 | \newcommand{\pcendif}{\@pc@decreaseindent\highlightkeyword{endif}} 2007 | \newcommand{\pcendfor}{\@pc@decreaseindent\highlightkeyword{endfor}} 2008 | \newcommandx*{\pcthen}[2][1=\ ,2=\ ]{#1\highlightkeyword[#2]{then}} 2009 | \newcommand{\pcreturn}{\highlightkeyword{return}} 2010 | \newcommandx*{\pcin}[2][1=\ ,2=]{#1\highlightkeyword[#2]{in}} 2011 | \newcommand{\pcfor}{\@pc@increaseindent\highlightkeyword{for}} 2012 | \newcommand{\pcrepeat}[1]{\@pc@increaseindent\ensuremath{\highlightkeyword{repeat} #1\ \highlightkeyword{times}}} 2013 | \newcommand{\pcrepeatuntil}[2]{\ensuremath{\highlightkeyword{repeat}\ #1\ \highlightkeyword{until}\ #2}} 2014 | \newcommand{\pcforeach}{\@pc@increaseindent\highlightkeyword{foreach}} 2015 | \newcommand{\pcendforeach}{\@pc@decreaseindent\highlightkeyword{endforeach}} 2016 | \newcommand{\pcuntil}{\@pc@decreaseindent\highlightkeyword{until}} 2017 | \newcommand{\pccontinue}{\highlightkeyword{continue}} 2018 | \newcommandx*{\pcfalse}[2][1=\ ,2=]{\highlightkeyword[#2]{false}} 2019 | \newcommandx*{\pctrue}[2][1=\ ,2=]{\highlightkeyword[#2]{true}} 2020 | \newcommandx*{\pcnull}[2][1=\ ,2=]{\highlightkeyword[#2]{null}} 2021 | \newcommand{\pccomment}[1]{{\mbox{/\!\!/ } \text{\scriptsize#1}}} 2022 | \newcommand{\pcdone}{\highlightkeyword{done}} 2023 | \newcommand{\pcparse}{\highlightkeyword{parse}} 2024 | \newcommand{\pcfail}{\highlightkeyword{fail}} 2025 | \newcommand{\pcabort}{\highlightkeyword{abort}} 2026 | 2027 | %%% 2028 | % highlighting 2029 | \definecolor{gamechangecolor}{gray}{0.90} 2030 | \newcommand{\gamechange}[2][gamechangecolor]{% 2031 | {\setlength{\fboxsep}{0pt}\colorbox{#1}{\ifmmode$\displaystyle#2$\else#2\fi}}% 2032 | } 2033 | 2034 | %%% 2035 | % boxing 2036 | \newcommand{\pcbox}[1]{% 2037 | {\setlength{\fboxsep}{3pt}\fbox{$\displaystyle#1$}} 2038 | } 2039 | 2040 | \endinput -------------------------------------------------------------------------------- /cryptocode-2020-04-24.sty: -------------------------------------------------------------------------------- 1 | %% Copyright 2018 Arno Mittelbach 2 | % 3 | % This work may be distributed and/or modified under the 4 | % conditions of the LaTeX Project Public License, either version 1.3 5 | % of this license or (at your option) any later version. 6 | % The latest version of this license is in 7 | % http://www.latex-project.org/lppl.txt 8 | % and version 1.3 or later is part of all distributions of LaTeX 9 | % version 2005/12/01 or later. 10 | % 11 | % This work has the LPPL maintenance status `maintained'. 12 | % 13 | % The Current Maintainer of this work is Arno Mittelbach. 14 | % 15 | % This work consists of the files cryptocode.tex and cryptocode.sty 16 | % 17 | % Changelog 18 | % 19 | % 2016/11/30 20 | % - changed \pckeystyle to ensure that subscripts on \sk and \pk are aligned the same 21 | % before, $(\sk_R, \pk_R)$ had slightly misaligned subscripts due to Tex treating 22 | % subscripts on composite objects with descenders differently than without. 23 | % see https://groups.google.com/forum/#!msg/comp.text.tex/IaXu_xBG06Q/CibRPH5GCAAJ 24 | % - added \NAND 25 | % - added pcmbox environment for matrices in pseudocode 26 | % 27 | % 2016/12/02 28 | % - changed minheight for bbrbox environment to actually reflect a minimum height in tikz 29 | % the old minheight which added space at the bottom was preserved as addheight 30 | % - added namepos middle for bbrbox 31 | % - added pcfail 32 | % - added valign to pseudocode to allow minipage vertical alignment 33 | % - added \setgameproceduredefaultstyle 34 | % - ensure line numbers are right aligned to allow for two digit linenumbers having the same width 35 | % 36 | % 2017/08/26 37 | % - added \pcabort 38 | % - better control whitespace for \pcif, \pcelse, \pcelseif 39 | % 40 | % 2017/10/02 41 | % - side and oside support to \bbroracleqryto and \bbroracleqryfrom 42 | % - add bottom to namepos in bbrbox 43 | % - names for brrinput and bbroutput 44 | % - angle for bbrloop 45 | % - fix length for bbrinput 46 | % - introduce hoffset for bbrinput 47 | % 48 | % 2017/12/21 49 | % - added \pcunless 50 | % 51 | % 2018/11/11 52 | % replace obsolete l3regex 53 | % 54 | % 2018/11/26 TODO: document 55 | % added tprob (variants for prob and co for in-text) 56 | % 57 | % 2018/12/21 58 | % added \prp 59 | % 60 | % 2020/01/11 61 | % - allow to control spacing with \pcfor 62 | % - allow overwriting rule command in pseudocode via headlinecmd (defaults to \hrule) 63 | % 64 | % 2020/04/24 65 | % - fix spacing of pchstack[center]. Can be controlled via \pccenterbelowskip and \pccenteraboveskip 66 | % 67 | % 68 | \NeedsTeXFormat{LaTeX2e} 69 | \ProvidesPackage{cryptocode} 70 | [2018/11/11 v0.3.0 Cryptocode LaTeX package for typesetting pseudocode, algorithms and protocols as well as cryptographic proofs.] 71 | 72 | 73 | \def\hi{Hello, this is cryptocode.} 74 | \let\myDate\date 75 | 76 | \RequirePackage{amsmath} 77 | \RequirePackage{mathtools} 78 | %\usepackage{l3tl-analysis} % uncomment for debugging 79 | 80 | %%% 81 | % option modes 82 | \newif\ifpc@orderofgrowth 83 | \newif\ifpc@algorithmstyle 84 | \newif\ifpc@amsfonts 85 | \newif\ifpc@advantage 86 | \newif\ifpc@primitives 87 | 88 | %%% 89 | % 90 | \DeclareOption{operators}{ 91 | \providecommand{\sample}{\hskip2.3pt{\gets\!\!\mbox{\tiny${\$}$\normalsize}}\,} 92 | 93 | \providecommand{\floor}[1]{\ensuremath{\left\lfloor #1\right\rfloor}} 94 | \providecommand{\ceil}[1]{\ensuremath{\left\lceil #1\right\rceil}} 95 | \providecommand{\Angle}[1]{\ensuremath{\left\langle #1\right\rangle}} 96 | \providecommand{\abs}[1]{\ensuremath{\left\lvert #1 \right\rvert}} 97 | \providecommand{\norm}[1]{\ensuremath{\left\|#1\right\|}} 98 | \providecommand{\concat}{\ensuremath{\|}} 99 | 100 | \providecommand{\emptystring}{\ensuremath{\varepsilon}} 101 | } 102 | 103 | \DeclareOption{adversary}{ 104 | \providecommand{\pcadvstyle}[1]{\mathcal{#1}} 105 | 106 | \providecommand{\adv}{\ensuremath{\pcadvstyle{A}}} 107 | \providecommand{\bdv}{\ensuremath{\pcadvstyle{B}}} 108 | \providecommand{\cdv}{\ensuremath{\pcadvstyle{C}}} 109 | \providecommand{\ddv}{\ensuremath{\pcadvstyle{D}}} 110 | \providecommand{\mdv}{\ensuremath{\pcadvstyle{M}}} 111 | \providecommand{\pdv}{\ensuremath{\pcadvstyle{P}}} 112 | \providecommand{\rdv}{\ensuremath{\pcadvstyle{R}}} 113 | \providecommand{\sdv}{\ensuremath{\pcadvstyle{S}}} 114 | } 115 | 116 | \DeclareOption{landau}{ 117 | \pc@orderofgrowthtrue 118 | 119 | \providecommand{\bigO}[1]{\ensuremath{\mathcal{O}\olrk{#1}}} 120 | \providecommand{\smallO}[1]{\ensuremath{\text{o}\olrk{#1}}} 121 | \providecommand{\bigOmega}[1]{\ensuremath{\Omega\olrk{#1}}} 122 | \providecommand{\smallOmega}[1]{\ensuremath{\omega\olrk{#1}}} 123 | \providecommand{\bigsmallO}[1]{\ensuremath{\Theta\olrk{#1}}} 124 | } 125 | 126 | \DeclareOption{probability}{ 127 | \pc@orderofgrowthtrue 128 | \pc@amsfontstrue 129 | 130 | \providecommand{\probname}{Pr} 131 | \providecommand{\expectationname}{\ensuremath{\mathbb{E}}} 132 | \providecommand{\supportname}{Supp} 133 | 134 | \providecommand{\tprob}[1]{\ensuremath{\operatorname{\probname}\telrk{#1}}} 135 | \providecommand{\prob}[1]{\ensuremath{\operatorname{\probname}\elrk{#1}}} 136 | 137 | \providecommand{\tprobsub}[2]{\ensuremath{\operatorname{\probname}_{#1}\telrk{#2}}} 138 | \providecommand{\probsub}[2]{\ensuremath{\operatorname{\probname}_{#1}\elrk{#2}}} 139 | 140 | \providecommand{\tcondprob}[2]{\ensuremath{\tprob{#1\,\left|\,#2\vphantom{#1}\right.}}} 141 | \providecommand{\condprob}[2]{\ensuremath{\prob{#1\,\left|\,#2\vphantom{#1}\right.}}} 142 | 143 | \providecommand{\tcondprobsub}[3]{\ensuremath{\tprobsub{#1}{#2\,\left|\,#3\vphantom{#1}\right.}}} 144 | \providecommand{\condprobsub}[3]{\ensuremath{\probsub{#1}{#2\,\left|\,#3\vphantom{#1}\right.}}} 145 | 146 | \providecommand{\texpect}[1]{\ensuremath{\operatorname{\expectationname}\telrk{#1}}} 147 | \providecommand{\expect}[1]{\ensuremath{\operatorname{\expectationname}\elrk{#1}}} 148 | 149 | \providecommand{\texpsub}[2]{\ensuremath{\operatorname{\expectationname}_{#1}\telrk{#2}}} 150 | \providecommand{\expsub}[2]{\ensuremath{\operatorname{\expectationname}_{#1}\elrk{#2}}} 151 | 152 | \providecommand{\tcondexp}[2]{\ensuremath{\texpect{#1\,\left|\,#2\vphantom{#1}\right.}}} 153 | \providecommand{\condexp}[2]{\ensuremath{\expect{#1\,\left|\,#2\vphantom{#1}\right.}}} 154 | 155 | \providecommand{\tcondexpsub}[3]{\ensuremath{\texpsub{#1}{#2\,\left|\,#3\vphantom{#1}\right.}}} 156 | \providecommand{\condexpsub}[3]{\ensuremath{\expsub{#1}{#2\,\left|\,#3\vphantom{#1}\right.}}} 157 | 158 | \providecommand{\supp}[1]{ \ensuremath{\operatorname{Supp}\olrk{#1}}} 159 | 160 | \providecommand{\entropy}[1]{\ensuremath{\operatorname{H}\olrk{#1}}} 161 | \providecommand{\condentropy}[2]{\ensuremath{\operatorname{H}\olrk{#1\,\left|\,#2\vphantom{#1}\right.}}} 162 | \providecommand{\minentropy}[1]{\ensuremath{\operatorname{H_\infty}\olrk{#1}}} 163 | \providecommand{\condminentropy}[2]{\ensuremath{\operatorname{H_\infty}\olrk{#1\,\left|\,#2\vphantom{#1}\right.}}} 164 | \providecommand{\condavgminentropy}[2]{\ensuremath{\operatorname{\tilde{H}_\infty}\olrk{#1\,\left|\,#2\vphantom{#1}\right.}}} 165 | } 166 | 167 | \DeclareOption{sets}{ 168 | \pc@orderofgrowthtrue 169 | \pc@amsfontstrue 170 | 171 | \providecommand\NN{\mathbb{N}} 172 | \providecommand\ZZ{\mathbb{Z}} 173 | \providecommand\CC{\mathbb{C}} 174 | \providecommand\QQ{\mathbb{Q}} 175 | \providecommand\RR{\mathbb{R}} 176 | \providecommand\PP{\mathbb{P}} 177 | \providecommand\FF{\mathbb{F}} 178 | \providecommand\GG{\mathbb{G}} 179 | 180 | \providecommand{\set}[1]{\ensuremath{\clrk{#1}}} 181 | \providecommand{\sequence}[1]{\ensuremath{\olrk{#1}}} 182 | \providecommand{\bin}{\ensuremath{\{0,1\}}} 183 | } 184 | 185 | \DeclareOption{noamsfonts}{ 186 | \pc@amsfontsfalse 187 | } 188 | 189 | 190 | \DeclareOption{notions}{ 191 | \providecommand{\pcnotionstyle}[1]{\ensuremath{\mathrm{#1}}} 192 | 193 | \providecommand{\indcpa}{\pcnotionstyle{IND\pcmathhyphen{}CPA}} 194 | \providecommand{\indcca}{\pcnotionstyle{IND\pcmathhyphen{}CCA}} 195 | \providecommand{\indccai}{\pcnotionstyle{IND\pcmathhyphen{}CCA1}} 196 | \providecommand{\indccaii}{\pcnotionstyle{IND\pcmathhyphen{}CCA2}} 197 | \providecommand{\priv}{\pcnotionstyle{PRIV}} 198 | \providecommand{\ind}{\pcnotionstyle{IND}} 199 | \providecommand{\indcda}{\pcnotionstyle{IND\pcmathhyphen{}CDA}} 200 | \providecommand{\prvcda}{\pcnotionstyle{PRV\pcmathhyphen{}CDA}} 201 | \providecommand{\prvrcda}{\pcnotionstyle{PRV\$\pcmathhyphen{}CDA}} 202 | \providecommand{\kiae}{\pcnotionstyle{KIAE}} 203 | \providecommand{\kdae}{\pcnotionstyle{KDAE}} 204 | \providecommand{\mle}{\pcnotionstyle{MLE}} 205 | \providecommand{\uce}{\pcnotionstyle{UCE}} 206 | } 207 | 208 | \DeclareOption{logic}{ 209 | \providecommand{\AND}{\ensuremath{\mathrm{AND}}} 210 | \providecommand{\OR}{\ensuremath{\mathrm{OR}}} 211 | \providecommand{\NOR}{\ensuremath{\mathrm{NOR}}} 212 | \providecommand{\NOT}{\ensuremath{\mathrm{NOT}}} 213 | \providecommand{\NAND}{\ensuremath{\mathrm{NAND}}} 214 | \providecommand{\XOR}{\ensuremath{\mathrm{XOR}}} 215 | \providecommand{\XNOR}{\ensuremath{\mathrm{XNOR}}} 216 | \providecommand{\xor}{\ensuremath{\oplus}} 217 | \providecommand{\false}{\mathsf{false}} 218 | \providecommand{\true}{\mathsf{true}} 219 | } 220 | 221 | 222 | % Function Families 223 | \DeclareOption{ff}{ 224 | \pc@algorithmstyletrue 225 | 226 | \providecommand{\kgen}{\pcalgostyle{KGen}} 227 | \providecommand{\pgen}{\pcalgostyle{Pgen}} 228 | \providecommand{\eval}{\pcalgostyle{Eval}} 229 | \providecommand{\invert}{\pcalgostyle{Inv}} 230 | 231 | \providecommand{\il}{\pcalgostyle{il}} 232 | \providecommand{\ol}{\pcalgostyle{ol}} 233 | \providecommand{\kl}{\pcalgostyle{kl}} 234 | \providecommand{\nl}{\pcalgostyle{nl}} 235 | \providecommand{\rl}{\pcalgostyle{rl}} 236 | } 237 | 238 | % Machine Model 239 | \DeclareOption{mm}{ 240 | \pc@algorithmstyletrue 241 | 242 | \providecommand{\pcmachinemodelstyle}[1]{\ensuremath{\mathsf{#1}}} 243 | 244 | \providecommand{\CRKT}{\pcmachinemodelstyle{C}} 245 | \providecommand{\TM}{\pcmachinemodelstyle{M}} 246 | \providecommand{\PROG}{\pcmachinemodelstyle{P}} 247 | 248 | \providecommand{\uTM}{\pcmachinemodelstyle{UM}} 249 | \providecommand{\uC}{\pcmachinemodelstyle{UC}} 250 | \providecommand{\uP}{\pcmachinemodelstyle{UEval}} 251 | 252 | \providecommand{\csize}{\pcmachinemodelstyle{size}} 253 | \providecommand{\tmtime}{\pcmachinemodelstyle{time}} 254 | \providecommand{\ppt}{\pcalgostyle{PPT}} 255 | } 256 | 257 | \DeclareOption{advantage}{ 258 | \pc@advantagetrue 259 | } 260 | 261 | \DeclareOption{primitives}{ 262 | \pc@primitivestrue 263 | \pc@algorithmstyletrue 264 | } 265 | 266 | \DeclareOption{events}{ 267 | \providecommand{\event}[1]{\ensuremath{\mathsf{#1}}} 268 | \providecommand{\nevent}[1]{\ensuremath{\overline{\event{#1}}}} 269 | 270 | \providecommand{\bad}{\ensuremath{\event{bad}}} 271 | } 272 | 273 | \DeclareOption{complexity}{ 274 | \providecommand{\pccomplexitystyle}[1]{\ensuremath{\mathsf{#1}}} 275 | 276 | \providecommand{\npol}{\pccomplexitystyle{NP}} 277 | \providecommand{\conpol}{\ensuremath{\mathsf{co}}\pccomplexitystyle{NP}} 278 | \providecommand{\pol}{\pccomplexitystyle{P}} 279 | \providecommand{\bpp}{\pccomplexitystyle{BPP}} 280 | \providecommand{\ppoly}{\ensuremath{\pol/\mathrm{poly}}} 281 | 282 | \providecommand{\AM}{\pccomplexitystyle{AM}} 283 | \providecommand{\coAM}{\ensuremath{\mathsf{co}}\pccomplexitystyle{AM}} 284 | 285 | \providecommand{\AC}[1]{\ensuremath{\ifthenelse{\equal{#1}{}}{\pccomplexitystyle{AC}}{\pccomplexitystyle{AC}^{#1}}}} 286 | \providecommand{\NC}[1]{\ensuremath{\ifthenelse{\equal{#1}{}}{\pccomplexitystyle{NC}}{\pccomplexitystyle{NC}^{#1}}}} 287 | \providecommand{\TC}[1]{\ensuremath{\ifthenelse{\equal{#1}{}}{\pccomplexitystyle{TC}}{\pccomplexitystyle{TC}^{#1}}}} 288 | } 289 | 290 | \DeclareOption{asymptotics}{ 291 | \pc@orderofgrowthtrue 292 | 293 | \providecommand{\pcpolynomialstyle}[1]{\mathsf{#1}} 294 | 295 | \providecommand{\negl}[1][\secpar]{\ensuremath{\pcpolynomialstyle{negl}\ifthenelse{\equal{#1}{}}{}{\olrk{#1}}}} 296 | \providecommand{\poly}[1][\secpar]{\ensuremath{\pcpolynomialstyle{poly}\ifthenelse{\equal{#1}{}}{}{\olrk{#1}}}} 297 | 298 | \providecommand{\pp}{\ensuremath{\pcpolynomialstyle{p}}} 299 | \providecommand{\qq}{\ensuremath{\pcpolynomialstyle{q}}} 300 | } 301 | 302 | \DeclareOption{keys}{ 303 | \providecommand{\pckeystyle}[1]{\ensuremath{\mathsf{\protect\vphantom{p}#1}}} 304 | 305 | \providecommand{\pk}{\pckeystyle{pk}} 306 | \providecommand{\vk}{\pckeystyle{vk}} 307 | \providecommand{\sk}{\pckeystyle{sk}} 308 | \providecommand{\key}{\pckeystyle{k}} 309 | \providecommand{\hk}{\pckeystyle{hk}} 310 | \providecommand{\gk}{\pckeystyle{gk}} 311 | \providecommand{\fk}{\pckeystyle{fk}} 312 | 313 | \providecommand{\st}{\pckeystyle{st}} 314 | \providecommand{\state}{\pckeystyle{state}} 315 | } 316 | 317 | \DeclareOption{n}{ 318 | \providecommand{\secpar}{\ensuremath{n}} 319 | \providecommand{\secparam}{\ensuremath{1^\secpar}} 320 | } 321 | 322 | \DeclareOption{lambda}{ 323 | \renewcommand{\secpar}{\ensuremath{\lambda}} 324 | \renewcommand{\secparam}{\ensuremath{1^\secpar}} 325 | } 326 | 327 | \DeclareOption*{% 328 | \PackageError{crypto code}{Unknown option ‘\CurrentOption’}% 329 | } 330 | 331 | \ExecuteOptions{n} 332 | 333 | \ProcessOptions\relax 334 | 335 | \RequirePackage{etex} 336 | 337 | %amsfonts 338 | \ifpc@amsfonts 339 | \RequirePackage{amsfonts} 340 | \fi 341 | \RequirePackage{xcolor} 342 | \RequirePackage{calc} 343 | \RequirePackage{tikz} 344 | \usetikzlibrary{positioning,calc} 345 | \RequirePackage{ifthen} 346 | \RequirePackage{xargs} 347 | \RequirePackage{pgf} 348 | %\RequirePackage{mathabx} 349 | \RequirePackage{forloop} 350 | \RequirePackage{array} 351 | \RequirePackage{xparse} 352 | \RequirePackage{expl3} 353 | \RequirePackage{pbox} 354 | \RequirePackage{varwidth} 355 | \RequirePackage{suffix} 356 | \RequirePackage{etoolbox} 357 | \RequirePackage{environ} 358 | %\RequirePackage{xspace} 359 | \RequirePackage{xkeyval} 360 | 361 | \ifpc@advantage 362 | \newcommand{\pcadvantagesuperstyle}[1]{\mathrm{\MakeLowercase{#1}}} 363 | \newcommand{\pcadvantagesubstyle}[1]{#1} 364 | \newcommandx*{\advantage}[3][3=(\secpar)]{\ensuremath{\mathsf{Adv}^{\pcadvantagesuperstyle{#1}}_{\pcadvantagesubstyle{#2}}#3}} 365 | \fi 366 | 367 | \ifpc@primitives 368 | % zero knowledge 369 | \providecommand{\prover}{\pcalgostyle{P}} 370 | \providecommand{\verifier}{\pcalgostyle{V}} 371 | \providecommand{\nizk}{\pcalgostyle{NIZK}} 372 | 373 | % hash 374 | \providecommand{\hash}{\pcalgostyle{H}} 375 | \providecommand{\gash}{\pcalgostyle{G}} 376 | \providecommand{\fash}{\pcalgostyle{F}} 377 | 378 | % encryption 379 | \providecommand{\enc}{\pcalgostyle{Enc}} 380 | \providecommand{\dec}{\pcalgostyle{Dec}} 381 | 382 | % signatures 383 | \providecommand{\sig}{\pcalgostyle{Sig}} 384 | \providecommand{\verify}{\pcalgostyle{Vf}} 385 | 386 | % obfuscation 387 | \providecommand{\obf}{\pcalgostyle{O}} 388 | \providecommand{\iO}{\pcalgostyle{iO}} 389 | \providecommand{\diO}{\pcalgostyle{diO}} 390 | 391 | % PRF, PRP, PRG 392 | \providecommand{\prf}{\pcalgostyle{PRF}} 393 | \providecommand{\prp}{\pcalgostyle{PRP}} 394 | \providecommand{\prg}{\pcalgostyle{PRG}} 395 | 396 | % Mac 397 | \providecommand{\mac}{\pcalgostyle{MAC}} 398 | 399 | % puncture 400 | \providecommand{\puncture}{\pcalgostyle{Puncture}} 401 | 402 | % Misc 403 | \providecommand{\source}{\pcalgostyle{S}} 404 | \providecommand{\predictor}{\pcalgostyle{P}} 405 | \providecommand{\sam}{\pcalgostyle{Sam}} 406 | \providecommand{\dist}{\pcalgostyle{D}} 407 | \providecommand{\distinguisher}{\pcalgostyle{Dist}} 408 | \providecommand{\simulator}{\pcalgostyle{Sim}} 409 | \providecommand{\ext}{\pcalgostyle{Ext}} 410 | \providecommand{\extractor}{\ext} 411 | \fi 412 | 413 | %% 414 | % math hyphen 415 | \mathchardef\pcmathhyphen ="2D 416 | 417 | %%% 418 | % order of growth helper 419 | \ifpc@orderofgrowth 420 | \providecommand{\tolrk}[1]{\ifx\nursymbol#1\else\!\!\mskip6.5mu plus 0.5mu (\mskip0.5mu plus0.5mu #1\mskip1.5mu plus0.5mu )\fi} 421 | \providecommand{\olrk}[1]{\ifx\nursymbol#1\else\!\!\mskip4.5mu plus 0.5mu\left(\mskip0.5mu plus0.5mu #1\mskip1.5mu plus0.5mu \right)\fi} 422 | 423 | \providecommand{\telrk}[1]{\ifx\nursymbol#1\else\!\!\mskip6.5mu plus0.5mu [\mskip0.5mu plus0.5mu #1\mskip1.5mu plus0.5mu ]\fi} 424 | \providecommand{\elrk}[1]{\ifx\nursymbol#1\else\!\!\mskip4.5mu plus0.5mu\left[\mskip0.5mu plus0.5mu #1\mskip1.5mu plus0.5mu \right]\fi} 425 | 426 | \providecommand{\tclrk}[1]{\ifx\nursymbol#1\else\!\!\mskip6.5mu plus0.5mu \{\mskip0.5mu plus0.5mu #1\mskip1.5mu plus0.5mu \}\fi} 427 | \providecommand{\clrk}[1]{\ifx\nursymbol#1\else\!\!\mskip4.5mu plus0.5mu\left\{\mskip0.5mu plus0.5mu #1\mskip1.5mu plus0.5mu \right\}\fi} 428 | \fi 429 | 430 | \ifpc@algorithmstyle 431 | \providecommand{\pcalgostyle}[1]{\ensuremath{\mathsf{#1}}} 432 | \fi 433 | 434 | %%% 435 | % create command to measure width of align 436 | % 437 | \newcommand{\@settowidthofalign}[2]{% 438 | \setbox\z@=\vbox{\@pseudocodecodesize 439 | \begin{flalign*} 440 | #2 441 | \ifmeasuring@\else\global\let\got@maxcolwd\maxcolumn@widths\fi 442 | \end{flalign*} 443 | }% 444 | \begingroup 445 | \def\or{+}\edef\x{\endgroup#1=\dimexpr\got@maxcolwd\relax}\x} 446 | 447 | \newcommand{\@settowidthofaligned}[2]{% 448 | \settowidth{#1}{\@pseudocodesubcodesize$\begin{aligned}#2\end{aligned}$}} 449 | 450 | % check for draft mode 451 | \def\@pc@ifdraft{\ifdim\overfullrule>\z@ 452 | \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi} 453 | 454 | % run stuff in an empty box 455 | \newcommand{\@pcexecuteblindly}[1]{% 456 | \setbox\z@=\vbox{#1 }} 457 | 458 | % copy label command 459 | \AtBeginDocument{ 460 | \let\pc@original@label\ltx@label 461 | } 462 | 463 | 464 | %%%%%% 465 | \newcommand*{\@pc@globaladdtolength}[2]{% 466 | \addtolength{#1}{#2}% 467 | \global#1=#1\relax} 468 | 469 | \newcommand*{\@pc@globalsetlength}[2]{% 470 | \setlength{#1}{#2}% 471 | \global#1=#1\relax} 472 | 473 | 474 | 475 | %%%%% 476 | % spaces before and after pseudo codes (left and right) 477 | \providecommand{\beforepcskip}{2pt} 478 | \providecommand{\afterpcskip}{0pt} 479 | 480 | %%% 481 | % a global counter of the number of times the pseudocode command was triggered 482 | \newcounter{@pc@global@pc@cnt} 483 | \newcounter{@pc@global@pc@nestcnt} 484 | 485 | %%% 486 | % Fix hyperref package.. gnarl http://tex.stackexchange.com/questions/130319/incompatibility-between-etoolbox-and-hyperref 487 | \providecommand{\pcfixhyperref}{ 488 | \global\let\textlabel\label 489 | \global\let\pc@original@label\textlabel 490 | %\global\let\pc@original@label\relax 491 | %\global\let\label\relax 492 | } 493 | 494 | \newcounter{@spacecounter} 495 | \providecommand{\spacetoindent}{1} 496 | \newenvironment{@withspaces} 497 | {\obeyspaces\begingroup\lccode`~=` \lowercase{\endgroup\let~}\ } 498 | {} 499 | 500 | %%%%%%%%%%%%%% 501 | % a latex3 string substitution. 502 | \ExplSyntaxOn 503 | \tl_new:N \l_pc_strsub_input_tl 504 | \tl_new:N \l_pc_strsub_search_tl 505 | \tl_new:N \l_pc_strsub_replace_tl 506 | 507 | \NewDocumentCommand{\@pc@stringsubstitution}{mmm} 508 | { 509 | \tl_set:Nn \l_pc_strsub_input_tl { #1 } 510 | \tl_set:Nn \l_pc_strsub_search_tl { #2 } 511 | \tl_set:Nn \l_pc_strsub_replace_tl { #3 } 512 | % \tl_show_analysis:N \l_pc_strsub_input_tl % uncomment for debugging 513 | % \tl_show_analysis:N \l_pc_strsub_search_tl % uncomment for debugging 514 | % \tl_show_analysis:N \l_pc_strsub_replace_tl % uncomment for debugging 515 | \regex_replace_all:nnN 516 | { (\W)\u{l_pc_strsub_search_tl} } %only match if keyword does not have a word character preceding 517 | { \1\u{l_pc_strsub_replace_tl} } 518 | \l_pc_strsub_input_tl 519 | % \tl_show_analysis:N \l_tmpa_tl % uncomment for debugging 520 | \tl_use:N \l_pc_strsub_input_tl 521 | } 522 | 523 | % same as \@pc@stringsubstitution but without requiring the extra non word character 524 | \NewDocumentCommand{\@pc@spacesubstitution}{mmm} 525 | { 526 | \tl_set:Nn \l_pc_strsub_input_tl { #1 } 527 | \tl_set:Nn \l_pc_strsub_search_tl { #2 } 528 | \tl_set:Nn \l_pc_strsub_replace_tl { #3 } 529 | % \tl_show_analysis:N \l_pc_strsub_input_tl % uncomment for debugging 530 | % \tl_show_analysis:N \l_pc_strsub_search_tl % uncomment for debugging 531 | % \tl_show_analysis:N \l_pc_strsub_replace_tl % uncomment for debugging 532 | \regex_replace_all:nnN 533 | { \u{l_pc_strsub_search_tl} } 534 | { \u{l_pc_strsub_replace_tl} } 535 | \l_pc_strsub_input_tl 536 | % \tl_show_analysis:N \l_tmpa_tl % uncomment for debugging 537 | \tl_use:N \l_pc_strsub_input_tl 538 | } 539 | 540 | \NewDocumentCommand{\@pc@centercolifnec}{m}% 541 | {% 542 | #1% 543 | } 544 | 545 | 546 | 547 | \ExplSyntaxOff 548 | 549 | %%%%%%%% 550 | % line numbers 551 | %%%%%%%% 552 | % The following commands handle line numbering within the pseudocode command. The 553 | % pseudocode command itself does need to do some counter magic 554 | \newcounter{pclinenumber} 555 | \newcounter{Hpclinenumber} % make hyperref happy 556 | \newcounter{@pclinenumber} 557 | \newcounter{H@pclinenumber} % make hyperref happy 558 | \newcounter{@pclinenumbertmp} 559 | \newcounter{pcgamecounter} 560 | \newcounter{Hpcgamecounter} 561 | \newcounter{pcrlinenumber} 562 | \newcounter{Hpcrlinenumber} 563 | \newcounter{@pcrlinenumbertmp} 564 | 565 | % separators 566 | \providecommand{\pclnseparator}{:} 567 | \providecommand{\pcrlnseparator}{\hspace{1pt}} 568 | 569 | % spacing for linenumbers 570 | \providecommand{\pclnspace}{0pt} 571 | \providecommand{\pclnrspace}{5pt} 572 | 573 | \renewcommand{\the@pclinenumber}{\thepclinenumber} 574 | \providecommand{\@pcln}{% 575 | \refstepcounter{@pclinenumber}% 576 | \stepcounter{H@pclinenumber}% 577 | } 578 | 579 | % left align line numbers 580 | \providecommand{\pcln}[1][]{% 581 | \refstepcounter{pclinenumber}% 582 | \stepcounter{Hpclinenumber}% 583 | \ifthenelse{\equal{#1}{}}{}{% 584 | %keep hyperref happy 585 | \ifmeasuring@\else\pc@original@label{#1}\fi% 586 | }% 587 | \ifthenelse{\value{pclinenumber}<10}{\hspace{1ex}}{}% 588 | \hspace{\pclnspace}\text{\scriptsize\arabic{pclinenumber}}\pclnseparator\quad}% 589 | 590 | % allow to skip numbering single lines if linenumbering=on 591 | \providecommand{\pcnoln}{% 592 | } 593 | 594 | % right align line numbers (same counter) 595 | \providecommand{\pclnr}{% 596 | \refstepcounter{pclinenumber}% 597 | \quad\text{\scriptsize\pcrlnseparator\arabic{pclinenumber}}\hspace{5pt}} 598 | 599 | % right align line numbers different counter 600 | \providecommand{\pcrln}{ 601 | \refstepcounter{pcrlinenumber}% 602 | \stepcounter{Hpcrlinenumber}% 603 | \text{\scriptsize\pcrlnseparator\arabic{pcrlinenumber}}\hspace{\pclnrspace}} 604 | 605 | 606 | %%% 607 | % indentation 608 | \newlength{\@pcindentwidth} 609 | \providecommand{\pcind}[1][1]{% 610 | \setlength{\@pcindentwidth}{\widthof{\ensuremath{\quad}}*#1}% 611 | \ensuremath{\mathmakebox[\@pcindentwidth]{}}} 612 | 613 | 614 | % create length 615 | \newlength{\@pc@minipage@length} 616 | \newlength{\@pc@alt@minipage@length} 617 | 618 | % backward games 619 | \newcommand{\@withingame}{false} 620 | \newcommand{\@withinbxgame}{false} 621 | \newcommand{\@bxgameheader}{} 622 | \newcommand{\@withingamedescription}{false} 623 | 624 | 625 | %%%%%%%%%%%% 626 | % The pseudocode Command 627 | %%%%% 628 | \newlength{\@pc@length@tmp@width@vstack} 629 | 630 | 631 | \newcommand{\@pc@beginnewline}{% 632 | \@pseudocodecodeatbeginline\@pseudocodelinenumber\@pc@and\@pcln% 633 | %checkspace 634 | \ifthenelse{\equal{\@pseudocodespace}{auto}}% 635 | {\expandafter\pcind\expandafter[\value{@pc@indentationlevel}]}% 636 | {}% 637 | %reset column counter 638 | \setcounter{pccolumncounter}{2}% 639 | %beginmode 640 | \@pc@modebegin} 641 | \newcommand{\@pc@and}{&} 642 | \newcommand{\@pc@and@wrap@end}{\@pc@modeend&\@pseudocodecodeatendline} 643 | \newcommand{\@pc@and@wrap@start}{\@pc@beginnewline} 644 | \newcommand{\pctabname}{>} 645 | \newcommand{\pcdbltabname}{<} 646 | \newcommand{\pcindentname}{t} 647 | 648 | 649 | 650 | \newcommand*\@pseudocodehead{} 651 | \newcommand*\@pseudocodewidth{} 652 | \newcommand*\@pseudocodexshift{0pt} 653 | \newcommand*\@pseudocodeyshift{0pt} 654 | \newcommand*\@pseudocodelinenumber{} 655 | \newcommand*\@pseudocodebeforeskip{0ex} 656 | \newcommand*\@pseudocodeafterskip{0ex} 657 | \newcommand*\@pseudocodelnstart{0} 658 | \newcommand*\@pseudocodelnstartright{0} 659 | \newcommand*\@pseudocodesyntaxhighlighting{} 660 | \newcommand*\@pseudocodenodraft{false} 661 | \newcommand*\@pseudocodecolspace{} % empty per default, use length, 662 | 663 | \newcommand*\@pseudocodeheadlinecmd{\hrule} 664 | \newcommand*\@pseudocodeheadlinesep{0em} 665 | \newcommand*\@pseudocodebodylinesep{-0.5\baselineskip} 666 | 667 | \newcommand*\@pseudocodecolsep{0em} 668 | \newcommand*\@pseudocodeaddtolength{2pt} 669 | 670 | \newcommand*\@pseudocodecodeatbeginline{} 671 | \newcommand*\@pseudocodecodeatendline{} 672 | \newcommand*\@pseudocodecodejot{0em} 673 | \newcommand*\@pseudocodecodesize{\small} 674 | \newcommand*\@pseudocodesubcodesize{\footnotesize} 675 | 676 | \newcommand*\@pseudocodeminipagealign{t} 677 | 678 | %%%%%%%%%%%%%% 679 | % Define keywords for the automatic syntax highlighting 680 | % the accompanying add provides additional keywords. 681 | % The space version for automatic spacing 682 | \newcommand*\@pseudocodekeywordsindent{for ,foreach ,if ,repeat ,while } 683 | \newcommand*\@pseudocodekeywordsunindent{endfor,endforeach,fi,endif,until ,endwhile} 684 | \newcommand*\@pseudocodekeywordsuninindent{else if,elseif, else} 685 | \newcommand*\@pseudocodekeywords{return ,{ do }, in ,new ,null ,null,true ,true,{ to },false ,false,{ then },done ,done} 686 | \newcommand*\@pseudocodeaddkeywords{} 687 | \newcommand*\@pseudocodealtkeywords{} 688 | \begin{@withspaces} 689 | \global\def\@pseudocodekeywordsspace{for,endfor,foreach,endforeach,return,do,in,new,if,null,true,until,to,false,then,repeat,else if,elseif,while,endwhile,else,done,fi,endif} 690 | \end{@withspaces} 691 | 692 | 693 | \define@key{pseudocode}{beginline}[]{\renewcommand*\@pseudocodecodeatbeginline{#1}} 694 | \define@key{pseudocode}{endline}[]{\renewcommand*\@pseudocodecodeatendline{#1}} 695 | \define@key{pseudocode}{jot}[0em]{\renewcommand*\@pseudocodecodejot{#1}} 696 | \define@key{pseudocode}{codesize}[\small]{\renewcommand*\@pseudocodecodesize{#1}} 697 | \define@key{pseudocode}{subcodesize}[\small]{\renewcommand*\@pseudocodesubcodesize{#1}} 698 | \define@key{pseudocode}{head}[]{\renewcommand*\@pseudocodehead{#1}} 699 | \define@key{pseudocode}{width}[]{\renewcommand*\@pseudocodewidth{#1}} 700 | \define@key{pseudocode}{valign}[t]{\renewcommand*\@pseudocodeminipagealign{#1}} 701 | \define@key{pseudocode}{xshift}[]{\renewcommand*\@pseudocodexshift{#1}} 702 | \define@key{pseudocode}{yshift}[]{\renewcommand*\@pseudocodeyshift{#1}} 703 | \define@key{pseudocode}{colspace}[]{\renewcommand*\@pseudocodecolspace{#1}} 704 | \define@key{pseudocode}{linenumbering}[on]{\ifthenelse{\equal{#1}{on}}{\renewcommand*\@pseudocodelinenumber{\pcln}}{\renewcommand*\@pseudocodelinenumber{}}} 705 | \define@key{pseudocode}{beforeskip}[]{\renewcommand*\@pseudocodebeforeskip{#1}} 706 | \define@key{pseudocode}{afterskip}[]{\renewcommand*\@pseudocodeafterskip{#1}} 707 | \define@key{pseudocode}{lnstart}[0]{\renewcommand*\@pseudocodelnstart{#1}} 708 | \define@key{pseudocode}{lnstartright}[0]{\renewcommand*\@pseudocodelnstartright{#1}} 709 | \define@key{pseudocode}{colsep}[0em]{\renewcommand*\@pseudocodecolsep{#1}} 710 | \define@key{pseudocode}{headlinecmd}[\hrule]{\renewcommand*\@pseudocodeheadlinecmd{#1}} 711 | \define@key{pseudocode}{headlinesep}[0em]{\renewcommand*\@pseudocodeheadlinesep{#1}} 712 | \define@key{pseudocode}{bodylinesep}[0em]{\renewcommand*\@pseudocodebodylinesep{#1}} 713 | \define@key{pseudocode}{addtolength}[2pt]{\renewcommand*\@pseudocodeaddtolength{#1}} 714 | \define@key{pseudocode}{mode}[math]{% 715 | \ifthenelse{\equal{#1}{text}}{% 716 | \renewcommand*\@pc@modebegin{\begin{varwidth}{\textwidth}% 717 | %introduce line magic for text mode 718 | \let\@pc@lb\\% 719 | \renewcommandx*{\\}[2][1=,2=]{\@pc@modeend\@pc@and \@pseudocodecodeatendline\ifthenelse{\equal{####1}{}}{\@pc@lb}{\@pc@lb[####1]}####2 \@pc@beginnewline}% 720 | \def\pclb{\let\\\@pc@lb\relax\@pc@modeend\\}% 721 | \def\pcolb{\let\\\@pc@lb\relax\@pc@modeend\\}% 722 | }% 723 | \renewcommand*\@pc@modeend{\end{varwidth}} 724 | }{}% 725 | } 726 | \define@key{pseudocode}{nodraft}[true]{\renewcommand*\@pseudocodenodraft{#1}} 727 | \define@key{pseudocode}{keywords}[]{\renewcommand*\@pseudocodekeywords{#1}} 728 | \define@key{pseudocode}{keywordsindent}[]{\renewcommand*\@pseudocodekeywordsindent{#1}} 729 | \define@key{pseudocode}{keywordsunindent}[]{\renewcommand*\@pseudocodekeywordsunindent{#1}} 730 | \define@key{pseudocode}{keywordsuninindent}[]{\renewcommand*\@pseudocodekeywordsuninindent{#1}} 731 | \define@key{pseudocode}{addkeywords}[]{\renewcommand*\@pseudocodeaddkeywords{#1}} 732 | \define@key{pseudocode}{altkeywords}[]{\renewcommand*\@pseudocodealtkeywords{#1}} 733 | \define@key{pseudocode}{syntaxhighlight}[]{\renewcommand*\@pseudocodesyntaxhighlighting{#1}} 734 | 735 | \newcommand{\@pc@modebegin}{} 736 | \newcommand{\@pc@modeend}{} 737 | \newcommand{\@pc@thecontent}{} 738 | 739 | \newcommand{\@pc@syntaxhighlight}[1]{% 740 | \ifthenelse{\equal{\@pseudocodesyntaxhighlighting}{auto}}{% 741 | \def\@shtmp{#1}% first step 742 | \ifthenelse{\equal{\@pseudocodespace}{keep}} 743 | {\edef\@tmpkeywords{\@pseudocodekeywordsspace,\@pseudocodeaddkeywords}} 744 | {\ifthenelse{\equal{\@pseudocodespace}{auto}} 745 | {\edef\@tmpkeywords{\@pseudocodekeywords,\@pseudocodeaddkeywords}} 746 | {\edef\@tmpkeywords{\@pseudocodekeywords,\@pseudocodekeywordsindent,\@pseudocodekeywordsunindent,\@pseudocodekeywordsuninindent,\@pseudocodeaddkeywords}}} 747 | \foreach \@pckw in \@tmpkeywords{% 748 | \ifthenelse{\equal{\@pckw}{}}{}{% 749 | % we are doing a simple strsub and storing the result (globally) in @shtmp 750 | \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 751 | \gdef\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 752 | \@shtmp\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 753 | {\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 754 | \@pc@stringsubstitution\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 755 | {\expandafter\expandafter\expandafter\@shtmp\expandafter\expandafter\expandafter 756 | }\expandafter\expandafter\expandafter{\expandafter\@pckw\expandafter}\expandafter{\expandafter\@pc@highlight\expandafter{\@pckw}}}% 757 | }% alt keywords 758 | }% 759 | \foreach \@pckw in \@pseudocodealtkeywords{% 760 | \ifthenelse{\equal{\@pckw}{}}{}{% 761 | % we are doing a simple strsub and storing the result (globally) in @shtmp 762 | \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 763 | \gdef\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 764 | \@shtmp\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 765 | {\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 766 | \@pc@stringsubstitution\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 767 | {\expandafter\expandafter\expandafter\@shtmp\expandafter\expandafter\expandafter 768 | }\expandafter\expandafter\expandafter{\expandafter\@pckw\expandafter}\expandafter{\expandafter\@pc@althighlight\expandafter{\@pckw}}}% 769 | }% 770 | }% 771 | %%%% 772 | % if automatic spacing 773 | \ifthenelse{\equal{\@pseudocodespace}{auto}} 774 | {% 775 | \foreach \@pckw in \@pseudocodekeywordsindent{% indentation keywords 776 | \ifthenelse{\equal{\@pckw}{}}{}{% 777 | % we are doing a simple strsub and storing the result (globally) in @shtmp 778 | \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 779 | \gdef\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 780 | \@shtmp\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 781 | {\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 782 | \@pc@stringsubstitution\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 783 | {\expandafter\expandafter\expandafter\@shtmp\expandafter\expandafter\expandafter 784 | }\expandafter\expandafter\expandafter{\expandafter\@pckw\expandafter}\expandafter{\expandafter\@pc@highlightindent\expandafter{\@pckw}}}% 785 | }}% 786 | \foreach \@pckw in \@pseudocodekeywordsunindent{% unindentation keywords 787 | \ifthenelse{\equal{\@pckw}{}}{}{% 788 | % we are doing a simple strsub and storing the result (globally) in @shtmp 789 | \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 790 | \gdef\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 791 | \@shtmp\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 792 | {\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 793 | \@pc@stringsubstitution\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 794 | {\expandafter\expandafter\expandafter\@shtmp\expandafter\expandafter\expandafter 795 | }\expandafter\expandafter\expandafter{\expandafter\@pckw\expandafter}\expandafter{\expandafter\@pc@highlightunindent\expandafter{\@pckw}}}% 796 | }}% 797 | \foreach \@pckw in \@pseudocodekeywordsuninindent{% uninindentation keywords 798 | \ifthenelse{\equal{\@pckw}{}}{}{% 799 | % we are doing a simple strsub and storing the result (globally) in @shtmp 800 | \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 801 | \gdef\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 802 | \@shtmp\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 803 | {\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 804 | \@pc@stringsubstitution\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter 805 | {\expandafter\expandafter\expandafter\@shtmp\expandafter\expandafter\expandafter 806 | }\expandafter\expandafter\expandafter{\expandafter\@pckw\expandafter}\expandafter{\expandafter\@pc@highlightuninindent\expandafter{\@pckw}}}% 807 | }}% 808 | }{}% 809 | % return result 810 | \@shtmp% 811 | }{#1}% nothing to highlight 812 | } 813 | 814 | \newcommand{\@pc@highlight}[1]{% 815 | \ifthenelse{\equal{\@pseudocodespace}{keep}} 816 | {\highlightkeyword[]{#1}}% 817 | {\highlightkeyword[]{\@pc@spacesubstitution{#1}{ }{~}}}% 818 | } 819 | 820 | \newcommand{\@pc@highlightindent}[1]{% 821 | \@pc@increaseindent\@pc@highlight{#1}% 822 | } 823 | 824 | \newcommand{\@pc@highlightunindent}[1]{% 825 | \@pc@decreaseindent\@pc@highlight{#1}% 826 | } 827 | 828 | \newcommand{\@pc@highlightuninindent}[1]{% 829 | \@pc@tmpdecreaseindent\@pc@highlight{#1}% 830 | } 831 | 832 | \newcommand{\@pc@althighlight}[1]{% 833 | \ifthenelse{\equal{\@pseudocodespace}{keep}} 834 | {\highlightaltkeyword{#1}}% 835 | {\highlightaltkeyword{\@pc@spacesubstitution{#1}{ }{~}}}% 836 | } 837 | 838 | \newcommand{\@pc@colspace}{} 839 | 840 | %%%%%%%%%%%%%%%%% 841 | % Allow for spacing 842 | \newcommand{\@withinspaces}{false}% 843 | \newcommand{\@keepspaces}{% 844 | \renewcommand{\@withinspaces}{true}\@withspaces% 845 | } 846 | \newcommand{\@pc@endgroupafterpc}{} 847 | 848 | \newcommand*\@pseudocodespace{} 849 | \define@key{pcspace}{space}[]{\ifthenelse{\equal{#1}{keep}}{\@keepspaces}{}\renewcommand*\@pseudocodespace{#1}} 850 | 851 | %%% automatic indentation 852 | \newcounter{@pc@indentationlevel} 853 | \newcommand{\@pc@increaseindent}{\addtocounter{@pc@indentationlevel}{1}} 854 | \newcommand{\@pc@decreaseindent}{\ifthenelse{\equal{\@pseudocodespace}{auto}}{\pcind[-1]}{}\addtocounter{@pc@indentationlevel}{-1}} 855 | \newcommand{\@pc@tmpdecreaseindent}{\ifthenelse{\equal{\@pseudocodespace}{auto}}{\pcind[-1]}{}} 856 | 857 | \newcounter{pccolumncounter} 858 | \setcounter{pccolumncounter}{2} 859 | 860 | % store original halign 861 | \let\@pc@halign\halign% 862 | 863 | %% Check if the pseudocode command is called with an optional argument 864 | \providecommand{\pseudocode}{% 865 | \begingroup% 866 | \renewcommand{\@withinspaces}{false}% 867 | \@ifnextchar[%] 868 | {\@pseudocodeA}% 869 | {\@pseudocode[]}% 870 | } 871 | 872 | \def\@pseudocodeA[#1]{% 873 | \setkeys*{pcspace}{#1}%test if there is a space assignment within the keys .. make the necessary arrangements and call the actual method 874 | \@pseudocode[#1]% 875 | } 876 | 877 | \def\@pseudocode[#1]#2{% 878 | \begingroup% 879 | \setkeys{pseudocode}[space]{#1}%ignore the space key. 880 | % check draft mode and disable syntax highlighting 881 | \@pc@ifdraft{\ifthenelse{\equal{\@pseudocodenodraft}{true}}{}{\renewcommand\@pseudocodesyntaxhighlighting{}}}{}% 882 | % 883 | % 884 | \addtocounter{@pc@global@pc@nestcnt}{1}% 885 | % allow for tikz usage 886 | \@pc@ensureremember% 887 | % 888 | % create tabbing command 889 | \ifcsname \pctabname\endcsname% 890 | \expandafter\renewcommand\csname \pctabname\endcsname{\@pc@modeend&\@pc@colspace\@pc@modebegin}% 891 | \else% 892 | \expandafter\newcommand\csname \pctabname\endcsname{\@pc@modeend&\@pc@colspace\@pc@modebegin}% 893 | \fi% 894 | \ifcsname \pcdbltabname\endcsname% 895 | \expandafter\renewcommand\csname \pcdbltabname\endcsname{\@pc@modeend&&\@pc@colspace\@pc@modebegin}% 896 | \else% 897 | \expandafter\newcommand\csname \pcdbltabname\endcsname{\@pc@modeend&&\@pc@colspace\@pc@modebegin}% 898 | \fi% 899 | % create colspace command if necessary (must be empty for multicolumns 900 | \ifthenelse{\equal{\@pseudocodecolspace}{}} 901 | {} 902 | {\renewcommand{\@pc@colspace}{\hspace{\@pseudocodecolspace}}}% 903 | % 904 | %adjust row width 905 | \addtolength{\jot}{\@pseudocodecodejot}% 906 | % create indent command 907 | \expandafter\let\csname \pcindentname\endcsname\pcind% 908 | % 909 | %store and wrap (do syntax highlighting) argument 910 | \renewcommand{\@pc@thecontent}{\@pc@and@wrap@start\@pc@syntaxhighlight{#2}\@pc@and@wrap@end}% 911 | % 912 | %take care of counters 913 | \stepcounter{@pc@global@pc@cnt}% 914 | \setcounter{pclinenumber}{\@pseudocodelnstart}% 915 | \setcounter{pcrlinenumber}{\@pseudocodelnstartright}% 916 | \setlength{\@pc@minipage@length}{0pt}% 917 | \setlength{\@pc@alt@minipage@length}{0pt}% 918 | \setcounter{@pclinenumbertmp}{\value{pclinenumber}}% 919 | \setcounter{@pcrlinenumbertmp}{\value{pcrlinenumber}}% 920 | %reset column counter 921 | \setcounter{pccolumncounter}{2}% 922 | % 923 | % vertical space 924 | \vspace{\@pseudocodeyshift}% 925 | %\setlength{\abovedisplayskip}{0pt}% 926 | %\setlength{\belowdisplayskip}{0pt}% 927 | %\setlength{\abovedisplayshortskip}{0pt}% 928 | %\setlength{\belowdisplayshortskip}{0pt}% 929 | % 930 | % 931 | % line magic 932 | \ifthenelse{\value{@pc@global@pc@nestcnt}=1}{% 933 | \let\@pc@halign\halign% 934 | \newenvironment{pcmbox}{\let\halign\@pc@halign}{}% 935 | \def\halign{% 936 | \renewcommand{\label}[1]{\ifmeasuring@\else\pc@original@label{####1}\fi}% 937 | \let\@pc@lb\\% 938 | \renewcommandx*{\\}[2][1=,2=]{\@pc@modeend\@pc@and\@pseudocodecodeatendline \ifthenelse{\equal{####1}{}}{\@pc@lb}{\@pc@lb[####1]}####2 \@pc@beginnewline}% 939 | \def\pclb{\let\\\@pc@lb\relax\@pc@modeend\\}% 940 | \@pc@halign}% 941 | }{}% 942 | % 943 | %align column separation 944 | \renewcommand*{\minalignsep}{\@pseudocodecolsep}% 945 | % 946 | % if no width is set compute width and store in circuitlength 947 | \ifthenelse{\equal{\@pseudocodewidth}{}}{% 948 | % compute length of pseudocode 949 | \ifthenelse{\value{@pcsubprogstep}=0}{% 950 | \@settowidthofalign{\@pc@minipage@length}{\@pc@thecontent}% 951 | }{% 952 | \@settowidthofaligned{\@pc@minipage@length}{\@pc@thecontent}% 953 | }% 954 | %compute length of header 955 | \addtolength{\@pc@alt@minipage@length}{\widthof{\@pseudocodehead}}% 956 | % use header length if longer and add some points for good measure 957 | \ifdim\@pc@alt@minipage@length>\@pc@minipage@length% 958 | \setlength{\@pc@minipage@length}{\@pc@alt@minipage@length}% 959 | \fi% 960 | \addtolength{\@pc@minipage@length}{\@pseudocodeaddtolength}% 961 | }{\addtolength{\@pc@minipage@length}{\@pseudocodewidth}}% 962 | % reset counter 963 | \setcounter{pclinenumber}{\value{@pclinenumbertmp}}% 964 | \setcounter{pcrlinenumber}{\value{@pcrlinenumbertmp}}% 965 | \setcounter{@pc@indentationlevel}{0}% 966 | % begin actual output 967 | % 968 | % 969 | %do the actual mini page 970 | \hspace{\@pseudocodexshift}% 971 | \begin{minipage}[\@pseudocodeminipagealign]{\@pc@minipage@length}% 972 | \ifthenelse{\value{@pcsubprogstep}=0}{% 973 | \pc@display@pseudocode{\@pseudocodehead}{\@pc@thecontent}% 974 | }{% if sub procedure 975 | \pc@display@subcode{\@pseudocodehead}{\@pc@thecontent}% 976 | }% 977 | \end{minipage}% 978 | \hspace{\afterpcskip}% 979 | % tikz usage 980 | \@pc@releaseremember% 981 | \addtocounter{@pc@global@pc@nestcnt}{-1}% 982 | \endgroup% 983 | % close spacing and potentially a single group generated by the space tester 984 | \ifthenelse{\equal{\@withinspaces}{true}}{\end@withspaces}{}% 985 | \endgroup% 986 | } 987 | 988 | \newcommand{\@pc@gameheader}[2]{% 989 | \tikz{\gdef\i{\thepcgamecounter}% 990 | \node[anchor=base,#2,inner sep=0.05em,outer sep=0] (gamenode\i) {#1\vphantom{$\sum^A_{A_b}$}}; 991 | \ifthenelse{\equal{\@withinbxgame}{true}} 992 | {\node[draw,anchor=base, above=0.1cm of gamenode\i] (bgamenode\i) {\@bxgameheader\vphantom{$\sum^A_{A_b}$}};} 993 | {}% 994 | }% 995 | } 996 | 997 | \let\pclb\relax 998 | % 999 | \newcommand{\pc@display@pseudocode}[2]{% 1000 | \ifthenelse{\equal{#1}{}}{\vspace{-1\baselineskip}\@pseudocodecodesize}{% 1001 | \ifthenelse{\equal{\@withingame}{true}}{% 1002 | \@pc@gameheader{#1}{}\ifthenelse{\equal{\@pc@secondheader}{true}}{\addtocounter{pcgamecounter}{1}\@pc@gameheader{#1}{draw}}{}% 1003 | \vspace{0.2em}% 1004 | }{#1\vphantom{$\sum^A_{A_b}$}}% 1005 | \vspace{\@pseudocodeheadlinesep}\@pseudocodeheadlinecmd\vspace{\@pseudocodebodylinesep}\@pseudocodecodesize}% 1006 | \begin{flalign*}#2\end{flalign*}% 1007 | } 1008 | 1009 | 1010 | \newcommand{\pc@display@subcode}[2]{% 1011 | \begingroup% 1012 | \ifthenelse{\equal{#1}{}}{}{#1\vphantom{$\sum^A_{A_b}$} % 1013 | \vspace{\@pseudocodeheadlinesep}\@pseudocodeheadlinecmd \vspace{\baselineskip}\vspace{\@pseudocodebodylinesep}}% 1014 | \@pseudocodesubcodesize% 1015 | $\begin{aligned}#2\end{aligned}$% 1016 | \endgroup% 1017 | } 1018 | 1019 | 1020 | \newcommand{\@pc@gettikzwidth}[2]{ % #1 = width, #2 = height 1021 | \pgfextractx{\@tempdima}{\pgfpointdiff{\pgfpointanchor{current bounding box}{south west}} 1022 | {\pgfpointanchor{current bounding box}{north east}}} 1023 | \global#1=\@tempdima 1024 | \pgfextracty{\@tempdima}{\pgfpointdiff{\pgfpointanchor{current bounding box}{south west}} 1025 | {\pgfpointanchor{current bounding box}{north east}}} 1026 | \global#2=\@tempdima 1027 | } 1028 | 1029 | 1030 | %%%%%%%%%%%%%%%%%%% 1031 | % remember pictues 1032 | \newcounter{@pc@remember} 1033 | 1034 | \newcommand{\@pc@ensureremember}{% 1035 | \ifthenelse{\value{@pc@remember}=0}{\tikzstyle{every picture}+=[remember picture]}{}% 1036 | \addtocounter{@pc@remember}{1}} 1037 | 1038 | \newcommand{\@pc@releaseremember}{% 1039 | \addtocounter{@pc@remember}{-1}% 1040 | \ifthenelse{\value{@pc@remember}=0}{\tikzstyle{every picture}-=[remember picture]}{}% 1041 | } 1042 | 1043 | 1044 | %%%%%%%%%%%%%%%%%%% 1045 | % pcimage 1046 | \newenvironment{pcimage}{% 1047 | \begingroup\@pc@ensureremember% 1048 | }{% 1049 | \@pc@releaseremember\endgroup% 1050 | } 1051 | 1052 | \newcommand*\@pcnodecontent{} 1053 | \newcommand*\@pcnodestyle{} 1054 | \newcommand*\@pcnodedraw{} 1055 | \define@key{pcnode}{content}[]{\renewcommand*\@pcnodecontent{#1}} 1056 | \define@key{pcnode}{style}[]{\renewcommand*\@pcnodestyle{#1}} 1057 | \define@key{pcnode}{draw}[]{\renewcommand*\@pcnodedraw{#1}} 1058 | 1059 | \newcommandx*{\pcnode}[2][2=]{% 1060 | \begingroup\setkeys{pcnode}{#2}% 1061 | \tikzset{PCNODE-STYLE/.style/.expand once=\@pcnodestyle}% 1062 | \begin{tikzpicture}[inner sep=0ex,baseline=0pt]% 1063 | \node[PCNODE-STYLE] (#1) {\@pcnodecontent}; % 1064 | \end{tikzpicture}% 1065 | \ifdefempty{\@pcnodedraw}{}{% 1066 | \begin{tikzpicture}[overlay,inner sep=0ex,baseline=0pt]\@pcnodedraw\end{tikzpicture} 1067 | }% 1068 | \endgroup} 1069 | 1070 | \newcommandx*{\pcdraw}[2][2=]{% 1071 | \begin{tikzpicture}[overlay,inner sep=0ex,baseline=0pt,#2] 1072 | #1 1073 | \end{tikzpicture}} 1074 | 1075 | 1076 | %%%%%%%%%%%%%%%%%%%%%%%%% 1077 | % Reductions 1078 | \newcommand{\@bb@lastbox}{} 1079 | \newcommand{\@bb@lastoracle}{} 1080 | \newcommand{\@bb@lastchallenger}{} 1081 | 1082 | 1083 | \newlength{\@bb@message@hoffset} 1084 | \newlength{\@bb@query@hoffset} 1085 | \newlength{\@bb@oraclequery@hoffset} 1086 | \newlength{\@bb@challengerquery@hoffset} 1087 | 1088 | \newcounter{@bb@oracle@cnt} 1089 | \newcounter{@bb@oracle@nestcnt} 1090 | \newcounter{@bb@challenger@cnt} 1091 | \newcounter{@bb@challenger@nestcnt} 1092 | 1093 | \newcounter{@bb@env@nestcnt} 1094 | 1095 | \newcommand{\bbroraclenodenameprefix}{ora-} 1096 | \newcommand{\bbrchallengernodenameprefix}{challenger-} 1097 | \newcommand{\bbrenvnodenameprefix}{env-} 1098 | 1099 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 1100 | % Black Box Reduction Environment 1101 | \newenvironmentx{bbrenv}[3][1=0pt,3=0pt]{% 1102 | \addtocounter{@bb@env@nestcnt}{1}% 1103 | \renewcommand{\@bb@lastbox}{#2}% 1104 | % 1105 | % reset lengths 1106 | \@pc@globalsetlength{\@bb@message@hoffset}{0pt}% 1107 | \@pc@globalsetlength{\@bb@query@hoffset}{0pt}% 1108 | \@pc@globalsetlength{\@bb@oraclequery@hoffset}{0pt}% 1109 | \@pc@globalsetlength{\@bb@challengerquery@hoffset}{0pt}% 1110 | % 1111 | %reset oracle counter and oracle query offset 1112 | \ifthenelse{\value{@bb@oracle@nestcnt}=0} 1113 | {\setcounter{@bb@oracle@cnt}{0}}{}% 1114 | \ifthenelse{\value{@bb@challenger@nestcnt}=0} 1115 | {\setcounter{@bb@challenger@cnt}{0}}{}% 1116 | % 1117 | \def\@bbendskip{#3}% 1118 | \vspace{#1}% 1119 | \ifthenelse{\value{@bb@env@nestcnt}=1} 1120 | {\@pc@ensureremember% 1121 | \begin{tikzpicture} 1122 | }{\tikz\bgroup} 1123 | }{% 1124 | \ifthenelse{\value{@bb@env@nestcnt}=1} 1125 | {\end{tikzpicture}% 1126 | \@pc@releaseremember% 1127 | }{\egroup}% 1128 | \vspace{\@bbendskip}% 1129 | \addtocounter{@bb@env@nestcnt}{-1}% 1130 | % reset lengths 1131 | \@pc@globalsetlength{\@bb@message@hoffset}{0pt}% 1132 | \@pc@globalsetlength{\@bb@query@hoffset}{0pt}% 1133 | \@pc@globalsetlength{\@bb@oraclequery@hoffset}{0pt}% 1134 | \@pc@globalsetlength{\@bb@challengerquery@hoffset}{0pt}% 1135 | } 1136 | 1137 | %%%%%%%%%%%%%%%%%%%%%%%%%%%% 1138 | % black box reduction box 1139 | % option keys 1140 | \newcommand*\bbrboxname{} 1141 | \newcommand*\bbrboxnamepos{right} 1142 | \newcommand*\bbrboxnamestyle{} 1143 | \newcommand*\@bbrboxnamepos{below right=0.5ex and -0.5ex of \@bb@lastbox.north east,anchor=north east} 1144 | \newcommand*\bbrboxabovesep{\baselineskip} 1145 | \newcommand*\@bbrboxnameposoffset{below left=\bbrboxabovesep of phantomname.south west} 1146 | \newcommand*\bbrboxstyle{draw} 1147 | \newcommand*\bbrboxafterskip{} 1148 | \newcommand*\bbrboxminheight{0cm} 1149 | \newcommand*\bbrboxminwidth{2cm} 1150 | \newcommand*\bbrboxxshift{0cm} 1151 | \newcommand*\bbrboxyshift{0cm} 1152 | \define@key{bbrbox}{abovesep}[]{\renewcommand*\bbrboxabovesep{#1}} 1153 | \define@key{bbrbox}{name}[]{\renewcommand*\bbrboxname{#1}} 1154 | \define@key{bbrbox}{namestyle}[]{\renewcommand*\bbrboxnamestyle{#1}} 1155 | \define@key{bbrbox}{namepos}[]{\renewcommand*\bbrboxnamepos{#1}} 1156 | \define@key{bbrbox}{style}[draw]{\renewcommand*\bbrboxstyle{#1}} 1157 | \define@key{bbrbox}{minwidth}[]{\renewcommand*\bbrboxminwidth{#1}} 1158 | \define@key{bbrbox}{addheight}[]{\renewcommand*\bbrboxafterskip{#1}} 1159 | \define@key{bbrbox}{minheight}[]{\renewcommand*\bbrboxminheight{#1}} 1160 | \define@key{bbrbox}{xshift}[]{\renewcommand*\bbrboxxshift{#1}} 1161 | \define@key{bbrbox}{yshift}[]{\renewcommand*\bbrboxyshift{#1}} 1162 | 1163 | 1164 | \NewEnviron{bbrbox}[1][]{% 1165 | \setkeys{bbrbox}{#1}% 1166 | 1167 | \ifthenelse{\equal{\bbrboxnamepos}{center}} 1168 | {\renewcommand{\@bbrboxnamepos}{below=0.5ex of \@bb@lastbox.north,anchor=north}}{} 1169 | \ifthenelse{\equal{\bbrboxnamepos}{left}} 1170 | {\renewcommand{\@bbrboxnamepos}{below=0.5ex of \@bb@lastbox.north west,anchor=north west}}{} 1171 | \ifthenelse{\equal{\bbrboxnamepos}{top right}} 1172 | {\renewcommand{\@bbrboxnamepos}{above=0cm of \@bb@lastbox.north east,anchor=south east}\renewcommand{\@bbrboxnameposoffset}{below left=0cm of phantomname.north west}}{} 1173 | \ifthenelse{\equal{\bbrboxnamepos}{top center}} 1174 | {\renewcommand{\@bbrboxnamepos}{above=0cm of \@bb@lastbox.north,anchor=south}\renewcommand{\@bbrboxnameposoffset}{below left=0cm of phantomname.north west}}{} 1175 | \ifthenelse{\equal{\bbrboxnamepos}{top left}} 1176 | {\renewcommand{\@bbrboxnamepos}{above=0cm of \@bb@lastbox.north west,anchor=south west}\renewcommand{\@bbrboxnameposoffset}{below left=0cm of phantomname.north west}}{} 1177 | \ifthenelse{\equal{\bbrboxnamepos}{middle}} 1178 | {\renewcommand{\@bbrboxnamepos}{above=0.5ex of \@bb@lastbox.base,anchor=south}}{} 1179 | \ifthenelse{\equal{\bbrboxnamepos}{bottom}} 1180 | {\renewcommand{\@bbrboxnamepos}{above=0.5ex of \@bb@lastbox.base,anchor=north}}{} 1181 | 1182 | 1183 | \tikzset{BBRBOXSTYLE/.style/.expand once=\bbrboxstyle}% 1184 | \tikzset{BBRBOXNAMEPOS/.style/.expand once=\@bbrboxnamepos}% 1185 | \tikzset{BBRBOXNAMESTYLE/.style/.expand once=\bbrboxnamestyle}% 1186 | \tikzset{BBRBOXNAMEPOSOFFSET/.style/.expand once=\@bbrboxnameposoffset}% 1187 | 1188 | \node[inner sep=0pt,outer sep=0pt] (\@bb@lastbox-tmpouter) {}; 1189 | \node[inner sep=.3333em,anchor=north,BBRBOXSTYLE,minimum height=\bbrboxminheight,below right=\bbrboxyshift and \bbrboxxshift of \@bb@lastbox-tmpouter] (\@bb@lastbox) \bgroup 1190 | \tikz{ 1191 | \node[inner sep=0pt,outer sep=0pt,minimum height=0cm] (phantomname) {}; %minimum width 1192 | \node[BBRBOXNAMEPOSOFFSET,minimum height=0cm] (\@bb@lastbox-inner) {\begin{varwidth}{2\linewidth}\BODY\end{varwidth}}; 1193 | \ifthenelse{\equal{\bbrboxafterskip}{}}{}{ 1194 | \node[below=0cm of \@bb@lastbox-inner,minimum height=\bbrboxafterskip] {}; 1195 | } 1196 | \node[inner sep=0pt,outer sep=0pt,at=(\@bb@lastbox-inner.south west),minimum height=0cm] () {\phantom{\hspace{\bbrboxminwidth}}}; %minimum width 1197 | } 1198 | \egroup; 1199 | \ifthenelse{\equal{\bbrboxnamepos}{none}} 1200 | {}{\node[BBRBOXNAMEPOS,BBRBOXNAMESTYLE, inner sep=0.2ex, outer sep=0pt, overlay] () {\bbrboxname};} 1201 | } 1202 | 1203 | 1204 | \newcommand*\bbroraclevdistance{\baselineskip} 1205 | \newcommand*\bbroraclehdistance{1.5cm} 1206 | \define@key{bbroracle}{distance}[]{\renewcommand*\bbroraclehdistance{#1}} 1207 | \define@key{bbroracle}{hdistance}[]{\renewcommand*\bbroraclehdistance{#1}} 1208 | \define@key{bbroracle}{vdistance}[]{\renewcommand*\bbroraclevdistance{#1}} 1209 | 1210 | 1211 | % ORACLES 1212 | \newenvironmentx{bbroracle}[2][2=]{% 1213 | \begingroup 1214 | \setkeys{bbroracle}{#2} 1215 | %add to nesting cout 1216 | \addtocounter{@bb@oracle@nestcnt}{1} 1217 | %if first oracle, then put it to the right, else stack them vertically 1218 | \addtocounter{@bb@oracle@cnt}{1} 1219 | \ifthenelse{\value{@bb@oracle@cnt}=1}{ 1220 | \setlength{\@bb@tmplength@b}{\bbroraclevdistance-\baselineskip} 1221 | \node[inner sep=0pt,below right=\@bb@tmplength@b and \bbroraclehdistance of \@bb@lastbox.north east,anchor=north west] (\bbroraclenodenameprefix#1) \bgroup 1222 | }{ 1223 | % compute distance of top of last box to bottom of last oracle 1224 | \coordinate (@bbtmpcoord) at (\@bb@lastbox.north east); 1225 | \path (@bbtmpcoord); 1226 | \pgfgetlastxy{\XCoord}{\YCoordA} 1227 | \coordinate (@bbtmpcoord) at (\bbroraclenodenameprefix \@bb@lastoracle.south west); 1228 | \path (@bbtmpcoord); 1229 | \pgfgetlastxy{\XCoord}{\YCoordB} 1230 | \setlength{\@bb@tmplength@b}{\YCoordA-\YCoordB+\bbroraclevdistance} 1231 | \node[inner sep=0pt,below right=\@bb@tmplength@b and \bbroraclehdistance of \@bb@lastbox.north east,anchor=north west] (\bbroraclenodenameprefix#1) \bgroup 1232 | } 1233 | \global\def\@bb@lastoracle{#1} 1234 | \begin{bbrenv}{#1} 1235 | }{ 1236 | \end{bbrenv} 1237 | \egroup; 1238 | 1239 | \addtocounter{@bb@oracle@nestcnt}{-1} 1240 | \endgroup 1241 | } 1242 | 1243 | 1244 | \newcommand*\bbrchallengerhdistance{1.5cm} 1245 | \newcommand*\bbrchallengervdistance{\baselineskip} 1246 | \define@key{bbrchallenger}{distance}[]{\renewcommand*\bbrchallengerhdistance{#1}} 1247 | \define@key{bbrchallenger}{hdistance}[]{\renewcommand*\bbrchallengerhdistance{#1}} 1248 | \define@key{bbrchallenger}{vdistance}[]{\renewcommand*\bbrchallengervdistance{#1}} 1249 | 1250 | 1251 | % Challenger 1252 | \newenvironmentx{bbrchallenger}[2][2=]{% 1253 | \begingroup% 1254 | \setkeys{bbrchallenger}{#2}% 1255 | %add to nesting cout 1256 | \addtocounter{@bb@challenger@nestcnt}{1}% 1257 | %if first oracle, then put it to the right, else stack them vertically 1258 | \addtocounter{@bb@challenger@cnt}{1}% 1259 | \ifthenelse{\value{@bb@challenger@cnt}=1}{% 1260 | \setlength{\@bb@tmplength@b}{\bbrchallengervdistance-\baselineskip}% 1261 | \node[inner sep=0pt,below left=\@bb@tmplength@b and \bbrchallengerhdistance of \@bb@lastbox.north west,anchor=north east] (\bbrchallengernodenameprefix#1) \bgroup% 1262 | }{% 1263 | \coordinate (@bbtmpcoord) at (\@bb@lastbox.north west);% 1264 | \path (@bbtmpcoord);% 1265 | \pgfgetlastxy{\XCoord}{\YCoordA}% 1266 | \coordinate (@bbtmpcoord) at (\bbrchallengernodenameprefix \@bb@lastchallenger.south east);% 1267 | \path (@bbtmpcoord);% 1268 | \pgfgetlastxy{\XCoord}{\YCoordB}% 1269 | \setlength{\@bb@tmplength@b}{\YCoordA-\YCoordB+\bbrchallengervdistance}% 1270 | \node[inner sep=0pt,below left=\@bb@tmplength@b and \bbrchallengerhdistance of \@bb@lastbox.north west,anchor=north east] (\bbrchallengernodenameprefix#1) \bgroup% 1271 | }% 1272 | \global\def\@bb@lastchallenger{#1} 1273 | \begin{bbrenv}{#1}% 1274 | }{ 1275 | \end{bbrenv}% 1276 | \egroup;% 1277 | \addtocounter{@bb@challenger@nestcnt}{-1}% 1278 | \endgroup% 1279 | \let\msgfrom\bbrchallengerqueryto% 1280 | } 1281 | 1282 | 1283 | \newcommand*\bbrinputlength{0.5cm} 1284 | \newcommand*\bbrinputhoffset{0.5cm} 1285 | \newcommand*\bbrinputbottom{} 1286 | \newcommand*\bbrinputtop{} 1287 | \newcommand*\bbrinputedgestyle{} 1288 | \newcommand*\bbrinputtopstyle{} 1289 | \newcommand*\bbrinputbottomstyle{} 1290 | \newcommand*\bbrinputnodestyle{} 1291 | \newcommand*\bbrinputnodename{} 1292 | \define@key{bbrinput}{length}[]{\renewcommand*\bbrinputlength{#1}} 1293 | \define@key{bbrinput}{hoffset}[]{\renewcommand*\bbrinputhoffset{#1}} 1294 | \define@key{bbrinput}{name}[]{\renewcommand*\bbrinputnodename{#1}} 1295 | \define@key{bbrinput}{top}[]{\renewcommand*\bbrinputtop{#1}} 1296 | \define@key{bbrinput}{bottom}[]{\renewcommand*\bbrinputbottom{#1}} 1297 | 1298 | 1299 | \newcommand{\@bb@inputsetup}[1]{ 1300 | %load keys 1301 | \begingroup % for local keys 1302 | 1303 | \setkeys{bbrinput}{#1}% 1304 | 1305 | \tikzset{BBRINPUT-NODESTYLE/.style/.expand once=\bbrinputedgestyle}% 1306 | \tikzset{BBRINPUT-TOPSTYLE/.style/.expand once=\bbrinputtopstyle}% 1307 | \tikzset{BBRINPUT-BOTTOMSTYLE/.style/.expand once=\bbrinputbottomstyle}% 1308 | \tikzset{BBRINPUT-EDGESTYLE/.style/.expand once=\bbrinputedgestyle}% 1309 | 1310 | } 1311 | 1312 | \newcommand{\@bb@inputfinalize}{ 1313 | \endgroup 1314 | } 1315 | 1316 | \newcommandx*{\bbrinput}[2][2=]{% 1317 | \@bb@inputsetup{#2} 1318 | \ifthenelse{\equal{\bbrinputnodename}{}} 1319 | {\renewcommand{\bbrinputnodename}{\@bb@lastbox-input}}{} 1320 | 1321 | \node[overlay,above right={\bbrinputlength} and {\bbrinputhoffset} of \@bb@lastbox.north west, anchor=south,BBRINPUT-NODESTYLE] (\bbrinputnodename) {#1}; 1322 | \path[->] (\bbrinputnodename.south) edge[BBRINPUT-EDGESTYLE] node[above,anchor=east,BBRINPUT-TOPSTYLE] () {\bbrinputtop} node[below,anchor=west,BBRINPUT-BOTTOMSTYLE] () {\bbrinputbottom} (\bbrinputnodename.south|-\@bb@lastbox.north); 1323 | \@bb@inputfinalize 1324 | } 1325 | 1326 | \newcommandx*{\bbroutput}[2][2=]{% 1327 | \@bb@inputsetup{#2} 1328 | \ifthenelse{\equal{\bbrinputnodename}{}} 1329 | {\renewcommand{\bbrinputnodename}{\@bb@lastbox-output}}{} 1330 | 1331 | \node[overlay,below right={\bbrinputlength} and {\bbrinputhoffset} of \@bb@lastbox.south west, anchor=north] (\bbrinputnodename) {#1}; 1332 | \draw[->] (\bbrinputnodename.north|-\@bb@lastbox.south) -- (\bbrinputnodename.north|-\bbrinputnodename.north); 1333 | \@bb@inputfinalize 1334 | } 1335 | 1336 | \newenvironment{bbrpic}[1][]{% 1337 | \begin{tikzpicture}[overlay,inner sep=0ex,baseline=0pt,#1]% 1338 | }{% 1339 | \end{tikzpicture}} 1340 | 1341 | %%%%%%%%%%% 1342 | % communication 1343 | %temporary lengths 1344 | \newlength{\@bb@com@tmpoffset} 1345 | \newlength{\@bb@tmplength@b} 1346 | \newcommand{\@bb@firstmessageheight}{0.25\baselineskip} 1347 | \newcommand{\@bb@msglength}{1.25cm} 1348 | \newcommand{\@bb@qrylength}{1.5cm} 1349 | 1350 | %keys 1351 | \newcommand*\bbrcomnsidestyle{} 1352 | \newcommand*\bbrcomtopstyle{} 1353 | \newcommand*\bbrcombottomstyle{} 1354 | \newcommand*\bbrcomside{} 1355 | \newcommand*\bbrcomoside{} 1356 | \newcommand*\bbrcomtop{} 1357 | \newcommand*\bbrcombottom{} 1358 | \newcommand*\bbrcomedgestyle{} 1359 | \newcommand*\bbrcomlength{1.25cm} 1360 | \newcommand*\bbrcomtopname{bbrcomtop} 1361 | \newcommand*\bbrcombottomname{bbrcombottom} 1362 | \newcommand*\bbrcomsidename{bbrcomside} 1363 | \newcommand*\bbrcomosidename{bbrcomoside} 1364 | \newcommand*\bbrcombeforeskip{0pt} 1365 | \newcommand*\bbrcomafterskip{0pt} 1366 | \define@key{bbrcom}{sidestyle}[]{\renewcommand*\bbrcomnsidestyle{#1}} 1367 | \define@key{bbrcom}{topstyle}[]{\renewcommand*\bbrcomtopstyle{#1}} 1368 | \define@key{bbrcom}{bottomstyle}[]{\renewcommand*\bbrcombottomstyle{#1}} 1369 | \define@key{bbrcom}{side}[]{\renewcommand*\bbrcomside{#1}} 1370 | \define@key{bbrcom}{oside}[]{\renewcommand*\bbrcomoside{#1}} 1371 | \define@key{bbrcom}{top}[]{\renewcommand*\bbrcomtop{#1}} 1372 | \define@key{bbrcom}{bottom}[]{\renewcommand*\bbrcombottom{#1}} 1373 | \define@key{bbrcom}{edgestyle}[]{\renewcommand*\bbrcomedgestyle{#1}} 1374 | \define@key{bbrcom}{length}[]{\renewcommand*\bbrcomlength{#1}} 1375 | \define@key{bbrcom}{topname}[]{\renewcommand*\bbrcomtopname{#1}} 1376 | \define@key{bbrcom}{bottomname}[]{\renewcommand*\bbrcombottomname{#1}} 1377 | \define@key{bbrcom}{sidename}[]{\renewcommand*\bbrcomsidename{#1}} 1378 | \define@key{bbrcom}{osidename}[]{\renewcommand*\bbrcomosidename{#1}} 1379 | \define@key{bbrcom}{beforeskip}[]{\renewcommand*\bbrcombeforeskip{#1}} 1380 | \define@key{bbrcom}{afterskip}[]{\renewcommand*\bbrcomafterskip{#1}} 1381 | 1382 | \newcommand*\bbrbasenodestyle{} 1383 | \newcommand*\bbrbasenodename{bbrtmpname} 1384 | \define@key{bbrabase}{nodestyle}[]{\renewcommand*\bbrbasenodestyle{#1}} 1385 | \define@key{bbrabase}{nodename}[]{\renewcommand*\bbrbasenodename{#1}} 1386 | 1387 | 1388 | \newcommand{\@bb@comsetup}[3]{ 1389 | %load keys 1390 | \begingroup % for local keys 1391 | 1392 | \setkeys{bbrcom}{#1}% 1393 | 1394 | %set styles 1395 | \tikzset{BBRCOM-SIDESTYLE/.style/.expand once=\bbrcomnsidestyle}% 1396 | \tikzset{BBRCOM-TOPSTYLE/.style/.expand once=\bbrcomtopstyle}% 1397 | \tikzset{BBRCOM-BOTTOMSTYLE/.style/.expand once=\bbrcombottomstyle}% 1398 | \tikzset{BBRCOM-EDGESTYLE/.style/.expand once=\bbrcomedgestyle}% 1399 | 1400 | % increase space 1401 | \ifthenelse{\lengthtest{#2<\@bb@firstmessageheight}} 1402 | {#3{\@bb@firstmessageheight}} 1403 | { 1404 | #3{1.25\baselineskip} 1405 | \ifthenelse{\equal{\bbrcomtop}{}}{}{#3{0.5\baselineskip}} 1406 | } 1407 | 1408 | #3{\bbrcombeforeskip} 1409 | 1410 | \setlength{\@bb@com@tmpoffset}{#2}% 1411 | } 1412 | 1413 | \newcommand{\@bb@comfinalize}[1]{ 1414 | \ifthenelse{\equal{\bbrcombottom}{}}{}{#1{\baselineskip}} 1415 | #1{\bbrcomafterskip} 1416 | \endgroup 1417 | } 1418 | 1419 | \newcommand{\@bbrmsg}[8]{ 1420 | \@bb@comsetup{#1}{#7}{#8} 1421 | % 1422 | \node[#3=\@bb@com@tmpoffset and \bbrcomlength of \@bb@lastbox.#4,anchor=#6,BBRCOM-SIDESTYLE] (\bbrcomsidename) {\bbrcomside}; 1423 | \path[#2] (\bbrcomsidename.#6) edge[BBRCOM-EDGESTYLE] node[above,BBRCOM-TOPSTYLE] (\bbrcomtopname) {\bbrcomtop} node[below,BBRCOM-BOTTOMSTYLE] (\bbrcombottomname) {\bbrcombottom} (\@bb@lastbox.#5|-\bbrcomsidename) node[inner sep=0pt,outer sep=0pt] (\bbrcomosidename) {}; 1424 | % 1425 | \@bb@comfinalize{#8} 1426 | } 1427 | 1428 | \newcommandx{\bbrmsgto}[1]{% 1429 | \@bbrmsg{#1}{->}{below left}{north west}{west}{east}{\@bb@message@hoffset}{\bbrmsgspace} 1430 | } 1431 | \newcommandx{\bbrmsgfrom}[1]{% 1432 | \@bbrmsg{#1}{<-}{below left}{north west}{west}{east}{\@bb@message@hoffset}{\bbrmsgspace} 1433 | } 1434 | \newcommandx{\bbrmsgvdots}{% 1435 | \bbrmsgtxt[xshift=\bbrcomlength/2,beforeskip=-0.5\baselineskip,afterskip=-0.5\baselineskip]{$\vdots$} 1436 | } 1437 | 1438 | 1439 | \newcommandx{\bbrqryto}[1]{% 1440 | \@bbrmsg{#1}{<-}{below right}{north east}{east}{west}{\@bb@query@hoffset}{\bbrqryspace} 1441 | } 1442 | \newcommandx{\bbrqryfrom}[1]{% 1443 | \@bbrmsg{#1}{->}{below right}{north east}{east}{west}{\@bb@query@hoffset}{\bbrqryspace} 1444 | } 1445 | 1446 | \newcommand{\@bbroracleqry}[4]{ 1447 | \@bb@comsetup{#1}{#3}{#4} 1448 | % 1449 | 1450 | \path[#2] (\@bb@lastoracle.north west) -- ++ (0,-\@bb@com@tmpoffset) node[inner sep=0pt,outer sep=0pt] (\bbrcomsidename){\bbrcomside} edge[BBRCOM-EDGESTYLE] node[above,BBRCOM-TOPSTYLE] (\bbrcomtopname) {\bbrcomtop} node[below,BBRCOM-BOTTOMSTYLE] (\bbrcombottomname) {\bbrcombottom} (\@bb@lastbox.east|-\bbrcomsidename) node[inner sep=0pt,outer sep=0pt] (\bbrcomosidename) {\bbrcomoside}; 1451 | % 1452 | \@bb@comfinalize{#4} 1453 | } 1454 | 1455 | \newcommand{\bbroracleqryfrom}[1]{ 1456 | \@bbroracleqry{#1}{->}{\@bb@oraclequery@hoffset}{\bbroracleqryspace} 1457 | } 1458 | 1459 | \newcommand{\bbroracleqryto}[1]{ 1460 | \@bbroracleqry{#1}{<-}{\@bb@oraclequery@hoffset}{\bbroracleqryspace} 1461 | } 1462 | 1463 | \newcommand{\@bbrchallengerqry}[4]{ 1464 | \@bb@comsetup{#1}{#3}{#4} 1465 | % 1466 | 1467 | \path[#2] (\@bb@lastchallenger.north east) -- ++ (0,-\@bb@com@tmpoffset) node[inner sep=0pt,outer sep=0pt] (\bbrcomsidename){\bbrcomside} edge[BBRCOM-EDGESTYLE] node[above,BBRCOM-TOPSTYLE] (\bbrcomtopname) {\bbrcomtop} node[below,BBRCOM-BOTTOMSTYLE] (\bbrcombottomname) {\bbrcombottom} (\@bb@lastbox.west|-\bbrcomsidename) node[inner sep=0pt,outer sep=0pt] (\bbrcomosidename) {\bbrcomoside}; 1468 | % 1469 | \@bb@comfinalize{#4} 1470 | } 1471 | 1472 | \newcommand{\bbrchallengerqryfrom}[1]{ 1473 | \@bbrchallengerqry{#1}{<-}{\@bb@challengerquery@hoffset}{\bbrchallengerqryspace} 1474 | } 1475 | 1476 | \newcommand{\bbrchallengerqryto}[1]{ 1477 | \@bbrchallengerqry{#1}{->}{\@bb@challengerquery@hoffset}{\bbrchallengerqryspace} 1478 | } 1479 | 1480 | 1481 | 1482 | \newcommand*\bbrcomloopleft{} 1483 | \newcommand*\bbrcomloopright{} 1484 | \newcommand*\bbrcomloopcenter{} 1485 | \newcommand*\bbrcomloopangle{50} 1486 | \define@key{bbrcomloop}{left}[]{\renewcommand*\bbrcomloopleft{#1}} 1487 | \define@key{bbrcomloop}{right}[]{\renewcommand*\bbrcomloopright{#1}} 1488 | \define@key{bbrcomloop}{center}[]{\renewcommand*\bbrcomloopcenter{#1}} 1489 | \define@key{bbrcomloop}{angle}[]{\renewcommand*\bbrcomloopangle{#1}} 1490 | 1491 | \newcommand{\bbrloop}[3]{ 1492 | \begingroup % for local keys 1493 | \setkeys{bbrcomloop}{#3}% 1494 | 1495 | \path[->] (#1) edge[bend right=\bbrcomloopangle] node[midway,left] (bbrleft) {\bbrcomloopleft} (#2); 1496 | \path[->] (#2) edge[bend right=\bbrcomloopangle] node[midway,right] (bbrright) {\bbrcomloopright} (#1); 1497 | \node[at=($(bbrleft.north west)!0.5!(bbrright.north east)$),anchor=north]() {\bbrcomloopcenter}; 1498 | 1499 | \endgroup 1500 | } 1501 | 1502 | \newcommand*\bbrintertexthoffset{1.5cm} 1503 | \define@key{bbrintertext}{xshift}[]{\renewcommand*\bbrintertexthoffset{#1}} 1504 | 1505 | \newcommand{\@bb@intertextsetup}[1]{ 1506 | %load keys 1507 | \begingroup % for local keys 1508 | 1509 | \setkeys{bbrcom,bbrabase,bbrintertext}{#1}% 1510 | 1511 | \tikzset{BBRBASE-NODESTYLE/.style/.expand once=\bbrbasenodestyle}% 1512 | } 1513 | 1514 | \newcommand{\@bb@intertextfinalize}[1]{ 1515 | #1{\bbrcomafterskip} 1516 | \endgroup 1517 | } 1518 | 1519 | \newcommand{\@bbrintertext}[6]{ 1520 | \@bb@intertextsetup{#1} 1521 | 1522 | % increase space 1523 | \ifthenelse{\lengthtest{#4<\@bb@firstmessageheight}} 1524 | {#5{\@bb@firstmessageheight}} 1525 | {#5{1\baselineskip}} 1526 | 1527 | \setlength{\@bb@com@tmpoffset}{#4+\bbrcombeforeskip}% 1528 | 1529 | % 1530 | \node[#2=\@bb@com@tmpoffset and \bbrintertexthoffset of \@bb@lastbox.#3,BBRBASE-NODESTYLE] (\bbrbasenodename) {#6}; 1531 | % 1532 | % compute height of node 1533 | \coordinate (@bbtmpcoord) at (\bbrbasenodename.north); 1534 | \path (@bbtmpcoord); 1535 | \pgfgetlastxy{\XCoord}{\YCoordA} 1536 | \coordinate (@bbtmpcoord) at (\bbrbasenodename.south); 1537 | \path (@bbtmpcoord); 1538 | \pgfgetlastxy{\XCoord}{\YCoordB} 1539 | 1540 | % update hoffset 1541 | \setlength{\@bb@tmplength@b}{\YCoordA-\YCoordB} 1542 | #5{\the\@bb@tmplength@b} 1543 | 1544 | \@bb@intertextfinalize{#5} 1545 | } 1546 | 1547 | \newcommand{\bbrmsgtxt}[2][]{ 1548 | \@bbrintertext{#1}{below left}{north west}{\@bb@message@hoffset}{\bbrmsgspace}{#2} 1549 | } 1550 | 1551 | \newcommand{\bbrqrytxt}[2][]{ 1552 | \@bbrintertext{#1}{below right}{north east}{\@bb@query@hoffset}{\bbrqryspace}{#2} 1553 | } 1554 | 1555 | \newcommand{\bbrchallengertxt}[2][]{ 1556 | \begingroup 1557 | \setlength{\@bb@tmplength@b}{\bbrchallengerhdistance/2}% 1558 | \renewcommand{\bbrintertexthoffset}{\the\@bb@tmplength@b}% 1559 | \@bbrintertext{#1}{below left}{north west}{\@bb@challengerquery@hoffset}{\bbrchallengerqryspace}{#2} 1560 | \endgroup 1561 | } 1562 | 1563 | \newcommand{\bbroracletxt}[2][]{ 1564 | \begingroup 1565 | \setlength{\@bb@tmplength@b}{\bbroraclehdistance/2}% 1566 | \renewcommand{\bbrintertexthoffset}{\the\@bb@tmplength@b}% 1567 | \@bbrintertext{#1}{below left}{north west}{\@bb@oraclequery@hoffset}{\bbroracleqryspace}{#2} 1568 | \endgroup 1569 | } 1570 | 1571 | \newcommand{\bbrmsgspace}[1]{ 1572 | \@pc@globaladdtolength{\@bb@message@hoffset}{#1} 1573 | } 1574 | 1575 | \newcommand{\bbrqryspace}[1]{ 1576 | \@pc@globaladdtolength{\@bb@query@hoffset}{#1} 1577 | } 1578 | 1579 | \newcommand{\bbroracleqryspace}[1]{ 1580 | \@pc@globaladdtolength{\@bb@oraclequery@hoffset}{#1} 1581 | } 1582 | 1583 | \newcommand{\bbrchallengerqryspace}[1]{ 1584 | \@pc@globaladdtolength{\@bb@challengerquery@hoffset}{#1} 1585 | } 1586 | 1587 | 1588 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 1589 | % stacking 1590 | \providecommand{\pccenteraboveskip}{0.5\baselineskip plus 0.25\baselineskip minus 0.25\baselineskip} 1591 | \providecommand{\pccenterbelowskip}{0.5\baselineskip plus 0.25\baselineskip minus 0.25\baselineskip} 1592 | \newenvironment{pccenter}{% 1593 | \setlength\topsep{0pt}\setlength\parskip{0pt}% 1594 | \begin{center}\vspace{\pccenteraboveskip}% 1595 | }{% 1596 | \vspace{\pccenterbelowskip}% 1597 | \end{center}} 1598 | 1599 | 1600 | %%%%%%%%%%%%%%%%%%%%% 1601 | % horizontal stacking 1602 | % space before hstacks 1603 | \newlength{\pcbeforehstackskip} 1604 | 1605 | \NewEnviron{pchstack}[1][]{% 1606 | % write out content 1607 | \ifthenelse{\equal{#1}{center}}{% 1608 | \begin{pccenter}\mbox{\hspace{\pcbeforehstackskip}\BODY}\end{pccenter}}{% 1609 | \mbox{\hspace{\pcbeforehstackskip}\BODY}}% 1610 | } 1611 | 1612 | 1613 | %%%%%%%%%%%%%%%%%%%%%%% 1614 | \NewEnviron{pcvstack}[1][]{% 1615 | % display minipage 1616 | \ifthenelse{\equal{#1}{center}}{\begin{pccenter}}{}% 1617 | \begin{varwidth}[t]{2\linewidth}\hspace{0pt}\BODY\end{varwidth}% hspace needed for proper vertical positioning .. strange as it is. 1618 | \ifthenelse{\equal{#1}{center}}{\end{pccenter}}{}% 1619 | } 1620 | 1621 | 1622 | % spacing for stacking 1623 | \newcommand{\pchspace}[1][1em]{\hspace{#1}} 1624 | \newcommand{\pcvspace}[1][\baselineskip]{\par\vspace{#1}} 1625 | 1626 | 1627 | 1628 | 1629 | 1630 | %%%% 1631 | % subprocedures 1632 | \newcounter{@pcsubprogcnt1} 1633 | \newcounter{@pcrsubprogcnt1} 1634 | \newcounter{@pcsubprogcnt2} 1635 | \newcounter{@pcrsubprogcnt2} 1636 | \newcounter{@pcsubprogcnt3} 1637 | \newcounter{@pcrsubprogcnt3} 1638 | \newcounter{@pcsubprogcnt4} 1639 | \newcounter{@pcrsubprogcnt4} 1640 | \newcounter{@pcsubprogcnt5} 1641 | \newcounter{@pcrsubprogcnt5} 1642 | \newcounter{@pcsubprogcnt6} 1643 | \newcounter{@pcrsubprogcnt6} 1644 | \newcounter{@pcsubprogcnt7} 1645 | \newcounter{@pcrsubprogcnt7} 1646 | \newcounter{@pcsubprogcnt8} 1647 | \newcounter{@pcrsubprogcnt8} 1648 | \newcounter{@pcsubprogcnt9} 1649 | \newcounter{@pcrsubprogcnt9} 1650 | \newcounter{@pcsubprogstep} 1651 | 1652 | \newenvironment{subprocedure}{% 1653 | \addtocounter{@pcsubprogstep}{1}% 1654 | % store old counter values 1655 | \setcounter{@pcsubprogcnt\the@pcsubprogstep}{\value{pclinenumber}}% 1656 | \setcounter{@pcrsubprogcnt\the@pcsubprogstep}{\value{pcrlinenumber}}% 1657 | }{% 1658 | \setcounter{pclinenumber}{\value{@pcsubprogcnt\the@pcsubprogstep}}% 1659 | \setcounter{pcrlinenumber}{\value{@pcrsubprogcnt\the@pcsubprogstep}}% 1660 | \addtocounter{@pcsubprogstep}{-1}} 1661 | 1662 | 1663 | %%%%% 1664 | % parameter reordering 1665 | \def\@pseudocodeB#1#2[#3]#4{\setkeys*{pcspace}{#2,#3}\@pseudocode[head={#1#4},#2,#3]} 1666 | \def\@pseudocodeC#1#2#3{\setkeys*{pcspace}{#2}\@pseudocode[head={#1#3},#2]} 1667 | %for no headers 1668 | \def\@pseudocodeE#1#2[#3]{\setkeys*{pcspace}{#2,#3}\@pseudocode[head={#1},#2,#3]} 1669 | \def\@pseudocodeF#1#2{\setkeys*{pcspace}{#2}\@pseudocode[head={#1},#2]} 1670 | 1671 | %%%%%%%%% 1672 | % Define pseudocode command: 1673 | % #1 name 1674 | % #2 code to execute after begingroup 1675 | % #3 head prefix 1676 | % #4 other config 1677 | \newcommand{\createprocedurecommand}[4]{ 1678 | \expandafter\gdef\csname #1\endcsname{% 1679 | \begingroup% 1680 | \renewcommand{\@withinspaces}{false}% 1681 | #2% 1682 | \@ifnextchar[%] 1683 | {\@pseudocodeB{#3}{#4}} 1684 | {\@pseudocodeC{#3}{#4}}% 1685 | }% 1686 | } 1687 | 1688 | \newcommand{\createpseudocodecommand}[4]{ 1689 | \expandafter\gdef\csname #1\endcsname{% 1690 | \begingroup% 1691 | \renewcommand{\@withinspaces}{false}% 1692 | #2% 1693 | \@ifnextchar[%] 1694 | {\@pseudocodeE{#3}{#4}} 1695 | {\@pseudocodeF{#3}{#4}}% 1696 | }% 1697 | } 1698 | 1699 | 1700 | %%%%%% 1701 | % create procedure 1702 | \createprocedurecommand{procedure}{}{}{} 1703 | 1704 | 1705 | 1706 | 1707 | %%% 1708 | % send message 1709 | \newcommand{\pcshortmessageoffset}{0.5cm} 1710 | \newcommand{\pcdefaultmessagelength}{3.5cm} 1711 | \newcommand{\pcdefaultlongmessagelength}{6cm} 1712 | \newcommand{\pcbeforemessageskip}{0pt} 1713 | \newcommand{\pcaftermessageskip}{10pt} 1714 | \newlength{\pcmessagearrow} 1715 | 1716 | \newcommand*\@pcsendmessagelength{\pcdefaultmessagelength} 1717 | \newcommand*\@pcsendmessagecol{} 1718 | \newcommand*\@pcsendmessagewidth{} 1719 | \newcommand*\@pcsendmessagestyle{} 1720 | \newcommand*\@pcsendmessagetop{} 1721 | \newcommand*\@pcsendmessagebottom{} 1722 | \newcommand*\@pcsendmessageright{} 1723 | \newcommand*\@pcsendmessageleft{} 1724 | \newcommand*\@pcsendmessagetopname{t} 1725 | \newcommand*\@pcsendmessagebottomname{b} 1726 | \newcommand*\@pcsendmessagerightname{r} 1727 | \newcommand*\@pcsendmessageleftname{l} 1728 | \newcommand*\@pcsendmessagetopstyle{} 1729 | \newcommand*\@pcsendmessagebottomstyle{} 1730 | \newcommand*\@pcsendmessagerightstyle{} 1731 | \newcommand*\@pcsendmessageleftstyle{} 1732 | \newcommand*\@pcsendmessagebeforeskip{\pcbeforemessageskip} 1733 | \newcommand*\@pcsendmessageafterskip{\pcaftermessageskip} 1734 | \define@key{pcsendmessage}{centercol}[]{\renewcommand*\@pcsendmessagecol{#1}} 1735 | \define@key{pcsendmessage}{width}[]{\renewcommand*\@pcsendmessagewidth{#1}} 1736 | \define@key{pcsendmessage}{style}[]{\renewcommand*\@pcsendmessagestyle{#1}} 1737 | \define@key{pcsendmessage}{length}[]{\renewcommand*\@pcsendmessagelength{#1}} 1738 | \define@key{pcsendmessage}{top}[]{\renewcommand*\@pcsendmessagetop{#1}} 1739 | \define@key{pcsendmessage}{bottom}[]{\renewcommand*\@pcsendmessagebottom{#1}} 1740 | \define@key{pcsendmessage}{right}[]{\renewcommand*\@pcsendmessageright{#1}} 1741 | \define@key{pcsendmessage}{left}[]{\renewcommand*\@pcsendmessageleft{#1}} 1742 | \define@key{pcsendmessage}{topname}[]{\renewcommand*\@pcsendmessagetopname{#1}} 1743 | \define@key{pcsendmessage}{bottomname}[]{\renewcommand*\@pcsendmessagebottomname{#1}} 1744 | \define@key{pcsendmessage}{rightname}[]{\renewcommand*\@pcsendmessagerightname{#1}} 1745 | \define@key{pcsendmessage}{leftname}[]{\renewcommand*\@pcsendmessageleftname{#1}} 1746 | \define@key{pcsendmessage}{topstyle}[]{\renewcommand*\@pcsendmessagetopstyle{#1}} 1747 | \define@key{pcsendmessage}{bottomstyle}[]{\renewcommand*\@pcsendmessagebottomstyle{#1}} 1748 | \define@key{pcsendmessage}{rightstyle}[]{\renewcommand*\@pcsendmessagerightstyle{#1}} 1749 | \define@key{pcsendmessage}{leftstyle}[]{\renewcommand*\@pcsendmessageleftstyle{#1}} 1750 | \define@key{pcsendmessage}{beforeskip}[]{\renewcommand*\@pcsendmessagebeforeskip{#1}} 1751 | \define@key{pcsendmessage}{afterskip}[]{\renewcommand*\@pcsendmessageafterskip{#1}} 1752 | 1753 | 1754 | \newcommand{\@pc@centerincol}[2]{% 1755 | \ifmeasuring@% 1756 | #2% 1757 | \else% 1758 | \makebox[\ifcase\expandafter #1\maxcolumn@widths\fi]{$\displaystyle#2$}% 1759 | \fi% 1760 | } 1761 | 1762 | \newcommand{\centerincol}[1]{\@pc@centerincol{\thepccolumncounter}{#1}} 1763 | 1764 | \newcommand{\@do@sendmessage}[1]{% 1765 | \ifthenelse{\equal{\@pcsendmessagecol}{}}{% 1766 | \ifthenelse{\equal{\@pcsendmessagewidth}{}}{#1}{% we have some width 1767 | \makebox[\@pcsendmessagewidth]{$\displaystyle#1$}% 1768 | }}{%we know the column to center on 1769 | \@pc@centerincol{\@pcsendmessagecol}{#1}% 1770 | }% 1771 | } 1772 | 1773 | \newcommandx*{\sendmessage}[2]{% 1774 | \begingroup\setkeys{pcsendmessage}{#2}% 1775 | \tikzset{PCSENDMSG-PATH-STYLE/.style/.expand once=\@pcsendmessagestyle}% 1776 | \tikzset{PCSENDMSG-TOP-STYLE/.style/.expand once=\@pcsendmessagetopstyle}% 1777 | \tikzset{PCSENDMSG-BOTTOM-STYLE/.style/.expand once=\@pcsendmessagebottomstyle}% 1778 | \tikzset{PCSENDMSG-LEFT-STYLE/.style/.expand once=\@pcsendmessageleftstyle}% 1779 | \tikzset{PCSENDMSG-RIGHT-STYLE/.style/.expand once=\@pcsendmessagerightstyle}% 1780 | %restore halign 1781 | % 1782 | \hspace{\@pcsendmessagebeforeskip}% 1783 | \begin{varwidth}{\linewidth} 1784 | \@do@sendmessage{ 1785 | \begin{tikzpicture}% 1786 | \node[PCSENDMSG-LEFT-STYLE] (\@pcsendmessageleftname) {\@pcsendmessageleft}; 1787 | \node[right=\@pcsendmessagelength of \@pcsendmessageleftname,PCSENDMSG-RIGHT-STYLE] (\@pcsendmessagerightname) {\@pcsendmessageright}; 1788 | \path[#1,PCSENDMSG-PATH-STYLE] (\@pcsendmessageleftname) edge[] node[above,PCSENDMSG-TOP-STYLE] (\@pcsendmessagetopname) {\@pcsendmessagetop} node[below,PCSENDMSG-BOTTOM-STYLE] (\@pcsendmessagebottomname) {\@pcsendmessagebottom} (\@pcsendmessagerightname); 1789 | \end{tikzpicture}% 1790 | }% 1791 | \end{varwidth} 1792 | \hspace{\@pcsendmessageafterskip}% 1793 | \endgroup% 1794 | } 1795 | 1796 | \newcommandx*{\sendmessageright}[2][1=->]{% 1797 | \sendmessage{#1}{#2}% 1798 | } 1799 | 1800 | \newcommandx*{\sendmessageleft}[2][1=<-]{% 1801 | \sendmessage{#1}{#2}% 1802 | } 1803 | 1804 | \WithSuffix\newcommand\sendmessageleft*[2][\pcdefaultmessagelength]{% 1805 | \begingroup% 1806 | \renewcommand{\@pcsendmessagetop}{\let\halign\@pc@halign$\begin{aligned}#2\end{aligned}$}% 1807 | \sendmessage{<-}{length=#1}% 1808 | \endgroup% 1809 | } 1810 | 1811 | 1812 | \WithSuffix\newcommand\sendmessageright*[2][\pcdefaultmessagelength]{% 1813 | \begingroup% 1814 | \renewcommand{\@pcsendmessagetop}{\let\halign\@pc@halign$\begin{aligned}#2\end{aligned}$}% 1815 | \sendmessage{->}{length=#1}% 1816 | \endgroup% 1817 | } 1818 | 1819 | 1820 | 1821 | \DeclareExpandableDocumentCommand{\sendmessagerightx}{O{\pcdefaultlongmessagelength}mO{}m}{% 1822 | \multicolumn{#2}{c}{\ensuremath{\hspace{\pcbeforemessageskip}\xrightarrow[\begin{aligned}#3\end{aligned}]{\mathmakebox[#1]{\begin{aligned}#4\end{aligned}}}\hspace{\pcaftermessageskip}}} 1823 | } 1824 | 1825 | \DeclareExpandableDocumentCommand{\sendmessageleftx}{O{\pcdefaultlongmessagelength}mO{}m}{% 1826 | \multicolumn{#2}{c}{\ensuremath{\hspace{\pcbeforemessageskip}\xleftarrow[\begin{aligned}#3\end{aligned}]{\mathmakebox[#1]{\begin{aligned}#4\end{aligned}}}\hspace{\pcaftermessageskip}}} 1827 | } 1828 | 1829 | %%% 1830 | % Division 1831 | \DeclareExpandableDocumentCommand{\pcintertext}{O{}m}{\intertext{% 1832 | \ifthenelse{\equal{#1}{center}}{\makebox[\linewidth][c]{#2}}{}% 1833 | \ifthenelse{\equal{#1}{dotted}}{\dotfill#2\dotfill}{}% 1834 | \ifthenelse{\equal{#1}{}}{#2}{}% 1835 | }\@pc@beginnewline} 1836 | 1837 | 1838 | 1839 | %%% 1840 | % Games 1841 | % 1842 | \newcounter{pcstartgamecounter} 1843 | 1844 | 1845 | \newcommand*{\pcgameprocedurestyle}{} % define pseudocode arguments for game procedures 1846 | 1847 | \newcommand*{\pcgamename}{\ensuremath{\mathsf{Game}}} 1848 | \newcommand*{\gameprocedurearg}{\ensuremath{(\secpar)}} 1849 | \newcommand*\@pcgameproofgamenr{0} 1850 | \define@key{pcgameproof}{nr}[]{\renewcommand*\@pcgameproofgamenr{#1}} 1851 | \define@key{pcgameproof}{name}[]{\renewcommand*\pcgamename{\ensuremath{#1}}} 1852 | \define@key{pcgameproof}{arg}[]{\renewcommand*\gameprocedurearg{\ensuremath{#1}}} 1853 | 1854 | \newenvironment{gameproof}[1][]{% 1855 | \begingroup% 1856 | \setkeys{pcgameproof}{#1}% 1857 | \@pc@ensureremember% 1858 | \setcounter{pcgamecounter}{\@pcgameproofgamenr}% 1859 | \setcounter{pcstartgamecounter}{\@pcgameproofgamenr}\stepcounter{pcstartgamecounter}% 1860 | }{\@pc@releaseremember\endgroup} 1861 | 1862 | \newcommand{\setgameproceduredefaultstyle}[1]{% 1863 | \createpseudocodecommand{gameprocedure} 1864 | {\addtocounter{pcgamecounter}{1}\renewcommand{\@withingame}{true}} 1865 | {\ensuremath{\pcgamename_{\thepcgamecounter}\gameprocedurearg}} 1866 | {#1} 1867 | } 1868 | \setgameproceduredefaultstyle{} 1869 | 1870 | \def\@bxgame@pseudocodeA[#1]#2#3{\setkeys*{pcspace}{#1}\renewcommand{\@bxgameheader}{$\pcgamename_{#2}$\gameprocedurearg}% 1871 | \@pseudocode[head=\ensuremath{\pcgamename_{\thepcgamecounter}\gameprocedurearg},#1]{#3}} 1872 | \def\@bxgame@pseudocodeB#1#2{\renewcommand{\@bxgameheader}{$\pcgamename_{#1}$\gameprocedurearg}% 1873 | \@pseudocode[head=\ensuremath{\pcgamename_{\thepcgamecounter}\gameprocedurearg}]{#2}} 1874 | 1875 | \newcommand{\bxgameprocedure}{ 1876 | \begingroup% 1877 | \renewcommand{\@withinspaces}{false}% 1878 | \renewcommand{\@withingame}{true}% 1879 | \renewcommand{\@withinbxgame}{true}% 1880 | \stepcounter{pcgamecounter}% 1881 | \@ifnextchar[%] 1882 | {\@bxgame@pseudocodeA} 1883 | {\@bxgame@pseudocodeB}% 1884 | } 1885 | 1886 | \newcommand{\@pc@secondheader}{} 1887 | 1888 | %tbx top boxed 1889 | \createpseudocodecommand{tbxgameprocedure} 1890 | {\addtocounter{pcgamecounter}{1}\renewcommand{\@withingame}{true}%% 1891 | \renewcommand{\@pc@secondheader}{true}} 1892 | {\ensuremath{\pcgamename_{\thepcgamecounter}\gameprocedurearg}} 1893 | {} 1894 | 1895 | 1896 | \newcommand*\@pcgamehopnodestyle{} 1897 | \newcommand*\@pcgamehopedgestyle{bend left} 1898 | \newcommand*\@pcgamehoppathestyle{} 1899 | \newcommand*\@pcgamehophint{} 1900 | \newcommand*\@pcgamehophintbelow{} 1901 | \newcommand*\@pcgamehopinhint{} 1902 | \newcommand*\@pcgamehoplength{1.5cm} 1903 | \define@key{pcgamehop}{nodestyle}[]{\renewcommand*\@pcgamehopnodestyle{#1}} 1904 | \define@key{pcgamehop}{edgestyle}[]{\renewcommand*\@pcgamehopedgestyle{#1}} 1905 | \define@key{pcgamehop}{pathstyle}[]{\renewcommand*\@pcgamehoppathestyle{#1}} 1906 | \define@key{pcgamehop}{hint}[]{\renewcommand*\@pcgamehophint{#1}} 1907 | \define@key{pcgamehop}{belowhint}[]{\renewcommand*\@pcgamehophintbelow{#1}} 1908 | \define@key{pcgamehop}{inhint}[]{\renewcommand*\@pcgamehopinhint{#1}} 1909 | \define@key{pcgamehop}{length}[]{\renewcommand*\@pcgamehoplength{#1}} 1910 | 1911 | 1912 | \newcommand{\@pc@setupgamehop}[1]{ 1913 | \begingroup\setkeys{pcgamehop}{#1}% 1914 | \tikzset{GAMEHOP-PATH-STYLE/.style/.expand once=\@pcgamehoppathestyle}% 1915 | \tikzset{GAMEHOP-NODE-STYLE/.style/.expand once=\@pcgamehopnodestyle}% 1916 | \tikzset{GAMEHOP-EDGE-STYLE/.style/.expand once=\@pcgamehopedgestyle}% 1917 | } 1918 | 1919 | \newcommand{\@pc@finalizegamehop}{ 1920 | \endgroup 1921 | } 1922 | 1923 | \newcommandx*{\addgamehop}[3]{% 1924 | \begingroup% 1925 | \ifthenelse{#1<#2}% 1926 | {\ifthenelse{\equal{\@withingamedescription}{true}}% 1927 | {\renewcommand*\@pcgamehopedgestyle{bend right=20}\renewcommand*\@pcgamehopnodestyle{rotate=90}}{}% 1928 | }% 1929 | {\renewcommand*\@pcgamehopedgestyle{bend right}}% 1930 | \@pc@setupgamehop{#3}% 1931 | \begin{tikzpicture}[overlay]% 1932 | \ifthenelse{#1<#2}{% 1933 | \path[->,GAMEHOP-PATH-STYLE] (gamenode#1) edge[GAMEHOP-EDGE-STYLE] node[above,GAMEHOP-NODE-STYLE] {\@pcgamehophint} 1934 | node[below,GAMEHOP-NODE-STYLE] {\@pcgamehophintbelow} (gamenode#2); 1935 | }{% 1936 | \path[->,GAMEHOP-PATH-STYLE] (bgamenode#1) edge[GAMEHOP-EDGE-STYLE] node[above,GAMEHOP-NODE-STYLE] {\@pcgamehophint} 1937 | node[above,GAMEHOP-NODE-STYLE] {\@pcgamehophintbelow} (bgamenode#2); 1938 | }% 1939 | \end{tikzpicture}% 1940 | \@pc@finalizegamehop% 1941 | \endgroup% 1942 | } 1943 | \newcommandx*{\addstartgamehop}[2][1=\thepcstartgamecounter]{% 1944 | \@pc@setupgamehop{#2} 1945 | \begin{tikzpicture}[overlay] 1946 | \node[left=\@pcgamehoplength of gamenode#1] (tmpgamenode0) {}; 1947 | \path[->,GAMEHOP-PATH-STYLE] (tmpgamenode0) edge[GAMEHOP-EDGE-STYLE] node[above,GAMEHOP-NODE-STYLE] {\@pcgamehophint} 1948 | node[below,GAMEHOP-NODE-STYLE] {\@pcgamehophintbelow} (gamenode#1); 1949 | \end{tikzpicture} 1950 | \@pc@finalizegamehop 1951 | } 1952 | \newcommandx*{\addendgamehop}[2][1=\thepcgamecounter]{% 1953 | \@pc@setupgamehop{#2} 1954 | \begin{tikzpicture}[overlay] 1955 | \node[right=\@pcgamehoplength of gamenode#1] (tmpgamenode#1) {}; 1956 | \path[->,GAMEHOP-PATH-STYLE] (gamenode#1) edge[GAMEHOP-EDGE-STYLE] node[above,GAMEHOP-NODE-STYLE] {\@pcgamehophint} 1957 | node[below,GAMEHOP-NODE-STYLE] {\@pcgamehophintbelow} (tmpgamenode#1); 1958 | \end{tikzpicture} 1959 | \@pc@finalizegamehop 1960 | } 1961 | \newcommandx*{\addbxgamehop}[3]{% 1962 | \@pc@setupgamehop{#3} 1963 | \begin{tikzpicture}[overlay] 1964 | \path[->,GAMEHOP-PATH-STYLE] (bgamenode#1) edge[GAMEHOP-EDGE-STYLE] node[above,GAMEHOP-NODE-STYLE]] {\@pcgamehophint} 1965 | node[below,GAMEHOP-NODE-STYLE] {\@pcgamehophintbelow} (bgamenode#2); 1966 | \end{tikzpicture} 1967 | \@pc@finalizegamehop 1968 | } 1969 | \newcommandx*{\addloopgamehop}[2][1=\thepcgamecounter]{% 1970 | \@pc@setupgamehop{#2} 1971 | \begin{tikzpicture}[overlay] 1972 | \node (looptemp1) [right=0.5cm of gamenode#1] {}; 1973 | \draw[->,GAMEHOP-PATH-STYLE] (gamenode#1) -- (looptemp1|-gamenode#1) -- node[right,GAMEHOP-NODE-STYLE] {\@pcgamehophint} 1974 | node[left,GAMEHOP-NODE-STYLE] {\@pcgamehophintbelow} (looptemp1|-bgamenode#1)-- (bgamenode#1); 1975 | \end{tikzpicture} 1976 | \@pc@finalizegamehop 1977 | } 1978 | 1979 | 1980 | %%%%%%%% 1981 | % game description 1982 | \newenvironment{gamedescription}[1][]{% 1983 | \begingroup% 1984 | \setkeys{pcgameproof}{#1} 1985 | \renewcommand{\@withingamedescription}{true}% 1986 | \@pc@ensureremember% 1987 | \setcounter{pcgamecounter}{\@pcgameproofgamenr}% 1988 | \setcounter{pcstartgamecounter}{\@pcgameproofgamenr}\stepcounter{pcstartgamecounter}% 1989 | \begin{description}% 1990 | }{\end{description}\@pc@releaseremember\endgroup} 1991 | 1992 | \newcommandx*{\describegame}[1][1=]{% 1993 | \addtocounter{pcgamecounter}{1}% 1994 | \item[% 1995 | \pcdraw{ 1996 | \gdef\i{\thepcgamecounter}% 1997 | \node[inner sep=0.0em,outer sep=0, xshift=-1ex, yshift=0.5ex] (gamenode\i) {}; 1998 | }% 1999 | \ensuremath{\pcgamename_{\thepcgamecounter}\gameprocedurearg}:]% 2000 | \begingroup\setkeys{pcgamehop}{#1}% 2001 | \ifthenelse{\equal{}{\@pcgamehophint}} 2002 | {} 2003 | {\hspace{-0.7ex}\pcdraw{%the -0.7ex is a horrible hack to fix a whitespace issue with tikz (see http://tex.stackexchange.com/questions/22873/tikzpicture-with-overlay-takes-up-space 2004 | \tikzset{GAMEHOP-PATH-STYLE/.style/.expand once=\@pcgamehoppathestyle}% 2005 | \tikzset{GAMEHOP-NODE-STYLE/.style/.expand once=\@pcgamehopnodestyle}% 2006 | \draw[->,GAMEHOP-PATH-STYLE] (gamenode\thepcgamecounter) --++ (0,-\@pcgamehoplength) node[midway,above,xshift=-1mm,rotate=90,GAMEHOP-NODE-STYLE] {\@pcgamehophint}; 2007 | }}% 2008 | \ifthenelse{\equal{}{\@pcgamehopinhint}} 2009 | {} 2010 | {\hspace{-0.7ex}\pcdraw{%the -0.7ex is a horrible hack to fix a whitespace issue with tikz (see http://tex.stackexchange.com/questions/22873/tikzpicture-with-overlay-takes-up-space 2011 | \tikzset{GAMEHOP-PATH-STYLE/.style/.expand once=\@pcgamehoppathestyle}% 2012 | \tikzset{GAMEHOP-NODE-STYLE/.style/.expand once=\@pcgamehopnodestyle}% 2013 | \draw[<-,GAMEHOP-PATH-STYLE] (gamenode\thepcgamecounter) --++ (0,\@pcgamehoplength) node[midway,above,xshift=-1mm,rotate=90,GAMEHOP-NODE-STYLE] {\@pcgamehopinhint}; 2014 | }% 2015 | }% 2016 | \endgroup% 2017 | } 2018 | 2019 | 2020 | 2021 | 2022 | 2023 | 2024 | %%%%%%%% 2025 | % basic pseudocode constants 2026 | 2027 | \newcommand{\highlightkeyword}[2][\ ]{\ensuremath{\mathbf{#2}}#1} 2028 | \newcommand{\highlightaltkeyword}[1]{\ensuremath{\mathsf{#1}}} 2029 | 2030 | \newcommand{\pcglobvar}{\highlightkeyword{gbl}} 2031 | \newcommand{\pcnew}{\highlightkeyword{new}} 2032 | \newcommand{\pcwhile}{\@pc@increaseindent\highlightkeyword{while}} 2033 | \newcommand{\pcendwhile}{\@pc@decreaseindent\highlightkeyword{endwhile}} 2034 | \newcommandx*{\pcdo}[2][1=\ ,2=]{#1\highlightkeyword[#2]{do}} 2035 | \newcommandx*{\pcif}[1][1=\ ]{\@pc@increaseindent\highlightkeyword[#1]{if}} 2036 | \newcommandx*{\pcunless}[1][1=\ ]{\@pc@increaseindent\highlightkeyword[#1]{unless}} 2037 | \newcommandx*{\pcelse}[1][1=\ ]{\@pc@tmpdecreaseindent\highlightkeyword[#1]{else}} 2038 | \newcommandx*{\pcelseif}[1][1=\ ]{\@pc@tmpdecreaseindent\highlightkeyword[#1]{else if}} 2039 | \newcommand{\pcfi}{\@pc@decreaseindent\highlightkeyword{fi}} 2040 | \newcommand{\pcendif}{\@pc@decreaseindent\highlightkeyword{endif}} 2041 | \newcommand{\pcendfor}{\@pc@decreaseindent\highlightkeyword{endfor}} 2042 | \newcommandx*{\pcthen}[2][1=\ ,2=\ ]{#1\highlightkeyword[#2]{then}} 2043 | \newcommand{\pcreturn}{\highlightkeyword{return}} 2044 | \newcommandx*{\pcin}[2][1=\ ,2=]{#1\highlightkeyword[#2]{in}} 2045 | \newcommandx*{\pcfor}[1][1=\ ]{\@pc@increaseindent\highlightkeyword[#1]{for}} 2046 | \newcommand{\pcrepeat}[1]{\@pc@increaseindent\ensuremath{\highlightkeyword{repeat} #1\ \highlightkeyword{times}}} 2047 | \newcommand{\pcrepeatuntil}[2]{\ensuremath{\highlightkeyword{repeat}\ #1\ \highlightkeyword{until}\ #2}} 2048 | \newcommand{\pcforeach}{\@pc@increaseindent\highlightkeyword{foreach}} 2049 | \newcommand{\pcendforeach}{\@pc@decreaseindent\highlightkeyword{endforeach}} 2050 | \newcommand{\pcuntil}{\@pc@decreaseindent\highlightkeyword{until}} 2051 | \newcommand{\pccontinue}{\highlightkeyword{continue}} 2052 | \newcommandx*{\pcfalse}[2][1=\ ,2=]{\highlightkeyword[#2]{false}} 2053 | \newcommandx*{\pctrue}[2][1=\ ,2=]{\highlightkeyword[#2]{true}} 2054 | \newcommandx*{\pcnull}[2][1=\ ,2=]{\highlightkeyword[#2]{null}} 2055 | \newcommand{\pccomment}[1]{{\mbox{/\!\!/ } \text{\scriptsize#1}}} 2056 | \newcommand{\pcdone}{\highlightkeyword{done}} 2057 | \newcommand{\pcparse}{\highlightkeyword{parse}} 2058 | \newcommand{\pcfail}{\highlightkeyword{fail}} 2059 | \newcommand{\pcabort}{\highlightkeyword{abort}} 2060 | 2061 | %%% 2062 | % highlighting 2063 | \definecolor{gamechangecolor}{gray}{0.90} 2064 | \newcommand{\gamechange}[2][gamechangecolor]{% 2065 | {\setlength{\fboxsep}{0pt}\colorbox{#1}{\ifmmode$\displaystyle#2$\else#2\fi}}% 2066 | } 2067 | 2068 | %%% 2069 | % boxing 2070 | \newcommand{\pcbox}[1]{% 2071 | {\setlength{\fboxsep}{3pt}\fbox{$\displaystyle#1$}} 2072 | } 2073 | 2074 | \endinput -------------------------------------------------------------------------------- /cryptocode.ins: -------------------------------------------------------------------------------- 1 | % cryptocode.ins generated using makedtx version 1.2 2020/6/20 20:14 2 | \input docstrip 3 | 4 | \preamble 5 | 6 | cryptocode.dtx 7 | Copyright 2021 Mittelbach, Arno 8 | 9 | This work may be distributed and/or modified under the 10 | conditions of the LaTeX Project Public License, either version 1.3 11 | of this license or (at your option) any later version. 12 | The latest version of this license is in 13 | http://www.latex-project.org/lppl.txt 14 | and version 1.3 or later is part of all distributions of LaTeX 15 | version 2005/12/01 or later. 16 | 17 | This work has the LPPL maintenance status `maintained'. 18 | 19 | The Current Maintainer of this work is Mittelbach, Arno. 20 | 21 | This work consists of the files cryptocode.dtx and cryptocode.ins and the derived files 22 | cryptocode.sty and cryptocode.pdf. 23 | 24 | \endpreamble 25 | 26 | \askforoverwritefalse 27 | 28 | \generate{\file{cryptocode.sty}{\usepreamble\defaultpreamble 29 | \usepostamble\defaultpostamble\from{cryptocode.dtx}{cryptocode.sty,package}} 30 | } 31 | 32 | \endbatchfile 33 | -------------------------------------------------------------------------------- /cryptocode.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arnomi/cryptocode/946af0d9432ae1906b056e610b6366f0e4b00b85/cryptocode.pdf -------------------------------------------------------------------------------- /ctan_packages/v0.40/cryptocode.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arnomi/cryptocode/946af0d9432ae1906b056e610b6366f0e4b00b85/ctan_packages/v0.40/cryptocode.tar.gz -------------------------------------------------------------------------------- /ctan_packages/v0.44/cryptocode.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arnomi/cryptocode/946af0d9432ae1906b056e610b6366f0e4b00b85/ctan_packages/v0.44/cryptocode.tar.gz --------------------------------------------------------------------------------