[Tex/LaTex] Undefined control sequence \pgfmath@ in \node with text height or text depth

errorspgfmathtikz-chainstikz-pgf

The below file gives this error when compiled with pdflatex (from TeX Live 2015). How do I fix it, and what have I done wrong?

Error

\pgfmath@dimen@ …men@@ #1=0.0pt\relax \pgfmath@

l.27 …e,draw=none] (idx) {index:\hspace*{10pt}};

It seems that using either text height=... or text depth=... induces the error (see commented lines below). This was compiling fine some time ago, but I believe between then and now I have done a tlmgr update --all.

MWE

\documentclass{article}

\usepackage{tikz}
\usepackage{calc}

\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}
\usetikzlibrary{chains}
% Errors
\tikzstyle{tape}=[draw,
  text height=\heightof{$\sum_{i=1}^{n-1} m_i$},
  text depth=\depthof{$\sum_{i=1}^{n-1} m_i$}]

% Errors
% \tikzstyle{tape}=[draw,text height=\heightof{$\sum_{i=1}^{n-1} m_i$}]

% Errors
% \tikzstyle{tape}=[draw,text depth=\depthof{$\sum_{i=1}^{n-1} m_i$}]

% No error
% \tikzstyle{tape}=[draw]

\begin{scope}[start chain=0 going right,node distance=0mm]
    \node [on chain=0,tape,draw=none] (idx) {index:\hspace*{10pt}};
    \node [on chain=0,tape] {$k_1$};
    \node [on chain=0,tape] {$\ldots$};
    \node [on chain=0,tape] {$k_n$};
    \node [on chain=0,tape,draw=none] {$=$};
    \node [on chain=0,tape] {$0$};
    \node [on chain=0,tape] {$\ldots$};
    \node [on chain=0,tape] {$\sum_{i=1}^{n-1} m_i$};
\end{scope}

\end{tikzpicture}
\end{figure}

\end{document}

I have found several questions with similar errors here, but was not able to convert any of the answers to fixes for this situation.

Best Answer

calc's macros are not expandable, though PGF expects a mathematical value.

PGF does provide its own measurement functions:

  • depth("…"),
  • width("…") and
  • height("…").

The " are needed because they escape the evaluation to text.

If you have ,, = or ] in your text, you have to enclose the value in braces.

For example:

\tikzset{
  text vert/.style={
    text height={height("#1")},
    text depth={depth("#1")}},
  type/.style={draw, text vert={$\sum_{i=1}^{n-1} m_i$}}
}