3

So I have a big number of figures with _ in their names. I want to include them in my document and I want to print the filename for the file. Something like:

\foreach \dataset in {CPD, EPAFHM, FDA, cas_N6512, cox2, dhfr, screen_U251} {
    \foreach \height in {0,1,2,3,4,5} {
            \begin{minipage}{0.5\textwidth}
            \includegraphics[width=0.45\textwidth]{heatmaps/\dataset\height Bit.pdf}
            AUC for bit fingerprint of height \height for dataset \dataset.
            \end{minipage}
    }
}

It works great for the graphics but of course the _ should really be \_ when it comes to printing. How can I fix this? I have looked at this question but it does not seem to be quite the same thing.

Also, if I try the underscore package it works for the text but not for the graphics.

jonalv
  • 11,466

2 Answers2

6

Under the T1 font encoding, \detokenize will allow you to print the underscore:

enter image description here

\documentclass{article}
\usepackage[T1]{fontenc}% http://ctan.org/pkg/fontenc
\def\dataset{xyz_123}
\begin{document}
\detokenize{abc_123} \expandafter\detokenize\expandafter{\dataset}
\end{document}
Werner
  • 603,163
3

The graphics package itself when printing filenames with the info option uses

       \edef\@tempa{#3}%
       \rlap{ \ttfamily\expandafter\strip@prefix\meaning\@tempa}%

so you could do

\makeatletter
\def\showfilename#1{%
  \edef\@tempa{#1}%
   \texttt{\expandafter\strip@prefix\meaning\@tempa}}%
\makeatother

use as \showfilename{\dataset}

David Carlisle
  • 757,742