# LuaTeX RTL text: Wrong horizontal spacing in headlines

When typesetting syriac RTL text in LuaTeX, it seems the right-alignment of section and subsection headlines has a bug. It seems that the small horizontal space between number and headline text is still typesetted to the right of the number, resulting in a small indentation of the whole headline from the right and in a missing horizontal space between number and headline.

MWE:

\documentclass{scrartcl}
\usepackage{fontspec}

\newfontfamily\syriacfont[Script=Syriac, Scale=1.2]{estre.otf}

\newcommand{\textsyriac}[1] % Syriac inside LTR
{\bgroup\luatextextdir TRT\syriacfont #1\egroup}
\newcommand{\n}         [1] % for digits inside RTL text
{\bgroup\luatextextdir TLT #1\egroup}
\newenvironment{syriac}     % Syriac paragraph
{\luatextextdir TRT\luatexpardir TRT\syriacfont}{}

\setlength{\parindent}{0pt}

\begin{document}

\section{English section}

The number of the english section is aligned to the left edge of the column.
There is a horizontal space between number and headline.

In the RTL (syriac) paragraph below, the section number is not right aligned
to the right edge of the column. It seems the horizontal space which is
supposed to be between number and headline is still on the right side of the
number, though it should switch to the left.

\subsection{English subsection}

The same issue holds for subsections.

\begin{syriac}
\section{\textsyriac{ܡܿܟܪܟܝ}}
ܘܟܕ ܡܿܟܪܟܝܢ ܐܪܟܢܐ ܗ̄ ܡܘܪܐ ܗܿܝ ܩ7ܕܡܝܬܐ

\subsection{\textsyriac{ܡܿܟܪܟܝ}}
ܘܟܕ ܡܿܟܪܟܝܢ ܐܪܟܢܐ ܗ̄ ܡܘܪܐ ܗܿܝ ܩ7ܕܡܝܬܐ
\end{syriac}

\end{document}


The problem also occurs when using article.cls instead of scrartcl.cls, and when using arabic script instead of syriac. Maybe it is a general problem with the \section command in RTL typesetting? Or did I do anything wrong in the setup of the RTL environment?

Note: The problem does not appear when using a XeLaTeX + polyglossia + bidi setup. It seems specific to LuaTeX.

The problem is resolved by adding \bodydir TRT to the definition of the syriac environment. So, the correct definition is
\newenvironment{syriac}