@@ -139,6 +139,23 @@ $endif$
139139$if(verbatim-in-note)$
140140\VerbatimFootnotes % allows verbatim text in footnotes
141141$endif$
142+$if(dir)$
143+\ifxetex
144+ % load bidi as late as possible as it modifies e.g. graphicx
145+ $if(latex-dir-rtl)$
146+ \usepackage[RTLdocument]{bidi}
147+ $else$
148+ \usepackage{bidi}
149+ $endif$
150+\fi
151+\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
152+ \TeXXeTstate=1
153+ \newcommand{\RL}[1]{\beginR #1\endR}
154+ \newcommand{\LR}[1]{\beginL #1\endL}
155+ \newenvironment{RTL}{\beginR}{\endR}
156+ \newenvironment{LTR}{\beginL}{\endL}
157+\fi
158+$endif$
142159
143160$if(title)$
144161\title{$title$$if(subtitle)$\\\vspace{0.5em}{\large $subtitle$}$endif$}