[texhax] \input{file} adds an extraneous space
Heiko Oberdiek
heiko.oberdiek at googlemail.com
Tue Jan 3 11:43:50 CET 2012
On Tue, Jan 03, 2012 at 01:53:57AM -0800, jtzzaa11-texhax2 at yahoo.com wrote:
> I've noticed that \input{file} adds an extraneous space, for example, if
> f.tex contains abc
>
> then
> \input{f}test
>
> produces
> abc test
>
> Here is a minimal example:
> \documentclass[10pt]{article}
> \begin{document}
> \input{f}test
> \end{document}
The space is correct.
If TeX reads a line, it removes the end line marker and spaces
at the end of the line. Then it inserts the character, configured
by \endlinechar. Usually it's <CR> (0x13) with catcode end of line (5)
that then becomes a space.
Rationale. Without space the previous paragraph would read like
The space is correct.If TeX ... and spacesat the end ... configuredby ...
> Would appreciate suggestions how to solve this.
If you don't want that space at the line end, one solution is
already shown. A comment char at the line end puts the
inserted end of line character in a comment:
abc%
But that means, the contents of the file needs to be modified.
Another way is to set
\endlinechar=-1
during the reading of the input file. Then the insertion of
the end of line chararacter is suppressed, e.g.:
\begingroup
\endlinechar=-1 %
\input{f}%
\endgroup
test
If the contents of the file should be put in a macro, then
package catchfile helps.
Yours sincerely
Heiko Oberdiek
More information about the texhax
mailing list