3

Is it possible to import a Latex macro file, for instance

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

so that I can then use it between $...$ as $\Xcal$?

4

2 回答 2

4

是的,这似乎有效:

---
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$

在此处输入图像描述

在 script 标签上使用很重要type=text/x-mathjax-config,因此 mathjax 会找到该块。有关在 MathJax 中定义宏的详细信息,请参见此处

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

---
title: "Presentation Ninja"
subtitle: "⚔&lt;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
---
于 2019-03-22T01:06:21.807 回答
3

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

---
title: "Presentation Ninja"
subtitle: "⚔&lt;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.
于 2019-04-02T18:04:00.880 回答