用knitr和Rmarkdown生成pdf:文本中带重音,但数字中不带重音. [英] Producing pdf with knitr and Rmarkdown: accents in text show up but not in figures.

查看:152
本文介绍了用knitr和Rmarkdown生成pdf:文本中带重音,但数字中不带重音.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

段落中的口音很完美.图中的文字在绘图查看器中是正确的,但是一旦我编译了pdf,口音就会从图中消失.

Accents in paragraphs work perfectly. Text in figures is correct in the plot viewer, but once I compile the pdf the accents disappear from the figures.

这是一个重现此问题的示例.

Here's an example that reproduces the issue.

---
title: 'Some title'
author: 'This be me'
date: '`r format(Sys.Date(), "%B %Y")`'
lang: es
header-includes: 
  - \usepackage{tikz}
output: 
  pdf_document:
    fig_caption: yes
---


```{r global options, echo = F, message=F}
library(knitr)
opts_chunk$set(fig.width=6, fig.height=3.5, dev = 'tikz')
```

I have some paragraphs that include cool accents like áspid. 

If I run the next chunk in the R console I see the accent on the figure it generated. But the accent is missing in the pdf. 


```{r}
plot(pressure, main= "áspid")
```

推荐答案

这看起来像R tikzDevice包中的错误.它使用UTF-8编码生成.tikz文件,但不包含类似

This looks like a bug in the R tikzDevice package. It generates a .tikz file using the UTF-8 encoding, but doesn't include something like

\usepackage[utf8]{inputenc}

在其中声明编码.在其文档中,有许多对?tikzDevice帮助主题的"Unicode"部分的引用,但是没有这样的部分.您可能想在Github页面上报告该软件包的问题,​​ https://github.com/yihui/tikzDevice .

in it to declare the encoding. There are a number of references in its documentation to the "Unicode" section of the ?tikzDevice help topic, but there is no such section. You might want to report an issue on the Github page for the package, https://github.com/yihui/tikzDevice.

编辑后添加:

经过一些试验,我看不到将该行添加到.tikz文件的方法,但是请求了xelatex而不是默认的LaTeX引擎 确实有效.您可以通过添加R代码来做到这一点

After some experimentation, I can't see a way to add that line to the .tikz file, but requesting xelatex instead of the default LaTeX engine does seem to work. You can do that by adding the R code

options(tikzDefaultEngine = "xetex")

进入您的早期代码块.数字将使用xelatex,其余部分将使用pdflatex. ("xetex"不是错字;这就是您请求xelatex的方式.)

into your early code chunk. That will use xelatex for the figures, pdflatex for the rest. ("xetex" is not a typo; that's how you request xelatex.)

如果需要,可以使用YAML标头中的latex_engine: xelatex切换到xelatex,但是除非您还添加选项设置,否则数字仍将使用pdflatex.

If you want, you can switch to xelatex for the rest using latex_engine: xelatex in the YAML header, but the figures will still use pdflatex unless you also add the option setting.

这篇关于用knitr和Rmarkdown生成pdf:文本中带重音,但数字中不带重音.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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