cleveref 和 lineno

cleveref 和 lineno

我怎样才能开始cleveref工作?\linelabellineno

\documentclass{article}



\usepackage{lineno}
\usepackage{cleveref}



\begin{document}
\linenumbers

Bla bla bla  bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla \linelabel{foo}  bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla

\cref{foo} doesn't work because the cleveref line doesn't get written to the aux file, but \ref{foo} works.
\end{document}

答案1

这是一个快速破解方法,使用\@LN@linelabel它来进行线路标记。

首先我使用旧版本的命令,再次提取标签值,然后设置一个备份计数器,设置linenumber为标签值,减少它并再次步进以获得正确的值\cref@currentlabel,然后直接写入标签cleveref

\documentclass{article}
\usepackage{refcount}


\usepackage{lineno}
\usepackage{cleveref}

\newcounter{backuplineno}

\crefname{linenumber}{linenumber}{linenumbers}
\Crefname{linenumber}{Linenumber}{Linenumbers}



\makeatletter
\let\@LN@linelabelorig\@LN@linelabel
\renewcommand{\@LN@linelabel}[1]{%
  \@LN@linelabelorig{#1}%
  \IfRefUndefinedExpandable{#1}{}{%
    \setcounter{backuplineno}{\value{linenumber}}
    \addtocounter{linenumber}{-1}%
    \setcounter{linenumber}{\numexpr\getrefnumber{#1} -1}
    \refstepcounter{linenumber}%
    \protected@write\@auxout{}%
    {\string\newlabel{#1@cref}{{\cref@currentlabel}{\thepage}}}%
    \setcounter{linenumber}{\value{backuplineno}}
  }%
}
\makeatother

\begin{document}
\linenumbers

Bla bla bla  bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla \linelabel{foo}  bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla

\cref{foo} doesn't work because the cleveref line doesn't get written to the aux file, but \ref{foo} works.
\end{document}

在此处输入图片描述

相关内容