get_equation
Extract a specific equation from a Word document by index to obtain its LaTeX representation and optional OMML XML data.
Instructions
Get a specific equation by index from a Word document.
Args: filepath: Path to the document equation_index: Index of the equation (0-based) include_omml: If True, include the raw OMML XML
Returns: Dictionary with equation details including LaTeX representation
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filepath | Yes | ||
| equation_index | Yes | ||
| include_omml | No |
Implementation Reference
- src/docx_mcp/server.py:1062-1111 (handler)Implementation of the get_equation tool handler, which fetches specific equation details from a document.
def get_equation(filepath: str, equation_index: int, include_omml: bool = False) -> dict[str, Any]: """ Get a specific equation by index from a Word document. Args: filepath: Path to the document equation_index: Index of the equation (0-based) include_omml: If True, include the raw OMML XML Returns: Dictionary with equation details including LaTeX representation """ logger.info( "Getting equation", extra={"tool": "get_equation", "filepath": filepath, "index": equation_index}, ) try: equations = extract_equations(filepath) if equation_index < 0 or equation_index >= len(equations): raise InvalidParameterError( "equation_index", f"Index {equation_index} out of range (0-{len(equations)-1})", ) eq = equations[equation_index] result = { "status": "success", "filepath": filepath, "equation": { "index": eq["index"], "paragraph_index": eq["paragraph_index"], "type": eq["type"], "latex": eq["latex"], "context": eq["context"], }, } if include_omml: result["equation"]["omml"] = eq["omml"] return result except DocxMcpError as e: logger.warning(e.message, extra={"tool": "get_equation", "error_code": e.error_code}) return {"status": "error", "error": e.message, "error_code": e.error_code} except Exception as e: logger.error(f"Unexpected error getting equation: {str(e)}") return {"status": "error", "error": str(e)} - src/docx_mcp/server.py:1061-1062 (registration)Registration of the get_equation tool using the @app.tool() decorator.
@app.tool() def get_equation(filepath: str, equation_index: int, include_omml: bool = False) -> dict[str, Any]: