[Tex/LaTex] Adding a custom symbol/logo as a font character to XeteX/Latex

fontawesomesymbolsxetex

Imagine you have logo or pictogram you would like to use as a font in XeTeX/LateX much like the fontawesome package provides for the likes of twitter, github etc. How would one go about this ?

Best Answer

In order to get a not yet existing symbol as a character in LaTex from a logo or comparable, please follow these steps:

Disclaimer: This is not a scientific approach nor one founded in Software Engineering. You can file it as a life hack if you so will.

System used (YMMV):

  • Windows 7.1 x64
  • XeLatex
  • MikTex 2.9
  • fontspec package

Step 1

Create an .svg file of your desired symbol using the tool of your choice. [InkScape][1] is a good [FOSS][2] program to do so. Alternatively, VectorMagic is an incredibly good suite for nearly 100% automation of vectorization and tracing.

Remember to save it as SVG 1.1. For this walkthrough, no further constraints are required.

Step 2

Having done so, you can use a number of "font generators" on the web. I have tried a number of them ([fontello][3], [icomoon][4], [fontastic][5]), but only fontastic generated correct .ttf files that I could install and that actually contained the symbols I produced.

Going with fontastic you need to

  • register
  • log in

After logging in, click on [Add more icons][6] in the top navbar. Now you can click on the import button and select your .svg file for upload.

After that, you need to go back to 'Home' and then click on 'Select'. Here you should click on the icon you just uploaded - it has already been 'fontified' . Great !

Select all other icons you might want in the font you are about to generate or simply repeat this step until all your icons have been fontified.

Step 3

Now you click on 'Customize' in the middle navbar.

Now you can do two things:

  1. change the css class mapping you would later use for the icons (mostly for web devs and web designers)
  2. change the character mapping which you will need for this to work in XeteX

For instance, if your desired logo maps to the capital M, then typing M after selecting your font in LateX will result in your icon showing up !

After adjusting your mappings to your need, proceed to 'Publish'.

Here you want to download your font to install it manually on your system.

Step 4

After downloading your font, you can install it (on Windows) by opening the zip, navigating to the 'fonts' fodler contained within and doubleclicking on the file with the .ttf extension. If you cannot see extensions on your system, either activate file extensions to show up or look for a file icon with a small, capital 'A'.

THe font preview window opens where you can check if your font has come out as expected. Click on the 'install' button to install this font on your system for use anywhere.

Step 5

In order to use your font in your tex document, you can add a class file upon which your .tex will be based. Just make sure you create the classfile.cls in the same directory as your .tex.

Here is an example of my classfile fot the document class 'article:

\ProvidesClass{friggeri-cv}[2012/04/30 CV class]
\NeedsTeXFormat{LaTeX2e}

\DeclareOption{print}{\def\@cv@print{}}
\DeclareOption*{%
  \PassOptionsToClass{\CurrentOption}{article}%
}
\ProcessOptions\relax
\LoadClass{article}

%%%%%%%%%
% Fonts %
%%%%%%%%%

\RequirePackage[quiet]{fontspec}
\newfontfamily\customfont[]{generated-font-2}

The last two lines create a new command for you to use in your tex file: \customfont{}

Step 6

Lastly, you need to add the classfile to the header of your tex file by putting

\documentclass[]{yourclassfile}

at its very beginning. You're now set to go! YOu can use {\customfont } to get your symbol in the right size and manipulate it like a font character!

I welcome all feedback to improve this post - feel free to comment.