gpt4 book ai didi

html - 带有 html/docx 输出的 R Markdown 文档,使用 LaTeX 包 bbm?

转载 作者:行者123 更新时间:2023-12-03 16:18:32 25 4
gpt4 key购买 nike

如何使用 LaTeX 包 bbm在 html/docx 输出的 R Markdown 中?
目前我正在使用下面的 hack 解决方案,基本上,我只是放弃使用包 bbm用于 .docx/.html 输出。是否有我仍然可以使用该软件包的 hack 解决方案?
注意,这个问题与我的问题有关 In an R Markdown document, “includes” for docx output?我在哪里专门询问如何移动这些特殊的<!--- For DOCX Only --->代码块到 preamble-word.tex要包含在 YAML header 中的文件。这个问题也和问题How to get \bm{} to work in an R markdown (to HTML) file?有关。我目前对 bbm 的破解基本上是对作为该问题的答案而提出的一种技巧的改编。
tinytexttest.Rmd

---
title: "TinyTeX Test"
header-includes:
- \usepackage{bbm}
output:
pdf_document: default
html_document: default
word_document: default
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

<!--- For HTML Only --->
`r if (knitr:::is_html_output()) '
$\\newcommand{\\mathbbm}[1]{\\mathbf{#1}}$
'`

<!--- For DOCX Only --->
`r if (!knitr:::is_latex_output() & !knitr:::is_html_output()) '
\\newcommand{\\mathbbm}[1]{\\mathbf{#1}}
'`

Hello

\[\mathbbm{1}_{S}(x)\]
.pdf 输出
enter image description here
.docx/.html 输出
enter image description here

最佳答案

好的,另一个答案,我刚刚意识到,这是两个略有不同的问题 - 一个由问题起始者提出,一个由赏金起始者提出。

I would need a solution to this issue as well. Here is my minimumexample expected to work:

---
title: "Testing LaTeX packages in Docx format"
output: word_document
header-includes:
- \usepackage{xfrac}
---
$$ \sfrac{1}{2} $$ ```

在这种情况下,使用 MathJax 概述的答案不会那么好。 MathJax 不支持 sfrac ( http://docs.mathjax.org/en/latest/input/tex/macros/index.html)
我不知道您是否特别需要\sfrac,但会支持\frac 或\tfrac。也许您可以改用这些。
这里有一个\frac 的例子
 ---
title: "Frac Test"
header-includes:
- \usepackage{xfrac}
output:
pdf_document: default
html_document: default
word_document: default
---

$$
\frac{1}{2}+1
$$
\frac 示例 html 的输出:
enter image description here
这适用于 .pdf/word 和 html。
这里有一个\tfrac 的例子
---
title: "TFrac Test"
header-includes:
- \usepackage{xfrac}
output:
pdf_document: default
html_document: default
word_document: default
---

$$
\tfrac{1}{2}+1
$$
输出\tfrac 示例 html:
enter image description here
这将对 html、pdf 运行 - 对于 word 它将写 1/2 而不是公式,因为 word 中没有\tfrac 等价物。
MathJax 也支持\cfrac 和\dfrac。

关于html - 带有 html/docx 输出的 R Markdown 文档,使用 LaTeX 包 bbm?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56211210/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com