# File name with underscore as figure caption [duplicate]

Possible Duplicate:
Escaping from the escaping hell

I did scour the internet for solution but I found no satisfactory answer for this problem.

I have a bash script that searches my folder for .pdf images and creates a latex file with several includegraphics commands with the file names as the figure caption.

However, my file names have underscores and this is unavoidable. When I run pdflatex on the below latex file, I do get a pdf file with all my figures as required but the captions are all italicized or subscripted.

Any ideas on how I might avoid this (how should I allow underscores in figure captions?):

## Latex file:

\documentclass[a4paper,10pt]{article}
\usepackage{setspace}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{eps2pdf}
\usepackage{subfigure}
\usepackage{float}
\usepackage[super,numbers,sort&compress]{natbib}
\usepackage{color}
\usepackage{grrfile}
\newcommand{\hilight}[1]{\colorbox{yellow}{#1}}
\renewcommand{\thefootnote}{\alph{footnote}}

% \usepackage[dvips]{hyperref}

\date{07/31/12}

\begin{document}

\clearpage

\begin{figure}[h]
\begin{center}
\centering
\includegraphics[scale=0.75]{/home/dnaneet/Research/Dissertation/APS2012/G=0.0/L_2lambda_max_1wl_zg_2m.pdf}
\caption{L_2lambda_max_1wl_zg_2m.pdf}
\label{fig:fig1}
\end{center}
\end{figure}
\end{document}


Edit:

Using the underscore package helped only partially:

• The caption is fine now and the file name is displayed.

• Since the file name has underscore, that messed up the path and hence the figures aren't displayed anymore.

-
 @GonzaloMedina Right, but the underscore package only "_ in text mode (i.e., \textunderscore) prints an underscore"... – drN Jul 31 '12 at 18:31 @GonzaloMedina I loaded the underscore package. No change in the situaiton. In fact it is worse as the figures are no longer displayed in the eventual pdf file. – drN Jul 31 '12 at 18:33 @DavidCarlisle Not really. Not a duplicate. – drN Jul 31 '12 at 18:34 @DNA Ah, I didn't saw the path also contained underscores; I'll delete my comments. – Gonzalo Medina Jul 31 '12 at 18:35 @GonzaloMedina Your comment was useful! :) however, like you noticed , the path is screwed up now! :P – drN Jul 31 '12 at 18:37

## marked as duplicate by David Carlisle, Marco Daniel, percusse, Claudio Fiandrino, Paul GaboritSep 15 '12 at 21:46

Using \detokenize{L_2lambda_max_1wl_zg_2m.pdf} removes the math interpretation of _ and adding \usepackage[T1]{fontenc} allows for the correct printing of _ inside the caption. For completeness, the following setup should work:

\usepackage[T1]{fontenc}% http://ctan.org/pkg/fontenc
%...

\begin{figure}[h]
\begin{center}
\centering
\includegraphics[scale=0.75]{/home/dnaneet/Research/Dissertation/APS2012/G=0.0/L_2lambda_max_1wl_zg_2m.pdf}
\caption{\detokenize{L_2lambda_max_1wl_zg_2m.pdf} }
\label{fig:fig1}
\end{center}
\end{figure}
\end{document}

-