# How to prevent \endlinechar=-1 from interfering a loaded EPS image?

I have to work in a block that begins with \endlinechar=-1\relax removing any space at the end of each line. After the \endlinechar=-1\relax, there will be codes related to loading an image (EPS,PNG,JPG,PDF) and drawing geometric objects (by PSTricks).

Unfortunately \endlinechar=-1\relax disrupts the structure of the loaded EPS image as follows.

% Trash.tex
\documentclass{standalone}

\usepackage{graphicx}

\begin{document}
\endlinechar=-1\relax
% other settings go here
% ...
\includegraphics{Image.eps}% extension is explicitly specified to emphasize that it is an EPS image!
% other codes go here
% ...
\end{document}


How to prevent \endlinechar=-1\relax from interfering the loaded EPS image?

As the error message shows the error occurs in the \Gread@eps macro (which is part of the DVI/PS output driver and is of course EPS specific, which explains why PDF or JPG files are not affected). The code there wants to change the catcode of the end-of-line characters to 5 (RETURN, i.e. the normal value) but doesn't change the \endlinechar itself. Here it is -1 which isn't a valid input for \catcode<char number>=<catcode>. IMHO this is actually a bug in that code.
You need to either change the \endlinechar back to its normal value (13) around the \includegraphics, patch some internal macros of graphics/x to do that automatically or don't change the value of \endlinechar at all. In the latter case you could use \catcode\endlinechar=9\relax to make TeX ignore endline characters, instead of not inserting them as before with \endlinechar=-1\relax. It should lead to the same result in the document but will work with the \Gread@eps macro.
Question 1: Is it OK if I use \catcode\endlinechar=9\relax instead of \endlinechar=-1\relax for all cases (whether or not I import PDF,EPS,JPG,PNG images followed by PSTricks, equation, etc)? Question 2: Why is there \catcode in \catcode\endlinechar=9\relax while no \catcode in the previous \endlinechar=-1\relax? Is \catcode mandatory? –  xport Aug 3 '11 at 14:02
A1: Yes, it should be OK. A2: \endlinechar is an integer register which holds the ASCII number of the character which should be used for end-of-line characters (independent of their real ASCII code in the file). When you say \endlinechar=-1\relax then you assign -1 to \endlinechar. You can use this also in any place where you can use a number. So \catcode\endlinechar=9\relax says: Change the catcode of the character with the number currently stored in \endlinechar to 9 (ignore). You don't change the \endlinechar itself just its catcode. –  Martin Scharrer Aug 3 '11 at 14:07