Using Font Awesome icons from groff
I recently had a need for using icons in a PDF that I was generating. This PDF
is generated using groff
. More specifically, it's generated using the mom
macro package for groff
. What follows is a guide to how I use pretty icons in
the PDFs I create with mom
.
The creator of mom
provides a helpful script for adding fonts to groff
.
First, acquire the font files and run this script to add them to groff
. I
create them as regular fonts using the following invocation of the script.
# ./install-font.sh -s -d -n -F FontAwesome -f +R './Font Awesome 6
Free-Regular-400.otf'
-s
installs the font as a system font to/usr/share/groff
.-d
makes the font available togropdf
.-n
doesn't copy input files to a system-accessible location.-F
names the font family.-f
names the style (when the name is prefixed with+
).
This will install the fonts into
/usr/share/groff/site-font/devpdf/FontAwesomeR
. In order to name the icons
we're going to use, we need a little bit of information out of this file. Let's
pretend like we're attempting to use the file icon. If we grep the installed
font for "file", we find the following line:
# rg 'file$' /usr/share/groff/site-font/devpdf/FontAwesomeR
146:--- 750,875,125 3 352 file
The number that comes before the name (in this case, 352) is the glyph's ID. We'll need this in just a moment.
Now, we can make a groff
file. In icon.mom
, we write
.char \[file] \N[352]
.FT FontAwesomeR
.PT_SIZE 64
.ALD 64p
\[file]
.char
defines a custom character\[file]
to be the glyph with ID 352..FT
sets Font Awesome as the active font..PT_SIZE
sets the font size to be larger (so it's easier to see)..ALD
advances the lead, moves vertically down the page (so the icon isn't cut off).\[file]
uses the icon.
Invoking groff
in the following way
$ pdfmom icon.mom > icon.pdf
produces a PDF file that uses the icon, as desired.