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.

I have a system of where a .tex is generated from a program. The final .tex file has a (simplified) structure like this:

\newcommand{\PlotFrame}[1]{%
\begin{frame}
\frametitle{...}
...
...
\includegraphics{#1}
\end{frame}}



\PlotFrame{File_1.png}
\PlotFrame{File_2.png}
...
\PlotFrame{File_n.png}

Now - when compiling this with pdflatex it complains at \PlotFrame{File_n.png} statements; because of the underscore. Unfortunately I do not have control over the filenames. Any suggestions of how I could keep the current structure with the \PlotFrame{} command - and let it accept arguments with underscore?

I would strongly prefer not having to escape it with \_.

share|improve this question
1  
Welcome to TeX.sx! You don't have to sign with your name since it automatically appears in the lower right corner of your post. –  Werner Aug 28 '12 at 14:07
1  
For me, underscores in filenames work without problems. Can you post a Minimal Working Example? –  Sašo Živanović Aug 28 '12 at 14:28
    
In a minimal example with your code I get the image even if the name contains an underscore. Please, add a real example of something that causes the error. It probably has to do with printing the file name, rather than including the file. –  egreg Aug 28 '12 at 15:16
    
Ahhh - this was embarassing; it turns out the problem was not with filename as such - but the figure caption which basically said: \caption{File: #1} –  Joakim Hove Aug 28 '12 at 15:23
add comment

1 Answer 1

up vote 4 down vote accepted

You can define an additional macro like this:

\documentclass{article}

\usepackage{graphicx}

\newcommand{\PlotFrameB}[1]{%
\includegraphics{#1}\endgroup}

\def\PlotFrame{\begingroup 
\catcode`\_=12
\PlotFrameB}

\begin{document}


\PlotFrame{File_1.png}
\PlotFrame{File_2.png}
...
\PlotFrame{File_n.png}

\[ a_b \]

\end{document}

This will temporarily change the catcode for _ in the argument.

share|improve this answer
    
The solution based on \catcode worked - thanks a lot! –  Joakim Hove Aug 28 '12 at 15:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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