summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/babel/luababel.def
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/generic/babel/luababel.def')
-rw-r--r--Master/texmf-dist/tex/generic/babel/luababel.def150
1 files changed, 104 insertions, 46 deletions
diff --git a/Master/texmf-dist/tex/generic/babel/luababel.def b/Master/texmf-dist/tex/generic/babel/luababel.def
index c3cd913bbf7..a2fbb24b845 100644
--- a/Master/texmf-dist/tex/generic/babel/luababel.def
+++ b/Master/texmf-dist/tex/generic/babel/luababel.def
@@ -317,12 +317,15 @@
Babel.intraspaces = Babel.intraspaces or {}
Babel.intraspaces['\csname bbl@sbcp@\languagename\endcsname'] = %
{b = #1, p = #2, m = #3}
+ Babel.locale_props[\the\localeid].intraspace = %
+ {b = #1, p = #2, m = #3}
}}
\def\bbl@intrapenalty#1\@@{%
\directlua{
Babel = Babel or {}
Babel.intrapenalties = Babel.intrapenalties or {}
Babel.intrapenalties['\csname bbl@sbcp@\languagename\endcsname'] = #1
+ Babel.locale_props[\the\localeid].intrapenalty = #1
}}
\begingroup
\catcode`\%=12
@@ -333,6 +336,7 @@
\let\bbl@seaintraspace\relax
\directlua{
Babel = Babel or {}
+ Babel.sea_enabled = true
Babel.sea_ranges = Babel.sea_ranges or {}
function Babel.set_chranges (script, chrng)
local c = 0
@@ -374,13 +378,81 @@
end
end
end
+ }^^
+ \bbl@luahyphenate}
+\catcode`\%=14
+\gdef\bbl@cjkintraspace{%
+ \let\bbl@cjkintraspace\relax
+ \directlua{
+ Babel = Babel or {}
+ require'babel-data-cjk.lua'
+ Babel.cjk_enabled = true
+ function Babel.cjk_linebreak(head)
+ local GLYPH = node.id'glyph'
+ local last_char = nil
+ local quad = 655360 % 10 pt = 655360 = 10 * 65536
+ local last_class = nil
+
+ for item in node.traverse(head) do
+ if item.id == GLYPH then
+
+ local LOCALE = node.get_attribute(item,
+ luatexbase.registernumber'bbl@attr@locale')
+
+ local props = Babel.locale_props[LOCALE]
+
+ class = Babel.cjk_class[item.char].c
+
+ if class == 'cp' then class = 'cl' end % )] as CL
+ if class == 'id' then class = 'I' end
+
+ if class and last_class and Babel.cjk_breaks[last_class][class] then
+ br = Babel.cjk_breaks[last_class][class]
+ else
+ br = 0
+ end
+
+ if br == 1 and props.linebreak == 'c' then
+ local intrapenalty = props.intrapenalty
+ if intrapenalty ~= 0 then
+ local n = node.new(14, 0) % penalty
+ n.penalty = intrapenalty
+ node.insert_before(head, item, n)
+ end
+ local intraspace = props.intraspace
+ local n = node.new(12, 13) % (glue, spaceskip)
+ node.setglue(n, intraspace.b * quad,
+ intraspace.p * quad,
+ intraspace.m * quad)
+ node.insert_before(head, item, n)
+ end
+
+ quad = font.getfont(item.font).size
+ last_class = class
+ else % if penalty, glue or anything else
+ last_class = nil
+ end
+ end
+ lang.hyphenate(head)
+ end
+ }%
+ \bbl@luahyphenate}
+\gdef\bbl@luahyphenate{%
+ \let\bbl@luahyphenate\relax
+ \directlua{
luatexbase.add_to_callback('hyphenate',
- function (head, tail)
- lang.hyphenate(head)
+ function (head, tail)
+ if Babel.cjk_enabled then
+ Babel.cjk_linebreak(head)
+ end
+ lang.hyphenate(head)
+ if Babel.sea_enabled then
Babel.sea_disc_to_space(head)
- end,
- 'Babel.sea_disc_to_space')
-}}
+ end
+ end,
+ 'Babel.hyphenate')
+ }
+}
\endgroup
\AddBabelHook{luatex}{loadkernel}{%
\begingroup
@@ -581,22 +653,24 @@
\fi
\ifx\bbl@opt@layout\@nnil\endinput\fi % if no layout
\ifx\bbl@beforeforeign\leavevmode % A poor test for bidi=
- \def\bbl@nextfake#1{% non-local changes - always inside a group!
+ \def\bbl@nextfake#1{% non-local changes, use always inside a group!
\bbl@exp{%
\mathdir\the\bodydir
#1% Once entered in math, set boxes to restore values
- \everyvbox{%
- \the\everyvbox
- \bodydir\the\bodydir
- \mathdir\the\mathdir
- \everyhbox{\the\everyhbox}%
- \everyvbox{\the\everyvbox}}%
- \everyhbox{%
- \the\everyhbox
- \bodydir\the\bodydir
- \mathdir\the\mathdir
- \everyhbox{\the\everyhbox}%
- \everyvbox{\the\everyvbox}}}}%
+ \<ifmmode>%
+ \everyvbox{%
+ \the\everyvbox
+ \bodydir\the\bodydir
+ \mathdir\the\mathdir
+ \everyhbox{\the\everyhbox}%
+ \everyvbox{\the\everyvbox}}%
+ \everyhbox{%
+ \the\everyhbox
+ \bodydir\the\bodydir
+ \mathdir\the\mathdir
+ \everyhbox{\the\everyhbox}%
+ \everyvbox{\the\everyvbox}}%
+ \<fi>}}%
\def\@hangfrom#1{%
\setbox\@tempboxa\hbox{{#1}}%
\hangindent\wd\@tempboxa
@@ -606,38 +680,22 @@
\noindent\box\@tempboxa}
\fi
\IfBabelLayout{tabular}
- {\def\@tabular{%
- \leavevmode\hbox\bgroup\bbl@nextfake$% %$
- \let\@acol\@tabacol \let\@classz\@tabclassz
- \let\@classiv\@tabclassiv \let\\\@tabularcr\@tabarray}}
+ {\bbl@replace\@tabular{$}{\bbl@nextfake$}%
+ \let\bbl@tabular\@tabular
+ \AtBeginDocument{%
+ \ifx\bbl@tabular\@tabular\else
+ \bbl@replace\@tabular{$}{\bbl@nextfake$}%
+ \fi}}
{}
\IfBabelLayout{lists}
- {\def\list#1#2{%
- \ifnum \@listdepth >5\relax
- \@toodeep
- \else
- \global\advance\@listdepth\@ne
- \fi
- \rightmargin\z@
- \listparindent\z@
- \itemindent\z@
- \csname @list\romannumeral\the\@listdepth\endcsname
- \def\@itemlabel{#1}%
- \let\makelabel\@mklab
- \@nmbrlistfalse
- #2\relax
- \@trivlist
- \parskip\parsep
- \parindent\listparindent
- \advance\linewidth -\rightmargin
- \advance\linewidth -\leftmargin
- \advance\@totalleftmargin \leftmargin
- \parshape \@ne
- \@totalleftmargin \linewidth
+ {\expandafter\def\expandafter\bbl@toreplace\expandafter{\list{##1}{##2}}%
+ \bbl@replace\bbl@toreplace{\parshape}{\bbl@listparshape}%
+ \bbl@exp{\def\\\list##1##2{\the\toks@}}% \toks@ <- implicit result
+ \def\bbl@listparshape#1#2#3{%
+ \parshape #1 #2 #3 %
\ifnum\bbl@getluadir{page}=\bbl@getluadir{par}\else
\shapemode\tw@
- \fi
- \ignorespaces}}
+ \fi}}
{}
\IfBabelLayout{counters}%
{\def\@textsuperscript#1{{% lua has separate settings for math