sgrubsmyon
sgrubsmyon

Reputation: 1229

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

I am preapring a scientific article manuscript using R Markdown. My R Markdown file is first converted to Markdown by knitr and then to LaTeX code by pandoc.

In LaTeX, the ~ character is used to indicate a non-breaking space. It is considered good style by some journals to use the ~ character in front of \ref or \cite. For instance, LaTeX code like Section~\ref{...} and Figure~\ref{...} or rather Sect.~\ref{...} and Fig.~\ref{...} is expected by my journal.

Trying to use R Markdown to generate LaTeX code as close as possible to the journal's guidelines, I try to use Sect.~\ref{...}, but this is converted to Sect.\textasciitilde{}\ref{...} by pandoc.

How can I prevent pandoc escaping the ~ character to \textasciitilde{} to obtain the valid LaTeX?

Upvotes: 3

Views: 2574

Answers (1)

sgrubsmyon
sgrubsmyon

Reputation: 1229

I have found in the pandoc manual (1, 2) that using Sect.\ \ref{...} solves the problem:

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

Sect.\ \ref{...} in the Markdown file is compiled to Sect.~\ref{...} in the LaTeX file as intended.

Upvotes: 3

Related Questions