Formulas: Variables in text and text equations: Difference between revisions
No edit summary |
|||
Line 111: | Line 111: | ||
===In other languages=== | ===In other languages=== | ||
[https://docs.moodle.org/all/es/ | [https://docs.moodle.org/all/es/F%C3%B3rmulas:_Variables_en_el_texto_y_en_las_ecuaciones_del_texto Español]<br> | ||
[https://docs.moodle.org/3x/fr/Formules:_Variables_dans_le_texte_et_dans_les_équations_du_texte Français] | [https://docs.moodle.org/3x/fr/Formules:_Variables_dans_le_texte_et_dans_les_équations_du_texte Français] |
Revision as of 05:07, 8 January 2018
Using variables in the text
It is easy to insert values of variables directly in the text. All that is needed is to enclose the variable names 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 and insert its value directly in the text by adding an equal sign at the beginning of the bracket such as {=x/1000}. This way is simpler 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 mathematical expressions or equations that are displayed in the text using math syntax such as:
See Equation Construction and Display for additional information on writing mathematical expressions.
Values of variables can be inserted in text equations in the same way as in the text, that is, by enclosing the variable names with {}. Values of expressions such as {=x/1000} can also be inserted.
Write the following equation in TeX syntax. Upon display, {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 \)
Write the following equation in MathML syntax. Upon display, {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 with an editor, it is easier to write a number, say 99, in lieu of the variables, for example:
«math xmlns=¨http://www.w3.org/1998/Math/MathML¨» «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» «/math»
and then replace the numbers 99 by the variables {a}, {b} and {c} in the HTML code.
Write the following equation in the AsciiMath syntax. Upon display, {a}, {b} and {c} will be substituted by the value of these variables:
- {a}x2 + {b}x + {c} = 0
<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=AM_HTMLorMML"></script> `{a} x^2 + {b} x + {c} = 0`
Use variables and expressions in text equations that appear in the main question text, the general feedback and the part's feedback of a Formulas question. Use MathML syntax.
Downloadable question file: QuadraticEquation.xml
This Formulas question looks like this: