Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I've created my own package, but, when I use it in a new document, and pdflatex find an error using a custom command (defined in my own package), it shows me only the error line where this command was used (respect to the main file), and not the error line inside the package itself (respect to the package file).

Anybody knows how can I force pdflatex shows me the error line inside the package file (i.e, forcing navigation inside includes or packages)?

share|improve this question
3  
TeX can't do it. It doesn't keep track of files and line numbers when it stores definitions. –  egreg Nov 2 '12 at 14:14
1  
i don't think you can. once the package is (successfully) processed, all that remains of it is the macros, etc., that it defined. –  wasteofspace Nov 2 '12 at 14:14
    
A sad issue then ... :( –  Peregring-lk Nov 2 '12 at 14:20
5  
If by "line" you mean lines of definition rather than line number in the file then set \errorcontextlines=\maxdimen to get more of the definition context shown in error messages –  David Carlisle Nov 2 '12 at 16:01
add comment

1 Answer

up vote 10 down vote accepted

I would claim this is a natural result of the fact that TeX is a macro language that works by expansion. As such a definition that you make in your package will not be code that is executed but largely code that expands to other code (possibly from other packages) and so it is not at all clear what you mean by "not the error line inside the package itself (respect to the package file)".

To give you a (fully nonsense) example of this, consider the following code:

% this here could be in package A that you loaded or in the kernel
\def\foo !#1!{*#1*}
\def\bar{\foo !test!}

% this here would be in your package
\def\gobbleabit#1#2{#1}
\def\baz { \expandafter \gobbleabit \bar }

% this would be in your document:
\baz

now if you run this through TeX (or LaTeX) then you you will get

! Use of \foo doesn't match its definition.
\bar ->\foo !t
              est!
l.11 \baz

And where is the error? In package "A" where \foo and \bar was defined, or in your package that defined \baz in a way that it gobbled away the "!" needed to execute \foo? I would say the error was in your package.

However, if we alter the example a bit to

% this here would be in package A
\def\foo !#1!{*#1*}
\def\bar{\foo test!}

% this here would be in your package

\def\baz { \bar ... }

% this would be in your document:
\baz

we will get nearly the same error message:

! Use of \foo doesn't match its definition.
\bar ->\foo t
             est!
l.11 \baz

but this time the fault is in package A with a wrong definition of \bar. Bottom line, the best you can do in such languages is to give a stack trace which is what TeX does.

If you want to see the full stack trace of all ongoing expansions, set \errorcontextlines=\maxdimen and then you will also see all intermediate parts of the stack (and how far TeX has read in each level of expansion), in this case one more:

! Use of \foo doesn't match its definition.
\bar ->\foo t
             est!
\baz -> \bar 
             ... 
l.11 \baz
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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