wviechtb / mathjaxr

R package to make use of Mathjax in Rd files
47 stars 6 forks source link

equations not rendered in Rstudio server help pane #10

Open gschnabel opened 2 years ago

gschnabel commented 2 years ago

I am trying to use the mathjaxr package to inline equations in roxygen2 generated documentation. I followed the steps on the github website to install mathjaxr. Testing the display via preview_rd(...) produces the correct result. However, trying directly to display the help via ?... shows the equations verbatim. In the developer console I see that the mathjax library is not loaded due to MIME type mismatch:

The resource from “http://localhost:8787/help/library/mathjaxr/doc/mathjax/es5/tex-chtml-full.js” was blocked due to MIME type (“text/plain”) mismatch (X-Content-Type-Options: nosniff).

I managed to solve the issue by adding the following line to /etc/rstudio/rserver.conf server-add-header=X-Content-Type-Options:

Formulas are now rendered correctly in the help pane shown by RStudio server. If it is of importance, there are still some error messages in the firefox developer console,

Uncaught InternalError: too much recursion combineConfig http://localhost:8787/help/library/mathjaxr/doc/mathjax/es5/tex-chtml-full.js:949 combineConfig http://localhost:8787/help/library/mathjaxr/doc/mathjax/es5/tex-chtml-full.js:955 combineConfig http://localhost:8787/help/library/mathjaxr/doc/mathjax/es5/tex-chtml-full.js:955 ...

and

Source map error: Error: request failed with status 404 Resource URL: http://localhost:8787/help/library/mathjaxr/doc/mathjax/es5/tex-chtml-full.js Source Map URL: css_util.js.map

wviechtb commented 2 years ago

I just installed RStudio Server and I can reproduce this problem and the suggested fix. However, I really don't know enough about RStudio Server to say if that's the 'proper' way to address this issue.

gschnabel commented 2 years ago

The disadvantage of using server-add-header=X-Content-Type-Options: to solve the problem is that the browser is instructed to ignore the content-type as provided by the server. A better solution would be to somehow instruct the server to serve js-files with the correct content-type specification. If I figure out how this can be done, I'll update this issue. From a practical point of view, the suggested solution is satisfactory for my personal package development needs.

Btw: thanks for developing mathjaxr, it is really a helpful package and I like it a lot!

wviechtb commented 2 years ago

Thanks for raising this issue. I never use RStudio Server, so it was not something I would ever come across. Also, thanks for the suggested fix. When I get the chance, I will document this here (done!). Of course, this fix only helps if you are actually the admin of the RStudio Server.