5

Is it possible to have a feature similar to the lineno package that outputs the .tex file line number that the pdf line came from?

\documentclass[11pt]{article}
\usepackage[english]{babel}
\usepackage{lineno, blindtext}
\begin{document}
    \blindtext

    \begin{linenumbers}
        \blindtext % the lineno output numbers here show 8

        \blindtext % the lineno output numbers here show 10
    \end{linenumbers}
\end{document}

In other words, I do not want the paragraph to number the lines 1..N, just show 8 on the first numbered paragraph line (or all of the associated pdf output lines) and 10 for the following paragraph.

I realize this gets difficult with \input or \include entries also. I believe this feature does not exist right now, but I am curious if it is even possible with pdflatex.

Tele
  • 53

1 Answers1

5

It is not entirely impossible, because there is \inputlineno:

\documentclass[11pt]{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\newenvironment{linenumbers}{%
  \everypar{\marginpar{\the\inputlineno}}%
}{}

\begin{document} \blindtext

\begin{linenumbers}
    \blindtext % the lineno output numbers here show 8

    \blindtext % the lineno output numbers here show 10
\end{linenumbers}

\end{document}

Result

However LaTeX uses \everypar very often, thus many problems are to be expected.

Heiko Oberdiek
  • 271,626
  • 1
    I would like to see this feature added at some point. My goal is to help me to quickly identify the line in the .tex file of where I need to edit. For example, if I have a typo, I could see where to go very quickly. Do you have a recommendation if this could be added in the LaTeX scripting (painfully?) or is this something that needs to be added into the internal engine? – Tele Aug 19 '13 at 02:04
  • 2
    @Tele: There are many TeX IDEs/viewers that provide "inverse search" (e.g. source code specials with DVI or syncTeX with PDF). – Heiko Oberdiek Aug 19 '13 at 04:52