1

I have data which I do not want to change or duplicate it. I would like to have a line number after each empty line. It would be great if this can be done by some presentation only.

Data

This is a sentence. 

This is a sentence 2. 

which should be shown like

1 This is a sentence. 

2 This is a sentence 2. 

and you can choose where you show the number (margin next to the body etc).

How can you add such linenumbers at the start of each line?

  • 2
    Could you show how you would use this a minimal example? For example, wrapping the lines inside some magical environment, say...? – Werner Jun 15 '15 at 06:44
  • You could use sections. Have a look at Herbert and egreg's answers at this old question of mine. http://tex.stackexchange.com/q/40748/7093 – McGafter Jun 15 '15 at 10:34

1 Answers1

1

In plain \TeX nique I would do it this way. "Each empty line", should be \everypar. I removed the need for empty lines by \obeylines.

\newdimen\linenowd\setbox0=\hbox{9999}\linenowd=\wd0
\newdimen\linenoskipamount\linenoskipamount=5pt
\newcount\lineno\lineno=1
\def\linenoskip{\hskip \linenoskipamount}
\def\beginlineno{\begingroup\obeylines\global\advance\lineno by -1\everypar={\global\advance\lineno by 1\hbox to \linenowd{\hfill\the\lineno\linenoskip}}}
\def\endlineno{\endgroup}

\beginlineno
This is a sentence.
This is another sentence.
\endlineno
\bye
ikrabbe
  • 603