PGF/TikZ Manual

The TikZ and PGF Packages
Manual for version 3.1.10

The Basic Layer

117 Adding libraries to pgf: temporary registers

This section is intended for those who like to write libraries to extend pgf. Of course, this requires a good deal of knowledge about -programming and the structure of the pgf basic layer. Besides, one will encounter the need of temporary variables and, especially, temporary registers. This section describes how to use a set of pre-allocated temporary registers of the basic layer without needing to allocate more of them.

A part of these internals are already mentioned in section 101.7, but the basic layer provides more temporaries than \pgf@x and \pgf@y.

  • Internal dimen register \pgf@x

  • Internal dimen register \pgf@y

  • These registers are used to process point coordinates in the basic layer of pgf, see section 101.7. After a \pgfpoint\(\dotsc \) command, they contain the final \(x\) and \(y\) coordinate, respectively.

    The values of \pgf@x and \pgf@y are set globally in contrast to other available pgf registers. You should never assume anything about their value unless the context defines them explicitly.

    Please prefer the \pgf@xa, \pgf@xb, \(\dotsc \) registers for temporary dimen registers unless you are writing point coordinate commands.

  • Internal dimen register \pgf@xa

  • Internal dimen register \pgf@xb

  • Internal dimen register \pgf@xc

  • Internal dimen register \pgf@ya

  • Internal dimen register \pgf@yb

  • Internal dimen register \pgf@yc

  • Temporary registers for dimensions which can be modified freely. Just make sure changes occur only within groups.

Attention: pgf uses these registers to perform path operations. For reasons of efficiency, path commands do not always guard them. As a consequence, the code


\pgfpointadd{\pgfpoint{\pgf@xa}{\pgf@ya}}{\pgfpoint{\pgf@xb}{\pgf@yb}}

may fail: Inside \pgfpointadd, the \pgf@xa and friend registers might be modified. In particular, it might happen that \pgf@xb is changed before \pgfpoint{\pgf@xb}{\pgf@yb} is evaluated. The right thing to do would be to first expand everything using \edef and process the values afterwards, resulting in unnecessary expensive operations. Of course, one can avoid this by simply looking into the source code of \pgfpointadd to see which registers are used.

  • Internal dimen register \pgfutil@tempdima

  • Internal dimen register \pgfutil@tempdimb

  • Further multi-purpose temporary dimen registers. For , these registers are already allocated as \@tempdima and \@tempdimb and are simply \let to the \pgfutil@\(\dotsc \) names.

  • Internal count register \c@pgf@counta

  • Internal count register \c@pgf@countb

  • Internal count register \c@pgf@countc

  • Internal count register \c@pgf@countd

  • These multiple-purpose count registers are used throughout pgf to perform integer computations. Feel free to use them as well, just make sure changes are scoped by local groups.

  • Internal openout handle \w@pgf@writea

  • An \openout handle which is used to generate complete output files within locally scoped parts of pgf (for example, to interact with gnuplot). You should always use \immediate in front of output operations involving \w@pgf@writea and you should always close the file before returning from your code.


    \immediate\openout\w@pgf@writea=myfile.dat
    \immediate\write\w@pgf@writea{...}%
    \immediate\write\w@pgf@writea{...}%
    \immediate\closeout\w@pgf@writea%

  • Internal openin handle \r@pgf@reada

  • An \openin handle which is used to read files within locally scoped parts of pgf, for example to check if a file exists or to read data files. You should always use \immediate in front of output operations involving \r@pgf@writea and you should always close the file before returning from your code.


    \immediate\openin\r@pgf@reada=myfile.dat
    % do something with \macro
    \ifeof\r@pgf@reada
    % end of file or it doesn't exist
    \else
    % loop or whatever
    \immediate\read\r@pgf@reada to\macro
    ...
    \fi
    \immediate\closein\r@pgf@reada

  • Internal box \pgfutil@tempboxa

  • A box for temporary use inside of local scopes. For , this box is the same as the already pre-allocated \@tempboxa.