I want to find the width that a node will have when it is later constructed. The width depends on the node's content and the style applied to the node. The style may alter the font using the font key.
My attempt was to use \settowidth on a TikZ picture containing just the node, with the style applied but inner sep set to zero. This works fine if the style used is something like red or text opacity=.1 or, even,fill=colour@background. But if the user adds font=\scriptsize to the style, then compilation fails with a fatal error.
MNWE:
\documentclass[border=10pt,multi,tikz]{standalone} \newlength\mylength \tikzset{% my code/.code={% \settowidth\mylength{\tikz{\node[my style] {something};}}% \draw (0,0) -- +(\mylength,0); }, my style/.style={red}, } \begin{document} \begin{tikzpicture} [ my code, ] \end{tikzpicture} \begin{tikzpicture} [ my style/.style={font=\normalfont},% or font=\scriptszie or font=\itshape or whatever my code, ]% this is line 119 mentioned in the error message \end{tikzpicture} \end{document} Here's the error in all its lethal glory:
! TeX capacity exceeded, sorry [input stack size=5000]. \pgf@selectfontorig ->\pgf@selectfontorig \nullfont l.119 ] ! ==> Fatal error occurred, no output PDF file produced! Now \nullfont looks clearly dodgy, but I'm not sure why TikZ would be falling through to it.
In any case, my approach is clearly far too simple-minded.
What is the cause of the error and how can it be avoided?


\settowidth{\node ...}I don't get errors, but is that really correct?0ptand be done with it ;).\nullfont(cf. p.124, pgfmanual v3.0.1a).