2

I have downloaded the icon font "Font Awesome" to use unicode icons to illustrate my documents.

Using XeTeX, I was able to declare a new font family like this:

\newfontfamily\fontawesome[
    Path=fonts/iconic/FontAwesome/
]{FontAwesome.otf}

This works. Now, if I want to use an icon from the font, for example the floppy disk icon, I do the following:

\fontawesome{}\normalfont

I would however like to have a shorter way to use this icon. I would much prefer something like ... Some text \floppy more text... to avoid to manually have to reset the font after using the icon. I came across \DeclareUnicodeCharacter{f0c7}{\floppy}, but it seems like this wouldn't work with XeTeX.

Any ideas on how to "shortcut" this icon in a similar way?

  • What's wrong with \newcommand*\floppy{{\fontawesome{}}} or similar? – Joseph Wright Aug 4 '14 at 8:14
  • @JosephWright Nothing :-) I guess that answers my question. – mritz_p Aug 4 '14 at 8:26
2

You don't want a Unicode char here, you want a new command that inserts jsut the appropriate symbol.

\newcommand*\floppy{{\fontawesome{}}}

I've used an extra pair of braces to group the font change so there is no need for \normalfont. Note that in the usual TeX way you will need to allow for the space-skipping which occurs after the command, e.g. \floppy{} more text not \floppy more text.

2
\documentclass[border=10pt]{standalone}
\usepackage{fontawesome}
\setmainfont{Linux Libertine O}
\def\floppyA{{\FA}}
\let\floppyB\faSave
\let\\floppyB

\begin{document}
Some awesome icons:
\faSave\   %%% loads automatically  the awesome icons
\floppyA\ 
\floppyB\  
\

\end{document}

enter image description here

  • Thanks for your answer. I was not aware that there was a package for "Font Awesome". I do prefer the answer by @JosephWright though, since it does not require additional packages and works with other fonts too. – mritz_p Aug 4 '14 at 9:08
  • package fontawesome does nothing else than defining the font family and the macros \fa<name>. It doesn't touch any local font setting! – user2478 Aug 4 '14 at 9:11
  • I am aware of that. But the other method makes it very easy for me, to use other Icon Fonts, like the ones featured here fontsquirrel.com/fonts/list/classification/dingbat, without hesitation. – mritz_p Aug 5 '14 at 6:46
  • fontawesome itself defines the font family \FA. You can define any other icon font. It is overkill to use \newfontfamily for fontawesome! – user2478 Aug 5 '14 at 6:52
  • Thank you. Perhaps you misunderstood, I am not using the fontawesome package. – mritz_p Aug 5 '14 at 7:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.