【问题标题】:Font issue in rmarkdown slides with Metropolis theme带有 Metropolis 主题的 rmarkdown 幻灯片中的字体问题
【发布时间】:2019-08-27 09:16:37
【问题描述】:

我正在使用 rmarkdown 包来制作带有 Metropolis 主题的 PDF 幻灯片。最近,我注意到方程开始出现不同的显示 - 它们使用不同的字体。

*.Rmd 文件的最小示例:

---
output: 
  beamer_presentation:
    theme: "metropolis"
    latex_engine: xelatex
    keep_tex: true
---

## Problem with font
$$f(x_i\mid\mu,\sigma^2) = \exp\left\{-\frac{(x_i-\mu)^2}{2\sigma^2}\right\}$$

在 RStudio 中编织时,会产生:

这看起来与直接在 LaTeX 中使用 xelatex 编译同一张幻灯片时获得的不同:

\documentclass{beamer}
\usetheme{metropolis}

\begin{document}

\begin{frame}{Problem with font}

\[f(x_i\mid\mu,\sigma^2) = \exp\left\{-\frac{(x_i-\mu)^2}{2\sigma^2}\right\}\]

\end{frame}

\end{document}

产生:

这看起来差别不大,但在其他方程式中缺少一些特殊字符,并且字体大小略有不同,影响了我幻灯片的整体布局。

经过一番调查,事实证明在rmarkdown生成的tex文件中注释掉这两行会更好:

  %\usepackage{unicode-math}
  %\defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase}

unicode-math 包是(唯一的)罪魁祸首吗?如何解决这个问题并确保 Metropolis 使用正确的字体而不需要手动更改 tex 文件?

提前感谢您的帮助!

系统配置:

  • RStudio 1.2.1335
  • rmarkdown 1.15
  • pandoc 2.3.1(通过 RStudio)
  • Metropolis theme1.2
  • Fira Sans font4.3
  • XeTeX 3.14159265-2.6-0.999991(TeX Live 2019)

【问题讨论】:

  • 似乎 rmarkdown 出于某种原因设置了 pandoc mathspec 变量?尝试取消设置。我在默认模板 (pandoc -D latex) 中搜索了unicode-math,结果出现了……见pandoc.org/MANUAL.html#templates
  • 感谢您的反馈。正如@tarleb 建议的那样,强制 pandoc 使用 mathspec 包解决了这个问题。

标签: r r-markdown pandoc xelatex


【解决方案1】:

您所看到的确实是 unicode-math 包的效果。有一种简单的方法可以通过强制 pandoc 使用 mathspec 包来解决这个问题。这可以通过在元数据中设置 mathspec: true 来完成

---
mathspec: true
output: …
---

或者在调用 pandoc 时设置相应的变量

---
output: 
  beamer_presentation:
    theme: "metropolis"
    latex_engine: xelatex
    pandoc_args: ["--variable=mathspec"]
---

两者之间只有很小的、非常微妙的、几乎无关紧要的区别。我建议使用第一个版本,因为它更简单。

有关differences between unicode-math and mathspec 的讨论,请参见 TeX StackExchange。

【讨论】:

  • 这解决了我的问题,非常感谢! (我不知道 unicode-math 和 mathspec 之间的这种区别。)
猜你喜欢
  • 2014-01-03
  • 2013-09-03
  • 2017-10-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-15
  • 1970-01-01
相关资源
最近更新 更多