I often have a whole bunch of definitions such as


with R replaced by R,Z,C, etc.

I might also have a bunch of math operators or category definitions, e.g.


What I would love is a way I could define this all at once. For example I could have some function \bb that I could just write




and this would then allow me to just use \Z for \mathbb{Z} in the document.

Is such a thing possible?

  • 3
    possible duplicate of tex.stackexchange.com/questions/48 Apr 10, 2012 at 6:41
  • 2
    Just a remark: I would recommend not using \ensuremath with commands like \N. I don't think that $\N$ costs much more typing than \N. And imagine you want to write $-\N$ and you forget the dollars and write -\N, then it gets completely different meaning.
    – yo'
    Apr 10, 2012 at 8:23
  • 3 wonderful answers, so I'll go with the community! Thanks to all responders
    – Qwirk
    Apr 13, 2012 at 5:33

3 Answers 3


etoolbox's list parser \docsvlist is an ideal candidate for this:

enter image description here

\usepackage{amssymb}% http://ctan.org/pkg/amssymb
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
  \renewcommand*{\do}[1]{% \do to each item in list
    \expandafter\newcommand\csname ##1\endcsname{\ensuremath{\mathbb{##1}}}%
  \docsvlist{#1}% Process list
\bb{R,N,Z,Q,C}% Create \mathbb macros
Real: \R, Natural: \N, Integer: \Z, Rational: \Q, Complex: \C

The macro \do is applied to each entry in the CSV list.


Here's a possible solution:



  \expandafter\newcommand\csname #1\endcsname{\ensuremath{\mathbb{#1}}}}

Real: \R, Natural: \N, Relative: \Z, Fractional: \Q

I should add that I combined these two answers to come up with the above.


Here's a more abstract (and quite shorter) way:

% #1 = command to use
% #2 = optional prefix
% #3 = list
\NewDocumentCommand{\createbunch}{ m O{} m }
  \clist_map_inline:nn { #3 } { \cs_new_protected:cpn { #2 ##1 } { #1 { ##1 } } }




% This is just for showing the meaning of some of the created macros
\newcommand\Meaning[1]{\texttt{\string#1: \expandafter\strip@prefix\meaning#1}}






enter image description here

Your Answer

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

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