I write a command to help me draw circle easy:
\def\Tdot@i{circle (1mm)}
\def\Tdot@ii[#1]{circle (#1)}
\def\Tdot{%
\@ifnextchar[%
{\Tdot@ii}%
{\Tdot@i}%
}
When I try, it works well:
\documentclass{minimal}
\makeatletter
\def\Tdot@i{circle (1mm)}
\def\Tdot@ii[#1]{circle (#1)}
\def\Tdot{%
@ifnextchar[%
{\Tdot@ii}%
{\Tdot@i}%
}
\makeatother
\begin{document}
\Tdot is circle (1mm),
\Tdot[5mm] is circle (5mm).
\end{document}
so I try to bring it to tikz, it raise some error:
% ...
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0, 0) circle (1mm); % goodA
% Package tikz Error: Giving up on this path. Did you forget a semicolon?
% \draw (0, 0) \Tdot;
% Package tikz Error: Giving up on this path. Did you forget a semicolon?
% \draw (0, 0) \Tdot[5mm];
\end{tikzpicture}
\end{document}
Is the if-else bad for TikZ?

TikZuses its own parser. You can't easily modify its behavior. This parser accepts external commands at the location of the coordinates but not between the coordinates. – Paul Gaborit Nov 19 '21 at 06:26\@ifnextcharuses\futureletwhich is not expandable. – Henri Menke Nov 19 '21 at 08:30