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

问题描述

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

---作品名称:福作者:马吕斯·霍费尔特标头包括:- 使用包{bm}输出:pdf_document小插图:>%VignetteEngine{knitr::rmarkdown}%VignetteIndexEntry{Foo}---[开始{对齐}m{U}=am{X}quadoldmath{U}=aoldmath{X}quadmathbf{U}=amathbf{X}.结束{对齐}]

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

为了获得斜体粗体向量,我想在我的 .Rmd 文档中使用 m{X} ,但它失败了(尽管我加载了包 bm).为什么?如果没有 output: pdf_document 部分,也会发生同样的情况.

更新

如果我在跑步

---作品名称:福作者:马吕斯·霍费尔特标头包括:- 使用包{bm}输出:pdf_document小插图:>%VignetteEngine{knitr::rmarkdown}%VignetteIndexEntry{Foo}---[开始{对齐}m{U}=am{X}quadoldmath{U}=aoldmath{X}quadmathbf{U}=amathbf{X}.结束{对齐}][m{U}=am{X}quadoldmath{U}=aoldmath{X}quadmathbf{U}=amathbf{X}.]开始{对齐}m{U}=am{X}quadoldmath{U}=aoldmath{X}quadmathbf{U}=amathbf{X}.结束{对齐}

我得到(没有错误)

解决方案

我认为你的 [ ]egin{align} ... end{align} 是多余的.当我按照上面写的方式运行它时,我得到了

!包 amsmath 错误:方程式结构的错误嵌套;(amsmath) 尝试使用 `aligned' 恢复.

请参阅 amsmath 软件包文档以获取解释.键入 H 以获得即时帮助....

l.84 end{align}

当我删除 egin{align} ... end{align} ...

(在

归根结底,如果您想正确呈现精美的数学,最好还是坚持使用 PDF 输出.

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}
---
[
egin{align}
   m{U}=am{X}quadoldmath{U}=aoldmath{X}quadmathbf{U}=amathbf{X}.
end{align}
]

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

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

UPDATE

If I'm running

---
title: Foo
author: Marius Hofert
header-includes:
    - usepackage{bm}
output:
    pdf_document
vignette: >
  %VignetteEngine{knitr::rmarkdown}
  %VignetteIndexEntry{Foo}
---
[
egin{align}
   m{U}=am{X}quadoldmath{U}=aoldmath{X}quadmathbf{U}=amathbf{X}.
end{align}
]

[
   m{U}=am{X}quadoldmath{U}=aoldmath{X}quadmathbf{U}=amathbf{X}.
]

egin{align}
   m{U}=am{X}quadoldmath{U}=aoldmath{X}quadmathbf{U}=amathbf{X}.
end{align}

I get (without errors)

解决方案

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

Worked fine for me when I deleted egin{align} ... end{align} ...

(It seems that a similar issue arose in your previous question too ...)

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


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 oldmath; adding the package to your LaTeX input won't help, you'll have to use mathbf and oldsymbol instead. You can play around here to see what works and what doesn't: entering

$m X oldmath X oldsymbol X mathbf X$

at that web page gives

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

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

07-29 18:38