4

I'm having trouble printing special characters (ščž) to a pdf report made by knitr.

\documentclass[a4paper, 12pt, oneside]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[slovene]{babel}

\begin{document}

<<>>=
plot(runif(100), main = "ŠČĆŽ ščćž")
@

\end{document}

enter image description here

Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197

1 Answers1

4

Based on comments by Yihui (see also comments below), here's a solution that worked for me. The .Rnw document I'm working with is encoded as UTF-8.

The key is to specify encoding to knit.

enter image description here

Notice that we're still missing the "č" (for non-native speakers, you can read this character as "ch").

The issue can be resolved by specifying a different printing device. Consider specifying dev = "CairoPDF" (requires additional CairoPDF package) or dev = "cairo_pdf" (requires no additional packages) in your chunk option.

<<dev = "CairoPDF">>=
plot(runif(100), main = "ŠČĆŽ ščćž")
@

or

<<dev = "cairo_pdf">>=
plot(runif(100), main = "ŠČĆŽ ščćž")
@

enter image description here

If you're using Eclipse + StatET to weave your reports, you can set these options to automate the workflow.

enter image description here

Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197
  • 1
    Sorry, my comment that you mentioned about the encoding is no longer appropriate. Now you should use `knit(..., encoding='UTF-8')` if you know the document is UTF-8 encoded. It is much safer than `options(encoding = 'UTF-8')`. For the graphical device, you can also try `cairo_pdf`, which is shipped with base R, i.e. no add-on packages required. – Yihui Xie Jun 05 '13 at 18:08
  • 1
    @Yihui well, that... simplifies things. :) I'll edit my answer to reflect the newly found wisdom. – Roman Luštrik Jun 06 '13 at 07:26