Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 11 down vote accepted

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}

enter image description here

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

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.