I'm using \cryptocode to display codes like:
By default, it seems that it's not floating. However, when the games are big I'd prefer to make them float. Moreover, to refer to them, I'd like to just type \cref{mygame} and get a link like:
For now, even the manual method using anchors and manually copying the name of the code does not work: the link does not point to the game. And I've no idea how I could automatically ask cref to add the name of the game.
MWE
\documentclass[]{article}
\usepackage{amsmath}
\usepackage [
n,
advantage,
operators,
sets,
adversary,
landau,
probability,
notions,
logic,
ff,
mm,
primitives,
events,
complexity,
asymptotics,
keys
] {cryptocode}
\createprocedureblock{game}{center,boxed}{}{}{}
\usepackage{lipsum}
\usepackage{float}
\floatstyle{ruled} % Defines the "rule" style for next environments defined using newfloat.
\newfloat{protocol}{htb!}{Protocol}
\usepackage{hyperref}
\usepackage{cleveref}
\crefname{protocol}{Protocol}{Protocols}
\Crefname{protocol}{Protocol}{Protocols}
\begin{document}
\lipsum[1-4]\
As you can see if there is not eough space, the game is pushed on the next page leaving a large white space:
\begin{pcimage}
{\normalfont\game[linenumbering]{$\indcpa_\enc^\adv(\secpar)$}{\phantomsection\label{mygame}
b \sample \bin \
(\pk,\sk) \sample \kgen (\secparam) \
(\state,m_0,m_1) \sample \adv(\secparam, \pk, c) \
c \sample \enc(\pk,m_b) \
b' \sample \adv(\secparam, \pk, c, \state) \
\pcreturn b = b'
}}
\end{pcimage}
Moreover, I cannot really refer to it: \cref{mygame}.
\section{What I would like to do}
Sometimes (for big games mostly), I would prefer to be able to put it inside a float, and I'd like to be able to refer to them using cref, like I can do for protocols: \cref{protocol:myprotocol} (this should be feasible for all games). More precisely, what I'd like is that when I type \verb|\cref{mygame}| I should get something like \hyperlink{mygame}{$\indcpa_\enc^\adv(\secpar)$}, but I don't know why the link is broken. \lipsum[1]
Note that there is no white space anymore after this line.
\begin{protocol}
\caption{My protocol\label{protocol:myprotocol}}
\lipsum[1-2]
\end{protocol}
\lipsum[1]
\end{document}




\newfloatdeclaration before\floatstyle{ruled}. – egreg Nov 20 '21 at 20:58\AtBeginDocument{\let\@pc@original@label\label}can be replaced by\pcfixcleveref(or\pcfixhyperrefif you use only hyperref but not cleveref) in cryptocode >= 0.43, see https://github.com/arnomi/cryptocode/issues/5. – real-or-random Dec 23 '21 at 10:37