<latex>

A snippet of LaTeX that can be rendered as math

<latex> is a Text component that stores a LaTeX-formatted string. It is equivalent to <text> with the isLatex attribute defaulted to true.

The primary reason <latex> exists is that the latex property of a <math> (or any math-valued component) returns a <latex>. That makes round-tripping through the LaTeX form natural: a reference like $myMath.latex is itself a <latex>, and feeding it back into a <math> produces the original expression — without having to set format="latex" on the outer <math>.

<latex> is rarely useful as a display tag — <m>, <me>, and <md> always parse their children as LaTeX, so for typeset output they do the job whether you wrap the LaTeX in <latex>, in <text>, or leave it bare. <latex> becomes distinguishable from <text> only when the surrounding context is going to parse the content, not just render it. The canonical such context is a <math>.

How <math> consumes a <latex> child

Each text-like child of a <math> parses its own value with its own parser before being incorporated as a math sub-expression: a <latex> (or any <text> with isLatex="true") uses the LaTeX parser, a plain <text> uses the text parser. This is independent of the outer <math>’s format attribute, which only controls how the outer math parses its own string content.

So <math><latex>…</latex></math> parses the contents as LaTeX even though the outer <math>’s format is still its default "text".

Attributes and Properties

Attributes for <latex>

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: true. 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 <latex name="l">

Positioning (2)
$l.anchor

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

$l.positionFromAnchor

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

Other (21)
$l.backgroundColor

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

$l.characters

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

$l.disabled

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

$l.draggable

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

$l.fixed

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

$l.fixLocation

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

$l.hidden

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

$l.isLatex

boolean. Whether the text content is treated as LaTeX.

$l.latex

latex. The LaTeX content as a string.

$l.layer

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

$l.list

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

$l.math

math. The text parsed as a math expression.

$l.number

number. The text parsed as a number.

$l.numCharacters

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

$l.numListItems

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

$l.numWords

integer. The number of words in the text value.

$l.text

text. The text rendered as a plain text string.

$l.textColor

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

$l.textStyleDescription

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

$l.value

latex. The text value.

$l.words

[ text ]. The text value split into words.

Common to all components (4)
$l.doenetML

text. The DoenetML source code that produced this component.

$l.hide

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

$l.isResponse

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

$l.styleNumber

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

Examples

Example: Round-trip math → latex → math

The first two paragraphs show the original expression and its LaTeX-formatted string. The third places $m.latex (which is a <latex> component) inside a <math>. The outer <math> has no format attribute, yet the round trip works: the <latex> child uses the LaTeX parser to convert its own contents back into a math expression, which the outer <math> then incorporates.


Example: Why a plain <text> does not round-trip

Wrapping $m.latex in a <text> instead of a <latex> loses the isLatex flag. The <text> parses its own value using its own isLatex setting (false by default), so the text parser tries to read the LaTeX string and fails — the result renders as a blank box, _. Setting format="latex" on the outer <math> does not help, because that attribute only controls how the outer math parses its own string content; the <text> child is still parsed by the <text>’s own parser. The real fix is to mark the child as LaTeX — either with isLatex="true" on the <text>, or by using a <latex>, which is just that case spelled more concisely.


Example: Reuse one LaTeX string in multiple places

A named <latex> value can be referenced anywhere a text or math component is accepted. The <math> parses the LaTeX into an expression (via the round-trip mechanism above); <me> renders it as display math. Storing the LaTeX once keeps every consumer in sync.