1

So, I'm using the fontawesome package to display icons next to small headings. In essence, the following code

{\large \faBook\ } \textbf {Method}\\

Creates the following:

Icon of a book followed by "Method"

Now, I need to do this at multiple points in the document, but with different icons. As such, I attempted the following:

\newcommand{\iconHeading}[2]{{\large \fa#1\ } \textbf{#2}\\}

\iconHeading{Book}{Method}

Unfortunately, this returns:

Use of \fa doesn't match its definition.

So, I'd be curious to know if this is possible in any way?

Just for the sake of reference, fontawesome works in the following way:

\faNameOfIcon\
1
1

The fontawesome package defines \faBook to do \faicon{book}. So you simply solve the issue by doing

\newcommand{\iconHeading}[2]{%
  {\large\faicon{#1}}\quad\textbf{#2}%
}

calling

\iconHeading{book}{Method}

The translation rules are simple:

Book -> book
SearchPlus -> search-plus
ArrowCircleODown -> arrow-circle-o-down

You could also do

\newcommand{\iconHeading}[2]{%
  {\large\csname fa#1\endcsname}\quad\textbf{#2}%
}

and in this case you would call this like \iconHeading{Book}{Method}.

Take your pick.

2
  • That's awesome, thanks so much. I prefer the first method. Just out of interest, what does \csname do?
    – DLJ
    Dec 16 '17 at 13:57
  • 2
    @DLJ It builds a command name from the characters up to \endcsname. In other words it does what you were trying to do with \fa#1 which doesn't work because at definition time \fa is already stored as a single token.
    – egreg
    Dec 16 '17 at 14:13

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.