# pgfkey and macro parameter pass the same test differently

In the next MWE, the test provided on a macro parameter gives the expected answer (it finds if the parameter begins with a (), but the same test fails on or ignores the pgfkey it has to test.

This is a minimal example, it is to finish my answer to this question : How to define at tikz style option to draw a dimension line between to specific points

    \documentclass{article}
\usepackage{xparse,tikz}
\usetikzlibrary{calc}
\usepackage{ifluatex}

\makeatletter

\ifluatex
\RequirePackage{pdftexcmds}
\let\pdfstrcmp\pdf@strcmp
\let\pdffilemoddate\pdf@filemoddate
\fi

\tikzset{%
Cote/.style={to path={\pgfextra{
\pgfinterruptpath
\draw[>=latex,|<->|] let
\p1=($(\tikztostart)!2mm!90:(\tikztotarget)$),
\p2=($(\tikztotarget)!2mm!-90:(\tikztostart)$)
in(\p1) -- (\p2) node[pos=.5,sloped,above]{%
\expandafter\Cote\expandafter{\@aspect} --
\expandafter\CoteBis{$\pi$}\expandafter<\@aspect>};
\endpgfinterruptpath
}(\tikztostart) -- (\tikztotarget) \tikztonodes}}
}

\pgfkeys{tikz/Cote/.cd,
aspect/.store in=\@aspect,
aspect=o,
}
\makeatletter

\NewDocumentCommand{\Cote}{m}{%
\ifnum\pdfstrcmp{\unexpanded\expandafter{\@car#1\@nil}}{(}=\z@
true
\else
false
\fi
}

\NewDocumentCommand{\CoteBis}{md<>
}{%
#1
\ifnum\pdfstrcmp{\unexpanded\expandafter{\@car#2\@nil}}{(}=\z@
true
\else
false
\fi
}

\makeatother

\begin{document}

\verb+\Cote+ : \Cote{(F)} -- \Cote{F} : The test gives the expected answers

\verb+\Codetis+ : \CoteBis{$\pi$}<(F)> -- \CoteBis{$\pi$}<F> : The test gives the expected answers

\bigskip

In the \verb+\Cote+ macro, the test gives the expected answers

In the \verb+\CoteBis+ macro, the test gives unexpected answers

\bigskip

\begin{tikzpicture}
\path[Cote/aspect=F] (0,0) to[Cote] (5,0) ;
\path[Cote/aspect=(F)] (0,1) to[Cote] (5,1) ;
\end{tikzpicture}
\end{document}


Two issues:

• \CoteBis is never called in the TikZ style Cote. I assume the second \Cote should be \CoteBis.

• \expandafter only jumps over one token, not a group of tokens. Thus, the line

\expandafter\Cote{$\pi$}\expandafter<\@aspect>


needs much more calls of \expandafter (and probably \CoteBis instead of \Cote):

\expandafter\CoteBis\expandafter{%
\expandafter$\expandafter\pi\expandafter$\expandafter}%
\expandafter<\@aspect>


The result:

• Sorry, post the wrong code. I made the corrections. – Tarass Feb 28 '18 at 19:26
• @HeikoOberdiek I try to adapt your solution to my code here, but it still not working. Could you take a look, please ? tex.stackexchange.com/questions/417617/… – Tarass Feb 28 '18 at 19:35
• Thanks. (Sorry, can't upvote again for the fix.) I'll try to remember about the typos - just some people don't like anybody to touch their answers, even for typos. (Personally, I'm happy if somebody does this for me!) – cfr Feb 28 '18 at 23:04