I want to create a macro, namely \newpoint{<point name>}{<point style>}
, that creates macros like \Point<point name>{<x coord>}{<y coord>}{<label>}
.
I've seen How to define a macro to create a new macro with a name passed as its argument? which is half way through as it does not show how to make the created macro receive arguments.
I tried:
\newcommand*{\newpoint}[2]{%
\tikzset{#1/.style={#2}}%
\newcounter{point#1}\setcounter{point#1}{0}%
\def\csname Point#1\endcsname (##1,##2)|##3;{%
\stepcounter{point#1}\fill[#1] (##1,##2) circle (2pt) node[above](#1-\thepoint#1){##3};}%
}
But it didn't work, appearently Use of \csname doesn't match it's definition
and honestly... I don't know what I'm doing anymore.
Here is my M(N)WE:
\documentclass[tikz, border=2mm]{standalone}
\newcommand*{\newpoint}[2]{%
\tikzset{#1/.style={#2}}%
\newcounter{point#1}\setcounter{point#1}{0}%
\def\csname Point#1\endcsname (##1,##2)|##3;{%
\stepcounter{point#1}\fill[#1] (##1,##2) circle (2pt) node[above](#1-\thepoint#1){##3};}%
}
\newpoint{A}{red}
\begin{document}
\begin{tikzpicture}
\PointA(1,2)|A;
\end{tikzpicture}
\end{document}
\expandafter\def\csname ...
, the counter stuff seems very bad. What exactly are you trying there?\PointA
does way more than just the circle. But essencially, that's it, it does some drawing and uses automatic naming, therefore the counter is absolutely mantadory here. Using\expandafter
gives a new errorUndefined \thepoint
, which means\thepoint#1
is not working, I may have to change the question...