I am in an mildly unfortunate situation in which, because of the way I prepared the files automatically, I ended up with a file to be attached but also another file with the same name but ending in the .tex extension. It seems that when referring to a file inside TeX the file with the extension .tex is always preferred. For example:

If I have the files example.cpp.tex and example.cpp (no .tex extension), then with

The TeXboot mentions: In most installations of TeX, the extension .tex will be appended to the file name, as with \input, if no extension is given explicitly. But this shouldn't affect file names with extensions…
– Andrey VihrovAug 3 '11 at 6:38

4

I would recommend something like [untested] rename 's/\.cpp\.tex/-cpp.tex/' in a unix terminal. Much better than trying to fix this through tex
– SeamusAug 3 '11 at 10:13

1

@Andrey: thanks for pointing that out. I would say that it makes some sense for "\input". But for attachfile? what for, why would it add the .tex extension?
– alfCAug 3 '11 at 18:53

2 Answers
2

How TeX handles files with unusual numbers of dots (where "unusual" is any number unequal to 1) is quite inpredictable and also has changed over time. In miktex 2.4 e.g. \input{file.cfg} would have tried at first file.cfg then file.cfg.tex, in miktex 2.5 it tried only file.cfg, in the current 2.9 it tries at first file.cfg.tex and then file.cfg.

The only advice I can give: Avoid in TeX multiple dots like the plague.

I agree, however the real issue IMHO are not the multiple dots but having a file foo.bar and also foo.bar.tex. This constellation should really be avoided. For me TeX Live 2011 always takes foo.bar.tex before foo.bar, even with the low level \@@input primitive.
– Martin Scharrer♦Aug 3 '11 at 7:56

2

The ambiguity between foo.bar and foo.bar.tex only exists because of the multiple dots in one of the file names. If all your files use only one dot the problem can't happen.
– Ulrike FischerAug 3 '11 at 8:42

@ulrike's comment: between foo and foo.tex will also prefer foo.tex with \attachfile{foo}, so the double extension is not the problem.
– alfCAug 3 '11 at 18:47

I've had some luck with appending a . for example I have a file called readme.tex that inputs a file called readme using the input command \input{readme.} (Note the dot). This works in MikTeX 2.9 on Windows 10, I can't vouch for other flavours/distributions though. I think it stems from the need to append a dot when creating .extention files e.g. one must name the file .extention. for it to be called .extention, windows strips the dot.
– CarelJul 22 '16 at 18:29

If these files are generated automatically, then I recommend some regex-fu to disambiguate the files. Obviously, depending on exactly what the automatic naming scheme for the files is, you may need to change the pattern, but this should be pretty general.

rename 's/\.tex/-tex.tex/' *.tex

What this will do is rename each example.tex file to example-tex.tex. Now doing \input{example} will input example, not example-tex.tex.

OK. So this is a little ugly, but it works. If the files are actually like example.cpp.tex then the less ugly renaming would be:

rename 's/\.cpp\.tex/-cpp.tex/' *.tex

This requires a unix-like terminal or something like cygwin. Hints in comments for a native windows equivalent regex batch file renamer appreciated.

thanks, but the filenames are really automatic I didn't want to change that just because some avoidable issue in LaTeX. I was looking for a latex answer to a latex problem. thanks anyway.
– alfCAug 3 '11 at 18:51

@alfC but if they're automatically generated, why not just generate them with different names? Or rename them in a predictable way? And given that the issue doesn't seem to be avoidable (see the accepted answer) then what other option do you have?
– SeamusAug 4 '11 at 10:47

in the light of these answers... it seems that none other unfortunately. +1
– alfCAug 5 '11 at 6:02