aboutsummaryrefslogtreecommitdiff
path: root/arabluatex.lua
diff options
context:
space:
mode:
Diffstat (limited to 'arabluatex.lua')
-rw-r--r--arabluatex.lua62
1 files changed, 31 insertions, 31 deletions
diff --git a/arabluatex.lua b/arabluatex.lua
index 39b4f56..df03156 100644
--- a/arabluatex.lua
+++ b/arabluatex.lua
@@ -97,7 +97,7 @@ local albrkcmds = {
97} 97}
98local brkcmds = {} 98local brkcmds = {}
99 99
100function mkarbbreak(str, opt) 100function arabluatex.mkarbbreak(str, opt)
101 str = str .."," 101 str = str ..","
102 str = string.gsub(str, "%s+", "") 102 str = string.gsub(str, "%s+", "")
103 local fieldstart = 1 103 local fieldstart = 1
@@ -661,17 +661,17 @@ end
661local utffilesuffix = "_out" 661local utffilesuffix = "_out"
662local export_utf = "no" 662local export_utf = "no"
663 663
664function al_utffilesuffix(str) 664function arabluatex.utffilesuffix(str)
665 utffilesuffix = str 665 utffilesuffix = str
666 return true 666 return true
667end 667end
668 668
669function al_doexport(str) 669function arabluatex.doexport(str)
670 export_utf = str 670 export_utf = str
671 return true 671 return true
672end 672end
673 673
674function al_openstream() 674function arabluatex.openstream()
675 local f = io.open(tex.jobname..utffilesuffix.."_tmp.tex", "a+") 675 local f = io.open(tex.jobname..utffilesuffix.."_tmp.tex", "a+")
676 local preamble = io.open(tex.jobname..".tex", "r") 676 local preamble = io.open(tex.jobname..".tex", "r")
677 for line in preamble:lines() do 677 for line in preamble:lines() do
@@ -708,7 +708,7 @@ local function processarbtoutf(str)
708 body = string.gsub(body, "(\\abjad%s?)(%b{})", function(btag, bbody) 708 body = string.gsub(body, "(\\abjad%s?)(%b{})", function(btag, bbody)
709 bbody = string.sub(bbody, 2, -2) 709 bbody = string.sub(bbody, 2, -2)
710 if tonumber(bbody) ~= nil then 710 if tonumber(bbody) ~= nil then
711 bbody = abjadify(bbody) 711 bbody = arabluatex.abjadify(bbody)
712 return string.format("\\oline*{\\arb[novoc]{%s}}", bbody) 712 return string.format("\\oline*{\\arb[novoc]{%s}}", bbody)
713 else 713 else
714 return string.format("%s{%s}", btag, bbody) 714 return string.format("%s{%s}", btag, bbody)
@@ -795,7 +795,7 @@ local function processarbtoutf(str)
795 return str 795 return str
796end 796end
797 797
798function arbtoutf(str) 798function arabluatex.arbtoutf(str)
799 str = processarbtoutf(str) 799 str = processarbtoutf(str)
800 str = "\\ArbOutFile{"..str.."}" 800 str = "\\ArbOutFile{"..str.."}"
801 str = string.gsub(str, "(\\ArbOutFile)%s?(%b{})", function(tag, body) 801 str = string.gsub(str, "(\\ArbOutFile)%s?(%b{})", function(tag, body)
@@ -816,7 +816,7 @@ function arbtoutf(str)
816 return str 816 return str
817end 817end
818 818
819function tooutfile(str, nl) 819function arabluatex.tooutfile(str, nl)
820 local f = io.open(tex.jobname..utffilesuffix.."_tmp.tex", "a+") 820 local f = io.open(tex.jobname..utffilesuffix.."_tmp.tex", "a+")
821 if nl == "newline" then 821 if nl == "newline" then
822 f:write(str, "\n\n") 822 f:write(str, "\n\n")
@@ -827,7 +827,7 @@ function tooutfile(str, nl)
827 return str 827 return str
828end 828end
829 829
830function al_closestream() 830function arabluatex.closestream()
831 local f = io.open(tex.jobname..utffilesuffix.."_tmp.tex", "r") 831 local f = io.open(tex.jobname..utffilesuffix.."_tmp.tex", "r")
832 local o = io.open(tex.jobname..utffilesuffix..".tex", "w") 832 local o = io.open(tex.jobname..utffilesuffix..".tex", "w")
833 local t = f:read("*a") 833 local t = f:read("*a")
@@ -885,7 +885,7 @@ function al_closestream()
885end 885end
886 886
887-- Process standard arabluatex modes: 887-- Process standard arabluatex modes:
888function processvoc(str, rules, scheme) 888function arabluatex.processvoc(str, rules, scheme)
889 str = takeoutarb(str) 889 str = takeoutarb(str)
890 str = processarbnull(str, scheme) 890 str = processarbnull(str, scheme)
891 str = takeoutcapetc(str) 891 str = takeoutcapetc(str)
@@ -903,17 +903,17 @@ function processvoc(str, rules, scheme)
903 str = unprotectarb(str) 903 str = unprotectarb(str)
904 if export_utf == "yes" then 904 if export_utf == "yes" then
905 tofile = "\\txarb{"..str.."}" 905 tofile = "\\txarb{"..str.."}"
906 tooutfile(tofile) 906 arabluatex.tooutfile(tofile)
907 elseif export_utf == "arabverse" then 907 elseif export_utf == "arabverse" then
908 tofile = "\\txarb{"..str.."}" 908 tofile = "\\txarb{"..str.."}"
909 tooutfile(tofile) 909 arabluatex.tooutfile(tofile)
910 else 910 else
911 return str 911 return str
912 end 912 end
913 return "" 913 return ""
914end 914end
915 915
916function processfullvoc(str, rules, scheme) 916function arabluatex.processfullvoc(str, rules, scheme)
917 str = takeoutarb(str) 917 str = takeoutarb(str)
918 str = processarbnull(str, scheme) 918 str = processarbnull(str, scheme)
919 str = takeoutcapetc(str) 919 str = takeoutcapetc(str)
@@ -933,17 +933,17 @@ function processfullvoc(str, rules, scheme)
933 str = unprotectarb(str) 933 str = unprotectarb(str)
934 if export_utf == "yes" then 934 if export_utf == "yes" then
935 tofile = "\\txarb{"..str.."}" 935 tofile = "\\txarb{"..str.."}"
936 tooutfile(tofile) 936 arabluatex.tooutfile(tofile)
937 elseif export_utf == "arabverse" then 937 elseif export_utf == "arabverse" then
938 tofile = "\\txarb{"..str.."}" 938 tofile = "\\txarb{"..str.."}"
939 tooutfile(tofile) 939 arabluatex.tooutfile(tofile)
940 else 940 else
941 return str 941 return str
942 end 942 end
943 return "" 943 return ""
944end 944end
945 945
946function processnovoc(str, rules, scheme) 946function arabluatex.processnovoc(str, rules, scheme)
947 str = takeoutarb(str) 947 str = takeoutarb(str)
948 str = processarbnull(str, scheme) 948 str = processarbnull(str, scheme)
949 str = takeoutcapetc(str) 949 str = takeoutcapetc(str)
@@ -961,17 +961,17 @@ function processnovoc(str, rules, scheme)
961 str = unprotectarb(str) 961 str = unprotectarb(str)
962 if export_utf == "yes" then 962 if export_utf == "yes" then
963 tofile = "\\txarb{"..str.."}" 963 tofile = "\\txarb{"..str.."}"
964 tooutfile(tofile) 964 arabluatex.tooutfile(tofile)
965 elseif export_utf == "arabverse" then 965 elseif export_utf == "arabverse" then
966 tofile = "\\txarb{"..str.."}" 966 tofile = "\\txarb{"..str.."}"
967 tooutfile(tofile) 967 arabluatex.tooutfile(tofile)
968 else 968 else
969 return str 969 return str
970 end 970 end
971 return "" 971 return ""
972end 972end
973 973
974function processtrans(str, mode, rules, scheme) 974function arabluatex.processtrans(str, mode, rules, scheme)
975 str = takeoutarb(str) 975 str = takeoutarb(str)
976 str = processdiscretionary(str) 976 str = processdiscretionary(str)
977 str = processarbnull(str, scheme) 977 str = processarbnull(str, scheme)
@@ -992,17 +992,17 @@ function processtrans(str, mode, rules, scheme)
992 str = unprotectarb(str) 992 str = unprotectarb(str)
993 if export_utf == "yes" then 993 if export_utf == "yes" then
994 tofile = "\\txtrans{"..str.."}" 994 tofile = "\\txtrans{"..str.."}"
995 tooutfile(tofile) 995 arabluatex.tooutfile(tofile)
996 elseif export_utf == "arabverse" then 996 elseif export_utf == "arabverse" then
997 tofile = "\\txtrans{"..str.."}" 997 tofile = "\\txtrans{"..str.."}"
998 tooutfile(tofile) 998 arabluatex.tooutfile(tofile)
999 else 999 else
1000 return str 1000 return str
1001 end 1001 end
1002 return "" 1002 return ""
1003end 1003end
1004 1004
1005function newarbmark(abbr, rtlmk, ltrmk) 1005function arabluatex.newarbmark(abbr, rtlmk, ltrmk)
1006 abbr = "@"..abbr 1006 abbr = "@"..abbr
1007 rtlmk = "\\arabicfont{}"..rtlmk 1007 rtlmk = "\\arabicfont{}"..rtlmk
1008 table.insert(arbmarks, {a = abbr, b = rtlmk, c = ltrmk}) 1008 table.insert(arbmarks, {a = abbr, b = rtlmk, c = ltrmk})
@@ -1019,7 +1019,7 @@ local function isintable(table, element)
1019 return false 1019 return false
1020end 1020end
1021 1021
1022function processarbmarks(str, dir) 1022function arabluatex.processarbmarks(str, dir)
1023 str = "@"..str 1023 str = "@"..str
1024 if not isintable(arbmarks, str) then 1024 if not isintable(arbmarks, str) then
1025 str = "\\LR{<??>}"..atletter.."\\al@wrong@mark{}"..atother 1025 str = "\\LR{<??>}"..atletter.."\\al@wrong@mark{}"..atother
@@ -1044,17 +1044,17 @@ function processarbmarks(str, dir)
1044 end 1044 end
1045 if export_utf == "yes" then 1045 if export_utf == "yes" then
1046 tofile = str 1046 tofile = str
1047 tooutfile(tofile) 1047 arabluatex.tooutfile(tofile)
1048 elseif export_utf == "arabverse" then 1048 elseif export_utf == "arabverse" then
1049 tofile = str 1049 tofile = str
1050 tooutfile(tofile) 1050 arabluatex.tooutfile(tofile)
1051 else 1051 else
1052 return str 1052 return str
1053 end 1053 end
1054 return "" 1054 return ""
1055end 1055end
1056 1056
1057function uc(str) 1057function arabluatex.uc(str)
1058 str = string.gsub(str, "(\\txtrans.?)(%b{})", function(tag, body) 1058 str = string.gsub(str, "(\\txtrans.?)(%b{})", function(tag, body)
1059 body = string.sub(body, 2, -2) 1059 body = string.sub(body, 2, -2)
1060 return string.format("%s", body) 1060 return string.format("%s", body)
@@ -1115,10 +1115,10 @@ function uc(str)
1115 str = string.gsub(str, "\\@al@cb", "}") 1115 str = string.gsub(str, "\\@al@cb", "}")
1116 if export_utf == "yes" then 1116 if export_utf == "yes" then
1117 tofile = str 1117 tofile = str
1118 tooutfile(tofile) 1118 arabluatex.tooutfile(tofile)
1119 elseif export_utf == "arabverse" then 1119 elseif export_utf == "arabverse" then
1120 tofile = str 1120 tofile = str
1121 tooutfile(tofile) 1121 arabluatex.tooutfile(tofile)
1122 else 1122 else
1123 return str 1123 return str
1124 end 1124 end
@@ -1128,7 +1128,7 @@ end
1128-- this function is adapted from an 'obsolete project' of Khaled 1128-- this function is adapted from an 'obsolete project' of Khaled
1129-- Hosny's that dates back to 2010. Thanks to him. 1129-- Hosny's that dates back to 2010. Thanks to him.
1130-- See https://github.com/khaledhosny/lualatex-arabic 1130-- See https://github.com/khaledhosny/lualatex-arabic
1131function abjadify(n) 1131function arabluatex.abjadify(n)
1132 local abjadnum = "" 1132 local abjadnum = ""
1133 n = tonumber(n) 1133 n = tonumber(n)
1134 if n >= 1000 then 1134 if n >= 1000 then
@@ -1151,7 +1151,7 @@ function abjadify(n)
1151 return "\\arb[novoc]{"..abjadnum.."}" 1151 return "\\arb[novoc]{"..abjadnum.."}"
1152end 1152end
1153 1153
1154function abraces(str) 1154function arabluatex.abraces(str)
1155 if tex.textdir == "TRT" then 1155 if tex.textdir == "TRT" then
1156 str = "\\}"..str.."\\{" 1156 str = "\\}"..str.."\\{"
1157 elseif tex.textdir == "TLT" then 1157 elseif tex.textdir == "TLT" then
@@ -1160,7 +1160,7 @@ function abraces(str)
1160 return str 1160 return str
1161end 1161end
1162 1162
1163function aemph(str, opt) 1163function arabluatex.aemph(str, opt)
1164 if tex.textdir == "TRT" then 1164 if tex.textdir == "TRT" then
1165 str = "\\oline{\\textdir TRT{}"..str.."}" 1165 str = "\\oline{\\textdir TRT{}"..str.."}"
1166 elseif tex.textdir == "TLT" then 1166 elseif tex.textdir == "TLT" then
@@ -1173,7 +1173,7 @@ function aemph(str, opt)
1173 return str 1173 return str
1174end 1174end
1175 1175
1176function ayah(str) 1176function arabluatex.ayah(str)
1177 if tonumber(str) ~= nil and str.len(str) < 4 then 1177 if tonumber(str) ~= nil and str.len(str) < 4 then
1178 if tex.textdir == "TRT" then 1178 if tex.textdir == "TRT" then
1179 str = indnum(str).."^^^^06dd" 1179 str = indnum(str).."^^^^06dd"