Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTL (Right-To-Left) latex environment not defined for xelatex #8460

Open
daamien opened this issue Nov 28, 2022 · 10 comments
Open

RTL (Right-To-Left) latex environment not defined for xelatex #8460

daamien opened this issue Nov 28, 2022 · 10 comments

Comments

@daamien
Copy link
Contributor

daamien commented Nov 28, 2022

Hi !

Thanks for this amazing software !

I am trying to build a document writtent in a Right-To-Left language

Here's a minimal example:

<div dir="rtl" markdown="1"> 
ﭗﯿﺸﮕﻔﺗﺍﺭ                                                                                                
</div>   

When I try to generate the PDF with this command

pandoc --pdf-engine=xelatex sample.md -o sample.pdf

I get this error

Error producing PDF.                                                                                                                                      
! LaTeX Error: Environment RTL undefined.                                                                                                                 
                                                                                                                                                          
See the LaTeX manual or LaTeX Companion for explanation.                                                                                                  
Type  H <return>  for immediate help.                                                                                                                     
 ...                                                                                                                                                      
                                                                                                                                                          
l.62 \begin{RTL}                                                                                                                                                            

Looking at the default template, I can see that the RTL env is only defined for pdftex

https://github.com/jgm/pandoc-templates/blob/master/default.latex#L354

Is there's a specific reason for that ?

Would it be possible to this env for xelatex too ?

@jgm
Copy link
Owner

jgm commented Nov 28, 2022

I believe the RTL environment is provided by the bidi package.
My vague recollection is that those definitions were added for pdflatex because it didn't use bidi?
Something may have changed regarding this when we switched from using polyglossia to using babel.
@mb21 @adunning can you see what is going on here and how it should be fixed?

@jgm
Copy link
Owner

jgm commented Nov 28, 2022

You could try adding \usepackage{bidi} to your preamble to see if that helps.

@daamien
Copy link
Contributor Author

daamien commented Nov 28, 2022

Yes ! Adding bidi in the header solves the problem.

Sorry I am not familiar with that topic, but at first glance I'd say that when dir = rtl and --pdf-engine=xelatex are defined, then the bidi package should loaded by the template...

@jgm
Copy link
Owner

jgm commented Nov 28, 2022

Sorry I am not familiar with that topic, but at first glance I'd say that when dir = rtl and --pdf-engine=xelatex are defined, then the bidi package should loaded by the template...

Yes, I think that's probably right -- and probably it wasn't needed before, because polyglossia loaded it automatically. But let me see if anyone can confirm that.

@jgm
Copy link
Owner

jgm commented Nov 29, 2022

See https://tex.stackexchange.com/questions/392175/how-can-i-defer-the-loading-of-the-bidi-package for some hints on loading order for bidi. This also confirms that bidi is loaded by polyglossia, which is probably why we originally loaded it only for pdflatex.

@daamien
Copy link
Contributor Author

daamien commented Nov 29, 2022

Sure, The workaround is easy and there's no hurry...

Thanks again for your time and efforts

@tarleb
Copy link
Collaborator

tarleb commented Nov 29, 2022

Somewhat related: #8283.

@jgm
Copy link
Owner

jgm commented Dec 2, 2022

I tried the following patch to the latex template:

diff --git a/data/templates/default.latex b/data/templates/default.latex
index bb752a680..e9c69537b 100644
--- a/data/templates/default.latex
+++ b/data/templates/default.latex
@@ -357,15 +357,6 @@ $endfor$
 \ifLuaTeX
   \usepackage{selnolig}  % disable illegal ligatures
 \fi
-$if(dir)$
-\ifPDFTeX
-  \TeXXeTstate=1
-  \newcommand{\RL}[1]{\beginR #1\endR}
-  \newcommand{\LR}[1]{\beginL #1\endL}
-  \newenvironment{RTL}{\beginR}{\endR}
-  \newenvironment{LTR}{\beginL}{\endL}
-\fi
-$endif$
 $if(natbib)$
 \usepackage[$natbiboptions$]{natbib}
 \bibliographystyle{$if(biblio-style)$$biblio-style$$else$plainnat$endif$}
@@ -392,6 +383,17 @@ $endif$
 $if(verbatim-in-note)$
 \VerbatimFootnotes % allow verbatim text in footnotes
 $endif$
+$if(dir)$
+\ifPDFTeX
+  \TeXXeTstate=1
+  \newcommand{\RL}[1]{\beginR #1\endR}
+  \newcommand{\LR}[1]{\beginL #1\endL}
+  \newenvironment{RTL}{\beginR}{\endR}
+  \newenvironment{LTR}{\beginL}{\endL}
+\else
+  \usepackage{bidi}
+\fi
+$endif$
 \hypersetup{
 $if(title-meta)$
   pdftitle={$title-meta$},

But this did not work. Tried with

::: {dir=rtl}
hello
:::

With --pdf-engine=pdflatex I get 'olleh' at the left margin. With --pdf-engine=xelatex I get 'hello' at the right margin. With --pdf-engine=lualatex I get


Error producing PDF.
! Emergency stop.
<read *> 
   
l.91 \RequireXeTeX

So this isn't the solution.

@jgm
Copy link
Owner

jgm commented Dec 2, 2022

If we can't find a solution, we may need to document that dir=rtl won't work with xelatex and lualatex. But hopefully there's a better way!

@tarleb
Copy link
Collaborator

tarleb commented Dec 9, 2022

I got decent result with --pdf-engine=lualatex when using the luabidi package. Still trying to get xelatex to work, no success so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants