OSDN Git Service

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