How to create a macro that creates other macros (that takes arguments)?
As @daleif remarked, put\expandafter
before \def
. And to get \thepointA
you have to use \csname ... \endcsname
there. I guess this is what you want:
\newcommand*{\newpoint}[2]{%
\tikzset{#1/.style={#2}}%
\newcounter{point#1}\setcounter{point#1}{0}%
\expandafter\def\csname Point#1\endcsname (##1,##2)|##3;{%
\stepcounter{point#1}\fill[#1] (##1,##2) circle (2pt) node[above](#1-\csname thepoint#1\endcsname){##3};}%
}
And here is a solution without a real counter for each call of \newpoint
, based on the solution with a pseudo-counter by @egreg, but with an increment of the pseudo-counter, each time the \point<name>
macro is called.
\newcounter{pointnumber}
\newcommand\StepPointNumber[1]{%
\setcounter{pointnumber}{\csname number@point#1\endcsname}%
\stepcounter{pointnumber}
\expandafter\xdef\csname number@point#1\endcsname{\thepointnumber}%
\expandafter\show\csname number@point#1\endcsname
}
\newcommand*{\newpoint}[2]{%
\tikzset{#1/.style={#2}}%
\expandafter\def\csname number@point#1\endcsname{0}%
\expandafter\def\csname Point#1\endcsname (##1,##2)|##3;{%
\StepPointNumber{#1}%
\fill[#1] (##1,##2) circle (2pt) node[above](#1-\csname number@point#1\endcsname){##3-\csname number@point#1\endcsname};}%
}
I don't see the need to allocate a new counter, unless you want to do arithmetic with it.
The main point, though, is that you need to use \csname
in the right way:
\documentclass[tikz, border=2mm]{standalone}
\newcommand*{\newpoint}[2]{%
\tikzset{#1/.style={#2}}%
\expandafter\def\csname number@point#1\endcsname{0}%
\expandafter\def\csname Point#1\endcsname (##1,##2)|##3;{%
\fill[#1] (##1,##2) circle (2pt) node[above](#1-\csname number@point#1\endcsname){##3};}%
}
\newpoint{A}{red}
\begin{document}
\begin{tikzpicture}
\PointA(1,2)|A;
\end{tikzpicture}
\end{document}