Inline Display of Formatted Math Expressions
The algorithmic function mathml(s) accepts a string argument s, which it treats as a formula in calculator syntax and typesets it as MathML that can be used inside algorithms.
Note: When you create inline typeset math expressions using the mathml(f) function, the system automatically simplifies the expressions.
qu.1.1.question=
What is the derivative of ${mathml(sqrt(1+x^$n))}?
@
qu.1.1.answer=
(1/2)(1+x^$n)^(-1/2) $n x^${$n-1}
@
qu.1.1.algorithm=
$n=range(2,10);
@
Since you can also use algorithmic commands to generate inline expressions, you can use the $mathml(s) command along with inline expressions of the form ${expression} to display the following typeset math expression inside a question statement.
What is ${mathml( (x+1)/sqrt(x^2-1) )}
This will generate
This is a quick and easy way to place MathML in question banks that use a little math notation but are not heavily reliant on it.
In addition, your expression can include other algorithmic functions and variables. You can use the following,
${mathml((x+$a)/sqrt(x^$n-1))}
Numeric Arguments to the mathml function
mathml(expr, 0)
returns MathML with no <math> tags
mathml(expr, 1)
(the default) returns MathML with <math> tags
See Also:
Simplified Math Expressions
mathml(f)
MathML Authoring with MathType
The Maple T.A. system can display and process MathML expressions as part of questions, answers, and feedback. However, creating MathML expressions in a plain text or HTML editor is extremely complicated, so this topic discusses how to use Design Science MathType^{TM} Version 6.9 to create expressions that can then be exported into MathML expressions for importing into your Maple T.A. content.
Microsoft Windows and Mac OS^{®} X users can use the Design Science MathType Version 6.9 to create MathML expressions. To do so, follow these steps:
- Set the MathType MathML translator to export MathML as follows:
- From the menu, select Preferences > Translators to set MathML export.
- Set the options exactly as indicated in the MathType Dialog box below, then click OK:
- Select Translator: MathML 2.0 (no namespace) radio button
- Clear Include translator name in translation check box.
- Clear Include MathType data in translation check box.
- Create your math expression using MathType.
- Select the expression (use Ctrl-A to select all elements).
- Copy the highlighted expression to the Windows clipboard (use Ctrl-C).
- Open your .qu plain-text script file and position the cursor at the location for the MathML expression.
- Paste the MathML expression into your plain-text script file (use Ctrl-V).
- Save your .qu script file according to the system requirements.
- Open your class web site and use the Question Editor to upload and install the new question bank, with MathML intact.
See Also:
Editing with the Equation Editor
MathML is used by the system for both the display of complicated math expressions as well as for content in math expressions (mathematical meaning).
For small expressions, you can use the mathml(f) function to create inline MathML expressions, in effect, to force the system to render an expression defined in calculator syntax as a typeset math expression.
Example
qu.1.8.mode=Formula@
qu.1.8.name=Fractions@
qu.1.8.editing=useHTML@
qu.1.8.algorithm=
$a=range(1,8);
$num=$mathml("(x/2)=$a");
$ans=$a*2;
@
qu.1.8.question=
Solve for x:
<br> $num@
qu.1.8.answer=$ans@
For larger expressions, you can include the MathML code for the expressions directly in questions, answers, hints, and feedback in your question bank.
Example
The following is an example of MathML code used to create an expression inside a question script:
qu.1.5.mode=Equation@
qu.1.5.name=<b>Equations with algorithmic MathML feedback</b>@
qu.1.5.comment=
Use the slope/intercept form of the line to find the equation as
<math>
<mo>(</mo><mi>y</mi> <mo>-</mo> <mn>$yone</mn><mo>)</mo>
<mo>=</mo>
<mfrac>
<mrow><mn>$ytwo</mn> <mo>-</mo> <mn>$yone</mn></mrow>
<mrow><mn>$xtwo</mn> <mo>-</mo> <mn>$xone</mn></mrow>
</mfrac>
<mo>(</mo><mi>x</mi> <mo>-</mo> <mn>$xone</mn><mo>)</mo>
</math>
@
qu.1.5.editing=useHTML@
qu.1.5.algorithm=
$xone=decimal(1, rand(0,10));
$xtwo=decimal(1, rand(0,10));
condition: ne($xone, $xtwo);
$yone=decimal(1, rand(0,10));
$ytwo=decimal(1, rand(0,10));
$m=($ytwo - $yone)/($xtwo-$xone);
$b=-$m*$xone + $yone;
@
qu.1.5.question=
What is the equation of the straight line passing through the points
($xone, $yone) and ($xtwo, $ytwo)?
<br>
@
qu.1.5.answer=
y = $m x + $b
@
You can also generate MathML using Maple.
qu.1.5.mode=Equation@
qu.1.5.name=<b>Equations with algorithmic MathML feedback</b>@
qu.1.5.comment=
Use the slope/intercept form of the line to find the equation as $Solution.
@
qu.1.5.editing=useHTML@
qu.1.5.algorithm=
$xone=decimal(1, rand(0,10));
$xtwo=decimal(1, rand(0,10));
condition: ne($xone, $xtwo);
$yone=decimal(1, rand(0,10));
$ytwo=decimal(1, rand(0,10));
$m=($ytwo - $yone)/($xtwo-$xone);
$b=-$m*$xone + $yone;
$Solution=maple("printf(MathML:-ExportPresentation(y=$m*x + $b))");
@
qu.1.5.question=
What is the equation of the straight line passing through the points
($xone, $yone) and ($xtwo, $ytwo)?
<br>
@
qu.1.5.answer=
y = $m x + $b
@
See Also:
Inline Display of Formatted Math Expressions
MathML Authoring with MathType
Simplified Math Expressions
When you use the mathml(f) function to easily render typeset mathematics expressions, the system also engages a set of automatic simplification rules, as follows.
- Simple addition, subtraction, and multiplication are performed. For example, x+(2+3) are set as x+5 and 2*3*x as 6x.
- Additions and subtractions of zero are disregarded. For example, x+0 is x
- Addition of a negative number on the right becomes subtraction. For example, x+(-2) becomes x-2.
- Subtraction of a negative number on the right becomes addition. For example, x-(-2) becomes x+2.
- Multiplication by a number always comes first. For example, x*2 becomes 2x.
- Multiplication by 0 becomes 0. For example,0*x becomes 0.
- Multiplication by 1 and -1 handled correctly. For example, -1*x becomes -x.
- Division of two numbers simplified:
- Denominator is always positive. For example, 3/-2 becomes -3/2.
- Quotient of two integers is always put in lowest terms. For example, 3/6 becomes 1/2 and 6/3 becomes 2.
The best place to use these functions is in in-line expressions. For example, consider the algorithm:
$a=range(-10,10);
$b=range(-10,10);
$c=range(-10,10);
$d=range(-10,10);
condition: ne($a*$c, $b*$d);
You can set the question as follows.
Solve the simultaneous linear equations ${mathml("$a*x+$b*y")}=0
and ${mathml("$c*x+$d*y")}=0
Exceptions to Automatic Simplification
There may be situations in which the simplifications performed by mathml(f) may go beyond what you want. For example, you might want to typeset "2*3"4"x" literally. Automatic simplification is the system default.
To override the system defaults, use the optional numeric arguments for the mathml(f) function, which indicates that it is not to simplify math, as follows.
There are two pieces of mathml(f) behavior that can be controlled by a numeric argument:
- Whether to enclose the generated MathML in <math> tags - the default is to do so
- Whether to simplify math expressions - the default is to do so
Syntax
mathml(expr) - set expression in MathML using the defaults above
mathml(expr, k) - set expression in MathML using the options from the table below
Table 6.4: Options for the mathML Function
k | Include <math> tags | Simplify math |
---|
0 Default | yes | yes |
1 | no | yes |
2 | yes | no |
3 | no | no |
Turning off the <math> tags allows you to generate a MathML snippet with mathml(...) that is to be used within a larger math layout that is generated either in raw MathML or from LaTeX. For example, in the LaTeX macros you can write:
$$ \int_1^\infty \var{mathml("$a+$b/x^2", 1)} dx $$
to display simplified algorithmic math inside an integral.
See Also:
Inline Display of Formatted Math Expressions
mathml(f)