From a38f6ef2095cd689b0eb652dcef6beb04971c33c Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Fri, 9 Sep 2016 11:20:32 +0200 Subject: Support LaTeX math notation in templates --- js/codeq/template.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'js/codeq/template.js') diff --git a/js/codeq/template.js b/js/codeq/template.js index 85f1596..ec8b080 100644 --- a/js/codeq/template.js +++ b/js/codeq/template.js @@ -98,6 +98,19 @@ along with this program. If not, see . */ } }; + // convert latex math notation to MathML + var renderMath = function (str) { + // inline math delimited by \( \) + str = str.replace(/\\\((.*?)\\\)/g, function (match, expression) { + return katex.renderToString(expression); + }); + // display math delimited by \[ \] + str = str.replace(/\\\[(.*?)\\\]/g, function (match, expression) { + return katex.renderToString(expression, {'displayMode': true}); + }); + return str; + }; + // instantiate template with args var process = function (template, templatePath, args) { var templateName, @@ -157,7 +170,8 @@ along with this program. If not, see . */ // add any remaining text output += template.substr(end == -1 ? start : end); - return output; + // render latex formulas + return renderMath(output); }; codeq.template = { -- cgit v1.2.1