aboutsummaryrefslogtreecommitdiff
path: root/arabluatex.lua
diff options
context:
space:
mode:
Diffstat (limited to 'arabluatex.lua')
-rw-r--r--arabluatex.lua84
1 files changed, 53 insertions, 31 deletions
diff --git a/arabluatex.lua b/arabluatex.lua
index f639770..114a569 100644
--- a/arabluatex.lua
+++ b/arabluatex.lua
@@ -2,24 +2,23 @@
2This file is part of the `arabluatex' package 2This file is part of the `arabluatex' package
3 3
4ArabLuaTeX -- Processing ArabTeX notation under LuaLaTeX 4ArabLuaTeX -- Processing ArabTeX notation under LuaLaTeX
5Copyright (C) 2016--2022 Robert Alessi 5Copyright (C) 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023
6Robert Alessi <alessi@robertalessi.net>
6 7
7Please send error reports and suggestions for improvements to Robert 8Permission to use, copy, modify, and distribute this software for any
8Alessi <alessi@robertalessi.net> 9purpose with or without fee is hereby granted, provided that the above
9 10copyright notice and this permission notice appear in all copies.
10This program is free software: you can redistribute it and/or modify
11it under the terms of the GNU General Public License as published by
12the Free Software Foundation, either version 3 of the License, or
13(at your option) any later version.
14 11
15This program is distributed in the hope that it will be useful, but 12THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
16WITHOUT ANY WARRANTY; without even the implied warranty of 13WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
18General Public License for more details. 15ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 19
20You should have received a copy of the GNU General Public License 20Please send error reports and suggestions for improvements to Robert
21along with this program. If not, see 21Alessi <alessi@robertalessi.net>
22<http://www.gnu.org/licenses/>.
23--]] 22--]]
24 23
25arabluatex = {} 24arabluatex = {}
@@ -54,11 +53,26 @@ local cmd = lpeg.Cs(dblbkslash * ascii^1 * cmdstar^-1)
54local rawcmd = lpeg.Cs(dblbkslash * ascii^1) 53local rawcmd = lpeg.Cs(dblbkslash * ascii^1)
55local aftercmd = lpeg.Cs(lpeg.S("*[{,.?;:'`\"") + dblbkslash) 54local aftercmd = lpeg.Cs(lpeg.S("*[{,.?;:'`\"") + dblbkslash)
56local cmdargs = lpeg.Cs(spce^-1 * bsqbracketsii * bcbracesii * bsqbrackets^-1) 55local cmdargs = lpeg.Cs(spce^-1 * bsqbracketsii * bcbracesii * bsqbrackets^-1)
56local cmdargsnobs = lpeg.Cs(spce^-1 * bcbracesii)
57local arbargs = lpeg.Cs(spce^-1 * bsqbrackets^-1 * bcbraces) 57local arbargs = lpeg.Cs(spce^-1 * bsqbrackets^-1 * bcbraces)
58local baytargs = lpeg.Cs(spce * bcbraces * bsqbrackets^-1 * bcbraces) 58local baytargs = lpeg.Cs(spce * bcbraces * bsqbrackets^-1 * bcbraces)
59local arind = lpeg.Cs(dblbkslash * lpeg.P("arind") * spce^-1 * bsqbracketsii) 59local arind = lpeg.Cs(dblbkslash * lpeg.P("arind") * spce^-1 * bsqbracketsii)
60 60
61local function protectarb(str) 61local function protectarb(str)
62 -- \App[]{}{}
63 str = string.gsub(str, "(\\App%s?)(%b{})(%b{})", "%1[]%2%3")
64 str = gsub(str, lpeg.P("\\App") * spcenc^-1 * bsqbrackets * bcbraces * bcbraces,
65 function(opt, lem, rdg)
66 opt = string.sub(opt, 2, -2)
67 lem = string.sub(lem, 2, -2)
68 rdg = string.sub(rdg, 2, -2)
69 if opt == ""
70 then
71 return string.format("\\app{%s%s}", lem, rdg)
72 else
73 return string.format("\\app[%s]{%s%s}", opt, lem, rdg)
74 end
75 end)
62 str = string.gsub(str, "(\\arb%s?)(%[.-%])(%b{})", "\\al@brk{\\arb%2%3}") 76 str = string.gsub(str, "(\\arb%s?)(%[.-%])(%b{})", "\\al@brk{\\arb%2%3}")
63 str = string.gsub(str, "(\\LR%s?)(%b{})", "\\@LR%2") 77 str = string.gsub(str, "(\\LR%s?)(%b{})", "\\@LR%2")
64 str = string.gsub(str, "(\\RL%s?)(%b{})", "\\@RL%2") 78 str = string.gsub(str, "(\\RL%s?)(%b{})", "\\@RL%2")
@@ -90,7 +104,6 @@ local outofarb = {
90local albrkcmds = { 104local albrkcmds = {
91 "begin", 105 "begin",
92 "end", 106 "end",
93 "par",
94 "LRmarginpar", 107 "LRmarginpar",
95 "arbmark", 108 "arbmark",
96 "abjad", 109 "abjad",
@@ -121,13 +134,15 @@ function arabluatex.mkarbbreak(str, opt)
121end 134end
122 135
123local function breakcmd(str) 136local function breakcmd(str)
137 -- \par
138 str = gsub(str, dblbkslash * lpeg.Cs("par") * cmdargsnobs, "\\al@brk{%1%2%3}")
124 -- process \item[], then \item[] 139 -- process \item[], then \item[]
125 str = string.gsub(str, "\\(item.?)(%b[])", 140 str = string.gsub(str, "\\(item.?)(%b[])",
126 function(tag, body) 141 function(tag, body)
127 body = string.sub(body, 2, -2) 142 body = string.sub(body, 2, -2)
128 return string.format("\\al@brk{\\item[\\arb{%s}] }", body) 143 return string.format("\\al@brk{\\item[\\arb{%s}] }", body)
129 end) 144 end)
130 str = string.gsub(str, "(\\item)(%s+)", "%1{}%2") 145 str = string.gsub(str, "(\\item)(%s+)", "%1{}%2")
131 -- \textcolor 146 -- \textcolor
132 str = string.gsub(str, "\\(textcolor%s?)(%b{})(%b{})", 147 str = string.gsub(str, "\\(textcolor%s?)(%b{})(%b{})",
133 function(tag, bodycolor, bodytext) 148 function(tag, bodycolor, bodytext)
@@ -189,10 +204,15 @@ local function arbnum(str) -- not used, see below
189 return str 204 return str
190end 205end
191 206
192local function indnum(str) 207local function indnum(str, dir)
193 str = string.gsub(str, "([0-9%,%-%/]+)", function(num) 208 if dir == "ltr"
194 return string.reverse(num) 209 then
195 end) 210 -- do nothing
211 else
212 str = string.gsub(str, "([0-9%,%-%/]+)", function(num)
213 return string.reverse(num)
214 end)
215 end
196 if indorarbnum == "Indian" 216 if indorarbnum == "Indian"
197 then 217 then
198 for i = 1,#numbers do 218 for i = 1,#numbers do
@@ -820,16 +840,16 @@ local function processarbtoutf(str)
820 end) 840 end)
821 return string.format("%s{%s}", tag, body) 841 return string.format("%s{%s}", tag, body)
822 end) 842 end)
823 str = string.gsub(str, "(\\bayt)%s?(%b{})(%b[])(%b{})", function(tag, argi, argii, argiii) 843 str = string.gsub(str, "(\\bayt)%s?(%+?)(%b{})(%b[])(%b{})", function(tag, plus, argi, argii, argiii)
824 argi = string.sub(argi, 2, -2) 844 argi = string.sub(argi, 2, -2)
825 argii = string.sub(argii, 2, -2) 845 argii = string.sub(argii, 2, -2)
826 argiii = string.sub(argiii, 2, -2) 846 argiii = string.sub(argiii, 2, -2)
827 return string.format("%s*{\\arb{%s}}[\\arb{%s}]{\\arb{%s}}", tag, argi, argii, argiii) 847 return string.format("%s%s*{\\arb{%s}}[\\arb{%s}]{\\arb{%s}}", tag, argi, argii, argiii)
828 end) 848 end)
829 str = string.gsub(str, "(\\bayt)%s?(%b{})(%b{})", function(tag, argi, argii) 849 str = string.gsub(str, "(\\bayt)%s?(%+?)(%b{})(%b{})", function(tag, plus, argi, argii)
830 argi = string.sub(argi, 2, -2) 850 argi = string.sub(argi, 2, -2)
831 argii = string.sub(argii, 2, -2) 851 argii = string.sub(argii, 2, -2)
832 return string.format("%s*{\\arb{%s}}{\\arb{%s}}", tag, argi, argii) 852 return string.format("%s%s*{\\arb{%s}}{\\arb{%s}}", tag, plus, argi, argii)
833 end) 853 end)
834 str = string.gsub(str, "(\\prname)%s?(%b{})", function(tag, body) 854 str = string.gsub(str, "(\\prname)%s?(%b{})", function(tag, body)
835 body = string.sub(body, 2, -2) 855 body = string.sub(body, 2, -2)
@@ -1287,7 +1307,9 @@ end
1287function arabluatex.ayah(str) 1307function arabluatex.ayah(str)
1288 if tonumber(str) ~= nil and str.len(str) < 4 then 1308 if tonumber(str) ~= nil and str.len(str) < 4 then
1289 if tex.textdir == "TRT" then 1309 if tex.textdir == "TRT" then
1290 str = indnum(str).."^^^^06dd" 1310 -- end of ayah is typeset LTR and the number comes after the
1311 -- sign (see https://github.com/aliftype/amiri/issues/263#issuecomment-1872979252)
1312 str = "{\\textdir TLT ".."^^^^06dd"..indnum(str, "ltr").."}"
1291 elseif tex.textdir == "TLT" then 1313 elseif tex.textdir == "TLT" then
1292 str = "\\arb[trans]{("..str..")}" 1314 str = "\\arb[trans]{("..str..")}"
1293 end 1315 end