Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
snoeyink opened this issue Jun 22, 2022 · 4 comments
Closed

Comments

@snoeyink
Copy link

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

@snoeyink snoeyink changed the title Please add a mdx_str version so I can write mdx" \LaTeX" instead of @mdx "\\LaTeX" Please add a mdx_str version so that latex backslashes need not be escaped Jun 22, 2022
@snoeyink
Copy link
Author

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

snoeyink added a commit to snoeyink/MarkdownLiteral.jl that referenced this issue Jun 23, 2022
@fonsp
Copy link
Member

fonsp commented Sep 5, 2022

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 fonsp closed this as not planned Won't fix, can't repro, duplicate, stale Sep 5, 2022
@fonsp
Copy link
Member

fonsp commented Sep 5, 2022

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.

@snoeyink
Copy link
Author

snoeyink commented Sep 8, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants