-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathREADME.Rmd
113 lines (77 loc) · 4.03 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{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`.
<!-- If you also wish to generate the images (although `rmarkdown` will gladly do this for you) this can be achieved using -->
<!-- ```{r, eval = FALSE} -->
<!-- render_latex(latex, fileDir) -->
<!-- ``` -->
<!-- where `latex` is the LaTeX generated by `mathpix()` (or any other escaped LaTeX) and `fileDir` is the (optional) directory where you wish to save the image (by default, a temp file). This requires that you have `pdflatex` set up correctly and available on your machine. -->
## API Documentation
Refer to http://docs.mathpix.com/