将连字添加到Rmarkdown代码

时间:2018-04-05 12:58:07

标签: r latex r-markdown

我在R markdown中使用字体DejaVu Sans Code作为我的代码块,但只有部分代码连字正在工作,例如,以下代码:

---
output:
  pdf_document:
    latex_engine: xelatex
monofont: DejaVu Sans Code
---

Here is some code:

```{r}
x <- 5 + 10
y <- (x != 15)
```

产地:

Example output

!=连字是有效的,但不是<-连字,有没有办法解决这个问题?可能使用fontspec Ligatures=

1 个答案:

答案 0 :(得分:0)

一种方法是将Sweave与XeLaTeX一起用作编译器。

this answer借用代码:

\documentclass{article}

\usepackage{fontspec}

\setmonofont{DejaVu Sans Code}

\makeatletter
\def\verbatim@nolig@list{}
\makeatother

\begin{document}
<<>>=
x <- 5 + 10
y <- (x != 15)
@

\begin{verbatim}
== != ~= === !== <!-- <-- <- -> --> <= >= => <=> ++ ::
\end{verbatim}
\end{document}

给出以下内容:

Result

所有连字正确。

相关问题