ohnoplus
ohnoplus

Reputation: 1335

Can I strike out text in an equation in R markdown

I have an equation that I wrote in r-markdown as follows

$$ 2 \frac{meter}{day} * 3 ~ days $$

base equation

I'd like to show that the days cancel by striking them out. You can strike out text in r-markdown normally by ~~surrounding the text in tildaes~~

However, the tildae in the expression seems to only insert spaces.

$$ 2 \frac{meter}{~~day~~} * 3 ~ ~~days~~ $$

tildae

I also tried as one might in latex

$$ 2 \frac{meter}{sout{day}} * 3 ~ days $$

But this doesn't seem to work either.

souteqn

Are there any options for striking out bits of equation that work in r-markdown equations?

Upvotes: 6

Views: 3842

Answers (2)

jpneto
jpneto

Reputation: 143

For HTML, add at the beginning of the markdown,

<script type="text/x-mathjax-config">
MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
  MathJax.Hub.Insert(MathJax.InputJax.TeX.Definitions.macros,{
    cancel: ["Extension","cancel"],
    bcancel: ["Extension","cancel"],
    xcancel: ["Extension","cancel"],
    cancelto: ["Extension","cancel"]
  });
});
</script>

and then

$$2 \frac{\text{meter}}{\cancel{\text{day}}} * 3 ~ \cancel{\text{days}}$$

will work

enter image description here

Upvotes: 3

Ralf Stubner
Ralf Stubner

Reputation: 26833

For PDF output you can use the LaTeX style cancel:

---
header-includes: \usepackage[makeroom]{cancel}
output: pdf_document
---

$$ 2 \frac{\text{meter}}{\cancel{\text{day}}} * 3 ~ \cancel{\text{days}} $$

Result:

enter image description here

Note that the usage of \text is unrelated to your question and only used for typographical reasons.

Unfortunately this does not work with HTML output.

Upvotes: 3

Related Questions