2

In cryptocode, it is possible to define the first line number of a block using something like lnstart=3. However, most of the time I want to set this number depending on the position of a specific lined (referenced using a label). Is it possible to use a label in lnstart, instead of hardcoding the first line number? It is very practical when I modify often the code.

enter image description here

MWE:

\documentclass[]{article}

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

\begin{document} \game[linenumbering]{ ${\tt GAME}$ }{ ABC\ DEF\ GHI\ \label{my:line:jkl}JKL\ MNO\ PQR }

The line \ref{my:line:jkl} is changed, is it possible not to hardcode the first line number in \verb|lnstart=XX| but use the label of the line instead?

\game[linenumbering,lnstart=3]{ ${\tt GAME}$ }{ JKLLLLL }

\end{document}

tobiasBora
  • 8,684

1 Answers1

2

You can use refcount and \getrefnumber.

Apparently, the start number is one more than the value specified with lnstart=.

\documentclass[]{article}

\usepackage{refcount} \usepackage[colorlinks]{hyperref}

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

\createprocedureblock{game}{center,boxed}{}{}{}

\begin{document} \game[linenumbering]{\texttt{GAME}}{ ABC\ DEF\ GHI\ \label{my:line:jkl}JKL\ MNO\ PQR }

The line \ref{my:line:jkl} is changed, is it possible not to hardcode the first line number in \verb|lnstart=XX| but use the label of the line instead?

\game[linenumbering,lnstart=\getrefnumber{my:line:jkl}]{\texttt{GAME}}{ JKLLLLL }

\game[linenumbering,lnstart=4]{\texttt{GAME}}{ JKLLLLL }

\end{document}

enter image description here

Please note that \tt has been deprecated for about 25 years. There's no point in using $...$ around \texttt{GAME}, by the way.

egreg
  • 1,121,712
  • Great, thank you very much! Concerning the -1, yes, it is indeed written in the documentation. Also, surprisingly, we can correct this -1 by simply adding a -1 at the end using simply lnstart=\getrefnumber{my:line:jkl}-1. And thanks for \tt, I was not aware of that deprecation. – tobiasBora Feb 15 '21 at 12:09