\expandafter\let\csname ifltj@in@latex\expandafter\endcsname
\csname iftrue\endcsname
\NeedsTeXFormat{LaTeX2e}
- \ProvidesPackage{luatexja-core}[2014/09/24 Core of LuaTeX-ja]
+ \ProvidesPackage{luatexja-core}[2021-05-11 Core of LuaTeX-ja]
\fi %</LaTeX>
%% Load prerequisite packages.
\newif\ifltj@everyhook@avail\ltj@everyhook@availfalse
%! 外部パッケージは普通の \endlinechar で読まないと危険.
\ifltj@in@latex %<*LaTeX>
- \RequirePackage{luaotfload} [2013/05/10] % v2.2
+ \RequirePackage{luatexbase}
+ \RequirePackage{luaotfload}
\RequirePackage{ltxcmds} [2011/11/09] % v1.22
\RequirePackage{pdftexcmds} [2011/11/29] % v0.20
\RequirePackage{xkeyval} [2012/10/14] % v2.6b
- \RequirePackage{atbegshi}
+ \RequirePackage{etoolbox}
\IfFileExists{everyhook.sty}{\RequirePackage{everyhook}\ltj@everyhook@availtrue}{}
\else %<*!LaTeX>
+ \input luatexbase.sty
\input luaotfload.sty
\input ltxcmds.sty
\input pdftexcmds.sty
\input xkeyval
- \input atbegshi.sty
- \AtBeginShipoutInit
\fi %</LaTeX>
\endlinechar=-1 %
%% Check if LuaTeX is used
\ltx@LocalExpandAfter\ifx\csname directlua\endcsname\relax
% Loading is silently aborted, since the notice of the wrong
- % engine is aldready shown in otfluaload.
+ % engine is already shown in luaotfload.
\ltj@core@AtEnd
\expandafter\endinput\fi\relax
%% Check LuaTeX version.
-\ifnum\luatexversion<74
+\ifnum\luatexversion<100
\@PackageError{luatexja-core}
{This LuaTeX engine is too old for this package;\MessageBreak
- at least beta-0.74.0 is needed}
+ at least 1.0.0 is needed}
{Package loading is aborted now.\MessageBreak}
\expandafter\endinput\fi\relax
-%! なお、luatexbase-compat の説明に従うと、LuaTeX 拡張プリミティブは
-%! plain/LaTeX の両方で \luatex 付の名前(\directlua はそのまま)
-%! で使えると考えてよい。
-
%% \LuaTeXjaAvailable
%! 環境検査にパスした時に定義される.
\let\LuaTeXjaAvailable=t %
%%------------------
\endlinechar=13
-%! この中に master の luatexja-core.sty の内容を挿入する
+
%! ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
% LuaTeX-ja core TeX source
-\catcode"FFFFF=14 %"
+\newcount\ltjlineendcomment
+\ltjlineendcomment="FFFFF
+\catcode\ltjlineendcomment=14 %"
\def\ltj@loaded{hoge}
-\newdimen\ltj@zw
-\newdimen\ltj@zh
-\newdimen\jQ \jQ=0.25mm
-\let\jH=\jQ
+\newdimen\ltj@dimen@zw
+\newdimen\ltj@dimen@zh
+\newdimen\ltj@dimen@jQ \ltj@dimen@jQ=0.25mm
+\let\jQ=\ltj@dimen@jQ \let\jH=\jQ
%%%%%%%% error message
\def\ltj@defnum{0}
\def\ltj@defdimen{0}
%%%%%%%% Attributes for Japanese typesetting.
-\newluatexattribute\ltj@icflag % attribute for italic correction
-\newluatexattribute\ltj@curjfnt % index for ``current horizontal Japanese font''
-\newluatexattribute\ltj@curtfnt % index for ``current vertical Japanese font''
-\newluatexattribute\ltj@origchar %
-\newluatexattribute\ltj@charclass %
-\newluatexattribute\ltj@autospc % attribute for autospacing
-\newluatexattribute\ltj@autoxspc % attribute for autoxspacing
-\newluatexattribute\ltj@yablshift % attribute for yalbaselineshift
-\newluatexattribute\ltj@ykblshift % attribute for yjabaselineshift
-\newluatexattribute\ltj@tablshift % attribute for talbaselineshift
-\newluatexattribute\ltj@tkblshift % attribute for tjabaselineshift
-\newluatexattribute\jfam % index for current jfam
-
-\newluatexattribute\ltj@dir
+\newattribute\ltj@icflag % attribute for italic correction
+\newattribute\ltj@curjfnt % index for ``current horizontal Japanese font''
+\newattribute\ltj@curtfnt % index for ``current vertical Japanese font''
+\newattribute\ltj@charclass %
+\newattribute\ltj@charcode %
+\newattribute\ltj@autospc % attribute for autospacing
+\newattribute\ltj@autoxspc % attribute for autoxspacing
+\newattribute\ltj@yablshift % attribute for yalbaselineshift
+\newattribute\ltj@ykblshift % attribute for yjabaselineshift
+\newattribute\ltj@tablshift % attribute for talbaselineshift
+\newattribute\ltj@tkblshift % attribute for tjabaselineshift
+\newattribute\jfam % index for current jfam
+\newattribute\ltj@vert@ori % <=0: UAX#50, >0: always upright
+
+\newattribute\ltj@dir
\newlanguage\ltj@@japanese
-\ltj@dir=0
-\ltj@icflag=0
-\ltj@origchar=0
-\ltj@charclass=0
-\ltj@curjfnt=-1
-\ltj@curtfnt=-1
+\ltj@dir\z@
+\ltj@icflag\z@
+\ltj@charclass\z@
+\ltj@curjfnt\m@ne
+\ltj@curtfnt\m@ne
+\ltj@yablshift\z@
+\ltj@ykblshift\z@
+\ltj@tablshift\z@
+\ltj@tkblshift\z@
%%%%%%%% Attributes for character ranges
\newcount\ltj@tempcnta
-\ltj@tempcnta=0
+\ltj@tempcnta\z@
\loop\ifnum\ltj@tempcnta<7
- \expandafter\newluatexattribute%
+ \expandafter\newattribute%
\csname ltj@kcat\the\ltj@tempcnta\endcsname
\csname ltj@kcat\the\ltj@tempcnta\endcsname=0
- \advance\ltj@tempcnta by1
+ \advance\ltj@tempcnta\@ne
\repeat
\protected\def\ltj@@q@escapenum{\ltj@@q@escapenum@}
\directlua{%
- luatexja = {}
+ luatexja = {};
+ luatexja.lang_ja = \the\ltj@@japanese;
dofile(assert(kpse.find_file('luatexja.lua', 'tex'),
"File `luatexja.lua' not found"))
}
\def\RequireLuaTeXjaSubmodule#1{%
\@ifnextchar[{\ltj@requirelua@submod{#1}}{\ltj@requirelua@submod{#1}[]}}
\def\ltj@requirelua@submod#1[#2]{%
- \directlua{luatexja.load_module(
- "\luatexluaescapestring{#1}")}}
+ \directlua{luatexja.load_module("\luatexluaescapestring{#1}")}}
%%%%%%%% Load all sub-packages.
\ifltj@in@latex %<*LaTeX>
- \RequirePackage{ltj-base} [2013/05/14]
+ \RequirePackage{ltj-base}
\else %<*!LaTeX>
\input ltj-base.sty %
\fi %</LaTeX>
%%%%%%%% \asluastring
-\def\asluastring#1{'\luaescapestring{\detokenize{#1}}'}
+\def\asluastring#1{'\luatexluaescapestring{\detokenize{#1}}'}
%%%%%%%% Redefine \/
-\protected\def\/{\relax\directlua{luatexja.jfont.append_italic()}}
+\newluafunction\ltj@@italic@inner
+\newluafunction\ltj@@start@time@measure@inner
+\newluafunction\ltj@@stop@time@measure@inner
+\directlua{
+ local t = lua.get_functions_table()
+ local start_time_measure = luatexja.base.start_time_measure
+ local stop_time_measure = luatexja.base.stop_time_measure
+ local scan_arg = token.scan_argument
+ t[\the\ltj@@italic@inner] = luatexja.jfont.append_italic
+ t[\the\ltj@@start@time@measure@inner] = function()
+ start_time_measure(scan_arg())
+ end
+ t[\the\ltj@@stop@time@measure@inner] = function()
+ stop_time_measure(scan_arg())
+ end
+}
+\begingroup\catcode`\/=11
+\protected\gdef\ltj@@/{\relax\luafunction\ltj@@italic@inner}
+\global\let\/\ltj@@/ %% PRIMITIVE
+\endgroup
+\luadef\ltj@@start@time@measure\ltj@@start@time@measure@inner
+\luadef\ltj@@stop@time@measure\ltj@@stop@time@measure@inner
%%%%%%%% \jfont\CS={...:...;jfm=metric;...}, \globaljfont
-\protected\def\jfont{%
- \afterassignment\ltj@@jfont\directlua{luatexja.jfont.jfontdefX(false, 'yoko')}}
-\protected\def\globaljfont{%
- \afterassignment\ltj@@jfont\directlua{luatexja.jfont.jfontdefX(true, 'yoko')}}
-\def\ltj@@jfont{\directlua{luatexja.jfont.jfontdefY()}}
+\protected\def\jfont#1{%
+ \afterassignment\ltj@@jfont\directlua{luatexja.jfont.jfontdefX(false, 'yoko','\luatexluaescapestring{\noexpand#1}')}}
+\protected\def\globaljfont#1{%
+ \afterassignment\ltj@@jfont\directlua{luatexja.jfont.jfontdefX(true, 'yoko','\luatexluaescapestring{\noexpand#1}')}}
+\newluafunction\ltj@@jfont@inner
+\directlua{
+ local t = lua.get_functions_table()
+ t[\the\ltj@@jfont@inner] = luatexja.jfont.jfontdefY
+}
+\def\ltj@@jfont{\luafunction\ltj@@jfont@inner}
%%%%%%%% \tfont\CS={...:...;jfm=metric;...}, \globaltfont
-\protected\def\tfont{%
- \afterassignment\ltj@@tfont\directlua{luatexja.jfont.jfontdefX(false, 'tate')}}
-\protected\def\globaltfont{%
- \afterassignment\ltj@@tfont\directlua{luatexja.jfont.jfontdefX(true, 'tate')}}
-\def\ltj@@tfont{\directlua{luatexja.jfont.jfontdefY()}}
-
+\protected\def\tfont#1{%
+ \afterassignment\ltj@@jfont\directlua{luatexja.jfont.jfontdefX(false, 'tate','\luatexluaescapestring{\noexpand#1}')}}
+\protected\def\globaltfont#1{%
+ \afterassignment\ltj@@jfont\directlua{luatexja.jfont.jfontdefX(true, 'tate','\luatexluaescapestring{\noexpand#1}')}}
%%%%%%%% \zw, \zh
-\protected\def\zw{\directlua{tex.setdimen('ltj@zw', luatexja.jfont.get_zw())}\ltj@zw}
-\protected\def\zh{\directlua{tex.setdimen('ltj@zh', luatexja.jfont.get_zh())}\ltj@zh}
+\newluafunction\ltj@zw@inner
+\newluafunction\ltj@zh@inner
+\directlua{
+ local t, setdimen, ltjf = lua.get_functions_table(), tex.setdimen, luatexja.jfont
+ t[\the\ltj@zw@inner] = function() setdimen('ltj@dimen@zw', ltjf.get_zw()) end
+ t[\the\ltj@zh@inner] = function() setdimen('ltj@dimen@zh', ltjf.get_zh()) end
+}
+\protected\def\ltj@zw{\luafunction\ltj@zw@inner\ltj@dimen@zw}
+\protected\def\ltj@zh{\luafunction\ltj@zh@inner\ltj@dimen@zh}
+\let\zw=\ltj@zw
+\let\zh=\ltj@zh
%%%%%%%% \inhibitglue
-\protected\def\ltj@reset@globaldefs{%
- \directlua{luatexja.global_temp = tex.globaldefs; tex.globaldefs = 0}}
-\protected\def\ltj@restore@globaldefs{\directlua{tex.globaldefs = luatexja.global_temp}\relax}
-\protected\def\inhibitglue{\ifhmode\ltj@@ihb\fi}
-\def\ltj@@ihb{\relax\directlua{luatexja.jfmglue.create_inhibitglue_node()}}
+\newluafunction\ltj@reset@globaldefs@inner
+\newluafunction\ltj@restore@globaldefs@inner
+\newluafunction\ltj@@disihb@inner
+\newluafunction\ltj@@ihb@inner
+\newluafunction\ltj@@fakeparbegin@inner
+\newluafunction\ltj@@fakeboxbdd@inner
+\newluafunction\ltj@@ins@xk@inner
+\newluafunction\ltj@@ins@k@inner
+\directlua{
+ local t = lua.get_functions_table()
+ t[\the\ltj@reset@globaldefs@inner]
+ = function() luatexja.global_temp = tex.globaldefs; tex.globaldefs = 0 end
+ t[\the\ltj@restore@globaldefs@inner]
+ = function() tex.globaldefs = luatexja.global_temp end
+ t[\the\ltj@@disihb@inner] = luatexja.jfmglue.create_disinhibitglue_node
+ t[\the\ltj@@ihb@inner] = luatexja.jfmglue.create_inhibitglue_node
+ t[\the\ltj@@fakeparbegin@inner] = luatexja.jfmglue.create_beginpar_node
+ t[\the\ltj@@fakeboxbdd@inner] = luatexja.jfmglue.create_boxbdd_node
+ t[\the\ltj@@ins@xk@inner] = luatexja.jfmglue.insert_xk_skip
+ t[\the\ltj@@ins@k@inner] = luatexja.jfmglue.insert_k_skip
+}
+\protected\luadef\ltj@reset@globaldefs \ltj@reset@globaldefs@inner
+\protected\luadef\ltj@restore@globaldefs\ltj@restore@globaldefs@inner
+\protected\def\disinhibitglue{\ifhmode\relax\luafunction\ltj@@disihb@inner\fi}
+\protected\def\inhibitglue{\ifhmode\relax\luafunction\ltj@@ihb@inner\fi}
+\protected\def\ltjfakeparbegin{\ifhmode\relax\luafunction\ltj@@fakeparbegin@inner\fi}
+\protected\def\ltjfakeboxbdd{\ifhmode\relax\luafunction\ltj@@fakeboxbdd@inner\fi}
+\protected\luadef\insertxkanjiskip \ltj@@ins@xk@inner
+\protected\luadef\insertkanjiskip \ltj@@ins@k@inner
+
%%%%%%%% \ltjdefcharrange<name>{100-200,3000-,5000,...}
\protected\def\ltjdefcharrange#1#2{%
%%%%%%%% \ltjsetparameter
\newcount\ltj@@stack \newcount\ltj@@group@level
-\ltj@@group@level=0 \ltj@@stack=0
+\ltj@@group@level\z@\ltj@@stack\z@
-\setbox0\hbox{%
+\setbox\z@\hbox{%
\directlua{% This value depends on the version of LuaTeX.
luatexja.stack.hmode = -tex.nest[tex.nest.ptr].mode
}%
}
-\setbox0\vbox{%
+\setbox\z@\vbox{%
\directlua{% This value depends on the version of LuaTeX.
luatexja.stack.vmode = -tex.nest[tex.nest.ptr].mode
}%
}
+\setbox\z@\box\voidb@x
% prebreakpenalty = {<char_code>, <penalty>}
-\define@key[ltj]{japaram}{kcatcode}{%
- \expandafter\ltj@@set@stack#1:{KCAT}{0}{0x7FFFFFFF}}
-\define@key[ltj]{japaram}{prebreakpenalty}{%
- \expandafter\ltj@@set@stack#1:{PRE}{-10000}{10000}}
-\define@key[ltj]{japaram}{postbreakpenalty}{%
- \expandafter\ltj@@set@stack#1:{POST}{-10000}{10000}}
-\def\ltj@@set@stack#1,#2:#3#4#5{%
- \directlua{luatexja.stack.set_stack_perchar(luatexja.stack_table_index.#3,
- \ltj@safe@num@or{nil}{#1},\ltj@safe@num@or{nil}{#2},#4,#5)}}
+\define@key[ltj]{japaram}{kcatcode}{\ltj@@set@stack{KCAT}{0}{0x7FFFFFFF}#1\relax}
+\define@key[ltj]{japaram}{prebreakpenalty}{\ltj@@set@stack{PRE}{-10000}{10000}#1\relax}
+\define@key[ltj]{japaram}{postbreakpenalty}{\ltj@@set@stack{POST}{-10000}{10000}#1\relax}
+\def\ltj@@set@stack#1#2#3{%
+ \directlua{luatexja.stack.set_stack_perchar(luatexja.stack_table_index.#1,#2,#3)}}
+%\def\ltj@@set@stack#1,#2:#3#4#5{%
+% \directlua{luatexja.stack.set_stack_perchar(luatexja.stack_table_index.#3,
+% \ltj@safe@num@or{nil}{#1},\ltj@safe@num@or{nil}{#2},#4,#5)}}
% jatextfont = {<char_code>, <font_cs>}
% only horizontal font is supported
\expandafter\ltj@@set@stackfont#1:{MJSS}}
\protected\def\ltj@@set@stackfont#1,#2:#3{%
\ltj@reset@globaldefs
- \ltj@tempcnta=\ltj@curjfnt\ltj@curjfnt=-1 #2%
- \ifnum\ltj@curjfnt=-1
+ \ltj@tempcnta=\ltj@curjfnt\ltj@curjfnt\m@ne#2%
+ \ifnum\ltj@curjfnt=\m@ne
\@PackageError{luatexja-core}%
{\string#2 is not a control sequence that represents \MessageBreak
a Japanese font}{}%
\ltj@restore@globaldefs
}
-% yalbaselineshift = <dimen>
+% {y,t}{ja,al}baselineshift = <dimen>
% yjabaselineshift = <dimen>
\define@key[ltj]{japaram}{yalbaselineshift}{%
\directlua{tex.setattribute(luatexja.isglobal,
- luatexbase.attributes['ltj@yablshift'],
- \ltj@safe@dimen@or\ltj@defdimen{#1})}}
+ luatexbase.attributes['ltj@yablshift'], token.scan_dimen())}#1\relax}
\define@key[ltj]{japaram}{yjabaselineshift}{%
\directlua{tex.setattribute(luatexja.isglobal,
- luatexbase.attributes['ltj@ykblshift'],
- \ltj@safe@dimen@or\ltj@defdimen{#1})}}
-% talbaselineshift = <dimen>
-% tjabaselineshift = <dimen>
+ luatexbase.attributes['ltj@ykblshift'], token.scan_dimen())}#1\relax}
\define@key[ltj]{japaram}{talbaselineshift}{%
\directlua{tex.setattribute(luatexja.isglobal,
- luatexbase.attributes['ltj@tablshift'],
- \ltj@safe@dimen@or\ltj@defdimen{#1})}}
+ luatexbase.attributes['ltj@tablshift'], token.scan_dimen())}#1\relax}
\define@key[ltj]{japaram}{tjabaselineshift}{%
\directlua{tex.setattribute(luatexja.isglobal,
- luatexbase.attributes['ltj@tkblshift'],
- \ltj@safe@dimen@or\ltj@defdimen{#1})}}
+ luatexbase.attributes['ltj@tkblshift'], token.scan_dimen())}#1\relax}
% jaxspmode = {<char_code>, <mode>}
% mode: inhibit, preonly, postonly, allow
\def\ltj@tempa{preonly}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{1}\fi
\def\ltj@tempa{postonly}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{2}\fi
\def\ltj@tempa{allow}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{3}\fi
- \directlua{luatexja.stack.set_stack_perchar(luatexja.stack_table_index.XSP,
- \ltj@safe@num@or{nil}{#1},
- \ltj@safe@num@or{nil}{\ltj@temp},0,3)}}
+ \ltj@@set@stack{XSP}03#1 \ltj@temp}
% alxspmode = {<char_code>, <mode>}
% mode: inhibit, preonly, postonly, allow
% or 0 1 2 3
\define@key[ltj]{japaram}{alxspmode}{% \inhibitxspcode
- \expandafter\ltj@set@alxspmode#1:\relax}
-\def\ltj@set@alxspmode#1,#2:{%
- \lowercase{\edef\ltj@temp{#2}}%
- \def\ltj@tempa{inhibit}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{0}\fi
- \def\ltj@tempa{preonly}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{1}\fi
- \def\ltj@tempa{postonly}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{2}\fi
- \def\ltj@tempa{allow}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{3}\fi
- \directlua{luatexja.stack.set_stack_perchar(luatexja.stack_table_index.XSP,
- \ltj@safe@num@or{nil}{#1},
- \ltj@safe@num@or{nil}{\ltj@temp},0,3)}}
+ \expandafter\ltj@set@jaxspmode#1:\relax}% same code as jaxspmode
% autospacing = <bool> (default: true)
\define@boolkey[ltj]{japaram}{autospacing}[true]{%
\ifltj@japaram@autospacing
- \directlua{luatexja.ext_print_global()}\ltj@autospc=1
+ \directlua{luatexja.ext_print_global()}\ltj@autospc\@ne
\else
- \directlua{luatexja.ext_print_global()}\ltj@autospc=0
+ \directlua{luatexja.ext_print_global()}\ltj@autospc\z@
\fi}
% autoxspacing = <bool> (default: true)
\define@boolkey[ltj]{japaram}{autoxspacing}[true]{%
\ifltj@japaram@autoxspacing
- \directlua{luatexja.ext_print_global()}\ltj@autoxspc=1
+ \directlua{luatexja.ext_print_global()}\ltj@autoxspc\@ne
\else
- \directlua{luatexja.ext_print_global()}\ltj@autoxspc=0
+ \directlua{luatexja.ext_print_global()}\ltj@autoxspc\z@
\fi}
-% [x]]kanjiskip = <dimen>
-\define@key[ltj]{japaram}{kanjiskip}{\ltjsetkanjiskip{#1}}
-\define@key[ltj]{japaram}{xkanjiskip}{\ltjsetxkanjiskip{#1}}
-\protected\def\ltjsetkanjiskip#1{% % SKIP
- \directlua{%
- local d = \ltj@safe@glue{#1}
- luatexja.stack.set_stack_skip(luatexja.stack_table_index.KSK, d); node.free(d)
-}\ignorespaces}
-\protected\def\ltjsetxkanjiskip#1{% % SKIP
- \directlua{%
- local d = \ltj@safe@glue{#1}
- luatexja.stack.set_stack_skip(luatexja.stack_table_index.XSK, d); node.free(d)
-}\ignorespaces}
-
+% [x]]kanjiskip = <skip>
+\define@key[ltj]{japaram}{kanjiskip}{\ltjsetkanjiskip#1}
+\define@key[ltj]{japaram}{xkanjiskip}{\ltjsetxkanjiskip#1}
+\newluafunction\ltjsetkanjiskip@inner
+\newluafunction\ltjsetxkanjiskip@inner
+\directlua{
+ local t, scan_glue = lua.get_functions_table(), token.scan_glue
+ local sss, sti = luatexja.stack.set_stack_skip, luatexja.stack_table_index
+ t[\the\ltjsetkanjiskip@inner] = function()
+ local d = scan_glue(); sss(sti.KSK, d); node.free(d)
+ end
+ t[\the\ltjsetxkanjiskip@inner] = function()
+ local d = scan_glue(); sss(sti.XSK, d); node.free(d)
+ end
+}
+\protected\luadef\ltjsetkanjiskip \ltjsetkanjiskip@inner
+\protected\luadef\ltjsetxkanjiskip\ltjsetxkanjiskip@inner
% jcharwidowpenalty = <count>
\define@key[ltj]{japaram}{jcharwidowpenalty}{% %COUNT
- \ltj@@set@stack0,#1:{JWP}{-10000}{10000}}
+ \ltj@@set@stack{JWP}{-10000}{10000}\z@#1 }
% differentjfm = { large | small | average | pleft | pright | paverage | both}
\define@choicekey*+[ltj]{japaram}{differentjfm}[\ltj@temp\ltj@tempr]%
\directlua{luatexja.jfmglue.diffmet_rule = math.two_paverage}\or
\directlua{luatexja.jfmglue.diffmet_rule = math.two_add}
\fi
-}{\ltj@PackageError{luatexja}{invalid argument `#1' for `differentjfm'}{%
+}{\@PackageError{luatexja}{invalid argument `#1' for `differentjfm'}{%
Argument for `differentjfm' must be one of `large', `small', `average',^^J%
`pleft', `pright', 'paverage' or `both'. }}
% large, small, average, pleft, pright, paverage, both
\define@key[ltj]{japaram}{jacharrange}{\expandafter\ltj@@scrange#1,,}
\def\ltj@@scrange#1,{%
\edef\ltj@temp{#1}%
- \ifx\ltj@temp\empty\let\next=\relax\else\let\next=\ltj@@scrange
+ \ifx\ltj@temp\empty\let\ltj@@next=\relax\else\let\ltj@@next=\ltj@@scrange
\directlua{luatexja.charrange.toggle_char_range(%
luatexja.is_global,\ltj@safe@num@or{nil}{#1})}%
- \fi\next
+ \fi\ltj@@next
}
\protected\def\ltj@setpar@global{%
\else\directlua{luatexja.isglobal=''}\fi
}
\protected\def\ltjsetparameter#1{%
- \directlua{luatexja.base.start_time_measure('set_par')}%
+ \ltj@@start@time@measure{set_par}%
\ltj@setpar@global\setkeys[ltj]{japaram}{#1}%
- \directlua{luatexja.base.stop_time_measure('set_par')}%
+ \ltj@@stop@time@measure{set_par}%
\ignorespaces}
\protected\def\ltjglobalsetparameter#1{%
\relax\ifnum\globaldefs<0\directlua{luatexja.isglobal=''}%
\else\directlua{luatexja.isglobal='global'}\fi%
- \directlua{luatexja.base.start_time_measure('set_par')}%
+ \ltj@@start@time@measure{set_par}%
\setkeys[ltj]{japaram}{#1}%
- \directlua{luatexja.base.stop_time_measure('set_par')}%
+ \ltj@@stop@time@measure{set_par}%
\ignorespaces}
%%%%%%%% \ltjgetparameter
\ltj@@decl@array@param{chartorange}
\ltj@@decl@array@param{boxdir}
\def\ltjgetparameter#1{%
- \directlua{luatexja.base.start_time_measure('get_par')}%
+ \ltj@@start@time@measure{get_par}%
% stop call is moved in luatexja.lua
\ifcsname ltj@@array@param/#1\endcsname
\expandafter\ltx@firstoftwo
{\ltj@@getparam@two{#1}}%
{\ltj@@getparam@one{#1}}%
}
-\def\ltj@@getparam@one#1{%
- \directlua{luatexja.ext_get_parameter_unary('#1')}%
-}%
+\newluafunction\ltj@@getparam@one@inner
+\directlua{
+ local t = lua.get_functions_table()
+ t[\the\ltj@@getparam@one@inner] = luatexja.ext_get_parameter_unary
+}
+\luadef\ltj@@getparam@one\ltj@@getparam@one@inner
\def\ltj@@getparam@two#1#2{%
\directlua{luatexja.ext_get_parameter_binary('#1', \ltj@safe@num@or{nil}{#2})}%
}
%%%%%%%% \ltjalchar<number>, \ltjjachar<number>
\let\ltj@@origchar=\char
-\protected\def\ltj@alljachar{\relax
- \csname ltj@kcat0\endcsname=0
- \csname ltj@kcat1\endcsname=0
- \csname ltj@kcat2\endcsname=0
- \csname ltj@kcat3\endcsname=0
- \csname ltj@kcat4\endcsname=0
- \csname ltj@kcat5\endcsname=0
- \csname ltj@kcat6\endcsname=0 }
+\newluafunction\ltj@alljachar@inner
+\directlua{
+ local t, set_attr = lua.get_functions_table(), tex.setattribute
+ local get_attr, floor = tex.getattribute, math.floor
+ local attr_curjfnt = luatexbase.attributes['ltj@curjfnt']
+ local lang_ja = luatexja.lang_ja
+ t[\the\ltj@alljachar@inner] = function()
+ font.current(get_attr(attr_curjfnt)); tex.language=lang_ja;
+ for i=0,6 do
+ set_attr(luatexbase.attributes['ltj@kcat' .. floor(i)],0)
+ end
+ end
+}
+\protected\luadef\ltj@alljachar\ltj@alljachar@inner
\protected\def\ltj@allalchar{\relax
\csname ltj@kcat0\endcsname="7FFFFFFF %"
\csname ltj@kcat1\endcsname="7FFFFFFF %"
\csname ltj@kcat5\endcsname="7FFFFFFF %"
\csname ltj@kcat6\endcsname="7FFFFFFF }%"
-\protected\def\ltjjachar{\afterassignment\ltj@@jachar\ltj@tempcnta}
-\def\ltj@@jachar{{\directlua{tex.globaldefs = 0}\ltj@alljachar\ltj@@origchar\ltj@tempcnta}}
-\protected\def\ltjalchar{\afterassignment\ltj@@alchar\ltj@tempcnta}
-\def\ltj@@alchar{{\directlua{tex.globaldefs = 0}\ltj@allalchar\ltj@@origchar\ltj@tempcnta}}
+\protected\def\ltjjachar{\leavevmode\afterassignment\ltj@@jachar\ltj@tempcnta}
+\def\ltj@@jachar{{\directlua{tex.globaldefs=0}\ltj@alljachar\ltj@@origchar\ltj@tempcnta}}
+\protected\def\ltjalchar{\leavevmode\afterassignment\ltj@@alchar\ltj@tempcnta}
+\def\ltj@@alchar{{\directlua{tex.globaldefs=0}\ltj@allalchar\ltj@@origchar\ltj@tempcnta}}
%%%%%%%% \ltjsetmathletter<number>, \ltjunsetmathletter<number>
\protected\def\ltjsetmathletter#1{%
- \ltj@tempcnta=#1
- \directlua{luatexja.math.is_math_letters[\the\ltj@tempcnta]=true}%
+ \directlua{luatexja.math.is_math_letters[token.scan_int()]=true}#1\relax
}
\protected\def\ltjunsetmathletter#1{%
- \ltj@tempcnta=#1
- \directlua{luatexja.math.is_math_letters[\the\ltj@tempcnta]=false}%
+ \directlua{luatexja.math.is_math_letters[token.scan_int()]=false}#1\relax
}
%%%%%%%% \ltjdeclarealtfont<base_font_cs><alt_font_cs>{100-200,3000-,5000,...}
% いつも global
\def\ltj@@getjfontnumber#1{% result in \ltj@tempcntc
\ltj@reset@globaldefs
- \begingroup\ltj@curjfnt=-1 \ltj@curtfnt=-1\relax
+ \begingroup\ltj@curjfnt\m@ne\ltj@curtfnt\m@ne\relax
#1\directlua{luatexja.__temp = -(\the\ltj@curjfnt)*(\the\ltj@curtfnt)}\endgroup
\ltj@tempcntc=\directlua{tex.sprint(luatexja.__temp)}\relax
- \ifnum\ltj@tempcntc=-1
+ \ifnum\ltj@tempcntc=\m@ne
\@PackageError{luatexja-core}%
{\string#1 is not a control sequence that represents \MessageBreak
a Japanese font}{I'll use the current horizontal Japanese font instead.^^J}%
\yoko
%%%% insert
-\let\orig@insert=\insert
-\protected\def\insert{\begingroup\afterassignment\ltj@@insert@A\ltj@tempcnta}
-\protected\def\ltj@@insert@A{\orig@insert\ltj@tempcnta\bgroup
- \aftergroup\ltj@@insert@B\let\next}
-\protected\def\ltj@@insert@B{\directlua{luatexja.direction.populate_insertion_dir_whatsit()}\endgroup}
+\let\ltj@@orig@insert\insert
+\newluafunction\ltj@@lua@populate@insertwhatsit@inner
+\directlua{
+ local t = lua.get_functions_table()
+ t[\the\ltj@@lua@populate@insertwhatsit@inner]
+ = luatexja.direction.populate_insertion_dir_whatsit
+}
+\luadef\ltj@@lua@populate@insertwhatsit\ltj@@lua@populate@insertwhatsit@inner
+\protected\def\ltj@@insert{\begingroup\afterassignment\ltj@@insert@A\ltj@tempcnta}
+\let\insert\ltj@@insert %% PRIMITIVE
+\protected\def\ltj@@insert@A{\ltj@@orig@insert\ltj@tempcnta\bgroup
+ \aftergroup\ltj@@insert@B\let\ltj@@next}
+\protected\def\ltj@@insert@B{\ltj@@lua@populate@insertwhatsit\endgroup}
%%%% vadjust
-\let\ltj@@orig@vadjust=\vadjust
-\protected\def\vadjust{%
+\let\ltj@@orig@vadjust\vadjust
+\protected\def\ltj@@vadjust{%
\ltj@@orig@vadjust\bgroup
\directlua{luatexja.direction.set_list_direction_hook('adj')}%
- \aftergroup\ltj@@vadjust@check@dir\let\next}
+ \aftergroup\ltj@@vadjust@check@dir\let\ltj@@next}
+\let\vadjust\ltj@@vadjust %% PRIMITIVE
\protected\def\ltj@@vadjust@check@dir{%
\directlua{luatexja.direction.check_adjust_direction()}%
}
%%%% \hbox, \vbox, \vtop
-\setbox0\hbox{%
+\setbox\z@\hbox{%
+ \primitive\everymath{}%
$\directlua{% This value depends on the version of LuaTeX.
- luatexja.stack.mmode = -tex.nest[tex.nest.ptr].mode
+ luatexja.stack.mmode = -tex.nest[tex.nest.ptr].mode
}$%
}
-\ifltj@everyhook@avail
- \PushPreHook{hbox}{%
- \directlua{luatexja.direction.set_list_direction_hook()}%
- \aftergroup\ltj@@reset@badness
- }
- \PushPreHook{vbox}{%
- \directlua{luatexja.direction.set_list_direction_hook()}%
- \aftergroup\ltj@@reset@badness
- }
-\else
- {\catcode`\!=0\catcode`\\=12
- !@PackageWarningNoLine{luatexja-core}{%
- I will use \everyhbox and \everyvbox directly !MessageBreak
- for supporting multiple directions, !MessageBreak
- since everyhook.sty is not available}}
- \everyhbox{%
- \directlua{luatexja.direction.set_list_direction_hook()}%
- \aftergroup\ltj@@reset@badness
- }
- \everyvbox{%
- \directlua{luatexja.direction.set_list_direction_hook()}%
- \aftergroup\ltj@@reset@badness
- }
-\fi
-\protected\def\ltj@@reset@badness{%
- \directlua{%
+\setbox\z@\box\voidb@x
+\newluafunction\ltj@@box@dirhook@inner
+\newluafunction\ltj@@reset@badness@inner
+\directlua{
+ local t, ltjd = lua.get_functions_table(), luatexja.direction
+ t[\the\ltj@@box@dirhook@inner]
+ = function() ltjd.set_list_direction_hook() end
+ t[\the\ltj@@reset@badness@inner] = function()
if luatexja.global_temp then
tex.hbadness= tex.hbadness or luatexja.hbadness_temp
tex.vbadness= tex.vbadness or luatexja.vbadness_temp
tex.globaldefs= luatexja.global_temp or tex.globaldefs
end
- }%
+ end
}
-\AtBeginShipout{\directlua{luatexja.direction.finalize()}}
+\luadef\ltj@@box@dirhook\ltj@@box@dirhook@inner
+\ifltj@everyhook@avail% using everyhook package
+ \PushPreHook{hbox}{\ltj@@box@dirhook\aftergroup\ltj@@reset@badness}
+ \PushPreHook{vbox}{\ltj@@box@dirhook\aftergroup\ltj@@reset@badness}
+\else
+ \let\ltj@@everyhbox\everyhbox\let\ltj@@everyvbox\everyvbox
+ \newtoks\ltj@@i@everyhbox\newtoks\ltj@@i@everyvbox
+ \let\everyhbox\ltj@@i@everyhbox\let\everyvbox\ltj@@i@everyvbox
+ \ltj@@everyhbox{\ltj@@box@dirhook
+ \aftergroup\ltj@@reset@badness\the\ltj@@i@everyhbox}
+ \ltj@@everyvbox{\ltj@@box@dirhook
+ \aftergroup\ltj@@reset@badness\the\ltj@@i@everyvbox}
+\fi
+
+\luadef\ltj@@reset@badness\ltj@@reset@badness@inner
%%%% \raise, \lower, \moveleft, \moveright
-\let\ltj@@orig@raise=\raise
-\let\ltj@@orig@lower=\lower
-\protected\def\raise{\ltj@reset@globaldefs\afterassignment\ltj@@raise\ltj@tempdima}
-\protected\def\lower{\ltj@reset@globaldefs\afterassignment\ltj@@raise\ltj@tempdima-}
-\protected\def\ltj@@raise{%
+\newluafunction\ltj@@lua@raisebox@inner
+\directlua{
+ local t = lua.get_functions_table()
+ t[\the\ltj@@lua@raisebox@inner]=luatexja.direction.raise_box
+}
+\protected\luadef\ltj@@lua@raisebox\ltj@@lua@raisebox@inner
+\let\ltj@@orig@raise\raise
+\let\ltj@@orig@lower\lower
+\protected\def\ltj@@raise{\ltj@reset@globaldefs\afterassignment\ltj@@raise@\ltj@tempdima}
+\protected\def\ltj@@lower{\ltj@reset@globaldefs\afterassignment\ltj@@raise@\ltj@tempdima-}
+\protected\def\ltj@@raise@{%
\ltj@restore@globaldefs
\edef\ltj@@raise@a{%
- \noexpand\directlua{luatexja.direction.raise_box()}%
- \ltj@@orig@raise\the\ltj@tempdima\noexpand\box\ltj@afbox
+ \ltj@@lua@raisebox\ltj@@orig@raise\the\ltj@tempdima\noexpand\box\ltj@afbox
}\ltj@afterbox\ltj@@raise@a}
-\let\ltj@@orig@moveleft=\moveleft
-\let\ltj@@orig@moveright=\moveright
-\protected\def\moveleft{\ltj@reset@globaldefs\afterassignment\ltj@@moveleft\ltj@tempdima}
-\protected\def\moveright{\ltj@reset@globaldefs\afterassignment\ltj@@moveleft\ltj@tempdima-}
-\protected\def\ltj@@moveleft{%
+\let\ltj@@orig@moveleft\moveleft
+\let\ltj@@orig@moveright\moveright
+\protected\def\ltj@@moveleft{\ltj@reset@globaldefs\afterassignment\ltj@@moveleft@\ltj@tempdima}
+\protected\def\ltj@@moveright{\ltj@reset@globaldefs\afterassignment\ltj@@moveleft@\ltj@tempdima-}
+\protected\def\ltj@@moveleft@{%
\ltj@restore@globaldefs
\edef\ltj@@moveleft@a{%
- \noexpand\directlua{luatexja.direction.raise_box()}%
- \ltj@@orig@moveleft\the\ltj@tempdima\noexpand\box\ltj@afbox
+ \ltj@@lua@raisebox\ltj@@orig@moveleft\the\ltj@tempdima\noexpand\box\ltj@afbox
}\ltj@afterbox\ltj@@moveleft@a}
+\let\raise\ltj@@raise %% PRIMITIVE
+\let\lower\ltj@@lower %% PRIMITIVE
+\let\moveleft\ltj@@moveleft %% PRIMITIVE
+\let\moveright\ltj@@moveright %% PRIMITIVE
+
+%%%%\vsplit
+\let\ltj@@orig@vsplit\vsplit
+\protected\def\ltj@@vsplit{\directlua{luatexja.direction.vsplit()}}
+\let\vsplit\ltj@@vsplit %% PRIMITIVE
%%%% \vcenter
-\let\ltj@@orig@vcenter=\vcenter
-\protected\def\vcenter{\ltj@afterbox\ltj@@vcenter\vbox}
-\protected\def\ltj@@vcenter{%
- \directlua{luatexja.direction.raise_box()}%
- \ltj@@orig@vcenter{\box\ltj@afbox}%
+\let\ltj@@orig@vcenter\vcenter
+\protected\def\ltj@@vcenter{\ltj@afterbox\ltj@@vcenter@\vbox}
+\protected\def\ltj@@vcenter@{%
+ \ltj@@lua@raisebox\ltj@@orig@vcenter{\box\ltj@afbox}%
}
+\let\vcenter\ltj@@vcenter %% PRIMITIVE
%%%% \unhbox and \unvbox
+\newluafunction\ltj@@lua@unboxcheckdir@inner
+\directlua{
+ local t = lua.get_functions_table()
+ t[\the\ltj@@lua@unboxcheckdir@inner]=luatexja.direction.unbox_check_dir
+}
+\luadef\ltj@@lua@unboxcheckdir\ltj@@lua@unboxcheckdir@inner
\long\def \@gobbletwo #1#2{}
-\let\ltj@@orig@unhbox=\unhbox
-\let\ltj@@orig@unvbox=\unvbox
-\protected\def\unhbox{\ltj@reset@globaldefs\afterassignment\ltj@@unhbox\ltj@tempcnta}
-\protected\def\unvbox{\ltj@reset@globaldefs\afterassignment\ltj@@unvbox\ltj@tempcnta}
-\protected\def\ltj@@unhbox{%
- \directlua{luatexja.direction.unbox_check_dir()}%
- \ltj@@orig@unhbox\ltj@tempcnta}
-\protected\def\ltj@@unvbox{%
- \directlua{luatexja.direction.unbox_check_dir()}%
- \ltj@@orig@unvbox\ltj@tempcnta}
-\let\ltj@@orig@unhcopy=\unhcopy
-\let\ltj@@orig@unvcopy=\unvcopy
-\protected\def\unhcopy{\ltj@reset@globaldefs\afterassignment\ltj@@unhcopy\ltj@tempcnta}
-\protected\def\unvcopy{\ltj@reset@globaldefs\afterassignment\ltj@@unvcopy\ltj@tempcnta}
-\protected\def\ltj@@unhcopy{%
+\let\ltj@@orig@unhbox\unhbox
+\let\ltj@@orig@unvbox\unvbox
+\protected\def\ltj@@unhbox{\ltj@reset@globaldefs\afterassignment\ltj@@unhbox@\ltj@tempcnta}
+\protected\def\ltj@@unvbox{\ltj@reset@globaldefs\afterassignment\ltj@@unvbox@\ltj@tempcnta}
+\protected\def\ltj@@unhbox@{\ltj@@lua@unboxcheckdir\ltj@@orig@unhbox\ltj@tempcnta}
+\protected\def\ltj@@unvbox@{\ltj@@lua@unboxcheckdir\ltj@@orig@unvbox\ltj@tempcnta}
+\let\ltj@@orig@unhcopy\unhcopy
+\let\ltj@@orig@unvcopy\unvcopy
+\protected\def\ltj@@unhcopy{\ltj@reset@globaldefs\afterassignment\ltj@@unhcopy@\ltj@tempcnta}
+\protected\def\ltj@@unvcopy{\ltj@reset@globaldefs\afterassignment\ltj@@unvcopy@\ltj@tempcnta}
+\protected\def\ltj@@unhcopy@{%
\directlua{luatexja.direction.unbox_check_dir(true)}%
\ltj@@orig@unhcopy\ltj@tempcnta
\directlua{luatexja.direction.uncopy_restore_whatsit()}}
-\protected\def\ltj@@unvcopy{%
+\protected\def\ltj@@unvcopy@{%
\directlua{luatexja.direction.unbox_check_dir(true)}%
\ltj@@orig@unvcopy\ltj@tempcnta
\directlua{luatexja.direction.uncopy_restore_whatsit()}}
-
+\let\unhbox\ltj@@unhbox %% PRIMITIVE
+\let\unvbox\ltj@@unvbox %% PRIMITIVE
+\let\unhcopy\ltj@@unhcopy %% PRIMITIVE
+\let\unvcopy\ltj@@unvcopy %% PRIMITIVE
%%%% lastbox
\let\ltj@@orig@lastbox=\lastbox
-\protected\def\lastbox{%
- \directlua{luatexja.direction.lastbox_hook()}\ltj@@orig@lastbox
-}
+\protected\def\ltj@@lastbox{\directlua{luatexja.direction.lastbox_hook()}\ltj@@orig@lastbox}
+\let\lastbox\ltj@@lastbox %% PRIMITIVE
%%%%%%%% \ltjgetwd<box_num> etc.
-\def\ltj@@getwd#1{%
- \directlua{luatexja.direction.get_box_dim('width', \the\numexpr#1\relax)}%
- \ltj@tempdima%
-}
-\def\ltj@@getht#1{%
- \directlua{luatexja.direction.get_box_dim('height', \the\numexpr#1\relax)}%
- \ltj@tempdima%
-}
-\def\ltj@@getdp#1{%
- \directlua{luatexja.direction.get_box_dim('depth', \the\numexpr#1\relax)}%
- \ltj@tempdima%
-}
+\def\ltj@@getwd{\directlua{luatexja.direction.get_box_dim('width', token.scan_int())}}
+\def\ltj@@getht{\directlua{luatexja.direction.get_box_dim('height', token.scan_int())}}
+\def\ltj@@getdp{\directlua{luatexja.direction.get_box_dim('depth', token.scan_int())}}
\let\ltjgetwd=\ltj@@getwd\let\ltjgetht=\ltj@@getht\let\ltjgetdp=\ltj@@getdp
%%%%%%%% \ltjsetwd<box_num>=<dimen> etc.
-\protected\def\ltjsetwd{\begingroup
- \ltj@reset@globaldefs\afterassignment\ltj@@setwd@a\ltj@tempcnta}
-\def\ltj@@setwd@a{\afterassignment\ltj@@setwd@b\ltj@tempdima}
-\def\ltj@@setwd@b{%
- \directlua{luatexja.direction.set_box_dim('width')}%
- \ltj@restore@globaldefs\endgroup}
-\protected\def\ltjsetht{\begingroup
- \ltj@reset@globaldefs\afterassignment\ltj@@setht@a\ltj@tempcnta}
-\def\ltj@@setht@a{\afterassignment\ltj@@setht@b\ltj@tempdima}
-\def\ltj@@setht@b{%
- \directlua{luatexja.direction.set_box_dim('height')}%
- \ltj@restore@globaldefs\endgroup}
-\protected\def\ltjsetdp{\begingroup
- \ltj@reset@globaldefs\afterassignment\ltj@@setdp@a\ltj@tempcnta}
-\def\ltj@@setdp@a{\afterassignment\ltj@@setdp@b\ltj@tempdima}
-\def\ltj@@setdp@b{%
- \directlua{luatexja.direction.set_box_dim('depth')}%
- \ltj@restore@globaldefs\endgroup}
+\protected\def\ltjsetwd{\directlua{luatexja.direction.set_box_dim('width')}}
+\protected\def\ltjsetht{\directlua{luatexja.direction.set_box_dim('height')}}
+\protected\def\ltjsetdp{\directlua{luatexja.direction.set_box_dim('depth')}}
%%------------------ Load module for the format
+\directlua{luatexja.load_kinsoku()}
\ifltj@in@latex %<*LaTeX>
- \RequirePackage{ltj-latex}[2013/05/14]
+ \RequirePackage{ltj-latex}
\else\ifltj@in@plain %<*plain>
\input ltj-plain.sty %
\fi\fi %</LaTeX|plain>
-\newluatexcatcodetable\ltj@temp@cctb
+\newcatcodetable\ltj@temp@cctb
\def\ltj@overwrite@catcodetable#1{%
\setluatexcatcodetable\ltj@temp@cctb{\luatexcatcodetable#1}%
- \setluatexcatcodetable#1{\luatexcatcodetable\ltj@temp@cctb\catcode"FFFFF=14}%"
+ \setluatexcatcodetable#1{\luatexcatcodetable\ltj@temp@cctb\catcode\ltjlineendcomment=14}%"
}
\ltj@overwrite@catcodetable\CatcodeTableLaTeX
\ltj@overwrite@catcodetable\CatcodeTableLaTeXAtLetter