6

I am writing a paper on overleaf where I use the prime indicator function, which is 0 when its input is not a prime and 1 otherwise. I have seen it been written as a 1 with the same font as sets like the integers and reals. So I thought using the \mathbb command would write it in the proper format. However, \mathbb{1} doesn’t give a one at all, it gives lines written weirdly. Here is a picture:

enter image description here

(I apologize for the blurry picture as I am on a phone right now) The packages I am using are Amsmath and Amssymb. When I put a Z in \mathbb I get what I want, but it does not work for 1 for some reason.

Stephen
  • 3,826
  • 2
    https://tex.stackexchange.com/questions/488/blackboard-bold-characters – Stephen Jan 04 '24 at 02:03
  • 3
    Welcome! If you need further help, please provide code for a minimal document which we can compile to reproduce the problem, but likely the characters are just missing. (The log should tell you this.) – cfr Jan 04 '24 at 02:58
  • I will add this, I appreciate that. The first comment solves my issue but technically doesn’t answer the question exactly. Also the log did not say anything about that. – Kamal Saleh Jan 04 '24 at 03:00
  • You could also load the dsfont package and write \mathds{1}. (I suppose "ds" is short for "double-struck".) – Mico Jan 04 '24 at 03:35
  • 2
    This has already been answered here. In short, there is no symbol for "1" in the \mathbb font, so you need a workaround. – bonk Jan 04 '24 at 03:39
  • The symbol that you get seems to be \nVdash (not double vertical, dash). If you are fine with using unicode fonts (with xelatex or lualatex), then many fonts such as NewCM, LM, Stix2 provide with double-struck 1. – Apoorv Potnis Jan 04 '24 at 05:57

3 Answers3

15

You want the explanation. OK, here it is.

Letters and digits are assigned math class 7, which means the same as class 0 (ordinary symbols) as far as spacing is concerned, but the letter or digit is taken from the math font corresponding to the current math group (math family, in plain TeX parlance).

Thus \mathit{1} or \mathbf{1} will choose the character at the slot 0x31 (hexadecimal, 49 in decimal) of the font assigned at startup to the “math italic” or “math bold”. This also works for \mathcal{1} and \mathbb{1}, but the fonts used by \mathcal and \mathbb don't necessarily have a 1 at that slot and in most font setups only uppercase letters are supported for \mathcal and \mathbb. What you get from \mathbb{1} is quite unpredictable.

Some math fonts have extended support for \mathcal or \mathbb to cover the whole alphabet (uppercase and lowercase).

If you're happy with your current font setup, but need a double stroked 1, you can look for a font that supports it. For instance, stix2 does

enter image description here

How can you get it in your document without loading stix2, which would completely change the document fonts?

You look into stix2.sty to find

\DeclareSymbolFontAlphabet{\mathbb}  {symbols3}

Now we look for symbols3

\DeclareSymbolFont{symbols3}      {LS1}{stix2bb}   {m} {n}

OK, now we look for the file ls1stix2bb.fd

\ProvidesFile{ls1stix2bb.fd}
[2018/04/02 v2.0.0-latex stix2 %
blackboard LS1 %
font definitions]
\DeclareFontFamily{LS1}{stix2bb}{\skewchar\font127 }

\DeclareFontShape{LS1}{stix2bb}{m}{n} {<-> stix2-mathbb}{} \DeclareFontShape{LS1}{stix2bb}{m}{it}{<-> stix2-mathbbit}{} \DeclareFontShape{LS1}{stix2bb}{b}{n} {<->sub * stix2bb/m/n}{} \DeclareFontShape{LS1}{stix2bb}{b}{it}{<->sub * stix2bb/m/it}{} \endinput

and we just need the first one. But we can avoid defining a font encoding, because we just need ASCII characters.

\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}

%%% put this in your document preamble \DeclareFontFamily{U}{stix2bb}{} \DeclareFontShape{U}{stix2bb}{m}{n} {<-> stix2-mathbb}{}

\NewDocumentCommand{\indicator}{}{\text{\usefont{U}{stix2bb}{m}{n}1}} %%%

\begin{document}

$\mathbb{A}+\indicator_{X}(x)$

\end{document}

enter image description here

egreg
  • 1,121,712
4

The symbol is registered in Unicode table. If you are using Unicode math, then you can use the symbol directly or using a macro. For example, in OpTeX:

\fontfam[lm]
$$
\bye

or

\fontfam[lm]
$\bbchar 1$
\bye

If you are using classical TeX (wich doesn't support Unicode) then you will drown in problems. The reason is that there is no single font with all math characters (like in Unicode math) but the set of math symbols is composed of many fonts: typically 7 bit fonts with 128 characters in them and each of them has very specific encoding. This concept has no future.

And why \mathbb{1} in LaTeX doesn't report problem and prints something different than user expects? The \mathbb macro selects one of the 7 bit font (mentioned above) and this font has a special math symbol at the code slot of 1 character, no .

wipet
  • 74,238
3

We could invoke the blackboard numbers by \mathbbold as follows.

\documentclass{article}
\usepackage{amsmath,amsfonts,amssymb}
\DeclareMathAlphabet{\mathbbold}{U}{bbold}{m}{n}

\begin{document} \huge \begin{align} \mathbbold{0123456789}\ \mathbb{ABCQR} \end{align}

\end{document}

enter image description here

As above, we use blackboard numbers by \mathbbold and blackboard letters by \mathbb from amsfonts or amssymb. Note that such blackboard numbers are also included in the mathbbol package which also includes blackboard letters different from ones here, and which is included on both computers installing windows and macs.

Also, the bbold package in which the blackboard numbers and letters here are included, is included in TeX Live 202X while not in the MacTeX. So if you use TeX Live on computers installing windows, you could invoke the bbold package, and if you use MacTeX on macs, you could use the solution as above.

M. Logic
  • 4,214