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).
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With