I am trying to get a TeX file to read certain lines from a different text file. More precisely, in my database file a.tex I have a long list. Now in a different file, I would like to have items with specific numbers. Of course, I can copy-paste. My question is, is there a way to get LaTeX to do it?

2 Answers 2


The short answer is yes. The longer answer is that we'd need more information. You can easily read a file one line at a time. The e-TeX extension \readline is especially helpful for reading files.

How are these lines numbered? How many do you want to read at once? Are the lines sorted by these "specific numbers"? Is your list of numbers sorted? What else can you tell us about these lines?

  • One file is basically an itemized list. I want the first file to just copy items numbered, say, 1,2,5. So the reference will not be to a particular physical line, but rather to the first, second, and the fifth item in that list. Each one of the items may occupy more than one line as well.
    – user1227
    Sep 19, 2010 at 9:11

Maybe the datatool package can do what you want. It can sort external files, do things like mail merging and so on.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .