
Estou tentando inserir um ícone (um pdf
arquivo) literalmente próximo ao nome da seção.
Quero que o pequeno ícone do escudo esteja onde <Icon>
está.
O código para gerar esta imagem é:
\subsection{Sentinel $<$Icon$>$}\icon{static/sentinel.pdf}
Se eu tentar adicionar o \icon
interior do \subsection
:
\subsection{Sentinel \icon{static/sentinel.pdf}}
Eu recebo um erro.
! 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
Se possível, seria bom que o ícone não aparecesse no índice e que o link do índice continuasse funcionando.
\icon
é definido por
\newcommand{\icon}[1]{\begingroup
\setbox0=\hbox{\includegraphics[height=12pt,keepaspectratio]{#1}}%
\parbox{\wd0}{\box0}\endgroup}
Responder1
Você precisa de um pouco \protect
de íon. Aliás, esse complicado \newcommand
pode ser simplificado.
\documentclass{article}
\usepackage{graphicx}
\newcommand{\icon}[1]{\includegraphics[height=12pt]{#1}}
\begin{document}
\section{Some section here}
\subsection{Sentinel \protect\icon{example-image-a}}
\end{document}
Se você não quiser \protect
em muitos casos, você tem essas possibilidades. Primeiro faça isso robust
usando etoolbox
.
\documentclass{article}
\usepackage{graphicx}
\usepackage{etoolbox}
\newcommand{\icon}[1]{\includegraphics[height=12pt]{#1}}
\robustify{\icon}
\begin{document}
\section{Some section here}
\subsection{Sentinel \icon{example-image-a}}
\end{document}
Ou use \newrobustcmd
(de etoolbox
novo) como
\usepackage{etoolbox}
\newrobustcmd{\icon}[1]{\includegraphics[height=12pt]{#1}}
Ou use um argumento opcional como
\subsection[<opt argument>]{Sentinel \icon{example-image-a}}
etc....
Se você estiver usando hyperref
, pode ser necessário usá-lo \texorpdfstring{\icon{example-image-a}}{}
para se livrar do aviso e das consequências.
\documentclass{article}
\usepackage{graphicx}
\usepackage{etoolbox}
\usepackage{hyperref}
\newrobustcmd{\icon}[1]{\includegraphics[height=12pt]{#1}}
\begin{document}
\section{Some section here}
\subsection{Sentinel \texorpdfstring{\icon{example-image-a}}{}}
\end{document}