# Just for fun: Globally replace one glyph with another

Once upon a time, when I used a WYSIWYG word processor, I took a completed document and used Find-Replace to turn all instances of "." into tiny smiley faces. It wasn't really a difference that anyone would notice, but if you printed with a good printer and looked closely, it was there. Each sentence was slightly more joyful, for me at least.

I'm interested in repeating this in LaTeX. My initial stab:

\documentclass{article}

\usepackage{wasysym}% For the smiley character
\usepackage{lipsum}

\catcode\.=\active% Make . an active character
\def.{{\tiny\blacksmiley{}}}% Make . expand to a black smiley

\begin{document}

\section{A Section}
\subsection{Stuff}

Some text. A number: $3.14$. \lipsum[1]

\end{document}


The results are mediocre. The tiny smiley is too large, and will of course remain \tiny even in the middle of \tiny text. The decimal which appears in the subsection label (1.1 Stuff) and the periods in the lipsum text also remain normal periods.

It seems that the better way of doing this would be to define a custom font where the period character is defined as being a black smiley. Is there a way of doing this within LaTeX - that is, saying "load this font, then modify it by redefining the period character as scaled-down version of this black smiley character from another font" ?

In this related question [ Replacing a glyph in one font with a glyph from another ], the asker wanted to replace the double-storey "a" and "g" with single-storey versions. The comments suggested that it's possible, but that the kerning would have to be redefined and this would be an enormous pain. This case is a little different because the replacement character should have the same size and shape as the original - i.e., the kerning of the original period would work perfectly for the replacement smiley.

• What's the background behind making the black smiley tiny? Do you want it to be of similar size to the dot? – 1010011010 Oct 17 '14 at 20:10
• Have a look at tex.stackexchange.com/questions/40828/… – I think it’s a duplicate, what do you think? – doncherry Oct 17 '14 at 20:16
• i think it's a duplicate too, but i also think it might be useful to suggest that instead of using a \tiny smiley directly from a font, a scaled version could be created with \scaledbox from the graphicx package. – barbara beeton Oct 17 '14 at 20:31
• @101001101 Yes, the goal is to make the smiley look like a period. – user1476176 Oct 17 '14 at 20:52
• My question is similar to the linked question in that I'm looking to replace the period, but different in that my specific goal is to do this via replacing the glyph, to avoid all the potential trouble associated with redefining "." as an active character. – user1476176 Oct 17 '14 at 20:57

Making the . active is strongly NOT recommended, because it ruins your ability to specify decimal lengths, such as 1.5pt, or other decimal parameters.

That disclaimer given, the scalerel package allows you to scale one object to the vertical extent of another object. In this case, I scaled the \blacksmiley to the vertical extent of \svdot, which was a saved copy of the period.

In my MWE, I print out a \svdot at the end, so that the comparison may be made. [Note that I removed the \lipsum from my MWE, because it is defined before . is made active and thus retains its non-active periods]

\documentclass{article}

\usepackage{wasysym}% For the smiley character
\usepackage{scalerel}

\let\svdot.
\catcode\.=\active% Make . an active character
\def.{\scalerel*{$\blacksmiley$}{\svdot}}% Make . expand to a black smiley

\begin{document}
\section{A Section}
\subsection{Stuff}
Some text. A number: $3.14$.\svdot
\end{document}