You're not reading the latest revision of this page, which is here.

How write questions and answers

Type of problem, question and answer

The content of every generic TeX problem is included in a problem environment which must be contained only once in TeX files.

The use of the \usepackage declaration is mandatory too. WebMiau creates it by using the code snippet creator.

alt-p

Every question is defined in a question environment inside problem. The structure looks as following:

1
2
3
4
5
6
7
8
9
10
\usepackage{mumie.genericproblem}
\begin{problem}
    \begin{question} % start of question 1
      ...
    \end{question}
 
    \begin{question} % start of question 2
      ...
    \end{question}
\end{problem}

Within the question environment, one must define a type using the \type{...} command.

\type{...} can be set for the whole group of questions, but can also be set individually for each question and answer.
The position of the command determines how it works.

1
2
3
4
5
6
7
8
9
10
11
12
\begin{problem}
  \type{...} % set for all questions
 
  \begin{question}
    \type{...} % or set only for this question and all their answers
 
    \begin{answer}
      \type{...} % or set only for this answer
    \end{answer}         
 
  \end{question}        
\end{problem}

What type is applicable

Type Preview
input.number


more
input.number
input.finite-number-set


more
input.finite-number-set
input.function
Compare the user's answer numerically
with the pre-given solution

more
input.function
input.interval


more
input.interval
input.cases.function
Designed for case differentiations of e.g. absolute value functions.
Note that you can only use this input type in an answer environment.

more

input.cases.function
input.matrix
If the solution to a question is a row vector, a column vector or a matrix,
the generic problem is of the type input.matrix.

more
input.matrix
input.text


examples in WebMiau or the full article here
input.text
input.truth-table


more
input.truth-table
mc.matrix


example in WebMiau or the full article here
mc.matrix
mc.unique


more
mc.unique
mc.yesno


more
mc.yesno
mc.multiple


more
mc.multiple

Overview input field questions

Number fields

All variables and functions are interpreted in a number field which can be defined by the \field{...} command. It can take one of the following values:

number field Description
real real numbers (i.e. double values); this is the default value if the \field{number field} command is omitted
integer integer numbers
rational rational numbers
complex complex numbers with real numbers as real and imaginary parts
complex-rational complex numbers with rational numbers as real and imaginary parts
1
2
3
4
5
6
7
8
9
10
11
12
\begin{problem}
  \field{...} % set for all questions
 
  \begin{question}
    \field{...} % or set only for this question and all their answers
 
    \begin{answer}
      \field{...} % or set only for this answer
    \end{answer}         
 
  \end{question}        
\end{problem}

Variables

Questions can become dynamic and personalised through the use of variables and functions. These must be defined
in a variables environment

The environment \begin{variables} ... \end{variables} can be set for the whole group of questions, but can also be
set individually for each question. The position of the command determines how it works.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
\begin{problem}
 
    \begin{variables} % set for all questions
      ...
    \end{variables}
 
    \begin{question}
      \begin{variables} % set only for this questions
        ...
      \end{variables}
 
      \begin{answer}
      \end{answer}         
 
    \end{question}        
\end{problem}

Example

1
2
3
4
5
6
7
8
9
10
11
\begin{question}
   \begin{variables}
       \number{a}{12}
       \number{b}{4}
       \number{c}{10}
       \number{d}{5}
       \function{f}{a/b}
       \function{g}{c/d}
   \end{variables}
   ...
\end{question}

Will result in variables

  • $$a=12$$,
  • $$b=4$$,
  • $$c=10$$,
  • $$d=5$$ and
  • functions $$f=\frac{12}{4}$$ and $$g=\frac{10}{5}$$

Commands

Command Description Details
\number A fixed number variable, this can be any kind of number. The field command determines how the number will be interpreted.
\function A function definition, the definition may include variables and other functions.
When an included variable is not defined, it will be a free variable.
Again, the field command determines how the numbers within the function will be interpreted.
function
\derivative Creates a new function representing the derivative of the expression/variable that was passed into it. derivative
\substitute Creates a new function that is the composition of two other functions. substitute
\randint A random integer number, including zero (same as randint[z])
\randint[Z] A random integer number, excluding zero Random numbers
\randdouble A random double number, including zero Random numbers
\randrat A random rational number, including zero Random numbers
\drawFromSet Randomly draw a number (or string) from a set Random numbers
\randadjustIf Random variables can be adjusted to satisfy a specific constraint. randadjustIf

Using Variables in text

All variables can be used in texts (e.g. question task, answer text) by using the tex command \var with the name of the variable as argument:

1
2
3
4
5
6
7
8
9
10
11
12
13
\begin{question}
 
  \begin{variables}
    \function{f}{a/3}
  \end{variables}
 
  \text{Determine the decimal expansion of $\var{f}$ correct to three decimal places.}
 
  \begin{choice}
    \text{$\var{solution1}$}
  \end{choice}
 
\end{question}

Random numbers

Random numbers can be used instead of fixed numbers to personalize problem data.

Example

1
2
3
4
5
6
7
8
9
\begin{question}
 
  \begin{variables}
      \randint[Z]{x1}{-10}{10}  %\randint[Z]{name}{min}{max}
      \randdouble{x2}{0}{1}
      \randrat{name}{minNumerator}{maxNumerator}{minDenominator}{maxDenominator}
  \end{variables}
 
\end{question}

\drawFromSet Draw randomly a number (or string) from a set

  • parameters \drawFromSet[options]{name}{set}
  • numbers in the set can be integer, rational or double numbers
  • separator in the set can be any (non white space) character, default separator is the comma
  • type is either number or string, default type is number
  • multiple options are separated by a space (see example below)
1
2
3
4
5
6
7
8
9
10
\begin{question}
 
  \begin{variables}
      \drawFromSet{a}{1,2,3,4,5,6}
      \drawFromSet{b}{1/2,5,1.3,9/11,42}
      \drawFromSet[separator=;]{c}{1;2.1;3.5;9}
      \drawFromSet[separator=; type=string]{d}{hello;world}
  \end{variables}
 
\end{question}

Variable pools

Instead of using random values for numbers it is possible to define several sets of values inside a so called variable pool.

  • A pool consists of several variables environments holding each the elements for a single set of variables.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
\begin{question}
 
  \begin{pool}
    \begin{variables}
      \randint{a}{1}{3}
      \drawFromSet{b}{1,2,3}
      \randadjustIf{a,b}{a = b}
      \function[calculate]{f}{2*a+b}
    \end{variables}   
 
    \begin{variables}
      \randint{a}{-3}{-1}
      \drawFromSet{b}{-1,-2,-3}
      \randadjustIf{a,b}{a = b}
      \function[calculate]{f}{2*a-b}
    \end{variables}   
  \end{pool}
 
\end{question}
  • A single set will be chosen randomly for every homework problem. The following example shows a pool with two sets of variables:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
\begin{question}
 
  \begin{pool}
 
      \begin{variables}
          \number{a}{7}
          \number{b}{3}
      \end{variables}
 
      \begin{variables}
          \number{a}{5}
          \number{b}{6}
      \end{variables}
 
  \end{pool}
 
\end{question}
Variable pools can only be used inside a question. There are no global variable pools at the moment.

Explanations

With \explanation the author can define a feedback that the user gets if an answer wasn't (completely) correct. Usage: \explanation[optional condition]{text}.

More details