I'm working on a lightweight package that allows you to put any content (typically LaTeX code) in an environment, then use that content multiple times, each time scanned separately, so you can use it both as verbatim output and interpreted as LaTeX.
Its main purpose is to typeset LaTeX code and its 'result' side-by-side; useful for documenting TeX packages without having to copy/paste code. But it has other purposes as well.
After experimenting with
\scantokens until I gave up in tears, I arrived at the
filecontents environment, which almost solved my problem singlehandedly!
The problem is, when reintroducing
filecontented code through
\input, LaTeX adds an implicit newline at the end, which translates to whitespace that I can't seem to get rid of.
I've seen many semi-related questions floating around, with answers employing techniques like:
- reading a file line-by-line,
\everyeofin some clever way,
- playing with
- using packages such as
but none of them provides a clear answer to the following question:
How can I
\input a file without getting the implicit newline?
Minimal Working Example
Note the extra whitespace to the right of the box.
Note also that I'm definitely not adding any explicit whitespace. Even a manually produced file (so, not using
filecontents) with no newlines at all exhibits the same problem.