某些Unicode字符未显示在RMarkdown PDF输出中 [英] Some Unicode characters not displayed in RMarkdown PDF output

查看:111
本文介绍了某些Unicode字符未显示在RMarkdown PDF输出中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一些课程笔记整理为PDF,但无法使某些Unicode字符正确显示.

I'm trying to put together some course notes as a PDF, and am having trouble getting certain Unicode characters to display properly.

要完全渲染文档,必须使用 xelatex 乳胶引擎(使用默认引擎会由于无法识别的字符而导致错误),但是,只有第一个Unicode字符(大写字母增量)会正确显示.

Using the xelatex latex engine is necessary for the document to be rendered at all (using the default engine results in an error due to the unrecognized characters), however, only the first Unicode character (uppercase delta) is displayed properly.

例如,当使用rmarkdown render()函数呈现以下.Rmd文件时:

For example, when using the rmarkdown render() function to render the following .Rmd file:

---
output:
  pdf_document:
    latex_engine: xelatex
---

- works - Δ
- doesn't work - ⌘

生成的PDF仅显示第一个unicode字符(大写字母delta),而不显示后一个Unicode字符(环形正方形).

The resulting PDF only shows the first unicode character (uppercase delta), and not the later one (looped square).

我知道有不同的字符子集,它们构成了完整的UTF-8字符编码,因此似乎只支持更多基本子集.

I know that there are different character subsets that make up the full UTF-8 character encoding, so it seems like perhaps only more basic subsets are supported.

可以肯定的是,我使用iconv -f UTF-8 your_file -o /dev/null [ 1 ]检查了文件的编码,的确确实是有效的UTF-8文档.

Just to be certain, I checked the encoding of the file using iconv -f UTF-8 your_file -o /dev/null [1], and it does indeed appear to be a valid UTF-8 document.

最后,使用默认选项,文档可以很好地呈现为HTML,因此问题仅针对PDF输出.

Finally, the document renders fine as HTML using the default options, so the issue is specific to PDF output.

有什么想法如何获取第二个字符以呈现为PDF?

Any ideas how to get the second character to render to PDF?

系统信息

  • Linux 64位
  • R 3.3.1
  • rmarkdown 1.0
  • pandoc 1.17.2
  • XeTeX 3.14159265-2.6-0.99996
  • 语言环境:en_US.UTF-8

推荐答案

问题可能是默认字体没有该字符.您需要找到具有该字体的字体.在Linux上,fc-list列出计算机上可用的字体.选择一个并将其添加到您的Yaml前线:

The problem might be that the default font does not have that character. You'll need to find a font that has it. On Linux, fc-list lists the fonts that are available on your computer. Pick one and add it to your yaml front matter:

---
output:
  pdf_document:
    latex_engine: xelatex
mainfont: FreeMono
---

- works - Δ
- doesn't work - ⌘

在这里,我正在使用FreeMono,这是我发现的第一个带有⌘字符的字符,但是可能有一个更好的字符.

Here, I am using FreeMono, which is the first one I found that has the ⌘ character, but there probably is a better one.

这篇关于某些Unicode字符未显示在RMarkdown PDF输出中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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