2

I would like to find a way to number the lines of a text and add references to specific lines, while at the same time retaining the ability to turn line numbering off. (This is useful when one writes a scientific paper: when submitting to a journal a revised version one often needs to refer to specific lines in order, say, to indicate where a requested revision has been made, but when submitting the final version this is no longer needed, and one thus wants to remove all line numbering.) For this I tried to use the lineno package; it does allow to number lines and to refer to specific lines, but has the drawback that, when line numbering is no longer needed, all \linelabel{} commands must seemingly be removed from the text, which is way too cumbersome. E.g., the attached MWE (which simulates a situation in which line numbering is no longer needed) returns an error unless I manually remove the \linelabel{cons} command. Any suggestion?

\documentclass{article}

\usepackage{lineno}

%\linenumbers

\nolinenumbers

\begin{document}

\noindent Lorem ipsum dolor sit amet, \linelabel{cons}consectetur adipiscing elit.

\end{document}
1
  • IMO the final version should just include the line numbers too, in case any further edits are needed. However, you can use \nolinenumbers\renewcommand{\linelabel}[1]{} to create a dummy command to avoid the error. \refs will return ?? -- is this what you want? I've opened an issue on lineno since this might be better default behaviour. Commented May 22 at 13:27

1 Answer 1

1

Referring to line numbers is usually not a very good idea. If your article contains boxes, equations or specially designed section title styles, etc., the numbering might not be very accurate.

However, if you insist on doing this, e.g. if your article is in pure text, you may consider changing the color of the line numbers into the background color to make it invisible, for example like the following:

\documentclass{article}

\usepackage{lineno}
\usepackage{xcolor}

\linenumbers

\renewcommand\linenumberfont{\color{white}}

% \nolinenumbers

\begin{document}

\noindent Lorem ipsum dolor sit amet, \linelabel{cons}consectetur adipiscing elit.

See line \ref{cons} on page \pageref{cons}.

\end{document}

enter image description here

More directly, you can even discard the line numbers by redefining \makeLineNumber to be empty:

\documentclass{article}

\usepackage{lineno}

\linenumbers
\renewcommand\makeLineNumber{}

\begin{document}

\noindent Lorem ipsum dolor sit amet, \linelabel{cons}consectetur adipiscing elit.

See line \ref{cons} on page \pageref{cons}.

\end{document}

Personally I'd recommend changing the line numbers into a lighter color, barely noticeable but can still be seen if you look hard enough. In this way there shall be less confusion about the numbering in a page containing unusual elements.

1
  • 1
    Thanks for your reply! Concerning the accuracy of line numbering, it is true that it is not 100% accurate, but it is certainly accurate enough for my needs (i.e., pointing peer reviewers to specific portions of the text where a revision has been made). The solution involving \renewcommand\linenumberfont{\color{white}} is, I think, only a partial solution, and anyway likely not acceptable to publishers to whom a manuscript needs to be sent for publishing. The solution involving \renewcommand\makeLineNumber{} instead works very well, thanks!
    – Jingo Loba
    Commented May 4, 2022 at 10:44

You must log in to answer this question.

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