[Tex/LaTex] Syntax error; pgfuseimage

graphicssyntaxtikz-pgf

Possible Duplicate:
Include figure (from macro) with underscore in filename

I am trying to make first presentation in LaTeX using Beamer environment. In order to include some graphics, I choose pgf package since it is automatically loaded with Beamer.

I was trying to put a simple picture but my attempt failed. I tried to make it as simple as possible to find out where I am doing the mistake but I did not succeed.

I was following this manual: TikZ & PGF Manual for Version 2.10

I am using MikTeX ver 0.4.3. r.857, Beamer from 2012-04-17, Pgf from 2011-11-05.

Code:

\documentclass[slidestop,cmpress,mathsefir,red]{beamer}
\usetheme{sidebar}
\usecolortheme{dove}
\setbeamercolor{structure}{green}
\pgfdeclareimage[width=3cm]{Transmitlogo}{transmit_round}
\begin{document}
\section*{Outline}
\frame {
    \pgfuseimage{Transmitlogo}
    \frametitle{Outline}
    \tableofcontents
}
\end{document}

If I comment \pgfuseimage{Transmitlogo} everything works OK. Keeping the line I am getting error:

! Missing $ inserted.
<inserted text> 
            $
l.38 }

line 38 is the line with the frame ending }.

Thanks for any hit.

Best Answer

This is a misfeature of the \pgfdeclareimage macro, that absorbs the file name without taking precautions about characters which should be allowed in file names, such as the underscore.

However the PGF/TikZ manual states that \includegraphics is preferable (see section 79.1), so use

\includegraphics[width=3cm]{transmit_round}

and you'll experiment no problem.


In case you prefer to get along with \pgfuseimage, a possible fix, which will also allow to include macros in the file name (for denoting in an abstract way a directory, for example) is the following

\documentclass[slidestop,cmpress,mathsefir,red]{beamer}
\usetheme{sidebar}
\usecolortheme{dove}
\setbeamercolor{structure}{green}

%%% PATCH STARTS
\makeatletter
\let\original@pgf@declareimage\pgf@declareimage
\def\pgf@declareimage[#1]#2#3{%
  \def\temppatch@declareimage{\original@pgf@declareimage[#1]{#2}}%
  \edef\temppatch@declareimagearg{#3}%
  \expandafter\temppatch@declareimage\expandafter{\detokenize\expandafter{\temppatch@declareimagearg}}%
}
\makeatother
%%% PATCH ENDS    

\newcommand{\mygraphics}{figures}

\pgfdeclareimage[width=3cm]{Transmitlogo}{transmit_round}
\pgfdeclareimage[width=3cm]{try}{\mygraphics/abc_def}

\begin{document}
\section*{Outline}
\frame {
    \pgfuseimage{Transmitlogo}
    \frametitle{Outline}
    \tableofcontents
}

\frame{\pgfuseimage{try}}
\end{document}

The file in the figures subdirectory is correctly found.

Related Question