2

I have EPS image files (with spaces in their names) in a directory ../../Images space bla bla bla/. The following MWE simulates the real scenario in a simplified way.

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents*}{\jobname.list}
a space.eps
b space.png
\end{filecontents*}
\usepackage{grffile}

\parindent=0pt
\usepackage{graphicx}
\newread\reader

\begin{document}
\def\stripend#1 \stop{\unexpanded{#1}}
\openin\reader=\jobname.list\relax
\loop
    \read\reader to \x
    \unless\ifeof\reader
    \section{\x}
    \edef\x{%
      \unexpanded{%
        \includegraphics[width=\textwidth,height=\textheight,keepaspectratio]%
       }%
       {../../Images space bla bla bla/\expandafter\stripend\x \stop}%
     }%
     \x
\repeat
\closein\reader
\end{document}

Because I want to import all image formats and manipulate them with PSTricks, I have to use latex-dvips-ps2pdf sequence. xelatex is not my option because it runs much slower. Shortly speaking, the compilation fails. How to solve it?

Note that the available questions and the corresponding answers in this site do not help. I have read all, none works.

  • It works as is with pdflatex (if you replace .eps by an extension pdflatex knows so I think it's probably the graphicx xelatex driver that needs to use the web2c convention of using " to quote filenames more completely. – David Carlisle Sep 27 '12 at 09:20
  • @DavidCarlisle: Have you succeeded to compile it with quotes with xetex? – kiss my armpit Sep 27 '12 at 09:26
  • No and can't delve in that far at work, left comment as a hint of someone else looking at this.. – David Carlisle Sep 27 '12 at 10:01
  • 1
    My expl3 solution to http://tex.stackexchange.com/questions/74008/how-to-trim-the-end-of-line-character-for-each-line-read-from-an-external-file works, provided you load also the grffile package. I suspect that also your current code will work with that package. – egreg Sep 27 '12 at 10:20
  • @egreg: your comment works but now i change to latex-dvips-ps2pdf. – kiss my armpit Sep 29 '12 at 17:16
  • @ガベージコレクタ Are you sure that dvips accepts file names with spaces? I'm not. – egreg Sep 29 '12 at 17:41
  • @egreg: I don't know anything about the internal. :-) – kiss my armpit Sep 29 '12 at 17:44
  • @ガベージコレクタ If I try including a file with spaces in the name between quotes it's accepted by LaTeX, but causes errors to dvips. Don't use spaces for any reason. – egreg Sep 29 '12 at 17:49

1 Answers1

4

The \special for dvips' EPS file support already uses quotes, e.g.:

PSfile="a b c/d e f.eps" llx=0 lly=0 urx=24 ury=24 rwi=240

However, the graphics package has to do much more:

  • File exists?
  • Without extension? Try out the extensions, given in the extension list.
  • Searching via \graphicspath.
  • Driver specific: \Gread@eps reads the PostScript file to find the bounding box.

Package grffile deals with the first three items, if option space is given. The last item needs patching (at least until I might update grffile):

\documentclass{article}
\usepackage{graphicx}

\usepackage[space]{grffile}
\usepackage{etoolbox}
\makeatletter
\patchcmd\Gread@eps{\@inputcheck#1 }{\@inputcheck"#1"\relax}{}{}
\makeatother

\begin{document}
\includegraphics{a b c/d e f.eps}
\includegraphics{a b c/d e f}
\graphicspath{{a b c/}}
\includegraphics{d e f.eps}
\includegraphics{d e f}
\end{document}
Heiko Oberdiek
  • 271,626