I'm working on a math book with exercises interspersed within the running text. I have an ex environment for these exercises and a sol environment for the solutions. The solutions reside in an appendix at the end of the book. The book is pretty big already and distributed over 40+ files.
Right now, whenever I add an exercise, I add the corresponding solution to the appendix, but I have to make sure the order of solutions in the appendix corresponds to the order of exercises in the book. I have rearranged the order of some chapters a few times and that always was a PITA as I had to manually move the solutions around.
Is there a library similar to something like endnotes that would allow me to put each solution directly after the corresponding exercise in the source with the outcome that in the final document the solutions would all be moved to their own chapter at the end of the text?
(I'm afraid I couldn't find a meaningful tag for this question. Maybe someone else can.)
probsoln,answers,exsheet... all do such kind of things – Feb 06 '17 at 17:26collect, mentioned in How to collect text for later usage in appendix? and How to place all proofs automatically in appendix? – ebosi Feb 06 '17 at 17:55collectlooked as if it were exactly what I was looking for, but it turns out it doesn't work together withfancyvrbwhich I'm using in many solutions. Hmm... – Frunobulax Feb 06 '17 at 20:07collectnorfancyvrbare really at fault here. In *TeX,verbatim(and by extension,fancyvrb) breaks when placed inside pretty much anything. See the FAQ – Fox Feb 06 '17 at 23:15answersas suggested by @ChristianHupfer and that seems to work fine withfancyvrb. The difference is thatcollectsomehow pre-digests the text it collects and strips off all whitespace whileanswerswrites the contents to file as is. – Frunobulax Feb 07 '17 at 10:11exsheetshas a very versatile successor calledxsim– cgnieder Oct 12 '17 at 10:19