[Tex/LaTex] Inserting slashed zero in non-OpenType supporting LaTeX

opentypesymbols

Is there a slashed zero symbol in the standard LaTeX font that's accessible with pdflatex et al? I greped through the comprehensive symbols list a bit but didn't spot anything.

In XeLaTeX I can use the OpenType feature +zero on supported fonts. For instance, with Calluna by Exljbris I can do something like this:

\documentclass{minimal}

\usepackage{fontspec}

\newcommand*{\defaultfontfamily}{Calluna}
\setmainfont[Mapping=tex-text]{\defaultfontfamily}
\newcommand*{\lnum}[1]{{\fontspec[RawFeature={+lnum}]{\defaultfontfamily}#1}}
\newcommand*{\zero}[1]{{\fontspec[RawFeature={+zero}]{\defaultfontfamily}#1}}
\newcommand*{\zerolnum}[1]{{\fontspec[RawFeature={+lnum,+zero}]{\defaultfontfamily}#1}}

\begin{document}
0\zero{0}\lnum{0}\zerolnum{0}
\end{document}

and get a few different types of zero:

Several different zeros in Calluna

However, I'd love to find a way to do this in non-OpenType supporting LaTeX engines.

P.S. \(\emptyset\), \(\slashed{0}\), and the like don't count. I'm mostly interested in text mode, but if you have a solution for text mode and math mode that would be nice too. Also, before someone says it, \o and \O are letters, not numbers. They don't count either!

Best Answer

The following example defines poor man's versions of a zero with dot (\pmzerodot) and slash (\pmzeroslash).

Remarks for \pmzerodot:

  • \cdot is used as the dot. Normally it is placed on the math axis that does not have to be the vertical middle of the digit zero. Therefore the height of the digit is measured and the dot is placed in the middle.
  • For slanted fonts, the italic correction for the digit zero is taken into account for a better horizontal placement of the dot.
  • \cdot is used in math mode. This makes a visible difference for bold text fonts. If the font series (\f@series) starts with b, then \mathversion{bold} is used for the dot.

Remarks for \pmzeroslash:

  • The slash is centered vertically around the middle of digit zero.
  • Using the text version of the slash has the advantage that the symbol is taken from the same font as the digit.

Example file:

\documentclass{article}

\makeatletter
\newcommand*{\pmzerodot}{%
  \nfss@text{%
    \sbox0{$\vcenter{}$}% math axis
    \sbox2{0}%
    \sbox4{0\/}%
    \ooalign{%
      0\cr
      \hidewidth
      \kern\dimexpr\wd4-\wd2\relax % compensate for slanted fonts
      \raise\dimexpr(\ht2-\dp2)/2-\ht0\relax\hbox{%
        \if b\expandafter\@car\f@series\@nil\relax
          \mathversion{bold}%
        \fi
        $\cdot\m@th$%
      }%
      \hidewidth
      \cr
      \vphantom{0}% correct depth of final symbol
    }%
  }%
}
\newcommand*{\pmzeroslash}{%
  \nfss@text{%
    \sbox0{0}%
    \sbox2{/}%
    \sbox4{%
      \raise\dimexpr((\ht0-\dp0)-(\ht2-\dp2))/2\relax\copy2 %
    }%
    \ooalign{%
      \hfill\copy4 \hfill\cr
      \hfill0\hfill\cr
    }%
    \vphantom{0\copy4 }% correct overall height and depth of the symbol
  }%
}
\makeatother

\usepackage{amstext}% for resizing the symbol in math

\begin{document}

  \newcommand*{\teststring}{0\pmzerodot\pmzeroslash}

  \teststring

  % check symbol bounding boxes
  \setlength{\fboxsep}{0pt} 
  \setlength{\fboxrule}{.1pt}
  \fbox{0}\fbox{\pmzerodot}\fbox{\pmzeroslash}

  % test different fonts

  \textsf{\teststring}

  \texttt{\teststring}

  \textbf{\teststring}

  \textit{\teststring}

  % math test
  $\teststring^{\teststring^{\teststring}}$

\end{document}

Result

Remarks:

  • The symbols are wrapped in \nfss@text. It is defined by the LaTeX kernel as \mbox inside a group. Package amstext (loaded by amsmath) redefines it as \text that allows that the symbols can be automatically resized in math mode.

  • \ooalign only keeps the height of the first line and the depth of the final line. \vphantom is inserted to get the correct overall height and depth of the symbol.

  • \m@th avoids additional horizontal spacing, if \mathsurround is used.

  • The height of the math axis is available by the height of an empty \vcenter{}.

Related Question