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