6 %% Avoid multiple loading.
7 \csname\if11luatexjacoreLoaded\fi\endcsname
9 \catcode32=\the\catcode32%
10 \catcode33=\the\catcode33%
11 \catcode35=\the\catcode35%
12 \catcode40=\the\catcode40%
13 \catcode41=\the\catcode41%
14 \catcode42=\the\catcode42%
15 \catcode43=\the\catcode43%
16 \catcode44=\the\catcode44%
17 \catcode45=\the\catcode45%
18 \catcode46=\the\catcode46%
19 \catcode58=\the\catcode58%
20 \catcode59=\the\catcode59%
21 \catcode60=\the\catcode60%
22 \catcode61=\the\catcode61%
23 \catcode62=\the\catcode62%
24 \catcode64=\the\catcode64%
25 \catcode91=\the\catcode91%
26 \catcode93=\the\catcode93%
27 \catcode94=\the\catcode94%
28 \catcode95=\the\catcode95%
29 \catcode126=\the\catcode126%
30 \endlinechar=\the\endlinechar
54 %! なお, 上のcatcode設定はcoreとcompatで同一にしておく.
55 \edef\ltj@core@AtEnd{\x
56 \noexpand\let\noexpand\ltj@core@AtEnd\relax}
57 \def\luatexjacoreLoaded{\endinput}
59 %% Check if LaTeX is used.
60 \begingroup\expandafter\expandafter\expandafter\endgroup
61 \expandafter\ifx\csname RequirePackage\endcsname\relax %<*!LaTeX>
62 \expandafter\let\csname ifltj@in@latex\expandafter\endcsname
63 \csname iffalse\endcsname
65 \expandafter\let\csname ifltj@in@latex\expandafter\endcsname
66 \csname iftrue\endcsname
67 \NeedsTeXFormat{LaTeX2e}
68 \ProvidesPackage{luatexja-core}[2014/09/24 Core of LuaTeX-ja]
71 %% Load prerequisite packages.
73 \newif\ifltj@everyhook@avail\ltj@everyhook@availfalse
74 %! 外部パッケージは普通の \endlinechar で読まないと危険.
75 \ifltj@in@latex %<*LaTeX>
76 \RequirePackage{luaotfload} [2013/05/10] % v2.2
77 \RequirePackage{ltxcmds} [2011/11/09] % v1.22
78 \RequirePackage{pdftexcmds} [2011/11/29] % v0.20
79 \RequirePackage{xkeyval} [2012/10/14] % v2.6b
80 \RequirePackage{atbegshi}
81 \IfFileExists{everyhook.sty}{\RequirePackage{everyhook}\ltj@everyhook@availtrue}{}
92 %% Check if LuaTeX is used
93 \ltx@LocalExpandAfter\ifx\csname directlua\endcsname\relax
94 % Loading is silently aborted, since the notice of the wrong
95 % engine is aldready shown in otfluaload.
97 \expandafter\endinput\fi\relax
99 %% Check LuaTeX version.
100 \ifnum\luatexversion<74
101 \@PackageError{luatexja-core}
102 {This LuaTeX engine is too old for this package;\MessageBreak
103 at least beta-0.74.0 is needed}
104 {Package loading is aborted now.\MessageBreak}
105 \expandafter\endinput\fi\relax
107 %! なお、luatexbase-compat の説明に従うと、LuaTeX 拡張プリミティブは
108 %! plain/LaTeX の両方で \luatex 付の名前(\directlua はそのまま)
111 %% \LuaTeXjaAvailable
113 \let\LuaTeXjaAvailable=t %
117 %! この中に master の luatexja-core.sty の内容を挿入する
119 % LuaTeX-ja core TeX source
123 \def\ltj@loaded{hoge}
127 \newdimen\jQ \jQ=0.25mm
130 %%%%%%%% error message
134 %%%%%%%% Attributes for Japanese typesetting.
135 \newluatexattribute\ltj@icflag % attribute for italic correction
136 \newluatexattribute\ltj@curjfnt % index for ``current horizontal Japanese font''
137 \newluatexattribute\ltj@curtfnt % index for ``current vertical Japanese font''
138 \newluatexattribute\ltj@origchar %
139 \newluatexattribute\ltj@charclass %
140 \newluatexattribute\ltj@charcode %
141 \newluatexattribute\ltj@autospc % attribute for autospacing
142 \newluatexattribute\ltj@autoxspc % attribute for autoxspacing
143 \newluatexattribute\ltj@yablshift % attribute for yalbaselineshift
144 \newluatexattribute\ltj@ykblshift % attribute for yjabaselineshift
145 \newluatexattribute\ltj@tablshift % attribute for talbaselineshift
146 \newluatexattribute\ltj@tkblshift % attribute for tjabaselineshift
147 \newluatexattribute\jfam % index for current jfam
149 \newluatexattribute\ltj@dir
150 \newlanguage\ltj@@japanese
158 %%%%%%%% Attributes for character ranges
159 \newcount\ltj@tempcnta
161 \loop\ifnum\ltj@tempcnta<7
162 \expandafter\newluatexattribute%
163 \csname ltj@kcat\the\ltj@tempcnta\endcsname
164 \csname ltj@kcat\the\ltj@tempcnta\endcsname=0
165 \advance\ltj@tempcnta by1
169 %%%%%%%% Loading luatexja.lua
170 %% Quark tokens needed in ltj-base
171 \protected\def\ltj@@q@escape{\ltj@@q@escape@}
172 \protected\def\ltj@@q@escapenum{\ltj@@q@escapenum@}
176 dofile(assert(kpse.find_file('luatexja.lua', 'tex'),
177 "File `luatexja.lua' not found"))
180 %% \RequireLuaTeXjaSubmodule{name}[date]
181 % A TeX version of luatexja.load_module(name)
182 % The second optional argument [date] is simply ignored.
183 \def\RequireLuaTeXjaSubmodule#1{%
184 \@ifnextchar[{\ltj@requirelua@submod{#1}}{\ltj@requirelua@submod{#1}[]}}
185 \def\ltj@requirelua@submod#1[#2]{%
186 \directlua{luatexja.load_module(
187 "\luatexluaescapestring{#1}")}}
190 %%%%%%%% Load all sub-packages.
191 \ifltj@in@latex %<*LaTeX>
192 \RequirePackage{ltj-base} [2013/05/14]
194 \input ltj-base.sty %
197 %%%%%%%% \asluastring
198 \def\asluastring#1{'\luaescapestring{\detokenize{#1}}'}
201 \protected\def\/{\relax\directlua{luatexja.jfont.append_italic()}}
203 %%%%%%%% \jfont\CS={...:...;jfm=metric;...}, \globaljfont
204 \protected\def\jfont{%
205 \afterassignment\ltj@@jfont\directlua{luatexja.jfont.jfontdefX(false, 'yoko')}}
206 \protected\def\globaljfont{%
207 \afterassignment\ltj@@jfont\directlua{luatexja.jfont.jfontdefX(true, 'yoko')}}
208 \def\ltj@@jfont{\directlua{luatexja.jfont.jfontdefY()}}
210 %%%%%%%% \tfont\CS={...:...;jfm=metric;...}, \globaltfont
211 \protected\def\tfont{%
212 \afterassignment\ltj@@tfont\directlua{luatexja.jfont.jfontdefX(false, 'tate')}}
213 \protected\def\globaltfont{%
214 \afterassignment\ltj@@tfont\directlua{luatexja.jfont.jfontdefX(true, 'tate')}}
215 \def\ltj@@tfont{\directlua{luatexja.jfont.jfontdefY()}}
218 \protected\def\zw{\directlua{tex.setdimen('ltj@zw', luatexja.jfont.get_zw())}\ltj@zw}
219 \protected\def\zh{\directlua{tex.setdimen('ltj@zh', luatexja.jfont.get_zh())}\ltj@zh}
221 %%%%%%%% \inhibitglue
222 \protected\def\ltj@reset@globaldefs{%
223 \directlua{luatexja.global_temp = tex.globaldefs; tex.globaldefs = 0}}
224 \protected\def\ltj@restore@globaldefs{\directlua{tex.globaldefs = luatexja.global_temp}\relax}
225 \protected\def\inhibitglue{\ifhmode\ltj@@ihb\fi}
226 \def\ltj@@ihb{\relax\directlua{luatexja.jfmglue.create_inhibitglue_node()}}
228 %%%%%%%% \ltjdefcharrange<name>{100-200,3000-,5000,...}
229 \protected\def\ltjdefcharrange#1#2{%
230 {\ltj@tempcntc=#1 \expandafter\ltj@@dcrange#2,,}\ignorespaces}
231 \def\ltj@@dcrange#1,{\def\ltj@temp{#1}%
232 \ifx\ltj@temp\empty\let\@next=\relax\else
233 \ltj@@dcrangeA{#1}\let\@next=\ltj@@dcrange\fi\@next}
234 \def\ltj@@dcrangeA#1{\ltj@@dcrangeB#1--\@nil}
235 \def\ltj@@dcrangeB#1-#2-#3\@nil{\def\ltj@temp{#3}%
237 \ltj@tempcnta=#1 \ltj@tempcntb=\ltj@tempcnta
240 \ifx\ltj@temp\empty\ltj@tempcnta='200\else\ltj@tempcnta=#1\fi\relax
242 \ifx\ltj@temp\empty\ltj@tempcntb="10FFFF\else\ltj@tempcntb=#2\fi\relax%"
244 \directlua{luatexja.charrange.add_char_range(\the\ltj@tempcnta,\the\ltj@tempcntb,
248 %%%%%%%% \ltjsetparameter
249 \newcount\ltj@@stack \newcount\ltj@@group@level
250 \ltj@@group@level\z@\ltj@@stack\z@
253 \directlua{% This value depends on the version of LuaTeX.
254 luatexja.stack.hmode = -tex.nest[tex.nest.ptr].mode
258 \directlua{% This value depends on the version of LuaTeX.
259 luatexja.stack.vmode = -tex.nest[tex.nest.ptr].mode
262 \setbox\z@\box\voidb@x
264 % prebreakpenalty = {<char_code>, <penalty>}
265 \define@key[ltj]{japaram}{kcatcode}{%
266 \expandafter\ltj@@set@stack#1:{KCAT}{0}{0x7FFFFFFF}}
267 \define@key[ltj]{japaram}{prebreakpenalty}{%
268 \expandafter\ltj@@set@stack#1:{PRE}{-10000}{10000}}
269 \define@key[ltj]{japaram}{postbreakpenalty}{%
270 \expandafter\ltj@@set@stack#1:{POST}{-10000}{10000}}
271 \def\ltj@@set@stack#1,#2:#3#4#5{%
272 \directlua{luatexja.stack.set_stack_perchar(luatexja.stack_table_index.#3,
273 \ltj@safe@num@or{nil}{#1},\ltj@safe@num@or{nil}{#2},#4,#5)}}
275 % jatextfont = {<char_code>, <font_cs>}
276 % only horizontal font is supported
277 \define@key[ltj]{japaram}{jatextfont}{%
278 \expandafter\ltj@@set@stackfont#1:{MJT}}
279 \define@key[ltj]{japaram}{jascriptfont}{%
280 \expandafter\ltj@@set@stackfont#1:{MJS}}
281 \define@key[ltj]{japaram}{jascriptscriptfont}{%
282 \expandafter\ltj@@set@stackfont#1:{MJSS}}
283 \protected\def\ltj@@set@stackfont#1,#2:#3{%
284 \ltj@reset@globaldefs
285 \ltj@tempcnta=\ltj@curjfnt\ltj@curjfnt=-1 #2%
286 \ifnum\ltj@curjfnt=-1
287 \@PackageError{luatexja-core}%
288 {\string#2 is not a control sequence that represents \MessageBreak
291 \directlua{luatexja.stack.set_stack_font(luatexja.stack_table_index.#3,
292 \ltj@safe@num@or{nil}{#1}, \the\ltj@curjfnt)}%
294 \ltj@curjfnt=\ltj@tempcnta
295 \ltj@restore@globaldefs
298 % yalbaselineshift = <dimen>
299 % yjabaselineshift = <dimen>
300 \define@key[ltj]{japaram}{yalbaselineshift}{%
301 \directlua{tex.setattribute(luatexja.isglobal,
302 luatexbase.attributes['ltj@yablshift'],
303 \ltj@safe@dimen@or\ltj@defdimen{#1})}}
304 \define@key[ltj]{japaram}{yjabaselineshift}{%
305 \directlua{tex.setattribute(luatexja.isglobal,
306 luatexbase.attributes['ltj@ykblshift'],
307 \ltj@safe@dimen@or\ltj@defdimen{#1})}}
308 % talbaselineshift = <dimen>
309 % tjabaselineshift = <dimen>
310 \define@key[ltj]{japaram}{talbaselineshift}{%
311 \directlua{tex.setattribute(luatexja.isglobal,
312 luatexbase.attributes['ltj@tablshift'],
313 \ltj@safe@dimen@or\ltj@defdimen{#1})}}
314 \define@key[ltj]{japaram}{tjabaselineshift}{%
315 \directlua{tex.setattribute(luatexja.isglobal,
316 luatexbase.attributes['ltj@tkblshift'],
317 \ltj@safe@dimen@or\ltj@defdimen{#1})}}
319 % jaxspmode = {<char_code>, <mode>}
320 % mode: inhibit, preonly, postonly, allow
322 \define@key[ltj]{japaram}{jaxspmode}{% \inhibitxspcode
323 \expandafter\ltj@set@jaxspmode#1:\relax}
324 \def\ltj@set@jaxspmode#1,#2:{%
325 \lowercase{\edef\ltj@temp{#2}}%
326 \def\ltj@tempa{inhibit}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{0}\fi
327 \def\ltj@tempa{preonly}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{1}\fi
328 \def\ltj@tempa{postonly}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{2}\fi
329 \def\ltj@tempa{allow}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{3}\fi
330 \directlua{luatexja.stack.set_stack_perchar(luatexja.stack_table_index.XSP,
331 \ltj@safe@num@or{nil}{#1},
332 \ltj@safe@num@or{nil}{\ltj@temp},0,3)}}
334 % alxspmode = {<char_code>, <mode>}
335 % mode: inhibit, preonly, postonly, allow
337 \define@key[ltj]{japaram}{alxspmode}{% \inhibitxspcode
338 \expandafter\ltj@set@alxspmode#1:\relax}
339 \def\ltj@set@alxspmode#1,#2:{%
340 \lowercase{\edef\ltj@temp{#2}}%
341 \def\ltj@tempa{inhibit}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{0}\fi
342 \def\ltj@tempa{preonly}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{1}\fi
343 \def\ltj@tempa{postonly}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{2}\fi
344 \def\ltj@tempa{allow}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{3}\fi
345 \directlua{luatexja.stack.set_stack_perchar(luatexja.stack_table_index.XSP,
346 \ltj@safe@num@or{nil}{#1},
347 \ltj@safe@num@or{nil}{\ltj@temp},0,3)}}
349 % autospacing = <bool> (default: true)
350 \define@boolkey[ltj]{japaram}{autospacing}[true]{%
351 \ifltj@japaram@autospacing
352 \directlua{luatexja.ext_print_global()}\ltj@autospc=1
354 \directlua{luatexja.ext_print_global()}\ltj@autospc=0
357 % autoxspacing = <bool> (default: true)
358 \define@boolkey[ltj]{japaram}{autoxspacing}[true]{%
359 \ifltj@japaram@autoxspacing
360 \directlua{luatexja.ext_print_global()}\ltj@autoxspc=1
362 \directlua{luatexja.ext_print_global()}\ltj@autoxspc=0
365 % [x]]kanjiskip = <dimen>
366 \define@key[ltj]{japaram}{kanjiskip}{\ltjsetkanjiskip{#1}}
367 \define@key[ltj]{japaram}{xkanjiskip}{\ltjsetxkanjiskip{#1}}
368 \protected\def\ltjsetkanjiskip#1{% % SKIP
370 local d = \ltj@safe@glue{#1}
371 luatexja.stack.set_stack_skip(luatexja.stack_table_index.KSK, d); node.free(d)
373 \protected\def\ltjsetxkanjiskip#1{% % SKIP
375 local d = \ltj@safe@glue{#1}
376 luatexja.stack.set_stack_skip(luatexja.stack_table_index.XSK, d); node.free(d)
380 % jcharwidowpenalty = <count>
381 \define@key[ltj]{japaram}{jcharwidowpenalty}{% %COUNT
382 \ltj@@set@stack0,#1:{JWP}{-10000}{10000}}
384 % differentjfm = { large | small | average | pleft | pright | paverage | both}
385 \define@choicekey*+[ltj]{japaram}{differentjfm}[\ltj@temp\ltj@tempr]%
386 {large,small,average,pleft,pright,paverage,both}{%
388 \directlua{luatexja.jfmglue.diffmet_rule = math.max}\or
389 \directlua{luatexja.jfmglue.diffmet_rule = math.min}\or
390 \directlua{luatexja.jfmglue.diffmet_rule = math.two_average}\or
391 \directlua{luatexja.jfmglue.diffmet_rule = math.two_pleft}\or
392 \directlua{luatexja.jfmglue.diffmet_rule = math.two_pright}\or
393 \directlua{luatexja.jfmglue.diffmet_rule = math.two_paverage}\or
394 \directlua{luatexja.jfmglue.diffmet_rule = math.two_add}
396 }{\ltj@PackageError{luatexja}{invalid argument `#1' for `differentjfm'}{%
397 Argument for `differentjfm' must be one of `large', `small', `average',^^J%
398 `pleft', `pright', 'paverage' or `both'. }}
399 % large, small, average, pleft, pright, paverage, both
402 % jacharrange = { +-<range_number> }
403 \define@key[ltj]{japaram}{jacharrange}{\expandafter\ltj@@scrange#1,,}
404 \def\ltj@@scrange#1,{%
406 \ifx\ltj@temp\empty\let\next=\relax\else\let\next=\ltj@@scrange
407 \directlua{luatexja.charrange.toggle_char_range(%
408 luatexja.is_global,\ltj@safe@num@or{nil}{#1})}%
412 \protected\def\ltj@setpar@global{%
413 \relax\ifnum\globaldefs>0\directlua{luatexja.isglobal='global'}%
414 \else\directlua{luatexja.isglobal=''}\fi
416 \protected\def\ltjsetparameter#1{%
417 \directlua{luatexja.base.start_time_measure('set_par')}%
418 \ltj@setpar@global\setkeys[ltj]{japaram}{#1}%
419 \directlua{luatexja.base.stop_time_measure('set_par')}%
421 \protected\def\ltjglobalsetparameter#1{%
422 \relax\ifnum\globaldefs<0\directlua{luatexja.isglobal=''}%
423 \else\directlua{luatexja.isglobal='global'}\fi%
424 \directlua{luatexja.base.start_time_measure('set_par')}%
425 \setkeys[ltj]{japaram}{#1}%
426 \directlua{luatexja.base.stop_time_measure('set_par')}%
429 %%%%%%%% \ltjgetparameter
430 \def\ltj@@decl@array@param#1{%
431 \expandafter\let\csname ltj@@array@param/#1\endcsname=t%
433 \ltj@@decl@array@param{prebreakpenalty}
434 \ltj@@decl@array@param{postbreakpenalty}
435 \ltj@@decl@array@param{jaxspmode}
436 \ltj@@decl@array@param{alxspmode}
437 \ltj@@decl@array@param{kcatcode}
438 \ltj@@decl@array@param{jacharrange}
439 \ltj@@decl@array@param{chartorange}
440 \ltj@@decl@array@param{boxdir}
441 \def\ltjgetparameter#1{%
442 \directlua{luatexja.base.start_time_measure('get_par')}%
443 % stop call is moved in luatexja.lua
444 \ifcsname ltj@@array@param/#1\endcsname
445 \expandafter\ltx@firstoftwo
447 \expandafter\ltx@secondoftwo
449 {\ltj@@getparam@two{#1}}%
450 {\ltj@@getparam@one{#1}}%
452 \def\ltj@@getparam@one#1{%
453 \directlua{luatexja.ext_get_parameter_unary('#1')}%
455 \def\ltj@@getparam@two#1#2{%
456 \directlua{luatexja.ext_get_parameter_binary('#1', \ltj@safe@num@or{nil}{#2})}%
459 %%%%%%%% \ltjalchar<number>, \ltjjachar<number>
460 \let\ltj@@origchar=\char
461 \protected\def\ltj@alljachar{\relax
462 \csname ltj@kcat0\endcsname=0
463 \csname ltj@kcat1\endcsname=0
464 \csname ltj@kcat2\endcsname=0
465 \csname ltj@kcat3\endcsname=0
466 \csname ltj@kcat4\endcsname=0
467 \csname ltj@kcat5\endcsname=0
468 \csname ltj@kcat6\endcsname=0 }
469 \protected\def\ltj@allalchar{\relax
470 \csname ltj@kcat0\endcsname="7FFFFFFF %"
471 \csname ltj@kcat1\endcsname="7FFFFFFF %"
472 \csname ltj@kcat2\endcsname="7FFFFFFF %"
473 \csname ltj@kcat3\endcsname="7FFFFFFF %"
474 \csname ltj@kcat4\endcsname="7FFFFFFF %"
475 \csname ltj@kcat5\endcsname="7FFFFFFF %"
476 \csname ltj@kcat6\endcsname="7FFFFFFF }%"
478 \protected\def\ltjjachar{\afterassignment\ltj@@jachar\ltj@tempcnta}
479 \def\ltj@@jachar{{\directlua{tex.globaldefs = 0}\ltj@alljachar\ltj@@origchar\ltj@tempcnta}}
480 \protected\def\ltjalchar{\afterassignment\ltj@@alchar\ltj@tempcnta}
481 \def\ltj@@alchar{{\directlua{tex.globaldefs = 0}\ltj@allalchar\ltj@@origchar\ltj@tempcnta}}
483 %%%%%%%% \ltjsetmathletter<number>, \ltjunsetmathletter<number>
484 \protected\def\ltjsetmathletter#1{%
486 \directlua{luatexja.math.is_math_letters[\the\ltj@tempcnta]=true}%
488 \protected\def\ltjunsetmathletter#1{%
490 \directlua{luatexja.math.is_math_letters[\the\ltj@tempcnta]=false}%
493 %%%%%%%% \ltjdeclarealtfont<base_font_cs><alt_font_cs>{100-200,3000-,5000,...}
494 % <base_font_cs> の 第 3 引数の文字達は <alt_font_cs> で組む
496 \def\ltj@@getjfontnumber#1{% result in \ltj@tempcntc
497 \ltj@reset@globaldefs
498 \begingroup\ltj@curjfnt=-1 \ltj@curtfnt=-1\relax
499 #1\directlua{luatexja.__temp = -(\the\ltj@curjfnt)*(\the\ltj@curtfnt)}\endgroup
500 \ltj@tempcntc=\directlua{tex.sprint(luatexja.__temp)}\relax
501 \ifnum\ltj@tempcntc=-1
502 \@PackageError{luatexja-core}%
503 {\string#1 is not a control sequence that represents \MessageBreak
504 a Japanese font}{I'll use the current horizontal Japanese font instead.^^J}%
505 \ltj@tempcntc=\ltj@curjfnt
506 \fi\ltj@restore@globaldefs}
508 \protected\def\ltjdeclarealtfont#1#2#3{%
509 {\ltj@@getjfontnumber#1\@tempcnta=\ltj@tempcntc% \@tempcnta: 基底フォント
510 \ltj@@getjfontnumber#2%
511 \expandafter\ltj@@altfont#3,,}\ignorespaces}
512 \def\ltj@@altfont#1,{\def\ltj@temp{#1}%
513 \ifx\ltj@temp\empty\let\@next=\relax\else
514 \ltj@@altfontA{#1}\let\@next=\ltj@@altfont\fi\@next}
515 \def\ltj@@altfontA#1{\ltj@@altfontB#1--\@nil}
516 \def\ltj@@altfontB#1-#2-#3\@nil{\def\ltj@temp{#3}%
518 \ltj@tempcnta=#1 \ltj@tempcntb=\ltj@tempcnta
521 \ifx\ltj@temp\empty\ltj@tempcnta='200\else\ltj@tempcnta=#1\fi\relax
523 \ifx\ltj@temp\empty\ltj@tempcntb="10FFFF\else\ltj@tempcntb=#2\fi\relax%"
525 \directlua{luatexja.jfont.set_alt_font(
526 \the\ltj@tempcnta,\the\ltj@tempcntb,
527 \the\ltj@tempcntc, \the\@tempcnta)}%
530 %%%%%%%% \ltjclearaltfont<font_cs>
531 % <font_cs> の文字は全部 <font_cs> 本来の文字で組む
532 \protected\def\ltjclearaltfont#1{%
533 {\ltj@@getjfontnumber#1%
534 \directlua{luatexja.jfont.clear_alt_font(\the\ltj@tempcntc)}}\ignorespaces}
537 %%%%%%%% \yoko, \tate,\dtou
538 \protected\def\tate{%
539 \directlua{luatexja.direction.set_list_direction(3, 'tate')}%
541 \protected\def\yoko{%
542 \directlua{luatexja.direction.set_list_direction(4, 'yoko')}%
544 \protected\def\dtou{%
545 \directlua{luatexja.direction.set_list_direction(1, 'dtou')}%
547 \protected\def\utod{% 「縦数式ディレクション」
548 \directlua{luatexja.direction.set_list_direction(11, 'utod')}%
550 \define@key[ltj]{japaram}{direction}{%% always local
551 \directlua{luatexja.direction.set_list_direction(1, 'ltjsetparameter')}%
557 \let\orig@insert=\insert
558 \protected\def\insert{\begingroup\afterassignment\ltj@@insert@A\ltj@tempcnta}
559 \protected\def\ltj@@insert@A{\orig@insert\ltj@tempcnta\bgroup
560 \aftergroup\ltj@@insert@B\let\next}
561 \protected\def\ltj@@insert@B{\directlua{luatexja.direction.populate_insertion_dir_whatsit()}\endgroup}
564 \let\ltj@@orig@vadjust=\vadjust
565 \protected\def\vadjust{%
566 \ltj@@orig@vadjust\bgroup
567 \directlua{luatexja.direction.set_list_direction_hook('adj')}%
568 \aftergroup\ltj@@vadjust@check@dir\let\next}
569 \protected\def\ltj@@vadjust@check@dir{%
570 \directlua{luatexja.direction.check_adjust_direction()}%
573 %%%% \hbox, \vbox, \vtop
575 $\directlua{% This value depends on the version of LuaTeX.
576 luatexja.stack.mmode = -tex.nest[tex.nest.ptr].mode
579 \setbox\z@\box\voidb@x
580 \ifltj@everyhook@avail% using everyhook package
582 \directlua{luatexja.direction.set_list_direction_hook()}%
583 \aftergroup\ltj@@reset@badness
586 \directlua{luatexja.direction.set_list_direction_hook()}%
587 \aftergroup\ltj@@reset@badness
590 \let\ltj@@everyhbox=\everyhbox\let\ltj@@everyvbox=\everyvbox
591 \newtoks\ltj@@i@everyhbox\newtoks\ltj@@i@everyvbox
592 \let\everyhbox=\ltj@@i@everyhbox\let\everyvbox=\ltj@@i@everyvbox
594 \directlua{luatexja.direction.set_list_direction_hook()}%
595 \aftergroup\ltj@@reset@badness
596 \the\ltj@@i@everyhbox}
598 \directlua{luatexja.direction.set_list_direction_hook()}%
599 \aftergroup\ltj@@reset@badness
600 \the\ltj@@i@everyvbox}
603 \protected\def\ltj@@reset@badness{%
605 if luatexja.global_temp then
606 tex.hbadness= tex.hbadness or luatexja.hbadness_temp
607 tex.vbadness= tex.vbadness or luatexja.vbadness_temp
608 tex.globaldefs= luatexja.global_temp or tex.globaldefs
612 \AtBeginShipout{\directlua{luatexja.direction.finalize()}}
614 %%%% \raise, \lower, \moveleft, \moveright
615 \let\ltj@@orig@raise=\raise
616 \let\ltj@@orig@lower=\lower
617 \protected\def\raise{\ltj@reset@globaldefs\afterassignment\ltj@@raise\ltj@tempdima}
618 \protected\def\lower{\ltj@reset@globaldefs\afterassignment\ltj@@raise\ltj@tempdima-}
619 \protected\def\ltj@@raise{%
620 \ltj@restore@globaldefs
622 \noexpand\directlua{luatexja.direction.raise_box()}%
623 \ltj@@orig@raise\the\ltj@tempdima\noexpand\box\ltj@afbox
624 }\ltj@afterbox\ltj@@raise@a}
625 \let\ltj@@orig@moveleft=\moveleft
626 \let\ltj@@orig@moveright=\moveright
627 \protected\def\moveleft{\ltj@reset@globaldefs\afterassignment\ltj@@moveleft\ltj@tempdima}
628 \protected\def\moveright{\ltj@reset@globaldefs\afterassignment\ltj@@moveleft\ltj@tempdima-}
629 \protected\def\ltj@@moveleft{%
630 \ltj@restore@globaldefs
631 \edef\ltj@@moveleft@a{%
632 \noexpand\directlua{luatexja.direction.raise_box()}%
633 \ltj@@orig@moveleft\the\ltj@tempdima\noexpand\box\ltj@afbox
634 }\ltj@afterbox\ltj@@moveleft@a}
637 \let\ltj@@orig@vcenter=\vcenter
638 \protected\def\vcenter{\ltj@afterbox\ltj@@vcenter\vbox}
639 \protected\def\ltj@@vcenter{%
640 \directlua{luatexja.direction.raise_box()}%
641 \ltj@@orig@vcenter{\box\ltj@afbox}%
644 %%%% \unhbox and \unvbox
645 \long\def \@gobbletwo #1#2{}
646 \let\ltj@@orig@unhbox=\unhbox
647 \let\ltj@@orig@unvbox=\unvbox
648 \protected\def\unhbox{\ltj@reset@globaldefs\afterassignment\ltj@@unhbox\ltj@tempcnta}
649 \protected\def\unvbox{\ltj@reset@globaldefs\afterassignment\ltj@@unvbox\ltj@tempcnta}
650 \protected\def\ltj@@unhbox{%
651 \directlua{luatexja.direction.unbox_check_dir()}%
652 \ltj@@orig@unhbox\ltj@tempcnta}
653 \protected\def\ltj@@unvbox{%
654 \directlua{luatexja.direction.unbox_check_dir()}%
655 \ltj@@orig@unvbox\ltj@tempcnta}
656 \let\ltj@@orig@unhcopy=\unhcopy
657 \let\ltj@@orig@unvcopy=\unvcopy
658 \protected\def\unhcopy{\ltj@reset@globaldefs\afterassignment\ltj@@unhcopy\ltj@tempcnta}
659 \protected\def\unvcopy{\ltj@reset@globaldefs\afterassignment\ltj@@unvcopy\ltj@tempcnta}
660 \protected\def\ltj@@unhcopy{%
661 \directlua{luatexja.direction.unbox_check_dir(true)}%
662 \ltj@@orig@unhcopy\ltj@tempcnta
663 \directlua{luatexja.direction.uncopy_restore_whatsit()}}
664 \protected\def\ltj@@unvcopy{%
665 \directlua{luatexja.direction.unbox_check_dir(true)}%
666 \ltj@@orig@unvcopy\ltj@tempcnta
667 \directlua{luatexja.direction.uncopy_restore_whatsit()}}
670 \let\ltj@@orig@lastbox=\lastbox
671 \protected\def\lastbox{%
672 \directlua{luatexja.direction.lastbox_hook()}\ltj@@orig@lastbox
675 %%%%%%%% \ltjgetwd<box_num> etc.
677 \directlua{luatexja.direction.get_box_dim('width', \the\numexpr#1\relax)}%
681 \directlua{luatexja.direction.get_box_dim('height', \the\numexpr#1\relax)}%
685 \directlua{luatexja.direction.get_box_dim('depth', \the\numexpr#1\relax)}%
688 \let\ltjgetwd=\ltj@@getwd\let\ltjgetht=\ltj@@getht\let\ltjgetdp=\ltj@@getdp
690 %%%%%%%% \ltjsetwd<box_num>=<dimen> etc.
691 \protected\def\ltjsetwd{\begingroup
692 \ltj@reset@globaldefs\afterassignment\ltj@@setwd@a\ltj@tempcnta}
693 \def\ltj@@setwd@a{\afterassignment\ltj@@setwd@b\ltj@tempdima}
695 \directlua{luatexja.direction.set_box_dim('width')}%
696 \ltj@restore@globaldefs\endgroup}
697 \protected\def\ltjsetht{\begingroup
698 \ltj@reset@globaldefs\afterassignment\ltj@@setht@a\ltj@tempcnta}
699 \def\ltj@@setht@a{\afterassignment\ltj@@setht@b\ltj@tempdima}
701 \directlua{luatexja.direction.set_box_dim('height')}%
702 \ltj@restore@globaldefs\endgroup}
703 \protected\def\ltjsetdp{\begingroup
704 \ltj@reset@globaldefs\afterassignment\ltj@@setdp@a\ltj@tempcnta}
705 \def\ltj@@setdp@a{\afterassignment\ltj@@setdp@b\ltj@tempdima}
707 \directlua{luatexja.direction.set_box_dim('depth')}%
708 \ltj@restore@globaldefs\endgroup}
710 %%------------------ Load module for the format
712 \ifltj@in@latex %<*LaTeX>
713 \RequirePackage{ltj-latex}[2013/05/14]
714 \else\ifltj@in@plain %<*plain>
715 \input ltj-plain.sty %
716 \fi\fi %</LaTeX|plain>
718 \newluatexcatcodetable\ltj@temp@cctb
719 \def\ltj@overwrite@catcodetable#1{%
720 \setluatexcatcodetable\ltj@temp@cctb{\luatexcatcodetable#1}%
721 \setluatexcatcodetable#1{\luatexcatcodetable\ltj@temp@cctb\catcode"FFFFF=14}%"
723 \ltj@overwrite@catcodetable\CatcodeTableLaTeX
724 \ltj@overwrite@catcodetable\CatcodeTableLaTeXAtLetter
725 \ltj@overwrite@catcodetable\CatcodeTableExpl
728 %%------------------ all done