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 seems that there is more than a single source for that phenomenon).
here is a 'sub-minimal' MWE:
xxxxxxx\\
xxx\input{/tmp/out.txt}xxx\\
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 a space after the fourth x
in the second line of the resulting pdf file. 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 — the command \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?
Best Answer
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%