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

Is there a way to find out (from Tex) the page number corresponding to a particular location in the source file? Using a macro in the file at that location is fine.

My motivation is that I'd like to (eventually) get a system working for partial compilation for Beamer presentations. Since I typically only change one or two frames between compilations, it's pretty inefficient that the entire document is recompiled every time (modulo tricks like conditional compilation, which help a bit). If I know which pages correspond to each frame, it should be possible to splice together an older compiled version with the new content.

EDIT: Sorry, I should have been more specific. I don't want any output in the pdf, rather I want to get it some other way (through a log file probably) so that I can access it from an external program.

share|improve this question
By conditional compilation, you mean using \includeonly? – Yossi Farjoun Aug 7 '10 at 15:53
@Yossi: Yes. Beamer also allows you to name frames and then list a specific list of frames to compile, but it always gave me problems for some reason. – Neil Olver Aug 7 '10 at 16:07
up vote 4 down vote accepted

Use \typeout{Some identifier of your choice \thepage}. This will make the typed out message appear in the console output and the .log file.

share|improve this answer
Thanks, this will work nicely. In particular, for frames with multiple pages (due to Beamer overlays), this handily gives output for each page. – Neil Olver Aug 8 '10 at 16:10
But it is unfortunately incorrect in the general case. It only works in the special case where the page breaks are at fixed places and not dynamically calculated by TeX. In case of a beamer presentation that is the case (so it is correct for the scenario in the second para of the question) but for the general case it has to be \label \pageref solution writing to the terminal or a special file. – Frank Mittelbach May 31 '12 at 18:34

There are packages that support that, for the purpose of forward searching: i.e. you click on a source code location in your editor and you’re then taken to the corresponding location in the preview application. Both the editor and the preview application have to support this (but most do).

Long story short, forward search uses information in a separate file that is generated during compilation.

For example, the pdfsync package creates a file called <name>.pdfsync. You can use that file to get the information you need. I don’t know the format of that file but it shouldn’t be too hard to figure out, considering that the file format is described on the homepage.

An alternative (that seems to supersede pdfsync) is the synctex tool. It can be used directly from the command line, or activated from within LaTeX (on new distributions) by the command \synctex=1 (or via the command line switch synctex=1). In that case, a file <name>.synctex.gz will be generated that contains a similar file as above, albeit gzipped.

share|improve this answer

This \label{this} is on page~\pageref{this} (needs multiple compiling).

share|improve this answer
Sorry, see my edit. But actually, now that I think about it, the label should get placed in the .aux file, and maybe that will give me enough information. – Neil Olver Aug 7 '10 at 16:42

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.