summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/lualatex/arabluatex/arabluatex.sty
blob: 67485aaf4c3e79f6699763ecd57052d87572072c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
%%
%% This is file `arabluatex.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% arabluatex.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% This file is part of the `arabluatex' package
%% 
%% ArabLuaTeX -- Processing ArabTeX notation under LuaLaTeX
%% Copyright (C) 2016--2018  Robert Alessi
%% 
%% Please send error reports and suggestions for improvements to Robert
%% Alessi <alessi@robertalessi.net>
%% 
%% This program is free software: you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
%% the Free Software Foundation, either version 3 of the License, or
%% (at your option) any later version.
%% 
%% This program is distributed in the hope that it will be useful, but
%% WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
%% General Public License for more details.
%% 
%% You should have received a copy of the GNU General Public License
%% along with this program.  If not, see
%% <http://www.gnu.org/licenses/>.
%% 
%% This release of 'arabluatex' consists of the following source files:
%% - arabluatex.ins
%% - arabluatex.dtx
%% - arabluatex.lua
%% - arabluatex_voc.lua
%% - arabluatex_fullvoc.lua
%% - arabluatex_novoc.lua
%% - arabluatex_trans.lua
%% 
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{arabluatex}%
[2018/06/24 v1.12 An ArabTeX-like interface for LuaLaTeX]
\RequirePackage{ifluatex}
\ifluatex\else
 \PackageError{arabluatex}{lualatex needed}{%
  Package `arabluatex' needs LuaTeX.\MessageBreak
  So you should use `lualatex' to process your document.\MessageBreak
  See documentation of `arabluatex' for further information.}%
  \expandafter\expandafter\expandafter\csname endinput\endcsname
\fi
\RequirePackage{xkeyval}
\DeclareOptionX{voc}{\def\al@mode{voc}}
\DeclareOptionX{fullvoc}{\def\al@mode{fullvoc}}
\DeclareOptionX{novoc}{\def\al@mode{novoc}}
\DeclareOptionX{trans}{\def\al@mode{trans}}
\ExecuteOptionsX{voc}
\ProcessOptionsX\relax
\def\al@mode@voc{voc}
\def\al@mode@fullvoc{fullvoc}
\def\al@mode@novoc{novoc}
\def\al@mode@trans{trans}
\RequirePackage{xcolor}
\RequirePackage{luacolor}
\RequirePackage{etoolbox}
\RequirePackage{arabluatex-patch}
\RequirePackage{fontspec}
\RequirePackage{amsmath}
\RequirePackage{luacode}
\RequirePackage{xparse}
\RequirePackage{environ}
\RequirePackage{adjustbox}
\newbool{al@rlmode}
\luadirect{dofile(kpse.find_file("arabluatex.lua"))}
\AtBeginDocument{\ifdefined\arabicfont\relax\else
\PackageWarning{arabluatex}{\string\arabicfont\ is not defined.^^JI
  will try to load Amiri}%
\newfontfamily\arabicfont[Script=Arabic]{Amiri}\fi}%
\AtBeginDocument{\def\setRL{\booltrue{al@rlmode}\pardir TRT\textdir TRT}}
\AtBeginDocument{\def\setLR{\boolfalse{al@rlmode}\pardir TLT\textdir TLT}}
\AtBeginDocument{\ifdef{\LR}%
  {\RenewDocumentCommand{\LR}{m}{\bgroup\textdir TLT\rmfamily#1\egroup}}
  {\NewDocumentCommand{\LR}{m}{\bgroup\textdir TLT\rmfamily#1\egroup}}}
\AtBeginDocument{\ifdef{\RL}%
  {\RenewDocumentCommand{\RL}{m}{\bgroup\textdir TRT\rmfamily#1\egroup}}
  {\NewDocumentCommand{\RL}{m}{\bgroup\textdir TRT#1\rmfamily\egroup}}}
\NewDocumentCommand{\MkArbBreak}{s m}{%
  \IfBooleanTF{#1}
  {\luadirect{mkarbbreak(\luastringN{#2}, "out")}}
  {\luadirect{mkarbbreak(\luastringN{#2}, "dflt")}}
}
\AtBeginDocument{\ifdef{\aemph}%
  {\RenewDocumentCommand{\aemph}{s m}{%
      \IfBooleanTF{#1}{%
        \luadirect{tex.sprint(aemph(\luastringN{#2}, "over"))}}
      {\luadirect{tex.sprint(aemph(\luastringN{#2}, "dflt"))}}}}
  {\NewDocumentCommand{\aemph}{s m}{%
      \IfBooleanTF{#1}{%
        \luadirect{tex.sprint(aemph(\luastringN{#2}, "over"))}}
      {\luadirect{tex.sprint(aemph(\luastringN{#2}, "dflt"))}}}}}
\NewDocumentCommand{\arbcolor}{o m}{%
  \IfNoValueTF{#1}{#2}{\textcolor{#1}{#2}}}
\def\al@input@scheme{arabtex}
\NewDocumentCommand{\SetInputScheme}{m}{\def\al@input@scheme{#1}}
\def\al@arb@rules{dflt}
\NewDocumentCommand{\SetArbEasy}{s}{%
  \IfBooleanTF{#1}
  {\def\al@arb@rules{easynosukun}}
  {\def\al@arb@rules{easy}}}
\NewDocumentCommand{\SetArbDflt}{s}{%
  \IfBooleanTF{#1}
  {\def\al@arb@rules{idgham}}
  {\def\al@arb@rules{dflt}}}
\def\al@trans@font{\rmfamily}%
\NewDocumentCommand{\SetTranslitFont}{m}{\def\al@trans@font{#1}}
\def\al@trans@style{\itshape}%
\NewDocumentCommand{\SetTranslitStyle}{m}{\def\al@trans@style{#1}}
\def\al@trans@convention{dmg}
\NewDocumentCommand{\SetTranslitConvention}{m}{\def\al@trans@convention{#1}}
\NewDocumentCommand{\al@arbup@dflt}{m}{\textsuperscript{\thinspace#1}}%
\NewDocumentCommand{\al@arbup}{m}{\al@arbup@dflt{#1}}
\NewDocumentCommand{\arbup}{m}{\al@arbup{#1}}
\NewDocumentCommand{\ArbUpDflt}{}{\let\al@arbup=\al@arbup@dflt}
\NewDocumentCommand{\NoArbUp}{}{\RenewDocumentCommand{\al@arbup}{m}{##1}}
\NewDocumentCommand{\SetArbUp}{m}{\RenewDocumentCommand{\al@arbup}{m}{#1}}
\NewDocumentCommand{\uc}{m}%
  {\luadirect{tex.sprint(uc(\luastringN{#1}))}}
\let\Uc\uc
\NewDocumentCommand{\prname}{m}{%
  \bgroup\SetTranslitStyle{\relax}\arb[trans]{\uc{#1}}\egroup}
\NewDocumentCommand{\txarb}{+m}{\bgroup\textdir
  TRT\arabicfont#1\egroup}
\NewDocumentCommand{\txtrans}{+m}{\bgroup\textdir
  TLT\al@trans@font\al@trans@style#1\egroup}
\NewDocumentEnvironment{txarab}{}{%
  \par%
  \booltrue{al@rlmode}%
  \pardir TRT\textdir TRT\arabicfont}{\par}
\NewDocumentCommand{\arb}{O{\al@mode} +m}%
{\edef\@tempa{#1}%
  \ifx\@tempa\al@mode@voc%
  \booltrue{al@rlmode}%
  \bgroup\textdir TRT\arabicfont%
  \luadirect{tex.sprint(processvoc(\luastringN{#2},
    \luastringO{\al@arb@rules}, \luastringO{\al@input@scheme}))}\egroup%
  \boolfalse{al@rlmode}%
  \else%
  \ifx\@tempa\al@mode@fullvoc%
  \booltrue{al@rlmode}%
  \bgroup\textdir TRT\arabicfont%
  \luadirect{tex.sprint(processfullvoc(\luastringN{#2},
    \luastringO{\al@arb@rules}, \luastringO{\al@input@scheme}))}\egroup%
  \boolfalse{al@rlmode}%
  \else%
  \ifx\@tempa\al@mode@novoc%
  \booltrue{al@rlmode}%
  \bgroup\textdir TRT\arabicfont%
  \luadirect{tex.sprint(processnovoc(\luastringN{#2},
    \luastringO{\al@arb@rules}, \luastringO{\al@input@scheme}))}\egroup%
  \boolfalse{al@rlmode}%
  \else%
  \ifx\@tempa\al@mode@trans%
  \bgroup\textdir TLT\al@trans@style%
  \luadirect{tex.sprint(processtrans(\luastringN{#2},
    \luastringO{\al@trans@convention},
    \luastringO{\al@arb@rules},
    \luastringO{\al@input@scheme}))}\egroup%
  \else%
  \fi\fi\fi\fi}
\NewDocumentCommand{\arbmark}{m}{%
  \bgroup%
  \SetInputScheme{arabtex}%
  \luadirect{tex.sprint(processarbmarks(\luastringN{#1}))}%
  \egroup}
\NewDocumentCommand{\newarbmark}{m m m}{%
  \luadirect{newarbmark(\luastringN{#1}, \luastringN{#2}, \luastringN{#3})}}
\NewEnviron{arab}[1][\al@mode]%
{\par\edef\@tempa{#1}%
  \ifx\@tempa\al@mode@voc%
  \booltrue{al@rlmode}%
  \bgroup\pardir TRT\textdir TRT\arabicfont%
  \luadirect{tex.sprint(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},
    \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},
    \luastringO{\al@arb@rules}, \luastringO{\al@input@scheme}))}\egroup%
  \else%
  \ifx\@tempa\al@mode@trans%
  \bgroup\pardir TLT\textdir TLT\al@trans@style%
  \luadirect{tex.sprint(processtrans(\luastringO{\BODY},
    \luastringO{\al@trans@convention},
    \luastringO{\al@arb@rules},
    \luastringO{\al@input@scheme}))}\egroup%
  \else \fi\fi\fi\fi}[\par]
\newlength{\al@bayt@width}
\newlength{\al@gutter@width}
\setlength{\al@bayt@width}{.3\textwidth}
\setlength{\al@gutter@width}{.15\al@bayt@width}
\define@key[al]{verse}{width}{\setlength{\al@bayt@width}{#1}}
\define@key[al]{verse}{gutter}{\setlength{\al@gutter@width}{#1}}
\define@key[al]{verse}{metre}{\arb{#1}}
\define@boolkey[al]{verse}{utf}[true]{}
\define@boolkey[al]{verse}{delim}[true]{}
\define@choicekey[al]{verse}{mode}{fullvoc, voc, novoc,
  trans}{\def\al@mode{#1}}
\presetkeys[al]{verse}{metre={}, utf=false,
  delim=false}{}
\NewDocumentEnvironment{arabverse}{O{}}%
{\par\centering\noindent\bgroup\setkeys[al]{verse}[metre]{#1}%
  \ifx\al@mode\al@mode@trans%
  \ifal@verse@utf\setRL\else\setLR\fi%
  \else\setRL\fi}%
{\hfill\setkeys[al]{verse}[width,gutter,utf,mode]{#1}\egroup}
\NewDocumentCommand{\arb@utf}{m}{%
  \ifal@verse@utf\txarb{#1}\else\arb{#1}\fi}
\def\al@hemistich@delim{*}
\NewDocumentCommand{\SetHemistichDelim}{m}{\def\al@hemistich@delim{#1}}
\def\al@verse@stroke{\leavevmode\xleaders\hbox{\arb{--}}\hfill\kern0pt}
\NewDocumentCommand{\bayt}{m o m}{%
  \ifdefined\savenotes\savenotes\else\fi%
  \edef\al@tatweel{--}%
  \adjustbox{width=\al@bayt@width, height=\Height}{\arb@utf{#1}}%
  \IfNoValueTF{#2}{%
    \ifal@verse@delim\makebox[\al@gutter@width][c]{\al@hemistich@delim}%
    \else%
    \hspace{\al@gutter@width}%
    \fi
  }{%
    \edef\@tempa{#2}%
    \ifx\@tempa\al@tatweel%
    \ifx\al@mode\al@mode@trans%
    \hspace{\al@gutter@width}%
    \else%
    \makebox[\al@gutter@width][s]{\al@verse@stroke}%
    \fi%
    \else%
    \ifx\al@mode\al@mode@trans%
    \adjustbox{width=\al@gutter@width, height=\Height}{\arb@utf{#2}}%
    \else%
    \makebox[\al@gutter@width][s]{\arb@utf{#2}}%
    \fi\fi}%
  \adjustbox{width=\al@bayt@width, height=\Height}{\arb@utf{#3}}%
  \ifdefined\spewnotes\spewnotes\else\fi%
}
\AtBeginDocument{%
  \ifdefined\abjad%
  \RenewDocumentCommand{\abjad}{m}%
  {\ifbool{al@rlmode}%
    {\aemph{\luadirect{tex.sprint(abjadify(\luastring{#1}))}}}
    {\luadirect{tex.sprint(abjadify(\luastring{#1}))}}}
  \else%
  \NewDocumentCommand{\abjad}{m}%
  {\ifbool{al@rlmode}%
    {\aemph{\luadirect{tex.sprint(abjadify(\luastring{#1}))}}}
    {\luadirect{tex.sprint(abjadify(\luastring{#1}))}}}
  \fi}
\NewDocumentCommand{\arbnull}{m}{\relax}
\NewDocumentCommand{\abraces}{+m}{%
  \luadirect{tex.sprint(abraces(\luastringN{#1}))}}
\DeclareDocumentCommand{\LRmarginpar}{o m}{%
  \IfNoValueTF{#1}
  {\marginpar{\textdir TLT #2}}
  {\marginpar[\textdir TLT #1]{\textdir TLT #2}}}
\DeclareDocumentCommand{\LRfootnote}{m}{\bgroup\pardir
  TLT\textdir TLT\footnote{#1}\egroup}
\DeclareDocumentCommand{\RLfootnote}{m}{\bgroup\pardir
  TRT\textdir TRT\footnote{#1}\egroup}
\NewDocumentCommand{\FixArbFtnmk}{}{%
  \@ifpackageloaded{scrextend}%
  {\AtBeginDocument{\deffootnote{2em}{1.6em}{\LR{\thefootnotemark}.\enskip}}}%
  {\RequirePackage{scrextend}
  \AtBeginDocument{\deffootnote{2em}{1.6em}{\LR{\thefootnotemark}.\enskip}}}}
\newcommand{\al@warning}[1]{\PackageWarning{arabluatex}{#1}}
\newcommand{\al@error}[2]{\PackageError{arabluatex}{#1}{#2}}
\newcommand{\al@wrong@nesting}{\al@error{%
    (RL/LR)\string\footnote\space is not allowed\MessageBreak inside
    \string\RL{} and \string\RL{} commands}{%
    Get rid of the surrounding \string\RL{} or \string\LR{} command.}}
\newcommand{\al@wrong@mark}{\al@warning{%
    Unknown Arabic mark in \string\arbmark{}. Replaced
    with\MessageBreak <??>. Please check your code}}
\endinput
%%
%% End of file `arabluatex.sty'.