Search code examples
mathjaxxaringan

Disable MathJax equation reference link in xaringan slides


I've added MathJax equation numbering to my xaringan slides, but the \eqref{} (or \ref{}) link takes me back to the first slide. I want to disable the link and remove the link colouring from the reference.

My .Rmd

---
title: "MathJax test"
output:
  xaringan::moon_reader:
    includes:
      in_header: "mathjax-equation-numbers.html"
    lib_dir: libs
---

\begin{align}
\bar{x} = \frac{1}{n}\sum_{i=1}^{10} x_i \label{my-eq}
\end{align}

An example of an equation is \eqref{my-eq}. Or \ref{my-eq}. 

My attempt at a solution (not working) in the mathjax-equation-numbers.html file:

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    TeX: { equationNumbers: { autoNumber: "AMS" } },
  "HTML-CSS": {
    styles: {
      ".MathJax a": { color: "black",
                      "pointer-events": "none",
                      cursor: "default",
                      "text-decoration": "none"
      },
      ".MathJax_Preview a": { color: "black",
                      "pointer-events": "none",
                      cursor: "default",
                      "text-decoration": "none"
      },
    }
  }
  });
</script>

Solution

  • Try replacing the content of mathjax-equation-numbers.html with below.

    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        TeX: { equationNumbers: { autoNumber: "AMS" } },
      });
    </script>
    <style>
    .mjx-mrow a {
      color: black;
      pointer-events: none;
      cursor: default;
    }
    </style>