I am working on a Quarto book rendered both as HTML and as pdf. The HTML consists of multiple pages with separate qmd
files. A set of LaTeX macros, defined via \newcommand
s, should be used across the whole book. LaTeX is rendered with MathJax.
Tried three different approaches:
A – Insert the macros towards the beginning of each qmd
file. This way the macros are correctly displayed when used, but there are two drawbacks: repetition of the macro definitions (and they are many) in each qmd
file, and XeTeX complaining of already-defined commands.
B – Define the macros in a separate macros.qmd
file, and call that common file at the beginning of the other qmd
ones by inserting
{{< include macros.qmd >}}
in each of them, as explained in the Quarto guide. This succeeds in producing the macros correctly in the HTML, but XeTeX still complains about already defined commands. – I suppose replacing \newcommand
with \providecommand
could solve this.
C – Call the macros.qmd
file using include-in-body:
or similar options in the _quarto.yml
file, as suggested in the answers to this, this, and this questions. For example:
format:
html:
include-in-body: macros.qmd
or
format:
html:
include-in-body:
- text: {{< include macros.qmd >}}
But the renderer does not seem to load those macros definitions (and XeTeX doesn't see them either).
I wonder if there is a simple solution that works for both HTML and XeTeX and avoids text redundancies (on the author's side) such as repeated definitions or calls to external files. My impression is that many authors using Quarto for maths/physics would face this problem.