diff options
Diffstat (limited to 'js/codeq')
-rw-r--r-- | js/codeq/template.js | 16 |
1 files changed, 15 insertions, 1 deletions
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 <http://www.gnu.org/licenses/>. */ } }; + // 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 <http://www.gnu.org/licenses/>. */ // add any remaining text output += template.substr(end == -1 ? start : end); - return output; + // render latex formulas + return renderMath(output); }; codeq.template = { |