宏参数和pgf键解释问题

宏参数和pgf键解释问题

在此 mmwe 中,如果在 macto 的参数上使用相同的测试,则该测试有效,但在 pgf 键上使用时则失败。知道原因吗?

在此处输入图片描述

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

编辑更复杂的宏存在问题。我的 mwe 太小了。

非最小例子是我对这个问题的回答:如何定义 tikz 样式选项以在特定点之间绘制尺寸线

在此处输入图片描述

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

答案1

你的问题不太清楚,但我猜你想

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

测试@aspectis的第一个标记(,而不是测试是否为@aspectis ((这始终为假)

相关内容