2

I am trying to get some greek characters into the rownames of a table in rmarkdown knitting to pdf. I am using knitr, pander and MacTex. It seems like pander accepts some unicode characters but not others. When i use \u2013 (emdash) it works.

---
title: "Untitled"
author: "Llew Mills"
date: "24 June 2016"
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(fig.width=12, fig.height=8, fig.path='Figs/', 
                      echo=FALSE, warning=FALSE, message=FALSE, dev = 'pdf')
```

``` {r stuff}

library(pander)

m1 <- rnorm(12,8,3)
m2 <- rnorm(12,4,5)
m3 <- rnorm(12,5,1)
mR <- rep("gene \u2013", 12)
df <- data.frame(mR,m1,m2,m3)

pander(df, justify = "right", style = "simple")


```

However if instead of that unicode character I use the unicode for gamma \u03B3 i get the error message ! Package inputenc Error: Unicode char \u8:γ not set up for use with LaTeX.

Does anyone know if there is a list of unicode characters that are compatible with LaTex, or alternatively a way to get latex to accept all unicode characters?

llewmills
  • 2,959
  • 3
  • 31
  • 58
  • 1
    Why don't you just use `$\gamma$`? – Werner Jun 24 '16 at 16:16
  • If I replace `"gene u\2013"` with either `$\gamma$` or `"$\gamma$"` the rmarkdown document will not knit, with error `Error: '\g' is an unrecognized escape in character string starting ""$\g"` – llewmills Jun 24 '16 at 19:59
  • 1
    @llewmills what if you escape the backslash? Eg `$\\gamma$` – daroczig Jun 26 '16 at 04:06
  • Yes!!!! `mR <- rep("$\\gamma$", 12)` worked. Hallelujah. Once again you have come through @daroczig. Wish I could give you more than the upvote. Thank you so much. This is great too because it will enable all that LaTex math functionality like subscripts etc to be passed into the table. Brilliant. – llewmills Jun 26 '16 at 05:35

1 Answers1

1

I think it's an issue with your locale/console settings and not really a pander issue, as this seems to work fine in a console with support for Unicode chars:

pander with unicode chars

But pdflatex indeed sucks with Unicode chars, you might better try eg xelatex.

PS: sorry for posting this comment as an answer, but this was the easiest way to add an image

daroczig
  • 28,004
  • 7
  • 90
  • 124
  • hi again! Can you get the unicode for gamma, `\u03B3`, to work on your machine? – llewmills Jun 24 '16 at 22:24
  • damn. ok. so it's a latex issue. thank you. very helpful as always. will have to try and source xelatex from somewhere. – llewmills Jun 25 '16 at 05:16
  • 1
    @llewmills see the `latex_engine` rmarkdown option at http://rmarkdown.rstudio.com/pdf_document_format.html#latex_engine – daroczig Jun 25 '16 at 11:21
  • Thanks @darzcig, yes I tried that yesterday but I get an error `Scanner error: mapping values are not allowed in this context at line 5, column 16` when I use this option. And I updated to MacTex 2016 last night. I also changed from pdflatex to XeLatex in RStudio Tools-Global Options, but still no greek gamma with unicode \u03B3.. This is getting very frustrating. – llewmills Jun 26 '16 at 01:20