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: Formulas: Variables in text and text equations.

Formulas: Variables in text and text equations: Difference between revisions

From MoodleDocs
(12 intermediate revisions by the same user not shown)
Line 3: Line 3:
==Using variables in the text==
==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 <span style="font-family:monospace;font-size:113%;">{ }</span>. 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 <span style="font-family:monospace;font-size:113%;">{x}</span> 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 <span style="font-family:monospace;font-size:113%;">{}</span>. Each text field has a scope of variables. All variables <span style="font-family:monospace;font-size:113%;">x</span> of either number or string in the scope of the text can be used to replace the corresponding placeholder <span style="font-family:monospace;font-size:113%;">{x}</span> 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 <span style="font-family:monospace;font-size:113%;">{=x/1000}</span>. 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:
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 <span style="font-family:monospace;font-size:113%;">{=x/1000}</span>. 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:


<pre style="font-size:113%;width: 98%;">
<pre style="font-size:113%;width: 97%;">
What is the speed of the rocket if it travels with distance {=x/1000} km in {t} s?
What is the speed of the rocket if it travels with distance {=x/1000} km in {t} s?
</pre>
</pre>
Line 14: Line 14:


Text equations are mathematical expressions or equations that are displayed in the text using math syntax such as:
Text equations are mathematical expressions or equations that are displayed in the text using math syntax such as:
*[http://www.tug.org/ TeX]
*'''[http://www.tug.org/ TeX]'''
*[https://www.w3.org/TR/MathML3/ MathML]
*'''[https://www.w3.org/TR/MathML3/ MathML]'''
*[http://asciimath.org/ AsciiMath]
*'''[http://asciimath.org/ AsciiMath]'''


See [https://docs.moodle.org/32/en/Mathematics#Equation_Construction_and_Display Equation Construction and Display] for additional information on writing mathematical expressions.  
See [https://docs.moodle.org/33/en/Mathematics#Equation_Construction_and_Display '''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.
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 <span style="font-family:monospace;font-size:113%;">{}</span>. Values of expressions such as <span style="font-family:monospace;font-size:113%;">{=x/1000}</span> can also be inserted.


<div style="border:1px solid #bce8f1;border-radius:4px;padding: 0px 15px 0px; margin:20px 0 25px;">
<div style="border:1px solid #bce8f1;border-radius:4px;padding: 0px 15px 0px; margin:20px 0 25px;">
<div style="font-family:Lucida Sans Unicode;font-size:150%;color:#f98012;margin:10px 0 10px;>Example</div>
<div style="font-family:Lucida Sans Unicode;font-size:150%;color:#f98012;margin:10px 0 10px;>Example</div>


Write the following equation in TeX syntax. Upon display, {a}, {b} and {c} will be substituted by the value of these variables:
Write the following equation in '''TeX''' syntax. Upon display, <span style="font-family:monospace;font-size:113%;">{a}</span>, <span style="font-family:monospace;font-size:113%;">{b}</span> and <span style="font-family:monospace;font-size:113%;">{c}</span> 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


<pre style="font-size:113%;width: 98%;>
<pre style="font-size:113%;width: 97%;">
\( {a} x^2 + {b} x + {c} = 0 \)
\( {a} x^2 + {b} x + {c} = 0 \)
</pre>
</pre>
Line 38: Line 38:
<div style="font-family:Lucida Sans Unicode;font-size:150%;color:#f98012;margin:10px 0 10px;>Example</div>
<div style="font-family:Lucida Sans Unicode;font-size:150%;color:#f98012;margin:10px 0 10px;>Example</div>


Write the following equation in MathML syntax. Upon display, {a}, {b} and {c} will be substituted by the value of these variables:
Write the following equation in '''MathML''' syntax. Upon display, <span style="font-family:monospace;font-size:113%;">{a}</span>, <span style="font-family:monospace;font-size:113%;">{b}</span> and <span style="font-family:monospace;font-size:113%;">{c}</span> 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


<pre style="font-size:113%;width: 98%;">
<pre style="font-size:113%;width: 97%;">
«math xmlns=¨http://www.w3.org/1998/Math/MathML¨»
«math xmlns=¨http://www.w3.org/1998/Math/MathML¨»
   «mn»{a}«/mn»
   «mn»{a}«/mn»
Line 55: Line 55:
«/math»
«/math»
</pre>
</pre>
</div>
<div style="border:1px solid #bce8f1;border-radius:4px;padding: 0px 15px 0px; margin:20px 0 25px;">
<div style="font-family:Lucida Sans Unicode;font-size:150%;color:#f98012;margin:10px 0 10px;>Tip</div>


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:
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:


<pre style="font-size:113%;width: 98%;margin-top:0px;">
<pre style="font-size:113%;width: 97%;margin-top:0px;">
«math xmlns=¨http://www.w3.org/1998/Math/MathML¨»
«math xmlns=¨http://www.w3.org/1998/Math/MathML¨»
   «mn»99«/mn»
   «mn»99«/mn»
Line 78: Line 83:
<div style="font-family:Lucida Sans Unicode;font-size:150%;color:#f98012;margin:10px 0 10px;>Example</div>
<div style="font-family:Lucida Sans Unicode;font-size:150%;color:#f98012;margin:10px 0 10px;>Example</div>


Write the following equation in the AsciiMath syntax. Upon display, {a}, {b} and {c} will be substituted by the value of these variables:
Write the following equation in the '''AsciiMath''' syntax. Upon display, <span style="font-family:monospace;font-size:113%;">{a}</span>, <span style="font-family:monospace;font-size:113%;">{b}</span> and <span style="font-family:monospace;font-size:113%;">{c}</span> 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


<pre style="font-size:113%;width: 98%;">
<pre style="font-size:113%;width: 97%;">
<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>
`{a} x^2 + {b} x + {c} = 0`
`{a} x^2 + {b} x + {c} = 0`
Line 91: Line 96:
<div style="font-family:Lucida Sans Unicode;font-size:150%;color:#f98012;margin:10px 0 10px;>Example</div>
<div style="font-family:Lucida Sans Unicode;font-size:150%;color:#f98012;margin:10px 0 10px;>Example</div>


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.
Use variables and expressions in the equations of the main question text, the general feedback and the part's feedback. Use MathML syntax.
 
''Downloadable question file:'' [https://drive.google.com/open?id=1MVUhvncCMHYl3LM-XpklggV-bpku5L8v QuadraticEquation.xml]


This Formulas question looks like this:
This Formulas question looks like this:
Line 100: Line 103:


<div style="margin:20px 0 20px;">
<div style="margin:20px 0 20px;">
[http://35.193.77.29/mod/quiz/view.php?id=125 <span style="background-color:#f98012;box-shadow: 0 5px 10px #cbcbcb;border: none;color:white;padding: 8px 16px;text-align:center;text-decoration: none;cursor:pointer;">Play it</span>]
<span style="background-color:#f98012;box-shadow: 0 5px 10px #cbcbcb;border: none;color:white;padding: 8px 16px;text-align:center;text-decoration: none;cursor:pointer;">[http://35.193.77.29/mod/quiz/view.php?id=125 <span style="color:white;">Play it </span>]</span>   [[Formulas_question_type#Examples|Login info ↗]]  ''(Open in new tab: Ctrl+Shift+Click)''
</div>
</div>



Revision as of 05:56, 20 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.

Example

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 \)
Example

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»
Tip

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.

Example

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`
Example

Use variables and expressions in the equations of the main question text, the general feedback and the part's feedback. Use MathML syntax.

This Formulas question looks like this:

QuadraticEquation.png

Play it    Login info ↗  (Open in new tab: Ctrl+Shift+Click)


Back to top of page

← FORMULAS QUESTION TYPE

In other languages

Español
Français