OSDN Git Service

Merge branch 'master' into kitagawa_test
[luatex-ja/luatexja.git] / src / luatexja-core.sty
1 %
2 % luatexja-core.sty
3 %
4
5 %! 外から読まれるので仰々しくなってます
6 %% Avoid multiple loading.
7 \csname\if11luatexjacoreLoaded\fi\endcsname
8 \edef\x{%
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
31 \relax}
32 \catcode32=10 %< >
33 \catcode33=12 %<">
34 \catcode35=6  %<#>
35 \catcode40=12 %<(>
36 \catcode41=12 %<)>
37 \catcode42=12 %<*>
38 \catcode43=12 %<+>
39 \catcode44=12 %<,>
40 \catcode45=12 %<->
41 \catcode46=12 %<.>
42 \catcode58=12 %<:>
43 \catcode59=12 %<;>
44 \catcode60=12 %<<>
45 \catcode61=12 %<=>
46 \catcode62=12 %<>>
47 \catcode64=11 %<@>
48 \catcode91=12 %<[>
49 \catcode93=12 %<]>
50 \catcode94=7  %<^>
51 \catcode95=8  %<_>
52 \catcode126=13 %<~>
53 \endlinechar=-1 %
54 %! なお, 上のcatcode設定はcoreとcompatで同一にしておく.
55 \edef\ltj@core@AtEnd{\x
56   \noexpand\let\noexpand\ltj@core@AtEnd\relax}
57 \def\luatexjacoreLoaded{\endinput}
58
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
64 \else                           %<*LaTeX>
65   \expandafter\let\csname ifltj@in@latex\expandafter\endcsname
66     \csname iftrue\endcsname
67   \NeedsTeXFormat{LaTeX2e}
68   \ProvidesPackage{luatexja-core}[2015/05/03 Core of LuaTeX-ja]
69 \fi                             %</LaTeX>
70
71 %% Load prerequisite packages.
72 \endlinechar=13 %
73 \newif\ifltj@everyhook@avail\ltj@everyhook@availfalse
74 %! 外部パッケージは普通の \endlinechar で読まないと危険.
75 \ifltj@in@latex                 %<*LaTeX>
76   \RequirePackage{luaotfload} [2013/12/31] % v2.3
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}{}
82 \else                           %<*!LaTeX>
83   \input luaotfload.sty
84   \input ltxcmds.sty
85   \input pdftexcmds.sty
86   \input xkeyval
87   \input atbegshi.sty
88   \AtBeginShipoutInit
89 \fi                             %</LaTeX>
90 \endlinechar=-1 %
91
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.
96   \ltj@core@AtEnd
97 \expandafter\endinput\fi\relax
98
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
106
107 %! なお、luatexbase-compat の説明に従うと、LuaTeX 拡張プリミティブは
108 %! plain/LaTeX の両方で \luatex 付の名前(\directlua はそのまま)
109 %! で使えると考えてよい。
110
111 %% \LuaTeXjaAvailable
112 %! 環境検査にパスした時に定義される.
113 \let\LuaTeXjaAvailable=t %
114
115 %%------------------
116 \endlinechar=13
117 %! この中に master の luatexja-core.sty の内容を挿入する
118 %! ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
119 % LuaTeX-ja core TeX source
120
121 \catcode"FFFFF=14 %"
122
123 \def\ltj@loaded{hoge}
124
125 \newdimen\ltj@zw
126 \newdimen\ltj@zh
127 \newdimen\jQ \jQ=0.25mm
128 \let\jH=\jQ
129
130 %%%%%%%% error message
131 \def\ltj@defnum{0}
132 \def\ltj@defdimen{0}
133
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
148
149 \newluatexattribute\ltj@dir
150 \newlanguage\ltj@@japanese
151 \ltj@dir\z@
152 \ltj@icflag\z@
153 \ltj@origchar\z@
154 \ltj@charclass\z@
155 \ltj@curjfnt\m@ne
156 \ltj@curtfnt\m@ne
157
158 %%%%%%%% Attributes for character ranges
159 \newcount\ltj@tempcnta
160 \ltj@tempcnta\z@
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\@ne
166 \repeat
167
168
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@}
173
174 \directlua{%
175   luatexja = {};
176   luatexja.lang_ja = \the\ltj@@japanese;
177   dofile(assert(kpse.find_file('luatexja.lua', 'tex'),
178       "File `luatexja.lua' not found"))
179 }
180
181 %% \RequireLuaTeXjaSubmodule{name}[date]
182 % A TeX version of luatexja.load_module(name)
183 % The second optional argument [date] is simply ignored.
184 \def\RequireLuaTeXjaSubmodule#1{%
185   \@ifnextchar[{\ltj@requirelua@submod{#1}}{\ltj@requirelua@submod{#1}[]}}
186 \def\ltj@requirelua@submod#1[#2]{%
187   \directlua{luatexja.load_module(
188     "\luatexluaescapestring{#1}")}}
189
190
191 %%%%%%%% Load all sub-packages.
192 \ifltj@in@latex                 %<*LaTeX>
193   \RequirePackage{ltj-base}   [2013/05/14]
194 \else                           %<*!LaTeX>
195   \input ltj-base.sty %
196 \fi                             %</LaTeX>
197
198 %%%%%%%% \asluastring
199 \def\asluastring#1{'\luatexluaescapestring{\detokenize{#1}}'}
200
201 %%%%%%%% Redefine \/
202 \protected\def\/{\relax\directlua{luatexja.jfont.append_italic()}}
203
204 %%%%%%%% \jfont\CS={...:...;jfm=metric;...}, \globaljfont
205 \protected\def\jfont#1{%
206   \afterassignment\ltj@@jfont\directlua{luatexja.jfont.jfontdefX(false, 'yoko','\luatexluaescapestring{\noexpand#1}')}}
207 \protected\def\globaljfont#1{%
208   \afterassignment\ltj@@jfont\directlua{luatexja.jfont.jfontdefX(true,  'yoko','\luatexluaescapestring{\noexpand#1}')}}
209 \def\ltj@@jfont{\directlua{luatexja.jfont.jfontdefY()}}
210
211 %%%%%%%% \tfont\CS={...:...;jfm=metric;...}, \globaltfont
212 \protected\def\tfont#1{%
213   \afterassignment\ltj@@tfont\directlua{luatexja.jfont.jfontdefX(false, 'tate','\luatexluaescapestring{\noexpand#1}')}}
214 \protected\def\globaltfont#1{%
215   \afterassignment\ltj@@tfont\directlua{luatexja.jfont.jfontdefX(true,  'tate','\luatexluaescapestring{\noexpand#1}')}}
216 \def\ltj@@tfont{\directlua{luatexja.jfont.jfontdefY()}}
217
218 %%%%%%%% \zw, \zh
219 \protected\def\zw{\directlua{tex.setdimen('ltj@zw', luatexja.jfont.get_zw())}\ltj@zw}
220 \protected\def\zh{\directlua{tex.setdimen('ltj@zh', luatexja.jfont.get_zh())}\ltj@zh}
221
222 %%%%%%%% \inhibitglue
223 \protected\def\ltj@reset@globaldefs{%
224   \directlua{luatexja.global_temp = tex.globaldefs; tex.globaldefs = 0}}
225 \protected\def\ltj@restore@globaldefs{\directlua{tex.globaldefs = luatexja.global_temp}\relax}
226 \protected\def\inhibitglue{\ifhmode\ltj@@ihb\fi}
227 \def\ltj@@ihb{\relax\directlua{luatexja.jfmglue.create_inhibitglue_node()}}
228
229 %%%%%%%% \ltjdefcharrange<name>{100-200,3000-,5000,...}
230 \protected\def\ltjdefcharrange#1#2{%
231   {\ltj@tempcntc=#1 \expandafter\ltj@@dcrange#2,,}\ignorespaces}
232 \def\ltj@@dcrange#1,{\def\ltj@temp{#1}%
233   \ifx\ltj@temp\empty\let\@next=\relax\else
234   \ltj@@dcrangeA{#1}\let\@next=\ltj@@dcrange\fi\@next}
235 \def\ltj@@dcrangeA#1{\ltj@@dcrangeB#1--\@nil}
236 \def\ltj@@dcrangeB#1-#2-#3\@nil{\def\ltj@temp{#3}%
237   \ifx\ltj@temp\empty
238     \ltj@tempcnta=#1 \ltj@tempcntb=\ltj@tempcnta
239   \else
240     \def\ltj@temp{#1}%
241     \ifx\ltj@temp\empty\ltj@tempcnta='200\else\ltj@tempcnta=#1\fi\relax
242     \def\ltj@temp{#2}%
243     \ifx\ltj@temp\empty\ltj@tempcntb="10FFFF\else\ltj@tempcntb=#2\fi\relax%"
244   \fi
245   \directlua{luatexja.charrange.add_char_range(\the\ltj@tempcnta,\the\ltj@tempcntb,
246     \the\ltj@tempcntc)}%
247   }
248
249 %%%%%%%% \ltjsetparameter
250 \newcount\ltj@@stack \newcount\ltj@@group@level
251 \ltj@@group@level\z@\ltj@@stack\z@
252
253 \setbox\z@\hbox{%
254   \directlua{% This value depends on the version of LuaTeX.
255     luatexja.stack.hmode = -tex.nest[tex.nest.ptr].mode
256   }%
257 }
258 \setbox\z@\vbox{%
259   \directlua{% This value depends on the version of LuaTeX.
260     luatexja.stack.vmode = -tex.nest[tex.nest.ptr].mode
261   }%
262 }
263 \setbox\z@\box\voidb@x
264
265 % prebreakpenalty = {<char_code>, <penalty>}
266 \define@key[ltj]{japaram}{kcatcode}{\ltj@@set@stack{KCAT}{0}{0x7FFFFFFF}#1\relax}
267 \define@key[ltj]{japaram}{prebreakpenalty}{\ltj@@set@stack{PRE}{-10000}{10000}#1\relax}
268 \define@key[ltj]{japaram}{postbreakpenalty}{\ltj@@set@stack{POST}{-10000}{10000}#1\relax}
269 \def\ltj@@set@stack#1#2#3{%
270   \directlua{luatexja.stack.set_stack_perchar(luatexja.stack_table_index.#1,#2,#3)}}
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)}}
274
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\m@ne#2%
286   \ifnum\ltj@curjfnt=\m@ne
287     \@PackageError{luatexja-core}%
288     {\string#2 is not a control sequence that represents \MessageBreak
289      a Japanese font}{}%
290   \else
291     \directlua{luatexja.stack.set_stack_font(luatexja.stack_table_index.#3,
292     \ltj@safe@num@or{nil}{#1}, \the\ltj@curjfnt)}%
293   \fi
294   \ltj@curjfnt=\ltj@tempcnta
295   \ltj@restore@globaldefs
296   }
297
298 % {y,t}{ja,al}baselineshift = <dimen>
299 % yjabaselineshift = <dimen>
300 \define@key[ltj]{japaram}{yalbaselineshift}{%
301   \directlua{tex.setattribute(luatexja.isglobal,
302     luatexbase.attributes['ltj@yablshift'], luatexja.token.scan_dimen())}#1\relax}
303 \define@key[ltj]{japaram}{yjabaselineshift}{%
304   \directlua{tex.setattribute(luatexja.isglobal,
305     luatexbase.attributes['ltj@ykblshift'], luatexja.token.scan_dimen())}#1\relax}
306 \define@key[ltj]{japaram}{talbaselineshift}{%
307   \directlua{tex.setattribute(luatexja.isglobal,
308     luatexbase.attributes['ltj@tablshift'], luatexja.token.scan_dimen())}#1\relax}
309 \define@key[ltj]{japaram}{tjabaselineshift}{%
310   \directlua{tex.setattribute(luatexja.isglobal,
311     luatexbase.attributes['ltj@tkblshift'], luatexja.token.scan_dimen())}#1\relax}
312
313 % jaxspmode = {<char_code>, <mode>}
314 % mode: inhibit, preonly, postonly, allow
315 %    or       0        1         2      3
316 \define@key[ltj]{japaram}{jaxspmode}{%        \inhibitxspcode
317   \expandafter\ltj@set@jaxspmode#1:\relax}
318 \def\ltj@set@jaxspmode#1,#2:{%
319   \lowercase{\edef\ltj@temp{#2}}%
320   \def\ltj@tempa{inhibit}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{0}\fi
321   \def\ltj@tempa{preonly}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{1}\fi
322   \def\ltj@tempa{postonly}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{2}\fi
323   \def\ltj@tempa{allow}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{3}\fi
324   \ltj@@set@stack{XSP}03#1 \ltj@temp}
325
326 % alxspmode = {<char_code>, <mode>}
327 % mode: inhibit, preonly, postonly, allow
328 %    or       0        1         2      3
329 \define@key[ltj]{japaram}{alxspmode}{%        \inhibitxspcode
330   \expandafter\ltj@set@jaxspmode#1:\relax}% same code as jaxspmode
331
332 % autospacing = <bool> (default: true)
333 \define@boolkey[ltj]{japaram}{autospacing}[true]{%
334   \ifltj@japaram@autospacing
335     \directlua{luatexja.ext_print_global()}\ltj@autospc\@ne
336   \else
337     \directlua{luatexja.ext_print_global()}\ltj@autospc\z@
338   \fi}
339
340 % autoxspacing = <bool> (default: true)
341 \define@boolkey[ltj]{japaram}{autoxspacing}[true]{%
342   \ifltj@japaram@autoxspacing
343     \directlua{luatexja.ext_print_global()}\ltj@autoxspc\@ne
344   \else
345     \directlua{luatexja.ext_print_global()}\ltj@autoxspc\z@
346   \fi}
347
348 % [x]]kanjiskip = <skip>
349   \define@key[ltj]{japaram}{kanjiskip}{\ltjsetkanjiskip#1}
350   \define@key[ltj]{japaram}{xkanjiskip}{\ltjsetxkanjiskip#1}
351   \protected\def\ltjsetkanjiskip{%                  % SKIP
352     \directlua{%
353       local d = luatexja.token.scan_glue()
354       luatexja.stack.set_stack_skip(luatexja.stack_table_index.KSK, d); node.free(d)
355   }}
356   \protected\def\ltjsetxkanjiskip{%                  % SKIP
357     \directlua{%
358       local d = luatexja.token.scan_glue()
359       luatexja.stack.set_stack_skip(luatexja.stack_table_index.XSK, d); node.free(d)
360   }}
361
362 % jcharwidowpenalty = <count>
363 \define@key[ltj]{japaram}{jcharwidowpenalty}{%      %COUNT
364   \ltj@@set@stack{JWP}{-10000}{10000}\z@#1 }
365
366 % differentjfm = { large | small | average | pleft | pright | paverage | both}
367 \define@choicekey*+[ltj]{japaram}{differentjfm}[\ltj@temp\ltj@tempr]%
368   {large,small,average,pleft,pright,paverage,both}{%
369   \ifcase\ltj@tempr
370     \directlua{luatexja.jfmglue.diffmet_rule = math.max}\or
371     \directlua{luatexja.jfmglue.diffmet_rule = math.min}\or
372     \directlua{luatexja.jfmglue.diffmet_rule = math.two_average}\or
373     \directlua{luatexja.jfmglue.diffmet_rule = math.two_pleft}\or
374     \directlua{luatexja.jfmglue.diffmet_rule = math.two_pright}\or
375     \directlua{luatexja.jfmglue.diffmet_rule = math.two_paverage}\or
376     \directlua{luatexja.jfmglue.diffmet_rule = math.two_add}
377   \fi
378 }{\ltj@PackageError{luatexja}{invalid argument `#1' for `differentjfm'}{%
379   Argument for `differentjfm' must be one of `large', `small', `average',^^J%
380   `pleft', `pright', 'paverage' or `both'. }}
381   % large, small, average, pleft, pright, paverage, both
382
383
384 % jacharrange = { +-<range_number> }
385 \define@key[ltj]{japaram}{jacharrange}{\expandafter\ltj@@scrange#1,,}
386 \def\ltj@@scrange#1,{%
387   \edef\ltj@temp{#1}%
388   \ifx\ltj@temp\empty\let\next=\relax\else\let\next=\ltj@@scrange
389     \directlua{luatexja.charrange.toggle_char_range(%
390       luatexja.is_global,\ltj@safe@num@or{nil}{#1})}%
391   \fi\next
392 }
393
394 \protected\def\ltj@setpar@global{%
395   \relax\ifnum\globaldefs>0\directlua{luatexja.isglobal='global'}%
396     \else\directlua{luatexja.isglobal=''}\fi
397 }
398 \protected\def\ltjsetparameter#1{%
399   \directlua{luatexja.base.start_time_measure('set_par')}%
400   \ltj@setpar@global\setkeys[ltj]{japaram}{#1}%
401   \directlua{luatexja.base.stop_time_measure('set_par')}%
402   \ignorespaces}
403 \protected\def\ltjglobalsetparameter#1{%
404   \relax\ifnum\globaldefs<0\directlua{luatexja.isglobal=''}%
405     \else\directlua{luatexja.isglobal='global'}\fi%
406   \directlua{luatexja.base.start_time_measure('set_par')}%
407   \setkeys[ltj]{japaram}{#1}%
408   \directlua{luatexja.base.stop_time_measure('set_par')}%
409   \ignorespaces}
410
411 %%%%%%%% \ltjgetparameter
412 \def\ltj@@decl@array@param#1{%
413   \expandafter\let\csname ltj@@array@param/#1\endcsname=t%
414 }
415 \ltj@@decl@array@param{prebreakpenalty}
416 \ltj@@decl@array@param{postbreakpenalty}
417 \ltj@@decl@array@param{jaxspmode}
418 \ltj@@decl@array@param{alxspmode}
419 \ltj@@decl@array@param{kcatcode}
420 \ltj@@decl@array@param{jacharrange}
421 \ltj@@decl@array@param{chartorange}
422 \ltj@@decl@array@param{boxdir}
423 \def\ltjgetparameter#1{%
424   \directlua{luatexja.base.start_time_measure('get_par')}%
425   % stop call is moved in luatexja.lua
426   \ifcsname ltj@@array@param/#1\endcsname
427     \expandafter\ltx@firstoftwo
428   \else
429     \expandafter\ltx@secondoftwo
430   \fi
431   {\ltj@@getparam@two{#1}}%
432   {\ltj@@getparam@one{#1}}%
433 }
434 \def\ltj@@getparam@one#1{%
435   \directlua{luatexja.ext_get_parameter_unary('#1')}%
436 }%
437 \def\ltj@@getparam@two#1#2{%
438   \directlua{luatexja.ext_get_parameter_binary('#1', \ltj@safe@num@or{nil}{#2})}%
439 }
440
441 %%%%%%%% \ltjalchar<number>, \ltjjachar<number>
442 \let\ltj@@origchar=\char
443 \protected\def\ltj@alljachar{\relax
444     \csname ltj@kcat0\endcsname\z@
445     \csname ltj@kcat1\endcsname\z@
446     \csname ltj@kcat2\endcsname\z@
447     \csname ltj@kcat3\endcsname\z@
448     \csname ltj@kcat4\endcsname\z@
449     \csname ltj@kcat5\endcsname\z@
450     \csname ltj@kcat6\endcsname\z@}
451 \protected\def\ltj@allalchar{\relax
452     \csname ltj@kcat0\endcsname="7FFFFFFF %"
453     \csname ltj@kcat1\endcsname="7FFFFFFF %"
454     \csname ltj@kcat2\endcsname="7FFFFFFF %"
455     \csname ltj@kcat3\endcsname="7FFFFFFF %"
456     \csname ltj@kcat4\endcsname="7FFFFFFF %"
457     \csname ltj@kcat5\endcsname="7FFFFFFF %"
458     \csname ltj@kcat6\endcsname="7FFFFFFF }%"
459
460 \protected\def\ltjjachar{\afterassignment\ltj@@jachar\ltj@tempcnta}
461 \def\ltj@@jachar{{\directlua{tex.globaldefs=0}\ltj@alljachar\ltj@@origchar\ltj@tempcnta}}
462 \protected\def\ltjalchar{\afterassignment\ltj@@alchar\ltj@tempcnta}
463 \def\ltj@@alchar{{\directlua{tex.globaldefs=0}\ltj@allalchar\ltj@@origchar\ltj@tempcnta}}
464
465 %%%%%%%% \ltjsetmathletter<number>, \ltjunsetmathletter<number>
466 \protected\def\ltjsetmathletter#1{%
467   \directlua{luatexja.math.is_math_letters[luatexja.token.scan_int()]=true}#1\relax
468 }
469 \protected\def\ltjunsetmathletter#1{%
470   \directlua{luatexja.math.is_math_letters[luatexja.token.scan_int()]=false}#1\relax
471 }
472
473 %%%%%%%% \ltjdeclarealtfont<base_font_cs><alt_font_cs>{100-200,3000-,5000,...}
474 % <base_font_cs> の 第 3 引数の文字達は <alt_font_cs> で組む
475 % いつも global
476 \def\ltj@@getjfontnumber#1{% result in \ltj@tempcntc
477   \ltj@reset@globaldefs
478   \begingroup\ltj@curjfnt\m@ne\ltj@curtfnt\m@ne\relax
479   #1\directlua{luatexja.__temp = -(\the\ltj@curjfnt)*(\the\ltj@curtfnt)}\endgroup
480   \ltj@tempcntc=\directlua{tex.sprint(luatexja.__temp)}\relax
481   \ifnum\ltj@tempcntc=\m@ne
482     \@PackageError{luatexja-core}%
483     {\string#1 is not a control sequence that represents \MessageBreak
484      a Japanese font}{I'll use the current horizontal Japanese font instead.^^J}%
485     \ltj@tempcntc=\ltj@curjfnt
486   \fi\ltj@restore@globaldefs}
487
488 \protected\def\ltjdeclarealtfont#1#2#3{%
489   {\ltj@@getjfontnumber#1\@tempcnta=\ltj@tempcntc% \@tempcnta: 基底フォント
490    \ltj@@getjfontnumber#2%
491    \expandafter\ltj@@altfont#3,,}\ignorespaces}
492 \def\ltj@@altfont#1,{\def\ltj@temp{#1}%
493   \ifx\ltj@temp\empty\let\@next=\relax\else
494   \ltj@@altfontA{#1}\let\@next=\ltj@@altfont\fi\@next}
495 \def\ltj@@altfontA#1{\ltj@@altfontB#1--\@nil}
496 \def\ltj@@altfontB#1-#2-#3\@nil{\def\ltj@temp{#3}%
497   \ifx\ltj@temp\empty
498     \ltj@tempcnta=#1 \ltj@tempcntb=\ltj@tempcnta
499   \else
500     \def\ltj@temp{#1}%
501     \ifx\ltj@temp\empty\ltj@tempcnta='200\else\ltj@tempcnta=#1\fi\relax
502     \def\ltj@temp{#2}%
503     \ifx\ltj@temp\empty\ltj@tempcntb="10FFFF\else\ltj@tempcntb=#2\fi\relax%"
504   \fi
505   \directlua{luatexja.jfont.set_alt_font(
506     \the\ltj@tempcnta,\the\ltj@tempcntb,
507     \the\ltj@tempcntc, \the\@tempcnta)}%
508   }
509
510 %%%%%%%% \ltjclearaltfont<font_cs>
511 % <font_cs> の文字は全部 <font_cs> 本来の文字で組む
512 \protected\def\ltjclearaltfont#1{%
513   {\ltj@@getjfontnumber#1%
514    \directlua{luatexja.jfont.clear_alt_font(\the\ltj@tempcntc)}}\ignorespaces}
515
516
517 %%%%%%%% \yoko, \tate,\dtou
518 \protected\def\tate{%
519   \directlua{luatexja.direction.set_list_direction(3, 'tate')}%
520 }
521 \protected\def\yoko{%
522   \directlua{luatexja.direction.set_list_direction(4, 'yoko')}%
523 }
524 \protected\def\dtou{%
525   \directlua{luatexja.direction.set_list_direction(1, 'dtou')}%
526 }
527 \protected\def\utod{% 「縦数式ディレクション」
528   \directlua{luatexja.direction.set_list_direction(11, 'utod')}%
529 }
530 \define@key[ltj]{japaram}{direction}{%% always local
531   \directlua{luatexja.direction.set_list_direction(1, 'ltjsetparameter')}%
532 }
533
534 \yoko
535
536 %%%% insert
537 \let\orig@insert=\insert
538 \protected\def\insert{\begingroup\afterassignment\ltj@@insert@A\ltj@tempcnta}
539 \protected\def\ltj@@insert@A{\orig@insert\ltj@tempcnta\bgroup
540   \aftergroup\ltj@@insert@B\let\next}
541 \protected\def\ltj@@insert@B{\directlua{luatexja.direction.populate_insertion_dir_whatsit()}\endgroup}
542
543 %%%% vadjust
544 \let\ltj@@orig@vadjust=\vadjust
545 \protected\def\vadjust{%
546   \ltj@@orig@vadjust\bgroup
547   \directlua{luatexja.direction.set_list_direction_hook('adj')}%
548   \aftergroup\ltj@@vadjust@check@dir\let\next}
549 \protected\def\ltj@@vadjust@check@dir{%
550   \directlua{luatexja.direction.check_adjust_direction()}%
551 }
552
553 %%%% \hbox, \vbox, \vtop
554 \setbox\z@\hbox{%
555   $\directlua{% This value depends on the version of LuaTeX.
556     luatexja.stack.mmode = -tex.nest[tex.nest.ptr].mode
557   }$%
558 }
559 \setbox\z@\box\voidb@x
560 \ifltj@everyhook@avail% using everyhook package
561   \PushPreHook{hbox}{%
562     \directlua{luatexja.direction.set_list_direction_hook()}%
563     \aftergroup\ltj@@reset@badness
564   }
565   \PushPreHook{vbox}{%
566     \directlua{luatexja.direction.set_list_direction_hook()}%
567     \aftergroup\ltj@@reset@badness
568   }
569 \else
570   \let\ltj@@everyhbox=\everyhbox\let\ltj@@everyvbox=\everyvbox
571   \newtoks\ltj@@i@everyhbox\newtoks\ltj@@i@everyvbox
572   \let\everyhbox=\ltj@@i@everyhbox\let\everyvbox=\ltj@@i@everyvbox
573   \ltj@@everyhbox{%
574     \directlua{luatexja.direction.set_list_direction_hook()}%
575     \aftergroup\ltj@@reset@badness
576     \the\ltj@@i@everyhbox}
577   \ltj@@everyvbox{%
578     \directlua{luatexja.direction.set_list_direction_hook()}%
579     \aftergroup\ltj@@reset@badness
580     \the\ltj@@i@everyvbox}
581 \fi
582
583 \protected\def\ltj@@reset@badness{%
584   \directlua{%
585     if luatexja.global_temp then
586       tex.hbadness= tex.hbadness or luatexja.hbadness_temp
587       tex.vbadness= tex.vbadness or luatexja.vbadness_temp
588       tex.globaldefs= luatexja.global_temp or tex.globaldefs
589     end
590   }%
591 }
592 \AtBeginShipout{\directlua{luatexja.direction.finalize()}}
593
594 %%%% \raise, \lower, \moveleft, \moveright
595 \let\ltj@@orig@raise=\raise
596 \let\ltj@@orig@lower=\lower
597 \protected\def\raise{\ltj@reset@globaldefs\afterassignment\ltj@@raise\ltj@tempdima}
598 \protected\def\lower{\ltj@reset@globaldefs\afterassignment\ltj@@raise\ltj@tempdima-}
599 \protected\def\ltj@@raise{%
600   \ltj@restore@globaldefs
601   \edef\ltj@@raise@a{%
602     \noexpand\directlua{luatexja.direction.raise_box()}%
603     \ltj@@orig@raise\the\ltj@tempdima\noexpand\box\ltj@afbox
604   }\ltj@afterbox\ltj@@raise@a}
605 \let\ltj@@orig@moveleft=\moveleft
606 \let\ltj@@orig@moveright=\moveright
607 \protected\def\moveleft{\ltj@reset@globaldefs\afterassignment\ltj@@moveleft\ltj@tempdima}
608 \protected\def\moveright{\ltj@reset@globaldefs\afterassignment\ltj@@moveleft\ltj@tempdima-}
609 \protected\def\ltj@@moveleft{%
610   \ltj@restore@globaldefs
611   \edef\ltj@@moveleft@a{%
612     \noexpand\directlua{luatexja.direction.raise_box()}%
613     \ltj@@orig@moveleft\the\ltj@tempdima\noexpand\box\ltj@afbox
614   }\ltj@afterbox\ltj@@moveleft@a}
615
616 %%%% \vcenter
617 \let\ltj@@orig@vcenter=\vcenter
618 \protected\def\vcenter{\ltj@afterbox\ltj@@vcenter\vbox}
619 \protected\def\ltj@@vcenter{%
620   \directlua{luatexja.direction.raise_box()}%
621   \ltj@@orig@vcenter{\box\ltj@afbox}%
622 }
623
624 %%%% \unhbox and \unvbox
625 \long\def \@gobbletwo #1#2{}
626 \let\ltj@@orig@unhbox=\unhbox
627 \let\ltj@@orig@unvbox=\unvbox
628 \protected\def\unhbox{\ltj@reset@globaldefs\afterassignment\ltj@@unhbox\ltj@tempcnta}
629 \protected\def\unvbox{\ltj@reset@globaldefs\afterassignment\ltj@@unvbox\ltj@tempcnta}
630 \protected\def\ltj@@unhbox{%
631   \directlua{luatexja.direction.unbox_check_dir()}%
632   \ltj@@orig@unhbox\ltj@tempcnta}
633 \protected\def\ltj@@unvbox{%
634   \directlua{luatexja.direction.unbox_check_dir()}%
635   \ltj@@orig@unvbox\ltj@tempcnta}
636 \let\ltj@@orig@unhcopy=\unhcopy
637 \let\ltj@@orig@unvcopy=\unvcopy
638 \protected\def\unhcopy{\ltj@reset@globaldefs\afterassignment\ltj@@unhcopy\ltj@tempcnta}
639 \protected\def\unvcopy{\ltj@reset@globaldefs\afterassignment\ltj@@unvcopy\ltj@tempcnta}
640 \protected\def\ltj@@unhcopy{%
641   \directlua{luatexja.direction.unbox_check_dir(true)}%
642   \ltj@@orig@unhcopy\ltj@tempcnta
643   \directlua{luatexja.direction.uncopy_restore_whatsit()}}
644 \protected\def\ltj@@unvcopy{%
645   \directlua{luatexja.direction.unbox_check_dir(true)}%
646   \ltj@@orig@unvcopy\ltj@tempcnta
647   \directlua{luatexja.direction.uncopy_restore_whatsit()}}
648
649 %%%% lastbox
650 \let\ltj@@orig@lastbox=\lastbox
651 \protected\def\lastbox{%
652   \directlua{luatexja.direction.lastbox_hook()}\ltj@@orig@lastbox
653 }
654
655 %%%%%%%% \ltjgetwd<box_num> etc.
656 \def\ltj@@getwd{%
657   \directlua{luatexja.direction.get_box_dim('width', luatexja.token.scan_int())}}
658 \def\ltj@@getht{%
659   \directlua{luatexja.direction.get_box_dim('height', luatexja.token.scan_int())}}
660 \def\ltj@@getdp{%
661   \directlua{luatexja.direction.get_box_dim('depth', luatexja.token.scan_int())}}
662 \let\ltjgetwd=\ltj@@getwd\let\ltjgetht=\ltj@@getht\let\ltjgetdp=\ltj@@getdp
663
664 %%%%%%%% \ltjsetwd<box_num>=<dimen> etc.
665 \protected\def\ltjsetwd{\directlua{luatexja.direction.set_box_dim('width')}}
666 \protected\def\ltjsetht{\directlua{luatexja.direction.set_box_dim('height')}}
667 \protected\def\ltjsetdp{\directlua{luatexja.direction.set_box_dim('depth')}}
668
669 %%------------------ Load module for the format
670
671 \ifltj@in@latex                 %<*LaTeX>
672   \RequirePackage{ltj-latex}[2013/05/14]
673 \else\ifltj@in@plain            %<*plain>
674   \input ltj-plain.sty %
675 \fi\fi                          %</LaTeX|plain>
676
677 \newluatexcatcodetable\ltj@temp@cctb
678 \def\ltj@overwrite@catcodetable#1{%
679   \setluatexcatcodetable\ltj@temp@cctb{\luatexcatcodetable#1}%
680   \setluatexcatcodetable#1{\luatexcatcodetable\ltj@temp@cctb\catcode"FFFFF=14}%"
681 }
682 \ltj@overwrite@catcodetable\CatcodeTableLaTeX
683 \ltj@overwrite@catcodetable\CatcodeTableLaTeXAtLetter
684 \ltj@overwrite@catcodetable\CatcodeTableExpl
685
686
687 %%------------------ all done
688 \ltj@core@AtEnd
689 \endinput
690 %% EOF