Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Some Unicode characters not displayed in RMarkdown PDF output

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
like image 659
Keith Hughitt Avatar asked Aug 29 '16 12:08

Keith Hughitt


Video Answer


1 Answers

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.

like image 166
scoa Avatar answered Oct 17 '22 18:10

scoa