Add javascript to <head> of atom editor?

I’m trying to render mathjax inline in the atom editor. I have Hydrogen set up rinning a sagemath jupyter kernel, which is set to output html code like

but it doesn’t display because there is no mathjax running in the editor. The only way I could think to make this work is to somehow make it so the section of the atom editor contained the lines

but I don’t see a method in the atom API which lets me edit the section. Any help?

I’m trying to render mathjax inline in the atom editor. I have Hydrogen set up rinning a sagemath jupyter kernel, which is set to output html code like

<script type="math/tex; mode=display">\newcommand{\Bold}[1]{\mathbf{#1}}{\left(q^{7} + q^{2}\right)} q^{8}</script>

but it doesn’t display because there is no mathjax running in the editor. The only way I could think to make this work is to somehow make it so the section of the atom editor contained the lines

 <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-mml-chtml.js"></script>

but I don’t see a method in the atom API which lets me edit the section. Any help?

Generally speaking, adding a script to the head is probably not the way to go (I’m not even sure if the default security settings allow loading remote scripts). This should be done through a plugin that depends on the MathJax Node module and exposes it to Atom.

Looks like somebody did that already:

If you know what you’re doing and absolutely have to add a script to the head, you can use standard JavaScript methods, no special API required.

Example:

const head = document.querySelector('head');
head.insertAdjacentHTML('beforeend', '<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>');