Get a proper double-struck one while using amsmath

amssymbmath-mode

I am using the amssymb package and from time to time I want to print a proper looking double-struck digit 1 as I could get by using the bbold package.

The double-struck one I am looking for

However they both are using the \mathbb{} command, so importing both just results in bbold overwriting the amssymb command (it somehow does not matter which package I import first). Since I only need a double-struck 1 and not any other double-struck number and I am using the amssymb version much more often, I thought of maybe declaring a new operator (e.g. \id) which uses the bbold version. I cannot seem to get it to work, however (Of course I also looked for other workarounds or other packages, but that did not turn out successfully either).

The somehow working version for at least defining my \id Operator looks like this:

\documentclass{article}

\usepackage{bbold}
\DeclareMathOperator{\id}{$\mathbb{1}$}



\begin{document}

\begin{equation}
    \id
\end{equation}

\end{document}

The result is:
result
Additionally, I get the following error massages:

Undefined control sequence. (line 4)
LaTeX Error: Missing \begin{document}. (line 4)
Undefined control sequence. (line 11)

Best Answer

Your code isn't working because (1) you don't load amsmath so \DeclareMathOperator is not defined, and (2) where you use \id you are already inside math mode because of the \begin{equation}, and so using the dollar signs $ in the operator definition yields an error. That's not what \DeclareMathOperator is for anyway -- see here. \ensuremath would have made more sense in your definition.

I take it the real problem is that you want to use the font loaded by amssymb for \mathbb as applied to letters, but loading the bbold package prevents that?

You can use the bbold font in math mode without loading the bbold package by declaring a math alphabet using a different name than \mathbb. (Look at bbold.sty--a slight variation of this is the only important command for math mode in it.)

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

\DeclareMathAlphabet{\bbold}{U}{bbold}{m}{n}
\newcommand{\id}{\ensuremath{\bbold{1}}}

\begin{document}

\begin{equation}
    \id \mathbb{A}
\end{equation}

\end{document}

bbold examples

There is a limit to how many math alphabets you're allowed to declare, so if you are at your limit because of other packages, you can modify the instructions given here for grabbing a single certain math mode symbol:

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

\makeatletter
\newcommand\bboldsymbol[2][\mathord]{%
  #1{\@bboldmathsymbol{#2}}}
\def\@bboldmathsymbol#1{\mathchoice
  {\@bboldm@thsymbol{#1}\tf@size}
  {\@bboldm@thsymbol{#1}\tf@size}
  {\@bboldm@thsymbol{#1}\sf@size}
  {\@bboldm@thsymbol{#1}\ssf@size}}
\def\@bboldm@thsymbol#1#2{%
  \mbox{\fontsize{#2}{#2}\usefont{U}{bbold}{m}{n}#1}}
\makeatother
\newcommand{\id}{\bboldsymbol{1}}

\begin{document}

\begin{equation}
    \id \mathbb{A}
\end{equation}

\end{document}