[texhax] \input adds an extra space if the included file contains a command?

Heiko Oberdiek heiko.oberdiek at googlemail.com
Thu Oct 7 09:36:10 CEST 2010

On Thu, Oct 07, 2010 at 01:28:20AM +0200, Aleksandar Zec wrote:

> 2010/10/7 Kevin Godby <godbyk at gmail.com>:
> > Hello, Aleksandar.
> >
> > On Wed, Oct 6, 2010 at 6:02 PM, Aleksandar Zec <zealeksanman at gmail.com> wrote:
> >> ----- i.tex -----
> >> \text{test}% <-- add a percent sign to suppress the space
> >> -----------------
> >
> > Put a % after the \text{test} command.  This will suppress the space
> > inserted by the new-line character.
> Thank you, Kevin (and all that replied off-list), this works! However,
> I still don't understand because there is no newline in the file. Try
> echo -n "test" > i.tex
> i.e. no newline; the extra space is still there.

If TeX reads a line it first strips <CR> and <LF> from the end
(also spaces are removed at the end of line). Then TeX inserts
the character denoted by \endlinechar at the end of the line.
Usually \endlinechar is 13, that means that <CR> or ^^M is inserted.
In LaTeX and plain TeX that character has catcode 5 (end of line)
that behaves like a space in most circumstances.

The addition of the end of line character does not depend on
the original line ending. With \endlinechar=-1 the addition
of the end line character is suppressed. The percent sign
above puts the end of line character in a comment.

BTW, this line reading behaviour is the main reason, why TeX
cannot be used for reading binary files.

Yours sincerely
  Heiko Oberdiek

More information about the texhax mailing list