-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use pipes to communicate with mathjax; add asciimath support (#2)
* change svg I/O from shell args to pipe; add asciimath support * update README
- Loading branch information
1 parent
6a4786d
commit 8906a7b
Showing
5 changed files
with
71 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,40 @@ | ||
const fs = require('fs') | ||
/** | ||
* This file reads asciimath string from stdin and output svg formula to | ||
* stdout. On linux you can end the input with ctrl-d; unfortunately on | ||
* windows this is not possible, so you may use ctrl-c to interrupt the | ||
* input. | ||
* | ||
* Another option is to redirect from file: | ||
* $ node index.js < input.txt | ||
* On windows, quote is needed: | ||
* $ "node" index.js < input.txt | ||
*/ | ||
|
||
const { am2tex } = require('asciimath-js') | ||
const tex2svg = require('./tex2svg.js') | ||
const { stdin, stdout } = process | ||
const buf = [] | ||
|
||
stdin.setEncoding('utf8') | ||
|
||
stdin.on('readable', () => { | ||
let data | ||
while ((data = stdin.read()) !== null) { | ||
buf.push(data.trim()) | ||
} | ||
}) | ||
|
||
const convert = process.argv[2] === '--am' | ||
? (input) => tex2svg(am2tex(input)) | ||
: tex2svg | ||
|
||
function onEnd () { | ||
const input = buf.join('\n') | ||
convert(input).then(svg => { | ||
console.log(svg) | ||
process.exit() | ||
}) | ||
} | ||
|
||
let { argv } = process | ||
tex2svg(argv[3]).then(svg => fs.writeFileSync(argv[2], svg)) | ||
stdin.on('end', onEnd) | ||
process.on('SIGINT', onEnd) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"dependencies": { | ||
"asciimath-js": "^1.0.1", | ||
"mathjax-full": "^3.2.0" | ||
}, | ||
"name": "manim-mathjax", | ||
|