Note: You are currently viewing documentation for Moodle 3.3. Up-to-date documentation for the latest stable version of Moodle is probably available here: FQT Using variables in text and text equations.

FQT Using variables in text and text equations: Difference between revisions

From MoodleDocs
No edit summary
No edit summary
Line 36: Line 36:
<div style="font-family:Lucida Sans Unicode;font-size:113%;color:#6c336d;margin:10px 0 10px;> Example</div>
<div style="font-family:Lucida Sans Unicode;font-size:113%;color:#6c336d;margin:10px 0 10px;> Example</div>


Write the following equation in the TeX, MathML and AsciiMath syntaxes, where {a}, {b} and {c} will be substituted by the value of these variables:
Write the following equation in the MathML syntax, where {a}, {b} and {c} will be substituted by the value of these variables:


::{a}''x''<sup>2</sup> + {b}''x'' + {c} = 0
::{a}''x''<sup>2</sup> + {b}''x'' + {c} = 0


TeX
<pre style="font-size:113%;width: 98%;">
<pre style="font-size:113%;width: 98%;margin-top:-5px;">
\( {a} x^2 + {b} x + {c} = 0 \)
</pre>
 
MathML
<pre style="font-size:113%;width: 98%;margin-top:-5px;">
«math xmlns=¨http://www.w3.org/1998/Math/MathML¨»«mn»{a}«/mn»«msup»«mi»x«/mi»«mn»2«/mn»«/msup»«mo»+«/mo»«mn»{b}«/mn»«mi»x«/mi»«mo»+«/mo»«mn»{c}«/mn»«mo»=«/mo»«mn»0«/mn»«/math»
«math xmlns=¨http://www.w3.org/1998/Math/MathML¨»«mn»{a}«/mn»«msup»«mi»x«/mi»«mn»2«/mn»«/msup»«mo»+«/mo»«mn»{b}«/mn»«mi»x«/mi»«mo»+«/mo»«mn»{c}«/mn»«mo»=«/mo»«mn»0«/mn»«/math»
</pre>
</pre>


MathML equations are usually created with the aid of an editor. When creating the equation, write a number, say 99, in lieu of the variables, for example:
MathML equations are usually created with the aid of an editor. When creating the equation, it is easier to write a number, say 99, in lieu of the variables, for example:


<pre style="font-size:113%;width: 98%;margin-top:-5px;">
<pre style="font-size:113%;width: 98%;margin-top:-5px;">
Line 56: Line 50:
</pre>
</pre>
and then replace the numbers 99 by the variables {a}, {b} and {c} in the HTML code.
and then replace the numbers 99 by the variables {a}, {b} and {c} in the HTML code.
AsciiMath
<pre style="font-size:113%;width: 98%;margin-top:-5px;">
`{a} x^2 + {b} x + {c} = 0`
<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=AM_HTMLorMML"></script>
</pre>


</div>
</div>
Line 68: Line 56:
<div style="font-family:Lucida Sans Unicode;font-size:113%;color:#6c336d;margin:10px 0 10px;> Example</div>
<div style="font-family:Lucida Sans Unicode;font-size:113%;color:#6c336d;margin:10px 0 10px;> Example</div>


Write the following equation in the TeX, MathML and AsciiMath syntaxes, where {a}, {b} and {c} will be substituted by the value of these variables:
Write the following equation in the AsciiMath syntax, where {a}, {b} and {c} will be substituted by the value of these variables:


::{a}''x''<sup>2</sup> + {b}''x'' + {c} = 0
::{a}''x''<sup>2</sup> + {b}''x'' + {c} = 0


TeX
<pre style="font-size:113%;width: 98%;">
<pre style="font-size:113%;width: 98%;margin-top:-5px;">
\( {a} x^2 + {b} x + {c} = 0 \)
</pre>
 
MathML
<pre style="font-size:113%;width: 98%;margin-top:-5px;">
«math xmlns=¨http://www.w3.org/1998/Math/MathML¨»«mn»{a}«/mn»«msup»«mi»x«/mi»«mn»2«/mn»«/msup»«mo»+«/mo»«mn»{b}«/mn»«mi»x«/mi»«mo»+«/mo»«mn»{c}«/mn»«mo»=«/mo»«mn»0«/mn»«/math»
</pre>
 
MathML equations are usually created with the aid of an editor. When creating the equation, write a number, say 99, in lieu of the variables, for example:
 
<pre style="font-size:113%;width: 98%;margin-top:-5px;">
    «math style=¨font-family:Arial¨ xmlns=¨http://www.w3.org/1998/Math/MathML¨»«mstyle mathsize=¨17px¨»«mn»99«/mn»«msup»«mi»x«/mi»«mn»2«/mn»«/msup»«mo»+«/mo»«mn»99«/mn»«mi»x«/mi»«mo»+«/mo»«mn»99«/mn»«mo»=«/mo»«mn»0«/mn»«/mstyle»«/math»
</pre>
and then replace the numbers 99 by the variables {a}, {b} and {c} in the HTML code.
 
AsciiMath
<pre style="font-size:113%;width: 98%;margin-top:-5px;">
`{a} x^2 + {b} x + {c} = 0`
`{a} x^2 + {b} x + {c} = 0`
<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=AM_HTMLorMML"></script>
<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=AM_HTMLorMML"></script>

Revision as of 06:19, 4 December 2017

< Formulas question type

Using variables in text

It is simple to substitute the variables in the text, you only need to enclose the corresponding variables with { }. Each text field has a scope of variables. All variables x of either number or string in the scope of the text can be used to replace the corresponding placeholder {x} in the text.

It is also possible to evaluate an expression directly in the text by adding an equal sign at the beginning of the bracket such as {=x/1000}. It is easier to use if the named variables are not required. However, no error check is done unless the question is being instantiated in the quiz. An example is the rescaling of meters to kilometers below:

What is the speed of the rocket if it travels with distance {=x/1000} km in {t} s?

Using variables in text equations

Text equations are equations that are displayed in the text using an equation syntax such as:

  • TeX
  • MathML
  • AsciiMath

Variables can be substituted in these equations, as in the text, by enclosing them with {}. Expressions such as {=x/1000} can also be substituted in these equations.

Example

Write the following equation in the TeX syntax, where {a}, {b} and {c} will be substituted by the value of these variables:

{a}x2 + {b}x + {c} = 0
\( {a} x^2 + {b} x + {c} = 0 \)
Example

Write the following equation in the MathML syntax, where {a}, {b} and {c} will be substituted by the value of these variables:

{a}x2 + {b}x + {c} = 0
«math xmlns=¨http://www.w3.org/1998/Math/MathML¨»«mn»{a}«/mn»«msup»«mi»x«/mi»«mn»2«/mn»«/msup»«mo»+«/mo»«mn»{b}«/mn»«mi»x«/mi»«mo»+«/mo»«mn»{c}«/mn»«mo»=«/mo»«mn»0«/mn»«/math»

MathML equations are usually created with the aid of an editor. When creating the equation, it is easier to write a number, say 99, in lieu of the variables, for example:

    «math style=¨font-family:Arial¨ xmlns=¨http://www.w3.org/1998/Math/MathML¨»«mstyle mathsize=¨17px¨»«mn»99«/mn»«msup»«mi»x«/mi»«mn»2«/mn»«/msup»«mo»+«/mo»«mn»99«/mn»«mi»x«/mi»«mo»+«/mo»«mn»99«/mn»«mo»=«/mo»«mn»0«/mn»«/mstyle»«/math»

and then replace the numbers 99 by the variables {a}, {b} and {c} in the HTML code.

Example

Write the following equation in the AsciiMath syntax, where {a}, {b} and {c} will be substituted by the value of these variables:

{a}x2 + {b}x + {c} = 0
`{a} x^2 + {b} x + {c} = 0`
<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=AM_HTMLorMML"></script>

< Formulas question type