Skip to content

Instantly share code, notes, and snippets.

@jagedn
Last active June 21, 2019 19:40
Show Gist options
  • Save jagedn/fd9646c7b97aa21fdb2d06a9ffb19e86 to your computer and use it in GitHub Desktop.
Save jagedn/fd9646c7b97aa21fdb2d06a9ffb19e86 to your computer and use it in GitHub Desktop.
Mathml2Png en Google Sheet
String.prototype.addQuery = function(obj) {
return this + Object.keys(obj).reduce(function(p, e, i) {
return p + (i == 0 ? "?" : "&") +
(Array.isArray(obj[e]) ? obj[e].reduce(function(str, f, j) {
return str + e + "=" + encodeURIComponent(f) + (j != obj[e].length - 1 ? "&" : "")
},"") : e + "=" + encodeURIComponent(obj[e]));
},"");
}
function mathml2png( math, format, scale, transparent){
format = format ? format : 'AsciiMath';
scale = scale ? scale : 4;
transparent = transparent ? transparent : false;
var request ={
e: math,
f:format,
s:scale,
t:transparent
}
return "https://mathml2png.herokuapp.com/img/mathml.png".addQuery(request)
}
@jagedn
Copy link
Author

jagedn commented Jun 21, 2019

En A1 escribe la formula, por ejemplo

e=m*c^2

En otra celda escribe
=image(mathml2png(A1;"AsciiMath";10))

los argumentos a mathml2png son:

  • el texto de la formula o la celda de donde tomarlo
  • AsciiMath o TeX segun el formato que queramos usar (Asciimath por defecto)
  • escala de la imagen a generar (2 por defecto)
  • transparente ( por defecto false)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment