6

I am trying ot write a paper in RMarkdown pdf. But I dont know how to use special characters like "İ, ı, ğ, ü, ö". Those characters are present in Turkish. I can easily use them in Latex using e.g. \u{g} – ğ, \c{c} – ç, \”{u} – ü, {\i} – ı, etc.

Could you please tell how can I do the same in RMarkdown?

And where can I find some Rmarkdown paper or book templates?

ilker_arslan
  • 637
  • 3
  • 7
  • 17
  • depends a lot on your environment. The answer is probably to create them however you are generating them to type them into StackOverflow -- compose key? (On Linux I can get ü (Compose-"-u) or ç (Compose-,-c) pretty easily. I can get g with a caron ǧ (Compose-c-g), ğ (Compose-U-g) ...) – Ben Bolker Nov 08 '14 at 20:07

5 Answers5

11

HTML codes for Turkish characters will work (example from wikipedia):

---
title: "My doc"
output: pdf_document
---

HTML      char  detail                            anglicized
-------   --    ------------------------------    ---
Ğ   Ğ       Uppercase "G" with breve accent   gh1
İ     İ     Uppercase dotted "I"²               i (as in "tree")
Ş     Ş     Uppercase "S" with cedilla          sh
ğ     ğ     Lowercase "g" with breve accent   gh1
ı     ı     Lowercase dotless "i"³              ou (as in "in")
ş     ş     Lowercase "s" with cedilla          sh
-------   --    -------------------------------   --

Which renders the PDF like this:

enter image description here

For article templates, see the rticles package, or make your own

For book templates, have a look at pandoc ebook, gitbook and bookdown


This xelatex option I initially suggested will not work for Turkish characters:

The xelatex engine is recommended for this kind of thing. Then you can access your system fonts with the mainfont argument:

---
title: "My doc"
output:
  pdf_document:
    latex_engine: xelatex
mainfont: "name of your system font that has all those characters"
---

PDF output will be in the font you specify. 

Just type as normal with no special codes.
Community
  • 1
  • 1
Ben
  • 41,615
  • 18
  • 132
  • 227
  • I just realized that that doesn't work for İ, Ş, Ğ, ı, ş, ğ. They still appear as I, S, G, i, s, g. Do you have any idea? Thanks in advance. – ilker_arslan Nov 08 '14 at 23:10
  • Right, yes, another option is HTML codes, I've added it to my answer. – Ben Nov 09 '14 at 01:10
4

I guess this question per se is obsolete. As of now (rmarkdown V1.4 / knitr V1.15.1), knitr automatically follows the advice of this question and includes

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

in the preamble to LaTeX output (caveat: of course this means that your document editor will have to be using UTF-8, but e.g., RStudio does that by default).

Then this works as expected:

---
title: "Test"
output: pdf_document
---

Here are some special characters: İ ı Ş Ğ ş ğ ö ü

This is not a panacea, as many scripts still require more tinkering (I tried Korean, Chinese, and Japanese). See here for where to start on bolstering the preamble in case you need more multifarious fonts.

MichaelChirico
  • 33,841
  • 14
  • 113
  • 198
3

rmarkdown uses LaTeX to create the PDF, so you should be able to just use LaTeX markup. As an example:

---
title: "Test"
output: pdf_document
---

This is a special character: \u{g}.

Also, depending on the particular characters, you may be able to just type them in as-is (see, for example, here).

Community
  • 1
  • 1
Thomas
  • 43,637
  • 12
  • 109
  • 140
  • 1
    That is ok for ğ,Ğ,ş, and Ş but doesn't work for İ and ı. \.{I} is seen on the output as .{I}. Do you have any idea how can I solve it? – ilker_arslan Nov 09 '14 at 11:05
1

If you need special characters for other languages in addition to Turkish, looks like you can type in the code listed at this webpage:

http://www.starr.net/is/type/htmlcodes.html

Be sure to include the ;

K Bro
  • 359
  • 3
  • 6
0

This might be too late but I would like to add someothing in addition to the amazing and straightforward existing answers so far. This answer also works not only for pdf_documents but also for html_ and word_documents.

Solution: Use the

  1. base R functions capture.output() and cat()
  2. Unicode notation

Example: Consider writing ñ. A quick look at https://www.compart.com/en/unicode/U+00F1, gives us the U+00F1 code for ñ. In R, this is \u00f1. An MWE is as follows.

---
title: "Minimum Working Example"
author: "Mr. John Ate`r capture.output(cat('\u00f1'))`o"
output:
  pdf_document: default
  word_document: default
  html_document: default
---

## Some Example of Printing `r capture.output(cat('\u00f1'))`

This is an inline output of `r capture.output(cat('\u00f1'))`.

Simplification: It is quite cumbersome to use the capture.output(cat()) all the time so we can define a custom function say

diac <- function(x) {
  capture.output(cat(x))
}

and use it inline as follows: `r diac('\u00f1')`.

venrey
  • 175
  • 9