5

I have asked before in Using my svg images as blackboard bold characters about how to use an entire alphabet of svg images. I will now simplify my question to only one character (and no phantom character below it).

I have an svg image of a blackboard bold 0 that I want to insert and use as a command \zero. I want it to have the same size, placement inline and spacing as \mathbf{0} from the amsmath package. I also want that the command properly resizes when in display mode, text mode, script and scriptscript sizes.

I believe this involves using \includesvg (or \includegraphics if using a png image is better) from the svg package with specified sizes and placement, \mathord for the proper spacing in math mode, and \mathchoice for the 4 math sizes, but I do not know how to do this properly.

2 Answers 2

7

You could do this with scalerel.

enter image description here

\documentclass{article}

\usepackage{scalerel}

\newcommand{\zero}{\scalerel*{\includegraphics{example-image}}{\mathbf{0}}}

\begin{document}

Here is some text.  $\mathbf{0}_{\mathbf{0}_{\mathbf{0}}}\zero_{\zero_{\zero}}$

\end{document}
1
  • Thanks, this works well. I am still testing the placement because 0 goes slightly below the baseline. Commented May 23 at 15:29
7

I'd convert SVG to PDF, but you're the judge about it.

Anyway, here's how I'd do it (using a PDF image).

\documentclass{article}
\usepackage{amsmath}
\usepackage{graphicx}

\NewDocumentCommand{\bbzero}{}{%
  \text{\normalfont\includegraphics[height=\fontcharht\font`0]{example-image-9x16}}%
}

\begin{document}

$1\bbzero_{1\bbzero_{1\bbzero}}$

$0\bbzero_{0\bbzero_{0\bbzero}}$

\end{document}

enter image description here

This is the basic setup, but now we realize that digits, especially 0, overshoot their bounding box and so also your image should.

\documentclass{article}
\usepackage{amsmath}
\usepackage{graphicx}

\newlength\bbheight
\NewDocumentCommand{\bbzero}{}{%
  \text{%
    \normalfont
    \bbheight=\fontcharht\font`0 % save for reuse
    \raisebox{-0.04\bbheight}[\bbheight][0pt]{%
      \includegraphics[height=1.08\bbheight]{example-image-9x16}%
    }%
  }%
}

\begin{document}

$1\bbzero_{1\bbzero_{1\bbzero}}$

$0\bbzero_{0\bbzero_{0\bbzero}}$

\end{document}

The 8% increase works for Computer Modern, experiment with your font setup.

enter image description here

3
  • This uses the size of 0, not \mathbf{0}, right? Is there a way to fix that? Also, I know this is not part of the answer, but I tested with the character Q, which has some a greater depth, and the result looks odd. I believe it is because this code takes into account only height. Is this easy to fix? Commented May 23 at 15:27
  • @PedroG.Mattos Use \normalfont\bfseries instead of \normalfont. Why using Q?
    – egreg
    Commented May 23 at 16:19
  • I am testing this for the whole Latin and Greek alphabets, as well as Hindu-Arabic numerals. Commented May 28 at 19:06

You must log in to answer this question.

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