OSDN Git Service

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