readthedocs / readthedocs.org

The source code that powers readthedocs.org
https://readthedocs.org/
MIT License
8.06k stars 3.59k forks source link

Math does not get rendered #283

Closed rubik closed 11 years ago

rubik commented 12 years ago

I use MathJax in my project documentation and it does not get rendered! I think this is the same of #99, not sure why that one was closed...

EDIT: This is what I mean: https://radon.readthedocs.org/en/latest/intro.html#maintainability-index

You can see that there is a weird [MI escape instead of the formulas.

vrajmohan commented 12 years ago

I am able to see the formulas at https://radon.readthedocs.org/en/latest/intro.html#maintainability-index.

Perhaps you are not able to get MathJax from http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML?

vrajmohan commented 12 years ago

Correction - I was able to see the formulas using Firefox 16.0.2 but not with Chrome Version 23.0.1271.64. Chrome complained saying that the page has insecure content. When I chose to load the insecure content anyway, the formulas were correctly displayed.

Further investigation revealed that the JavaScript console on Chrome was reporting: [blocked] The page at https://radon.readthedocs.org/en/latest/intro.html#maintainability-index ran insecure content from http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML. [blocked] The page at https://radon.readthedocs.org/en/latest/intro.html#maintainability-index ran insecure content from http://fonts.googleapis.com/css?family=PT+Mono|Open+Sans:300italic,400italic,700italic,400,300,700. [blocked] The page at https://radon.readthedocs.org/en/latest/intro.html#maintainability-index ran insecure content from http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML. [blocked] The page at https://radon.readthedocs.org/en/latest/intro.html#maintainability-index ran insecure content from http://fonts.googleapis.com/css?family=PT+Mono|Open+Sans:300italic,400italic,700italic,400,300,700.

rubik commented 12 years ago

Thanks for the help. I'm using Chromium version 23.0.1271.64 (165188). It seems that the insecure content that Chrome complains about is some Javascript from MathJax. I found the following wiki section about this issue: http://www.mediawiki.org/wiki/Extension_talk:MathJax#.5BFIXED.5D_MathJax_fails_to_render_in_Chrome

So apparently we just need to change MathJax url in Sphinx/Readthedocs conf.py, I'll dig Sphinx docs.

vrajmohan commented 12 years ago

Looks like you should be using src="https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">. Ugly, but they say (http://docs.mathjax.org/en/latest/start.html#secure-access-to-the-cdn) it is a stable address.

pao commented 11 years ago

This is going to break for Firefox users very soon due to bug 834836 (release notes). This is currently in Aurora, and should be expected to hit release August 6.

rubik commented 11 years ago

Hmm thanks for the report. So there is no workaround?

pao commented 11 years ago

I think if you wanted a straight workaround, you'd need to pull in MathJax.js as a static file and would probably have to override one of the templates. But I suspect that figuring out how to fix it in readthedocs.org's templates would be better (and everyone would get to take advantage, then.)

pao commented 11 years ago

This actually looks to be driven by sphinx.ext.mathjax, which points at the CDN by default. One possible workaround would be to place a local JS file in your static folder which looks something like this (haven't tested yet):

  var mathjax_host = (
      ("https:" == document.location.protocol) 
      ? "https://c328740.ssl.cf1.rackcdn.com/" 
      : "http://cdn.mathjax.org/"
  );
  document.write(
      unescape(
          "%3Cscript"
              + " src='"
                  + mathjax_host
                  + "mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
              + "'"
              + " type='text/javascript'
          + "%3E"
          + "%3C/script%3E"
      ) // this HAS to be escaped, otherwise it would 
        // close the actual (not injected) <script> element
  );

Then, set mathjax_path in conf.py to point where that static file will end up. (JS cribbed from http://stackoverflow.com/a/2725730/105880)

cdeil commented 11 years ago

I have the same problem with this page ... mathjax works with Safari, but not Chrome.

Is it possible to implement a workaround in readthedocs so that not every project has to (I didn't try to snippet by @pao yet).

hit9 commented 11 years ago

any updates on this issues? I meet the same problem now..

rubik commented 11 years ago

Apparently it's solved by adding this line in conf.py:

mathjax_path = 'http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'

Obviously the MathJax extension must be added as well to the corresponding setting variable. As you can see, now it gets rendered: http://radon.readthedocs.org/en/latest/intro.html

On Chrome, at least. For me, the issue is solved and can be closed.

hit9 commented 11 years ago

@rubik thanks a lot !

rubik commented 11 years ago

@hit9 No problem, happy to help! Did you solved the issue?

hit9 commented 11 years ago

@rubik It seems works. http://curdpy.readthedocs.org/ Fonts on google.com display well.

hit9 commented 11 years ago

@rubik but, it goes back into that problem a short time later. ..

rubik commented 11 years ago

@hit9 That's weird! My page still works as expected. Are you sure that it isn't another problem?

pao commented 11 years ago

@hit9 @rubik both links to radon and curdpy are http, not https--the CDN works perfectly fine on the non-SSL site.

hit9 commented 11 years ago

@rubik @pao Yep. http ok, but https still blocked.

ericholscher commented 11 years ago

mathjax_path = '//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'

Should work for both http and https.

Cheers, Eric

On Tue, Oct 1, 2013 at 8:23 PM, 王超 notifications@github.com wrote:

@rubik https://github.com/rubik @pao https://github.com/pao Yep. http ok, but https still blocked.

— Reply to this email directly or view it on GitHubhttps://github.com/rtfd/readthedocs.org/issues/283#issuecomment-25511085 .

Eric Holscher Maker of the internet residing in Portland, Or http://ericholscher.com

hit9 commented 11 years ago

@ericholscher I tested your solution, but not work with https.

Commit is here: https://github.com/hit9/CURD.py/commit/2b5d4dfb589c7887444a91f5e35070b2534300e1

jodal commented 11 years ago

I think you should remove the part inside the < and > quotes. I think it was only included in Eric's reply because of the conversion from his email reply to an GitHub Issues comment.

ericholscher commented 11 years ago

Ah, indeed. Sorry.

mathjax_path = '//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'

hit9 commented 11 years ago

oh.. I updated that line to

mathjax_path = '//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'

https still blocked... http is always ok.

pao commented 11 years ago

That's not a surprise--as explained at http://docs.mathjax.org/en/latest/start.html#secure-access-to-the-cdn posted by @vrajmohan the URLs are not the same, hence the need for the stupidly complicated JS snippet.

ericholscher commented 11 years ago

You should be able to safely always point to https, and it will work fine on http.

pao commented 11 years ago

Except now you have mixed active content again.

ericholscher commented 11 years ago

an http page including an https link won't cause any issue that I know of. Lots of pages do it all the time.

pao commented 11 years ago

Sorry, you're quite right that I had that backwards. Maybe it's time to pull request a universal switch to the SSL CDN address?

ericholscher commented 11 years ago

Seems reasonable, as long as the SSL CDN isn't costing you ton of money.

On Mon, Oct 7, 2013 at 12:21 PM, pao notifications@github.com wrote:

Sorry, you're quite right that I had that backwards. Maybe it's time to pull request a universal switch to the SSL CDN address?

— Reply to this email directly or view it on GitHubhttps://github.com/rtfd/readthedocs.org/issues/283#issuecomment-25837118 .

Eric Holscher Maker of the internet residing in Portland, Or http://ericholscher.com

pao commented 11 years ago

I've no idea how MathJax's hosting is funded.

ericholscher commented 11 years ago

Closing this now.