以下は期待どおりに動作します:
\documentclass{minimal}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\makeatletter
\node (01) at (0, 0) {};
\draw (0, 0) -- (0, 01);
\makeatother
\end{tikzpicture}
\end{document}
01
しかし、 の 1 つを に置き換えると\@ifnextchar1001
、私の理解では同等であるはずが、次のようになってしまいます。
\documentclass{minimal}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\makeatletter
\node (\@ifnextchar1001) at (0, 0) {};
\makeatother
\end{tikzpicture}
\end{document}
与える
! Argument of \XC@definec@lor has an extra }. <inserted text> \par l.6 \node (\@ifnextchar1001) at (0, 0) {};
そして
\documentclass{minimal}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\makeatletter
\draw (0, 0) -- (0, \@ifnextchar1001);
\makeatother
\end{tikzpicture}
\end{document}
収穫
! Argument of \XC@definec@lor has an extra }. <inserted text> \par l.6 \draw (0, 0) -- (0, \@ifnextchar1001) ;
この場合、01
との違いは何でしょうか? これ、または同様の構造を意図したとおりに機能させるにはどうすればよいですか?\@ifnextchar1001
答え1
\@ifnextchar
は、内部で を使用しているため拡張できません\futurelet
。ノード名は拡張可能である必要があり、内部で\csname
...内で使用されます\endcsname
。
単純な数字を比較するだけであれば、通常のマクロ引数解析を使用したテストで十分です。
\documentclass{minimal}
\usepackage{tikz}
% \IfNextChar
% #1: the char for testing
% #2: code for true
% #3: code for false
% #4: next char
\makeatletter
\newcommand{\IfNextChar}[4]{%
\ifx#1#4\@empty\@empty
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{#2}{#3}%
}
\makeatother
\begin{document}
\begin{tikzpicture}
\node (\IfNextChar1001) at (0, 0) {};
\end{tikzpicture}
\end{document}
\@ifnextchar
座標としてのの使用にも同じことが当てはまります。
答え2
PGF 数学を使用して、数値を 10 進数から 10 進数に変換するだけです。やりすぎかもしれませんし、そうでないかもしれません。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\pgfmathbasetodec{\myconvresult}{001}{10}
\pgfmathsetmacro\myresult{\myconvresult+1}\myresult
\pgfmathbasetodec{\myconvresult}{0214}{10}
\pgfmathsetmacro\myresult{\myconvresult+1}\myresult
\pgfmathbasetodec{\myconvresult}{000035}{10}
\pgfmathsetmacro\myresult{\myconvresult+1}\myresult
\pgfmathbasetodec{\myconvresult}{301}{10}
\pgfmathsetmacro\myresult{\myconvresult+1}\myresult
\end{document}
どこかにこれの設定がないとびっくりしますね…。