diff options
author | Robert Alessi <alessi@robertalessi.net> | 2016-04-26 13:02:21 +0200 |
---|---|---|
committer | Robert Alessi <alessi@robertalessi.net> | 2016-04-26 13:02:58 +0200 |
commit | d6397857b9a28e7a73d6806422dcb03112441711 (patch) | |
tree | e689092c1516ec015498605c4c64c87e319c949e | |
parent | 00b0ecbf36167f16bbdf284ad3d7140139015591 (diff) | |
download | arabluatex-d6397857b9a28e7a73d6806422dcb03112441711.tar.gz |
implementation of abjad numbering in Lua, so that polyglossia no longer be needed (this is much more flexible)
-rw-r--r-- | arabluatex.dtx | 2 | ||||
-rw-r--r-- | arabluatex.lua | 42 |
2 files changed, 42 insertions, 2 deletions
diff --git a/arabluatex.dtx b/arabluatex.dtx index bd9810c..79d038d 100644 --- a/arabluatex.dtx +++ b/arabluatex.dtx | |||
@@ -1967,6 +1967,8 @@ wa-ya.sIru ta.hta 'l-jildi | |||
1967 | {\NewDocumentCommand{\RL}{m}{\bgroup\textdir TRT#1\rmfamily\egroup}}} | 1967 | {\NewDocumentCommand{\RL}{m}{\bgroup\textdir TRT#1\rmfamily\egroup}}} |
1968 | % \end{macrocode} | 1968 | % \end{macrocode} |
1969 | % \end{macro} | 1969 | % \end{macro} |
1970 | \NewDocumentCommand{\abjad}{m}% | ||
1971 | {\luadirect{tex.sprint(abjadify(#1))}} | ||
1970 | % \begin{macro}{\aemph} Arabic emphasis. Needs to be redefined as well. | 1972 | % \begin{macro}{\aemph} Arabic emphasis. Needs to be redefined as well. |
1971 | % \begin{macrocode} | 1973 | % \begin{macrocode} |
1972 | \AtBeginDocument{\ifdef{\aemph}% | 1974 | \AtBeginDocument{\ifdef{\aemph}% |
diff --git a/arabluatex.lua b/arabluatex.lua index f6597e8..102974a 100644 --- a/arabluatex.lua +++ b/arabluatex.lua | |||
@@ -72,11 +72,11 @@ local function breakcmd(str) | |||
72 | body = string.sub(body, 2, -2) | 72 | body = string.sub(body, 2, -2) |
73 | return string.format("}\\%s{%s}\\arb{", tag, body) | 73 | return string.format("}\\%s{%s}\\arb{", tag, body) |
74 | end) | 74 | end) |
75 | -- Abjad (Needs polyglossia) | 75 | -- Abjad |
76 | str = string.gsub(str, "\\(abjad.-)(%b{})", | 76 | str = string.gsub(str, "\\(abjad.-)(%b{})", |
77 | function(tag, body) | 77 | function(tag, body) |
78 | body = string.sub(body, 2, -2) | 78 | body = string.sub(body, 2, -2) |
79 | return string.format("}\\aemph{\\txarb{\\%s{%s}}}\\arb{", tag, body) | 79 | return string.format("}\\aemph{\\%s{%s}}\\arb{", tag, body) |
80 | end) | 80 | end) |
81 | return str | 81 | return str |
82 | end | 82 | end |
@@ -115,6 +115,14 @@ local function indnum(str) | |||
115 | return str | 115 | return str |
116 | end | 116 | end |
117 | 117 | ||
118 | local function takeoutabjad(str) | ||
119 | str = string.gsub(str, "(\\abjad.?)(%b{})", function(tag, body) | ||
120 | body = string.sub(body, 2, -2) | ||
121 | return string.format("%s", body) | ||
122 | end) | ||
123 | return str | ||
124 | end | ||
125 | |||
118 | local function takeoutcap(str) | 126 | local function takeoutcap(str) |
119 | str = string.gsub(str, "(\\cap.?)(%b{})", function(tag, body) | 127 | str = string.gsub(str, "(\\cap.?)(%b{})", function(tag, body) |
120 | body = string.sub(body, 2, -2) | 128 | body = string.sub(body, 2, -2) |
@@ -339,6 +347,7 @@ end | |||
339 | 347 | ||
340 | function processtrans(str, mode) | 348 | function processtrans(str, mode) |
341 | str = "\\arb{".. str.."}" | 349 | str = "\\arb{".. str.."}" |
350 | str = takeoutabjad(str) | ||
342 | str = protectarb(str) | 351 | str = protectarb(str) |
343 | str = breakcmd(str) | 352 | str = breakcmd(str) |
344 | str = holdcmd(str) | 353 | str = holdcmd(str) |
@@ -371,3 +380,32 @@ function cap(str) | |||
371 | end | 380 | end |
372 | return str | 381 | return str |
373 | end | 382 | end |
383 | |||
384 | local abjad = { | ||
385 | {"a\"'", "b", "j", "d", "h", "w", "z", ".h", ".t"}, | ||
386 | {"y", "k", "l", "m", "n", "s", "`", "f", ".s", }, | ||
387 | {"q", "r", "^s", "t", "_t", "x", "_d", ".d", ".z", }, | ||
388 | {".g"} | ||
389 | } | ||
390 | |||
391 | function abjadify(n) | ||
392 | local result = "" | ||
393 | if n >= 1000 then | ||
394 | for i=1,math.floor(n/1000) do | ||
395 | result = result .. abjad[4][1] | ||
396 | end | ||
397 | n = math.fmod(n,1000) | ||
398 | end | ||
399 | if n >= 100 then | ||
400 | result = result .. abjad[3][math.floor(n/100)] | ||
401 | n = math.fmod(n, 100) | ||
402 | end | ||
403 | if n >= 10 then | ||
404 | result = result .. abjad[2][math.floor(n/10)] | ||
405 | n = math.fmod(n, 10) | ||
406 | end | ||
407 | if n >= 1 then | ||
408 | result = result .. abjad[1][math.floor(n/1)] | ||
409 | end | ||
410 | return "\\arb{"..result.."}" | ||
411 | end | ||