texlive[49131] Master/texmf-dist: cryptocode (11nov18)

commits+karl at tug.org commits+karl at tug.org
Sun Nov 11 22:55:56 CET 2018


Revision: 49131
          http://tug.org/svn/texlive?view=revision&revision=49131
Author:   karl
Date:     2018-11-11 22:55:56 +0100 (Sun, 11 Nov 2018)
Log Message:
-----------
cryptocode (11nov18)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/cryptocode/README
    trunk/Master/texmf-dist/doc/latex/cryptocode/cryptocode.pdf
    trunk/Master/texmf-dist/doc/latex/cryptocode/cryptocode.tex
    trunk/Master/texmf-dist/tex/latex/cryptocode/cryptocode.sty

Modified: trunk/Master/texmf-dist/doc/latex/cryptocode/README
===================================================================
--- trunk/Master/texmf-dist/doc/latex/cryptocode/README	2018-11-11 21:55:38 UTC (rev 49130)
+++ trunk/Master/texmf-dist/doc/latex/cryptocode/README	2018-11-11 21:55:56 UTC (rev 49131)
@@ -1,8 +1,10 @@
-The cryptocode bundle provides commands and commands for easily typesetting
-pseudocode and simple protocols as well as environments for visualizing 
-game-based proofs and black-box reductions as often used within the cryptographic
-community.
+The cryptocode package provides a set of macros to ease the typesetting of 
+pseudocode, algorithms and protocols. In addition it comes with a wide range 
+of tools to typeset cryptographic papers (hence the name).
+This includes simple predefined commands for concepts such as 
+a security parameter or advantage terms but also flexible and powerful
+environments to layout game-based proofs or black-box reductions.
 
 The cryptocode bundle is licensed under the LaTeX Project Public License
 
- -- Arno Mittelbach <mail at arno-mittelbach.de>  22 Apr 2015
\ No newline at end of file
+ -- Arno Mittelbach <mail at arno-mittelbach.de>  11 Nov 2018
\ No newline at end of file

Modified: trunk/Master/texmf-dist/doc/latex/cryptocode/cryptocode.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/latex/cryptocode/cryptocode.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/cryptocode/cryptocode.tex	2018-11-11 21:55:38 UTC (rev 49130)
+++ trunk/Master/texmf-dist/doc/latex/cryptocode/cryptocode.tex	2018-11-11 21:55:56 UTC (rev 49131)
@@ -1,4 +1,4 @@
- %% Copyright 2015 Arno Mittelbach
+%% Copyright 2018 Arno Mittelbach
   %
   % This work may be distributed and/or modified under the
   % conditions of the LaTeX Project Public License, either version 1.3
@@ -45,7 +45,6 @@
 
 \usepackage{url}
 
-
 \usetikzlibrary{shapes.callouts}
 
 \usepackage{listings}
@@ -107,10 +106,11 @@
 
 \begin{abstract}
 \thispagestyle{empty}
-The cryptocode package is targeted at cryptographers typesetting their results in \LaTeX. 
-It provides various predefined commands for different topics in cryptography.
-In particular it provides an easy interface to write pseudocode, protocols, game based proofs 
-and draw black-box reductions.
+The cryptocode package provides a set of macros to ease the typesetting of 
+pseudocode, algorithms and protocols (such as the one below). In addition it comes with a wide range of tools to typeset cryptographic papers (hence the name).
+This includes simple predefined commands for concepts such as 
+a security parameter $\secparam$ or advantage terms $\advantage{prf}{\adv,\prf} = \negl$ but also flexible and powerful
+environments to layout game-based proofs or black-box reductions.
 
 \vspace{2em}
 \begin{center}
@@ -139,10 +139,12 @@
 \newpage
 
 \pagenumbering{arabic}
+
+
 \chapter{Cryptocode by Example}
 
-Cryptocode is a \LaTeX package to ease the writing of cryptographic papers. It provides mechanisms
-for writing pseudocode, protocols, game-based proofs and black-box reductions. In addition it comes
+The cryptocode package provides a set of commands to ease the typesetting of 
+pseudocode, protocols, game-based proofs and black-box reductions. In addition it comes
 with a large number of predefined commands. In this chapter we present the various features of 
 cryptocode by giving small examples. But first, let's load the package
 
@@ -422,7 +424,8 @@
 quite some control over how things should look like. Additionally, as you can specify node names
 (for example the outer box in the next example is called \enquote{A}) you can easily extend the pictures
 by using plain TIKZ commands.
-\begin{bbrenv}{A}
+
+\begin{bbrenv}[1cm]{A}[0.5cm]
 	\begin{bbrbox}[name=Reduction]
 	\pseudocode{
 		\text{Do something} \\
@@ -689,13 +692,17 @@
 \begin{lstlisting}
 \entropy{X}
 \minentropy{X}
+\condentropy{X}{Y=5}
 \condminentropy{X}{Y=5}
+\condavgminentropy(X}{Y=5}
 \end{lstlisting}
 This yields 
 \begin{align*}
 & \entropy{X} \\
 & \minentropy{X} \\
-& \condminentropy{X}{Y=5}
+& \condentropy{X}{Y=5} \\
+& \condminentropy{X}{Y=5} \\
+& \condavgminentropy{X}{Y=5}
 \end{align*}
 
 \section{Sets}
@@ -766,7 +773,11 @@
 \begin{tabular}{l l l}
 \textbf{Command} & \textbf{Description} & \textbf{Result} \\\hline
 \lstinline$\AND$ & Logical AND & $\AND$  \\
+\lstinline$\NAND$ & Logical NAND & $\NAND$  \\
 \lstinline$\OR$ & Logical OR & $\OR$  \\
+\lstinline$\NOR$ & Logical NOR & $\NOR$  \\
+\lstinline$\XOR$ & Logical XOR & $\XOR$  \\
+\lstinline$\XNOR$ & Logical XNOR & $\XNOR$  \\
 \lstinline$\NOT$ & not & $\NOT$  \\
 \lstinline$\xor$ & exclusive or & $\xor$  \\
 \lstinline$\false$ & false & $\false$  \\
@@ -788,6 +799,7 @@
 \lstinline$\kgen$ & Key generation & $\kgen$  \\
 \lstinline$\pgen$ & Parameter generation & $\pgen$  \\
 \lstinline$\eval$ & Evaluation & $\eval$  \\
+\lstinline$\invert$ & Inversion & $\invert$  \\
 \lstinline$\il$ & Input length & $\il$  \\
 \lstinline$\ol$ & Output length & $\ol$  \\
 \lstinline$\kl$ & Key length & $\kl$  \\
@@ -965,7 +977,7 @@
 \section{Basics}
 \index{\textbackslash pseudocode}
 
-The cryptocode package provides the command \emph{pseudocode} in order to write simple cryptostyle algorithms.
+The cryptocode package provides the command \emph{pseudocode} for typesetting algorithms.
 Consider the following definition of an IND-CPA game
 \begin{center}
 \fbox{%
@@ -1026,6 +1038,9 @@
 \index{yshift}
 \index{bodylinesep}
 \index{headlinesep}
+\index{jot}
+\index{beginline}
+\index{endline}
 
 Besides the mandatory argument the \lstinline{\pseudocode} command can take an optional argument which consists of a list of key=value pairs
 separated by commas (,).
@@ -1070,6 +1085,18 @@
 \item[codesize]
 Allows to specify the fontsize for the pseudocode. Set to \lstinline$\scriptsize$ for a smaller size.
 
+\item[colspace]
+Allows to insert spacing between columns. In particular this allows to also overlap columns by inserting negative space.
+
+\item[jot]
+Allows to specify extra space between each line. Use \lstinline$jot=1mm$.
+
+\item[beginline]
+Allows to specify a macro that is placed at the beginning of each line.
+
+\item[endline]
+Allows to specify a macro that is placed at the end of each line.
+
 \item[xshift]
 Allows horizontal shifting
 \item[yshift]
@@ -1083,6 +1110,10 @@
 Defines the space between columns.
 \item[addtolength]
 Is added to the automatically computed width of the pseudocode (which does not take colsep into account). 
+
+\item[valign]
+Controls the vertical alignment of the pseudocode. Pseudocode is wrapped in a minipage environment and valign value is passed as orientation for the minipage. By default valign is set to \enquote{t}.
+
 \item[nodraft]
 Forces syntax highlighting also in draft mode.
 \end{description}
@@ -1129,7 +1160,7 @@
    \pcreturn b = b' }
 \end{lstlisting}
 
-You can define customized pseudocode commands with either take one optional argument and two mandatory arguments (as the procedure command)
+You can define customized pseudocode commands which either take one optional argument and two mandatory arguments (as the procedure command)
 or one optional and one mandatory argument (as the pseudocode command). The following
 \begin{lstlisting}
 \createprocedurecommand{mypseudocode}{}{}{linenumbering}
@@ -1296,6 +1327,8 @@
 \section{Syntax Highlighting}
 \label{sec:syntaxhighlight}
 
+\index{\textbackslash pcabort}
+\index{\textbackslash pcfail}
 \index{\textbackslash pccontinue}
 \index{\textbackslash pccomment}
 \index{\textbackslash pcdo}
@@ -1328,10 +1361,12 @@
 \begin{center}
 \begin{tabular}{lll}
  \textbf{name} & \textbf{usage} & \textbf{outcome} \\ 
+ pcabort & \lstinline$\pcabort$ & \pcabort\\
  pccontinue & \lstinline$\pccontinue$ & \pccontinue \\
  pccomment & \lstinline$\pccomment{comment}$ & \pccomment{comment} \\
  pcdo & \lstinline$\pcdo$ & \pcdo \\
  pcdone & \lstinline$\pcdone$ & \pcdone \\
+ pcfail & \lstinline$\pcfail$ & \pcfail \\
  pcfalse & \lstinline$\pcfalse$ & \pcfalse \\
  pcif & \lstinline$\pcif$ & \pcif \\
  pcfi & \lstinline$\pcfi$ & \pcfi \\
@@ -1348,8 +1383,8 @@
  pcnull & \lstinline$\pcnull$ & \pcnull \\
  pcparse & \lstinline$\pcparse$ & \pcparse \\
  pcrepeat & \lstinline$\pcrepeat{10}$ & \pcrepeat{10} \\
+ pcreturn & \lstinline$\pcreturn$ & \pcreturn \\ 
  pcuntil & \lstinline$\pcuntil$ & \pcuntil \\
- pcreturn & \lstinline$\pcreturn$ & \pcreturn \\
  pcthen & \lstinline$\pcthen$ & \pcthen \\
  pctrue & \lstinline$\pctrue$ & \pctrue \\
  pcwhile & \lstinline$\pcwhile$ & \pcwhile \\
@@ -1861,7 +1896,7 @@
 \section{Divisions and Linebreaks}
 \index{linebreaks}
 \index{\textbackslash hline}
-Within the pseudocode command you generate linebreaks as $\\$. In order to specify the linewidth you can add an optional argument
+Within the pseudocode command you generate linebreaks as \lstinline$\\$. In order to specify the linewidth you can add an optional argument
 \begin{lstlisting}
 \\[height]
 \end{lstlisting}
@@ -1892,7 +1927,54 @@
  \pcln   \pcreturn b = b' }
 \end{lstlisting}
 
+\section{Matrices and Math Environments within pseudocode}
 
+In order to work its magic, cryptocode (in particular within the \lstinline{\pseudocode} command) mingles with a few low level commands such as
+\lstinline{\\} or \lstinline{\halign}. The effect of this is, that when you use certain math environments, for example, to create matrices, within pseudocode
+the result may be unexpected. Consider the following example
+
+\begin{lstlisting}
+\pseudocode{
+\text{compute } P = \begin{pmatrix}
+    A \\ B + C
+\end{pmatrix}
+}
+\end{lstlisting}
+
+which, somewhat unexpectedly, yields
+
+\begin{center}
+\fbox{
+\pseudocode{
+\text{compute } P = \begin{pmatrix}
+    A \\ B + C
+\end{pmatrix}
+}
+}
+\end{center}
+
+That is, the alignment is somewhat off. In order, to allow for the \emph{pmatrix} environment to properly work without interference from \lstinline{\pseudocode}
+you can wrap it into a \emph{pcmbox} environment (where pcmbox is short for pseudocode math box). This ensures that the low-level changes introduced by  \lstinline{\pseudocode} are not active.
+
+\begin{lstlisting}
+\pseudocode{
+\text{compute } P = \begin{pcmbox}\begin{pmatrix}
+    A \\ B + C
+\end{pmatrix}\end{pcmbox}
+}
+\end{lstlisting}
+
+\begin{center}
+\fbox{
+\pseudocode{
+\text{compute } P = \begin{pcmbox}\begin{pmatrix}
+    A \\ B + C
+\end{pmatrix}\end{pcmbox}
+}
+}
+\end{center}
+
+
 \section{Fancy Code with Overlays}
 
 Consider the \indcpa\ game. Here we have a single adversary $\adv$ that is called twice, first to output two messages then
@@ -2771,6 +2853,56 @@
 \end{gameproof}
 \end{lstlisting}
 
+\subsection{Styling game procedures}
+It may come in handy to define default style arguments for the underlying pseudocode 
+command used by \lstinline$\gameprocedure$. For this you can
+define the default arguments by calling \lstinline{\setgameproceduredefaultstyle} to 
+for example:
+
+\begin{lstlisting}
+\setgameproceduredefaultstyle{beginline=\vphantom{\bin^\prg_\prg}
+\end{lstlisting}
+
+The default is to not set any options.
+
+\section{Game Descriptions}
+Cryptocode also comes with an environment to provide textual descriptions of games such as
+
+
+ \begin{gamedescription}[name=MyGame,nr=2]
+\describegame
+ This is the third game. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis condimentum velit et orci volutpat, sed ultrices lorem lobortis. Nam vehicula, justo eu varius interdum, felis mi consectetur dolor, ac posuere nulla lacus varius diam. Etiam dapibus blandit leo, et porttitor augue lacinia auctor.
+
+\describegame[inhint=reduction target]
+ This is the second game. The arrow at the side indicates the reduction target.
+ \end{gamedescription}
+ 
+ The above example is generated as
+ 
+\begin{lstlisting}
+\begin{gamedescription}[name=MyGame,nr=2]
+\describegame
+This is the third game. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis condimentum velit et orci volutpat, sed ultrices lorem lobortis. Nam vehicula, justo eu varius interdum, felis mi consectetur dolor, ac posuere nulla lacus varius diam. Etiam dapibus blandit leo, et porttitor augue lacinia auctor.
+
+\describegame[inhint=reduction target]
+This is the second game. The arrow at the side indicates the reduction target.
+\end{gamedescription}
+\end{lstlisting}
+
+The \emph{gamedescription} environment takes an optional argument to specify name and counter (defaults to Game and 0). The command 
+\lstinline$\describegame$ starts a new game description and can allows you to provide a reduction hint using the option parameter \emph{inhint}.
+
+\begin{center}
+\begin{tabular}{ll}
+\textbf{Parameter} & \textbf{Description} \\
+\lstinline$inhint$ & Displays an ingoing arrow to denote the reduction target for this game hop.\\
+\lstinline$length$ & Allows to control the length of the arrow. \\
+\lstinline$nodestyle$ & Allows to control the style of the node. \\
+\lstinline$hint$ &  Instead of having an ingoing arrow, this adds an outgoing arrow. \\
+\end{tabular}
+\end{center}
+
+
 \chapter{Black-box Reductions}
 \label{chap:bbr}
 \index{bbrenv}
@@ -2793,7 +2925,8 @@
 \enquote{bbrbox} environment and some additional commands. 
 
 The following is a simple example drawing one (black)box with some code and input output:
-\begin{bbrenv}{A}
+
+\begin{bbrenv}[1cm]{A}[1cm]
 	\begin{bbrbox}[name=Box Name]
 	\pseudocode{
 		\text{step 1} \\
@@ -2805,9 +2938,10 @@
 	\bbrinput{input}
 	\bbroutput{output}
 \end{bbrenv}
+
 This box is generated as
 \begin{lstlisting}
-\begin{bbrenv}{A}
+\begin{bbrenv}[1cm]{A}[1cm]
 	\begin{bbrbox}[name=Box Name]
 	\pseudocode{
 		\text{step 1} \\
@@ -2822,14 +2956,17 @@
 \end{lstlisting}
 
 The commands \lstinline$bbrinput$ and \lstinline$bbroutput$ allow to specify input and output for the latest
-''bbrenv´´ environment. The single argument to the bbrenv environment needs to specify a unique identifier
+\enquote{bbrenv} environment. The optional parameters for the \lstinline$bbrenv$ environment allow to specify leading and trailing space (this
+may become necessary when using inputs and outputs).
+The single argument to the bbrenv environment needs to specify a unique identifier
 (unique for the current reduction). This id is used as an internal TIKZ node name (\url{https://www.ctan.org/pkg/pgf}).
 \begin{lstlisting}
-\begin{bbrenv}{UNIQUE IDENTIFIER}
+\begin{bbrenv}[vspace before]{UNIQUE IDENTIFIER}[vspace after]
 \end{lstlisting}
 As we are drawing a TIKZ image, note that we can easily later customize the image using the labels that we
 have specified on the way. 
-\begin{bbrenv}{A}
+
+\begin{bbrenv}[1cm]{A}[1cm]
 	\begin{bbrbox}[name=Box Name]
 	\pseudocode{
 		\text{step 1} \\
@@ -2874,6 +3011,7 @@
 
 \index{namepos}
 \index{namestyle}
+\index{abovesep}
 \index{minheight}
 \index{xshift}
 \index{yshift}
@@ -2880,10 +3018,12 @@
 \begin{center}
 \begin{tabular}{ll}
 \textbf{Option} & \textbf{Description} \\ \hline
-name & Specifies the box' label \\
-namepos & Specifies the position (left, center, right, top left, top center, top right) \\
+name & Specifies the box's label \\
+namepos & Specifies the position (left, center, right, top left, top center, top right, middle) \\
 namestyle & Specifies the style of the name \\
+abovesep & Space above box (defaults to \lstinline$\baselineskip$) \\
 minheight & The minimal height \\
+addheight & Additional height at the end of the box \\
 xshift & Allows horizontal positioning \\
 yshift & Allows horizontal positioning \\
 style & allows to customize the node
@@ -2895,7 +3035,7 @@
 Boxes can be nested. For this simply insert a bbrenv (together with a single bbrbox) environment into an
 existing bbrbox.
 
-\begin{bbrenv}{A}
+\begin{bbrenv}[1cm]{A}[0.5cm]
 	\begin{bbrbox}[name=Box Name]
 	\pseudocode{
 		\text{step 1} \\
@@ -2908,7 +3048,7 @@
 		\begin{bbrbox}[name=Inner Box]
 		\pseudocode{
 			\text{inner step 1} \\
-			\text{inner step 2} \\
+			\text{inner step 2} 
 		}
 		\end{bbrbox}
 	\end{bbrenv}
@@ -2915,7 +3055,7 @@
 
 	\pseudocode{
 		\text{step 4} \\
-		\text{step 5} \\
+		\text{step 5} 
 	}
 	\end{bbrbox}
 	\bbrinput{input}
@@ -2936,7 +3076,7 @@
 		\begin{bbrbox}[name=Inner Box]
 		\pseudocode{
 			\text{inner step 1} \\
-			\text{inner step 2} \\
+			\text{inner step 2} 
 		}
 		\end{bbrbox}
 	\end{bbrenv}
@@ -2943,7 +3083,7 @@
 
 	\pseudocode{
 		\text{step 4} \\
-		\text{step 5} \\
+		\text{step 5} 
 	}
 	\end{bbrbox}
 	\bbrinput{input}
@@ -2979,7 +3119,7 @@
 
 Following is a complete example. Notice that cryptocode takes care of the vertical positioning.
 
-\begin{bbrenv}{A}
+\begin{bbrenv}[1cm]{A}[0.5cm]
 	\begin{bbrbox}[name=Box Name]
 	\pseudocode{
 		\text{step 1} \\
@@ -2992,7 +3132,7 @@
 		\begin{bbrbox}[name=Inner Box]
 		\pseudocode{
 			\text{inner step 1} \\
-			\text{inner step 2} \\
+			\text{inner step 2} 
 		}
 		\end{bbrbox}
 		
@@ -3007,7 +3147,7 @@
 
 	\pseudocode{
 		\text{step 4} \\
-		\text{step 5} \\
+		\text{step 5} 
 	}
 	\end{bbrbox}
 	\bbrinput{input}
@@ -3028,7 +3168,7 @@
 		\begin{bbrbox}[name=Inner Box]
 		\pseudocode{
 			\text{inner step 1} \\
-			\text{inner step 2} \\
+			\text{inner step 2} 
 		}
 		\end{bbrbox}
 		
@@ -3043,7 +3183,7 @@
 
 	\pseudocode{
 		\text{step 4} \\
-		\text{step 5} \\
+		\text{step 5} 
 	}
 	\end{bbrbox}
 	\bbrinput{input}
@@ -3053,7 +3193,7 @@
 
 \subsection{Options}
 Besides specifying labels for top, side and bottom you can further specify how cryptocode renders the message.
-Remember that tnderneath the reduction commands is a TIKZ image (\url{https://www.ctan.org/pkg/pgf/}).
+Remember that underneath the reduction commands is a TIKZ image (\url{https://www.ctan.org/pkg/pgf/}).
 For each label position (top, side, bottom) a node is generated. You can provide additional properties for
 this node using the options:
 \begin{itemize}
@@ -3069,11 +3209,10 @@
 \item bottomname
 \end{itemize}
 The \enquote{osidename} allows you to provide a name for the \enquote{other side}. 
+Via the option \enquote{length} you can specify the length of the arrow.
 
-Via the option \enquote{length} you can specifiy the length of the arrow.
 
-
-\begin{bbrenv}{A}
+\begin{bbrenv}[1cm]{A}[0.5cm]
 	\begin{bbrbox}[name=Box Name]
 	\pseudocode{
 		\text{step 1} \\
@@ -3143,7 +3282,8 @@
 \index{\textbackslash bbrqryspace}
 If the spacing between messages is not sufficient you can use the \lstinline$bbrmsgspace$ and
 \lstinline$bbrqryspace$ commands to add additional space.
-\begin{bbrenv}{A}
+
+\begin{bbrenv}[1cm]{A}[0.5cm]
 	\begin{bbrbox}[name=Reduction]
 	\pseudocode{
 		\text{Do something} 
@@ -3205,7 +3345,7 @@
 Often an adversary may send poly many queries to an oracle, or a reduction sends many queries to an adversary.
 Consider the following setting
 
-\begin{bbrenv}{A}
+\begin{bbrenv}[1cm]{A}[0.5cm]
 	\begin{bbrbox}[name=Reduction]
 	\pseudocode{
 		\text{Do something} 
@@ -3260,7 +3400,7 @@
 The \lstinline$bbrloop$ command takes two node names and a config which allows you to specify if the label is
 to be shown on the left, center or right. Here is the result.
 
-\begin{bbrenv}{A}
+\begin{bbrenv}[1cm]{A}[0.5cm]
 	\begin{bbrbox}[name=Reduction]
 	\pseudocode{
 		\text{Do something} 
@@ -3320,7 +3460,8 @@
 \bbrmsgtxt[options]{Text}
 \bbrqrytxt[options]{Text}
 \end{lstlisting}
-\begin{bbrenv}{A}
+
+\begin{bbrenv}[1cm]{A}[0.5cm]
 	\begin{bbrbox}[name=Reduction]
 	\pseudocode{
 		\text{Do something} 
@@ -3400,7 +3541,7 @@
 is created similarly to a \emph{bbrenv} environment using the \emph{bbroracle} environment. Oracles
 go behind the single \emph{bbrbox} environment within an \emph{bbrenv} enviornment.
 
-\begin{bbrenv}{A}
+\begin{bbrenv}[1cm]{A}[0.5cm]
 	\begin{bbrbox}[name=Reduction]
 	\pseudocode{
 		\text{Do something} 
@@ -3472,7 +3613,7 @@
 \lstinline$\bbroracleqryspace$ to generate extra space between oracle messages. Note
 that oracle messages need to be added after the closing \lstinline$\end{bbroracle}$ command.
 
-\begin{bbrenv}{A}
+\begin{bbrenv}[1cm]{A}[0.5cm]
 	\begin{bbrbox}[name=Reduction]
 	\pseudocode{
 		\text{Do something} 
@@ -3545,7 +3686,7 @@
 is created similarly to a \emph{bbrenv} environment using the \emph{bbrchallenger} environment. Challengers
 go behind the single \emph{bbrbox} environment within an \emph{bbrenv} enviornment.
 
-\begin{bbrenv}{A}
+\begin{bbrenv}[1cm]{A}[0.5cm]
 	\begin{bbrbox}[name=Adversary,minheight=2cm]
 	\pseudocode{
 		\text{Do something} 
@@ -3597,7 +3738,8 @@
 \lstinline$\bbrchallengerqryspace$ to generate extra space between oracle messages. Note
 that challenger messages need to be added after the closing \lstinline$\end{bbrchallenger}$ command.
 
-\begin{bbrenv}{A}
+\vspace{2em}
+\begin{bbrenv}[1cm]{A}[0.5cm]
 	\begin{bbrbox}[name=Adversary,minheight=2cm]
 	\pseudocode{
 		\text{Do something} 
@@ -3639,8 +3781,151 @@
 \end{bbrenv}
 \end{lstlisting}
 
+\section{Examples}
+A reduction for full domain hash.
 
 
+\begin{bbrenv}{Red}
+
+	\begin{bbrbox}[name=\textsc{Reduction }$\bdv$]
+
+		\pseudocode{
+			j \sample [q] 
+		}
+		
+		\vspace{2ex}
+		\emph{/* begin simulation */}
+		
+		\begin{bbrenv}{Adv}
+			\begin{bbrbox}[name=$\adv$,minheight=7.5cm,style={fill=black},namestyle={color=white},xshift=3cm,yshift=0.75cm]
+			\end{bbrbox}
+
+			\bbrinput{$\fk$}
+			\bbroutput{$\sigma$}			
+			
+			\bbrmsgfrom{top=$m_1$}
+			\bbrmsgto{bottom=$\$$,beforeskip=-0.5\baselineskip,afterskip=-0.5\baselineskip}
+			
+			\bbrmsgvdots
+			
+			\bbrmsgfrom{top=$m_{j-1}$}
+			\bbrmsgto{bottom=$\$$,beforeskip=-0.5\baselineskip,afterskip=-0.5\baselineskip}
+			
+			\bbrmsgfrom{top=$m_j$}
+			\bbrmsgto{bottom=$y$,beforeskip=-0.5\baselineskip,afterskip=-0.5\baselineskip}
+
+			\bbrmsgfrom{top=$m_{j+1}$}
+			\bbrmsgto{bottom=$\$$,beforeskip=-0.5\baselineskip,afterskip=-0.5\baselineskip}
+
+			\bbrmsgvdots
+			
+			\bbrmsgfrom{top=$m_q$}
+			\bbrmsgto{bottom=$\$$,beforeskip=-0.5\baselineskip,afterskip=-0.5\baselineskip}
+
+			\begin{bbroracle}{Sign}
+				\begin{bbrbox}[name=Sign,namepos=center,style={draw},minheight=1cm]
+				\end{bbrbox}
+			\end{bbroracle}
+
+			\bbroracleqryto{top=$m$}
+			\bbroracleqryfrom{top=$\sigma$}			
+
+		\end{bbrenv}
+		
+	
+		\pcdraw{
+			\node[left=2cm of Adv.north west] (startsim) {};
+			\node[left=2cm of Adv.south west] (endsim) {};			
+			\draw[->,thick] (startsim) -- (endsim);
+			\node[rotate=90, left=2.75cm of Adv.west,anchor=center] () {\textsc{Simulation of Random Oracle}};
+		}
+		
+		\vspace{-3ex}
+		\emph{/* end simulation */}
+		
+		\pseudocode{
+		 y \gets \sigma
+		}
+
+	\end{bbrbox}
+	\bbrqryfrom{beforeskip=0.25cm,top={$(\fk, y)$},side={\dbox{\pseudocode{
+	  \fk \sample \fash.\kgen(\secparam) \\ x \sample \bin^{\fash.\il(\secpar)} \\ y \gets \fash.\eval(\fk, x)} 
+	}}}
+	\bbrqryto{beforeskip=10.75cm,side=\pseudocode{y \in \fash^{-1}(\fk, x)}}
+\end{bbrenv}
+
+\begin{lstlisting}
+\begin{bbrenv}{Red}
+
+	\begin{bbrbox}[name=\textsc{Reduction }$\bdv$]
+
+		\pseudocode{
+			j \sample [q] 
+		}
+		
+		\vspace{2ex}
+		\emph{/* begin simulation */}
+		
+		\begin{bbrenv}{Adv}
+			\begin{bbrbox}[name=$\adv$,minheight=7.5cm,style={fill=black},namestyle={color=white},xshift=3cm,yshift=0.75cm]
+			\end{bbrbox}
+
+			\bbrinput{$\fk$}
+			\bbroutput{$\sigma$}			
+			
+			\bbrmsgfrom{top=$m_1$}
+			\bbrmsgto{bottom=$\$$,beforeskip=-0.5\baselineskip,afterskip=-0.5\baselineskip}
+			
+			\bbrmsgvdots
+			
+			\bbrmsgfrom{top=$m_{j-1}$}
+			\bbrmsgto{bottom=$\$$,beforeskip=-0.5\baselineskip,afterskip=-0.5\baselineskip}
+			
+			\bbrmsgfrom{top=$m_j$}
+			\bbrmsgto{bottom=$y$,beforeskip=-0.5\baselineskip,afterskip=-0.5\baselineskip}
+
+			\bbrmsgfrom{top=$m_{j+1}$}
+			\bbrmsgto{bottom=$\$$,beforeskip=-0.5\baselineskip,afterskip=-0.5\baselineskip}
+
+			\bbrmsgvdots
+			
+			\bbrmsgfrom{top=$m_q$}
+			\bbrmsgto{bottom=$\$$,beforeskip=-0.5\baselineskip,afterskip=-0.5\baselineskip}
+
+			\begin{bbroracle}{Sign}
+				\begin{bbrbox}[name=Sign,namepos=center,style={draw},minheight=1cm]
+				\end{bbrbox}
+			\end{bbroracle}
+
+			\bbroracleqryto{top=$m$}
+			\bbroracleqryfrom{top=$\sigma$}			
+
+		\end{bbrenv}
+		
+	
+		\pcdraw{
+			\node[left=2cm of Adv.north west] (startsim) {};
+			\node[left=2cm of Adv.south west] (endsim) {};			
+			\draw[->,thick] (startsim) -- (endsim);
+			\node[rotate=90, left=2.75cm of Adv.west,anchor=center] () {\textsc{Simulation of Random Oracle}};
+		}
+		
+		\vspace{-3ex}
+		\emph{/* end simulation */}
+		
+		\pseudocode{
+		 y \gets \sigma
+		}
+
+	\end{bbrbox}
+	\bbrqryfrom{beforeskip=0.25cm,top={$(\fk, y)$},side={\dbox{\pseudocode{
+	  \fk \sample \fash.\kgen(\secparam) \\ x \sample \bin^{\fash.\il(\secpar)} \\ y \gets \fash.\eval(\fk, x)} 
+	}}}
+	\bbrqryto{beforeskip=10.75cm,side=\pseudocode{y \in \fash^{-1}(\fk, x)}}
+\end{bbrenv}
+\end{lstlisting}
+
+
 \chapter{Known Issues}
 
 \section{Pseudocode KeepSpacing within Commands}

Modified: trunk/Master/texmf-dist/tex/latex/cryptocode/cryptocode.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/cryptocode/cryptocode.sty	2018-11-11 21:55:38 UTC (rev 49130)
+++ trunk/Master/texmf-dist/tex/latex/cryptocode/cryptocode.sty	2018-11-11 21:55:56 UTC (rev 49131)
@@ -1,4 +1,4 @@
- %% Copyright 2015 Arno Mittelbach
+ %% Copyright 2018 Arno Mittelbach
   %
   % This work may be distributed and/or modified under the
   % conditions of the LaTeX Project Public License, either version 1.3
@@ -13,12 +13,50 @@
   % The Current Maintainer of this work is Arno Mittelbach.
   %
   % This work consists of the files cryptocode.tex and cryptocode.sty
+  %
+  % Changelog
+  %
+  % 2016/11/30
+  % - changed \pckeystyle to ensure that subscripts on \sk and \pk are aligned the same 
+  %   before, $(\sk_R, \pk_R)$ had slightly misaligned subscripts due to Tex treating 
+  %   subscripts on composite objects with descenders differently than without.
+  %   see https://groups.google.com/forum/#!msg/comp.text.tex/IaXu_xBG06Q/CibRPH5GCAAJ
+  % - added \NAND
+  % - added pcmbox environment for matrices in pseudocode
+  %
+  % 2016/12/02
+  % - changed minheight for bbrbox environment to actually reflect a minimum height in tikz
+  %   the old minheight which added space at the bottom was preserved as addheight
+  % - added namepos middle for bbrbox
+  % - added pcfail
+  % - added valign to pseudocode to allow minipage vertical alignment
+  % - added \setgameproceduredefaultstyle
+  % - ensure line numbers are right aligned to allow for two digit linenumbers having the same width
+  %
+  % 2017/08/26
+  % - added \pcabort
+  % - better control whitespace for \pcif, \pcelse, \pcelseif
+  %
+  % 2017/10/02
+  % - side and oside support to \bbroracleqryto and \bbroracleqryfrom
+  % - add bottom to namepos in bbrbox
+  % - names for brrinput and bbroutput
+  % - angle for bbrloop
+  % - fix length for bbrinput
+  % - introduce hoffset for bbrinput
+  % 
+  % 2017/12/21
+  % - added \pcunless
+  %
+  % 2018/11/11
+  % replace obsolete l3regex
+  %
 \NeedsTeXFormat{LaTeX2e}
 \ProvidesPackage{cryptocode}
-  [2015/04/22 v0.1 Cryptocode LaTeX package for writing pseudocode in cryptographic settings]
+  [2018/11/11 v0.3.0 Cryptocode LaTeX package for typesetting pseudocode, algorithms and protocols as well as cryptographic proofs.]
 
 
-\def\hi{Hello, this is Arno's crypto code package. }
+\def\hi{Hello, this is cryptocode.}
 \let\myDate\date
 
 \RequirePackage{amsmath}
@@ -92,8 +130,10 @@
 	\providecommand{\supp}[1]{  \ensuremath{\operatorname{Supp}\olrk{#1}}}
 	
 	\providecommand{\entropy}[1]{\ensuremath{\operatorname{H}\olrk{#1}}}
+   	\providecommand{\condentropy}[2]{\ensuremath{\operatorname{H}\olrk{#1\,\left|\,#2\vphantom{#1}\right.}}}    	
 	\providecommand{\minentropy}[1]{\ensuremath{\operatorname{H_\infty}\olrk{#1}}}
-    	\providecommand{\condminentropy}[2]{\ensuremath{\operatorname{\tilde{H}_\infty}\olrk{#1|#2}}}    
+    	\providecommand{\condminentropy}[2]{\ensuremath{\operatorname{H_\infty}\olrk{#1\,\left|\,#2\vphantom{#1}\right.}}}    
+    	\providecommand{\condavgminentropy}[2]{\ensuremath{\operatorname{\tilde{H}_\infty}\olrk{#1\,\left|\,#2\vphantom{#1}\right.}}}        	
 }
 
 \DeclareOption{sets}{
@@ -140,8 +180,12 @@
 \DeclareOption{logic}{
         \providecommand{\AND}{\ensuremath{\mathrm{AND}}}
         \providecommand{\OR}{\ensuremath{\mathrm{OR}}}
+        \providecommand{\NOR}{\ensuremath{\mathrm{NOR}}}
         \providecommand{\NOT}{\ensuremath{\mathrm{NOT}}}
-        \providecommand{\xor}{\ensuremath{\oplus}}
+        \providecommand{\NAND}{\ensuremath{\mathrm{NAND}}}        
+		\providecommand{\XOR}{\ensuremath{\mathrm{XOR}}}		
+		\providecommand{\XNOR}{\ensuremath{\mathrm{XNOR}}}		
+		\providecommand{\xor}{\ensuremath{\oplus}}        
         \providecommand{\false}{\mathsf{false}} 
         \providecommand{\true}{\mathsf{true}}
 }
@@ -154,6 +198,7 @@
 	\providecommand{\kgen}{\pcalgostyle{KGen}}
 	\providecommand{\pgen}{\pcalgostyle{Pgen}}
 	\providecommand{\eval}{\pcalgostyle{Eval}}
+	\providecommand{\invert}{\pcalgostyle{Inv}}	
 	
 	\providecommand{\il}{\pcalgostyle{il}}
 	\providecommand{\ol}{\pcalgostyle{ol}}
@@ -227,7 +272,7 @@
 }
 
 \DeclareOption{keys}{
-            \providecommand{\pckeystyle}[1]{\ensuremath{\mathsf{#1}}}
+            \providecommand{\pckeystyle}[1]{\ensuremath{\mathsf{\protect\vphantom{p}#1}}}
             
             \providecommand{\pk}{\pckeystyle{pk}}
             \providecommand{\vk}{\pckeystyle{vk}}
@@ -259,6 +304,8 @@
 
 \ProcessOptions\relax
 
+\RequirePackage{etex}
+
 %amsfonts
 \ifpc at amsfonts
 	\RequirePackage{amsfonts}
@@ -274,13 +321,11 @@
 \RequirePackage{forloop}
 \RequirePackage{array}
 \RequirePackage{xparse}
-\RequirePackage{l3regex}
+\RequirePackage{expl3}
 \RequirePackage{pbox}
 \RequirePackage{varwidth}
 \RequirePackage{suffix}
 \RequirePackage{etoolbox}
-\RequirePackage{etex}
-%\RequirePackage{etextools}
 \RequirePackage{environ}
 %\RequirePackage{xspace}
 \RequirePackage{xkeyval}
@@ -460,7 +505,13 @@
       \tl_use:N \l_pc_strsub_input_tl    
  }
  
+\NewDocumentCommand{\@pc at centercolifnec}{m}%
+{%
+#1%
+}
  
+ 
+ 
 \ExplSyntaxOff
 
 %%%%%%%%
@@ -501,8 +552,12 @@
 %keep hyperref happy
 \ifmeasuring@\else\pc at original@label{#1}\fi%
 }%
+\ifthenelse{\value{pclinenumber}<10}{\hspace{1ex}}{}%
 \hspace{\pclnspace}\text{\scriptsize\arabic{pclinenumber}}\pclnseparator\quad}%
 
+% allow to skip numbering single lines if linenumbering=on 
+\providecommand{\pcnoln}{%
+}
 
 % right align line numbers (same counter)
 \providecommand{\pclnr}{%
@@ -532,6 +587,7 @@
 \newcommand{\@withingame}{false}
 \newcommand{\@withinbxgame}{false}
 \newcommand{\@bxgameheader}{}
+\newcommand{\@withingamedescription}{false}
 
 
 %%%%%%%%%%%%
@@ -541,15 +597,17 @@
 
 
 \newcommand{\@pc at beginnewline}{%
-\@pseudocodelinenumber\@pc at and\@pcln%
+\@pseudocodecodeatbeginline\@pseudocodelinenumber\@pc at and\@pcln%
 %checkspace
 \ifthenelse{\equal{\@pseudocodespace}{auto}}%
 {\expandafter\pcind\expandafter[\value{@pc at indentationlevel}]}%
 {}%
+%reset column counter
+\setcounter{pccolumncounter}{2}%
 %beginmode
 \@pc at modebegin}
 \newcommand{\@pc at and}{&}
-\newcommand{\@pc at and@wrap at end}{\@pc at modeend&}
+\newcommand{\@pc at and@wrap at end}{\@pc at modeend&\@pseudocodecodeatendline}
 \newcommand{\@pc at and@wrap at start}{\@pc at beginnewline}
 \newcommand{\pctabname}{>}
 \newcommand{\pcdbltabname}{<}
@@ -568,6 +626,7 @@
 \newcommand*\@pseudocodelnstartright{0}
 \newcommand*\@pseudocodesyntaxhighlighting{}
 \newcommand*\@pseudocodenodraft{false}
+\newcommand*\@pseudocodecolspace{} % empty per default, use length,
 
 \newcommand*\@pseudocodeheadlinesep{0em}
 \newcommand*\@pseudocodebodylinesep{-0.5\baselineskip}
@@ -575,9 +634,14 @@
 \newcommand*\@pseudocodecolsep{0em}
 \newcommand*\@pseudocodeaddtolength{2pt}
 
+\newcommand*\@pseudocodecodeatbeginline{}
+\newcommand*\@pseudocodecodeatendline{}
+\newcommand*\@pseudocodecodejot{0em}
 \newcommand*\@pseudocodecodesize{\small}
 \newcommand*\@pseudocodesubcodesize{\footnotesize}
 
+\newcommand*\@pseudocodeminipagealign{t}
+
 %%%%%%%%%%%%%%
 % Define keywords for the automatic syntax highlighting
 % the accompanying add provides additional keywords.
@@ -593,12 +657,17 @@
 \end{@withspaces}
 
 
+\define at key{pseudocode}{beginline}[]{\renewcommand*\@pseudocodecodeatbeginline{#1}}
+\define at key{pseudocode}{endline}[]{\renewcommand*\@pseudocodecodeatendline{#1}}
+\define at key{pseudocode}{jot}[0em]{\renewcommand*\@pseudocodecodejot{#1}}
 \define at key{pseudocode}{codesize}[\small]{\renewcommand*\@pseudocodecodesize{#1}}
 \define at key{pseudocode}{subcodesize}[\small]{\renewcommand*\@pseudocodesubcodesize{#1}}
 \define at key{pseudocode}{head}[]{\renewcommand*\@pseudocodehead{#1}}
 \define at key{pseudocode}{width}[]{\renewcommand*\@pseudocodewidth{#1}}
+\define at key{pseudocode}{valign}[t]{\renewcommand*\@pseudocodeminipagealign{#1}}
 \define at key{pseudocode}{xshift}[]{\renewcommand*\@pseudocodexshift{#1}}
 \define at key{pseudocode}{yshift}[]{\renewcommand*\@pseudocodeyshift{#1}}
+\define at key{pseudocode}{colspace}[]{\renewcommand*\@pseudocodecolspace{#1}}
 \define at key{pseudocode}{linenumbering}[on]{\ifthenelse{\equal{#1}{on}}{\renewcommand*\@pseudocodelinenumber{\pcln}}{\renewcommand*\@pseudocodelinenumber{}}}
 \define at key{pseudocode}{beforeskip}[]{\renewcommand*\@pseudocodebeforeskip{#1}}
 \define at key{pseudocode}{afterskip}[]{\renewcommand*\@pseudocodeafterskip{#1}}
@@ -613,8 +682,9 @@
 \renewcommand*\@pc at modebegin{\begin{varwidth}{\textwidth}%
 %introduce line magic for text mode
 \let\@pc at lb\\%
-\renewcommandx*{\\}[2][1=,2=]{\@pc at modeend\@pc at and \ifthenelse{\equal{####1}{}}{\@pc at lb}{\@pc at lb[####1]}####2 \@pc at beginnewline}%
+\renewcommandx*{\\}[2][1=,2=]{\@pc at modeend\@pc at and \@pseudocodecodeatendline\ifthenelse{\equal{####1}{}}{\@pc at lb}{\@pc at lb[####1]}####2 \@pc at beginnewline}%
 \def\pclb{\let\\\@pc at lb\relax\@pc at modeend\\}%
+\def\pcolb{\let\\\@pc at lb\relax\@pc at modeend\\}%
 }%
 \renewcommand*\@pc at modeend{\end{varwidth}}
 }{}%
@@ -731,6 +801,8 @@
     {\highlightaltkeyword{\@pc at spacesubstitution{#1}{ }{~}}}%
 }
 
+\newcommand{\@pc at colspace}{}
+
 %%%%%%%%%%%%%%%%%
 % Allow for spacing
 \newcommand{\@withinspaces}{false}%
@@ -748,6 +820,9 @@
 \newcommand{\@pc at decreaseindent}{\ifthenelse{\equal{\@pseudocodespace}{auto}}{\pcind[-1]}{}\addtocounter{@pc at indentationlevel}{-1}}
 \newcommand{\@pc at tmpdecreaseindent}{\ifthenelse{\equal{\@pseudocodespace}{auto}}{\pcind[-1]}{}}
 
+\newcounter{pccolumncounter}
+\setcounter{pccolumncounter}{2}
+
 % store original halign
 \let\@pc at halign\halign%
 
@@ -778,15 +853,22 @@
 %
 % create tabbing command
 \ifcsname \pctabname\endcsname%
-\expandafter\renewcommand\csname \pctabname\endcsname{\@pc at modeend&\@pc at modebegin}%
+\expandafter\renewcommand\csname \pctabname\endcsname{\@pc at modeend&\@pc at colspace\@pc at modebegin}%
 \else%
-\expandafter\newcommand\csname \pctabname\endcsname{\@pc at modeend&\@pc at modebegin}%
+\expandafter\newcommand\csname \pctabname\endcsname{\@pc at modeend&\@pc at colspace\@pc at modebegin}%
 \fi%
 \ifcsname \pcdbltabname\endcsname%
-\expandafter\renewcommand\csname \pcdbltabname\endcsname{\@pc at modeend&&\@pc at modebegin}%
+\expandafter\renewcommand\csname \pcdbltabname\endcsname{\@pc at modeend&&\@pc at colspace\@pc at modebegin}%
 \else%
-\expandafter\newcommand\csname \pcdbltabname\endcsname{\@pc at modeend&&\@pc at modebegin}%
+\expandafter\newcommand\csname \pcdbltabname\endcsname{\@pc at modeend&&\@pc at colspace\@pc at modebegin}%
 \fi%
+% create colspace command if necessary (must be empty for multicolumns
+\ifthenelse{\equal{\@pseudocodecolspace}{}}
+ {}
+ {\renewcommand{\@pc at colspace}{\hspace{\@pseudocodecolspace}}}%
+%
+%adjust row width
+\addtolength{\jot}{\@pseudocodecodejot}%
 % create indent command
 \expandafter\let\csname \pcindentname\endcsname\pcind%
 %
@@ -801,6 +883,8 @@
 \setlength{\@pc at alt@minipage at length}{0pt}%
 \setcounter{@pclinenumbertmp}{\value{pclinenumber}}%
 \setcounter{@pcrlinenumbertmp}{\value{pcrlinenumber}}%
+%reset column counter
+\setcounter{pccolumncounter}{2}%
 %
 % vertical space
 \vspace{\@pseudocodeyshift}%
@@ -813,10 +897,11 @@
 % line magic
 \ifthenelse{\value{@pc at global@pc at nestcnt}=1}{%
 \let\@pc at halign\halign%
+\newenvironment{pcmbox}{\let\halign\@pc at halign}{}%
 \def\halign{%
 \renewcommand{\label}[1]{\ifmeasuring@\else\pc at original@label{####1}\fi}%
 \let\@pc at lb\\%
-\renewcommandx*{\\}[2][1=,2=]{\@pc at modeend\@pc at and \ifthenelse{\equal{####1}{}}{\@pc at lb}{\@pc at lb[####1]}####2 \@pc at beginnewline}%
+\renewcommandx*{\\}[2][1=,2=]{\@pc at modeend\@pc at and\@pseudocodecodeatendline \ifthenelse{\equal{####1}{}}{\@pc at lb}{\@pc at lb[####1]}####2 \@pc at beginnewline}%
 \def\pclb{\let\\\@pc at lb\relax\@pc at modeend\\}%
 \@pc at halign}%
 }{}%
@@ -849,7 +934,7 @@
 %
 %do the actual mini page
 \hspace{\@pseudocodexshift}%
-\begin{minipage}[t]{\@pc at minipage@length}%
+\begin{minipage}[\@pseudocodeminipagealign]{\@pc at minipage@length}%
 \ifthenelse{\value{@pcsubprogstep}=0}{%
 \pc at display@pseudocode{\@pseudocodehead}{\@pc at thecontent}%
 }{% if sub procedure
@@ -914,8 +999,7 @@
 
 \newcommand{\@pc at ensureremember}{%
 \ifthenelse{\value{@pc at remember}=0}{\tikzstyle{every picture}+=[remember picture]}{}%
-\addtocounter{@pc at remember}{1}
-}
+\addtocounter{@pc at remember}{1}}
 
 \newcommand{\@pc at releaseremember}{%
 \addtocounter{@pc at remember}{-1}%
@@ -949,8 +1033,8 @@
 }%
 \endgroup}
 
-\newcommandx*{\pcdraw}[1]{%
-\begin{tikzpicture}[overlay,inner sep=0ex,baseline=0pt]
+\newcommandx*{\pcdraw}[2][2=]{%
+\begin{tikzpicture}[overlay,inner sep=0ex,baseline=0pt,#2]
 #1
 \end{tikzpicture}}
 
@@ -979,14 +1063,14 @@
 \newcommand{\bbrenvnodenameprefix}{env-}
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% Black Box Reduction Enviconment
+% Black Box Reduction Environment
 \newenvironmentx{bbrenv}[3][1=0pt,3=0pt]{%
 \addtocounter{@bb at env@nestcnt}{1}%
 \renewcommand{\@bb at lastbox}{#2}%
 %
 % reset lengths
-\setlength{\@bb at message@hoffset}{0pt}%
-\setlength{\@bb at query@hoffset}{0pt}%
+\@pc at globalsetlength{\@bb at message@hoffset}{0pt}%
+\@pc at globalsetlength{\@bb at query@hoffset}{0pt}%
 \@pc at globalsetlength{\@bb at oraclequery@hoffset}{0pt}%
 \@pc at globalsetlength{\@bb at challengerquery@hoffset}{0pt}%
 %
@@ -1009,6 +1093,11 @@
 }{\egroup}%
 \vspace{\@bbendskip}%
 \addtocounter{@bb at env@nestcnt}{-1}%
+% reset lengths
+\@pc at globalsetlength{\@bb at message@hoffset}{0pt}%
+\@pc at globalsetlength{\@bb at query@hoffset}{0pt}%
+\@pc at globalsetlength{\@bb at oraclequery@hoffset}{0pt}%
+\@pc at globalsetlength{\@bb at challengerquery@hoffset}{0pt}%
 }
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -1017,19 +1106,23 @@
 \newcommand*\bbrboxname{}
 \newcommand*\bbrboxnamepos{right}
 \newcommand*\bbrboxnamestyle{}
-\newcommand*\@bbrboxnamepos{below=0.5ex of \@bb at lastbox.north east,anchor=north east}
-\newcommand*\@bbrboxnameposoffset{below left=0cm of phantomname.north west}
+\newcommand*\@bbrboxnamepos{below right=0.5ex and -0.5ex of \@bb at lastbox.north east,anchor=north east}
+\newcommand*\bbrboxabovesep{\baselineskip}
+\newcommand*\@bbrboxnameposoffset{below left=\bbrboxabovesep of phantomname.south west}
 \newcommand*\bbrboxstyle{draw}
 \newcommand*\bbrboxafterskip{}
+\newcommand*\bbrboxminheight{0cm}
 \newcommand*\bbrboxminwidth{2cm}
 \newcommand*\bbrboxxshift{0cm}
 \newcommand*\bbrboxyshift{0cm}
+\define at key{bbrbox}{abovesep}[]{\renewcommand*\bbrboxabovesep{#1}}
 \define at key{bbrbox}{name}[]{\renewcommand*\bbrboxname{#1}}
 \define at key{bbrbox}{namestyle}[]{\renewcommand*\bbrboxnamestyle{#1}}
 \define at key{bbrbox}{namepos}[]{\renewcommand*\bbrboxnamepos{#1}}
 \define at key{bbrbox}{style}[draw]{\renewcommand*\bbrboxstyle{#1}}
 \define at key{bbrbox}{minwidth}[]{\renewcommand*\bbrboxminwidth{#1}}
-\define at key{bbrbox}{minheight}[]{\renewcommand*\bbrboxafterskip{#1}}
+\define at key{bbrbox}{addheight}[]{\renewcommand*\bbrboxafterskip{#1}}
+\define at key{bbrbox}{minheight}[]{\renewcommand*\bbrboxminheight{#1}}
 \define at key{bbrbox}{xshift}[]{\renewcommand*\bbrboxxshift{#1}}
 \define at key{bbrbox}{yshift}[]{\renewcommand*\bbrboxyshift{#1}}
 
@@ -1040,13 +1133,17 @@
 \ifthenelse{\equal{\bbrboxnamepos}{center}}
  {\renewcommand{\@bbrboxnamepos}{below=0.5ex of \@bb at lastbox.north,anchor=north}}{} 
 \ifthenelse{\equal{\bbrboxnamepos}{left}}
- {\renewcommand{\@bbrboxnamepos}{below=0.5ex of \@bb at lastbox.north west,anchor=north west}\renewcommand{\@bbrboxnameposoffset}{below left=1\baselineskip of phantomname.south west}}{} 
+ {\renewcommand{\@bbrboxnamepos}{below=0.5ex of \@bb at lastbox.north west,anchor=north west}}{} 
 \ifthenelse{\equal{\bbrboxnamepos}{top right}}
- {\renewcommand{\@bbrboxnamepos}{above=0cm of \@bb at lastbox.north east,anchor=south east}}{}
+ {\renewcommand{\@bbrboxnamepos}{above=0cm of \@bb at lastbox.north east,anchor=south east}\renewcommand{\@bbrboxnameposoffset}{below left=0cm of phantomname.north west}}{}
 \ifthenelse{\equal{\bbrboxnamepos}{top center}}
- {\renewcommand{\@bbrboxnamepos}{above=0cm of \@bb at lastbox.north,anchor=south}}{} 
+ {\renewcommand{\@bbrboxnamepos}{above=0cm of \@bb at lastbox.north,anchor=south}\renewcommand{\@bbrboxnameposoffset}{below left=0cm of phantomname.north west}}{} 
 \ifthenelse{\equal{\bbrboxnamepos}{top left}}
- {\renewcommand{\@bbrboxnamepos}{above=0cm of \@bb at lastbox.north west,anchor=south west}}{} 
+ {\renewcommand{\@bbrboxnamepos}{above=0cm of \@bb at lastbox.north west,anchor=south west}\renewcommand{\@bbrboxnameposoffset}{below left=0cm of phantomname.north west}}{} 
+\ifthenelse{\equal{\bbrboxnamepos}{middle}}
+ {\renewcommand{\@bbrboxnamepos}{above=0.5ex of \@bb at lastbox.base,anchor=south}}{} 
+\ifthenelse{\equal{\bbrboxnamepos}{bottom}}
+ {\renewcommand{\@bbrboxnamepos}{above=0.5ex of \@bb at lastbox.base,anchor=north}}{} 
 
 
 \tikzset{BBRBOXSTYLE/.style/.expand once=\bbrboxstyle}%
@@ -1055,17 +1152,18 @@
 \tikzset{BBRBOXNAMEPOSOFFSET/.style/.expand once=\@bbrboxnameposoffset}%
 
 \node[inner sep=0pt,outer sep=0pt] (\@bb at lastbox-tmpouter) {};
-\node[inner sep=.3333em,anchor=north,BBRBOXSTYLE,below right=\bbrboxyshift and \bbrboxxshift of \@bb at lastbox-tmpouter] (\@bb at lastbox)  \bgroup
+\node[inner sep=.3333em,anchor=north,BBRBOXSTYLE,minimum height=\bbrboxminheight,below right=\bbrboxyshift and \bbrboxxshift of \@bb at lastbox-tmpouter] (\@bb at lastbox)  \bgroup
 	\tikz{
-		\node[inner sep=0pt,outer sep=0pt] (phantomname) {}; %minimum width
-		\node[BBRBOXNAMEPOSOFFSET] (inner) {\begin{varwidth}{2\linewidth}\BODY\end{varwidth}};
+		\node[inner sep=0pt,outer sep=0pt,minimum height=0cm] (phantomname) {}; %minimum width
+		\node[BBRBOXNAMEPOSOFFSET,minimum height=0cm] (\@bb at lastbox-inner) {\begin{varwidth}{2\linewidth}\BODY\end{varwidth}};
 		\ifthenelse{\equal{\bbrboxafterskip}{}}{}{
-			\node[below=0cm of inner,minimum height=\bbrboxafterskip] {};
+			\node[below=0cm of \@bb at lastbox-inner,minimum height=\bbrboxafterskip] {};
 		}
-		\node[inner sep=0pt,outer sep=0pt,at=(inner.south west)] () {\phantom{\hspace{\bbrboxminwidth}}}; %minimum width
+		\node[inner sep=0pt,outer sep=0pt,at=(\@bb at lastbox-inner.south west),minimum height=0cm] () {\phantom{\hspace{\bbrboxminwidth}}}; %minimum width
 	}
 \egroup;
-\node[BBRBOXNAMEPOS,BBRBOXNAMESTYLE, inner sep=0.2ex, outer sep=0pt, overlay] () {\bbrboxname};
+\ifthenelse{\equal{\bbrboxnamepos}{none}}
+{}{\node[BBRBOXNAMEPOS,BBRBOXNAMESTYLE, inner sep=0.2ex, outer sep=0pt, overlay] () {\bbrboxname};}
 }
 
 
@@ -1148,17 +1246,64 @@
 }
 
 
+\newcommand*\bbrinputlength{0.5cm}
+\newcommand*\bbrinputhoffset{0.5cm}
+\newcommand*\bbrinputbottom{}
+\newcommand*\bbrinputtop{}
+\newcommand*\bbrinputedgestyle{}
+\newcommand*\bbrinputtopstyle{}
+\newcommand*\bbrinputbottomstyle{}
+\newcommand*\bbrinputnodestyle{}
+\newcommand*\bbrinputnodename{}
+\define at key{bbrinput}{length}[]{\renewcommand*\bbrinputlength{#1}}
+\define at key{bbrinput}{hoffset}[]{\renewcommand*\bbrinputhoffset{#1}}
+\define at key{bbrinput}{name}[]{\renewcommand*\bbrinputnodename{#1}}
+\define at key{bbrinput}{top}[]{\renewcommand*\bbrinputtop{#1}}
+\define at key{bbrinput}{bottom}[]{\renewcommand*\bbrinputbottom{#1}}
 
-\newcommandx{\bbrinput}[2][1=0.75cm]{%
-\node[above right=#1 of \@bb at lastbox.north west] (input) {#2};
-\draw[->] (input)  --++ (0,-0.75cm);
+
+\newcommand{\@bb at inputsetup}[1]{
+	%load keys	
+	\begingroup % for local keys
+
+	\setkeys{bbrinput}{#1}%
+
+	\tikzset{BBRINPUT-NODESTYLE/.style/.expand once=\bbrinputedgestyle}%	
+	\tikzset{BBRINPUT-TOPSTYLE/.style/.expand once=\bbrinputtopstyle}%	
+	\tikzset{BBRINPUT-BOTTOMSTYLE/.style/.expand once=\bbrinputbottomstyle}%			
+	\tikzset{BBRINPUT-EDGESTYLE/.style/.expand once=\bbrinputedgestyle}%
+
 }
 
-\newcommandx{\bbroutput}[2][1=0.75cm]{%
-\node[below right=#1 of \@bb at lastbox.south west] (output) {#2};
-\draw[<-] (output)  --++ (0,#1);
+\newcommand{\@bb at inputfinalize}{
+	\endgroup
 }
 
+\newcommandx*{\bbrinput}[2][2=]{%
+\@bb at inputsetup{#2}
+\ifthenelse{\equal{\bbrinputnodename}{}}
+  {\renewcommand{\bbrinputnodename}{\@bb at lastbox-input}}{} 
+  
+\node[overlay,above right={\bbrinputlength} and {\bbrinputhoffset} of \@bb at lastbox.north west, anchor=south,BBRINPUT-NODESTYLE] (\bbrinputnodename) {#1};
+\path[->] (\bbrinputnodename.south)  edge[BBRINPUT-EDGESTYLE] node[above,anchor=east,BBRINPUT-TOPSTYLE] () {\bbrinputtop} node[below,anchor=west,BBRINPUT-BOTTOMSTYLE] () {\bbrinputbottom} (\bbrinputnodename.south|-\@bb at lastbox.north);
+\@bb at inputfinalize
+}
+
+\newcommandx*{\bbroutput}[2][2=]{%
+\@bb at inputsetup{#2}
+\ifthenelse{\equal{\bbrinputnodename}{}}
+  {\renewcommand{\bbrinputnodename}{\@bb at lastbox-output}}{} 
+  
+\node[overlay,below right={\bbrinputlength} and {\bbrinputhoffset} of \@bb at lastbox.south west, anchor=north] (\bbrinputnodename) {#1};
+\draw[->] (\bbrinputnodename.north|-\@bb at lastbox.south)  -- (\bbrinputnodename.north|-\bbrinputnodename.north);
+\@bb at inputfinalize
+}
+
+\newenvironment{bbrpic}[1][]{%
+\begin{tikzpicture}[overlay,inner sep=0ex,baseline=0pt,#1]%
+}{%
+\end{tikzpicture}}
+
 %%%%%%%%%%%
 % communication
 %temporary lengths
@@ -1173,6 +1318,7 @@
 \newcommand*\bbrcomtopstyle{}
 \newcommand*\bbrcombottomstyle{}
 \newcommand*\bbrcomside{}
+\newcommand*\bbrcomoside{}
 \newcommand*\bbrcomtop{}
 \newcommand*\bbrcombottom{}
 \newcommand*\bbrcomedgestyle{}
@@ -1187,6 +1333,7 @@
 \define at key{bbrcom}{topstyle}[]{\renewcommand*\bbrcomtopstyle{#1}}
 \define at key{bbrcom}{bottomstyle}[]{\renewcommand*\bbrcombottomstyle{#1}}
 \define at key{bbrcom}{side}[]{\renewcommand*\bbrcomside{#1}}
+\define at key{bbrcom}{oside}[]{\renewcommand*\bbrcomoside{#1}}
 \define at key{bbrcom}{top}[]{\renewcommand*\bbrcomtop{#1}}
 \define at key{bbrcom}{bottom}[]{\renewcommand*\bbrcombottom{#1}}
 \define at key{bbrcom}{edgestyle}[]{\renewcommand*\bbrcomedgestyle{#1}}
@@ -1220,11 +1367,13 @@
 	\ifthenelse{\lengthtest{#2<\@bb at firstmessageheight}}
  	{#3{\@bb at firstmessageheight}}
 	{
-	  #3{0.75\baselineskip}
-	  \ifthenelse{\equal{\bbrcomtop}{}}{}{#3{0.75\baselineskip}}	
+	  #3{1.25\baselineskip}
+	  \ifthenelse{\equal{\bbrcomtop}{}}{}{#3{0.5\baselineskip}}	
            }
 
-	\setlength{\@bb at com@tmpoffset}{#2+\bbrcombeforeskip}%
+	#3{\bbrcombeforeskip}
+
+	\setlength{\@bb at com@tmpoffset}{#2}%
 }
 
 \newcommand{\@bb at comfinalize}[1]{
@@ -1233,26 +1382,31 @@
 	\endgroup
 }
 
-\newcommand{\@bbrmsg}[7]{
-	\@bb at comsetup{#1}{#6}{#7}
+\newcommand{\@bbrmsg}[8]{
+	\@bb at comsetup{#1}{#7}{#8}
 	%
-	\node[#3=\@bb at com@tmpoffset and \bbrcomlength of \@bb at lastbox.#4,BBRCOM-SIDESTYLE] (\bbrcomsidename) {\bbrcomside};
-	\path[#2] (\bbrcomsidename)  edge[BBRCOM-EDGESTYLE] node[above,BBRCOM-TOPSTYLE] (\bbrcomtopname) {\bbrcomtop} node[below,BBRCOM-BOTTOMSTYLE] (\bbrcombottomname) {\bbrcombottom} (\@bb at lastbox.#5|-\bbrcomsidename) node[inner sep=0pt,outer sep=0pt] (\bbrcomosidename) {};
+	\node[#3=\@bb at com@tmpoffset and \bbrcomlength of \@bb at lastbox.#4,anchor=#6,BBRCOM-SIDESTYLE] (\bbrcomsidename) {\bbrcomside};
+	\path[#2] (\bbrcomsidename.#6)  edge[BBRCOM-EDGESTYLE] node[above,BBRCOM-TOPSTYLE] (\bbrcomtopname) {\bbrcomtop} node[below,BBRCOM-BOTTOMSTYLE] (\bbrcombottomname) {\bbrcombottom} (\@bb at lastbox.#5|-\bbrcomsidename) node[inner sep=0pt,outer sep=0pt] (\bbrcomosidename) {};
 	%
-	\@bb at comfinalize{#7}
+	\@bb at comfinalize{#8}
 }
 
 \newcommandx{\bbrmsgto}[1]{%
-\@bbrmsg{#1}{->}{below left}{north west}{west}{\@bb at message@hoffset}{\bbrmsgspace}
+\@bbrmsg{#1}{->}{below left}{north west}{west}{east}{\@bb at message@hoffset}{\bbrmsgspace}
 }
 \newcommandx{\bbrmsgfrom}[1]{%
-\@bbrmsg{#1}{<-}{below left}{north west}{west}{\@bb at message@hoffset}{\bbrmsgspace}
+\@bbrmsg{#1}{<-}{below left}{north west}{west}{east}{\@bb at message@hoffset}{\bbrmsgspace}
 }
+\newcommandx{\bbrmsgvdots}{%
+	\bbrmsgtxt[xshift=\bbrcomlength/2,beforeskip=-0.5\baselineskip,afterskip=-0.5\baselineskip]{$\vdots$}
+}
+
+
 \newcommandx{\bbrqryto}[1]{%
-\@bbrmsg{#1}{<-}{below right}{north east}{east}{\@bb at query@hoffset}{\bbrqryspace}
+\@bbrmsg{#1}{<-}{below right}{north east}{east}{west}{\@bb at query@hoffset}{\bbrqryspace}
 }
 \newcommandx{\bbrqryfrom}[1]{%
-\@bbrmsg{#1}{->}{below right}{north east}{east}{\@bb at query@hoffset}{\bbrqryspace}
+\@bbrmsg{#1}{->}{below right}{north east}{east}{west}{\@bb at query@hoffset}{\bbrqryspace}
 }
 
 \newcommand{\@bbroracleqry}[4]{
@@ -1259,7 +1413,7 @@
 	\@bb at comsetup{#1}{#3}{#4}
 	%
 
-	\path[#2] (\@bb at lastoracle.north west) -- ++ (0,-\@bb at 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 at lastbox.east|-\bbrcomsidename) node[inner sep=0pt,outer sep=0pt] (\bbrcomosidename) {};
+	\path[#2] (\@bb at lastoracle.north west) -- ++ (0,-\@bb at com@tmpoffset) node[inner sep=0pt,outer sep=0pt] (\bbrcomsidename){\bbrcomside} edge[BBRCOM-EDGESTYLE] node[above,BBRCOM-TOPSTYLE] (\bbrcomtopname) {\bbrcomtop} node[below,BBRCOM-BOTTOMSTYLE] (\bbrcombottomname) {\bbrcombottom} (\@bb at lastbox.east|-\bbrcomsidename) node[inner sep=0pt,outer sep=0pt] (\bbrcomosidename) {\bbrcomoside};
 	%
 	\@bb at comfinalize{#4}
 }
@@ -1276,7 +1430,7 @@
 	\@bb at comsetup{#1}{#3}{#4}
 	%
 
-	\path[#2] (\@bb at lastchallenger.north east) -- ++ (0,-\@bb at 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 at lastbox.west|-\bbrcomsidename) node[inner sep=0pt,outer sep=0pt] (\bbrcomosidename) {};
+	\path[#2] (\@bb at lastchallenger.north east) -- ++ (0,-\@bb at com@tmpoffset) node[inner sep=0pt,outer sep=0pt] (\bbrcomsidename){\bbrcomside} edge[BBRCOM-EDGESTYLE] node[above,BBRCOM-TOPSTYLE] (\bbrcomtopname) {\bbrcomtop} node[below,BBRCOM-BOTTOMSTYLE] (\bbrcombottomname) {\bbrcombottom} (\@bb at lastbox.west|-\bbrcomsidename) node[inner sep=0pt,outer sep=0pt] (\bbrcomosidename) {\bbrcomoside};
 	%
 	\@bb at comfinalize{#4}
 }
@@ -1294,16 +1448,18 @@
 \newcommand*\bbrcomloopleft{}
 \newcommand*\bbrcomloopright{}
 \newcommand*\bbrcomloopcenter{}
+\newcommand*\bbrcomloopangle{50}
 \define at key{bbrcomloop}{left}[]{\renewcommand*\bbrcomloopleft{#1}}
 \define at key{bbrcomloop}{right}[]{\renewcommand*\bbrcomloopright{#1}}
 \define at key{bbrcomloop}{center}[]{\renewcommand*\bbrcomloopcenter{#1}}
+\define at key{bbrcomloop}{angle}[]{\renewcommand*\bbrcomloopangle{#1}}
 
 \newcommand{\bbrloop}[3]{
 	\begingroup % for local keys
 	\setkeys{bbrcomloop}{#3}%
 
-	\path[->] (#1) edge[bend right=50] node[midway,left] (bbrleft) {\bbrcomloopleft} (#2);
-	\path[->] (#2) edge[bend right=50] node[midway,right] (bbrright) {\bbrcomloopright} (#1);
+	\path[->] (#1) edge[bend right=\bbrcomloopangle] node[midway,left] (bbrleft) {\bbrcomloopleft} (#2);
+	\path[->] (#2) edge[bend right=\bbrcomloopangle] node[midway,right] (bbrright) {\bbrcomloopright} (#1);
 	\node[at=($(bbrleft.north west)!0.5!(bbrright.north east)$),anchor=north]() {\bbrcomloopcenter};
 
 	\endgroup
@@ -1329,12 +1485,13 @@
 \newcommand{\@bbrintertext}[6]{
 	\@bb at intertextsetup{#1}
 
-	%introduce space
-	#5{\baselineskip}
-	
-	%compute offset
-	\setlength{\@bb at com@tmpoffset}{#4+\@bb at firstmessageheight+\bbrcombeforeskip}%
+	% increase space
+	\ifthenelse{\lengthtest{#4<\@bb at firstmessageheight}}
+ 	{#5{\@bb at firstmessageheight}}
+	{#5{1\baselineskip}}
 
+	\setlength{\@bb at com@tmpoffset}{#4+\bbrcombeforeskip}%
+
 	%
 	\node[#2=\@bb at com@tmpoffset and \bbrintertexthoffset of \@bb at lastbox.#3,BBRBASE-NODESTYLE] (\bbrbasenodename) {#6};
 	%
@@ -1396,11 +1553,11 @@
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % stacking
-\providecommand{\pccenteraboveskip}{0.5\baselineskip}
-\providecommand{\pccenterbelowskip}{0.5\baselineskip}
+\providecommand{\pccenteraboveskip}{0.5\baselineskip plus 0.25\baselineskip minus 0.25\baselineskip}
+\providecommand{\pccenterbelowskip}{0.5\baselineskip plus 0.25\baselineskip minus 0.25\baselineskip}
 \newenvironment{pccenter}{%
 \setlength\topsep{0pt}\setlength\parskip{0pt}%
-\begin{center}\vspace{\pccenteraboveskip}
+\begin{center}\vspace{\pccenteraboveskip}%
 }{%
 \vspace{\pccenteraboveskip}%
 \end{center}}
@@ -1510,6 +1667,9 @@
 % create procedure
 \createprocedurecommand{procedure}{}{}{}
 
+
+
+
 %%%
 % send message
 \newcommand{\pcshortmessageoffset}{0.5cm}
@@ -1557,7 +1717,7 @@
 \define at key{pcsendmessage}{afterskip}[]{\renewcommand*\@pcsendmessageafterskip{#1}}
 
 
-\newcommand{\centerincol}[2]{%
+\newcommand{\@pc at centerincol}[2]{%
 \ifmeasuring@%
 #2%
 \else%
@@ -1565,12 +1725,14 @@
 \fi%
 }
 
+\newcommand{\centerincol}[1]{\@pc at centerincol{\thepccolumncounter}{#1}}
+
 \newcommand{\@do at sendmessage}[1]{%
 \ifthenelse{\equal{\@pcsendmessagecol}{}}{%
 \ifthenelse{\equal{\@pcsendmessagewidth}{}}{#1}{% we have some width
 \makebox[\@pcsendmessagewidth]{$\displaystyle#1$}%
 }}{%we know the column to center on
-\centerincol{\@pcsendmessagecol}{#1}%
+\@pc at centerincol{\@pcsendmessagecol}{#1}%
 }%
 }
 
@@ -1645,6 +1807,9 @@
 %
 \newcounter{pcstartgamecounter}
 
+
+\newcommand*{\pcgameprocedurestyle}{} % define pseudocode arguments for game procedures
+
 \newcommand*{\pcgamename}{\ensuremath{\mathsf{Game}}}
 \newcommand*{\gameprocedurearg}{\ensuremath{(\secpar)}}
 \newcommand*\@pcgameproofgamenr{0}
@@ -1654,16 +1819,19 @@
 
 \newenvironment{gameproof}[1][]{%
 \begingroup%
-\setkeys{pcgameproof}{#1}
+\setkeys{pcgameproof}{#1}%
 \@pc at ensureremember%
 \setcounter{pcgamecounter}{\@pcgameproofgamenr}%
 \setcounter{pcstartgamecounter}{\@pcgameproofgamenr}\stepcounter{pcstartgamecounter}%
 }{\@pc at releaseremember\endgroup}
 
+\newcommand{\setgameproceduredefaultstyle}[1]{%
 \createpseudocodecommand{gameprocedure}
   {\addtocounter{pcgamecounter}{1}\renewcommand{\@withingame}{true}}
   {\ensuremath{\pcgamename_{\thepcgamecounter}\gameprocedurearg}}
-  {}
+  {#1}
+}
+\setgameproceduredefaultstyle{}
 
 \def\@bxgame at pseudocodeA[#1]#2#3{\setkeys*{pcspace}{#1}\renewcommand{\@bxgameheader}{$\pcgamename_{#2}$\gameprocedurearg}%
 \@pseudocode[head=\ensuremath{\pcgamename_{\thepcgamecounter}\gameprocedurearg},#1]{#3}}
@@ -1695,11 +1863,15 @@
 \newcommand*\@pcgamehopedgestyle{bend left}
 \newcommand*\@pcgamehoppathestyle{}
 \newcommand*\@pcgamehophint{}
+\newcommand*\@pcgamehophintbelow{}
+\newcommand*\@pcgamehopinhint{}
 \newcommand*\@pcgamehoplength{1.5cm}
 \define at key{pcgamehop}{nodestyle}[]{\renewcommand*\@pcgamehopnodestyle{#1}}
 \define at key{pcgamehop}{edgestyle}[]{\renewcommand*\@pcgamehopedgestyle{#1}}
 \define at key{pcgamehop}{pathstyle}[]{\renewcommand*\@pcgamehoppathestyle{#1}}
 \define at key{pcgamehop}{hint}[]{\renewcommand*\@pcgamehophint{#1}}
+\define at key{pcgamehop}{belowhint}[]{\renewcommand*\@pcgamehophintbelow{#1}}
+\define at key{pcgamehop}{inhint}[]{\renewcommand*\@pcgamehopinhint{#1}}
 \define at key{pcgamehop}{length}[]{\renewcommand*\@pcgamehoplength{#1}}
 
 
@@ -1715,24 +1887,31 @@
 }
 
 \newcommandx*{\addgamehop}[3]{%
-\begingroup
-\ifthenelse{#1<#2}{}{\renewcommand*\@pcgamehopedgestyle{bend right}}
-\@pc at setupgamehop{#3}
-\begin{tikzpicture}[overlay]
-\ifthenelse{#1<#2}{
-       \path[->,GAMEHOP-PATH-STYLE] (gamenode#1) edge[GAMEHOP-EDGE-STYLE] node[above,GAMEHOP-NODE-STYLE] {\@pcgamehophint} (gamenode#2);
-}{
- 	 \path[->,GAMEHOP-PATH-STYLE] (bgamenode#1) edge[GAMEHOP-EDGE-STYLE] node[above,GAMEHOP-NODE-STYLE] {\@pcgamehophint} (bgamenode#2);
+\begingroup%
+\ifthenelse{#1<#2}%
+  {\ifthenelse{\equal{\@withingamedescription}{true}}%
+   {\renewcommand*\@pcgamehopedgestyle{bend right=20}\renewcommand*\@pcgamehopnodestyle{rotate=90}}{}%
+  }%
+  {\renewcommand*\@pcgamehopedgestyle{bend right}}%
+\@pc at setupgamehop{#3}%
+\begin{tikzpicture}[overlay]%
+\ifthenelse{#1<#2}{%
+       \path[->,GAMEHOP-PATH-STYLE] (gamenode#1) edge[GAMEHOP-EDGE-STYLE] node[above,GAMEHOP-NODE-STYLE] {\@pcgamehophint} 
+       node[below,GAMEHOP-NODE-STYLE] {\@pcgamehophintbelow} (gamenode#2);
+}{%
+ 	 \path[->,GAMEHOP-PATH-STYLE] (bgamenode#1) edge[GAMEHOP-EDGE-STYLE] node[above,GAMEHOP-NODE-STYLE] {\@pcgamehophint} 
+	 node[above,GAMEHOP-NODE-STYLE] {\@pcgamehophintbelow} (bgamenode#2);
+}%
+\end{tikzpicture}%
+\@pc at finalizegamehop%
+\endgroup%
 }
-\end{tikzpicture}
-\@pc at finalizegamehop
-\endgroup
-}
 \newcommandx*{\addstartgamehop}[2][1=\thepcstartgamecounter]{%
 \@pc at setupgamehop{#2}
 \begin{tikzpicture}[overlay]
        \node[left=\@pcgamehoplength of gamenode#1] (tmpgamenode0) {};
-       \path[->,GAMEHOP-PATH-STYLE] (tmpgamenode0) edge[GAMEHOP-EDGE-STYLE] node[above,GAMEHOP-NODE-STYLE] {\@pcgamehophint} (gamenode#1);
+       \path[->,GAMEHOP-PATH-STYLE] (tmpgamenode0) edge[GAMEHOP-EDGE-STYLE] node[above,GAMEHOP-NODE-STYLE] {\@pcgamehophint} 
+       node[below,GAMEHOP-NODE-STYLE] {\@pcgamehophintbelow} (gamenode#1);
 \end{tikzpicture}
 \@pc at finalizegamehop
 }
@@ -1740,7 +1919,8 @@
 \@pc at setupgamehop{#2}
 \begin{tikzpicture}[overlay]
        \node[right=\@pcgamehoplength of gamenode#1] (tmpgamenode#1) {};
-       \path[->,GAMEHOP-PATH-STYLE] (gamenode#1) edge[GAMEHOP-EDGE-STYLE] node[above,GAMEHOP-NODE-STYLE] {\@pcgamehophint} (tmpgamenode#1);
+       \path[->,GAMEHOP-PATH-STYLE] (gamenode#1) edge[GAMEHOP-EDGE-STYLE] node[above,GAMEHOP-NODE-STYLE] {\@pcgamehophint} 
+       node[below,GAMEHOP-NODE-STYLE] {\@pcgamehophintbelow} (tmpgamenode#1);
 \end{tikzpicture}
 \@pc at finalizegamehop
 }
@@ -1747,7 +1927,8 @@
 \newcommandx*{\addbxgamehop}[3]{%
 \@pc at setupgamehop{#3}
 \begin{tikzpicture}[overlay]
-       \path[->,GAMEHOP-PATH-STYLE] (bgamenode#1) edge[GAMEHOP-EDGE-STYLE] node[above,GAMEHOP-NODE-STYLE]] {\@pcgamehophint} (bgamenode#2);
+       \path[->,GAMEHOP-PATH-STYLE] (bgamenode#1) edge[GAMEHOP-EDGE-STYLE] node[above,GAMEHOP-NODE-STYLE]] {\@pcgamehophint} 
+       node[below,GAMEHOP-NODE-STYLE] {\@pcgamehophintbelow} (bgamenode#2);
 \end{tikzpicture}
 \@pc at finalizegamehop
 }
@@ -1755,13 +1936,57 @@
 \@pc at setupgamehop{#2}
 \begin{tikzpicture}[overlay]
        \node (looptemp1)  [right=0.5cm of gamenode#1] {};
-       \draw[->,GAMEHOP-PATH-STYLE] (gamenode#1) -- (looptemp1|-gamenode#1) -- node[right,GAMEHOP-NODE-STYLE] {\@pcgamehophint} (looptemp1|-bgamenode#1)-- (bgamenode#1);
+       \draw[->,GAMEHOP-PATH-STYLE] (gamenode#1) -- (looptemp1|-gamenode#1) -- node[right,GAMEHOP-NODE-STYLE] {\@pcgamehophint} 
+       node[left,GAMEHOP-NODE-STYLE] {\@pcgamehophintbelow} (looptemp1|-bgamenode#1)-- (bgamenode#1);
 \end{tikzpicture}
 \@pc at finalizegamehop
 }
 
 
+%%%%%%%% 
+% game description
+\newenvironment{gamedescription}[1][]{%
+\begingroup%
+\setkeys{pcgameproof}{#1}
+\renewcommand{\@withingamedescription}{true}%
+\@pc at ensureremember%
+\setcounter{pcgamecounter}{\@pcgameproofgamenr}%
+\setcounter{pcstartgamecounter}{\@pcgameproofgamenr}\stepcounter{pcstartgamecounter}%
+\begin{description}%
+}{\end{description}\@pc at releaseremember\endgroup}
 
+\newcommandx*{\describegame}[1][1=]{%
+\addtocounter{pcgamecounter}{1}%
+\item[%
+\pcdraw{
+\gdef\i{\thepcgamecounter}%
+\node[inner sep=0.0em,outer sep=0, xshift=-1ex, yshift=0.5ex] (gamenode\i) {}; 
+}%
+\ensuremath{\pcgamename_{\thepcgamecounter}\gameprocedurearg}:]%
+\begingroup\setkeys{pcgamehop}{#1}%
+\ifthenelse{\equal{}{\@pcgamehophint}}
+  {}
+  {\hspace{-0.7ex}\pcdraw{%the -0.7ex is a horrible hack to fix a whitespace issue with tikz (see http://tex.stackexchange.com/questions/22873/tikzpicture-with-overlay-takes-up-space
+\tikzset{GAMEHOP-PATH-STYLE/.style/.expand once=\@pcgamehoppathestyle}%
+\tikzset{GAMEHOP-NODE-STYLE/.style/.expand once=\@pcgamehopnodestyle}%
+\draw[->,GAMEHOP-PATH-STYLE] (gamenode\thepcgamecounter) --++ (0,-\@pcgamehoplength) node[midway,above,xshift=-1mm,rotate=90,GAMEHOP-NODE-STYLE]  {\@pcgamehophint};
+}}%
+\ifthenelse{\equal{}{\@pcgamehopinhint}}
+  {}
+  {\hspace{-0.7ex}\pcdraw{%the -0.7ex is a horrible hack to fix a whitespace issue with tikz (see http://tex.stackexchange.com/questions/22873/tikzpicture-with-overlay-takes-up-space
+\tikzset{GAMEHOP-PATH-STYLE/.style/.expand once=\@pcgamehoppathestyle}%
+\tikzset{GAMEHOP-NODE-STYLE/.style/.expand once=\@pcgamehopnodestyle}%
+\draw[<-,GAMEHOP-PATH-STYLE] (gamenode\thepcgamecounter) --++ (0,\@pcgamehoplength) node[midway,above,xshift=-1mm,rotate=90,GAMEHOP-NODE-STYLE]  {\@pcgamehopinhint};
+}%
+}%
+\endgroup%
+}
+
+
+
+
+
+
 %%%%%%%% 
 % basic pseudocode constants
 
@@ -1773,13 +1998,14 @@
 \newcommand{\pcwhile}{\@pc at increaseindent\highlightkeyword{while}}
 \newcommand{\pcendwhile}{\@pc at decreaseindent\highlightkeyword{endwhile}}
 \newcommandx*{\pcdo}[2][1=\ ,2=]{#1\highlightkeyword[#2]{do}}
-\newcommand{\pcif}{\@pc at increaseindent\highlightkeyword{if}}
-\newcommand{\pcelse}{\@pc at tmpdecreaseindent\highlightkeyword{else}}
-\newcommand{\pcelseif}{\@pc at tmpdecreaseindent\highlightkeyword{else if}}
+\newcommandx*{\pcif}[1][1=\ ]{\@pc at increaseindent\highlightkeyword[#1]{if}}
+\newcommandx*{\pcunless}[1][1=\ ]{\@pc at increaseindent\highlightkeyword[#1]{unless}}
+\newcommandx*{\pcelse}[1][1=\ ]{\@pc at tmpdecreaseindent\highlightkeyword[#1]{else}}
+\newcommandx*{\pcelseif}[1][1=\ ]{\@pc at tmpdecreaseindent\highlightkeyword[#1]{else if}}
 \newcommand{\pcfi}{\@pc at decreaseindent\highlightkeyword{fi}}
 \newcommand{\pcendif}{\@pc at decreaseindent\highlightkeyword{endif}}
 \newcommand{\pcendfor}{\@pc at decreaseindent\highlightkeyword{endfor}}
-\newcommandx*{\pcthen}[2][1=\ ,2=]{#1\highlightkeyword[#2]{then}}
+\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 at increaseindent\highlightkeyword{for}}
@@ -1789,18 +2015,20 @@
 \newcommand{\pcendforeach}{\@pc at decreaseindent\highlightkeyword{endforeach}}
 \newcommand{\pcuntil}{\@pc at decreaseindent\highlightkeyword{until}}
 \newcommand{\pccontinue}{\highlightkeyword{continue}}
-\newcommand{\pcfalse}{\highlightkeyword{false}}
-\newcommand{\pctrue}{\highlightkeyword{true}}
-\newcommand{\pcnull}{\highlightkeyword{null}}
+\newcommandx*{\pcfalse}[2][1=\ ,2=]{\highlightkeyword[#2]{false}}
+\newcommandx*{\pctrue}[2][1=\ ,2=]{\highlightkeyword[#2]{true}}
+\newcommandx*{\pcnull}[2][1=\ ,2=]{\highlightkeyword[#2]{null}}
 \newcommand{\pccomment}[1]{{\mbox{/\!\!/ } \text{\scriptsize#1}}}
 \newcommand{\pcdone}{\highlightkeyword{done}}
 \newcommand{\pcparse}{\highlightkeyword{parse}}
+\newcommand{\pcfail}{\highlightkeyword{fail}}
+\newcommand{\pcabort}{\highlightkeyword{abort}}
 
 %%%
 % highlighting 
-\definecolor{highlight-gray}{gray}{0.90}
-\newcommand{\gamechange}[2][highlight-gray]{%
-{\setlength{\fboxsep}{0pt}\colorbox{#1}{\ifmmode$\displaystyle#2$\else#2\fi}}
+\definecolor{gamechangecolor}{gray}{0.90}
+\newcommand{\gamechange}[2][gamechangecolor]{%
+{\setlength{\fboxsep}{0pt}\colorbox{#1}{\ifmmode$\displaystyle#2$\else#2\fi}}%
 }
 
 %%%



More information about the tex-live-commits mailing list