How to get \bm{} to work in an R markdown (to HTML) file?

后端 未结 4 2019
误落风尘
误落风尘 2021-02-08 00:42

My R Markdown (.Rmd) file looks like this:

---
title: Foo
author: Marius Hofert
header-includes:
    - \\usepackage{bm}
output:
    pdf_document
vignette: >
          


        
4条回答
  •  我在风中等你
    2021-02-08 01:36

    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}}
    

提交回复
热议问题