3

So far, I haven't found a way to have the standard list environments correctly indented under LuaTeX in right-to-left mode without using both of the \bodydir and \pagedir primitives, like so:—

\documentclass{article}

\begin{document}

\bodydir TRT
\pagedir TRT
desserts.\footnote{Would you have any?}
\begin{enumerate}
\pardir TRT
\textdir TRT
\item desserts desserts desserts desserts desserts desserts desserts
  desserts desserts desserts desserts desserts desserts desserts
  desserts desserts desserts desserts desserts desserts desserts
  desserts desserts desserts desserts desserts desserts desserts
  desserts desserts desserts desserts desserts desserts desserts
  desserts desserts.
  \item desserts.
    \begin{itemize}
    \item desserts desserts desserts desserts desserts desserts
      desserts desserts desserts desserts desserts desserts desserts
      desserts desserts desserts desserts desserts desserts desserts
      desserts desserts desserts desserts desserts desserts desserts
      desserts desserts desserts desserts desserts desserts desserts
      desserts desserts desserts desserts.
      \begin{itemize}
      \item desserts.
      \end{itemize}
    \item desserts desserts desserts desserts desserts desserts
      desserts desserts desserts desserts desserts desserts desserts
      desserts desserts desserts desserts desserts desserts desserts
      desserts desserts desserts desserts desserts desserts desserts
      desserts desserts desserts desserts desserts desserts desserts
      desserts desserts desserts.
    \end{itemize}
\end{enumerate}

% \bodydir TLT
% \pagedir TLT
\pardir TLT
\textdir TLT
desserts.\footnote{Would you have any?}

\end{document}

Note that both \bodydir and \pagedir have to be set outside the list environment; otherwise the indentation appears on the left side, which is wrong.

The problem is that I get into trouble when I try to set \bodydir and \pagedir back to TLT.

As for the above mwe, it compiles fine, but the footnote rule is flushed right while I would like to have it flushed left.

Any help would be much appreciated.

3

So far, I haven't found a way to have the standard list environments correctly indented under LuaTeX in right-to-left mode without using both of the \bodydir and \textdir primitives, like so:—

You meant \pagedir not \textdir?

LuaTeX's bidi model has too many bugs so it is much better to forget \pagedir and \bodydir and just work with \pardir and \textdir.

This is taken (almost) verbatim from the bidi package:

\documentclass{article}
\usepackage{lipsum}
\makeatletter
\def\list#1#2{%
  \ifnum \@listdepth >5\relax
    \@toodeep
  \else
    \global\advance\@listdepth\@ne
  \fi
  \rightmargin\z@
  \listparindent\z@
  \itemindent\z@
  \csname @list\romannumeral\the\@listdepth\endcsname
  \def\@itemlabel{#1}%
  \let\makelabel\@mklab
  \@nmbrlistfalse
  #2\relax
  \@trivlist
  \parskip\parsep
  \parindent\listparindent
  \advance\linewidth -\rightmargin
  \advance\linewidth -\leftmargin
  \advance\@totalleftmargin \rightmargin
  \parshape \@ne \@totalleftmargin \linewidth
  \ignorespaces}

\def\itemize{%
  \ifnum \@itemdepth >\thr@@\@toodeep\else
    \advance\@itemdepth\@ne
    \edef\@itemitem{labelitem\romannumeral\the\@itemdepth}%
    \expandafter
    \list
      \csname\@itemitem\endcsname
      {\def\makelabel##1{\llap{##1}\hss}}%
  \fi}

\def\@item[#1]{%
  \if@noparitem
    \@donoparitem
  \else
    \if@inlabel
      \indent \par
    \fi
    \ifhmode
      \unskip\unskip \par
    \fi
    \if@newlist
      \if@nobreak
        \@nbitem
      \else
        \addpenalty\@beginparpenalty
        \addvspace\@topsep
        \addvspace{-\parskip}%
      \fi
    \else
      \addpenalty\@itempenalty
      \addvspace\itemsep
    \fi
    \global\@inlabeltrue
  \fi
  \everypar{%
    \@minipagefalse
    \global\@newlistfalse
    \if@inlabel
      \global\@inlabelfalse
      {\setbox\z@\lastbox
       \ifvoid\z@
         \kern-\itemindent
       \fi}%
      \box\@labels
      \penalty\z@
    \fi
    \if@nobreak
      \@nobreakfalse
      \clubpenalty \@M
    \else
      \clubpenalty \@clubpenalty
      \everypar{}%
    \fi}%
  \if@noitemarg
    \@noitemargfalse
    \if@nmbrlist
      \refstepcounter\@listctr
    \fi
  \fi
  \sRTLbox\@tempboxa{\makelabel{#1}}%
  \global\setbox\@labels\hbox dir TRT{%
    \unhbox\@labels
    \hskip \itemindent
    \hskip -\labelwidth
    \hskip -\labelsep
    \ifdim \wd\@tempboxa >\labelwidth
      \box\@tempboxa
    \else
      \hbox to\labelwidth {\unhbox\@tempboxa}%
    \fi
    \hskip \labelsep}%
  \ignorespaces}

\def\itemize{%
  \ifnum \@itemdepth >\thr@@\@toodeep\else
    \advance\@itemdepth\@ne
    \edef\@itemitem{labelitem\romannumeral\the\@itemdepth}%
    \expandafter
    \list
      \csname\@itemitem\endcsname
      {\def\makelabel##1{\hss\llap{##1}}}%
  \fi}

\long\def\sRTLbox#1#2{\setbox#1\hbox dir TRT{%
  \color@setgroup#2\color@endgroup}}
\makeatother
\pardir TRT
\textdir TRT
\begin{document}
\lipsum[1]
desserts.\footnote{Would you have any?}
\begin{enumerate}
\item desserts desserts desserts desserts desserts desserts desserts
  desserts desserts desserts desserts desserts desserts desserts
  desserts desserts desserts desserts desserts desserts desserts
  desserts desserts desserts desserts desserts desserts desserts
  desserts desserts desserts desserts desserts desserts desserts
  desserts desserts.
  \item desserts.
    \begin{itemize}
    \item desserts desserts desserts desserts desserts desserts
      desserts desserts desserts desserts desserts desserts desserts
      desserts desserts desserts desserts desserts desserts desserts
      desserts desserts desserts desserts desserts desserts desserts
      desserts desserts desserts desserts desserts desserts desserts
      desserts desserts desserts desserts.
      \begin{itemize}
      \item desserts.
      \end{itemize}
    \item desserts desserts desserts desserts desserts desserts
      desserts desserts desserts desserts desserts desserts desserts
      desserts desserts desserts desserts desserts desserts desserts
      desserts desserts desserts desserts desserts desserts desserts
      desserts desserts desserts desserts desserts desserts desserts
      desserts desserts desserts.
    \end{itemize}
\end{enumerate}
desserts.\footnote{Would you have any?}

\end{document}
  • Yes, I meant \pagedir. Many thanks for your answer: I'll run some tests with this code right away. – Robert Alessi Nov 8 '16 at 18:12
  • Thank you very much @user118241. This works. By the way, is it known for a fact that \bodydir and \pagedir have bugs? Both primitives are hardly documented as far as I know. Can anybody shed some light on this? – Robert Alessi Nov 9 '16 at 10:42
  • @RobertAlessi: Not just \bodydir and \pagedir but the whole LuaTeX's bidi model has too many bugs. Even if you look at ConTeXt sources, they also do not use \bodydir and \pagedir (just \pardir and \textdir). – user118241 Nov 9 '16 at 10:53
  • 1
    @RobertAlessi For an example of how ugly LuaTeX's bidi model is, see tex.stackexchange.com/questions/134061 – user118241 Nov 9 '16 at 11:14
  • 1
    @RobertAlessi: For ConTeXt, please see the comment in file spac-ali.mkiv: github.com/contextgarden/context-mirror/blob/… – user118241 Nov 9 '16 at 11:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.