aboutsummaryrefslogtreecommitdiff
path: root/arabluatex.lua
diff options
context:
space:
mode:
Diffstat (limited to 'arabluatex.lua')
-rw-r--r--arabluatex.lua133
1 files changed, 92 insertions, 41 deletions
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)
65 return str 65 return str
66end 66end
67 67
68-- commands the arguments of which must not be processed by 68-- the following is to be taken out of \arb{}
69-- arabluatex. 'albrkcmds' is what is set by default. 'brkcmds' is 69local outofarb = {
70-- what may be set in the preamble as argument of \MkArbBreak{} 70 "LRfootnote",
71 "RLfootnote",
72 "edtext",
73 "pstart",
74 "pend"
75}
76-- commands the arguments of which must not be processed by arabluatex
77-- inside \arb{}. 'albrkcmds' is what is set by default. 'brkcmds'
78-- collects the commands set in the preamble with \MkArbBreak{}
71local albrkcmds = { 79local albrkcmds = {
72 "begin", 80 "begin",
73 "end", 81 "end",
@@ -75,23 +83,31 @@ local albrkcmds = {
75 "LRmarginpar", 83 "LRmarginpar",
76 "Footnote", 84 "Footnote",
77 "Marginpar", 85 "Marginpar",
78 "edtext", 86 "arbmark",
79 "pstart", 87 "textcolor",
80 "pend", 88 "abjad"
81 "arbmark"
82} 89}
83local brkcmds = {} 90local brkcmds = {}
84 91
85function mkarbbreak(str) 92function mkarbbreak(str, opt)
86 str = str .."," 93 str = str ..","
87 str = string.gsub(str, "%s+", "") 94 str = string.gsub(str, "%s+", "")
88 local fieldstart = 1 95 local fieldstart = 1
89 repeat 96 if opt == "dflt" then
90 local nexti = string.find(str, "%,", fieldstart) 97 repeat
91 table.insert(brkcmds, string.sub(str, fieldstart, nexti-1)) 98 local nexti = string.find(str, "%,", fieldstart)
92 fieldstart = nexti +1 99 table.insert(brkcmds, string.sub(str, fieldstart, nexti-1))
93 until fieldstart > string.len(str) 100 fieldstart = nexti +1
94 return brkcmds 101 until fieldstart > string.len(str)
102 return brkcmds
103 elseif opt == "out" then
104 repeat
105 local nexti = string.find(str, "%,", fieldstart)
106 table.insert(outofarb, string.sub(str, fieldstart, nexti-1))
107 fieldstart = nexti +1
108 until fieldstart > string.len(str)
109 return outofarb
110 end
95end 111end
96 112
97local function breakcmd(str) 113local function breakcmd(str)
@@ -103,29 +119,37 @@ local function breakcmd(str)
103 end) 119 end)
104 str = string.gsub(str, "(\\item)(%s+)", "%1{}%2") 120 str = string.gsub(str, "(\\item)(%s+)", "%1{}%2")
105 -- \textcolor 121 -- \textcolor
106 str = string.gsub(str, "\\(textcolor%s?)(%b{})(%b{})", 122 -- str = string.gsub(str, "\\(textcolor%s?)(%b{})(%b{})",
107 function(tag, bodycolor, bodytext) 123 -- function(tag, bodycolor, bodytext)
108 bodycolor = string.sub(bodycolor, 2, -2) 124 -- bodycolor = string.sub(bodycolor, 2, -2)
109 bodytext = string.sub(bodytext, 2, -2) 125 -- bodytext = string.sub(bodytext, 2, -2)
110 return string.format("\\al@brk{\\%s{%s}{\\arb{%s}}}", tag, bodycolor, bodytext) 126 -- return string.format("\\al@brk{\\%s{%s}{\\arb{%s}}}", tag, bodycolor, bodytext)
111 end) 127 -- end)
128 str = string.gsub(str, "(.)(\\arbcolor%s?)(%b[])(%b{})(.)",
129 function (li, tag, opt, body, lii)
130 li = string.gsub(li, "%+", "‍") -- ^^^^200d
131 lii = string.gsub(lii, "%+", "‍") -- ^^^^200d
132 body = string.sub(body, 2, -2)
133 body = string.gsub(body, "%+", "‍") -- ^^^^200d
134 return string.format("%s%s%s{%s}%s", li, tag, opt, body, lii)
135 end)
112 -- Abjad 136 -- Abjad
113 str = string.gsub(str, "\\(abjad%s?)(%b{})", 137 -- str = string.gsub(str, "\\(abjad%s?)(%b{})",
114 function(tag, body) 138 -- function(tag, body)
115 body = string.sub(body, 2, -2) 139 -- body = string.sub(body, 2, -2)
116 return string.format("\\al@brk{\\%s{%s}}", tag, body) 140 -- return string.format("\\al@brk{\\%s{%s}}", tag, body)
117 end) 141 -- end)
118 -- LR/RL footnotes 142---[[
119 str = string.gsub(str, "\\(RLfootnote%s?)(%b{})", 143 -- to be taken out of \arb{}, as LR/RL footnotes and the like:
120 function(tag, body) 144 for i = 1,#outofarb do
121 body = string.sub(body, 2, -2) 145 str = gsub(str, dblbkslash * lpeg.Cs(outofarb[i]) * cmdargs, "}%1%2%3\\arb{")
122 return string.format("}\\%s{%s}\\arb{", tag, body) 146 -- str = gsub(str, dblbkslash * lpeg.Cs(outofarb[i]) * spcenc^-1 * bcbraces,
123 end) 147 -- function(prefix, tag, body)
124 str = string.gsub(str, "\\(LRfootnote%s?)(%b{})", 148 -- body = string.sub(body, 2, -2)
125 function(tag, body) 149 -- return string.format("}%s%s{%s}\\arb{", prefix, tag, body)
126 body = string.sub(body, 2, -2) 150 -- end)
127 return string.format("}\\%s{%s}\\arb{", tag, body) 151 end
128 end) 152--]]
129 -- commands set by default in albrkcmds 153 -- commands set by default in albrkcmds
130 for i = 1,#albrkcmds do 154 for i = 1,#albrkcmds do
131 str = gsub(str, dblbkslash * lpeg.Cs(albrkcmds[i]) * cmdargs, "\\al@brk{%1%2%3}") 155 str = gsub(str, dblbkslash * lpeg.Cs(albrkcmds[i]) * cmdargs, "\\al@brk{%1%2%3}")
@@ -144,7 +168,7 @@ end
144local function holdcmd(str) 168local function holdcmd(str)
145 str = gsub(str, lpeg.Cs("\\arb") * bcbraces, function(tag, body) 169 str = gsub(str, lpeg.Cs("\\arb") * bcbraces, function(tag, body)
146 body = string.sub(body, 2, -2) 170 body = string.sub(body, 2, -2)
147 body = gsub(body, cmd * bsqbracketsii * spcenc^-1 * bcbraces, function(btag, bopt, bbody) 171 body = gsub(body, cmd * spcenc^-1 * bsqbracketsii * spcenc^-1 * bcbraces, function(btag, bopt, bbody)
148 bbody = string.sub(bbody, 2, -2) 172 bbody = string.sub(bbody, 2, -2)
149 if string.find(btag, "@") then 173 if string.find(btag, "@") then
150 return holdcmd(string.format("}%s%s{%s}\\arb{", btag, bopt, bbody)) 174 return holdcmd(string.format("}%s%s{%s}\\arb{", btag, bopt, bbody))
@@ -218,6 +242,32 @@ local function takeoutcapetc(str)
218 return str 242 return str
219end 243end
220 244
245local function takeoutarb(str)
246 for i = 1,#outofarb do
247 str = gsub(str, dblbkslash * lpeg.Cs(outofarb[i]) * cmdargs,
248 function(prefix, tag, body)
249-- body = string.sub(body, 2, -2)
250 body = gsub(body, lpeg.P("\\arb"), "\\@rb")
251 return string.format("%s%s%s", prefix, tag, body)
252 end)
253 end
254 -- for i = 1,#outofarb do
255 -- str = gsub(str, dblbkslash * lpeg.Cs(outofarb[i]) * spcenc^-1 * bcbraces,
256 -- function(prefix, tag, body)
257 -- body = string.sub(body, 2, -2)
258 -- body = gsub(body, lpeg.P("\\arb"), "\\@rb")
259 -- return string.format("%s%s{%s}", prefix, tag, body)
260 -- end)
261 -- end
262 str = string.gsub(str, "(\\arb%s?)(%b{})", function(tag, body)
263 body = string.sub(body, 2, -2)
264 return string.format("%s", body)
265 end)
266 str = string.gsub(str, "\\@rb", "\\arb")
267 str = "\\arb{"..str.."}"
268 return str
269end
270
221local function voc(str, rules) 271local function voc(str, rules)
222 str = string.gsub(str, "\\arb(%b{})", function(inside) 272 str = string.gsub(str, "\\arb(%b{})", function(inside)
223 inside = string.sub(inside, 2, -2) 273 inside = string.sub(inside, 2, -2)
@@ -599,7 +649,7 @@ return str
599end 649end
600 650
601function processvoc(str, rules, scheme) 651function processvoc(str, rules, scheme)
602 str = "\\arb{".. str.."}" 652 str = takeoutarb(str)
603 str = processarbnull(str, scheme) 653 str = processarbnull(str, scheme)
604 str = takeoutcapetc(str) 654 str = takeoutcapetc(str)
605 str = protectarb(str) 655 str = protectarb(str)
@@ -618,7 +668,7 @@ return str
618end 668end
619 669
620function processfullvoc(str, rules, scheme) 670function processfullvoc(str, rules, scheme)
621 str = "\\arb{".. str.."}" 671 str = takeoutarb(str)
622 str = processarbnull(str, scheme) 672 str = processarbnull(str, scheme)
623 str = takeoutcapetc(str) 673 str = takeoutcapetc(str)
624 str = protectarb(str) 674 str = protectarb(str)
@@ -639,7 +689,7 @@ return str
639end 689end
640 690
641function processnovoc(str, rules, scheme) 691function processnovoc(str, rules, scheme)
642 str = "\\arb{".. str.."}" 692 str = takeoutarb(str)
643 str = processarbnull(str, scheme) 693 str = processarbnull(str, scheme)
644 str = takeoutcapetc(str) 694 str = takeoutcapetc(str)
645 str = protectarb(str) 695 str = protectarb(str)
@@ -658,7 +708,7 @@ return str
658end 708end
659 709
660function processtrans(str, mode, rules, scheme) 710function processtrans(str, mode, rules, scheme)
661 str = "\\arb{".. str.."}" 711 str = takeoutarb(str)
662 str = processdiscretionary(str) 712 str = processdiscretionary(str)
663 str = processarbnull(str, scheme) 713 str = processarbnull(str, scheme)
664 str = takeoutabjad(str) 714 str = takeoutabjad(str)
@@ -682,6 +732,7 @@ end
682function newarbmark(abbr, rtlmk, ltrmk) 732function newarbmark(abbr, rtlmk, ltrmk)
683 rtlmk = "\\arabicfont "..rtlmk 733 rtlmk = "\\arabicfont "..rtlmk
684 table.insert(arbmarks, {a = abbr, b = rtlmk, c = ltrmk}) 734 table.insert(arbmarks, {a = abbr, b = rtlmk, c = ltrmk})
735 table.sort(arbmarks, function(a ,b) return(#a.a > #b.a) end)
685 return true 736 return true
686end 737end
687 738