【问题标题】:xaringan: add custom Latex file with macrosxaringan:添加带有宏的自定义 Latex 文件
【发布时间】:2019-08-12 03:05:02
【问题描述】:

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

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

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

【问题讨论】:

    标签: r r-markdown mathjax xaringan


    【解决方案1】:

    是的,这似乎有效:

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

    在脚本标签上使用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
    ---
    

    【讨论】:

    • 谢谢。它确实有效!我有点希望你可以使用文件中现有的 Latex 宏,但我想我总是可以编写一个快速程序来将它们解析成这种格式
    【解决方案2】:

    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.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-26
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      • 2021-07-10
      • 2019-03-18
      • 2013-11-21
      相关资源
      最近更新 更多