Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

> \temp=macro:
->test*1.txt.

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

\newwrite\tempwrite
\immediate\openout\tempwrite\temp\relax
\immediate\write\tempwrite{test}
\immediate\closeout\tempwrite
\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?)

share|improve this question
9  
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

1 Answer 1

up vote 8 down vote accepted

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

\edef\Jobname{\jobname}
\catcode`\*=\active
\def*{ }
\edef\Jobname{"\scantokens\expandafter{\Jobname\noexpand}"}
\catcode`\*=12 %
\show\Jobname

(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!)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.