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

\QuartoMarkdownBase64 command in LaTeX formats #7451

Merged
merged 1 commit into from
Nov 2, 2023

Conversation

cscheid
Copy link
Collaborator

@cscheid cscheid commented Nov 2, 2023

In LaTeX raw blocks and LaTeX output formats, \QuartoMarkdownBase64{<<base64content>>} works in LaTeX analogously to how <span data-qmd-base64="<<base64content>>" works in all quarto formats.

Specifically, this allows third-party-libraries that emit LaTeX programmatically to "inject" quarto-compatible markdown in their RawBlocks.

This is necessary for the same reason that the <span> trick is necessary. On occasion, a single RawBlock is interpreted (and its contents are parsed) as a full unit. Currently, we parse tables in HTML rawblocks, and do table fixups in LaTeX rawblocks. Both of these require a "single" RawBlock to work.

Here's a minimal example:

---
format: pdf
a_meta_key: a_value
---

![A caption](./foo.jpg){#fig-1}

```{=latex}
% QGZpZy0x is "@fig-1" in base-64 encoding
% U29tZSBfbWFya2Rvd25fIGhlcmUu is "{{< meta a_meta_key >}} Some _markdown_ here." in base-64 encoding
\begin{tabular}{|c|c|}
col1 & col2 \\
\QuartoMarkdownBase64{QGZpZy0x} & \QuartoMarkdownBase64{e3s8IG1ldGEgYV9tZXRhX2tleSA+fX0gU29tZSBfbWFya2Rvd25fIGhlcmUu} \\
\end{tabular}
```

This renders to:

image

Notice that both crossrefs and shortcodes are resolved properly.

It might be tempting to think that this feature isn't necessary, and to try something like

```{=latex}
\begin{tabular}{|c|c|}
col1 & col2 \\
```
@fig-1 ` & `{=latex} {{< meta a_meta_key >}} Some _markdown_ here. `{=latex} \\`
```{=latex}
\end{tabular}
```

The problem is that the matching pair of \{begin,end}{tabular} commands are now broken across different RawBlocks, and quarto is then incapable of applying some fixups.

We purposefully don't offer a non-base-64 encoded version because parsing the valid non-latex content inside the LaTeX rawblock would be annoyingly hard to do well. We expect this feature to be used by third-party libraries like gt essentially all of the time.

@cscheid
Copy link
Collaborator Author

cscheid commented Nov 2, 2023

@dragonstyle This adds an explicit API for something similar to what you call the "markdown pipeline". At some point we should figure out if there's a way to consolidate the two paths. They're not quite the same but I wanted to point this out anyway.

@cscheid cscheid force-pushed the feature/latex-quartomarkdowncmd branch from 70f2639 to ccb87a4 Compare November 2, 2023 20:31
@cscheid cscheid merged commit a283f8f into main Nov 2, 2023
@cscheid cscheid deleted the feature/latex-quartomarkdowncmd branch November 2, 2023 20:33
@cderv
Copy link
Collaborator

cderv commented Nov 2, 2023

So cool ! Thanks !

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

Successfully merging this pull request may close these issues.

2 participants