# Math not rendering in embedded posts

**URL:** https://meta.discourse.org/t/math-not-rendering-in-embedded-posts/176699
**Category:** Support
**Tags:** math
**Created:** [January 18, 2021, 6:25pm UTC](https://meta.discourse.org/t/math-not-rendering-in-embedded-posts/176699 "2021-01-18T18:25:29Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![hammond](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hammond/32/206440_2.png) [@hammond](https://meta.discourse.org/u/hammond)
#### Post date: [January 18, 2021, 6:25pm UTC](https://meta.discourse.org/t/math-not-rendering-in-embedded-posts/176699/1 "2021-01-18T18:25:29Z")

</div>

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](https://github.com/kasperpeulen/discourse-mathjax/issues/21) to get the math to render. Is there something we can do with `discourse-math` to make it work in embeds?

[Here’s a sample of what I’m talking about](https://www.math.wichita.edu/~hammond/class-notes/section-prop-logic.html) (scroll to the bottom).

Thanks!

---

<div class="post-metadata">

### Author: ![danekhollas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/danekhollas/32/79637_2.png) [@danekhollas](https://meta.discourse.org/u/danekhollas)
#### Post date: [January 30, 2021, 6:20pm UTC](https://meta.discourse.org/t/math-not-rendering-in-embedded-posts/176699/2 "2021-01-30T18:20:52Z")

</div>

It looks like the solution is in the last comment on the Github thread that you referenced:

[https://github.com/kasperpeulen/discourse-mathjax/issues/21#issuecomment-471256399](https://github.com/kasperpeulen/discourse-mathjax/issues/21#issuecomment-471256399)

Have you tried it?

---

<div class="post-metadata">

### Author: ![hammond](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hammond/32/206440_2.png) [@hammond](https://meta.discourse.org/u/hammond)
#### Post date: [January 30, 2021, 7:02pm UTC](https://meta.discourse.org/t/math-not-rendering-in-embedded-posts/176699/3 "2021-01-30T19:02:42Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![danekhollas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/danekhollas/32/79637_2.png) [@danekhollas](https://meta.discourse.org/u/danekhollas)
#### Post date: [January 30, 2021, 7:45pm UTC](https://meta.discourse.org/t/math-not-rendering-in-embedded-posts/176699/4 "2021-01-30T19:45:47Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![danekhollas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/danekhollas/32/79637_2.png) [@danekhollas](https://meta.discourse.org/u/danekhollas)
#### Post date: [January 30, 2021, 8:12pm UTC](https://meta.discourse.org/t/math-not-rendering-in-embedded-posts/176699/5 "2021-01-30T20:12:21Z")

</div>

To be clear, what I’m suggesting that this patch should still work?

```diff
@@ -70,5 +70,11 @@
   </head>
   <body>
     <%= yield %>
+ <script type="text/x-mathjax-config">
+ MathJax.Hub.Config({
+ extensions: ["jsMath2jax.js"]
+ });
+ </script>
+ <script src="//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
   </body>
 </html>

```

Currently, I don’t see code in your embedded comment section?  
Can you verify you’re actually applying the patch?

```sh
./launcher enter app
cat app/views/layouts/embed.html.erb

```

---

<div class="post-metadata">

### Author: ![danekhollas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/danekhollas/32/79637_2.png) [@danekhollas](https://meta.discourse.org/u/danekhollas)
#### Post date: [January 30, 2021, 8:32pm UTC](https://meta.discourse.org/t/math-not-rendering-in-embedded-posts/176699/6 "2021-01-30T20:32:36Z")

</div>

The problem with that patch might be that it tries to load Javascript from [mathjax.org](http://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.

---

<div class="post-metadata">

### Author: ![hammond](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hammond/32/206440_2.png) [@hammond](https://meta.discourse.org/u/hammond)
#### Post date: [January 31, 2021, 2:21pm UTC](https://meta.discourse.org/t/math-not-rendering-in-embedded-posts/176699/7 "2021-01-31T14:21:46Z")

</div>

That might be it! Now, the `cors origins` site setting will be on my discourse server or the web server in which I’m embedding?

---

<div class="post-metadata">

### Author: ![danekhollas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/danekhollas/32/79637_2.png) [@danekhollas](https://meta.discourse.org/u/danekhollas)
#### Post date: [January 31, 2021, 4:56pm UTC](https://meta.discourse.org/t/math-not-rendering-in-embedded-posts/176699/8 "2021-01-31T16:56:42Z")

</div>

It’s one of the Discourse settings.

---

<div class="post-metadata">

### Author: ![hammond](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hammond/32/206440_2.png) [@hammond](https://meta.discourse.org/u/hammond)
#### Post date: [February 1, 2021, 12:32am UTC](https://meta.discourse.org/t/math-not-rendering-in-embedded-posts/176699/9 "2021-02-01T00:32:52Z")

</div>

This solved it for me! Thank you so much for that help; that site settings for security had never crossed my mind.

Thank you so much!

---

<div class="post-metadata">

### Author: ![danekhollas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/danekhollas/32/79637_2.png) [@danekhollas](https://meta.discourse.org/u/danekhollas)
#### Post date: [February 16, 2021, 7:01pm UTC](https://meta.discourse.org/t/math-not-rendering-in-embedded-posts/176699/10 "2021-02-16T19:01:22Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [February 18, 2021, 4:48am UTC](https://meta.discourse.org/t/math-not-rendering-in-embedded-posts/176699/11 "2021-02-18T04:48:23Z")

</div>

I certainly support making such a change. We may need to add some sort of hook in core though like: (perhaps an `embed_javascripts` in [discourse/lib/discourse\_plugin\_registry.rb at 7829558c6d42b5f0dfbb0c2351fb332a940d651e · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/7829558c6d42b5f0dfbb0c2351fb332a940d651e/lib/discourse_plugin_registry.rb#L50-L50) .

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [March 19, 2021, 7:00am UTC](https://meta.discourse.org/t/math-not-rendering-in-embedded-posts/176699/12 "2021-03-19T07:00:26Z")

</div>



---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [June 8, 2024, 12:37pm UTC](https://meta.discourse.org/t/math-not-rendering-in-embedded-posts/176699/13 "2024-06-08T12:37:01Z")

</div>

This topic was automatically closed after 1236 days. New replies are no longer allowed.
