1

I'm using cryptocode to display some crypto-related things in a memoir document, but I'd like to decrease the default spacing, which is huge (especially when using one half spacing in the rest of the document):

enter image description here

I managed to make everything smaller but I still have a few issues, sometimes I've too much spacing (in red squares, sometimes it's even sometimes more than in the original picture), sometimes I've not enough (in green circles):

enter image description here

Any idea how to fix that? MWE

\documentclass{memoir}

\checkandfixthelayout
%% Configure 1.5 spacing between lines
\OnehalfSpacing
% even if not documented, one must use checkandfixthelayout not to break the title template
% https://tex.stackexchange.com/questions/601273/memoir-checkandfixthelayout-required-for-single-onehalfspacing
\checkandfixthelayout

\usepackage [
lambda,
advantage,
operators,
sets,
adversary,
landau,
probability,
notions,
logic,
ff,
mm,
primitives,
events,
complexity,
asymptotics,
keys
] {cryptocode}
\createprocedureblock{interactGame}{center,boxed}{}{}{}


\begin{document}

What I managed to have (problem: still too much space between two arrows):

\NewExpandableDocumentCommand{\mysendmessageleft}{m}{\sendmessage{<-,inner sep=0pt}{topstyle={inner sep=2pt},top={$#1$}}}
\NewExpandableDocumentCommand{\mysendmessageright}{m}{\sendmessage{->,inner sep=0pt}{topstyle={inner sep=2pt},top={$#1$}}}
\NewDocumentEnvironment{gameInteract}{mb}{
\begin{Spacing}{0}%
  \interactGame[linenumbering]{#1}{#2\vspace{5mm}}
\end{Spacing}\par\vskip\baselineskip % Seems required or the next line will be eated up.
}{}

\begin{gameInteract}{My protocol}
    \textbf{Challenger}                           \>                                      \> \textbf{Adversary} \\
    \> \mysendmessageleft{(m^{(0)},m^{(1)})} \> \text{Compute $m^{(0)}$ and $m^{(1)}$} \\
    c \sample \bin                                  \>                                      \> \\
    (k, t_k) \gets \textsf{Gen}(1^\lambda, m^{(c)}) \>                                      \> \\
    \> \mysendmessageright{k}                \> \\
    \> \mysendmessageleft{\tilde{c}}         \> \\
    \pcreturn \tilde{c} = c                         \>                                      \>
\end{gameInteract}


What I have by default:
{\normalfont \interactGame[linenumbering]{My protocol}{
    \textbf{Challenger}                           \>                                      \> \textbf{Adversary} \\
                                                  \> \sendmessageleft*{(m^{(0)},m^{(1)})} \> \text{Compute $m^{(0)}$ and $m^{(1)}$} \\
  c \sample \bin                                  \>                                      \> \\
  (k, t_k) \gets \textsf{Gen}(1^\lambda, m^{(c)}) \>                                      \> \\
                                                  \> \sendmessageright*{k}                \> \\
                                                  \> \sendmessageleft*{\tilde{c}}         \> \\
  \pcreturn \tilde{c} = c                         \>                                      \>
}}

\end{document}

2 Answers 2

2

The body of \gameInteract is not typeset with much attention to line spacing. You can get a uniform distance by setting Spacing to 1.2 and by smashing the labels above the arrows. I also reduced their size with \scriptstyle. Remove it if you don't like the style.

\documentclass{memoir}
\usepackage{amsmath}

\OnehalfSpacing
\checkandfixthelayout

\usepackage [
lambda,
advantage,
operators,
sets,
adversary,
landau,
probability,
notions,
logic,
ff,
mm,
primitives,
events,
complexity,
asymptotics,
keys
] {cryptocode}

\createprocedureblock{interactGame}{center,boxed}{}{}{}

\NewDocumentCommand{\mysendmessageleft}{m}{%
  \sendmessage{<-,inner sep=0pt}{
    topstyle={inner sep=2pt},
    top=\smash[t]{$\scriptstyle#1$},
  }%
}
\NewDocumentCommand{\mysendmessageright}{m}{%
  \sendmessage{->,inner sep=0pt}{
    topstyle={inner sep=2pt},
    top=\smash[t]{$\scriptstyle#1$},
  }%
}

\NewDocumentEnvironment{gameInteract}{m+b}
 {%
  \par\begin{Spacing}{1.2}
  \interactGame[linenumbering]{#1}{#2}
  \par\addvspace{\baselineskip}
  \end{Spacing}
 }{}

\begin{document}

What I managed to have (problem: still too much space between two arrows):

\begin{gameInteract}{My protocol}
  \textbf{Challenger} \> \> \textbf{Adversary} \\
    \> \mysendmessageleft{(m^{(0)},m^{(1)})} \> \text{Compute $m^{(0)}$ and $m^{(1)}$} \\
  c \sample \bin \\
  (k, t_k) \gets \textsf{Gen}(1^\lambda, m^{(c)}) \\
    \> \mysendmessageright{k} \\
    \> \mysendmessageleft{\tilde{c}} \\
  \pcreturn \tilde{c} = c
\end{gameInteract}

Some other text to see what happens after the game.

\end{document}

enter image description here

1
  • Thanks a lot! never heard of \par\addvspace{\baselineskip} before, good to know!
    – tobiasBora
    Commented Nov 24, 2021 at 23:52
2

You can eliminate the "red boxes" by adding negative space to the appropriate newlines \\ of the tabbing environment using the optional parameter \\[<vertical space>].

The space between the head line and the body is controlled by bodylinesep. I am not sure if you want to increase or decrease the default (set to -3pt in the example to show the effect).

The "green circle" issue disappears after simplifying the gameInteract environment.

b

\documentclass{memoir}

\checkandfixthelayout
%% Configure 1.5 spacing between lines
\OnehalfSpacing
% even if not documented, one must use checkandfixthelayout not to break the title template
% https://tex.stackexchange.com/questions/601273/memoir-checkandfixthelayout-required-for-single-onehalfspacing
\checkandfixthelayout

\usepackage [
lambda,
advantage,
operators,
sets,
adversary,
landau,
probability,
notions,
logic,
ff,
mm,
primitives,
events,
complexity,
asymptotics,
keys
] {cryptocode}
\createprocedureblock{interactGame}{center,boxed}{}{}{}

\begin{document}
    
    What I managed to have (problem: still too much space between two arrows):
    
    \NewExpandableDocumentCommand{\mysendmessageleft}{m}{\sendmessage{<-,inner sep=0pt}{topstyle={inner sep=2pt},top={$#1$}}}
    \NewExpandableDocumentCommand{\mysendmessageright}{m}{\sendmessage{->,inner sep=0pt}{topstyle={inner sep=2pt},top={$#1$}}}
    \NewDocumentEnvironment{gameInteract}{mb}{
%       \begin{Spacing}{0}% Not needed
            \interactGame[linenumbering,bodylinesep=-3pt]{#1}{#2}  % changed <<<<<<<<<<<<<<<<<
%       \end{Spacing}\par\vskip\baselineskip % Seems required or the next line will be eated up.
    }{}
    
    \begin{gameInteract}{My new protocol}   
        \textbf{Challenger}                           \>                                      \> \textbf{Adversary} \\
        \> \mysendmessageleft{(m^{(0)},m^{(1)})} \> \text{Compute $m^{(0)}$ and $m^{(1)}$} \\[-1.5ex]% changed <<<<<<<<<<<<<<<<<
        c \sample \bin                                  \>                                      \> \\
        (k, t_k) \gets \textsf{Gen}(1^\lambda, m^{(c)}) \>                                      \> \\
        \> \mysendmessageright{k}                \> \\[-1.5ex]% changed <<<<<<<<<<<<<<<<<
        \> \mysendmessageleft{\tilde{c}}         \> \\
        \pcreturn \tilde{c} = c                         \>                                      \>
    \end{gameInteract}
    
    
    What I have by default:
    {\normalfont \interactGame[linenumbering]{My protocol}{
            \textbf{Challenger}                           \>                                      \> \textbf{Adversary} \\
            \> \sendmessageleft*{(m^{(0)},m^{(1)})} \> \text{Compute $m^{(0)}$ and $m^{(1)}$} \\[-1.5ex]
            c \sample \bin                                  \>                                      \> \\
            (k, t_k) \gets \textsf{Gen}(1^\lambda, m^{(c)}) \>                                      \> \\
            \> \sendmessageright*{k}                \> \\[-2.5ex]
            \> \sendmessageleft*{\tilde{c}}         \> \\
            \pcreturn \tilde{c} = c                         \>                                      \>
    }}
    
    
\end{document}
1
  • Thanks for your answer, but I was looking more for an automated way to remove the space around arrows (manually doing it is tedious on big documents). Spacing was an attempt to redious the spacing documentwise (removing it adds some space between lines, and I don't want to correct them all individually), but it's not perfect. I'd love to hear a solution with the \`. And thanks for the bodylinesep, for now it fixes the problem. Also, I realized that codesize=\scriptsize` decreases quite significantly the space, so arrows space are less obviously wrong, but it's still not ideal.
    – tobiasBora
    Commented Nov 24, 2021 at 18:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .