https://github.com/jonocarroll/mathpix
Query the mathpix API to convert math images to LaTeX
https://github.com/jonocarroll/mathpix
latex r
Last synced: 11 days ago
JSON representation
Query the mathpix API to convert math images to LaTeX
- Host: GitHub
- URL: https://github.com/jonocarroll/mathpix
- Owner: jonocarroll
- Created: 2017-03-07T00:56:42.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-04-26T09:56:33.000Z (12 months ago)
- Last Synced: 2025-03-28T09:06:14.000Z (18 days ago)
- Topics: latex, r
- Language: R
- Size: 302 KB
- Stars: 249
- Watchers: 12
- Forks: 25
- Open Issues: 1
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
- jimsghstars - jonocarroll/mathpix - Query the mathpix API to convert math images to LaTeX (R)
README
---
output: github_document
---```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```
# mathpix
[](http://www.repostatus.org/#active)
[](https://cran.r-project.org/package=mathpix)
[](commits/master)
[)`-yellowgreen.svg)](/commits/master)[](https://travis-ci.org/jonocarroll/mathpix)
[](https://ci.appveyor.com/project/jonocarroll/mathpix)
[](https://codecov.io/gh/jonocarroll/mathpix)[](http://www.r-pkg.org/pkg/mathpix)
[](https://github.com/jonocarroll/mathpix/network)
[](https://github.com/jonocarroll/mathpix/stargazers)
[](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

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

Even complicated, hand-drawn figures work

```{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)
$$
```
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/