简体   繁体   中英

Using R, RStudio Knit to PDF, how to pass tilde to prevent line wrapping "Table~\ref{table:data-from-phone}"?

In Latex, it is common to reference a label using the "~" to keep the number attached to the label such as Figure or Table.

https://tex.stackexchange.com/questions/227285/problems-with-tilde-and-line-breaking/227296 shows an example of this.

A fully working example can be found here:

http://md5.mshaffer.com/WSU_STATS419/stackoverflow/tilde/

In the Rmd file, http://md5.mshaffer.com/WSU_STATS419/stackoverflow/tilde/reference-tilde.Rmd ,

I have the following:

---
title: "Untitled"
output:
  pdf_document:
    keep_tex: true
    number_sections: true
    latex_engine: pdflatex
---


\section{My Section Name}
\label{sec:my}

Below you will find Equation~\ref{eq:my-model}.

\begin{equation}
\label{eq:my-model}
    Y_{jt} = \alpha + \beta X_{jt} + \upsilon_{j}  + \varepsilon_{jt} ,
\end{equation}


\subsection{My sub section}
\label{sec:mysub}

For more information, please refer to Section~\ref{sec:my}.

Notice the "~" tilde being used as outlined in basic Latex usage.

When I click Knit-PDF, it outputs something I did not expect:

http://md5.mshaffer.com/WSU_STATS419/stackoverflow/tilde/reference-tilde.pdf

Since I choose "keep_tex", I can view the .TEX file

http://md5.mshaffer.com/WSU_STATS419/stackoverflow/tilde/reference-tilde.tex which can be seen online here: http://md5.mshaffer.com/WSU_STATS419/stackoverflow/tilde/reference-tilde.tex.txt

It appears to have replaced the tilde with a text version:

\begin{document}
\maketitle

\section{My Section Name}
\label{sec:my}

Below you will find Equation\textasciitilde{}\ref{eq:my-model}.

\begin{equation}
\label{eq:my-model}
    Y_{jt} = \alpha + \beta X_{jt} + \upsilon_{j}  + \varepsilon_{jt} ,
\end{equation}

\subsection{My sub section}
\label{sec:mysub}

For more information, please refer to
Section\textasciitilde{}\ref{sec:my}.

\end{document}

How do I rectify this situation?

How do I get the Latex to render as expected?

How do I get my tilde as a spacer back?

A unicode non-breaking space should work. Or pandoc parses even an HTML entity inside markdown into the correct thing, see eg

echo ' foo' | pandoc -t latex

~foo

If you must include some hard to parse LaTeX in your markdown, you can use generic raw attributes like:

```{=latex}
my LaTeX
```
  1. According to this question and answer , you can try replacing your tilde with "\\~" or "\\sim" and see which one works.

  2. Since you kept the .tex file, you can always search+replace the \\textasciitilde{} with a real tilde, even if #1 does not work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM