12

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.

user1476176
  • 1,225
  • 1
    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
  • 2
    Have a look at https://tex.stackexchange.com/questions/40828/replacing-all-dots-in-a-document – I think it’s a duplicate, what do you think? – doncherry Oct 17 '14 at 20:16
  • 1
    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
  • Yes. It can be done using virtual fonts. If you planned to do it for the default fonts, you would need to do it for all optical sizes you use. You would also need to do it for sans and typewriter, as well as roman, if applicable. (I'm assuming you don't wish to do it in mathematics.) How much time and effort are you prepared to spend? How much do you know about TeX's fonts? (Do you know what a virtual font is? Have you read the font installation guide?) If you really want to do it, start by doing something simpler: work through the tutorials in that guide. – cfr Oct 18 '14 at 01:47
  • Oh. And you will know what the kerning should be but I think you will need to copy the kerning information or it will be lost. I can't remember: it may be that there is a way to set the glyph without setting the kerning, in which case you could just do that (i.e. set the full stop the normal way and then just set the glyph). Note that what you are doing is *not* replacing a glyph with another. What you have to do is construct the entire (virtual) font according to your requirements. To use CM, that means constructing entirely new families of fonts which provide the coverage desired. – cfr Oct 18 '14 at 01:52
  • A suggestion: Do us a favour and change your username to something more telling than "user1234". – Martin Schröder Oct 21 '14 at 22:48

1 Answers1

11

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}

enter image description here