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'm trying to include a pdf in a document, using pdfpages package, but I'm having troubles when filename contains tilde or space.

e.g.

\includepdf[pages=-]{C:/Users/MYUSER~1/AppData/Local/Temp/mypdfpdf.pdf}

\includepdf[pages=-]{C:/Users/MYUSER FOO/AppData/Local/Temp/mypdfpdf.pdf}

I've tried to escape for example through $\sim$ but it doesn't work...

Is it possible to escape tilde/space in the filename ?

Thanks in advance

share|improve this question
4  
You can try \string~ for the tilde and enclosing the whole file name in a pair of double quotes " for the space. –  egreg Nov 15 '11 at 14:22
    
@egreg: this should be an answer! –  Herbert Nov 15 '11 at 15:16
    
@Herbert Martin's already covers it. –  egreg Nov 15 '11 at 15:20
    
See also David's answer on how to quote special characters in tex.stackexchange.com/a/53646/175 –  Charles Stewart Jun 28 '13 at 10:34

2 Answers 2

up vote 12 down vote accepted

About the tilde: Apparently the ~ is taken in its usually meaning, not as literal ~. I get a Package pdfpages Error: Cannot find file `test\nobreakspace {}it' error for a test~it file. Taking the filename verbatim should help. This can be done by \Verbdef from the newverbs package:

\usepackage{newverbs}

% ...

\Verbdef\filename{C:/Users/MYUSER~1/AppData/Local/Temp/mypdfpdf.pdf}
\includepdf[pages=-]{\filename}

It is also possible to write \string~ instead of ~ every time. You shouldn't use math symbols to "escape" these characters in filenames. Typesetting and file reading are two completely different things.

Finally you can use the e-TeX primitive \detokenize{...} to sanitize the file name:

\includepdf[pages=-]{\detokenize{C:/Users/MYUSER~1/AppData/Local/Temp/mypdfpdf.pdf}}

To allow spaces you need to wrap the filename in " ". At best you should avoid any spaces, tildes or any other special characters in filenames.

share|improve this answer
    
Actually it's generated through Sweave so I can't avoid tildes and spaces, but thanks this works fine ! :) –  digEmAll Nov 15 '11 at 15:36
2  
@Martin Scharrer - thanks for the \Verbdef tip. At my site I've got people who use two or more (!!!) blanks for directory names. FYI: two or more blanks in the directory name get shrunk down to one blank when using \detokenize with \includepdf. –  infowanna Mar 11 '13 at 13:59

Spaces at file names of PDF files at \includegraphics or \includepdf are allowed, if you are using package grffile:

\usepackage{grffile}
\usepakcage{pdfpages}
% …
\includepdf[pages=-]{test this.pdf}

And for more verbatim interpretation of the file name you may use \detokenize:

\usepackage{grffile}
\usepakcage{pdfpages}
% …
\includepdf[pages=-]{\detokenize{test~this.pdf}}
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.