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.

for my project to bring scripting to (Xe)(La)TeX, i need to execute command lines with write18, redirect output to a temporary file, and then insert the produced text using input. i've noticed some extraneous whitespace that occurs right after each output, and i managed to hunt down one source down to the most basic part of the equation (i'm observing three different amounts of whitespace; the one discussed here is the smallest amount, so it would appear there is more than a single source for that phenomenon).

here is a 'sub-minimal' MWE:

xxxx xxx

assuming that the contents of said file consists of a single x (which i can easily prove by running cat /tmp/out.txt:

$ cat /tmp/out.txt
x$ ▌

see how the x is directly followed by the command line prompt), i still get, in the resulting pdf file, a space after the fourth x in the second line. the second line is matching perfectly with the third line, which does contain a deliberate space; it should for all intents and purposes match with the first line, of course.

this looks as if—contrary to the descriptions i've read—\input actually inserts the file contents plus (at least) a single (?) \x20 character into the document.

can this observation be corroborated? and, importantly: how do i get rid of that extraneous space?

share|improve this question
Try xxx\input{/tmp/out.txt}\ignorespaces xxx –  Sigur Jan 26 at 17:26
add comment

2 Answers

up vote 8 down vote accepted

that is correct, your external file has one line and the lineend is replaced by a space.

Use \input{/tmp/out.txt}\unskip or insert a % at the end of the x in the external file: x%

share|improve this answer
thx a lot! that was real fast! –  flow Jan 26 at 18:01
add comment

If the files you input in that way have a single line, then you can define

  \begingroup\endlinechar=-1 \input{#1}\endgroup

which would remove the trailing end of line. Then


will not have the problem.

share|improve this answer
add comment

Your Answer


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.