# Reading an external file failed with dimension related errors

I want to read an external file one line per read and insert each line as an item. I failed to do so because of dimension related errors. How to solve it?

\documentclass{article}
\def\trimtok i{}
\def\trimmer#1{\expandafter\trimtok #1}

\immediate\write18{tlmgr list --only-installed > installed-packages.txt}
\begin{document}
\makeatletter
\begin{enumerate}
\loop
\item \trimmer{\data}
\repeat
\end{enumerate}
\makeatother
\end{document}

-
By replacing installed-packages.txt by a random file containing a list, and adding curly braces aroud i{}in the definition of \trimtok, I get an output. I wonder if your problem wouldn't be related to the various backslashes and @ you get in installed-packages. – T. Verron Sep 24 '12 at 7:37

The text file you create contains TeX commands, which are present in the descriptions of some of the packages. Thus you need to detokenize somewhere. If you do it after reading, TeX will insert spaces after the control sequences. So I'd read as strings, and then deal with the i and end-of-line as 'other' characters in your tidy-up macros:

\documentclass{article}
\usepackage[T1]{fontenc}
\begingroup
\catcode\^^M=12\relax%
\expandafter\gdef\expandafter\trimtok\detokenize{i}#1^^M{#1}%
\gdef\trimmer#1{\expandafter\trimtok #1}%
\endgroup

\immediate\write18{tlmgr list --only-installed > installed-packages.txt}
\begin{document}
\makeatletter
\begin{enumerate}
\loop
\item \trimmer{\data}
\repeat

i addlines: A user-friendly wrapper around \enlargethispage.

which tries to execute \enlargethispage` without a suitable argument!