When I LaTeX a file named test 1.tex with the code \edef\temp{\jobname.txt}\show\temp, I get

> \temp=macro:

This seems to work fine with LaTeX's internal commands, but if I then mix this with \write18, it fails.
For example, something like

\immediate\write18{rm "\temp"}

How can I get a version of \jobname that actually uses spaces instead of the asterisks? (Can I do something fancy with catcodes to make \write18 transform asterisks into spaces?)

  • 12
    Easy solution: Do not use spaces in filenames with (La)TeX! Never! – Martin Scharrer Apr 4 '11 at 23:25
  • Which LaTeX distribution in which version and which executable are you using on which OS? It works fine for me (no *s) with pdfTeX, Version 3.1415926-1.40.11 (TeX Live 2010) under Ubuntu Linux. A minimal example that causes the *s to appear would be helpful. – Martin Scharrer Apr 4 '11 at 23:32
  • 3
    Perhaps the * has catcode 10?? Try \edef\temp{\jobname}\def\showr#1{\show#1\showr}\expandafter\showr\temp{.\show}. – Bruno Le Floch Apr 5 '11 at 18:08
  • I was using MiKTeX 2.9 under Windows 7. My laptop recently died, so I'll give the results of \edef\temp{\jobname}\def\showr#1{\show#1\showr}\expandafter\showr\temp{.\show} the next time I have access to a windows machine with LaTeX. – Jason Gross Apr 6 '11 at 9:46
  • Using pdfTeX, Version 3.1415926-1.40.11 (MiKTeX 2.9) on windows 7, the \showr sequence just shows me the name of the file, with *s instead of spaces (it doesn't say, e.g., "the letter a"). I tried echo "\edef\temp{\jobname}\def\showr#1{\message{\detokenize{#1}}\showthe\catcode`#1\showr}\expandafter\showr\temp{.\show}" > "temp a1a_.tex" && latex "temp a1a_.tex" and it gave me the characters temp*a1a_ with catcodes 11,11,11,11,12,11,12,11,8. – Jason Gross Apr 8 '11 at 21:44

This behaviour is MiKTeX-specific: TeX Live on Windows behaves in the same way as on other platforms, and quotes the file name.

What you can do is convert the * characters into spaces. Something like

\def*{ }
\catcode`\*=12 %

(using e-TeX) will do the task cleanly. Of course, that will only work if there are no * characters in the file name. (There should not be, but it is possible to end up with this type of awkward file name!)

  • One could use a classical TeX loop to remove the * here: I've simply taken a 'short cut' as one is available! – Joseph Wright Feb 5 '15 at 20:27
  • MiKTeX has recently been updated to follow the TeX Live approach on this: names with spaces are now quoted rather than using * chars. – Joseph Wright Mar 1 '15 at 14:17

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.