I have many special characters in a filename e.g., ./CaMKII-8+PP1-32+L-125e-9+N-5+diff-0.1e-12.dat_processed.csv. I want to write this filename in a footnote. To make matter worse, this filename is stored in a macro e.g., \edef\fiename\{./CaMKII-8+PP1-32+L-125e-9+N-5+diff-0.1e-12.dat_processed.csv}.

When I try to print it using \texttt{\fileName}, I run into a 'missing $ inserted' issue. If I use \verb!\fileName!, it just prints \fileName (it's not expanded.)

How to get the filename printed in my pdf?

  • 4
    – egreg
    Commented May 16, 2017 at 13:46
  • @egreg Worked like a charm. I think you can add it as an answer. It was not easy to find.
    – Dilawar
    Commented May 16, 2017 at 13:51
  • You can also use the \path command supplied by the url package. Commented May 16, 2017 at 13:54

1 Answer 1


If the file name is stored in a macro, you can exploit \detokenize:

\newcommand{\fileName}{}% just to see it can be used

This will have no consequence when \fileName is used for reading a file.

Note that you need \usepackage[T1]{fontenc} for the underscore to print when not in a \ttfamily or \texttt context. It will print fine with \texttt{\fileName}.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .