0

I am trying to generate automatic labels to work with package lineno. For this, I defined a new counter lineref to work with the command \linelabel in the command \linelabel{l\thelineref}. The problem is that the command is not working, for one reason that I do not know, the reference is working just for the last generated label. Here my MWE:

\documentclass{scrbook}
\usepackage{lineno}
\usepackage{refcount}

\newcounter{lineref}
\setcounter{lineref}{0}
\newcommand{\linemark}{\refstepcounter{lineref}\linelabel{l\thelineref}}

\begin{document}
    
\begin{linenumbers}
Lorem ipsum dolor sit\linemark amet, consectetur adipiscing elit. Duis mollis magna in erat porta, nec posuere nisi gravida. Quisque tristique dui non ante rhoncus, eu cursus augue\linemark iaculis. Vivamus ut efficitur mauris, sed condimentum metus. Nullam in mattis tortor, nec\linemark blandit mauris. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae;\linemark Curabitur elementum sem nulla, nec sagittis enim mattis ac. Maecenas iaculis odio a erat dapibus,\linemark sed sagittis urna aliquam. Pellentesque et risus eu sem\linemark varius imperdiet ut non est. Ut facilisis quam et nibh convallis, ac rutrum magna faucibus.\linemark Pellentesque molestie tempus urna, in\linemark ultricies neque varius eget. Quisque id velit mattis,\linemark tincidunt turpis\linemark id, tempus sapien.
\end{linenumbers}

\par\getrefnumber{l1}
\par\getrefnumber{l2}
\par\getrefnumber{l3}
\par\getrefnumber{l4}
\par\getrefnumber{l5}
\par\getrefnumber{l6}
\par\getrefnumber{l7}
\par\getrefnumber{l8}
\par\getrefnumber{l9}
\par\getrefnumber{l10}
\end{document}

And here my output:

enter image description here

How can I get the correct number references??

1 Answer 1

0

I found a solution based on this question

The trick is just to prevent the expansion of the command:

\documentclass{scrbook}
\usepackage{lineno}
\usepackage{refcount}

\newcounter{lineref}
\setcounter{lineref}{0}
%\newcommand{\linemark}{\refstepcounter{lineref}\linelabel{l\thelineref}}

\newcommand{\linemark}{%
  \stepcounter{lineref}%
  \begingroup\edef\x{\endgroup\noexpand\linelabel{l\thelineref}}\x%
}

\begin{document}
    
\begin{linenumbers}
Lorem ipsum dolor sit\linemark amet, consectetur adipiscing elit. Duis mollis magna in erat porta, nec posuere nisi gravida. Quisque tristique dui non ante rhoncus, eu cursus augue\linemark iaculis. Vivamus ut efficitur mauris, sed condimentum metus. Nullam in mattis tortor, nec\linemark blandit mauris. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae;\linemark Curabitur elementum sem nulla, nec sagittis enim mattis ac. Maecenas iaculis odio a erat dapibus,\linemark sed sagittis urna aliquam. Pellentesque et risus eu sem\linemark varius imperdiet ut non est. Ut facilisis quam et nibh convallis, ac rutrum magna faucibus.\linemark Pellentesque molestie tempus urna, in\linemark ultricies neque varius eget. Quisque id velit mattis,\linemark tincidunt turpis\linemark id, tempus sapien.
\end{linenumbers}

\par\getrefnumber{l1}
\par\getrefnumber{l2}
\par\getrefnumber{l3}
\par\getrefnumber{l4}
\par\getrefnumber{l5}
\par\getrefnumber{l6}
\par\getrefnumber{l7}
\par\getrefnumber{l8}
\par\getrefnumber{l9}
\par\getrefnumber{l10}
\end{document}

You must log in to answer this question.

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