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.

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

\documentclass{article}
\usepackage{attachfile}
\begin{document}
\textattachfile{example.cpp}{link}
\end{document}

attachfile will attach example.cpp.tex instead of example.cpp. This seems to be also true for many LaTeX commands, such as \input, \include, embedfile etc.

How can I enforce to use the file specified and not the .tex terminated one in general or in particular for \attachfile?

(Note: the problem is not the double extension; the unexpected result will also happen with the files example and example.tex.)

share|improve this question
4  
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 Vihrov Aug 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 –  Seamus Aug 3 '11 at 10:13
    
@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? –  alfC Aug 3 '11 at 18:53
add comment

2 Answers 2

up vote 11 down vote accepted

There is as far as I know no way to get around the problem.

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.

share|improve this answer
2  
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 Fischer Aug 3 '11 at 8:42
    
I see, thanks for clarifying this again. –  Martin Scharrer Aug 3 '11 at 9:05
    
@ulrike's comment: between foo and foo.tex will also prefer foo.tex with \attachfile{foo}, so the double extension is not the problem. –  alfC Aug 3 '11 at 18:47
add comment

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.

share|improve this answer
    
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. –  alfC Aug 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? –  Seamus Aug 4 '11 at 10:47
    
in the light of these answers... it seems that none other unfortunately. +1 –  alfC Aug 5 '11 at 6:02
add comment

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.