1

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

enter image description here

\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

enter image description here

\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}
15
  • are you sure you want \let\pdfstrcmp\pdf@strcmp ????????? Feb 28, 2018 at 14:04
  • not surprisingly your document loops forever after that definition. Feb 28, 2018 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, 2018 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? Feb 28, 2018 at 14:08
  • egreg's answer does not suggest \let\pdfstrcmp\pdf@strcmp (which defines \pdfstrcmp to loop indefinitely) Feb 28, 2018 at 14:09

1 Answer 1

2

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)

5
  • As a wizard, you guessed what I didn't say ;-)
    – Tarass
    Feb 28, 2018 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, 2018 at 15:33
  • 1
    @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. Feb 28, 2018 at 15:39
  • Next time, I will carefully look if it solves the nmwe before to accept it. Sorry again.
    – Tarass
    Feb 28, 2018 at 15:42
  • Thank you your patience and advices. I posted a new question here : tex.stackexchange.com/questions/417799/…
    – Tarass
    Feb 28, 2018 at 18:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .