When inserting a listing with the catchfilebetweentags package, I get the error job aborted, no legal \end found. How do I make these packages work together? If I can't, are there viable alternatives?

Use case

I have a large collection of exercises and I want to be able to easily put some of them together into one exercise sheet. Furthermore I want to have a document where I can look at all exercises together. Due to the number and the small size of each exercise it is infeasible to create a separate file for each of them. Therefore I put them into one large file collection.tex and use tags to extract single exercises.

MWE Description

The MWE below shows the way in which I use these files. I use a patch for catchfilebetweentags as described here to prevent it from swallowing eol's. This is irrelevant for the error but I included it in case it becomes relevant for a solution.





    a + b



Any help would be appreciated!

  • Looking at the related pane to the right there are 1 2 3. Should be usable here
    – user202729
    Commented Jun 29, 2022 at 16:46
  • ... apparently nobody have implemented a "replacement" that rescan the tokens correctly yet...???
    – user202729
    Commented Jun 29, 2022 at 16:48
  • Thanks for pointing that out. I've read about the package having problems with verbatim, but I am not sure whether this is the same problem. Unfortunately there doesn't seem to be a solution, which seems weird since there shouldn't be a need for any preprocessing/tokenization in my use case (the behavior of "input" would be perfectly fine).
    – cero
    Commented Jun 29, 2022 at 18:09
  • TeX programming is complicated. Seemingly-easy things can be hard to implement. (and if it's hard to implement, chances are packages won't support it. Which is the case here. Not that it cannot be implement, but it's true that the package author doesn't support that.)
    – user202729
    Commented Jun 29, 2022 at 18:13


You must log in to answer this question.

Browse other questions tagged .