Simplify Math Document Creation with Texify's Image Conversion

26 Apr 2025
Simplify Math Document Creation with Texify's Image Conversion

In today's fast-paced digital world, sharing and editing mathematical documents can be cumbersome, especially when dealing with images or PDFs that contain mathematical content. Texify offers a powerful solution with its Cognitive Actions, specifically designed to convert math images into easily editable formats like LaTeX and Markdown. This streamlines the process for developers, educators, and researchers alike, allowing for faster collaboration and improved accessibility of mathematical documents.

Prerequisites

To get started with Texify's Cognitive Actions, you'll need an API key for authentication and a basic understanding of how to make API calls.

Convert Math Images to LaTeX and Markdown

This action allows you to convert images or PDFs containing mathematical content into Markdown and LaTeX formats that can be rendered by MathJax. This feature not only simplifies the editing process but also enhances the sharing capabilities of mathematical documents, making it easier for users to collaborate on complex mathematical concepts.

Input Requirements:

  • Image: A URI pointing to the input image is required. This image should contain the mathematical content you wish to convert.
  • isKatexCompatible: An optional boolean parameter that specifies whether the output should be compatible with KaTeX. By default, this is set to false.

Example Input:

{
  "image": "https://replicate.delivery/pbxt/KXEKe16MrgEhUAgdP2MTdTmicOzpDQXXMksjfwhZcNpMXHQN/0.png",
  "isKatexCompatible": false
}

Expected Output: The expected output will be a string formatted in LaTeX or Markdown, which can then be rendered by tools like MathJax. For instance, the output might look like this:

The potential $V_i$ of cell $\mathcal{C}_i$ centred at position $\mathbf{r}_i$ is related to the surface charge densities $\sigma_j$ of cells $\mathcal{C}_j$ $j\in[1,N]$ through the superposition principle as: $$V_i\,=\,\sum_{j=0}^{N}\,\frac{\sigma_j}{4\pi\varepsilon_0}\,\int_{\mathcal{C}_j}\frac{1}{\|\mathbf{r}_i-\mathbf{r}^{\prime}\|}\,\mathrm{d}^2\mathbf{r}^{\prime}\,=\,\sum_{j=0}^{N}\,Q_{ij}\,\sigma_j,$$ where the integral over the surface of cell $\mathcal{C}_j$ only depends on $\mathcal{C}_j$ shape and on the relative position of the target point $\mathbf{r}_i$ with respect to $\mathcal{C}_j$ location, as $\sigma_j$ is assumed constant over the whole surface of cell $\mathcal{C}_j$.

Use Cases for this specific action:

  • Academic Publishing: Researchers can convert their handwritten equations from scanned documents into editable formats for easy publication in journals.
  • Educational Tools: Educators can utilize this action to convert math problems from images into LaTeX format for online quizzes or instructional materials.
  • Collaborative Projects: Teams working on mathematical modeling can quickly share and edit mathematical expressions without needing to retype or redraw them.
import requests
import json

# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"

action_id = "2a18367b-e0b5-4e80-b37a-5a319bff5e33" # Action ID for: Convert Math Images to LaTeX and Markdown

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "image": "https://replicate.delivery/pbxt/KXEKe16MrgEhUAgdP2MTdTmicOzpDQXXMksjfwhZcNpMXHQN/0.png",
  "isKatexCompatible": false
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json",
    # Add any other required headers for the Cognitive Actions API
}

# Prepare the request body for the hypothetical execution endpoint
request_body = {
    "action_id": action_id,
    "inputs": payload
}

print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json=request_body
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully. Result:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body (non-JSON): {e.response.text}")
    print("------------------------------------------------")

Conclusion

Texify's Cognitive Actions, particularly the ability to convert math images to LaTeX and Markdown, significantly enhance the way mathematical content is handled. By simplifying the editing and sharing process, it empowers developers, educators, and researchers to focus on what truly matters—collaboration and innovation in their respective fields. Start integrating Texify into your projects today and experience the benefits of streamlined mathematical document creation!