如何使用 R markdown 和 pandoc 防止 LaTeX 文档中的 ~(波浪号)字符转义?

How to prevent escape of a ~ (tilde) character in LaTeX document using R markdown and pandoc?

我正在使用 R Markdown 准备科学文章手稿。我的 R Markdown 文件首先由 knitr 转换为 Markdown,然后由 pandoc 转换为 LaTeX 代码。

在 LaTeX 中,~ 字符用于表示不间断的 space。 It is considered good style 一些期刊在 \ref\cite 前面使用 ~ 字符。例如,像 Section~\ref{...}Figure~\ref{...} 或者 Sect.~\ref{...}Fig.~\ref{...} 这样的 LaTeX 代码是我的期刊所期望的。

尝试使用 R Markdown 生成尽可能接近期刊指南的 LaTeX 代码,我尝试使用 Sect.~\ref{...},但这被 pandoc 转换为 Sect.\textasciitilde{}\ref{...}

如何防止 pandoc 将 ~ 字符转义为 \textasciitilde{} 以获得有效的 LaTeX?

我在 pandoc 手册 (1, 2) 中发现使用 Sect.\ \ref{...} 可以解决问题:

A backslash-escaped space is parsed as a nonbreaking space. It will appear in TeX output as ~ and in HTML and XML as \  or \ .

Markdown 文件中的

Sect.\ \ref{...} 按预期编译为 LaTeX 文件中的 Sect.~\ref{...}