# Using a macro inside the axis options for pgfplots

I want to create an macro to replace the string '{a,b,c}' in my code:

xticklabels={a,b,c}


so I set

\newcommand\inputnames{a,b,c}
xticklabels=\inputnames


but this gives me the same result as xticklabels={{a,b,c}}, which is different in my case. I suppose that it comes from an unwanted expansion of my macro but I can't find how to prevent it.

The complete code is bellow:

\documentclass{standalone}
\usepackage{pgfplots}

\begin{document}

\newcommand{\inputnames}{a,b,c}

\begin{tikzpicture}
\begin{axis}[xtick={1,2,3},xticklabels=\inputnames]
\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}[xtick={1,2,3},xticklabels={a,b,c}]
\end{axis}
\end{tikzpicture}

\end{document}


You need to use

xticklabels/.expand once=\inputnames


which expands the argument to xticklabel once before actually applying it. (There’s also .expand twice and .expanded.)

Otherwise when the xticklabels are read, the parser only find one label, namely \xticklabel which is then given to the node that typesets this. Firstly here the macro is expanded.

## Code

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\newcommand{\inputnames}{a,b,c}
\begin{tikzpicture}
\begin{axis}[xtick={1,2,3},xticklabels/.expand once=\inputnames]