# `Expresso.Element.Math`
[🔗](https://github.com/rellen/expresso/blob/main/lib/expresso/element/math.ex#L1)

An element that shows a formula in MathML

The `math` entity takes the formula in one of two forms:

- The MathML as its first argument, from the `<math>` tag to the `</math>`
  tag. Give the `math` tag the attribute `display="block"` for a formula on
  its own line, which is the usual form on a slide.
- The LaTeX in the `tex` option. `typeset/1` makes the MathML with
  `Expresso.Element.Math.Tex`, in one run of Node for the deck.

A browser renders MathML Core without a script and without a font file, and
each browser of the floor of this project supports it. The text goes into
the document as it is, as the text of a text area does.
`docs/math-parts.md` gives the design of the LaTeX.

# `t`

```elixir
@type t() :: %Expresso.Element.Math{
  __spark_metadata__: term(),
  at: term(),
  class: term(),
  easing: term(),
  effect: term(),
  el: term(),
  elements: term(),
  line_names: term(),
  lines: term(),
  morph: term(),
  on: term(),
  reveal: term(),
  rewrite_lines: term(),
  signature: term(),
  speed: term(),
  steps: term(),
  tex: term(),
  text: term(),
  two_step_lines: term()
}
```

The struct of a math element

# `check`

```elixir
@spec check(t()) :: {:ok, t()} | {:error, String.t()}
```

Check a math element, and write its lines into one formula

A math element has one source: the MathML, the `tex` option, or `line`
entities. The function writes the lines into the LaTeX of one formula of the
environment `aligned`, a row for each line, with the relation, the term and
the reason in three columns. A `rewrite` entity becomes a line first, with
`Expresso.Element.Math.Rewrite.expand/1`. Each line becomes a part with its name, and
with `reveal true` it shows at its own step. The function then checks the
name of each `\part{name}{…}` and `\id{name}{…}` of the LaTeX. The entity of
the DSL and `Expresso.Builder` call this function.

# `get_assigns`

```elixir
@spec get_assigns(t()) :: map()
```

Make the assigns of the render function from the struct

The key `overlay` holds the attributes of the overlay contract, from
`Expresso.Overlay.Render.attributes/1`.

# `parts`

```elixir
@spec parts(String.t()) :: [String.t()]
```

Give the names of the parts of the MathML of a formula, in the order of the
MathML, without a repeat

A part has a name in the attribute `data-part`, from `\part{name}{…}`, or
in the attribute `class`, from `\class{name}{…}`. The list also holds the
classes that Temml writes, such as `tml-display`.

    iex> Expresso.Element.Math.parts(~s(<math class="tml-display"><mrow data-part="redex"><mi class="bind">f</mi></mrow></math>))
    ["tml-display", "redex", "bind"]

# `place`

```elixir
@spec place(Expresso.Deck.t()) :: Expresso.Deck.t()
```

Replace each `move_to` of the parts of a deck with a move that the browser
measures

An `on` entity of a part of a formula can take `move_to`, the name of a
different part of the same formula. The place of a part comes from the
fonts of the browser, so the render cannot measure it. This function puts
`x: "var(--to-x-name)"` and `y: "var(--to-y-name)"` into `set`, and the
presenter script gives the part these two custom properties: the distance
from the center of the part to the center of the part `name`. A browser
with no script then shows the part at its place.

`Expresso.Renderer` calls this function after `typeset/1`. It raises for a
name that the formula does not have, and for a part that moves to itself.

# `render`

```elixir
@spec render(map()) :: Phoenix.HTML.safe()
```

Make the HTML of a math element

The MathML goes into one block element inside the root tag.

# `typeset`

```elixir
@spec typeset(Expresso.Deck.t(), ([String.t()] -&gt;
                              [Expresso.Element.Math.Tex.result()])) ::
  Expresso.Deck.t()
```

Make the MathML of each math element of a deck with the `tex` option

`Expresso.Renderer` calls this function before the render. One run of Node
makes the MathML of each formula of the deck, and the watch mode keeps the
MathML of each source from one render to the next, so a change of one slide
runs Node for the formulas that changed. A deck with no LaTeX runs no Node.

`render` makes the MathML of a list of sources. The default is
`Expresso.Element.Math.Tex.render!/1`, and a test can give a function that
needs no Node. The function raises an `ArgumentError` with the message of
Temml for a source that Temml cannot read.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
