4

In the file below:

\documentclass{report}

\usepackage{tikz}

\begin{document}
 This is a test.
\end{document}

commenting and uncommenting the {tikz} entry changes the PDF file produced. Since tikz is not being used -- in what ways the PDF file is changed?

4
  • What is the change you observe Commented Apr 29, 2019 at 13:57
  • Indeed: there is none here.
    – Denis
    Commented Apr 29, 2019 at 14:03
  • 4
    Yes, pgf will load the graphics-drivers and this will set/change the pdf page size to letter. Commented Apr 29, 2019 at 14:15
  • @subhamsoni Denis I do not care so much for changes in the date of creation of the file and things like that, but the changes here go beyond that, as explained by Phelype Oleinik down below.
    – Paulo Ney
    Commented Apr 29, 2019 at 15:49

1 Answer 1

9

Long story short, there are two differences:

  1. The color is changed from the default color to explicit black;

  2. The paper size is changed from the default of your TeX distribution setup to letter paper.


One thing that changes is the PDF metadata which contains the date in which it was generated and an unique ID generated with that info. You can suppress those to create the exact same PDF using (reference):

\pdfinfoomitdate=1
\pdfsuppressptexinfo=-1
\pdftrailerid{}

(assuming you are using pdfTeX).

That said, you can disable the compression to make the PDF human-readable (or as close as it can get):

\pdfcompresslevel=0
\pdfobjcompresslevel=0

and then run pdflatex on two files and diff them:

$ diff -a notikz.pdf tikz.pdf
3c3
< 3 0 obj
---
> 6 0 obj
5c5
< /Length 103       
---
> /Length 144       
7a8,10
> 0 g 0 G
> 0 g 0 G
> 0 g 0 G
9c12,15
< /F8 9.9626 Tf 148.712 707.125 Td [(This)-333(is)-334(a)-333(test.)]TJ 154.421 -567.87 Td [(1)]TJ
---
> /F8 9.9626 Tf 148.712 657.235 Td [(This)-333(is)-334(a)-333(test.)]TJ
> 0 g 0 G
>  154.421 -567.87 Td [(1)]TJ
> 0 g 0 G
14c20
< 2 0 obj
---
> 5 0 obj
17,20c23,26
< /Contents 3 0 R
< /Resources 1 0 R
< /MediaBox [0 0 595.276 841.89]
< /Parent 5 0 R
---
> /Contents 6 0 R
> /Resources 4 0 R
> /MediaBox [0 0 612 792]
> /Parent 8 0 R
23c29
< 1 0 obj
---
> 4 0 obj
25c31,32
< /Font << /F8 4 0 R >>
---
>  /ColorSpace 3 0 R /Pattern 2 0 R /ExtGState 1 0 R 
> /Font << /F8 7 0 R >>
29c36,45
< 6 0 obj
---
> 1 0 obj
> <<>>
> endobj
> 2 0 obj
> <<>>
> endobj
> 3 0 obj
> <<  /pgfprgb [/Pattern /DeviceRGB] >>
> endobj
> 9 0 obj
32c48
< 7 0 obj
---
> 10 0 obj
128c144
< 8 0 obj
---
> 11 0 obj
141c157
< /FontFile 7 0 R
---
> /FontFile 10 0 R
144c160
< 4 0 obj
---
> 7 0 obj
149c165
< /FontDescriptor 8 0 R
---
> /FontDescriptor 11 0 R
152c168
< /Widths 6 0 R
---
> /Widths 9 0 R
155c171
< 5 0 obj
---
> 8 0 obj
159c175
< /Kids [2 0 R]
---
> /Kids [5 0 R]
162c178
< 9 0 obj
---
> 12 0 obj
165c181
< /Pages 5 0 R
---
> /Pages 8 0 R
168c184
< 10 0 obj
---
> 13 0 obj
176c192
< 0 11
---
> 0 14
178,179c194,198
< 0000000287 00000 n 
< 0000000176 00000 n 
---
> 0000000440 00000 n 
> 0000000460 00000 n 
> 0000000480 00000 n 
> 0000000321 00000 n 
> 0000000217 00000 n 
181,187c200,206
< 0000011782 00000 n 
< 0000011919 00000 n 
< 0000000354 00000 n 
< 0000000750 00000 n 
< 0000011544 00000 n 
< 0000011976 00000 n 
< 0000012025 00000 n 
---
> 0000011964 00000 n 
> 0000012102 00000 n 
> 0000000533 00000 n 
> 0000000929 00000 n 
> 0000011724 00000 n 
> 0000012159 00000 n 
> 0000012209 00000 n 
189,191c208,210
< << /Size 11
< /Root 9 0 R
< /Info 10 0 R
---
> << /Size 14
> /Root 12 0 R
> /Info 13 0 R
194c213
< 12105
---
> 12289

It seems to be a lot, but actually there are only few relevant changes. Most of the above are address changes to PDF objects, for example the first difference:

3c3
< 3 0 obj
---
> 6 0 obj

Says that the difference is an object which was numbered 3 and now is numberered 6. Later on references to this object will change as well (edited):

17,20c23,26
< /Contents 3 0 R
---
> /Contents 6 0 R

Also, at the end, the addresses (offset in bytes) of the objects in the file are changed because the file has changed.

The only relevant changes are three:

7a8,10
> 0 g 0 G
> 0 g 0 G
> 0 g 0 G
9c12,15
< /F8 9.9626 Tf 148.712 707.125 Td [(This)-333(is)-334(a)-333(test.)]TJ 154.421 -567.87 Td [(1)]TJ
---
> /F8 9.9626 Tf 148.712 657.235 Td [(This)-333(is)-334(a)-333(test.)]TJ
> 0 g 0 G
>  154.421 -567.87 Td [(1)]TJ
> 0 g 0 G
17,20c23,26
< /Contents 3 0 R
< /Resources 1 0 R
< /MediaBox [0 0 595.276 841.89]
< /Parent 5 0 R
---
> /Contents 6 0 R
> /Resources 4 0 R
> /MediaBox [0 0 612 792]
> /Parent 8 0 R
25c31,32
< /Font << /F8 4 0 R >>
---
>  /ColorSpace 3 0 R /Pattern 2 0 R /ExtGState 1 0 R 
> /Font << /F8 7 0 R >>

The first one is the actual text you printed. The stream without tikz was:

stream
BT
/F8 9.9626 Tf 148.712 707.125 Td [(This)-333(is)-334(a)-333(test.)]TJ 154.421 -567.87 Td [(1)]TJ
ET
endstream

and with tikz it became:

stream
0 g 0 G
0 g 0 G
0 g 0 G
BT
/F8 9.9626 Tf 148.712 657.235 Td [(This)-333(is)-334(a)-333(test.)]TJ
0 g 0 G
 154.421 -567.87 Td [(1)]TJ
0 g 0 G
ET
endstream

The 0 g 0 G are color specification which are inserted in the PDF. These changes are actually inserted by the color driver and you can see them if you \usepackage{color}. They are explicitly saying that the text is black, and not the default color (which is also black :).

The third difference is also related to the color driver which adds color information to the loaded fonts:

 /ColorSpace 3 0 R /Pattern 2 0 R /ExtGState 1 0 R 

(remember object number 3 which changed to 6? This statement points to the new object number 3).

Finally, the second part is related to the graphics driver:

17,20c23,26
< /Contents 3 0 R
< /Resources 1 0 R
< /MediaBox [0 0 595.276 841.89]
< /Parent 5 0 R
---
> /Contents 6 0 R
> /Resources 4 0 R
> /MediaBox [0 0 612 792]
> /Parent 8 0 R

which, apart from object references, changed the value of /MediaBox, which is basically the paper size. When you \usepackage{graphics} the paper size is changed from the default (which depends on how your TeX distribution is set up) to letter paper.

2
  • This must be one of the most complete answer I have ever seen in SX. Many thanks!
    – Paulo Ney
    Commented Apr 29, 2019 at 15:42
  • @PauloNey I'm glad you liked :-) Commented Apr 29, 2019 at 16:10

You must log in to answer this question.

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