# How to show line number common to more files in emacs?

I have a LaTeX project that consists of one master file and other files (mainly chapters) that are included in the main file via the \input command:

\documentclass[a4paper,10pt,oneside,openany]{book}
....
\begin{document}
...
\mainmatter
\input{capitoli/one.tex}
\input{capitoli/two.tex}
\input{capitoli/n.tex}
...
\end{document}


As you can see, the included files usually lie in subfolders relative to the main file.

I would like that when I'm visiting, say, two.tex the line number shown at the bottom of the buffer by line-number-mode would not start from 1 but would consider the lines of code before that file (in this case the ones in the mail file and in one.tex). This is because when I compile the document with pdfLaTeX the compiler provides "general" line numbers for errors, so it's hard to find it in the source code. I tried the linum mode, but it seems to work just like the line-number-mode for the specific problem.

There is a way to achieve this behaviour? I did not posted the question on TeX.StackExchange because I think this is really an Emacs related question.

-

For me latex reports the line number within a given file. How are you invoking latex that it gives "general" line numbers?

You should also consider using -file-line-error-style since that helps AUCTeX find the error in a few corner cases. It causes errors to be printed like ./capitoli/three.tex:2: Undefined control sequence.

-
Hitting C-c C-c RET Emacs uses: pdflatex -synctex=-1 -src-specials "\input" "usr.tex" (given the synctex option, this should be the default behaviour). Thanks for the other tip, but I usually compile in interactive mode, so the compiler stops automatically on the first error –  Spike Jul 13 '12 at 13:09
Using that command I still get correct, i.e. local, line numbers and TeX-next-error has no problem finding the error. –  Ivan Andrus Jul 13 '12 at 18:34
After installing the new TeXLive 2012, everything is just as you say. Thanks –  Spike Jul 14 '12 at 10:10

This is more like a hack to get what you're asking for, but you could use an (e.g.) awk script to prepare a file concatenating the \input'ed file into the file (see this link). From it, you can derive the offset of each file (the line number it has in the merged file). Then, you can use some form of relative line numbering (see e.g. this link). You then need some way of modifying your .emacs file whenever you open a .tex file that is not the main file (e.g. using an alias or a function).

With some work, you can get what you want, but it's not straightforward.

P.S. The line numbers from the concatenation might not be those reported on your error log, since there might be other macros expanding (e.g. \include).

-
This would be too tricky for me. I was searching for a more "out of the box" solution. Thanks –  Spike Jul 14 '12 at 10:11