use rtl in rmarkdown

hey guys, i want use rtl in rmarkdown, how can i use it?

Rmarkdown uses pandoc for the conversion stuff.
Pandoc has language option, among them rtl or ltr.
https://pandoc.org/MANUAL.html#language-variables

Did you try to set those options ?

----
title: my doc
dir: rtl
output: html_document
---

I did not try myself but this is how you pass pandoc options.
It seems to be accounted for as option in latex template. Not html it seems.

There may be some improvement to be done...

How would you do that usually with HTML or LATEX document ?

hope it helps.

1 Like

thanks cderv
but not work this and give an error:
Error in yaml::yaml.load(..., eval.expr = TRUE) :
Scanner error: while scanning a simple key at line 2, column 1 could not find expected ':' at line 3, column 1
Calls: ... parse_yaml_front_matter -> yaml_load ->
Execution halted

@cderv is correct. I'm able to successfully have an rtl PDF document using the following yaml header:

---
title: "RTL Test"
output:
  pdf_document: 
    latex_engine: xelatex
dir: rtl
---

I'm attaching the resulting document.

rtl_test.pdf (25.3 KB)

2 Likes

Check your yaml header, indentation and syntax.
Yaml is sensible to a lot of things.

@jdb i use the same yaml header, but my output is ltr!

i check any section but is correct

What is you version of pandoc ?
Do you use pdf output ?
Can you share a reproductible example of what you do ?
Thanks.

i don't use pandoc.
yes i use pdf .

title: 'one'
author: "me"
date: "7/26/2019"
output:
pdf_document: default
dir: rtl

If you are using Rmarkdown, you are using pandoc because it is what does the conversion from markdown to other formats. Inside R, you can call

rmarkdown::pandoc_version()

If you use RStudio, it is shipped with the IDE installation. If you don't you need to install it.

Also, you yaml header need to have correct indentation and you need to use xelatex engine for latext, as explain in the doc I linked above
From pandoc MANUAL:

When using LaTeX for bidirectional documents, only the xelatex engine is fully supported (use --pdf-engine=xelatex ).

This is what tried @jdb in his answer and This is working for him.

---
title: 'one'
author: "me"
date: "7/26/2019"
output:
  pdf_document:
    latex_engine: xelatex
dir: rtl
----
2 Likes

version pandoc is 2.3.1
i install tinytex and miktex, but when i run the code get error!!!
+++++++
sh: 1: xelatex: not found
Error: Failed to compile 1.tex. See The R package tinytex - Helper Functions to Manage TinyTeX, and Compile LaTeX Documents - Yihui Xie | 谢益辉 for debugging tips.
In addition: Warning messages:
1: In system2(..., stdout = FALSE, stderr = FALSE) :
error in running command
2: In system2(...) : error in running command
Execution halted

Your latex distribution does not seem to include xelatex.

Personally i use tinytex distribution that works well with rmarkdown

You need to install the package and the distribution.

Otherwise as you use miktex, you need to add support for xelatex in your current distribution.

@cderv thanks for your help
Is there no other way?
And I have another question. In this way, the whole text turns to the right, and what if we want one line to the right and another to the left , how doing?

Pandoc says that it is possible with span or div using a dir attributes.
https://pandoc.org/MANUAL.html#language-variables

You should be able to make it work that way.

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