# How can I replace a character (zero)?

Is it possible to replace characters in pdflatex? I use the Minion Pro and Myriad Pro font and the zero looks like a small 'O'. I want to replace the zero by a zero with a dot or slash in the middle (Inserting slashed zero in non-OpenType supporting LaTeX). Is it possible to replace the character globally (I just want to write 0 instead of something like \zero)?

Is it possible in pdflatex or should I switch to lualatex (I have no experience in Lualatex but I have heard it has better font handling)?

• It is possible but if the existing package doesn't support this out of the box, it will be a lot of work for a relatively small gain. If XeLaTeX or LuaLaTeX is an option, that will be by far the more straightforward option. Failing that, I would look to see if any fonts are already set up suitably for pdflatex. I'd only consider ways of creating support for this as a last resort. (And it would be a lot more hassle than e.g. just typing \zero now and again. It would be easier to just write a script to replace all your 0s with \zeros when done writing!)
– cfr
Jan 4, 2014 at 19:26
• You observe that the zero character "looks like a small 'o'." Are you using "oldstyle" (aka text-style) numerals instead of "lining" (aka "uppercase") numerals? AFAICT, there are no slashed variants of the "0" character for oldstyle figures -- at least not for Minion Pro and Myriad Pro. If you want slashed zeros, you should be using lining-style numerals throughout, not just for "0".
– Mico
Jan 4, 2014 at 21:50

If switching to LuaLaTeX is something you're considering doing anyway, then you'll find that using a "slashed zero" is very straightforward: it's a simple option provided by the command \setmainfont (and \setsansfont) of the fontspec package.

% !TEX TS-program = lualatex
\documentclass{article}
\usepackage{fontspec}
\setmainfont[Numbers=SlashedZero]{Minion Pro}
\begin{document}
Minion Pro: 1001 007

\sffamily
\end{document}


This program can be run under XeLaTeX as well. Incidentally, do note that the slashed zeros in the example above are being produced in text mode. There is apparently no such thing as a unicode-compliant slashed zero in math mode.

Aside: The most recent version -- released within just the past few days -- of the luaotfload package (which is loaded by fontspec) contains at least one serious bug that makes it crash with a cryptic and fairly useless error message. If you have TeXLive2013 on your system -- sorry, I don't have MikTeX and thus don't know what MikTeX users should do -- and you've recently run the TeXLive Manager program to update your distribution's packages, you can revert to the previous version of luaotfload by executing the command

sudo tlmgr restore luaotfload 31286


at a command prompt. Hopefully, a bug fix for this important package will be pushed to the CTAN soon.

• Thanks Mico, you made my day! Especially the hint to the bug saved me some time. Everything works perfectly with LuaTex. I only have to convert my files to UTF-8 and do some minor changed in the preamble. Jan 5, 2014 at 14:03
• Damn it! Too happy too soon. It only works for normal text. If I use $0$ in a formula, I get the "standard" zero. I have read that I have to include \usepackage[no-math]{fontspec}, \usepackage{MnSymbol} to get the Minion Pro math symbols in LuaTex. I am not sure but I think this package has no support for "slashed zeros". Can I use the MnSymbol package but set the numbers using Minion Pro and Slashed Zero option? Jan 5, 2014 at 21:05
• @user4811 - I tried to indicate in the 2nd para of my answer that there seems to be no slashed-zero glyph in any Opentype math font. (I checked Latin Modern Math, Asana Math, XITS Math, and Cambria Math: definitely no slashed zeros. Minion Math has a symbol of which I'm not sure if it's supposed to be a slashed zero or the "empty set".) This suggests that it's probably not advisable to use such a glyph in math mode.
– Mico
Jan 5, 2014 at 21:14
• I have found a solution and add it to your solution. Jan 6, 2014 at 18:08

One option with pdflatex (and without Minion font, sorry I do not have this font installed) for small chunks of simple text (without any LaTeX command) could be the package xstring:

\documentclass{article}
\usepackage{xstring}
\usepackage{mathtools}
\newcommand\zero{\rlap{0}/}
\begin{document}
\StrSubstitute{%

102030 is a big number

But 1020030004000 is bigger

}{0}{\zero}
\end{document}


Edit

As Mico commented, \rlap{0}/ is not a very beautiful slashed zero, but the tuning of the slash position is not easy inside a string substitution. An easy alternative could be $\emptyset$ but unfortunately is clearly bigger than the normal 0. But it is possible to select a character much more similar:

\documentclass{article}
\usepackage{xstring}
\font\zerofont = cmsy7 at 9.3pt
\newcommand\zero{{\zerofont \char 59}}
\begin{document}
\StrSubstitute{%

102030 is a big number

But 1020030004000 is bigger

}{0}{\zero}

Zeroes comparison:
$\emptyset${\zerofont \char 59}0$\rlap{0}/$
\end{document}


• The "slash" character, /, is really too tall for the purpose of creating a "slashed zero" character.
– Mico
Jan 4, 2014 at 20:19
• @Mico. I agreed. It was only to show the character substitution with some more that another character as $\emptyset$(that also look ugly in this MWE). I will update the answer.
– Fran
Jan 4, 2014 at 21:38