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 using Windows. The objective is to import all images in a sub directory. I divide into 2 categories, for PNG and EPS, separately as follows.

For PNG

This category works without problem. So you can skip it.

\documentclass{article}

{
    \catcode`\^0
    \catcode`\\12
    ^gdef^dirsep{\}
}

\usepackage[a6paper,margin=15mm]{geometry}
\usepackage{graphicx}
\edef\subdir{Sub Dir\dirsep}

\graphicspath{{"\subdir"}}

\immediate\write18{cmd /c dir /b "\subdir*.png" > imagelist.txt}


\begin{document}
\makeatletter
\newread\reader
\openin\reader=imagelist.txt\relax
\begingroup
\endlinechar=-1\relax
\loop
    \readline\reader to \data
    \unless\ifeof\reader
            \filename@parse{\data}\noindent  
            \includegraphics[scale=.5,ext=.\filename@ext,width=\textwidth,height=\textheight,keepaspectratio]{"\filename@base"}\newpage
\repeat
\endgroup
\closein\reader
\makeatother
\end{document}

For EPS

\documentclass{article}

{
    \catcode`\^0
    \catcode`\\12
    ^gdef^dirsep{\}
}

\usepackage[a6paper,margin=15mm]{geometry}

\usepackage{graphicx}
\edef\subdir{Sub Dir} % must be no double quotes used

\graphicspath{{\subdir/}}

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

\immediate\write18{cmd /c dir /b "\subdir\dirsep*.eps" > imagelist.txt}


\begin{document}
\makeatletter
\newread\reader
\openin\reader=imagelist.txt\relax
\begingroup
\endlinechar=-1\relax
\loop
    \readline\reader to \data
    \unless\ifeof\reader
            \filename@parse{\data}\noindent  
            \includegraphics[scale=.5,ext=.\filename@ext,width=\textwidth,height=\textheight,keepaspectratio]{\filename@base}\newpage% must be no double quotes used.
\repeat
\endgroup
\closein\reader
\makeatother
\end{document}

The compilation fails with some errors as follows.

This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013/W32TeX)
 restricted \write18 enabled.
entering extended mode
(./for eps.tex
LaTeX2e <2011/06/27>
Babel <3.9g> and hyphenation patterns for 78 languages loaded.
(c:/texlive/2013/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(c:/texlive/2013/texmf-dist/tex/latex/base/size10.clo))
(c:/texlive/2013/texmf-dist/tex/latex/geometry/geometry.sty
(c:/texlive/2013/texmf-dist/tex/latex/graphics/keyval.sty)
(c:/texlive/2013/texmf-dist/tex/generic/oberdiek/ifpdf.sty)
(c:/texlive/2013/texmf-dist/tex/generic/oberdiek/ifvtex.sty)
(c:/texlive/2013/texmf-dist/tex/generic/ifxetex/ifxetex.sty))
(c:/texlive/2013/texmf-dist/tex/latex/graphics/graphicx.sty
(c:/texlive/2013/texmf-dist/tex/latex/graphics/graphics.sty
(c:/texlive/2013/texmf-dist/tex/latex/graphics/trig.sty)
(c:/texlive/2013/texmf-dist/tex/latex/latexconfig/graphics.cfg)
(c:/texlive/2013/texmf-dist/tex/latex/graphics/dvips.def)))
(c:/texlive/2013/texmf-dist/tex/latex/oberdiek/grffile.sty
(c:/texlive/2013/texmf-dist/tex/latex/oberdiek/kvoptions.sty
(c:/texlive/2013/texmf-dist/tex/generic/oberdiek/ltxcmds.sty)
(c:/texlive/2013/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty
(c:/texlive/2013/texmf-dist/tex/generic/oberdiek/infwarerr.sty)
(c:/texlive/2013/texmf-dist/tex/generic/oberdiek/etexcmds.sty
(c:/texlive/2013/texmf-dist/tex/generic/oberdiek/ifluatex.sty))))
(c:/texlive/2013/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty))
(c:/texlive/2013/texmf-dist/tex/latex/etoolbox/etoolbox.sty
(c:/texlive/2013/texmf-dist/tex/latex/etex-pkg/etex.sty))
No file "for eps".aux.
*geometry* driver: auto-detecting
*geometry* detected driver: dvips
! Bad character code (-1).
\Gread@eps ...catcode `\    10 \catcode \endlinechar 
                                                  5 \@makeother \:\@makeothe...
l.36 \repeat

? 

Downloadable complete MWE

The complete code with dummy images in both PNG and EPS format can be downloaded here.

share|improve this question
    
are you stuck with windows due to the organisation, may be you should try Linux dual boot with permission from them or at home to solve some your Q since latex and linux go well each together :) –  texenthusiast Dec 4 '13 at 6:13
    
@texenthusiast: Wasting time to learn linux for the current situation. –  stalking is prohibited Dec 4 '13 at 6:27
13  
Imho it is a complete waste of time. Why don't you simply give your subdirectory a sensible name without a space? This takes 10 seconds and will avoid a lot of troubles in the future. Beside this: dvips.def uses quotes too: \special{PSfile="#1" ... Perhaps your problem is there. –  Ulrike Fischer Dec 4 '13 at 8:58
    
I agree with Ulrike Fischer. Is it mandatory for you to vave blanks in the folder name? Moreover, some packages as pdfpages simply does not suuport blank in filenames (cf. p.2 of the documentation). –  Clément Dec 11 '13 at 14:40

1 Answer 1

As the error message shows the file is trying to do

\catcode \endlinechar 5

to normalize end of line handling while looking in an EPS file for BoundIngBox comments

It (I) wasn't expecting you to have done

 \endlinechar=-1\relax

so this ends up trying to set the catcode of character -1 which produces the error you show.

I assume you can do

            {\endlinechar=13
            \includegraphics[scale=.5,ext=.\filename@ext,width=\textwidth,height=\textheight,keepaspectratio]{\filename@base}}

so that the endlinechar is back to normal while reading the EPS file.

Arguably it's a bug^H^H^Hfeature (or at least a lack of defensive coding) in graphics.sty and that line 260 of graphics.sty should say

\ifnum\endlinechar>\z@\catcode\endlinechar5 \fi

rather than

\catcode\endlinechar5 %
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.