From f0195ef546e9c35f539edd3bf01ef8b1b0cb7344 Mon Sep 17 00:00:00 2001
From: Robert Alessi <alessi@robertalessi.net>
Date: Tue, 21 Aug 2018 17:52:35 +0200
Subject: arabtex2utf: arabverse needed much more work

---
 arabluatex.dtx | 88 +++++++++++++++++++++++++++++++---------------------------
 1 file changed, 47 insertions(+), 41 deletions(-)

(limited to 'arabluatex.dtx')

diff --git a/arabluatex.dtx b/arabluatex.dtx
index e6b6e87..bb4658b 100644
--- a/arabluatex.dtx
+++ b/arabluatex.dtx
@@ -4081,6 +4081,7 @@ wa-ya.sIru ta.hta 'l-jild-i
 \RequirePackage{xparse}
 \RequirePackage{environ}
 \RequirePackage{adjustbox}
+\RequirePackage{xstring}
 %    \end{macrocode}
 % The following boolean will be set to |true| in |RL| mode:
 %    \begin{macrocode}
@@ -4471,20 +4472,26 @@ wa-ya.sIru ta.hta 'l-jild-i
 {\bgroup\setkeys[al]{verse}[width, gutter, color, utf, delim, mode,
   metre]{#1}%
   \if@pkg@export\ifal@verse@export%
-  \ArbOutFile{\begin{arabverse}}%
-    \luadirect{tooutfile(\luastringN{[#1]})}%
-    \else\fi\else\fi\egroup%
+    \ArbOutFile{\begin{arabverse}}%
+      \IfSubStr[1]{#1}{utf}%
+        {\luadirect{tooutfile(\luastringN{[#1]})}}%
+        {\luadirect{tooutfile(\luastringN{[#1, utf]})}}%
+  \else\fi\else\fi\egroup%
   \par\centering\noindent\bgroup\setkeys[al]{verse}[metre]{#1}%
   \ifx\al@mode\al@mode@trans%
-  \ifal@verse@utf\setRL\else\setLR\fi%
-  \else\setRL\fi}%
-{\hfill\setkeys[al]{verse}[width, gutter, color, utf, delim, mode,
-  export]{#1}%
-  \egroup\par%
-  \bgroup\setkeys[al]{verse}[width, gutter, color, utf, delim, mode,
-  metre]{#1}%
-  \if@pkg@export\ifal@verse@export%
-  \ArbOutFile{\end{arabverse}}\else\fi\else\fi\egroup}
+    \ifal@verse@utf\setRL\else\setLR\fi%
+  \else\setRL\fi%
+  \arab@v@export{#1}
+  }%
+  {\endarab@v@export
+    \hfill\setkeys[al]{verse}[width, gutter, color, utf, delim, mode,
+    export]{#1}%
+    \egroup\par%
+    \bgroup\setkeys[al]{verse}[width, gutter, color, utf, delim, mode,
+    metre]{#1}%
+    \if@pkg@export\ifal@verse@export%
+    \ArbOutFile{\end{arabverse}}
+  \else\fi\else\fi\egroup}
 %    \end{macrocode}
 % \begin{macro}{\bayt}
 %   \changes{v1.6}{2016/12/17}{New macro \cs{bayt} for typesetting
@@ -4510,25 +4517,20 @@ wa-ya.sIru ta.hta 'l-jild-i
 \def\al@hemistich@delim{*}
 \NewDocumentCommand{\SetHemistichDelim}{m}{\def\al@hemistich@delim{#1}}
 \def\al@verse@stroke{\leavevmode\xleaders\hbox{\arb{--}}\hfill\kern0pt}
-\NewDocumentCommand{\bayt}{m o m}{%
-  \if@pkg@export\ifal@verse@export%
-    \luadirect{al_doexport("arabverse")}\else\fi\else\fi%
+\NewDocumentCommand{\bayt}{s m o m}{%
+  \IfBooleanTF{#1}{\relax}{\relax}%
   {^^^^200b}% quick fix to a bug (or a missing feature) in either
             % luacolor or adjustbox 
   \ifdefined\savenotes\savenotes\else\fi%
   \edef\al@tatweel{--}%
-  \if@pkg@export\ifal@verse@export%
-    \ArbOutFile{\bayt\@al@ob}\else\fi\else\fi%
-  \adjustbox{width=\al@bayt@width, height=\Height}{\arb@utf{#1}}%
-  \if@pkg@export\ifal@verse@export%
-    \ArbOutFile{\@al@cb}\else\fi\else\fi%
-  \IfNoValueTF{#2}{%
+  \adjustbox{width=\al@bayt@width, height=\Height}{\arb@utf{#2}}%
+  \IfNoValueTF{#3}{%
     \ifal@verse@delim\makebox[\al@gutter@width][c]{\al@hemistich@delim}%
     \else%
     \hspace{\al@gutter@width}%
     \fi
   }{%
-    \edef\@tempa{#2}%
+    \edef\@tempa{#3}%
     \ifx\@tempa\al@tatweel%
     \ifx\al@mode\al@mode@trans%
     \hspace{\al@gutter@width}%
@@ -4537,29 +4539,15 @@ wa-ya.sIru ta.hta 'l-jild-i
     \fi%
     \else%
     \ifx\al@mode\al@mode@trans%
-    \if@pkg@export\ifal@verse@export%
-      \ArbOutFile{[}\else\fi\else\fi%
-    \adjustbox{width=\al@gutter@width, height=\Height}{\arb@utf{#2}}%
-    \if@pkg@export\ifal@verse@export%
-      \ArbOutFile{]}\else\fi\else\fi%
+    \adjustbox{width=\al@gutter@width, height=\Height}{\arb@utf{#3}}%
     \else%
-    \if@pkg@export\ifal@verse@export%
-      \ArbOutFile{[}\else\fi\else\fi%
-    \makebox[\al@gutter@width][s]{\arb@utf{#2}}%
-    \if@pkg@export\ifal@verse@export%
-      \ArbOutFile{]}\else\fi\else\fi%
+    \makebox[\al@gutter@width][s]{\arb@utf{#3}}%
     \fi\fi}%
-  \if@pkg@export\ifal@verse@export%
-    \ArbOutFile{\@al@ob}\else\fi\else\fi%
-  \adjustbox{width=\al@bayt@width, height=\Height}{\arb@utf{#3}}%
-  \if@pkg@export\ifal@verse@export%
-    \ArbOutFile{\@al@cb\\ }\else\fi\else\fi%
+  \adjustbox{width=\al@bayt@width, height=\Height}{\arb@utf{#4}}%
   \ifdefined\spewnotes\spewnotes\else\fi%
-  \if@pkg@export\ifal@verse@export%
-    \luadirect{al_doexport("no")}\else\fi\else\fi%
 }
 %    \end{macrocode}
-% \end{macro} 
+% \end{macro}
 % \end{environment}
 % \begin{macro}{\abjad} \cs{abjad}\marg{number} expresses its argument
 %   in Arabic letters in accordance with the \arb[trans]{'abjad}
@@ -4691,8 +4679,26 @@ wa-ya.sIru ta.hta 'l-jild-i
   \BODY
   \luadirect{al_doexport("yes")}
   \luadirect{tex.sprint(arbtoutf(\luastringO{\BODY}))}
+  \luadirect{al_doexport("no")}
   \else\par\BODY\fi
-  }[\if@pkg@export\par\luadirect{al_doexport("no")}\else\par\fi]
+  }[\par]
+%    \end{macrocode}
+% \end{environment}
+% \begin{environment}{arab@v@export} The |arab@v@export| environment
+%   does for |arabverse| the same as |arabexport|. It is used
+%   internally by |arabverse|.
+%    \begin{macrocode}
+\NewEnviron{arab@v@export}[1]{%
+  \setkeys[al]{verse}[width, gutter, color, utf, delim, mode,
+  metre]{#1}
+  \if@pkg@export\ifal@verse@export%
+  \par
+  \BODY
+  \luadirect{al_doexport("arabverse")}
+  \luadirect{tex.sprint(arbtoutf(\luastringO{\BODY}))}
+  \luadirect{al_doexport("no")}
+  \else\par\BODY\fi\else\par\BODY\fi
+}[\par]
 %    \end{macrocode}
 % \end{environment}
 % \begin{macro}{\arbpardir}
-- 
cgit v1.2.3

