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

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}.

Within the explanation text variables can be used the same way as in question tasks and answer texts. Explanations on question level are displayed if one or more than one answers wasn't correct. On answer level explanations are displayed if the specific answer wasn't correct. The author can optionally decide if an explanation is displayed only if certain mistakes were made or if a random variable has a specific value.

With \showExplanation{always} the author can define, that an explanations is always displayed - even if the user's answer was correct.

Optional Condition

The optional condition is an expression that can be evaluated to true of false. It can contain

  • logical operators: AND, OR, NOT
  • relation symbols: =, !=, >, >=, <, <=
  • variable references
  • answer references: An answer reference can be 'ans', referencing the current answer (on answer level only) or 'ans_index' to reference the answer with the specific indix, e.g. 'ans_3'.
  • functions: length, count, valid, equal, equalString, equalTrimmedString, equalChoice, edited, condition, equalAnswer

The Functions in Detail

Syntax Description Example
length(arg) Returns the length of a string. arg is a variable or an answer reference. length(ans)=length(myvar) OR length(ans)>3
count(symbol, arg) Returns how often the symbol occurs. arg is a variable or an answer reference. count((,ans)=count(),ans), count(+,ans_1)=0, count(1,ans)=2
valid(arg) Checks if the given answer is a valid mathematical expression. arg is an answer reference. valid(ans)
equal(arg1, arg2) Checks if the two expressions are algebraic identical. If \checkAsFunction is set, the comparison will be numerical with the given parameters of checkAsFunction. arg1/arg2 is a variable or an answer reference. equal(ans_2, myvar)
equalString(arg1, arg2) Checks if the string representation of the two arguments are identical. arg1/arg2 is a variable, an answer reference or a string. equalString(Hallo,ans_5), equalString(ans,myStringVar)
equalTrimmedString(arg1,arg2) Same as equalString but the arguments are trimmed first.
equalChoice(arg, choices) Compares an answer with the given choices representation. For mc.unique its the choice number that is selected by the user. For mc.yesno and mc.multiple its a string of zeros and ones indicating which choices are selected by the user. E.g. 011 means that the last two choices are selected, but not the first. The wildcard '?' can be used. E.g., 0?1 means, that the third choice is selected, but not the first. If the second choice was selected doesn't matter. This of course only works for answer/question type mc.yesno and mc.multiple. arg is an answer reference. equalChoice(ans,4), equalChoice(ans,011001), equalChoice(ans_2,011?01)
edited Evaluates to true on answer level if the current answer was edited. Evalues to tru on question level if at least one answer of the current question was edited.
edited(arg) Evaluates to true if the referenced answer was edited. arg is an answer reference edited(ans), edited(ans_4)
condition(arg) Substitutes this command with arg. That is helpful if one wants to reuse the same condition multiple times. arg is a string variable. It's value is a valid condition expression. declared variable: \string{mycondition}{NOT [edited(ans)] OR count(/,ans)=0 }, reusing it: condition{mycondition} OR equalString(42,ans)
answerEqual(arg) At the moment that only works for type input.interval. It compares the current answer with the given expression arg. The expression may contain variables. Be aware that you have to escape brackets. NOT [edited] OR answerEqual(\[a;3\]), answerEqual(\[-infinity;3\],\(4;5\))