7

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} 
1
  • 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. Commented Sep 24, 2012 at 7:37

1 Answer 1

6

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!

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.