# Options for Tikzpicture with newcommand

I'd like to define options via newcommand, so i can use them for tikzpicture-environments. I tried this:

\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\newcommand{\test}{[every path/.style={->,red,thick}]}
\begin{document}
\begin{tikzpicture}\test
\draw (0,0)--(1,1);
\end{tikzpicture}
\end{document}

But the line is still black. Where is the mistake in my approach? i thought, newcommand simply expands its content when it is written. I assume that the square brackets are perhaps the problem...

• Try \newcommand{\test}{ \tikzset{every path/.style={->,red,thick}}}
– user31034
Jan 28 '20 at 12:44

Welcome to TeX.SE! While technically correct, the method given in @ferahfeza's comment is probably not the one I would use here. Staying in the spirit of pgfkeys, I would define a /tikz/test style. This is often easier to reuse within TikZ pictures. Note that both methods allow one to take advantage of TeX's grouping rules, as shown below in the case of “my” method:

\documentclass{article}
\usepackage{tikz}

\tikzset{
test/.style={
every path/.style={->, red, thick},
}
}

\begin{document}

\begin{tikzpicture}[test] % '/tikz/test' style manually set for this picture
\draw (0,0)--(1,1);
\end{tikzpicture}

\bigskip
{%
\tikzset{test}% Applies to the current TeX group, until (possibly) overridden
%
\begin{tikzpicture}
\draw (1,1)--(0,0);
\end{tikzpicture}%
\begin{tikzpicture}
\draw (0,1)--(1,0);
\end{tikzpicture}%
}% TeX group terminated; the '/tikz/test' style is not in effect anymore.

\bigskip
\begin{tikzpicture}
\draw (0,0)--(1,1) (1,0)--(0,1);
\end{tikzpicture}

\end{document}

In the spirit of NOT using \pgfkeys, one can use

\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\newcommand{\test}{[every path/.style={->,red,thick}]}
\newcommand{\tikzstart}{\begin{tikzpicture}}
\begin{document}
\expandafter\tikzstart\test
\draw (0,0)--(1,1);
\end{tikzpicture}
\end{document}