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}
\nolinenumbers\renewcommand{\linelabel}[1]{}
to create a dummy command to avoid the error.\ref
s will return ?? -- is this what you want? I've opened an issue onlineno
since this might be better default behaviour.