# pdflatex long file name error: I can't find file

I was compiling some certificates with automatically generated file names using pdflatex on a Linux machine. It worked well until I got this name: "[Nicola Scott] [Induction Module 2 _New_ - Safeguarding and Medication] [12_04_2016].tex".

pdflatex gives an error: "I can't find file <file name>". Tried the same name on Windows with MikTex: the same error.

Shortening the file name helped. What are the rules for the file name to avoid the error?

• It depends. To be safe and since you've not given any indication whatsoever of your code so we don't know how you are using the file names: avoid any strange characters. Strange characters include brackets of all descriptions, spaces, possibly underscores, non-ASCII characters, punctuation marks (hyphens are safe, a dot precedes the file extension). If you stick to English alphabet letters, Arabic numerals and hyphens, excepting the dot preceding the extension, you should be reasonably safe. – cfr Apr 30 '16 at 1:37
• A piece of advice: you're using Linux? Great. Install detox and run all files through that. It will zap through directories of dubious file names in no time. The results will sometimes be awkward-looking, but they will be safe. Can be customised as required. – cfr Apr 30 '16 at 1:39
• @cfr The source course is just an empty LaTeX document. The problem is the file name. – user4035 Apr 30 '16 at 7:58
• @cfr It compiled other files with square brackes, so I suspect that the cause is the length of the name and not the characters. – user4035 Apr 30 '16 at 8:00
• That's why I said we needed to know how the name is being used. Depending on how you are doing it, various things may be allowed, even though it would be better to detoxify the names on grounds of general safety. I explicitly stated that my comment was erred on the side of caution in the absence of any meaningful information. – cfr Apr 30 '16 at 21:29

Seems, that pdflatex doesn't accept files that have 2 adjacent spaces. To reproduce the problem create a file: a a.tex. Then:

\$ pdflatex ./a\ \ a.tex

This is pdfTeX, Version 3.14159265-2.6-1.40.16 (MiKTeX 2.9)
entering extended mode
! I can't find file "./a a.tex"'.


For some reason it converted 2 spaces in the file name into 1 space.

• The problem is the category code of the space. Thus TeX ignores the further tokens, if it finds consecutive spaces in the input line. Thus tricks are needed to get it work for TeX and the command line. Example for bash and the file foo⌴⌴bar.tex: pdflatex⌴'\def\x#1{\input{"foo#1#1bar"}}\x{⌴}' (The symbol ⌴` visualizes the space.) – Heiko Oberdiek Apr 30 '16 at 11:21
• BTW, well spotted the cause with the two spaces. – Heiko Oberdiek Apr 30 '16 at 11:24