From 23bc528c89e84c5caa540d030b6591dca963184f Mon Sep 17 00:00:00 2001
From: Robert Alessi <alessi@robertalessi.net>
Date: Sat, 24 Aug 2019 13:06:54 +0200
Subject: done rewriting \lem

---
 ekdosis.dtx | 59 ++++++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 40 insertions(+), 19 deletions(-)

(limited to 'ekdosis.dtx')

diff --git a/ekdosis.dtx b/ekdosis.dtx
index 0f08c82..afacb0c 100644
--- a/ekdosis.dtx
+++ b/ekdosis.dtx
@@ -456,7 +456,7 @@ idno={}, msName={}, origDate={}][3]{%
 \newif\ifekd@isinapp
 \providebool{al@rlmode}
 \@ifpackageloaded{arabluatex}{}{%
-  \def\setRL{\booltrue{al@rlmode} \pardir TRT \textdir TRT}}
+  \def\setRL{\booltrue{al@rlmode}\pardir TRT\textdir TRT}}
 \newcounter{ekd@lab}
 \def\unconditional@appin#1{%
   \luadirect{ekdosis.appin(
@@ -514,30 +514,51 @@ idno={}, msName={}, origDate={}][3]{%
 \NewDocumentCommand{\SetSeparator}{m}{\edef\ekdsep{#1}}
 \define@cmdkeys[ekd]{lemrdg}[ekdlr@]{wit, alt, pre, post, prewit,
   postwit}
-\define@cmdkey[ekd]{lem}[ekdl@]{sep}[\ekdsep]{#1}
+\define@cmdkey[ekd]{lem}[ekdl@]{sep}{}
+\presetkeys[ekd]{lem}{sep=\ekdsep}{}
 \define@boolkeys[ekd]{lem}[ekdl@]{nolem, nosep}[true]
 \NewDocumentCommand{\lem}{O{} m}{%
   #2%
+  \bgroup%
   \setkeys[ekd]{lemrdg,lem}{#1}%
   \ifekdl@nolem\append@ln@app{}\else%
-  % 
-  \edef\lem@app{%
-    \ifdefined\ekdlr@alt
-      \ifdefined\ekdlr@pre\ekdlr@pre\else\fi
-      \ekdlr@alt
-      \ifdefined\ekdlr@post\ekdlr@post\else\fi
-    \else
-      \ifdefined\ekdlr@pre\ekdlr@pre\else\fi
-    #2
-    \ifdefined\ekdlr@post\ekdlr@post\else\fi    
-    \fi
-    \ifdefined\ekdlr@prewit\ekdlr@prewit\else\fi
-    \ifdefined\ekdlr@wit\getsiglum{\ekdlr@wit}\else\fi
-    \ifdefined\ekdlr@postwit\ekdlr@postwit\else\fi
-    %\ekdl@sep
-  }
-  \append@ln@app{\lem@app}
+  \ifbool{al@rlmode}{%
+    \edef\lem@app{%
+      \ifdefined\ekdlr@alt
+        \ifdefined\ekdlr@post\space\ekdlr@post\space\else\fi
+        {\textdir TRT\ekdlr@alt}
+        \ifdefined\ekdlr@pre\space\ekdlr@pre\space\else\fi
+      \else
+        \ifdefined\ekdlr@post\space\ekdlr@post\space\else\fi
+        {\textdir TRT#2}%
+        \ifdefined\ekdlr@pre\space\ekdlr@pre\space\else\fi
+      \fi
+      \ifdefined\ekdlr@postwit\space\ekdlr@postwit\else\fi
+      \ifdefined\ekdlr@wit\space\getsiglum{\ekdlr@wit}\else\fi
+      \ifdefined\ekdlr@prewit\space\ekdlr@prewit\space\else\fi
+      \ifekdl@nosep\else\ekdl@sep\fi
+    }%
+  }%
+  {%
+    \edef\lem@app{%
+      \ifdefined\ekdlr@alt
+        \ifdefined\ekdlr@pre\space\ekdlr@pre\space\else\fi
+        \ekdlr@alt
+        \ifdefined\ekdlr@post\space\ekdlr@post\space\else\fi
+      \else
+        \ifdefined\ekdlr@pre\space\ekdlr@pre\space\else\fi
+        #2%
+        \ifdefined\ekdlr@post\space\ekdlr@post\space\else\fi
+      \fi
+      \ifdefined\ekdlr@prewit\space\ekdlr@prewit\space\else\fi
+      \ifdefined\ekdlr@wit\space\getsiglum{\ekdlr@wit}\else\fi
+      \ifdefined\ekdlr@postwit\space\ekdlr@postwit\else\fi
+      \ifekdl@nosep\else\ekdl@sep\fi
+    }%
+  }%
+  \append@ln@app{\lem@app}%
   \fi%
+  \egroup%
 }
 \newkeycommand+[\|]{\lemout}[wit, alt, pre, post, prewit, postwit,
 sep={\ekdsep}, choice nosep={false,,true},
-- 
cgit v1.2.3

