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