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.

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}

\newread\reader

\immediate\write18{tlmgr list --only-installed > installed-packages.txt}
\begin{document}
\makeatletter
\begin{enumerate}
\openin\reader=installed-packages.txt\relax
\loop
    \read\reader to \data
    \unless\ifeof\reader
        \item \trimmer{\data}
\repeat
\closein\reader
\end{enumerate}
\makeatother
\end{document}
share|improve this question
    
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
add comment

1 Answer

up vote 6 down vote accepted

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

\newread\reader

\immediate\write18{tlmgr list --only-installed > installed-packages.txt}
\begin{document}
\makeatletter
\begin{enumerate}
\openin\reader=installed-packages.txt\relax
\loop
    \readline\reader to \data
    \unless\ifeof\reader
        \item \trimmer{\data}
\repeat
\closein\reader
\end{enumerate}
\makeatother
\end{document}

The actual error you get is related to the first 'problematic' line

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

which tries to execute \enlargethispage without a suitable argument!

share|improve this answer
add comment

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.