I am in the process of writing a Python program that scrapes exam questions in tex files from a website and combines them to create a new paper. The questions are picked by random from a spreadsheet, so that questions from various years (and therefore from different latex files) may be combined. Here is an example of such a paper (1987), and here is an example from a much newer paper (2018).

The preambles are considerably distinct and this makes it difficult to simply include them into the same latex file. How could I, for example, take a particular question from the older paper and another question from the newer paper and produce a single pdf file? I have attempted to use the subfiles and standalone packages but I get bombarded with errors. I have also considered compiling each latex file separately and concatenating them using pdfpages or a similar command line utility but I would like to avoid having only a single question per page. I have thought about programmatically retrieving the "union" of the preambles from the two (or more) files and simply substituting in each \question in a single latex file, but this is a last resort.


I have opted to use the combine document class and structure the main document similar to below:









The use of the papers environment proved necessary, as did the line \let\clearpage\relax to ensure that the documents do not simply start at the next page. Compiling the main document produces a consistent pdf file, but there are many "X already defined!" errors which thankfully do not disrupt the compilation of the pdf (and especially so after passing the interaction=nonstopmode argument to latexmk).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.