summaryrefslogtreecommitdiff
path: root/js/codeq
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@fri.uni-lj.si>2016-09-09 11:20:32 +0200
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2016-09-09 11:20:32 +0200
commita38f6ef2095cd689b0eb652dcef6beb04971c33c (patch)
tree034d467c4b57d75e61a129560e0bde22d0b28daa /js/codeq
parent6337a155b61e6c1cf3dc29923b2d9509d3edaec2 (diff)
Support LaTeX math notation in templates
Diffstat (limited to 'js/codeq')
-rw-r--r--js/codeq/template.js16
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 = {