JuliaPluto/MarkdownLiteral.jl

Please add a mdx_str version so that latex backslashes need not be escaped

snoeyink opened this issue · 4 comments

Request: Please add a mdx_str version of @markdown so I can write mdx" ``\LaTeX``" instead of @mdx "``\\LaTeX``". I've spent several hours playing with escaping and un-escaping strings, discovering differences in the interpolation parsing between htl" " and cm" ", and realizing that I am too new to Julia/Pluto to do this properly. But I think I can see what can be done:

Issue: CommonMark.jl provides cm" ", which means that one need not escape backslashes for latex, for example. It's parser does not do interpolation into code, latex, or HTML environments. MarkdownLiteral.jl, by using @htl first, supports interpolation into those environments, but at the cost of not working on raw strings, so things like latex have to be properly escaped.

  1. Main goal: I'd like mdx"``\LaTeX``" to work like cm"``\LaTeX``", but at the moment I need to write @mdx "``\\LaTeX``".
  2. Fix MarkdownLiteral double escaping for text: the fact that @htl is followed by the cm_parser means that to get the effect of cm"\@at", I have to write @mdx "\\\\\\@", whereas mdx"\@at" I expect will just work.
  3. One complication: HypertextLiteral interpolation requires more parens and is not stopped by escape \$: cm"\$3.50" #-> "$3.50", as expected. Somehow @mdx "\$3.50" works, but special handling may be needed for mdx"\$3.50", since htl"\$3.50" fails with an interpolation error and htl"\$(3.50)" #-> "\3.5".

Thanks: MarkdownLiteral.jl is a really elegant hack that puts me very close to being able to convert all my Discrete Structures book & slides to markdown in Pluto notebooks. Issue 3 suggests that it may be better to first interpolate, then clean the html, then parse markdown, but I think that just having an mdx" " version would already be a big help.

This brief Pluto notebook illustrates these issues, and shows that using result = htl" " in place of result = @htl` could fix 1&2.
mdxTesting.zip

I have a possible fix to stop htl' " from interpolating with escaped $ (part of 3 above) in pull request HypertextLiteral #30.

fonsp commented

Thanks for your contribution @snoeyink !

Unfortunately we made the design decision to not add a _str macro. We found that the _str macro is convenient for small snippets, but it becomes confusing to use when you are interpolating complicated objects, or when nesting interpolation. We also can't support syntax highlighting in Pluto for interpolation into the _str macro.

To avoid this frustrating experience, and confusion over two similar but different syntaxes, we only offer the @md "" syntax.

fonsp commented

Could you open a new issue about the backslash problem? In general, we found that it helps in open source discussions to split a problem statement from a feature request. By stating a problem, you encourage others to contribute creative solutions, while a direct feature request locks the discussion in to a single direction.

Unfortunately we made the design decision to not add a _str macro. We found that the _str macro is convenient for small snippets, but it becomes confusing to use when you are interpolating complicated objects, or when nesting interpolation. We also can't support syntax highlighting in Pluto for interpolation into the _str macro.

To avoid this frustrating experience, and confusion over two similar but different syntaxes, we only offer the @md "" syntax.

@fonsp You are interacting with packages that supply cm" " and htl" ", so it is frustrating and confusing not to have mdx" ". I need a way to send raw strings into the interpolation pipeline so that Julia string processing doesn't try to interpret all my \LaTeX before it is ready. All my slides depend on this.

Ok, I will open a separate issue, but to me the consistency with CommonMark and HypertextLiteral suggests the opposite design decision.