From ac621f443c80d34c8a08812020ceb8d60877041f Mon Sep 17 00:00:00 2001 From: Robert Alessi Date: Wed, 13 Jun 2018 12:18:25 +0200 Subject: new function checkwrnested(). issue an error when arbout-ed commands are nested into \LR{} or \RL{}, issue a warning on unknown arbmarks --- arabluatex.lua | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/arabluatex.lua b/arabluatex.lua index 4d135f3..11a91c3 100644 --- a/arabluatex.lua +++ b/arabluatex.lua @@ -34,6 +34,10 @@ local function gsub(s, patt, repl) return lpeg.match(patt, s) end +-- makeatletter, makeatother +local atletter = "\\makeatletter{}" +local atother = "\\makeatother{}" + -- some basic patterns: local ascii = lpeg.R("az", "AZ", "@@") local dblbkslash = lpeg.Cs("\\") @@ -229,7 +233,23 @@ local function takeoutcapetc(str) return str end +local function checkwrnested(str) + for i = 1,#outofarb do + str = gsub(str, dblbkslash * lpeg.Cs(lpeg.P("LR") + lpeg.P("RL")) * cmdargs, + function(prefix, tag, body) + body = string.sub(body, 2, -2) + if string.find(body, "\\"..outofarb[i]) then + return atletter.."\\al@wrong@nesting{}"..atother + else + -- nothing to do, so proceed. + end + end) + end + return str +end + local function takeoutarb(str) + str = checkwrnested(str) for i = 1,#outofarb do str = gsub(str, dblbkslash * lpeg.Cs(outofarb[i]) * cmdargs, function(prefix, tag, body) @@ -725,7 +745,7 @@ end function processarbmarks(str) if not isintable(arbmarks, str) then - str = "\\LR{}" + str = "\\LR{}"..atletter.."\\al@wrong@mark{}"..atother else if tex.textdir == "TLT" then for i = 1,#arbmarks do -- cgit v1.2.3