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?

  • 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. Commented Feb 3, 2017 at 8:43
  • 2
    @DavidCarlisle I think "cannot be printed properly" means the strange overdots instead of the underscores. \usepackage[T1]{fontenc} might be enough.
    – campa
    Commented Feb 3, 2017 at 8:49
  • @campa probably. But should have that anyway:-) Commented Feb 3, 2017 at 8:52
  • I tend to use \path from the url package for this, in this case try \expandafter\path\expandafter{\jobname}
    – daleif
    Commented Feb 3, 2017 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 imgur.com/a/YKwLU - this is the result if my main file is called 'test_with_underscores.tex'.
    – T. Pluess
    Commented Feb 6, 2017 at 7:35

1 Answer 1


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


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

  • Controlong????????
    – user31729
    Commented Feb 3, 2017 at 21:19
  • Controlling? Or is controling American usage? (I don't want to change it if it is correct American.)
    – cfr
    Commented Feb 4, 2017 at 3:31
  • @cfr I'm not American, change whatever you want
    – daleif
    Commented Feb 4, 2017 at 6:56

You must log in to answer this question.

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