1

I have a document where I would like to put the jobname into the footer with the \jobname macro. However, if my main file has underscores in its file name, the jobname cannot be printed properly due to the underscore. How can I tell LaTeX to automatically escape any special characters in the jobname?

T. Pluess
  • 1,040
  • 2
    The underscores in \jobname are not math subscript characters and should not give an error. If you are getting errors please show code that reproduces the problem. – David Carlisle Feb 03 '17 at 08:43
  • 2
    @DavidCarlisle I think "cannot be printed properly" means the strange overdots instead of the underscores. \usepackage[T1]{fontenc} might be enough. – campa Feb 03 '17 at 08:49
  • @campa probably. But should have that anyway:-) – David Carlisle Feb 03 '17 at 08:52
  • I tend to use \path from the url package for this, in this case try \expandafter\path\expandafter{\jobname} – daleif Feb 03 '17 at 12:34
  • unfortunately, the underscores are replaced with inverted commas. I think this is because the underscore in normal LaTeX mode means a special thing.See http://imgur.com/a/YKwLU - this is the result if my main file is called 'test_with_underscores.tex'. – T. Pluess Feb 06 '17 at 07:35

1 Answers1

4

I tend to use \path from the url package, though you need to expand \jobname first

\expandafter\path\expandafter{\jobname}

Controlling the font of \path (it is tt by default) can be done by making a custom \path command, see the source of url.sty

cfr
  • 198,882
daleif
  • 54,450