Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xaringan: add custom Latex file with macros

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

like image 875
skd Avatar asked Oct 27 '25 11:10

skd


1 Answers

Yes, this seems to work:

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

It is important to use type=text/x-mathjax-config on the script tag, so mathjax finds the block. Details on defining macros in MathJax can be found here.

An alternative is to include the definition using the before_body YAML option:

---
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
---
like image 186
Martin Schmelzer Avatar answered Oct 30 '25 00:10

Martin Schmelzer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!