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.

  • Welcome to TeX.SX!. Just out of curiosity, what do 8 and 10 represent in your case? – karlkoeller Aug 17 '13 at 7:36
  • @karlkoeller: The line numbers of the lines in the source file. – Heiko Oberdiek Aug 17 '13 at 7:55
  • @Heiko thanks, I didn't understand the question correctly! – karlkoeller Aug 17 '13 at 7:59
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.

| improve this answer | |
  • 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 2: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 4:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.