Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question

marked as duplicate by percusse, Marco Daniel, Tom Bombadil, zeroth, lockstep Sep 22 '12 at 7:27

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
your file name has underscore which triggers TeX to look for math mode context like $a_i$. –  percusse Sep 21 '12 at 10:36
    
Please, put your text as an answer, it works just fine. Such a trivial mistake, thx. So it means, that files cannot have _inside their names. –  MasterPJ Sep 21 '12 at 10:41
    
Instead may I suggest to close this as too localized or a duplicate? It's indeed a minor issue and would serve better to point to a better answer. –  percusse Sep 21 '12 at 10:43
    
Sure, probably no one will use it in the future. –  MasterPJ Sep 21 '12 at 10:44
    
@percusse The trick in the linked question/answer does not work here, which is a very different problem, not involving \includegraphics. –  egreg Sep 21 '12 at 11:48
add comment

1 Answer

up vote 4 down vote accepted

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.

share|improve this answer
    
That works perfectly, thank you. You prevented me from renaming a lot of picture names! –  MasterPJ Sep 24 '12 at 7:48
add comment

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