ReferenceextractMathOperator

<extractMathOperator>

Returns the top-level operator of a math expression as text (e.g. "+", "vector")

<extractMathOperator> returns the top-level operator of a math expression as a text value. For a sum it returns "+", for a product "*", for an equation "=", for a vector "vector", and so on. If the expression is a single value (number, variable, or constant) with no top-level operator, the result is the empty string.

Unlike <extractMath>, which pulls out operands or function names and returns them as math expressions, <extractMathOperator> returns the operator itself as plain text — useful for branching on the kind of expression you have.

Attributes and Properties

Attributes for <extractMathOperator>

Positioning (2)
anchor

point. Default value: \(\left( 0, 0 \right)\). Coordinates of the anchor point used to position this component on a graph.

positionFromAnchor

keyword. Where this component sits relative to its anchor point.

ValueDescription
upperRightPlace the component above and to the right of the anchor point.
upperLeftPlace the component above and to the left of the anchor point.
lowerRightPlace the component below and to the right of the anchor point.
lowerLeftPlace the component below and to the left of the anchor point.
topPlace the component directly above the anchor point.
bottomPlace the component directly below the anchor point.
leftPlace the component directly to the left of the anchor point.
rightPlace the component directly to the right of the anchor point.
center (default)Center the component on the anchor point.
Other (3)
draggable

boolean. Default value: true. Whether the text can be dragged on a graph.

isLatex

boolean. Default value: false. Whether the text content is treated as LaTeX.

layer

number. Default value: 0. Z-order layer index when shown on a graph.

Common to all components (9)
copy

reference. Create an independent copy of another component by reference. Enter a references a $name.

disabled

boolean. Default value: false. Whether this component is disabled and cannot be interacted with.

extend

reference. Extend another component by reference, inheriting its children and attributes. Enter a reference as $name.

fixed

boolean. Default value: false. Whether this component's value is fixed and cannot be modified.

fixLocation

boolean. Default value: false. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).

hide

boolean. Default value: false. Whether to hide this component from the rendered output.

isResponse

boolean. Default value: false. Whether this component is treated as a response for the purposes of assessment.

name

text. The name used to reference this component from elsewhere in the document.

styleNumber

integer. Default value: 1. The style number used to select this component's visual styling from the available style definitions.

Properties for <extractMathOperator name="e">

Positioning (2)
$e.anchor

point. The coordinates where this component is anchored on the graph.

$e.positionFromAnchor

text. Where this component sits relative to its anchor point.

Other (20)
$e.backgroundColor

text. Human-readable name for this component's background color, derived from the active style and theme.

$e.characters

[ text ]. The text value split into characters (graphemes).

$e.disabled

boolean. Whether this component is disabled and cannot be interacted with.

$e.draggable

boolean. Whether the text can be dragged on a graph.

$e.fixed

boolean. Whether this component's value is fixed and cannot be modified.

$e.fixLocation

boolean. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).

$e.hidden

boolean. Whether this component is hidden from the rendered output.

$e.isLatex

boolean. Whether the text content is treated as LaTeX.

$e.layer

number. Z-order layer index when shown on a graph.

$e.list

[ text ]. The text value split into items at commas.

$e.math

math. The text parsed as a math expression.

$e.number

number. The text parsed as a number.

$e.numCharacters

integer. The number of characters (graphemes) in the text value.

$e.numListItems

integer. The number of comma-separated items when the text is interpreted as a list.

$e.numWords

integer. The number of words in the text value.

$e.text

text. The text rendered as a plain text string.

$e.textColor

text. Human-readable name for this component's text color, derived from the active style and theme.

$e.textStyleDescription

text. Human-readable description of this component's text styling (color and any background color).

$e.value

text. The text result of applying this operator to its child math values.

$e.words

[ text ]. The text value split into words.

Common to all components (4)
$e.doenetML

text. The DoenetML source code that produced this component.

$e.hide

boolean. Whether to hide this component from the rendered output.

$e.isResponse

boolean. Whether this component is treated as a response for the purposes of assessment.

$e.styleNumber

integer. The style number used to select this component's visual styling from the available style definitions.

Examples

Example: Operator of a sum, product, and equation

For each expression the top-level operator (+, *, or =) is returned as text. The result of <extractMathOperator> is a regular <text> value, so it can be compared, displayed, or used in a condition.


Example: Operator from a <mathInput>

The operator updates live as the learner edits the input — try entering a vector (1,2,3), a function call f(x), a power x^2, or just a single number to see how the operator changes.


Example: Branch on the kind of expression

Comparing the result of <extractMathOperator> against string literals lets <conditionalContent> show different content for different kinds of expressions.