Tell me more ×
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:
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.

share|improve this question
@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
show 5 more comments

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

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.

1 Answer

up vote 2 down vote accepted

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}
share|improve this answer

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