I am looking for a way to annotate the pdf with line numbers (like we get with the lineno package). But I want these numbers to correspond to the line number in the source (tex) file, so I know where to look to change it.
Using this answer I have built the following—numbers in parenthesis are the source file number I wish was at the margin (nevermind the lorem ipsum).
\documentclass[a5paper,12pt]{article}
\usepackage[a5paper]{geometry}
% Get the source file number
\makeatletter
\ifnum\inputlineno=\m@ne
\let\showlineno\@empty
\else
\def\showlineno{line \the\inputlineno}
\fi
\makeatother
% Package to write numbers in the margin
\usepackage{lineno}
% set the file number as the number lineno will show
\renewcommand\LineNumber{\the\inputlineno}
\begin{document}
\linenumbers
(20) This is a story of a person, and another, and another.
(21) Who tried to have some fun, doing something or another.
(22) And they did, just so, until the afternoon was gone.
(23) Thus ends our little story.
(25) A second paragraph begins, like a dance.
(26) While green serenades are played at a stance,
(27) and mosquitos bite be, pray me, delicious blood!
(28) I think we should move in this tasty neighbourhood!
(30) And so we did it all again! (But in a single line.)
(32) This is a story of a person, and another, and another. Who tried to have some fun, doing something or another. And they did, just so, until the afternoon was gone. Thus ends our little story.
(34) A second paragraph begins, like a dance. While green serenades are played at a stance, and mosquitos bite be, pray me, delicious blood! I think we should move in this tasty neighbourhood!
\end{document}
The code above is good enough for my personal use, but all lines which end up in the same paragraph are "numbered" with the last line number of a line in the paragraph (i.e.: I get labels 24 (x4), 29 (x4) 31, 33 (x4) and 35 (x4)). Is there a simple way to avoid this?
Edit: I have just noticed that if we print just the first line number (of each paragraph), then we are done (or, at least, I would be completely satisfied).