I am working on a svelte text editor project in svelte , the code is very simple (REPL) :
<script>
let rawText
let formatText = (text)=>{
// Text Formating
return text
}
$: formatedText = formatText(rawText)
</script>
<textarea bind:value={rawText}></textarea>
{#if formatedText}
{formatedText}
{/if}
I need to be able to write math equations.
To do so I have found MathJax but I can't find a clean way to import it into my svelte app
I have tried multiples approach like
the npm way :
using :
npm i mathjax
and on the svelte component :
import MathJax from 'mathjax'
But when I do this the app turn white without any error
The svelte:head way :
The second solution I tried was to import MathJax from a cdn in a script tag like that :
<svelte:head>
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script
id="MathJax-script"
async
src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js"></script>
</svelte:head>
And it kinda works because I can access MathJax functions in the browser console but I don't know to use them in my svelte app
The hacky way :
The last solution I have found in this example leads to the same problem.
So my question is how to import mathjax in my svelte project or can I use something else?