2
---
title: "esc"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

A. An amount between $5 and $10.  
B. An amount between \$5 and \$10.  
C. An amount between \\$5 and \\$10.    

X. An equation $1 and 1 = 2$.  
Y. An equation \$1 and 1 = 2\$.  
Z. An equation \\$1 and 1 = 2\\$.  

I've got a similar, but different question here. Please comment if I need to add clarification to differences. I'm asking two different questions and hope that's obvious.

Anyways, the output of knitting the .Rmd above is shown below. Why does example X properly invoke LaTeX, where example A does not? X and A seem almost identical to me, and I'm left wondering why they both don't transform whatever is inside the dollar signs $ into LaTeX text?

I'm aware I could use \( and \) to replace $ and $. I just want to know why $ and $ doesn't properly call LaTeX in my example. It seems arbitray that it works for X, but not A, although I doubt it's arbitrary.

esc rmd output

tarleb
  • 19,863
  • 4
  • 51
  • 80
Display name
  • 4,153
  • 5
  • 27
  • 75

1 Answers1

4

Pandoc's manual, under the Pandoc's Markdown > Math section, probably explains it best:

Anything between two $ characters will be treated as TeX math. The opening $ must have a non-space character immediately to its right, while the closing $ must have a non-space character immediately to its left, and must not be followed immediately by a digit. Thus, $20,000 and $30,000 won’t parse as math. If for some reason you need to enclose text in literal $ characters, backslash-escape them and they won’t be treated as math delimiters.

tarleb
  • 19,863
  • 4
  • 51
  • 80