13

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?

1 Answers1

24

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

egreg
  • 1,121,712
  • 1
    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
  • 2
    I'd never heard of newunicodecharacter - very useful. Also, I apologise for forgetting to acknowledge this answer when answering a question. (It was by email so I cannot, unfortunately, edit it retrospectively.) – cfr Jul 01 '15 at 00:04
  • Usually when you use your unicode, you don't want to worry about the math-mode, so instead declare: \newunicodechar{ℝ}{\ensuremath{\mathbb{R}}}. Now ℝ can be used without the dollar, $, symbols! :-) – Musa Al-hassy Aug 16 '18 at 14:12
  • @MusaAl-hassy \ensuremath is considered bad practise by some. – Skillmon Nov 22 '18 at 11:34
  • 1
    @MusaAl-hassy I don't think it's good practice: ℝ is a math symbol anyway, so it should be properly segregated. – egreg Nov 22 '18 at 11:40
  • @Skillmon why do you say that? I've seen it often and so have used it for that reason; it also makes things work for me. egreg what do you mean? – Musa Al-hassy Nov 22 '18 at 12:57
  • 1
    @MusaAl-hassy it leads to bad markup. Math stuff should be recognizable as such. – Skillmon Nov 22 '18 at 13:46