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}[2011/04/01 v0.1]
71 %% Load prerequisite packages.
72 %! 参考: W32TeX の LuaTeX
73 %! 2010/11/27 v0.65.0 r3988 (LuaTeX-ja の最低要件)
74 %! 2010/07/10 v0.60.2 r3735 (TL2010 とほぼ同じ)
76 %! 外部パッケージは普通の \endlinechar で読まないと危険.
77 \ifltj@in@latex %<*LaTeX>
78 \RequirePackage{luaotfload} [2010/11/11] % v1.21
79 \RequirePackage{infwarerr} [2010/04/08] % v1.3
80 \RequirePackage{ltxcmds} [2010/04/26] % v1.7
81 \RequirePackage{pdftexcmds} [2010/04/01] % v0.9
82 \RequirePackage{xkeyval} [2008/08/13] % v2.6a
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<65
101 \@PackageError{luatexja-core}
102 {This LuaTeX engine is too old for this package;\MessageBreak
103 at least v0.65 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 %% Load all sub-packages.
118 \ifltj@in@latex %<*LaTeX>
119 \RequirePackage{luatexja-cctbreg}[2011/04/01]
120 \RequirePackage{luatexja-base}[2011/04/01]
122 \input luatexja-cctbreg.sty %
123 \input luatexja-base.sty %
128 %! この中に master の luatexja-core.sty の内容を挿入する
130 % LuaTeX-ja core TeX source
134 \def\ltj@loaded{hoge}
136 \newcount\ltj@tempcnta
137 \newcount\ltj@tempcntb
138 \newcount\ltj@tempcntc
139 \newdimen\ltj@tempdima
140 \newskip\ltj@tempskipa
144 \newdimen\jQ \jQ=0.25mm
145 \newdimen\jH \jH=0.25mm
147 %%%%%%%% error message
152 %%%%%%%% Attributes for Japanese typesetting.
153 \newluatexattribute\ltj@curjfnt % index for ``current Japanese font''
154 \newluatexattribute\jfam % index for current jfam
155 \newluatexattribute\ltj@charclass %
156 \newluatexattribute\ltj@yablshift % attribute for \yabaselineshift
157 \newluatexattribute\ltj@ykblshift % attribute for \ykbaselineshift
158 \newluatexattribute\ltj@autospc % attribute for autospacing
159 \newluatexattribute\ltj@autoxspc % attribute for autoxspacing
160 \newluatexattribute\ltj@icflag % attribute for italic correction
161 \newlanguage\ltj@japanese
163 %%%%%%%% Loading lua files
167 function ltj.loadlua(file)
168 local path = assert(kpse.find_file(file, 'tex'),
169 "File '"..file.."' not found")
170 texio.write_nl("("..path..")")
173 ltj.loadlua('luatexja-core.lua')
177 %%%%%%%% Attributes for character ranges
179 \loop\ifnum\ltj@tempcnta<7
180 \expandafter\newluatexattribute%
181 \csname ltj@kcat\the\ltj@tempcnta\endcsname
182 \csname ltj@kcat\the\ltj@tempcnta\endcsname=0
183 \advance\ltj@tempcnta by1
186 %%%%%%%% \asluastring
187 \def\asluastring#1{'\luaescapestring{\detokenize{#1}}'}
190 %\let\ltj@ic=\/ \protected\def\/{{\ltj@icflag=1\ltj@ic}}
191 \protected\def\/{\directlua{luatexja.jfont.append_italic()}}
193 %%%%%%%% \jfont\CS={...:...;jfm=metric;...}, \globaljfont
194 \protected\def\jfont{\afterassignment\ltj@@jfont\directlua{luatexja.jfont.jfontdefX(false)}}
195 \protected\def\globaljfont{%
196 \afterassignment\ltj@@jfont\directlua{luatexja.jfont.jfontdefX(true)}}
197 \def\ltj@@jfont{\directlua{luatexja.jfont.jfontdefY()}}
199 \def\zw{\directlua{luatexja.jfont.load_zw()}\ltj@zw}
200 \def\zh{\directlua{luatexja.jfont.load_zh()}\ltj@zh}
202 %%%%%%%% \inhibitglue
203 \protected\def\inhibitglue{\ifvmode\leavevmode\fi
204 \ifmmode\else\directlua{luatexja.jfmglue.create_inhibitglue_node()}\fi}
206 %%%%%%%% \yoko, \tate, \ifydir, \iftdir
207 %% At this moment, tategaki mode is not implemented;
208 %% there is only yokogaki mode now.
211 \newif\ifydir\ydirtrue
212 \newif\iftdir\tdirfalse
214 %%%%%%%% \ltjdefcharrange<name>{100-200,3000-,5000,...}
215 \protected\def\ltjdefcharrange#1#2{%
216 {\ltj@tempcntc=#1 \expandafter\ltj@@dcrange#2,,}\ignorespaces}
217 \def\ltj@@dcrange#1,{\def\ltj@temp{#1}%
218 \ifx\ltj@temp\empty\let\@next=\relax\else
219 \ltj@@dcrangeA{#1}\let\@next=\ltj@@dcrange\fi\@next}
220 \def\ltj@@dcrangeA#1{\ltj@@dcrangeB#1--\@nil}
221 \def\ltj@@dcrangeB#1-#2-#3\@nil{\def\ltj@temp{#3}%
223 \ltj@tempcnta=#1 \ltj@tempcntb=\ltj@tempcnta
226 \ifx\ltj@temp\empty\ltj@tempcnta='200\else\ltj@tempcnta=#1\fi\relax
228 \ifx\ltj@temp\empty\ltj@tempcntb="10FFFF\else\ltj@tempcntb=#2\fi\relax%"
230 \directlua{luatexja.charrange.add_char_range(\the\ltj@tempcnta,\the\ltj@tempcntb,
234 %%%%%%%% \ltjsetparameter
235 \newcount\ltj@@stack \newcount\ltj@@group@level
236 \ltj@@group@level=0 \ltj@@stack=0
238 % prebreakpenalty = {<char_code>, <penalty>}
239 \define@key[ltj]{japaram}{kcatcode}{%
240 \expandafter\ltj@@set@stack#1:{kcat}{0}{0x7FFFFFFF}}
241 \define@key[ltj]{japaram}{prebreakpenalty}{%
242 \expandafter\ltj@@set@stack#1:{pre}{-10000}{10000}}
243 \define@key[ltj]{japaram}{postbreakpenalty}{%
244 \expandafter\ltj@@set@stack#1:{post}{-10000}{10000}}
245 \def\ltj@@set@stack#1,#2:#3#4#5{%
246 \directlua{luatexja.stack.set_stack_table(ltj.isglobal, \asluastring{#3},
247 \ltj@safe@num@or\ltj@defnum{#1},\ltj@safe@num@or\ltj@defnum{#2},#4,#5)}}
249 % jatextfont = {<char_code>, <font_cs>}
250 \define@key[ltj]{japaram}{jatextfont}{%
251 \expandafter\ltj@@set@stackfont#1:{mjtext}}
252 \define@key[ltj]{japaram}{jascriptfont}{%
253 \expandafter\ltj@@set@stackfont#1:{mjscr}}
254 \define@key[ltj]{japaram}{jascriptscriptfont}{%
255 \expandafter\ltj@@set@stackfont#1:{mjss}}
256 \def\ltj@@set@stackfont#1,#2:#3{%
258 ltj.global_temp = tex.globaldefs;
260 \ltj@tempcnta=\ltj@curjfnt\ltj@curjfnt=-1 #2%
261 \ifnum\ltj@curjfnt=-1
262 \@PackageError{luatexja-core}%
263 {\string#2 is not a control sequence that represents \MessageBreak
266 \directlua{luatexja.stack.set_stack_font(ltj.isglobal, \asluastring{#3},
267 \ltj@safe@num@or\ltj@defnum{#1}, \the\ltj@curjfnt)}%
269 \ltj@curjfnt=\ltj@tempcnta
270 \directlua{tex.globaldefs = ltj.global_temp}%
273 % yalbaselineshift = <dimen>
274 % yjabaselineshift = <dimen>
275 \define@key[ltj]{japaram}{yalbaselineshift}{%
276 \directlua{tex.setattribute(ltj.isglobal,
277 luatexbase.attributes['ltj@yablshift'],
278 \ltj@safe@dimen@or\ltj@defdimen{#1})}}
279 \define@key[ltj]{japaram}{yjabaselineshift}{%
280 \directlua{tex.setattribute(ltj.isglobal,
281 luatexbase.attributes['ltj@ykblshift'],
282 \ltj@safe@dimen@or\ltj@defdimen{#1})}}
284 % jaxspmode = {<char_code>, <mode>}
285 % mode: inhibit, preonly, postonly, allow
287 \define@key[ltj]{japaram}{jaxspmode}{% \inhibitxspcode
288 \expandafter\ltj@set@jaxspmode#1:\relax}
289 \def\ltj@set@jaxspmode#1,#2:{%
290 \lowercase{\edef\ltj@temp{#2}}%
291 \def\ltj@tempa{inhibit}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{0}\fi
292 \def\ltj@tempa{preonly}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{2}\fi
293 \def\ltj@tempa{postonly}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{1}\fi
294 \def\ltj@tempa{allow}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{3}\fi
295 \directlua{luatexja.stack.set_stack_table(ltj.isglobal, 'xsp',
296 \ltj@safe@num@or\ltj@defnum{#1},
297 \ltj@safe@num@or\ltj@defnum{\ltj@temp},0,3)}}
299 % alxspmode = {<char_code>, <mode>}
300 % mode: inhibit, preonly, postonly, allow
302 \define@key[ltj]{japaram}{alxspmode}{% \inhibitxspcode
303 \expandafter\ltj@set@alxspmode#1:\relax}
304 \def\ltj@set@alxspmode#1,#2:{%
305 \lowercase{\edef\ltj@temp{#2}}%
306 \def\ltj@tempa{inhibit}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{0}\fi
307 \def\ltj@tempa{preonly}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{1}\fi
308 \def\ltj@tempa{postonly}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{2}\fi
309 \def\ltj@tempa{allow}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{3}\fi
310 \directlua{luatexja.stack.set_stack_table(ltj.isglobal, 'xsp',
311 \ltj@safe@num@or\ltj@defnum{#1},
312 \ltj@safe@num@or\ltj@defnum{\ltj@temp},0,3)}}
314 % autospacing = <bool> (default: true)
315 \define@boolkey[ltj]{japaram}{autospacing}[true]{%
316 \ifltj@japaram@autospacing
317 \directlua{ltj.ext_print_global()}\ltj@autospc=1
319 \directlua{ltj.ext_print_global()}\ltj@autospc=0
322 % autoxspacing = <bool> (default: true)
323 \define@boolkey[ltj]{japaram}{autoxspacing}[true]{%
324 \ifltj@japaram@autoxspacing
325 \directlua{ltj.ext_print_global()}\ltj@autoxspc=1
327 \directlua{ltj.ext_print_global()}\ltj@autoxspc=0
330 % [x]]kanjiskip = <dimen>
331 \define@key[ltj]{japaram}{kanjiskip}{% % SKIP
332 \directlua{luatexja.stack.set_stack_skip(ltj.isglobal, 'kanjiskip', \ltj@safe@glue{#1})}}
333 \define@key[ltj]{japaram}{xkanjiskip}{% % SKIP
334 \directlua{luatexja.stack.set_stack_skip(ltj.isglobal, 'xkanjiskip', \ltj@safe@glue{#1})}}
336 % jcharwidowpenalty = <count>
337 \define@key[ltj]{japaram}{jcharwidowpenalty}{% %COUNT
338 \ltj@@set@stack0,#1:{jwp}{-10000}{10000}}
340 % differentjfm = { large | small | average | both }
341 \define@choicekey*+[ltj]{japaram}{differentjfm}[\ltj@temp\ltj@tempr]%
342 {large,small,average,both}{%
344 \directlua{luatexja.jfmglue.diffmet_rule = math.max}\or
345 \directlua{luatexja.jfmglue.diffmet_rule = math.min}\or
346 \directlua{luatexja.jfmglue.diffmet_rule = math.two_average}\or
347 \directlua{luatexja.jfmglue.diffmet_rule = math.two_add}
349 }{\ltj@PackageError{luatexja}{invalid argument `#1' for `differentjfm'}{%
350 Argument for `differentjfm' must be one of `large', `small', `average',^^J%
352 % large, small, average, both
355 % jacharrange = { +-<range_number> }
356 \define@key[ltj]{japaram}{jacharrange}{\expandafter\ltj@@scrange#1,,}
357 \def\ltj@@scrange#1,{%
359 \ifx\ltj@temp\empty\let\next=\relax\else\let\next=\ltj@@scrange
360 \directlua{luatexja.charrange.toggle_char_range(%
361 ltj.is_global,\ltj@safe@num@or\ltj@defnum{#1})}%
365 \protected\def\ltjsetparameter#1{%
366 \ifnum\globaldefs>0\directlua{ltj.isglobal='global'}\else\directlua{ltj.isglobal=''}\fi
367 \setkeys[ltj]{japaram}{#1}\ignorespaces}
368 \protected\def\ltjglobalsetparameter#1{%
369 \ifnum\globaldefs<0\directlua{ltj.isglobal=''}\else\directlua{ltj.isglobal='global'}\fi
370 \setkeys[ltj]{japaram}{#1}\ignorespaces}
373 \def\ltj@@decl@array@param#1{%
374 \expandafter\let\csname ltj@@array@param/#1\endcsname=t%
376 \ltj@@decl@array@param{prebreakpenalty}
377 \ltj@@decl@array@param{postbreakpenalty}
378 \ltj@@decl@array@param{jaxspmode}
379 \ltj@@decl@array@param{alxspmode}
380 \ltj@@decl@array@param{kcatcode}
381 \ltj@@decl@array@param{jacharrange}
382 \ltj@@decl@array@param{chartorange}
383 \def\ltjgetparameter#1{%
384 \ifcsname ltj@@array@param/#1\endcsname
385 \expandafter\ltx@firstoftwo
387 \expandafter\ltx@secondoftwo
389 {\ltj@@getparam@two{#1}}%
390 {\ltj@@getparam@one{#1}}%
392 \def\ltj@@getparam@one#1{%
393 \directlua{ltj.ext_get_parameter_unary('#1')}}%
394 \def\ltj@@getparam@two#1#2{%
395 \directlua{ltj.ext_get_parameter_binary('#1', \ltj@safe@num{#2})}%
400 %\def\ltj@temp{plain}
401 %\ifx\fmtname\ltj@temp
402 % \message{plain format: loading luatexja-plain.tex}
404 %\input luatexja-plain.tex
409 %%------------------ Load module for the format
411 \ifltj@in@latex %<*LaTeX>
412 \RequirePackage{luatexja-latex}[2011/04/01]
413 \else\ifltj@in@plain %<*plain>
414 \input luatexja-plain.sty %
415 \fi\fi %</LaTeX|plain>
417 %%------------------ all done