2

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
    \edef\fileName{\detokenize{./CaMKII-8+PP1-32+L-125e-9+N-5+diff-0.1e-12.dat_processed.csv}} – egreg May 16 '17 at 13:46
  • @egreg Worked like a charm. I think you can add it as an answer. It was not easy to find. – Dilawar May 16 '17 at 13:51
  • You can also use the \path command supplied by the url package. – Herb Schulz May 16 '17 at 13:54
5

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

\newcommand{\fileName}{}% just to see it can be used
\edef\fileName{\detokenize{./CaMKII-8+PP1-32+L-125e-9+N-5+di‌​ff-0.1e-12.dat_proce‌​ssed.csv}}

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}.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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