[Tex/LaTex] line numbering including blank (empty lines)

formattingline-numbering

I have a latex document and I would like to include line numbers in it, the tricky part is that I need to count the blank (empty) lines too (emulating what MSWord does :(.
I know I could use the package lineno but it doesn't seem to have an option for counting blank lines.

any ideas? thanks

Best Answer

You can insert a blank line that will be marked using a macro

enter image description here

\documentclass{article}

\usepackage{lineno,lipsum}

\newcommand{\markblankline}{\par\mbox{}\par}

\begin{document}

\linenumbers

\lipsum[1]

\markblankline

\lipsum[2]

\markblankline

\lipsum[3]

\end{document}

Using such explicit blank-line-numbering seems extreme. However, your document may contain a whole host of formatting options that might not interact well with lineno as it stands.

If your document contains straight-forward text, perhaps the following may be of use:

\documentclass{article}

\usepackage{lineno,lipsum,everyhook}

\newcommand{\markblankline}{\par\mbox{}\par}

\begin{document}

\linenumbers

\lipsum[1]

\PushPreHook{par}{\hspace*{-\parindent}\makebox[\linewidth]{}\\\hspace*{\parindent}}

\lipsum[2-3]

\end{document}

The above code provides the same output by appending a blank line with every issue of \par thanks to the everyhook package.