0

I am trying to find a way to automatically reference the line numbers of a quote that may run on multiple lines.

I am using the lineno package to number the lines of a text and it also enables to create line labels \linelabel{} and then by using \ref{} the corresponding line number is shown. However this only works if the label is attached to a single word, not a sentence that may run on several lines. Is there a command to reference the line numbers of the beginning and the end of a quote?

2

A possible approach is to set a label to the start and end of the sentence and refer to that. As an extension you can define a command that checks if the starting line number is the same as the ending line number and print a single number if it is and a range otherwise.

The numbers can be extracted from the reference with the \getrefnumber command from the refcount package, and the test can be performed using \ifthenelse from the ifthen package.

MWE:

\documentclass{article}
\usepackage{lineno}
\usepackage{refcount}
\usepackage{ifthen}
\newcommand{\linerange}[2]{%
\ifthenelse{\equal{\getrefnumber{#1}}{\getrefnumber{#2}}}{%
line \ref{#1}%
}{%
lines \ref{#1}--\ref{#2}%
}%
}
\begin{document}
\linenumbers
\begin{quote}
I am using the "lineno" package \linelabel{starta}to number the lines
of a text and it also enables to create line labels \verb+\linelabel{}+
and then by using \verb+\ref{}+ the corresponding line number is
shown\linelabel{enda}. However this only works if the label is attached
to a single word, not a sentence that may run on several lines.
Is there a command to reference the line numbers of the beginning and
\linelabel{startb}the end\linelabel{endb} of a quote?
\end{quote}
See lines \ref{starta}, \ref{enda} and \ref{startb}, \ref{endb}.\\
See \linerange{starta}{enda} and \linerange{startb}{endb}.
\end{document}

Result:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.