summaryrefslogtreecommitdiff
path: root/Master
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2018-11-11 21:55:56 +0000
committerKarl Berry <karl@freefriends.org>2018-11-11 21:55:56 +0000
commitc323e97ada4b9c09aee417afa1db2efe4ce12e99 (patch)
treee9a1e690ad071a63e0799dc28c56e8ea972b3562 /Master
parenta797deba5707684edfdc10e6c0ffe8edcc5a9664 (diff)
cryptocode (11nov18)
git-svn-id: svn://tug.org/texlive/trunk@49131 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master')
-rw-r--r--Master/texmf-dist/doc/latex/cryptocode/README12
-rw-r--r--Master/texmf-dist/doc/latex/cryptocode/cryptocode.pdfbin901298 -> 981559 bytes
-rw-r--r--Master/texmf-dist/doc/latex/cryptocode/cryptocode.tex371
-rw-r--r--Master/texmf-dist/tex/latex/cryptocode/cryptocode.sty424
4 files changed, 661 insertions, 146 deletions
diff --git a/Master/texmf-dist/doc/latex/cryptocode/README b/Master/texmf-dist/doc/latex/cryptocode/README
index 13be19840bc..4d95ad33dc3 100644
--- a/Master/texmf-dist/doc/latex/cryptocode/README
+++ b/Master/texmf-dist/doc/latex/cryptocode/README
@@ -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@arno-mittelbach.de> 22 Apr 2015 \ No newline at end of file
+ -- Arno Mittelbach <mail@arno-mittelbach.de> 11 Nov 2018 \ No newline at end of file
diff --git a/Master/texmf-dist/doc/latex/cryptocode/cryptocode.pdf b/Master/texmf-dist/doc/latex/cryptocode/cryptocode.pdf
index 20eba7122cb..e2817d214a6 100644
--- a/Master/texmf-dist/doc/latex/cryptocode/cryptocode.pdf
+++ b/Master/texmf-dist/doc/latex/cryptocode/cryptocode.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/cryptocode/cryptocode.tex b/Master/texmf-dist/doc/latex/cryptocode/cryptocode.tex
index fbbb292109f..3abe7f40b43 100644
--- a/Master/texmf-dist/doc/latex/cryptocode/cryptocode.tex
+++ b/Master/texmf-dist/doc/latex/cryptocode/cryptocode.tex
@@ -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 @@ x \sample \ZZ_q \< \< \\
\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 @@ Cryptocode makes heavy use of TIKZ (\url{https://www.ctan.org/pkg/pgf}) for this
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 @@ For denoting entropy and min-entropy use
\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 @@ The \enquote{logic} option provides the following list of commands:
\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 @@ The \enquote{ff} option provides the following list of commands:
\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 @@ In this chapter we discuss how to write pseudocode with the cryptocode library.
\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 @@ Code
\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 @@ If set to \enquote{auto} it will try to detect spacing according to keywords suc
\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 @@ Specifies the distance between body and the line.
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 @@ which is generated as
\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 @@ This is \\
\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 @@ examples the package defines the following set of constants:
\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 @@ examples the package defines the following set of constants:
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 @@ Horizontal and vertical stacking can be combined
\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,6 +1927,53 @@ Furthermore, you can add, for example a horizontal line by using the second opti
\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}
@@ -2771,6 +2853,56 @@ to add the gamehop in the middle.
\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 @@ That is, a \enquote{bbrenv} (where bbr is short for black-box reduction) environ
\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 @@ The following is a simple example drawing one (black)box with some code and inpu
\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 @@ This box is generated as
\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,16 +3011,19 @@ to specify the label. The following options are available
\index{namepos}
\index{namestyle}
+\index{abovesep}
\index{minheight}
\index{xshift}
\index{yshift}
\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 @@ style & allows to customize the node
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,14 +3048,14 @@ existing bbrbox.
\begin{bbrbox}[name=Inner Box]
\pseudocode{
\text{inner step 1} \\
- \text{inner step 2} \\
+ \text{inner step 2}
}
\end{bbrbox}
\end{bbrenv}
\pseudocode{
\text{step 4} \\
- \text{step 5} \\
+ \text{step 5}
}
\end{bbrbox}
\bbrinput{input}
@@ -2936,14 +3076,14 @@ existing bbrbox.
\begin{bbrbox}[name=Inner Box]
\pseudocode{
\text{inner step 1} \\
- \text{inner step 2} \\
+ \text{inner step 2}
}
\end{bbrbox}
\end{bbrenv}
\pseudocode{
\text{step 4} \\
- \text{step 5} \\
+ \text{step 5}
}
\end{bbrbox}
\bbrinput{input}
@@ -2979,7 +3119,7 @@ If your label contains a \enquote{,} (comma), then group the label in $\{\}$ (cu
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 @@ Following is a complete example. Notice that cryptocode takes care of the vertic
\begin{bbrbox}[name=Inner Box]
\pseudocode{
\text{inner step 1} \\
- \text{inner step 2} \\
+ \text{inner step 2}
}
\end{bbrbox}
@@ -3007,7 +3147,7 @@ Following is a complete example. Notice that cryptocode takes care of the vertic
\pseudocode{
\text{step 4} \\
- \text{step 5} \\
+ \text{step 5}
}
\end{bbrbox}
\bbrinput{input}
@@ -3028,7 +3168,7 @@ Following is a complete example. Notice that cryptocode takes care of the vertic
\begin{bbrbox}[name=Inner Box]
\pseudocode{
\text{inner step 1} \\
- \text{inner step 2} \\
+ \text{inner step 2}
}
\end{bbrbox}
@@ -3043,7 +3183,7 @@ Following is a complete example. Notice that cryptocode takes care of the vertic
\pseudocode{
\text{step 4} \\
- \text{step 5} \\
+ \text{step 5}
}
\end{bbrbox}
\bbrinput{input}
@@ -3053,7 +3193,7 @@ Following is a complete example. Notice that cryptocode takes care of the vertic
\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 @@ You can additionally provide custom names for the nodes for later reference usin
\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 specifiy the length of the arrow.
+Via the option \enquote{length} you can specify 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 @@ Via the option \enquote{length} you can specifiy the length of the arrow.
\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 @@ If the spacing between messages is not sufficient you can use the \lstinline$bbr
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 @@ can now use the \lstinline$bbrloop$ command to visualize that these two messages
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 @@ and \lstinline$\bbrqrytxt$ commands.
\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 @@ Each box can have one or more oracles which are drawn on the right hand side of
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 @@ Here options allow you to specify where the label goes (top, bottom). In additio
\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 @@ behave identically to oracles with the exception that they are to the left of th
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 @@ Here options allow you to specify where the label goes (top, bottom). In additio
\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,6 +3781,149 @@ that challenger messages need to be added after the closing \lstinline$\end{bbrc
\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}
diff --git a/Master/texmf-dist/tex/latex/cryptocode/cryptocode.sty b/Master/texmf-dist/tex/latex/cryptocode/cryptocode.sty
index 5c1edac52b2..d406c963067 100644
--- a/Master/texmf-dist/tex/latex/cryptocode/cryptocode.sty
+++ b/Master/texmf-dist/tex/latex/cryptocode/cryptocode.sty
@@ -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@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,6 +505,12 @@
\tl_use:N \l_pc_strsub_input_tl
}
+\NewDocumentCommand{\@pc@centercolifnec}{m}%
+{%
+#1%
+}
+
+
\ExplSyntaxOff
@@ -501,8 +552,12 @@
%keep hyperref happy
\ifmeasuring@\else\pc@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@beginnewline}{%
-\@pseudocodelinenumber\@pc@and\@pcln%
+\@pseudocodecodeatbeginline\@pseudocodelinenumber\@pc@and\@pcln%
%checkspace
\ifthenelse{\equal{\@pseudocodespace}{auto}}%
{\expandafter\pcind\expandafter[\value{@pc@indentationlevel}]}%
{}%
+%reset column counter
+\setcounter{pccolumncounter}{2}%
%beginmode
\@pc@modebegin}
\newcommand{\@pc@and}{&}
-\newcommand{\@pc@and@wrap@end}{\@pc@modeend&}
+\newcommand{\@pc@and@wrap@end}{\@pc@modeend&\@pseudocodecodeatendline}
\newcommand{\@pc@and@wrap@start}{\@pc@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@key{pseudocode}{beginline}[]{\renewcommand*\@pseudocodecodeatbeginline{#1}}
+\define@key{pseudocode}{endline}[]{\renewcommand*\@pseudocodecodeatendline{#1}}
+\define@key{pseudocode}{jot}[0em]{\renewcommand*\@pseudocodecodejot{#1}}
\define@key{pseudocode}{codesize}[\small]{\renewcommand*\@pseudocodecodesize{#1}}
\define@key{pseudocode}{subcodesize}[\small]{\renewcommand*\@pseudocodesubcodesize{#1}}
\define@key{pseudocode}{head}[]{\renewcommand*\@pseudocodehead{#1}}
\define@key{pseudocode}{width}[]{\renewcommand*\@pseudocodewidth{#1}}
+\define@key{pseudocode}{valign}[t]{\renewcommand*\@pseudocodeminipagealign{#1}}
\define@key{pseudocode}{xshift}[]{\renewcommand*\@pseudocodexshift{#1}}
\define@key{pseudocode}{yshift}[]{\renewcommand*\@pseudocodeyshift{#1}}
+\define@key{pseudocode}{colspace}[]{\renewcommand*\@pseudocodecolspace{#1}}
\define@key{pseudocode}{linenumbering}[on]{\ifthenelse{\equal{#1}{on}}{\renewcommand*\@pseudocodelinenumber{\pcln}}{\renewcommand*\@pseudocodelinenumber{}}}
\define@key{pseudocode}{beforeskip}[]{\renewcommand*\@pseudocodebeforeskip{#1}}
\define@key{pseudocode}{afterskip}[]{\renewcommand*\@pseudocodeafterskip{#1}}
@@ -613,8 +682,9 @@
\renewcommand*\@pc@modebegin{\begin{varwidth}{\textwidth}%
%introduce line magic for text mode
\let\@pc@lb\\%
-\renewcommandx*{\\}[2][1=,2=]{\@pc@modeend\@pc@and \ifthenelse{\equal{####1}{}}{\@pc@lb}{\@pc@lb[####1]}####2 \@pc@beginnewline}%
+\renewcommandx*{\\}[2][1=,2=]{\@pc@modeend\@pc@and \@pseudocodecodeatendline\ifthenelse{\equal{####1}{}}{\@pc@lb}{\@pc@lb[####1]}####2 \@pc@beginnewline}%
\def\pclb{\let\\\@pc@lb\relax\@pc@modeend\\}%
+\def\pcolb{\let\\\@pc@lb\relax\@pc@modeend\\}%
}%
\renewcommand*\@pc@modeend{\end{varwidth}}
}{}%
@@ -731,6 +801,8 @@
{\highlightaltkeyword{\@pc@spacesubstitution{#1}{ }{~}}}%
}
+\newcommand{\@pc@colspace}{}
+
%%%%%%%%%%%%%%%%%
% Allow for spacing
\newcommand{\@withinspaces}{false}%
@@ -748,6 +820,9 @@
\newcommand{\@pc@decreaseindent}{\ifthenelse{\equal{\@pseudocodespace}{auto}}{\pcind[-1]}{}\addtocounter{@pc@indentationlevel}{-1}}
\newcommand{\@pc@tmpdecreaseindent}{\ifthenelse{\equal{\@pseudocodespace}{auto}}{\pcind[-1]}{}}
+\newcounter{pccolumncounter}
+\setcounter{pccolumncounter}{2}
+
% store original halign
\let\@pc@halign\halign%
@@ -778,15 +853,22 @@
%
% create tabbing command
\ifcsname \pctabname\endcsname%
-\expandafter\renewcommand\csname \pctabname\endcsname{\@pc@modeend&\@pc@modebegin}%
+\expandafter\renewcommand\csname \pctabname\endcsname{\@pc@modeend&\@pc@colspace\@pc@modebegin}%
\else%
-\expandafter\newcommand\csname \pctabname\endcsname{\@pc@modeend&\@pc@modebegin}%
+\expandafter\newcommand\csname \pctabname\endcsname{\@pc@modeend&\@pc@colspace\@pc@modebegin}%
\fi%
\ifcsname \pcdbltabname\endcsname%
-\expandafter\renewcommand\csname \pcdbltabname\endcsname{\@pc@modeend&&\@pc@modebegin}%
+\expandafter\renewcommand\csname \pcdbltabname\endcsname{\@pc@modeend&&\@pc@colspace\@pc@modebegin}%
\else%
-\expandafter\newcommand\csname \pcdbltabname\endcsname{\@pc@modeend&&\@pc@modebegin}%
+\expandafter\newcommand\csname \pcdbltabname\endcsname{\@pc@modeend&&\@pc@colspace\@pc@modebegin}%
\fi%
+% create colspace command if necessary (must be empty for multicolumns
+\ifthenelse{\equal{\@pseudocodecolspace}{}}
+ {}
+ {\renewcommand{\@pc@colspace}{\hspace{\@pseudocodecolspace}}}%
+%
+%adjust row width
+\addtolength{\jot}{\@pseudocodecodejot}%
% create indent command
\expandafter\let\csname \pcindentname\endcsname\pcind%
%
@@ -801,6 +883,8 @@
\setlength{\@pc@alt@minipage@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@global@pc@nestcnt}=1}{%
\let\@pc@halign\halign%
+\newenvironment{pcmbox}{\let\halign\@pc@halign}{}%
\def\halign{%
\renewcommand{\label}[1]{\ifmeasuring@\else\pc@original@label{####1}\fi}%
\let\@pc@lb\\%
-\renewcommandx*{\\}[2][1=,2=]{\@pc@modeend\@pc@and \ifthenelse{\equal{####1}{}}{\@pc@lb}{\@pc@lb[####1]}####2 \@pc@beginnewline}%
+\renewcommandx*{\\}[2][1=,2=]{\@pc@modeend\@pc@and\@pseudocodecodeatendline \ifthenelse{\equal{####1}{}}{\@pc@lb}{\@pc@lb[####1]}####2 \@pc@beginnewline}%
\def\pclb{\let\\\@pc@lb\relax\@pc@modeend\\}%
\@pc@halign}%
}{}%
@@ -849,7 +934,7 @@
%
%do the actual mini page
\hspace{\@pseudocodexshift}%
-\begin{minipage}[t]{\@pc@minipage@length}%
+\begin{minipage}[\@pseudocodeminipagealign]{\@pc@minipage@length}%
\ifthenelse{\value{@pcsubprogstep}=0}{%
\pc@display@pseudocode{\@pseudocodehead}{\@pc@thecontent}%
}{% if sub procedure
@@ -914,8 +999,7 @@ $\begin{aligned}#2\end{aligned}$%
\newcommand{\@pc@ensureremember}{%
\ifthenelse{\value{@pc@remember}=0}{\tikzstyle{every picture}+=[remember picture]}{}%
-\addtocounter{@pc@remember}{1}
-}
+\addtocounter{@pc@remember}{1}}
\newcommand{\@pc@releaseremember}{%
\addtocounter{@pc@remember}{-1}%
@@ -949,8 +1033,8 @@ $\begin{aligned}#2\end{aligned}$%
}%
\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 @@ $\begin{aligned}#2\end{aligned}$%
\newcommand{\bbrenvnodenameprefix}{env-}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% Black Box Reduction Enviconment
+% Black Box Reduction Environment
\newenvironmentx{bbrenv}[3][1=0pt,3=0pt]{%
\addtocounter{@bb@env@nestcnt}{1}%
\renewcommand{\@bb@lastbox}{#2}%
%
% reset lengths
-\setlength{\@bb@message@hoffset}{0pt}%
-\setlength{\@bb@query@hoffset}{0pt}%
+\@pc@globalsetlength{\@bb@message@hoffset}{0pt}%
+\@pc@globalsetlength{\@bb@query@hoffset}{0pt}%
\@pc@globalsetlength{\@bb@oraclequery@hoffset}{0pt}%
\@pc@globalsetlength{\@bb@challengerquery@hoffset}{0pt}%
%
@@ -1009,6 +1093,11 @@ $\begin{aligned}#2\end{aligned}$%
}{\egroup}%
\vspace{\@bbendskip}%
\addtocounter{@bb@env@nestcnt}{-1}%
+% reset lengths
+\@pc@globalsetlength{\@bb@message@hoffset}{0pt}%
+\@pc@globalsetlength{\@bb@query@hoffset}{0pt}%
+\@pc@globalsetlength{\@bb@oraclequery@hoffset}{0pt}%
+\@pc@globalsetlength{\@bb@challengerquery@hoffset}{0pt}%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -1017,19 +1106,23 @@ $\begin{aligned}#2\end{aligned}$%
\newcommand*\bbrboxname{}
\newcommand*\bbrboxnamepos{right}
\newcommand*\bbrboxnamestyle{}
-\newcommand*\@bbrboxnamepos{below=0.5ex of \@bb@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@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@key{bbrbox}{abovesep}[]{\renewcommand*\bbrboxabovesep{#1}}
\define@key{bbrbox}{name}[]{\renewcommand*\bbrboxname{#1}}
\define@key{bbrbox}{namestyle}[]{\renewcommand*\bbrboxnamestyle{#1}}
\define@key{bbrbox}{namepos}[]{\renewcommand*\bbrboxnamepos{#1}}
\define@key{bbrbox}{style}[draw]{\renewcommand*\bbrboxstyle{#1}}
\define@key{bbrbox}{minwidth}[]{\renewcommand*\bbrboxminwidth{#1}}
-\define@key{bbrbox}{minheight}[]{\renewcommand*\bbrboxafterskip{#1}}
+\define@key{bbrbox}{addheight}[]{\renewcommand*\bbrboxafterskip{#1}}
+\define@key{bbrbox}{minheight}[]{\renewcommand*\bbrboxminheight{#1}}
\define@key{bbrbox}{xshift}[]{\renewcommand*\bbrboxxshift{#1}}
\define@key{bbrbox}{yshift}[]{\renewcommand*\bbrboxyshift{#1}}
@@ -1040,13 +1133,17 @@ $\begin{aligned}#2\end{aligned}$%
\ifthenelse{\equal{\bbrboxnamepos}{center}}
{\renewcommand{\@bbrboxnamepos}{below=0.5ex of \@bb@lastbox.north,anchor=north}}{}
\ifthenelse{\equal{\bbrboxnamepos}{left}}
- {\renewcommand{\@bbrboxnamepos}{below=0.5ex of \@bb@lastbox.north west,anchor=north west}\renewcommand{\@bbrboxnameposoffset}{below left=1\baselineskip of phantomname.south west}}{}
+ {\renewcommand{\@bbrboxnamepos}{below=0.5ex of \@bb@lastbox.north west,anchor=north west}}{}
\ifthenelse{\equal{\bbrboxnamepos}{top right}}
- {\renewcommand{\@bbrboxnamepos}{above=0cm of \@bb@lastbox.north east,anchor=south east}}{}
+ {\renewcommand{\@bbrboxnamepos}{above=0cm of \@bb@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@lastbox.north,anchor=south}}{}
+ {\renewcommand{\@bbrboxnamepos}{above=0cm of \@bb@lastbox.north,anchor=south}\renewcommand{\@bbrboxnameposoffset}{below left=0cm of phantomname.north west}}{}
\ifthenelse{\equal{\bbrboxnamepos}{top left}}
- {\renewcommand{\@bbrboxnamepos}{above=0cm of \@bb@lastbox.north west,anchor=south west}}{}
+ {\renewcommand{\@bbrboxnamepos}{above=0cm of \@bb@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@lastbox.base,anchor=south}}{}
+\ifthenelse{\equal{\bbrboxnamepos}{bottom}}
+ {\renewcommand{\@bbrboxnamepos}{above=0.5ex of \@bb@lastbox.base,anchor=north}}{}
\tikzset{BBRBOXSTYLE/.style/.expand once=\bbrboxstyle}%
@@ -1055,17 +1152,18 @@ $\begin{aligned}#2\end{aligned}$%
\tikzset{BBRBOXNAMEPOSOFFSET/.style/.expand once=\@bbrboxnameposoffset}%
\node[inner sep=0pt,outer sep=0pt] (\@bb@lastbox-tmpouter) {};
-\node[inner sep=.3333em,anchor=north,BBRBOXSTYLE,below right=\bbrboxyshift and \bbrboxxshift of \@bb@lastbox-tmpouter] (\@bb@lastbox) \bgroup
+\node[inner sep=.3333em,anchor=north,BBRBOXSTYLE,minimum height=\bbrboxminheight,below right=\bbrboxyshift and \bbrboxxshift of \@bb@lastbox-tmpouter] (\@bb@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@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@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@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 @@ $\begin{aligned}#2\end{aligned}$%
}
+\newcommand*\bbrinputlength{0.5cm}
+\newcommand*\bbrinputhoffset{0.5cm}
+\newcommand*\bbrinputbottom{}
+\newcommand*\bbrinputtop{}
+\newcommand*\bbrinputedgestyle{}
+\newcommand*\bbrinputtopstyle{}
+\newcommand*\bbrinputbottomstyle{}
+\newcommand*\bbrinputnodestyle{}
+\newcommand*\bbrinputnodename{}
+\define@key{bbrinput}{length}[]{\renewcommand*\bbrinputlength{#1}}
+\define@key{bbrinput}{hoffset}[]{\renewcommand*\bbrinputhoffset{#1}}
+\define@key{bbrinput}{name}[]{\renewcommand*\bbrinputnodename{#1}}
+\define@key{bbrinput}{top}[]{\renewcommand*\bbrinputtop{#1}}
+\define@key{bbrinput}{bottom}[]{\renewcommand*\bbrinputbottom{#1}}
+
+
+\newcommand{\@bb@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}%
+
+}
+
+\newcommand{\@bb@inputfinalize}{
+ \endgroup
+}
-\newcommandx{\bbrinput}[2][1=0.75cm]{%
-\node[above right=#1 of \@bb@lastbox.north west] (input) {#2};
-\draw[->] (input) --++ (0,-0.75cm);
+\newcommandx*{\bbrinput}[2][2=]{%
+\@bb@inputsetup{#2}
+\ifthenelse{\equal{\bbrinputnodename}{}}
+ {\renewcommand{\bbrinputnodename}{\@bb@lastbox-input}}{}
+
+\node[overlay,above right={\bbrinputlength} and {\bbrinputhoffset} of \@bb@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@lastbox.north);
+\@bb@inputfinalize
}
-\newcommandx{\bbroutput}[2][1=0.75cm]{%
-\node[below right=#1 of \@bb@lastbox.south west] (output) {#2};
-\draw[<-] (output) --++ (0,#1);
+\newcommandx*{\bbroutput}[2][2=]{%
+\@bb@inputsetup{#2}
+\ifthenelse{\equal{\bbrinputnodename}{}}
+ {\renewcommand{\bbrinputnodename}{\@bb@lastbox-output}}{}
+
+\node[overlay,below right={\bbrinputlength} and {\bbrinputhoffset} of \@bb@lastbox.south west, anchor=north] (\bbrinputnodename) {#1};
+\draw[->] (\bbrinputnodename.north|-\@bb@lastbox.south) -- (\bbrinputnodename.north|-\bbrinputnodename.north);
+\@bb@inputfinalize
}
+\newenvironment{bbrpic}[1][]{%
+\begin{tikzpicture}[overlay,inner sep=0ex,baseline=0pt,#1]%
+}{%
+\end{tikzpicture}}
+
%%%%%%%%%%%
% communication
%temporary lengths
@@ -1173,6 +1318,7 @@ $\begin{aligned}#2\end{aligned}$%
\newcommand*\bbrcomtopstyle{}
\newcommand*\bbrcombottomstyle{}
\newcommand*\bbrcomside{}
+\newcommand*\bbrcomoside{}
\newcommand*\bbrcomtop{}
\newcommand*\bbrcombottom{}
\newcommand*\bbrcomedgestyle{}
@@ -1187,6 +1333,7 @@ $\begin{aligned}#2\end{aligned}$%
\define@key{bbrcom}{topstyle}[]{\renewcommand*\bbrcomtopstyle{#1}}
\define@key{bbrcom}{bottomstyle}[]{\renewcommand*\bbrcombottomstyle{#1}}
\define@key{bbrcom}{side}[]{\renewcommand*\bbrcomside{#1}}
+\define@key{bbrcom}{oside}[]{\renewcommand*\bbrcomoside{#1}}
\define@key{bbrcom}{top}[]{\renewcommand*\bbrcomtop{#1}}
\define@key{bbrcom}{bottom}[]{\renewcommand*\bbrcombottom{#1}}
\define@key{bbrcom}{edgestyle}[]{\renewcommand*\bbrcomedgestyle{#1}}
@@ -1220,11 +1367,13 @@ $\begin{aligned}#2\end{aligned}$%
\ifthenelse{\lengthtest{#2<\@bb@firstmessageheight}}
{#3{\@bb@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@com@tmpoffset}{#2+\bbrcombeforeskip}%
+ #3{\bbrcombeforeskip}
+
+ \setlength{\@bb@com@tmpoffset}{#2}%
}
\newcommand{\@bb@comfinalize}[1]{
@@ -1233,33 +1382,38 @@ $\begin{aligned}#2\end{aligned}$%
\endgroup
}
-\newcommand{\@bbrmsg}[7]{
- \@bb@comsetup{#1}{#6}{#7}
+\newcommand{\@bbrmsg}[8]{
+ \@bb@comsetup{#1}{#7}{#8}
%
- \node[#3=\@bb@com@tmpoffset and \bbrcomlength of \@bb@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@lastbox.#5|-\bbrcomsidename) node[inner sep=0pt,outer sep=0pt] (\bbrcomosidename) {};
+ \node[#3=\@bb@com@tmpoffset and \bbrcomlength of \@bb@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@lastbox.#5|-\bbrcomsidename) node[inner sep=0pt,outer sep=0pt] (\bbrcomosidename) {};
%
- \@bb@comfinalize{#7}
+ \@bb@comfinalize{#8}
}
\newcommandx{\bbrmsgto}[1]{%
-\@bbrmsg{#1}{->}{below left}{north west}{west}{\@bb@message@hoffset}{\bbrmsgspace}
+\@bbrmsg{#1}{->}{below left}{north west}{west}{east}{\@bb@message@hoffset}{\bbrmsgspace}
}
\newcommandx{\bbrmsgfrom}[1]{%
-\@bbrmsg{#1}{<-}{below left}{north west}{west}{\@bb@message@hoffset}{\bbrmsgspace}
+\@bbrmsg{#1}{<-}{below left}{north west}{west}{east}{\@bb@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@query@hoffset}{\bbrqryspace}
+\@bbrmsg{#1}{<-}{below right}{north east}{east}{west}{\@bb@query@hoffset}{\bbrqryspace}
}
\newcommandx{\bbrqryfrom}[1]{%
-\@bbrmsg{#1}{->}{below right}{north east}{east}{\@bb@query@hoffset}{\bbrqryspace}
+\@bbrmsg{#1}{->}{below right}{north east}{east}{west}{\@bb@query@hoffset}{\bbrqryspace}
}
\newcommand{\@bbroracleqry}[4]{
\@bb@comsetup{#1}{#3}{#4}
%
- \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) {};
+ \path[#2] (\@bb@lastoracle.north west) -- ++ (0,-\@bb@com@tmpoffset) node[inner sep=0pt,outer sep=0pt] (\bbrcomsidename){\bbrcomside} edge[BBRCOM-EDGESTYLE] node[above,BBRCOM-TOPSTYLE] (\bbrcomtopname) {\bbrcomtop} node[below,BBRCOM-BOTTOMSTYLE] (\bbrcombottomname) {\bbrcombottom} (\@bb@lastbox.east|-\bbrcomsidename) node[inner sep=0pt,outer sep=0pt] (\bbrcomosidename) {\bbrcomoside};
%
\@bb@comfinalize{#4}
}
@@ -1276,7 +1430,7 @@ $\begin{aligned}#2\end{aligned}$%
\@bb@comsetup{#1}{#3}{#4}
%
- \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) {};
+ \path[#2] (\@bb@lastchallenger.north east) -- ++ (0,-\@bb@com@tmpoffset) node[inner sep=0pt,outer sep=0pt] (\bbrcomsidename){\bbrcomside} edge[BBRCOM-EDGESTYLE] node[above,BBRCOM-TOPSTYLE] (\bbrcomtopname) {\bbrcomtop} node[below,BBRCOM-BOTTOMSTYLE] (\bbrcombottomname) {\bbrcombottom} (\@bb@lastbox.west|-\bbrcomsidename) node[inner sep=0pt,outer sep=0pt] (\bbrcomosidename) {\bbrcomoside};
%
\@bb@comfinalize{#4}
}
@@ -1294,16 +1448,18 @@ $\begin{aligned}#2\end{aligned}$%
\newcommand*\bbrcomloopleft{}
\newcommand*\bbrcomloopright{}
\newcommand*\bbrcomloopcenter{}
+\newcommand*\bbrcomloopangle{50}
\define@key{bbrcomloop}{left}[]{\renewcommand*\bbrcomloopleft{#1}}
\define@key{bbrcomloop}{right}[]{\renewcommand*\bbrcomloopright{#1}}
\define@key{bbrcomloop}{center}[]{\renewcommand*\bbrcomloopcenter{#1}}
+\define@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,11 +1485,12 @@ $\begin{aligned}#2\end{aligned}$%
\newcommand{\@bbrintertext}[6]{
\@bb@intertextsetup{#1}
- %introduce space
- #5{\baselineskip}
-
- %compute offset
- \setlength{\@bb@com@tmpoffset}{#4+\@bb@firstmessageheight+\bbrcombeforeskip}%
+ % increase space
+ \ifthenelse{\lengthtest{#4<\@bb@firstmessageheight}}
+ {#5{\@bb@firstmessageheight}}
+ {#5{1\baselineskip}}
+
+ \setlength{\@bb@com@tmpoffset}{#4+\bbrcombeforeskip}%
%
\node[#2=\@bb@com@tmpoffset and \bbrintertexthoffset of \@bb@lastbox.#3,BBRBASE-NODESTYLE] (\bbrbasenodename) {#6};
@@ -1396,11 +1553,11 @@ $\begin{aligned}#2\end{aligned}$%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 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 @@ $\begin{aligned}#2\end{aligned}$%
% create procedure
\createprocedurecommand{procedure}{}{}{}
+
+
+
%%%
% send message
\newcommand{\pcshortmessageoffset}{0.5cm}
@@ -1557,7 +1717,7 @@ $\begin{aligned}#2\end{aligned}$%
\define@key{pcsendmessage}{afterskip}[]{\renewcommand*\@pcsendmessageafterskip{#1}}
-\newcommand{\centerincol}[2]{%
+\newcommand{\@pc@centerincol}[2]{%
\ifmeasuring@%
#2%
\else%
@@ -1565,12 +1725,14 @@ $\begin{aligned}#2\end{aligned}$%
\fi%
}
+\newcommand{\centerincol}[1]{\@pc@centerincol{\thepccolumncounter}{#1}}
+
\newcommand{\@do@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@centerincol{\@pcsendmessagecol}{#1}%
}%
}
@@ -1645,6 +1807,9 @@ $\begin{aligned}#2\end{aligned}$%
%
\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 @@ $\begin{aligned}#2\end{aligned}$%
\newenvironment{gameproof}[1][]{%
\begingroup%
-\setkeys{pcgameproof}{#1}
+\setkeys{pcgameproof}{#1}%
\@pc@ensureremember%
\setcounter{pcgamecounter}{\@pcgameproofgamenr}%
\setcounter{pcstartgamecounter}{\@pcgameproofgamenr}\stepcounter{pcstartgamecounter}%
}{\@pc@releaseremember\endgroup}
+\newcommand{\setgameproceduredefaultstyle}[1]{%
\createpseudocodecommand{gameprocedure}
{\addtocounter{pcgamecounter}{1}\renewcommand{\@withingame}{true}}
{\ensuremath{\pcgamename_{\thepcgamecounter}\gameprocedurearg}}
- {}
+ {#1}
+}
+\setgameproceduredefaultstyle{}
\def\@bxgame@pseudocodeA[#1]#2#3{\setkeys*{pcspace}{#1}\renewcommand{\@bxgameheader}{$\pcgamename_{#2}$\gameprocedurearg}%
\@pseudocode[head=\ensuremath{\pcgamename_{\thepcgamecounter}\gameprocedurearg},#1]{#3}}
@@ -1695,11 +1863,15 @@ $\begin{aligned}#2\end{aligned}$%
\newcommand*\@pcgamehopedgestyle{bend left}
\newcommand*\@pcgamehoppathestyle{}
\newcommand*\@pcgamehophint{}
+\newcommand*\@pcgamehophintbelow{}
+\newcommand*\@pcgamehopinhint{}
\newcommand*\@pcgamehoplength{1.5cm}
\define@key{pcgamehop}{nodestyle}[]{\renewcommand*\@pcgamehopnodestyle{#1}}
\define@key{pcgamehop}{edgestyle}[]{\renewcommand*\@pcgamehopedgestyle{#1}}
\define@key{pcgamehop}{pathstyle}[]{\renewcommand*\@pcgamehoppathestyle{#1}}
\define@key{pcgamehop}{hint}[]{\renewcommand*\@pcgamehophint{#1}}
+\define@key{pcgamehop}{belowhint}[]{\renewcommand*\@pcgamehophintbelow{#1}}
+\define@key{pcgamehop}{inhint}[]{\renewcommand*\@pcgamehopinhint{#1}}
\define@key{pcgamehop}{length}[]{\renewcommand*\@pcgamehoplength{#1}}
@@ -1715,24 +1887,31 @@ $\begin{aligned}#2\end{aligned}$%
}
\newcommandx*{\addgamehop}[3]{%
-\begingroup
-\ifthenelse{#1<#2}{}{\renewcommand*\@pcgamehopedgestyle{bend right}}
-\@pc@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);
-}
-\end{tikzpicture}
-\@pc@finalizegamehop
-\endgroup
+\begingroup%
+\ifthenelse{#1<#2}%
+ {\ifthenelse{\equal{\@withingamedescription}{true}}%
+ {\renewcommand*\@pcgamehopedgestyle{bend right=20}\renewcommand*\@pcgamehopnodestyle{rotate=90}}{}%
+ }%
+ {\renewcommand*\@pcgamehopedgestyle{bend right}}%
+\@pc@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@finalizegamehop%
+\endgroup%
}
\newcommandx*{\addstartgamehop}[2][1=\thepcstartgamecounter]{%
\@pc@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@finalizegamehop
}
@@ -1740,14 +1919,16 @@ $\begin{aligned}#2\end{aligned}$%
\@pc@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@finalizegamehop
}
\newcommandx*{\addbxgamehop}[3]{%
\@pc@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@finalizegamehop
}
@@ -1755,12 +1936,56 @@ $\begin{aligned}#2\end{aligned}$%
\@pc@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@finalizegamehop
}
+%%%%%%%%
+% game description
+\newenvironment{gamedescription}[1][]{%
+\begingroup%
+\setkeys{pcgameproof}{#1}
+\renewcommand{\@withingamedescription}{true}%
+\@pc@ensureremember%
+\setcounter{pcgamecounter}{\@pcgameproofgamenr}%
+\setcounter{pcstartgamecounter}{\@pcgameproofgamenr}\stepcounter{pcstartgamecounter}%
+\begin{description}%
+}{\end{description}\@pc@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 @@ $\begin{aligned}#2\end{aligned}$%
\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}}
+\newcommandx*{\pcif}[1][1=\ ]{\@pc@increaseindent\highlightkeyword[#1]{if}}
+\newcommandx*{\pcunless}[1][1=\ ]{\@pc@increaseindent\highlightkeyword[#1]{unless}}
+\newcommandx*{\pcelse}[1][1=\ ]{\@pc@tmpdecreaseindent\highlightkeyword[#1]{else}}
+\newcommandx*{\pcelseif}[1][1=\ ]{\@pc@tmpdecreaseindent\highlightkeyword[#1]{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}}
+\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}}
@@ -1789,18 +2015,20 @@ $\begin{aligned}#2\end{aligned}$%
\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}}
+\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}}%
}
%%%