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

Add support for math in blastula_email rmarkdown format #298

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cderv
Copy link
Collaborator

@cderv cderv commented Feb 8, 2023

This is a POC to test how we could support math easily in blastula rmardown fomat following the improved support in rmarkdown

This first test is using webtex method which allow to use an online service to insert math as SVG (default) or PNG in HTML document. Hopefully self-contained image like SVG or PNG are ok to be included in email.

Another possible method would be using the katex R package https://docs.ropensci.org/katex/index.html that we support through math_method: r-katex in rmarkdown but this will require a specific CSS file.

I don't how this CSS would behave in email client etc... This needs to be studied.

If none of this two solutions are possible for email format, this is harder and needs possibly specific adjustement somehow is possible.

Testing

Using this PR you can try rendering this document

---
title: "Math in email"
output: blastula::blastula_email
---

Testing math

$$
\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)
$$

Math formula will be inserted in email with a img and SVG data. It looks ok but require probably some CSS tweak.
image

HTML code looks like

<p><img style="vertical-align:middle" src="data:image/svg+xml;base64<longencodeddatastring>" alt="\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)" title="\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)" class="math display"></p>

I don't think anything else is inserted in the document - to check.

@rich-iannone sharing that so you see what is possible. Happy to discuss this with you

@cderv cderv linked an issue Feb 8, 2023 that may be closed by this pull request
@rich-iannone
Copy link
Member

Christoph this is great! I've been wanting the same thing in gt as well (SVG-based formulas in non-LaTeX, non-Word output) but I'm really happy to see this work here in this package. We can definitely discuss this a bit more :)

@rich-iannone rich-iannone self-requested a review April 27, 2023 03:57
@rich-iannone rich-iannone marked this pull request as ready for review April 27, 2023 03:58
Copy link
Member

@rich-iannone rich-iannone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I'm ready to accept this, testing in email clients could come later.

@cderv
Copy link
Collaborator Author

cderv commented May 2, 2023

As you want. I really don't know how this behave from email. I just wanted to show here how this could be done in a R Markdown output format.

Maybe you want to make this feature opt-in, and not opt-out in case of issues ? I used the default to webtex here - you could still deactivate but let user opt-in webtex math is they agree ?

I am thinking about this because it requires internet connection for webtex to work and generate the svg.

Anyhow, if you feel good about this without testing some email client, feel free to add a news bullet and merge.

@dmi3kno
Copy link

dmi3kno commented Sep 10, 2023

Dear RMD team, anything is happening on this front? We would really, really appreciate mathjax in emails. Please? :)

image

I think the images get sanitized by google

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

Successfully merging this pull request may close these issues.

MathJax in emails
3 participants