9

I'm currently wondering how packages like tikz can possibly work. I've read the TeX Book and found no evidence of TeX primitives capable of drawing things. LaTeX is just a collection of macros so the use of LaTeX cannot provide this capability.

Is the pdfTeX engine providing the primitives necessary for producing drawings? If yes, which are those primitives?

3
  • 3
    for pdftex it is \pdfliteral then tikz injects literal pdf fragments, just as graphicx does for image inclusion, or color does for color Dec 2, 2023 at 13:53
  • 1
    TeX also provides \special features. OTOH, picture and pict2e do graphics using special fonts. Dec 2, 2023 at 14:05
  • 1
    @JohnKormylo pict2e uses \special or \pdfliteral rather than specialized fonts, so it is able to lift the restrictions of legacy picture mode.
    – egreg
    Dec 2, 2023 at 15:12

1 Answer 1

3

My TeX Live on windows has among others the following folder

c:/texlive/2023/texmf-dist/tex/generic/pgf/systemlayer/

Here you'll find many files like pgfsys-pdftex.def, pfgsys-dvips.def, pgfsys-luatex.def, pgfsys-xetex.def and so on...

Depending on how you are compiling your file, the system loads the appropriate .def file. There the TeX instructions are "translated" into driver-dependent instructions. For example, pgfsys-pdftex.def has

\def\pgfsys@invoke#1{\pdfliteral{#1}}

while pgfsys-luatex.def has

\def\pgfsys@invoke#1{\pdfextension literal{#1}}

and pgfsys-dvips.def has

\def\pgfsys@invoke#1{\special{ps\ifpgfsys@ps@boxmode\else:\fi: #1}}

Analogously, all macros are in the end mapped into the appropriate driver instruction. For example, pgfsys-common-pdf.def (used by pdftex and luatex have

\def\pgfsys@miterjoin{\pgfsysprotocol@literal{0 j}}
\def\pgfsys@roundjoin{\pgfsysprotocol@literal{1 j}}
\def\pgfsys@beveljoin{\pgfsysprotocol@literal{2 j}}

while pgfsys-common-postscript.def has

\def\pgfsys@miterjoin{\pgfsysprotocol@literal{0 setlinejoin}}
\def\pgfsys@roundjoin{\pgfsysprotocol@literal{1 setlinejoin}}
\def\pgfsys@beveljoin{\pgfsysprotocol@literal{2 setlinejoin}}

and so on.

pdfTeX is in a sense its own driver, so it can use \pdfliteral directly. On the other hand, going using e.g. dvips means that the TikZ macros just use appropriate \special nodes: these are just shipped out, and it is the job of dvips to use them to actually print something.

2
  • Aside: Is \pdfliteral something like q 0 0 1 0 0 rg 0 0 m and such things as I see as "whatsit" code? That is, does \pdfliteral mean a string of characters (not obvious to end users) that is written directly into the PDF (or pre-PDF) file?
    – rallg
    Dec 2, 2023 at 19:20
  • 1
    @rallg Not sure I understand the first question but for the second I'd say yes, though I'm no PDF expert. In Knuth TeX you would just have a \special whatsit node which is written into the dvi file and which your printing driver (xdvi, dvips, dvipdf(m)(x),...) interprets. \pdfliteral is a pdfTeX primitive but I assume it makes a whatisit node like like \specialdoes.
    – campa
    Dec 4, 2023 at 10:09

You must log in to answer this question.

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