In a support thread titled ‘Math not rendering in embedded posts,’ hammond reports that mathematical content fails to render in Discourse posts embedded on external websites. While a patch previously worked with the legacy discourse-mathjax plugin, it doesn’t function with Discourse’s native discourse-math plugin. danekhollas suggests the issue may not be the plugin itself, but rather how Discourse embeds content or security restrictions. They propose modifying embed.html.erb to include MathJax scripts and note that https://cdn.mathjax.org may need to be added to the cors origins site setting to bypass Content Security Policy restrictions danekhollas. hammond confirms the cors origins setting is on the Discourse server, not the embedding site, and successfully resolves the issue after applying the fix hammond. danekhollas then asks if plugins could automatically inject required JS into embedded iframes, prompting sam to endorse adding a core hook (e.g., embed_javascripts) to support such functionality in the future. The thread concludes with a practical workaround and a proposal for long-term plugin integration improvements.
I have some posts embedded within my website. The mathematics in them isn’t rendering within the embeds.
Using the old plugin, we could patch the embed.js.erb file to get the math to render. Is there something we can do with discourse-math to make it work in embeds?
Yes, and that works with the old third-party extension discourse-mathjax . However, discourse has implemented their own discourse-math extension and this solution does not work.
I don’t think the issue is with the plugin. The new plugin still uses the math spans (as you can see if you inspect the source of your page) so the solution should still work. What may have changes since then is how Discourse code embeds the posts?
The problem with that patch might be that it tries to load Javascript from mathjax.org, which I think the current Discourse version blocks by default? You might need to add https://cdn.mathjax.org to the cors origins Site Setting.
I wonder whether we could do something better here. @sam is there a way for a plugin to somehow modify app/views/layouts/embed.html.erb? So that the Discourse could load MathJax/KaTeX JS inside the embedded iframe?