I am preparing a question bank type book which contains problems as well as answer keys to all the problems. I'm doing this using org-mode. This will be exported to LaTeX PDF for my final book.

However, there is a problem I'm running into. To put it very simply, here is the problem:

Problem

My book will have 2 sections: one containing problems, and the other containing answers to those problems. In org-mode, I have one major heading for Problems, under which I create sub-headings for each new problem. Inside each problem sub-heading, I have another sub-heading which contains the answer to that problem. In my final book, I wish the answers to be in a separate chapter and not directly after the problem. However, in org-mode, I am adding the answers as a new sub-heading inside each problem itself for my own convenience of writing.

Now, I want to somehow to segregate out the answers' subheadings and push them into new section during my LaTeX export. Can this be done?

Could you suggest some other methodology for writing a question-answer type book, where we have answers in a separate section of the book?

This would require some coding, but not impossible in general with Org. My approach would be to use named Babel Org blocks. I'd write answers in these blocks and place the blocks next to the questions, I'd also configure export settings such that only the results are exported, and would put the result headers in the place I want them in the exported document.
– wvxvwDec 25 '16 at 14:28

If you export it, you'll get the headings plus answers only. If you change the EXCLUDE_TAGS to "a" and press C-c C-c on the header to update the info, export will export only the questions.

This functionality can be used programmatically, and can thereby serve as a basis for a more automatic solution. One approach would be to write a simple publishing function that exported the q&a file twice, each time excluding one of the two tags. If the file is exported as latex, body-only, the resulting files could be directly included into a bigger latex file of the whole book.