R Markdown Inline LaTeX Equations: `$` … `$` vs `\(` … `\)`

大城市里の小女人 提交于 2021-02-17 04:51:58

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/62917217/r-markdown-inline-latex-equations-vs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!