first commit
This commit is contained in:
commit
24fa9a2d77
15 changed files with 1870 additions and 0 deletions
64
numbas-mathjax.js
Normal file
64
numbas-mathjax.js
Normal file
|
@ -0,0 +1,64 @@
|
|||
/**
|
||||
* An extension to MathJax which adds \var and \simplify commands.
|
||||
*/
|
||||
|
||||
|
||||
(function() {
|
||||
|
||||
var NumbasMap = new MathJax._.input.tex.SymbolMap.CommandMap(
|
||||
'numbasMap',
|
||||
|
||||
{
|
||||
var: ['numbasVar', 'var'],
|
||||
simplify: ['numbasToken', 'simplify']
|
||||
},
|
||||
|
||||
{
|
||||
numbasVar: function mmlToken(parser, name, type) {
|
||||
const {jme} = Numbas;
|
||||
|
||||
try {
|
||||
const settings_string = parser.GetBrackets(name); // The optional argument to the command, in square brackets.
|
||||
|
||||
const settings = {};
|
||||
if(settings_string!==undefined) {
|
||||
settings_string.split(/\s*,\s*/g).forEach(function(v) {
|
||||
var setting = jme.normaliseRulesetName(v.trim());
|
||||
settings[setting] = true;
|
||||
});
|
||||
}
|
||||
|
||||
const expr = parser.GetArgument(name);
|
||||
|
||||
const {scope} = parser.configuration.packageData.get('numbas');
|
||||
|
||||
const tok = jme.evaluate(expr, scope);
|
||||
const tex = jme.display.texify({tok}, settings, scope);
|
||||
const mml = new MathJax._.input.tex.TexParser.default(tex, parser.stack.env, parser.configuration).mml();
|
||||
|
||||
parser.Push(mml);
|
||||
} catch(e) {
|
||||
console.error(e);
|
||||
throw(new Numbas.Error('mathjax.math processing error',{message:e.message,expression:expr}));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
function saveJMEScope(arg) {
|
||||
const scope = Numbas.display.find_jme_scope(arg.math.start.node);
|
||||
arg.data.packageData.set('numbas',{scope});
|
||||
}
|
||||
|
||||
|
||||
var NumbasConfiguration = MathJax._.input.tex.Configuration.Configuration.create('numbas', {
|
||||
handler: {
|
||||
macro: ['numbasMap']
|
||||
},
|
||||
preprocessors: [
|
||||
[saveJMEScope, 1]
|
||||
],
|
||||
});
|
||||
|
||||
})();
|
Loading…
Add table
Add a link
Reference in a new issue