I am generating LaTeX code in an automated way and have run into a problem I'm not quite sure how to solve. The problem occurs when I am generating a clickable contents page using hyperlinks. File names must be given as clickable text in the contents, in the following manner:


The difficulty arises in coping with the special characters that can arise in filenames (and I do not have some defined filename format). I know that I could manually escape the underscore, but this isn't an option here because this code is to be generated automatically for many files.

My first attempt involved using verbatim in conjunction with cprotect, however I couldn't get this to work. My current attempt involves the use of url, in the following manner:


However, this is inelegant. Would anyone have some inventive solutions to this or some ideas I might try?

Many preemptive thanks for any assistance



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

The T1 font encoding allows for proper printing of the underscore _, while \detokenize removes the meaning of _ which denotes/switches to subscript notation.

The solution is similar to Escaping from the escaping hell.

  • 1
    Ah, this seems to work well. I thank you sincerely for your assistance! – d3pd Aug 2 '12 at 12:02

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.