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 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?

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

2 Answers 2

up vote 9 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

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

\newcommand{\lineinput}[1]{%
  \begingroup\endlinechar=-1 \input{#1}\endgroup
}

which would remove the trailing end of line. Then

xxx\lineinput{/tmp/out.txt}xxx

will not have the problem.

share|improve this answer

Your Answer

 
discard

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.