LATEX in processing

Sure! The sketch below renders Poisson’s equation \nabla^{2}\Phi=\sigma(x) into a paragraph element.

let tex;

function setup() {
  createCanvas(400, 400);
  tex = createP();
  tex.style('font-size', '20px');
  tex.position(135, 165);
  katex.render('\\nabla^{2}\\Phi=\\sigma(x)', tex.elt);
}

The double \\ avoids escaping characters unintentionally in the middle of your TeX expression.

You can add KaTeX to the <head></head> of your sketch’s HTML file as outlined in the library’s documentation. Here is the full example in the p5.js Web Editor.

2 Likes