> ## Documentation Index
> Fetch the complete documentation index at: https://docsa.stemfard.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Stemfard step output formats: HTML, LaTeX, and speech

> Request Stemfard step-by-step solutions in HTML, LaTeX, or speech format and combine multiple output formats in a single API call.

Stemfard can return step-by-step solutions in multiple formats so you can render them however your application requires. Whether you are building a web UI that needs HTML markup, a document system that requires LaTeX typesetting, or an accessibility feature that feeds output to a text-to-speech engine, you control the format through the `steps_output_formats` request parameter.

## Requesting output formats

Set `steps_output_formats` to an array of one or more format strings in your request body. The `steps` array in the response will then include content rendered in each format you specified.

<Tip>
  You can request multiple formats in a single call by passing more than one value in the array — for example, `"steps_output_formats": ["html", "latex"]`. The API returns all requested formats together, so you only need one round-trip regardless of how many formats your application uses.
</Tip>

## The three formats

<Tabs>
  <Tab title="html">
    The `html` format wraps mathematical expressions and step text in standard HTML markup. Use this when you are rendering solutions directly into a web page without a dedicated math typesetting library.

    **Request:**

    ```bash cURL theme={null}
    curl --request POST \
      --url https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/add \
      --header 'Authorization: Bearer YOUR_API_KEY' \
      --header 'Content-Type: application/json' \
      --data '{
        "a": [[1, 2], [3, 4]],
        "b": [[5, 6], [7, 8]],
        "api_level": "standard",
        "steps_output_formats": ["html"]
      }'
    ```

    **Example step output:**

    ```json html step output theme={null}
    {
      "step": 1,
      "description": "Add corresponding elements of matrices A and B",
      "expression": "<p>sum[i][j] = A[i][j] + B[i][j]</p><p>sum = <strong>[[6, 8], [10, 12]]</strong></p>"
    }
    ```
  </Tab>

  <Tab title="latex">
    The `latex` format returns expressions as LaTeX strings, ready for rendering with MathJax, KaTeX, or any compatible typesetting library. Use this when your platform displays publication-quality mathematical notation.

    **Request:**

    ```bash cURL theme={null}
    curl --request POST \
      --url https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/add \
      --header 'Authorization: Bearer YOUR_API_KEY' \
      --header 'Content-Type: application/json' \
      --data '{
        "a": [[1, 2], [3, 4]],
        "b": [[5, 6], [7, 8]],
        "api_level": "standard",
        "steps_output_formats": ["latex"]
      }'
    ```

    **Example step output:**

    ```json latex step output theme={null}
    {
      "step": 1,
      "description": "Add corresponding elements of matrices A and B",
      "expression": "\\begin{pmatrix}1&2\\\\3&4\\end{pmatrix} + \\begin{pmatrix}5&6\\\\7&8\\end{pmatrix} = \\begin{pmatrix}6&8\\\\10&12\\end{pmatrix}"
    }
    ```
  </Tab>

  <Tab title="speech">
    The `speech` format returns plain text written for text-to-speech engines. Symbols and operators are spelled out in natural language so screen readers and TTS systems can pronounce them correctly without preprocessing.

    **Request:**

    ```bash cURL theme={null}
    curl --request POST \
      --url https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/add \
      --header 'Authorization: Bearer YOUR_API_KEY' \
      --header 'Content-Type: application/json' \
      --data '{
        "a": [[1, 2], [3, 4]],
        "b": [[5, 6], [7, 8]],
        "api_level": "standard",
        "steps_output_formats": ["speech"]
      }'
    ```

    **Example step output:**

    ```json speech step output theme={null}
    {
      "step": 1,
      "description": "Add corresponding elements of matrices A and B",
      "expression": "Add each element of matrix A to the corresponding element of matrix B. Row 1: 1 plus 5 equals 6, 2 plus 6 equals 8. Row 2: 3 plus 7 equals 10, 4 plus 8 equals 12."
    }
    ```
  </Tab>
</Tabs>

## Combining multiple formats

You can include any combination of `html`, `latex`, and `speech` in a single request. Each step in the response will contain the expression rendered in every format you requested.

```bash cURL (all three formats) theme={null}
curl --request POST \
  --url https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/add \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
    "a": [[1, 2], [3, 4]],
    "b": [[5, 6], [7, 8]],
    "api_level": "standard",
    "steps_output_formats": ["html", "latex", "speech"]
  }'
```

```json multi-format step output theme={null}
{
  "step": 1,
  "description": "Add corresponding elements of matrices A and B",
  "expression_html": "<p>sum[i][j] = A[i][j] + B[i][j]</p><p>sum = <strong>[[6, 8], [10, 12]]</strong></p>",
  "expression_latex": "\\begin{pmatrix}1&2\\\\3&4\\end{pmatrix} + \\begin{pmatrix}5&6\\\\7&8\\end{pmatrix} = \\begin{pmatrix}6&8\\\\10&12\\end{pmatrix}",
  "expression_speech": "Add each element of matrix A to the corresponding element of matrix B. The result is 6, 8 in the first row and 10, 12 in the second row."
}
```

## Including background theory

Set `steps_bg: true` in your request to include background theory notes alongside each step. These notes explain the mathematical rule or concept being applied, which is useful for learners who need more context than the step expression alone provides.

```bash cURL (with background theory) theme={null}
curl --request POST \
  --url https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/matmul \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
    "a": [[1, 2], [3, 4]],
    "b": [[5, 6], [7, 8]],
    "api_level": "standard",
    "steps_output_formats": ["latex"],
    "steps_bg": true
  }'
```

When `steps_bg` is enabled, each step object includes an additional `background` field:

```json step with background theory theme={null}
{
  "step": 1,
  "description": "Multiply row 1 of A by column 1 of B",
  "expression": "(1 \\cdot 5) + (2 \\cdot 7) = 19",
  "background": "Matrix multiplication computes the dot product of each row in A with each column in B. The element at position (i, j) in the result equals the sum of products of row i from A and column j from B."
}
```

<Note>
  `steps_bg` requires `api_level` to be `"standard"` or `"detailed"`, since `lite` responses do not include a `steps` array.
</Note>

## Parameter reference

<AccordionGroup>
  <Accordion title="steps_output_formats">
    **Type:** `string[]`

    **Default:** `[""]` (no formatted output)

    An array of format identifiers controlling how step expressions are rendered. Accepted values are `"html"`, `"latex"`, and `"speech"`. Pass an empty array or omit the parameter to receive steps without a specific output format applied.
  </Accordion>

  <Accordion title="steps_bg">
    **Type:** `boolean`

    **Default:** `true`

    When `true`, each step object includes a `background` field containing an explanation of the mathematical concept or rule used in that step. Requires `api_level: "standard"` or `api_level: "detailed"`.
  </Accordion>
</AccordionGroup>
