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: ""
    # latex_engine: xelatex
    keep_md: true
    keep_tex: true
   # - \usepackage[arabic]{babel}
   - \usepackage[arabic,english]{babel}

   # - \inputencoding{utf8}
   # - \usepackage[utf8]{inputenc}
<!-- from -->

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

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






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:


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


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:


     \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.

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.