4

I'm trying to do the following: put the input line number (of the code) on each paragraph in the whole pdf output. For example, for the code

\documentclass{book}
\usepackage{amsthm}
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}
\begin{document}
\chapter{First chapter}
Text text text text text text text text text.
\section{First section}
Text text text text text text text text text text text text text text   text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.
\begin{theorem}This is a theorem.
\end{theorem}
Text text text text text text text text text.

Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.
\end{document}

The output must be

enter image description here

(Note: I did this example by doing \marginpar{\the\inputlineno} on every line on the source.)

For this purpose I am trying to use the \everypar command. Hence I tried the following

\documentclass{book}
\usepackage{amsthm}
\everypar={\marginpar{\the\inputlineno}}
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}
\begin{document}
\chapter{First chapter}
Text text text text text text text text text.
\section{First section}
Text text text text text text text text text text text text text text   text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.
\begin{theorem}This is a theorem.
\end{theorem}
Text text text text text text text text text.

Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.
\end{document}

But do nothing. Also, I tried to put it after \begin{document}, hence the number appears but only for the line \chapter. By applying the code used in this post Why does \everypar not work?. I obtained the following

\documentclass{book}
\usepackage{amsthm}
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}
\begin{document}
\let\oldep\everypar \newtoks\everypar\oldep{\the\everypar\the\inputlineno}
\chapter{First chapter}
Text text text text text text text text text.
\section{First section}
Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.
\begin{theorem}This is a theorem.
\end{theorem}
Text text text text text text text text text.

Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.
\end{document}

enter image description here

It's an start of what I want. I tried to put

\let\oldep\everypar \newtoks\everypar\oldep{\the\everypar\marginpar\the\inputlineno}

but send some errors:

! You can't use `\global' after \the.
\@minipagefalse ->\global 
                      \let \if@minipage \iffalse 
l.7 \chapter{First chapter}

I'm forgetting what you said and using zero instead.

Thanks in advance.

MrSelberg
  • 151

1 Answers1

2

Like this?

\documentclass{book}
\usepackage{amsthm}
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}
\begin{document}
\let\oldpar=\par
\def\par{\hfill\the\inputlineno\oldpar}

\chapter{First chapter}
Text text text text text text text text text.
\section{First section}
Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.
\begin{theorem}This is a theorem.
\end{theorem}
Text text text text text text text text text.

Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.
\end{document}

enter image description here

JPi
  • 13,595
  • Thanks, looks good! Do you know why the theorems appears without numbers? Moreover, do you know what's the problem on using \marginpar ? I put this code in the document I'm working on ( a thesis.cls style document) and this move the headings to the left. – MrSelberg Aug 16 '15 at 12:59
  • The thesis class may have left and right pages. By default, marginpar moves around accordingly. – JPi Aug 19 '15 at 13:35