Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Possible Duplicate:
How can I produce exercises in one part of a LaTeX document with selected answers in another?

I'm writing a book and want to add some math problems and solutions to this book. Is it possible to have the following in LaTeX?

  1. In the LaTeX source file, the source of the solution will be directly after the problem.
  2. In the typeset book, the section with solutions will be typeset at the end.
share|improve this question

migrated from stackoverflow.com Jun 5 '11 at 22:19

This question came from our site for professional and enthusiast programmers.

marked as duplicate by cgnieder, Werner, Kurt, Andrew Swann, Stefan Kottwitz Oct 19 '12 at 16:01

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
The answer to "is it possible" is Yes. Hopefully someone else will come and explain how. [You can also look at the source of the TeXbook to see how Knuth does it in plain TeX, but it will be easier to wait. :-)] –  ShreevatsaR Jul 18 '10 at 7:58
2  
Have you ever heard of acrotex? Their education bundle is free and has lots of tools to design exercises. I am not sure it gives you exactly what you want, but it is definitely worth looking into. acrotex.net/aeb_index.php –  Vivi Jun 6 '11 at 0:42

2 Answers 2

There's a package called answers which appears to do something like this (do texdoc answers, or the equivalent on your platform, for the documentation).

If that doesn't work, or isn't really suitable, then I've got a hand-rolled solution to exactly this problem which I could post here.

share|improve this answer
2  
Always good to use a pre-existing package where possible. +1 –  Will Robertson Jul 19 '10 at 8:27

You can put material at the end of the document (regardless of its location in the source) with \AtEndDocument{...}.

Incorporating that into your macro for writing questions/answers is left as an exercise :)

share|improve this answer
    
I think it's a rather hard exercise. Could you elaborate? What if you want to have an index (for instance) to appear after the solutions? –  ShreevatsaR Jul 18 '10 at 22:33
    
Write \AtEndDocument{\PrintIndex} at the end of your document. –  Will Robertson Jul 19 '10 at 6:39

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