I don't really understand what is the problem here, but I guess it has to do with expansion and fragile macros since when I do the same outside of \path
it works.
Code:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,calc}
\usepackage{xstring}
\newcommand{\aw}{10pt}
\newcommand{\bbw}{20pt}
\newcommand{\cw}{30pt}
\newcommand{\width}[1]{%
\StrBefore{#1}{'}[\notprimed]
\IfEndWith{#1}{'}
{ \csname \notprimed w\endcsname }
{ \csname #1w\endcsname }
}
\begin{document}
\foreach \name in {a,bb,c,a'}
{ ++(\width{\name},0pt) node {\name} };
\begin{tikzpicture}
% \draw (0pt,0pt) node {s}
% ++(\aw,0pt) node {a}
% ++(\bbw,0pt) node {bb}
% ++(\cw,0pt) node {c}
% ++(\aw,0pt) node {a'};
\draw (0pt,0pt) node {s}
\foreach \name in {a,bb,c,a'}
{ ++(\width{\name},0pt) node {\name} };
\end{tikzpicture}
\end{document}
I think it has to do with xstring
also because when I remove the \StrBefore
and \IfEndWith
from the definition of \width
it also works.
Any ideas?
foreach
loop instead of testing for prime?(\width{…},0pt)
as\width{…}
is not just a length but includes all thexstring
stuff, too. You will need to do that outside of the path (or inside of\pgfextra
).