Use macro/newcommand for attributes

How would one define a newcommand so that it can be used for attributes?

I have \somecommand which I can pass attributes, for example color=black in square brackets. Now I want to have a newcommand to do something like this:


\begin{document}
\somecommand[\anewcommand]
\end{document}


Although the anewcommand holds the same value as I would pass by typing it out, it doesn't work and tells me that my attributes are not defined.

Well. The \somecommand is actually the ganttbar command of the gantt.sty package. I want to have \newcommand{\person}{color=black} and then pass \person to \ganttbar[\person]. hope this clarifies it more.

MWE:

\documentclass[paper=a4,landscape]{scrartcl}
\usepackage[usenames,dvipsnames,svgnames]{xcolor}
\usepackage{gantt}

\newcommand{\person}{color=black}

\begin{document}
\begin{gantt}[xunitlength=0.8cm,fontsize=\small,titlefontsize=\small,drawledgerline=true]{2}{7} %{# of tasks}{# of slots}
\begin{ganttitle}
\titleelement{week 1}{7}
\end{ganttitle}
\ganttbar[color=NavyBlue]{localization}{3}{3} % this works
\ganttbar[\person]{Bla}{1}{1} % this doesn't
\end{gantt}
\end{document}

-
Depending on the definition of \somecommand, \anewcommand may be used directly or expanded. We need more context to give a good answer. –  Joseph Wright Jun 20 '12 at 10:04
It clarifies it more but I find it still confusing and in any case, can you provide a minimal working example? –  Christian Jun 20 '12 at 10:47
where did you get gantt.sty from I didn't see it on ctan only pst-gantt and pgfgantt –  David Carlisle Jun 20 '12 at 12:08
It's a package by Martin Krumm. Don't know why it isn't listed on ctan. Pgfgantt uses gantt.sty though. –  cherrung Jun 20 '12 at 12:23

Escaping the command with {} makes your MWE compilable.

However, I can't offer you insight into the inner workings. Maybe somebody else can help out here.

EDIT:

\person{} made it compilable, but as cherrung pointed out in the comments, it doesn't really solve the issue.

As a simple workaround, I'd define only the actual color-argument as a variable:

\documentclass[paper=a4,landscape]{scrartcl}
\usepackage[usenames,dvipsnames,svgnames]{xcolor}
\usepackage{gantt}

\newcommand{\person}{green}

\begin{document}
\begin{gantt}[xunitlength=0.8cm,fontsize=\small,titlefontsize=\small,drawledgerline=true]{2}{7} %{# of tasks}{# of slots}
\begin{ganttitle}
\titleelement{week 1}{7}
\end{ganttitle}
\ganttbar[color=NavyBlue]{localization}{3}{3} % this works
\ganttbar[color=\person]{Bla}{1}{1} % this works as well
\end{gantt}
\end{document}

-
Wow. And here I was thinking that I've tried every possible combination with {}. Well... I'm really interested in why it works. EDIT: Oh. Just noticed that it doesn't work. It just uses the standard color, which is black. Kinda stupid, because I defined person with black. –  cherrung Jun 20 '12 at 11:54
@cherrung: That's correct. I didn't really check for that. I edited the answer to offer you an actual fix. –  dhst Jun 20 '12 at 12:03
Not as elegant, but I guess best solution I can get for now. –  cherrung Jun 20 '12 at 16:28