xaringan:使用宏添加自定义Latex文件

问题描述 投票:3回答:2

例如,是否可以导入Latex宏文件

\newcommand{\Xcal}{\mathcal{X}

这样我就可以在$...$之间使用它作为$\Xcal$

r r-markdown mathjax xaringan
2个回答
3
投票

是的,这似乎有效:

---
title: "Presentation Ninja"
subtitle: "⚔<br/>with xaringan"
author: "Yihui Xie"
date: "2016/12/12 (updated: `r Sys.Date()`)"
output:
  xaringan::moon_reader:
    lib_dir: libs
    nature:
      highlightStyle: github
      highlightLines: true
      countIncrementalSlides: false
---

<script type="text/x-mathjax-config">
MathJax.Hub.Config({
  TeX: {
    Macros: {
      Xcal: "{\\mathcal{X}}",
      water: "{H_2O}"
    }
  }
});
</script>

$\water$    
$\Xcal$

enter image description here

在脚本标记上使用type=text/x-mathjax-config非常重要,因此mathjax会找到该块。有关在MathJax中定义宏的详细信息,请参阅here

另一种方法是使用before_body YAML选项包含定义:

---
title: "Presentation Ninja"
subtitle: "⚔<br/>with xaringan"
author: "Yihui Xie"
date: "2016/12/12 (updated: `r Sys.Date()`)"
output:
  xaringan::moon_reader:
    lib_dir: libs
    nature:
      highlightStyle: github
      highlightLines: true
      countIncrementalSlides: false
    includes:
      before_body: local.html
---

1
投票

MathJax允许您定义宏。在Xaringan中,您只需将宏放入双美元符号即可。

---
title: "Presentation Ninja"
subtitle: "⚔<br/>with xaringan"
author: "Yihui Xie"
date: "2016/12/12 (updated: `r Sys.Date()`)"
output:
  xaringan::moon_reader:
    lib_dir: libs
    nature:
      highlightStyle: github
      highlightLines: true
      countIncrementalSlides: false
---

$$\newcommand{\Xcal}{\mathcal{X}}$$

# Math Macros

You can define your own macros by putting them in double dollars signs.

```
$$\newcommand{\Xcal}{\mathcal{X}}$$
```

This symbol $\Xcal$ is a calligraphic X.
© www.soinside.com 2019 - 2024. All rights reserved.