[Tex/LaTex] \DeclareUnicodeCharacter doesn’t work for all characters

unicode

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?

Best Answer

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}.

Related Question