Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jonocarroll/mathpix

Query the mathpix API to convert math images to LaTeX
https://github.com/jonocarroll/mathpix

latex r

Last synced: 4 days ago
JSON representation

Query the mathpix API to convert math images to LaTeX

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```
![](./tools/logo_blue.png)

# mathpix

[![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active)
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/mathpix)](https://cran.r-project.org/package=mathpix)
[![packageversion](https://img.shields.io/badge/Package%20version-0.3.0-orange.svg?style=flat-square)](commits/master)
[![Last-changedate](https://img.shields.io/badge/last%20change-`r gsub('-', '--', Sys.Date())`-yellowgreen.svg)](/commits/master)

[![Linux/Mac Travis Build Status](https://img.shields.io/travis/jonocarroll/mathpix/master.svg?label=Mac%20OSX%20%26%20Linux)](https://travis-ci.org/jonocarroll/mathpix)
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/jonocarroll/mathpix?branch=master&svg=true)](https://ci.appveyor.com/project/jonocarroll/mathpix)
[![codecov](https://codecov.io/gh/jonocarroll/mathpix/branch/master/graph/badge.svg)](https://codecov.io/gh/jonocarroll/mathpix)

[![Downloads](http://cranlogs.r-pkg.org/badges/mathpix)](http://www.r-pkg.org/pkg/mathpix)
[![GitHub forks](https://img.shields.io/github/forks/jonocarroll/mathpix.svg)](https://github.com/jonocarroll/mathpix/network)
[![GitHub stars](https://img.shields.io/github/stars/jonocarroll/mathpix.svg)](https://github.com/jonocarroll/mathpix/stargazers)
[![Twitter](https://img.shields.io/twitter/url/https/github.com/jonocarroll/mathpix.svg?style=social)](https://twitter.com/intent/tweet?text=Wow:&url=%5Bobject%20Object%5D)

## Installation:

`mathpix` is now on CRAN, so you can install using

```{r, eval = FALSE}
install.packages("mathpix")
```

If you're after newer development features (if there are any); you can install from GitHub using

```{r, eval = FALSE}
devtools::install_github("jonocarroll/mathpix")
```

## Authentication

The free API key has been removed due to overuse. Please sign up at https://dashboard.mathpix.com/ then save your
ID and key in your `.Renviron` file as

```
MATHPIX_APP_ID='yourid'
MATHPIX_APP_KEY='yourkey'
```

Note that this requires you to accept Mathpix's terms and conditions and sign up for any relevant pricing scheme.

You can check that your credentials are loaded correctly with `credentials()`.

## Usage

If you have an image you would rather properly encode in LaTeX, for example

![](./tools/integral.jpg)

then simply calling

```{r, eval = FALSE}
mathpix("./integral.jpg")
```

(with the appropriate path to the file) will insert a LaTeX block into your document which will render what the image represents

```
$$
\int \frac { 4 x } { \sqrt { x ^ { 2 } + 1 } } d x
$$
```

which renders to

![](./tools/eq_no_01.png)

Even complicated, hand-drawn figures work

![](./tools/matrix_3x3.jpg)

```{r, eval = FALSE}
mathpix("matrix_3x3.jpg")
```

```
$$
A = \left( \begin{array} { l l l } { 2 } & { 7 } & { 3 } \\ { 3 } & { 5 } & { 2 } \\ { 9 } & { 4 } & { 1 } \\ \end{array} \right)
$$
```

![](./tools/eq_no_02.png)

If your image only result in warnings and no LaTeX, use `retry = TRUE` to attempt some pre-processing of the image into a more amenable form. Unfortunately, there are still images which fail.

To *not* insert the resulting equation directly into your document, but rather store it in a variable, use `insert = FALSE`.

## API Documentation

Refer to http://docs.mathpix.com/