Giter Club home page Giter Club logo

mpx-cli's Introduction

mpx cli npm package github license

Document conversion for scientific documents.

Install

npm install -g @mathpix/mpx-cli

Usage

Sign up at https://accounts.mathpix.com and then run mpx login which will ask for your Mathpix email and password then save an authorization token to be used for any commands that require connecting to our servers such as digitizing PDF files or converting Markdown to docx or pdf files.

mpx login

Alternatively you can use a Mathpix API account by creating an API key from https://accounts.mathpix.com/ocr-api and then set the API key as an environment variable MATHPIX_OCR_API_KEY:

export MATHPIX_OCR_API_KEY=...

Or save it permanently in the mpx config file:

mpx set-api-key ...
# This will save the key in a file at
# ~/.mpx/config on Linux, macOS, or Unix
# C:\Users\USERNAME\.mpx\config on Windows

To digitize PDF's to editable Mathpix Markdown, docx, html or tex.zip:

mpx convert input-file.pdf output-file.mmd
mpx convert input-file.pdf output-file.docx
mpx convert input-file.pdf output-file.tex
mpx convert input-file.pdf output-file.html

To digitize images to editable Mathpix Markdown, docx, html or tex.zip:

mpx convert input-file.png output-file.mmd
mpx convert input-file.png output-file.docx
mpx convert input-file.jpeg output-file.tex
mpx convert input-file.jpeg output-file.html

You can also compile Markdown files without using Mathpix OCR:

mpx convert input-file.mmd output-file.docx
mpx convert input-file.mmd output-file.tex
mpx convert input-file.mmd output-file.html
mpx convert input-file.mmd output-file.pdf
mpx convert input-file.mmd output-file.pdf --pdf-method html

To view mmd files rendered into html on a local server:

mpx serve ./input-dir
mpx serve ./input-dir/example.mmd

To build a directory of mmd files into a static html site:

mpx build ./input-dir ./output-dir

The cli has built in --help that will show all commands and flags:

$ mpx --help
Usage: mpx command [options] [args]

Document conversion for scientific documents

Options:
  -V, --version                                     output the version number
  -h, --help                                        display help for command

Commands:
  build [options] [source] [destination]            build a static html site from a directory of markdown or mathpix markdown
  convert [options] <source.ext> <destination.ext>  convert files between markdown, mathpix markdown, docx, latex and pdf formats
  serve [options] <source>                          serve markdown or mathpix markdown rendered at html
  set-api-key [options] <mathpix_ocr_api_key>       save Mathpix OCR API key
  unset-api-key [options]                           remove Mathpix OCR API key
  login [options]                                   log into your Mathpix Snip account and save authorization token
  logout [options]                                  log out of your Mathpix Snip account and remove authorization token
  help [command]                                    display help for command

mpx-cli's People

Contributors

montanaflynn avatar nicodjimenez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mpx-cli's Issues

`convert` handles markdown footnotes, but `build` does not

Given an empty directory out, and in/index.mmd containing:

# Test

Here is some text referencing footnote one[^1].

[^1]: This is a footnote.

Then running npx mpx build --input in --output out does not handle the footnote correctly. You end up with html that renders like this in a browser:

Here is some text referencing footnote one[^1].
[^1]: This is a footnote.

(where the text [^1] is just plain text, not a link)

However, npx mpx convert in/index.mmd out/index.html converts the footnote correctly, so that you end up with html that renders like this:

Here is some text referencing footnote one[1].
This is a footnote. ↩︎

(where the [1] is a link to the footnote, and the ↩︎ is a link back to the relevant point in the document)

(node:14308) UnhandledPromiseRejectionWarning:

Hi:

I just tried calling the API using the mpx path/to/input.pdf path/to/output.docx method and received the following warning (5 times).

at Timeout.<anonymous> (C:\Users\USERNAME\AppData\Roaming\npm\node_modules\@mathpix\mpx-cli\lib\convert.js:258:22)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
(node:14308) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 6)

I have attached the (single-page) PDF file in question.

Page 250.pdf

The Markdown and MS Word documents I requested are downloaded successfully, but what do you recommend?

mpx build will not write files if invoked with `--input src`

I've been playing around with mpx ("@mathpix/mpx-cli": "^0.4.0") to build a github pages site from some markdown files with inline and block equations, and noticed some strange behaviour.

Given src/index.mmd, and an empty docs directory, invoking mpx with npx build --input src --output docs results in:

bash-5.1# npx mpx build --input src --output docs
Converting src to docs
Wrote 0 files in 0.24 seconds

If I rename src to source and repeat, it works fine:

bash-5.1# npx mpx build --input source --output docs
Converting source to docs
Wrote 1 file in 0.57 seconds

Is there a way to export to standard Markdown?

When I try to convert pdf files to Markdown using mpx convert file.pdf file.md, it seems like it always uses the non-standard Mathpix Markdown format, even when I don't use the mmd file extension. I was wondering if there is a way to export to standard Markdown, similar to the functionality found in Snap Web?

No way to install spectra, following the instructions in Github

Hi there,

I am trying to install spectra following the instructions in Github, which I understand is only to run npm install -g @mathpix/spectra. This is the error message I obtain, once and again:

The authenticity of host 'github.com (140.82.121.3)' can't be [email protected] checking installable status
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
⸨░░░░░░░░░░░░░░░░░░⸩ ⠇ fetchMetadata: sill resolveWithNewModule @mathpix/[email protected] checking installable status
npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t ssh://[email protected]/montanaflynn/eleventy.git
npm ERR!
npm ERR! Host key verification failed.
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR!
npm ERR! exited with error code: 128

npm ERR! A complete log of this run can be found in:
npm ERR! path_to_the_log_file____logs/2021-02-05T05_07_16_988Z-debug.log

I would very much appreciate some clue to solve this problem, perhaps only mine because I have not too much experience on this kind of things.

Many thanks for your time and effort!!!

Josu

HTML output that includes mathml.

Hello…

I'm a screen reader user attempting to get MathML from the html output, but the tool doesn't seem to provide this option.

(node:19632) ExperimentalWarning: The fs.promises API is experimental Unexpected error

An unexpected error occurred in converting a DOCX file from a PDF file.

  1. Comand
    mpx convert 68222-247693-1-SM.pdf 68222-247693-1-SM.docx

  2. Error Message
    (node:19632) ExperimentalWarning: The fs.promises API is experimental
    Unexpected error, please submit a bug report at: https://github.com/mathpix/mpx-cli/issues

  3. About PDF file
    PDF file name is 68222-247693-1-SM.pdf.
    This PDF downloaded from https://www.ccsenet.org/journal/index.php/apr/article/view/68222.

  4. About Node.js version
    v10.15.3

Cannot read properties of null (reading 'startsWith') at ConvertPDFWithSnipAPI

There was an unexpected error, you can try again or if it continues please submit
an issue to https://github.com/mathpix/mpx-cli/issues including the output below:

TypeError: Cannot read properties of null (reading 'startsWith')
at ConvertPDFWithSnipAPI (C:\Users\peter\AppData\Roaming\npm\node_modules@mathpix\mpx-cli\lib\convert.js:319:40)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async ConvertPDF (C:\Users\peter\AppData\Roaming\npm\node_modules@mathpix\mpx-cli\lib\convert.js:169:5)
at async Object.PDFToDOCX (C:\Users\peter\AppData\Roaming\npm\node_modules@mathpix\mpx-cli\lib\convert.js:432:3)
at async Command. (C:\Users\peter\AppData\Roaming\npm\node_modules@mathpix\mpx-cli\lib\mpx.js:164:11)

TypeError: Cannot read properties of null (reading 'startsWith') at ConvertPDFWithSnipAPI

There was an unexpected error, you can try again or if it continues please submit
an issue to https://github.com/mathpix/mpx-cli/issues including the output below:

TypeError: Cannot read properties of null (reading 'startsWith')
at ConvertPDFWithSnipAPI (C:\Users\peter\AppData\Roaming\npm\node_modules@mathpix\mpx-cli\lib\convert.js:319:40)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async ConvertPDF (C:\Users\peter\AppData\Roaming\npm\node_modules@mathpix\mpx-cli\lib\convert.js:169:5)
at async Object.PDFToTEX (C:\Users\peter\AppData\Roaming\npm\node_modules@mathpix\mpx-cli\lib\convert.js:436:3)
at async Command. (C:\Users\peter\AppData\Roaming\npm\node_modules@mathpix\mpx-cli\lib\mpx.js:167:11)

error 400

i got this when i ran mpx convert x.jpg y.tex

Error: Snip server response 400 with json body:
{"errors":[{"id":"invalid_image_format","message":"Image must be jpeg or png format."}]}
    at ConvertImageWithSnipAPI (/data/data/com.termux/files/usr/lib/node_modules/@mathpix/mpx-cli/lib/convert.js:479:15)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async ConvertImage (/data/data/com.termux/files/usr/lib/node_modules/@mathpix/mpx-cli/lib/convert.js:596:5)
    at async Object.ImageToTEX (/data/data/com.termux/files/usr/lib/node_modules/@mathpix/mpx-cli/lib/convert.js:615:3)
    at async Command.<anonymous> (/data/data/com.termux/files/usr/lib/node_modules/@mathpix/mpx-cli/lib/mpx.js:180:11)
-------------------------------------------------------------------------------

TypeError: process.stdout.clearLine is not a function

>mpx --version
0.4.0

I run this:

>mpx convert --verbose "xxx.png" "xxx.mmd"

And get this:

Source: xxx.png
Destination: xxx.mmd
Options: { pdfMethod: 'latex', verbose: true }
Convert with snip api xxx.png xxx.mmd mmd
There was an unexpected error, you can try again or if it continues please submit
an issue to https://github.com/mathpix/mpx-cli/issues including the output below:
--------------------------------------------------------------------------------
TypeError: process.stdout.clearLine is not a function
    at ConvertImageWithSnipAPI (<PATH_TO_NPM>\npm\node_modules\@mathpix\mpx-cli\lib\convert.js:492:18)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async ConvertImage (<PATH_TO_NPM>\npm\node_modules\@mathpix\mpx-cli\lib\convert.js:596:5)
    at async Object.ImageToMMD (<PATH_TO_NPM>\npm\node_modules\@mathpix\mpx-cli\lib\convert.js:607:3)
    at async Command.<anonymous> (<PATH_TO_NPM>\npm\node_modules\@mathpix\mpx-cli\lib\mpx.js:171:11)
--------------------------------------------------------------------------------

Could not write to destination path: image.mmd

Hi,

I am trying to convert an image in my user root folder.

The command I am using is as follows:

mpx convert image.jpg image.mmd

It succeeds in converting, but it says this:

Convert with snip api image.jpg image.mmd mmd                                                                           
Could not write to destination path: image.mmd

Finally, I lose a snip from my plan and can't see it.

I tried it in another folder that has 777 permissions and the same thing happens.

What can I do?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.