1

Is there any analog of \mathbb which can be used outside of math mode?

My specific problem is that I have a section title which includes \mathbb (in math mode, of course) but I am using hyperref, so I get a warning every time I compile. I would like to have some text alternative which I can put in \texorpdfstring so that I get no warning, but the output in the table of contents still looks similar to the math which appears in the section title.

3
  • You could also use the optional argument of \section to give an alternate formatting in the ToC, additionally to using \texorpdfstring.
    – Skillmon
    Nov 9, 2020 at 14:38
  • I think by table of contents and text mode here you mean the bookmark outline in pdf not the TeX typeset table of contents? You can in theory use unicode text such as 𝔸𝔹ℂ𝔻𝔼𝔽 Nov 9, 2020 at 14:51
  • Note that this is almost a duplicate of tex.stackexchange.com/questions/45513/…, the difference being that the code in the question there (that didn't work in 2012) seems to be the answer here (that works fine in 2020 it seems, for all characters, even uncommon ones such as 𝔽).
    – Marijn
    Nov 9, 2020 at 15:01

2 Answers 2

3

In all three compilers (pdfLaTeX, XeLaTeX, LuaLaTeX) you can put the Unicode characters in \texorpdfstring. For pdfLaTeX this requires \usepackage[unicode]{hyperref}.

MWE:

\documentclass{article}
\usepackage{amssymb}
\usepackage[unicode]{hyperref}
\begin{document}
\section{\texorpdfstring%
{The difference between $\mathbb{R}$, $\mathbb{N}$ and $\mathbb{Q}$}%
{The difference between ℝ, β„•, and β„š}}
\end{document}

Result:

enter image description here

This is slightly more robust than just using \section{The difference between ℝ, β„•, and β„š}, because that requires that the current document font contains the characters (instead of taking them from amssymb), which is not always the case. Also that approach would work only in XeLaTeX and LuaLaTeX. With \texorpdfstring the only requirement is that the font used in the interface of your pdf reader contains the characters, which is more likely to be the case.

1

A nuance:

To expand on the comment about using unicode text.

It turns out that β„β„•β„š are in the Letterlike Symbols unicode block, which in turn means that they could be covered by the text font, and indeed, for Noto Serif font (as an example), they are.

To get them to appear in the fontface being used for math mode (Fira Math, say), the font used for math mode could be re-declared as just another text font in the usual fontspec way.

math font as text

MWE

\documentclass{article}
%\usepackage{amssymb}
\usepackage{xcolor}
\usepackage{unicode-math}
\setmainfont{Noto Serif}
\setmathfont{Fira Math}[Colour=blue]
\newfontface\ftextasmath{Fira Math}[Colour=red]
\usepackage[unicode]{hyperref}
\begin{document}
\section{\texorpdfstring%
{The difference between $\mathbb{R}$, $\mathbb{N}$ and $\mathbb{Q}$}%
{The difference between ℝ, β„•, and β„š}}

Comparison

Text mode:

ℝ, β„•, and β„š
\bigskip

Math mode:

$\mathbb{R}$, $\mathbb{N}$ and $\mathbb{Q}$
\bigskip

Unicode-math macros (text mode):

\BbbR \BbbN \BbbQ  x + y = z
\bigskip

Unicode-math macros (math mode):

$\BbbR \BbbN \BbbQ x + y = z$
\bigskip

Fira Math as text:

\ftextasmath{ℝ β„• β„š}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .