# \DeclareUnicodeCharacter doesn't work for all characters

I am trying to incorporate some Unicode characters into my LaTeX files. All characters I added so far worked well, but when I use

\DeclareUnicodeCharacter{211D}{{\mathbb R}}


(211D is the Unicode character ℝ, i.e. what would be denoted \mathbb{R} in LaTeX), I get an error message

Undefined control sequence ℝ


The problem is dependent neither on what is "…" in \DeclareUnicodeCharacter{211D}{…}, nor on whether the character ℝ is used in math mode or not. For most other Unicode characters (even those with higher numbers), \DeclareUnicodeCharacter works as expected, but I get the same error also for other double stroke letters (e.g. ℂ). Do you have any idea why this is so and how to make it work?

-

## migrated from stackoverflow.comSep 25 '11 at 10:55

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

Have you got \usepackage[utf8]{inputenc} in your preamble? –  N.N. Sep 25 '11 at 10:06
Of course, that's where the macro \DeclareUnicodeCharacter is defined. –  user963099 Sep 25 '11 at 11:10

The following works for me:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amssymb}
\DeclareUnicodeCharacter{211D}{\mathbb{R}}

\begin{document}
$ℝ$
\end{document}


You probably forgot to load amssymb. By the way, there's a different way to define such symbols without looking in Unicode tables:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amssymb}
\usepackage{newunicodechar}
\newunicodechar{ℝ}{\mathbb{R}}

\begin{document}
$ℝ$
\end{document}


Notice also that the correct syntax is \mathbb{R} rather than {\mathbb R}.

-
Strange, it was indeed missing amssymb, but I was almost sure that I tested it also with simple 'test' instead of \mathbb{R} to make sure that \mathbb is not the problem. I was solving several issues at once and have probably mistaken it with some other character (I shouldn't ask such questions at 2 AM). Thank you for the solution. –  user963099 Sep 25 '11 at 12:37
As for the rest – I know about the newunicodechar, but I would like to make it possible to build my files everywhere and this package is not standardly included (at least not in my distribution). –  user963099 Sep 25 '11 at 12:41
And lastly – \mathbb R and \mathbb{R} is the same, I just wanted to make sure that there wouldn't be any problem with using this character as a parameter of a macro when not using {} (I like to write things like \frac12, \sqrt2 etc. and I have had some issues when the parameter was a macro whose content was not surrounded by {}, but this was all in XeLaTeX and it doesn't seem to be an issue here). –  user963099 Sep 25 '11 at 12:49
Of course \mathbb R and \mathbb{R} are the same. But definitely \mathbb{RX} and {\mathbb RX} aren't. Usually \mathbb isn't used like this, but \mathcal sometimes is. –  egreg Sep 25 '11 at 12:52