Why does using \uline within a pgfmath expression result in an error?
\documentclass{article}
\usepackage[normalem]{ulem}
\usepackage{tikz}
\begin{document}
\pgfmathparse{width("\uline{blabla}")}
\end{document}
The error:
! Undefined control sequence.
\ULset ->\UL@setULdepth \def \UL@leadtype
{\leaders \hrule \@height \UL@heig...
l.6 ...se{width("\let\uline\relax\uline{blabla}")}
! TeX capacity exceeded, sorry [input stack size=5000].
\UL@on #1->\leavevmode
\UL@ender \let \UL@on \UL@onin \everymath {\UL@hrest ...
l.6 ...se{width("\let\uline\relax\uline{blabla}")}
! ==> Fatal error occurred, no output PDF file produced!
My \uline is embedded in some other macro, so I can't simply not write it there. I had the idea to temporarily undefine \uline within the math expression (I don't need it to calculate the width, right!), but it only made matters more misterious: the error persists (it seems that \let is never executed).
\documentclass{article}
\usepackage[normalem]{ulem}
\usepackage{tikz}
\begin{document}
\pgfmathparse{width("\let\uline\relax\uline{blabla}")}
\end{document}

\pgfmathparse{width("...")}is bound to failure whenever there's something in the argument that doesn't survive\edef(\textbf, for instance). So I guess that the\sboxmethod is better in any case when you can't fully control the text. – egreg Mar 01 '13 at 00:09\sboxand\wdway is certainly preferable and the most safe. With the packageetoolbox, one can simply do\robustify\uline(which protects\ulinefrom expansion by\edef) and\pgfmathprint{width("\uline{blabla}")}will give26.66675then. (Of course, this doesn’t work if you don’t know what to expect.) – Qrrbrbirlbel Jul 18 '13 at 03:29