From 60c78040664d5f4b9c155c3298f60ab49e367213 Mon Sep 17 00:00:00 2001
From: Robert Alessi <alessi@robertalessi.net>
Date: Sun, 13 Nov 2016 10:56:06 +0100
Subject: arabluatex now accepts environments and can process RTL list
 environments; a new 'txarab' environment has been added which does for
 running paragraphs the same as 'txarb' does for short insertions of unicode
 Arabic

---
 arabluatex.dtx | 135 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 120 insertions(+), 15 deletions(-)

(limited to 'arabluatex.dtx')

diff --git a/arabluatex.dtx b/arabluatex.dtx
index 74474b8..3289b8e 100644
--- a/arabluatex.dtx
+++ b/arabluatex.dtx
@@ -2426,20 +2426,20 @@ wa-ya.sIru ta.hta 'l-jild-i
 \def\al@mode@novoc{novoc}
 \def\al@mode@trans{trans}
 %    \end{macrocode}
-% The following line will be used in the next release of
-% \package{arabluatex}:
-%    \begin{macrocode}
-% \newif\ifal@mode@defined
-%    \end{macrocode}
 % Packages that are required by \package{arabluatex}:
 %    \begin{macrocode}
+\RequirePackage{etoolbox}
+\RequirePackage{arabluatex-patch}
 \RequirePackage{fontspec}
 \RequirePackage{amsmath}
-\RequirePackage{etoolbox}
 \RequirePackage{luacode}
 \RequirePackage{xparse}
 \RequirePackage{environ}
 %    \end{macrocode}
+% The following boolean will be set to |true| in |RL| mode:
+%    \begin{macrocode}
+\newbool{al@rlmode}
+%    \end{macrocode}
 % Here begins the real work: load |arabluatex.lua|:
 %    \begin{macrocode}
 \luadirect{dofile(kpse.find_file("arabluatex.lua"))}
@@ -2462,13 +2462,13 @@ wa-ya.sIru ta.hta 'l-jild-i
 %   This neutralizes what is defined by the same command in
 %   \package{luabidi}:
 %    \begin{macrocode}
-\AtBeginDocument{\def\setRL{\pardir TRT\textdir TRT}}
+\AtBeginDocument{\def\setRL{\booltrue{al@rlmode}\pardir TRT\textdir TRT}}
 %    \end{macrocode}
 % \end{macro}
 % \begin{macro}{\setLR}
 %   The same applies to \cs{setLR}:
 %    \begin{macrocode}
-\AtBeginDocument{\def\setLR{\pardir TLT\textdir TLT}}
+\AtBeginDocument{\def\setLR{\boolfalse{al@rlmode}\pardir TLT\textdir TLT}}
 %    \end{macrocode}
 % \end{macro}
 % \begin{macro}{\LR} This command typesets its argument from left to
@@ -2613,6 +2613,18 @@ wa-ya.sIru ta.hta 'l-jild-i
 %    \end{macrocode}
 % \end{macro}
 % \end{macro}
+% \begin{environment}{txarab}
+%   \changes{v1.5}{2016/11/13}{New \texttt{txarab} environment for
+%   typesetting running paragraphs in unicode Arabic} The |txarab|
+%   environment does for paragraphs the same as \cs{txarb} does for
+%   short insertions of |utf8| Arabic text.
+%    \begin{macrocode}
+\NewDocumentEnvironment{txarab}{}{%
+  \par%
+  \booltrue{al@rlmode}%
+  \pardir TRT\textdir TRT\arabicfont}{\par}
+%    \end{macrocode}
+% \end{environment}
 % \begin{macro}{\arb}
 %   The \cs{arb} command detects which Arabic mode is to be used,
 %   either globally if no option is set, or locally, then passes its
@@ -2652,20 +2664,24 @@ wa-ya.sIru ta.hta 'l-jild-i
 \NewEnviron{arab}[1][\al@mode]%
 {\par\edef\@tempa{#1}%
   \ifx\@tempa\al@mode@voc%
+  \booltrue{al@rlmode}%
   \bgroup\pardir TRT\textdir TRT\arabicfont%
   \luadirect{tex.sprint(processvoc(\luastringO{\BODY},
     \luastringO{\al@arb@rules}, \luastringO{\al@input@scheme}))}\egroup%
   \else%
   \ifx\@tempa\al@mode@fullvoc%
+  \booltrue{al@rlmode}%
   \bgroup\pardir TRT\textdir TRT\arabicfont%
   \luadirect{tex.sprint(processfullvoc(\luastringO{\BODY},
     \luastringO{\al@arb@rules}, \luastringO{\al@input@scheme}))}\egroup%
   \else%
   \ifx\@tempa\al@mode@novoc%
+  \booltrue{al@rlmode}%
   \bgroup\pardir TRT\textdir TRT\arabicfont%
   \luadirect{tex.sprint(processnovoc(\luastringO{\BODY},
     \luastringO{\al@arb@rules}, \luastringO{\al@input@scheme}))}\egroup%
-  \else \ifx\@tempa\al@mode@trans%
+  \else%
+  \ifx\@tempa\al@mode@trans%
   \bgroup\pardir TLT\textdir TLT\al@trans@style%
   \luadirect{tex.sprint(processtrans(\luastringO{\BODY},
     \luastringO{\al@trans@convention},
@@ -2737,16 +2753,14 @@ wa-ya.sIru ta.hta 'l-jild-i
 %    \end{macrocode}
 % \end{macro}
 % That is it. Say goodbye before leaving.
-%    \begin{macrocode}
-\endinput
-%    \end{macrocode}
-%
-% \printbibliography[heading=bibintoc]
 %
 % \iffalse
 %</package>
 % \fi
 %
+% \subsection*{Patches}
+% \label{sec:patches}
+%
 % \iffalse
 %<*patch>
 % \fi
@@ -2754,12 +2768,103 @@ wa-ya.sIru ta.hta 'l-jild-i
 %    \begin{macrocode}
 \NeedsTeXFormat{LaTeX2e}
 \ProvidesPackage{arabluatex-patch}%
-[2016/11/13 v1.0 arabluatex patches]
+[2016/11/13 v1.0 patches for arabluatex]
+\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
+  \ifbool{al@rlmode}{\advance\@totalleftmargin \rightmargin}%
+  {\advance\@totalleftmargin \leftmargin}
+  \parshape \@ne \@totalleftmargin \linewidth
+  \ignorespaces}
+\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
+  \ifbool{al@rlmode}{\sRLbox\@tempboxa{\makelabel{#1}}}{%
+  \sbox\@tempboxa{\makelabel{#1}}}%
+  \ifbool{al@rlmode}{\global\setbox\@labels\hbox dir TRT}%
+  {\global\setbox\@labels\hbox}{%
+    \unhbox\@labels
+    \hskip \itemindent
+    \hskip -\labelwidth
+    \hskip -\labelsep
+    \ifdim \wd\@tempboxa >\labelwidth
+      \box\@tempboxa
+    \else
+      \hbox to\labelwidth {\unhbox\@tempboxa}%
+    \fi
+    \hskip \labelsep}%
+  \ignorespaces}
+\long\def\sRLbox#1#2{\setbox#1\hbox dir TRT{%
+  \color@setgroup#2\color@endgroup}}
 %    \end{macrocode}
 %
 % \iffalse
 %</patch>
 % \fi
 %
+% \printbibliography[heading=bibintoc]
+%
 % \Finale
 \endinput
-- 
cgit v1.2.3

