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

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

问题描述

---标题:esc";输出:html_document---```{r 设置,包括=FALSE}knitr::opts_chunk$set(echo = TRUE)```A. 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天全站免登陆