I want to use math.js in the script in the card template. Is this possible somehow?
I get with this code:
ReferenceError: mathjs is not defined
Don’t worry about it. It’s a bot. Talks weird and has created multiple new accounts around the web with the same name (name with a typo, probably so doesn’t show up in search if your spelling is correct). This has been a pattern recently.
Hi @Bjoe
You are probably calling your script / a function of your script before it has been loaded. Try this approach of loading the script (instead of simply loading it via a <script>
tag):
/*define custom script loading function*/
function loadScript(scriptUrl) {
const script = document.createElement('script');
script.src = scriptUrl;
document.body.appendChild(script);
return new Promise((res, rej) => {
script.onload = res;
script.onerror = rej;
});
}
/*use script loading function with math.js*/
loadScript('_math.js')
.then(() => {
console.log('Script loaded.');
exampleFunction();
})
.catch(() => {
console.error('Script loading failed.');
});
Make sure that the name of the file and the name you use as an argument when calling the loadScript function match exactly. You will also need to add an underscore “_
” character to the beginning of the file name, so Anki does not delete your file on sync.
Hope this works for you
Cheers!
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.