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}
Tarass
  • 16,912
  • 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 https://tex.stackexchange.com/questions/132248/test-if-the-first-character-of-a-string-is-a 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
  • @Tarass: There is no \let\pdfstrcmp\pdf@strcmp in that linked code. Furthermore, you should say what \pdf@strcmp is supposed to be before you use that as a \let replacement –  Feb 28 '18 at 14:10
  • I just test pdflatex and loops indeed, but lualatex works fine... ans produce the document I posted as an image. I never use pdflatex, I didn't know it loops. – Tarass Feb 28 '18 at 14:10
  • there is a reason that the pdftexcmds package uses consistent new names for all the commands it defines. Both your \let statements completely break it. – David Carlisle Feb 28 '18 at 14:12
  • I'm a little confused. Without the package the compilation fails with lualatex, whit the package it fails with pdflatex. I suppose one have too chose, the one or the other way? I chose lualatex and the package, ifluatex can prevent the misloading of the package. Is it normal that it works with lualatex ? And if yes, why the pgfkey issue ? – Tarass Feb 28 '18 at 14:19
  • I tried my mwe without the package ans the two line, the compilation works, the test work on macro parameter but not on pgf key. – Tarass Feb 28 '18 at 14:22
  • @DavidCarlisle I add the ifluatex, no more loops, still my question. – Tarass Feb 28 '18 at 14:26
  • No why choose? Just use the package as intended and use \pdf@strcmp and \pdf@moddate without renaming them back on the original names. (but the ifluatex version works) note there is not really any question in your question. You just say "it fails" without saying what you get or what you expected. – David Carlisle Feb 28 '18 at 14:42
  • Are we agree on my correction loading ifluatex? My question in on the failling of the test : it works fine with a macro parameter, and does no give the right answer if I test a pgfkey, what I call fails. – Tarass Feb 28 '18 at 14:47
  • the correction using ifluatex avoids the loop in pdftex but is not really how you are intended to use the pdftexcmds package. There are multiple issues in renaming the aliases defined there to have the same names, you got lucky and in this case the modified code works in pdftex and luatex but in general it will not. So while it is not completely broken with an infinite loop it is not correct. – David Carlisle Feb 28 '18 at 15:02
  • please do not describe a problem as "does not give the right answer" The code you posted does give the right answer, it works as designed and gave the answer I expected. But you made me guess what answer you expected which is hard to get right without a crystal ball. Luckily I had a working one today. – David Carlisle Feb 28 '18 at 15:04

1 Answers1

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)

David Carlisle
  • 757,742
  • 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
  • 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. – 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 : https://tex.stackexchange.com/questions/417799/pgfkey-and-macro-parameter-pass-the-same-test-differently – Tarass Feb 28 '18 at 18:37