aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--arabluatex.lua53
1 files changed, 29 insertions, 24 deletions
diff --git a/arabluatex.lua b/arabluatex.lua
index 8ba42fd..053fb50 100644
--- a/arabluatex.lua
+++ b/arabluatex.lua
@@ -35,21 +35,21 @@ local function gsub(s, patt, repl)
35end 35end
36 36
37local function protectarb(str) 37local function protectarb(str)
38 str = string.gsub(str, "(\\arb.?)(%[.-%])(%b{})", "\\@arb%2%3") 38-- str = string.gsub(str, "(\\arb%s?)(%[.-%])(%b{})", "\\@arb%2%3")
39 str = string.gsub(str, "(\\begin.?)(%b{})(%b[])", "\\@@begin{%2%3}") 39-- str = string.gsub(str, "(\\begin%s?)(%b{})(%b[])", "\\@@begin{%2%3}")
40 str = string.gsub(str, "(\\begin.?)(%b{})", "\\@begin%2") 40-- str = string.gsub(str, "(\\begin%s?)(%b{})", "\\@begin%2")
41 str = string.gsub(str, "(\\end.?)(%b{})", "\\@end%2") 41-- str = string.gsub(str, "(\\end%s?)(%b{})", "\\@end%2")
42 str = string.gsub(str, "\\par", "\\p@r{}") 42-- str = string.gsub(str, "\\par", "\\p@r{}")
43 str = string.gsub(str, "\\@@par", "\\p@r{}") 43-- str = string.gsub(str, "\\@@par", "\\p@r{}")
44return str 44return str
45end 45end
46 46
47local function unprotectarb(str) 47local function unprotectarb(str)
48 str = string.gsub(str, "(\\@arb)(%[.-%])(%b{})", "\\arb%2%3") 48-- str = string.gsub(str, "(\\@arb)(%[.-%])(%b{})", "\\arb%2%3")
49 str = string.gsub(str, "(\\@@begin){(%b{})(%b[])}", "\\begin%2%3") 49-- str = string.gsub(str, "(\\@@begin){(%b{})(%b[])}", "\\begin%2%3")
50 str = string.gsub(str, "(\\@begin)(%b{})", "\\begin%2") 50-- str = string.gsub(str, "(\\@begin)(%b{})", "\\begin%2")
51 str = string.gsub(str, "(\\@end)(%b{})", "\\end%2") 51-- str = string.gsub(str, "(\\@end)(%b{})", "\\end%2")
52 str = string.gsub(str, "\\p@r{}", "\\par") 52-- str = string.gsub(str, "\\p@r{}", "\\par")
53return str 53return str
54end 54end
55 55
@@ -57,6 +57,11 @@ end
57-- arabluatex. 'albrkcmds' is what is set by default. 'brkcmds' is 57-- arabluatex. 'albrkcmds' is what is set by default. 'brkcmds' is
58-- what may be set in the preamble as argument of \MkArbBreak{} 58-- what may be set in the preamble as argument of \MkArbBreak{}
59local albrkcmds = { 59local albrkcmds = {
60 "arb",
61 "begin",
62 "end",
63 "par",
64 "@@par",
60 "RL", 65 "RL",
61 "LR", 66 "LR",
62 "RLfootnote", 67 "RLfootnote",
@@ -90,7 +95,7 @@ local bcbraces = lpeg.Cs{ "{" * ((1 - lpeg.S"{}") + lpeg.V(1))^0 * "}" }
90local spce = lpeg.Cs(" ") 95local spce = lpeg.Cs(" ")
91local bsqbracketsii = lpeg.Cs(bsqbrackets^-2) 96local bsqbracketsii = lpeg.Cs(bsqbrackets^-2)
92local bcbracesii = lpeg.Cs(bcbraces^-2) 97local bcbracesii = lpeg.Cs(bcbraces^-2)
93local cmdargs = lpeg.Cs(spce * bsqbracketsii * bcbracesii) 98local cmdargs = lpeg.Cs(spce * bsqbracketsii * bcbracesii * bsqbrackets^-1)
94 99
95local function breakcmd(str) 100local function breakcmd(str)
96 -- process \item[], then \item[] 101 -- process \item[], then \item[]
@@ -133,11 +138,11 @@ local function holdcmd(str)
133 body = string.sub(body, 2, -2) 138 body = string.sub(body, 2, -2)
134 body = string.gsub(body, "\\(.-)(%b{})", function(btag, bbody) 139 body = string.gsub(body, "\\(.-)(%b{})", function(btag, bbody)
135 bbody = string.sub(bbody, 2, -2) 140 bbody = string.sub(bbody, 2, -2)
136 if string.find(btag, "@") then 141-- if string.find(btag, "@") then
137 return holdcmd(string.format("}\\%s{%s}\\arb{", btag, bbody)) 142-- return holdcmd(string.format("}\\%s{%s}\\arb{", btag, bbody))
138 else 143-- else
139 return holdcmd(string.format("}\\%s{\\arb{%s}}\\arb{", btag, bbody)) 144 return holdcmd(string.format("}\\%s{\\arb{%s}}\\arb{", btag, bbody))
140 end 145-- end
141 end) 146 end)
142 return string.format("\\%s{%s}", tag, body) 147 return string.format("\\%s{%s}", tag, body)
143 end) 148 end)
@@ -589,7 +594,7 @@ function processvoc(str, rules, scheme)
589 str = "\\arb{".. str.."}" 594 str = "\\arb{".. str.."}"
590 str = processarbnull(str, scheme) 595 str = processarbnull(str, scheme)
591 str = takeoutcapetc(str) 596 str = takeoutcapetc(str)
592 str = protectarb(str) 597-- str = protectarb(str)
593 str = breakcmd(str) 598 str = breakcmd(str)
594 str = holdcmd(str) 599 str = holdcmd(str)
595 if scheme == "buckwalter" then 600 if scheme == "buckwalter" then
@@ -600,7 +605,7 @@ function processvoc(str, rules, scheme)
600 elseif rules == "dflt" or rules == "idgham" then 605 elseif rules == "dflt" or rules == "idgham" then
601 str = voc(str, rules) 606 str = voc(str, rules)
602 else end 607 else end
603 str = unprotectarb(str) 608-- str = unprotectarb(str)
604return str 609return str
605end 610end
606 611
@@ -608,7 +613,7 @@ function processfullvoc(str, rules, scheme)
608 str = "\\arb{".. str.."}" 613 str = "\\arb{".. str.."}"
609 str = processarbnull(str, scheme) 614 str = processarbnull(str, scheme)
610 str = takeoutcapetc(str) 615 str = takeoutcapetc(str)
611 str = protectarb(str) 616-- str = protectarb(str)
612 str = breakcmd(str) 617 str = breakcmd(str)
613 str = holdcmd(str) 618 str = holdcmd(str)
614 if scheme == "buckwalter" then 619 if scheme == "buckwalter" then
@@ -621,7 +626,7 @@ function processfullvoc(str, rules, scheme)
621 elseif rules == "dflt" or rules == "idgham" then 626 elseif rules == "dflt" or rules == "idgham" then
622 str = fullvoc(str, rules) 627 str = fullvoc(str, rules)
623 else end 628 else end
624 str = unprotectarb(str) 629-- str = unprotectarb(str)
625return str 630return str
626end 631end
627 632
@@ -629,7 +634,7 @@ function processnovoc(str, rules, scheme)
629 str = "\\arb{".. str.."}" 634 str = "\\arb{".. str.."}"
630 str = processarbnull(str, scheme) 635 str = processarbnull(str, scheme)
631 str = takeoutcapetc(str) 636 str = takeoutcapetc(str)
632 str = protectarb(str) 637-- str = protectarb(str)
633 str = breakcmd(str) 638 str = breakcmd(str)
634 str = holdcmd(str) 639 str = holdcmd(str)
635 if scheme == "buckwalter" then 640 if scheme == "buckwalter" then
@@ -640,7 +645,7 @@ function processnovoc(str, rules, scheme)
640 elseif rules == "dflt" or rules == "idgham" then 645 elseif rules == "dflt" or rules == "idgham" then
641 str = novoc(str) 646 str = novoc(str)
642 else end 647 else end
643 str = unprotectarb(str) 648-- str = unprotectarb(str)
644return str 649return str
645end 650end
646 651
@@ -649,7 +654,7 @@ function processtrans(str, mode, rules, scheme)
649 str = processdiscretionary(str) 654 str = processdiscretionary(str)
650 str = processarbnull(str, scheme) 655 str = processarbnull(str, scheme)
651 str = takeoutabjad(str) 656 str = takeoutabjad(str)
652 str = protectarb(str) 657-- str = protectarb(str)
653 str = breakcmd(str) 658 str = breakcmd(str)
654 str = holdcmd(str) 659 str = holdcmd(str)
655 if scheme == "buckwalter" then 660 if scheme == "buckwalter" then
@@ -662,7 +667,7 @@ function processtrans(str, mode, rules, scheme)
662 elseif mode == "arabica" then 667 elseif mode == "arabica" then
663 str = transarabica(str) 668 str = transarabica(str)
664 end 669 end
665 str = unprotectarb(str) 670-- str = unprotectarb(str)
666return str 671return str
667end 672end
668 673