I'm trying to copy a (binary) file with LaTeX (mostly for the sake of it), but when I read a line, the trailing spaces are removed.
The MWE, based on this TeX.SX answer:
\edef\infile{infile}
\edef\outfile{outfile}
\newread\in%
\openin\in=\infile%
\newwrite\out%
\immediate\openout\out\outfile%
\endlinechar-1%
\loop\unless\ifeof\in%
\readline\in to\l%
\immediate\write\out{\l}%
\message{copied line : \l}
\repeat%
\immediate\closeout\out%
\closein\in%
\endlinechar13%
\documentclass{article}
\begin{document}
\end{document}
The infile
file consists of a single line, and has three trailing spaces:
$ cat infile
abc def
$ tr ' ' '_' < infile
abc___def___
The outfile
file, after running the above code, lacks these spaces:
$ latex copy.tex
...
$ cat outfile
abc def
$ tr ' ' '_' < outfile
abc___def
Surely there is a way to achieve that, by changing some catcodes I guess, but I tried adding some \catcode` =11
(with a backtick) or \catcode` = 9
, but the trailing spaces were still absent from outfile
.