如何使\ bm {}在R markdown(至HTML)文件中工作? [英] How to get \bm{} to work in an R markdown (to HTML) file?

查看:292
本文介绍了如何使\ bm {}在R markdown(至HTML)文件中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的R Markdown(.Rmd)文件如下:

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

---
title: Foo
author: Marius Hofert
header-includes:
    - \usepackage{bm}
output:
    pdf_document
vignette: >
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteIndexEntry{Foo}
---
\[
\begin{align}
   \bm{U}=a\bm{X}\quad\boldmath{U}=a\boldmath{X}\quad\mathbf{U}=a\mathbf{X}.
\end{align}
\]

输出(通过R CMD build./inst/doc/*.html的视图获得)是这样的:

The output (obtained via R CMD build and the looking in ./inst/doc/*.html) is this:

要获取斜体粗体矢量,我想在我的.Rmd文档中使用\bm{X},但是它失败了(尽管我加载了软件包bm).为什么?没有output: pdf_document部分,也会发生相同的情况.

For getting italics bold vectors, I would like to use \bm{X} in my .Rmd document, but it fails (although I load the package bm). Why? The same happens without the output: pdf_document part.

更新

如果我在跑步

---
title: Foo
author: Marius Hofert
header-includes:
    - \usepackage{bm}
output:
    pdf_document
vignette: >
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteIndexEntry{Foo}
---
\[
\begin{align}
   \bm{U}=a\bm{X}\quad\boldmath{U}=a\boldmath{X}\quad\mathbf{U}=a\mathbf{X}.
\end{align}
\]

\[
   \bm{U}=a\bm{X}\quad\boldmath{U}=a\boldmath{X}\quad\mathbf{U}=a\mathbf{X}.
\]

\begin{align}
   \bm{U}=a\bm{X}\quad\boldmath{U}=a\boldmath{X}\quad\mathbf{U}=a\mathbf{X}.
\end{align}

我得到了(没有错误)

推荐答案

我认为您的\[ \]\begin{align} ... \end{align}是多余的.当我按照上面的描述运行它时,我得到了

I think your \[ \] and \begin{align} ... \end{align} are redundant. When I ran it as written above I got

! Package amsmath错误:方程式结构的错误嵌套; (amsmath)尝试使用"aligned"进行恢复.

! Package amsmath Error: Erroneous nesting of equation structures; (amsmath) trying to recover with `aligned'.

有关说明,请参阅amsmath软件包文档. 键入H以立即获得帮助. ...

See the amsmath package documentation for explanation. Type H for immediate help. ...

l.84 \ end {align}

l.84 \end{align}

当我删除\begin{align} ... \end{align} ...

(似乎在(也许您遇到了您没有注意到的错误,并且不小心查看了先前编译的版本?)

(Perhaps you were getting errors that you didn't notice and were accidentally looking at a previously compiled version?)

至于为什么您没有获得正确的HTML输出:我可以肯定MathJax(用于渲染嵌入Rmarkdown生成的HTML中的LaTeX的引擎)此处进行操作,以查看有效和无效的方法:输入

As far as why you don't get the right HTML output: I'm pretty certain that MathJax (the engine used to render LaTeX embedded in Rmarkdown-produced HTML) doesn't know about \boldmath; adding the package to your LaTeX input won't help, you'll have to use \mathbf and \boldsymbol instead. You can play around here to see what works and what doesn't: entering

$\bm X \boldmath X \boldsymbol X \mathbf X$

该网页上的

给出了

at that web page gives

最重要的是,如果您想正确呈现精美的数学运算,最好还是坚持使用PDF输出.

Bottom line, if you want fancy math rendered properly, you're probably better off sticking to PDF output.

这篇关于如何使\ bm {}在R markdown(至HTML)文件中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆