# Line number in cross reference

Cross references in Latex allow me to print the page number of a reference. How can I print the line number too (for instance the word Lily appears on page xxx, line xx)? Thank you, A

• I guess that this is not possible, but lets wait the experts. – Sigur Jan 27 '15 at 16:50
• I don't see this being possible either. The output routine doesn't work with pages and so it is never known what the current line number is to the LaTeX engine. – 1010011010 Jan 27 '15 at 17:01
• The assumption is that you want to show visible line numbers on the page as well, otherwise a reference to something that is not visible doesn't really help. You could consider the lineno package, but it has its limitations. – Werner Jan 27 '15 at 19:04
• Thanks Werner, line numbers may be hidden by setting \modulolinenumbers[200] so that line numbers are shown only every [200] numbers; none of my pages has so many lines. – user56153 Jan 27 '15 at 22:08

Following up on @Werner's suggestion, you may want to use the lineno ("line numbers") package. Load it with the option pagewise, turn line numbering on with the instruction \linenumbers, insert \linelabel{<somelabelstring>} next to the word whose line number you're interested in, and use \ref{<somelabelstring>} and \pageref{<somelabelstring>} elsewhere to create cross-references that list the line number and associated page number.

For instance, the following code

\documentclass[letterpaper]{article}
\usepackage[pagewise]{lineno}
\usepackage{lipsum}
\begin{document}
\linenumbers  % enable line numbering

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. Donec vehicula augue eu neque. Pellentesque\linelabel{word:pellentesque} habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra metus rhoncus sem. Nulla et lectus vestibulum urna fringilla ultrices.  Phasellus eu tellus sit amet tortor gravida placerat. Integer sapien est, iaculis in, pretium quis, viverra ac, nunc. Praesent eget sem vel leo ultrices bibendum. Aenean faucibus. Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. Curabitur auctor semper nulla. Donec varius orci eget risus. Duis nibh mi, congue eu, accumsan eleifend, sagittis quis, diam. Duis eget orci sit amet orci dignissim rutrum.

\newpage
\nolinenumbers % disable line numbering
The word \emph{pellentesque} occurs on line \ref{word:pellentesque} of page~\pageref{word:pellentesque}.
\end{document}


generates the following output (on page 2), after running LaTeX twice:

The word pellentesque occurs on line 4 of page 1.

• Thanks Werner and Mico, this method works. I found a workaround by setting \modulolinenumbers to a very high value, so the line numbers is not shown. – user56153 Jan 27 '15 at 22:07
• @user56153 - Indeed, executing \modulolinenumbers[<some large integer value>] will succeed in not showing the line numbers, though at the cost of not making it easy for your readers to find the line in question... – Mico Jan 27 '15 at 22:10
• In my case this is exactly what I needed: my project is more on the reading than on the reference side. – user56153 Jan 27 '15 at 22:13