R Markdown 内联 LaTeX 方程:`$` ... `$` vs `\(` ... `\)` [英] R Markdown Inline LaTeX Equations: `$` ... `$` vs `\(` ... `\)`

查看:41
本文介绍了R Markdown 内联 LaTeX 方程:`$` ... `$` vs `\(` ... `\)`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  ---标题:"esc"输出:html_document---```{r setup,include = FALSE}knitr :: opts_chunk $ set(echo = TRUE)```答:5美元到10美元之间的金额.B. \ $ 5到\ $ 10之间的金额.C.介于\\ $ 5到\\ $ 10之间的金额.X.等式$ 1和1 = 2 $.Y.方程\ $ 1和1 = 2 \ $.Z.方程\\ $ 1和1 = 2 \\ $. 

我有一个类似但不同的问题

解决方案

Pandoc手册,在 Pandoc的Markdown>数学部分,可能最好地解释了这一点:

两个 $ 字符之间的任何字符都将被视为TeX数学.开头的 $ 的右边必须有一个非空格字符,而结尾的 $ 的左边必须有一个非空格字符,并且不能跟在后面立即由一个数字表示.因此, $ 20,000和$ 30,000 不会解析为数学.如果出于某种原因您需要用文本 $ 字符括住文本,请对它们进行反斜杠转义,这样它们就不会被视为数学定界符.

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

解决方案

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.

这篇关于R Markdown 内联 LaTeX 方程:`$` ... `$` vs `\(` ... `\)`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆