In C there is #line which allows stating the origin of a particular line of code. This is useful for autogenerated C source files: The (unreadable) code in the generated file is mapped back to the original source. All subsequent lines will inherit the file name from the last #line directive and advance the line counter. Here's a completely artificial example:
Source file input.in:
a <- b* c
c <- (a)
Autogenerated C source input.in.c:
#line 1 "input.in"
while (b) do_b();
#line 1 "input.in"
do_c();
#line 2 "input.in"
do_open_paren();
#line 2 "input.in"
do_a();
#line 2 "input.in"
do_close_paren();
Is there something similar in TeX? What would have to be done to make TeX think that it is in a particular line of a particular source file, effective from the beginning of the next line?
The purpose of this exercise is to have SyncTeX refer to the original file instead of the autogenerated code. Autogenerated TeX files appear when you knit R, and also if you Replace \input{fileX} by the content of fileX automatically. Of course, the code generator will have to emit the #line equivalent into the generated code.
\jobnametex doesn't give primitive access to files that are\inputalthough of course you can redefine input to save the argument in a macro (as latex does for\listfiles) – David Carlisle Jun 22 '12 at 22:40