I find myself writing $\{0,1\}^x$
a whole lot, so I want to define a shorthand macro:
\def\zo#1{\{0,1\}^{#1}}
However, sometimes I need $\{0,1\}$
with no superscript. If I write \zo{}
I get a tiny bit of extra space after the close brace (because there's an empty superscript in there). The only way I have found to get rid of it is
\def\zo#1{\{0,1\}\if\relax\detokenize{#1}\relax\else^{#1}\fi}
which is rather a mouthful. Is there a more elegant way to accomplish this? Note that the actual document I am writing is in LaTeX, so if amsmath (for instance) has something to the purpose, that would be a fine answer. I have expressed the question in plain TeX because it is fundamentally a question about the core math engine.
If you can't see the tiny bit of extra space, this MWE (requires (pdf)etex
) will make it obvious:
\def\a#1{\{0,1\}^{#1}}
\def\b#1{\{0,1\}\if\relax\detokenize{#1}\relax\else^{#1}\fi}
\leavevmode\rlap{$\a{}\a{}\a{}\a{}$}$\b{}\b{}\b{}\b{}$
\bye
→ (400% zoom)
\@ifnextchar
, but ok :)\def\a{\{0,1\}}
and use verbose^{<stuff>}
if needed …