-
Notifications
You must be signed in to change notification settings - Fork 450
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove node-latex in favour of swiftlatex
- Loading branch information
Showing
8 changed files
with
66 additions
and
201 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { PdfTeXEngine, XeTeXEngine, DvipdfmxEngine } from 'swiftlatex' | ||
import { LaTeXOpts } from '../types' | ||
|
||
let pdftex | ||
let xetex | ||
let dvipdfmx | ||
let engineLoaded = false | ||
|
||
export default async function latex(texDoc: string, opts: LaTeXOpts) { | ||
if (!engineLoaded) { | ||
pdftex = new PdfTeXEngine() | ||
await pdftex.loadEngine() | ||
|
||
xetex = new XeTeXEngine() | ||
await xetex.loadEngine() | ||
|
||
dvipdfmx = new DvipdfmxEngine() | ||
await dvipdfmx.loadEngine() | ||
|
||
engineLoaded = true | ||
} | ||
|
||
switch(opts.cmd) { | ||
case 'pdflatex': { | ||
await pdftex.writeMemFSFile("main.tex", texDoc) | ||
await pdftex.setEngineMainFile("main.tex") | ||
const { pdf } = await pdftex.compileLaTeX() | ||
|
||
return URL.createObjectURL(new Blob([pdf], {type: 'application/pdf'})) | ||
} | ||
case 'xelatex': { | ||
await xetex.writeMemFSFile("main.tex", texDoc) | ||
await xetex.setEngineMainFile("main.tex") | ||
const res = await xetex.compileLaTeX() | ||
console.log(res) | ||
|
||
await dvipdfmx.writeMemFSFile("main.xdv", res.pdf) | ||
await dvipdfmx.setEngineMainFile("main.xdv") | ||
const { pdf } = await dvipdfmx.compilePDF() | ||
|
||
return URL.createObjectURL(new Blob([pdf], {type: 'application/pdf'})) | ||
} | ||
case 'lualatex': { | ||
throw new Error(`${opts.cmd} is not supported yet`) | ||
} | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.