在密码中,可以使用类似 来定义块的第一行号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}