加密代码:第一行号带有标签而不是硬编码

加密代码:第一行号带有标签而不是硬编码

在密码中,可以使用类似 来定义块的第一行号lnstart=3。但是,大多数时候我想根据特定行的位置(使用标签引用)来设置此数字。是否可以使用 标签lnstart,而不是硬编码第一行号?当我经常修改代码时,这非常实用。

在此处输入图片描述

梅威瑟:

\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

您可以使用refcount\getrefnumber

显然,起始编号比 指定的值多一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}

在此处输入图片描述

请注意已被弃用约 25 年。顺便说一句,使用around\tt是没有意义的。$...$\texttt{GAME}

相关内容