diff options
author | Robert Alessi <alessi@robertalessi.net> | 2016-02-29 21:53:35 +0100 |
---|---|---|
committer | Robert Alessi <alessi@robertalessi.net> | 2016-02-29 21:53:35 +0100 |
commit | 2eeb8fbdce276376dbbae8be0e76d7db5ae7b113 (patch) | |
tree | 8ea31a62e8e50fe4c24d3ba8441e8a072993be67 | |
parent | a60a9791400541ec7d3ebec310705c1cfe7ab911 (diff) | |
download | arabluatex-2eeb8fbdce276376dbbae8be0e76d7db5ae7b113.tar.gz |
first implementation of transliteration tables (dmg)
-rw-r--r-- | arabluatex.dtx | 28 | ||||
-rw-r--r-- | arabluatex.lua | 42 |
2 files changed, 65 insertions, 5 deletions
diff --git a/arabluatex.dtx b/arabluatex.dtx index ec2f630..1dbfd3d 100644 --- a/arabluatex.dtx +++ b/arabluatex.dtx | |||
@@ -183,13 +183,15 @@ | |||
183 | % \end{macrocode} | 183 | % \end{macrocode} |
184 | % \begin{macrocode} | 184 | % \begin{macrocode} |
185 | \DeclareOption{voc}{\def\al@mode{voc}} | 185 | \DeclareOption{voc}{\def\al@mode{voc}} |
186 | \DeclareOption{novoc}{\def\al@mode{novoc}} | ||
187 | \DeclareOption{fullvoc}{\def\al@mode{fullvoc}} | 186 | \DeclareOption{fullvoc}{\def\al@mode{fullvoc}} |
187 | \DeclareOption{novoc}{\def\al@mode{novoc}} | ||
188 | \DeclareOption{trans}{\def\al@mode{trans}} | ||
188 | \ExecuteOptions{voc} | 189 | \ExecuteOptions{voc} |
189 | \ProcessOptions\relax | 190 | \ProcessOptions\relax |
190 | \def\al@mode@voc{voc} | 191 | \def\al@mode@voc{voc} |
191 | \def\al@mode@fullvoc{fullvoc} | 192 | \def\al@mode@fullvoc{fullvoc} |
192 | \def\al@mode@novoc{novoc} | 193 | \def\al@mode@novoc{novoc} |
194 | \def\al@mode@trans{trans} | ||
193 | % \newif\ifal@mode@defined | 195 | % \newif\ifal@mode@defined |
194 | \RequirePackage{amsmath} | 196 | \RequirePackage{amsmath} |
195 | \RequirePackage{etoolbox} | 197 | \RequirePackage{etoolbox} |
@@ -220,7 +222,14 @@ | |||
220 | \AtBeginDocument{\ifdef{\aemph}% | 222 | \AtBeginDocument{\ifdef{\aemph}% |
221 | {\RenewDocumentCommand{\aemph}{m}{$\overline{\text{#1}}$}} | 223 | {\RenewDocumentCommand{\aemph}{m}{$\overline{\text{#1}}$}} |
222 | {\NewDocumentCommand{\aemph}{m}{$\overline{\text{#1}}$}}} | 224 | {\NewDocumentCommand{\aemph}{m}{$\overline{\text{#1}}$}}} |
223 | \DeclareDocumentCommand{\txarb}{+m}{\bgroup\textdir TRT\arabicfont#1\egroup} | 225 | \def\al@trans@style{\itshape}% |
226 | \NewDocumentCommand{\SetTranslitStyle}{m}{\def\al@trans@style{#1}} | ||
227 | \NewDocumentCommand{\SetTranslitConvention}{m}{\def\al@trans@convention{#1}} | ||
228 | \def\al@trans@convention{dmg} | ||
229 | \DeclareDocumentCommand{\txarb}{+m}{\bgroup\textdir | ||
230 | TRT\arabicfont#1\egroup} | ||
231 | \DeclareDocumentCommand{\txtrans}{+m}{\bgroup\textdir | ||
232 | TLT\rmfamily#1\egroup} | ||
224 | \DeclareDocumentCommand{\arb}{O{\al@mode} +m}% | 233 | \DeclareDocumentCommand{\arb}{O{\al@mode} +m}% |
225 | {\edef\@tempa{#1}% | 234 | {\edef\@tempa{#1}% |
226 | \ifx\@tempa\al@mode@voc% | 235 | \ifx\@tempa\al@mode@voc% |
@@ -235,7 +244,12 @@ | |||
235 | \bgroup\textdir TRT\arabicfont% | 244 | \bgroup\textdir TRT\arabicfont% |
236 | \luadirect{tex.sprint(processnovoc(\luastringN{#2}))}\egroup% | 245 | \luadirect{tex.sprint(processnovoc(\luastringN{#2}))}\egroup% |
237 | \else% | 246 | \else% |
238 | \fi\fi\fi} | 247 | \ifx\@tempa\al@mode@trans% |
248 | \bgroup\textdir TLT\al@trans@style% | ||
249 | \luadirect{tex.sprint(processtrans(\luastringN{#2}, | ||
250 | \luastringO{\al@trans@convention}))}\egroup% | ||
251 | \else% | ||
252 | \fi\fi\fi\fi} | ||
239 | \NewEnviron{arab}[1][\al@mode]% | 253 | \NewEnviron{arab}[1][\al@mode]% |
240 | {\par\edef\@tempa{#1}% | 254 | {\par\edef\@tempa{#1}% |
241 | \ifx\@tempa\al@mode@voc% | 255 | \ifx\@tempa\al@mode@voc% |
@@ -250,8 +264,12 @@ | |||
250 | \bgroup\pardir TRT\textdir TRT\arabicfont% | 264 | \bgroup\pardir TRT\textdir TRT\arabicfont% |
251 | \luadirect{tex.sprint(processnovoc(\luastringO{\BODY}))}\egroup% | 265 | \luadirect{tex.sprint(processnovoc(\luastringO{\BODY}))}\egroup% |
252 | \else | 266 | \else |
253 | \BODY% | 267 | \ifx\@tempa\al@mode@trans% |
254 | \fi\fi\fi}[\par] | 268 | \bgroup\pardir TLT\textdir TLT\al@trans@style% |
269 | \luadirect{tex.sprint(processtrans(\luastringO{\BODY}, | ||
270 | \luastringO{\al@trans@convention}))}\egroup% | ||
271 | \else | ||
272 | \fi\fi\fi\fi}[\par] | ||
255 | % \robustify{\textbf} | 273 | % \robustify{\textbf} |
256 | % \robustify{\emph} | 274 | % \robustify{\emph} |
257 | % \robustify{\footnote} | 275 | % \robustify{\footnote} |
diff --git a/arabluatex.lua b/arabluatex.lua index f0cfa78..b716bea 100644 --- a/arabluatex.lua +++ b/arabluatex.lua | |||
@@ -25,6 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |||
25 | require("arabluatex_voc") | 25 | require("arabluatex_voc") |
26 | require("arabluatex_fullvoc") | 26 | require("arabluatex_fullvoc") |
27 | require("arabluatex_novoc") | 27 | require("arabluatex_novoc") |
28 | require("arabluatex_trans") | ||
28 | 29 | ||
29 | local function protectarb(str) | 30 | local function protectarb(str) |
30 | str = string.gsub(str, "(\\arb.?)(%[.-%])(%b{})", "\\@arb%2%3") | 31 | str = string.gsub(str, "(\\arb.?)(%[.-%])(%b{})", "\\@arb%2%3") |
@@ -206,6 +207,35 @@ local function novoc(str) | |||
206 | return str | 207 | return str |
207 | end | 208 | end |
208 | 209 | ||
210 | local function transdmg(str) | ||
211 | str = string.gsub(str, "\\arb(%b{})", function(inside) | ||
212 | inside = string.sub(inside, 2, -2) | ||
213 | for i = 1,#hamzatrdmg do | ||
214 | inside = string.gsub(inside, hamzatrdmg[i].a, hamzatrdmg[i].b) | ||
215 | end | ||
216 | for i = 1,#tanwintrdmg do | ||
217 | inside = string.gsub(inside, tanwintrdmg[i].a, tanwintrdmg[i].b) | ||
218 | end | ||
219 | for i = 1,#trigraphstrdmg do | ||
220 | inside = string.gsub(inside, trigraphstrdmg[i].a, trigraphstrdmg[i].b) | ||
221 | end | ||
222 | for i = 1,#digraphstrdmg do | ||
223 | inside = string.gsub(inside, digraphstrdmg[i].a, digraphstrdmg[i].b) | ||
224 | end | ||
225 | for i = 1,#singletrdmg do | ||
226 | inside = string.gsub(inside, singletrdmg[i].a, singletrdmg[i].b) | ||
227 | end | ||
228 | for i = 1,#longvtrdmg do | ||
229 | inside = string.gsub(inside, longvtrdmg[i].a, longvtrdmg[i].b) | ||
230 | end | ||
231 | for i = 1,#shortvtrdmg do | ||
232 | inside = string.gsub(inside, shortvtrdmg[i].a, shortvtrdmg[i].b) | ||
233 | end | ||
234 | return string.format("\\txtrans{%s}", inside) | ||
235 | end) | ||
236 | return str | ||
237 | end | ||
238 | |||
209 | function processvoc(str) | 239 | function processvoc(str) |
210 | str = "\\arb{".. str.."}" | 240 | str = "\\arb{".. str.."}" |
211 | str = protectarb(str) | 241 | str = protectarb(str) |
@@ -236,6 +266,18 @@ function processnovoc(str) | |||
236 | return str | 266 | return str |
237 | end | 267 | end |
238 | 268 | ||
269 | function processtrans(str, mode) | ||
270 | str = "\\arb{".. str.."}" | ||
271 | str = protectarb(str) | ||
272 | str = breakcmd(str) | ||
273 | str = holdcmd(str) | ||
274 | if mode == "dmg" then | ||
275 | str = transdmg(str) | ||
276 | else end | ||
277 | str = unprotectarb(str) | ||
278 | return str | ||
279 | end | ||
280 | |||
239 | --print(processvoc("'at_A .sadIquN 'il_A ju.hA ya.tlubu min-hu .himAra-hu li-yarkiba-hu fI safraTiN qa.sIraTiN wa-qAla la-hu sawfa 'u`Idu-hu 'ilay-ka fI 'l-masA'i wa-'adfa`u la-ka 'ujraTaN 'at_A .sadIquN 'il_A ju.hA ya.tlubu min-hu .himAra-hu li-yarkiba-hu fI safraTiN qa.sIraTiN wa-qAla la-hu sawfa 'u`Idu-hu 'ilay-ka fI 'l-masA'i wa-'adfa`u la-ka 'ujraTaN")) | 281 | --print(processvoc("'at_A .sadIquN 'il_A ju.hA ya.tlubu min-hu .himAra-hu li-yarkiba-hu fI safraTiN qa.sIraTiN wa-qAla la-hu sawfa 'u`Idu-hu 'ilay-ka fI 'l-masA'i wa-'adfa`u la-ka 'ujraTaN 'at_A .sadIquN 'il_A ju.hA ya.tlubu min-hu .himAra-hu li-yarkiba-hu fI safraTiN qa.sIraTiN wa-qAla la-hu sawfa 'u`Idu-hu 'ilay-ka fI 'l-masA'i wa-'adfa`u la-ka 'ujraTaN")) |
240 | --print(arbnum("bop 0123456789")) | 282 | --print(arbnum("bop 0123456789")) |
241 | --print(processvoc("daxala \\arb[novoc]{mubtasimaN}")) | 283 | --print(processvoc("daxala \\arb[novoc]{mubtasimaN}")) |