15

I wish to do a simple question and answer sheet for my students. I'd like to have something like this:

\section{Differential Equations}

    \begin{questions}

         \begin{question}
              ... Question here ...
         \end{question}

         \begin{answer}
              ... Answer here ...
         \end{answer}

    \end{questions}

I wish to have the environment QUESTIONS to have counters like enumerate. That is, each \begin{question} ... \end{question} should behave just like \item in

\begin{question} 
\item 
\end{question}

The \begin{question} ... \end{question} environment should take "normal" LaTeX commands.

If possible, I'd wish to have deferred printing to print the answers at the end of the document.

I first tried this

\makeatletter
\newtoks\answerscollect
\newcounter{question}
\setcounter{question}{0}
\def\thequestion{{\bfseries{Question \arabic{question}. }}\\}

\def\answer#1{%
\protected@edef\answertmp{%
\the\answerscollect\vspace{.5\baselineskip}\noindent\thequestion#1\par}%
\par\answerscollect=\expandafter{\answertmp}}
\def\printanswers{\the\answerscollect\answerscollect={}}
\def\initbox{\answerscollect={\par\noindent Answers:\par}}

\newcommand{\question}[1]{\stepcounter{question}\par\noindent\thequestion#1}
\makeatother

but it's not behaving the way I'd love the results to be ...

Dorogz
  • 173
  • 1
    Welcome to TeX.SX. Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Accepting and upvoting answers is the preferred way here to say "thank you" to users who helped you. – Claudio Fiandrino Apr 12 '13 at 12:52
  • 4
    Have you looked at the exam package? http://www.ctan.org/tex-archive/macros/latex/contrib/exam I guess the package answers too http://ctan.uib.no/macros/latex/contrib/answers/answers.pdf – N3buchadnezzar Apr 12 '13 at 12:53
  • @N3buchadnezzar I have tried a number of existing packages. They are cool, but do not actually give me the flexibility to do what I want! – Dorogz Apr 12 '13 at 13:10
  • 3
    I do not see anything in your question, making the answers package not valid. Please state what this package is missing =) – N3buchadnezzar Apr 12 '13 at 13:14
  • @N3buchadnezzar, I've looked at them and they are awkward to use. No lack of flexibility, mind you. But then again, I really don't see a simple(r) way to express the rather complex documents to be created... unless you leave the cozy LaTeX world and build a database with questions and answers, and splice the exam together from the result of a query. – vonbrand Apr 12 '13 at 13:49
  • @vonbrand Have you played around with this, for instance: ftp://ctan.tug.org/tex-archive/macros/latex/contrib/exsheets/exsheets_en.pdf? While, I realise that, you may have specific needs to address, this question is too general to get a good answer (please note that, I am NOT saying the question is bad!). Please help us arrive at a precise question that you'd like to answer. For instance, start with a base code and tell us, what it is lacking. We might work on it one by one and at the end you'd have your derired code. :) – kan Apr 12 '13 at 13:53
  • I am after simplicity and flexibility. Packages like answer do provide solutions, but they are an overkill for the simple task that I want to do. Moreover, it's pretty difficult to tweak them ... I've defined new environments viz. \newenvironment{questions}{\begin{enumerate}}{\end{enumerate}} \newenvironment{question}{\item}{} \newenvironment{answer}{\item}{} I wish to go further and defer printing the answers – Dorogz Apr 12 '13 at 16:15

1 Answers1

20

Simple use of exam package :

\documentclass{exam}
%\printanswers
\begin{document}

\section{Differential Equations}
\begin{questions}
\question ... Short question here ... \answerline[Short answer]
\question ... Question here ... 

\begin{solution}[.2in]
... Answer here ... 
\end{solution}

\question Long descriptive question about everything

\begin{solutionorlines}[2in]
Long descriptive answer is a long descriptive answer that is a long descriptive answer that is along descriptive answer that is along descriptive answer that is along descriptive answer that is a lie.
\end{solutionorlines}

\question Draw an arrow showing north direction.

\begin{solutionorbox}[2in]
$\uparrow$
\end{solutionorbox}

\end{questions}

\ifprintanswers
Stuff to appear only when answers \textbf{are} being printed.
\else
Stuff to appear only when answers \textbf{are not} being printed.
\fi

\end{document}

Commenting and uncommenting \printanswers yields in one of two following:

1)

Only questions

2)

Questions with answers

I don't see any lack of functionality compared to your example.

Vairis
  • 754
  • 1
    At my department, we took exam.cls as a foundation for our own examination class, so that the cover page would always look the same, and it works very well. It is very flexible. – Benjamin McKay Oct 21 '13 at 15:20