0

I use Latex, specifically with the pdfLatex processor on Ubuntu 16.04

Suppose I have typed up a long document (say Hamlet) in Latex. After processing, suppose Latex produces a 300 page pdf.

I want to know where exactly in the .tex document does pdfLatex insert pagebreaks and thus begins a new page.

More formally, is it possible to tell pdfLatex to output a kind of dictionary such that for each page of the pdf (the "key") the dictionary specifies the set of lines ("the value") of the original .tex file with the contents of that page.

One could possibly come up with a kludgy solution using pdfgrep but I wonder if the pdfLatex compiler generates this information automatically.

1
  • What would be your use case for this? You could "use" Synctex for this, because it kind of holds these data.
    – TeXnician
    Commented May 27, 2018 at 7:35

1 Answer 1

3

You really want to use synctex for this, because it is generated by running pdflatex with the synctex flag. That will produce a .synctex.gz file which is basically a gzipped text file (the synctex file) or if you choose a negative flag it's just the text file.

To show this at an example:

\documentclass[12pt]{article}
\usepackage{lipsum}
\begin{document}
\lipsum\lipsum
\end{document}

will produce the following synctex file (shortened):

SyncTeX Version:1
Input:1:/path/to/file.tex
Input:2:/usr/local/texlive/2018/texmf-dist/tex/latex/base/article.cls
Input:3:/usr/local/texlive/2018/texmf-dist/tex/latex/base/size12.clo
Input:4:/usr/local/texlive/2018/texmf-dist/tex/latex/lipsum/lipsum.sty
Input:5:/path/to/file.aux
Output:pdf
Magnification:1000
Unit:1
X Offset:0
Y Offset:0
Content:
!410
{1
[1,7:4736286,46187806:28114944,41451520,0
[1,7:7292190,46187806:25559040,40337408,0
[1,7:7292190,6636830:25559040,786432,0
h1,7:7292190,6636830:25559040,0,0
]
[1,7:7292190,44221726:25559040,35946496,0
(1,7:7292190,9061662:25559040,546132,152916
h1,7:7292190,9061662:1155060,0,0
x1,7:10596809,9061662
k1,7:10882169,9061662:285360
x1,7:11523869,9061662
x1,7:12897107,9061662
k1,7:13182468,9061662:285361
x1,7:13995288,9061662
x1,7:14893668,9061662
k1,7:15179028,9061662:285360
x1,7:15996126,9061662
k1,7:16281486,9061662:285360
x1,7:18163806,9061662
k1,7:18456337,9061662:292531
x1,7:19611397,9061662
x1,7:22610275,9061662
k1,7:22895635,9061662:285360
x1,7:24350155,9061662
x1,7:25210033,9061662
x1,7:26236753,9061662
k1,7:26522113,9061662:285360
x1,7:27805513,9061662
k1,7:28233794,9061662:428281
x1,7:29110511,9061662
k1,7:29395872,9061662:285361
x1,7:30251472,9061662
x1,7:31282470,9061662
k1,7:31567830,9061662:285360
x1,7:32851230,9061662
k1,7:32851230,9061662:0
)
... MORE CONTENT HERE ...
]
(1,7:7292190,46187806:25559040,506811,0
k1,7:19879200,46187806:12587010
x1,7:20264220,46187806
k1,7:32851230,46187806:12587010
)
]
]
!27910
}1
!10
... MORE CONTENT HERE ...
{4
[1,8:4736286,46187806:28114944,41451520,0
[1,8:7292190,46187806:25559040,40337408,0
[1,8:7292190,6636830:25559040,786432,0
h1,8:7292190,6636830:25559040,0,0
]
[1,8:7292190,44221726:25559040,35946496,0
(1,8:7292190,9061662:25559040,546132,152916
x1,8:9580920,9061662
x1,8:10928490,9061662
k1,8:11236209,9061662:307719
x1,8:12220149,9061662
k1,8:12540627,9061662:320478
x1,8:13229385,9061662
x1,8:14923473,9061662
k1,8:15231192,9061662:307719
x1,8:17549868,9061662
k1,8:17870346,9061662:320478
x1,8:20308806,9061662
k1,8:20804163,9061662:495357
x1,8:22889552,9061662
k1,8:23197270,9061662:307718
x1,8:23967310,9061662
k1,8:24275029,9061662:307719
x1,8:26375527,9061662
k1,8:26870883,9061662:495356
x1,8:29591691,9061662
k1,8:29899410,9061662:307719
x1,8:30305820,9061662
x1,8:32851230,9061662
k1,8:32851230,9061662:0
)
... MORE CONTENT HERE ...
(1,8:7292190,21415198:25559040,546132,152916
x1,8:7698600,21415198
x1,8:8447250,21415198
g1,8:8703930,21415198
x1,8:11249340,21415198
g1,8:11506020,21415198
x1,8:14483508,21415198
g1,8:14740188,21415198
x1,8:15146598,21415198
x1,8:17478108,21415198
g1,8:17734788,21415198
x1,8:18718728,21415198
g1,8:18975408,21415198
x1,8:20862006,21415198
k1,8:32851230,21415198:11989224
g1,8:32851230,21415198
)
]
(1,8:7292190,46187806:25559040,506811,0
k1,8:19879200,46187806:12587010
x1,8:20264220,46187806
k1,8:32851230,46187806:12587010
)
]
]
!9778
}4
Input:6:/path/to/file.aux
!66
Postamble:
Count:1701
!26
Post scriptum:

The interesting parts are the lines starting with {<int>, e.g. {1, because this denotes a new page (pages are closed by }<int> btw). You'll find the so-called byte offset records there. These are the numbers preceded by a !. So to get the exact position of a page break you just need to use the byte offset which is output prior to the start of a page.

The byte offsets can easily be converted to the lines by a simple script, so I'm not going into detail here. But as you wanted to have a range of lines you'll need to look at a second byte offset record too, the one right before the end of the page.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .