Skip to main content
Glama

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
NameRequiredDescriptionDefault
filepathYes
equation_indexYes
include_ommlNo

Implementation Reference

  • 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)}
  • 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]:

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Andrew82106/LLM_Docx_Agent_MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server