# New command with default does not work

Hello I have the following new command (a bit simplified for readability):

\newcommand{\xz}[1][0]{x_{#1}}


I'm expecting the following behavior:

$\xz$ outputs as $x_0$
$\xz{1}$ outputs as $x_1$


Though, the compiled result returns:

$\xz$ outputs as $x_0$ (ok!)
$\xz{1}$ outputs as $x_01$ (??)


What I'm missing there?

-

You declared an optional argument, so you need to use \xz[1]:

\documentclass{article}
\usepackage{amsmath}

\newcommand{\xz}[1][0]{x_{#1}}

\begin{document}

$\xz\quad\xz[1]$

\end{document}


\xz{1} will be understood as \xz without the optional argument and then {1}.

-
I would accept immediately, but I can accept the answer in 10 minutes. It's obviously true. And I have to sleep!! Thanks :) –  Emiliano Poggi Sep 1 '12 at 22:06