Consider this MWE:
\documentclass[varwidth,tightpage,border=1bp]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\makeatletter
\gdef\getMyInfoString{%
\let\trfm\relax % ! Undefined control sequence.
\pgfgettransform{\trfm}% with previous commented: ! Undefined control sequence. <argument> \trfm
\edef\tout{%
pgfgettransform: \trfm ; %
pgf@pt@aa, pgf@pt@ba, pgf@pt@ab, pgf@pt@bb: \pgf@pt@aa, \pgf@pt@ba, \pgf@pt@ab, \pgf@pt@bb %
}
\tout % output tout
}
\makeatother
\pgfgettransform{\trfmX}%
\makeatletter
\typeout{Manually check: %
pgfgettransform: \trfmX ; %
pgf@pt@aa, pgf@pt@ba, pgf@pt@ab, pgf@pt@bb: \pgf@pt@aa, \pgf@pt@ba, \pgf@pt@ab, \pgf@pt@bb %
}
\makeatother
\typeout{This is via macro function: \getMyInfoString}%
\end{tikzpicture}
\end{document}
If you compile this, the first \typeout
prints this to stdout:
Manually: pgfgettransform: {1.0}{0.0}{0.0}{1.0}{0.0pt}{0.0pt}; pgf@pt@aa, pgf@p
t@ba, pgf@pt@ab, pgf@pt@bb: 1.0, 0.0, 0.0, 1.0
... while the second \typeout
raises an error:
! Undefined control sequence.
\getMyInfoString ->\let \trfm
\relax \pgfgettransform {\trfm }\edef \tout {p...
l.30 \typeout{This is: \getMyInfoString}
%
?
Clearly, latex
wants to execute the \trfm
control sequence/command/token/macro - while I intend it to be a "local variable", which will be used as an "argument" to \pgfgettransform
(which will then populate it with data).
Is there a way to "protect" this \trfm
macro -- so the \getMyInfoString
executes correctly, and returns a string (in an expandable way, I guess, since the intent is to use it in \typeout
), when called?
\getMyInfoString
in an expansion context (\typeout
): presumably you need to define\getMyInfoString
to store the result (\tout
) but not print it, then use\tout
inside\typeout
.\edef
and\write
, and thus derivatives of these. Anything writing to the log, such as\typeout
, is related to\write
so is an expansion context.