Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple CLI #71

Merged
merged 2 commits into from
Sep 19, 2014
Merged

Simple CLI #71

merged 2 commits into from
Sep 19, 2014

Conversation

mildsunrise
Copy link
Contributor

This PR adds a simple command line interface to KaTeX. (closes #55)

It just reads TeX from standard input (until EOF is found), renders it through katex.renderToString, and outputs the HTML to standard output. Given that KaTeX needs no or little customization, command-line arguments are ignored for now.

The CLI (cli.js) is exported via package.json, so that installing KaTeX globally:

$ sudo npm install -g katex

Will also install a katex command system-wide, that is a symlink to the CLI. Then, this:

$ katex <<< "a = b \times c"

outputs

<span class="katex"><span class="katex-inner"><span class="strut" style="height:0.69444em;"></span><span class="strut bottom" style="height:0.77777em;vertical-align:-0.08333em;"></span><span class="base textstyle uncramped"><span class="mord mathit">a</span><span class="mrel">=</span><span class="mord mathit">b</span><span class="mbin">×</span><span class="mord mathit">c</span></span></span></span>

This allows webservers written in other languages to easily interface with KaTeX to render math server-side.

Not related to this PR, but good to have.
@douglascamata
Copy link

Just a suggestion, $ katex <<< "a = b \times c" is everything but intuitive. I think the most intuitive interface would be something like $ katex "a = b \time c", or reading from stdin, like $ latex < file.katex or $ echo a = b \\times c | katex

@mildsunrise
Copy link
Contributor Author

@douglascamata the CLI does exactly that: it reads from stdin.
command <<< "string" is just another way to say echo "string" | command.

So yeah, katex < file.katex and echo a = b \\times c | katex will work as you'd expect.

@douglascamata
Copy link

@jmendeth awesome, thanks for the tip!

@xymostech
Copy link
Contributor

@jmendeth This looks great! Like I've said on some of the other requests, we're getting our CLA worked out right now; I'll let you know when we figure it out so we can merge this!

@mildsunrise
Copy link
Contributor Author

Okay!

2014-09-18 20:52 GMT+02:00 Emily Eisenberg notifications@github.com:

@jmendeth https://github.com/jmendeth This looks great! Like I've said
on some of the other requests, we're getting our CLA worked out right now;
I'll let you know when we figure it out so we can merge this!


Reply to this email directly or view it on GitHub
#71 (comment).

@xymostech
Copy link
Contributor

We've set up our CLA, found at www.khanacademy.org/r/cla Please sign it so we can merge this in!

@mildsunrise
Copy link
Contributor Author

Signed. (but I don't have a phone)

xymostech added a commit that referenced this pull request Sep 19, 2014
@xymostech xymostech merged commit b675587 into KaTeX:master Sep 19, 2014
@mildsunrise mildsunrise deleted the simple-cli branch September 19, 2014 20:11
sebastianpantin pushed a commit to sebastianpantin/KaTeX that referenced this pull request Sep 17, 2017
…cityForStepImage-SPL

Fixed some styling for webview and step image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

KaTeX should totally have a CLI
3 participants