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}

1 Answer 1

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.

1
  • 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
    Commented Feb 15, 2021 at 12:09

You must log in to answer this question.

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