mathpix-go

mathpix-go

A Go client library for the Mathpix API

mathpix-go ΒΆ

As an electrical engineering student passionate about integrating advanced technologies into software development, I created mathpix-go, a Go client library designed to interface with the Mathpix API. This project facilitates seamless integration of Mathpix’s Optical Character Recognition (OCR) capabilities into Go applications, enabling the conversion of images containing mathematical expressions into LaTeX code.

Key Features of mathpix-go:

  • Image-to-LaTeX Conversion: The library allows for the transformation of images with mathematical content into corresponding LaTeX representations, streamlining the process of digitizing complex equations.

  • Batch Processing: mathpix-go supports batch processing, enabling the submission of multiple images in a single request, which enhances efficiency when dealing with large datasets.

  • Asynchronous Operations: The library provides asynchronous processing capabilities, allowing applications to handle other tasks while awaiting the OCR results, thereby improving overall performance.

Installation:

To incorporate mathpix-go into your Go project, execute:

go get github.com/conneroisu/mathpix-go

Example Usage:

Below is a basic example demonstrating how to use mathpix-go to convert an image containing a mathematical expression into LaTeX code:

package main

import (
    "context"
    "fmt"
    "log"
    "os"

    "github.com/conneroisu/mathpix-go"
)

func main() {
    apiKey := "your_api_key"
    appID := "your_app_id"

    client := mathpix.NewClient(apiKey, appID)

    imagePath := "path_to_your_image.png"
    imageFile, err := os.Open(imagePath)
    if err != nil {
        log.Fatalf("failed to open image: %v", err)
    }
    defer imageFile.Close()

    request := &mathpix.ImageRequest{
        Src: imageFile,
    }

    response, err := client.Image(context.Background(), request)
    if err != nil {
        log.Fatalf("failed to process image: %v", err)
    }

    fmt.Println("LaTeX Code:", response.Latex)
}

In this example, the mathpix.NewClient function initializes a new client with the provided API key and application ID. An image file is then opened and passed to the Image method of the client, which sends the image to the Mathpix API for processing. The resulting LaTeX code is printed to the console.

Development and Contribution:

mathpix-go is developed with a focus on performance and ease of use, aiming to provide Go developers with a straightforward means to integrate Mathpix’s OCR capabilities into their applications. The project is open-source and licensed under the MIT License, encouraging community involvement and collaboration.

For more information, to explore the source code, or to contribute to the project, visit the GitHub repository: https://github.com/conneroisu/mathpix-go

By developing mathpix-go, I aim to empower Go developers to seamlessly incorporate advanced OCR technology into their applications, facilitating the digitization and manipulation of complex mathematical content.