# Macro argument and pgf key interpretation problem

In this mmwe, the same test work if used on a parameter of a macto and fails on a pgf key. Any idea why ?

\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]{\Cote{\@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
}

\makeatother

\begin{document}

\Cote{(F)} -- \Cote{F}

\begin{tikzpicture}

\path[Cote/aspect=F] (0,0) to[Cote] (5,0) ;

\path[Cote/aspect=(F)] (0,2) to[Cote] (5,2) ;

\end{tikzpicture}

\end{document}


Edit There is a problem with a more complex macro. My mwe was too minimal.

The non minimal exemple is 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{$\pi$}\expandafter<\@aspect>};
\endpgfinterruptpath
}(\tikztostart) -- (\tikztotarget) \tikztonodes}}
}

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

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

\makeatother

\begin{document}

\Cote{$\pi$}<($\pi$)> -- \Cote{$\pi$}<F>

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

• are you sure you want \let\pdfstrcmp\pdf@strcmp ????????? – David Carlisle Feb 28 '18 at 14:04
• not surprisingly your document loops forever after that definition. – David Carlisle Feb 28 '18 at 14:07
• Based on egreg's here tex.stackexchange.com/questions/132248/… answer, this test worked since a long time if I test a macro parameter. I want to use this test on a pgfkey and it fails. I confess that it is a magic formula for mee ;-) – Tarass Feb 28 '18 at 14:07
• your document if used with pdftex never terminates and has to be killed from the operating system. That does not appear to match the behaviour that you are asking about? Are you testing with luatex or xetex rather than pdftex? – David Carlisle Feb 28 '18 at 14:08
• egreg's answer does not suggest \let\pdfstrcmp\pdf@strcmp (which defines \pdfstrcmp to loop indefinitely) – David Carlisle Feb 28 '18 at 14:09

Your question is not very clear but I guess that you want

\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}};
\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
}

\makeatother

\begin{document}

\Cote{(F)} -- \Cote{F}

\begin{tikzpicture}

\path[Cote/aspect=F] (0,0) to[Cote] (5,0) ;

\path[Cote/aspect=(F)] (0,2) to[Cote] (5,2) ;

\end{tikzpicture}

\end{document}


to test the first token of @aspect is ( rather than test if @aspect is ( (which is always false)

• As a wizard, you guessed what I didn't say ;-) – Tarass Feb 28 '18 at 14:53
• I updated my question, because I don't know how adapt your answer to my more complex macro. My mwe was to minimal. I' sorry. – Tarass Feb 28 '18 at 15:33
• @Tarass you know it's bad form to change the question after answers posted, especially after they are accepted. (as its's showing as answered basically no one but me is likely to see the new question, if you had asked it as a new question, someone else could tale a turn. – David Carlisle Feb 28 '18 at 15:39
• Next time, I will carefully look if it solves the nmwe before to accept it. Sorry again. – Tarass Feb 28 '18 at 15:42
• Thank you your patience and advices. I posted a new question here : tex.stackexchange.com/questions/417799/… – Tarass Feb 28 '18 at 18:37