I am trying to insert an icon (a pdf
file) literally next to the section name.
I want the little shield icon to be where the <Icon>
is.
The code to generate this image is:
\subsection{Sentinel $<$Icon$>$}\icon{static/sentinel.pdf}
If I try to add the \icon
inside the \subsection
:
\subsection{Sentinel \icon{static/sentinel.pdf}}
I get an error.
! Missing \endcsname inserted.
<to be read again>
\csname\endcsname
l.42 ...ction{Sentinel \icon{static/sentinel.pdf}}
?
! Emergency stop.
<to be read again>
\csname\endcsname
l.42 ...ction{Sentinel \icon{static/sentinel.pdf}}
! ==> Fatal error occurred, no output PDF file produced!
Transcript written on generated//manual.log.
make: *** [all] Error 1
If possible it would be nice that the icon doesn't appear in the table of content and that the link from the table of content continues to work.
\icon
is defined by
\newcommand{\icon}[1]{\begingroup
\setbox0=\hbox{\includegraphics[height=12pt,keepaspectratio]{#1}}%
\parbox{\wd0}{\box0}\endgroup}
\protect\icon{static/sentinel.pdf}
should work. However, you will get into troubles with bookmarks, ifhyperref
is used\subsection[title for the toc]{\protect\icon{....}}
then. The sectioning commands (at least of standard classes) all have an optional first argument for providing a shorter title (or optional title) which enters the toc and the mandatory argument for the really header of the chapter, section etc. My concern was rather the complaints byhyperref
about non-allowed tokens in the PDFString issue. There should be a\texorpdfstring{\protect\icon{}}{}
command.