[Tex/LaTex] Create a symbol font from SVG symbols

conversionfontsmetapostpackage-writingsvg

Is it possible to create an own scalable font from a set of symbols (~700), all in SVG format. All of them are symbols (like Zapf Dingbats), so there would be no need for special settings like ligatures, italic corrections, etc. Basically I want that {\mysymbolfont\char123} displays the symbol which was originally provided as 123.svg. Should the ~700 symbols be to many I don't mind to split it into two or more fonts. All symbols have about the same height but vary in width.

I imagine that the SVG needs to be converted to MetaPost first. What would be the steps to do this and to create a basic font out of this? What LaTeX code is required to declare the font, i.e. how to create a LaTeX package for it?

I realize that font creation is not a trivial thing. Any hints are welcome.

PS: I realize that I can convert the SVGs to PDFs and include them as small images. That's what I'm doing at the moment, but it would be great to have it as font, because I guess its much more efficient.

Best Answer

Here are some rough step-by-step instructions to generate a font using FontForge and make it available to TeX.

  1. Start FontForge and create a new font.
  2. Import the SVG files into the different glyphs. The import is not perfect: For example, you might need to remove some spurious paths, and you should move and scale the glyphs so that they sit on the baseline and their height does not exceed 1000 units (probably around 800 units is fine). See also the instructions on the FontForge site.
  3. Use File->Generate Fonts to generate a (binary) PostScript Type1 font. Only 256 characters are accessible in one PS Type 1 font, so if you have 700 symbols, you actually want to make 3 different fonts (or you can make one font and then let pdftex/dvips re-encode them, but this a bit more complicated.) Alternatively, generate an OpenType font, which you can use directly with LuaTeX or XeTeX.
  4. You can let FontForge create TeX font metrics too, or you can use afm2tfm to generate these from the .afm files that FontForge generates.
  5. Generate a map file mysymbols.map that lists your fonts in the following format

    mysymbols1 MySymbols1 <mysymbols1.pfb
    mysymbols2 MySymbols2 <mysymbols2.pfb
    mysymbols3 MySymbols3 <mysymbols3.pfb
    

    The syntax of map files is described in Chapter 6 of the dvips manual.

  6. Copy all (.tfm, .pfb and .map) files into a texmf tree: .tfm files go into a subfolder of fonts/tfm/, .pfb files into a subfolder of fonts/type1 and the .map file goes into a subfolder of fonts/map/dvips.
  7. You might need to regenerate the file database by running mktexlsr.
  8. Activate the map file. In TeXLive, you can do this by running

    updmap-sys --enable Map mysymbols.map
    

    as a super user (Use updmap if you don't have admin rights.)

  9. Now you should be able to use the fonts in TeX. For instance

    \font\mysym=mysymbols1 at 10pt\mysym\char0
    

    should print the first glyph in mysymbols1.

  10. To use the font with the LaTeX font selection macros, you need to declare it using \DeclareFontFamily and \DeclareFontShape in a package or font definition file. For instance, to declare the first family, you could use the following code:

    \DeclareFontFamily{U}{mysymbols1}{}
    \DeclareFontShape{U}{mysymbols1}{m}{n}{ <-> mysymbols1 }{}
    

    After that, you can access the font in LaTeX like this:

    \usefont{U}{mysymbols1}{m}{n}\char0
    

    See the LaTeX 2e font selection guide for more information.