aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--arabluatex.lua66
1 files changed, 40 insertions, 26 deletions
diff --git a/arabluatex.lua b/arabluatex.lua
index 053fb50..6a08a33 100644
--- a/arabluatex.lua
+++ b/arabluatex.lua
@@ -35,21 +35,12 @@ local function gsub(s, patt, repl)
35end 35end
36 36
37local function protectarb(str) 37local function protectarb(str)
38-- str = string.gsub(str, "(\\arb%s?)(%[.-%])(%b{})", "\\@arb%2%3") 38 str = string.gsub(str, "(\\arb%s?)(%[.-%])(%b{})", "\\@arb%2%3")
39-- str = string.gsub(str, "(\\begin%s?)(%b{})(%b[])", "\\@@begin{%2%3}")
40-- str = string.gsub(str, "(\\begin%s?)(%b{})", "\\@begin%2")
41-- str = string.gsub(str, "(\\end%s?)(%b{})", "\\@end%2")
42-- str = string.gsub(str, "\\par", "\\p@r{}")
43-- str = string.gsub(str, "\\@@par", "\\p@r{}")
44return str 39return str
45end 40end
46 41
47local function unprotectarb(str) 42local function unprotectarb(str)
48-- str = string.gsub(str, "(\\@arb)(%[.-%])(%b{})", "\\arb%2%3") 43 str = string.gsub(str, "(\\@arb)(%[.-%])(%b{})", "\\arb%2%3")
49-- str = string.gsub(str, "(\\@@begin){(%b{})(%b[])}", "\\begin%2%3")
50-- str = string.gsub(str, "(\\@begin)(%b{})", "\\begin%2")
51-- str = string.gsub(str, "(\\@end)(%b{})", "\\end%2")
52-- str = string.gsub(str, "\\p@r{}", "\\par")
53return str 44return str
54end 45end
55 46
@@ -57,11 +48,8 @@ end
57-- arabluatex. 'albrkcmds' is what is set by default. 'brkcmds' is 48-- arabluatex. 'albrkcmds' is what is set by default. 'brkcmds' is
58-- what may be set in the preamble as argument of \MkArbBreak{} 49-- what may be set in the preamble as argument of \MkArbBreak{}
59local albrkcmds = { 50local albrkcmds = {
60 "arb",
61 "begin", 51 "begin",
62 "end", 52 "end",
63 "par",
64 "@@par",
65 "RL", 53 "RL",
66 "LR", 54 "LR",
67 "RLfootnote", 55 "RLfootnote",
@@ -89,12 +77,16 @@ function mkarbbreak(str)
89end 77end
90 78
91-- some basic patterns: 79-- some basic patterns:
80local ascii = lpeg.R("az", "AZ", "@@")
92local dblbkslash = lpeg.Cs("\\") 81local dblbkslash = lpeg.Cs("\\")
93local bsqbrackets = lpeg.Cs{ "[" * ((1 - lpeg.S"[]") + lpeg.V(1))^0 * "]" } 82local bsqbrackets = lpeg.Cs{ "[" * ((1 - lpeg.S"[]") + lpeg.V(1))^0 * "]" }
94local bcbraces = lpeg.Cs{ "{" * ((1 - lpeg.S"{}") + lpeg.V(1))^0 * "}" } 83local bcbraces = lpeg.Cs{ "{" * ((1 - lpeg.S"{}") + lpeg.V(1))^0 * "}" }
95local spce = lpeg.Cs(" ") 84local spce = lpeg.Cs(" ")
85local spcenc = lpeg.P(" ")
86local cmdstar = lpeg.Cs(spce * lpeg.P("*"))
96local bsqbracketsii = lpeg.Cs(bsqbrackets^-2) 87local bsqbracketsii = lpeg.Cs(bsqbrackets^-2)
97local bcbracesii = lpeg.Cs(bcbraces^-2) 88local bcbracesii = lpeg.Cs(bcbraces^-2)
89local cmd = lpeg.Cs(dblbkslash * ascii^1 * cmdstar^-1)
98local cmdargs = lpeg.Cs(spce * bsqbracketsii * bcbracesii * bsqbrackets^-1) 90local cmdargs = lpeg.Cs(spce * bsqbracketsii * bcbracesii * bsqbrackets^-1)
99 91
100local function breakcmd(str) 92local function breakcmd(str)
@@ -133,22 +125,43 @@ local function breakcmd(str)
133 return str 125 return str
134end 126end
135 127
128---[[
129local function holdcmd(str)
130 str = gsub(str, lpeg.Cs("\\arb") * bcbraces, function(tag, body)
131 body = string.sub(body, 2, -2)
132 body = gsub(body, cmd * bsqbracketsii * spcenc^-1 * bcbraces, function(btag, bopt, bbody)
133 bbody = string.sub(bbody, 2, -2)
134 if string.find(btag, "@") then
135 return holdcmd(string.format("}%s%s{%s}\\arb{", btag, bopt, bbody))
136 else
137 return holdcmd(string.format("}%s%s{\\arb{%s}}\\arb{", btag, bopt, bbody))
138 end
139 end)
140 return string.format("%s{%s}", tag, body)
141 end)
142 str = string.gsub(str, "\\arb{}", "")
143 return str
144end
145--]]
146
147--[[
136local function holdcmd(str) 148local function holdcmd(str)
137 str = string.gsub(str, "\\(arb)(%b{})", function(tag, body) 149 str = string.gsub(str, "\\(arb)(%b{})", function(tag, body)
138 body = string.sub(body, 2, -2) 150 body = string.sub(body, 2, -2)
139 body = string.gsub(body, "\\(.-)(%b{})", function(btag, bbody) 151 body = string.gsub(body, "\\(.-)(%b{})", function(btag, bbody)
140 bbody = string.sub(bbody, 2, -2) 152 bbody = string.sub(bbody, 2, -2)
141-- if string.find(btag, "@") then 153 if string.find(btag, "@") then
142-- return holdcmd(string.format("}\\%s{%s}\\arb{", btag, bbody)) 154 return holdcmd(string.format("}\\%s{%s}\\arb{", btag, bbody))
143-- else 155 else
144 return holdcmd(string.format("}\\%s{\\arb{%s}}\\arb{", btag, bbody)) 156 return holdcmd(string.format("}\\%s{\\arb{%s}}\\arb{", btag, bbody))
145-- end 157 end
146 end) 158 end)
147 return string.format("\\%s{%s}", tag, body) 159 return string.format("\\%s{%s}", tag, body)
148 end) 160 end)
149 str = string.gsub(str, "\\arb{}", "") 161 str = string.gsub(str, "\\arb{}", "")
150return str 162return str
151end 163end
164--]]
152 165
153local function arbnum(str) 166local function arbnum(str)
154 str = string.gsub(str, "([0-9%,%-%/]+)", function(num) 167 str = string.gsub(str, "([0-9%,%-%/]+)", function(num)
@@ -207,6 +220,7 @@ local function takeoutcapetc(str)
207 end) 220 end)
208 str = string.gsub(str, "\\linebreak", "") 221 str = string.gsub(str, "\\linebreak", "")
209 str = string.gsub(str, "\\%-", "") 222 str = string.gsub(str, "\\%-", "")
223 str = string.gsub(str, "\\(@-)par", "\\%1par{}")
210 return str 224 return str
211end 225end
212 226
@@ -594,7 +608,7 @@ function processvoc(str, rules, scheme)
594 str = "\\arb{".. str.."}" 608 str = "\\arb{".. str.."}"
595 str = processarbnull(str, scheme) 609 str = processarbnull(str, scheme)
596 str = takeoutcapetc(str) 610 str = takeoutcapetc(str)
597-- str = protectarb(str) 611 str = protectarb(str)
598 str = breakcmd(str) 612 str = breakcmd(str)
599 str = holdcmd(str) 613 str = holdcmd(str)
600 if scheme == "buckwalter" then 614 if scheme == "buckwalter" then
@@ -605,7 +619,7 @@ function processvoc(str, rules, scheme)
605 elseif rules == "dflt" or rules == "idgham" then 619 elseif rules == "dflt" or rules == "idgham" then
606 str = voc(str, rules) 620 str = voc(str, rules)
607 else end 621 else end
608-- str = unprotectarb(str) 622 str = unprotectarb(str)
609return str 623return str
610end 624end
611 625
@@ -613,7 +627,7 @@ function processfullvoc(str, rules, scheme)
613 str = "\\arb{".. str.."}" 627 str = "\\arb{".. str.."}"
614 str = processarbnull(str, scheme) 628 str = processarbnull(str, scheme)
615 str = takeoutcapetc(str) 629 str = takeoutcapetc(str)
616-- str = protectarb(str) 630 str = protectarb(str)
617 str = breakcmd(str) 631 str = breakcmd(str)
618 str = holdcmd(str) 632 str = holdcmd(str)
619 if scheme == "buckwalter" then 633 if scheme == "buckwalter" then
@@ -626,7 +640,7 @@ function processfullvoc(str, rules, scheme)
626 elseif rules == "dflt" or rules == "idgham" then 640 elseif rules == "dflt" or rules == "idgham" then
627 str = fullvoc(str, rules) 641 str = fullvoc(str, rules)
628 else end 642 else end
629-- str = unprotectarb(str) 643 str = unprotectarb(str)
630return str 644return str
631end 645end
632 646
@@ -634,7 +648,7 @@ function processnovoc(str, rules, scheme)
634 str = "\\arb{".. str.."}" 648 str = "\\arb{".. str.."}"
635 str = processarbnull(str, scheme) 649 str = processarbnull(str, scheme)
636 str = takeoutcapetc(str) 650 str = takeoutcapetc(str)
637-- str = protectarb(str) 651 str = protectarb(str)
638 str = breakcmd(str) 652 str = breakcmd(str)
639 str = holdcmd(str) 653 str = holdcmd(str)
640 if scheme == "buckwalter" then 654 if scheme == "buckwalter" then
@@ -645,7 +659,7 @@ function processnovoc(str, rules, scheme)
645 elseif rules == "dflt" or rules == "idgham" then 659 elseif rules == "dflt" or rules == "idgham" then
646 str = novoc(str) 660 str = novoc(str)
647 else end 661 else end
648-- str = unprotectarb(str) 662 str = unprotectarb(str)
649return str 663return str
650end 664end
651 665
@@ -654,7 +668,7 @@ function processtrans(str, mode, rules, scheme)
654 str = processdiscretionary(str) 668 str = processdiscretionary(str)
655 str = processarbnull(str, scheme) 669 str = processarbnull(str, scheme)
656 str = takeoutabjad(str) 670 str = takeoutabjad(str)
657-- str = protectarb(str) 671 str = protectarb(str)
658 str = breakcmd(str) 672 str = breakcmd(str)
659 str = holdcmd(str) 673 str = holdcmd(str)
660 if scheme == "buckwalter" then 674 if scheme == "buckwalter" then
@@ -667,7 +681,7 @@ function processtrans(str, mode, rules, scheme)
667 elseif mode == "arabica" then 681 elseif mode == "arabica" then
668 str = transarabica(str) 682 str = transarabica(str)
669 end 683 end
670-- str = unprotectarb(str) 684 str = unprotectarb(str)
671return str 685return str
672end 686end
673 687