OSDN Git Service

da23ecd6b87a48249fa52e03f3bac3a0f03851c2
[luatex-ja/luatexja.git] / doc / manual.dtx
1 %#! lualatex -shell-escape manual.ins
2
3 %<*en>
4 \documentclass[a4paper,titlepage]{article}
5 \usepackage[margin=20mm,footskip=5mm]{geometry}
6 %</en>
7 %<*ja>
8 \documentclass[a4paper,titlepage]{bxjsarticle}
9 \setpagelayout*{margin=20mm,footskip=5mm}
10 \def\headfont{\normalfont\bfseries}
11 % \def\headfont{\sffamily\gtfamily} is needed in ordinal documents
12 % This document cannot typeset in ltjsclasses (conflict with showexpl?)
13 %</ja>
14
15 \usepackage{amsmath,amssymb,xcolor,pict2e,multienum,amsthm,float}
16 \usepackage{booktabs,listings,lltjlisting,showexpl,multicol}
17 \usepackage{luatexja-otf}
18 \usepackage[unicode=false]{hyperref}
19 \usepackage[all]{xy}
20 \SelectTips{cm}{}
21
22 \DeclareRobustCommand\eTeX{\ensuremath{\varepsilon}-\kern-.125em\TeX}
23 \DeclareRobustCommand\LuaTeX{Lua\TeX}
24 \DeclareRobustCommand\pdfTeX{pdf\TeX}
25 \DeclareRobustCommand\pTeX{p\kern-.05em\TeX}
26 \DeclareRobustCommand\upTeX{p\kern-.05em\TeX}
27 \DeclareRobustCommand\pLaTeX{p\kern-.05em\LaTeX}
28 \DeclareRobustCommand\pLaTeXe{p\kern-.05em\LaTeXe}
29 \DeclareRobustCommand\epTeX{\ensuremath{\varepsilon}-\kern-.125em\pTeX}
30
31 \theoremstyle{definition}
32 \newtheorem{defn}{Definition}
33
34 \newenvironment{cslist}{%
35   \leftskip2em\parindent=0pt\def\makelabel##1{{\tt\char92##1}}
36   \def\{{\char`\{}\def\}{\char`\}}
37   \def\item[##1]{\par\smallskip\par\hskip-\leftskip\makelabel{##1}\par}
38 }{}
39
40 \makeatletter
41 \long\def\@makecaption#1#2{%
42   \vskip\abovecaptionskip
43   \sbox\@tempboxa{{\small #1. #2}}%
44   \ifdim \wd\@tempboxa >\hsize
45     {\small #1. #2}\par
46   \else
47     \global \@minipagefalse
48     \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
49   \fi
50   \vskip\belowcaptionskip}
51 \makeatother
52
53 %<*en>
54 \title{The \LuaTeX-ja package}
55 \author{The \LuaTeX-ja project team}
56 %</en>
57 %<*ja>
58 \title{\LuaTeX-jaパッケージ}
59 \author{\LuaTeX-jaプロジェクトチーム}
60 %</ja>
61
62 \lstset{
63   basicstyle=\ttfamily\small, pos=o, breaklines=true,
64   numbers=none, rframe={}, basewidth=0.5em
65 }
66
67 \parskip=\smallskipamount
68 \begin{document}
69 \catcode`\<=13
70 \def<#1>{{\normalfont\rm\itshape$\langle$#1$\rangle$}}
71 \maketitle
72
73 \tableofcontents
74 \bigskip
75
76 %<*en>
77 {\Large\bf This documentation is far from complete. It may have many
78 grammatical (and contextual) errors.}
79 %</en>
80 %<*ja>
81 \textbf{\large 本ドキュメントはまだまだ未完成です.
82 また,英語版と日本語版をdocstripプログラムを用いることで一緒に生成している都合上,
83 見出しが英語のままになっています.}
84 %</ja>
85
86 \clearpage
87 \part{User's manual}
88
89 \section{Introduction}
90
91 %<*en>
92 The \LuaTeX-ja package is a macro package for typesetting high-quality
93 Japanese documents when using \LuaTeX.
94 %</en>
95 %<*ja>
96 \LuaTeX-jaパッケージは,次世代標準\TeX である\LuaTeX の上で,\pTeX と同等
97 /それ以上の品質の日本語組版を実現させようとするマクロパッケージである.
98 %</ja>
99
100 \subsection{Backgrounds}
101 %<*en>
102 Traditionally, ASCII \pTeX, an extension of \TeX, and its derivatives
103 are used to typeset Japanese documents in \TeX. \pTeX\ is an engine
104 extension of \TeX: so it can produce high-quality Japanese documents
105 without using very complicated macros. But this point is a mixed
106 blessing: \pTeX\ is left behind from other extensions of \TeX,
107 especially \eTeX\ and pdf\TeX, and from changes about
108 Japanese processing in computers (\textit{e.g.}, the UTF-8 encoding).
109
110 Recently extensions of \pTeX, namely \upTeX\ (Unicode-implementation
111 of \pTeX) and \epTeX\ (merging of \pTeX\ and
112 \eTeX\ extension), have developed to fill those gaps to some
113 extent, but gaps still exist.
114
115 However, the appearance of \LuaTeX\ changed the whole situation. With
116 using Lua `callbacks', users can customize the internal processing of
117 \LuaTeX. So there is no need to modify sources of engines to
118 support Japanese typesetting: to do this, we only have to write Lua
119 scripts for appropriate callbacks.
120 %</en>
121 %<*ja>
122 従来,「\TeX を用いて日本語組版を行う」といったとき,エンジンとしては
123 ASCII \pTeX やそれの拡張物が用いられることが一般的であった.\pTeX は\TeX
124 のエンジン拡張であり,(少々仕様上不便な点はあるものの)商業印刷の分野に
125 も用いられるほどの高品質な日本語組版を可能としている.だが,それは弱点に
126 もなってしまった:\pTeX という(組版的に)満足なものがあったため,海外で
127 行われている数々の\TeX の拡張──例えば\eTeX や\pdfTeX ──や,TrueType,
128 OpenType, Unicodeといった計算機で日本語を扱う際の状況の変化に追従すること
129 を怠ってしまったのだ.
130
131 ここ数年,若干状況は改善されてきた.現在手に入る大半の\pTeX バイナリでは
132 外部UTF-8入力が利用可能となり,さらにUnicode化を推進し,\pTeX の内部処理
133 までUnicode化した\upTeX も開発されている.また,\pTeX に\eTeX 拡張をマー
134 ジした\epTeX も登場し,\TeX\ Live\ 2011では\pLaTeX が\epTeX の上で動作す
135 るようになった.だが,\pdfTeX 拡張(pdf直接出力やmicro-typesetting)を
136 \pTeX に対応させようという動きはなく,海外とのgapは未だにあるのが現状であ
137 る.
138
139 しかし,\LuaTeX の登場で,状況は大きく変わることになった.Luaコードで
140 `callback'を書くことにより,\LuaTeX の内部処理に割り込みをかけることが可
141 能となった.これは,エンジン拡張という真似をしなくても,Luaコードとそれに
142 関する\TeX マクロを書けば,エンジン拡張とほぼ同程度のことができるようになっ
143 たということを意味する.\LuaTeX-jaは,このアプローチによってLuaコード・
144 \TeX マクロによって日本語組版を\LuaTeX の上で実現させようという目的で開発
145 が始まったパッケージである.
146 %</ja>
147
148 \subsection{Major Changes from \pTeX}
149 %<*en>
150 The \LuaTeX-ja package is under much influence of \pTeX\ engine. The initial
151 target of development was to implement features of \pTeX. However,
152 \emph{\LuaTeX-ja is not a just porting of \pTeX; unnatural
153 specifications/behaviors of \pTeX\ were not adopted}.
154 %</en>
155
156 %<*ja>
157 \LuaTeX-jaは,\pTeX に多大な影響を受けている.初期の開発目標は,\pTeX の機
158 能をLuaコードにより実装することであった.しかし,開発が進むにつれ,\pTeX
159 の完全な移植は不可能であり,また\pTeX における実装がいささか不可解になっ
160 ているような状況も発見された.そのため,\textbf{\LuaTeX-ja は,もはや
161 \pTeX の完全な移植は目標とはしない.\pTeX における不自然な仕様・挙動があ
162 れば,そこは積極的に改める.}
163 %</ja>
164
165 The followings are major changes from \pTeX:
166 \begin{itemize}
167 \item A Japanese font is a tuple of a `real' font, a Japanese font
168       metric (\textbf{JFM}, for short), and an optional string called
169       `variation'.
170
171 \item In \pTeX, a linebreak after Japanese character is ignored (and
172       doesn't yield a space), since linebreaks (in source files) are
173       permitted almost everywhere in Japanese texts. However, \LuaTeX-ja
174       doesn't have this function completely, because of a specification
175       of \LuaTeX.
176 \item The insertion process of glues/kerns between two Japanese
177       characters and between a Japanese character and other characters
178       (we refer these glues/kerns as \textbf{JAglue}) is rewritten from
179       scratch.
180
181 \begin{itemize}
182 \item As \LuaTeX's internal character handling is `node-based'
183       (\textit{e.g.}, \verb+of{}fice+ doesn't prevent ligatures), the
184       insertion process of \textbf{JAglue} is now `node-based'.
185 \item Furthermore, nodes between two characters which have no effects in
186       linebreak (\textit{e.g.}, \verb+\special+ node) are ignored in the
187       insertion process.
188 \item In the process, two Japanese fonts which differ in their `real'
189       fonts only are identified.
190 \end{itemize}
191 \item At the present, vertical typesetting (\emph{tategaki}), is not
192       supported in \LuaTeX-ja.
193
194 \end{itemize} 
195 For detailed information, see Part~\ref{part-imp}.
196
197 \subsection{Notations}
198 In this document, the following terms and notations are used:
199 \begin{itemize}
200 \item Characters are divided into two types: 
201 \begin{itemize}
202 \item \textbf{JAchar}: standing for Japanese characters such as
203       Hiragana, Katakana, Kanji and other punctuation marks for
204       Japanese.
205 \item \textbf{ALchar}: standing for all other characters like alphabets. 
206 \end{itemize}
207 We say `alphabetic fonts' for fonts used in \textbf{ALchar}, and `Japanese fonts' for fonts used in \textbf{JAchar}.
208
209 \item A word in a sans-serif font (like \textsf{prebreakpenalty})
210       represents an internal parameter for Japanese typesetting, and it
211       is used as a key in \verb+\ltjsetparameter+ command.
212 \item The word `primitive' is used not only for primitives in \LuaTeX,
213       but also for control sequences that defined in the core module of
214       \LuaTeX-ja.
215 \item In this document, natural numbers start from~0.
216 \end{itemize}
217
218 \subsection{About the project}
219 \paragraph{Project Wiki} Project Wiki is under construction.
220 \begin{itemize}
221 \item \url{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage%28en%29} (English)
222 \item \url{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage} (Japanese)
223 \end{itemize}
224
225 This project is hosted by SourceForge.JP.
226
227 \paragraph{Members}\ 
228 %<*en>
229 \begin{multienumerate}
230 \def\labelenumi{$\bullet$}
231 \mitemxxx{Hironori KITAGAWA}{Kazuki MAEDA}{Takayuki YATO}
232 \mitemxxx{Yusuke KUROKI}{Noriyuki ABE}{Munehiro YAMAMOTO}
233 \mitemx{Tomoaki HONDA}
234 \end{multienumerate}
235 %</en>
236 %<*ja>
237 \begin{multienumerate}
238 \def\labelenumi{$\bullet$}
239 \mitemxxx{Hironori KITAGAWA}{Kazuki MAEDA}{Takayuki YATO}
240 \mitemxxx{Yusuke KUROKI}{Noriyuki ABE}{Munehiro YAMAMOTO}
241 \mitemx{Tomoaki HONDA}
242 \end{multienumerate}
243 %</ja>
244
245
246 % \paragraph{Acknowledgments} -- 挿入するならここ
247
248 \clearpage
249 \section{Getting Started}
250 \subsection{Installation}
251 To install the \LuaTeX-ja\ package, you will need:
252 \begin{itemize}
253 \item \LuaTeX\ (version 0.65.0-beta or later) and its supporting packages.\\
254 If you are using \TeX~Live~2011 or current W32\TeX, you don't have to worry.
255 \item The source archive of \LuaTeX-ja, of course{\tt:)}
256 \end{itemize}
257
258 The installation methods are as follows:
259 \begin{enumerate}
260 \item Download the source archive.
261
262 At the present, \LuaTeX-ja has no official release, so you have to retrieve
263 the archive from the repository.
264 You can retrieve the Git repository via
265 \begin{verbatim}
266 $ git clone git://git.sourceforge.jp/gitroot/luatex-ja/luatexja.git
267 \end{verbatim} 
268 or download the archive of HEAD in \texttt{master} branch from
269 \begin{flushleft}
270 \url{http://git.sourceforge.jp/view?p=luatex-ja/luatexja.git;a=snapshot;h=HEAD;sf=tgz}.
271 \end{flushleft}
272
273 Note that the forefront of development may not be in \texttt{master} branch.
274 \item Extract the archive. You will see {\tt src/} and several other sub-directories.
275 \item Copy all the contents of {\tt src/} into one of your \texttt{TEXMF} tree.
276 \item If {\tt mktexlsr} is needed to update the filename database, make it so.
277 \end{enumerate}
278
279 \subsection{Cautions}
280 \begin{itemize}
281 \item The encoding of your source file must be UTF-8. No other
282       encodings, such as EUC-JP or Shift-JIS, are not supported.
283 \item May be conflict with other packages. 
284
285 For example, the default setting of \textbf{JAchar} in the present
286       version does not coexist with \texttt{unicode-math}
287       package. Putting the following line in preamble makes that
288       mathematical symbols will be typeset correctly, but several
289       Japanese characters will be treated as an \textbf{ALchar} as
290       side-effect:
291 \begin{verbatim}
292 \ltjsetparameter{jacharrange={-3, -8}}
293 \end{verbatim}
294 \end{itemize}
295
296 \subsection{Using in plain \TeX}\label{ssec-plain}
297 To use \LuaTeX-ja in plain \TeX, simply put the following  at the beginning of the document:
298 \begin{verbatim}
299 \input luatexja.sty
300 \end{verbatim}
301
302 This does minimal settings (like {\tt ptex.tex}) for typesetting Japanese documents:
303 \begin{itemize}
304 \item The following 6~Japanese fonts are preloaded:
305 \begin{center}
306 \begin{tabular}{ccccc}
307 \toprule
308 \textbf{classification}&\textbf{font name}&\bf `10\,pt'&\bf`7\,pt'&\bf`5\,pt'\\\midrule
309 \emph{mincho}&Ryumin-Light    &\verb+\tenmin+&\verb+\sevenmin+&\verb+\fivemin+\\
310 \emph{gothic}&GothicBBB-Medium&\verb+\tengt+ &\verb+\sevengt+ &\verb+\fivegt+\\
311 \bottomrule
312 \end{tabular}
313 \end{center}
314 \begin{itemize}
315 \item The `Q' is a unit used in Japanese phototypesetting, and
316       $1\,\textrm{Q}=0.25\,\textrm{mm}$. This length is stored in a
317       dimension \verb+\jQ+.
318
319 \item It is widely accepted that the font `Ryumin-Light' and
320       `GothicBBB-Medium' aren't embedded into PDF files, and PDF reader
321       substitute them by some external Japanese fonts (\textit{e.g.},
322       Kozuka Mincho is used for Ryumin-Light in Adobe Reader). We adopt this custom to
323       the default setting.
324 \item A character in an alphabetic font is generally smaller than a
325       Japanese font in the same size. So actual size specification of
326       these Japanese fonts is in fact smaller than that of alphabetic
327       fonts, namely scaled by 0.962216.
328 \end{itemize}
329 \item The amount of glue that are inserted between a \textbf{JAchar} and
330       an \textbf{ALchar} (the parameter \textsf{xkanjiskip}) is set to
331 \[
332  (0.25\cdot 13.5\,\textrm{Q})^{+1\,\text{pt}}_{-1\,\text{pt}} 
333  = {27\over 32}\,\mathrm{mm}^{+1\,\text{pt}}_{-1\,\text{pt}}.
334 \]
335 \end{itemize}
336
337 \subsection{Using in \LaTeX}\label{ssec-ltx}
338 \paragraph{\LaTeXe}
339 Using in \LaTeXe\ is basically same. To set up the minimal environment
340 for Japanese, you only have to load {\tt luatexja.sty}:
341 \begin{verbatim}
342 \usepackage{luatexja}
343 \end{verbatim}
344 It also does minimal settings (counterparts in \pLaTeX\ are {\tt
345 plfonts.dtx} and {\tt pldefs.ltx}):
346
347 \begin{itemize}
348 \item {\tt JY3} is the font encoding for Japanese fonts (in horizontal direction).\\
349 When vertical typesetting is supported by \LuaTeX-ja in the future, {\tt JT3} will be used for vertical fonts.
350 \item Two font families {\tt mc} and {\tt gt} are defined: 
351 \begin{center}
352 \begin{tabular}{ccccc}
353 \toprule
354 \textbf{classification}&\textbf{family}&\verb+\mdseries+&\verb+\bfseries+&\textbf{scale}\\\midrule
355 \emph{mincho}&\tt mc&Ryumin-Light    &GothicBBB-Medium&0.962216\\
356 \emph{gothic}&\tt gt&GothicBBB-Medium&GothicBBB-Medium&0.962216\\
357 \bottomrule
358 \end{tabular}
359 \end{center}
360 Remark that the bold series in both family are same as the medium series of \emph{gothic} family.
361 This is a convention in \pLaTeX.
362
363 \item Japanese characters in math mode are typeset by the font family {\tt mc}.
364 \end{itemize}
365
366 However, above settings are not sufficient for Japanese-based
367 documents. To typeset Japanese-based documents, You are better to use
368 class files other than {\tt article.cls}, {\tt book.cls}, and so on.  At
369 the present, we have the counterparts of \texttt{jclasses} (standard
370 classes in \pLaTeX) and \texttt{jsclasses} (classes by Haruhiko
371 Okumura), namely, \texttt{ltjclasses} and \texttt{ltjsclasses}.
372
373 \paragraph{{\tt\char92 CID, {\tt\char92 UTF}} and macros in OTF package}
374 Under \pTeX, \texttt{OTF} package (developed by Shuzaburo Saito) is
375 used for typesetting characters which is in Adobe-japan1-6 CID but not
376 in JIS~X~0208. Since this package is widely used, \LuaTeX-ja
377 supports some of functions in \texttt{OTF} package.
378
379 \begin{LTXexample}
380 森\UTF{9DD7}外と内田百\UTF{9592}とが\UTF{9AD9}島屋に行く。
381
382 \CID{7652}飾区の\CID{13706}野家,
383 葛飾区の吉野家
384 \end{LTXexample}
385 %lltjlisting.sty要修正?:↑「森」の直後で改行.
386
387
388 \subsection{Changing Fonts}\label{ssub-chgfnt}
389 \paragraph{Remark: Japanese Characters in Math Mode}
390 Since \pTeX\ supports Japanese characters in math mode, there are
391 sources like the following:
392
393 \begin{LTXexample}
394 $f_{高温}$~($f_{\text{high temperature}}$).
395 \[ y=(x-1)^2+2\quad{}よって\quad y>0 \]
396 $5\in{}素:=\{\,p\in\mathbb N:\text{$p$ is a prime}\,\}$.
397 \end{LTXexample}
398
399 We (the project members of \LuaTeX-ja) think that using
400 Japanese characters in math mode are allowed if and only if these are used as identifiers.
401 In this point of view, 
402 \begin{itemize}
403 \item The lines 1~and~2 above are not correct, since `高温' in above is used as a textual label, and
404 `よって' is used as a conjunction. 
405 \item However, the line~3 is correct, since `素' is used as an identifier.
406 \end{itemize}
407 Hence, in our opinion, the above input should be corrected as:
408 \begin{LTXexample}
409 $f_{\text{高温}}$~%
410 ($f_{\text{high temperature}}$).
411 \[ y=(x-1)^2+2\quad 
412   \mathrel{\text{よって}}\quad y>0 \]
413 $5\in{}素:=\{\,p\in\mathbb N:\text{$p$ is a prime}\,\}$.
414 \end{LTXexample}
415 %BUG?: \{\}がなければ「素」がでない.上の段落の「よって」もでてない.
416 We also believe that using Japanese characters as identifiers is rare,
417 hence we don't describe how to change Japanese fonts in math mode in
418 this chapter. For the method, please see Part~\ref{part-ref}.
419
420
421 \paragraph{plain \TeX}
422 To change Japanese fonts in plain \TeX, you must use the primitive
423 \verb+\jfont+. So please see Part~\ref{part-ref}.
424
425
426 \paragraph{NFSS2}
427 For \LaTeXe, \LuaTeX-ja simply adopted the font selection system from that
428 of \pLaTeXe\ (in {\tt plfonts.dtx}).
429 \begin{itemize}
430 \item Two control sequences \verb+\mcdefault+ and \verb+\gtdefault+ are
431       used to specify the default font families for \emph{mincho} and
432       \emph{gothic}, respectively. Default values: \texttt{mc} for
433       \verb+\mcdefault+ and \texttt{gt} for \verb+\gtdefault+.
434 \item Commands \verb+\fontfamily+, \verb+\fontseries+,
435       \verb+\fontshape+ and \verb+\selectfont+ can be used to change
436       attributes of Japanese fonts. 
437 \begin{center}
438 \begin{tabular}{cccccc}
439 \toprule
440 &\textbf{encoding}&\textbf{family}&\textbf{series}&\textbf{shape}&\textbf{selection}\\\midrule
441 alphabetic fonts
442 &\verb+\romanencoding+&\verb+\romanfamily+&\verb+\romanseries+&\verb+\romanshape+
443 &\verb+\useroman+\\
444 Japanese fonts
445 &\verb+\kanjiencoding+&\verb+\kanjifamily+&\verb+\kanjiseries+&\verb+\kanjishape+
446 &\verb+\usekanji+\\
447 both&---&--&\verb+\fontseries+&\verb+\fontshape+&---\\
448 auto select&\verb+\fontencoding+&\verb+\fontfamily+&---&---&\verb+\usefont+\\
449 \bottomrule
450 \end{tabular}
451 \end{center}
452
453 %<*ja>
454 ここで,\verb+\fontencoding{<encoding>}+は,引数により和文側か欧文側かの
455       どちらかが切り替わる.例えば,次の入力で最初の\verb+\fontencoding+
456       の呼び出しは和文フォントのエンコーディングを\texttt{JT3}に変更し,
457       2回目の呼びだしでは欧文フォント側を\texttt{T1}へと変更する.
458 \begin{verbatim}
459 \fontencoding{JY3}\fontencoding{T1}
460 \end{verbatim}
461 %</ja>
462
463 \item For defining a Japanese font family, use \verb+\DeclareKanjiFamily+
464       instead of \verb+\DeclareFontFamily+.
465 \end{itemize}
466
467 \paragraph{fontspec}
468 To coexist with the \texttt{fontspec} package, it is needed to load
469 \texttt{luatexja-fontspec} package in the preamble. This additional
470 package automatically loads \texttt{luatexja} and \texttt{fontspec}
471 package, if needed.
472
473 In \texttt{luatexja-fontspec} package, the following 7~commands are defined as
474 counterparts of original commands in \texttt{fontspec}:
475 \begin{center}
476 \begin{tabular}{ccccc}
477 \toprule
478 Japanese fonts
479 &\verb+\jfontspec+&\verb+\setmainjfont+&\verb+\setsansjfont+&\verb+\newjfontfamily+\\
480 alphabetic fonts
481 &\verb+\fontspec+&\verb+\setmainfont+&\verb+\setsansfont+&\verb+\newfontfamily+\\
482 \midrule
483 Japanese fonts
484 &\verb+\newjfontface+&\verb+\defaultjfontfeatures+&\verb+\addjfontfeatures+\\
485 alphabetic fonts
486 &\verb+\newfontface+&\verb+\defaultfontfeatures+&\verb+\addfontfeatures+\\
487 \bottomrule
488 \end{tabular}
489 \end{center}
490 使用例
491
492
493 Note that there is no command named \verb+\setmonojfont+, since it is
494 popular for Japanese fonts that nearly all Japanese glyphs have same
495 widths.  Also note that the kerning feature is set off by default in
496 these 7~commands, since this feature and \textbf{JAglue} will clash (see
497 \ref{para-kern}).
498
499 \section{Changing Parameters}
500 There are many parameters in \LuaTeX-ja. And due to the behavior of \LuaTeX,
501 most of them are not stored as internal register of \TeX, but as an
502 original storage system in \LuaTeX-ja. Hence, to assign or acquire those
503 parameters, you have to use commands \verb+\ltjsetparameter+ and
504 \verb+\ltjgetparameter+.
505
506 \subsection{Editing the range of \textbf{JAchar}s}
507
508
509 To edit the range of \textbf{JAchar}s, You have to assign a non-zero
510 natural number which is less than 217 to the character range first. This
511 can be done by using \verb+\ltjdefcharrange+ primitive. For example, the
512 next line assigns whole characters in Supplementary Multilingual Plane
513 and the character `漢' to the range number~100.
514 \begin{lstlisting}
515 \ltjdefcharrange{100}{"10000-"1FFFF,`漢}
516 \end{lstlisting}
517 This assignment of numbers to ranges are always global, so you should
518 not do this in the middle of a document. 
519
520 If some character has been belonged to some non-zero numbered range,
521 this will be overwritten by the new setting. For example, whole SMP
522 belong the range~4 in the default setting of \LuaTeX-ja, and if you
523 specify the above line, then SMP will belong the range~100 and be
524 removed from the range~4.
525
526 After assigning numbers to ranges, the {\sf jacharrange} parameter can
527 be used to customize which character range will be treated as ranges of
528 \textbf{JAchar}s, as the following line (this is just the default
529 setting of \LuaTeX-ja):
530 \begin{verbatim}
531 \ltjsetparameter{jacharrange={-1, +2, +3, -4, -5, +6, +7, +8}}
532 \end{verbatim}
533 The argument to {\sf jacharrange} parameter is a list of integer. Negative interger $-n$ in the list means that `the character range~$n$ is ...'.
534
535 \paragraph{Default Setting}
536 Lua\TeX-ja predefines eight character ranges for convinience. They are
537 determined from the following data:
538 \begin{itemize}
539 \item Blocks in Unicode~6.0.
540 \item The \texttt{Adobe-Japan1-UCS2} mapping between a CID Adobe-Japan1-6 and Unicode.
541 \item The \texttt{PXbase} bundle for \upTeX\ by Takayuki Yato.
542 \end{itemize}
543
544 Now we describe these eight ranges. The alphabet `J' or `A' after the
545 number shows whether characters in the range is treated as
546 \textbf{JAchar}s or not by default. These settings are similar to \texttt{prefercjk} ...
547 \begin{description}
548 \item[Range~8${}^{\text{J}}$] Symbols in the intersection of the upper half of ISO~8859-1
549          (Latin-1 Supplement) and JIS~X~0208 (a basic character set for Japanese). This character range
550          consists of the following charatcers:
551 \begin{multicols}{2}
552 \begin{itemize}
553 \def\ch#1#2{\item \char"#1\ ({\tt U+00#1}, #2)}%"
554 \ch{A7}{Section Sign}
555 \ch{A8}{Umlaut or diaeresis}
556 \ch{B0}{Degree sign}
557 \ch{B1}{Plus-minus sign}
558 \ch{B4}{Spacing acute}
559 \ch{B6}{Paragraph sign}
560 \ch{D7}{Multiplication sign}
561 \ch{F7}{Division Sign}
562 \end{itemize}
563 \end{multicols}
564 \item[Range~1${}^{\text{A}}$] Latin characters that some of them are included in Adobe-Japan1-6.
565 This range consist of the following Unicode ranges, \emph{except characters in the range~8 above}:
566 \begin{multicols}{2}
567 \begin{itemize}
568 \item {\tt U+0080}--{\tt U+00FF}: Latin-1 Supplement
569 \item {\tt U+0100}--{\tt U+017F}: Latin Extended-A
570 \item {\tt U+0180}--{\tt U+024F}: Latin Extended-B
571 \item {\tt U+0250}--{\tt U+02AF}: IPA Extensions
572 \item {\tt U+02B0}--{\tt U+02FF}: Spacing Modifier Letters
573 \item {\tt U+0300}--{\tt U+036F}: Combining Diacritical Marks
574 \item {\tt U+1E00}--{\tt U+1EFF}: Latin Extended Additional
575 \par\ 
576 \end{itemize}
577 \end{multicols}
578 \item[Range~2${}^{\text{J}}$] Greek and Cyrillic letters. JIS~X~0208 (hence most of Japanese
579            fonts) has some of these characters.
580 \begin{multicols}{2}
581 \begin{itemize}
582 \item {\tt U+0370}--{\tt U+03FF}: Greek and Coptic
583 \item {\tt U+0400}--{\tt U+04FF}: Cyrillic
584 \item {\tt U+1F00}--{\tt U+1FFF}: Greek Extended
585 \\\ 
586 \end{itemize}
587 \end{multicols}
588 \item[Range~3${}^{\text{J}}$] Punctuations and Miscellaneous symbols. The block list is
589            indicated in Table~\ref{table-rng3}.
590 \begin{table}[!tb]
591 \caption{Unicode blocks in predefined character range~3.}\label{table-rng3}
592 \catcode`\"=13\def"#1#2#3#4{{\tt U+#1#2#3#4}}%"
593 \begin{center}\small
594 \begin{tabular}{llll}
595 "2000--"206F&General Punctuation&
596 "2070--"209F&Superscripts and Subscripts\\
597 "20A0--"20CF&Currency Symbols&
598 "20D0--"20FF&Comb.\ Diacritical Marks for Symbols\\
599 "2100--"214F&Letterlike Symbols&
600 "2150--"218F&Number Forms\\
601 "2190--"21FF&Arrows&
602 "2200--"22FF&Mathematical Operators\\
603 "2300--"23FF&Miscellaneous Technical&
604 "2400--"243F&Control Pictures\\
605 "2500--"257F&Box Drawing&
606 "2580--"259F&Block Elements\\
607 "25A0--"25FF&Geometric Shapes&
608 "2600--"26FF&Miscellaneous Symbols\\
609 "2700--"27BF&Dingbats&
610 "2900--"297F&Supplemental Arrows-B\\
611 "2980--"29FF&Misc.\ Mathematical Symbols-B&
612 "2B00--"2BFF&Miscellaneous Symbols and Arrows\\
613 "E000--"F8FF&Private Use Area&
614 \end{tabular}
615 \end{center}
616 \end{table}
617 \item[Range~4${}^{\text{A}}$] Characters usually not in Japanese fonts. This range consists
618            of almost all Unicode blocks which are not in other
619            predefined ranges. Hence, instead of showing the block list,
620            we put the definition of this range itself:
621 \begin{lstlisting}
622 \ltjdefcharrange{4}{%
623    "500-"10FF, "1200-"1DFF, "2440-"245F, "27C0-"28FF, "2A00-"2AFF, 
624   "2C00-"2E7F, "4DC0-"4DFF, "A4D0-"A82F, "A840-"ABFF, "FB50-"FE0F, 
625   "FE20-"FE2F, "FE70-"FEFF, "FB00-"FB4F, "10000-"1FFFF} % non-Japanese
626 \end{lstlisting}
627 \item[Range~5${}^{\text{A}}$] Surrogates and Supplementary Private Use Areas.
628 \item[Range~6${}^{\text{J}}$] Characters used in Japanese. The block list is indicated in Table~\ref{table-rng6}.
629 \begin{table}[!tb]
630 \caption{Unicode blocks in predefined character range~6.}\label{table-rng6}
631 \catcode`\"=13\def"#1#2#3#4{{\tt U+#1#2#3#4}}%"
632 \begin{center}\small
633 \begin{tabular}{llll}
634 "2460--"24FF&Enclosed Alphanumerics&
635 "2E80--"2EFF&CJK Radicals Supplement\\
636 "3000--"303F&CJK Symbols and Punctuation&
637 "3040--"309F&Hiragana\\
638 "30A0--"30FF&Katakana&
639 "3190--"319F&Kanbun\\
640 "31F0--"31FF&Katakana Phonetic Extensions&
641 "3200--"32FF&Enclosed CJK Letters and Months\\
642 "3300--"33FF&CJK Compatibility&
643 "3400--"4DBF&CJK Unified Ideographs Extension A\\
644 "4E00--"9FFF&CJK Unified Ideographs&
645 "F900--"FAFF&CJK Compatibility Ideographs\\
646 "FE10--"FE1F&Vertical Forms&
647 "FE30--"FE4F&CJK Compatibility Forms\\
648 "FE50--"FE6F&Small Form Variants&
649 "{20}000--"{2F}FFF&(Supplementary Ideographic Plane)
650 \end{tabular}
651 \end{center}
652 \end{table}
653 \item[Range~7${}^{\text{J}}$] Characters used in CJK languages, but not included in  Adobe-Japan1-6.
654 The block list is indicated in Table~\ref{table-rng7}.
655 \begin{table}[!tb]
656 \caption{Unicode blocks in predefined character range~7.}\label{table-rng7}
657 \catcode`\"=13\def"#1#2#3#4{{\tt U+#1#2#3#4}}%"
658 \begin{center}\small
659 \begin{tabular}{llll}
660 "1100--"11FF&Hangul Jamo&
661 "2F00--"2FDF&Kangxi Radicals\\
662 "2FF0--"2FFF&Ideographic Description Characters&
663 "3100--"312F&Bopomofo\\
664 "3130--"318F&Hangul Compatibility Jamo&
665 "31A0--"31BF&Bopomofo Extended\\
666 "31C0--"31EF&CJK Strokes&
667 "A000--"A48F&Yi Syllables\\
668 "A490--"A4CF&Yi Radicals&
669 "A830--"A83F&Common Indic Number Forms\\
670 "AC00--"D7AF&Hangul Syllables&
671 "D7B0--"D7FF&Hangul Jamo Extended-B
672 \end{tabular}
673 \end{center}
674 \end{table}
675 \end{description}
676
677
678 \subsection{\textsf{kanjiskip} and \textsf{xkanjiskip}}\label{subs-kskip}
679 \textbf{JAglue} is divided into the following three categories:
680 \begin{itemize}
681 \item Glues/kerns specified in JFM. If \verb+\inhibitglue+ is issued
682       around a Japanese character, this glue will be not inserted at the
683       place.
684 \item The default glue which inserted between two \textbf{JAchar}s ({\sf
685       kanjiskip}).
686 \item The default glue which inserted between a \textbf{JAchar} and an
687       \textbf{ALchar} (\textsf{xkanjiskip}).
688 \end{itemize}
689 The value (a skip) of \textsf{kanjiskip} or \textsf{xkanjiskip} can be
690 changed as the following.
691 \begin{lstlisting}
692 \ltjsetparameter{kanjiskip={0pt plus 0.4pt minus 0.4pt}, 
693                  xkanjiskip={0.25\zw plus 1pt minus 1pt}}
694 \end{lstlisting}
695
696
697 It may occur that JFM contains the data of `ideal width of {\sf
698 kanjiskip}' and/or `ideal width of \textsf{xkanjiskip}'.
699 To use these data from JFM, set the value of \textsf{kanjiskip} or 
700 \textsf{xkanjiskip} to \verb+\maxdimen+.
701
702 \subsection{Insertion Setting of \textsf{xkanjiskip}}
703 It is not desirable that \textsf{xkanjiskip} is inserted between every
704 boundary between \textbf{JAchar}s and \textbf{ALchar}s. For example,
705 \textsf{xkanjiskip} should not be inserted after opening parenthesis
706 (\textit{e.g.}, compare `(あ' and `(\hskip\ltjgetparameter{xkanjiskip}あ').
707
708 \LuaTeX-ja can control whether \textsf{xkanjiskip} can be inserted
709 before/after a character, by changing \textsf{jaxspmode} for \textbf{JAchar}s and
710 \textsf{alxspmode} parameters \textbf{ALchar}s respectively. 
711 \begin{LTXexample}
712 \ltjsetparameter{jaxspmode={`あ,preonly}, alxspmode={`\!,postonly}} 
713 pあq い!う
714 \end{LTXexample}
715
716 The second argument {\tt preonly} means `the insertion of
717 \textsf{xkanjiskip} is allowed before this character, but not after'.
718 the other possible values are {\tt postonly}, {\tt allow} and {\tt
719 inhibit}. For the compatibility with \pTeX, natural numbers between
720 0~and~3 are also allowed as the second argument\footnote{But we don't
721 recommend this: since numbers 1~and~2 have opposite meanings in
722 \textsf{jaxspmode} and \textsf{alxspmode}.}.
723
724 If you want to enable/disable all insertions of \textsf{kanjiskip} and
725 \textsf{xkanjiskip}, set \textsf{autospacing} and \textsf{autoxspacing}
726 parameters to {\tt false}, respectively.
727
728
729 \subsection{Shifting Baseline}
730 To make a match between a Japanese font and an alphabetic font, sometimes
731 shifting of the baseline of one of the pair is needed. In \pTeX, this is achieved
732 by setting \verb+\ybaselineshift+ to a non-zero length (the
733 baseline of alphabetic fonts is shifted below). However, for documents
734 whose main language is not Japanese, it is good to shift the baseline of
735 Japanese fonts, but not that of alphabetic fonts.
736 Because of this, \LuaTeX-ja can independently set the shifting amount
737 of the baseline of alphabetic fonts (\textsf{yalbaselineshift}
738 parameter) and that of Japanese fonts (\textsf{yjabaselineshift}
739 parameter). 
740
741 \begin{LTXexample}
742 \vrule width 150pt height 0.4pt depth 0pt\hskip-120pt
743 \ltjsetparameter{yjabaselineshift=0pt, yalbaselineshift=0pt}abcあいう
744 \ltjsetparameter{yjabaselineshift=5pt, yalbaselineshift=2pt}abcあいう
745 \end{LTXexample}
746 Here the horizontal line in above is the baseline of a line.
747
748 There is an interesting side-effect: characters in different size can be
749 vertically aligned center in a line, by setting two parameters appropriately.
750 The following is an example (beware the value is not well tuned):
751 \begin{LTXexample}
752 xyz漢字 
753 {\scriptsize
754   \ltjsetparameter{yjabaselineshift=-1pt, 
755     yalbaselineshift=-1pt}
756   XYZひらがな
757 }abcかな
758 \end{LTXexample}
759
760
761 \subsection{Cropmark}
762 Cropmark is a mark for indicating 4~corners and horizontal/vertical
763 center of the paper. In Japanese, we call cropmark as tombo(w).
764 \pLaTeX\ and this \LuaTeX-ja support `tombow' by their kernel.
765 The following steps are needed to typeset cropmark:
766
767 \begin{enumerate}
768 \item First, define the banner which will be printed at the upper left
769       of the paper. This is done by assigning a token list to
770       \verb+\@bannertoken+.
771
772 For example, the following sets banner as `{\tt filename (2012-01-01 17:01)}':
773 \begin{verbatim}
774 \makeatletter
775
776 \hour\time \divide\hour by 60 \@tempcnta\hour \multiply\@tempcnta 60\relax
777 \minute\time \advance\minute-\@tempcnta
778 \@bannertoken{%
779    \jobname\space(\number\year-\two@digits\month-\two@digits\day
780    \space\two@digits\hour:\two@digits\minute)}%
781 \end{verbatim}
782
783 \item ...
784 \end{enumerate}
785
786
787 \part{Reference}\label{part-ref}
788 \section{Font Metric and Japanese Font}
789 \subsection{\texttt{\char92jfont} primitive}
790 To load a font as a Japanese font, you must use the
791 \verb+\jfont+ primitive instead of~\verb+\font+, while
792 \verb+\jfont+ admits the same syntax used in~\verb+\font+. 
793 \LuaTeX-ja automatically loads \texttt{luaotfload} package,
794 so TrueType/OpenType fonts with features can be used for Japanese fonts:
795 \begin{LTXexample}
796 \jfont\tradgt={file:ipaexg.ttf:script=latn;%
797   +trad;-kern;jfm=ujis} at 14pt
798 \tradgt{}当/体/医/区
799 \end{LTXexample}
800
801 Note that the defined control sequence
802 (\verb+\tradgt+ in the example above) using \verb+\jfont+ is not a
803 \textit{font\_def} token, hence the input like \verb+\fontname\tradgt+
804 causes a error.  We denote control sequences which are defined in
805 \verb+\jfont+ by <jfont\_cs>.
806
807 \paragraph{Prefix \texttt{psft}}
808 Besides \texttt{file:}\ and \texttt{name:}\ prefixes, \texttt{psft:}\
809 can be used a prefix in \verb+\jfont+ (and~\verb+\font+) primitive.
810 Using this prefix, you can specify a `name-only' Japanese font which
811 will be not embedded to PDF. Typical use of this prefix is to specify
812 the `standard' Japanese fonts, namely, `Ryumin-Light' and
813 `GothicBBB-Medium'. For kerning or other informations, that of Kozuka
814 Mincho Pr6N Regular (this is a font by Adobe Inc., and included in
815 Japanese Font Packs for Adore Reader) will be used.
816
817
818 \paragraph{JFM}
819 As noted in Introduction, a JFM has measurements of characters and
820 glues/kerns that are automatically inserted for Japanese
821 typesetting. The structure of JFM will be described in the next
822 subsection. At the calling of \verb+\jfont+ primitive, you must specify
823 which JFM will be used for this font by the following keys:
824
825 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
826 \item[jfm=<name>]
827 Specify the name of JFM. A file named \texttt{jfm-<name>.lua} will be searched and/or loaded.
828
829 The followings are JFMs shipped with Lua\TeX-ja:
830 \begin{description}
831 \item[\tt jfm-ujis.lua] A standard JFM in Lua\TeX-ja. This JFM is
832       based on \verb+upnmlminr-h.tfm+, a metric for UTF/OTF package that
833       is used in \upTeX. When you use \texttt{luatexja-otf.sty}, please use this JFM.
834 \item[\tt jfm-jis.lua] A counterpart for \verb+jis.tfm+, `JIS font
835            metric' which is widely used in \pTeX. A major difference of
836            \texttt{jfm-ujis.lua} and this \texttt{jfm-jis.lua} is that
837            most haracters under \texttt{jfm-ujis.lua} are square-shaped,
838            while that under \texttt{jfm-jis.lua} are horizontal
839            rectangles.
840
841 \item[\tt jfm-min.lua] A counterpart for \verb+min10.tfm+, which is one
842            of the default Japanese font metric shipped with \pTeX. There
843            are notable difference between this JFM and other 2~JFMs, as
844            shown in Table~\ref{tab-difjfm}.
845 \end{description}
846
847 \item[jfmvar=<string>] Sometimes there is a need that 
848 \end{list}
849
850 \begin{table}[t]
851 \caption{Differences between JFMs shipped with \LuaTeX-ja}
852 \label{tab-difjfm}
853 \begin{center}
854 \def\r#1{{\jfont\g=psft:Ryumin-Light:jfm=#1 at 14.43324pt \g
855 \setbox0=\vtop{\hsize=7\zw\noindent ◆◆◆◆◆◆◆
856 ある日モモちゃんがお使いで迷子になって泣きました.}\copy0
857 \vrule height 0pt depth \dp0}}
858 \def\s#1{{\jfont\g=psft:Ryumin-Light:jfm=#1 at 14.43324pt \g
859 \setbox0=\vtop{\hsize=7\zw\noindent ちょっと!何}\copy0}}
860 \def\t#1{{\jfont\g=psft:Ryumin-Light:jfm=#1 at 19.24432pt \g
861 \setbox0=\hbox{漢}%
862 \vrule width 0.4pt height\ht0 depth\dp0\kern-.2pt\copy0
863 \kern-\wd0\vrule width\wd0height .2pt depth .2pt
864 \kern-\wd0\raise\ht0\hbox{\vrule width\wd0height .2pt depth .2pt}%
865 \kern-\wd0\lower\dp0\hbox{\vrule width\wd0height .2pt depth .2pt}%
866 \kern-.2pt\vrule width 0.4pt height\ht0 depth \dp0}}
867 \begin{tabular}{rccc}
868 \toprule
869 &\tt jfm-ujis.lua&\tt jfm-jis.lua&\tt jfm-min.lua\\
870 \midrule
871 Example~1&\r{ujis}&\r{jis}&\r{min}\\
872 Example~2&\s{ujis}&\s{jis}&\s{min}\\
873 Bounding Box&\t{ujis}&\t{jis}&\t{min}\\
874 \bottomrule
875 \end{tabular}
876 \end{center}
877 \end{table}
878
879 \paragraph{Note: kern feature}\label{para-kern}
880 Some fonts have information for inter-glyph spacing. However, this
881 information is not well-compatible with \LuaTeX-ja.  More concretely,
882 this kerning space from this information are inserted \emph{before} the
883 insertion process of \textbf{JAglue}, and this causes incorrect spacing
884 between two characters when both a glue/kern from the data in the font
885 and it from JFM are present.
886
887 \begin{itemize}
888 \item You should specify {\tt -kern} in
889 {\tt\char92jfont} primitive, when you want to use other font features,
890       such as {\tt script=...}\,.
891 \item If you want to use Japanese fonts in proportinal width, and use
892       information from this font, use \texttt{jfm-prop.lua} for its JFM, and ...
893
894 TODO: kanjiskip?
895 \end{itemize}
896
897
898 \subsection{Structure of JFM file}
899 A JFM file is a Lua script which has only one function call:
900 \begin{verbatim}
901 luatexja.jfont.define_jfm { ... }
902 \end{verbatim}
903 Real data are stored in the table which indicated above by
904 \verb+{ ... }+.  So, the rest of this subsection are devoted to describe the
905 structure of this table.  Note that all lengths in a JFM file are
906 floating-point numbers in design-size unit.
907
908 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
909 \item[dir=<direction>] (required)
910
911 The direction of JFM. At the present, only \texttt{'yoko'} is supported.
912
913 \item[zw=<length>] (required)
914
915 The amount of the length of the `full-width'.
916
917 \item[zh=<length>] (required)
918
919 \item[kanjiskip=\{<natural>, <stretch>, <shrink>\}] (optional)
920
921 This field specifies the `ideal' amount of \textsf{kanjiskip}. As noted
922              in Subsection~\ref{subs-kskip}, if the parameter
923              \textsf{kanjiskip} is \verb+\maxdimen+, the value specified
924              in this field is actually used (if this field is not specified in
925              JFM, it is regarded as 0\,pt). Note that <stretch> and <shrink>
926              fields are in design-size unit too.
927
928
929 \item[xkanjiskip=\{<natural>, <stretch>, <shrink>\}] (optional)
930
931 Like the \texttt{kanjiskip} field, this field specifies the `ideal'
932              amount of \textsf{xkanjiskip}.
933
934 \end{list}
935
936 Besides from above fields, a JFM file have several sub-tables those
937 indices are natural numbers.  The table indexed by~$i\in\omega$ stores
938 informations of `character class'~$i$. At least, the character class~0 is
939 always present, so each JFM file must have a sub-table whose index is
940 \texttt{[0]}.  Each sub-table (its numerical index is denoted by $i$) has
941 the following fields:
942
943 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
944 \item[chars=\{<character>, ...\}] (required except character class~0)
945
946 This field is a list of characters which are in this character
947              type~$i$. This field is not required if $i=0$, since all
948              \textbf{JAchar} which are not in any character class other
949              than 0 (hence, the character class~0 contains most of
950              \textbf{JAchar}s). In the list, a character can be
951              specified by its code number, or by the character itself
952              (as a string of length~1). Moreover, there are `imaginary
953              characters' which specified in the list. We will describe these later.
954
955 \item[width=<length>, height=<length>, depth=<length>, italic=<length>]\ (required)
956
957 Specify width of characters in character class~$i$, height, depth and
958 the amount of italic correction. All characters in character class~$i$ are regarded that its width, height and depth are
959 as values of these fields. 
960 But there is one exception: if \texttt{'prop'} is specified in \texttt{width} field, width of a character becomes that of its `real' glyph 
961
962 \item[left=<length>, down=<length>, align=<align>]\ 
963
964 These fields are for adjusting the position of the `real' glyph. Legal
965              values of \texttt{align} field are \texttt{'left'},
966              \texttt{'middle'} and \texttt{'right'}. If one of these
967              3~fields are omitted, \texttt{left} and \texttt{down} are
968              treated as~0, and \texttt{align} field is treated as
969              \texttt{'left'}.
970 The effects of these 3~fields are indicated in Figure~\ref{fig-pos}.
971
972 In most cases, \texttt{left} and \texttt{down} fields are~0, while
973 it is not uncommon that the \texttt{align} field is \texttt{'middle'} or \texttt{'right'}.
974 For example, setting the \texttt{align} field to \texttt{'right'} is practically needed 
975 when the current character class is the class for opening delimiters'. 
976 \begin{figure}[!tb]
977 \begin{minipage}{0.4\textwidth}%
978 \begin{center}\unitlength=10pt\small
979 \begin{picture}(15,12)(-1,-4)
980 \color{black!10!white}% real glyph :step1
981 \put(0,0){\vrule width 12\unitlength height 8\unitlength depth 3\unitlength}
982
983 \color{red!20!white}% real glyph :step1
984 \put(-1,-1.5){\vrule width 6\unitlength height 7\unitlength depth 2.5\unitlength}
985
986 \color{red}% real glyph
987 \thicklines
988 \put(-1,-1.5){\vector(0,1){7}\vector(0,-1){2.5}\vector(1,0){6}}
989 \put(5,-1.5){\line(0,1){7}\line(0,-1){2.5}}
990 \put(-1,5.5){\line(1,0){6}}
991 \put(-1,-4){\line(1,0){6}}
992
993 \color{green!20!white}% real glyph :step1
994 \put(3,0){\vrule width 6\unitlength height 7\unitlength depth 2.5\unitlength}
995
996 \color{black}% real glyph :step1
997 \thicklines
998 \put(0,0){\vector(0,1){8}\line(0,-1){3}\vector(1,0){12}}
999 \put(12,0){\line(0,1){8}\vector(0,-1){3}}
1000 \put(0,8){\line(1,0){12}}
1001 \put(0,-3){\line(1,0){12}}
1002 \put(0.2,4){\makebox(0,0)[l]{\texttt{height}}}
1003 \put(12.2,-1.5){\makebox(0,0)[l]{\texttt{depth}}}
1004 \put(6,0.2){\makebox(0,0)[b]{\texttt{width}}}
1005
1006 \color{green!50!black}% real glyph :step1
1007 \thicklines
1008 \put(3,0){\vector(0,1){7}\vector(0,-1){2.5}\vector(1,0){6}}
1009 \put(9,0){\line(0,1){7}\line(0,-1){2.5}}
1010 \put(3,7){\line(1,0){6}}
1011 \put(3,-2.5){\line(1,0){6}}
1012 \newsavebox{\eqdist}
1013 \savebox{\eqdist}(0,0)[b]{%
1014   \thinlines
1015   \put(-0.08,0.2){\line(0,-1){0.4}}%
1016   \put(0.08,0.2){\line(0,-1){0.4}}}
1017 \put(1.5,0){\usebox{\eqdist}}
1018 \put(10.5,0){\usebox{\eqdist}}
1019
1020 \color{blue}% shifted
1021 \thicklines
1022 \put(3,-1.5){\vector(-1,0){4}}
1023 \put(1,-1.7){\makebox(0,0)[t]{\texttt{left}}}
1024 \put(3,0){\vector(0,-1){1.5}}
1025 \put(3.2,-0.75){\makebox(0,0)[l]{\texttt{down}}}
1026 \end{picture} 
1027 \end{center}
1028 \end{minipage}%
1029 \begin{minipage}{0.6\textwidth}%
1030 Consider a node containing Japanese character whose value of the \texttt{align} 
1031 field is \texttt{'middle'}.
1032 \begin{itemize}
1033 \item The black rectangle is a frame of the node.
1034 Its width, height and depth are specified by JFM.
1035 \item Since the \texttt{align} field is \texttt{'middle'}, 
1036 the `real' glyph is centered horizontally (the green rectangle).
1037 \item Furthermore, the glyph is shifted according to values of fields
1038       \texttt{left} and \texttt{down}. The ultimate position of the real
1039       glyph is indicated by the red rectangle.
1040 \end{itemize}
1041 \end{minipage}
1042 \caption{The position of the `real' glyph.}
1043 \label{fig-pos}
1044 \end{figure}
1045
1046
1047 \item[kern={\{[$j$]=<kern>, ...\}}]
1048
1049 \item[glue={\{[$j$]=\{<width>, <stretch>, <shrink>\}, ...\}}]
1050 \end{list}
1051
1052 %<*en>
1053 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
1054 \item['lineend'] An ending of a line. 
1055 \item['diffmet'] Used at a boundary between two \textbf{JAchar}s whose JFM or size is different.
1056 \item['boxbdd'] The beginning/ending of a horizontal box, and the beginging of a noindented paragraph.
1057 \item['parbdd'] The beginning of an (indented) paragraph.
1058 \item['jcharbdd'] A boundary between \textbf{JAchar} and anything else
1059              (such as \textbf{ALchar}, kern, glue, ...).
1060 \item[$-1$] The left/right boundary of an inline math formula.
1061 \end{list}
1062 %</en>
1063
1064 %<*ja>
1065 上で説明した通り,\texttt{chars}フィールド中にはいくつかの「特殊文字」も
1066 指定可能である.これらは,大半が\pTeX のJFMグルーの挿入処理ではみな「文字
1067 クラス0の文字」として扱われていた文字であり,その結果として\pTeX より細か
1068 い組版調整ができるようになっている.以下のその一覧を述べる:
1069 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
1070 \item['lineend'] 行の終端を表す.
1071 \item['diffmet'] 
1072
1073 \item['boxbdd'] hboxの先頭と末尾,及びインデントされていない
1074              (\verb+\noindent+で開始された)段落の先頭を表す.
1075 \item['parbdd'] 通常の(\verb+\noindent+で開始されていない)段落の先頭.
1076 \item['jcharbdd'] 和文文字と「その他のもの」(欧文文字,glue,kern等)との境界.
1077 \item[$-1$] 行中数式と地の文との境界.
1078 \end{list}
1079
1080 \paragraph{\pTeX 用和文フォントメトリックの移植}
1081 以下に,\pTeX 用和文フォントメトリックを\LuaTeX-ja用に移植する場合の注意点を挙げておく.
1082 \begin{itemize}
1083 \item 実際に出力される和文フォントのサイズがdesign sizeとなる.
1084 このため,例えば$1\,\textrm{zw}$がdesign sizeの0.962216倍であるJISフォン
1085       トメトリック等を移植する場合は,
1086 \begin{itemize}
1087 \item JFM中の全ての数値を$1/0.962216$倍しておく.
1088 \item \TeX ソース中で使用するところで,サイズ指定を0.962216倍にする.
1089       \LaTeX でのフォント宣言なら,例えば次のように:
1090 \begin{verbatim}
1091 \DeclareFontShape{JY3}{mc}{m}{n}{<-> s*[0.962216] psft:Ryumin-Light:jfm=jis}{}
1092 \end{verbatim}
1093 \end{itemize}
1094 \item 上に述べた特殊文字は,\texttt{'boxbdd'}を除き文字クラスを全部0とする
1095       (JFM中に単に書かなければよい).
1096 \item \texttt{'boxbdd'}については,それのみで一つの文字クラスを形成し,その
1097       文字クラスに関してはglue/kernの設定はしない.
1098
1099 これは,\pTeX では,
1100       hboxの先頭・末尾とインデントされていない(\verb+\noindent+で開始さ
1101       れた)段落の先頭にはJFMグルーは入らないという仕様を実現させるためである.
1102 \item \pTeX の組版を再現させようというのが目的であれば以上の注意を守れば十分である.
1103
1104 ところで,\pTeX では通常の段落の先頭にJFMグルーが残るという仕様があるので,
1105       段落先頭の開き括弧は全角二分下がりになる.全角下がりを実現させるに
1106       は,段落の最初に手動で\verb+\inhibitglue+を追加するか,あるいは
1107       \verb+\everypar+のhackを行い,それを自動化させるしかなかった.
1108
1109 一方,\LuaTeX-jaでは,\texttt{'parbdd'}によって,それがJFM側で調整できるよ
1110 うになった.例えば,\LuaTeX-ja同梱のJFMのように,\texttt{'boxbdd'}と同じ文字クラスに
1111 \texttt{'parbdd'}を入れれば全角下がりとなる.
1112
1113 \begin{LTXexample}
1114 \jfont\g=psft:Ryumin-Light:jfm=test \g
1115 \parindent1\zw\noindent{}◆◆◆◆◆
1116 \par{}「◆◆←二分下がり
1117 \par{}【◆◆←全角下がり
1118 \par{}〔◆◆←全角二分下がり
1119 \end{LTXexample}
1120 \end{itemize}
1121
1122 %</ja>
1123
1124 \subsection{Math Font Family}
1125 \TeX\ handles fonts in math formulas by 16~font families\footnote{Omega,
1126 Aleph, \LuaTeX~and $\varepsilon$-\kern-.125em(u)\pTeX can handles 256~families, but
1127 an external package is needed to support this in plain \TeX\ and
1128 \LaTeX.}, and each family has three fonts:
1129 \verb+\textfont+, \verb+\scriptfont+ and \verb+\scriptscriptfont+.
1130
1131 \LuaTeX-ja's handling of Japanese fonts in math formulas is similar;
1132 Table~\ref{tab-math} shows counterparts to \TeX's primitives for math
1133 font families. There is no relation between the value of
1134 \verb+\fam+ and that of \verb+\jfam+; with appropreate settings, 
1135 you can set both \verb+\fam+ and \verb+\jfam+ to~the same value.
1136
1137 \begin{table}[!tb]
1138 \caption{Primitives for Japanese math fonts.}
1139 \label{tab-math}
1140 \begin{center}\def\{{\char`\{}\def\}{\char`\}}
1141 \begin{tabular}{lll}
1142 \toprule
1143 &Japanese fonts&alphabetic fonts\\
1144 \midrule
1145 font family&\verb+\jfam+${}\in [0,256)$&\verb+\fam+\\
1146 text size&\tt\textsf{jatextfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\verb+\textfont+<fam>=<font\_cs>\\
1147 script size&\tt\textsf{jascriptfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\verb+\scriptfont+<fam>=<font\_cs>\\
1148 scriptscript size&\tt\textsf{jascriptscriptfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\verb+\scriptscriptfont+<fam>=<font\_cs>\\
1149 \bottomrule
1150 \end{tabular}
1151 \end{center}
1152 \end{table}
1153
1154 \subsection{Callbacks}
1155 Like \LuaTeX\ itself, \LuaTeX-ja also has callbacks. These callbacks can
1156 be accessed via \verb+luatexbase.add_to_callback+ function and so on, as other callbacks
1157 \begin{list}{}%
1158 {\def\makelabel#1{\bfseries#1}}
1159 \item[\texttt{luatexja.load\_jfm} callback]
1160 With this callback you can overwrite JFMs.
1161
1162 \begin{verbatim}
1163 function (<table> jfm_info, <string> jfm_name)
1164   return <table> new_jfm_info
1165 end
1166 \end{verbatim}
1167
1168 The argument \verb+jfm_info+ contains a table similar to the table in a JFM file, except 
1169 this argument has \texttt{chars} field which contains character codes
1170              whose character class is not~0.
1171
1172 An example of this callback is the \texttt{ltjarticle} class, with
1173              forcefully assigning character class~0 to \texttt{'parbdd'}
1174              in the JFM \texttt{jfm-min.lua}. This callback doesn't
1175              replace any code of \LuaTeX-ja.
1176
1177 \item[\texttt{luatexja.define\_font} callback]
1178 This callback and the next callback form a pair, and you can assign letters which don't have
1179              fixed codepoints in Unicode to non-zero character classes.
1180 This \texttt{luatexja.define\_font} callback is called just when new Japanese font is loaded.
1181 \begin{verbatim}
1182 function (<table> jfont_info, <number> font_number)
1183   return <table> new_jfont_info
1184 end
1185 \end{verbatim}
1186
1187 You may assume that \verb+jfont_info+ has the following fields:
1188 \begin{description}
1189 \item[\tt jfm] The index number of JFM.
1190 \item[\tt size] Font size in a scaled point (${}=2^{-16}\,\textrm{pt}$).
1191 \item[\tt var] The value specified in \texttt{jfmvar=...} at a call of \verb+\jfont+.
1192 \end{description}
1193
1194 The returned table \verb+new_jfont_info+ also should include these three fields. 
1195 The \verb+font_number+ is a font number. 
1196
1197 A good example of this and the next callbacks is \texttt{luatexja-otf}
1198              package, supporting \verb+"AJ1-xxx"+ form for Adobe-Japan1
1199              CID characters in a JFM. This callback doesn't replace any
1200              code of \LuaTeX-ja.
1201
1202
1203 \item[\texttt{luatexja.find\_char\_class} callback]
1204 This callback is called just when \LuaTeX-ja inready to determine which
1205              character class a character \verb+chr_code+ belongs.
1206 A function used in this callback should be in the following form:
1207 \begin{lstlisting}[numbers=left]
1208 function (<number> char_class, <table> jfont_info, <number> chr_code)
1209   if char_class~=0 then return char_class
1210   else
1211     ....
1212     return (<number> new_char_class or 0)
1213   end
1214 end
1215 \end{lstlisting}
1216
1217 The argument \verb+char_class+ is the result of \LuaTeX-ja's default
1218              routine or previous function calls in this callback, hence
1219              this argument may not be 0. Moreover, the returned
1220              \verb+new_char_class+ should be as same as \verb+char_class+ when \verb+char_class+
1221              is not~0, otherwise you will overwrite the \LuaTeX-ja's
1222              default routine.
1223
1224 This callback doesn't replace any code of \LuaTeX-ja.
1225
1226
1227
1228 \end{list}
1229
1230
1231
1232 \section{Parameters}
1233 \subsection{{\tt\char92 ltjsetparameter} primitive}
1234 As noted before, \verb+\ltjsetparameter+ and \verb+\ltjgetparameter+ are
1235 primitives for accessing most parameters of \LuaTeX-ja. One of the main
1236 reason that \LuaTeX-ja didn't adopted the syntax similar to that of \pTeX\ 
1237 (\textit{e.g.},~\verb+\prebreakpenalty`)=10000+) 
1238 is the position of \verb+hpack_filter+ callback in the source
1239 of \LuaTeX, see Section~\ref{sec-para}.
1240
1241 \verb+\ltjsetparameter+ and \verb+\ltjglobalsetparameter+ are primitives
1242 for assigning parameters. These take one argument which is a
1243 \texttt{<key>=<value>} list. Allowed keys are described in the next
1244 subsection.  
1245 The difference between
1246 \verb+\ltjsetparameter+ and \verb+\ltjglobalsetparameter+ is only the
1247 scope of assignment;
1248 \verb+\ltjsetparameter+ does a local assignment and 
1249 \verb+\ltjglobalsetparameter+ does a global one. 
1250 They also obey the value of \verb+\globaldefs+,
1251 like other assignment.
1252
1253 \verb+\ltjgetparameter+ is the primitive for acquiring parameters. It
1254 always takes a parameter name as first argument, and also takes the
1255 additional argument---a character code, for example---in some cases.
1256 \begin{LTXexample}
1257 \ltjgetparameter{differentjfm}, 
1258 \ltjgetparameter{autospacing},
1259 \ltjgetparameter{prebreakpenalty}{`)}.
1260 \end{LTXexample}
1261 \emph{The return value of\/ {\normalfont\tt\char92ltjgetparameter} is
1262 always a string}. This is outputted by \texttt{tex.write()}, so any
1263 character other than space~`{\tt\char32}'~(U+0020) has the category code
1264 12~(other), while the space has 10~(space).
1265
1266 \subsection{List of Parameters}
1267 The following is the list of parameters which can be specificated by the
1268 \verb+\ltjsetparameter+ command. [\verb+\cs+] indicates the counterpart
1269 in \pTeX, and symbols beside each parameter has the following meaning:
1270 \begin{itemize}
1271 \item No mark: values at the end of the paragraph or the hbox are
1272       adopted in the whole paragraph/hbox.
1273 \item `\ast' : local parameters, which can change everywhere inside a paragraph/hbox.
1274 \item `\dagger': assignments are always global.
1275 \end{itemize}
1276
1277 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
1278 \item[\textsf{jcharwidowpenalty}\,=<penalty>] [\verb+\jcharwidowpenalty+]
1279
1280 Penalty value for supressing orphans. This penalty is inserted just
1281              after the last \textbf{JAchar} which is not regarded as a
1282              (Japanese) punctuation mark.
1283
1284 \item[\textsf{kcatcode}\,=\{<chr\_code>,<natural number>\}]\
1285
1286 An additional attributes having each character whose character code is <chr\_code>.  
1287 At the present version, the lowermost bit of <natural number> indicates
1288              whether the character is considered as a punctuation mark
1289              (see the description of \textsf{jcharwidowpenalty} above).
1290
1291
1292 \item[\textsf{prebreakpenalty}\,=\{<chr\_code>,<penalty>\}] [\verb+\prebreakpenalty+]\ 
1293 %<*ja>
1294 文字コード<chr\_code>の\textbf{JAchar}が行頭にくることを抑止するために,
1295              この文字の前に挿入/追加されるペナルティの量を指定する.
1296
1297 例えば閉じ括弧「〗」は絶対に行頭にきてはならないので,標準で読み込まれる
1298              \texttt{luatexja-kinsoku.tex}において
1299 \begin{verbatim}
1300 \ltjsetparameter{prebreakpenalty={`〙,10000}}
1301 \end{verbatim}
1302 と,最大値の10000が指定されている.他にも,小書きのカナなど,絶対禁止とい
1303              うわけではないができれば行頭にはきて欲しくない場合に,0と
1304              10000の間の値を指定するのも有用であろう.
1305 \begin{verbatim}
1306 \ltjsetparameter{prebreakpenalty={`ゕ,150}}
1307 \end{verbatim}
1308 %</ja>
1309
1310 \item[\textsf{postbreakpenalty}\,=\{<chr\_code>,<penalty>\}] [\verb+\postbreakpenalty+]
1311 %<*ja>
1312 文字コード<chr\_code>の\textbf{JAchar}が行末にくることを抑止するために,
1313              この文字の後に挿入/追加されるペナルティの量を指定する.
1314
1315 \pTeX では,\verb+\prebreakpenalty+, \verb+\postbreakpenalty+において,
1316 \begin{itemize}
1317 \item 一つの文字に対して,pre, postどちらか一つしか指定することができなかっ
1318       た(後から指定した方で上書きされる).
1319 \item pre, post合わせて256文字分の情報を格納することしかできなかった.
1320 \end{itemize}
1321 という制限があったが,\LuaTeX-ja ではこれらの制限は解消されている.
1322 %</ja>
1323
1324 \item[\textsf{jatextfont}\,=\{<jfam>,<jfont\_cs>\}] [\verb+\textfont+ in \TeX]
1325 \item[\textsf{jascriptfont}\,=\{<jfam>,<jfont\_cs>\}] [\verb+\scriptfont+ in \TeX]
1326 \item[\textsf{jascriptscriptfont}\,=\{<jfam>,<jfont\_cs>\}] [\verb+\scriptscriptfont+ in \TeX]
1327 \item[\textsf{yjabaselineshift}\,=<dimen>$^\ast$]\ 
1328 \item[\textsf{yalbaselineshift}\,=<dimen>$^\ast$] [\verb+\ybaselineshift+]
1329
1330 \item[\textsf{jaxspmode}\,=\{<chr\_code>,<mode>\}] [\verb+\inhibitxspcode+]
1331
1332 Setting whether inserting  \textsf{xkanjiskip} is allowed before/after a \textbf{JAchar} whose character code is <chr\_code>.
1333 The followings are allowed for <mode>:
1334 \begin{description}
1335 \item[0, \texttt{inhibit}] Insertion of \textsf{xkanjiskip} is inhibited before the charater, nor after the charater.
1336 \item[2, \texttt{preonly}] Insertion of \textsf{xkanjiskip} is allowed before the charater, but not after.
1337 \item[1, \texttt{postonly}] Insertion of \textsf{xkanjiskip} is allowed after the charater, but not before.
1338 \item[3, \texttt{allow}] Insertion of \textsf{xkanjiskip} is allowed before the charater and after the charater.
1339 This is the default value.
1340 \end{description}
1341
1342 \item[\textsf{alxspmode}\,=\{<chr\_code>,<mode>\}] [\verb+\xspcode+]
1343
1344 Setting whether inserting \textsf{xkanjiskip} is allowed before/after a
1345              \textbf{ALchar} whose character code is <chr\_code>.
1346 The followings are allowed for <mode>:
1347 \begin{description}
1348 \item[0, \texttt{inhibit}] Insertion of \textsf{xkanjiskip} is inhibited
1349            before the charater, nor after the charater.
1350 \item[1, \texttt{preonly}] Insertion of \textsf{xkanjiskip} is allowed
1351            before the charater, but not after.
1352 \item[2, \texttt{postonly}] Insertion of \textsf{xkanjiskip} is allowed
1353            after the charater, but not before.
1354 \item[3, \texttt{allow}] Insertion of \textsf{xkanjiskip} is allowed both
1355            before the charater and after the charater.
1356 This is the default value.
1357 \end{description}
1358 Note that parameters \textsf{jaxspmode} and \textsf{alxspmode} use a common table.
1359
1360 \item[\textsf{autospacing}\,=<bool>$^\ast$] [\verb+\autospacing+]
1361 \item[\textsf{autoxspacing}\,=<bool>$^\ast$] [\verb+\autoxspacing+]
1362 \item[\textsf{kanjiskip}\,=<skip>] [\verb+\kanjiskip+]
1363 \item[\textsf{xkanjiskip}\,=<skip>] [\verb+\xkanjiskip+]
1364
1365 \item[\textsf{differentjfm}\,=<mode>$^\dagger$]
1366
1367 Specify how glues/kerns between two \textbf{JAchar}s whose JFM (or size) are different. 
1368 The allowed arguments are the followings:
1369 \begin{description}
1370 \item[\texttt{average}]
1371 \item[\texttt{both}]
1372 \item[\texttt{large}]
1373 \item[\texttt{small}]
1374 \end{description}
1375
1376 \item[\textsf{jacharrange}\,=<ranges>$^\ast$]
1377 \item[\textsf{kansujichar}\,=\{<digit>, <chr\_code>\}] [\verb+\kansujichar+]
1378 \end{list}
1379
1380
1381 \section{Other Primitives}
1382 \subsection{Primitives for Compatibility}
1383 The following primtives are implemented for compatibility with \pTeX:
1384 \begin{list}{}{\def\makelabel{\ttfamily\char92 }}
1385 \item[kuten]
1386 \item[jis]
1387 \item[euc]
1388 \item[sjis]
1389 \item[ucs]
1390 \item[kansuji]
1391 \end{list}
1392 \subsection{{\tt\char92 inhibitglue}}
1393 The primitive \verb+\inhibitglue+ suppresses the insertion of \textbf{JAglue}.
1394 The following is an example, using a special JFM that there will be a glue between 
1395 the beginning of a box and `あ', and also between `あ' and `ウ'.
1396
1397 \begin{LTXexample}
1398 \jfont\g=psft:Ryumin-Light:jfm=test \g
1399 あウあ\inhibitglue{}ウ\inhibitglue\par
1400 あ\par\inhibitglue{}あ
1401 \par\inhibitglue\hrule{}あoff\inhibitglue ice
1402 \end{LTXexample}
1403
1404 With the help of this example, we remark the specification of \verb+\inhibitglue+:
1405 \begin{itemize}
1406 \item The call of \verb+\inhibitglue+ in the (internal) vertical mode is
1407       effective at the beginning of the next paragraph. This is realized
1408       by hacking \verb+\everypar+.
1409 \item The call of \verb+\inhibitglue+ in the (restricted) horizontal
1410       mode is only effective on the spot; does not get over boundary of
1411       paragraphs. Moreover, \verb+\inhibitglue+ cancels ligatures and
1412       kernings, as shown in line~4 of above example.
1413 \item The call of \verb+\inhibitglue+ in math mode is just ignored.
1414 \end{itemize}
1415
1416 \section{Control Sequences for \LaTeXe}
1417 \subsection{Patch for NFSS2}
1418 As described in Subsection~\ref{ssec-ltx}, \LuaTeX-ja simply adopted
1419 \texttt{plfonts.dtx} in \pLaTeXe\ for the Japanese patch for NFSS2.
1420 For an convinience, we will describe
1421 commands which are not described in Subsection~\ref{ssub-chgfnt}.
1422
1423 \begin{cslist}%
1424 \item[DeclareYokoKanjiEncoding\{<encoding>\}\{<text-settings>\}\{<math-settings>\}]
1425 In NFSS2 under \LuaTeX-ja, distinction between alphabetic font families
1426              and Japanese font families is only made by its
1427              encoding. For example, encodings OT1 and T1 are for
1428              alphabetic font families, and a Japanese font family cannot
1429              have these encodings. This command defines a new encoding
1430              scheme for Japanese font family (in horizontal direction).
1431
1432 \item[DeclareKanjiEncodingDefaults\{<text-settings>\}\{<math-settings>\}]
1433 \item[DeclareKanjiSubstitution\{<encoding>\}\{<family>\}\{<series>\}\{<shape>\}]
1434 \item[DeclareErrorKanjiFont\{<encoding>\}\{<family>\}\{<series>\}\{<shape>\}\{<size>\}]
1435
1436 The above 3~commands are just the counterparts for \verb+DeclareFontEncodingDefaults+ and~others.
1437
1438 \item[reDeclareMathAlphabet\{<unified-cmd>\}\{<al-cmd>\}\{<ja-cmd>\}]
1439 和文・欧文の数式用フォントファミリを一度に変更する命令を作成する.
1440 具体的には,欧文数式用フォントファミリ変更の命令<al-cmd>と,和文数式用フォ
1441              ントファミリ変更の命令<ja-cmd>の2つを同時に行う命令として
1442              <unified-cmd>を(再)定義する.実際の使用では<unified-cmd>と
1443              <al-cmd>に同じものを指定する,すなわち,<al-cmd>に和文側も変
1444              更させるようにするのが一般的と思われる.
1445
1446 本コマンドの使用については,\pLaTeX 配布中の\texttt{plfonts.dtx}に詳しく
1447              注意点が述べられているので,そちらを参照されたい.
1448
1449 \item[DeclareRelationFont\{<ja-encoding>\}\{<ja-family>\}\{<ja-series>\}\{<ja-shape>\}\\
1450   \hfill\{<al-encoding>\}\{<al-family>\}\{<al-series>\}\{<al-shape>\}]
1451 %<*en>
1452 This command sets the `accompanied' alphabetic font family (given by the latter 4~arguments) 
1453 with respect to a Japanese font family given by the former 4~arguments. 
1454 %</en>
1455 %<*ja>
1456 いわゆる「従属欧文」を設定するための命令である.前半の4引数で表される和文フォントファミリに対して,
1457 そのフォントに対応する「従属欧文」フォントファミリを後半の4引数により与える.
1458 %</ja>
1459 \item[SetRelationFont]
1460 This command is almost same as \verb+\DeclareRelationFont+, except that this command does a local 
1461 assignment, where \verb+\DeclareRelationFont+ does a global assignment.
1462 \item[userelfont]
1463 Change current alphabetic font encoding/family/\dots\ to the `accompanied' alphabetic
1464              font family with respect to current Japanese font family,
1465              which was set by
1466              \verb+\DeclareRelationFont+ or \verb+SetRelationFont+.
1467 Like \verb+\fontfamily+, \verb+\selectfont+ is required to take an effect.
1468
1469 \item[adjustbaseline]
1470 ...
1471 \end{cslist}
1472
1473 As closing this subsection, we shall introduce an example of
1474 \verb+SetRelationFont+ and \verb+\userelfont+:
1475 \begin{LTXexample}
1476 \gtfamily{}あいうabc
1477 \SetRelationFont{JY3}{gt}{m}{n}{OT1}{pag}{m}{n}
1478 \userelfont\selectfont{}あいうabc
1479 \end{LTXexample}
1480
1481
1482 \subsection{Cropmark/`tombow'}
1483
1484 \section{Extensions}
1485 \subsection{{\tt luatexja-fontspec.sty}}
1486
1487 \subsection{{\tt luatexja-otf.sty}}
1488 This optional package supports typesetting charaters in
1489 Adobe-Japan1. {\tt luatexja-otf.sty} offers the following 2~low-level
1490 commands:
1491 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
1492 \item[\char92CID\{<number>\}]
1493 Typeset a character whose CID number is <number>.
1494 \item[\char92UTF\{<hex\_number>\}]
1495 Typeset a character whose character code is <hex\_number> (in hexadecimal).
1496 This command is similar to \verb+\char"+<hex\_number>,\ %"
1497 but please remind remarks below.
1498 \end{list}
1499
1500 \paragraph{Remarks}
1501 Characters by \verb+\CID+ and \verb+\UTF+ commands are different from
1502 ordinary characters in the following points:
1503 \begin{itemize}
1504 \item Always treated as \textbf{JAchar}s.
1505 \item Processing codes for supporting OpenType features (\textit{e.g.},
1506       glyph replacement and kerning) by the \texttt{luaotfload} package
1507       is not performed to these characters.
1508 \end{itemize}
1509
1510
1511 \paragraph{Additionally Syntax of JFM}
1512 {\tt luatexja-otf.sty} extends the syntax of JFM; the entries of {\tt
1513 chars} table in JFM now allows a string in the form
1514 \verb+'AJ1-xxx'+, which stands for the character 
1515 whose CID number in Adobe-Japan1 is \verb+xxx+. 
1516
1517 \part{Implementations}\label{part-imp}
1518 \section{Storing Parameters}\label{sec-para}
1519 \subsection{Used Dimensions,  Attributes and whatsit nodes}
1520 Here the following is the list of dimension and attributes which are used in \LuaTeX-ja.
1521 \begin{list}{}{%
1522 \def\makelabel{\ttfamily}
1523 \def\dim#1{\item[\char92 #1\ \textrm{(dimension)}]}
1524 \def\attr#1{\item[\char92 #1\ \textrm{(attribute)}]}
1525 }
1526
1527 \dim{jQ}
1528 As explained in Subsection~\ref{ssec-plain}, \verb+\jQ+ is equal to
1529                         $1\,\textrm{Q}=0.25\,\textrm{mm}$, where `Q'~(also called `級') is
1530                         a unit used in Japanese phototypesetting. So one should not change the value of this dimension. 
1531 \dim{jH}
1532 There is also a unit called `歯' which equals to $0.25\,\textrm{mm}$ and
1533                         used in Japanese phototypesetting. The dimension
1534                         \verb+\jH+ stores this length, similar to \verb+\jQ+. 
1535 \dim{ltj@zw} A temporal register for the `full-width' of current Japanese font.
1536 \dim{ltj@zh} A temporal register for the `full-height' (usually the sum of height of imaginary body and its depth) of current Japanese font.
1537 \attr{jfam} Current number of Japanese font family for math formulas.
1538 \attr{ltj@curjfnt} The font index of current Japanese font.
1539 \attr{ltj@charclass} The character class of Japanese \textit{glyph\_node}.
1540 \attr{ltj@yablshift} The amount of shifting the baseline of alphabetic
1541                         fonts in scaled point ($2^{-16}\,\textrm{pt}$).
1542 \attr{ltj@ykblshift} The amount of shifting the baseline of Japanese
1543                         fonts in scaled point ($2^{-16}\,\textrm{pt}$).
1544 \attr{ltj@autospc} Whether the auto insertion of \textsf{kanjiskip} is allowed at the node.
1545 \attr{ltj@autoxspc} Whether the auto insertion of \textsf{xkanjiskip} is allowed at the node.
1546 \attr{ltj@icflag} An attribute for distinguishing `kinds' of a node. One of the following value is
1547                         assigned to this attribute:
1548 \begin{description}
1549 \item[\textit{italic} (1)] Glues from an itaric correction
1550            (\verb+\/+). This distinction of origins of glues 
1551            (from explicit \verb+\kern+, or from \verb+\/+)
1552            is needed in the insertion process of \textsf{xkanjiskip}.
1553 \item[\textit{packed} (2)] 
1554 \item[\textit{kinsoku} (3)] Penalties inserted for the word-wrapping  process of Japanese characters (\emph{kinsoku}).
1555 \item[\textit{from\_jfm} (4)] Glues/kerns from JFM.
1556 \item[\textit{line\_end} (5)] Kerns for ...
1557 \item[\textit{kanji\_skip} (6)] Glues for \textsf{kanjiskip}.
1558 \item[\textit{xkanji\_skip} (7)] Glues for \textsf{xkanjiskip}.
1559 \item[\textit{processed} (8)] Nodes which is already processed by ...
1560 \item[\textit{ic\_processed} (9)] Glues from an itaric correction, but also already processed.
1561 \item[\textit{boxbdd} (15)] Glues/kerns that inserted just the beginning or the ending of an hbox or a paragraph.
1562 \end{description}
1563 \attr{ltj@kcat$i$} Where $i$~is a natural number which is less than~7.
1564 These 7~attributes store bit~vectors indicating which character block is regarded as a block of \textbf{JAchar}s.
1565 \end{list}
1566
1567 Furthermore, \LuaTeX-ja uses several `user-defined' whatsit nodes for
1568 typesetting. All those nodes store a natural number (hence the node's
1569 \texttt{type} is 100).
1570 \begin{description}
1571 \item[30111] Nodes for indicating that \verb+\inhibitglue+ is
1572            specified. The \texttt{value} field of these nodes doesn't matter.
1573 \item[30112] Nodes for \LuaTeX-ja's stack system (see the next
1574            subsection). The \texttt{value} field of these nodes is
1575            current group.
1576 \item[30113] Nodes for Japanese Characters which the callback process of
1577            luaotfload won't be applied, andd the character code is
1578            stored in the \texttt{value} field. Each node having this
1579            \verb+user_id+ is converted to a `glyph\_node' \emph{after}
1580            the callback process of luaotfload.
1581 \end{description}
1582 These whatsits will be removed during the process of inserting \textbf{JAglue}s.
1583
1584 \subsection{Stack System of \LuaTeX-ja}\label{ssec-stack}
1585 \paragraph{Background}
1586 \LuaTeX-ja has its own stack system, and most parameters of \LuaTeX-ja
1587 are stored in it.  To clarify the reason, imagine the parameter
1588 \textsf{kanjiskip} is stored by a skip, and consider the following
1589 source:
1590 \begin{LTXexample}
1591 \ltjsetparameter{kanjiskip=0pt}ふがふが.%
1592 \setbox0=\hbox{\ltjsetparameter{kanjiskip=5pt}ほげほげ}
1593 \box0.ぴよぴよ\par
1594 \end{LTXexample}
1595
1596 As described in Part~\ref{part-ref}, the only effective value of
1597 \textsf{kanjiskip} in an hbox is the latest value, so the value of
1598 \textsf{kanjiskip} which applied in the entire hbox should be 5\,pt.
1599 However, by the implementation method of \LuaTeX, this `5\,pt' cannot be
1600 known from any callbacks.  In the \texttt{tex/packaging.w} (which is a
1601 file in the source of \LuaTeX), there are the following codes:
1602 \begin{lstlisting}
1603 void package(int c)
1604 {
1605     scaled h;                   /* height of box */
1606     halfword p;                 /* first node in a box */
1607     scaled d;                   /* max depth */
1608     int grp;
1609     grp = cur_group;
1610     d = box_max_depth;
1611     unsave();
1612     save_ptr -= 4;
1613     if (cur_list.mode_field == -hmode) {
1614         cur_box = filtered_hpack(cur_list.head_field,
1615                                  cur_list.tail_field, saved_value(1),
1616                                  saved_level(1), grp, saved_level(2));
1617         subtype(cur_box) = HLIST_SUBTYPE_HBOX;
1618 \end{lstlisting}
1619 Notice that \verb+unsave+ is executed \emph{before}
1620 \verb+filtered_hpack+ (this is where \verb+hpack_filter+ callback is
1621 executed): so `5\,pt' in the above source is orphaned at
1622 \texttt+unsave+, and hence it can't be accessed from \verb+hpack_filter+
1623 callback.
1624
1625 \paragraph{The method}
1626 The code of stack system is based on that in a post of Dev-luatex mailing list\footnote{%
1627 \texttt{[Dev-luatex] tex.currentgrouplevel}, a post at 2008/8/19 by Jonathan Sauer.}.
1628
1629 These are two \TeX\ count registers for maintaining informations:
1630 \verb+\ltj@@stack+ for the stack level, and \verb+\ltj@@group@level+ for
1631 the \TeX's group level when the last assignment was done.  Parameters
1632 are stored in one big table named \texttt{charprop\_stack\_table}, where
1633 \texttt{charprop\_stack\_table[$i$]} stores data of stack level~$i$. If
1634 a new stack level is created by \verb+\ltjsetparameter+, all data of the
1635 previous level is copied.
1636
1637 To resolve the problem mentioned in `Background' above, \LuaTeX-ja uses
1638 another thing: When a new stack level is about to be created, a whatsit
1639 node whose type, subtype and value are 44~(\textit{user\_defined}),
1640 30112, and current group level respectively is appended to the current
1641 list (we refer this node by \textit{stack\_flag}). This enables us to
1642 know whether assignment is done just inside a hbox. Suppose that the
1643 stack level is~$s$ and the \TeX's group level is~$t$ just after the hbox
1644 group, then:
1645 \begin{itemize}
1646 \item If there is no \textit{stack\_flag} node in the list of hbox, then
1647       no assignment was occurred inside the hbox. Hence values of
1648       parameters at the end of the hbox are stored in the stack
1649       level~$s$.
1650 \item If there is a \textit{stack\_flag} node whose value is~$t+1$, then
1651       an assignment was occurred just inside the hbox group. Hence
1652       values of parameters at the end of the hbox are stored in the
1653       stack level~$s+1$.
1654 \item If there are \textit{stack\_flag} nodes but all of their values
1655       are more than~$t+1$, then an assignment was occurred in the box,
1656       but it is done is `more internal' group. Hence values of
1657       parameters at the end of the hbox are stored in the stack
1658       level~$s$.
1659 \end{itemize}
1660
1661 Note that to work this trick correctly, assignments to
1662 \verb+\ltj@@stack+ and \verb+\ltj@@group@level+ have to be local always, 
1663 regardless the value of \verb+\globaldefs+.
1664 This problem is resolved by using
1665 \hbox{\verb+\directlua{tex.globaldefs=0}+} (this assignment is local).
1666
1667
1668 \section{Linebreak after Japanese Character}\label{sec-lbreak}
1669 \subsection{Reference: Behavior in \pTeX}
1670 %<*en>
1671 In~\pTeX, a linebreak after a Japanese character doesn't emit a space,
1672 since words are not separated by spaces in Japanese writings. However,
1673 this feature isn't fully implemented in \LuaTeX-ja due to the
1674 specification of callbacks in~\LuaTeX. To clarify the difference between
1675 \pTeX~and~\LuaTeX, We briefly describe the handling of a linebreak in~\pTeX, in
1676 this subsection. 
1677
1678 \pTeX's input processor can be described in terms of a finite state
1679 automaton, as that of~\TeX\ in~Section~2.5 of~\cite{texbytopic}. The
1680 internal states are as follows:
1681 \begin{itemize}
1682 \item State~$N$: new line
1683 \item State~$S$: skipping spaces
1684 \item State~$M$: middle of line
1685 \item State~$K$: after a Japanese character
1686 \end{itemize}
1687 The first three states---$N$, $S$~and~$M$---are as same as \TeX's input
1688 processor.  State~$K$ is similar to state~$M$, and is entered after
1689 Japanese characters.  The diagram of state transitions are indicated in
1690 Figure~\ref{fig-ptexipro}.  Note that \pTeX\ doesn't leave state~$K$
1691 after `beginning/ending of a group' characters.
1692 %</en>
1693
1694 %<*ja>
1695 欧文では文章の改行は単語間でしか行わない.そのため,\TeX では,(文字の直後の)改行は
1696 空白文字と同じ扱いとして扱われる.一方,和文ではほとんどどどこでも改行が可能なため,
1697 \pTeX では和文文字の直後の改行は単純に無視されるようになっている.
1698
1699 このような動作は,\pTeX が\TeX からエンジンとして拡張されたことによって可能になったことである.
1700 \pTeX の入力処理部は,\TeX におけるそれと同じように,有限オートマトンとして記述することができ,
1701 以下に述べるような4状態を持っている.
1702
1703 \begin{itemize}
1704 \item State~$N$: 行の開始.
1705 \item State~$S$: 空白読み飛ばし.
1706 \item State~$M$: 行中.
1707 \item State~$K$: 行中(和文文字の後).
1708 \end{itemize}
1709 また,状態遷移は,図\label{fig-ptexipro}のようになっており,図中の数字は
1710 カテゴリーコードを表している.最初の3状態は\TeX の入力処理部と同じであり,
1711 図中から状態$K$と「$j$」と書かれた矢印を取り除けば,\TeX の入力処理部と同
1712 じものになる.
1713
1714 この図から分かることは,
1715 \begin{quote}
1716 行が和文文字(とグループ境界文字)で終わっていれば,改行は無視される
1717 \end{quote}
1718 ということである.
1719 %</ja>
1720
1721 \begin{figure}[!tb]
1722 \begin{gather*}
1723  \def\sp{\text{\tt\char32}}
1724  \xymatrix{&&
1725    {\text{scan a cs}}\ar@(r,ul)[dr]&\\
1726 \ar[r]&
1727    *++[o][F-]{N}\ar[ur]^0\ar[dd]_{d,\ g}\ar[u]^{5\ (\text{\tt\char92par})}
1728      \ar@{->}@(d,l)[ddrr]_(0.45){j}&&
1729    *++[o][F-]{S}\ar@(l,dr)[ul]^0\ar@(l,ur)[ddll]_{d,\ g}\ar[u]_{5}
1730      \ar@{->}@(r,r)[dd]^{j}\\&\\&
1731    *++[o][F-]{M}\ar[uuur]^0\ar@(r,dl)[uurr]_(0.55){10\ (\sp)}
1732      \ar[d]_{5\ ({\sp})}\ar@{->}@(dr,dl)[rr]_{j}&&
1733    *++[o][F-]{K}\ar@{->}@(ul,d)[uuul]^0\ar@{->}[ll]^{d}
1734      \ar@{->}@(ur,dr)[uu]^{10\ (\sp)}\ar@{->}[d]_5\\
1735    &&&
1736  }\\
1737  d:=\{3,4,6,7,8,11,12,13\},\quad g:=\{1,2\},\quad j:=(\text{Japanese characters})
1738 \end{gather*}
1739 \begin{itemize}
1740 \item Numbers represent category codes.
1741 \item Category codes 9~(ignored), 14~(comment)~and~15~(invalid) are omitted in above diagram.
1742 \end{itemize}
1743 \caption{State transitions of \pTeX's input processor.}
1744 \label{fig-ptexipro}
1745 \end{figure}
1746
1747
1748 \subsection{Behavior in \LuaTeX-ja}
1749 %<*en>
1750 States in the input processoe of \LuaTeX\ is the same as that of \TeX,
1751 and they can't be customized by any callbacks. Hence, we can only use
1752 \verb+process_input_buffer+ and \verb+token_filter+ callbacks for to
1753 suppress a space by a linebreak which is after Japanese characters.
1754
1755 However, \verb+token_filter+ callback cannot be used either, since a
1756 character in category code 5~(end-of-line) is converted into an space
1757 token \emph{in the input processor}.  So we can use only the
1758 \verb+process_input_buffer+ callback.  This means that suppressing a
1759 space must be done \emph{just before} an input line is read.
1760
1761 Considering these situations, handling of an end-of-line in \LuaTeX-ja are as follows:
1762 \begin{quote}
1763 A character U+FFFFF (its category code is set to 14~(comment) by
1764 \LuaTeX-ja) is appended to an input line, \emph{before \LuaTeX\ actually
1765 process it}, if and only if the following two conditions are satisfied:
1766 \begin{enumerate}
1767 \item The category code of the character $\langle${return}$\rangle$
1768       (whose character code is 13) is 5~(end-of-line).
1769 \item The input line matches the following `regular expression':
1770 \[
1771   (\text{any char})^*(\textbf{JAchar})
1772   \bigl(\{\text{catcode}=1\}\cup\{\text{catcode}=2\}\bigr)^*
1773 \]
1774 \end{enumerate}
1775 \end{quote}
1776
1777 \paragraph{Remark}
1778 The following example shows the major difference from the behavior of \pTeX:
1779 \begin{LTXexample}
1780 \ltjsetparameter{autoxspacing=false}
1781 \ltjsetparameter{jacharrange={-6}}xあ
1782 y\ltjsetparameter{jacharrange={+6}}zあ
1783 u
1784 \end{LTXexample}
1785 \begin{itemize}
1786 \item There is no space between `x' and `y', since the line~2 ends with a \textbf{JAchar} `あ'
1787 (this `あ' considered as an \textbf{JAchar} at the ending of line~1).
1788 \item There is no space between `あ' (in the line~3) and `u', since the
1789       line~3 ends with an \textbf{ALchar}
1790 (the letter `あ' considered as an \textbf{ALchar} at the ending of line~2).
1791 \end{itemize}
1792 %</en>
1793
1794 %<*ja>
1795 \LuaTeX の入力処理部は\TeX のそれと全く同じであり,callbackによりユーザが
1796 カスタマイズすることはできない.このため,改行抑制の目的でユーザが利用で
1797 きそうなcallbackとしては,\verb+process_input_buffer+や
1798 \verb+token_filter+に限られてしまう.しかし,\TeX の入力処理部をよく見る
1799 と,後者も役には経たないことが分かる:改行文字は,入力処理部によってトー
1800 クン化される時に,カテゴリーコード10の32番文字へと置き換えられてしまうた
1801 め,\verb+token_filter+で非標準なトークン読み出しを行おうとしても,空白文
1802 字由来のトークンと,改行文字由来のトークンは区別できないのだ.
1803
1804 すると,我々のとれる道は,\verb+process_input_buffer+を用いて
1805 \LuaTeX の入力処理部に引き渡される前に入力文字列を編集するというものしかない.
1806 以上を踏まえ,\LuaTeX-jaにおける「和文文字直後の改行抑制」の処理は,次のようになっている:
1807
1808 \begin{quote}
1809 各入力行に対し,\textbf{その入力行が読まれる前の内部状態で}
1810 以下の2条件が満たされている場合,\LuaTeX-jaはU+FFFFF番の文字
1811 \footnote{この文字はコメント文字として扱われるように\LuaTeX-ja内部で設定をしている.}
1812 を末尾に追加する.よって,その場合に改行は空白とは見做されないこととなる.
1813 \begin{enumerate}
1814 \item 改行文字(文字コード13番)のカテゴリーコードが5~(end-of-line)である.
1815 \item 入力行は次の「正規表現」にマッチしている:
1816 \[
1817   (\text{any char})^*(\textbf{JAchar})
1818   \bigl(\{\text{catcode}=1\}\cup\{\text{catcode}=2\}\bigr)^*
1819 \]
1820 \end{enumerate}
1821 \end{quote}
1822
1823 この仕様は,前節で述べた\pTeX の仕様にできるだけ近づけたものとなっている.最初の条件は,
1824 \texttt{verbatim}系環境などの日本語対応マクロを書かなくてすませるためのものである.
1825 しかしながら,完全に同じ挙動が実現できたわけではない.
1826 差異は,次の例が示すように,和文文字の範囲を変更した行の改行において見られる:
1827 \begin{LTXexample}
1828 \ltjsetparameter{autoxspacing=false}
1829 \ltjsetparameter{jacharrange={-6}}xあ
1830 y\ltjsetparameter{jacharrange={+6}}zあ
1831 u
1832 \end{LTXexample}
1833 もし\pTeX とまったく同じ挙動を示すならば,出力は
1834 「\hbox{\ltjsetparameter{autoxspacing=false}x yzあu}」となるべきである.しかし,実際には
1835 上のように異なる挙動となっている.
1836 \begin{itemize}
1837 \item 2行目は「あ」という和文文字で終わる(2行目を処理する前の時点では,
1838       「あ」は和文文字扱いである)ため,直後の改行文字は無視される.
1839 \item 3行目は「あ」という欧文文字で終わる(2行目を処理する前の時点では,
1840       「あ」は欧文文字扱いである)ため,直後の改行文字は空白に置き換わる.
1841 \end{itemize}
1842 このため,トラブルを避けるために,和文文字の範囲を\verb+\ltjsetparameter+で編集した場合,
1843 その行はそこで改行するようにした方がいいだろう.
1844 %</ja>
1845
1846
1847 \section{Insertion of JFM glues, \textsf{kanjiskip} and \textsf{xkanjiskip}}
1848 \subsection{Overview}
1849 %<*en>
1850 NOT COMPLETED
1851 %</en>
1852
1853 %<*ja>
1854 \LuaTeX-ja における和文処理グルーの挿入方法は,\pTeX のそれとは全く異なる.
1855 \pTeX では次のような仕様であった:
1856 \begin{itemize}
1857 \item JFMグルーの挿入は,和文文字を表すトークンを元に水平リストに(文字を表す)<char\_node>を
1858 追加する過程で行われる.
1859 \item \textsf{xkanjiskip}の挿入は,hboxへのパッケージングや行分割前に行われる.
1860 \item \textsf{kanjiskip}はノードとしては挿入されない.パッケージングや行分割の計算時に
1861 「和文文字を表す2つの<char\_node>の間には\textsf{kanjiskip}がある」ものとみなされる.
1862 \end{itemize}
1863 しかし,\LuaTeX-jaでは,hboxへのパッケージングや行分割前に全ての
1864 \textbf{JAglue},即ちJFMグルー・\textsf{xkanjiskip}・\textsf{kanjiskip}の
1865 3種類を一度に挿入することになっている.これは,\LuaTeX において欧文の合字・
1866 カーニング処理がノードベースになったことに対応する変更である.
1867
1868 \LuaTeX-jaにおける\textbf{JAglue}挿入処理では,下の図\ref{fig-clu}のよう
1869 に「塊」を単位にして行われる.大雑把にいうと,「塊」は文字とそれに付随す
1870 るノード達(アクセント位置補正用のkernや,イタリック補正)をまとめたもの
1871 であり,2つの塊の間には,ペナルティ,\verb+\vadjust+,whatsitなど,行組版
1872 には関係しないものがある.そのため,……
1873 %</ja>
1874
1875 % \begin{figure}[!tb]
1876 % \unitlength=10mm
1877 % \end{figure}
1878
1879 \subsection{Definition of a `cluster'}
1880
1881 \begin{defn}
1882 A \emph{cluster} is a list of nodes in one of the following forms, with the \textit{id} of it:
1883 \begin{enumerate}
1884 \item Nodes whose value of\ \verb+\ltj@icflag+ is in $[3,15)$.  These
1885       nodes come from a hbox which is already packaged, by unpackaging
1886       (\verb+\unhbox+).
1887       The \textit{id} is \textit{id\_pbox}.
1888 \item A inline math formula, including two \textit{math\_node}s at the boundary of it:
1889 HOGE
1890       The \textit{id} is \textit{id\_math}.
1891 \item A \textit{glyph\_node} with nodes which relate with it: 
1892 HOGE
1893 The \textit{id} is \textit{id\_jglyph} or
1894 \textit{id\_glyph}, according to whether the \textit{glyph\_node}
1895 represents a Japanese character or not.
1896 \item An box-like node, that is, an hbox, an vbox and an rule (\verb+\vrule+). 
1897 The \textit{id} is \textit{id\_hlist} if the node is an
1898       hbox which is not shifted vertically, or \textit{id\_box\_like}
1899       otherwise.
1900 \item A glue, a kern whose subtype is not 2~(\textit{accent}), and a discretionary break.
1901 The \textit{id} is \textit{id\_glue}, \textit{id\_kern}
1902       and \textit{id\_disc}, respectively.
1903 %Just a node which will \dots, \textit{i.e.}, a node which is \emph{not} one of the following:
1904 %\textit{ins\_node}, \textit{mark\_node}, \textit{adjust\_node}, \textit{whatsit\_node}
1905 %and \textit{penalty\_node}.
1906 \end{enumerate}
1907 We denote a cluster by \textit{Np}, \textit{Nq} and \textit{Nr}.
1908 \end{defn}
1909
1910 Internally, a cluster is represented by a table $\textit{Np}$ with the following fields.
1911
1912 \begin{description}
1913 \def\makelabel#1{\textbf{\textit{#1}}}
1914 \item[first, last] The first/last node of the cluster.
1915 \item[id] The \textit{id} in above definition.
1916 \item[nuc]
1917
1918 % jachar
1919 \item[auto\_kspc, auto\_xspc]
1920 \item[xspc\_before, xspc\_after]
1921
1922 % alchar, jachar
1923 \item[pre, post]
1924 \item[char]
1925 \item[class]
1926 \item[lend]
1927 \item[met, var]
1928 \end{description}
1929 \end{document}