quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.95k stars 325 forks source link

Option to render display math blocks as images? #818

Open ajfriend opened 2 years ago

ajfriend commented 2 years ago

I use Quarto (and previously just pandoc) at work to write docs that often include LaTeX math blocks. Unfortunately for me, to get anyone to read them, I have to convert them to Google Docs.

That often works fine by rendering as .docx, uploading the doc, and converting it to a Google Doc. However, I usually have issues with display math blocks not rendering correctly when converting from docx to Google Docs.

I'm thinking about a potential workaround where I could tell Quarto to render those display math blocks as images, so they'd display correctly in Google Docs. Is that already possible? I'd also think a feature like this might be useful in other scenarios outside of just my use case.

My current workflow is to render the doc in a different format, screenshot the correctly-rendered math blocks, and paste them into the Google Doc manually. But it would be really nice to be able to automate that step. :)

Example of the rendering issue

---
title: "Quarto to Google Docs math example"
self-contained: true
format:
  html:
    toc: true
  pdf:
    toc: true
  docx:
    toc: false
---

Inline math often renders OK: $1 = \sum_{i=1}^n \pi_i$.

Math blocks are also sometimes OK:

$$
1 = \sum_{i=1}^n \pi_i.
$$

But more complicated ones usually have issues like:

$$
\begin{array}{ll}
\mbox{minimize}    & f(x)     \\
\mbox{subject to}  & x \in C
\end{array}
$$

or like this:

$$
\begin{aligned}
x \in A \\
y \in B
\end{aligned}
$$

Google Docs

Screen Shot 2022-05-06 at 11 24 47 AM

MS Word on Mac

Screen Shot 2022-05-06 at 11 24 18 AM

PDF

Screen Shot 2022-05-06 at 11 24 06 AM

HTML

Screen Shot 2022-05-06 at 11 23 58 AM

jjallaire commented 2 years ago

I'm not aware of any way to do this. With HTML you can use gladtex to embed images or webtex to embed links to webtex equation URLs. One thing I've seen suggested is to create HTML (possibly with theme: none or minimal: true) with one of these options, and then convert that HTML back into docx (using a raw pandoc conversion command).

ajfriend commented 2 years ago

Do you mean any way to do this currently, or would this be a reasonable feature request?

For example, would it be possible to add a tag to denote a block as something that should be converted to an image and embedded?

Something like:

:::{.math-as-image}
$$
\begin{array}{ll}
\mbox{minimize}    & f(x)     \\
\mbox{subject to}  & x \in C
\end{array}
$$
:::
jjallaire commented 2 years ago

We don't have an easy way to convert that to an image right now (Pandoc can convert it to "native" math but not an image without an external program like gladtex).

So I think for now there will be various multi-step workarounds possible (e.g. convert to html w/ gladtex or webtex then convert to word, then on to gdocs) but this isn't something we'll be tooling up. If we do decide to create a "Google Docs" format I suspect we'll want to tackle this problem in earnest.