aboutsummaryrefslogtreecommitdiff
path: root/arabluatex.lua
diff options
context:
space:
mode:
Diffstat (limited to 'arabluatex.lua')
-rw-r--r--arabluatex.lua451
1 files changed, 265 insertions, 186 deletions
diff --git a/arabluatex.lua b/arabluatex.lua
index d999548..0bb4756 100644
--- a/arabluatex.lua
+++ b/arabluatex.lua
@@ -134,217 +134,288 @@ end
134local function voc(str) 134local function voc(str)
135 str = string.gsub(str, "\\arb(%b{})", function(inside) 135 str = string.gsub(str, "\\arb(%b{})", function(inside)
136 inside = string.sub(inside, 2, -2) 136 inside = string.sub(inside, 2, -2)
137 for i = 1,#hamza do 137 for i = 1,#hamza do
138 inside = string.gsub(inside, hamza[i].a, hamza[i].b) 138 inside = string.gsub(inside, hamza[i].a, hamza[i].b)
139 end 139 end
140 for i = 1,#tanwin do 140 for i = 1,#tanwin do
141 inside = string.gsub(inside, tanwin[i].a, tanwin[i].b) 141 inside = string.gsub(inside, tanwin[i].a, tanwin[i].b)
142 end 142 end
143 for i = 1,#trigraphs do 143 for i = 1,#trigraphs do
144 inside = string.gsub(inside, trigraphs[i].a, trigraphs[i].b) 144 inside = string.gsub(inside, trigraphs[i].a, trigraphs[i].b)
145 end 145 end
146 for i = 1,#digraphs do 146 for i = 1,#digraphs do
147 inside = string.gsub(inside, digraphs[i].a, digraphs[i].b) 147 inside = string.gsub(inside, digraphs[i].a, digraphs[i].b)
148 end 148 end
149 for i = 1,#single do 149 for i = 1,#single do
150 inside = string.gsub(inside, single[i].a, single[i].b) 150 inside = string.gsub(inside, single[i].a, single[i].b)
151 end 151 end
152 for i = 1,#longv do 152 for i = 1,#longv do
153 inside = string.gsub(inside, longv[i].a, longv[i].b) 153 inside = string.gsub(inside, longv[i].a, longv[i].b)
154 end 154 end
155 for i = 1,#shortv do 155 for i = 1,#shortv do
156 inside = string.gsub(inside, shortv[i].a, shortv[i].b) 156 inside = string.gsub(inside, shortv[i].a, shortv[i].b)
157 end 157 end
158 for i = 1,#punctuation do 158 for i = 1,#punctuation do
159 inside = string.gsub(inside, punctuation[i].a, punctuation[i].b) 159 inside = string.gsub(inside, punctuation[i].a, punctuation[i].b)
160 end 160 end
161 for i = 1,#null do 161 for i = 1,#null do
162 inside = string.gsub(inside, null[i].a, null[i].b) 162 inside = string.gsub(inside, null[i].a, null[i].b)
163 end 163 end
164 inside = indnum(inside) 164 inside = indnum(inside)
165 return string.format("\\txarb{%s}", inside) 165 return string.format("\\txarb{%s}", inside)
166 end) 166 end)
167return str 167return str
168end 168end
169 169
170local function voceasy(str) 170local function voceasy(str)
171 str = string.gsub(str, "\\arb(%b{})", function(inside) 171 str = string.gsub(str, "\\arb(%b{})", function(inside)
172 inside = string.sub(inside, 2, -2) 172 inside = string.sub(inside, 2, -2)
173 for i = 1,#hamza do 173 for i = 1,#hamzaeasy do
174 inside = string.gsub(inside, hamza[i].a, hamza[i].b) 174 inside = string.gsub(inside, hamzaeasy[i].a, hamzaeasy[i].b)
175 end 175 end
176 for i = 1,#tanwin do 176 for i = 1,#tanwineasy do
177 inside = string.gsub(inside, tanwin[i].a, tanwin[i].b) 177 inside = string.gsub(inside, tanwineasy[i].a, tanwineasy[i].b)
178 end 178 end
179 for i = 1,#trigraphs do 179 for i = 1,#trigraphseasy do
180 inside = string.gsub(inside, trigraphs[i].a, trigraphs[i].b) 180 inside = string.gsub(inside, trigraphseasy[i].a, trigraphseasy[i].b)
181 end 181 end
182 for i = 1,#digraphs do 182 for i = 1,#digraphs do
183 inside = string.gsub(inside, digraphs[i].a, digraphs[i].b) 183 inside = string.gsub(inside, digraphs[i].a, digraphs[i].b)
184 end 184 end
185 for i = 1,#single do 185 for i = 1,#single do
186 inside = string.gsub(inside, single[i].a, single[i].b) 186 inside = string.gsub(inside, single[i].a, single[i].b)
187 end 187 end
188 for i = 1,#longv do 188 for i = 1,#longv do
189 inside = string.gsub(inside, longv[i].a, longv[i].b) 189 inside = string.gsub(inside, longv[i].a, longv[i].b)
190 end 190 end
191 for i = 1,#shortv do 191 for i = 1,#shortv do
192 inside = string.gsub(inside, shortv[i].a, shortv[i].b) 192 inside = string.gsub(inside, shortv[i].a, shortv[i].b)
193 end 193 end
194 for i = 1,#punctuation do 194 for i = 1,#punctuation do
195 inside = string.gsub(inside, punctuation[i].a, punctuation[i].b) 195 inside = string.gsub(inside, punctuation[i].a, punctuation[i].b)
196 end 196 end
197 for i = 1,#null do 197 for i = 1,#null do
198 inside = string.gsub(inside, null[i].a, null[i].b) 198 inside = string.gsub(inside, null[i].a, null[i].b)
199 end 199 end
200 inside = indnum(inside) 200 inside = indnum(inside)
201 return string.format("\\txarb{%s}", inside) 201 return string.format("\\txarb{%s}", inside)
202 end) 202 end)
203return str 203return str
204end 204end
205 205
206local function fullvoc(str) 206local function fullvoc(str)
207 str = string.gsub(str, "\\arb(%b{})", function(inside) 207 str = string.gsub(str, "\\arb(%b{})", function(inside)
208 inside = string.sub(inside, 2, -2) 208 inside = string.sub(inside, 2, -2)
209 for i = 1,#hamzafv do 209 for i = 1,#hamzafv do
210 inside = string.gsub(inside, hamzafv[i].a, hamzafv[i].b) 210 inside = string.gsub(inside, hamzafv[i].a, hamzafv[i].b)
211 end 211 end
212 for i = 1,#tanwinfv do 212 for i = 1,#tanwinfv do
213 inside = string.gsub(inside, tanwinfv[i].a, tanwinfv[i].b) 213 inside = string.gsub(inside, tanwinfv[i].a, tanwinfv[i].b)
214 end 214 end
215 for i = 1,#trigraphsfv do 215 for i = 1,#trigraphsfv do
216 inside = string.gsub(inside, trigraphsfv[i].a, trigraphsfv[i].b) 216 inside = string.gsub(inside, trigraphsfv[i].a, trigraphsfv[i].b)
217 end 217 end
218 for i = 1,#digraphsfv do 218 for i = 1,#digraphsfv do
219 inside = string.gsub(inside, digraphsfv[i].a, digraphsfv[i].b) 219 inside = string.gsub(inside, digraphsfv[i].a, digraphsfv[i].b)
220 end 220 end
221 for i = 1,#singlefv do 221 for i = 1,#singlefv do
222 inside = string.gsub(inside, singlefv[i].a, singlefv[i].b) 222 inside = string.gsub(inside, singlefv[i].a, singlefv[i].b)
223 end 223 end
224 for i = 1,#longv do 224 for i = 1,#longv do
225 inside = string.gsub(inside, longv[i].a, longv[i].b) 225 inside = string.gsub(inside, longv[i].a, longv[i].b)
226 end 226 end
227 for i = 1,#shortv do 227 for i = 1,#shortv do
228 inside = string.gsub(inside, shortv[i].a, shortv[i].b) 228 inside = string.gsub(inside, shortv[i].a, shortv[i].b)
229 end 229 end
230 for i = 1,#punctuation do 230 for i = 1,#punctuation do
231 inside = string.gsub(inside, punctuation[i].a, punctuation[i].b) 231 inside = string.gsub(inside, punctuation[i].a, punctuation[i].b)
232 end 232 end
233 for i = 1,#null do 233 for i = 1,#null do
234 inside = string.gsub(inside, null[i].a, null[i].b) 234 inside = string.gsub(inside, null[i].a, null[i].b)
235 end 235 end
236 inside = indnum(inside) 236 inside = indnum(inside)
237 return string.format("\\txarb{%s}", inside) 237 return string.format("\\txarb{%s}", inside)
238 end) 238 end)
239return str
240end
241
242local function fullvoceasy(str)
243 str = string.gsub(str, "\\arb(%b{})", function(inside)
244 inside = string.sub(inside, 2, -2)
245 for i = 1,#hamzafveasy do
246 inside = string.gsub(inside, hamzafveasy[i].a, hamzafveasy[i].b)
247 end
248 for i = 1,#tanwinfveasy do
249 inside = string.gsub(inside, tanwinfveasy[i].a, tanwinfveasy[i].b)
250 end
251 for i = 1,#trigraphsfveasy do
252 inside = string.gsub(inside, trigraphsfveasy[i].a, trigraphsfveasy[i].b)
253 end
254 for i = 1,#digraphsfveasy do
255 inside = string.gsub(inside, digraphsfveasy[i].a, digraphsfveasy[i].b)
256 end
257 for i = 1,#singlefveasy do
258 inside = string.gsub(inside, singlefveasy[i].a, singlefveasy[i].b)
259 end
260 for i = 1,#longv do
261 inside = string.gsub(inside, longv[i].a, longv[i].b)
262 end
263 for i = 1,#shortv do
264 inside = string.gsub(inside, shortv[i].a, shortv[i].b)
265 end
266 for i = 1,#punctuation do
267 inside = string.gsub(inside, punctuation[i].a, punctuation[i].b)
268 end
269 for i = 1,#null do
270 inside = string.gsub(inside, null[i].a, null[i].b)
271 end
272 inside = indnum(inside)
273 return string.format("\\txarb{%s}", inside)
274 end)
239return str 275return str
240end 276end
241 277
242local function novoc(str) 278local function novoc(str)
243 str = string.gsub(str, "\\arb(%b{})", function(inside) 279 str = string.gsub(str, "\\arb(%b{})", function(inside)
244 inside = string.sub(inside, 2, -2) 280 inside = string.sub(inside, 2, -2)
245 for i = 1,#hamza do 281 for i = 1,#hamza do
246 inside = string.gsub(inside, hamza[i].a, hamza[i].b) 282 inside = string.gsub(inside, hamza[i].a, hamza[i].b)
247 end 283 end
248 for i = 1,#tanwinnv do 284 for i = 1,#tanwinnv do
249 inside = string.gsub(inside, tanwinnv[i].a, tanwinnv[i].b) 285 inside = string.gsub(inside, tanwinnv[i].a, tanwinnv[i].b)
250 end 286 end
251 for i = 1,#trigraphsnv do 287 for i = 1,#trigraphsnv do
252 inside = string.gsub(inside, trigraphsnv[i].a, trigraphsnv[i].b) 288 inside = string.gsub(inside, trigraphsnv[i].a, trigraphsnv[i].b)
253 end 289 end
254 for i = 1,#digraphs do 290 for i = 1,#digraphs do
255 inside = string.gsub(inside, digraphs[i].a, digraphs[i].b) 291 inside = string.gsub(inside, digraphs[i].a, digraphs[i].b)
256 end 292 end
257 for i = 1,#single do 293 for i = 1,#single do
258 inside = string.gsub(inside, single[i].a, single[i].b) 294 inside = string.gsub(inside, single[i].a, single[i].b)
259 end 295 end
260 for i = 1,#longvnv do 296 for i = 1,#longvnv do
261 inside = string.gsub(inside, longvnv[i].a, longvnv[i].b) 297 inside = string.gsub(inside, longvnv[i].a, longvnv[i].b)
262 end 298 end
263 for i = 1,#shortvnv do 299 for i = 1,#shortvnv do
264 inside = string.gsub(inside, shortvnv[i].a, shortvnv[i].b) 300 inside = string.gsub(inside, shortvnv[i].a, shortvnv[i].b)
265 end 301 end
266 for i = 1,#punctuation do 302 for i = 1,#punctuation do
267 inside = string.gsub(inside, punctuation[i].a, punctuation[i].b) 303 inside = string.gsub(inside, punctuation[i].a, punctuation[i].b)
268 end 304 end
269 for i = 1,#null do 305 for i = 1,#null do
270 inside = string.gsub(inside, null[i].a, null[i].b) 306 inside = string.gsub(inside, null[i].a, null[i].b)
271 end 307 end
272 inside = indnum(inside) 308 inside = indnum(inside)
273 return string.format("\\txarb{%s}", inside) 309 return string.format("\\txarb{%s}", inside)
274 end) 310 end)
275return str 311return str
276end 312end
277 313
278local function transdmg(str) 314local function transdmg(str)
279 str = string.gsub(str, "\\arb(%b{})", function(inside) 315 str = string.gsub(str, "\\arb(%b{})", function(inside)
280 inside = string.sub(inside, 2, -2) 316 inside = string.sub(inside, 2, -2)
281 for i = 1,#hamzatrdmg do 317 for i = 1,#hamzatrdmg do
282 inside = string.gsub(inside, hamzatrdmg[i].a, hamzatrdmg[i].b) 318 inside = string.gsub(inside, hamzatrdmg[i].a, hamzatrdmg[i].b)
283 end 319 end
284 for i = 1,#tanwintrdmg do 320 for i = 1,#tanwintrdmg do
285 inside = string.gsub(inside, tanwintrdmg[i].a, tanwintrdmg[i].b) 321 inside = string.gsub(inside, tanwintrdmg[i].a, tanwintrdmg[i].b)
286 end 322 end
287 for i = 1,#trigraphstrdmg do 323 for i = 1,#trigraphstrdmg do
288 inside = string.gsub(inside, trigraphstrdmg[i].a, trigraphstrdmg[i].b) 324 inside = string.gsub(inside, trigraphstrdmg[i].a, trigraphstrdmg[i].b)
289 end 325 end
290 for i = 1,#digraphstrdmg do 326 for i = 1,#digraphstrdmg do
291 inside = string.gsub(inside, digraphstrdmg[i].a, digraphstrdmg[i].b) 327 inside = string.gsub(inside, digraphstrdmg[i].a, digraphstrdmg[i].b)
292 end 328 end
293 for i = 1,#singletrdmg do 329 for i = 1,#singletrdmg do
294 inside = string.gsub(inside, singletrdmg[i].a, singletrdmg[i].b) 330 inside = string.gsub(inside, singletrdmg[i].a, singletrdmg[i].b)
295 end 331 end
296 for i = 1,#longvtrdmg do 332 for i = 1,#longvtrdmg do
297 inside = string.gsub(inside, longvtrdmg[i].a, longvtrdmg[i].b) 333 inside = string.gsub(inside, longvtrdmg[i].a, longvtrdmg[i].b)
298 end 334 end
299 for i = 1,#shortvtrdmg do 335 for i = 1,#shortvtrdmg do
300 inside = string.gsub(inside, shortvtrdmg[i].a, shortvtrdmg[i].b) 336 inside = string.gsub(inside, shortvtrdmg[i].a, shortvtrdmg[i].b)
301 end 337 end
302 for i = 1,#punctuationtr do 338 for i = 1,#punctuationtr do
303 inside = string.gsub(inside, punctuationtr[i].a, punctuationtr[i].b) 339 inside = string.gsub(inside, punctuationtr[i].a, punctuationtr[i].b)
304 end 340 end
305 for i = 1,#nulltr do 341 for i = 1,#nulltr do
306 inside = string.gsub(inside, nulltr[i].a, nulltr[i].b) 342 inside = string.gsub(inside, nulltr[i].a, nulltr[i].b)
307 end 343 end
308 return string.format("\\txtrans{%s}", inside) 344 return string.format("\\txtrans{%s}", inside)
309 end) 345 end)
346return str
347end
348
349local function transdmgeasy(str)
350 str = string.gsub(str, "\\arb(%b{})", function(inside)
351 inside = string.sub(inside, 2, -2)
352 for i = 1,#hamzatrdmg do
353 inside = string.gsub(inside, hamzatrdmg[i].a, hamzatrdmg[i].b)
354 end
355 for i = 1,#tanwintrdmg do
356 inside = string.gsub(inside, tanwintrdmg[i].a, tanwintrdmg[i].b)
357 end
358 for i = 1,#trigraphstrdmgeasy do
359 inside = string.gsub(inside, trigraphstrdmgeasy[i].a, trigraphstrdmgeasy[i].b)
360 end
361 for i = 1,#digraphstrdmg do
362 inside = string.gsub(inside, digraphstrdmg[i].a, digraphstrdmg[i].b)
363 end
364 for i = 1,#singletrdmg do
365 inside = string.gsub(inside, singletrdmg[i].a, singletrdmg[i].b)
366 end
367 for i = 1,#longvtrdmg do
368 inside = string.gsub(inside, longvtrdmg[i].a, longvtrdmg[i].b)
369 end
370 for i = 1,#shortvtrdmg do
371 inside = string.gsub(inside, shortvtrdmg[i].a, shortvtrdmg[i].b)
372 end
373 for i = 1,#punctuationtr do
374 inside = string.gsub(inside, punctuationtr[i].a, punctuationtr[i].b)
375 end
376 for i = 1,#nulltr do
377 inside = string.gsub(inside, nulltr[i].a, nulltr[i].b)
378 end
379 return string.format("\\txtrans{%s}", inside)
380 end)
310return str 381return str
311end 382end
312 383
313local function transloc(str) 384local function transloc(str)
314 str = string.gsub(str, "\\arb(%b{})", function(inside) 385 str = string.gsub(str, "\\arb(%b{})", function(inside)
315 inside = string.sub(inside, 2, -2) 386 inside = string.sub(inside, 2, -2)
316 for i = 1,#hamzatrloc do 387 for i = 1,#hamzatrloc do
317 inside = string.gsub(inside, hamzatrloc[i].a, hamzatrloc[i].b) 388 inside = string.gsub(inside, hamzatrloc[i].a, hamzatrloc[i].b)
318 end 389 end
319 for i = 1,#tanwintrloc do 390 for i = 1,#tanwintrloc do
320 inside = string.gsub(inside, tanwintrloc[i].a, tanwintrloc[i].b) 391 inside = string.gsub(inside, tanwintrloc[i].a, tanwintrloc[i].b)
321 end 392 end
322 for i = 1,#trigraphstrloc do 393 for i = 1,#trigraphstrloc do
323 inside = string.gsub(inside, trigraphstrloc[i].a, trigraphstrloc[i].b) 394 inside = string.gsub(inside, trigraphstrloc[i].a, trigraphstrloc[i].b)
324 end 395 end
325 for i = 1,#digraphstrloc do 396 for i = 1,#digraphstrloc do
326 inside = string.gsub(inside, digraphstrloc[i].a, digraphstrloc[i].b) 397 inside = string.gsub(inside, digraphstrloc[i].a, digraphstrloc[i].b)
327 end 398 end
328 for i = 1,#singletrloc do 399 for i = 1,#singletrloc do
329 inside = string.gsub(inside, singletrloc[i].a, singletrloc[i].b) 400 inside = string.gsub(inside, singletrloc[i].a, singletrloc[i].b)
330 end 401 end
331 for i = 1,#longvtrloc do 402 for i = 1,#longvtrloc do
332 inside = string.gsub(inside, longvtrloc[i].a, longvtrloc[i].b) 403 inside = string.gsub(inside, longvtrloc[i].a, longvtrloc[i].b)
333 end 404 end
334 for i = 1,#shortvtrloc do 405 for i = 1,#shortvtrloc do
335 inside = string.gsub(inside, shortvtrloc[i].a, shortvtrloc[i].b) 406 inside = string.gsub(inside, shortvtrloc[i].a, shortvtrloc[i].b)
336 end 407 end
337 for i = 1,#finaltrloc do 408 for i = 1,#finaltrloc do
338 inside = string.gsub(inside, finaltrloc[i].a, finaltrloc[i].b) 409 inside = string.gsub(inside, finaltrloc[i].a, finaltrloc[i].b)
339 end 410 end
340 for i = 1,#punctuationtr do 411 for i = 1,#punctuationtr do
341 inside = string.gsub(inside, punctuationtr[i].a, punctuationtr[i].b) 412 inside = string.gsub(inside, punctuationtr[i].a, punctuationtr[i].b)
342 end 413 end
343 for i = 1,#nulltr do 414 for i = 1,#nulltr do
344 inside = string.gsub(inside, nulltr[i].a, nulltr[i].b) 415 inside = string.gsub(inside, nulltr[i].a, nulltr[i].b)
345 end 416 end
346 return string.format("\\txtrans{%s}", inside) 417 return string.format("\\txtrans{%s}", inside)
347 end) 418 end)
348return str 419return str
349end 420end
350 421
@@ -356,20 +427,24 @@ function processvoc(str, rules)
356 str = holdcmd(str) 427 str = holdcmd(str)
357 if rules == "easy" then 428 if rules == "easy" then
358 str = voceasy(str) 429 str = voceasy(str)
359 elseif mode == "dflt" then 430 elseif rules == "dflt" then
360 str = voc(str) 431 str = voc(str)
361 else end 432 else end
362 str = unprotectarb(str) 433 str = unprotectarb(str)
363return str 434return str
364end 435end
365 436
366function processfullvoc(str) 437function processfullvoc(str, rules)
367 str = "\\arb{".. str.."}" 438 str = "\\arb{".. str.."}"
368 str = takeoutcap(str) 439 str = takeoutcap(str)
369 str = protectarb(str) 440 str = protectarb(str)
370 str = breakcmd(str) 441 str = breakcmd(str)
371 str = holdcmd(str) 442 str = holdcmd(str)
372 str = fullvoc(str) 443 if rules == "easy" then
444 str = fullvoceasy(str)
445 elseif rules == "dflt" then
446 str = fullvoc(str)
447 else end
373 str = unprotectarb(str) 448 str = unprotectarb(str)
374return str 449return str
375end 450end
@@ -385,14 +460,18 @@ function processnovoc(str)
385return str 460return str
386end 461end
387 462
388function processtrans(str, mode) 463function processtrans(str, mode, rules)
389 str = "\\arb{".. str.."}" 464 str = "\\arb{".. str.."}"
390 str = takeoutabjad(str) 465 str = takeoutabjad(str)
391 str = protectarb(str) 466 str = protectarb(str)
392 str = breakcmd(str) 467 str = breakcmd(str)
393 str = holdcmd(str) 468 str = holdcmd(str)
394 if mode == "dmg" then 469 if mode == "dmg" then
395 str = transdmg(str) 470 if rules == "easy" then
471 str = transdmgeasy(str)
472 elseif rules == "dflt" then
473 str = transdmg(str)
474 else end
396 elseif mode == "loc" then 475 elseif mode == "loc" then
397 str = transloc(str) 476 str = transloc(str)
398 else end 477 else end