MCPcopy
hub / github.com/KaTeX/KaTeX / processTestCase

Function processTestCase

dockers/texcmp/texcmp.js:59–192  ·  view source on GitHub ↗
(key)

Source from the content-addressed store, hash-verified

57
58// Process a single test case: rasterize, then create diff
59function processTestCase(key) {
60 const itm = data[key];
61 let tex = "$" + itm.tex + "$";
62 if (itm.display) {
63 tex = "\\[" + itm.tex + "\\]";
64 }
65 if (itm.pre) {
66 tex = itm.pre.replace("<br>", "\\\\") + tex;
67 }
68 if (itm.post) {
69 tex = tex + itm.post.replace("<br>", "\\\\");
70 }
71 if (itm.macros) {
72 tex = Object.keys(itm.macros).map(name => {
73 const expansion = itm.macros[name];
74 let numArgs = 0;
75 if (expansion.includes("#")) {
76 const stripped = expansion.replace(/##/g, "");
77 while (stripped.includes("#" + (numArgs + 1))) {
78 ++numArgs;
79 }
80 }
81 let args = "";
82 for (let i = 1; i <= numArgs; ++i) {
83 args += "#" + i;
84 }
85 return "\\def" + name + args + "{" + expansion + "}\n";
86 }).join("") + tex;
87 }
88 tex = template.replace(/\$.*\$/, tex.replace(/\$/g, "$$$$"));
89 const texFile = path.join(tmpDir, key + ".tex");
90 const pdfFile = path.join(tmpDir, key + ".pdf");
91 const pngFile = path.join(teximgDir, key + "-pdflatex.png");
92 const browserFile = path.join(imagesDir, key + "-firefox.png");
93 const diffFile = path.join(diffDir, key + ".png");
94
95 // Step 1: write key.tex file
96 const fftLatex = writeFile(texFile, tex).then(function() {
97 // Step 2: call "pdflatex key" to create key.pdf
98 return execFile("pdflatex", [
99 "-interaction", "nonstopmode", key,
100 ], {cwd: tmpDir});
101 }).then(function() {
102 console.log("Typeset " + key);
103 // Step 3: call "convert ... key.pdf key.png" to create key.png
104 return execFile("convert", [
105 "-density", dpi, "-units", "PixelsPerInch", "-flatten",
106 "-depth", "8", pdfFile, pngFile,
107 ]);
108 }).then(function() {
109 console.log("Rasterized " + key);
110 // Step 4: apply FFT to that
111 return readPNG(pngFile).then(fftImage);
112 });
113 // Step 5: apply FFT to reference image as well
114 const fftBrowser = readPNG(browserFile).then(fftImage);
115
116 return Q.all([fftBrowser, fftLatex]).spread(function(browser, latex) {

Callers

nothing calls this directly

Calls 5

execFileFunction · 0.85
readPNGFunction · 0.85
createMatrixFunction · 0.85
getMethod · 0.80
setMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…