1

In Latex, I always use \mathbb{something0}_{something1}^{something2}, wheres sometimes 'something1' or 'something2' can be empty. So I had the idea to create a newcommand using the \newcommand. So I tried a lot. I wanna know if is possible to create a command such that if I use \mb{R} it's print \mathbb{R}; if I use \mb[+]{R} it's print \mathbb{R}_{+}; if I use \mb[n][+]{R} it's print \mathbb{R}_{+}^{n}. Or a newcommand that do something like that.

This is one of my attempts:

\newcommand{\mb}[3][ ]{\mathbb{#3}_{#2}^{#1}}

but when I try \mb[n][+]{R} the command only print \mathbb{R}^b+.

Thanks

migrated from stackoverflow.com Jul 23 '14 at 20:18

This question came from our site for professional and enthusiast programmers.

  • Welcome to TeX.sx! Your post was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. – Werner Jul 23 '14 at 20:28
4

This may help you:

More than one optional argument for newcommand

For your specific example though, I usually just do the following:

\newcommand{\R}{\mathbb{R}}

And then I write

\R
\R_+
\R_+^n

I find that much more easily readable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy