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

I am commenting on a LaTeX document (with todonotes), and I would like to put a reference to a line in the source code, writing e.g.:

See the code around line 123 of foo.tex to please fix this ugly equation.

foo.tex itself is included into a main.tex document, which contains the document's head and \include statements to all other document parts.

Is such a thing possible?

share|improve this question
You can just write \todo{See the code at line 123 of foo.tex}. But that isn't what you're asking, obviously. Could you be clearer what you want? You want to use the \label and \ref mechanism to refer to a line in the code? – Seamus Jul 17 '12 at 15:27
I am using \todo{foo} to place a little comment on the side of my document. Often, these comments are about a misplaced character or a suggested fix of the underlying source. In these cases, I want the reader/author to be quickly able to locate the part I commented on in the source. Therefore I need the line number and source file where my comment is located in. – mSSM Jul 17 '12 at 15:30
TeXworks allows to go from PDF output to the tex file. – projetmbc Jul 19 '12 at 0:11
Which would be feasible if I could force everyone who works with my code to use TeXworks. ;) Myself, I am not. – mSSM Jul 19 '12 at 12:23
up vote 6 down vote accepted

You can use the magic of \inputlineno and the currfile package:

\todo{Fix code at line \myline\ of file \currfilename}



I started working on a package that uses these tricks to help you keep track of where you are in the input file. It was inspired by this question. It's called draftinputlines. I am currently writing up my PhD. thesis, so development has slowed, somewhat.

share|improve this answer
Sweet! This is already one part of the solution. Is there now also a way to put the source file's name in there (e.g., if my PDF is compiled from a multi file .tex source)? – mSSM Jul 17 '12 at 15:32
@mSSM see edit. You need a package to do it, but it should work… – Seamus Jul 17 '12 at 15:34
Awesome; "watch"ing your progress on Github now. :) Got to wait a couple of minutes before accepting your answer; you were too fast! – mSSM Jul 17 '12 at 15:38
Do I understand this correctly: I need to \edef \myline every single time before using it? Isn't there a command that does not expand the argument before I actually call it? – mSSM Jul 17 '12 at 15:46
@mSSM If the todo note is always near where you want the line number to point to, you could just put \the\inputlineno inside the todo note. Doing it this way, you can have the line number and the todo note to be far apart. It depends precisely what you want. I guess there's some clever tricks you could do to build a sort of \label / \ref system for line numbers, but I don't know whether it would be worth it. – Seamus Jul 17 '12 at 15:51

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.