-
DescriptionI'm trying to provide different versions of macros for PDF and HTML output of my document. (This is necessary to handle some inconsistencies between browser math rendering and PDF rendering.) But I don't seem to find out how to achieve this. Other discussions mentioned to use ---
title: "Conditional Macros"
format: pdf
pdf-engine: xelatex
keep-tex: true
---
::: {.content-visible when-format="html"}
\providecommand{\mymacro}{\texttt{HTML version of macro}}
(This is HTML output.)
:::
::: {.content-visible when-format="pdf"}
\providecommand{\mymacro}{\texttt{PDF version of macro}}
(This is PDF output.)
:::
$$\textrm{Test: }\mymacro$$ My hope would have been that this renders as But the PDF output is: The reason seems to be that macros are detected regardless of content visibility policy and then unfolded in a preprocessing step (likely by Pandoc's [...]
\providecommand{\mymacro}{\texttt{PDF version of macro}}
(This is PDF output.)
\[\textrm{Test: }\texttt{HTML version of macro}\]
[...] How can one properly control the macro set for the preprocessing? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 9 replies
-
You could start avoiding raw language without specifying its raw languages which could explain the issue you are having. https://quarto.org/docs/authoring/markdown-basics.html#raw-content And regarding Math macros: https://quarto.org/docs/authoring/markdown-basics.html#equations
Yes, this macro thing is a Pandoc feature, not a Quarto one. |
Beta Was this translation helpful? Give feedback.
-
The following workaround leads to Pandoc unfolding latex_macros for HTML output (which is necessary for macros to affect KaTeX math), and to Pandoc leaving the macro processing to LaTeX for PDF. ---
title: "Conditional Macros"
format:
html:
html-math-method: katex
pdf:
from: markdown-latex_macros
---
::: {.content-visible when-format="html"}
\providecommand{\mymacro}{\texttt{HTML version of macro}}
<!-- this version of the macro will be unfolded by Pandoc's latex_macros filter, which we deactivate for PDF -->
(This is HTML output.)
:::
::: {.content-visible when-format="pdf"}
\providecommand{\mymacro}{\texttt{PDF version of macro}}
<!-- this version of the macro will be unfolded by LaTeX -->
(This is PDF output.)
:::
$$\textrm{Test: }\mymacro$$ (Note that the order of the |
Beta Was this translation helpful? Give feedback.
-
For reference, |
Beta Was this translation helpful? Give feedback.
-
FYI, following KaTeX documentation: ---
title: "Conditional Macros"
format:
html:
html-math-method: katex
include-after-body:
- text: |
<script>
const macros = {};
for (let element of mathElements) {
katex.render(element.textContent, element, {
throwOnError: false,
macros
};
}
</script>
---
$$
\gdef\mymacro{\texttt{HTML version of macro}}
$$
$$
\textrm{Test: }\mymacro
$$ Which lead to:
|
Beta Was this translation helpful? Give feedback.
The following workaround leads to Pandoc unfolding latex_macros for HTML output (which is necessary for macros to affect KaTeX math), and to Pandoc leaving the macro processing to LaTeX for PDF.