# How to create a virtual font?

In his answer to the question Replace hyphenation character by a backwards arrow, Hendrik Vogt writes:

If you come into a situation where you want your hyphenchar to be something like \hookleftarrow, and Philipp's answer does not help, then there's still the option to create a virtual font. By this you can circumvent both the problems that \hookleftarrow is from a different font and that it's not a single character. It's not as hard as it might sound: If you need this, I can fill in the details.

I would like to know these "details" and a solution to this problem in particular.

-
The UK TUG FAQ has a page on virtual fonts. There many other helpful resources. If you have access to a copy of Alan Hoenig's book "TeX Unbound: LaTeX & TeX strategies for fonts, graphics, and more" the chapter on "Virtual Fonts, Virtuous Fonts" is a good introduction to the topic, if now getting rather dated (published 1998). Amazon have a Look-inside facility for the book‌​; there was a review in TUGboat. – mas Aug 16 '11 at 17:36
Do you have a specific group of fonts in mind you'd like to convert to virtual fonts, or do you want to have instructions for all possible fonts? – Mico Sep 5 '11 at 17:18

You can do the following steps to create a virtual font with the hookleftarrow in it. First choose a font which you want as a base font. In this example, I take a helvetica clone (phvr8r). Create the property list format from that font and put the result into a file that will be used as a template for our virtual font property list file (vpl):

tftopl phvr8r.tfm > myfont.vpl


Now edit this file and add the following lines at the beginning of the vpl file:

(MAPFONT D 0 (FONTNAME phvr8r))
(MAPFONT D 1 (FONTNAME cmmi10))
(MAPFONT D 2 (FONTNAME cmsy10))


This loads phvr8r (our base font), and both math fonts needed for the hookleftarrow. Now we want to replace the hyphen of the font, so look up entry 055 (CHARACTER O 55 and replace this entry with

(CHARACTER O 55
(CHARWD R 0.8)
(MAP
(SELECTFONT D 2)
(SETCHAR O 040)
(MOVELEFT R 0.200)
(SELECTFONT D 1)
(SETCHAR O 055)
)
)


We place character (octal) 040 from font #2 and move left a bit and place character 055 from font 1. Now create a virtual font (this is a vpand a tfm file) from the property list:

vptovf myfont


Now your font is ready to use (put it in a directory where TeX can find it - I used the current working directory). This is my plain TeX test file:

 \font\myfont=myfont
\hsize 4in
\myfont
A wonderful serenity has taken possession of my entire soul, like these sweet
mornings of spring which I enjoy with my whole heart. I am alone, and feel the
charm of existence in this spot, which was created for the bliss of souls like mine.
I am so happy, my dear friend, so absorbed in the exquisite sense of mere tranquil
existence, that I neglect my talents. I should be incapable of drawing a single
stroke at the present moment; and yet I feel that I never was a greater artist than now.
\bye

-
Thanks a lot, it works perfectly! – Michel Fioc Sep 7 '11 at 9:42
@Michel: I now merged your registered and unregistered account together, so you receive ownership of this question again. You can now up-vote and accept an answer. – Martin Scharrer Sep 7 '11 at 10:20

Patrick's procedure works well indeed. However it's a bit more complicated to persuade LaTeX to use the new font. Here is a hack, I'll use the same font as example.

mv phvr8r.tfm xphvr8r.tfm
tftopl xphvr8r.tfm > phvr8r.vpl


Now edit the .vpl file as Patrick suggests, but changing

(MAPFONT D 0 (FONTNAME phvr8r)) -> (MAPFONT D 0 (FONTNAME xphvr8r))


Then run

vpltovf phvr8r.vpl


If we now write this test file in the same directory

\documentclass{article}
\pdfmapline{+xphvr8r NimbusSanL-Regu " TeXBase1Encoding ReEncodeFont " <8r.enc <uhvr8a.pfb}

\setlenght{\textwidth}{4in}

\begin{document}
\fontfamily{phv}\selectfont

A wonderful serenity has taken possession of my entire soul, like these sweet
mornings of spring which I enjoy with my whole heart. I am alone, and feel the
charm of existence in this spot, which was created for the bliss of souls like mine.
I am so happy, my dear friend, so absorbed in the exquisite sense of mere tranquil
existence, that I neglect my talents. I should be incapable of drawing a single
stroke at the present moment; and yet I feel that I never was a greater artist than now.

\end{document}


we'll get the same output. The argument of \pdfmapline can be obtained by looking for phvr8r in pdftex.map, by copying the relevant line and adding +x in front of it.

This works because TeX looks first in the current directory for files. Doing this way makes it possible to use the standard font description files for the phv family. In case the newly created virtual font must be used for bigger projects, it's better to define a new font family name and build new font description files.

-