Changes

Jump to navigation Jump to search
1,453 bytes added ,  08:10, 9 March 2006
New page.
< [[TeX and pdfeTeX]] >

Including the contents of another file with TeX is done with
<code>\input</code>. But you have to be careful: TeX appends a character
with the current value of <code>\endlinechar</code> to each line of an
inputed file, and that character is later converted to a space. That means,
that the following 2 examples give the same results:

<texcode>
\starttext
\immediate\write18{echo -n X >temp.tex}
X\input temp X
\stoptext
</texcode>

<texcode>
\starttext
\immediate\write18{echo X >temp.tex}
X\input temp X
\stoptext
</texcode>

There are at least 5 solutions, to get rid of the space before the last X:

* Setting <code>\endlinechar</code> to -1 temporarily:
<texcode>
\immediate\write18{echo X >temp.tex}
X{\endlinechar=-1 \input temp }X
</texcode>

* Writing a percent sign to the end of the line:
<texcode>
\immediate\write18{echo X\letterpercent >temp.tex}
X\input temp X
</texcode>

* Ending the written line with <code>\relax</code> (or a similar space-gobbling command):
<texcode>
\immediate\write18
{echo X\letterbackslash\letterbackslash relax >temp.tex}
X\input temp X
</texcode>

* Changing the catcode of the current <code>\endlinechar</code> to 9 (ignored) also works:
<texcode>
\immediate\write18{echo X >temp.tex}
X{\catcode`\^^M=9 \input temp }X
</texcode>

* Ignoring and removing the space:
<texcode>
\immediate\write18{echo X >temp.tex}
X\ignorespaces \input temp\relax \removeunwantedspaces X
</texcode>
148

edits

Navigation menu