I would like to use CommonMark as drop-in replacement for Markdown in some pluto cells but I can’t seem to understand how to make Latex math work with the cm"" string literal.
Based on the help from the @cm_str macro on Pluto and on the Readme of CommonMark.jl I was expecting the latex interpolation to work, but it apprently does not:
Pluto renders to math when class="tex" and the content is wrapped in $ or $$ as far as I can tell, while CommonMark generates \(...\) and \[...\] wrappers with class="math" and class="display-math". If you redefine the write_html methods to follow pluto’s requirements then it should work:
function CommonMark.write_html(::CommonMark.Math, rend, node, enter)
CommonMark.tag(rend, "span", CommonMark.attributes(rend, node, ["class" => "tex"]))
print(rend.buffer, '$', node.literal, '$')
CommonMark.tag(rend, "/span")
end
function CommonMark.write_html(::CommonMark.DisplayMath, rend, node, enter)
CommonMark.tag(rend, "p", CommonMark.attributes(rend, node, ["class" => "tex"]))
print(rend.buffer, "\$\$", node.literal, "\$\$")
CommonMark.tag(rend, "/p")
end
I’ve not looked into what would need to be adjusted within Pluto to make the current output from CommonMark “just work”, but it may not be too difficult. The other option is to adjust what CommonMark outputs instead. Not sure which approach is best, open to opinions there. Either way this should be made to work out-of-the-box and not need any kind of configuring from users.
Yes, technically it would be a breaking change, but the package is still pre-1.0 so we can just do a minor version bump. I’m open to that option if it’s the easiest route.
There’s no reference for CommonMark’s (the standard itself) behaviour with regards to maths content since it’s not specified part of the spec. The closest would probably be pandoc’s output, so just following that may be an option, not sure off the top of my head what it gives as output.
If you’ve not run into any issues with the md" macro for markdown then there’s no need for you to install CommonMark.
There’s a number of corner cases and odd behaviors in Markdown that don’t match the markdown that you’ll find in other places on the web (GitHub, discourse, etc.) so if you need more consistent parsing then it’s worth trying it out in place of Markdown.