diff options
Diffstat (limited to 'arabluatex.lua')
-rw-r--r-- | arabluatex.lua | 62 |
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 | } |
98 | local brkcmds = {} | 98 | local brkcmds = {} |
99 | 99 | ||
100 | function mkarbbreak(str, opt) | 100 | function 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 | |||
661 | local utffilesuffix = "_out" | 661 | local utffilesuffix = "_out" |
662 | local export_utf = "no" | 662 | local export_utf = "no" |
663 | 663 | ||
664 | function al_utffilesuffix(str) | 664 | function arabluatex.utffilesuffix(str) |
665 | utffilesuffix = str | 665 | utffilesuffix = str |
666 | return true | 666 | return true |
667 | end | 667 | end |
668 | 668 | ||
669 | function al_doexport(str) | 669 | function arabluatex.doexport(str) |
670 | export_utf = str | 670 | export_utf = str |
671 | return true | 671 | return true |
672 | end | 672 | end |
673 | 673 | ||
674 | function al_openstream() | 674 | function 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 |
796 | end | 796 | end |
797 | 797 | ||
798 | function arbtoutf(str) | 798 | function 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 |
817 | end | 817 | end |
818 | 818 | ||
819 | function tooutfile(str, nl) | 819 | function 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 |
828 | end | 828 | end |
829 | 829 | ||
830 | function al_closestream() | 830 | function 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() | |||
885 | end | 885 | end |
886 | 886 | ||
887 | -- Process standard arabluatex modes: | 887 | -- Process standard arabluatex modes: |
888 | function processvoc(str, rules, scheme) | 888 | function 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 "" |
914 | end | 914 | end |
915 | 915 | ||
916 | function processfullvoc(str, rules, scheme) | 916 | function 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 "" |
944 | end | 944 | end |
945 | 945 | ||
946 | function processnovoc(str, rules, scheme) | 946 | function 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 "" |
972 | end | 972 | end |
973 | 973 | ||
974 | function processtrans(str, mode, rules, scheme) | 974 | function 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 "" |
1003 | end | 1003 | end |
1004 | 1004 | ||
1005 | function newarbmark(abbr, rtlmk, ltrmk) | 1005 | function 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 |
1020 | end | 1020 | end |
1021 | 1021 | ||
1022 | function processarbmarks(str, dir) | 1022 | function 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 "" |
1055 | end | 1055 | end |
1056 | 1056 | ||
1057 | function uc(str) | 1057 | function 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 |
1131 | function abjadify(n) | 1131 | function 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.."}" |
1152 | end | 1152 | end |
1153 | 1153 | ||
1154 | function abraces(str) | 1154 | function 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 |
1161 | end | 1161 | end |
1162 | 1162 | ||
1163 | function aemph(str, opt) | 1163 | function 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 |
1174 | end | 1174 | end |
1175 | 1175 | ||
1176 | function ayah(str) | 1176 | function 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" |