why is this error message line number wrong?

If you want a more informative error message you can increase \errorcontextlines

\errorcontextlines=200
\documentclass[12pt]{report}
\usepackage[a4paper,widh=100mm,top=50mm]{geometry}
\begin{document}
test
\end{document}

produces

! Package keyval Error: widh undefined.

See the keyval package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

\GenericError  ...                                
                                                  \endgroup 
\KV@split ...x \KV@errx {\@tempa \space undefined}
                                                  \else \ifx \@empty #3\@emp...

\KV@do ...ax #1\@empty \else \KV@split #1==\relax 
                                                  \expandafter \KV@do \fi 
<argument> a4paper,widh=100mm,
                              top=50mm
\setkeys ... {KV@#1@}\let \@tempc \relax \KV@do #2
                                                  ,\relax ,
\@ProcessOptionsKV ...keys {#2}{\@tempa }}\@tempa 
                                                  \AtEndOfPackage {\let \@un...
l.994 \ProcessOptionsKV[p]{Gm}
                              %
? 

This shows the macro expansion levels that lead to the error, by default LaTeX turns this off as it just exposes the implementation of the various commands that is not that interesting to most uses.

TeX has no record of where a particular macro was defined, only the definition that it has at the point of the error so it has no way of saying that the argument currently being processed by \ProcessOptionsKV was originally input from the line

\usepackage[a4paper,widh=100mm,top=50mm]{geometry}

Well, package geometry calls package keyval to validate the given options. The error message shows the line from the package that showed the error, package keyval. That is okay.

But you get the message that the invalid option widh was found.

Now you can search your code for the wrong spelled option.

If you have a greater look to the error message you will find:

("C:\Program Files\MiKTeX 2.9\tex\latex\geometry\geometry.cfg")

! Package keyval Error: widh undefined.

See the keyval package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.994 \ProcessOptionsKV[p]{Gm}
                              %
Try typing  <return>  to proceed.
If that doesn't work, type  X <return>  to quit.

Now you can see that package geometry causes the error message (first line in error message above).

Tags:

Errors