Repository navigation
Support all math rendering engines from Pandoc in HTML documents - #1940
Conversation
|
It seems like math rendering fails when runtime is shiny... |
|
@RLesur Thanks for the comment. |
|
Great news! Thanks for doing this. I just happened to find liminal yesterday - wonder if it's any use to get around the issue mentioned in the comments? Maybe completely irrelevant though, my knowledge of all this is almost zero at the moment. |
|
I dropped the math rendering engine support for user templates with @RLesur @py9mrg |
|
Ah yeah sorry, I'm being stupid. I mentioned katex rendering being a solution for offline equation rendering fo |
|
A new package |
|
Thanks @jeroen ! That is a really great solution. Offering support directly into rmarkdown |
There was a problem hiding this comment.
it has been a long time - sorry for the delay @atusy ! We are focusing on rmarkdown currently so we should get this merge soon.
Improving the math support is important and this is possible an impactful change so I want to go thoroughly through this as there are several options.
I did review the current PR as-is but I have a few generic questions / topic in mind for this PR
Self contained now works better with Pandoc. Including for katex. However, it will create heavy document with longer rendering as it will download the JS lib and insert it in the document. We could then continue to provide some tricks to insert the required JS code. However, we could probably change it.
Patching the template file would be a way to insert it instead of using a JS script to modify the header. We could detect where the $math$ variable in the template is and replace with our content. This way we could support any template with self contained, as long as they have the if clause with the $math$ variable. BTW, this is what is done in Quarto for next generation of this.
Regarding self-contained for KaTeX, we could also default to katex R package (PR #2215) for server side rendering during post processing step. Or just offer a way to opt-in. We need to take this other PR into account for this PR.
Regading the YAML header, I wonder if we should not play with names but have something like this (also Quarto inspired):
output:
html_document:
math: katex
output:
html_document:
math:
engine: katex
url: https://cdn.jsdelivr.net/npm/[email protected]/dist"
Or use exactly like in Pandoc's default file (which Quarto will use)
output:
html_document:
html-math-method:
method: mathjax
url: "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"
Doing this could help with transition if we do need to use conversion tool. We could also add cleanly some specific method like katex R package
output:
html_document:
html-math-method: r-katex
I would think the latter to be convenient as this would be how to config with Pandoc directly.
Last topic is the lifecycle of this feature. Mathjax support is here since a long time in rmarkdown and I think we need to think of deprecation. The good and clean practice IMO would be to deprecate mathjax argument properly. For internal function, I think it is also good practice to deprecate just in case it is used somewhere. We don't yet use lifecycle R package for this, but it would be a good opportunity to start IMO. This would help to offer clean lifecycle information.
To be discussed for what to do exactly. I threw ideas here.
|
@atusy Thanks again for this great PR ! Supporting all Maths engine is really important IMO. What we would do:
@yihui did I miss anything ? Thanks. |
|
I have integrated the first part of the change by refactoring the logic and enabling the YAML syntax described in #1940 (comment) For now, I believe the change won't break anything as I believe I was cautious to insure backward compatibility
Next step would be to patch template, meaning putting back in our template. I don't think other engine use it for now, but it would be better to keep them. I don't know how doing that would affect other tooling (like learnr or shiny document) - this would require more tests I believe. I am currently testing several outputs after adding some unit tests. @yihui @atusy happy to have first review on the new stuff if you have time. Thanks! |
as it requires a local copy of Mathjax
for now the `math` argument is used only when `mathjax = 'default'`
|
I have made sure here that Example of message we can getlifecycle::deprecate_warn(
"2.11.3",
"rmarkdown::html_document_base(mathjax)",
"rmarkdown::html_document_base(math)")
#> Warning: The `mathjax` argument of `html_document_base()` is deprecated as of rmarkdown 2.11.3.
#> Please use the `math` argument instead.
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated.So I started to check support for other HTML format. I then wondered 'shouldn't we use a Here are some notes about math support in other outputs that I'll keep updating:
|
because of R partial mathching of argument in functions. Without this change, passing `math = "katex"` in a format that would pass to `html_document()` in `...` would set `mathjax = "katex"`, which is not expected.
on the same logic as `add_anchor_sections()` feature. A feature can return : - Some args for Pandoc - Some addition htmlDependency - Some lua filter to add
|
Last changes includes
output:
learnr::tutorial:
math_method: katex
I'll see if I can took this opportunity to remove the MathJax part from the template also using a similar trick or do template patching. A few more tests with shiny runtime and our other formats, and this should be good to merge. |
|
@yihui I tested with more formats and it is working well. I would suggest the following: We could merge the current PR which brings support for new engines without changing anything regarding Mathjax. This means that KaTeX dependency will included only when So I would try to work on improving mathjax integration with a patching process, and no template constraint, probably trying to remove this template constraint, but in another PR. Is this ok for you merge this one and build the rest upon it ? (R package katex support, github_document() math support, ...) |
yihui
left a comment
There was a problem hiding this comment.
Yes, I think it's a better idea to make the improvements in separate PRs. Thanks!
[skip ci]
|
Thanks @cderv ! |
This PR adds
support for user templatesnote that template must avoid$if(math)$$math$$endif$self_contained: FALSEfollowing the current implementation.