My R Markdown (.Rmd) file looks like this:
---
title: Foo
author: Marius Hofert
header-includes:
- \\usepackage{bm}
output:
pdf_document
vignette: >
Another solution is to use the child chunk argument. The downside, which is kind of major, is that it will only work for math surrounded by $ $ or $$ $$. It won't work in the equation environment. The upside is that you do not get your definitions "flashing" at the top of your html pages for a moment, which happens to me with the solution above.
demo.Rmd
---
title: Foo
output:
pdf_document: default
html_document: default
---
```{r child = 'defs.tex'}
```
My math definitions are in defs.tex. Now I can use the defs in equations
but they need to be in math mode for html output. This works for both
pdf and html:
$\AA^\top\BB$ and
$$\AA^\top\BB$$
But using your new commands in the equation environment
only works for pdf output because pandoc will not expand the
definitions if the newcommands are not in $ $ or $$ $$.
\begin{equation}
\AA^\top\BB
\end{equation}
defs.tex
\newcommand{\BB}{\mathbf{B}}
\newcommand{\CC}{\mathbf{C}}
\renewcommand{\AA}{\mathbf{A}}