TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
possible duplicate of tex.stackexchange.com/questions/48 – Zev Chonoles Apr 10 '12 at 6:41
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 '12 at 8:23
3 wonderful answers, so I'll go with the community! Thanks to all responders – Qwirk Apr 13 '12 at 5:33
up vote 25 down vote accepted

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.

share|improve this answer

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.

share|improve this answer

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

share|improve this answer

Your Answer


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.