Can't use Arabic text within an Rmarkdown document

Anyway to include a language other than English in Rmarkdown pdf_document?

Consider using this reprex to reproduce the problem.

---
title: ""
author: ""
date: ""
output:
  pdf_document:
    # latex_engine: xelatex
    keep_md: true
    keep_tex: true
header-includes: 
   # - \usepackage[arabic]{babel}
   - \usepackage[arabic,english]{babel}

   # - \inputencoding{utf8}
   # - \usepackage[utf8]{inputenc}
---
<!-- from https://rstudio.cloud/project/923892 -->

Uncomment the following code if your tinytex is not well configurated. Advisable to use in an Rstudio cloud project.

```{r}
# library(tinytex)
# options(tinytex.verbose = TRUE)
# options(tinytex.clean = FALSE)
# if (!dir.exists('~/.TinyTeX')) {
#   install_tinytex()
# }
# 
# Sys.getenv("PATH")

```

h

ل

dtthf

dgfافق

I wish to knit a document that includes English and Arabic text. The Arabic text is considered Unicode characters and execution halts. Using either of latex engines xelatex or lualatex renders the document successfully, but the Arabic/unicode characters are not rendered; they are simply ignored.

From this Rstudio community topic( Latex language package installation not working - RStudio Cloud - RStudio Community), it seems that there is a problem with defining languages in tinytex. A solution offered was to include:

header-includes:
     \usepackage[icelandic]{babel}

in the YAML header, to use the Icelandic locale provided by the CTAN: Package babel project for multilingual LaTeX support. Using:

header-includes:
     \usepackage[arabic]{babel}

renders Arabic characters perfectly, but renders only Arabic. English letters are converted to Arabic ones, even the R code itself. From the babel support, you can use this:

header-includes:

     \usepackage[arabic, english]{babel}

to declare you are using both English and Arabic, with the last one called (in this case, English) being the default language. However, I get this error: ! LaTeX Error: Command \lam unavailable in encoding T1. The \lam command corresponds to the Arabic letter, lam ( ل ), it just happens to be the first Arabic letter in the text. I tried to use xelatex, I tried to change the encoding into utf8, but none of these solved the solution.

I have no prior LaTeX knowledge so these encoding and multilingual topics seem to difficult for me. The main question is: how to successfully knit a bilingual rmarkdown document, especially English-Arabic document? Any help is most appreciated.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.