From 2eeb8fbdce276376dbbae8be0e76d7db5ae7b113 Mon Sep 17 00:00:00 2001 From: Robert Alessi Date: Mon, 29 Feb 2016 21:53:35 +0100 Subject: first implementation of transliteration tables (dmg) --- arabluatex.dtx | 28 +++++++++++++++++++++++----- 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 @@ % \end{macrocode} % \begin{macrocode} \DeclareOption{voc}{\def\al@mode{voc}} -\DeclareOption{novoc}{\def\al@mode{novoc}} \DeclareOption{fullvoc}{\def\al@mode{fullvoc}} +\DeclareOption{novoc}{\def\al@mode{novoc}} +\DeclareOption{trans}{\def\al@mode{trans}} \ExecuteOptions{voc} \ProcessOptions\relax \def\al@mode@voc{voc} \def\al@mode@fullvoc{fullvoc} \def\al@mode@novoc{novoc} +\def\al@mode@trans{trans} % \newif\ifal@mode@defined \RequirePackage{amsmath} \RequirePackage{etoolbox} @@ -220,7 +222,14 @@ \AtBeginDocument{\ifdef{\aemph}% {\RenewDocumentCommand{\aemph}{m}{$\overline{\text{#1}}$}} {\NewDocumentCommand{\aemph}{m}{$\overline{\text{#1}}$}}} -\DeclareDocumentCommand{\txarb}{+m}{\bgroup\textdir TRT\arabicfont#1\egroup} +\def\al@trans@style{\itshape}% +\NewDocumentCommand{\SetTranslitStyle}{m}{\def\al@trans@style{#1}} +\NewDocumentCommand{\SetTranslitConvention}{m}{\def\al@trans@convention{#1}} +\def\al@trans@convention{dmg} +\DeclareDocumentCommand{\txarb}{+m}{\bgroup\textdir + TRT\arabicfont#1\egroup} +\DeclareDocumentCommand{\txtrans}{+m}{\bgroup\textdir + TLT\rmfamily#1\egroup} \DeclareDocumentCommand{\arb}{O{\al@mode} +m}% {\edef\@tempa{#1}% \ifx\@tempa\al@mode@voc% @@ -235,7 +244,12 @@ \bgroup\textdir TRT\arabicfont% \luadirect{tex.sprint(processnovoc(\luastringN{#2}))}\egroup% \else% - \fi\fi\fi} + \ifx\@tempa\al@mode@trans% + \bgroup\textdir TLT\al@trans@style% + \luadirect{tex.sprint(processtrans(\luastringN{#2}, + \luastringO{\al@trans@convention}))}\egroup% + \else% + \fi\fi\fi\fi} \NewEnviron{arab}[1][\al@mode]% {\par\edef\@tempa{#1}% \ifx\@tempa\al@mode@voc% @@ -250,8 +264,12 @@ \bgroup\pardir TRT\textdir TRT\arabicfont% \luadirect{tex.sprint(processnovoc(\luastringO{\BODY}))}\egroup% \else - \BODY% - \fi\fi\fi}[\par] + \ifx\@tempa\al@mode@trans% + \bgroup\pardir TLT\textdir TLT\al@trans@style% + \luadirect{tex.sprint(processtrans(\luastringO{\BODY}, + \luastringO{\al@trans@convention}))}\egroup% + \else + \fi\fi\fi\fi}[\par] % \robustify{\textbf} % \robustify{\emph} % \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 require("arabluatex_voc") require("arabluatex_fullvoc") require("arabluatex_novoc") +require("arabluatex_trans") local function protectarb(str) str = string.gsub(str, "(\\arb.?)(%[.-%])(%b{})", "\\@arb%2%3") @@ -206,6 +207,35 @@ local function novoc(str) return str end +local function transdmg(str) + str = string.gsub(str, "\\arb(%b{})", function(inside) + inside = string.sub(inside, 2, -2) + for i = 1,#hamzatrdmg do + inside = string.gsub(inside, hamzatrdmg[i].a, hamzatrdmg[i].b) + end + for i = 1,#tanwintrdmg do + inside = string.gsub(inside, tanwintrdmg[i].a, tanwintrdmg[i].b) + end + for i = 1,#trigraphstrdmg do + inside = string.gsub(inside, trigraphstrdmg[i].a, trigraphstrdmg[i].b) + end + for i = 1,#digraphstrdmg do + inside = string.gsub(inside, digraphstrdmg[i].a, digraphstrdmg[i].b) + end + for i = 1,#singletrdmg do + inside = string.gsub(inside, singletrdmg[i].a, singletrdmg[i].b) + end + for i = 1,#longvtrdmg do + inside = string.gsub(inside, longvtrdmg[i].a, longvtrdmg[i].b) + end + for i = 1,#shortvtrdmg do + inside = string.gsub(inside, shortvtrdmg[i].a, shortvtrdmg[i].b) + end + return string.format("\\txtrans{%s}", inside) + end) +return str +end + function processvoc(str) str = "\\arb{".. str.."}" str = protectarb(str) @@ -236,6 +266,18 @@ function processnovoc(str) return str end +function processtrans(str, mode) + str = "\\arb{".. str.."}" + str = protectarb(str) + str = breakcmd(str) + str = holdcmd(str) + if mode == "dmg" then + str = transdmg(str) + else end + str = unprotectarb(str) +return str +end + --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")) --print(arbnum("bop 0123456789")) --print(processvoc("daxala \\arb[novoc]{mubtasimaN}")) -- cgit v1.2.3