# \inputlineno broken?

The following code demonstrates that \inputlineno is broken. It does not give the correct line numbers for macros\groups, it treats a macro as a singular line. I see why this could be understood as the TeX file is treated as a token stream and macro's arguments may or may not be outputed.

So \inputlineno is a sort of "expanded" line number.

\documentclass[12pt,oneside]{book}

\usepackage{xcolor}
\usepackage{everypage}

\AddEverypageHook{\typeout{Page = \thepage, Line = \the\inputlineno}}

\usepackage{lipsum}
\begin{document}
\textcolor{blue}{\lipsum}
\newpage

\textcolor{red}{This is a test cache1
\newpage
\lipsum
\newpage
\lipsum}

\newpage
\lipsum
\newpage
test
\newpage
xxxxxxxxxxxxxxxx
\end{document}


So, That may be the intended behavior but it is not what is generally said about inputlineno being the "source code line value".

Is there any way to fix this or get the actual source code line before expansion.

The above outputs

Page = 1, Line = 13
[1]
Page = 2, Line = 14
[2]
Page = 3, Line = 21 % note that texcolor ends here and spans 4 pages
[3]
Page = 4, Line = 21
[4]
Page = 5, Line = 21
[5]
Page = 6, Line = 21
[6]
Page = 7, Line = 24
[7]
Page = 8, Line = 26
[8]
Page = 9, Line = 26
[9]
Page = 10, Line = 28
[10]
Page = 11, Line = 30


while I want

Page = 1, Line = 13
[1]
Page = 2, Line = 13
[2]
Page = 3, Line = 17
[3]
Page = 4, Line = 19
[4]
Page = 5, Line = 19
[5]
Page = 6, Line = 21
[6]
Page = 7, Line = 21
[7]
Page = 8, Line = 25
[8]
Page = 9, Line = 25
[9]
Page = 10, Line = 27
[10]
Page = 11, Line = 29


(there may be a discrepancy because \inputlineno and page seem to occur and the end of the page and source line below where it actually looks visually)

Basically all I need is to get the actual source code line that matches the page it is on before any expansions. So if some macro adds 100 pages of junk internally but only uses one short source code line then that is all I want.

It is similar to syntex but I would like to avoid and external processing.

I realize that macros can do anything they want, but I am not concerned with that. I am only concerned with mapping page numbers to actual source lines. If there is no page number that maps to some line then it doesn't effect what I'm trying to do. If there are lines that don't map to pages then it doesn't bother me. But for every source line that shows up on a page in some way, I want that page number.

Macros that generate stuff internally, that are not part of the actual source code, get whatever pages they span mapped to their line.

The \textcolor macro usage above demonstrates this. It is not logical that we should ignore everything inside the macro and treat it as a singular line(which the first output demonstrates) when it is clear that it's arguments show up on different pages and there exists a mapping from the pages to the lines that is more informative than treating the macro as a atomic unit.

## 1 Answer

Your assumption of the cause of the error is flawed. Macros do have some effect here but the basic issue is unrelated to macros. Below is a document with no macros at all between begin document and end document but almost every page is reported as being on the same line, as the entire paragraph is processed as a unit for line breaking.

AAA:Page = 1, Line = 15
Page = 1, Line = 85
[1{/usr/local/texlive/2016/texmf-var/fonts/map/pdftex/updmap/pdftex.map}
BBB:Page = 1, Line = 85
]
Page = 2, Line = 85
[2]
Page = 3, Line = 85
[3]
Page = 4, Line = 85
[4]
Page = 5, Line = 85
[5]
Page = 6, Line = 85
[6]
Page = 7, Line = 87
[7]


Note how the \typeout{AAA within the paragraph reports line 15, as that is expanded at that point, the \typeout that you had in the page hook are essentially executed by the \par from the blank line on line 85.

The above log being generated by

\documentclass[12pt,oneside]{book}

\usepackage{everypage}

\setlength\textwidth{5cm}
\setlength\textheight{\dimexpr\topskip+20\baselineskip}

\AddEverypageHook{\typeout{Page = \thepage, Line = \the\inputlineno}}

\raggedright
\begin{document}

One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.\typeout{AAA:Page = \thepage, Line = \the\inputlineno}
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.

\end{document}