From 2fe9d383ef6bd6a5d105ce3382fbd977f4ba2c66 Mon Sep 17 00:00:00 2001 From: Mike Kamermans Date: Sun, 26 Mar 2017 09:24:01 -0700 Subject: [PATCH 1/2] Update tex-to-svg.js --- tools/tex-to-svg.js | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/tools/tex-to-svg.js b/tools/tex-to-svg.js index f42936e0..d68e2d45 100644 --- a/tools/tex-to-svg.js +++ b/tools/tex-to-svg.js @@ -45,19 +45,11 @@ dir = path.join(dir, "source"); fs.ensureDirSync(dir); var TeXfilename = path.join(dir, hash + ".tex"); +// form the LaTeX block that will be injected into the .tex file var latexSourceCode = cleanUp(latex); -var aligned = latexSourceCode.indexOf("\\begin{aligned}") !== -1; +latexSourceCode = ['\\[', latexSourceCode, '\\]'].join('\n'); -//if (aligned) { - latexSourceCode = [ - '\\[', - latexSourceCode, - '\\]' - ].join('\n'); -//} - -// Convert the passed LaTeX to SVG form -// write the .tex source +// Convert the passed LaTeX to SVG form and write the .tex source var filedata = [ '\\documentclass[12pt]{article}', '\\usepackage[paperwidth=12in, paperheight=12in]{geometry}', // pdfcrop will remove the unused bits later @@ -94,14 +86,16 @@ filedata = filedata.concat([ filedata = filedata.join('\n'); fs.writeFileSync(TeXfilename, filedata); +// Chronicle the filenames that we'll be working through as we run +// through the .tex to pdf to svg conversion process: var PDFfilename = TeXfilename.replace(".tex",".pdf"); var PDFfilenameCropped = TeXfilename.replace(".tex","-crop.pdf"); var SVGfilename = TeXfilename.replace(".tex",".svg"); -// set the SVGfilename one dir higher +// and make sure the SVGfilename points to one dir higher than the .tex file SVGfilename = path.resolve(path.join(path.dirname(TeXfilename), '..', hash + ".svg")); -// run xelatex on this file +// Finally: run the conversion try { var cmd = `npm run xelatex -- -output-directory "${path.dirname(TeXfilename)}" "${TeXfilename}"`; console.log("- running xelatex on " + hash + ".tex"); From 3af0fd03c6e111960ef6d1890d445ab904c59477 Mon Sep 17 00:00:00 2001 From: Mike Kamermans Date: Sun, 26 Mar 2017 09:26:57 -0700 Subject: [PATCH 2/2] Update tex-to-svg.js --- tools/tex-to-svg.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/tex-to-svg.js b/tools/tex-to-svg.js index d68e2d45..e9d5bdef 100644 --- a/tools/tex-to-svg.js +++ b/tools/tex-to-svg.js @@ -59,6 +59,8 @@ var filedata = [ '\\usepackage{unicode-math}' ] +// For Chinese, we need the xeCJK package because there might be Chinese +// in maths context, which base XeLaTeX can't quite deal with. if (process.env.LOCALE === 'zh-CN') { filedata = filedata.concat([ '\\usepackage{xeCJK}', @@ -67,6 +69,8 @@ if (process.env.LOCALE === 'zh-CN') { ]); } +// The same goes for Japanese, although we obviously want a different +// font than Chinese, as they are different languages entirely. if (process.env.LOCALE === 'ja-JP') { filedata = filedata.concat([ '\\usepackage{xeCJK}', @@ -75,6 +79,7 @@ if (process.env.LOCALE === 'ja-JP') { ]); } +// Form the final .tex source code, including the latexSourceCode we formed already: filedata = filedata.concat([ '\\setmainfont[Ligatures=TeX]{TeX Gyre Pagella}', '\\setmathfont{TeX Gyre Pagella Math}', @@ -83,6 +88,7 @@ filedata = filedata.concat([ '\\end{document}' ]); +// Then we write the .tex file to disk filedata = filedata.join('\n'); fs.writeFileSync(TeXfilename, filedata);