在Rmarkdown的PDF输出中使用Fira代码启用连字 [英] Enable ligatures with Fira Code in PDF output of Rmarkdown

查看:67
本文介绍了在Rmarkdown的PDF输出中使用Fira代码启用连字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码使我可以将

该解决方案在

以下YAML不起作用.

  ---monofont:费拉代码"输出:pdf_document:latex_engine:xelatex标头包括:|\ makeatletter\ def \ verbatim @ nolig @ list {}\ makeatother--- 

可以直接在YAML中完成启用连字吗?

解决方案

如果查看生成的LaTeX输出,则会看到大括号被引用了: \ def \ verbatim @ nolig @ list \ {\}.这个引用问题已在github上的多个问题中进行了讨论,并且似乎有可用的修复程序(参见这个问题),但由于我的Debian测试机器仍使用pandoc 1.19.2.4,因此我尚未对其进行测试.解决方法是,可以将必要的命令放在单独的文件中,例如 preamble.tex :

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

然后使用

  ---monofont:费拉代码"输出:pdf_document:latex_engine:xelatex包括:in_header:preamble.tex---```{r setup,include = FALSE}knitr :: opts_chunk $ set(echo = TRUE)``````{r}x <-1:5x!= 2``` 

The following code enables me to use Fira Code as mono font.

---
monofont: "Fira Code"
output: 
  pdf_document:
    latex_engine: xelatex
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r}
x <- 1:5
x != 2
```

This produces the desired ligature for != but not for <-.

The solution detailed in the accepted answer in this post works when done in LaTeX, e.g.,

\documentclass{article}

\usepackage{mathspec}
\setmonofont[Contextuals={Alternate}, Scale=0.75, Ligatures=TeX]{Fira Code}
\makeatletter
\def\verbatim@nolig@list{}
\makeatother

\begin{document}

\begin{verbatim}
x <- 1:5
x != 2
\end{verbatim}

\end{document}

The following YAML does not work.

---
monofont: "Fira Code"
output: 
  pdf_document:
    latex_engine: xelatex
header-includes: |
  \makeatletter
  \def\verbatim@nolig@list{}
  \makeatother
---

Can enabling ligatures be done directly in the YAML?

解决方案

If you look at the generated LaTeX output you see that the curly braces have been quoted: \def\verbatim@nolig@list\{\}. This quoting issue has been discussed in several issues on github, and there seems to be a fix available (c.f. this issue), but I have not tested it since my Debian testing machine still uses pandoc 1.19.2.4. As a workaround you can place the necessary commands into a separate file, say preamble.tex:

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

and then use

---
monofont: "Fira Code"
output: 
  pdf_document:
    latex_engine: xelatex
    include:
      in_header: preamble.tex
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r}
x <- 1:5
x != 2
```

这篇关于在Rmarkdown的PDF输出中使用Fira代码启用连字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆