Home/Tools/to_latex

Convert to LaTeX

Render an expression as a LaTeX string suitable for KaTeX/MathJax.

Endpoint: POST /api/v1/to_latex

When to use

Render an expression as a LaTeX string for KaTeX/MathJax.

Input schema

Validated server-side with Zod. The same schema feeds OpenAPI and the MCP tool list.

{
  "type": "object",
  "properties": {
    "expression": {
      "type": "string",
      "minLength": 1,
      "description": "Expression to convert to LaTeX"
    }
  },
  "required": [
    "expression"
  ],
  "additionalProperties": false
}

Response shape

All tools return { ok: true, result } on success and { ok: false, error } on failure. The result object contains:

FieldTypeDescription
resultstringLaTeX source (no surrounding `$…$`).

Example

Request

{
  "expression": "(x+1)^2 / sqrt(y)"
}

Response

{
  "ok": true,
  "result": {
    "result": "\\frac{\\left(x+1\\right)^{2}}{\\sqrt{y}}"
  }
}

curl

curl -X POST https://tools.aieo.se/api/v1/to_latex \
  -H 'Content-Type: application/json' \
  -d '{"expression":"(x+1)^2 / sqrt(y)"}'

MCP call (JSON-RPC)

MCP clients call this tool as tools/call against /api/mcp:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "to_latex",
    "arguments": {
      "expression": "(x+1)^2 / sqrt(y)"
    }
  }
}

Common errors

  • A required field is missing or has the wrong type.
    Zod validation error, e.g. `Required` or `Expected string, received number`.
  • Nerdamer cannot parse the expression (unbalanced parens, unknown function, stray characters).
    `Unexpected token …` or `… is not a valid expression`.