From 961af550fd3c6be7475b2f1410511b5506a00a0f Mon Sep 17 00:00:00 2001 From: Robert Alessi Date: Mon, 11 Jun 2018 14:47:01 +0200 Subject: arabluatex.lua: newtable 'outofarb' with an option in mkarbbreak() for inserting new entries in this table. added LPeg spcenc^-1 in holdcmd(). new function takeoutarb(). --- arabluatex.lua | 133 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 92 insertions(+), 41 deletions(-) (limited to 'arabluatex.lua') diff --git a/arabluatex.lua b/arabluatex.lua index d77aa51..b8ef9df 100644 --- a/arabluatex.lua +++ b/arabluatex.lua @@ -65,9 +65,17 @@ local function unprotectarb(str) return str end --- commands the arguments of which must not be processed by --- arabluatex. 'albrkcmds' is what is set by default. 'brkcmds' is --- what may be set in the preamble as argument of \MkArbBreak{} +-- the following is to be taken out of \arb{} +local outofarb = { + "LRfootnote", + "RLfootnote", + "edtext", + "pstart", + "pend" +} +-- commands the arguments of which must not be processed by arabluatex +-- inside \arb{}. 'albrkcmds' is what is set by default. 'brkcmds' +-- collects the commands set in the preamble with \MkArbBreak{} local albrkcmds = { "begin", "end", @@ -75,23 +83,31 @@ local albrkcmds = { "LRmarginpar", "Footnote", "Marginpar", - "edtext", - "pstart", - "pend", - "arbmark" + "arbmark", + "textcolor", + "abjad" } local brkcmds = {} -function mkarbbreak(str) +function mkarbbreak(str, opt) str = str .."," str = string.gsub(str, "%s+", "") local fieldstart = 1 - repeat - local nexti = string.find(str, "%,", fieldstart) - table.insert(brkcmds, string.sub(str, fieldstart, nexti-1)) - fieldstart = nexti +1 - until fieldstart > string.len(str) - return brkcmds + if opt == "dflt" then + repeat + local nexti = string.find(str, "%,", fieldstart) + table.insert(brkcmds, string.sub(str, fieldstart, nexti-1)) + fieldstart = nexti +1 + until fieldstart > string.len(str) + return brkcmds + elseif opt == "out" then + repeat + local nexti = string.find(str, "%,", fieldstart) + table.insert(outofarb, string.sub(str, fieldstart, nexti-1)) + fieldstart = nexti +1 + until fieldstart > string.len(str) + return outofarb + end end local function breakcmd(str) @@ -103,29 +119,37 @@ local function breakcmd(str) end) str = string.gsub(str, "(\\item)(%s+)", "%1{}%2") -- \textcolor - str = string.gsub(str, "\\(textcolor%s?)(%b{})(%b{})", - function(tag, bodycolor, bodytext) - bodycolor = string.sub(bodycolor, 2, -2) - bodytext = string.sub(bodytext, 2, -2) - return string.format("\\al@brk{\\%s{%s}{\\arb{%s}}}", tag, bodycolor, bodytext) - end) + -- str = string.gsub(str, "\\(textcolor%s?)(%b{})(%b{})", + -- function(tag, bodycolor, bodytext) + -- bodycolor = string.sub(bodycolor, 2, -2) + -- bodytext = string.sub(bodytext, 2, -2) + -- return string.format("\\al@brk{\\%s{%s}{\\arb{%s}}}", tag, bodycolor, bodytext) + -- end) + str = string.gsub(str, "(.)(\\arbcolor%s?)(%b[])(%b{})(.)", + function (li, tag, opt, body, lii) + li = string.gsub(li, "%+", "‍") -- ^^^^200d + lii = string.gsub(lii, "%+", "‍") -- ^^^^200d + body = string.sub(body, 2, -2) + body = string.gsub(body, "%+", "‍") -- ^^^^200d + return string.format("%s%s%s{%s}%s", li, tag, opt, body, lii) + end) -- Abjad - str = string.gsub(str, "\\(abjad%s?)(%b{})", - function(tag, body) - body = string.sub(body, 2, -2) - return string.format("\\al@brk{\\%s{%s}}", tag, body) - end) - -- LR/RL footnotes - str = string.gsub(str, "\\(RLfootnote%s?)(%b{})", - function(tag, body) - body = string.sub(body, 2, -2) - return string.format("}\\%s{%s}\\arb{", tag, body) - end) - str = string.gsub(str, "\\(LRfootnote%s?)(%b{})", - function(tag, body) - body = string.sub(body, 2, -2) - return string.format("}\\%s{%s}\\arb{", tag, body) - end) + -- str = string.gsub(str, "\\(abjad%s?)(%b{})", + -- function(tag, body) + -- body = string.sub(body, 2, -2) + -- return string.format("\\al@brk{\\%s{%s}}", tag, body) + -- end) +---[[ + -- to be taken out of \arb{}, as LR/RL footnotes and the like: + for i = 1,#outofarb do + str = gsub(str, dblbkslash * lpeg.Cs(outofarb[i]) * cmdargs, "}%1%2%3\\arb{") + -- str = gsub(str, dblbkslash * lpeg.Cs(outofarb[i]) * spcenc^-1 * bcbraces, + -- function(prefix, tag, body) + -- body = string.sub(body, 2, -2) + -- return string.format("}%s%s{%s}\\arb{", prefix, tag, body) + -- end) + end +--]] -- commands set by default in albrkcmds for i = 1,#albrkcmds do str = gsub(str, dblbkslash * lpeg.Cs(albrkcmds[i]) * cmdargs, "\\al@brk{%1%2%3}") @@ -144,7 +168,7 @@ end local function holdcmd(str) str = gsub(str, lpeg.Cs("\\arb") * bcbraces, function(tag, body) body = string.sub(body, 2, -2) - body = gsub(body, cmd * bsqbracketsii * spcenc^-1 * bcbraces, function(btag, bopt, bbody) + body = gsub(body, cmd * spcenc^-1 * bsqbracketsii * spcenc^-1 * bcbraces, function(btag, bopt, bbody) bbody = string.sub(bbody, 2, -2) if string.find(btag, "@") then return holdcmd(string.format("}%s%s{%s}\\arb{", btag, bopt, bbody)) @@ -218,6 +242,32 @@ local function takeoutcapetc(str) return str end +local function takeoutarb(str) + for i = 1,#outofarb do + str = gsub(str, dblbkslash * lpeg.Cs(outofarb[i]) * cmdargs, + function(prefix, tag, body) +-- body = string.sub(body, 2, -2) + body = gsub(body, lpeg.P("\\arb"), "\\@rb") + return string.format("%s%s%s", prefix, tag, body) + end) + end + -- for i = 1,#outofarb do + -- str = gsub(str, dblbkslash * lpeg.Cs(outofarb[i]) * spcenc^-1 * bcbraces, + -- function(prefix, tag, body) + -- body = string.sub(body, 2, -2) + -- body = gsub(body, lpeg.P("\\arb"), "\\@rb") + -- return string.format("%s%s{%s}", prefix, tag, body) + -- end) + -- end + str = string.gsub(str, "(\\arb%s?)(%b{})", function(tag, body) + body = string.sub(body, 2, -2) + return string.format("%s", body) + end) + str = string.gsub(str, "\\@rb", "\\arb") + str = "\\arb{"..str.."}" + return str +end + local function voc(str, rules) str = string.gsub(str, "\\arb(%b{})", function(inside) inside = string.sub(inside, 2, -2) @@ -599,7 +649,7 @@ return str end function processvoc(str, rules, scheme) - str = "\\arb{".. str.."}" + str = takeoutarb(str) str = processarbnull(str, scheme) str = takeoutcapetc(str) str = protectarb(str) @@ -618,7 +668,7 @@ return str end function processfullvoc(str, rules, scheme) - str = "\\arb{".. str.."}" + str = takeoutarb(str) str = processarbnull(str, scheme) str = takeoutcapetc(str) str = protectarb(str) @@ -639,7 +689,7 @@ return str end function processnovoc(str, rules, scheme) - str = "\\arb{".. str.."}" + str = takeoutarb(str) str = processarbnull(str, scheme) str = takeoutcapetc(str) str = protectarb(str) @@ -658,7 +708,7 @@ return str end function processtrans(str, mode, rules, scheme) - str = "\\arb{".. str.."}" + str = takeoutarb(str) str = processdiscretionary(str) str = processarbnull(str, scheme) str = takeoutabjad(str) @@ -682,6 +732,7 @@ end function newarbmark(abbr, rtlmk, ltrmk) rtlmk = "\\arabicfont "..rtlmk table.insert(arbmarks, {a = abbr, b = rtlmk, c = ltrmk}) + table.sort(arbmarks, function(a ,b) return(#a.a > #b.a) end) return true end -- cgit v1.2.3