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. – David Carlisle Feb 3 '17 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 Feb 3 '17 at 8:49
  • @campa probably. But should have that anyway:-) – David Carlisle Feb 3 '17 at 8:52
  • I tend to use \path from the url package for this, in this case try \expandafter\path\expandafter{\jobname} – daleif Feb 3 '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 imgur.com/a/YKwLU - this is the result if my main file is called 'test_with_underscores.tex'. – T. Pluess Feb 6 '17 at 7:35

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 Feb 3 '17 at 21:19
  • Controlling? Or is controling American usage? (I don't want to change it if it is correct American.) – cfr Feb 4 '17 at 3:31
  • @cfr I'm not American, change whatever you want – daleif Feb 4 '17 at 6:56

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.