Using Font Awesome

Posted on November 26, 2017

Font Awesome is a font that provides pictographic icons and is commonly used to display icons for email, editing tasks, popular social media website, etc. It is easy to use Font Awesome in ConTeXt: the font ships with ConTeXt Standalone and ConTeXt includes a symbolset to easily access the icons using names rather than icon numbers.

To use FontAwesome icons in ConTeXt, simply load the symbolset fontawesome using

\usesymbols[fontawesome]

and then any icon is accessible using

\symbol[fontawesome][...]

where ... is the name of the icon is listed in the Font Awesome icon list.

Recently, I wanted to use Font Awesome icons in a document that was typeset with CharisSIL at 11pt and there was a size mismatch between the text font and font awesome icons. It took me some time to figure out how to scale the icons so that the result looks good, so I am writing this blog post as a reference for my future self.

Almost all Font Awesome symbols are fixed width, so I decided to simply scale the height of the font to be equal to 1em. This can be done using

\scale[height=1em]{...}

The tricky part was to ensure that the symbol sits at the right location on the baseline. After a bit of trial and error—and skimming through supp-box.mkiv—the best solution was to use:

\inlinedbox{\scale[height=1em]{...}}

Here is a complete example:

\definetypeface[mainfont][rm][specserif][CharisSil][default]
\definetypeface[mainfont][mm][math] [pagellaovereuler][default]
\definetypeface[mainfont][tt][mono] [dejavu][default] [rscale=0.8, features=none]
\setupbodyfont[mainfont,11pt]
\usesymbols[fontawesome]

\define\FA{\dosingleargument\doFA}
\def\doFA[#1]{\inlinedbox
    {\scale[height=1em]{\symbol[fontawesome][#1]}}}

\starttext
Checked box \FA[check-square-o]
Unchecked box \FA[square-o]
\stoptext

which gives

Output showing Font Awesome

This entry was posted in Fonts, Macros and tagged font awesome, symbols.