Some Unicode characters not displayed in RMarkdown

2019-04-29 15:35发布

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

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.

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

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

- works - Δ
- doesn't work - ⌘

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

enter image description here

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.

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.

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

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

System Information

  • Linux 64-bit
  • R 3.3.1
  • rmarkdown 1.0
  • pandoc 1.17.2
  • XeTeX 3.14159265-2.6-0.99996
  • Locale: en_US.UTF-8

1条回答
在下西门庆
2楼-- · 2019-04-29 16:15

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 - ⌘

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

查看更多
登录 后发表回答