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 :) – yo' Jan 26 '13 at 21:07\def\a{\{0,1\}}and use verbose^{<stuff>}if needed … – Qrrbrbirlbel Jan 26 '13 at 21:26\zo^{x}is not much more difficult to type than\zo{x}and is clearer. So my suggestion is simply\def\zo{\{0,1\}}. – egreg Jan 26 '13 at 22:44\def\zoo{\{0,1\}}. Then use\zo{non empty stuff}and\zoo. – Jan 26 '13 at 23:45