TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I get the current .tex source line number? I want to use it to generate useful error messages in a package I am writing.

There are some errors that can only be detected at the end of the document, so I want to create a command that checks for them and tells at what line the error was made. To do that, I need to be able to save the source line number in the command that was misapplied.

Preferably a command that can be used like \sourcelineno in this example:

\newcommand \showlineno {line \sourcelineno}


You are now at \showlineno.

This paragraph starts at \showlineno, and 
some more text,
and runs until \showlineno. 


where the output would be

You are now at line 6.

This paragraph starts at line 8, and some more text, and runs until line 10. 
share|improve this question
Would \number\inputlineno instead of \sourcelineno do the trick? – egreg Nov 7 '12 at 13:53
@egreg: yes. I hadn't found out about \inputlineno yet. – JanKanis Nov 7 '12 at 14:27
up vote 9 down vote accepted

You can use a variation of the kernel's \on@line:


\def\showlineno{ line \the\inputlineno}


You are now at \showlineno.

This paragraph starts at \showlineno, and 
some more text,
and runs until \showlineno.

on input line \the\inputlineno

share|improve this answer
Great! \inputlineno is what I was looking for. – JanKanis Nov 7 '12 at 14:26
Gonzalo, do you know how to put this command on the whole document? I mean, there is a way to use automatically this command (\showlineno) on every line of the source? Mi objective is to get something like this: tex.stackexchange.com/questions/261571/… – MrSelberg Aug 16 '15 at 14:29

Your Answer


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.