【问题标题】:display math expression as non-italic using R Markdown and HTML output使用 R Markdown 和 HTML 输出将数学表达式显示为非斜体
【发布时间】:2021-02-07 23:50:16
【问题描述】:

习惯上以斜体显示数学 (the tradition dates to Ancient Greece)。但是对于非正式的演示,我真的不喜欢它的外观。我正在尝试使用我自己的字体进行数学显示,或者至少摆脱斜体。在 YAML 中使用 mathfont: my-math-fontlatex_engine: xelatex 更改 pdf_document: 的数学字体很简单,但对于 HTML 输出,它被证明更复杂。

显然,MathJax 用于通过 Pandoc 渲染方程。我已经尝试通过外部 CSS 文件添加 CSS 规则,或者直接在 YAML 下方添加 this stackoverflow question 中的建议。显然 Pandoc 将 .math { } 类应用于所有 MathJax 表达式......但是我不太了解 CSS,因此证明正确的参数很困难。据我所知,我的额外 CSS 规则只是被忽略了,因为当我在 R Studio 中编织时斜体仍然存在。

我希望有人有解决方案?这是我正在使用的代码的最小示例;要复制它,只需将其复制粘贴到 .Rmd 文件中并使用ctrl + shift + k 编织:

---
title: "How to change math font for HTML output?"
output:
 html_document
---

```{css}
.math {
  font-family: Sans-Serif;
  font-style: normal;
}
```

This math equation is still rendered with italics: $\rho~=~\frac{m_{water}}{m_{oven-dry~soil}}$

【问题讨论】:

    标签: html css r pandoc mathjax


    【解决方案1】:

    方法如下:

    ---
    title: "Change MathJax font"
    author: "Stéphane Laurent"
    date: "05/11/2020"
    output: html_document
    ---
    
    <script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      "HTML-CSS" : {
        availableFonts : ["STIX"],
        preferredFont : "STIX",
        webFont : "STIX-Web",
        imageFont : null
      }
    });
    </script>
    
    $$
    \int_0^1 f(x) dx = 0
    $$
    

    编辑

    现在这行不通了。要使用不同的字体,您必须下载它们并使用 MathJax 的本地副本。我尝试了所有可用的字体,但渲染效果并不好。

    我认为更好的解决方案是使用标准字体并使用\mathrm

    $$
    \mathrm{\int_0^1 f(x) dx = 0}
    $$
    

    【讨论】:

      猜你喜欢
      • 2018-05-01
      • 2018-06-22
      • 1970-01-01
      • 2021-09-17
      • 2021-10-11
      • 2021-07-12
      • 1970-01-01
      • 1970-01-01
      • 2022-10-04
      相关资源
      最近更新 更多