You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
renderthis::to_pdf() throw error for HTML slides using mathjax #75
But now, that the LaTeX equation displays correctly in the HTML presentation, renderthis::to_pdf() throw the following error and fails to produce the PDF.
> renderthis::to_pdf("index.cluster.html")
Warning: A runtime exception has occured while executing JavaScript
Runtime exception message:
TypeError: Cannot read properties of undefined (reading 'Config')
at http://127.0.0.1:5310/index.cluster_files/libs/revealjs/plugin/math/math.js:1:28635
at HTMLScriptElement.i (http://127.0.0.1:5310/index.cluster_files/libs/revealjs/plugin/math/math.js:1:28502)
Note that weirdly enough, if I click the 'Print' button in the RStudio 'Presentation' tab, and manually (not programmatically) print it from there, the PDF contains the equation formatted properly.
Silly question, but have you tried opening the rendered html page in a browser? I've had issues in the past where the RStudio viewer doesn't render the same as an actual browser like Chrome.
Not a silly question at all :) Indeed I noticed that web browser (I mostly use Chrome) display the equations properly (as in this case) even when the RStudio viewer doesn't.
Although, hold that thought... I think I'm getting closer to the issue:
Scenario 1
I click 'render' in RStudio.
The view doesn't show the 'N' properly in the equation.
In the 'Presentation' tab, I click the icon to 'Present in an external browser'
However, renderthis::to_pdf("foo.html") still produces a PDF that has a missing symbol square instead of the 'N'.
Scenario 2
After clicked 'Render' and produced the HTML file, I click on it in the 'Files' tab of RStudio
It opens file:///Users/kevin/git/kevinrue/OBDS_slides/foo.html#/title-slide (emphasis on the file path, no localhost here), which actually doesn't display the 'N' either (so no chance for the PDF to display it properly).
So basically, RStudio is doing something when serving the HTML on localhost that isn't present in the HTML file itself and thus can't be exported into the PDF by renderthis.
renderthis should be using chrome by default. If you open the html file in chrome and try to print from chrome, it should look correct. If it does, then there's something going on in RStudio. I'd also try just re-installing everything to see if there's a version issue somewhere.
These days, there are more than a few web features that are common practice that require a running web server to use. One of those is loading scripts and resources from external hosts. That's why the Render button fires up a local web server for the preview. Opening the file directly, on the other hand, causes these features break when you open the file with file:///path/to/your/slides.html.
One way around this is to use the Render button to launch the preview server and then use the URL for the preview in to_pdf():
if you open the html file in chrome and try to print from chrome, it should look correct
If I open the 'localhost' HTML that looks ok, then yes, the PDF looks OK too. That's essentially what I've done when I described
Note that weirdly enough, if I click the 'Print' button in the RStudio 'Presentation' tab, and manually (not programmatically) print it from there, the PDF contains the equation formatted properly.
However, like I said the HTML file itself, opened in a web browser without serving it from RStudio has the issue, and thus a PDF made from that one has the issue too.
which basically leads to @gadenbuie 's related workaround
The actual issue isn't really 'fixed' but I entirely agree with
These days, there are more than a few web features that are common practice that require a running web server to use.
I've got other fires to put out so I think I'll leave it at that until I've got more time to investigate further and/or chase up RStudio/Posit people who might have an opinion on the possibility of making self-contained HTML files in this scenario.
Activity
jhelvy commentedon May 9, 2024
I can't replicate the issue. I made this simple
foo.qmdslide deck:Then I rendered it to pdf with
renderthis::to_pdf("foo.html"), and I got a pdf with everything looking correct.If I use the specific mathjax setting you used, like this:
Then yes I get the error. But I didn't need to use it to get the latex math to render properly.
kevinrue commentedon May 10, 2024
Before I even get to

renderthis, I clearly need to update something because this is what I get when rendering your example:Not sure if it's quarto, RStudio, or a package that I need to update. I'll do the rounds!
jhelvy commentedon May 10, 2024
Silly question, but have you tried opening the rendered html page in a browser? I've had issues in the past where the RStudio viewer doesn't render the same as an actual browser like Chrome.
kevinrue commentedon May 10, 2024
Not a silly question at all :) Indeed I noticed that web browser (I mostly use Chrome) display the equations properly (as in this case) even when the RStudio viewer doesn't.
Although, hold that thought... I think I'm getting closer to the issue:
Scenario 1
renderthis::to_pdf("foo.html")still produces a PDF that has a missing symbol square instead of the 'N'.Scenario 2
So basically, RStudio is doing something when serving the HTML on localhost that isn't present in the HTML file itself and thus can't be exported into the PDF by renderthis.
Who do I poke now with these new details? :)
jhelvy commentedon May 10, 2024
renderthis should be using chrome by default. If you open the html file in chrome and try to print from chrome, it should look correct. If it does, then there's something going on in RStudio. I'd also try just re-installing everything to see if there's a version issue somewhere.
gadenbuie commentedon May 10, 2024
These days, there are more than a few web features that are common practice that require a running web server to use. One of those is loading scripts and resources from external hosts. That's why the Render button fires up a local web server for the preview. Opening the file directly, on the other hand, causes these features break when you open the file with
file:///path/to/your/slides.html.One way around this is to use the Render button to launch the preview server and then use the URL for the preview in
to_pdf():kevinrue commentedon May 12, 2024
If I open the 'localhost' HTML that looks ok, then yes, the PDF looks OK too. That's essentially what I've done when I described
However, like I said the HTML file itself, opened in a web browser without serving it from RStudio has the issue, and thus a PDF made from that one has the issue too.
which basically leads to @gadenbuie 's related workaround
The actual issue isn't really 'fixed' but I entirely agree with
I've got other fires to put out so I think I'll leave it at that until I've got more time to investigate further and/or chase up RStudio/Posit people who might have an opinion on the possibility of making self-contained HTML files in this scenario.
Cheers both!