Debian Codegraph @

texmf-dist/tex/generic/babel/luababel.def

raw
1 %%
2 %% This is file `luababel.def',
3 %% generated with the docstrip utility.
4 %%
5 %% The original source files were:
6 %%
7 %% babel.dtx (with options: `luatex')
8 %%
9 %%
10 %% Copyright (C) 2012-2026 Javier Bezos and Johannes L. Braams.
11 %% Copyright (C) 1989-2012 Johannes L. Braams and
12 %% any individual authors listed elsewhere in this file.
13 %% All rights reserved.
14 %%
15 %%
16 %% This file is part of the Babel system.
17 %% --------------------------------------
18 %%
19 %% It may be distributed and/or modified under the
20 %% conditions of the LaTeX Project Public License, either version 1.3
21 %% of this license or (at your option) any later version.
22 %% The latest version of this license is in
23 %% http://www.latex-project.org/lppl.txt
24 %% and version 1.3 or later is part of all distributions of LaTeX
25 %% version 2003/12/01 or later.
26 %%
27 %% This work has the LPPL maintenance status "maintained".
28 %%
29 %% The Current Maintainer of this work is Javier Bezos.
30 %%
31 %% The list of derived (unpacked) files belonging to the distribution
32 %% and covered by LPPL is defined by the unpacking scripts (with
33 %% extension |.ins|) which are part of the distribution.
34 %%
35 \directlua{ Babel = Babel or {} } % DL2
36 \ifx\AddBabelHook\@undefined % When plain.def, babel.sty starts
37 \bbl@trace{Read language.dat}
38 \ifx\bbl@readstream\@undefined
39 \csname newread\endcsname\bbl@readstream
40 \fi
41 \begingroup
42 \toks@{}
43 \count@\z@ % 0=start, 1=0th, 2=normal
44 \def\bbl@process@line#1#2 #3 #4 {%
45 \ifx=#1%
46 \bbl@process@synonym{#2}%
47 \else
48 \bbl@process@language{#1#2}{#3}{#4}%
49 \fi
50 \ignorespaces}
51 \def\bbl@manylang{%
52 \ifnum\bbl@last>\@ne
53 \bbl@info{Non-standard hyphenation setup}%
54 \fi
55 \let\bbl@manylang\relax}
56 \def\bbl@process@language#1#2#3{%
57 \ifcase\count@
58 \@ifundefined{zth@#1}{\count@\tw@}{\count@\@ne}%
59 \or
60 \count@\tw@
61 \fi
62 \ifnum\count@=\tw@
63 \expandafter\addlanguage\csname l@#1\endcsname
64 \language\allocationnumber
65 \chardef\bbl@last\allocationnumber
66 \bbl@manylang
67 \let\bbl@elt\relax
68 \xdef\bbl@languages{%
69 \bbl@languages\bbl@elt{#1}{\the\language}{#2}{#3}}%
70 \fi
71 \the\toks@
72 \toks@{}}
73 \def\bbl@process@synonym@aux#1#2{%
74 \global\expandafter\chardef\csname l@#1\endcsname#2\relax
75 \let\bbl@elt\relax
76 \xdef\bbl@languages{%
77 \bbl@languages\bbl@elt{#1}{#2}{}{}}}%
78 \def\bbl@process@synonym#1{%
79 \ifcase\count@
80 \toks@\expandafter{\the\toks@\relax\bbl@process@synonym{#1}}%
81 \or
82 \@ifundefined{zth@#1}{\bbl@process@synonym@aux{#1}{0}}{}%
83 \else
84 \bbl@process@synonym@aux{#1}{\the\bbl@last}%
85 \fi}
86 \ifx\bbl@languages\@undefined % Just a (sensible?) guess
87 \chardef\l@english\z@
88 \chardef\l@USenglish\z@
89 \chardef\bbl@last\z@
90 \global\@namedef{bbl@hyphendata@0}{{hyphen.tex}{}}
91 \gdef\bbl@languages{%
92 \bbl@elt{english}{0}{hyphen.tex}{}%
93 \bbl@elt{USenglish}{0}{}{}}
94 \else
95 \global\let\bbl@languages@format\bbl@languages
96 \def\bbl@elt#1#2#3#4{% Remove all except language 0
97 \ifnum#2>\z@\else
98 \noexpand\bbl@elt{#1}{#2}{#3}{#4}%
99 \fi}%
100 \xdef\bbl@languages{\bbl@languages}%
101 \fi
102 \def\bbl@elt#1#2#3#4{\@namedef{zth@#1}{}} % Define flags
103 \bbl@languages
104 \openin\bbl@readstream=language.dat
105 \ifeof\bbl@readstream
106 \bbl@warning{I couldn't find language.dat. No additional\\%
107 patterns loaded. Reported}%
108 \else
109 \loop
110 \endlinechar\m@ne
111 \read\bbl@readstream to \bbl@line
112 \endlinechar`\^^M
113 \if T\ifeof\bbl@readstream F\fi T\relax
114 \ifx\bbl@line\@empty\else
115 \edef\bbl@line{\bbl@line\space\space\space}%
116 \expandafter\bbl@process@line\bbl@line\relax
117 \fi
118 \repeat
119 \fi
120 \closein\bbl@readstream
121 \endgroup
122 \bbl@trace{Macros for reading patterns files}
123 \def\bbl@get@enc#1:#2:#3\@@@{\def\bbl@hyph@enc{#2}}
124 \ifx\babelcatcodetablenum\@undefined
125 \ifx\newcatcodetable\@undefined
126 \def\babelcatcodetablenum{5211}
127 \def\bbl@pattcodes{\numexpr\babelcatcodetablenum+1\relax}
128 \else
129 \newcatcodetable\babelcatcodetablenum
130 \newcatcodetable\bbl@pattcodes
131 \fi
132 \else
133 \def\bbl@pattcodes{\numexpr\babelcatcodetablenum+1\relax}
134 \fi
135 \def\bbl@luapatterns#1#2{%
136 \bbl@get@enc#1::\@@@
137 \setbox\z@\hbox\bgroup
138 \begingroup
139 \savecatcodetable\babelcatcodetablenum\relax
140 \initcatcodetable\bbl@pattcodes\relax
141 \catcodetable\bbl@pattcodes\relax
142 \catcode`\#=6 \catcode`\$=3 \catcode`\&=4 \catcode`\^=7
143 \catcode`\_=8 \catcode`\{=1 \catcode`\}=2 \catcode`\~=13
144 \catcode`\@=11 \catcode`\^^I=10 \catcode`\^^J=12
145 \catcode`\<=12 \catcode`\>=12 \catcode`\*=12 \catcode`\.=12
146 \catcode`\-=12 \catcode`\/=12 \catcode`\[=12 \catcode`\]=12
147 \catcode`\`=12 \catcode`\'=12 \catcode`\"=12
148 \input #1\relax
149 \catcodetable\babelcatcodetablenum\relax
150 \endgroup
151 \def\bbl@tempa{#2}%
152 \ifx\bbl@tempa\@empty\else
153 \input #2\relax
154 \fi
155 \egroup}%
156 \def\bbl@patterns@lua#1{%
157 \language=\expandafter\ifx\csname l@#1:\f@encoding\endcsname\relax
158 \csname l@#1\endcsname
159 \edef\bbl@tempa{#1}%
160 \else
161 \csname l@#1:\f@encoding\endcsname
162 \edef\bbl@tempa{#1:\f@encoding}%
163 \fi\relax
164 \@namedef{lu@texhyphen@loaded@\the\language}{}% Temp
165 \@ifundefined{bbl@hyphendata@\the\language}%
166 {\def\bbl@elt##1##2##3##4{%
167 \ifnum##2=\csname l@\bbl@tempa\endcsname % #2=spanish, dutch:OT1...
168 \def\bbl@tempb{##3}%
169 \ifx\bbl@tempb\@empty\else % if not a synonymous
170 \def\bbl@tempc{{##3}{##4}}%
171 \fi
172 \bbl@csarg\xdef{hyphendata@##2}{\bbl@tempc}%
173 \fi}%
174 \bbl@languages
175 \@ifundefined{bbl@hyphendata@\the\language}%
176 {\bbl@info{No hyphenation patterns were set for\\%
177 language '\bbl@tempa'. Reported}}%
178 {\expandafter\expandafter\expandafter\bbl@luapatterns
179 \csname bbl@hyphendata@\the\language\endcsname}}{}}
180 \endinput\fi
181 \ifx\DisableBabelHook\@undefined
182 \AddBabelHook{luatex}{everylanguage}{%
183 \def\process@language##1##2##3{%
184 \def\process@line####1####2 ####3 ####4 {}}}
185 \AddBabelHook{luatex}{loadpatterns}{%
186 \input #1\relax
187 \expandafter\gdef\csname bbl@hyphendata@\the\language\endcsname
188 {{#1}{}}}
189 \AddBabelHook{luatex}{loadexceptions}{%
190 \input #1\relax
191 \def\bbl@tempb##1##2{{##1}{#1}}%
192 \expandafter\xdef\csname bbl@hyphendata@\the\language\endcsname
193 {\expandafter\expandafter\expandafter\bbl@tempb
194 \csname bbl@hyphendata@\the\language\endcsname}}
195 \endinput\fi
196 \begingroup
197 \catcode`\%=12
198 \catcode`\'=12
199 \catcode`\"=12
200 \catcode`\:=12
201 \directlua{
202 Babel.locale_props = Babel.locale_props or {}
203 function Babel.lua_error(e, a)
204 tex.print([[\noexpand\csname bbl@error\endcsname{]] ..
205 e .. '}{' .. (a or '') .. '}{}{}')
206 end
207
208 function Babel.bytes(line)
209 return line:gsub("(.)",
210 function (chr) return unicode.utf8.char(string.byte(chr)) end)
211 end
212
213 function Babel.priority_in_callback(name,description)
214 for i,v in ipairs(luatexbase.callback_descriptions(name)) do
215 if v == description then return i end
216 end
217 return false
218 end
219
220 function Babel.begin_process_input()
221 if luatexbase and luatexbase.add_to_callback then
222 luatexbase.add_to_callback('process_input_buffer',
223 Babel.bytes,'Babel.bytes')
224 else
225 Babel.callback = callback.find('process_input_buffer')
226 callback.register('process_input_buffer',Babel.bytes)
227 end
228 end
229 function Babel.end_process_input ()
230 if luatexbase and luatexbase.remove_from_callback then
231 luatexbase.remove_from_callback('process_input_buffer','Babel.bytes')
232 else
233 callback.register('process_input_buffer',Babel.callback)
234 end
235 end
236
237 function Babel.str_to_nodes(fn, matches, base)
238 local n, head, last
239 if fn == nil then return nil end
240 for s in string.utfvalues(fn(matches)) do
241 if base.id == 7 then
242 base = base.replace
243 end
244 n = node.copy(base)
245 n.char = s
246 if not head then
247 head = n
248 else
249 last.next = n
250 end
251 last = n
252 end
253 return head
254 end
255
256 Babel.linebreaking = Babel.linebreaking or {}
257 Babel.linebreaking.before = {}
258 Babel.linebreaking.after = {}
259 Babel.locale = {}
260 function Babel.linebreaking.add_before(func, pos)
261 tex.print([[\noexpand\csname bbl@luahyphenate\endcsname]])
262 if pos == nil then
263 table.insert(Babel.linebreaking.before, func)
264 else
265 table.insert(Babel.linebreaking.before, pos, func)
266 end
267 end
268 function Babel.linebreaking.add_after(func)
269 tex.print([[\noexpand\csname bbl@luahyphenate\endcsname]])
270 table.insert(Babel.linebreaking.after, func)
271 end
272
273 function Babel.addpatterns(pp, lg)
274 local lg = lang.new(lg)
275 local pats = lang.patterns(lg) or ''
276 lang.clear_patterns(lg)
277 for p in pp:gmatch('[^%s]+') do
278 ss = ''
279 for i in string.utfcharacters(p:gsub('%d', '')) do
280 ss = ss .. '%d?' .. i
281 end
282 ss = ss:gsub('^%%d%?%.', '%%.') .. '%d?'
283 ss = ss:gsub('%.%%d%?$', '%%.')
284 pats, n = pats:gsub('%s' .. ss .. '%s', ' ' .. p .. ' ')
285 if n == 0 then
286 tex.sprint(
287 [[\string\csname\space bbl@info\endcsname{New pattern: ]]
288 .. p .. [[}]])
289 pats = pats .. ' ' .. p
290 else
291 tex.sprint(
292 [[\string\csname\space bbl@info\endcsname{Renew pattern: ]]
293 .. p .. [[}]])
294 end
295 end
296 lang.patterns(lg, pats)
297 end
298
299 Babel.characters = Babel.characters or {}
300 Babel.ranges = Babel.ranges or {}
301 function Babel.hlist_has_bidi(head)
302 local has_bidi = false
303 local ranges = Babel.ranges
304 for item in node.traverse(head) do
305 if item.id == node.id'glyph' then
306 local itemchar = item.char
307 local chardata = Babel.characters[itemchar]
308 local dir = chardata and chardata.d or nil
309 if not dir then
310 for nn, et in ipairs(ranges) do
311 if itemchar < et[1] then
312 break
313 elseif itemchar <= et[2] then
314 dir = et[3]
315 break
316 end
317 end
318 end
319 if dir and (dir == 'al' or dir == 'r') then
320 has_bidi = true
321 end
322 end
323 end
324 return has_bidi
325 end
326 function Babel.set_chranges_b (script, chrng)
327 if chrng == '' then return end
328 texio.write('Replacing ' .. script .. ' script ranges')
329 Babel.script_blocks[script] = {}
330 for s, e in string.gmatch(chrng..' ', '(.-)%.%.(.-)%s') do
331 table.insert(
332 Babel.script_blocks[script], {tonumber(s,16), tonumber(e,16)})
333 end
334 end
335
336 function Babel.discard_sublr(str)
337 if str:find( [[\string\indexentry]] ) and
338 str:find( [[\string\babelsublr]] ) then
339 str = str:gsub( [[\string\babelsublr%s*(%b{})]],
340 function(m) return m:sub(2,-2) end )
341 end
342 return str
343 end
344 }
345 \endgroup
346 \ifx\newattribute\@undefined\else % Test for plain
347 \newattribute\bbl@attr@locale % DL4
348 \directlua{ Babel.attr_locale = luatexbase.registernumber'bbl@attr@locale' }
349 \AddBabelHook{luatex}{beforeextras}{%
350 \setattribute\bbl@attr@locale\localeid}
351 \fi
352 \def\BabelStringsDefault{unicode}
353 \let\luabbl@stop\relax
354 \AddBabelHook{luatex}{encodedcommands}{%
355 \def\bbl@tempa{utf8}\def\bbl@tempb{#1}%
356 \ifx\bbl@tempa\bbl@tempb\else
357 \directlua{Babel.begin_process_input()}%
358 \def\luabbl@stop{%
359 \directlua{Babel.end_process_input()}}%
360 \fi}%
361 \AddBabelHook{luatex}{stopcommands}{%
362 \luabbl@stop
363 \let\luabbl@stop\relax}
364 \AddBabelHook{luatex}{patterns}{%
365 \@ifundefined{bbl@hyphendata@\the\language}%
366 {\def\bbl@elt##1##2##3##4{%
367 \ifnum##2=\csname l@#2\endcsname % #2=spanish, dutch:OT1...
368 \def\bbl@tempb{##3}%
369 \ifx\bbl@tempb\@empty\else % if not a synonymous
370 \def\bbl@tempc{{##3}{##4}}%
371 \fi
372 \bbl@csarg\xdef{hyphendata@##2}{\bbl@tempc}%
373 \fi}%
374 \bbl@languages
375 \@ifundefined{bbl@hyphendata@\the\language}%
376 {\bbl@info{No hyphenation patterns were set for\\%
377 language '#2'. Reported}}%
378 {\expandafter\expandafter\expandafter\bbl@luapatterns
379 \csname bbl@hyphendata@\the\language\endcsname}}{}%
380 \@ifundefined{bbl@patterns@}{}{%
381 \begingroup
382 \bbl@xin@{,\number\language,}{,\bbl@pttnlist}%
383 \ifin@\else
384 \ifx\bbl@patterns@\@empty\else
385 \directlua{ Babel.addpatterns(
386 [[\bbl@patterns@]], \number\language) }%
387 \fi
388 \@ifundefined{bbl@patterns@#1}%
389 \@empty
390 {\directlua{ Babel.addpatterns(
391 [[\space\csname bbl@patterns@#1\endcsname]],
392 \number\language) }}%
393 \xdef\bbl@pttnlist{\bbl@pttnlist\number\language,}%
394 \fi
395 \endgroup}%
396 \bbl@exp{%
397 \bbl@ifunset{bbl@prehc@\languagename}{}%
398 {\\\bbl@ifblank{\bbl@cs{prehc@\languagename}}{}%
399 {\prehyphenchar=\bbl@cl{prehc}\relax}}}}
400 \@onlypreamble\babelpatterns
401 \AtEndOfPackage{%
402 \newcommand\babelpatterns[2][\@empty]{%
403 \ifx\bbl@patterns@\relax
404 \let\bbl@patterns@\@empty
405 \fi
406 \ifx\bbl@pttnlist\@empty\else
407 \bbl@warning{%
408 You must not intermingle \string\selectlanguage\space and\\%
409 \string\babelpatterns\space or some patterns will not\\%
410 be taken into account. Reported}%
411 \fi
412 \ifx\@empty#1%
413 \protected@edef\bbl@patterns@{\bbl@patterns@\space#2}%
414 \else
415 \edef\bbl@tempb{\zap@space#1 \@empty}%
416 \bbl@for\bbl@tempa\bbl@tempb{%
417 \bbl@fixname\bbl@tempa
418 \bbl@iflanguage\bbl@tempa{%
419 \bbl@csarg\protected@edef{patterns@\bbl@tempa}{%
420 \@ifundefined{bbl@patterns@\bbl@tempa}%
421 \@empty
422 {\csname bbl@patterns@\bbl@tempa\endcsname\space}%
423 #2}}}%
424 \fi}}
425 \def\bbl@intraspace#1 #2 #3\@@{%
426 \directlua{
427 Babel.intraspaces = Babel.intraspaces or {}
428 Babel.intraspaces['\csname bbl@sbcp@\languagename\endcsname'] = %
429 {b = #1, p = #2, m = #3}
430 Babel.locale_props[\the\localeid].intraspace = %
431 {b = #1, p = #2, m = #3}
432 }}
433 \def\bbl@intrapenalty#1\@@{%
434 \directlua{
435 Babel.intrapenalties = Babel.intrapenalties or {}
436 Babel.intrapenalties['\csname bbl@sbcp@\languagename\endcsname'] = #1
437 Babel.locale_props[\the\localeid].intrapenalty = #1
438 }}
439 \begingroup
440 \catcode`\%=12
441 \catcode`\&=14
442 \catcode`\'=12
443 \catcode`\~=12
444 \gdef\bbl@seaintraspace{&
445 \let\bbl@seaintraspace\relax
446 \directlua{
447 Babel.sea_enabled = true
448 Babel.sea_ranges = Babel.sea_ranges or {}
449 function Babel.set_chranges (script, chrng)
450 local c = 0
451 for s, e in string.gmatch(chrng..' ', '(.-)%.%.(.-)%s') do
452 Babel.sea_ranges[script..c]={tonumber(s,16), tonumber(e,16)}
453 c = c + 1
454 end
455 end
456 function Babel.sea_disc_to_space (head)
457 local sea_ranges = Babel.sea_ranges
458 local last_char = nil
459 local quad = 655360 &% 10 pt = 655360 = 10 * 65536
460 for item in node.traverse(head) do
461 local i = item.id
462 if i == node.id'glyph' then
463 last_char = item
464 elseif i == 7 and item.subtype == 3 and last_char
465 and last_char.char > 0x0C99 then
466 quad = font.getfont(last_char.font).size
467 for lg, rg in pairs(sea_ranges) do
468 if last_char.char > rg[1] and last_char.char < rg[2] then
469 lg = lg:sub(1, 4) &% Remove trailing number of, e.g., Cyrl1
470 local intraspace = Babel.intraspaces[lg]
471 local intrapenalty = Babel.intrapenalties[lg]
472 local n
473 if intrapenalty ~= 0 then
474 n = node.new(14, 0) &% penalty
475 n.penalty = intrapenalty
476 node.insert_before(head, item, n)
477 end
478 n = node.new(12, 13) &% (glue, spaceskip)
479 node.setglue(n, intraspace.b * quad,
480 intraspace.p * quad,
481 intraspace.m * quad)
482 node.insert_before(head, item, n)
483 node.remove(head, item)
484 end
485 end
486 end
487 end
488 end
489 }&
490 \bbl@luahyphenate}
491 \catcode`\%=14
492 \gdef\bbl@cjkintraspace{%
493 \let\bbl@cjkintraspace\relax
494 \directlua{
495 require('babel-data-cjk.lua')
496 Babel.cjk_enabled = true
497 function Babel.cjk_linebreak(head)
498 local GLYPH = node.id'glyph'
499 local last_char = nil
500 local quad = 655360 % 10 pt = 655360 = 10 * 65536
501 local last_class = nil
502 local last_lang = nil
503 for item in node.traverse(head) do
504 if item.id == GLYPH then
505 local lang = item.lang
506 local LOCALE = node.get_attribute(item,
507 Babel.attr_locale)
508 local props = Babel.locale_props[LOCALE] or {}
509 local class = Babel.cjk_class[item.char].c
510 if props.cjk_quotes and props.cjk_quotes[item.char] then
511 class = props.cjk_quotes[item.char]
512 end
513 if class == 'cp' then class = 'cl' % )] as CL
514 elseif class == 'id' then class = 'I'
515 elseif class == 'cj' then class = 'I' % loose
516 end
517 local br = 0
518 if class and last_class and Babel.cjk_breaks[last_class][class] then
519 br = Babel.cjk_breaks[last_class][class]
520 end
521 if br == 1 and props.linebreak == 'c' and
522 lang ~= \the\l@nohyphenation\space and
523 last_lang ~= \the\l@nohyphenation then
524 local intrapenalty = props.intrapenalty
525 if intrapenalty ~= 0 then
526 local n = node.new(14, 0) % penalty
527 n.penalty = intrapenalty
528 node.insert_before(head, item, n)
529 end
530 local intraspace = props.intraspace
531 local n = node.new(12, 13) % (glue, spaceskip)
532 node.setglue(n, intraspace.b * quad,
533 intraspace.p * quad,
534 intraspace.m * quad)
535 node.insert_before(head, item, n)
536 end
537 if font.getfont(item.font) then
538 quad = font.getfont(item.font).size
539 end
540 last_class = class
541 last_lang = lang
542 else % if penalty, glue or anything else
543 last_class = nil
544 end
545 end
546 lang.hyphenate(head)
547 end
548 }%
549 \bbl@luahyphenate}
550 \gdef\bbl@luahyphenate{%
551 \let\bbl@luahyphenate\relax
552 \directlua{
553 luatexbase.add_to_callback('hyphenate',
554 function (head, tail)
555 if Babel.linebreaking.before then
556 for k, func in ipairs(Babel.linebreaking.before) do
557 func(head)
558 end
559 end
560 lang.hyphenate(head)
561 if Babel.cjk_enabled then
562 Babel.cjk_linebreak(head)
563 end
564 if Babel.linebreaking.after then
565 for k, func in ipairs(Babel.linebreaking.after) do
566 func(head)
567 end
568 end
569 if Babel.set_hboxed then
570 Babel.set_hboxed(head)
571 end
572 if Babel.sea_enabled then
573 Babel.sea_disc_to_space(head)
574 end
575 end,
576 'Babel.hyphenate')
577 }}
578 \endgroup
579 \def\bbl@provide@intraspace{%
580 \bbl@ifunset{bbl@intsp@\languagename}{}%
581 {\expandafter\ifx\csname bbl@intsp@\languagename\endcsname\@empty\else
582 \bbl@xin@{/c}{/\bbl@cl{lnbrk}}%
583 \ifin@ % cjk
584 \bbl@cjkintraspace
585 \directlua{
586 Babel.locale_props = Babel.locale_props or {}
587 Babel.locale_props[\the\localeid].linebreak = 'c'
588 }%
589 \bbl@exp{\\\bbl@intraspace\bbl@cl{intsp}\\\@@}%
590 \ifx\bbl@KVP@intrapenalty\@nnil
591 \bbl@intrapenalty0\@@
592 \fi
593 \else % sea
594 \bbl@seaintraspace
595 \bbl@exp{\\\bbl@intraspace\bbl@cl{intsp}\\\@@}%
596 \directlua{
597 Babel.sea_ranges = Babel.sea_ranges or {}
598 Babel.set_chranges('\bbl@cl{sbcp}',
599 '\bbl@cl{chrng}')
600 }%
601 \ifx\bbl@KVP@intrapenalty\@nnil
602 \bbl@intrapenalty0\@@
603 \fi
604 \fi
605 \fi
606 \ifx\bbl@KVP@intrapenalty\@nnil\else
607 \expandafter\bbl@intrapenalty\bbl@KVP@intrapenalty\@@
608 \fi}}
609 \ifnum\bbl@bidimode>100 \ifnum\bbl@bidimode<200
610 \def\bblar@chars{%
611 0628,0629,062A,062B,062C,062D,062E,062F,0630,0631,0632,0633,%
612 0634,0635,0636,0637,0638,0639,063A,063B,063C,063D,063E,063F,%
613 0640,0641,0642,0643,0644,0645,0646,0647,0649}
614 \def\bblar@elongated{%
615 0626,0628,062A,062B,0633,0634,0635,0636,063B,%
616 063C,063D,063E,063F,0641,0642,0643,0644,0646,%
617 0649,064A}
618 \begingroup
619 \catcode`_=11 \catcode`:=11
620 \gdef\bblar@nofswarn{\gdef\msg_warning:nnx##1##2##3{}}
621 \endgroup
622 \gdef\bbl@arabicjust{%
623 \let\bbl@arabicjust\relax
624 \newattribute\bblar@kashida
625 \directlua{ Babel.attr_kashida = luatexbase.registernumber'bblar@kashida' }%
626 \bblar@kashida=\z@
627 \bbl@patchfont{{\bbl@parsejalt}}%
628 \directlua{
629 Babel.arabic.elong_map = Babel.arabic.elong_map or {}
630 Babel.arabic.elong_map[\the\localeid] = {}
631 luatexbase.add_to_callback('post_linebreak_filter',
632 Babel.arabic.justify, 'Babel.arabic.justify')
633 luatexbase.add_to_callback('hpack_filter',
634 Babel.arabic.justify_hbox, 'Babel.arabic.justify_hbox')
635 }}%
636 \def\bblar@fetchjalt#1#2#3#4{%
637 \bbl@exp{\\\bbl@foreach{#1}}{%
638 \bbl@ifunset{bblar@JE@##1}%
639 {\setbox\z@\hbox{\textdir TRT ^^^^200d\char"##1#2}}%
640 {\setbox\z@\hbox{\textdir TRT ^^^^200d\char"\@nameuse{bblar@JE@##1}#2}}%
641 \directlua{%
642 local last = nil
643 for item in node.traverse(tex.box[0].head) do
644 if item.id == node.id'glyph' and item.char > 0x600 and
645 not (item.char == 0x200D) then
646 last = item
647 end
648 end
649 Babel.arabic.#3['##1#4'] = last.char
650 }}}
651 \gdef\bbl@parsejalt{%
652 \ifx\addfontfeature\@undefined\else
653 \bbl@xin@{/e}{/\bbl@cl{lnbrk}}%
654 \ifin@
655 \directlua{%
656 if Babel.arabic.elong_map[\the\localeid][\fontid\font] == nil then
657 Babel.arabic.elong_map[\the\localeid][\fontid\font] = {}
658 tex.print([[\string\csname\space bbl@parsejalti\endcsname]])
659 end
660 }%
661 \fi
662 \fi}
663 \gdef\bbl@parsejalti{%
664 \begingroup
665 \let\bbl@parsejalt\relax % To avoid infinite loop
666 \edef\bbl@tempb{\fontid\font}%
667 \bblar@nofswarn
668 \@nameuse{tracinglostchars}\z@
669 \bblar@fetchjalt\bblar@elongated{}{from}{}%
670 \bblar@fetchjalt\bblar@chars{^^^^064a}{from}{a}% Alef maksura
671 \bblar@fetchjalt\bblar@chars{^^^^0649}{from}{y}% Yeh
672 \addfontfeature{RawFeature=+jalt}%
673 % \@namedef{bblar@JE@0643}{06AA}% todo: catch medial kaf
674 \bblar@fetchjalt\bblar@elongated{}{dest}{}%
675 \bblar@fetchjalt\bblar@chars{^^^^064a}{dest}{a}%
676 \bblar@fetchjalt\bblar@chars{^^^^0649}{dest}{y}%
677 \directlua{%
678 for k, v in pairs(Babel.arabic.from) do
679 if Babel.arabic.dest[k] and
680 not (Babel.arabic.from[k] == Babel.arabic.dest[k]) then
681 Babel.arabic.elong_map[\the\localeid][\bbl@tempb]
682 [Babel.arabic.from[k]] = Babel.arabic.dest[k]
683 end
684 end
685 }%
686 \endgroup}
687 \begingroup
688 \catcode`#=11
689 \catcode`~=11
690 \directlua{
691
692 Babel.arabic = Babel.arabic or {}
693 Babel.arabic.from = {}
694 Babel.arabic.dest = {}
695 Babel.arabic.justify_factor = 0.95
696 Babel.arabic.justify_enabled = true
697 Babel.arabic.kashida_limit = -1
698
699 function Babel.arabic.justify(head)
700 if not Babel.arabic.justify_enabled then return head end
701 for line in node.traverse_id(node.id'hlist', head) do
702 Babel.arabic.justify_hlist(head, line)
703 end
704 % In case the very first item is a line (eg, in \vbox):
705 while head.prev do head = head.prev end
706 return head
707 end
708
709 function Babel.arabic.justify_hbox(head, gc, size, pack)
710 local has_inf = false
711 if Babel.arabic.justify_enabled and pack == 'exactly' then
712 for n in node.traverse_id(12, head) do
713 if n.stretch_order > 0 then has_inf = true end
714 end
715 if not has_inf then
716 Babel.arabic.justify_hlist(head, nil, gc, size, pack)
717 end
718 end
719 return head
720 end
721
722 function Babel.arabic.justify_hlist(head, line, gc, size, pack)
723 local d, new
724 local k_list, k_item, pos_inline
725 local width, width_new, full, k_curr, wt_pos, goal, shift
726 local subst_done = false
727 local elong_map = Babel.arabic.elong_map
728 local cnt
729 local last_line
730 local GLYPH = node.id'glyph'
731 local KASHIDA = Babel.attr_kashida
732 local LOCALE = Babel.attr_locale
733
734 if line == nil then
735 line = {}
736 line.glue_sign = 1
737 line.glue_order = 0
738 line.head = head
739 line.shift = 0
740 line.width = size
741 end
742
743 % Exclude last line.
744 if ((line.next ~= nil or line.glue_sign == 1) and line.glue_order == 0) then
745 elongs = {} % Stores elongated candidates of each line
746 k_list = {} % And all letters with kashida
747 pos_inline = 0 % Not yet used
748
749 for n in node.traverse_id(GLYPH, line.head) do
750 pos_inline = pos_inline + 1 % To find where it is. Not used.
751
752 % Elongated glyphs
753 if elong_map then
754 local locale = node.get_attribute(n, LOCALE)
755 if elong_map[locale] and elong_map[locale][n.font] and
756 elong_map[locale][n.font][n.char] then
757 table.insert(elongs, {node = n, locale = locale} )
758 node.set_attribute(n.prev, KASHIDA, 0)
759 end
760 end
761
762 % Tatwil. First create a list of nodes marked with kashida. The
763 % rest of nodes can be ignored. The list of used weigths is build
764 % when transforms with the key kashida= are declared.
765 if Babel.kashida_wts then
766 local k_wt = node.get_attribute(n, KASHIDA)
767 if k_wt > 0 then % todo. parameter for multi inserts
768 table.insert(k_list, {node = n, weight = k_wt, pos = pos_inline})
769 end
770 end
771
772 end % of node.traverse_id
773
774 if #elongs == 0 and #k_list == 0 then goto next_line end
775 full = line.width
776 shift = line.shift
777 goal = full * Babel.arabic.justify_factor % A bit crude
778 width = node.dimensions(line.head) % The 'natural' width
779
780 % == Elongated ==
781 % Original idea taken from 'chikenize'
782 while (#elongs > 0 and width < goal) do
783 subst_done = true
784 local x = #elongs
785 local curr = elongs[x].node
786 local oldchar = curr.char
787 curr.char = elong_map[elongs[x].locale][curr.font][curr.char]
788 width = node.dimensions(line.head) % Check if the line is too wide
789 % Substitute back if the line would be too wide and break:
790 if width > goal then
791 curr.char = oldchar
792 break
793 end
794 % If continue, pop the just substituted node from the list:
795 table.remove(elongs, x)
796 end
797
798 % == Tatwil ==
799 % Traverse the kashida node list so many times as required, until
800 % the line if filled. The first pass adds a tatweel after each
801 % node with kashida in the line, the second pass adds another one,
802 % and so on. In each pass, add first the kashida with the highest
803 % weight, then with lower weight and so on.
804 if #k_list == 0 then goto next_line end
805
806 width = node.dimensions(line.head) % The 'natural' width
807 k_curr = #k_list % Traverse backwards, from the end
808 wt_pos = 1
809
810 while width < goal do
811 subst_done = true
812 k_item = k_list[k_curr].node
813 if k_list[k_curr].weight == Babel.kashida_wts[wt_pos] then
814 d = node.copy(k_item)
815 d.char = 0x0640
816 d.yoffset = 0 % TODO. From the prev char. But 0 seems safe.
817 d.xoffset = 0
818 line.head, new = node.insert_after(line.head, k_item, d)
819 width_new = node.dimensions(line.head)
820 if width > goal or width == width_new then
821 node.remove(line.head, new) % Better compute before
822 break
823 end
824 if Babel.fix_diacr then
825 Babel.fix_diacr(k_item.next)
826 end
827 width = width_new
828 end
829 if k_curr == 1 then
830 k_curr = #k_list
831 wt_pos = (wt_pos >= table.getn(Babel.kashida_wts)) and 1 or wt_pos+1
832 else
833 k_curr = k_curr - 1
834 end
835 end
836
837 % Limit the number of tatweel by removing them. Not very efficient,
838 % but it does the job in a quite predictable way.
839 if Babel.arabic.kashida_limit > -1 then
840 cnt = 0
841 for n in node.traverse_id(GLYPH, line.head) do
842 if n.char == 0x0640 then
843 cnt = cnt + 1
844 if cnt > Babel.arabic.kashida_limit then
845 node.remove(line.head, n)
846 end
847 else
848 cnt = 0
849 end
850 end
851 end
852
853 ::next_line::
854
855 % Must take into account marks and ins, see luatex manual.
856 % Have to be executed only if there are changes. Investigate
857 % what's going on exactly.
858 if subst_done and not gc then
859 d = node.hpack(line.head, full, 'exactly')
860 d.shift = shift
861 node.insert_before(head, line, d)
862 node.remove(head, line)
863 end
864 end % if process line
865 end
866 }
867 \endgroup
868 \fi\fi % ends Arabic just block: \ifnum\bbl@bidimode>100...
869 \def\bbl@scr@node@list{%
870 ,Armenian,Coptic,Cyrillic,Georgian,,Glagolitic,Gothic,%
871 ,Greek,Latin,Old Church Slavonic Cyrillic,}
872 \ifnum\bbl@bidimode=102 % bidi-r
873 \bbl@add\bbl@scr@node@list{Arabic,Hebrew,Syriac}
874 \fi
875 \def\bbl@set@renderer{%
876 \bbl@xin@{\bbl@cl{sname}}{\bbl@scr@node@list}%
877 \ifin@
878 \let\bbl@unset@renderer\relax
879 \else
880 \bbl@exp{%
881 \def\\\bbl@unset@renderer{%
882 \def\<g__fontspec_default_fontopts_clist>{%
883 \[g__fontspec_default_fontopts_clist]}}%
884 \def\<g__fontspec_default_fontopts_clist>{%
885 Renderer=Harfbuzz,\[g__fontspec_default_fontopts_clist]}}%
886 \fi}
887 \bbl@trace{Font handling with fontspec}
888 \AddBabelHook{babel-fontspec}{afterextras}{\bbl@switchfont}
889 \AddBabelHook{babel-fontspec}{beforestart}{\bbl@ckeckstdfonts}
890 \DisableBabelHook{babel-fontspec}
891 \@onlypreamble\babelfont
892 \ifx\NewDocumentCommand\@undefined\else % Not plain
893 \NewDocumentCommand\babelfont{O{}mO{}mO{}}{%
894 \bbl@bblfont@o[#1]{#2}[#3,#5]{#4}}
895 \fi
896 \newcommand\bbl@bblfont@o[2][]{% 1=langs/scripts 2=fam
897 \ifx\fontspec\@undefined
898 \usepackage{fontspec}%
899 \fi
900 \EnableBabelHook{babel-fontspec}%
901 \edef\bbl@tempa{#1}%
902 \def\bbl@tempb{#2}% Used by \bbl@bblfont
903 \bbl@bblfont}
904 \newcommand\bbl@bblfont[2][]{% 1=features 2=fontname, @font=rm|sf|tt
905 \bbl@ifunset{\bbl@tempb family}%
906 {\bbl@providefam{\bbl@tempb}}%
907 {}%
908 % For the default font, just in case:
909 \bbl@ifunset{bbl@lsys@\languagename}{\bbl@provide@lsys{\languagename}}{}%
910 \expandafter\bbl@ifblank\expandafter{\bbl@tempa}%
911 {\bbl@csarg\edef{\bbl@tempb dflt@}{<>{#1}{#2}}% save bbl@rmdflt@
912 \bbl@exp{%
913 \let\<bbl@\bbl@tempb dflt@\languagename>\<bbl@\bbl@tempb dflt@>%
914 \\\bbl@font@set\<bbl@\bbl@tempb dflt@\languagename>%
915 \<\bbl@tempb default>\<\bbl@tempb family>}}%
916 {\bbl@foreach\bbl@tempa{% i.e., bbl@rmdflt@lang / *scrt
917 \bbl@csarg\def{\bbl@tempb dflt@##1}{<>{#1}{#2}}}}}%
918 \def\bbl@providefam#1{%
919 \bbl@exp{%
920 \\\newcommand\<#1default>{}% Just define it
921 \\\bbl@add@list\\\bbl@font@fams{#1}%
922 \\\NewHook{#1family}%
923 \\\DeclareRobustCommand\<#1family>{%
924 \\\not@math@alphabet\<#1family>\relax
925 % \\\prepare@family@series@update{#1}\<#1default>% TODO. Fails
926 \\\fontfamily\<#1default>%
927 \\\UseHook{#1family}%
928 \\\selectfont}%
929 \\\DeclareTextFontCommand{\<text#1>}{\<#1family>}}}
930 \def\bbl@nostdfont#1{%
931 \bbl@once{nostdfam-\f@family}%
932 {\bbl@infowarn{The current font is not a babel standard family:\\%
933 #1%
934 \fontname\font\\%
935 There is nothing intrinsically wrong, and you can\\%,
936 ignore this message altogether if you do not need\\%
937 this font. If they are used in the document, be aware\\%
938 'babel' will not set Script and Language for it, so\\%
939 you may consider defining a new family with \string\babelfont.\\%
940 See the manual for further details about \string\babelfont.
941 Reported}}%
942 {}}%
943 \gdef\bbl@switchfont{%
944 \bbl@ifunset{bbl@lsys@\languagename}{\bbl@provide@lsys{\languagename}}{}%
945 \bbl@exp{% e.g., Arabic -> arabic
946 \lowercase{\edef\\\bbl@tempa{\bbl@cl{sname}}}}%
947 \bbl@foreach\bbl@font@fams{%
948 \bbl@ifunset{bbl@##1dflt@\languagename}% (1) language?
949 {\bbl@ifunset{bbl@##1dflt@*\bbl@tempa}% (2) from script?
950 {\bbl@ifunset{bbl@##1dflt@}% 2=F - (3) from generic?
951 {}% 123=F - nothing!
952 {\bbl@exp{% 3=T - from generic
953 \global\let\<bbl@##1dflt@\languagename>%
954 \<bbl@##1dflt@>}}}%
955 {\bbl@exp{% 2=T - from script
956 \global\let\<bbl@##1dflt@\languagename>%
957 \<bbl@##1dflt@*\bbl@tempa>}}}%
958 {}}% 1=T - language, already defined
959 \def\bbl@tempa{\bbl@nostdfont{}}%
960 \bbl@foreach\bbl@font@fams{% don't gather with prev for
961 \bbl@ifunset{bbl@##1dflt@\languagename}%
962 {\bbl@cs{famrst@##1}%
963 \global\bbl@csarg\let{famrst@##1}\relax}%
964 {\bbl@exp{% order is relevant.
965 \\\bbl@add\\\originalTeX{%
966 \\\bbl@font@rst{\bbl@cl{##1dflt}}%
967 \<##1default>\<##1family>{##1}}%
968 \\\bbl@font@set\<bbl@##1dflt@\languagename>% the main part!
969 \<##1default>\<##1family>}}}%
970 \bbl@ifrestoring{}{\bbl@tempa}}%
971 \ifx\f@family\@undefined\else % if latex
972 \ifcase\bbl@engine % if pdftex
973 \let\bbl@ckeckstdfonts\relax
974 \else
975 \def\bbl@ckeckstdfonts{%
976 \begingroup
977 \global\let\bbl@ckeckstdfonts\relax
978 \let\bbl@tempa\@empty
979 \bbl@foreach\bbl@font@fams{%
980 \bbl@ifunset{bbl@##1dflt@}%
981 {\@nameuse{##1family}%
982 \bbl@csarg\gdef{WFF@\f@family}{}% Flag
983 \bbl@exp{\\\bbl@add\\\bbl@tempa{* \<##1family>= \f@family\\\\%
984 \space\space\fontname\font\\\\}}%
985 \bbl@csarg\xdef{##1dflt@}{\f@family}%
986 \expandafter\xdef\csname ##1default\endcsname{\f@family}}%
987 {}}%
988 \ifx\bbl@tempa\@empty\else
989 \bbl@infowarn{The following font families will use the default\\%
990 settings for all or some languages:\\%
991 \bbl@tempa
992 There is nothing intrinsically wrong with it, but\\%
993 'babel' will no set Script and Language, which could\\%
994 be relevant in some languages. If your document uses\\%
995 these families, consider redefining them with \string\babelfont.\\%
996 Reported}%
997 \fi
998 \endgroup}
999 \fi
1000 \fi
1001 \def\bbl@font@set#1#2#3{% e.g., \bbl@rmdflt@lang \rmdefault \rmfamily
1002 \bbl@xin@{<>}{#1}%
1003 \ifin@
1004 \bbl@exp{\\\bbl@fontspec@set\\#1\expandafter\@gobbletwo#1\\#3}%
1005 \fi
1006 \bbl@exp{% 'Unprotected' macros return prev values
1007 \def\\#2{#1}% e.g., \rmdefault{\bbl@rmdflt@lang}
1008 \\\bbl@ifsamestring{#2}{\f@family}%
1009 {\\#3%
1010 \\\bbl@ifsamestring{\f@series}{\bfdefault}{\\\bfseries}{}%
1011 \let\\\bbl@tempa\relax}%
1012 {}}}
1013 \def\bbl@fontspec@set#1#2#3#4{% eg \bbl@rmdflt@lang fnt-opt fnt-nme \xxfamily
1014 \let\bbl@tempe\bbl@mapselect
1015 \edef\bbl@tempb{\bbl@stripslash#4/}% Catcodes hack (better pass it).
1016 \bbl@exp{\\\bbl@replace\\\bbl@tempb{\bbl@stripslash\family/}{}}%
1017 \let\bbl@mapselect\relax
1018 \let\bbl@temp@fam#4% e.g., '\rmfamily', to be restored below
1019 \let#4\@empty % Make sure \renewfontfamily is valid
1020 \bbl@set@renderer
1021 \bbl@exp{%
1022 \let\\\bbl@temp@pfam\<\bbl@stripslash#4\space>% e.g., '\rmfamily '
1023 \<keys_if_exist:nnF>{fontspec-opentype}{Script/\bbl@cl{sname}}%
1024 {\\\newfontscript{\bbl@cl{sname}}{\bbl@cl{sotf}}}%
1025 \<keys_if_exist:nnF>{fontspec-opentype}{Language/\bbl@cl{lname}}%
1026 {\\\newfontlanguage{\bbl@cl{lname}}{\bbl@cl{lotf}}}%
1027 \\\renewfontfamily\\#4%
1028 [\bbl@cl{lsys},% xetex removes unknown features :-(
1029 \ifcase\bbl@engine\or RawFeature={family=\bbl@tempb},\fi
1030 #2]}{#3}% i.e., \bbl@exp{..}{#3}
1031 \bbl@unset@renderer
1032 \begingroup
1033 #4%
1034 \xdef#1{\f@family}% e.g., \bbl@rmdflt@lang{FreeSerif(0)}
1035 \endgroup
1036 \bbl@xin@{\string>\string s\string s\string u\string b\string*}%
1037 {\expandafter\meaning\csname TU/#1/bx/sc\endcsname}%
1038 \ifin@
1039 \global\bbl@ccarg\let{TU/#1/bx/sc}{TU/#1/b/sc}%
1040 \fi
1041 \bbl@xin@{\string>\string s\string s\string u\string b\string*}%
1042 {\expandafter\meaning\csname TU/#1/bx/scit\endcsname}%
1043 \ifin@
1044 \global\bbl@ccarg\let{TU/#1/bx/scit}{TU/#1/b/scit}%
1045 \fi
1046 \let#4\bbl@temp@fam
1047 \bbl@exp{\let\<\bbl@stripslash#4\space>}\bbl@temp@pfam
1048 \let\bbl@mapselect\bbl@tempe}%
1049 \def\bbl@font@rst#1#2#3#4{%
1050 \bbl@csarg\def{famrst@#4}{\bbl@font@set{#1}#2#3}}
1051 \def\bbl@font@fams{rm,sf,tt}
1052 \directlua{% DL6
1053 Babel.script_blocks = {
1054 ['dflt'] = {},
1055 ['Arab'] = {{0x0600, 0x06FF}, {0x08A0, 0x08FF}, {0x0750, 0x077F},
1056 {0xFE70, 0xFEFF}, {0xFB50, 0xFDFF}, {0x1EE00, 0x1EEFF}},
1057 ['Armn'] = {{0x0530, 0x058F}},
1058 ['Beng'] = {{0x0980, 0x09FF}},
1059 ['Cher'] = {{0x13A0, 0x13FF}, {0xAB70, 0xABBF}},
1060 ['Copt'] = {{0x03E2, 0x03EF}, {0x2C80, 0x2CFF}, {0x102E0, 0x102FF}},
1061 ['Cyrl'] = {{0x0400, 0x04FF}, {0x0500, 0x052F}, {0x1C80, 0x1C8F},
1062 {0x2DE0, 0x2DFF}, {0xA640, 0xA69F}},
1063 ['Deva'] = {{0x0900, 0x097F}, {0xA8E0, 0xA8FF}},
1064 ['Ethi'] = {{0x1200, 0x137F}, {0x1380, 0x139F}, {0x2D80, 0x2DDF},
1065 {0xAB00, 0xAB2F}},
1066 ['Geor'] = {{0x10A0, 0x10FF}, {0x2D00, 0x2D2F}},
1067 % Don't follow strictly Unicode, which places some Coptic letters in
1068 % the 'Greek and Coptic' block
1069 ['Grek'] = {{0x0370, 0x03E1}, {0x03F0, 0x03FF}, {0x1F00, 0x1FFF}},
1070 ['Hans'] = {{0x2E80, 0x2EFF}, {0x3000, 0x303F}, {0x31C0, 0x31EF},
1071 {0x3300, 0x33FF}, {0x3400, 0x4DBF}, {0x4E00, 0x9FFF},
1072 {0xF900, 0xFAFF}, {0xFE30, 0xFE4F}, {0xFF00, 0xFFEF},
1073 {0x20000, 0x2A6DF}, {0x2A700, 0x2B73F},
1074 {0x2B740, 0x2B81F}, {0x2B820, 0x2CEAF},
1075 {0x2CEB0, 0x2EBEF}, {0x2F800, 0x2FA1F}},
1076 ['Hebr'] = {{0x0590, 0x05FF},
1077 {0xFB1F, 0xFB4E}}, % <- Includes some <reserved>
1078 ['Jpan'] = {{0x3000, 0x303F}, {0x3040, 0x309F}, {0x30A0, 0x30FF},
1079 {0x4E00, 0x9FAF}, {0xFF00, 0xFFEF}},
1080 ['Khmr'] = {{0x1780, 0x17FF}, {0x19E0, 0x19FF}},
1081 ['Knda'] = {{0x0C80, 0x0CFF}},
1082 ['Kore'] = {{0x1100, 0x11FF}, {0x3000, 0x303F}, {0x3130, 0x318F},
1083 {0x4E00, 0x9FAF}, {0xA960, 0xA97F}, {0xAC00, 0xD7AF},
1084 {0xD7B0, 0xD7FF}, {0xFF00, 0xFFEF}},
1085 ['Laoo'] = {{0x0E80, 0x0EFF}},
1086 ['Latn'] = {{0x0000, 0x007F}, {0x0080, 0x00FF}, {0x0100, 0x017F},
1087 {0x0180, 0x024F}, {0x1E00, 0x1EFF}, {0x2C60, 0x2C7F},
1088 {0xA720, 0xA7FF}, {0xAB30, 0xAB6F}},
1089 ['Mahj'] = {{0x11150, 0x1117F}},
1090 ['Mlym'] = {{0x0D00, 0x0D7F}},
1091 ['Mymr'] = {{0x1000, 0x109F}, {0xAA60, 0xAA7F}, {0xA9E0, 0xA9FF}},
1092 ['Orya'] = {{0x0B00, 0x0B7F}},
1093 ['Sinh'] = {{0x0D80, 0x0DFF}, {0x111E0, 0x111FF}},
1094 ['Syrc'] = {{0x0700, 0x074F}, {0x0860, 0x086F}},
1095 ['Taml'] = {{0x0B80, 0x0BFF}},
1096 ['Telu'] = {{0x0C00, 0x0C7F}},
1097 ['Tfng'] = {{0x2D30, 0x2D7F}},
1098 ['Thai'] = {{0x0E00, 0x0E7F}},
1099 ['Tibt'] = {{0x0F00, 0x0FFF}},
1100 ['Vaii'] = {{0xA500, 0xA63F}},
1101 ['Yiii'] = {{0xA000, 0xA48F}, {0xA490, 0xA4CF}}
1102 }
1103
1104 Babel.script_blocks.Cyrs = Babel.script_blocks.Cyrl
1105 Babel.script_blocks.Hant = Babel.script_blocks.Hans
1106 Babel.script_blocks.Kana = Babel.script_blocks.Jpan
1107
1108 function Babel.locale_map(head)
1109 if not Babel.locale_mapped then return head end
1110
1111 local LOCALE = Babel.attr_locale
1112 local GLYPH = node.id('glyph')
1113 local inmath = false
1114 local toloc_save
1115 for item in node.traverse(head) do
1116 local toloc
1117 if not inmath and item.id == GLYPH then
1118 % Optimization: build a table with the chars found
1119 if Babel.chr_to_loc[item.char] then
1120 toloc = Babel.chr_to_loc[item.char]
1121 else
1122 for lc, maps in pairs(Babel.loc_to_scr) do
1123 for _, rg in pairs(maps) do
1124 if item.char >= rg[1] and item.char <= rg[2] then
1125 Babel.chr_to_loc[item.char] = lc
1126 toloc = lc
1127 break
1128 end
1129 end
1130 end
1131 % Treat composite chars in a different fashion, because they
1132 % 'inherit' the previous locale.
1133 if (item.char >= 0x0300 and item.char <= 0x036F) or
1134 (item.char >= 0x1AB0 and item.char <= 0x1AFF) or
1135 (item.char >= 0x1DC0 and item.char <= 0x1DFF) then
1136 Babel.chr_to_loc[item.char] = -2000
1137 toloc = -2000
1138 end
1139 if not toloc then
1140 Babel.chr_to_loc[item.char] = -1000
1141 end
1142 end
1143 if toloc == -2000 then
1144 toloc = toloc_save
1145 elseif toloc == -1000 then
1146 toloc = nil
1147 end
1148 if toloc and Babel.locale_props[toloc] and
1149 Babel.locale_props[toloc].letters and
1150 tex.getcatcode(item.char) \string~= 11 then
1151 toloc = nil
1152 end
1153 if toloc and Babel.locale_props[toloc].script
1154 and Babel.locale_props[node.get_attribute(item, LOCALE)].script
1155 and Babel.locale_props[toloc].script ==
1156 Babel.locale_props[node.get_attribute(item, LOCALE)].script then
1157 toloc = nil
1158 end
1159 if toloc then
1160 if Babel.locale_props[toloc].lg then
1161 item.lang = Babel.locale_props[toloc].lg
1162 node.set_attribute(item, LOCALE, toloc)
1163 end
1164 if Babel.locale_props[toloc]['/'..item.font] then
1165 item.font = Babel.locale_props[toloc]['/'..item.font]
1166 end
1167 end
1168 toloc_save = toloc
1169 elseif not inmath and item.id == 7 then % Apply recursively
1170 item.replace = item.replace and Babel.locale_map(item.replace)
1171 item.pre = item.pre and Babel.locale_map(item.pre)
1172 item.post = item.post and Babel.locale_map(item.post)
1173 elseif item.id == node.id'math' then
1174 inmath = (item.subtype == 0)
1175 end
1176 end
1177 return head
1178 end
1179 }
1180 \newcommand\babelcharproperty[1]{%
1181 \count@=#1\relax
1182 \ifvmode
1183 \expandafter\bbl@chprop
1184 \else
1185 \bbl@error{charproperty-only-vertical}{}{}{}%
1186 \fi}
1187 \newcommand\bbl@chprop[3][\the\count@]{%
1188 \@tempcnta=#1\relax
1189 \bbl@ifunset{bbl@chprop@#2}% {unknown-char-property}
1190 {\bbl@error{unknown-char-property}{}{#2}{}}%
1191 {}%
1192 \loop
1193 \bbl@cs{chprop@#2}{#3}%
1194 \ifnum\count@<\@tempcnta
1195 \advance\count@\@ne
1196 \repeat}
1197 \def\bbl@chprop@direction#1{%
1198 \directlua{
1199 Babel.characters[\the\count@] = Babel.characters[\the\count@] or {}
1200 Babel.characters[\the\count@]['d'] = '#1'
1201 }}
1202 \let\bbl@chprop@bc\bbl@chprop@direction
1203 \def\bbl@chprop@mirror#1{%
1204 \directlua{
1205 Babel.characters[\the\count@] = Babel.characters[\the\count@] or {}
1206 Babel.characters[\the\count@]['m'] = '\number#1'
1207 }}
1208 \let\bbl@chprop@bmg\bbl@chprop@mirror
1209 \def\bbl@chprop@linebreak#1{%
1210 \directlua{
1211 Babel.cjk_characters[\the\count@] = Babel.cjk_characters[\the\count@] or {}
1212 Babel.cjk_characters[\the\count@]['c'] = '#1'
1213 }}
1214 \let\bbl@chprop@lb\bbl@chprop@linebreak
1215 \def\bbl@chprop@locale#1{%
1216 \directlua{
1217 Babel.chr_to_loc = Babel.chr_to_loc or {}
1218 Babel.chr_to_loc[\the\count@] =
1219 \bbl@ifblank{#1}{-1000}{\the\bbl@cs{id@@#1}}\space
1220 }}
1221 \directlua{% DL7
1222 Babel.nohyphenation = \the\l@nohyphenation
1223 }
1224 \begingroup
1225 \catcode`\~=12
1226 \catcode`\%=12
1227 \catcode`\&=14
1228 \catcode`\|=12
1229 \gdef\babelprehyphenation{&%
1230 \@ifnextchar[{\bbl@settransform{0}}{\bbl@settransform{0}[]}}
1231 \gdef\babelposthyphenation{&%
1232 \@ifnextchar[{\bbl@settransform{1}}{\bbl@settransform{1}[]}}
1233 \gdef\bbl@settransform#1[#2]#3#4#5{&%
1234 \ifcase#1
1235 \bbl@activateprehyphen
1236 \or
1237 \bbl@activateposthyphen
1238 \fi
1239 \begingroup
1240 \def\babeltempa{\bbl@add@list\babeltempb}&%
1241 \let\babeltempb\@empty
1242 \def\bbl@tempa{#5}&%
1243 \bbl@replace\bbl@tempa{,}{ ,}&% TODO. Ugly trick to preserve {}
1244 \expandafter\bbl@foreach\expandafter{\bbl@tempa}{&%
1245 \bbl@ifsamestring{##1}{remove}&%
1246 {\bbl@add@list\babeltempb{nil}}&%
1247 {\directlua{
1248 local rep = [=[##1]=]
1249 local three_args = '%s*=%s*([%-%d%.%a{}|]+)%s+([%-%d%.%a{}|]+)%s+([%-%d%.%a{}|]+)'
1250 &% Numeric passes directly: kern, penalty...
1251 rep = rep:gsub('^%s*(remove)%s*$', 'remove = true')
1252 rep = rep:gsub('^%s*(insert)%s*,', 'insert = true, ')
1253 rep = rep:gsub('^%s*(after)%s*,', 'after = true, ')
1254 rep = rep:gsub('(string)%s*=%s*([^%s,]*)', Babel.capture_func)
1255 rep = rep:gsub('node%s*=%s*(%a+)%s*(%a*)', Babel.capture_node)
1256 rep = rep:gsub( '(norule)' .. three_args,
1257 'norule = {' .. '%2, %3, %4' .. '}')
1258 if #1 == 0 or #1 == 2 then
1259 rep = rep:gsub( '(space)' .. three_args,
1260 'space = {' .. '%2, %3, %4' .. '}')
1261 rep = rep:gsub( '(spacefactor)' .. three_args,
1262 'spacefactor = {' .. '%2, %3, %4' .. '}')
1263 rep = rep:gsub('(kashida)%s*=%s*([^%s,]*)', Babel.capture_kashida)
1264 &% Transform values
1265 rep, n = rep:gsub( '{([%a%-%.]+)|([%a%_%.]+)}',
1266 function(v,d)
1267 return string.format (
1268 '{\the\csname bbl@id@@#3\endcsname,"%s",%s}',
1269 v,
1270 load( 'return Babel.locale_props'..
1271 '[\the\csname bbl@id@@#3\endcsname].' .. d)() )
1272 end )
1273 rep, n = rep:gsub( '{([%a%-%.]+)|([%-%d%.]+)}',
1274 '{\the\csname bbl@id@@#3\endcsname,"%1",%2}')
1275 end
1276 if #1 == 1 then
1277 rep = rep:gsub( '(no)%s*=%s*([^%s,]*)', Babel.capture_func)
1278 rep = rep:gsub( '(pre)%s*=%s*([^%s,]*)', Babel.capture_func)
1279 rep = rep:gsub( '(post)%s*=%s*([^%s,]*)', Babel.capture_func)
1280 end
1281 tex.print([[\string\babeltempa{{]] .. rep .. [[}}]])
1282 }}}&%
1283 \bbl@foreach\babeltempb{&%
1284 \bbl@forkv{{##1}}{&%
1285 \in@{,####1,}{,nil,step,data,remove,insert,string,no,pre,no,&%
1286 post,penalty,kashida,space,spacefactor,kern,node,after,norule,}&%
1287 \ifin@\else
1288 \bbl@error{bad-transform-option}{####1}{}{}&%
1289 \fi}}&%
1290 \let\bbl@kv@attribute\relax
1291 \let\bbl@kv@label\relax
1292 \let\bbl@kv@fonts\@empty
1293 \let\bbl@kv@prepend\relax
1294 \bbl@forkv{#2}{\bbl@csarg\edef{kv@##1}{##2}}&%
1295 \ifx\bbl@kv@fonts\@empty\else\bbl@settransfont\fi
1296 \ifx\bbl@kv@attribute\relax
1297 \ifx\bbl@kv@label\relax\else
1298 \bbl@exp{\\\bbl@trim@def\\\bbl@kv@fonts{\bbl@kv@fonts}}&%
1299 \bbl@replace\bbl@kv@fonts{ }{,}&%
1300 \edef\bbl@kv@attribute{bbl@ATR@\bbl@kv@label @#3@\bbl@kv@fonts}&%
1301 \count@\z@
1302 \def\bbl@elt##1##2##3{&%
1303 \bbl@ifsamestring{#3,\bbl@kv@label}{##1,##2}&%
1304 {\bbl@ifsamestring{\bbl@kv@fonts}{##3}&%
1305 {\count@\@ne}&%
1306 {\bbl@error{font-conflict-transforms}{}{}{}}}&%
1307 {}}&%
1308 \bbl@transfont@list
1309 \ifnum\count@=\z@
1310 \bbl@exp{\global\\\bbl@add\\\bbl@transfont@list
1311 {\\\bbl@elt{#3}{\bbl@kv@label}{\bbl@kv@fonts}}}&%
1312 \fi
1313 \bbl@ifunset{\bbl@kv@attribute}&%
1314 {\global\bbl@carg\newattribute{\bbl@kv@attribute}}&%
1315 {}&%
1316 \global\bbl@carg\setattribute{\bbl@kv@attribute}\@ne
1317 \fi
1318 \else
1319 \edef\bbl@kv@attribute{\expandafter\bbl@stripslash\bbl@kv@attribute}&%
1320 \fi
1321 \directlua{
1322 local lbkr = Babel.linebreaking.replacements[#1]
1323 local u = unicode.utf8
1324 local id, attr, label
1325 if #1 == 0 then
1326 id = \the\csname bbl@id@@#3\endcsname\space
1327 else
1328 id = \the\csname l@#3\endcsname\space
1329 end
1330 \ifx\bbl@kv@attribute\relax
1331 attr = -1
1332 \else
1333 attr = luatexbase.registernumber'\bbl@kv@attribute'
1334 \fi
1335 \ifx\bbl@kv@label\relax\else &% Same refs:
1336 label = [==[\bbl@kv@label]==]
1337 \fi
1338 &% Convert pattern:
1339 local patt = string.gsub([==[#4]==], '%s', '')
1340 if #1 == 0 then
1341 patt = string.gsub(patt, '|', ' ')
1342 end
1343 if not u.find(patt, '()', nil, true) then
1344 patt = '()' .. patt .. '()'
1345 end
1346 patt = string.gsub(patt, '%(%)%^', '^()')
1347 patt = string.gsub(patt, '%$%(%)', '()$')
1348 patt = u.gsub(patt, '{(.)}',
1349 function (n)
1350 return '%' .. (tonumber(n) and (tonumber(n)+1) or n)
1351 end)
1352 patt = u.gsub(patt, '{(%x%x%x%x+)}',
1353 function (n)
1354 return u.gsub(u.char(tonumber(n, 16)), '(%p)', '%%%1')
1355 end)
1356 lbkr[id] = lbkr[id] or {}
1357 table.insert(lbkr[id], \ifx\bbl@kv@prepend\relax\else 1,\fi
1358 { label=label, attr=attr, pattern=patt, replace={\babeltempb} })
1359 }&%
1360 \endgroup}
1361 \endgroup
1362 \let\bbl@transfont@list\@empty
1363 \def\bbl@settransfont{%
1364 \global\let\bbl@settransfont\relax % Execute only once
1365 \gdef\bbl@transfont{%
1366 \def\bbl@elt####1####2####3{%
1367 \bbl@ifblank{####3}%
1368 {\count@\tw@}% Do nothing if no fonts
1369 {\count@\z@
1370 \bbl@vforeach{####3}{%
1371 \def\bbl@tempd{########1}%
1372 \edef\bbl@tempe{\bbl@transfam/\f@series/\f@shape}%
1373 \ifx\bbl@tempd\bbl@tempe
1374 \count@\@ne
1375 \else\ifx\bbl@tempd\bbl@transfam
1376 \count@\@ne
1377 \fi\fi}%
1378 \ifcase\count@
1379 \bbl@csarg\unsetattribute{ATR@####2@####1@####3}%
1380 \or
1381 \bbl@csarg\setattribute{ATR@####2@####1@####3}\@ne
1382 \fi}}%
1383 \bbl@transfont@list}%
1384 \AddToHook{selectfont}{\bbl@transfont}% Hooks are global.
1385 \gdef\bbl@transfam{-unknown-}%
1386 \bbl@foreach\bbl@font@fams{%
1387 \AddToHook{##1family}{\def\bbl@transfam{##1}}%
1388 \bbl@ifsamestring{\@nameuse{##1default}}\familydefault
1389 {\xdef\bbl@transfam{##1}}%
1390 {}}}
1391 \DeclareRobustCommand\enablelocaletransform[1]{%
1392 \bbl@ifunset{bbl@ATR@#1@\languagename @}%
1393 {\bbl@error{transform-not-available}{#1}{}{}}%
1394 {\bbl@csarg\setattribute{ATR@#1@\languagename @}\@ne}}
1395 \DeclareRobustCommand\disablelocaletransform[1]{%
1396 \bbl@ifunset{bbl@ATR@#1@\languagename @}%
1397 {\bbl@error{transform-not-available-b}{#1}{}{}}%
1398 {\bbl@csarg\unsetattribute{ATR@#1@\languagename @}}}
1399 \def\bbl@activateposthyphen{%
1400 \let\bbl@activateposthyphen\relax
1401 \ifx\bbl@attr@hboxed\@undefined
1402 \newattribute\bbl@attr@hboxed
1403 \fi
1404 \directlua{
1405 require('babel-transforms.lua')
1406 Babel.linebreaking.add_after(Babel.post_hyphenate_replace)
1407 }}
1408 \def\bbl@activateprehyphen{%
1409 \let\bbl@activateprehyphen\relax
1410 \ifx\bbl@attr@hboxed\@undefined
1411 \newattribute\bbl@attr@hboxed
1412 \fi
1413 \directlua{
1414 require('babel-transforms.lua')
1415 Babel.linebreaking.add_before(Babel.pre_hyphenate_replace)
1416 }}
1417 \newcommand\SetTransformValue[3]{%
1418 \directlua{
1419 Babel.locale_props[\the\csname bbl@id@@#1\endcsname].vars["#2"] = #3
1420 }}
1421 \newcommand\ShowBabelTransforms[1]{%
1422 \bbl@activateprehyphen
1423 \bbl@activateposthyphen
1424 \begingroup
1425 \directlua{ Babel.show_transforms = true }%
1426 \setbox\z@\vbox{#1}%
1427 \directlua{ Babel.show_transforms = false }%
1428 \endgroup}
1429 \newcommand\localeprehyphenation[1]{%
1430 \directlua{ Babel.string_prehyphenation([==[#1]==], \the\localeid) }}
1431 \def\bbl@activate@preotf{%
1432 \let\bbl@activate@preotf\relax % only once
1433 \directlua{
1434 function Babel.pre_otfload_v(head)
1435 if Babel.numbers and Babel.digits_mapped then
1436 head = Babel.numbers(head)
1437 end
1438 if Babel.bidi_enabled then
1439 head = Babel.bidi(head, false, dir)
1440 end
1441 return head
1442 end
1443 %
1444 function Babel.pre_otfload_h(head, gc, sz, pt, dir)
1445 if Babel.numbers and Babel.digits_mapped then
1446 head = Babel.numbers(head)
1447 end
1448 if Babel.bidi_enabled then
1449 head = Babel.bidi(head, false, dir)
1450 end
1451 return head
1452 end
1453 %
1454 luatexbase.add_to_callback('pre_linebreak_filter',
1455 Babel.pre_otfload_v,
1456 'Babel.pre_otfload_v',
1457 Babel.priority_in_callback('pre_linebreak_filter',
1458 'luaotfload.node_processor') or nil)
1459 %
1460 luatexbase.add_to_callback('hpack_filter',
1461 Babel.pre_otfload_h,
1462 'Babel.pre_otfload_h',
1463 Babel.priority_in_callback('hpack_filter',
1464 'luaotfload.node_processor') or nil)
1465 }}
1466 \ifnum\bbl@bidimode>\@ne % Any bidi= except default (=1)
1467 \let\bbl@beforeforeign\leavevmode
1468 \AtEndOfPackage{\EnableBabelHook{babel-bidi}}
1469 \RequirePackage{luatexbase}
1470 \bbl@activate@preotf
1471 \directlua{
1472 require('babel-data-bidi.lua')
1473 \ifcase\expandafter\@gobbletwo\the\bbl@bidimode\or
1474 require('babel-bidi-basic.lua')
1475 \or
1476 require('babel-bidi-basic-r.lua')
1477 table.insert(Babel.ranges, {0xE000, 0xF8FF, 'on'})
1478 table.insert(Babel.ranges, {0xF0000, 0xFFFFD, 'on'})
1479 table.insert(Babel.ranges, {0x100000, 0x10FFFD, 'on'})
1480 \fi}
1481 \newattribute\bbl@attr@dir
1482 \directlua{ Babel.attr_dir = luatexbase.registernumber'bbl@attr@dir' }
1483 \bbl@exp{\output{\bodydir\pagedir\the\output}}
1484 \fi
1485 \chardef\bbl@thetextdir\z@
1486 \chardef\bbl@thepardir\z@
1487 \def\bbl@setluadir#1#2{% 1=\text/pardirection 2= 0:l 1:r 2:al
1488 \ifcase#2\relax
1489 \ifcase#1\else#1=\z@\fi
1490 \else
1491 \ifcase#1#1=\@ne\fi
1492 \fi}
1493 \def\bbl@thedir{0}
1494 \def\bbl@textdir#1{%
1495 \bbl@setluadir\textdirection{#1}%
1496 \chardef\bbl@thetextdir#1\relax
1497 \edef\bbl@thedir{\the\numexpr\bbl@thepardir*4+#1}%
1498 \setattribute\bbl@attr@dir{\numexpr\bbl@thepardir*4+#1}}
1499 \def\bbl@pardir#1{% Used twice
1500 \bbl@setluadir\pardirection{#1}%
1501 \chardef\bbl@thepardir#1\relax}
1502 \def\bbl@bodydir{\bbl@setluadir\bodydirection}% Used once
1503 \def\bbl@dirparastext{\pardirection=\textdirection\relax}% Used once
1504 \ifnum\bbl@bidimode>\z@ % Any bidi=
1505 \def\bbl@insidemath{0}%
1506 \def\bbl@everymath{\def\bbl@insidemath{1}}
1507 \def\bbl@everydisplay{\def\bbl@insidemath{2}}
1508 \frozen@everymath\expandafter{%
1509 \expandafter\bbl@everymath\the\frozen@everymath}
1510 \frozen@everydisplay\expandafter{%
1511 \expandafter\bbl@everydisplay\the\frozen@everydisplay}
1512 \AtBeginDocument{
1513 \directlua{
1514 function Babel.math_box_dir(head)
1515 if not (token.get_macro('bbl@insidemath') == '0') then
1516 if Babel.hlist_has_bidi(head) then
1517 local d = node.new(node.id'dir')
1518 d.dir = '+TRT'
1519 for item in node.traverse(head) do
1520 if item.id == 11 or item.id == node.id'glyph' then
1521 head = node.insert_before(head, item, d)
1522 break
1523 end
1524 end
1525 local inmath = false
1526 for item in node.traverse(head) do
1527 if item.id == 11 then
1528 inmath = (item.subtype == 0)
1529 elseif not inmath then
1530 node.set_attribute(item,
1531 Babel.attr_dir, token.get_macro('bbl@thedir'))
1532 end
1533 end
1534 end
1535 end
1536 return head
1537 end
1538 luatexbase.add_to_callback("hpack_filter", Babel.math_box_dir,
1539 "Babel.math_box_dir", 0)
1540 if Babel.unset_atdir then
1541 luatexbase.add_to_callback("pre_linebreak_filter", Babel.unset_atdir,
1542 "Babel.unset_atdir")
1543 luatexbase.add_to_callback("hpack_filter", Babel.unset_atdir,
1544 "Babel.unset_atdir")
1545 end
1546 luatexbase.add_to_callback("post_mlist_to_hlist_filter", function(head)
1547 local dir = tex.mathdirection
1548 local n = node.new("dir")
1549 n.direction = dir
1550 head = node.insert_before(head,head,n)
1551 n = node.new("dir",1)
1552 n.direction = dir
1553 head = node.insert_after(head,node.tail(head),n)
1554 return head
1555 end,"Babel.ensure_math_dir")
1556 }}%
1557 \fi
1558 \DeclareRobustCommand\localebox[1]{%
1559 {\def\bbl@insidemath{0}%
1560 \mbox{\foreignlanguage{\languagename}{#1}}}}
1561 \bbl@trace{Redefinitions for bidi layout}
1562 \ifnum\bbl@bidimode>\z@ % Any bidi=
1563 \matheqdirmode\@ne % Several luatex primitives.
1564 \mathemptydisplaymode\@ne % For fixes.
1565 \breakafterdirmode\@ne %
1566 \fixupboxesmode\@ne %
1567 \let\bbl@eqnodir\relax
1568 \def\bbl@eqdel{()}
1569 \def\bbl@eqnum{%
1570 {\normalfont\normalcolor
1571 \expandafter\@firstoftwo\bbl@eqdel
1572 \theequation
1573 \expandafter\@secondoftwo\bbl@eqdel}}
1574 \def\bbl@puteqno#1{\eqno\hbox{#1}}
1575 \def\bbl@putleqno#1{\leqno\hbox{#1}}
1576 \def\bbl@eqno@flip#1{% So
1577 \ifdim\predisplaysize=-\maxdimen % For consecutive displays
1578 \eqno
1579 \hb@[email protected]{%
1580 \hb@xt@\displaywidth{\hss{#1\glet\bbl@upset\@currentlabel}}\hss}%
1581 \else
1582 \leqno\hbox{#1\glet\bbl@upset\@currentlabel}%
1583 \fi
1584 \bbl@exp{\def\\\@currentlabel{\[bbl@upset]}}}
1585 \def\bbl@leqno@flip#1{%
1586 \ifdim\predisplaysize=-\maxdimen % For consecutive displays
1587 \leqno
1588 \hb@[email protected]{%
1589 \hss\hb@xt@\displaywidth{{#1\glet\bbl@upset\@currentlabel}\hss}}%
1590 \else
1591 \eqno\hbox{#1\glet\bbl@upset\@currentlabel}%
1592 \fi
1593 \bbl@exp{\def\\\@currentlabel{\[bbl@upset]}}}
1594 \AtBeginDocument{%
1595 \ifx\bbl@noamsmath\relax\else
1596 \ifx\maketag@@@\@undefined % Normal equation, eqnarray
1597 \ifnum\bbl@eqnpos=\tw@
1598 \bbl@replace\equation{\hb@xt@\linewidth}%
1599 {\hbox bdir\mathdirection to\linewidth}%
1600 \bbl@carg\bbl@sreplace{[ }{\hb@xt@\linewidth}%
1601 {\hbox bdir\mathdirection to\linewidth}%
1602 \fi
1603 \AddToHook{env/equation/begin}{%
1604 \ifnum\bbl@thetextdir>\z@
1605 \def\bbl@mathboxdir{\def\bbl@insidemath{1}}%
1606 \let\@eqnnum\bbl@eqnum
1607 \edef\bbl@eqnodir{\noexpand\bbl@textdir{\the\bbl@thetextdir}}%
1608 \chardef\bbl@thetextdir\z@
1609 \bbl@add\normalfont{\bbl@eqnodir}%
1610 \ifcase\bbl@eqnpos
1611 \let\bbl@puteqno\bbl@eqno@flip
1612 \or
1613 \let\bbl@puteqno\bbl@leqno@flip
1614 \fi
1615 \fi}%
1616 \ifnum\bbl@eqnpos=\tw@\else
1617 \def\endequation{\bbl@puteqno{\@eqnnum}$$\@ignoretrue}%
1618 \fi
1619 \AddToHook{env/eqnarray/begin}{%
1620 \ifnum\bbl@thetextdir>\z@
1621 \def\bbl@mathboxdir{\def\bbl@insidemath{1}}%
1622 \edef\bbl@eqnodir{\noexpand\bbl@textdir{\the\bbl@thetextdir}}%
1623 \chardef\bbl@thetextdir\z@
1624 \bbl@add\normalfont{\bbl@eqnodir}%
1625 \ifnum\bbl@eqnpos=\@ne
1626 \def\@eqnnum{%
1627 \setbox\z@\hbox{\bbl@eqnum}%
1628 \hbox to0.01pt{\hss\hbox to\displaywidth{\box\z@\hss}}}%
1629 \else
1630 \let\@eqnnum\bbl@eqnum
1631 \fi
1632 \fi}
1633 \else % amstex
1634 \ifnum\bbl@eqnpos=\tw@
1635 \bbl@exp{% Hack to hide maybe undefined conditionals:
1636 \\\bbl@sreplace\\\multline@\crcr{\<if@fleqn>\tabskip\z@skip\<fi>\crcr}}%
1637 \fi
1638 \bbl@exp{% Hack to hide maybe undefined conditionals:
1639 \chardef\bbl@eqnpos=0%
1640 \<iftagsleft@>1\<else>\<if@fleqn>2\<fi>\<fi>\relax}%
1641 \ifnum\bbl@eqnpos=\@ne
1642 \let\bbl@ams@lap\hbox
1643 \else
1644 \let\bbl@ams@lap\llap
1645 \fi
1646 \ExplSyntaxOn % Required by \bbl@sreplace with \intertext@
1647 \bbl@sreplace\intertext@{\normalbaselines}%
1648 {\normalbaselines
1649 \ifx\bbl@eqnodir\relax\else\bbl@pardir\@ne\bbl@eqnodir\fi}%
1650 \ExplSyntaxOff
1651 \def\bbl@ams@tagbox#1#2{#1{\bbl@eqnodir#2}}% #1=hbox|@lap|flip
1652 \ifx\bbl@ams@lap\hbox % leqno
1653 \def\bbl@ams@flip#1{%
1654 \hbox to 0.01pt{\hss\hbox to\displaywidth{{#1}\hss}}}%
1655 \else % eqno
1656 \def\bbl@ams@flip#1{%
1657 \hbox to 0.01pt{\hbox to\displaywidth{\hss{#1}}\hss}}%
1658 \fi
1659 \def\bbl@ams@preset#1{%
1660 \def\bbl@mathboxdir{\def\bbl@insidemath{1}}%
1661 \ifnum\bbl@thetextdir>\z@
1662 \edef\bbl@eqnodir{\noexpand\bbl@textdir{\the\bbl@thetextdir}}%
1663 \bbl@sreplace\textdef@{\hbox}{\bbl@ams@tagbox\hbox}%
1664 \bbl@sreplace\maketag@@@{\hbox}{\bbl@ams@tagbox#1}%
1665 \fi}%
1666 \def\bbl@ams@equation{%
1667 \def\bbl@mathboxdir{\def\bbl@insidemath{1}}%
1668 \ifnum\bbl@thetextdir>\z@
1669 \edef\bbl@eqnodir{\noexpand\bbl@textdir{\the\bbl@thetextdir}}%
1670 \chardef\bbl@thetextdir\z@
1671 \bbl@add\normalfont{\bbl@eqnodir}%
1672 \ifcase\bbl@eqnpos
1673 \def\veqno##1##2{\bbl@eqno@flip{##1##2}}%
1674 \or
1675 \def\veqno##1##2{\bbl@leqno@flip{##1##2}}%
1676 \fi
1677 \fi}%
1678 \AddToHook{env/equation/begin}{\bbl@ams@equation}%
1679 \AddToHook{env/equation*/begin}{\bbl@ams@equation}%
1680 \AddToHook{env/cases/begin}{\bbl@ams@preset\bbl@ams@lap}%
1681 \AddToHook{env/multline/begin}{\bbl@ams@preset\hbox}%
1682 \AddToHook{env/gather/begin}{\bbl@ams@preset\bbl@ams@lap}%
1683 \AddToHook{env/gather*/begin}{\bbl@ams@preset\bbl@ams@lap}%
1684 \AddToHook{env/align/begin}{\bbl@ams@preset\bbl@ams@lap}%
1685 \AddToHook{env/align*/begin}{\bbl@ams@preset\bbl@ams@lap}%
1686 \AddToHook{env/alignat/begin}{\bbl@ams@preset\bbl@ams@lap}%
1687 \AddToHook{env/alignat*/begin}{\bbl@ams@preset\bbl@ams@lap}%
1688 \AddToHook{env/eqnalign/begin}{\bbl@ams@preset\hbox}%
1689 % Hackish, for proper alignment. Don’t ask me why it works!:
1690 \bbl@exp{% Avoid a 'visible' conditional
1691 \\\AddToHook{env/align*/end}{\<iftag@>\<else>\\\tag*{}\<fi>}%
1692 \\\AddToHook{env/alignat*/end}{\<iftag@>\<else>\\\tag*{}\<fi>}}%
1693 \AddToHook{env/flalign/begin}{\bbl@ams@preset\hbox}%
1694 \AddToHook{env/split/before}{%
1695 \def\bbl@mathboxdir{\def\bbl@insidemath{1}}%
1696 \ifnum\bbl@thetextdir>\z@
1697 \bbl@ifsamestring\@currenvir{equation}%
1698 {\ifx\bbl@ams@lap\hbox % leqno
1699 \def\bbl@ams@flip#1{%
1700 \hbox to 0.01pt{\hbox to\displaywidth{{#1}\hss}\hss}}%
1701 \else
1702 \def\bbl@ams@flip#1{%
1703 \hbox to 0.01pt{\hss\hbox to\displaywidth{\hss{#1}}}}%
1704 \fi}%
1705 {}%
1706 \fi}%
1707 \fi\fi}
1708 \fi
1709 \def\bbl@provide@extra#1{%
1710 % == onchar ==
1711 \ifx\bbl@KVP@onchar\@nnil\else
1712 \bbl@luahyphenate
1713 \bbl@exp{%
1714 \\\AddToHook{env/document/before}{%
1715 {\let\\\bbl@ifrestoring\\\@firstoftwo
1716 \\\select@language{#1}{}}}}%
1717 \directlua{
1718 if Babel.locale_mapped == nil then
1719 Babel.locale_mapped = true
1720 Babel.linebreaking.add_before(Babel.locale_map, 1)
1721 Babel.loc_to_scr = {}
1722 Babel.chr_to_loc = Babel.chr_to_loc or {}
1723 end
1724 Babel.locale_props[\the\localeid].letters = false
1725 }%
1726 \bbl@xin@{ letters }{ \bbl@KVP@onchar\space}%
1727 \ifin@
1728 \directlua{
1729 Babel.locale_props[\the\localeid].letters = true
1730 }%
1731 \fi
1732 \bbl@xin@{ ids }{ \bbl@KVP@onchar\space}%
1733 \ifin@
1734 \ifx\bbl@starthyphens\@undefined % Needed if no explicit selection
1735 \AddBabelHook{babel-onchar}{beforestart}{{\bbl@starthyphens}}%
1736 \fi
1737 \bbl@exp{\\\bbl@add\\\bbl@starthyphens
1738 {\\\bbl@patterns@lua{\languagename}}}%
1739 \directlua{
1740 if Babel.script_blocks['\bbl@cl{sbcp}'] then
1741 Babel.loc_to_scr[\the\localeid] = Babel.script_blocks['\bbl@cl{sbcp}']
1742 Babel.locale_props[\the\localeid].lg = \the\@nameuse{l@\languagename}\space
1743 end
1744 }%
1745 \fi
1746 \bbl@xin@{ fonts }{ \bbl@KVP@onchar\space}%
1747 \ifin@
1748 \bbl@ifunset{bbl@lsys@\languagename}{\bbl@provide@lsys{\languagename}}{}%
1749 \bbl@ifunset{bbl@wdir@\languagename}{\bbl@provide@dirs{\languagename}}{}%
1750 \directlua{
1751 if Babel.script_blocks['\bbl@cl{sbcp}'] then
1752 Babel.loc_to_scr[\the\localeid] =
1753 Babel.script_blocks['\bbl@cl{sbcp}']
1754 end}%
1755 \ifx\bbl@mapselect\@undefined
1756 \AtBeginDocument{%
1757 \bbl@patchfont{{\bbl@mapselect}}%
1758 {\selectfont}}%
1759 \def\bbl@mapselect{%
1760 \let\bbl@mapselect\relax
1761 \edef\bbl@prefontid{\fontid\font}}%
1762 \def\bbl@mapdir##1{%
1763 \begingroup
1764 \setbox\z@\hbox{% Force text mode
1765 \def\languagename{##1}%
1766 \let\bbl@ifrestoring\@firstoftwo % To avoid font warning
1767 \bbl@switchfont
1768 \ifnum\fontid\font>\z@ % A hack, for the pgf nullfont hack
1769 \directlua{
1770 Babel.locale_props[\the\csname bbl@id@@##1\endcsname]%
1771 ['/\bbl@prefontid'] = \fontid\font\space}%
1772 \fi}%
1773 \endgroup}%
1774 \fi
1775 \bbl@exp{\\\bbl@add\\\bbl@mapselect{\\\bbl@mapdir{\languagename}}}%
1776 \fi
1777 \fi
1778 % == mapfont ==
1779 % For bidi texts, to switch the font based on direction. Deprecated
1780 \ifx\bbl@KVP@mapfont\@nnil\else
1781 \bbl@ifsamestring{\bbl@KVP@mapfont}{direction}{}%
1782 {\bbl@error{unknown-mapfont}{}{}{}}%
1783 \bbl@ifunset{bbl@lsys@\languagename}{\bbl@provide@lsys{\languagename}}{}%
1784 \bbl@ifunset{bbl@wdir@\languagename}{\bbl@provide@dirs{\languagename}}{}%
1785 \ifx\bbl@mapselect\@undefined
1786 \AtBeginDocument{%
1787 \bbl@patchfont{{\bbl@mapselect}}%
1788 {\selectfont}}%
1789 \def\bbl@mapselect{%
1790 \let\bbl@mapselect\relax
1791 \edef\bbl@prefontid{\fontid\font}}%
1792 \def\bbl@mapdir##1{%
1793 {\def\languagename{##1}%
1794 \let\bbl@ifrestoring\@firstoftwo % avoid font warning
1795 \bbl@switchfont
1796 \directlua{Babel.fontmap
1797 [\the\csname bbl@wdir@##1\endcsname]%
1798 [\bbl@prefontid]=\fontid\font}}}%
1799 \fi
1800 \bbl@exp{\\\bbl@add\\\bbl@mapselect{\\\bbl@mapdir{\languagename}}}%
1801 \fi
1802 % == Line breaking: CJK quotes ==
1803 \ifcase\bbl@engine\or
1804 \bbl@xin@{/c}{/\bbl@cl{lnbrk}}%
1805 \ifin@
1806 \bbl@ifunset{bbl@quote@\languagename}{}%
1807 {\directlua{
1808 Babel.locale_props[\the\localeid].cjk_quotes = {}
1809 local cs = 'op'
1810 for c in string.utfvalues(%
1811 [[\csname bbl@quote@\languagename\endcsname]]) do
1812 if Babel.cjk_characters[c].c == 'qu' then
1813 Babel.locale_props[\the\localeid].cjk_quotes[c] = cs
1814 end
1815 cs = ( cs == 'op') and 'cl' or 'op'
1816 end
1817 }}%
1818 \fi
1819 \fi
1820 % == Counters: mapdigits ==
1821 % Native digits
1822 \ifx\bbl@KVP@mapdigits\@nnil\else
1823 \bbl@ifunset{bbl@dgnat@\languagename}{}%
1824 {\bbl@activate@preotf
1825 \directlua{
1826 Babel.digits_mapped = true
1827 Babel.digits = Babel.digits or {}
1828 Babel.digits[\the\localeid] =
1829 table.pack(string.utfvalue('\bbl@cl{dgnat}'))
1830 if not Babel.numbers then
1831 function Babel.numbers(head)
1832 local LOCALE = Babel.attr_locale
1833 local GLYPH = node.id'glyph'
1834 local inmath = false
1835 for item in node.traverse(head) do
1836 if not inmath and item.id == GLYPH then
1837 local temp = node.get_attribute(item, LOCALE)
1838 if Babel.digits[temp] then
1839 local chr = item.char
1840 if chr > 47 and chr < 58 then
1841 item.char = Babel.digits[temp][chr-47]
1842 end
1843 end
1844 elseif item.id == node.id'math' then
1845 inmath = (item.subtype == 0)
1846 end
1847 end
1848 return head
1849 end
1850 end
1851 }}%
1852 \fi
1853 % == transforms ==
1854 \ifx\bbl@KVP@transforms\@nnil\else
1855 \def\bbl@elt##1##2##3{%
1856 \in@{$transforms.}{$##1}%
1857 \ifin@
1858 \def\bbl@tempa{##1}%
1859 \bbl@replace\bbl@tempa{transforms.}{}%
1860 \bbl@carg\bbl@transforms{babel\bbl@tempa}{##2}{##3}%
1861 \fi}%
1862 \bbl@exp{%
1863 \\\bbl@ifblank{\bbl@cl{dgnat}}%
1864 {\let\\\bbl@tempa\relax}%
1865 {\def\\\bbl@tempa{%
1866 \\\bbl@elt{transforms.prehyphenation}%
1867 {digits.native.1.0}{([0-9])}%
1868 \\\bbl@elt{transforms.prehyphenation}%
1869 {digits.native.1.1}{string={1\string|0123456789\string|\bbl@cl{dgnat}}}}}}%
1870 \ifx\bbl@tempa\relax\else
1871 \toks@\expandafter\expandafter\expandafter{%
1872 \csname bbl@inidata@\languagename\endcsname}%
1873 \bbl@csarg\edef{inidata@\languagename}{%
1874 \unexpanded\expandafter{\bbl@tempa}%
1875 \the\toks@}%
1876 \fi
1877 \csname bbl@inidata@\languagename\endcsname
1878 \bbl@release@transforms\relax % \relax closes the last item.
1879 \fi}
1880 \def\localerestoredirs{%
1881 \ifcase\bbl@thetextdir
1882 \ifnum\textdirection=\z@\else\textdirection=\z@\fi
1883 \else
1884 \ifnum\textdirection=\@ne\else\textdirection=\@ne\fi
1885 \fi
1886 \ifcase\bbl@thepardir
1887 \ifnum\pardirection=\z@\else\pardirection=\z@\bodydirection=\z@\fi
1888 \else
1889 \ifnum\pardirection=\@ne\else\pardirection=\@ne\bodydirection=\@ne\fi
1890 \fi}
1891 \IfBabelLayout{tabular}%
1892 {\chardef\bbl@tabular@mode\tw@}% All RTL
1893 {\IfBabelLayout{notabular}%
1894 {\chardef\bbl@tabular@mode\z@}%
1895 {\chardef\bbl@tabular@mode\@ne}}% Mixed, with LTR cols
1896 \ifnum\bbl@bidimode>\@ne % Any lua bidi= except default=1
1897 % Redefine: vrules mess up dirs (why?).
1898 \AtBeginDocument{\def\@arstrut{\relax\copy\@arstrutbox}}%
1899 \ifcase\bbl@tabular@mode\or % 1 = Mixed - default
1900 \let\bbl@parabefore\relax
1901 \AddToHook{para/before}{\bbl@parabefore}
1902 \AtBeginDocument{%
1903 \bbl@replace\@tabular{$}{$%
1904 \def\bbl@insidemath{0}%
1905 \def\bbl@parabefore{\localerestoredirs}}%
1906 \ifnum\bbl@tabular@mode=\@ne
1907 \bbl@ifunset{@tabclassz}{}{%
1908 \bbl@exp{% Hide conditionals
1909 \\\bbl@sreplace\\\@tabclassz
1910 {\<ifcase>\\\@chnum}%
1911 {\\\localerestoredirs\<ifcase>\\\@chnum}}}%
1912 \@ifpackageloaded{colortbl}%
1913 {\bbl@sreplace\@classz
1914 {\hbox\bgroup\bgroup}{\hbox\bgroup\bgroup\localerestoredirs}}%
1915 {\@ifpackageloaded{array}%
1916 {\bbl@exp{% Hide conditionals
1917 \\\bbl@sreplace\\\@classz
1918 {\<ifcase>\\\@chnum}%
1919 {\bgroup\\\localerestoredirs\<ifcase>\\\@chnum}%
1920 \\\bbl@sreplace\\\@classz
1921 {\\\do@row@strut\<fi>}{\\\do@row@strut\<fi>\egroup}}}%
1922 {}}%
1923 \fi}%
1924 \or % 2 = All RTL - tabular
1925 \let\bbl@parabefore\relax
1926 \AddToHook{para/before}{\bbl@parabefore}%
1927 \AtBeginDocument{%
1928 \@ifpackageloaded{colortbl}%
1929 {\bbl@replace\@tabular{$}{$%
1930 \def\bbl@insidemath{0}%
1931 \def\bbl@parabefore{\localerestoredirs}}%
1932 \bbl@sreplace\@classz
1933 {\hbox\bgroup\bgroup}{\hbox\bgroup\bgroup\localerestoredirs}}%
1934 {}}%
1935 \fi
1936 \AtBeginDocument{%
1937 \@ifpackageloaded{multicol}%
1938 {\toks@\expandafter{\multi@column@out}%
1939 \edef\multi@column@out{\bodydir\pagedir\the\toks@}}%
1940 {}%
1941 \@ifpackageloaded{paracol}%
1942 {\edef\pcol@output{%
1943 \bodydir\pagedir\unexpanded\expandafter{\pcol@output}}}%
1944 {}}%
1945 \fi
1946 \ifx\bbl@opt@layout\@nnil\endinput\fi
1947 \chardef\bbl@trace@vboxdir\z@
1948 \ifnum\bbl@bidimode>\z@ % Any bidi=
1949 \def\bbl@nextfake#1{% non-local changes, use always inside a group!
1950 \bbl@exp{%
1951 \mathdir\the\bodydir
1952 #1% Once entered in math, set boxes to restore values
1953 \def\\\bbl@insidemath{0}%
1954 \<ifmmode>%
1955 \everyvbox{%
1956 \the\everyvbox
1957 \bodydir\the\bodydir
1958 \mathdir\the\mathdir
1959 \everyhbox{\the\everyhbox}%
1960 \everyvbox{\the\everyvbox}}%
1961 \everyhbox{%
1962 \the\everyhbox
1963 \bodydir\the\bodydir
1964 \mathdir\the\mathdir
1965 \everyhbox{\the\everyhbox}%
1966 \everyvbox{\the\everyvbox}}%
1967 \<fi>}}%
1968 \IfBabelLayout{nopars}{}
1969 {\edef\bbl@opt@layout{\bbl@[email protected].}}%
1970 \IfBabelLayout{pars}
1971 {\chardef\bbl@trace@vboxdir\@ne
1972 \def\@hangfrom#1{%
1973 \setbox\@tempboxa\hbox{{#1}}%
1974 \hangindent\wd\@tempboxa
1975 \ifnum\bbl@vbox@bodydir=\pardirection\else
1976 \shapemode\@ne
1977 \fi
1978 \noindent\box\@tempboxa}}
1979 {}
1980 \fi
1981 \IfBabelLayout{tabular}
1982 {\let\bbl@OL@@tabular\@tabular
1983 \bbl@exp{\\\in@{\\\UseMathForPositioningText}{\[@tabular]}}%
1984 \ifin@
1985 \bbl@replace\@tabular{\UseMathForPositioningText$}%
1986 {\bbl@nextfake{\UseMathForPositioningText$}}%
1987 \else
1988 \bbl@replace\@tabular{$}{\bbl@nextfake$}%
1989 \fi
1990 \let\bbl@NL@@tabular\@tabular
1991 \AtBeginDocument{%
1992 \ifx\bbl@NL@@tabular\@tabular\else
1993 \bbl@exp{\\\in@{\\\UseMathForPositioningText}{\[@tabular]}}%
1994 \ifin@\else
1995 \ifin@
1996 \bbl@replace\@tabular{\UseMathForPositioningText$}%
1997 {\bbl@nextfake{\UseMathForPositioningText$}}%
1998 \else
1999 \bbl@replace\@tabular{$}{\bbl@nextfake$}%
2000 \fi
2001 \fi
2002 \let\bbl@NL@@tabular\@tabular
2003 \fi}}
2004 {}
2005 \IfBabelLayout{lists}
2006 {\chardef\bbl@trace@vboxdir\@ne
2007 \let\bbl@OL@list\list
2008 \bbl@sreplace\list{\parshape}{\bbl@listparshape}%
2009 \let\bbl@NL@list\list
2010 \def\bbl@listparshape#1#2#3{%
2011 \parshape #1 #2 #3 %
2012 \ifnum\bbl@vbox@bodydir=\pardirection\else
2013 \shapemode\tw@
2014 \fi}}
2015 {}
2016 \ifcase\bbl@trace@vboxdir\else
2017 \AtBeginDocument{\chardef\bbl@vbox@bodydir\pagedirection}%
2018 \def\bbl@vbox@lists{\chardef\bbl@vbox@bodydir\bodydirection}%
2019 \let\bbl@bidi@vbox\everyvbox
2020 \@nameuse{newtoks}\everyvbox % \outer in Plain
2021 \everyvbox\expandafter{\the\bbl@bidi@vbox}%
2022 \bbl@bidi@vbox{\bbl@vbox@lists\the\everyvbox}%
2023 \fi
2024 \IfBabelLayout{graphics}
2025 {\let\bbl@pictresetdir\relax
2026 \def\bbl@pictsetdir#1{%
2027 \ifcase\bbl@thetextdir
2028 \let\bbl@pictresetdir\relax
2029 \else
2030 \ifcase#1\bodydir TLT % Remember this sets the inner boxes
2031 \or\textdir TLT
2032 \else\bodydir TLT \textdir TLT
2033 \fi
2034 % \(text|par)dir required in pgf:
2035 \def\bbl@pictresetdir{\bodydir TRT\pardir TRT\textdir TRT\relax}%
2036 \fi}%
2037 \AddToHook{env/picture/begin}{\bbl@pictsetdir\tw@}%
2038 \directlua{
2039 Babel.get_picture_dir = true
2040 Babel.picture_has_bidi = 0
2041 %
2042 function Babel.picture_dir (head)
2043 if not Babel.get_picture_dir then return head end
2044 if Babel.hlist_has_bidi(head) then
2045 Babel.picture_has_bidi = 1
2046 end
2047 return head
2048 end
2049 luatexbase.add_to_callback("hpack_filter", Babel.picture_dir,
2050 "Babel.picture_dir")
2051 }%
2052 \AddToHook{package/graphics/after}{%
2053 \bbl@exp{%
2054 \\\bbl@sreplace\\\rotatebox{\hbox{{\string#2}}}
2055 {\hbox bdir\z@{\hbox bdir\<ifcase>\bbl@thetextdir\z@\<else>\@ne\<fi>{{\string#2}}}}}}
2056 \AddToHook{package/graphicx/after}{%
2057 \bbl@exp{%
2058 \\\bbl@sreplace\\\Grot@box@std{\hbox{{\string#2}}}
2059 {\hbox bdir\z@{\hbox bdir\<ifcase>\bbl@thetextdir\z@\<else>\@ne\<fi>{{\string#2}}}}%
2060 \\\bbl@sreplace\\\Grot@box@kv{\hbox{\string#3}}
2061 {{\hbox bdir\z@}{\hbox bdir\<ifcase>\bbl@thetextdir\z@\<else>\@ne\<fi>{{\string#3}}}}%
2062 \\\bbl@sreplace\\\Grot@box{\hbox}{\hbox bdir\z@}}}
2063 \AtBeginDocument{%
2064 \long\def\put(#1,#2)#3{%
2065 \@killglue
2066 % Try:
2067 \ifx\bbl@pictresetdir\relax
2068 \def\bbl@tempc{0}%
2069 \else
2070 \directlua{
2071 Babel.get_picture_dir = true
2072 Babel.picture_has_bidi = 0
2073 }%
2074 \setbox\z@\hb@xt@\z@{%
2075 \@defaultunitsset\@tempdimc{#1}\unitlength
2076 \kern\@tempdimc
2077 #3\hss}%
2078 \edef\bbl@tempc{\directlua{tex.print(Babel.picture_has_bidi)}}%
2079 \fi
2080 % Do:
2081 \@defaultunitsset\@tempdimc{#2}\unitlength
2082 \raise\@tempdimc\hb@xt@\z@{%
2083 \@defaultunitsset\@tempdimc{#1}\unitlength
2084 \kern\@tempdimc
2085 {\ifnum\bbl@tempc>\z@\bbl@pictresetdir\fi#3}\hss}%
2086 \ignorespaces}%
2087 \MakeRobust\put}%
2088 \AtBeginDocument
2089 {\AddToHook{cmd/diagbox@pict/before}{\let\bbl@pictsetdir\@gobble}%
2090 \ifx\pgfpicture\@undefined\else
2091 \AddToHook{env/pgfpicture/begin}{\bbl@pictsetdir\@ne}%
2092 \bbl@add\pgfinterruptpicture{\bbl@pictresetdir}%
2093 \bbl@add\pgfsys@beginpicture{\bbl@pictsetdir\z@}%
2094 \fi
2095 \ifx\tikzpicture\@undefined\else
2096 \AddToHook{env/tikzpicture/begin}{\bbl@pictsetdir\tw@}%
2097 \bbl@add\tikz@atbegin@node{\bbl@pictresetdir}%
2098 \bbl@sreplace\tikz{\begingroup}{\begingroup\bbl@pictsetdir\tw@}%
2099 \bbl@sreplace\tikzpicture{\begingroup}{\begingroup\bbl@pictsetdir\tw@}%
2100 \fi
2101 }}
2102 {}
2103 \IfBabelLayout{counters*}%
2104 {\bbl@add\bbl@opt@layout{.counters.}%
2105 \directlua{
2106 luatexbase.add_to_callback("process_output_buffer",
2107 Babel.discard_sublr , "Babel.discard_sublr") }%
2108 }{}
2109 \IfBabelLayout{counters}%
2110 {\let\bbl@OL@@textsuperscript\@textsuperscript
2111 \bbl@sreplace\@textsuperscript{\m@th}{\m@th\mathdir\pagedir}%
2112 \let\bbl@latinarabic=\@arabic
2113 \let\bbl@OL@@arabic\@arabic
2114 \def\@arabic#1{\babelsublr{\bbl@latinarabic#1}}%
2115 \@ifpackagewith{babel}{bidi=default}%
2116 {\let\bbl@asciiroman=\@roman
2117 \let\bbl@OL@@roman\@roman
2118 \def\@roman#1{\babelsublr{\ensureascii{\bbl@asciiroman#1}}}%
2119 \let\bbl@asciiRoman=\@Roman
2120 \let\bbl@OL@@roman\@Roman
2121 \def\@Roman#1{\babelsublr{\ensureascii{\bbl@asciiRoman#1}}}%
2122 \let\bbl@OL@labelenumii\labelenumii
2123 \def\labelenumii{)\theenumii(}%
2124 \let\bbl@OL@p@enumiii\p@enumiii
2125 \def\p@enumiii{\p@enumii)\theenumii(}}{}}{}
2126 \IfBabelLayout{extras}%
2127 {\bbl@ncarg\let\bbl@OL@underline{underline }%
2128 \bbl@carg\bbl@sreplace{underline }{\hbox}%
2129 {\def\bbl@insidemath{0}\hbox bdir\ifcase\bbl@thetextdir\z@\else\@ne\fi}%
2130 \let\bbl@OL@LaTeXe\LaTeXe
2131 \DeclareRobustCommand{\LaTeXe}{\mbox{\m@th
2132 \if b\expandafter\@car\f@series\@nil\boldmath\fi
2133 \babelsublr{%
2134 \LaTeX\kern.15em2\bbl@nextfake$_{\textstyle\varepsilon}$}}}}
2135 {}
2136 \endinput
2137 %%
2138 %% End of file `luababel.def'.