diff options
author | Karl Berry <karl@freefriends.org> | 2015-03-28 21:41:27 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2015-03-28 21:41:27 +0000 |
commit | 66d4bb2ab2031db51d7818a691dc267fd3991d79 (patch) | |
tree | 52d3a6e71c87eeca3dffa016cd60025ae56eb7c8 /Master/texmf-dist/tex/latex/cryptocode | |
parent | 719d9d5c5bf005dd81b357ada574bf794b34a7d2 (diff) |
cryptocode (28mar15)
git-svn-id: svn://tug.org/texlive/trunk@36659 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/cryptocode')
-rw-r--r-- | Master/texmf-dist/tex/latex/cryptocode/cryptocode.sty | 418 |
1 files changed, 338 insertions, 80 deletions
diff --git a/Master/texmf-dist/tex/latex/cryptocode/cryptocode.sty b/Master/texmf-dist/tex/latex/cryptocode/cryptocode.sty index 1e1b843dfce..72fc9e90b12 100644 --- a/Master/texmf-dist/tex/latex/cryptocode/cryptocode.sty +++ b/Master/texmf-dist/tex/latex/cryptocode/cryptocode.sty @@ -21,6 +21,10 @@ \def\hi{Hello, this is Arno's crypto code package. } \let\myDate\date +\RequirePackage{amsmath} +\RequirePackage{mathtools} +%\usepackage{l3tl-analysis} % uncomment for debugging + %%% % option modes \newif\ifpc@orderofgrowth @@ -98,6 +102,7 @@ \providecommand\NN{\mathbb{N}} \providecommand\ZZ{\mathbb{Z}} + \providecommand\CC{\mathbb{C}} \providecommand\QQ{\mathbb{Q}} \providecommand\RR{\mathbb{R}} \providecommand\PP{\mathbb{P}} @@ -255,11 +260,9 @@ \ProcessOptions\relax %amsfonts -\RequirePackage{amsmath} \ifpc@amsfonts \RequirePackage{amsfonts} \fi -\RequirePackage{mathtools} \RequirePackage{xcolor} \RequirePackage{calc} \RequirePackage{tikz} @@ -271,6 +274,7 @@ \RequirePackage{forloop} \RequirePackage{array} \RequirePackage{xparse} +\RequirePackage{l3regex} \RequirePackage{pbox} \RequirePackage{varwidth} \RequirePackage{suffix} @@ -278,12 +282,13 @@ \RequirePackage{etex} \RequirePackage{etextools} \RequirePackage{environ} -\RequirePackage{xstring} -\RequirePackage{xspace} +%\RequirePackage{xspace} \RequirePackage{xkeyval} \ifpc@advantage - \newcommandx*{\advantage}[3][3=(\secpar)]{\ensuremath{\mathsf{Adv}^{\mathrm{\MakeLowercase{#1}}}_{#2}#3}} + \newcommand{\pcadvantagesuperstyle}[1]{\mathrm{\MakeLowercase{#1}}} + \newcommand{\pcadvantagesubstyle}[1]{#1} + \newcommandx*{\advantage}[3][3=(\secpar)]{\ensuremath{\mathsf{Adv}^{\pcadvantagesuperstyle{#1}}_{\pcadvantagesubstyle{#2}}#3}} \fi \ifpc@primitives @@ -293,7 +298,7 @@ \providecommand{\nizk}{\pcalgostyle{NIZK}} % hash - \providecommand{\hash}{\pcalgostyle{H}} + \renewcommand{\hash}{\pcalgostyle{H}} \providecommand{\gash}{\pcalgostyle{G}} \providecommand{\fash}{\pcalgostyle{F}} @@ -368,6 +373,9 @@ \settowidth{#1}{$\begin{aligned}#2\end{aligned}$} } +% check for draft mode +\def\@pc@ifdraft{\ifdim\overfullrule>\z@ + \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi} % run stuff in an empty box \newcommand{\@pcexecuteblindly}[1]{% @@ -414,6 +422,55 @@ %\global\let\label\relax } +\newcounter{@spacecounter} +\providecommand{\spacetoindent}{1} +\newenvironment{@withspaces} + {\obeyspaces\begingroup\lccode`~=` \lowercase{\endgroup\let~}\ } + {} + +%%%%%%%%%%%%%% +% a latex3 string substitution. +\ExplSyntaxOn +\tl_new:N \l_pc_strsub_input_tl +\tl_new:N \l_pc_strsub_search_tl +\tl_new:N \l_pc_strsub_replace_tl + +\NewDocumentCommand{\@pc@stringsubstitution}{mmm} + { + \tl_set:Nn \l_pc_strsub_input_tl { #1 } + \tl_set:Nn \l_pc_strsub_search_tl { #2 } + \tl_set:Nn \l_pc_strsub_replace_tl { #3 } +% \tl_show_analysis:N \l_pc_strsub_input_tl % uncomment for debugging +% \tl_show_analysis:N \l_pc_strsub_search_tl % uncomment for debugging +% \tl_show_analysis:N \l_pc_strsub_replace_tl % uncomment for debugging + \regex_replace_all:nnN + { (\W)\u{l_pc_strsub_search_tl} } %only match if keyword does not have a word character preceding + { \1\u{l_pc_strsub_replace_tl} } + \l_pc_strsub_input_tl + % \tl_show_analysis:N \l_tmpa_tl % uncomment for debugging + \tl_use:N \l_pc_strsub_input_tl + } + + % same as \@pc@stringsubstitution but without requiring the extra non word character + \NewDocumentCommand{\@pc@spacesubstitution}{mmm} + { + \tl_set:Nn \l_pc_strsub_input_tl { #1 } + \tl_set:Nn \l_pc_strsub_search_tl { #2 } + \tl_set:Nn \l_pc_strsub_replace_tl { #3 } +% \tl_show_analysis:N \l_pc_strsub_input_tl % uncomment for debugging +% \tl_show_analysis:N \l_pc_strsub_search_tl % uncomment for debugging +% \tl_show_analysis:N \l_pc_strsub_replace_tl % uncomment for debugging + \regex_replace_all:nnN + { \u{l_pc_strsub_search_tl} } + { \u{l_pc_strsub_replace_tl} } + \l_pc_strsub_input_tl + % \tl_show_analysis:N \l_tmpa_tl % uncomment for debugging + \tl_use:N \l_pc_strsub_input_tl + } + + +\ExplSyntaxOff + %%%%%%%% % line numbers %%%%%%%% @@ -472,7 +529,7 @@ \newlength{\@pc@alt@minipage@length} % backward games -\newif\ifbxgame +\newcommand{\@withinbxgame}{false} \newcommand{\@bxgameheader}{} @@ -482,7 +539,14 @@ \newlength{\@pc@length@tmp@width@vstack} -\newcommand{\@pc@beginnewline}{\@pc@and\@pseudocodelinenumber\@pc@modebegin} +\newcommand{\@pc@beginnewline}{% +\@pc@and\@pseudocodelinenumber% +%checkspace +\ifthenelse{\equal{\@pseudocodespace}{auto}}% +{\expandafter\pcind\expandafter[\value{@pc@indentationlevel}]}% +{}% +%beginmode +\@pc@modebegin} \newcommand{\@pc@and}{&} \newcommand{\@pc@and@wrap@end}{\@pc@modeend&} \newcommand{\@pc@and@wrap@start}{\@pc@beginnewline} @@ -501,8 +565,26 @@ \newcommand*\@pseudocodelnstart{0} \newcommand*\@pseudocodelnstartright{0} \newcommand*\@pseudocodesyntaxhighlighting{} -\newcommand*\@pseudocodekeywords{for ,foreach ,return ,{ do }, in ,new ,if ,null ,null,true ,true,until ,{ to },false ,false,{ then },repeat ,else ,done ,done,fi } +\newcommand*\@pseudocodenodraft{false} + +\newcommand*\@pseudocodecolsep{0em} +\newcommand*\@pseudocodeaddtolength{2pt} + +%%%%%%%%%%%%%% +% Define keywords for the automatic syntax highlighting +% the accompanying add provides additional keywords. +% The space version for automatic spacing +\newcommand*\@pseudocodekeywordsindent{for ,foreach ,if ,repeat ,while } +\newcommand*\@pseudocodekeywordsunindent{endfor,endforeach,fi,endif,until ,endwhile} +\newcommand*\@pseudocodekeywordsuninindent{else if,elseif, else} +\newcommand*\@pseudocodekeywords{return ,{ do }, in ,new ,null ,null,true ,true,{ to },false ,false,{ then },done ,done} \newcommand*\@pseudocodeaddkeywords{} +\newcommand*\@pseudocodealtkeywords{} +\begin{@withspaces} +\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} +\end{@withspaces} + + \define@key{pseudocode}{head}[]{\renewcommand*\@pseudocodehead{#1}} \define@key{pseudocode}{width}[]{\renewcommand*\@pseudocodewidth{#1}} \define@key{pseudocode}{xshift}[]{\renewcommand*\@pseudocodexshift{#1}} @@ -511,6 +593,8 @@ \define@key{pseudocode}{afterskip}[]{\renewcommand*\@pseudocodeafterskip{#1}} \define@key{pseudocode}{lnstart}[0]{\renewcommand*\@pseudocodelnstart{#1}} \define@key{pseudocode}{lnstartright}[0]{\renewcommand*\@pseudocodelnstartright{#1}} +\define@key{pseudocode}{colsep}[0em]{\renewcommand*\@pseudocodecolsep{#1}} +\define@key{pseudocode}{addtolength}[2pt]{\renewcommand*\@pseudocodeaddtolength{#1}} \define@key{pseudocode}{mode}[math]{% \ifthenelse{\equal{#1}{text}}{% \renewcommand*\@pc@modebegin{\begin{varwidth}{\textwidth}% @@ -522,8 +606,13 @@ \renewcommand*\@pc@modeend{\end{varwidth}} }{}% } +\define@key{pseudocode}{nodraft}[true]{\renewcommand*\@pseudocodenodraft{#1}} \define@key{pseudocode}{keywords}[]{\renewcommand*\@pseudocodekeywords{#1}} +\define@key{pseudocode}{keywordsindent}[]{\renewcommand*\@pseudocodekeywordsindent{#1}} +\define@key{pseudocode}{keywordsunindent}[]{\renewcommand*\@pseudocodekeywordsunindent{#1}} +\define@key{pseudocode}{keywordsuninindent}[]{\renewcommand*\@pseudocodekeywordsuninindent{#1}} \define@key{pseudocode}{addkeywords}[]{\renewcommand*\@pseudocodeaddkeywords{#1}} +\define@key{pseudocode}{altkeywords}[]{\renewcommand*\@pseudocodealtkeywords{#1}} \define@key{pseudocode}{syntaxhighlight}[]{\renewcommand*\@pseudocodesyntaxhighlighting{#1}} \newcommand{\@pc@modebegin}{} @@ -532,35 +621,144 @@ \newcommand{\@pc@syntaxhighlight}[1]{% \ifthenelse{\equal{\@pseudocodesyntaxhighlighting}{auto}}{% -\saveexploremode\expandarg % suppress expansions made by xstring \def\@shtmp{#1}% first step -\edef\@tmpkeywords{\@pseudocodekeywords,\@pseudocodeaddkeywords}% +\ifthenelse{\equal{\@pseudocodespace}{keep}} + {\edef\@tmpkeywords{\@pseudocodekeywordsspace,\@pseudocodeaddkeywords}} + {\ifthenelse{\equal{\@pseudocodespace}{auto}} + {\edef\@tmpkeywords{\@pseudocodekeywords,\@pseudocodeaddkeywords}} + {\edef\@tmpkeywords{\@pseudocodekeywords,\@pseudocodekeywordsindent,\@pseudocodekeywordsunindent,\@pseudocodekeywordsuninindent,\@pseudocodeaddkeywords}}} \foreach \@pckw in \@tmpkeywords{% \ifthenelse{\equal{\@pckw}{}}{}{% -\StrSubstitute{\@pckw}{ }{PCXXMYBREAKSPACE}[\@pckwspace]% take care of spaces -\StrSubstitute{\@shtmp}{\@pckw}{\expandafter\@pc@highlight\expandafter{\@pckwspace}}[\@shtmpA]% -\global\let\@shtmp\@shtmpA% +% we are doing a simple strsub and storing the result (globally) in @shtmp +\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter + \gdef\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter + \@shtmp\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter + {\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter + \@pc@stringsubstitution\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter + {\expandafter\expandafter\expandafter\@shtmp\expandafter\expandafter\expandafter + }\expandafter\expandafter\expandafter{\expandafter\@pckw\expandafter}\expandafter{\expandafter\@pc@highlight\expandafter{\@pckw}}}% +}% alt keywords +}% +\foreach \@pckw in \@pseudocodealtkeywords{% +\ifthenelse{\equal{\@pckw}{}}{}{% +% we are doing a simple strsub and storing the result (globally) in @shtmp +\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter + \gdef\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter + \@shtmp\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter + {\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter + \@pc@stringsubstitution\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter + {\expandafter\expandafter\expandafter\@shtmp\expandafter\expandafter\expandafter + }\expandafter\expandafter\expandafter{\expandafter\@pckw\expandafter}\expandafter{\expandafter\@pc@althighlight\expandafter{\@pckw}}}% +}% +}% +%%%% +% if automatic spacing +\ifthenelse{\equal{\@pseudocodespace}{auto}} +{% +\foreach \@pckw in \@pseudocodekeywordsindent{% indentation keywords +\ifthenelse{\equal{\@pckw}{}}{}{% +% we are doing a simple strsub and storing the result (globally) in @shtmp +\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter + \gdef\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter + \@shtmp\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter + {\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter + \@pc@stringsubstitution\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter + {\expandafter\expandafter\expandafter\@shtmp\expandafter\expandafter\expandafter + }\expandafter\expandafter\expandafter{\expandafter\@pckw\expandafter}\expandafter{\expandafter\@pc@highlightindent\expandafter{\@pckw}}}% }}% -\restoreexploremode\@shtmp% -}{#1}% +\foreach \@pckw in \@pseudocodekeywordsunindent{% unindentation keywords +\ifthenelse{\equal{\@pckw}{}}{}{% +% we are doing a simple strsub and storing the result (globally) in @shtmp +\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter + \gdef\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter + \@shtmp\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter + {\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter + \@pc@stringsubstitution\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter + {\expandafter\expandafter\expandafter\@shtmp\expandafter\expandafter\expandafter + }\expandafter\expandafter\expandafter{\expandafter\@pckw\expandafter}\expandafter{\expandafter\@pc@highlightunindent\expandafter{\@pckw}}}% +}}% +\foreach \@pckw in \@pseudocodekeywordsuninindent{% uninindentation keywords +\ifthenelse{\equal{\@pckw}{}}{}{% +% we are doing a simple strsub and storing the result (globally) in @shtmp +\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter + \gdef\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter + \@shtmp\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter + {\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter + \@pc@stringsubstitution\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter + {\expandafter\expandafter\expandafter\@shtmp\expandafter\expandafter\expandafter + }\expandafter\expandafter\expandafter{\expandafter\@pckw\expandafter}\expandafter{\expandafter\@pc@highlightuninindent\expandafter{\@pckw}}}% +}}% +}{}% +% return result +\@shtmp% +}{#1}% nothing to highlight } \newcommand{\@pc@highlight}[1]{% -\StrSubstitute{#1}{PCXXMYBREAKSPACE}{}[\@pctmpname]% -\StrSubstitute{#1}{PCXXMYBREAKSPACE}{ }[\@pctmporg]% -\StrSubstitute{#1}{PCXXMYBREAKSPACE}{~}[\@pctmpres]% -\ifcsname dohighlight\@pctmpname\endcsname% -\csname dohighlight\@pctmpname\endcsname{\@pctmporg}% -\else\pseudocodeconstant[]{\@pctmpres}\fi% +\ifthenelse{\equal{\@pseudocodespace}{keep}} + {\highlightkeyword[]{#1}}% + {\highlightkeyword[]{\@pc@spacesubstitution{#1}{ }{~}}}% +} + +\newcommand{\@pc@highlightindent}[1]{% +\@pc@increaseindent\@pc@highlight{#1}% +} + +\newcommand{\@pc@highlightunindent}[1]{% +\@pc@decreaseindent\@pc@highlight{#1}% +} + +\newcommand{\@pc@highlightuninindent}[1]{% +\@pc@tmpdecreaseindent\@pc@highlight{#1}% +} + +\newcommand{\@pc@althighlight}[1]{% +\ifthenelse{\equal{\@pseudocodespace}{keep}} + {\highlightaltkeyword{#1}}% + {\highlightaltkeyword{\@pc@spacesubstitution{#1}{ }{~}}}% +} + +%%%%%%%%%%%%%%%%% +% Allow for spacing +\newcommand{\@withinspaces}{false}% +\newcommand{\@keepspaces}{% +\renewcommand{\@withinspaces}{true}\@withspaces% } +\newcommand{\@pc@endgroupafterpc}{} + +\newcommand*\@pseudocodespace{} +\define@key{pcspace}{space}[]{\ifthenelse{\equal{#1}{keep}}{\@keepspaces}{}\renewcommand*\@pseudocodespace{#1}} + +%%% automatic indentation +\newcounter{@pc@indentationlevel} +\newcommand{\@pc@increaseindent}{\addtocounter{@pc@indentationlevel}{1}} +\newcommand{\@pc@decreaseindent}{\ifthenelse{\equal{\@pseudocodespace}{auto}}{\pcind[-1]}{}\addtocounter{@pc@indentationlevel}{-1}} +\newcommand{\@pc@tmpdecreaseindent}{\ifthenelse{\equal{\@pseudocodespace}{auto}}{\pcind[-1]}{}} % store original halign \let\@pc@halign\halign% +%% Check if the pseudocode command is called with an optional argument +\providecommand{\pseudocode}{% +\begingroup% +\renewcommand{\@withinspaces}{false}% +\@ifnextchar[%] + {\@pseudocodeA}% + {\@pseudocode[]}% +} + +\def\@pseudocodeA[#1]{% +\setkeys*{pcspace}{#1}%test if there is a space assignment within the keys .. make the necessary arrangements and call the actual method +\@pseudocode[#1]% +} -\providecommand{\pseudocode}[2][]{% +\def\@pseudocode[#1]#2{% \begingroup% -\setkeys{pseudocode}{#1}% +\setkeys{pseudocode}[space]{#1}%ignore the space key. +% check draft mode and disable syntax highlighting +\@pc@ifdraft{\ifthenelse{\equal{\@pseudocodenodraft}{true}}{}{\renewcommand\@pseudocodesyntaxhighlighting{}}}{}% +% +% \addtocounter{@pc@global@pc@nestcnt}{1}% % allow for tikz usage \@pc@ensureremember% @@ -578,7 +776,8 @@ \fi% % create indent command \expandafter\let\csname \pcindentname\endcsname\pcind% -% wrap content if necessary +% +%store and wrap (do syntax highlighting) argument \renewcommand{\@pc@thecontent}{\@pc@and@wrap@start\@pc@syntaxhighlight{#2}\@pc@and@wrap@end}% % %take care of counters @@ -603,7 +802,7 @@ }{}% % %align column separation -\renewcommand*{\minalignsep}{0em}% +\renewcommand*{\minalignsep}{\@pseudocodecolsep}% % % if no width is set compute width and store in circuitlength \ifthenelse{\equal{\@pseudocodewidth}{}}{% @@ -619,11 +818,12 @@ \ifdim\@pc@alt@minipage@length>\@pc@minipage@length% \setlength{\@pc@minipage@length}{\@pc@alt@minipage@length}% \fi% -\addtolength{\@pc@minipage@length}{5pt}% +\addtolength{\@pc@minipage@length}{\@pseudocodeaddtolength}% }{\addtolength{\@pc@minipage@length}{\@pseudocodewidth}}% % reset counter \setcounter{pclinenumber}{\value{@pclinenumbertmp}}% \setcounter{pcrlinenumber}{\value{@pcrlinenumbertmp}}% +\setcounter{@pc@indentationlevel}{0}% % begin actual output % % @@ -641,6 +841,9 @@ \@pc@releaseremember% \addtocounter{@pc@global@pc@nestcnt}{-1}% \endgroup% +% close spacing and potentially a single group generated by the space tester +\ifthenelse{\equal{\@withinspaces}{true}}{\end@withspaces}{}% +\endgroup% } @@ -650,9 +853,11 @@ \ifthenelse{\equal{#1}{}}{\vspace{-0.8\baselineskip}\pcsize}{% \tikz{\gdef\i{\thepcgamecounter}% \node[anchor=base] (gamenode\i) {\hspace{-2pt}#1\vphantom{$\sum^A_{A_b}$}}; -\ifbxgame\node[draw,anchor=base, above=0.1cm of gamenode\i] (bgamenode\i) {\@bxgameheader\vphantom{$\sum^A_{A_b}$}};\fi % +\ifthenelse{\equal{\@withinbxgame}{true}} + {\node[draw,anchor=base, above=0.1cm of gamenode\i] (bgamenode\i) {\@bxgameheader\vphantom{$\sum^A_{A_b}$}};} + {}% }\vspace{-0.1\baselineskip}\hrule\small\vspace{-0.5\baselineskip}}% -\begin{flalign*} #2 \end{flalign*} +\begin{flalign*}#2\end{flalign*}% } @@ -660,7 +865,7 @@ \begingroup% \ifthenelse{\equal{#1}{}}{}{#1\vphantom{$\sum^A_{A_b}$}\hrule \vspace{0.2\baselineskip}}% \pcsubsize% -$\begin{aligned} #2 \end{aligned}$% +$\begin{aligned}#2\end{aligned}$% \endgroup% } @@ -815,7 +1020,16 @@ $\begin{aligned} #2 \end{aligned}$% \ifthenelse{\value{@bb@oracle@cnt}=1}{ \node[below right=0cm and \bbroracledistance of \@bb@lastbox.north east] (\bbroraclenodenameprefix#1) \bgroup }{ - \node[below=0.05cm of \bbroraclenodenameprefix \@bb@lastoracle.south west, anchor=north west] (\bbroraclenodenameprefix#1) \bgroup +% \node[below0.05cm of \bbroraclenodenameprefix \@bb@lastoracle.south west, anchor=north west] (\bbroraclenodenameprefix#1) \bgroup +% compute distance of top of last box to bottom of last oracle + \coordinate (@bbtmpcoord) at (\@bb@lastbox.north east); + \path (@bbtmpcoord); + \pgfgetlastxy{\XCoord}{\YCoordA} + \coordinate (@bbtmpcoord) at (\bbroraclenodenameprefix \@bb@lastoracle.south west); + \path (@bbtmpcoord); + \pgfgetlastxy{\XCoord}{\YCoordB} + \setlength{\@bb@tmplength@b}{\YCoordA-\YCoordB} + \node[below right=\@bb@tmplength@b and \bbroracledistance of \@bb@lastbox.north east] (\bbroraclenodenameprefix#1) \bgroup } \global\def\@bb@lastoracle{#1} \begin{bbrenv}{#1} @@ -1106,21 +1320,46 @@ $\begin{aligned} #2 \end{aligned}$% \addtocounter{@pcsubprogstep}{-1}} +%%%%% +% parameter reordering +\def\@pseudocodeB#1#2[#3]#4{\setkeys*{pcspace}{#2,#3}\@pseudocode[head={#1#4},#2,#3]} +\def\@pseudocodeC#1#2#3{\setkeys*{pcspace}{#2}\@pseudocode[head={#1#3},#2]} +%for no headers +\def\@pseudocodeE#1#2[#3]{\setkeys*{pcspace}{#2,#3}\@pseudocode[head={#1},#2,#3]} +\def\@pseudocodeF#1#2{\setkeys*{pcspace}{#2}\@pseudocode[head={#1},#2]} + +%%%%%%%%% +% Define pseudocode command: +% #1 name +% #2 code to execute after begingroup +% #3 head prefix +% #4 other config +\newcommand{\createprocedurecommand}[4]{ + \expandafter\gdef\csname #1\endcsname{% +\begingroup% +\renewcommand{\@withinspaces}{false}% +#2% +\@ifnextchar[%] + {\@pseudocodeB{#3}{#4}} + {\@pseudocodeC{#3}{#4}}% +}% +} -%%% some basic procedure commands -\newcommand{\pcmainname}{\textsc{Main }} -\newcommand{\pcalgorithmname}{\textsc{Algo. }} -\newcommand{\pccircuitname}{\textsc{Circ. }} -\newcommand{\pcprogramname}{\textsc{Prog. }} -\newcommand{\pcprotocolname}{\textsc{Protocol }} +\newcommand{\createpseudocodecommand}[4]{ + \expandafter\gdef\csname #1\endcsname{% +\begingroup% +\renewcommand{\@withinspaces}{false}% +#2% +\@ifnextchar[%] + {\@pseudocodeE{#3}{#4}} + {\@pseudocodeF{#3}{#4}}% +}% +} -\providecommand{\procedure}[3][]{\pseudocode[head={#2},#1]{#3}} -\providecommand{\mainprocedure}[3][]{\pseudocode[head={\pcmainname#2},#1]{#3}} -\providecommand{\algorithm}[3][]{\pseudocode[head={\pcalgorithmname#2},#1]{#3}} -\providecommand{\circuit}[3][]{\pseudocode[head={\pccircuitname#2},#1]{#3}} -\providecommand{\program}[3][]{\pseudocode[head={\pcprogramname#2},#1]{#3}} -\providecommand{\protocol}[3][]{\pseudocode[head={\pcprotocolname#2},#1]{#3}} +%%%%%% +% create procedure +\createprocedurecommand{procedure}{}{}{} %%% % send message @@ -1267,28 +1506,41 @@ $\begin{aligned} #2 \end{aligned}$% \newenvironment{gameproof}[1][]{% \begingroup% \setkeys{pcgameproof}{#1} -\bxgamefalse% \@pc@ensureremember% \setcounter{pcgamecounter}{\@pcgameproofgamenr}% \setcounter{pcstartgamecounter}{\@pcgameproofgamenr}\stepcounter{pcstartgamecounter}% }{\@pc@releaseremember\endgroup} -\newcommand{\gameprocedure}[2][]{\stepcounter{pcgamecounter}% -\pseudocode[head=\ensuremath{\pcgamename_{\thepcgamecounter}\gameprocedurearg},#1]{#2}} +\createpseudocodecommand{gameprocedure} + {\stepcounter{pcgamecounter}} + {\ensuremath{\pcgamename_{\thepcgamecounter}\gameprocedurearg}} + {} + +\def\@bxgame@pseudocodeA[#1]#2#3{\setkeys*{pcspace}{#1}\renewcommand{\@bxgameheader}{$\pcgamename_{#2}$\gameprocedurearg}% +\@pseudocode[head=\ensuremath{\pcgamename_{\thepcgamecounter}\gameprocedurearg},#1]{#3}} +\def\@bxgame@pseudocodeB#1#2{\renewcommand{\@bxgameheader}{$\pcgamename_{#1}$\gameprocedurearg}% +\@pseudocode[head=\ensuremath{\pcgamename_{\thepcgamecounter}\gameprocedurearg}]{#2}} -\newcommand{\bxgameprocedure}[3][]{% -\renewcommand{\@bxgameheader}{$\pcgamename_{#2}$\gameprocedurearg}% -\bxgametrue% +\newcommand{\bxgameprocedure}{ +\begingroup% +\renewcommand{\@withinspaces}{false}% +\renewcommand{\@withinbxgame}{true}% \stepcounter{pcgamecounter}% -\pseudocode[head=\ensuremath{\pcgamename_{\thepcgamecounter}\gameprocedurearg},#1]{#3}% -\bxgamefalse} +\@ifnextchar[%] + {\@bxgame@pseudocodeA} + {\@bxgame@pseudocodeB}% +} -\newcounter{@pc@game@tmpcnt@a} -\newcommand{\tbxgameprocedure}[2][]{\addtocounter{pcgamecounter}{1}% -\setcounter{@pc@game@tmpcnt@a}{\value{pcgamecounter}+1} -\pseudocode[head={\ensuremath{\pcgamename_{\thepcgamecounter}\gameprocedurearg}% -\ \setlength{\fboxsep}{3pt}\protect\fbox{\ensuremath{\pcgamename_{\thepcgamecounter}\gameprocedurearg}}},#1]{#2}% -\addtocounter{pcgamecounter}{1}} +%tbx top boxed +\createpseudocodecommand{tbxgameprocedure} + {\addtocounter{pcgamecounter}{1}% +\xdef\@pcfirstgamename{\thepcgamecounter}% +\addtocounter{pcgamecounter}{1}% +\xdef\@pcsecgamename{\thepcgamecounter}% +} + {\ensuremath{\pcgamename_{\@pcfirstgamename}\gameprocedurearg}% +\ \setlength{\fboxsep}{3pt}\protect\fbox{\ensuremath{\pcgamename_{\@pcsecgamename}\gameprocedurearg}}} +{} \newcommand*\@pcgamehopnodestyle{} @@ -1365,30 +1617,36 @@ $\begin{aligned} #2 \end{aligned}$% %%%%%%%% % basic pseudocode constants -\newcommand{\pseudocodeconstant}[2][\ ]{\ensuremath{\mathbf{#2}}#1} - -\newcommand{\pcglobvar}{\pseudocodeconstant{gbl}} -\newcommand{\pcnew}{\pseudocodeconstant{new}} -\newcommand{\pcwhile}{\pseudocodeconstant{while}} -\newcommandx*{\pcdo}[2][1=\ ,2=]{#1\pseudocodeconstant[#2]{do}} -\newcommand{\pcif}{\pseudocodeconstant{if}} -\newcommand{\pcelse}{\pseudocodeconstant{else}} -\newcommand{\pcfi}{\pseudocodeconstant{fi}} -\newcommandx*{\pcthen}[2][1=\ ,2=]{#1\pseudocodeconstant[#2]{then}} -\newcommand{\pcreturn}{\pseudocodeconstant{return}} -\newcommandx*{\pcin}[2][1=\ ,2=]{#1\pseudocodeconstant[#2]{in}} -\newcommand{\pcfor}{\pseudocodeconstant{for}} -\newcommand{\pcrepeat}[1]{\ensuremath{\pseudocodeconstant{repeat} #1\ \pseudocodeconstant{times}}} -\newcommand{\pcrepeatuntil}[2]{\ensuremath{\pseudocodeconstant{repeat}\ #1\ \pseudocodeconstant{until}\ #2}} -\newcommand{\pcforeach}{\pseudocodeconstant{for each}} -\newcommand{\pcuntil}{\pseudocodeconstant{until}} -\newcommand{\pccontinue}{\pseudocodeconstant{continue}} -\newcommand{\pcfalse}{\pseudocodeconstant{false}} -\newcommand{\pctrue}{\pseudocodeconstant{true}} -\newcommand{\pcnull}{\pseudocodeconstant{null}} +\newcommand{\highlightkeyword}[2][\ ]{\ensuremath{\mathbf{#2}}#1} +\newcommand{\highlightaltkeyword}[1]{\ensuremath{\mathsf{#1}}} + +\newcommand{\pcglobvar}{\highlightkeyword{gbl}} +\newcommand{\pcnew}{\highlightkeyword{new}} +\newcommand{\pcwhile}{\@pc@increaseindent\highlightkeyword{while}} +\newcommand{\pcendwhile}{\@pc@decreaseindent\highlightkeyword{endwhile}} +\newcommandx*{\pcdo}[2][1=\ ,2=]{#1\highlightkeyword[#2]{do}} +\newcommand{\pcif}{\@pc@increaseindent\highlightkeyword{if}} +\newcommand{\pcelse}{\@pc@tmpdecreaseindent\highlightkeyword{else}} +\newcommand{\pcelseif}{\@pc@tmpdecreaseindent\highlightkeyword{else if}} +\newcommand{\pcfi}{\@pc@decreaseindent\highlightkeyword{fi}} +\newcommand{\pcendif}{\@pc@decreaseindent\highlightkeyword{endif}} +\newcommand{\pcendfor}{\@pc@decreaseindent\highlightkeyword{endfor}} +\newcommandx*{\pcthen}[2][1=\ ,2=]{#1\highlightkeyword[#2]{then}} +\newcommand{\pcreturn}{\highlightkeyword{return}} +\newcommandx*{\pcin}[2][1=\ ,2=]{#1\highlightkeyword[#2]{in}} +\newcommand{\pcfor}{\@pc@increaseindent\highlightkeyword{for}} +\newcommand{\pcrepeat}[1]{\@pc@increaseindent\ensuremath{\highlightkeyword{repeat} #1\ \highlightkeyword{times}}} +\newcommand{\pcrepeatuntil}[2]{\ensuremath{\highlightkeyword{repeat}\ #1\ \highlightkeyword{until}\ #2}} +\newcommand{\pcforeach}{\@pc@increaseindent\highlightkeyword{foreach}} +\newcommand{\pcendforeach}{\@pc@decreaseindent\highlightkeyword{endforeach}} +\newcommand{\pcuntil}{\@pc@decreaseindent\highlightkeyword{until}} +\newcommand{\pccontinue}{\highlightkeyword{continue}} +\newcommand{\pcfalse}{\highlightkeyword{false}} +\newcommand{\pctrue}{\highlightkeyword{true}} +\newcommand{\pcnull}{\highlightkeyword{null}} \newcommand{\pccomment}[1]{{\mbox{/\!\!/ } \text{\scriptsize#1}}} -\newcommand{\pcdone}{\pseudocodeconstant{done}} -\newcommand{\pcparse}{\pseudocodeconstant{parse}} +\newcommand{\pcdone}{\highlightkeyword{done}} +\newcommand{\pcparse}{\highlightkeyword{parse}} %%% % highlighting |