(You probably don’t want this, I am just saying it as a possible solution.)
You could simply give up on rendering math in browser and instead create images on server. You are already willing to go the extra step of using the verbosifier. Why not instead use a program that will convert the expression to image (and automatically generate the HTML tag, including the alt attribute), and use that?
You could reuse the images by putting them in a separate “images/math” directory with an automatically created filename (could be a hash function of the math expression, or just keep an external list saying that “math0000.png” corresponds to this expression), so if you use the same equation twice, you will refer in both places to the same image.
Alternatively, you could create an endpoint that generates those pictures on the fly, and in the HTML code include “math.php?expr=a^2+b^2=c^2”. Then you don’t need to store the images. If needed, you could still cache the most frequently used ones.
(You probably don’t want this, I am just saying it as a possible solution.)
You could simply give up on rendering math in browser and instead create images on server. You are already willing to go the extra step of using the verbosifier. Why not instead use a program that will convert the expression to image (and automatically generate the HTML tag, including the alt attribute), and use that?
You could reuse the images by putting them in a separate “images/math” directory with an automatically created filename (could be a hash function of the math expression, or just keep an external list saying that “math0000.png” corresponds to this expression), so if you use the same equation twice, you will refer in both places to the same image.
Alternatively, you could create an endpoint that generates those pictures on the fly, and in the HTML code include “math.php?expr=a^2+b^2=c^2”. Then you don’t need to store the images. If needed, you could still cache the most frequently used ones.