I have this very short TeX file
\documentclass[12pt]{report}
\usepackage[a4paper,widh=100mm,top=50mm]{geometry}
\begin{document}
test
\end{document}
in which I have made an mistake writing widh instead of width. Now when I compile via pdflatex I would expect something like
! Error message: blablabala
l.2 \usepackage[a4paper,widh=100mm,top=50mm]{geometry}
which would help me spot the line in which the error originated in my source file (that would be the second line).
But instead I receive this error message
! Package keyval Error: widh undefined.
See the keyval package documentation for explanation.
Type H <return> for immediate help.
...
l.994 \ProcessOptionsKV[p]{Gm}
Why so? Furthermore how is it supposed to be helpful to , not only not show the line in which the error occurred, but even to show a different line in a different file, which?
My take on it is that l.994 \ProcessOptionsKV[p]{Gm} is some codepart that was called with my data from line 2 and the error only occured then and that it fine, but why then would the message not in addition state the file and a backtrack / trace to the actual line?
update to clarify the issue
I made some more testing and adapted the tex source to this
\documentclass[12pt]{report}
\usepackage[a4paper,widh=100mm,top=50mm]{geometry}
\errmessage{line three intentionally throws an error}
\begin{document}
\end{document}
which on purpose throws an error in the third line and the output shows then
/usr/share/texmf-dist/tex/latex/geometry/geometry.sty:994: Package keyval Error
: widh undefined.
See the keyval package documentation for explanation.
Type H <return> for immediate help.
...
l.994 \ProcessOptionsKV[p]{Gm}
%
)
./testerrorlinemadness.tex:3: line three intentionally throws an error.
l.3 ...e{line three intentionally throws an error}
clearly making the point that when raising the first error my source text file had not yet evaluated the third line and hence has imho no real excuse to **not to feature the current line number at occurrence of error*.
Update, how would other languages handle error messages?
Since the comments and answers had a tendency to argue that it is completely natural and acceptable that the example feature would not report the more correct line number (the line where the error was provoked in the original tex file) I would like to show that other languages can indeed give a trace back to the point where the error occured.
To do so lets have a look at a short example how javascript would have handled a comparable error reporting task
// EXAMPLE how error message and propagation work in many another
// language (example javascript)
//
// description: what would be MACROS in latex such as /usepackage
// would be named FUNCTIONS in javascript.
// To keep with the example in latex and allow comparison
// we make up a two functions 1: "usepackage" and 2: "geometry"
function usepackage(parameter)
{
geometry(parameter);
}
function geometry(parameter)
{
ProcessOptionsKV=parameter.width.length;
}
// When now calling the usepackage correctly no error occurs
usepackage( {width:"12mm"} )
// But when providing wrong input, there is an error message
usepackage( {widh:"12mm"} )
// this is the error message
/*
Exception: TypeError: parameter.width is undefined
geometry@Scratchpad/1:16:3
usepackage@Scratchpad/1:11:3
@Scratchpad/1:24:1
*/
// reading the message shows backtracingly line by line
// how the error came about. after the Error message it shows that
// the error occured in
// 1. function "geometry" in file "Scratchpad/1" line 16,
// which was called from
// 2. function "usepackage" in file "Scratchpad/1" line 11
// which was provided with the wrong input from
// 3. the file "Scratchpad/1" line 24
//
pdftexwith the-file-line-erroroption (see, e.g.,man pdftex). Edit: Also note thatlatex.ltxsets\errorcontextlines=-1; you could also reset that parameter. – GuM Aug 12 '16 at 20:13within combination with some english text would not allow to spot that easily. My easy example is no real excuse or explanation why the error is not reported as I suggest, is it? – humanityANDpeace Aug 12 '16 at 20:47latex.ltxand the\errorcontextlines=-1? – humanityANDpeace Aug 12 '16 at 20:48wdthwas initially entered? It shows all the information it has at the point that an error is first encountered, which is when the keys are processed with\ProcessOptionsKV– David Carlisle Aug 12 '16 at 20:56\errorcontextlinesparameter tells how many of these pending levels should be displayed to the user when an error occurs. The LaTeX format, of whichlatex.ltxis the source code, sets this number to -1 (no intermediate level is displayed), because its authors felt the user would have been shocked by the sight of LaTeX’s internal macros… (;-) – GuM Aug 12 '16 at 21:04\input{chapter2}on line 5 and you had an error on line 100 of chapter 2, you seem to be arguing that tex should report the error as line 5 not line 100?? (at this level there is no difference from using a package and having an error on line 994 and inputting a chapter and having an error on line 100) – David Carlisle Aug 12 '16 at 21:11\ProcessOptionsKVfinally result in an error, pdflatex has digressed (potentially executing several functions). Now it would make sense that either at each digression the necessary information is forwared, or that upon an error, the whole stack is presented as to allow a user to see the actual code line where it occured. Look at the addition I made to the question. It is apparent that pdflatex continues after the strange error at line 3. Hence if the error would have been signalled all the way up it should have been possible to tell that it was in line 2 – humanityANDpeace Aug 12 '16 at 21:11\errorcontextlinesdoes not produce the information you are asking for. The reason is that you are (comprehensibly!) misunderstanding how TeX behaves in this case. From TeX’s point of view, line 2 of your source file contains no error at all: it just asks to load a certain file and to pass it certain—as it were—“command line arguments”. Only the loaded file knows how to interpret those arguments and, when it detects that one of them is meaningless, throws an error. – GuM Aug 12 '16 at 21:15show_context) in the source code of TeX (texdoc tex). It has a condition (name>17) to stop when the first "external" file is reached, among lines in the input stack. This made sense for Knuth given the way he imagined TeX being used. I can confirm that if I recompile TeX without that first condition (NOTE: if you change TeX you should rename it), then I indeed see line number from the original file: but it's going to be on line 3: the first token after the\usepackageends (error or not). (Example.) – ShreevatsaR May 25 '17 at 16:47