Title: Support for the 'Mathpix' API (Image to 'LaTeX')
Version: 0.6.0
Maintainer: Jonathan Carroll <rpkg@jcarroll.com.au>
Description: Given an image of a formula (typeset or handwritten) this package provides calls to the 'Mathpix' service to produce the 'LaTeX' code which should generate that image, and pastes it into a (e.g. an 'rmarkdown') document. See https://docs.mathpix.com/ for full details. 'Mathpix' is an external service and use of the API is subject to their terms and conditions.
Depends: R (≥ 3.3.0)
License: GPL (≥ 3)
Encoding: UTF-8
URL: https://github.com/jonocarroll/mathpix
BugReports: https://github.com/jonocarroll/mathpix/issues
Suggests: testthat, covr
RoxygenNote: 7.2.1
Imports: purrr, base64enc, httr, rstudioapi, magick, utils
NeedsCompilation: no
Packaged: 2023-11-06 00:22:50 UTC; jono
Author: Jonathan Carroll ORCID iD [aut, cre]
Repository: CRAN
Date/Publication: 2023-11-06 08:10:05 UTC

Detect mathpix credentials

Description

Checks environmental variables for MATHPIX_APP_ID and MATHPIX_APP_KEY values.

Usage

credentials()

Value

a list of detected credentials (or this package's credentials)


Get a mathpix API key

Description

Get a mathpix API key

Usage

get_api_key()

Value

NULL (invisibly). Used for the side-effect of opening a browser.


Convert an image of an equation to a 'LaTeX' expression

Description

Given an image file location, mathpix performs the relevant transformations and send the data to the 'Mathpix' API, which returns a 'LaTeX' expression which should generate the typeset equation/expression in that image. When using 'RStudio', the resulting 'LaTeX' expression is automatically inserted into the current rmarkdown document.

Usage

mathpix(img, insert = TRUE, retry = FALSE)

Arguments

img

image to be converted to LaTeX

insert

Should the resulting LaTeX block be inserted into the document (default: TRUE)

retry

If Mathpix is not able to process the image, should we try again with a re-processed image?

Details

You must save your own API key in your environment (e.g. ⁠~/.Renviron⁠) with the identifiers MATHPIX_APP_ID and MATHPIX_APP_KEY. This can be tested with mathpix:::credentials().

Value

(invisibly) the rmarkdown LaTeX equation block

References

https://mathpix.com/


Connect to the mathpix API and translate an image to LaTeX

Description

Connect to the mathpix API and translate an image to LaTeX

Usage

mathpix_api(img)

Arguments

img

image to be converted to LaTeX

Details

You must save your own API key in your environment (e.g. '~/.Renviron') with the identifiers 'MATHPIX_APP_ID' and 'MATHPIX_APP_KEY'. This can be tested with 'mathpix:::credentials()'.

Value

a character string of LaTeX commands (or NULL if fails).


Convert a 'LaTeX' expression to an image (render)

Description

This calls tex_preview to render a 'LaTeX' expression into an image, either as a temporary file or saved to disk.

Usage

render_latex(latex, fileDir = NULL, ...)

Arguments

latex

'LaTeX' code to be evaluated. Surround in $ or $$.

fileDir

directory in which to save the image to (defaults to '/tmp/tempfile()').

...

other options to pass to tex_preview.

Value

NULL (invisibly)


Add LaTeX commands as an rmarkdown equation

Description

Converts an image to LaTeX then inserts that into an rmarkdown equation (surrounded by $$).

Usage

rmarkdown_block(img, retry = FALSE)

Arguments

img

image to be converted to LaTeX

retry

If Mathpix is not able to process the image, should we try again with a re-processed image?

Details

You must save your own API key in your environment (e.g. ⁠~/.Renviron⁠) with the identifiers MATHPIX_APP_ID and MATHPIX_APP_KEY. This can be tested with mathpix:::credentials().

Value

an rmarkdown equation block