I'm working on the following LaTeX code:
\documentclass[a4paper,13pt]{scrartcl}
\usepackage{tikz}
\usepackage{xstring}
\newcommand{\swcase}[1]{
\IfEqCase{#1}{{a}{1}{b}{2}}
}
\begin{document}
\begin{tikzpicture}[
single/.style={draw,circle}
]
\draw node[single,fill=white] at (6,\swcase{a}) {\swcase{a}};
%\draw node[single,fill=white] at (6,1) {\swcase{a}};
\end{tikzpicture}
\end{document}
This code fails to compile with pdflatex, and I get the following error message:
! Argument of \XC@definec@lor has an extra }.
<inserted text>
\par
l.14 ... node[single,fill=white] at (6,\swcase{a})
{\swcase{a}};
The macro \swcase should return 1 when fed with the argument a. You can confirm this by commenting the failing line and uncommenting the one below, where the macro inside the coordinates is substituted with the expected result. The example works as expected and draws a circle with the text 1 (resulting from the macro \swcase) in it.
Why is it not working if I embed the \swcase macro inside the coordinate vector?
By the way, it doesn't make any difference if I put the \IfEqCase statement directly into the coordinate parenthesis instead of using the wrapper macro.

tikzpicture, try\edef\myvalue{\swcase{a}}... – Paul Gaborit Jun 01 '16 at 13:44