I need to do the following:

I have a file A which consists out of short fragments of text:

Text 1

Text 2

Text 3

Text 4

I have another file file B in which I need to input fragments of text from file A:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Text 1

Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

Text 2

Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Text 3

Sometimes the text will need to go into a footnote so that should also be possible.

How could I achieve this without breaking the file A into separate files and using \input?

  • 1
    If the short text is always one line long (the line itself may be long), the answer here can help you : tex.stackexchange.com/a/2377/9517 (all you want is read a file one line at a time). If not, then you'll need to use the same technique to read lines until you see two linefeeds in a row.
    – T. Verron
    Apr 22, 2015 at 11:44

1 Answer 1


Before I give you an answer, I would like to give you couple of notes about the problems of your approach. Firstly, you should update whole File A even for small changes (instead of only changing what needs to be changed). In other words, this approach doesn't scale. Secondly, it is somehow breaking one of the nicest features of LaTeX, i.e., the possibility of breaking down big chunks of text to smaller and more manageable sizes. Lastly, if you are working in team, this would reduce your options for collaboration.

With that said, if you add some tags to File A, you can use catchfilebetweentags package which as its title suggests, catches parts of file surrounded by a certain tag.


and somewhere in your file you will have something like


Credits to this answer.

You must log in to answer this question.

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