5

I'm creating a tikz style to do some complicated linear transformation on the coordinates, computed in terms of variables. To give an idea, here's what the style declaration looks like now:

\tikzset{foo/.style={cm={\cosLgP,
                         \sinLgP * (-\sinEl),
                         \cosLa * \cosLg,
                         \sinLa * \cosEl - \cosLa * \sinLg * \sinEl,     
                         (0,0)}}}

...where \cosLgP &co are some previously defined macros (that should evaluate to various sines and cosines, if all goes well).

There's a bug and the coordinate transformation appears to be incorrect. How do I debug? Specifically, how do I print the (numerical) contents of the transformation matrix of foo, to see what it ended up containing?

Thanks!

Labrador
  • 245
  • 1
    Related I think: https://tex.stackexchange.com/questions/41660/how-to-extract-the-value-from-a-pgfkeys-style-element – Torbjørn T. Dec 20 '17 at 09:38
  • 2
    inside foo/.style add /utils/exec={\show\cosLgP} (mind the initial forward slash) as the last item. If those values are dimen registers then use \showthe instead – percusse Dec 20 '17 at 14:00
  • @percusse: Thanks! I noticed this command works anywhere and one can also do /utils/exec={\show\cosLgP\show\sinLa} and it works as expected. Only drawback I guess is that it interrupts the LaTeXing process, instead of "dumping" the values somewhere for later inspection. – Labrador Dec 21 '17 at 08:39
  • @Labrador You can try \typeout{\cosLgP} (instead of \show\cosLgP) to show the value in your .log file without interruption... – Paul Gaborit Feb 03 '18 at 11:38

2 Answers2

1

inside foo/.style add /utils/exec={\show\cosLgP} (mind the initial forward slash) as the last item. If those values are dimen registers then use \showthe instead.

Alternatively instead of showing you can dump them into macros inside utils/exec and check their values afterwards

percusse
  • 157,807
1

I answer the initial question: how to see content of a tikz style?

You can try the .show code handler (p.893, pgfmanual) to show the definition of a style but with interruption during compilation.

In the following document, I define the new handler .typeout code to put the definition of a style in the .log file:

\documentclass[tikz]{standalone}
% handler to use \typeout instead of \show (based on code of '.show code' handler)
\pgfkeys{
  /handlers/.typeout code/.code={%
    \pgfkeysgetvalue{\pgfkeyscurrentpath/.@cmd}{\pgfkeysshower}%
    \typeout{--- \pgfkeyscurrentpath\space---}%
    \typeout{\meaning\pgfkeysshower}%
  }
}
% application to your style
\tikzset{
  foo/.style={cm={\cosLgP,
      \sinLgP * (-\sinEl),
      \cosLa * \cosLg,
      \sinLa * \cosEl - \cosLa * \sinLg * \sinEl,     
      (0,0)}},
  foo/.typeout code,
}
% application to an ".estyle":
\def\cosLgP{1} \def\sinLgP{0}
\def\cosEl{0.707} \def\sinEl{0.707}
\def\cosLa{.848} \def\sinLa{.529}
\def\cosLg{0} \def\sinLg{1}
\tikzset{
  efoo/.estyle={cm={\cosLgP,
      \sinLgP * (-\sinEl),
      \cosLa * \cosLg,
      \sinLa * \cosEl - \cosLa * \sinLg * \sinEl,     
      (0,0)}},
  efoo/.typeout code,
}
\begin{document}
\end{document}

In the .log file:

--- /tikz/foo ---
\long macro:#1\pgfeov ->\pgfkeysalso {cm={\cosLgP , \sinLgP * (-\sinEl ), \cosLa * \cosLg , \sinLa * \cosEl - \cosLa * \sinLg * \sinEl , (0,0)}}
--- /tikz/efoo ---
\long macro:#1\pgfeov ->\pgfkeysalso {cm={1, 0* (-0.707), .848* 0, .529* 0.707- .848* 1* 0.707, (0,0)}}
Paul Gaborit
  • 70,770
  • 10
  • 176
  • 283