How to trim the end of line character for each line read from an external \jobname.list file below? Note that the real scenario does not use filecontents package to generate the list. I use a batch file to prepare the list. The following MWE is just for the sake of simplicity.
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.list}
a.jpg
b.pdf
c.eps
d.png
\end{filecontents*}
\parindent=0pt
\usepackage{graphicx}
\newread\reader
\begin{document}
\makeatletter
\openin\reader=\jobname.list\relax
\advance\endlinechar \@M
\loop
\read\reader to \x
\unless\ifeof\reader
\includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{../../Images/\x}%
\repeat
\advance\endlinechar -\@M
\makeatother
\end{document}
The code above cannot be compiled because \includegraphics does not like the end of line charcter appended in the file path. I wasted much time to find the source of problem.
Edit:
If the image files a.jpg and b.pdf are put in ../../Images/ then the proposed solutions no longer work. How to solve it?
I mainly use xelatex to accommodate 4 image formats.
\begingroup\endlinechar=-1before\loopand\endgroupafter\repeat. Also put a space (or\par)after{\x}. – egreg Sep 25 '12 at 09:39