Description
The \var
can be used in two different ways. The
simpler use is for referencing—that is, inserting the
value of—an algorithmic variable in a question field
other than the algorithm itself.
\var{variable-name}
- variable-name
- The name of the algorithmic variable, with no
prefixed
$
sign
\var
can also be used to place an inline
variable expression: a computed expression within a
variable reference.
\var{expression}
- expression
- An expression whose value is to be computed; the result is used as the replacement for the variable reference
These inline variable expression are extremely useful, as
they allow a question’s algorithm to be greatly
simplified. Without inline variable expressions, every
algorithmically-generated quantity in a question would
require a separate variable definition in that question's
\algorithm
. Inline variable expressions
allow for a minimum of variables. Not only does this benefit
the author, but it reduces the load on the servers when
students are taking assignments.
Inline variable expressions should also use \var
to
reference variables; that is, inline variable expressions are
constructed from nested \var
macros.
Notes
- All variables referenced within a
\var
must be defining within the current question’s\algorithm
.
Example
\begin{question}{Formula} \algorithm{$n = range(2,10);} \qutext{What is the derivative of $x^{\var{n}}$?} \answer{\var{n}x^\var{\var{n}-1}} \end{question}