249

I am trying to get the digit one printed the \mathbb{} font in math mode, however the command

\mathbb{1}

outputs some rubbish. I certainly saw the character I am after in some pdf's generated from latex, hence my question: how do you get it to work?

5
  • 3
    possible duplicate of How do I make a blackboard 1? Aug 27, 2011 at 15:04
  • 2
    The \mathbb provided as part of the amsfonts package does not provide numerals. Section 3.3 of amsfonts' documentation states that the \mathbb command it provides uses the msbm font and so supports only uppercase letters: no lowercase, no numerals.
    – mas
    Aug 27, 2011 at 15:52
  • 2
    note that using any package that provides a complete blackboard bold font overrides the \mathbb provided by amsfonts. if you wish to replace only the digit "1", you can use the method described here: Importing a single symbol from a different font Feb 13, 2017 at 17:30
  • 1
    off topic: After years reading math texts, I think that the most common notation for the characteristic function of a set $A$ is \chi_A.
    – Sigur
    Feb 27, 2018 at 11:25
  • 5
    How come "they" don't fix this? Is there a fundamental problem? Jan 20, 2020 at 4:41

10 Answers 10

274

Since \mathbb doesn't support digits (with amssymb or txfonts) you may use bbm:

\documentclass{article}
\usepackage{bbm}
\begin{document}
\[ \mathbbm{1} \]
\end{document}

bbm example

or dsfont in the doublestroke package:

\documentclass{article}
\usepackage{dsfont}
\begin{document}
\[ \mathds{1} \]
\end{document}

dsfont example

3
  • 12
    I guess \mathbbm{1}is the best in terms of consistency with \mathbb. Nov 28, 2014 at 23:15
  • 1
    You can also add \newcommand{\1}[1]{\mathds{1}\left[#1\right]} to your preamble to create a quick indicator function that handles what you wanna put inside it. Nov 8, 2016 at 23:07
  • I get the error: File bbm.sty not found. Also File dsfont.sty not found.
    – Albert
    May 10, 2020 at 16:28
59

Playing some necromancy here, the answer looks very different in 2021. I especially advise against using bbm, as the accepted answer suggests, since the old-fashioned font format it loads will come out pixelated in a PDF, and nobody prints DVIs out on paper any more.

I’d recommend using unicode-math in LuaTeX when you can, and legacy fonts when you have to. Nearly all OpenType math fonts support \mathbb{1} and \Bbbone out of the box. Few if any come with a bold version that supports \boldsymbol{\mathbb{1}}, but you can fake it if you need it:

\documentclass{article}
\tracinglostchars=2
\usepackage{unicode-math}

\setmathfont{NewCMMath-Book}
\setmathfont{NewCMMath-Book}[
  version=bold,
  FakeBold = 1.2 ]

\begin{document}
\[ \mathbb{1} \boldsymbol{\mathbb{1}}
\]
\end{document}

New Computer Modern sample

If your publisher still requires you to use PDFTeX, or you should wish to, the mathalpha package provides a consistent interface for loading and scaling math alphabets, including blackboard bold and bold blackboard bold. Here are the options that ship with TeX Live and at least partially work:

(Note that you do not need to define \Bbbbone this way in your own document! I put this in the template to simplify testing.)

\documentclass{article}
\usepackage{amsmath}
\usepackage[bb=dsserif]{mathalpha}
\usepackage{bm}

\pagestyle{empty}
    
\newcommand\Bbbbone{%
  \ifdefined\mathbbb%
    \mathbbb{1}%
  \else%
    \boldsymbol{\mathbb{1}}%
  \fi}

\begin{document}
\[ \mathbb{1} \Bbbbone
\]
\end{document}

dsserif sample

The dsserif alphabet is the only free one I know of that supports both blackboard-bold and bold-blackboard-bold digits in Type-1 format, and that a package can load without changing your other fonts. You will probably want to scale this to match your math font, with the bbscaled= package option.

With bb=pazo instead of bb=dsserif:

Pazo sample

With bb=fourier:

Fourier sample

With bb=esstix:

Esstix sample

With bb=boondox:

Boondox sample

There are other legacy packages not available through mathalpha (as of February 2021). Here are some of the more important ones that have not already been mentioned.

The cmathbb package is an attractive outline font based on Computer Modern bold.

cmathbb sample

With \usepackage[varbb]{newtxmath}, you get the same alphabet as in Xovee’s answer, but replacing the standard \mathbb:

Newtx varbb sample

There is a similar option for newpxmath (although this is incompatible with bm).

\documentclass{article}
\usepackage{amsmath}
\usepackage[varbb]{newpxmath}

\pagestyle{empty}

\newcommand\Bbbbone{%
  \ifdefined\mathbbb%
    \mathbbb{1}%
  \else%
    \boldsymbol{\mathbb{1}}%
  \fi}

\begin{document}
\[ \mathbb{1} \Bbbbone
\]
\end{document}

Newpx varbb sample

There is yet another blackboard bold alphabet available through newtxmath and newpxmath, with the vvarbb package option:

Newpx vvarbb sample

The stix and stix2 packages load an alphabet similar to boondox. (Which is a fork of the STIX fonts.) Here is what you get with \usepackage{stix2} instead of mathalpha:

STIX 2 font sample

4
  • Thank you very much for the answer. However, using unicode-math ruins the other mathbb letters. Is there any way of keeping the standard mathbb while using unicode-math? PS: I keep coming back to this question since I haven't still a satisfactory answer
    – Manza
    Nov 24, 2022 at 18:04
  • @Manza yes, you can \DeclareMathAlphabet with the AMS bb font. Just use another name than \mathbb.
    – Davislor
    Nov 24, 2022 at 22:38
  • 1
    @Manza Or load an Opentype font whose \mathbb you like better with range=bb.
    – Davislor
    Nov 24, 2022 at 22:38
  • Btw, the newer version of NewCM provides blackboard math in CM style, similar to dsfont. It contains numbera as well. Feb 6 at 15:48
25

Another option is to use bbold package.

\documentclass{article}
\usepackage{bbold}
\begin{document}
\[ \mathbb{1} \]
\end{document}

bbold example

Though it ruins the letters.

21

I'm surprised no one has mentioned this, but you can use the unicode-math package. Note that you need Xe(La)TeX or LuaLaTeX to use this package.

\documentclass{article}

\usepackage{amsmath}
\usepackage{unicode-math}

\begin{document}
    $\mathbb{1}$
\end{document}

enter image description here

2
  • Perhaps because it can't be used with pdflatex: "Package unicode-math Error: Cannot be run with pdfLaTeX!"
    – user26800
    May 24, 2020 at 16:53
  • 1
    Only this worked for me with LuaLaTex. Jun 5, 2020 at 13:34
15

A new solution: use newtxmath package.

With code:

\usepackage{newtxmath}

$\vmathbb{ABCDEFGHIGKLMNOPQRSTUVWSYZ}$

$\vmathbb{abcdefghijklmnopqrstuvwxyz}$

$\vmathbb{0123456789}$

which results:

enter image description here

Also, this solution is compatible with the ACM Template's whitelist restriction, since there're no need to import other packages, the document class asmart already imported the newtxmath.

Here's the document of the newtxmath: http://ctan.mirror.colo-serv.net/fonts/newtx/doc/newtxdoc.pdf

4
  • 4
    Why the lower case letters (except k) are not supported? Mar 15, 2020 at 19:56
  • This also works with the newpxmath package, could you update you answer? :)
    – G.J
    Mar 21, 2023 at 10:14
  • 1
    @HoseinRahnama now it supports lower letters
    – Xovee
    Mar 22, 2023 at 11:13
  • @G.J I have updated the answer! Thank you for remind.
    – Xovee
    Mar 22, 2023 at 11:14
4

Like user41766 said, using bbold is a good idea (the best imho if unicode-math isn't an option), but it would "ruin" the other letters. You can solve this issue by declaring a new alphabet, importing \mathbb from bbold into your own math alphabet, like was suggested here:

\DeclareMathAlphabet{\mathmybb}{U}{bbold}{m}{n}
\newcommand{\1}{\mathmybb{1}}

Note that you can then use \mathmybb in any other situation and name it any other way you please.

img

Edit: This question is also nicely dealt with here, where this compact solution can be found to avoid creating a whole math alphabet:

\newcommand*{\boldone}{\text{\usefont{U}{bbold}{m}{n}1}}
1
  • Thank you! the above \boldone plus the {bbold} package seem nice to me. May 12, 2023 at 11:09
2

This worked for me:

\usepackage{mathbbol}

+\mathbb{1}+

Actually, I'm using LyX, so I put \usepackage in the preamble and then simply used \mathbb with a 1 inside a formula box. It still displays as `rubbish' but renders fine as PDF.

If you don't like the discordance in LyX, you can say something like

\def\bbone{\mathbb{1}}

in the preamble, and then use \bbone in your document, or variants on this theme.

My 2c.

2

Almost all Unicode math fonts have the character U+1D7D9 with TeX control sequence \Bbbone which looks like this: 𝟙.

If you have Unicode math font loaded then you can use \Bbbone or directly 𝟙. For example, in OpTeX:

\fontfam[lm]  % loads Unicode math

$\Bbbone$ or $𝟙$.   
\bye
0
\documentclass{article}        
\usepackage{anyfontsize}         
% For documents in 10pt, 11pt or 12pt     
% \def\one{\mbox{1\hspace{-3.85pt}\fontsize{11}{14.4}\selectfont\textrm{1}}} % 10pt    
\def\one{\mbox{1\hspace{-4.25pt}\fontsize{12}{14.4}\selectfont\textrm{1}}} % 11pt    
% \def\one{\mbox{1\hspace{-4.75pt}\fontsize{13}{14.4}\selectfont\textrm{1}}} % 12pt    
\begin{document}    
You can use either $\one$ or $\one\{A\}$ or $\one_{A}$.
\end{document}

enter image description here

2
  • Welcome to TeX.SE. Do note that \rm is considered deprecated for a LaTeX document. It also doesn't take an argument; instead, it acts as a switch. Thus, instead of \rm{\fontsize{11}{14.4}\selectfont 1}, do write \fontsize{11}{14.4}\selectfont\textrm{1}. Also, is there something that can be done to produce less of an overlap/clash between the tops of the two 1 numeral?
    – Mico
    Feb 12, 2017 at 16:27
  • The correct metrics depend on the font and font family, I guess. I typeset most of my documents with \usepackage{mathptmx}, a Times like font, and the code given works just perfectly. Adjust the argument of \hspace accordingly.
    – Jotazuma
    Feb 12, 2017 at 17:19
0

With unicode-math (requires LuaTeX or XeTex), you can change the font of only the \mathbb{} numbers to, e.g., "Latin Modern Math", which does include them:

\setmathfont{Latin Modern Math}[range=bb/{num}]

You must log in to answer this question.

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