OSDN Git Service

Fix \unhcopy etc. to remove extra dir whatsits.
[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}[2014/06/22 Core of LuaTeX-ja]
69 \fi                             %</LaTeX>
70
71 %% Load prerequisite packages.
72 \endlinechar=13 %
73 %! 外部パッケージは普通の \endlinechar で読まないと危険.
74 \ifltj@in@latex                 %<*LaTeX>
75   \RequirePackage{luaotfload} [2013/05/10] % v2.2
76   \RequirePackage{infwarerr}  [2010/04/08] % v1.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 \else                           %<*!LaTeX>
82   \input luaotfload.sty
83   \input infwarerr.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@autospc   % attribute for autospacing
141 \newluatexattribute\ltj@autoxspc  % attribute for autoxspacing
142 \newluatexattribute\ltj@yablshift % attribute for yalbaselineshift
143 \newluatexattribute\ltj@ykblshift % attribute for yjabaselineshift
144 \newluatexattribute\ltj@tablshift % attribute for talbaselineshift
145 \newluatexattribute\ltj@tkblshift % attribute for tjabaselineshift
146 \newluatexattribute\jfam          % index for current jfam
147
148 \newluatexattribute\ltj@dir
149
150 \ltj@dir=0
151 \ltj@icflag=0
152 \ltj@origchar=0
153 \ltj@charclass=0
154 \ltj@curjfnt=-1
155 \ltj@curtfnt=-1
156
157 %%%%%%%% Attributes for character ranges
158 \newcount\ltj@tempcnta
159 \ltj@tempcnta=0
160 \loop\ifnum\ltj@tempcnta<7
161   \expandafter\newluatexattribute%
162     \csname ltj@kcat\the\ltj@tempcnta\endcsname
163   \csname ltj@kcat\the\ltj@tempcnta\endcsname=0
164   \advance\ltj@tempcnta by1
165 \repeat
166
167
168 %%%%%%%% Loading luatexja.lua
169 %% Quark tokens needed in ltj-base
170 \protected\def\ltj@@q@escape{\ltj@@q@escape@}
171 \protected\def\ltj@@q@escapenum{\ltj@@q@escapenum@}
172
173 \directlua{%
174   luatexja = {}
175   dofile(assert(kpse.find_file('luatexja.lua', 'tex'),
176       "File `luatexja.lua' not found"))
177 }
178
179 %% \RequireLuaTeXjaSubmodule{name}[date]
180 % A TeX version of luatexja.load_module(name)
181 % The second optional argument [date] is simply ignored.
182 \def\RequireLuaTeXjaSubmodule#1{%
183   \@ifnextchar[{\ltj@requirelua@submod{#1}}{\ltj@requirelua@submod{#1}[]}}
184 \def\ltj@requirelua@submod#1[#2]{%
185   \directlua{luatexja.load_module(
186     "\luatexluaescapestring{#1}")}}
187
188
189 %%%%%%%% Load all sub-packages.
190 \ifltj@in@latex                 %<*LaTeX>
191   \RequirePackage{ltj-base}   [2013/05/14]
192 \else                           %<*!LaTeX>
193   \input ltj-base.sty %
194 \fi                             %</LaTeX>
195
196 %%%%%%%% \asluastring
197 \def\asluastring#1{'\luaescapestring{\detokenize{#1}}'}
198
199 %%%%%%%% Redefine \/
200 \protected\def\/{\relax\directlua{luatexja.jfont.append_italic()}}
201
202 %%%%%%%% \jfont\CS={...:...;jfm=metric;...}, \globaljfont
203 \protected\def\jfont{%
204   \afterassignment\ltj@@jfont\directlua{luatexja.jfont.jfontdefX(false)}}
205 \protected\def\globaljfont{%
206   \afterassignment\ltj@@jfont\directlua{luatexja.jfont.jfontdefX(true)}}
207 \def\ltj@@jfont{\directlua{luatexja.jfont.jfontdefY('yoko')}}
208
209 %%%%%%%% \tfont\CS={...:...;jfm=metric;...}, \globaltfont
210 \protected\def\tfont{\afterassignment\ltj@@tfont\directlua{luatexja.jfont.jfontdefX(false)}}
211 \protected\def\globaltfont{%
212   \afterassignment\ltj@@tfont\directlua{luatexja.jfont.jfontdefX(true)}}
213 \def\ltj@@tfont{\directlua{luatexja.jfont.jfontdefY('tate')}}
214
215
216 %%%%%%%% \zw, \zh
217 \protected\def\zw{\directlua{tex.setdimen('ltj@zw', luatexja.jfont.get_zw())}\ltj@zw}
218 \protected\def\zh{\directlua{tex.setdimen('ltj@zh', luatexja.jfont.get_zh())}\ltj@zh}
219
220 %%%%%%%% \inhibitglue
221 \protected\def\ltj@reset@globaldefs{%
222   \directlua{luatexja.global_temp = tex.globaldefs; tex.globaldefs = 0}}
223 \protected\def\ltj@restore@globaldefs{\directlua{tex.globaldefs = luatexja.global_temp}\relax}
224 \protected\def\inhibitglue{\ifhmode\ltj@@ihb\fi}
225 \def\ltj@@ihb{\relax\directlua{luatexja.jfmglue.create_inhibitglue_node()}}
226
227 %%%%%%%% \ltjdefcharrange<name>{100-200,3000-,5000,...}
228 \protected\def\ltjdefcharrange#1#2{%
229   {\ltj@tempcntc=#1 \expandafter\ltj@@dcrange#2,,}\ignorespaces}
230 \def\ltj@@dcrange#1,{\def\ltj@temp{#1}%
231   \ifx\ltj@temp\empty\let\@next=\relax\else
232   \ltj@@dcrangeA{#1}\let\@next=\ltj@@dcrange\fi\@next}
233 \def\ltj@@dcrangeA#1{\ltj@@dcrangeB#1--\@nil}
234 \def\ltj@@dcrangeB#1-#2-#3\@nil{\def\ltj@temp{#3}%
235   \ifx\ltj@temp\empty
236     \ltj@tempcnta=#1 \ltj@tempcntb=\ltj@tempcnta
237   \else
238     \def\ltj@temp{#1}%
239     \ifx\ltj@temp\empty\ltj@tempcnta='200\else\ltj@tempcnta=#1\fi\relax
240     \def\ltj@temp{#2}%
241     \ifx\ltj@temp\empty\ltj@tempcntb="10FFFF\else\ltj@tempcntb=#2\fi\relax%"
242   \fi
243   \directlua{luatexja.charrange.add_char_range(\the\ltj@tempcnta,\the\ltj@tempcntb,
244     \the\ltj@tempcntc)}%
245   }
246
247 %%%%%%%% \ltjsetparameter
248 \newcount\ltj@@stack \newcount\ltj@@group@level
249 \ltj@@group@level=0 \ltj@@stack=0
250
251 \setbox0\hbox{%
252   \directlua{% This value depends on the version of LuaTeX.
253     luatexja.stack.hmode = -tex.nest[tex.nest.ptr].mode
254   }%
255 }
256 \setbox0\vbox{%
257   \directlua{% This value depends on the version of LuaTeX.
258     luatexja.stack.vmode = -tex.nest[tex.nest.ptr].mode
259   }%
260 }
261
262 % prebreakpenalty = {<char_code>, <penalty>}
263 \define@key[ltj]{japaram}{kcatcode}{%
264   \expandafter\ltj@@set@stack#1:{KCAT}{0}{0x7FFFFFFF}}
265 \define@key[ltj]{japaram}{prebreakpenalty}{%
266   \expandafter\ltj@@set@stack#1:{PRE}{-10000}{10000}}
267 \define@key[ltj]{japaram}{postbreakpenalty}{%
268   \expandafter\ltj@@set@stack#1:{POST}{-10000}{10000}}
269 \def\ltj@@set@stack#1,#2:#3#4#5{%
270   \directlua{luatexja.stack.set_stack_perchar(luatexja.stack_table_index.#3,
271     \ltj@safe@num@or{nil}{#1},\ltj@safe@num@or{nil}{#2},#4,#5)}}
272
273 % jatextfont = {<char_code>, <font_cs>}
274 % only horizontal font is supported
275 \define@key[ltj]{japaram}{jatextfont}{%
276   \expandafter\ltj@@set@stackfont#1:{MJT}}
277 \define@key[ltj]{japaram}{jascriptfont}{%
278   \expandafter\ltj@@set@stackfont#1:{MJS}}
279 \define@key[ltj]{japaram}{jascriptscriptfont}{%
280   \expandafter\ltj@@set@stackfont#1:{MJSS}}
281 \protected\def\ltj@@set@stackfont#1,#2:#3{%
282   \ltj@reset@globaldefs
283   \ltj@tempcnta=\ltj@curjfnt\ltj@curjfnt=-1 #2%
284   \ifnum\ltj@curjfnt=-1
285     \@PackageError{luatexja-core}%
286     {\string#2 is not a control sequence that represents \MessageBreak
287      a Japanese font}{}%
288   \else
289     \directlua{luatexja.stack.set_stack_font(luatexja.stack_table_index.#3,
290     \ltj@safe@num@or{nil}{#1}, \the\ltj@curjfnt)}%
291   \fi
292   \ltj@curjfnt=\ltj@tempcnta
293   \ltj@restore@globaldefs
294   }
295
296 % yalbaselineshift = <dimen>
297 % yjabaselineshift = <dimen>
298 \define@key[ltj]{japaram}{yalbaselineshift}{%
299   \directlua{tex.setattribute(luatexja.isglobal,
300     luatexbase.attributes['ltj@yablshift'],
301     \ltj@safe@dimen@or\ltj@defdimen{#1})}}
302 \define@key[ltj]{japaram}{yjabaselineshift}{%
303   \directlua{tex.setattribute(luatexja.isglobal,
304     luatexbase.attributes['ltj@ykblshift'],
305     \ltj@safe@dimen@or\ltj@defdimen{#1})}}
306 % talbaselineshift = <dimen>
307 % tjabaselineshift = <dimen>
308 \define@key[ltj]{japaram}{talbaselineshift}{%
309   \directlua{tex.setattribute(luatexja.isglobal,
310     luatexbase.attributes['ltj@tablshift'],
311     \ltj@safe@dimen@or\ltj@defdimen{#1})}}
312 \define@key[ltj]{japaram}{tjabaselineshift}{%
313   \directlua{tex.setattribute(luatexja.isglobal,
314     luatexbase.attributes['ltj@tkblshift'],
315     \ltj@safe@dimen@or\ltj@defdimen{#1})}}
316
317 % jaxspmode = {<char_code>, <mode>}
318 % mode: inhibit, preonly, postonly, allow
319 %    or       0        1         2      3
320 \define@key[ltj]{japaram}{jaxspmode}{%        \inhibitxspcode
321   \expandafter\ltj@set@jaxspmode#1:\relax}
322 \def\ltj@set@jaxspmode#1,#2:{%
323   \lowercase{\edef\ltj@temp{#2}}%
324   \def\ltj@tempa{inhibit}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{0}\fi
325   \def\ltj@tempa{preonly}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{1}\fi
326   \def\ltj@tempa{postonly}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{2}\fi
327   \def\ltj@tempa{allow}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{3}\fi
328   \directlua{luatexja.stack.set_stack_perchar(luatexja.stack_table_index.XSP,
329     \ltj@safe@num@or{nil}{#1},
330     \ltj@safe@num@or{nil}{\ltj@temp},0,3)}}
331
332 % alxspmode = {<char_code>, <mode>}
333 % mode: inhibit, preonly, postonly, allow
334 %    or       0        1         2      3
335 \define@key[ltj]{japaram}{alxspmode}{%        \inhibitxspcode
336   \expandafter\ltj@set@alxspmode#1:\relax}
337 \def\ltj@set@alxspmode#1,#2:{%
338   \lowercase{\edef\ltj@temp{#2}}%
339   \def\ltj@tempa{inhibit}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{0}\fi
340   \def\ltj@tempa{preonly}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{1}\fi
341   \def\ltj@tempa{postonly}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{2}\fi
342   \def\ltj@tempa{allow}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{3}\fi
343   \directlua{luatexja.stack.set_stack_perchar(luatexja.stack_table_index.XSP,
344     \ltj@safe@num@or{nil}{#1},
345     \ltj@safe@num@or{nil}{\ltj@temp},0,3)}}
346
347 % autospacing = <bool> (default: true)
348 \define@boolkey[ltj]{japaram}{autospacing}[true]{%
349   \ifltj@japaram@autospacing
350     \directlua{luatexja.ext_print_global()}\ltj@autospc=1
351   \else
352     \directlua{luatexja.ext_print_global()}\ltj@autospc=0
353   \fi}
354
355 % autoxspacing = <bool> (default: true)
356 \define@boolkey[ltj]{japaram}{autoxspacing}[true]{%
357   \ifltj@japaram@autoxspacing
358     \directlua{luatexja.ext_print_global()}\ltj@autoxspc=1
359   \else
360     \directlua{luatexja.ext_print_global()}\ltj@autoxspc=0
361   \fi}
362
363 % [x]]kanjiskip = <dimen>
364 \define@key[ltj]{japaram}{kanjiskip}{\ltjsetkanjiskip{#1}}
365 \define@key[ltj]{japaram}{xkanjiskip}{\ltjsetxkanjiskip{#1}}
366 \protected\def\ltjsetkanjiskip#1{%                  % SKIP
367   \directlua{%
368     local d = \ltj@safe@glue{#1}
369     luatexja.stack.set_stack_skip(luatexja.stack_table_index.KSK, d); node.free(d)
370 }\ignorespaces}
371 \protected\def\ltjsetxkanjiskip#1{%                  % SKIP
372   \directlua{%
373     local d = \ltj@safe@glue{#1}
374     luatexja.stack.set_stack_skip(luatexja.stack_table_index.XSK, d); node.free(d)
375 }\ignorespaces}
376
377
378 % jcharwidowpenalty = <count>
379 \define@key[ltj]{japaram}{jcharwidowpenalty}{%      %COUNT
380   \ltj@@set@stack0,#1:{JWP}{-10000}{10000}}
381
382 % differentjfm = { large | small | average | pleft | pright | paverage | both}
383 \define@choicekey*+[ltj]{japaram}{differentjfm}[\ltj@temp\ltj@tempr]%
384   {large,small,average,pleft,pright,paverage,both}{%
385   \ifcase\ltj@tempr
386     \directlua{luatexja.jfmglue.diffmet_rule = math.max}\or
387     \directlua{luatexja.jfmglue.diffmet_rule = math.min}\or
388     \directlua{luatexja.jfmglue.diffmet_rule = math.two_average}\or
389     \directlua{luatexja.jfmglue.diffmet_rule = math.two_pleft}\or
390     \directlua{luatexja.jfmglue.diffmet_rule = math.two_pright}\or
391     \directlua{luatexja.jfmglue.diffmet_rule = math.two_paverage}\or
392     \directlua{luatexja.jfmglue.diffmet_rule = math.two_add}
393   \fi
394 }{\ltj@PackageError{luatexja}{invalid argument `#1' for `differentjfm'}{%
395   Argument for `differentjfm' must be one of `large', `small', `average',^^J%
396   `pleft', `pright', 'paverage' or `both'. }}
397   % large, small, average, pleft, pright, paverage, both
398
399
400 % jacharrange = { +-<range_number> }
401 \define@key[ltj]{japaram}{jacharrange}{\expandafter\ltj@@scrange#1,,}
402 \def\ltj@@scrange#1,{%
403   \edef\ltj@temp{#1}%
404   \ifx\ltj@temp\empty\let\next=\relax\else\let\next=\ltj@@scrange
405     \directlua{luatexja.charrange.toggle_char_range(%
406       luatexja.is_global,\ltj@safe@num@or{nil}{#1})}%
407   \fi\next
408 }
409
410 \protected\def\ltj@setpar@global{%
411   \relax\ifnum\globaldefs>0\directlua{luatexja.isglobal='global'}%
412     \else\directlua{luatexja.isglobal=''}\fi
413 }
414 \protected\def\ltjsetparameter#1{%
415   \directlua{luatexja.base.start_time_measure('set_par')}%
416   \ltj@setpar@global\setkeys[ltj]{japaram}{#1}%
417   \directlua{luatexja.base.stop_time_measure('set_par')}%
418   \ignorespaces}
419 \protected\def\ltjglobalsetparameter#1{%
420   \relax\ifnum\globaldefs<0\directlua{luatexja.isglobal=''}%
421     \else\directlua{luatexja.isglobal='global'}\fi%
422   \directlua{luatexja.base.start_time_measure('set_par')}%
423   \setkeys[ltj]{japaram}{#1}%
424   \directlua{luatexja.base.stop_time_measure('set_par')}%
425   \ignorespaces}
426
427 %%%%%%%% \ltjgetparameter
428 \def\ltj@@decl@array@param#1{%
429   \expandafter\let\csname ltj@@array@param/#1\endcsname=t%
430 }
431 \ltj@@decl@array@param{prebreakpenalty}
432 \ltj@@decl@array@param{postbreakpenalty}
433 \ltj@@decl@array@param{jaxspmode}
434 \ltj@@decl@array@param{alxspmode}
435 \ltj@@decl@array@param{kcatcode}
436 \ltj@@decl@array@param{jacharrange}
437 \ltj@@decl@array@param{chartorange}
438 \ltj@@decl@array@param{boxdir}
439 \def\ltjgetparameter#1{%
440   \directlua{luatexja.base.start_time_measure('get_par')}%
441   \ifcsname ltj@@array@param/#1\endcsname
442     \expandafter\ltx@firstoftwo
443   \else
444     \expandafter\ltx@secondoftwo
445   \fi
446   {\ltj@@getparam@two{#1}}%
447   {\ltj@@getparam@one{#1}}%
448 }
449 \def\ltj@@getparam@one#1{%
450   \directlua{luatexja.ext_get_parameter_unary('#1')}%
451   \directlua{luatexja.base.stop_time_measure('get_par')}%
452 }%
453 \def\ltj@@getparam@two#1#2{%
454   \directlua{luatexja.ext_get_parameter_binary('#1', \ltj@safe@num@or{nil}{#2})}%
455   \directlua{luatexja.base.stop_time_measure('get_par')}%
456 }
457
458 %%%%%%%% \ltjalchar<number>, \ltjjachar<number>
459 \let\ltj@@origchar=\char
460 \protected\def\ltj@alljachar{\relax
461     \csname ltj@kcat0\endcsname=0
462     \csname ltj@kcat1\endcsname=0
463     \csname ltj@kcat2\endcsname=0
464     \csname ltj@kcat3\endcsname=0
465     \csname ltj@kcat4\endcsname=0
466     \csname ltj@kcat5\endcsname=0
467     \csname ltj@kcat6\endcsname=0 }
468 \protected\def\ltj@allalchar{\relax
469     \csname ltj@kcat0\endcsname="7FFFFFFF %"
470     \csname ltj@kcat1\endcsname="7FFFFFFF %"
471     \csname ltj@kcat2\endcsname="7FFFFFFF %"
472     \csname ltj@kcat3\endcsname="7FFFFFFF %"
473     \csname ltj@kcat4\endcsname="7FFFFFFF %"
474     \csname ltj@kcat5\endcsname="7FFFFFFF %"
475     \csname ltj@kcat6\endcsname="7FFFFFFF }%"
476
477 \protected\def\ltjjachar{\afterassignment\ltj@@jachar\ltj@tempcnta}
478 \def\ltj@@jachar{{\directlua{tex.globaldefs = 0}\ltj@alljachar\ltj@@origchar\ltj@tempcnta}}
479 \protected\def\ltjalchar{\afterassignment\ltj@@alchar\ltj@tempcnta}
480 \def\ltj@@alchar{{\directlua{tex.globaldefs = 0}\ltj@allalchar\ltj@@origchar\ltj@tempcnta}}
481
482 %%%%%%%% \ltjsetmathletter<number>, \ltjunsetmathletter<number>
483 \protected\def\ltjsetmathletter#1{%
484   \ltj@tempcnta=#1
485   \directlua{luatexja.math.is_math_letters[\the\ltj@tempcnta]=true}%
486 }
487 \protected\def\ltjunsetmathletter#1{%
488   \ltj@tempcnta=#1
489   \directlua{luatexja.math.is_math_letters[\the\ltj@tempcnta]=false}%
490 }
491
492 %%%%%%%% \ltjdeclarealtfont<base_font_cs><alt_font_cs>{100-200,3000-,5000,...}
493 % <base_font_cs> の 第 3 引数の文字達は <alt_font_cs> で組む
494 % いつも global
495 \def\ltj@@getjfontnumber#1{% result in \ltj@tempcntc
496   \ltj@reset@globaldefs
497   \begingroup\ltj@curjfnt=-1 \ltj@curtfnt=-1\relax
498   #1\directlua{luatexja.__temp = -(\the\ltj@curjfnt)*(\the\ltj@curtfnt)}\endgroup
499   \ltj@tempcntc=\directlua{tex.sprint(luatexja.__temp)}\relax
500   \ifnum\ltj@tempcntc=-1
501     \@PackageError{luatexja-core}%
502     {\string#1 is not a control sequence that represents \MessageBreak
503      a Japanese font}{I'll use the current horizontal Japanese font instead.^^J}%
504     \ltj@tempcntc=\ltj@curjfnt
505   \fi\ltj@restore@globaldefs}
506
507 \protected\def\ltjdeclarealtfont#1#2#3{%
508   {\ltj@@getjfontnumber#1\@tempcnta=\ltj@tempcntc% \@tempcnta: 基底フォント
509    \ltj@@getjfontnumber#2%
510    \expandafter\ltj@@altfont#3,,}\ignorespaces}
511 \def\ltj@@altfont#1,{\def\ltj@temp{#1}%
512   \ifx\ltj@temp\empty\let\@next=\relax\else
513   \ltj@@altfontA{#1}\let\@next=\ltj@@altfont\fi\@next}
514 \def\ltj@@altfontA#1{\ltj@@altfontB#1--\@nil}
515 \def\ltj@@altfontB#1-#2-#3\@nil{\def\ltj@temp{#3}%
516   \ifx\ltj@temp\empty
517     \ltj@tempcnta=#1 \ltj@tempcntb=\ltj@tempcnta
518   \else
519     \def\ltj@temp{#1}%
520     \ifx\ltj@temp\empty\ltj@tempcnta='200\else\ltj@tempcnta=#1\fi\relax
521     \def\ltj@temp{#2}%
522     \ifx\ltj@temp\empty\ltj@tempcntb="10FFFF\else\ltj@tempcntb=#2\fi\relax%"
523   \fi
524   \directlua{luatexja.jfont.set_alt_font(
525     \the\ltj@tempcnta,\the\ltj@tempcntb,
526     \the\ltj@tempcntc, \the\@tempcnta)}%
527   }
528
529 %%%%%%%% \ltjclearaltfont<font_cs>
530 % <font_cs> の文字は全部 <font_cs> 本来の文字で組む
531 \protected\def\ltjclearaltfont#1{%
532   {\ltj@@getjfontnumber#1%
533    \directlua{luatexja.jfont.clear_alt_font(\the\ltj@tempcntc)}}\ignorespaces}
534
535
536 %%%%%%%% \yoko, \tate,\dtou
537 \protected\def\tate{%
538   \directlua{luatexja.direction.set_list_direction(3, 'tate')}%
539 }
540 \protected\def\yoko{%
541   \directlua{luatexja.direction.set_list_direction(4, 'yoko')}%
542 }
543 \protected\def\dtou{%
544   \directlua{luatexja.direction.set_list_direction(1, 'dtou')}%
545 }
546 \protected\def\utod{% 「縦数式ディレクション」
547   \directlua{luatexja.direction.set_list_direction(11, 'utod')}%
548 }
549 \define@key[ltj]{japaram}{direction}{%% always local
550   \directlua{luatexja.direction.set_list_direction(1, 'ltjsetparameter')}%
551 }
552
553 \yoko
554
555 %%%% insert
556 %\let\orig@insert=\insert
557 %\protected\def\insert{\begingroup\afterassignment\ltj@@insert@A\ltj@tempcnta}
558 %\protected\def\ltj@@insert@A{\orig@insert\ltj@tempcnta\bgroup\aftergroup\endgroup\let\next}
559 %%%% vadjust
560 \let\ltj@@orig@vadjust=\vadjust
561 \protected\def\vadjust{%
562   \ltj@@orig@vadjust\bgroup
563   \directlua{luatexja.direction.set_list_direction('adj')}%
564   \aftergroup\ltj@@vadjust@check@dir\let\next}
565 \protected\def\ltj@@vadjust@check@dir{%
566   \directlua{luatexja.direction.check_adjust_direction()}%
567 }
568
569 %%%% \hbox, \vbox, \vtop
570 \everyhbox{%
571   \directlua{luatexja.direction.set_list_direction()}%
572   \aftergroup\ltj@@reset@badness
573 }
574 \everyvbox{%
575   \directlua{luatexja.direction.set_list_direction()}%
576   \aftergroup\ltj@@reset@badness
577 }
578 \protected\def\ltj@@reset@badness{%
579   \directlua{%
580     if luatexja.global_temp then
581       tex.hbadness= tex.hbadness or luatexja.hbadness_temp
582       tex.vbadness= tex.vbadness or luatexja.vbadness_temp
583       tex.globaldefs= luatexja.global_temp or tex.globaldefs
584     end
585   }%
586 }
587 \setbox0\hbox{%
588   $\directlua{% This value depends on the version of LuaTeX.
589     luatexja.stack.mmode = -tex.nest[tex.nest.ptr].mode
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
650 %%%% lastbox
651 \let\ltj@@orig@lastbox=\lastbox
652 \protected\def\lastbox{%
653   \directlua{luatexja.direction.lastbox_hook()}\ltj@@orig@lastbox
654 }
655
656 %%%%%%%% \ltjgetwd<box_num> etc.
657 \def\ltj@@getwd#1{%
658   \directlua{luatexja.direction.get_box_dim('width', \the\numexpr#1\relax)}%
659   \ltj@tempdima%
660 }
661 \def\ltj@@getht#1{%
662   \directlua{luatexja.direction.get_box_dim('height', \the\numexpr#1\relax)}%
663   \ltj@tempdima%
664 }
665 \def\ltj@@getdp#1{%
666   \directlua{luatexja.direction.get_box_dim('depth', \the\numexpr#1\relax)}%
667   \ltj@tempdima%
668 }
669 \let\ltjgetwd=\ltj@@getwd\let\ltjgetht=\ltj@@getht\let\ltjgetdp=\ltj@@getdp
670
671 %%%%%%%% \ltjsetwd<box_num>=<dimen> etc.
672 \protected\def\ltjsetwd{\begingroup
673   \ltj@reset@globaldefs\afterassignment\ltj@@setwd@a\ltj@tempcnta}
674 \def\ltj@@setwd@a{\afterassignment\ltj@@setwd@b\ltj@tempdima}
675 \def\ltj@@setwd@b{%
676   \directlua{luatexja.direction.set_box_dim('width')}%
677   \ltj@restore@globaldefs\endgroup}
678 \protected\def\ltjsetht{\begingroup
679   \ltj@reset@globaldefs\afterassignment\ltj@@setht@a\ltj@tempcnta}
680 \def\ltj@@setht@a{\afterassignment\ltj@@setht@b\ltj@tempdima}
681 \def\ltj@@setht@b{%
682   \directlua{luatexja.direction.set_box_dim('height')}%
683   \ltj@restore@globaldefs\endgroup}
684 \protected\def\ltjsetdp{\begingroup
685   \ltj@reset@globaldefs\afterassignment\ltj@@setdp@a\ltj@tempcnta}
686 \def\ltj@@setdp@a{\afterassignment\ltj@@setdp@b\ltj@tempdima}
687 \def\ltj@@setdp@b{%
688   \directlua{luatexja.direction.set_box_dim('depth')}%
689   \ltj@restore@globaldefs\endgroup}
690
691
692 %%------------------ Load module for the format
693
694 \ifltj@in@latex                 %<*LaTeX>
695   \RequirePackage{ltj-latex}[2013/05/14]
696 \else\ifltj@in@plain            %<*plain>
697   \input ltj-plain.sty %
698 \fi\fi                          %</LaTeX|plain>
699
700 \newluatexcatcodetable\ltj@temp@cctb
701 \def\ltj@overwrite@catcodetable#1{%
702   \setluatexcatcodetable\ltj@temp@cctb{\luatexcatcodetable#1}%
703   \setluatexcatcodetable#1{\luatexcatcodetable\ltj@temp@cctb\catcode"FFFFF=14}%"
704 }
705 \ltj@overwrite@catcodetable\CatcodeTableLaTeX
706 \ltj@overwrite@catcodetable\CatcodeTableLaTeXAtLetter
707 \ltj@overwrite@catcodetable\CatcodeTableExpl
708
709
710 %%------------------ all done
711 \ltj@core@AtEnd
712 \endinput
713 %% EOF