From 8976e160e584d67178ab14ee2110429a99623223 Mon Sep 17 00:00:00 2001
From: Robert Alessi <alessi@robertalessi.net>
Date: Wed, 22 Apr 2020 14:57:37 +0200
Subject: shorter version of envtotei()

---
 ekdosis.dtx | 64 ++++++++++++++++++++++++++-----------------------------------
 1 file changed, 27 insertions(+), 37 deletions(-)

(limited to 'ekdosis.dtx')

diff --git a/ekdosis.dtx b/ekdosis.dtx
index 257af7c..72d9904 100644
--- a/ekdosis.dtx
+++ b/ekdosis.dtx
@@ -1630,51 +1630,42 @@ end
 local function envtotei(str)
    for i = 1,#envtotags
    do
-      if envtotags[i].b ~= "" and isfound(close_p, envtotags[i].b)
+      if envtotags[i].b ~= ""
       then
-	 if envtotags[i].b == "p"
+	 if isfound(close_p, envtotags[i].b)
 	 then
-	    str = gsub(str, (lpeg.P("\\par") + lpeg.P("<p>")) * spcenc^-1 * lpeg.P("\\begin") * spcenc^-1 * lpeg.P("{")
+	    if envtotags[i].b == "p"
+	    then
+	       str = gsub(str, (lpeg.P("\\par") + lpeg.P("<p>")) * spcenc^-1 * lpeg.P("\\begin") * spcenc^-1 * lpeg.P("{")
+			     * lpeg.Cs(envtotags[i].a) * lpeg.P("}")
+			     * bsqbracketsii * bcbracesii * spcenc^-1,
+			  "\n<"..envtotags[i].b..envtotags[i].c..">")
+	    else
+	       str = gsub(str, (lpeg.P("\\par") + lpeg.P("<p>")) * spcenc^-1 * lpeg.P("\\begin") * spcenc^-1 * lpeg.P("{")
+			     * lpeg.Cs(envtotags[i].a) * lpeg.P("}")
+			     * bsqbracketsii * bcbracesii * spcenc^-1,
+			  "</p>\n<"..envtotags[i].b..envtotags[i].c..">")
+	    end
+	    str = gsub(str, spcenc^-1 * lpeg.P("\\end") * spcenc^-1 * lpeg.P("{")
+			  * lpeg.Cs(envtotags[i].a) * lpeg.P("}") * spcenc^-1 * (lpeg.P("\\par") + lpeg.P("</p>")),
+		       "</"..envtotags[i].b..">\n<p>")
+	    str = gsub(str, lpeg.P("\\begin") * spcenc^-1 * lpeg.P("{")
 			  * lpeg.Cs(envtotags[i].a) * lpeg.P("}")
 			  * bsqbracketsii * bcbracesii * spcenc^-1,
-		       "\n<"..envtotags[i].b..envtotags[i].c..">")
+		       "<"..envtotags[i].b..envtotags[i].c..">")
+	    str = gsub(str, spcenc^-1 * lpeg.P("\\end") * spcenc^-1 * lpeg.P("{")
+			  * lpeg.Cs(envtotags[i].a) * lpeg.P("}"),
+		       "</"..envtotags[i].b..">\n<p>")
 	 else
-	    str = gsub(str, (lpeg.P("\\par") + lpeg.P("<p>")) * spcenc^-1 * lpeg.P("\\begin") * spcenc^-1 * lpeg.P("{")
+	    str = gsub(str, lpeg.P("\\begin") * spcenc^-1 * lpeg.P("{")
 			  * lpeg.Cs(envtotags[i].a) * lpeg.P("}")
 			  * bsqbracketsii * bcbracesii * spcenc^-1,
-		       "</p>\n<"..envtotags[i].b..envtotags[i].c..">")
+		       "<"..envtotags[i].b..envtotags[i].c..">")
+	    str = gsub(str, spcenc^-1 * lpeg.P("\\end") * spcenc^-1 * lpeg.P("{")
+			  * lpeg.Cs(envtotags[i].a) * lpeg.P("}"),
+		       "</"..envtotags[i].b..">")
 	 end
-	 str = gsub(str, spcenc^-1 * lpeg.P("\\end") * spcenc^-1 * lpeg.P("{")
-		       * lpeg.Cs(envtotags[i].a) * lpeg.P("}") * spcenc^-1 * (lpeg.P("\\par") + lpeg.P("</p>")),
-		    "</"..envtotags[i].b..">\n<p>")
-	 str = gsub(str, lpeg.P("\\begin") * spcenc^-1 * lpeg.P("{")
-		       * lpeg.Cs(envtotags[i].a) * lpeg.P("}")
-		       * bsqbracketsii * bcbracesii * spcenc^-1,
-		    "<"..envtotags[i].b..envtotags[i].c..">")
-	 str = gsub(str, spcenc^-1 * lpeg.P("\\end") * spcenc^-1 * lpeg.P("{")
-		       * lpeg.Cs(envtotags[i].a) * lpeg.P("}"),
-		    "</"..envtotags[i].b..">\n<p>")
       else
-      end
-   end
-   for i = 1,#envtotags
-   do
-      if envtotags[i].b ~= "" and not isfound(close_p, envtotags[i].b)
-      then
-	 str = gsub(str, lpeg.P("\\begin") * spcenc^-1 * lpeg.P("{")
-		       * lpeg.Cs(envtotags[i].a) * lpeg.P("}")
-		       * bsqbracketsii * bcbracesii * spcenc^-1,
-		    "<"..envtotags[i].b..envtotags[i].c..">")
-	 str = gsub(str, spcenc^-1 * lpeg.P("\\end") * spcenc^-1 * lpeg.P("{")
-		       * lpeg.Cs(envtotags[i].a) * lpeg.P("}"),
-		    "</"..envtotags[i].b..">")
-      else
-      end
-   end
-   for i = 1,#envtotags
-   do
-      if envtotags[i].b == ""
-      then
 	 str = gsub(str, lpeg.P("\\begin") * spcenc^-1 * lpeg.P("{")
 		       * lpeg.Cs(envtotags[i].a) * lpeg.P("}")
 		       * bsqbracketsii * bcbracesii * spcenc^-1,
@@ -1682,7 +1673,6 @@ local function envtotei(str)
 	 str = gsub(str, spcenc^-1 * lpeg.P("\\end") * spcenc^-1 * lpeg.P("{")
 		       * lpeg.Cs(envtotags[i].a) * lpeg.P("}"),
 		    "")
-      else
       end
    end
    str = gsub(str, lpeg.P("\\begin") * spcenc^-1 * lpeg.P("{")
-- 
cgit v1.2.3

