From 374a2ade09506f08e0e903f15f8c08b0ec751120 Mon Sep 17 00:00:00 2001 From: Robert Alessi Date: Sat, 23 Mar 2019 10:34:02 +0100 Subject: stored all global functions in the 'arabluatex' table --- arabluatex.dtx | 75 +++++++++++++++++++++++++++++----------------------------- arabluatex.lua | 62 ++++++++++++++++++++++++------------------------ 2 files changed, 69 insertions(+), 68 deletions(-) diff --git a/arabluatex.dtx b/arabluatex.dtx index 8f13acd..4f185ce 100644 --- a/arabluatex.dtx +++ b/arabluatex.dtx @@ -4327,9 +4327,9 @@ wa-ya.sIru ta.hta 'l-jild-i \DeclareOptionX{trans}{\def\al@mode{trans}} \define@boolkey{arabluatex.sty}[@pkg@]{export}[true]{% \if@pkg@export% - \AtBeginDocument{\luadirect{al_openstream()}% + \AtBeginDocument{\luadirect{arabluatex.openstream()}% \MkArbBreak{@al@ob,@al@cb,@al@cb@sp}} - \AtEndDocument{\luadirect{al_closestream()}} + \AtEndDocument{\luadirect{arabluatex.closestream()}} \else\fi} \ExecuteOptionsX{voc} \ProcessOptionsX\relax @@ -4415,8 +4415,8 @@ wa-ya.sIru ta.hta 'l-jild-i % \begin{macrocode} \NewDocumentCommand{\MkArbBreak}{s m}{% \IfBooleanTF{#1} - {\luadirect{mkarbbreak(\luastringN{#2}, "out")}} - {\luadirect{mkarbbreak(\luastringN{#2}, "dflt")}} + {\luadirect{arabluatex.mkarbbreak(\luastringN{#2}, "out")}} + {\luadirect{arabluatex.mkarbbreak(\luastringN{#2}, "dflt")}} } % \end{macrocode} % \end{macro} @@ -4437,12 +4437,12 @@ wa-ya.sIru ta.hta 'l-jild-i \AtBeginDocument{\ifdef{\aemph}% {\RenewDocumentCommand{\aemph}{s m}{% \IfBooleanTF{#1}{% - \luadirect{tex.sprint(aemph(\luastringN{#2}, "over"))}} - {\luadirect{tex.sprint(aemph(\luastringN{#2}, "dflt"))}}}} + \luadirect{tex.sprint(arabluatex.aemph(\luastringN{#2}, "over"))}} + {\luadirect{tex.sprint(arabluatex.aemph(\luastringN{#2}, "dflt"))}}}} {\NewDocumentCommand{\aemph}{s m}{% \IfBooleanTF{#1}{% - \luadirect{tex.sprint(aemph(\luastringN{#2}, "over"))}} - {\luadirect{tex.sprint(aemph(\luastringN{#2}, "dflt"))}}}}} + \luadirect{tex.sprint(arabluatex.aemph(\luastringN{#2}, "over"))}} + {\luadirect{tex.sprint(arabluatex.aemph(\luastringN{#2}, "dflt"))}}}}} % \end{macrocode} % \end{macro} % \end{macro} @@ -4567,7 +4567,7 @@ wa-ya.sIru ta.hta 'l-jild-i % uppercased. \cs{uc} is actually coded in Lua. % \begin{macrocode} \NewDocumentCommand{\uc}{m}% - {\luadirect{tex.sprint(uc(\luastringN{#1}))}} + {\luadirect{tex.sprint(arabluatex.uc(\luastringN{#1}))}} % \end{macrocode} % \end{macro} % \begin{macro}{\Uc} \cs{uc} can be used safely in all of the modes @@ -4638,22 +4638,22 @@ wa-ya.sIru ta.hta 'l-jild-i {\edef\@tempa{#1}% \ifx\@tempa\al@mode@voc% \bgroup\booltrue{al@rlmode}\textdir TRT\arabicfont% - \luadirect{tex.sprint(processvoc(\luastringN{#2}, + \luadirect{tex.sprint(arabluatex.processvoc(\luastringN{#2}, \luastringO{\al@arb@rules}, \luastringO{\al@input@scheme}))}\egroup% \else% \ifx\@tempa\al@mode@fullvoc% \bgroup\booltrue{al@rlmode}\textdir TRT\arabicfont% - \luadirect{tex.sprint(processfullvoc(\luastringN{#2}, + \luadirect{tex.sprint(arabluatex.processfullvoc(\luastringN{#2}, \luastringO{\al@arb@rules}, \luastringO{\al@input@scheme}))}\egroup% \else% \ifx\@tempa\al@mode@novoc% \bgroup\booltrue{al@rlmode}\textdir TRT\arabicfont% - \luadirect{tex.sprint(processnovoc(\luastringN{#2}, + \luadirect{tex.sprint(arabluatex.processnovoc(\luastringN{#2}, \luastringO{\al@arb@rules}, \luastringO{\al@input@scheme}))}\egroup% \else% \ifx\@tempa\al@mode@trans% \bgroup\textdir TLT\al@trans@font\al@trans@style% - \luadirect{tex.sprint(processtrans(\luastringN{#2}, + \luadirect{tex.sprint(arabluatex.processtrans(\luastringN{#2}, \luastringO{\al@trans@convention}, \luastringO{\al@arb@rules}, \luastringO{\al@input@scheme}))}\egroup% @@ -4674,7 +4674,7 @@ wa-ya.sIru ta.hta 'l-jild-i \NewDocumentCommand{\arbmark}{O{} m}{% \bgroup% \SetInputScheme{arabtex}% - \luadirect{tex.sprint(processarbmarks(\luastringN{#2}, + \luadirect{tex.sprint(arabluatex.processarbmarks(\luastringN{#2}, \luastringN{#1}))}% \egroup} % \end{macrocode} @@ -4688,7 +4688,8 @@ wa-ya.sIru ta.hta 'l-jild-i % romanized Arabic. % \begin{macrocode} \NewDocumentCommand{\newarbmark}{m m m}{% - \luadirect{newarbmark(\luastringN{#1}, \luastringN{#2}, \luastringN{#3})}} + \luadirect{arabluatex.newarbmark(\luastringN{#1}, \luastringN{#2}, + \luastringN{#3})}} % \end{macrocode} % \end{macro} % \begin{environment}{arab} @@ -4700,24 +4701,24 @@ wa-ya.sIru ta.hta 'l-jild-i \ifx\@tempa\al@mode@voc% \booltrue{al@rlmode}% \bgroup\pardir TRT\textdir TRT\arabicfont% - \luadirect{tex.sprint(processvoc(\luastringO{\BODY}, + \luadirect{tex.sprint(arabluatex.processvoc(\luastringO{\BODY}, \luastringO{\al@arb@rules}, \luastringO{\al@input@scheme}))}\egroup% \else% \ifx\@tempa\al@mode@fullvoc% \booltrue{al@rlmode}% \bgroup\pardir TRT\textdir TRT\arabicfont% - \luadirect{tex.sprint(processfullvoc(\luastringO{\BODY}, + \luadirect{tex.sprint(arabluatex.processfullvoc(\luastringO{\BODY}, \luastringO{\al@arb@rules}, \luastringO{\al@input@scheme}))}\egroup% \else% \ifx\@tempa\al@mode@novoc% \booltrue{al@rlmode}% \bgroup\pardir TRT\textdir TRT\arabicfont% - \luadirect{tex.sprint(processnovoc(\luastringO{\BODY}, + \luadirect{tex.sprint(arabluatex.processnovoc(\luastringO{\BODY}, \luastringO{\al@arb@rules}, \luastringO{\al@input@scheme}))}\egroup% \else% \ifx\@tempa\al@mode@trans% \bgroup\pardir TLT\textdir TLT\al@trans@font\al@trans@style% - \luadirect{tex.sprint(processtrans(\luastringO{\BODY}, + \luadirect{tex.sprint(arabluatex.processtrans(\luastringO{\BODY}, \luastringO{\al@trans@convention}, \luastringO{\al@arb@rules}, \luastringO{\al@input@scheme}))}\egroup% @@ -4758,11 +4759,11 @@ wa-ya.sIru ta.hta 'l-jild-i \if@pkg@export\ifal@verse@export% \ArbOutFile{\begin{arabverse}}% % \ifx\al@mode\al@mode@trans% - % \luadirect{tooutfile(\luastringN{[#1]})}% + % \luadirect{arabluatex.tooutfile(\luastringN{[#1]})}% % \else% \IfSubStr[1]{#1}{utf}% - {\luadirect{tooutfile(\luastringN{[#1]})}}% - {\luadirect{tooutfile(\luastringN{[#1, utf]})}}% + {\luadirect{arabluatex.tooutfile(\luastringN{[#1]})}}% + {\luadirect{arabluatex.tooutfile(\luastringN{[#1, utf]})}}% % \fi \else\fi\else\fi\egroup% \par\centering\noindent\bgroup\setkeys[al]{verse}[metre]{#1}% @@ -4852,13 +4853,13 @@ wa-ya.sIru ta.hta 'l-jild-i \ifdefined\abjad% \RenewDocumentCommand{\abjad}{m}% {\ifbool{al@rlmode}% - {\oline*{\luadirect{tex.sprint(abjadify(\luastring{#1}))}}} - {\luadirect{tex.sprint(abjadify(\luastring{#1}))}}} + {\oline*{\luadirect{tex.sprint(arabluatex.abjadify(\luastring{#1}))}}} + {\luadirect{tex.sprint(arabluatex.abjadify(\luastring{#1}))}}} \else% \NewDocumentCommand{\abjad}{m}% {\ifbool{al@rlmode}% - {\oline*{\luadirect{tex.sprint(abjadify(\luastring{#1}))}}} - {\luadirect{tex.sprint(abjadify(\luastring{#1}))}}} + {\oline*{\luadirect{tex.sprint(arabluatex.abjadify(\luastring{#1}))}}} + {\luadirect{tex.sprint(arabluatex.abjadify(\luastring{#1}))}}} \fi} % \end{macrocode} % \end{macro} @@ -4868,7 +4869,7 @@ wa-ya.sIru ta.hta 'l-jild-i % depending on the mode which is selected. % \begin{macrocode} \NewDocumentCommand{\ayah}{m}{% - \luadirect{tex.sprint(ayah(\luastringN{#1}))}} + \luadirect{tex.sprint(arabluatex.ayah(\luastringN{#1}))}} % \end{macrocode} % \end{macro} % @@ -4890,7 +4891,7 @@ wa-ya.sIru ta.hta 'l-jild-i % expresses its argument between braces.} % \begin{macrocode} \NewDocumentCommand{\abraces}{+m}{% - \luadirect{tex.sprint(abraces(\luastringN{#1}))}} + \luadirect{tex.sprint(arabluatex.abraces(\luastringN{#1}))}} % \end{macrocode} % \end{macro} % \begin{macro}{\LRmarginpar} \cs{LRmarginpar} is supposed to be @@ -4940,7 +4941,7 @@ wa-ya.sIru ta.hta 'l-jild-i % set with \cs{SetArbOutSuffix}\marg{suffix}. % \begin{macrocode} \NewDocumentCommand{\SetArbOutSuffix}{m}{ - \luadirect{al_utffilesuffix(\luastringN{#1})}} + \luadirect{arabluatex.utffilesuffix(\luastringN{#1})}} % \end{macrocode} % \end{macro} % \begin{macro}{\ArbOutFile} @@ -4958,8 +4959,8 @@ wa-ya.sIru ta.hta 'l-jild-i \NewDocumentCommand{\ArbOutFile}{s O{no} +m}{% \if@pkg@export% \IfBooleanTF{#1}{% - #3\luadirect{tooutfile(\luastringN{#3}, "#2")}}{% - \luadirect{tooutfile(\luastringN{#3}, "#2")}}% + #3\luadirect{arabluatex.tooutfile(\luastringN{#3}, "#2")}}{% + \luadirect{arabluatex.tooutfile(\luastringN{#3}, "#2")}}% \else\IfBooleanTF{#1}{#3}{}\fi} % \end{macrocode} % \end{macro} @@ -4978,9 +4979,9 @@ wa-ya.sIru ta.hta 'l-jild-i \if@pkg@export% \par \BODY - \luadirect{al_doexport("yes")} - \luadirect{tex.sprint(arbtoutf(\luastringO{\BODY}))} - \luadirect{al_doexport("no")} + \luadirect{arabluatex.doexport("yes")} + \luadirect{tex.sprint(arabluatex.arbtoutf(\luastringO{\BODY}))} + \luadirect{arabluatex.doexport("no")} \else\par\BODY\fi }[\par] % \end{macrocode} @@ -4995,9 +4996,9 @@ wa-ya.sIru ta.hta 'l-jild-i \if@pkg@export\ifal@verse@export% \par \BODY - \luadirect{al_doexport("arabverse")} - \luadirect{tex.sprint(arbtoutf(\luastringO{\BODY}))} - \luadirect{al_doexport("no")} + \luadirect{arabluatex.doexport("arabverse")} + \luadirect{tex.sprint(arabluatex.arbtoutf(\luastringO{\BODY}))} + \luadirect{arabluatex.doexport("no")} \else\par\BODY\fi\else\par\BODY\fi }[\par] % \end{macrocode} diff --git a/arabluatex.lua b/arabluatex.lua index 39b4f56..df03156 100644 --- a/arabluatex.lua +++ b/arabluatex.lua @@ -97,7 +97,7 @@ local albrkcmds = { } local brkcmds = {} -function mkarbbreak(str, opt) +function arabluatex.mkarbbreak(str, opt) str = str .."," str = string.gsub(str, "%s+", "") local fieldstart = 1 @@ -661,17 +661,17 @@ end local utffilesuffix = "_out" local export_utf = "no" -function al_utffilesuffix(str) +function arabluatex.utffilesuffix(str) utffilesuffix = str return true end -function al_doexport(str) +function arabluatex.doexport(str) export_utf = str return true end -function al_openstream() +function arabluatex.openstream() local f = io.open(tex.jobname..utffilesuffix.."_tmp.tex", "a+") local preamble = io.open(tex.jobname..".tex", "r") for line in preamble:lines() do @@ -708,7 +708,7 @@ local function processarbtoutf(str) body = string.gsub(body, "(\\abjad%s?)(%b{})", function(btag, bbody) bbody = string.sub(bbody, 2, -2) if tonumber(bbody) ~= nil then - bbody = abjadify(bbody) + bbody = arabluatex.abjadify(bbody) return string.format("\\oline*{\\arb[novoc]{%s}}", bbody) else return string.format("%s{%s}", btag, bbody) @@ -795,7 +795,7 @@ local function processarbtoutf(str) return str end -function arbtoutf(str) +function arabluatex.arbtoutf(str) str = processarbtoutf(str) str = "\\ArbOutFile{"..str.."}" str = string.gsub(str, "(\\ArbOutFile)%s?(%b{})", function(tag, body) @@ -816,7 +816,7 @@ function arbtoutf(str) return str end -function tooutfile(str, nl) +function arabluatex.tooutfile(str, nl) local f = io.open(tex.jobname..utffilesuffix.."_tmp.tex", "a+") if nl == "newline" then f:write(str, "\n\n") @@ -827,7 +827,7 @@ function tooutfile(str, nl) return str end -function al_closestream() +function arabluatex.closestream() local f = io.open(tex.jobname..utffilesuffix.."_tmp.tex", "r") local o = io.open(tex.jobname..utffilesuffix..".tex", "w") local t = f:read("*a") @@ -885,7 +885,7 @@ function al_closestream() end -- Process standard arabluatex modes: -function processvoc(str, rules, scheme) +function arabluatex.processvoc(str, rules, scheme) str = takeoutarb(str) str = processarbnull(str, scheme) str = takeoutcapetc(str) @@ -903,17 +903,17 @@ function processvoc(str, rules, scheme) str = unprotectarb(str) if export_utf == "yes" then tofile = "\\txarb{"..str.."}" - tooutfile(tofile) + arabluatex.tooutfile(tofile) elseif export_utf == "arabverse" then tofile = "\\txarb{"..str.."}" - tooutfile(tofile) + arabluatex.tooutfile(tofile) else return str end return "" end -function processfullvoc(str, rules, scheme) +function arabluatex.processfullvoc(str, rules, scheme) str = takeoutarb(str) str = processarbnull(str, scheme) str = takeoutcapetc(str) @@ -933,17 +933,17 @@ function processfullvoc(str, rules, scheme) str = unprotectarb(str) if export_utf == "yes" then tofile = "\\txarb{"..str.."}" - tooutfile(tofile) + arabluatex.tooutfile(tofile) elseif export_utf == "arabverse" then tofile = "\\txarb{"..str.."}" - tooutfile(tofile) + arabluatex.tooutfile(tofile) else return str end return "" end -function processnovoc(str, rules, scheme) +function arabluatex.processnovoc(str, rules, scheme) str = takeoutarb(str) str = processarbnull(str, scheme) str = takeoutcapetc(str) @@ -961,17 +961,17 @@ function processnovoc(str, rules, scheme) str = unprotectarb(str) if export_utf == "yes" then tofile = "\\txarb{"..str.."}" - tooutfile(tofile) + arabluatex.tooutfile(tofile) elseif export_utf == "arabverse" then tofile = "\\txarb{"..str.."}" - tooutfile(tofile) + arabluatex.tooutfile(tofile) else return str end return "" end -function processtrans(str, mode, rules, scheme) +function arabluatex.processtrans(str, mode, rules, scheme) str = takeoutarb(str) str = processdiscretionary(str) str = processarbnull(str, scheme) @@ -992,17 +992,17 @@ function processtrans(str, mode, rules, scheme) str = unprotectarb(str) if export_utf == "yes" then tofile = "\\txtrans{"..str.."}" - tooutfile(tofile) + arabluatex.tooutfile(tofile) elseif export_utf == "arabverse" then tofile = "\\txtrans{"..str.."}" - tooutfile(tofile) + arabluatex.tooutfile(tofile) else return str end return "" end -function newarbmark(abbr, rtlmk, ltrmk) +function arabluatex.newarbmark(abbr, rtlmk, ltrmk) abbr = "@"..abbr rtlmk = "\\arabicfont{}"..rtlmk table.insert(arbmarks, {a = abbr, b = rtlmk, c = ltrmk}) @@ -1019,7 +1019,7 @@ local function isintable(table, element) return false end -function processarbmarks(str, dir) +function arabluatex.processarbmarks(str, dir) str = "@"..str if not isintable(arbmarks, str) then str = "\\LR{}"..atletter.."\\al@wrong@mark{}"..atother @@ -1044,17 +1044,17 @@ function processarbmarks(str, dir) end if export_utf == "yes" then tofile = str - tooutfile(tofile) + arabluatex.tooutfile(tofile) elseif export_utf == "arabverse" then tofile = str - tooutfile(tofile) + arabluatex.tooutfile(tofile) else return str end return "" end -function uc(str) +function arabluatex.uc(str) str = string.gsub(str, "(\\txtrans.?)(%b{})", function(tag, body) body = string.sub(body, 2, -2) return string.format("%s", body) @@ -1115,10 +1115,10 @@ function uc(str) str = string.gsub(str, "\\@al@cb", "}") if export_utf == "yes" then tofile = str - tooutfile(tofile) + arabluatex.tooutfile(tofile) elseif export_utf == "arabverse" then tofile = str - tooutfile(tofile) + arabluatex.tooutfile(tofile) else return str end @@ -1128,7 +1128,7 @@ end -- this function is adapted from an 'obsolete project' of Khaled -- Hosny's that dates back to 2010. Thanks to him. -- See https://github.com/khaledhosny/lualatex-arabic -function abjadify(n) +function arabluatex.abjadify(n) local abjadnum = "" n = tonumber(n) if n >= 1000 then @@ -1151,7 +1151,7 @@ function abjadify(n) return "\\arb[novoc]{"..abjadnum.."}" end -function abraces(str) +function arabluatex.abraces(str) if tex.textdir == "TRT" then str = "\\}"..str.."\\{" elseif tex.textdir == "TLT" then @@ -1160,7 +1160,7 @@ function abraces(str) return str end -function aemph(str, opt) +function arabluatex.aemph(str, opt) if tex.textdir == "TRT" then str = "\\oline{\\textdir TRT{}"..str.."}" elseif tex.textdir == "TLT" then @@ -1173,7 +1173,7 @@ function aemph(str, opt) return str end -function ayah(str) +function arabluatex.ayah(str) if tonumber(str) ~= nil and str.len(str) < 4 then if tex.textdir == "TRT" then str = indnum(str).."^^^^06dd" -- cgit v1.2.3