The following code...
%Question/Answer Commands
\usepackage{color}
\usepackage{ifthen}
\newcounter{q_num}
\setcounter{q_num}{1}
\newcommand{\question}[1]{Question \arabic{q_num}: #1\stepcounter{q_num}}
\ifthenelse{\equal{\showanswers}{true}}
{%: Show the answers
\newcommand{\answer}[1]{\textcolor{red}{Answer: #1}}
}
{%: Don't show the answers
\newcommand{\answer}[1]{}
}
...defines the following latex commands:
\question{<question-text>} - This appends a question number to the start of each question. The question number is incremented automatically.
\answer{<answer-text>} - The answer text is only visible when \showanswers is defined as true.
An example Question/Answer slide would look like:
\begin{frame}{}
\question{What is brown and sticky?}
\answer{A stick}
\end{frame}
If \showanswers is defined as false, the output would be:
Question 1: What is brown and sticky?
If \showanswers is defined as true, the output would be:
Question 1: What is brown and sticky? Answer: A stick
There are many ways to go about defining \showanswers. For example you could just define it in your main .tex file:
\newcommand{\showanswers}{true}
Or you could pass it as a command line argument which is what I chose to do using a makefile:
questions:
pdflatex --jobname=questions '\newcommand{\showanswers}{false}\input{quiz.tex}'
answers:
pdflatex --jobname=answers '\newcommand{\showanswers}{true}\input{quiz.tex}'
#where quiz.tex is the latex file containing quiz questions
This will produce two PDFs one called questions.pdf and one called answers.pdf. Only the second one will have the answers visible
No comments:
Post a comment