Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No MathJax in embedded threads #21

Open
selfshadow opened this issue Jun 29, 2015 · 7 comments
Open

No MathJax in embedded threads #21

selfshadow opened this issue Jun 29, 2015 · 7 comments

Comments

@selfshadow
Copy link

MathJax is currently not working when forum threads are embedded (http://eviltrout.com/2014/01/22/embedding-discourse.html) in a blog post. I'm guessing that this is due to Discourse being wrapped in an iframe, and that I need to include MathJax in the iframe contents in that case.

I'd be happy investigate this issue myself, but I may need one or two pointers.

@kasperpeulen
Copy link
Owner

thanks for creating the issue!

Im a bit busy the coming 3 weeks, but when I find some time I will look at it.

@kasperpeulen
Copy link
Owner

@selfshadow You could also ask at https://meta.discourse.org/t/mathjax-plugin-supports-math-notation-using-latex/12826 if someone has find a workaround.

Btw, does the plugin works for you in your own forum, I don't use the plugin myself anymore, but some people have reported it to be broken.

@selfshadow
Copy link
Author

You could also ask at https://meta.discourse.org/t/mathjax-plugin-supports-math-notation-using-latex/12826 if someone has find a workaround.

I'll try that, but I'm doubtful that there is a trivial workaround (not requiring a modification to the plugin or Discourse) if it's down to iframe security, since this is what also prevented MathJax from working with Disqus in recent years.

Btw, does the plugin works for you in your own forum, I don't use the plugin myself anymore, but some people have reported it to be broken.

It seems to be working for me (1.4.0.beta3 currently).

@brotchie
Copy link

We encountered this same issue: MathJax.js isn't being included in the embedded iframe. I can't find an obvious way for a Discourse plugin to inject scripts into the embedded thread template. Our workaround was to patch a script tag into the body of the embed.html erb template.

Here's two additions to the after_code hook to apply this patch. Note that this hardcodes the mathjax_url and
matchjax_config settings into the <script/> url.

hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - git clone https://github.com/discourse/docker_manager.git
          - git clone https://github.com/kasperpeulen/discourse-mathjax.git
    - file:
       path: /var/tmp/mathjax_embed.patch
       contents: |
         diff --git a/app/views/layouts/embed.html.erb b/app/views/layouts/embed.html.erb
         index b4ee7cf..c91743c 100644
         --- a/app/views/layouts/embed.html.erb
         +++ b/app/views/layouts/embed.html.erb
         @@ -70,5 +70,6 @@
            </head>
            <body>
              <%= yield %>
         +    <script src="//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
            </body>
          </html>

    - exec:
        cd: $home
        cmd:
          - patch -p1 < /var/tmp/mathjax_embed.patch

@selfshadow
Copy link
Author

Thank you so much for the fix, @brotchie. I finally got around to trying this out just now and it worked like a charm!

@selfshadow
Copy link
Author

@brotchie: It seems that the patch is no longer working for me, possibly after updating Discourse. I thought this might have simply been due to MathJax discontinuing their CDN, but I updated the URL and it's still not working. Any ideas?

I verified that embed.html.erb is patched as expected, but perhaps other changes are needed now. I was hoping that this might have been something that you'd already encountered and fixed.

@selfshadow
Copy link
Author

selfshadow commented Mar 10, 2019

Okay, I figured it out. I had been testing the discourse-math plugin and in the process edited some comments to get them to work. I hadn't noticed that, under the hood, it had wrapped math statements with <span class="math">...</span>. The solution was to update the patch so that it configures MathJax to convert these (see: http://docs.mathjax.org/en/latest/upgrading/jsMath.html).

Here's the complete updated patch:

@@ -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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants