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.

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.

share|improve this question

1 Answer 1

up vote 5 down vote accepted

TeX has an internal register \inputlineno that keeps track of the line number.

aaaa \the\inputlineno

aaaa \the\inputlineno

\newcount \inputlineno  \inputlineno=3 xaaaa \the\inputlineno

as shown above you can't assign to it but you can mask it with a count register of the same name. I don't know synctex but if it picks up the value from the csname \inputlineno rather directly accessing the primitive, then this may be enough if in each section of the generated file you assign a value to a masked copy of \inputlineno

share|improve this answer
    
Thank you. Unfortunately, this had no effect for SyncTeX, so I'll have to be looking for other ways. And I haven't even found anything similar for the file name in the TeX book. –  krlmlr Jun 22 '12 at 19:14
    
The top level filename is \jobname tex doesn't give primitive access to files that are \input although 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

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.