I have a macro written as \newcommand which contains a complete new tikz-environment.
How could one make a macro out of this that only contains the content of the tikz-environment, so that if one wants to have this drawing multiple times, it is drawn in one single tikz-environment?
I know I could simply strip the declaration of the tikz-environment in my macro, but that would let me use the macro outside a tikz-environment too.
Examples:
I have a macro similar to the following one:
\newcommand{\myTikzMacro}{
\begin{tikzpicture}
\draw (0,0) rectangle (1,1);
\draw (1,1) rectangle (2,0);
\end{tikzpicture}
Now I could use the macro multiple times after each other like this:
\myTikzMacro \\
\myTikzMacro \\
But then multiple tikz-environments would be used. To avoid that I'd be able to make this macro:
\newcommand{\myTikzMacro2}{
\draw (0,0) rectangle (1,1);
\draw (1,1) rectangle (2,0);
And use it as followed:
\begin{tikzpicture}
\myTikzMacro2
\myTikzMacro2
\end{tikzpicture}
But this would enable me to use the macro outside a tikzpicture environment too which I'd like to avoid too.
Is there a way to declare macros only available/visible within tikzpicture environments? (maybe with pgfkeys)
tikzenvironment? Just nothing? Then I have to ask why. Do you expect the macro to pop out at random places? – campa Oct 07 '20 at 12:44\draw). You might be interested in How can I check if the current code is inside a tikzpicture?. – campa Oct 07 '20 at 12:53Error: Macro ... is not defined(outsite tikzpicture)? – atticus Oct 07 '20 at 13:02\PackageError{mypackage}{dont do that}{extra help}from https://tex.stackexchange.com/a/183948/206293 Thanks @campa. Would you like to write an Answer so that I can mark it as solution? – atticus Oct 07 '20 at 14:01\PackageErroris meaningful if you are writing a package. Is that the case? – campa Oct 07 '20 at 14:09