OSDN Git Service

unhbox and unvbox.
[luatex-ja/luatexja.git] / doc / luatexja.dtx
1 %<*!showexpl>
2 %#! lualatex -shell-escape
3
4 % To typeset this manual, you need following two fonts:
5 %  - KozMinPr6N-Regular.otf
6 %  - KozGoPr6N-Medium.otf
7 %  - KozGoPr6N-Regular.otf
8
9 %%%%% section ==> 章
10 %%%%% subsection => 節
11
12 %<en>\documentclass[a4paper,titlepage]{article}
13 %<ja>\documentclass[a4paper,titlepage]{ltjsarticle}
14
15 %%%%%%%%
16 \makeatletter
17 %%%%%%%%
18
19 %%%%%%%% record loaded packages
20 \let\ltjpkglist\empty
21 \newif\if@real@append@list
22 \def\@append@newentry#1#2{{%
23   \@real@append@listtrue \def\@tempa{#2}%
24   \let\@pkglist\@append@newentry@pkglist#1%
25   \if@real@append@list
26     \let\@pkglist=\relax\xdef#1{#1\@pkglist{#2}}%
27   \fi}}
28 \def\@append@newentry@pkglist#1{%
29   \def\@tempb{#1}%
30   \ifx\@tempa\@tempb\@real@append@listfalse\fi}
31 \def\@addtofilelist#1{\@append@newentry\ltjpkglist{#1}}
32 \let\@listfiles\empty
33
34 %<*en>
35 \usepackage[margin=25mm,lmargin=30mm,rmargin=30mm,footskip=6mm]{geometry}
36 \usepackage{luatexja-adjust}\ltjdisableadjust
37 \parskip=\smallskipamount
38 \renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}%
39     {3.25ex \@plus1ex \@minus.2ex}%
40     {-1em}%
41     {\normalfont\normalsize\bfseries\raisebox{.2ex}{$\mdlgblksquare\mkern1mu$}}}
42 %</en>
43 %<*ja>
44 \usepackage[textwidth=45\zw, lines=45, footskip=6mm]{geometry}
45 \usepackage{luatexja-adjust}%\ltjdisableadjust
46 \advance\leftmargini-1\zw\advance\leftmarginii-1\zw
47 %</ja>
48
49 \usepackage{amsmath,array,tikz,pict2e,multienum,float}
50 \usepackage{booktabs,multicol,luatexja-ruby}
51 \usepackage{xy}
52
53 %%%%%%%% listings
54
55 %%%%%%%% IVS
56
57 \def\IVS#1{\char\numexpr "E0100+#1\relax}%"
58 \def\IVSA#1#2#3#4#5{%
59   \textcolor{blue}{\raisebox{3.5pt}{\tt%
60     \fboxsep=0.5pt\fbox{\tiny \oalign{0#1#2\crcr#3#4#5\crcr}}}}%
61 }
62 {\catcode`\%=11
63   \gdef\IVSB#1{\expandafter\IVSA\directlua{
64     local cat_str = luatexbase.catcodetables['string']
65     tex.sprint(cat_str, string.format('%X', 0xE00EF+#1))
66 }}}
67
68 \usepackage{listings,showexpl}
69 \lstset{
70   basicstyle=\ttfamily\small, pos=r, breaklines=true,
71   numbers=none, rframe={}, basewidth=0.5em, numberstyle=\tiny, numbersep=0.5em,
72   explpreset={numberstyle=\tiny, numbers=left, numbersep=1em, columns=fixed}
73 }
74 % Suppress output from showexpl to stdout.
75 \let\SX@Info\relax
76
77 %%%%%%%% hyperref
78 \usepackage{hyperref,bookmark}
79 %<*en>
80 \title{The \LuaTeX-ja package}
81 \author{The \LuaTeX-ja project team}
82 %</en>
83 %<*ja>
84 \title{\LuaTeX-jaパッケージ}
85 \author{\LuaTeX-jaプロジェクトチーム}
86 %</ja>
87 \hypersetup{%
88         unicode,
89         colorlinks,
90         allbordercolors=1 1 1,
91         allcolors=blue,
92 %<*en>
93         pdfauthor={The LuaTeX-ja project team},
94         pdftitle={The LuaTeX-ja package}
95 %</en>
96 %<*ja>
97         pdfauthor={LuaTeX-jaプロジェクトチーム},
98         pdftitle={LuaTeX-jaパッケージ}
99 %</ja>
100 }
101
102 %%%%%%%% definition env.
103 \usepackage{amsthm}
104 \theoremstyle{definition}
105 %<en>\newtheorem{defn}{Definition}
106 %<ja>\newtheorem{defn}{定義}
107
108 %%%%%%%% fonts
109 \usepackage{luatexja-otf}
110 %<ja>\usepackage{lmodern}
111 \directlua{luatexja.otf.enable_ivs()}
112 \usepackage[match]{luatexja-fontspec}
113 \usepackage[kozuka-pr6n]{luatexja-preset}
114 \setmonojfont{KozGoPr6N-Regular.otf}
115 %<*ja>
116 \def\emph#1{\textbf{\textgt{#1}}}
117 \def\headfont{\normalfont\bfseries\gtfamily}
118 \usepackage{amssymb}
119 %</ja>
120 %<*en>
121 \usepackage{unicode-math}
122 \setmainfont[Ligatures=TeX]{TeX Gyre Termes}
123 \setsansfont[Scale=0.95,Ligatures=TeX]{TeX Gyre Heros}
124 \setmathfont{xits-math.otf}
125 \frenchspacing
126 %</en>
127
128 %%%%%%%% logo
129 \usepackage{metalogo}
130 \DeclareRobustCommand\eTeX{\ensuremath{\varepsilon}-\kern-.125em\TeX}
131 \DeclareRobustCommand\LuaTeX{Lua\TeX}
132 \DeclareRobustCommand\pdfTeX{pdf\TeX}
133 \DeclareRobustCommand\pTeX{p\kern-.15em\TeX}
134 \DeclareRobustCommand\upTeX{up\kern-.15em\TeX}
135 \DeclareRobustCommand\pLaTeX{p\kern-.05em\LaTeX}
136 \DeclareRobustCommand\pLaTeXe{p\kern-.05em\LaTeXe}
137 \DeclareRobustCommand\epTeX{\ensuremath{\varepsilon}-\kern-.125em\pTeX}
138
139 %%%%%%%% other macros
140 \newenvironment{cslist}{%
141 %<ja>  \leftskip2\zw
142 %<en>  \leftskip2em
143   \parindent=0pt\def\makelabel##1{{\tt\textbackslash ##1}}
144   \def\{{\char`\{}\def\}{\char`\}}
145   \let\origitem=\item
146   \def\item[##1]{\par\smallskip\par\hskip-\leftskip\makelabel{##1}\par}
147   \@totalleftmargin\leftskip
148 }{\par%
149 %<en>\medskip
150 }
151
152 \def\labelenumii{(\arabic{enumii})}
153 \long\def\@makecaption#1#2{%
154   \vskip\abovecaptionskip
155   \sbox\@tempboxa{{\small #1. #2}}%
156   \ifdim \wd\@tempboxa >\hsize
157     {\small #1. #2}\par
158   \else
159     \global \@minipagefalse
160     \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
161   \fi
162   \vskip\belowcaptionskip}
163
164 \def\_{\leavevmode \kern .06em\vbox {\hrule \@width .333em}}
165
166 %%%%%%%%
167 \makeatother
168 %%%%%%%%
169
170 \def\Node#1#2{\,\vcenter{\hbox{\fboxsep=1pt\fbox{\vbox{\small\halign{\hfil##\hfil\cr
171   #1\mathstrut\cr\noalign{\hrule height.4pt}\strut#2\cr}}}}\,}}
172
173 \protected\def\Param#1{\textsf{#1}} % parameter name
174 \protected\def\Pkg#1{\underline{\smash{\texttt{#1}}}} % packages/classes
175
176
177 \begin{document}
178 \lstset{
179   vscmd=\IVSB
180 }
181
182 \catcode`\<=13
183 \def<#1>{{\normalfont\rm\itshape$\langle$#1\/$\rangle$}}
184 \let\LARG=<
185 \maketitle
186
187 \tableofcontents
188 \bigskip
189
190 %<*en>
191 \textbf{This documentation is far from complete. It may have many
192 grammatical (and contextual) errors.} Also, several parts
193 are written in Japanese only.
194 %</en>
195 %<*ja>
196 \emph{\large 本ドキュメントはまだまだ未完成です.}
197 %</ja>
198
199 \clearpage
200 %<en>\part{User's manual}
201 %<ja>\part{ユーザーズマニュアル}
202
203 %<en>\section{Introduction}
204 %<ja>\section{はじめに}
205
206
207 %<*en>
208 The \LuaTeX-ja package is a macro package for typesetting high-quality
209 Japanese documents when using \LuaTeX.
210 %</en>
211 %<*ja>
212 \LuaTeX-jaパッケージは,次世代標準\TeX である\LuaTeX の上で,\pTeX と同等
213 /それ以上の品質の日本語組版を実現させようとするマクロパッケージである.
214 %</ja>
215 %<en>\subsection{Backgrounds}
216 %<ja>\subsection{背景}
217
218 %<*en>
219 Traditionally, ASCII \pTeX, an extension of \TeX, and its derivatives
220 are used to typeset Japanese documents in \TeX. \pTeX\ is an engine
221 extension of \TeX: so it can produce high-quality Japanese documents
222 without using very complicated macros. But this point is a mixed
223 blessing: \pTeX\ is left behind from other extensions of \TeX,
224 especially \eTeX\ and \pdfTeX, and from changes about
225 Japanese processing in computers (\textit{e.g.}, the UTF-8 encoding).
226 %</en>
227 %<*ja>
228 従来,「\TeX を用いて日本語組版を行う」といったとき,エンジンとしては
229 ASCII \pTeX やそれの拡張物が用いられることが一般的であった.\pTeX は\TeX
230 のエンジン拡張であり,(少々仕様上不便な点はあるものの)商業印刷の分野に
231 も用いられるほどの高品質な日本語組版を可能としている.だが,それは弱点に
232 もなってしまった:\pTeX という(組版的に)満足なものがあったため,海外で
233 行われている数々の\TeX の拡張――例えば\eTeX や\pdfTeX ――や,TrueType,
234 OpenType, Unicodeといった計算機で日本語を扱う際の状況の変化に追従すること
235 を怠ってしまったのだ.
236 %</ja>
237
238 %<*en>
239 Recently extensions of \pTeX, namely \upTeX\ (Unicode-implementation
240 of \pTeX) and \epTeX\ (merging of \pTeX\ and
241 \eTeX\ extension), have developed to fill those gaps to some
242 extent, but gaps still exist.
243 %</en>
244 %<*ja>
245 ここ数年,若干状況は改善されてきた.現在手に入る大半の\pTeX バイナリでは
246 外部UTF-8入力が利用可能となり,さらにUnicode化を推進し,\pTeX の内部処理
247 までUnicode化した\upTeX も開発されている.また,\pTeX に\eTeX 拡張をマー
248 ジした\epTeX も登場し,\TeX\ Live\ 2011では\pLaTeX が\epTeX の上で動作す
249 るようになった.だが,\pdfTeX 拡張(PDF直接出力やmicro-typesetting)を
250 \pTeX に対応させようという動きはなく,海外とのgapは未だにあるのが現状であ
251 る.
252 %</ja>
253
254 %<*en>
255 However, the appearance of \LuaTeX\ changed the whole situation. With
256 using Lua ``callbacks'', users can customize the internal processing of
257 \LuaTeX. So there is no need to modify sources of engines to
258 support Japanese typesetting: to do this, we only have to write Lua
259 scripts for appropriate callbacks.
260 %</en>
261 %<*ja>
262 しかし,\LuaTeX の登場で,状況は大きく変わることになった.Luaコードで
263 ``callback''を書くことにより,\LuaTeX の内部処理に割り込みをかけることが可
264 能となった.これは,エンジン拡張という真似をしなくても,Luaコードとそれに
265 関する\TeX マクロを書けば,エンジン拡張とほぼ同程度のことができるようになっ
266 たということを意味する.\LuaTeX-jaは,このアプローチによってLuaコード・
267 \TeX マクロによって日本語組版を\LuaTeX の上で実現させようという目的で開発
268 が始まったパッケージである.
269 %</ja>
270
271 %<en>\subsection{Major Changes from \pTeX}
272 %<ja>\subsection{\pTeX からの主な変更点}
273 \label{ssec:chgptex}
274
275 %<*en>
276 The \LuaTeX-ja package is under much influence of \pTeX\ engine. The initial
277 target of development was to implement features of \pTeX. However,
278 \emph{\LuaTeX-ja is not a just porting of \pTeX; unnatural
279 specifications/behaviors of \pTeX\ were not adopted}.
280 %</en>
281 %<*ja>
282 \LuaTeX-jaは,\pTeX に多大な影響を受けている.初期の開発目標は,\pTeX の機
283 能をLuaコードにより実装することであった.しかし,開発が進むにつれ,\pTeX
284 の完全な移植は不可能であり,また\pTeX における実装がいささか不可解になっ
285 ているような状況も発見された.そのため,\emph{\LuaTeX-jaは,もはや
286 \pTeX の完全な移植は目標とはしない.\pTeX における不自然な仕様・挙動があ
287 れば,そこは積極的に改める.}
288 %</ja>
289
290 %<*en>
291 The followings are major changes from \pTeX:
292 %</en>
293 %<*ja>
294 以下は \pTeX からの主な変更点である.
295 %</ja>
296
297 \begin{itemize}
298 %<*en>
299 \item A Japanese font is a tuple of a ``real'' font, a Japanese font
300       metric (\emph{JFM}, for short).
301 %</en>
302 %<*ja>
303 \item 和文フォントは(小塚明朝,IPA明朝などの)実際のフォント,和文フォン
304       トメトリック(JFMと呼ぶ\footnote{混乱を防ぐため,p\TeX の意味での
305       JFM (\texttt{min10.tfm}) などは本ドキュメントでは\emph{和文用
306       TFM}とよぶことにする.})の組である.
307 %</ja>
308
309 %<*en>
310 \item In \pTeX, a line break after Japanese character is ignored (and
311       doesn't yield a space), since line breaks (in source files) are
312       permitted almost everywhere in Japanese texts. However, \LuaTeX-ja
313       doesn't have this function completely, because of a specification
314       of \LuaTeX.
315 %</en>
316 %<*ja>
317 \item 日本語の文書中では改行はほとんどどこでも許されるので,\pTeX では和文文字
318       直後の改行は無視される(スペースが入らない)ようになっていた.しかし,
319       \LuaTeX-ja では \LuaTeX の仕様のためにこの機能は完全には実装されていない.
320 %</ja>
321
322 %<*en>
323 \item The insertion process of glues/kerns between two Japanese
324       characters and between a Japanese character and other characters
325       (we refer glues/kerns of both kinds as \textbf{JAglue}) is rewritten from
326       scratch.
327 %</en>
328 %<*ja>
329 \item 2つの和文文字の間や,和文文字と欧文文字の間に入るグルー/カーン
330       (両者をあわせて\textbf{JAglue}と呼ぶ)の挿入処理が0から書き直されている.
331 %</ja>
332
333 \begin{itemize}
334 %<*en>
335 \item As \LuaTeX's internal ligature handling is ``node-based''
336       (\textit{e.g.}, \verb+of{}fice+ doesn't prevent ligatures), the
337       insertion process of \textbf{JAglue} is now ``node-based''.
338 %</en>
339 %<*ja>
340 \item \LuaTeX の内部での合字の扱いは「ノード」を単位として行われるようになっている(例えば,
341       \verb+of{}fice+ で合字は抑制されない).それに合わせ,\textbf{JAglue}の挿入処理も
342       ノード単位で実行される.
343 %</ja>
344
345 %<*en>
346 \item Furthermore, nodes between two characters which have no effects in
347       line break (\textit{e.g.}, \verb+\special+ node) and kerns from
348       italic correction are ignored in the insertion process.
349 %</en>
350 %<*ja>
351 \item さらに,2つの文字の間にある行末では効果を持たないノード(例えば \verb+\special+ ノード)や,
352   イタリック補正に伴い挿入されるカーンは挿入処理中では無視される.
353 %</ja>
354
355 %<*en>
356 \item \emph{Caution: due to above two points, many methods which did for the
357       dividing the process of the insertion of \textbf{JAglue} in \pTeX\ are not
358       effective anymore.} In concrete terms, the following two methods are not effective anymore:
359 %</en>
360 %<*ja>
361 \item \emph{注意:上の2つの変更により,従来\textbf{JAglue}の挿入処理を分断するのに
362       使われていたいくつかの方法は用いることができない.具体的には,次の方法はもはや無効である:}
363 %</ja>
364 \begin{verbatim}
365 ちょ{}っと    ちょ\/っと
366 \end{verbatim}
367 %<*en>
368       If you want to do so, please put an empty horizontal box (hbox) between it instead:
369 %</en>
370 %<*ja>
371       もし同じことをやりたければ,空の水平ボックス(hbox)を間に挟めばよい:
372 %</ja>
373 \begin{verbatim}
374 ちょ\hbox{}っと
375 \end{verbatim}
376
377
378 %<*en>
379 \item In the process, two Japanese fonts which only differ in their ``real''
380       fonts are identified. 
381 %</en>
382 %<*ja>
383 \item 処理中では,2つの和文フォントは,実フォントが異なるだけの場合には同一視
384       される.
385 %</ja>
386 \end{itemize}
387
388 %<*ja>
389 \item \LuaTeX-jaでは,\pTeX と同様に漢字・仮名を制御綴内に用いることができ,
390 \verb+\西暦+ などが正しく動作するようにしている.
391 但し,制御綴中に使える和文文字が\pTeX・\upTeX と全く同じではないことに注意すること.
392 %</ja>
393
394 %<*ja>
395 \item ****版からは,不安定ながらも\LuaTeX-ja における縦組みをサポートしている.
396 \LuaTeX のコールバックの制限などにより,特に異なった組方向のボックスを扱う場合には
397 仕様が異なるので注意すること.
398 %</ja>
399 \end{itemize}
400
401 %<*en>
402 For detailed information, see Part~\ref{part-imp}.
403 %</en>
404 %<*ja>
405 詳細については第\ref{part-imp}部を参照.
406 %</ja>
407
408 %<en>\subsection{Notations}
409 %<ja>\subsection{用語と記法}
410
411 %<*en>
412 In this document, the following terms and notations are used:
413 %</en>
414 %<*ja>
415 本ドキュメントでは,以下の用語と記法を用いる:
416 %</ja>
417 \begin{itemize}
418 %<*en>
419 \item Characters are classified into following two types.
420       Note that the classification can be customized by a user
421       (see Subsection~\ref{ssec-setrange}).
422 %</en>
423 %<*ja>
424 \item 文字は次の2種類に分けられる.この類別はユーザが後から変更可能である
425       (\ref{ssec-setrange}節を参照).
426 %</ja>
427 \begin{itemize}
428 %<*en>
429 \item \textbf{JAchar}: standing for characters which used in Japanese typesetting,
430       such as Hiragana,~Katakana, Kanji, and~other Japanese punctuation marks.
431 %</en>
432 %<*ja>
433 \item \textbf{JAchar}: ひらがな,カタカナ,漢字,和文用の約物といった
434       日本語組版に使われる文字のことを指す.
435 %</ja>
436
437 %<en>\item \textbf{ALchar}: standing for all other characters like latin alphabets.
438 %<ja>\item \textbf{ALchar}: ラテンアルファベットを始めとする,その他全ての文字を指す.
439 \end{itemize}
440
441 %<*en>
442 We say \emph{alphabetic fonts} for fonts used in \textbf{ALchar}, 
443 and \emph{Japanese fonts} for fonts used in \textbf{JAchar}.
444 %</en>
445 %<*ja>
446 そして,\textbf{ALchar}の出力に用いられるフォントを\emph{欧文フォント}と呼び,
447 \textbf{JAchar}の出力に用いられるフォントを\emph{和文フォント}と呼ぶ.
448 %</ja>
449 %<*en>
450 \item A word in a sans-serif font (like \Param{\hyperlink{fld:prebp}{prebreakpenalty}})
451       means an internal parameter for Japanese typesetting, and it
452       is used as a key in \verb+\ltjsetparameter+ command.
453 %</en>
454 %<*ja>
455 \item サンセリフ体で書かれた語(例:\Param{\hyperlink{fld:prebp}{prebreakpenalty}})は日本語組版用の
456       パラメータを表し,これらは \verb+\ltjsetparameter+ コマンドのキーとして
457       用いられる.
458 %</ja>
459 %<*en>
460 \item A word in typewriter font with underline (like \Pkg{fontspec})
461       means a package or a class of \LaTeX.
462 %</en>
463 %<*ja>
464 \item 下線付きタイプライタ体の語(例:\Pkg{fontspec})は\LaTeX の
465       パッケージやクラスを表す.
466 %</ja>
467 %<*en>
468 \item In this document, natural numbers start from~zero.
469   $\omega$ denotes the set of all natural numbers.
470 %</en>
471 %<*ja>
472 \item 本ドキュメントでは,自然数は0から始まる.自然数全体の集合は$\omega$と表記する.
473 %</ja>
474 \end{itemize}
475
476 %<en>\subsection{About the Project}
477 %<ja>\subsection{プロジェクトについて}
478
479 %<en>\paragraph{Project Wiki} Project Wiki is under construction.
480 %<ja>\paragraph{プロジェクトWiki} プロジェクトWikiは構築中である.
481 %<*en>
482 \begin{itemize}
483 \item \url{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage%28en%29} (English)
484 \item \url{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage} (Japanese)
485 \item \url{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage%28zh%29} (Chinese)
486 \end{itemize}
487 %</en>
488 %<*ja>
489 \begin{itemize}
490 \item \url{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage}(日本語)
491 \item \url{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage%28en%29}(英語)
492 \item \url{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage%28zh%29}(中国語)
493 \end{itemize}
494 %</ja>
495
496 %<en>This project is hosted by SourceForge.JP.
497 %<ja>本プロジェクトはSourceForge.JPのサービスを用いて運営されている.
498
499 %<en>\paragraph{Members}\
500 %<ja>\paragraph{開発メンバー}\
501
502 %<*en>
503 \begin{multienumerate}
504 \def\labelenumi{$\bullet$}
505 \mitemxxx{Hironori KITAGAWA}{Kazuki MAEDA}{Takayuki YATO}
506 \mitemxxx{Yusuke KUROKI}{Noriyuki ABE}{Munehiro YAMAMOTO}
507 \mitemxxx{Tomoaki HONDA}{Shuzaburo SAITO}{MA Qiyuan}
508 \end{multienumerate}
509 %</en>
510 %<*ja>
511 \begin{multienumerate}
512 \def\labelenumi{$\bullet$}
513 \mitemxxx{北川 弘典}{前田 一貴}{八登 崇之}
514 \mitemxxx{黒木 裕介}{阿部 紀行}{山本 宗宏}
515 \mitemxxx{本田 知亮}{齋藤 修三郎}{馬 起園}
516 \end{multienumerate}
517 %</ja>
518
519 % \paragraph{Acknowledgments} -- 挿入するならここ
520
521 \clearpage
522 %<en>\section{Getting Started}
523 %<ja>\section{使い方}
524 %<en>\subsection{Installation}
525 %<ja>\subsection{インストール}
526
527 %<en>To install the \LuaTeX-ja\ package, you will need:
528 %<ja>\LuaTeX-jaパッケージのインストールには,次のものが必要である.
529 \begin{itemize}
530 \item \LuaTeX\ beta-0.74.0 (or later)
531 \item \Pkg{luaotfload} v2.2 (or later)
532 \item \Pkg{luatexbase} v0.6
533 \item \Pkg{xunicode} v0.981~(2011/09/09)
534 \item \Pkg{adobemapping} (Adobe cmap and pdfmapping files)
535 \item \Pkg{everysel}
536 \end{itemize}
537
538 %<*en>
539 \emph{This version of \LuaTeX-ja no longer supports \TeX~Live~2012 (or older version),
540 since \LuaTeX\ binary and \Pkg{luaotfload} is updated in
541 \TeX~Live~2013.}
542
543 \medskip
544
545 Now \LuaTeX-ja is available from the following archive and distributions:
546   \begin{itemize}
547   \item CTAN (in the \texttt{macros/luatex/generic/luatexja} directory)
548   \item MiK\TeX\ (in \texttt{luatexja.tar.lzma}); see the next subsection
549   \item \TeX\ Live (in \texttt{texmf-dist/tex/luatex/luatexja})
550   \item W32\TeX\ (in \texttt{luatexja.tar.xz})
551   \end{itemize}
552
553 If you are using \TeX~Live~2013, you can install \LuaTeX-ja 
554 from \TeX~Live manager (\texttt{tlmgr}):
555 \begin{verbatim}
556 $ tlmgr install luatexja
557 \end{verbatim}
558 %</en>
559 %<*ja>
560 \emph{本バージョンの\LuaTeX-jaは\TeX~Live~2012以前では動作しない.}
561 これは,\LuaTeX と\Pkg{luaotfload}が\TeX~Live~2013において更新されたことによる.
562
563 \medskip
564
565 現在,\LuaTeX-jaは以下のアーカイブ,およびディストリビューションに収録されている:
566   \begin{itemize}
567   \item CTAN (\texttt{macros/luatex/generic/luatexja})
568   \item MiK\TeX\ (\texttt{luatexja.tar.lzma})
569   \item \TeX\ Live (\texttt{texmf-dist/tex/luatex/luatexja})
570   \item W32\TeX\ (\texttt{luatexja.tar.xz})
571   \end{itemize}
572
573 例えば\TeX~Live~2013以降を利用しているなら,\LuaTeX-jaは\TeX~Live manager (\texttt{tlmgr})を
574 使ってインストールすることができる.
575 \begin{verbatim}
576 $ tlmgr install luatexja
577 \end{verbatim}
578 %</ja>
579
580 %<en>\paragraph{Manual installation}
581 %<ja>\paragraph{手動インストール方法}
582
583 \begin{enumerate}
584 %<*en>
585 \item Download the source archive, by one of the following method.
586       At the present, \LuaTeX-ja has no \emph{stable} release.
587
588 \begin{itemize}
589 \item Copy the Git repository:
590 \begin{verbatim}
591 $ git clone git://git.sourceforge.jp/gitroot/luatex-ja/luatexja.git
592 \end{verbatim}
593 \item Download the \texttt{tar.gz} archive of HEAD in the \texttt{master} branch from
594 \begin{flushleft}
595 \url{http://git.sourceforge.jp/view?p=luatex-ja/luatexja.git;a=snapshot;h=HEAD;sf=tgz}.
596 \end{flushleft}
597 \end{itemize} 
598
599 Note that the \texttt{master} branch, and hence the archive in CTAN, are not updated frequently;
600 the forefront of development is not the \texttt{master} branch.
601 %</en>
602 %<*ja>
603 \item ソースアーカイブを以下のいずれかの方法で取得する.現在公開されているのはあくまでも
604       開発版であって,安定版でないことに注意.
605
606 \begin{itemize}
607 \item Gitリポジトリの内容をコピーする:
608 \begin{verbatim}
609 $ git clone git://git.sourceforge.jp/gitroot/luatex-ja/luatexja.git
610 \end{verbatim}
611 \item \texttt{master}ブランチのスナップショット(\texttt{tar.gz}形式)をダウンロードする.
612 \begin{flushleft}
613 \url{http://git.sourceforge.jp/view?p=luatex-ja/luatexja.git;a=snapshot;h=HEAD;sf=tgz}.
614 \end{flushleft}
615 \end{itemize}
616 \texttt{master}ブランチ(従って,CTAN内のアーカイブも)はたまにしか更新されないことに注意.
617 主な開発は\texttt{master}の外で行われ,比較的まとまってきたらそれを\texttt{master}に
618 反映させることにしている.
619 %</ja>
620
621 %<*en>
622 \item Extract the archive. You will see \texttt{src/} and several other sub-directories.
623 But only the contents in \texttt{src/} are needed to work \LuaTeX-ja.
624 %</en>
625 %<*ja>
626 \item 「Gitリポジトリをコピー」以外の方法でアーカイブを取得したならば,それを展開する.
627       \texttt{src/}をはじめとしたいくつかのディレクトリができるが,
628       動作には\texttt{src/}以下の内容だけで十分.
629 %</ja>
630
631 %<*en>
632 \item If you downloaded this package from CTAN, you have to run following commands
633     to generate classes 
634     and \texttt{ltj-kinsoku.lua} (the file which stores default ``\textit{kinsoku}'' parameters):
635 %</en>
636 %<*ja>
637 \item もしCTANから本パッケージを取得したのであれば,日本語用クラスファイルや
638 標準の禁則処理用パラメータを
639 格納した \texttt{ltj-kinsoku.lua} を生成するために,
640 以下を実行する必要がある:
641 %</ja>
642 \begin{verbatim}
643 $ cd src
644 $ lualatex ltjclasses.ins
645 $ lualatex ltjsclasses.ins
646 $ lualatex ltjltxdoc.ins
647 $ luatex   ltj-kinsoku_make.tex
648 \end{verbatim}
649 %<*en>
650 Note that \texttt{*.\{dtx,ins\}} and \texttt{ltj-kinsoku\_make.tex} are not needed in regular use.
651 %</en>
652 %<*ja>
653 ここで使用した \texttt{*.\{dtx,ins\}} と \texttt{ltj-kinsoku\_make.tex} は
654 通常の使用にあたっては必要ない.
655 %</ja>
656
657
658
659 %<*en>
660 \item Copy all the contents of \texttt{src/} into one of your \texttt{TEXMF} tree.
661       \texttt{TEXMF/tex/luatex/luatexja/} is an example location.
662       If you cloned entire Git repository, making a symbolic link of \texttt{src/}
663       instead copying is also good.
664 %</en>
665 %<*ja>
666 \item \texttt{src}の中身を自分の\texttt{TEXMF}ツリーにコピーする.
667       場所の例としては,例えば\texttt{TEXMF/tex/luatex/luatexja/}がある.
668       シンボリックリンクが利用できる環境で,かつリポジトリを直接取得したのであれば,
669       (更新を容易にするために)コピーではなくリンクを貼ることを勧める.
670 %</ja>
671 %<*en>
672 \item If \texttt{mktexlsr} is needed to update the file name database, make it so.
673 %</en>
674 %<*ja>
675 \item 必要があれば,\texttt{mktexlsr}を実行する.
676 %</ja>
677 \end{enumerate}
678
679 %<en>\subsection{Cautions}
680 %<ja>\subsection{注意点}
681
682 \begin{itemize}
683 %<*en>
684 \item The encoding of your source file must be UTF-8. No other
685       encodings, such as EUC-JP or Shift-JIS, are not supported.
686 %</en>
687 %<*ja>
688 \item 原稿のソースファイルの文字コードはUTF-8固定である.
689       従来日本語の文字コードとして用いられてきたEUC-JPやShift-JISは使用できない.
690 %</ja>
691 %<*en>
692 \item \LuaTeX-ja is very slower than \pTeX. 
693 Generally speaking, LuaJIT\TeX\ processes \LuaTeX-ja 
694 about 30\% faster than \LuaTeX, but not always.
695 %</en>
696 %<*ja>
697 \item \LuaTeX-jaは動作が\pTeX に比べて非常に遅い.
698 コードを調整して徐々に速くしているが,まだ満足できる速度ではない.
699 LuaJIT\TeX を用いると\LuaTeX のだいたい1.3倍の速度で動くようであるが,
700 IPA mj明朝などの大きいフォントを用いた場合には\LuaTeX よりも遅くなることもある.
701 %</ja>
702 \item%
703 %<*en>
704 \textbf{Note for MiK\TeX\ users}\quad
705 \LuaTeX-ja requires that several CMap files%
706 \footnote{\texttt{UniJIS2004-UTF32-\{H,V\}} and \texttt{Adobe-Japan1-UCS2}.}
707 must be found from \LuaTeX.
708 Strictly speaking, those CMaps are needed 
709 only in the first run of \LuaTeX-ja after installing or updating.
710 But it seems that MiK\TeX\ does not satisfy this condition, 
711 so you will encounter an error like the following:
712 %</en>
713 %<*ja>
714 \LuaTeX-jaが動作するためには,\emph{導入・更新後の初回起動時に}
715 \texttt{UniJIS2004-UTF32-\{H,V\}}, \texttt{Adobe-Japan1-UCS2}という3つのCMapが
716 \LuaTeX によって見つけられることが必要である.
717 しかしMiK\TeX ではそのようになっていないので,次のエラーが発生するだろう:
718 %</ja>
719 \begin{verbatim}
720 ! LuaTeX error ...iles (x86)/MiKTeX 2.9/tex/luatex/luatexja/ltj-rmlgbm.lua
721 bad argument #1 to 'open' (string expected, got nil)
722 \end{verbatim}
723
724 %<*en>
725 If so, please execute a batch file which is written on
726 \href{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage%28en%29}{ the Project Wiki (English)}.
727 This batch file creates a temporaly directory, copy CMaps in it, 
728 run \LuaTeX-ja in this directory, and finally delete the temporaly directory.
729 %</en>
730 %<*ja>
731 そのような場合には,
732 \href{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage%28en%29}{%
733   プロジェクトWiki英語版トップページ}中に書かれているバッチファイルを
734 実行して欲しい.このバッチファイルは,作業用ディレクトリにCMap達を
735 コピーし,その中で\LuaTeX-ja の初回起動を行い,作業用ディレクトリを消す作業をしている.
736 %</ja>
737
738 \end{itemize}
739
740 %<en>\subsection{Using in plain \TeX}
741 %<ja>\subsection{plain \TeX で使う}
742 \label{ssec-plain}
743
744 %<en>To use \LuaTeX-ja in plain \TeX, simply put the following at the beginning of the document:
745 %<ja>\LuaTeX-jaを plain \TeX で使うためには,単に次の行をソースファイルの冒頭に追加すればよい:
746 \begin{verbatim}
747 \input luatexja.sty
748 \end{verbatim}
749 %<en>This does minimal settings (like \texttt{ptex.tex}) for typesetting Japanese documents:
750 %<ja>これで(\texttt{ptex.tex}のように)日本語組版のための最低限の設定がなされる:
751
752 \begin{itemize}
753 %<*en>
754 \item The following 12~Japanese fonts are preloaded:
755 \begin{center}\small
756 \begin{tabular}{cccccc}
757 \toprule
758 \textbf{direction}&
759 \textbf{classification}&\textbf{font name}&\bf `10\,pt'&\bf`7\,pt'&\bf`5\,pt'\\\midrule
760 \smash{\raisebox{-1ex}{\emph{yoko} (horizontal)}}&
761 \emph{mincho}&Ryumin-Light    &\verb+\tenmin+&\verb+\sevenmin+&\verb+\fivemin+\\
762 \emph{gothic}&GothicBBB-Medium&\verb+\tengt+ &\verb+\sevengt+ &\verb+\fivegt+\\
763 \midrule
764 \smash{\raisebox{-1ex}{\emph{tate} (vertical)}}&
765 \emph{mincho}&Ryumin-Light    &\verb+\tentmin+&\verb+\seventmin+&\verb+\fivetmin+\\
766 \emph{gothic}&GothicBBB-Medium&\verb+\tentgt+ &\verb+\seventgt+ &\verb+\fivetgt+\\
767 \bottomrule
768 \end{tabular}
769 \end{center}
770 %</en>
771 %<*ja>
772 \item 以下の12個の和文フォントが定義される:
773 \begin{center}\small
774 \begin{tabular}{cccccc}
775 \toprule
776 \emph{組方向}&\emph{字体}&\emph{フォント名}&\bf `10\,pt'&\bf`7\,pt'&\bf`5\,pt'\\\midrule
777 \smash{\raisebox{-1ex}{横組}}&
778 明朝体&Ryumin-Light    &\verb+\tenmin+&\verb+\sevenmin+&\verb+\fivemin+\\
779 ゴシック体&GothicBBB-Medium&\verb+\tengt+ &\verb+\sevengt+ &\verb+\fivegt+\\
780 \midrule
781 \smash{\raisebox{-1ex}{縦組}}&
782 明朝体&Ryumin-Light    &\verb+\tentmin+&\verb+\seventmin+&\verb+\fivetmin+\\
783 ゴシック体&GothicBBB-Medium&\verb+\tentgt+ &\verb+\seventgt+ &\verb+\fivetgt+\\
784 \bottomrule
785 \end{tabular}
786 \end{center}
787 %</ja>
788 \begin{itemize}
789 %<*en>
790 \item It is widely accepted that fonts ``Ryumin-Light'' and
791       ``GothicBBB-Medium'' aren't embedded into PDF files, and a PDF reader
792       substitute them by some external Japanese fonts (\textit{e.g.},
793       Ryumin-Light is substituted with Kozuka Mincho in Adobe Reader). 
794       We adopt this custom to the default setting.
795 %</en>
796 %<*ja>
797 \item ``Ryumin-Light''と``GothicBBB-Medium''はPDFファイルに埋め込まずに
798       名前参照のみで用いることが広く受け入れられており,この場合PDFリーダーが
799       適切な外部フォントで代用する(例えば,Adobe ReaderではRyumin-Lightは
800       小塚明朝で代替される).そこで,これらを引き続きデフォルトのフォントと
801       して採用する.
802 %</ja>
803
804 %<*en>
805 \item A character in an alphabetic font is generally smaller than a
806       Japanese font in the same size. So actual size specification of
807       these Japanese fonts is in fact smaller than that of alphabetic
808       fonts, namely scaled by 0.962216.
809 %</en>
810 %<*ja>
811 \item 欧文フォントの文字は和文フォントの文字よりも,同じ文字サイズでも
812       一般に小さくデザインされている.そこで,標準ではこれらの和文フォントの実際のサイズは指定された値よりも
813       小さくなるように設定されており,具体的には指定の0.962216倍にスケールされる.
814       この0.962216という数値も,\pTeX におけるスケーリングを踏襲した値である.
815 %</ja>
816 \end{itemize}
817
818 %<*en>
819 \item The amount of glue that are inserted between a \textbf{JAchar} and
820       an \textbf{ALchar} (the parameter \Param{\hyperlink{fld:xks}{xkanjiskip}}) is set to
821 %</en>
822 %<*ja>
823 \item \textbf{JAchar}と\textbf{ALchar}の間に入るグルー(\Param{\hyperlink{fld:xks}{xkanjiskip}})の
824       量は次のように設定されている:
825 %</ja>
826 \[
827  (0.25\cdot 0.962216\cdot 10\,\mathrm{pt})^{+1\,\text{pt}}_{-1\,\text{pt}}
828  = 2.40554\,\mathrm{pt}^{+1\,\text{pt}}_{-1\,\text{pt}}.
829 \]
830 \end{itemize}
831
832 %<en>\subsection{Using in \LaTeX}
833 %<ja>\subsection{\LaTeX で使う}
834 \label{ssec-ltx}
835
836 \paragraph{\LaTeXe}
837
838 %<*en>
839 Using in \LaTeXe\ is basically same. To set up the minimal environment
840 for Japanese, you only have to load \texttt{luatexja.sty}:
841 %</en>
842 %<*ja>
843 \LaTeXe を用いる場合も基本的には同じである.日本語組版のための最低限の環境を
844 設定するためには,\texttt{luatexja.sty}を読み込むだけでよい:
845 %</ja>
846 \begin{verbatim}
847 \usepackage{luatexja}
848 \end{verbatim}
849 %<*en>
850 It also does minimal settings (counterparts in \pLaTeX\ are \texttt{%
851 plfonts.dtx} and \texttt{pldefs.ltx}):
852 %</en>
853 %<*ja>
854 これで\pLaTeX の\texttt{plfonts.dtx}と\texttt{pldefs.ltx}に相当する最低限の設定が
855 なされる:
856 %</ja>
857
858 \begin{itemize}
859 %<*en>
860 \item The font encoding for Japanese fonts (fot horizontal direction) is \texttt{JY3}.\\
861 \texttt{JT3} is used for Japanese fonts for vertical diraction.
862 %</en>
863 %<*ja>
864 \item 和文フォントのエンコーディングとしては,横組用には \texttt{JY3},縦組用には\ 
865 \texttt{JT3}が用いられる.
866 %</ja>
867
868 %<*en>
869 \item Traditionally, Japanese documents use two typeface category: \emph{mincho}~(明朝体) and
870  \emph{gothic}~(\textgt{ゴシック体}). \emph{mincho} is used in the main text, while \emph{gothic}
871       is used in the headings or for emphasis.
872 \begin{center}\small
873 \begin{tabular}{lllc}
874 \toprule
875 \textbf{classification}&&&\textbf{family name}\\\midrule
876 \emph{mincho} (明朝体)&\verb+\textmc{...}+&\verb+{\mcfamily ...}+&\verb+\mcdefault+\\
877 \emph{gothic} (\textgt{ゴシック体})&\verb+\textgt{...}+&\verb+{\gtfamily ...}+&\verb+\gtdefault+\\
878 \bottomrule
879 \end{tabular}
880 \end{center}
881 \item 
882 By default, the following fonts are used for \emph{mincho} and \emph{gothic}:
883 \begin{center}\small
884 \begin{tabular}{ccccc}
885 \toprule
886 \textbf{classification}&\textbf{family name}&\verb+\mdseries+&\verb+\bfseries+&\textbf{scale}\\\midrule
887 \emph{mincho} (明朝体)&\tt mc&Ryumin-Light    &GothicBBB-Medium&0.962216\\
888 \emph{gothic} (\textgt{ゴシック体})&\tt gt&GothicBBB-Medium&GothicBBB-Medium&0.962216\\
889 \bottomrule
890 \end{tabular}
891 \end{center}
892 Note that the bold series in both family are same as the medium series of \emph{gothic} family.
893 This is a convention in \pLaTeX. This is trace that there were only 2~fonts (these are Ryumin-Light
894 and GothicBBB-Medium) in early years of DTP. There is no italic nor slanted shape for
895       these \texttt{mc}~and~\texttt{gt}.
896 %</en>
897 %<*ja>
898 \item \pLaTeX と同様に,標準では「明朝体」「ゴシック体」の2種類を用いる:
899 \begin{center}\small
900 \begin{tabular}{cllc}
901 \toprule
902 \emph{字体}&&&\emph{ファミリ名}\\\midrule
903 明朝体&\verb+\textmc{...}+&\verb+{\mcfamily ...}+&\verb+\mcdefault+\\
904 \textgt{ゴシック体}&\verb+\textgt{...}+&\verb+{\gtfamily ...}+&\verb+\gtdefault+\\
905 \bottomrule
906 \end{tabular}
907 \end{center}
908 \item 標準では,次のフォントファミリが用いられる:
909 \begin{center}\small
910 \begin{tabular}{ccccc}
911 \toprule
912 \emph{字体}&\emph{ファミリ}&\verb+\mdseries+&\verb+\bfseries+&\emph{スケール}\\\midrule
913 明朝体&\tt mc&Ryumin-Light    &GothicBBB-Medium&0.962216\\
914 ゴシック体&\tt gt&GothicBBB-Medium&GothicBBB-Medium&0.962216\\
915 \bottomrule
916 \end{tabular}
917 \end{center}
918 どちらのファミリにおいても,そのboldシリーズで使われるフォントは
919 ゴシック体のmediumシリーズで使われるフォントと同じあることに注意.
920 これは初期のDTPにおいて和文フォントが2つ(それがちょうど\
921 Ryumin-Light, GothicBBB-Mediumだった)しか利用できなかった時の名残であり,\pLaTeX{}
922 での標準設定とも同じである.
923 %</ja>
924
925
926 %<en>\item Japanese characters in math mode are typeset by the font family \texttt{mc}.
927 %<ja>\item 数式モード中の和文文字は明朝体(\texttt{mc})で出力される.
928 \end{itemize}
929
930 %<*en>
931 However, above settings are not sufficient for Japanese-based
932 documents. To typeset Japanese-based documents, you are better to use
933 class files other than \texttt{article.cls}, \texttt{book.cls}, and so on.  At
934 the present, we have the counterparts of \Pkg{jclasses} (standard
935 classes in \pLaTeX) and \Pkg{jsclasses} (classes by Haruhiko
936 Okumura), namely, \Pkg{ltjclasses} and \Pkg{ltjsclasses}.
937 %</en>
938 %<*ja>
939 しかしながら,上記の設定は日本語の文書にとって十分とは言えない.
940 日本語文書を組版するためには,\texttt{article.cls}, \texttt{book.cls}といった
941 欧文用のクラスファイルではなく,和文用のクラスファイルを用いた方がよい.
942 現時点では,\Pkg{jclasses}(\pLaTeX の標準クラス)と\Pkg{jsclasses}
943 (奥村晴彦氏による「\pLaTeXe 新ドキュメントクラス」)に対応するものとして,\Pkg{ltjclasses},
944 \Pkg{ltjsclasses}がそれぞれ用意されている.
945 %</ja>
946
947 %<en>\section{Changing Fonts}
948 %<ja>\section{フォントの変更}
949
950 \subsection{plain \TeX~and~\LaTeXe}
951 \label{ssec-chgfnt}
952
953 \paragraph{plain \TeX}
954 %<*en>
955 To change Japanese fonts in plain \TeX, you must use the command
956 \verb+\jfont+~and~\verb+\tfont+. So please see Subsection~\ref{ssec-jfont}.
957 %</en>
958 %<*ja>
959 plain \TeX で和文フォントを変更するためには,
960 \pTeX のように \verb+\jfont+ 命令や \verb+\tfont+ 命令を直接用いる.
961 \ref{ssec-jfont}節を参照.
962 %</ja>
963
964 \paragraph{\LaTeXe\ (NFSS2)}
965 %<*en>
966 For \LaTeXe, \LuaTeX-ja adopted most of the font selection system of \pLaTeXe\ (in \texttt{plfonts.dtx}).
967 %</en>
968 %<*ja>
969 \LaTeXe については,\LuaTeX-jaではフォント選択システムを\pLaTeXe\ (\texttt{plfonts.dtx})
970 の大部分をそのまま採用している.
971 %</ja>
972 \begin{itemize}
973 %<*en>
974 \item Commands \verb+\fontfamily+, \verb+\fontseries+,
975       \verb+\fontshape+, and \verb+\selectfont+ can be used to change
976       attributes of Japanese fonts.
977 %</en>
978 %<*ja>
979 \item \verb+\fontfamily+, \verb+\fontseries+, \verb+\fontshape+, そして
980       \verb+\selectfont+ が和文フォントの属性を変更するために使用できる.
981 %</ja>
982
983 %<*en>
984 \begin{center}\small
985 \begin{tabular}{cccccc}
986 \toprule
987 &\textbf{encoding}&\textbf{family}&\textbf{series}&\textbf{shape}&\textbf{selection}\\\midrule
988 alphabetic fonts
989 &\verb+\romanencoding+&\verb+\romanfamily+&\verb+\romanseries+&\verb+\romanshape+
990 &\verb+\useroman+\\
991 Japanese fonts
992 &\verb+\kanjiencoding+&\verb+\kanjifamily+&\verb+\kanjiseries+&\verb+\kanjishape+
993 &\verb+\usekanji+\\
994 both&---&--&\verb+\fontseries+&\verb+\fontshape+&---\\
995 auto select&\verb+\fontencoding+&\verb+\fontfamily+&---&---&\verb+\usefont+\\
996 \bottomrule
997 \end{tabular}
998 \end{center}
999 %</en>
1000 %<*ja>
1001 \begin{center}\small
1002 \begin{tabular}{cccccc}
1003 \toprule
1004 &\emph{エンコーディング}&\emph{ファミリ}&\emph{シリーズ}&\emph{シェープ}&\emph{選択}\\\midrule
1005 欧文
1006 &\verb+\romanencoding+&\verb+\romanfamily+&\verb+\romanseries+&\verb+\romanshape+
1007 &\verb+\useroman+\\
1008 和文
1009 &\verb+\kanjiencoding+&\verb+\kanjifamily+&\verb+\kanjiseries+&\verb+\kanjishape+
1010 &\verb+\usekanji+\\
1011 両方&---&--&\verb+\fontseries+&\verb+\fontshape+&---\\
1012 自動選択&\verb+\fontencoding+&\verb+\fontfamily+&---&---&\verb+\usefont+\\
1013 \bottomrule
1014 \end{tabular}
1015 \end{center}
1016 %</ja>
1017
1018 %<*en>
1019       \verb+\fontencoding{+<encoding>\verb+}+ changes the encoding of alphabetic fonts
1020       or Japanese fonts depending on the argument. For example,
1021       \verb+\fontencoding{JY3}+ changes the encoding of Japanese fonts to
1022       \texttt{JY3},and \verb+\fontencoding{T1}+ changes the encoding of
1023       alphabetic fonts to \texttt{T1}.
1024       \verb+\fontfamily+ also changes the current Japanese font family, 
1025       the current alphabetic font family, \emph{or both}. 
1026       For the detail, see Subsection~\ref{ssec-nfsspat}.
1027 %</en>
1028 %<*ja>
1029       ここで,\verb+\fontencoding{+<encoding>\verb+}+ は,引数により和文側か欧文
1030       側かのどちらかのエンコーディングを変更する.例えば,
1031       \verb+\fontencoding{JY3}+ は和文フォントのエンコーディングを
1032       \texttt{JY3}に変更し,\verb+\fontencoding{T1}+ は欧文フォント側を
1033       \texttt{T1}へと変更する.\verb+\fontfamily+ も引数により和文側,欧文
1034       側,\emph{あるいは両方}のフォントファミリを変更する.詳細は
1035       \ref{ssec-nfsspat}節を参照すること.
1036 %</ja>
1037
1038 %<*en>
1039 \item For defining a Japanese font family, use
1040       \verb+\DeclareKanjiFamily+ instead of
1041       \verb+\DeclareFontFamily+. However, in the present implementation,
1042       using \verb+\DeclareFontFamily+ doesn't cause any problem.
1043 \item Defining a Japanese font shape can be done by usual \verb+\DeclareFontShape+:
1044 %</en>
1045 %<*ja>
1046 \item 和文フォントファミリの定義には \verb+\DeclareFontFamily+ の
1047       代わりに \verb+\DeclareKanjiFamily+ を用いる.しかし,現在の
1048       実装では \verb+\DeclareFontFamily+ を用いても問題は生じない.
1049 \item 和文フォントのシェイプを定義するには,通常の \verb+\DeclareFontShape+ を使えば良い:
1050 %</ja>
1051 \begin{verbatim}
1052 \DeclareFontShape{JY3}{mc}{bx}{n}{<-> s*KozMinPr6N-Bold:jfm=ujis;-kern}{}
1053     % Kozuka Mincho Pr6N Bold
1054 \end{verbatim}
1055 %<*ja>
1056 仮名書体を使う場合など,複数の和文フォントを組み合わせて使いたい場合は
1057 \ref{ssec-altfont}節の \verb+\ltjdeclarealtfont+ と,その\LaTeX 版の\ 
1058 \verb+\DeclareAlternateKanjiFont+(\ref{ssec-nfsspat}節)を参照せよ.
1059 %</ja>
1060 \end{itemize}
1061
1062 %<*en>
1063 \paragraph{Remark: Japanese characters in math mode}
1064 Since \pTeX\ supports Japanese characters in math mode, there are
1065 sources like the following:
1066 %</en>
1067 %<*ja>
1068 \paragraph{注意:数式モード中の和文文字}
1069 \pTeX では,特に何もしないでも数式中に和文文字を記述することができた.そのため,
1070 以下のようなソースが見られた:
1071 %</ja>
1072
1073 \begin{LTXexample}
1074 $f_{高温}$~($f_{\text{high temperature}}$).
1075 \[ y=(x-1)^2+2\quad よって\quad y>0 \]
1076 $5\in 素:=\{\,p\in\mathbb N:\text{$p$ is a prime}\,\}$.
1077 \end{LTXexample}
1078 %<*en>
1079 We (the project members of \LuaTeX-ja) think that using
1080 Japanese characters in math mode are allowed if and only if these are used as identifiers.
1081 In this point of view,
1082 %</en>
1083 %<*ja>
1084 \LuaTeX-jaプロジェクトでは,数式モード中での和文文字はそれらが識別子として用いられる
1085 ときのみ許されると考えている.
1086 この観点から,
1087 %</ja>
1088
1089 \begin{itemize}
1090 %<*en>
1091 \item The lines 1~and~2 above are not correct, since ``高温'' in above is used as a textual label, and
1092 ``よって'' is used as a conjunction.
1093 %</en>
1094 %<*ja>
1095 \item 上記数式のうち1, 2行目は正しくない.なぜならば「高温」が意味のあるラベルと
1096       して,「よって」が接続詞として用いられているからである.
1097 %</ja>
1098 %<en>\item However, the line~3 is correct, since ``素'' is used as an identifier.
1099 %<ja>\item しかしながら,3行目は「素」が単なる識別子として用いられているので正しい.
1100 \end{itemize}
1101 %<en>Hence, in our opinion, the above input should be corrected as:
1102 %<ja>したがって,\LuaTeX-jaプロジェクトの意見としては,上記の入力は次のように直されるべきである:
1103 \begin{LTXexample}
1104 $f_{\text{高温}}$~%
1105 ($f_{\text{high temperature}}$).
1106 \[ y=(x-1)^2+2\quad
1107   \mathrel{\text{よって}}\quad y>0 \]
1108 $5\in 素:=\{\,p\in\mathbb N:\text{$p$ is a prime}\,\}$.
1109 \end{LTXexample}
1110 %<*en>
1111 We also believe that using Japanese characters as identifiers is rare,
1112 hence we don't describe how to change Japanese fonts in math mode in
1113 this chapter. For the method, please see Subsection~\ref{ssec-math}.
1114 %</en>
1115 %<*ja>
1116 また\LuaTeX-jaプロジェクトでは,和文文字が識別子として用いられることはほとんどない
1117 と考えており,したがってこの節では数式モード中の和文フォントを変更する方法については
1118 記述しない.この方法については\ref{ssec-math}節を参照のこと.
1119 %</ja>
1120
1121
1122 \subsection{fontspec}
1123 \label{ssec-fontspec}
1124 %<*en>
1125 To coexist with the \Pkg{fontspec} package, it is needed to load
1126 \Pkg{luatexja-fontspec} package in the preamble, as follows:
1127 \begin{quote}
1128 \ttfamily \textbackslash usepackage[<options>]\{luatexja-fontspec\}
1129 \end{quote}
1130 This \Pkg{luatexja-fontspec} package 
1131 automatically loads \Pkg{luatexja} and \Pkg{fontspec}
1132 package, if needed.
1133 %</en>
1134 %<*ja>
1135 \Pkg{fontspec}パッケージと同様の機能を和文フォントに対しても用いる場合,
1136 \Pkg{luatexja-fontspec}パッケージを読み込む:
1137 \begin{quote}
1138 \ttfamily \textbackslash usepackage[<options>]\{luatexja-fontspec\}
1139 \end{quote}
1140 このパッケージ
1141 は必要ならば自動で\Pkg{luatexja}パッケージと\Pkg{fontspec}パッケージを読み込む.
1142 %</ja>
1143
1144 %<*en>
1145 In \Pkg{luatexja-fontspec} package, the following seven~commands are defined as
1146 counterparts of original commands in the \Pkg{fontspec} package:
1147 %</en>
1148 %<*ja>
1149 \Pkg{luatexja-fontspec}パッケージでは,以下の7つのコマンドを\Pkg{fontspec}
1150 パッケージの元のコマンドに対応するものとして定義している:
1151 %</ja>
1152 %<*en>
1153 \begin{center}\small
1154 \begin{tabular}{ccccc}
1155 \toprule
1156 Japanese fonts
1157 &\verb+\jfontspec+&\verb+\setmainjfont+&\verb+\setsansjfont+&\verb+\setmonojfont+$^*$\\
1158 alphabetic fonts
1159 &\verb+\fontspec+&\verb+\setmainfont+&\verb+\setsansfont+&\verb+\setmonofont+\\
1160 \midrule
1161 Japanese fonts
1162 &\verb+\newjfontfamily+&\verb+\newjfontface+
1163 &\verb+\defaultjfontfeatures+&\verb+\addjfontfeatures+\\
1164 alphabetic fonts
1165 &\verb+\newfontfamily+&\verb+\newfontface+
1166 &\verb+\defaultfontfeatures+&\verb+\addfontfeatures+\\
1167 \bottomrule
1168 \end{tabular}
1169 \end{center}
1170 %</en>
1171 %<*ja>
1172 \begin{center}\small
1173 \begin{tabular}{cccc}
1174 \toprule
1175 和文
1176 &\verb+\jfontspec+&\verb+\setmainjfont+&\verb+\setsansjfont+\\
1177 欧文
1178 &\verb+\fontspec+&\verb+\setmainfont+&\verb+\setsansfont+\\
1179 \midrule
1180 和文
1181 &\verb+\newjfontfamily+&\verb+\newjfontface+&\verb+\defaultjfontfeatures+\\
1182 欧文
1183 &\verb+\newfontfamily+&\verb+\newfontface+&\verb+\defaultfontfeatures+\\
1184 \midrule
1185 和文
1186 &\verb+\addjfontfeatures+\\
1187 欧文
1188 &\verb+\addfontfeatures+\\
1189 \bottomrule
1190 \end{tabular}
1191 \end{center}
1192 %</ja>
1193 %<*en>
1194 The package option of \Pkg{luatexja-fontspec} are the followings:
1195 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}\advance\leftmargin1\zw}
1196  \item[match] If this option is specified, usual family-changing commands such as
1197 \verb+\rmfamily+,~\verb+\textrm+, \verb+\sffamily+,~\dots\ also change Japanese font family.
1198
1199 Note that \emph{\texttt{\textup{\textbackslash setmonojfont}} is defined 
1200 if and only if this \texttt{\textup{match}} option is specified}.
1201
1202  \item[pass=<opts>] 
1203 Specify options <opts> which will be passed to the \Pkg{fontspec} package.
1204 \end{list} 
1205 The reason that \verb+\setmonojfont+ is not defined by default is that
1206 it is popular for Japanese fonts that nearly all Japanese glyphs have same
1207 widths.  Also note that kerning information in a font is not used
1208 (that is, \texttt{kern} feature is set off) by default in these seven (or~eight) commands.
1209 This is because of the compatibility with previous versions of \LuaTeX-ja
1210 (see \ref{para-kern}).
1211 %</en>
1212 %<*ja>
1213 \Pkg{luatexja-fontspec} パッケージのオプションは以下の通りである:
1214 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}\advance\leftmargin1\zw}
1215  \item[match] このオプションが指定されると,「\pLaTeXe 新ドキュメントクラス」のように\
1216 \verb+\rmfamily+, \verb+\textrm{...}+, \verb+\sffamily+ 等が
1217 欧文フォントだけでなく和文フォントも変更するようになる.
1218
1219 \emph{なお,{\tt \textbackslash setmonojfont} はこの \texttt{match} オプションが
1220 指定された時のみ定義される.}この命令は標準の「タイプライタ体に対応する和文フォント」を指定する.
1221
1222  \item[pass=<opts>] 
1223 \Pkg{fontspec} パッケージに渡すオプション <opts> を指定する.
1224 \end{list}
1225 標準で \verb+\setmonojfont+ コマンドが定義されないのは,
1226 和文フォントではほぼ全ての和文文字のグリフが等幅であるのが伝統的であったことによる.
1227 また,これらの和文用のコマンドではフォント内のペアカーニング情報は標準では使用されない,
1228 言い換えれば \texttt{kern} featureは標準では無効化となっている.
1229 これは以前のバージョンの\LuaTeX-jaとの互換性のためである(\ref{para-kern}節を参照).
1230 %</ja>
1231
1232 \begin{LTXexample}[width=0.4\textwidth]
1233 \fontspec[Numbers=OldStyle]{LMSans10-Regular}
1234 \jfontspec[CJKShape=NLC]{KozMinPr6N-Regular}
1235 JIS~X~0213:2004→辻
1236
1237 \jfontspec[CJKShape=JIS1990]{KozMinPr6N-Regular}
1238 JIS~X~0208:1990→辻
1239 \end{LTXexample}
1240
1241 %<en>\subsection{Presets}
1242 %<ja>\subsection{プリセット設定}
1243 \label{ssec-preset}
1244
1245 %<*en>
1246 To use standard Japanese font settings easily, one can load \Pkg{luatexja-preset}
1247 package with several options. This package provides functions in a part of
1248 \Pkg{japanese-otf} package and a part of \Pkg{PXchfon} package by Takayuki Yato,
1249 and loads \Pkg{luatexja-fontspec}, hence \Pkg{fontspec} internally.
1250
1251 If you need to pass some options to \Pkg{fontspec}, load \Pkg{fontspec} manually
1252 before \Pkg{luatexja-preset}:
1253 %</en>
1254 %<*ja>
1255 よく使われている和文フォント設定を一行で指定できるようにしたのが
1256 \Pkg{luatexja-preset}パッケージである.このパッケージは,
1257 \Pkg{otf}パッケージの一部機能と八登崇之氏による\Pkg{PXchfon}パッケージの一部機能とを
1258 合わせたような格好をしており,内部で\Pkg{luatexja-fontspec},従って
1259 \Pkg{fontspec}を読み込んでいる.
1260
1261 もし\Pkg{fontspec}パッケージに何らかのオプションを渡す必要がある
1262 \footnote{例えば,数式フォントまで置換されてしまい,\texttt{\textbackslash mathit}によってギリシャ文字の
1263 斜体大文字が出なくなる,など.}場合は,
1264 次のように\Pkg{luatexja-preset}の前に\Pkg{fontspec}を手動で読みこめば良い:
1265 %</ja>
1266 \begin{verbatim}
1267 \usepackage[no-math]{fontspec}
1268 \usepackage[...]{luatexja-preset}
1269 \end{verbatim}
1270
1271 %<en>\paragraph{General options}
1272 %<ja>\paragraph{一般的なオプション}
1273 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}\advance\leftmargin1\zw}
1274 \item[nodeluxe]
1275 %<*en>
1276 Use one-weighted \textit{mincho} and \textit{gothic} font families.
1277 This means that \verb+\mcfamily\bfseries+, \verb+\gtfamily\bfseries+ and 
1278 \verb+\gtfamily\mdseries+ use the same font.
1279 \emph{This option is enabled by default.}
1280 %</en>
1281 %<*ja>
1282 \LaTeXe 環境下での標準設定のように,明朝体・ゴシック体を各1ウェイトで使用する.
1283 より具体的に言うと,この設定の下では
1284 \verb+\mcfamily\bfseries+, \verb+\gtfamily\bfseries+, \verb+\gtfamily\mdseries+は
1285 みな同じフォントとなる.\emph{このオプションは標準で有効になっている.}
1286 %</ja>
1287 \item[deluxe]
1288 %<*en>
1289 Use \textit{mincho} with two weights (medium~and~bold),
1290 \textit{gothic} with three weights (medium, bold~and~heavy), and \textit{rounded gothic}%
1291 \footnote{Provided by \texttt{\textbackslash mgfamily} and \texttt{\textbackslash textmg\{...\}},
1292 because \textit{rounded gothic} is called \textit{maru gothic} (丸ゴシック) in Japanese.}.
1293 The heavy weight of \textit{gothic} can be used by ``changing the family'' \verb+\gtebfamily+,
1294 or \verb+\textgteb{...}+.
1295 This is because \Pkg{fontspec} package can handle only medium (\verb+\mdseries+) and
1296 bold (\verb+\bfseries+).
1297 %</en>
1298 %<*ja>
1299 明朝体2ウェイト・ゴシック体3ウェイトと,
1300 丸ゴシック体 (\verb+\mgfamily+, \verb+\textmg{...}+) を使用可能とする.
1301 ゴシック体は細字・太字・極太の3ウェイトがあるが,
1302 極太ゴシック体はファミリの切り替え (\verb+\gtebfamily+, \verb+\textgteb{...}+) %
1303 で実現している.\Pkg{fontspec}では通常 (\verb+\mdseries+) と太字 (\verb+\bfseries+) しか扱えないために
1304 このような中途半端な実装になっている.
1305 %</ja>
1306 \item[expert]
1307 %<*en>
1308 Use horizontal kana alternates, and define a command \verb+\rubyfamily+ to use kana
1309 characters designed for ruby.
1310 %</en>
1311 %<ja>横組専用仮名を用いる.また,\verb+\rubyfamily+ でルビ用仮名が使用可能となる.
1312 \item[bold]
1313 %<en>Substitute bold series of \textit{gothic} for  bold series of \textit{mincho}.
1314 %<ja>「明朝の太字」をゴシック体の太字によって代替する.
1315 \item[90jis]
1316 %<en>Use 90JIS glyph variants if possible.
1317 %<ja>出来る限り90JISの字形を使う.
1318 \item[jis2004]
1319 %<en>Use JIS2004 glyph variants if possible.
1320 %<ja>出来る限りJIS2004の字形を使う.
1321 \item[jis]
1322 %<*en>
1323 Use the JFM \texttt{jfm-jis.lua}, instead of \texttt{jfm-ujis.lua}, which is the default JFM of
1324 \LuaTeX-ja.
1325 %</en>
1326 %<*ja>
1327 用いるJFMを(JISフォントメトリック類似の)\texttt{jfm-jis.lua}にする.このオプションがない時は
1328 \LuaTeX-ja標準の\texttt{jfm-ujis.lua}が用いられる.
1329 %</ja>
1330 \end{list}
1331 %<*en>
1332 Note that \texttt{90jis} and \texttt{jis2004} only affect with \textit{mincho},
1333 \textit{gothic} (and possibly \textit{rounded gothic}) defined by this package.
1334 We didn't taken account of  when both \texttt{90jis} and \texttt{jis2004} are specified.
1335 %</en>
1336 %<*ja>
1337 \texttt{90jis}と\texttt{jis2004}については本パッケージで定義された
1338 明朝体・ゴシック体(・丸ゴシック体)にのみ有効である.両オプションが
1339 同時に指定された場合の動作については全く考慮していない.
1340 %</ja>
1341
1342 %<en>\paragraph{Presets for multi weight}
1343 %<ja>\paragraph{多ウェイト用プリセットの一覧}
1344 %<*en>
1345 Besides \texttt{morisawa-pro}~and~\texttt{morisawa-pr6n} presets,
1346 fonts are specified by fontname, not by filename.
1347 %</en>
1348 %<*ja>
1349 \texttt{morisawa-pro}, \texttt{morisawa-pr6n}以外はフォントの指定は
1350 (ファイル名でなく)フォント名で行われる.
1351 %</ja>
1352 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}\advance\leftmargin1\zw}
1353  \item[kozuka-pro] Kozuka Pro (Adobe-Japan1-4) fonts.
1354 %<en>    \\[-\dimexpr\medskipamount+\baselineskip\relax]
1355  \item[kozuka-pr6] Kozuka Pr6 (Adobe-Japan1-6)  fonts.
1356 %<en>    \\[-\dimexpr\medskipamount+\baselineskip\relax]
1357  \item[kozuka-pr6n] Kozuka Pr6N (Adobe-Japan1-6, JIS04-savvy) fonts.
1358
1359 %<*en>
1360 Kozuka Pro/Pr6N fonts are bundled with Adobe's software, such as Adobe~InDesign.
1361 There is not rounded gothic family in Kozuka fonts.
1362 %</en>
1363 %<*ja>
1364 小塚Pro書体・Pr6N書体はAdobe InDesign等のAdobe製品にバンドルされている.
1365 「小塚丸ゴシック」は存在しないので,便宜的に小塚ゴシックHによって代用している.
1366 %</ja>
1367 \begin{center}\small
1368 \begin{tabular}{cllll}
1369 \toprule
1370 \bf family&\bf series&\tt kozuka-pro&\tt kozuka-pr6&\tt kozuka-pr6n\\
1371 \midrule
1372  &medium&KozMinPro-Regular&KozMinProVI-Regular&KozMinPr6N-Regular\\
1373 %<en>\smash{\raisebox{1.5ex}{\textit{mincho}}}%
1374 %<ja>\smash{\raisebox{1.5ex}{\gt 明朝}}%
1375  &bold&KozMinPro-Bold&KozMinProVI-Bold&KozMinPr6N-Bold\\
1376 \midrule
1377  &&KozGoPro-Regular*&KozGoProVI-Regular*&KozGoPr6N-Regular*\\
1378  &\smash{\raisebox{1.5ex}{medium}}
1379  &KozGoPro-Medium&KozGoProVI-Medium&KozGoPr6N-Medium\\
1380 \cmidrule(l){2-5}
1381 %<en>\smash{\raisebox{2ex}{\textit{gothic}}}%
1382 %<ja>\smash{\raisebox{2ex}{\gt ゴシック}}%
1383  &bold&KozGoPro-Bold&KozGoProVI-Bold&KozGoPr6N-Bold\\
1384  &heavy&KozGoPro-Heavy&KozGoProVI-Heavy&KozGoPr6N-Heavy\\
1385 \midrule
1386 %<en>\textit{rounded gothic}
1387 %<ja>\gt 丸ゴシック
1388 &&KozGoPro-Heavy&KozGoProVI-Heavy&KozGoPr6N-Heavy\\
1389 \bottomrule
1390 \end{tabular}
1391 \end{center}
1392
1393 %<*en>
1394 In above table, starred fonts (KozGo\dots-Regular) are used for medium series of \textit{gothic},
1395 \emph{if and only if \texttt{deluxe} option is specified}.
1396 %</en>
1397 %<*ja>
1398 上の表において,*つきのフォント(KozGo\dots-Regular)は,\emph{\texttt{deluxe}オプション非指定時に}
1399 ゴシック体細字として用いられる.
1400 %</ja>
1401
1402 %<ja>\medskip
1403
1404  \item[hiragino-pro]  Hiragino Pro (Adobe-Japan1-5) fonts.
1405 %<en>    \\[-\dimexpr\medskipamount+\baselineskip\relax]
1406  \item[hiragino-pron] Hiragino ProN (Adobe-Japan1-5, JIS04-savvy) fonts.
1407
1408 %<*en>
1409 Hiragino fonts are bundled with Mac OS~X 10.5 or later.
1410 Some editions of a Japanese word-processor ``一太郎2012'' includes Hiragino ProN fonts.
1411 Note that the heavy weight of \textit{gothic} family only supports
1412 Adobe-Japan1-3 character collection (Std/StdN).
1413 %</en>
1414 %<*ja>
1415 ヒラギノフォントは,Mac OS~X以外にも,一太郎2012の上位エディションにもバンドルされている.
1416 極太ゴシックとして用いるヒラギノ角ゴW8は,Adobe-Japan1-3の範囲しかカバーしていない
1417 Std/StdNフォントであり,その他はAdobe-Japan1-5対応である.
1418 %</ja>
1419 \begin{center}\small
1420 \begin{tabular}{clll}
1421 \toprule
1422 \bf family&\bf series&\tt hiragino-pro&\tt hiragino-pron\\
1423 \midrule
1424  &medium&Hiragino~Mincho~Pro~W3&Hiragino~Mincho~ProN~W3\\
1425 %<en>\smash{\raisebox{1.5ex}{\textit{mincho}}}%
1426 %<ja>\smash{\raisebox{1.5ex}{\gt 明朝}}%
1427  &bold&Hiragino~Mincho~Pro~W6&Hiragino~Mincho~ProN~W6\\
1428 \midrule
1429  &&Hiragino~Kaku~Gothic~Pro~W3*&Hiragino~Kaku~Gothic~ProN~W3*\\
1430  &\smash{\raisebox{1.5ex}{medium}}
1431  &Hiragino~Kaku~Gothic~Pro~W6&Hiragino~Kaku~Gothic~ProN~W6\\
1432 \cmidrule(l){2-4}
1433 %<en>\smash{\raisebox{2ex}{\textit{gothic}}}%
1434 %<ja>\smash{\raisebox{2ex}{\gt ゴシック}}%
1435  &bold&Hiragino~Kaku~Gothic~Pro~W6&Hiragino~Kaku~Gothic~ProN~W6\\
1436  &heavy&Hiragino~Kaku~Gothic~Std~W8&Hiragino~Kaku~Gothic~StdN~W8\\
1437 \midrule
1438 %<en>\textit{rounded gothic}
1439 %<ja>\gt 丸ゴシック
1440 &&Hiragino~Maru~Gothic~ProN~W4&Hiragino~Maru~Gothic~ProN~W4\\
1441 \bottomrule
1442 \end{tabular}
1443 \end{center}
1444
1445 %<ja>\medskip
1446
1447  \item[morisawa-pro]  Morisawa Pro (Adobe-Japan1-4) fonts.
1448 %<en>    \\[-\dimexpr\medskipamount+\baselineskip\relax]
1449  \item[morisawa-pr6n]  Morisawa Pr6N (Adobe-Japan1-6, JIS04-savvy) fonts.
1450 \begin{center}\small
1451 \begin{tabular}{cl>{\tt}l>{\tt}l}
1452 \toprule
1453 \bf family&\bf series&morisawa-pro&morisawa-pr6n\\
1454 \midrule
1455  &medium&A-OTF-RyuminPro-Light.otf&A-OTF-RyuminPr6N-Light.otf\\
1456 %<en>\smash{\raisebox{1.5ex}{\textit{mincho}}}%
1457 %<ja>\smash{\raisebox{1.5ex}{\gt 明朝}}%
1458  &bold&A-OTF-FutoMinA101Pro-Bold.otf&A-OTF-FutoMinA101Pr6N-Bold.otf\\
1459 \midrule
1460  &medium
1461  &A-OTF-GothicBBBPro-Medium.otf&A-OTF-GothicBBBPr6N-Medium.otf\\
1462 %<en>\textit{gothic}%
1463 %<ja>\gt ゴシック
1464  &bold&A-OTF-FutoGoB101Pro-Bold.otf&A-OTF-FutoGoB101Pr6N-Bold.otf\\
1465  &heavy&A-OTF-MidashiGoPro-MB31.otf&A-OTF-MidashiGoPr6N-MB31.otf\\
1466 \midrule
1467 %<en>\textit{rounded gothic}
1468 %<ja>\gt 丸ゴシック
1469 &&A-OTF-Jun101Pro-Light.otf&A-OTF-ShinMGoPr6N-Light.otf\\
1470 \bottomrule
1471 \end{tabular}
1472 \end{center}
1473
1474  \item[yu-win]  Yu fonts bundled with Windows~8.1. 
1475 %<en>    \\[-\dimexpr\medskipamount+\baselineskip\relax]
1476  \item[yu-osx]  Yu fonts bundled with OSX~Mavericks. 
1477 \begin{center}\small
1478 \begin{tabular}{clll}
1479 \toprule
1480 \bf family&\bf series&\tt yu-win&\tt yu-osx\\
1481 \midrule
1482  &medium&YuMincho-Regular&YuMincho~Medium\\
1483 %<en>\smash{\raisebox{1.5ex}{\textit{mincho}}}%
1484 %<ja>\smash{\raisebox{1.5ex}{\gt 明朝}}%
1485  &bold&YuMincho-Demibold&YuMincho~Demibold\\
1486 \midrule
1487  &&YuGothic-Regular*&YuGothic~Medium*\\
1488  &\smash{\raisebox{1.5ex}{medium}}
1489  &YuGothic-Bold&YuGothic~Bold\\
1490 \cmidrule(l){2-4}
1491 %<en>\textit{gothic}%
1492 %<ja>\gt ゴシック
1493  &bold&YuGothic-Bold&YuGothic~Bold\\
1494  &heavy&YuGothic-Bold&YuGothic~Bold\\
1495 \midrule
1496 %<en>\textit{rounded gothic}
1497 %<ja>\gt 丸ゴシック
1498 &&YuGothic-Bold&YuGothic~Bold\\
1499 \bottomrule
1500 \end{tabular}
1501 \end{center}
1502
1503 \end{list}
1504 %<en>\paragraph{Presets for single weight}
1505 %<ja>\paragraph{単ウェイト用プリセット一覧}
1506 %<*en>
1507 Next, we describe settings for using only single weight.
1508 In four settings below, we use same fonts for medium and bold (and heavy) weights.
1509 (Hence \verb+\mcfamily\bfseries+ and \verb+\mcfamily\mdseries+ yields same Japanese fonts,
1510 even if \texttt{deluxe} option is also specified).
1511 %</en>
1512 %<*ja>
1513 次に,単ウェイト用の設定を述べる.この4設定では「細字」「太字」の区別はない.
1514 また,丸ゴシック体はゴシック体と同じフォントを用いる.
1515 %</ja>
1516 \par\nobreak\medskip
1517 {\centering\small
1518 \begin{tabular}{lllll}
1519 \toprule
1520 &\tt noembed&\tt ipa&\tt ipaex&\tt ms\\
1521 \midrule
1522 %<*en>
1523 \it mincho&Ryumin-Light (non-embedded)
1524 &IPAMincho&IPAexMincho&MS Mincho\\
1525 \it gothic&GothicBBB-Medium (non-embedded)
1526 &IPAGothic&IPAexGothic&MS Gothic\\
1527 %</en>
1528 %<*ja>
1529 \gtfamily 明朝体&Ryumin-Light(非埋込)
1530 &IPA明朝&IPAex明朝&MS明朝\\
1531 \gtfamily ゴシック体&GothicBBB-Medium(非埋込)
1532 &IPAゴシック&IPAexゴシック&MSゴシック\\
1533 %</ja>
1534 \bottomrule
1535 \end{tabular}\par\medskip}
1536
1537
1538 %<en>\paragraph{Using HG fonts}
1539 %<ja>\paragraph{HGフォントの利用}
1540 %<*en>
1541 We can use HG~fonts bundled with Microsoft~Office for realizing multiple weights.
1542 %</en>
1543 %<*ja>
1544 すぐ前に書いた単ウェイト用設定を,Microsoft Office等に付属するHGフォントを使って
1545 多ウェイト化した設定もある.
1546 %</ja>
1547 \par\nobreak\medskip
1548 {\centering\small
1549 \begin{tabular}{llll}
1550 \toprule
1551 &\tt ipa-hg&\tt ipaex-hg&\tt ms-hg\\
1552 \midrule
1553 %<*en>
1554 \bf mincho medium
1555 &IPAMincho&IPAexMincho&MS Mincho\\\midrule
1556 \bf mincho bold&
1557 \multicolumn{3}{c}{HG Mincho E}\\\midrule
1558 \bf Gothic medium\\
1559 ~~without \texttt{deluxe}
1560 &IPAGothic&IPAexGothic&MS Gothic\\
1561 ~~with {\tt jis2004}
1562 &IPAGothic&IPAexGothic&MS Gothic\\
1563 \cmidrule(lr){1-4}
1564 ~~otherwise&
1565 \multicolumn{3}{c}{HG Gothic M}\\\midrule
1566 \bf gothic bold&
1567 \multicolumn{3}{c}{HG Gothic E}\\\midrule
1568 \bf gothic heavy&
1569 \multicolumn{3}{c}{HG Soei Kaku Gothic UB}\\\midrule
1570 \bf rounded gothic&
1571 \multicolumn{3}{c}{HG Maru Gothic PRO}\\
1572 %</en>
1573 %<*ja>
1574 \gtfamily 明朝体細字
1575 &IPA明朝&IPAex明朝&MS明朝\\\midrule
1576 \gtfamily 明朝体太字&
1577 \multicolumn{3}{c}{HG明朝E}\\\midrule
1578 \gtfamily ゴシック体細字\\
1579  単ウェイト時
1580 &IPAゴシック&IPAexゴシック&MSゴシック\\
1581  {\tt jis2004}指定時
1582 &IPAゴシック&IPAexゴシック&MSゴシック\\
1583 \cmidrule(lr){1-4}
1584  それ以外の時&
1585 \multicolumn{3}{c}{HGゴシックM}\\\midrule
1586 \gtfamily ゴシック体太字&
1587 \multicolumn{3}{c}{HGゴシックE}\\\midrule
1588 \gtfamily ゴシック体極太&
1589 \multicolumn{3}{c}{HG創英角ゴシックUB}\\\midrule
1590 \gtfamily 丸ゴシック体&
1591 \multicolumn{3}{c}{HG丸ゴシック体PRO}\\
1592 %</ja>
1593 \bottomrule
1594 \end{tabular}\par\medskip}
1595
1596 %<*en>
1597 Note that HG~Mincho~E, HG~Gothic~E, HG Soei Kaku Gothic UB, and HG Maru Gothic PRO
1598 are internally specified by:
1599 \begin{description}
1600 \item[default] by font name (\texttt{HGMinchoE}, etc.).
1601 \item[{\tt 90jis}] by filename (\texttt{hgrme.ttc}, \texttt{hgrge.ttc}, \texttt{hgrsgu.ttc}, \texttt{hgrsmp.ttf}).
1602 \item[{\tt jis2004}] by filename (\texttt{hgrme04.ttc}, \texttt{hgrge04.ttc}, \texttt{hgrsgu04.ttc}, \texttt{hgrsmp04.ttf}).
1603 \end{description}
1604 %</en>
1605 %<*ja>
1606 なお,HG明朝E・HGゴシックE・HG創英角ゴシックUB・HG丸ゴシック体PROの4つについては,内部で
1607 \begin{description}
1608 \item[標準] フォント名(\texttt{HGMinchoE} など)
1609 \item[{\tt 90jis}指定時] ファイル名 (%
1610 \texttt{hgrme.ttc}, \texttt{hgrge.ttc}, \texttt{hgrsgu.ttc}, \texttt{hgrsmp.ttf})
1611 \item[{\tt jis2004}指定時] ファイル名 (%
1612 \texttt{hgrme04.ttc}, \texttt{hgrge04.ttc}, \texttt{hgrsgu04.ttc}, \texttt{hgrsmp04.ttf})
1613 \end{description}
1614 として指定を行っているので注意すること.
1615 %</ja>
1616
1617
1618 %<*en>
1619 \subsection{\texttt{\textbackslash CID}, \texttt{\textbackslash UTF}, and macros in \Pkg{japanese-otf} package}
1620 Under \pLaTeX, \Pkg{japanese-otf} package (developed by Shuzaburo Saito) is
1621 used for typesetting characters which is in Adobe-Japan1-6 CID but not
1622 in JIS~X~0208. Since this package is widely used, \LuaTeX-ja
1623 supports some of functions in \Pkg{japanese-otf} package.
1624 If you want to use these functions, load \Pkg{luatexja-otf} package.
1625 %</en>
1626 %<*ja>
1627 \subsection{\texttt{\textbackslash CID}, \texttt{\textbackslash UTF}と\Pkg{otf}パッケージのマクロ}
1628 \pLaTeX では,JIS~X~0208にないAdobe-Japan1-6の文字を出力するために,
1629 齋藤修三郎氏による\Pkg{otf}パッケージが用いられていた.このパッケージは
1630 広く用いられているため,\LuaTeX-jaにおいても\Pkg{otf}パッケージの機能の
1631 一部をサポートしている.これらの機能を用いるためには\Pkg{luatexja-otf}パッケージ
1632 を読み込めばよい.
1633 %</ja>
1634
1635 \begin{LTXexample}
1636 \jfontspec{KozMinPr6N-Regular.otf}
1637 森\UTF{9DD7}外と内田百\UTF{9592}とが\UTF{9AD9}島屋に行く。
1638
1639 \CID{7652}飾区の\CID{13706}野家,
1640 \CID{1481}城市,葛西駅,
1641 高崎と\CID{8705}\UTF{FA11}
1642
1643 \aj半角{はんかくカタカナ}
1644 \end{LTXexample}
1645
1646 %<*ja>
1647 \Pkg{otf}パッケージでは,それぞれ次のようなオプションが存在した:
1648 \begin{description}
1649 \item[\texttt{deluxe}] 明朝体・ゴシック体各2ウェイトと,丸ゴシック体を扱えるようになる.
1650 \item[\texttt{expert}] 仮名が横組・縦組専用のものに切り替わり,ルビ用仮名も扱えるようになる.
1651 \item[\texttt{bold}] ゴシック体を標準で太いウェイトのものに設定する.
1652 \end{description}
1653 しかしこれらのオプションは\Pkg{luatexja-otf}パッケージには存在しない.
1654 \Pkg{otf}パッケージが文書中で使用する和文用TFMを自前の物に置き換えていたのに対し,
1655 \Pkg{luatexja-otf}パッケージでは,そのようなことは行わないからである.
1656
1657 これら3オプションについては,
1658 \Pkg{luatexja-preset} パッケージにプリセットを使う時に一緒に指定するか,
1659 あるいは対応する内容を\ref{ssec-chgfnt}節,\ref{ssec-nfsspat}節 (NFSS2) や
1660 \ref{ssec-fontspec}節 (\Pkg{fontspec}) の方法で手動で指定する必要がある.
1661 %</ja>
1662
1663
1664 %<en>\section{Changing Parameters}
1665 %<ja>\section{パラメータの変更}
1666
1667 %<*en>
1668 There are many parameters in \LuaTeX-ja. And due to the behavior of \LuaTeX,
1669 most of them are not stored as internal register of \TeX, but as an
1670 original storage system in \LuaTeX-ja. Hence, to assign or acquire those
1671 parameters, you have to use commands \verb+\ltjsetparameter+ and
1672 \verb+\ltjgetparameter+.
1673 %</en>
1674 %<*ja>
1675 \LuaTeX-jaには多くのパラメータが存在する.そして\LuaTeX の仕様のために,
1676 その多くは\TeX のレジスタにではなく,\LuaTeX-ja独自の方法で保持されている.
1677 これらのパラメータを設定・取得するためには \verb+\ltjsetparameter+ と \verb+\ltjgetparameter+ を
1678 用いる.
1679 %</ja>
1680
1681 %<en>\subsection{Editing the Range of \textbf{JAchar}s}
1682 %<ja>\subsection{\textbf{JAchar}の範囲の設定}
1683 \label{ssec-setrange}
1684
1685 %<*en>
1686 \LuaTeX-ja divides the Unicode codespace \texttt{U+0080}--\texttt{U+10FFFF}
1687 into \emph{character ranges}, 
1688 numbered 1 to 217. The grouping can be (globally) customized by \verb+\ltjdefcharrange+.
1689 The next line adds whole characters in Supplementary Ideographic Plane
1690 and the character ``漢'' to the character range~100.
1691 %</en>
1692 %<*ja>
1693 \LuaTeX-jaは,Unicodeの \texttt{U+0080}--\texttt{U+10FFFF} の空間を
1694 1番から217番までの\emph{文字範囲}に分割している.
1695 区分けは \verb+\ltjdefcharrange+ を用いることで(グローバルに)変更することができ,
1696 例えば,次は追加漢字面(SIP)にある全ての文字と「漢」を「100番の文字範囲」に追加する.
1697 %</ja>
1698 \begin{lstlisting}
1699 \ltjdefcharrange{100}{"20000-"2FFFF,`漢}
1700 \end{lstlisting}
1701 %<*en>
1702 A character can belong to only one character range.
1703 For example, whole SIP belong to the range~4 in the default setting of \LuaTeX-ja, 
1704 and if you execute the above line, then SIP will belong to the range~100 and be
1705 removed from the range~4.
1706 %</en>
1707 %<*ja>
1708 各文字はただ一つの文字範囲に所属することができる.
1709 例えば,SIPは全て\LuaTeX-jaのデフォルトでは4番の文字範囲に
1710 属しているが,上記の指定を行えばSIPは100番に属すようになり,4番からは除かれる.
1711 %</ja>
1712
1713 %<*en>
1714 The distinction between \textbf{ALchar} and \textbf{JAchar} is done for character ranges.
1715 This can be edited by setting the \textsf{jacharrange} parameter.
1716 For example, this is just the default setting of \LuaTeX-ja, and
1717 it sets
1718 \begin{itemize}
1719  \item a character which belongs character ranges 1,~4, and~5 is \textbf{ALchar},
1720  \item a character which belongs character ranges 2,~3, 6, 7, and~8 is \textbf{JAchar}.
1721 \end{itemize}
1722 %</en>
1723 %<*ja>
1724 \textbf{ALchar}と\textbf{JAchar}の区別は文字範囲ごとに行われる.
1725 これは\textsf{jacharrange}パラメータによって編集できる.
1726 例えば,以下は\LuaTeX-jaの初期設定であり,次の内容を設定している:
1727 \begin{itemize}
1728  \item 1番,4番,5番の文字範囲に属する文字は\textbf{ALchar}.
1729  \item 2番,3番,6番,7番,8番の文字範囲に属する文字は\textbf{JAchar}.
1730 \end{itemize}
1731 %</ja>
1732 \begin{verbatim}
1733 \ltjsetparameter{jacharrange={-1, +2, +3, -4, -5, +6, +7, +8}}
1734 \end{verbatim}
1735 %<*en>
1736 The argument to \textsf{jacharrange} parameter is a list of non-zero integer.
1737 Negative integer $-n$ in the list means that ``each character in the range~$n$ is an
1738 \textbf{ALchar}'', 
1739 and positive integer $+n$ meansthat ``\dots\ is a \textbf{JAchar}''.
1740 %</en>
1741 %<*ja>
1742 \textsf{jacharrange}パラメータの引数は非零の整数のリストである.
1743 リスト中の負の整数$-n$は「文字範囲$n$に属する文字は\textbf{ALchar}として
1744 扱う」ことを意味し,正の整数$+n$は「\textbf{JAchar}として扱う」ことを意味する.
1745 %</ja>
1746
1747 %<*en>
1748 \paragraph{Default setting}
1749 \LuaTeX-ja predefines eight character ranges for convenience. They are
1750 determined from the following data:
1751 %</en>
1752 %<*ja>
1753 \paragraph{初期設定}
1754 \LuaTeX-jaでは8つの文字範囲を予め定義しており,
1755 これらは以下のデータに基づいて決定している.
1756 %</ja>
1757 \begin{itemize}
1758 %<en>\item Blocks in Unicode~6.0.
1759 %<ja>\item Unicode~6.0のブロック.
1760 %<en>\item The \texttt{Adobe-Japan1-UCS2} mapping between a CID Adobe-Japan1-6 and Unicode.
1761 %<ja>\item Adobe-Japan1-6のCIDとUnicodeの間の対応表\texttt{Adobe-Japan1-UCS2}.
1762 %<en>\item The \Pkg{PXbase} bundle for \upTeX\ by Takayuki Yato.
1763 %<ja>\item 八登崇之氏による\upTeX 用の\Pkg{PXbase}バンドル.
1764 \end{itemize}
1765
1766 %<*en>
1767 Now we describe these eight ranges. The superscript ``J'' or ``A'' after the
1768 number shows whether each character in the range is treated as
1769 \textbf{JAchar}s or not by default. These settings are similar to the
1770 \texttt{prefercjk} settings defined in \texttt{PXbase} bundle.
1771 Any characters above \texttt{U+0080} which does not belong to 
1772 these eight ranges belongs to the character range~217.
1773 %</en>
1774 %<*ja>
1775 以下ではこれら8つの文字範囲について記述する.添字のアルファベット「J」「A」
1776 は,その文字範囲内の文字が\textbf{JAchar}か\textbf{ALchar}かを表している.これらの設定は
1777 \texttt{PXbase}バンドルで定義されている\texttt{prefercjk}と類似のものである.
1778 なお,\texttt{U+0080} 以降でこれら8つの文字範囲に属さない文字は,217番の文字範囲に属することになっている.
1779 %</ja>
1780 \begin{description}
1781 %<*en>
1782 \item[Range~8${}^{\text{J}}$] The intersection of the upper half of ISO~8859-1
1783          (Latin-1 Supplement) and JIS~X~0208 (a basic character set for Japanese). This character range
1784          consists of the following characters:
1785 %</en>
1786 %<*ja>
1787 \item[範囲8${}^{\text{J}}$] ISO~8859-1の上位領域(ラテン1補助)と
1788                              JIS~X~0208の共通部分.この文字範囲は
1789                              以下の文字で構成される:
1790 %</ja>
1791 \begin{multicols}{2}
1792 \begin{itemize}
1793 \def\ch#1#2{\item \char"#1\ (\texttt{U+00#1}, #2)}%"
1794 \ch{A7}{Section Sign}
1795 \ch{A8}{Diaeresis}
1796 \ch{B0}{Degree sign}
1797 \ch{B1}{Plus-minus sign}
1798 \ch{B4}{Spacing acute}
1799 \ch{B6}{Paragraph sign}
1800 \ch{D7}{Multiplication sign}
1801 \ch{F7}{Division Sign}
1802 \end{itemize}
1803 \end{multicols}
1804
1805 %<*en>
1806 \item[Range~1${}^{\text{A}}$] Latin characters that some of them are included in Adobe-Japan1-6.
1807 This range consists of the following Unicode ranges, \emph{except characters in the range~8 above}:
1808 %</en>
1809 %<*ja>
1810 \item[範囲1${}^{\text{A}}$] ラテン文字のうち,Adobe-Japan1-6との共通部分があるもの.
1811                              この範囲は以下のUnicodeのブロックのうち
1812                              \emph{範囲8を除いた}部分で構成されている:
1813 %</ja>
1814 \begin{multicols}{2}
1815 \begin{itemize}
1816 \item \texttt{U+0080}--\texttt{U+00FF}: Latin-1 Supplement
1817 \item \texttt{U+0100}--\texttt{U+017F}: Latin Extended-A
1818 \item \texttt{U+0180}--\texttt{U+024F}: Latin Extended-B
1819 \item \texttt{U+0250}--\texttt{U+02AF}: IPA Extensions
1820 \item \texttt{U+02B0}--\texttt{U+02FF}: Spacing Modifier Letters
1821 \item \texttt{U+0300}--\texttt{U+036F}: \\\null\hfill Combining Diacritical Marks
1822 \item \texttt{U+1E00}--\texttt{U+1EFF}: \\\null\hfill Latin Extended Additional
1823 \par\
1824 \end{itemize}
1825 \end{multicols}
1826 %<*en>
1827 \item[Range~2${}^{\text{J}}$] Greek and Cyrillic letters. JIS~X~0208 (hence most of Japanese
1828            fonts) has some of these characters.
1829 %</en>
1830 %<*ja>
1831 \item[範囲2${}^{\text{J}}$] ギリシャ文字とキリル文字.JIS~X~0208(したがってほとんどの
1832                              和文フォント)はこれらの文字を持つ.
1833 %</ja>
1834 \begin{multicols}{2}
1835 \begin{itemize}
1836 \item \texttt{U+0370}--\texttt{U+03FF}: Greek and Coptic
1837 \item \texttt{U+0400}--\texttt{U+04FF}: Cyrillic
1838 \item \texttt{U+1F00}--\texttt{U+1FFF}: Greek Extended
1839 \\\
1840 \end{itemize}
1841 \end{multicols}
1842 %<*en>
1843 \item[Range~3${}^{\text{J}}$] Punctuations and Miscellaneous symbols. The block list is
1844            indicated in Table~\ref{table-rng3}.
1845 %</en>
1846 %<*ja>
1847 \item[範囲3${}^{\text{J}}$] 句読点と記号類.ブロックのリストは表\ref{table-rng3}%
1848                              に示してある.
1849 %</ja>
1850 \begin{table}[!tb]
1851 %<en>\caption{Unicode blocks in predefined character range~3.}
1852 %<ja>\caption{文字範囲3に指定されているUnicodeブロック.}
1853 \label{table-rng3}
1854 \catcode`\"=13\def"#1#2#3#4{\texttt{U+#1#2#3#4}}%"
1855 \centering\small
1856 \begin{tabular}{llll}
1857 "2000--"206F&General Punctuation&
1858 "2070--"209F&Superscripts and Subscripts\\
1859 "20A0--"20CF&Currency Symbols&
1860 "20D0--"20FF&Comb.\ Diacritical Marks for Symbols\\
1861 "2100--"214F&Letterlike Symbols&
1862 "2150--"218F&Number Forms\\
1863 "2190--"21FF&Arrows&
1864 "2200--"22FF&Mathematical Operators\\
1865 "2300--"23FF&Miscellaneous Technical&
1866 "2400--"243F&Control Pictures\\
1867 "2500--"257F&Box Drawing&
1868 "2580--"259F&Block Elements\\
1869 "25A0--"25FF&Geometric Shapes&
1870 "2600--"26FF&Miscellaneous Symbols\\
1871 "2700--"27BF&Dingbats&
1872 "2900--"297F&Supplemental Arrows-B\\
1873 "2980--"29FF&Misc.\ Mathematical Symbols-B&
1874 "2B00--"2BFF&Miscellaneous Symbols and Arrows
1875 \end{tabular}
1876 \end{table}
1877 %<*en>
1878 \item[Range~4${}^{\text{A}}$] Characters usually not in Japanese fonts. This range consists
1879            of almost all Unicode blocks which are not in other
1880            predefined ranges. Hence, instead of showing the block list,
1881            we put the definition of this range itself:
1882 %</en>
1883 %<*ja>
1884 \item[範囲4${}^{\text{A}}$] 通常和文フォントには含まれていない文字.
1885                              この範囲は他の範囲にないほとんど全てのUnicodeブロック
1886                              で構成されている.したがって,ブロックのリストを示す
1887                              代わりに,範囲の定義そのものを示す:
1888 %</ja>
1889 \begin{lstlisting}
1890 \ltjdefcharrange{4}{%
1891    "500-"10FF, "1200-"1DFF, "2440-"245F, "27C0-"28FF, "2A00-"2AFF,
1892   "2C00-"2E7F, "4DC0-"4DFF, "A4D0-"A82F, "A840-"ABFF, "FB00-"FE0F,
1893   "FE20-"FE2F, "FE70-"FEFF, "10000-"1FFFF, "E000-"F8FF} % non-Japanese
1894 \end{lstlisting}
1895 %<en>\item[Range~5${}^{\text{A}}$] Surrogates and Supplementary Private Use Areas.
1896 %<ja>\item[範囲5${}^{\text{A}}$] 代用符号と補助私用領域.
1897 %<en>\item[Range~6${}^{\text{J}}$] Characters used in Japanese. The block list is indicated in Table~\ref{table-rng6}.
1898 %<ja>\item[範囲6${}^{\text{J}}$] 日本語で用いられる文字.ブロックのリストは表\ref{table-rng6}に示す.
1899 \begin{table}[!tb]
1900 %<en>\caption{Unicode blocks in predefined character range~6.}
1901 %<ja>\caption{文字範囲6に指定されているUnicodeブロック.}
1902 \label{table-rng6}
1903 \catcode`\"=13\def"#1#2#3#4{\texttt{U+#1#2#3#4}}%"
1904 \centering\small
1905 \begin{tabular}{llll}
1906 "2460--"24FF&Enclosed Alphanumerics&
1907 "2E80--"2EFF&CJK Radicals Supplement\\
1908 "3000--"303F&CJK Symbols and Punctuation&
1909 "3040--"309F&Hiragana\\
1910 "30A0--"30FF&Katakana&
1911 "3190--"319F&Kanbun\\
1912 "31F0--"31FF&Katakana Phonetic Extensions&
1913 "3200--"32FF&Enclosed CJK Letters and Months\\
1914 "3300--"33FF&CJK Compatibility&
1915 "3400--"4DBF&CJK Unified Ideographs Extension A\\
1916 "4E00--"9FFF&CJK Unified Ideographs&
1917 "F900--"FAFF&CJK Compatibility Ideographs\\
1918 "FE10--"FE1F&Vertical Forms&
1919 "FE30--"FE4F&CJK Compatibility Forms\\
1920 "FE50--"FE6F&Small Form Variants&
1921 "{20}000--"{2F}FFF&(Supplementary Ideographic Plane)\\
1922 "{E0}100--"{E0}1EF&Variation Selectors Supplement
1923 \end{tabular}
1924 \end{table}
1925 %<*en>
1926 \item[Range~7${}^{\text{J}}$] Characters used in CJK languages, but not included in  Adobe-Japan1-6.
1927 The block list is indicated in Table~\ref{table-rng7}.
1928 %</en>
1929 %<*ja>
1930 \item[範囲7${}^{\text{J}}$] CJK言語で用いられる文字のうち,Adobe-Japan1-6に
1931                             含まれていないもの.
1932                             ブロックのリストは表\ref{table-rng7}に示す.
1933 %</ja>
1934 \begin{table}[!tb]
1935 %<en>\caption{Unicode blocks in predefined character range~7.}
1936 %<ja>\caption{文字範囲7に指定されているUnicodeブロック.}
1937 \label{table-rng7}
1938 \catcode`\"=13\def"#1#2#3#4{\texttt{U+#1#2#3#4}}%"
1939 \centering\small
1940 \begin{tabular}{llll}
1941 "1100--"11FF&Hangul Jamo&
1942 "2F00--"2FDF&Kangxi Radicals\\
1943 "2FF0--"2FFF&Ideographic Description Characters&
1944 "3100--"312F&Bopomofo\\
1945 "3130--"318F&Hangul Compatibility Jamo&
1946 "31A0--"31BF&Bopomofo Extended\\
1947 "31C0--"31EF&CJK Strokes&
1948 "A000--"A48F&Yi Syllables\\
1949 "A490--"A4CF&Yi Radicals&
1950 "A830--"A83F&Common Indic Number Forms\\
1951 "AC00--"D7AF&Hangul Syllables&
1952 "D7B0--"D7FF&Hangul Jamo Extended-B
1953 \end{tabular}
1954 \end{table}
1955 \end{description}
1956
1957
1958 %<en>\subsection{\Param{kanjiskip} and \Param{xkanjiskip}}
1959 %<ja>\subsection{\Param{kanjiskip}と\Param{xkanjiskip}}
1960 \label{subs-kskip}
1961
1962 %<en>\textbf{JAglue} is divided into the following three categories:
1963 %<ja>\textbf{JAglue}は以下の3つのカテゴリに分類される:
1964 \begin{itemize}
1965 %<*en>
1966 \item Glues/kerns specified in JFM. If \verb+\inhibitglue+ is issued
1967       around a Japanese character, this glue will not be inserted at the
1968       place.
1969 %</en>
1970 %<*ja>
1971 \item JFMで指定されたグルー/カーン.もし \verb+\inhibitglue+ が和文文字の周りで
1972       発行されていれば,このグルーは挿入されない.
1973 %</ja>
1974 %<*en>
1975 \item The default glue which inserted between two \textbf{JAchar}s (\Param{%
1976       kanjiskip}).
1977 %</en>
1978 %<*ja>
1979 \item デフォルトで2つの\textbf{JAchar}の間に挿入されるグルー(\Param{\hyperlink{fld:kanjiskip}{kanjiskip}}).
1980 %</ja>
1981 %<*en>
1982 \item The default glue which inserted between a \textbf{JAchar} and an
1983       \textbf{ALchar} (\Param{\hyperlink{fld:xks}{xkanjiskip}}).
1984 %</en>
1985 %<*ja>
1986 \item デフォルトで\textbf{JAchar}と\textbf{ALchar}の間に挿入されるグルー(\Param{\hyperlink{fld:xks}{xkanjiskip}}).
1987 %</ja>
1988 \end{itemize}
1989 %<*en>
1990 The value (a skip) of \Param{\hyperlink{fld:kanjiskip}{kanjiskip}} or 
1991 \Param{\hyperlink{fld:xks}{xkanjiskip}} can be changed as the following.
1992 Note that only their values \emph{at the end of a paragraph or a hbox are
1993 adopted in the whole paragraph or the whole hbox.
1994 }
1995 %</en>
1996 %<*ja>
1997 \Param{\hyperlink{fld:kanjiskip}{kanjiskip}}や\Param{\hyperlink{fld:xks}{xkanjiskip}}の値
1998 は以下のようにして変更可能である.
1999 %</ja>
2000 \begin{lstlisting}
2001 \ltjsetparameter{kanjiskip={0pt plus 0.4pt minus 0.4pt},
2002                  xkanjiskip={0.25\zw plus 1pt minus 1pt}}
2003 \end{lstlisting}
2004 %<*en>
2005 Here \verb+\zw+ is a internal dimension 
2006 which stores fullwidth of the current Japanese font.
2007 This \verb+\zw+ can be used as the unit \texttt{zw} in \pTeX.
2008
2009 It may occur that JFM contains the data of ``ideal width of 
2010 \Param{\hyperlink{fld:kanjiskip}{kanjiskip}}''
2011 and/or ``ideal width of \Param{\hyperlink{fld:xks}{xkanjiskip}}''.
2012 To use these data from JFM, set the value of \Param{\hyperlink{fld:kanjiskip}{kanjiskip}} or
2013 \Param{\hyperlink{fld:xks}{xkanjiskip}} to \verb+\maxdimen+.
2014 %</en>
2015 %<*ja>
2016 ここで,\verb+\zw+ は現在の和文フォントの全角幅を表す長さであり,
2017 \pTeX における長さ単位 \texttt{zw} と同じように使用できる.
2018
2019 JFMは「望ましい\Param{\hyperlink{fld:kanjiskip}{kanjiskip}}の値」や
2020 「望ましい\Param{\hyperlink{fld:xks}{xkanjiskip}}の値」を持っていることがある.
2021 これらのデータを使うためには,\Param{\hyperlink{fld:kanjiskip}{kanjiskip}}や%
2022 \Param{\hyperlink{fld:xks}{xkanjiskip}}の値を \verb+\maxdimen+ の値に設定すればよい.
2023 %</ja>
2024
2025 %<en>\subsection{Insertion Setting of \Param{xkanjiskip}}
2026 %<ja>\subsection{\Param{xkanjiskip} の挿入設定}
2027
2028 %<*en>
2029 It is not desirable that \Param{\hyperlink{fld:xks}{xkanjiskip}} is inserted into every
2030 boundary between \textbf{JAchar}s and \textbf{ALchar}s. For example,
2031 \Param{\hyperlink{fld:xks}{xkanjiskip}} should not be inserted after opening parenthesis
2032 (\textit{e.g.}, compare ``(あ'' and ``(\hskip\ltjgetparameter{xkanjiskip}あ'').
2033 \LuaTeX-ja can control whether \Param{\hyperlink{fld:xks}{xkanjiskip}} can be inserted
2034 before/after a character, by changing \Param{jaxspmode} for \textbf{JAchar}s and
2035 \Param{alxspmode} parameters \textbf{ALchar}s respectively.
2036 %</en>
2037 %<*ja>
2038 \Param{\hyperlink{fld:xks}{xkanjiskip}}がすべての\textbf{JAchar}と\textbf{ALchar}の境界に
2039 挿入されるのは望ましいことではない.例えば,\Param{\hyperlink{fld:xks}{xkanjiskip}}は開き括弧の
2040 後には挿入されるべきではない(「(あ」と「(\hskip\ltjgetparameter{xkanjiskip}あ」を
2041 比べてみよ).
2042 \LuaTeX-jaでは\Param{\hyperlink{fld:xks}{xkanjiskip}}をある文字の前/後に挿入するかどうかを,
2043 \textbf{JAchar}に対しては\Param{jaxspmode}を,\textbf{ALchar}に対しては
2044 \Param{alxspmode}をそれぞれ変えることで制御することができる.
2045 %</ja>
2046 \begin{LTXexample}
2047 \ltjsetparameter{jaxspmode={`あ,preonly}, alxspmode={`\!,postonly}}
2048 pあq い!う
2049 \end{LTXexample}
2050
2051 %<*en>
2052 The second argument \texttt{preonly} means that the insertion of
2053 \Param{\hyperlink{fld:xks}{xkanjiskip}} is allowed before this character, but not after.
2054 the other possible values are \texttt{postonly}, \texttt{allow}, and \texttt{inhibit}.
2055 %</en>
2056 %<*ja>
2057 2つ目の引数の \texttt{preonly}は「\Param{\hyperlink{fld:xks}{xkanjiskip}}の挿入はこの文字の
2058 前でのみ許され,後では許さない」ことを意味する.他に指定可能な値は
2059 \texttt{postonly}, \texttt{allow}, \texttt{inhibit}である.
2060 %</ja>
2061
2062 %<*en>
2063 \Param{jaxspmode} and \Param{alxspmode} use a same table to store the parameters
2064 on the current version. Therefore, line~1 in the code above can be rewritten
2065 as follows:
2066 %</en>
2067 %<*ja>
2068 なお,現行の
2069 仕様では,\Param{jaxspmode}, \Param{alxspmode}はテーブルを共有しており,
2070 上のコードの1行目を次のように変えても同じことになる:
2071 %</ja>
2072 \begin{verbatim}
2073 \ltjsetparameter{alxspmode={`あ,preonly}, jaxspmode={`\!,postonly}}
2074 \end{verbatim}
2075 %<*en>
2076 One can use also numbers to specify these two parameters (see Subsection~\ref{ssec-param}).
2077 %</en>
2078 %<*ja>
2079 また,これら2パラメータには数値で値を指定することもできる(\ref{ssec-param}節を参照).
2080 %</ja>
2081
2082 %<*en>
2083 If you want to enable/disable all insertions of \Param{\hyperlink{fld:kanjiskip}{kanjiskip}} and
2084 \Param{\hyperlink{fld:xks}{xkanjiskip}}, set \Param{autospacing} and \Param{autoxspacing}
2085 parameters to \texttt{true}/\texttt{false}, respectively.
2086 %</en>
2087 %<*ja>
2088 もし全ての\Param{\hyperlink{fld:kanjiskip}{kanjiskip}}と\Param{\hyperlink{fld:xks}{xkanjiskip}}の挿入を有効化/無効化
2089 したければ,それぞれ\Param{autospacing}と\Param{autoxspacing}を
2090 \texttt{true}/\texttt{false}に設定すればよい.
2091 %</ja>
2092
2093 %<en>\subsection{Shifting the baseline}
2094 %<ja>\subsection{ベースラインの移動}
2095 %<*en>
2096 To make a match between a Japanese font and an alphabetic font, sometimes
2097 shifting of the baseline of one of the pair is needed. In \pTeX, this is achieved
2098 by setting \verb+\ybaselineshift+ to a non-zero length (the
2099 baseline of \textbf{ALchar} is shifted below). However, for documents
2100 whose main language is not Japanese, it is good to shift the baseline of
2101 Japanese fonts, but not that of alphabetic fonts.
2102 Because of this, \LuaTeX-ja can independently set the shifting amount
2103 of the baseline of alphabetic fonts (\Param{yalbaselineshift}
2104 parameter) and that of Japanese fonts (\Param{yjabaselineshift}
2105 parameter).
2106 %</en>
2107 %<*ja>
2108 和文フォントと欧文フォントを合わせるためには,時々どちらかのベースラインの移動が
2109 必要になる.\pTeX ではこれは \verb+\ybaselineshift+ を設定することで
2110 なされていた(\textbf{ALchar}のベースラインがその分だけ下がる).しかし,日本語が主ではない
2111 文書に対しては,欧文フォントではなく和文フォントのベースラインを移動した方がよい.
2112 このため,\LuaTeX-jaでは欧文フォントのベースラインのシフト量
2113 (\Param{yalbaselineshift}パラメータ)と和文フォントのベースラインのシフト量
2114 (\Param{yjabaselineshift}パラメータ)を独立に設定できるようになっている.
2115 %</ja>
2116
2117 \begin{LTXexample}
2118 \vrule width 150pt height 0.4pt depth 0pt \hskip-120pt
2119 \ltjsetparameter{yjabaselineshift=0pt, yalbaselineshift=0pt}abcあいう
2120 \ltjsetparameter{yjabaselineshift=5pt, yalbaselineshift=2pt}abcあいう
2121 \end{LTXexample}
2122 %<*en>
2123 Here the horizontal line in above is the baseline of a line.
2124 %</en>
2125 %<*ja>
2126 上の例において引かれている水平線がベースラインである.
2127 %</ja>
2128
2129 %<*en>
2130 There is an interesting side-effect: characters in different size can be
2131 vertically aligned center in a line, by setting two parameters appropriately.
2132 The following is an example (beware the value is not well tuned):
2133 %</en>
2134 %<*ja>
2135 この機能には面白い使い方がある:2つのパラメータを適切に設定することで,サイズの
2136 異なる文字を中心線に揃えることができる.
2137 以下は一つの例である(値はあまり調整されていないことに注意):
2138 %</ja>
2139 \begin{LTXexample}
2140 xyz漢字
2141 {\scriptsize
2142   \ltjsetparameter{yjabaselineshift=-1pt,
2143     yalbaselineshift=-1pt}
2144   XYZひらがな
2145 }abcかな
2146 \end{LTXexample}
2147
2148
2149 %<*ja>
2150 \paragraph{数式における挙動:\pTeX との違い}
2151 \textbf{ALchar}のベースラインを補正する \Param{yalbaselineshift} パラメータは
2152 ほぼ\pTeX における \verb+\ybaselineshift+ に対応しているものであるが,
2153 数式中の挙動は異なっているので注意が必要である.
2154 例えば,表\ref{tab:math_bsa}のように,数式中に明示的に現れた \verb+\hbox+ は,
2155 \begin{itemize}
2156  \item \pTeX では,ボックス全体が \verb+\ybaselineshift+ だとシフトされるので,
2157  表\ref{tab:math_bsa}中の``い''のように,ボックス中の和文文字は
2158  \verb+\ybaselineshift+だけシフトされ,一方,``for all''のように,
2159  ボックス内の欧文文字は2重にシフトされることになる.
2160  \item 一方,\LuaTeX-jaではそのようなことはおこらず,
2161  数式中に明示的に現れた \verb+\hbox+ はシフトしない.そのため,
2162  表\ref{tab:math_bsa}中の``い''も``for all''も,それぞれ本文中に
2163  書かれたときと同じ上下位置に組まれる.
2164 \end{itemize}
2165 \begin{table}
2166 \small\centering
2167 \caption{数式関係のベースライン補正($\Param{yalbaselineshift}=10\,\textrm{pt}$)}
2168 \label{tab:math_bsa}
2169 \newdimen\origbaselineskip
2170 \origbaselineskip=\baselineskip
2171 \begin{tabular}{lp{30\zw}}
2172 \toprule
2173 \emph{入力}&\vspace*{\dimexpr-\origbaselineskip-\smallskipamount}
2174 \begin{verbatim}
2175 数式abc: $あa\hbox{い}$, $\int_0^x t\,dt=x^2\!/2$,
2176 $\Phi\vdash F(x)\ \hbox{for all}\ x\in A$
2177 \end{verbatim}\\
2178 \noalign{\vskip-\origbaselineskip}
2179 \midrule
2180 \emph{\pTeX}&
2181 {\ltjsetparameter{yalbaselineshift=10pt}%
2182 数式abc: $あa\lower10pt\hbox{い}$, $\int_0^x t\,dt=x^2\!/2$,
2183 $\Phi\vdash F(x)\ \lower10pt\hbox{for all}\ x\in A$
2184 \par}\\
2185 \midrule
2186 \emph{\LuaTeX-ja}&
2187 {\ltjsetparameter{yalbaselineshift=10pt}%
2188 数式abc: $あa\hbox{い}$, $\int_0^x t\,dt=x^2\!/2$,
2189 $\Phi\vdash F(x)\ \hbox{for all}\ x\in A$
2190 \par}\\
2191 \noalign{\vskip-\origbaselineskip}
2192 \bottomrule
2193 \end{tabular} 
2194 \end{table}
2195 %</ja>
2196
2197 %<en>\part{Reference}
2198 %<ja>\part{リファレンス}
2199 \label{part-ref}
2200
2201 %<*ja>
2202 \section{\LuaTeX-jaにおける \texttt{\textbackslash catcode}}
2203 \subsection{予備知識:\pTeX と\upTeX における \texttt{\textbackslash kcatcode}}
2204 \pTeX,\upTeX においては,和文文字が制御綴内で利用できるかどうか
2205 は \verb+\kcatcode+ の値によって決定されるのであった.
2206 詳細は表\ref{table-kcat}を参照されたい.
2207 %</ja>
2208 %<*en>
2209 \section{\texttt{\textbackslash catcode} in \LuaTeX-ja}
2210 \subsection{Preliminaries: \texttt{\textbackslash kcatcode} in \pTeX\ and \upTeX}
2211 In \pTeX~and~\upTeX, the value of \verb+\kcatcode+ determines
2212 whether a Japanese character can be used in a control word.
2213 For the detail, see Table~\ref{table-kcat}.
2214 %</en>
2215
2216 \begin{table}[t]
2217 \small
2218 \caption{\texttt{\textbackslash kcatcode} in \upTeX}
2219 \label{table-kcat}
2220 %<en>\medskip
2221
2222 \noindent\hfill
2223 \begin{tabular}{ccccc}
2224 \toprule
2225 \bfseries \verb+\kcatcode+&
2226 %<*en>
2227 \bfseries meaning&
2228 \bfseries control word&
2229 \bfseries widow penalty\hbox{}$^*$&
2230 \bfseries linebreak\\
2231 %</en>
2232 %<*ja>
2233 \bfseries 意図&
2234 \bfseries 制御綴中に使用&
2235 \bfseries 文字ウィドウ処理\hbox{}$^*$&
2236 \bfseries 直後での改行\\
2237 %</ja>
2238 \midrule
2239 15&non-cjk&\multicolumn{3}{c}{(treated as usual \LaTeX)}\\
2240 16&kanji&Y&Y&ignored\\
2241 17&kana&Y&Y&ignored\\
2242 18&other&N&N&ignored\\
2243 19&hangul&Y&Y&space\\
2244 \bottomrule
2245 \end{tabular}\hfill\null
2246
2247 \medskip
2248
2249 %<*ja>
2250 文字ウィドウ処理\hbox{}$^*$: 「漢字が一文字だけ次の行に行くのを防ぐ」\ 
2251 \texttt{\textbackslash jcharwidowpenalty} が,
2252 その文字の直前に挿入されうるか否か,を示す.
2253 %</ja>
2254 \end{table} 
2255
2256 %<*en>
2257 \verb+\kcatcode+ can be set by a row of JIS~X~0208 in \pTeX,
2258 and generally by a Unicode block\footnote{%
2259   \upTeX\ divides \texttt{U+FF00}--\texttt{U+FFEF} (Halfwidth and Fullwidth Forms)
2260   into three subblocks, and \texttt{\textbackslash kcatcode} can be set by a subblock.
2261 }
2262 in \upTeX. So characters which can be used in a control word 
2263 slightly differ between \pTeX~and~\upTeX.
2264 %</en>
2265 %<*ja>
2266 \pTeX では \verb+\kcatcode+ はJIS~X~0208の区単位,
2267 \upTeX では概ねUnicodeブロック単位\footnote{%
2268   \texttt{U+FF00}--\texttt{U+FFEF} (Halfwidth and Fullwidth Forms)は
2269   「全角英数字」「半角カナ」「その他」と3つに分割されており,
2270   それぞれ別々に \texttt{\textbackslash kcatcode} が指定できるようになっている.
2271 }で設定可能になっている.そのため,\pTeX と\upTeX の初期状態では
2272 制御綴内で使用可能な文字が微妙に異なっている.
2273 %</ja>
2274
2275 %<*en>
2276 \subsection{Case of \LuaTeX-ja}
2277 The role of \verb+\kcatcode+ in \pTeX~and~\upTeX\ caan be 
2278 divided into the following four kinds, 
2279 and \LuaTeX-ja can control these four kinds separately:
2280 \begin{itemize}
2281  \item
2282 \emph{Distinction between \textbf{JAchar} or \textbf{ALchar}}
2283 is controlled by using the character range, see Subsection~\ref{ssec-setrange}.
2284  \item
2285 \emph{Whether the character can be used in a control word}
2286 is controlled by setting \verb+\catcode+ to 11~(enabled) or 12~(disabled), as usual.
2287  \item
2288 \emph{Whether \Param{jcharwidowpenalty} can be inserted before the character}
2289 is controlled by the lowermost bit of the \Param{kcatcode} parameter.
2290  \item
2291 \emph{Ignoring linebreak after a \textbf{JAchar}} is always ignored.
2292 \end{itemize}
2293 %</en>
2294 %<*ja>
2295 \subsection{\LuaTeX-jaの場合}
2296 \LuaTeX-jaでは,従来の\pTeX・\upTeX における \verb+\kcatcode+ の役割を
2297 分割している:
2298 \begin{description}
2299  \item[欧文/和文の区別 (\upTeX)] 
2300 \verb+\ltjdefcharrange+ と\textsf{jacharrange}パラメータ(\ref{ssec-setrange}節)
2301  \item[制御綴中に使用可か]
2302 \LuaTeX 自身の \verb+\catcode+ でよい
2303  \item[\Param{jcharwidowpenalty}が挿入可か]
2304 \Param{kcatcode}パラメータの最下位ビット
2305  \item[直後の改行の無視]
2306 日本語しか想定していないので\textbf{JAchar}については一律有効
2307 \end{description}
2308 %</ja>
2309
2310 %<*en>
2311 Default setting of \verb+\catcode+ of \LuaTeX\ can be found 
2312 in \texttt{luatex-unicode-letters.tex},
2313 which is based on \texttt{unicode-letters.tex} (for \XeTeX).
2314 However, the default setting of \verb+\catcode+ differs
2315 between \XeTeX\ and \LuaTeX, by the following reasons:
2316 \begin{itemize}
2317  \item \texttt{luatex-unicode-letters.tex} is based on old \texttt{unicode-letters.tex}.
2318  \item The latter half of \texttt{unicode-letters.tex} sets
2319 \verb+\catcode+ of Kanji and kana characters to 11,
2320 via setting \verb+\XeTeXcharclass+.
2321
2322 However, this latter half is simply omitted in
2323 \texttt{luatex-unicode-letters.tex}, hence
2324 \verb+\catcode+ of Kanji and kana characters remains 12 in \LuaTeX.
2325 \end{itemize}
2326 In other words, Kanji nor kana characters cannot be used in 
2327 a control word, in the default setting of \LuaTeX.
2328
2329 This would be inconvenient for \pTeX~users to shifting to \LuaTeX-ja, 
2330 since several control words containing Kanji, such as \verb+\西暦+, 
2331 are used in \pTeX.
2332 Hence, \LuaTeX-ja have a counterpart of \texttt{unicode-letters.tex}
2333 for \LuaTeX, \emph{to match the \texttt{\textbackslash catcode} setting with that of \XeTeX.}
2334 %</en>
2335 %<*ja>
2336 ネイティブにUnicode全部の文字を扱える\XeTeX や\LuaTeX では,
2337 文字が制御綴内で使用できるかは通常の欧文文字と同じく \verb+\catcode+
2338 で指定することとなる.\XeTeX における \verb+\catcode+ の初期設定は\ 
2339 \texttt{unicode-letters.tex} 中に記述されており,\LuaTeX ではそれを
2340 元にした \texttt{luatex-unicode-letters.tex} を用いている.
2341
2342 だが,\XeTeX における \verb+\catcode+ の初期設定と
2343 \LuaTeX におけるそれは一致していない:
2344 \begin{itemize}
2345  \item \texttt{luatex-unicode-letters.tex} の元になった\ 
2346 \texttt{unicode-letters.tex} が古い
2347  \item \texttt{unicode-letters.tex} の後半部では
2348 \verb+\XeTeXcharclass+ の設定を行なっており,
2349 それによって漢字や仮名の \verb+\catcode+ が11に設定されている.
2350
2351 しかし,\texttt{luatex-unicode-letters.tex} ではこの「後半部」が
2352 まるごと省略されており,漢字や仮名の \verb+\catcode+ は12のまま.
2353 \end{itemize}
2354 言い換えると,\LuaTeX の初期状態では漢字や仮名を制御綴内に
2355 使用することはできない.
2356
2357 これでは \pTeX で使用できた \verb+\西暦+ などが使えないこととなり,
2358 \LuaTeX-jaへの移行で手間が生じる.そのため,\LuaTeX-jaでは
2359 \texttt{unicode-letters.tex} の後半部にあたる内容を自前でパッチし,
2360 結果として\textbf{\XeTeX における初期設定と同じになるようにしている.}
2361 %</ja>
2362
2363 \begin{table}
2364  \centering\small
2365 %<en>\caption{Difference of the set of non-kanji JIS~X~0208 characters which can be used in a control word}
2366 %<ja>\caption{制御綴中に使用出来るJIS~X~0208非漢字の違い}
2367 %<en>\medskip
2368 \label{table-kcat-diff}
2369 \def\D#1#2#3#4{%
2370   {\fboxsep0pt\fcolorbox{cyan}{white}%
2371   {\large\char"#1#2#3#4}}\ (\texttt{U+#1#2#3#4})} %"
2372 \leavevmode\hbox to 0pt{\hss\begin{tabular}{cccccc}
2373 \toprule
2374 %<en>&\bf row&\bf col.&\bf \pTeX&\bf \upTeX&\bf\LuaTeX-ja\\
2375 %<ja>&\bf 区&\bf 点&\bf \pTeX&\bf \upTeX&\fontseries{b}\selectfont\LuaTeX-ja\\
2376 \midrule
2377 \D 3000&1&1&N&N&Y\\
2378 \D 30FB&1&6&N&Y&N\\
2379 \D 309B&1&11&N&Y&N\\
2380 \D 309C&1&12&N&Y&N\\
2381 \D FF40&1&14&N&N&Y\\
2382 \D FF3E&1&16&N&N&Y\\
2383 \D FFE3&1&17&N&N&Y\\
2384 \D FF3F&1&18&N&N&Y\\
2385 \D 30FD&1&19&N&Y&Y\\
2386 \D 30FE&1&20&N&Y&Y\\
2387 \D 309D&1&21&N&Y&Y\\
2388 \D 309E&1&22&N&Y&Y\\
2389 \D 3003&1&23&N&N&Y\\
2390 \D 4EDD&1&24&N&Y&Y\\
2391 \D 3005&1&25&N&N&Y\\
2392 \D 3006&1&26&N&N&Y\\
2393 \D 3007&1&27&N&N&Y\\
2394 \D 30FC&1&28&N&Y&Y\\
2395 \bottomrule
2396 \end{tabular}\qquad
2397 \begin{tabular}{cccccc}
2398 \toprule
2399 %<en>&\bf row&\bf col.&\bf \pTeX&\bf \upTeX&\bf\LuaTeX-ja\\
2400 %<ja>&\bf 区&\bf 点&\bf \pTeX&\bf \upTeX&\fontseries{b}\selectfont\LuaTeX-ja\\
2401 \midrule
2402 \D FF0F&1&31&N&N&Y\\
2403 \D FF3C&1&32&N&N&Y\\
2404 \D FF5C&1&35&N&N&Y\\
2405 \D FF0B&1&60&N&N&Y\\
2406 \D FF1D&1&65&N&N&Y\\
2407 \D FF1C&1&67&N&N&Y\\
2408 \D FF1E&1&68&N&N&Y\\
2409 \D FF03&1&84&N&N&Y\\
2410 \D FF06&1&85&N&N&Y\\
2411 \D FF0A&1&86&N&N&Y\\
2412 \D FF20&1&87&N&N&Y\\
2413 \D 3012&2&9&N&N&Y\\
2414 \D 3013&2&14&N&N&Y\\
2415 \D FFE2&2&44&N&N&Y\\
2416 \D 212B&2&82&N&N&Y\\
2417 %<en>\multicolumn{3}{c}{$\vphantom{\D 3000}$\hbox{}Greek letters (row 6)}&Y&N&Y\\
2418 %<en>\multicolumn{3}{c}{$\vphantom{\D 3000}$\hbox{}Cyrillic letters (row 7)}&N&N&Y\\
2419 %<ja>\multicolumn{3}{c}{$\vphantom{\D 3000}$\hbox{}ギリシャ文字(6区)}&Y&N&Y\\
2420 %<ja>\multicolumn{3}{c}{$\vphantom{\D 3000}$\hbox{}キリル文字(7区)}&N&N&Y\\
2421 $\vphantom{\D 3000}$\\
2422 \bottomrule
2423 \end{tabular}\hss}\par
2424 \end{table}
2425
2426 %<*en>
2427 \subsection{Non-kanji Characters in a Control Word}
2428 Because the engine differ, so non-kanji JIS~X~0208 characters
2429 which can be used in a control word differ in \pTeX, in \upTeX,~and~in \LuaTeX-ja.
2430 Table~\ref{table-kcat-diff} shows the difference.
2431 Except for four characters ``・'',~``゛'', ``゜'',~``゠'', 
2432 \LuaTeX-ja admits more characters in a control word than \upTeX.
2433 \emph{Note that the ideographic space~\texttt{U+3000} can be used 
2434 in a control word in \LuaTeX-ja.}
2435
2436 Difference becomes larger, if we consider 
2437 non-kanji JIS~X~0213 characters.
2438 For the detail, see \url{https://github.com/h-kitagawa/kct}.
2439 %</en>
2440 %<*ja>
2441 \subsection{制御綴中に使用出来るJIS非漢字の違い}
2442
2443 エンジンが異なるので,\pTeX, \upTeX, \LuaTeX-ja
2444 において制御綴中に使用可能なJIS~X~0208の文字は異なる.
2445 異なっているところだけを載せると,表\ref{table-kcat-diff}のようになる.
2446 「・」「゛」「゜」「゠」を除けば,\LuaTeX-jaでは\upTeX より多くの文字が
2447 制御綴に使用可能になっている.
2448 \textbf{特に重要なのは,全角空白(\texttt{U+3000})が
2449 \LuaTeX-jaでは制御綴中に使用可能であることである.}
2450
2451 JIS~X~0213の範囲に広げると,差異はさらに大きくなる.
2452 詳細については例えば \url{https://github.com/h-kitagawa/kct} 中の\ 
2453 \texttt{kct-uni-out.pdf} などを参照すること.
2454 %</ja>
2455
2456
2457
2458
2459 %<*ja>
2460 \section{縦組}
2461 \label{sec-direction}
2462 \LuaTeX 本体でも,$\Omega$・$\aleph$由来の機能として,複数の組方向をサポートしている.
2463 しかし,\LuaTeX がサポートするのは \texttt{TLT},~\texttt{TRT}, \texttt{RTT},~\texttt{LTL}\ 
2464 のみであり,日本語の縦書きに使うのは望ましくない\footnote{%
2465 和文文字だけならば \texttt{RTT} を使えばなんとかなると思うが,
2466 欧文文字が入ってきた場合はうまくいかず,\texttt{RTR} という組方向が必要になる.
2467 }.そのため,\LuaTeX-jaでは横組(\texttt{TLT})で組んだボックスを回転させる方式で
2468 縦組を実装した.
2469
2470 \subsection{サポートする組方向}
2471 \begin{table}[t]
2472 \caption{\LuaTeX-ja のサポートする組方向}
2473 %<en>\medskip
2474 \label{tab-dir}
2475 \centering\small
2476 \def\obox#1{%
2477   \setbox0=\hbox{\yoko\hbox{#1%
2478   \large\ltjsetparameter{talbaselineshift=0pt}%
2479   \vrule height 25pt width 0.4pt depth 15pt\kern-.2pt%
2480   \raise25pt\hbox to 0pt{\hss\composite{*r^@{>>}}\hss}%
2481   \raise-15pt\hbox to 0pt{\hss\composite{*l^@{>|}}\hss}\kern.2pt%
2482   \vrule height.2pt depth.2pt width 60pt\hbox to 0pt{\hss\composite{*d^@{>}}\hss}\kern-60pt
2483   \hbox to 60pt{\,銀は、Ag\hss}}}%
2484   \raise\dimexpr 0.5\ltjgetdp0-0.5\ltjgetht0\box0%
2485 }
2486 \begin{tabular}{>{\bfseries}lccc}
2487 \toprule
2488 &\texttt{\textbackslash yoko}(横組)&\texttt{\textbackslash tate}(縦組)
2489  &\texttt{\textbackslash dtou}\\
2490 \midrule
2491 字送り方向&水平右向き(→)&垂直下向き(↓)&垂直上向き(↑)\\
2492 行送り方向&垂直下向き(↓)&水平左向き(←)&水平右向き(→)\\
2493 使用する和文フォント&横組用(\verb+\jfont+)&縦組用(\verb+\tfont+)&横組用(\verb+\jfont+)の
2494              $90^\circ$回転\\[\smallskipamount]
2495 組版例\null $^*$ &\obox{\yoko}&\obox{\tate}&\obox{\dtou}\\
2496 \noalign{\medskip}
2497 \bottomrule
2498 \end{tabular}
2499
2500 \medskip\raggedright
2501 \def\R#1{%
2502   \raise0.38\zw\hbox{%
2503     \vrule height.2pt  depth.2pt width2\zw%
2504     \hbox to 0pt{\hss\composite{*d^@{#1}}\hss}%
2505   }%
2506 }
2507 $^*$\ 幅(width),高さ(height),深さ(depth)の増加方向を,
2508 それぞれ「\R{>}」,「\R{>>}」,「\R{>|}」で表している.
2509 \raggedright
2510
2511 \end{table}
2512
2513 \LuaTeX-jaがサポートする組方向は表\ref{tab-dir}に示す3つである.
2514 4列目の \verb+\dtou+ は聞き慣れない命令だと思うが,
2515 実は\pTeX に同名の命令が(ドキュメントには書かれていないが)存在する.
2516 Down-TO-Upの意味なのだろう.\verb+\dtou+ を使用する機会はないだろうが,
2517 \LuaTeX-jaではデバッグ用に実装している.
2518
2519
2520 組方向は,\verb+\yoko+,~\verb+\tate+,~\verb+\dtou+ をそれぞれ使用することで,
2521 現在作成中のリストやボックスが空の時にのみ変更可能である.
2522
2523
2524 \subsection{異方向のボックス}
2525
2526 縦組の中に「42」などの2桁以上の算用数字を横組で組むなど,
2527 異なる組方向を混在させることがしばしば行われる.
2528 組方向の混在も\pTeX と同じようにできる:
2529 \begin{LTXexample}
2530 ここは横組%     yoko
2531 \hbox{\tate %   tate
2532   \hbox{縦組}%  tate
2533   の中に
2534   \hbox{\yoko 横組の内容}% yoko
2535   を挿入する
2536 }
2537 また横組に戻る% yoko
2538 \end{LTXexample}
2539
2540 異なる組方向のボックスを配置した場合にどう組まれるかの仕様も,\pTeX を
2541 踏襲している.表\ref{tab-diffdir}に示す.
2542
2543 \begin{table}[t]
2544 \caption{異方向のボックスの配置}
2545 %<en>\medskip
2546 \label{tab-diffdir}
2547  \centering\small\unitlength3mm
2548  \def\TATEeg{%
2549    \hbox{\smash{\begin{picture}(0,0)(-2,0)
2550      \thicklines
2551      \polyline(-2,0)(-2,-7)(5,-7)(5,0)
2552      \put(0,0){\circle*{0.3}}
2553      \put(0,0){\vector(1,0){5}} \put(2.5,-0.2){\makebox(0,0)[t]{$h_{\mathrm{T}}$}}
2554      \put(0,0){\vector(-1,0){2}}\put(-1,-0.2){\makebox(0,0)[t]{$d_{\mathrm{T}}$}}
2555      \put(0,0){\vector(0,-1){7}}\put(0.2,-3.5){\makebox(0,0)[l]{$w_{\mathrm{T}}$}}
2556    \end{picture}}}
2557  }
2558  \def\DTOUeg{%
2559    \hbox{\smash{\begin{picture}(0,0)(-5,0)
2560      \thicklines
2561      \polyline(-5,0)(-5,7)(2,7)(2,0)
2562      \put(0,0){\circle*{0.3}}
2563      \put(0,0){\vector(-1,0){5}} \put(-2.5,0.3){\makebox(0,0)[b]{$h_{\mathrm{D}}$}}
2564      \put(0,0){\vector(1,0){2}}\put(1,0.3){\makebox(0,0)[b]{$d_{\mathrm{D}}$}}
2565      \put(0,0){\vector(0,1){7}}\put(-0.2,3.5){\makebox(0,0)[r]{$w_{\mathrm{D}}$}}
2566    \end{picture}}}
2567  }
2568  \def\YOKOeg{%
2569    \hbox{\smash{\begin{picture}(0,0)
2570      \thicklines
2571      \polyline(0,5)(7,5)(7,-2)(0,-2)
2572      \put(0,0){\circle*{0.3}}
2573      \put(0,0){\vector(0,1){5}} \put(0.3,2.5){\makebox(0,0)[l]{$h_{\mathrm{Y}}$}}
2574      \put(0,0){\vector(0,-1){2}}\put(0.3,-1){\makebox(0,0)[l]{$d_{\mathrm{Y}}$}}
2575      \put(0,0){\vector(1,0){7}}\put(3.5,0.2){\makebox(0,0)[b]{$w_{\mathrm{Y}}$}}
2576    \end{picture}}}
2577  }
2578 \begin{tabular}{ccc}
2579 \toprule
2580 \emph{横組中に配置}&\emph{縦組中に配置}&%
2581 \emph{組方向\hskip\ltjgetparameter{xkanjiskip}\texttt{\textbackslash dtou}中に配置}\\
2582 \midrule
2583  \parbox[c]{15\unitlength}{\begin{picture}(15,15)(0,-4)
2584    \put(0,0){\line(1,0){3.8}}
2585    \put(4,7){\TATEeg}
2586    \put(11.2,0){\line(1,0){3.8}}
2587 %
2588    \put(2,7){\line(1,0){1.8}}
2589    \put(3,3.5){\vector(0,1){3.5}\vector(0,-1){3.5}}
2590    \put(2.8,3.5){\makebox(0,0)[r]{$H_{\mathrm{Y}}$}}
2591    \put(3,-2){\vector(0,1){2}}
2592    \put(2.8,-1){\makebox(0,0)[r]{$D_{\mathrm{Y}}$}}
2593 %
2594    \put(4,7.2){\line(0,1){1.8}}
2595    \put(11,7.2){\line(0,1){1.8}}
2596    \put(6,8){\vector(-1,0){2}}
2597    \put(9,8){\vector(1,0){2}}
2598    \put(7.5,8){\makebox(0,0){$W_{\mathrm{Y}}$}}
2599 %
2600  \end{picture}\vspace{-\baselineskip}
2601    \begin{align*}
2602    W_{\mathrm{Y}} &= h_{\mathrm{T}}+d_{\mathrm{T}},\\
2603    H_{\mathrm{Y}} &= w_{\mathrm{T}},\\
2604    D_{\mathrm{Y}} &=0\,\mathrm{pt}
2605    \end{align*}%
2606  }&
2607  \parbox[c]{15\unitlength}{\begin{picture}(15,15)(0,-4)
2608    \put(7.5,-0.2){\line(0,-1){2.8}}
2609    \put(4,2){\YOKOeg}
2610    \put(7.5, 7.2){\line(0,1){3.8}}
2611 %
2612    \put(2,7){\line(1,0){1.8}}
2613    \put(2,0){\line(1,0){1.8}}
2614    \put(3,5){\vector(0,1){2}}
2615    \put(3,2){\vector(0,-1){2}}
2616    \put(3,3.5){\makebox(0,0){$W_{\mathrm{T}}$}}
2617 %
2618    \put(4,7.2){\line(0,1){1.8}}
2619    \put(11,7.2){\line(0,1){1.8}}
2620    \put(8,8){\vector(-1,0){0.5}\vector(1,0){3}}
2621    \put(7,8){\vector(-1,0){3}\vector(1,0){0.5}}
2622    \put(9.25,8.2){\makebox(0,0)[b]{$H_{\mathrm{T}}$}}
2623    \put(5.75,8.2){\makebox(0,0)[b]{$D_{\mathrm{T}}$}}
2624 %
2625  \end{picture}\vspace{-\baselineskip}
2626    \begin{align*}
2627    W_{\mathrm{T}} &= h_{\mathrm{Y}}+d_{\mathrm{Y}},\\
2628    H_{\mathrm{T}} &= w_{\mathrm{Y}}/2,\\
2629    D_{\mathrm{T}} &= w_{\mathrm{Y}}/2
2630    \end{align*}%
2631  }&
2632  \parbox[c]{15\unitlength}{\begin{picture}(15,15)(0,-4)
2633    \put(11,-0.2){\line(0,-1){2.8}}
2634    \put(4,2){\YOKOeg}
2635    \put(11, 7.2){\line(0,1){3.8}}
2636 %
2637    \put(2,7){\line(1,0){1.8}}
2638    \put(2,0){\line(1,0){1.8}}
2639    \put(3,5){\vector(0,1){2}}
2640    \put(3,2){\vector(0,-1){2}}
2641    \put(3,3.5){\makebox(0,0){$W_{\mathrm{D}}$}}
2642 %
2643    \put(4,7.2){\line(0,1){1.8}}
2644    \put(11,7.2){\line(0,1){1.8}}
2645    \put(7.5,8){\vector(-1,0){3.5}\vector(1,0){3.5}}
2646    \put(13,8){\vector(-1,0){2}}
2647    \put(7.5,8.2){\makebox(0,0)[b]{$H_{\mathrm{D}}$}}
2648    \put(12,8.2){\makebox(0,0)[b]{$D_{\mathrm{D}}$}}
2649 %
2650  \end{picture}\vspace{-\baselineskip}
2651    \begin{align*}
2652    W_{\mathrm{D}} &= h_{\mathrm{Y}}+d_{\mathrm{Y}},\\
2653    H_{\mathrm{D}} &= w_{\mathrm{Y}},\\
2654    D_{\mathrm{D}} &= 0\,\mathrm{pt}
2655    \end{align*}%
2656  }%
2657 \\\midrule
2658  \parbox[c]{15\unitlength}{\begin{picture}(15,15)(0,-4)
2659    \put(0,0){\line(1,0){3.8}}
2660    \put(4,0){\DTOUeg}
2661    \put(11.2,0){\line(1,0){3.8}}
2662 %
2663    \put(2,7){\line(1,0){1.8}}
2664    \put(3,3.5){\vector(0,1){3.5}\vector(0,-1){3.5}}
2665    \put(2.8,3.5){\makebox(0,0)[r]{$H_{\mathrm{Y}}$}}
2666    \put(3,-2){\vector(0,1){2}}
2667    \put(2.8,-1){\makebox(0,0)[r]{$D_{\mathrm{Y}}$}}
2668 %
2669    \put(4,7.2){\line(0,1){1.8}}
2670    \put(11,7.2){\line(0,1){1.8}}
2671    \put(6,8){\vector(-1,0){2}}
2672    \put(9,8){\vector(1,0){2}}
2673    \put(7.5,8){\makebox(0,0){$W_{\mathrm{Y}}$}}
2674 %
2675  \end{picture}\vspace{-\baselineskip}
2676    \begin{align*}
2677    W_{\mathrm{Y}} &= h_{\mathrm{D}}+d_{\mathrm{D}},\\
2678    H_{\mathrm{Y}} &= w_{\mathrm{D}},\\
2679    D_{\mathrm{Y}} &= 0\,pt
2680    \end{align*}%
2681  }&
2682  \parbox[c]{15\unitlength}{\begin{picture}(15,15)(0,-4)
2683    \put(9,-0.2){\line(0,-1){2.8}}
2684    \put(4,0){\DTOUeg}
2685    \put(9, 7.2){\line(0,1){3.8}}
2686 %
2687    \put(2,7){\line(1,0){1.8}}
2688    \put(2,0){\line(1,0){1.8}}
2689    \put(3,5){\vector(0,1){2}}
2690    \put(3,2){\vector(0,-1){2}}
2691    \put(3,3.5){\makebox(0,0){$W_{\mathrm{T}}$}}
2692 %
2693    \put(4,7.2){\line(0,1){1.8}}
2694    \put(11,7.2){\line(0,1){1.8}}
2695    \put(6.5,8){\vector(-1,0){2.5}\vector(1,0){2.5}}
2696    \put(10,8){\vector(-1,0){1}\vector(1,0){1}}
2697    \put(10,8.2){\makebox(0,0)[b]{$H_{\mathrm{T}}$}}
2698    \put(6.5,8.2){\makebox(0,0)[b]{$D_{\mathrm{T}}$}}
2699 %
2700  \end{picture}\vspace{-\baselineskip}
2701    \begin{align*}
2702    W_{\mathrm{T}} &= h_{\mathrm{D}}+d_{\mathrm{D}},\\
2703    H_{\mathrm{T}} &= d_{\mathrm{D}},\\
2704    D_{\mathrm{T}} &= h_{\mathrm{D}}
2705    \end{align*}%
2706  }&
2707  \parbox[c]{15\unitlength}{\begin{picture}(15,15)(0,-4)
2708    \put(6,-0.2){\line(0,-1){2.8}}
2709    \put(4,7){\TATEeg}
2710    \put(6, 7.2){\line(0,1){3.8}}
2711 %
2712    \put(2,7){\line(1,0){1.8}}
2713    \put(2,0){\line(1,0){1.8}}
2714    \put(3,5){\vector(0,1){2}}
2715    \put(3,2){\vector(0,-1){2}}
2716    \put(3,3.5){\makebox(0,0){$W_{\mathrm{D}}$}}
2717 %
2718    \put(4,7.2){\line(0,1){1.8}}
2719    \put(11,7.2){\line(0,1){1.8}}
2720    \put(5,8){\vector(-1,0){1}\vector(1,0){1}}
2721    \put(8.5,8){\vector(-1,0){2.5}\vector(1,0){2.5}}
2722    \put(5,8.2){\makebox(0,0)[b]{$H_{\mathrm{D}}$}}
2723    \put(8.5,8.2){\makebox(0,0)[b]{$D_{\mathrm{D}}$}}
2724 %
2725  \end{picture}\vspace{-\baselineskip}
2726    \begin{align*}
2727    W_{\mathrm{D}} &= w_{\mathrm{T}},\\
2728    H_{\mathrm{D}} &= d_{\mathrm{T}},\\
2729    D_{\mathrm{D}} &= h_{\mathrm{T}}
2730    \end{align*}%
2731  }\\
2732 \bottomrule
2733 \end{tabular}
2734 \end{table}
2735
2736
2737 \paragraph{\texttt{\textbackslash wd} は組方向には対応しない}
2738 ボックスレジスタ \verb+\box+<num> にセットされているボックスの幅・高さ・深さの取得や
2739 変更にはそれぞれ \verb+\wd+,~\verb+\ht+,~\verb+\dp+ プリミティブを用いるのであった.
2740 \pTeX ではこれらのプリミティブは,「現在の組方向におけるボックスの寸法」を指すものであった.
2741
2742 \LuaTeX-jaにおいては状況が異なり,\verb+\wd+,~\verb+\ht+,~\verb+\dp+ は\emph{組方向が
2743 混在する状況においては正しく機能しない}.まず,現在の組方向に依存しないことが挙げられる.
2744 \begin{LTXexample}
2745 % yoko direction
2746 \setbox0=\hbox to 20pt{foo}
2747 \the\wd0,~\hbox{\tate\vrule\the\wd0}
2748 \wd0=100pt
2749 \the\wd0,~\hbox{\tate \the\wd0}
2750 \end{LTXexample}
2751 また,異方向のボックスの配置処理の関係で,
2752 \verb+\lastbox+ を駆使してボックスのコピーを
2753 作成した場合でも,\verb+\wd+ 等の値が異なる場合もある.
2754 例えば,下の実行例における \verb+\wd1+ の値は,「縦組で組んだ時の \verb+\box0+ の
2755 専有する幅」となる.
2756 \begin{LTXexample}
2757 % yoko direction
2758 \setbox0=\hbox to 20pt{Xy}
2759 \the\wd0,
2760 \setbox0=\hbox{\tate\copy0}
2761 \setbox0=\hbox{\tate\unhbox0
2762   \global\setbox1\lastbox}
2763 \the\wd1
2764 \end{LTXexample}
2765
2766 \paragraph{\texttt{\textbackslash wd} 等の代替命令}
2767
2768 \pTeX のように現在の組方向に応じたボックスの寸法の取得・設定を行うため,
2769 次の命令を新設した.
2770
2771 \begin{cslist}
2772
2773  \item[ltjgetwd\{<num>\}\textrm{, }\textbackslash ltjgetht\{<num>\}\textrm{, }%
2774   \textbackslash ltjgetdp\{<num>\}] 
2775 現在の組方向に応じたボックスの寸法の取得を行う.結果は内部長さであるため,
2776 {\let\item=\origitem
2777 \begin{verbatim}
2778 \dimexpr 2\ltjgetwd{42}-3pt\relax, \the\ltjgetwd{1701}
2779 \end{verbatim}
2780 のように \verb+\wd+<num> の代わりとして扱うことができる.引数が1桁の場合は,
2781 \verb+\ltjgetwd3+ のように引数をグループで括らなくても良いが,そうでない場合は
2782 (通常の命令への引数のように)\verb+\ltjgetwd{42}+ とグループに括る必要がある.
2783 使用例は以下の通りである.
2784 \begin{LTXexample}[width=0.3\textwidth]
2785 \parindent0pt
2786 \setbox32767=\hbox{\yoko よこぐみ}
2787 \fboxsep=0mm\fbox{\copy32767}
2788 \vbox{\hsize=20mm 
2789 \yoko YOKO \the\ltjgetwd{32767}, \\
2790   \the\ltjgetht{32767}, \\ \the\ltjgetdp{32767}.}
2791 \vbox{\hsize=20mm\raggedleft
2792 \tate TATE \the\ltjgetwd{32767}, \\
2793   \the\ltjgetht{32767}, \\ \the\ltjgetdp{32767}.}
2794 \vbox{\hsize=20mm\raggedleft
2795 \dtou DTOU \the\ltjgetwd{32767}, \\
2796   \the\ltjgetht{32767}, \\ \the\ltjgetdp{32767}.}
2797 \end{LTXexample}}
2798
2799  \item[ltjsetwd<num>=<dimen>\textrm{, }\textbackslash ltjsetht<num>=<dimen>\textrm{, }%
2800   \textbackslash ltjsetdp<num>=<dimen>]
2801 現在の組方向に応じたボックスの寸法の設定を行う.\verb+\afterassignment+ を2回利用して
2802 実装しているので,次の4通りは全て同じ意味である.
2803 {\let\item=\origitem
2804 \begin{verbatim}
2805 \ltjsetwd42 20pt,  \ltjsetwd42=20pt,  \ltjsetwd=42 20pt,  \ltjsetwd=42=20pt
2806 \end{verbatim}
2807 }%
2808
2809 設定値は組方向ごとに独立して記録される.
2810
2811 \end{cslist} 
2812
2813 \subsection{組方向の取得・条件判断}
2814 「現在の組方向」や「<num>番のボックスの組方向」は,以下の命令によって
2815 知ることができる.
2816
2817 \begin{cslist}
2818  \item[ifydir\textrm{, }\textbackslash iftdir\textrm{, }\textbackslash ifddir]
2819 現在の組方向が横組(\verb+\yoko+),縦組(\verb+\tate+),\verb+\dtou+ 方向であるかを
2820 それぞれ判定する.
2821
2822  \item[ifybox\{<num>\}\textrm{, }\textbackslash iftbox\{<num>\}\textrm{, }%
2823   \textbackslash ifdbox\{<num>\}]
2824 <num>番のレジスタの中身が横組ボックス,縦組ボックス,\verb+\dtou+ 方向の
2825 ボックスか否かをそれぞれ判定する.
2826
2827 \end{cslist}
2828
2829 %</ja>
2830
2831 %<en>\section{Font Metric and Japanese Font}
2832 %<ja>\section{フォントメトリックと和文フォント}
2833 %<en>\subsection{\texttt{\textbackslash jfont}}
2834 %<ja>\subsection{\texttt{\textbackslash jfont} 命令}
2835 \label{ssec-jfont}
2836
2837 %<*en>
2838 To load a font as a Japanese font (for horizontal direction), you must use the
2839 \verb+\jfont+ instead of~\verb+\font+, while
2840 \verb+\jfont+ admits the same syntax used in~\verb+\font+.
2841 \LuaTeX-ja automatically loads \Pkg{luaotfload} package,
2842 so TrueType/OpenType fonts with features can be used for Japanese fonts:
2843 %</en>
2844 %<*ja>
2845 フォントを(横組用)和文フォントとして読み込むためには,\verb+\jfont+ を
2846 \verb+\font+ プリミティブの代わりに用いる.
2847 \verb+\jfont+ の文法は \verb+\font+ と同じである.
2848 \LuaTeX-jaは\Pkg{luaotfload}パッケージを自動的に読み込むので,
2849 TrueType/OpenTypeフォントにfeatureを指定したものを和文フォントとして用いる
2850 ことができる:
2851 %</ja>
2852 \begin{LTXexample}[width=0.3\textwidth]
2853 \jfont\tradgt={file:KozMinPr6N-Regular.otf:script=latn;%
2854   +trad;-kern;jfm=ujis} at 14pt
2855 \tradgt 当/体/医/区
2856 \end{LTXexample}
2857
2858 %<*en>
2859 Note that the defined control sequence
2860 (\verb+\tradgt+ in the example above) using \verb+\jfont+ is not a
2861 \textit{font\_def} token,  but a macro.
2862 Hence the input like \verb+\fontname\tradgt+
2863 causes a error.  We denote control sequences which are defined in
2864 \verb+\jfont+ by <jfont\_cs>.
2865 %</en>
2866 %<*ja>
2867 なお,\verb+\jfont+ で定義された制御綴(上の例だと \verb+\tradgt+)
2868 は\textit{font\_def}トークンではなくマクロである.従って,\verb+\fontname\tradgt+ のような
2869 入力はエラーとなる.以下では \verb+\jfont+ で定義された
2870 制御綴を<jfont\_cs>で表す.
2871 %</ja>
2872
2873 \paragraph{JFM}
2874 %<*en>
2875 As noted in Introduction, a JFM has measurements of characters and
2876 glues/kerns that are automatically inserted for Japanese
2877 typesetting. The structure of JFM will be described in the next
2878 subsection. At the calling of \verb+\jfont+, you must specify
2879 which JFM will be used for this font by the following keys:
2880 %</en>
2881 %<*ja>
2882 「はじめに」の節で述べたように,JFMは文字と和文組版で自動的に挿入される
2883 グルー/カーンの寸法情報を持っている.JFMの構造は次の節で述べる.
2884 \verb+\jfont+ 命令の呼び出しの際には,どのJFMを用いるのかを以下のキーで
2885 指定する必要がある:
2886 %</ja>
2887
2888
2889 \begin{table}[t]
2890 %<en>\caption{Differences between JFMs shipped with \LuaTeX-ja}
2891 %<ja>\caption{\LuaTeX-ja に同梱されている JFM の違い}
2892 %<en>\medskip
2893 \label{tab-difjfm}
2894 \ltjsetparameter{jacharrange={+3}}
2895 \centering\small
2896 \def\r#1{{\jfont\g=file:KozMinPr6N-Regular.otf:jfm=#1 at 14.43324pt \g
2897 \setbox0=\vtop{\hsize=7\zw\noindent ◆◆◆◆◆◆◆
2898 ある日モモちゃんがお使いで迷子になって泣きました.}\copy0
2899 \vrule height 0pt depth \dp0}}
2900 \def\s#1{{\jfont\g=file:KozMinPr6N-Regular.otf:jfm=#1 at 14.43324pt \g
2901 \setbox0=\vtop{\hsize=7\zw\noindent ちょっと!何}\copy0}}
2902 \def\t#1{{\jfont\g=file:KozMinPr6N-Regular.otf:jfm=#1 at 19.24432pt \g
2903 \setbox0=\hbox{漢}%
2904 \vrule width 0.4pt height\ht0 depth\dp0\kern-.2pt\copy0
2905 \kern-\wd0\vrule width\wd0height .2pt depth .2pt
2906 \kern-\wd0\raise\ht0\hbox{\vrule width\wd0height .2pt depth .2pt}%
2907 \kern-\wd0\lower\dp0\hbox{\vrule width\wd0height .2pt depth .2pt}%
2908 \kern-.2pt\vrule width 0.4pt height\ht0 depth \dp0}}
2909 \begin{tabular}{rccc}
2910 \toprule
2911 &\tt jfm-ujis.lua&\tt jfm-jis.lua&\tt jfm-min.lua\\
2912 \midrule
2913 %<en>Example~1~\cite{min10}
2914 %<ja>例1~\cite{min10}
2915 &\r{ujis}&\r{jis}&\r{min}\\
2916 %<en>Example~2
2917 %<ja>例2
2918 &\s{ujis}&\s{jis}&\s{min}\\
2919 Bounding Box&\t{ujis}&\t{jis}&\t{min}\\
2920 \bottomrule
2921 \end{tabular}
2922 \ltjsetparameter{jacharrange={-3}}
2923 \end{table}
2924
2925
2926 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}\advance\leftmargin1\zw}
2927 \item[jfm=<name>]
2928 %<*en>
2929 Specify the name of (horizontal) JFM. 
2930 If specified JFM has not been loaded, \LuaTeX-ja search and load
2931 a file named \texttt{jfm-<name>.lua}.
2932
2933 The following JFMs are shipped with \LuaTeX-ja:
2934 %</en>
2935 %<*ja>
2936 用いる(横組用)JFMの名前を指定する.もし以前に指定されたJFMが読み込まれていなければ,
2937 \texttt{jfm-<name>.lua}を読み込む.以下の横組用JFMが\LuaTeX-jaには同梱されている:
2938 %</ja>
2939 \begin{description}
2940 %<*en>
2941 \item[\tt jfm-ujis.lua] A standard JFM in \LuaTeX-ja. This JFM is
2942   based on \verb+upnmlminr-h.tfm+, a metric for UTF/OTF package that
2943   is used in \upTeX. When you use the \Pkg{luatexja-otf} package, you should use this JFM.
2944 %</en>
2945 %<*ja>
2946 \item[\tt jfm-ujis.lua] \LuaTeX-jaの標準JFMである.このJFMは\upTeX で
2947   用いられるUTF/OTFパッケージ用の和文用TFMである \verb+upnmlminr-h.tfm+ を
2948   元にしている.\Pkg{luatexja-otf}パッケージを使うときはこのJFMを指定するべきである.
2949 %</ja>
2950 %<*en>
2951 \item[\tt jfm-jis.lua] A counterpart for \verb+jis.tfm+, ``JIS font
2952   metric'' which is widely used in \pTeX. A major difference between
2953   \texttt{jfm-ujis.lua} and this \texttt{jfm-jis.lua} is that
2954   most characters under \texttt{jfm-ujis.lua} are square-shaped,
2955   while that under \texttt{jfm-jis.lua} are horizontal
2956   rectangles.
2957 %</en>
2958 %<*ja>
2959 \item[\tt jfm-jis.lua] \pTeX で広く用いられている「JISフォントメトリック」
2960   \verb+jis.tfm+ に相当するJFMである.\texttt{jfm-ujis.lua} とこの
2961   \texttt{jfm-jis.lua} の主な違いは,\texttt{jfm-ujis.lua} ではほとんどの文字が
2962   正方形状であるのに対し,\texttt{jfm-jis.lua} では横長の長方形状であることと,
2963   \texttt{jfm-ujis.lua} では「?」「!」の直後に半角空白が挿入されることである.
2964 %</ja>
2965 %<*en>
2966 \item[\tt jfm-min.lua] A counterpart for \verb+min10.tfm+, which is one
2967   of the default Japanese font metric shipped with \pTeX. 
2968 %</en>
2969 %<*ja> 
2970 \item[\tt jfm-min.lua] \pTeX に同梱されているデフォルトの和文用TFM
2971   である \verb+min10.tfm+ に相当する.
2972 %</ja>
2973 \end{description}
2974 %<*en>
2975 The difference among these three~JFMs is  shown in Table~\ref{tab-difjfm}.
2976 %</en>
2977 %<*ja>
2978 これら3つのJFMの違いは表\ref{tab-difjfm}に示した.
2979 %</ja>
2980
2981 \begin{figure}
2982 \begin{LTXexample}[width=0.3\textwidth]
2983 \ltjsetparameter{differentjfm=both}
2984 \jfont\F=file:KozMinPr6N-Regular.otf:jfm=ujis
2985 \jfont\G=file:KozGoPr6N-Medium.otf:jfm=ujis
2986 \jfont\H=file:KozGoPr6N-Medium.otf:jfm=ujis;jfmvar=hoge
2987 \F ){\G 【】}( % halfwidth space
2988    ){\H 『』}( % fullwidth space
2989
2990 ほげ,{\G 「ほげ」}(ほげ)\par
2991 ほげ,{\H 「ほげ」}(ほげ)% pTeX-like
2992
2993 \ltjsetparameter{differentjfm=paverage}
2994 \end{LTXexample}
2995 \caption{Example of \texttt{jfmvar} key}
2996 \label{fig:jfmvar}
2997 \end{figure}
2998
2999 %<*en>
3000 \item[jfmvar=<string>] Sometimes there is a need that \ldots.
3001 %</en>
3002 %<*ja>
3003 \item[jfmvar=<string>] 標準では,JFMとサイズが同じで,
3004   実フォントだけが異なる2つの和文フォントは「区別されない」.例えば
3005 図\ref{fig:jfmvar}において,最初の「)」と「【」の実フォントは異なるが,
3006 JFMもサイズも同じなので,普通に「)【」と入力した時と同じように半角空きとなる.
3007
3008 しかし,JFMとサイズが同じであっても,\texttt{jfmvar} キーの異なる
3009 2つの和文フォント,例えば図\ref{fig:jfmvar}で言う \verb+\F+ と \verb+\H+,
3010 は「区別される」.異なる和文フォントに異なる \texttt{jfmvar} キーを割り当て,
3011 かつ\Param{differentjfm}パラメータを \texttt{both} に設定すれば,
3012 \pTeX と似た状況で組版されることになる.
3013 %</ja>
3014 \end{list}
3015
3016 \begin{figure}
3017 \begin{LTXexample}[pos=t]
3018 \newcommand\test{\vrule ダイナミックダイクマ\vrule\\}
3019 \jfont\KMFW = KozMinPr6N-Regular:jfm=prop;-kern at 17pt
3020 \jfont\KMFK = KozMinPr6N-Regular:jfm=prop at 17pt % kern is activated
3021 \jfont\KMPW = KozMinPr6N-Regular:jfm=prop;script=dflt;+pwid;-kern at 17pt
3022 \jfont\KMPK = KozMinPr6N-Regular:jfm=prop;script=dflt;+pwid;+kern at 17pt
3023 \begin{multicols}{2}
3024 \ltjsetparameter{kanjiskip=0pt}
3025 {\KMFW\test \KMFK\test \KMPW\test \KMPK\test}
3026
3027 \ltjsetparameter{kanjiskip=3pt}
3028 {\KMFW\test \KMFK\test \KMPW\test \KMPK\test}
3029 \end{multicols}
3030 \end{LTXexample}
3031 \caption{Kerning information and \Param{kanjiskip}}
3032 \label{fig:kern-jfm}
3033 \end{figure}
3034
3035 %<en>\paragraph{Using kerning information in a font}
3036 %<ja>\paragraph{ペアカーニング情報の使用}
3037 \label{para-kern}
3038 %<*en>
3039 Some fonts have information for inter-glyph spacing. 
3040 This version of \LuaTeX-ja treats kerning spaces like an italic correction;
3041 any glue and/or kern from the JFM and a kerning space can coexist.
3042 See Figure~\ref{fig:kern-jfm} for detail.
3043
3044 Note that in \verb+\setmainjfont+ etc.\ which are provided by \Pkg{luatexja-fontspec}
3045 package, kerning option is set \emph{off} (\texttt{Kerning=Off}) by default,
3046 because of the compatibility with previous versions of \LuaTeX-ja.
3047 %</en>
3048 %<*ja>
3049 いくつかのフォントはグリフ間のスペースについての情報を持っている.
3050 このカーニング情報は以前の\LuaTeX-ja とはあまり相性が良くなかったが,
3051 本バージョンではカーニングによる空白はイタリック補正と同様に扱うことになっている.
3052 つまり,カーニング由来の空白とJFM由来のグルー・カーンは同時に入りうる.
3053 図\ref{fig:kern-jfm}を参照.
3054 \begin{itemize}
3055  \item \emph{\texttt{\textbackslash jfont} や,
3056 NFSS2用の命令(\ref{ssec-chgfnt}節,\ref{ssec-nfsspat}節)における指定では
3057 カーニング情報は標準で使用する}ことになっているようである.
3058 言い換えれば,カーニング情報を使用しない設定にするには,面倒でも
3059 \begin{verbatim}
3060 \jfont\hoge=KozMinPr6N-Regular:jfm=ujis;-kern at 3.5mm
3061 \DeclareFontShape{JY3}{fuga}{m}{n} {<-> s*KozMinPr6N-Regular:jfm=ujis;-kern}{}
3062 \end{verbatim}
3063 のように,\texttt{-kern} という指定を自分で追架しなければいけない.
3064  \item 
3065 一方,\emph{\Pkg{luatexja-fontspec} の提供する \texttt{\textbackslash setmainjfont}\ 
3066 などの命令の標準設定ではカーニング情報は使用しない}(\texttt{Kerning=Off})
3067 ことになっている.これは以前のバージョンの\LuaTeX-jaとの互換性のためである.
3068 \end{itemize}
3069 %</ja>
3070
3071 %<*ja>
3072 \paragraph{\texttt{extend}と\texttt{slant}}
3073 OpenType font featureと見かけ上同じような形式で指定できるものに,
3074 \begin{description}
3075 \item[\texttt{extend=}<extend>] 横方向に<extend>倍拡大する.
3076 \item[\texttt{slant=}<slant>] <slant>に指定された割合だけ傾ける.
3077 \end{description}  
3078 の2つがある.
3079 \texttt{extend}や\texttt{slant}を指定した場合は,それに応じたJFMを指定すべきである%
3080 \footnote{\LuaTeX-jaでは,これらに対するJFMを特に提供することはしない予定である.}.
3081 例えば,次の例では無理やり通常のJFMを使っているために,文字間隔やイタリック補正量が
3082 正しくない:
3083 %</ja>
3084 %<*en>
3085 \paragraph{\texttt{extend} and \texttt{slant}}
3086 The following setting can be specified as OpenType font features:
3087 \begin{description}
3088 \item[\texttt{extend=}<extend>] expand the font horizontally by <extend>.
3089 \item[\texttt{slant=}<slant>] slant the font.
3090 \end{description}
3091 Note that \LuaTeX-ja doesn't adjust JFMs by these \texttt{extend} and \texttt{slant}
3092 settings; you have to write new JFMs on purpose. 
3093 For example, the following example uses the standard JFM \texttt{jfm-ujis.lua}, hence
3094 letter-spacing and the width of italic correction are not correct:
3095 %</en>
3096 \begin{LTXexample}[width=0.3\textwidth]
3097 \jfont\E=file:KozMinPr6N-Regular.otf:extend=1.5;jfm=ujis;-kern
3098 \E あいうえお
3099
3100 \jfont\S=file:KozMinPr6N-Regular.otf:slant=1;jfm=ujis;-kern
3101 \S あいう\/ABC
3102 \end{LTXexample}
3103
3104 %<en>\subsection{\texttt{\textbackslash tfont}}
3105 %<ja>\subsection{\texttt{\textbackslash tfont} 命令}
3106
3107 %<*en>
3108 ...
3109 %</en>
3110 %<*ja>
3111 \verb+\tfont+ はフォントを縦組用の和文フォントとして読み込む命令であり,
3112 \verb+\jfont+ の文法は \verb+\jfont+ と同じである.
3113 \verb+\tfont+ で定義された縦組用和文フォントは,
3114 以下の点が \verb+\jfont+ による横組用和文フォントとは異なる:
3115 \begin{itemize}
3116  \item 出力時に,自動的に「\verb+vert+ feature相当」のグリフ置換が行われる.
3117        これは,\Pkg{luaotfload}による各種featureのサポートとは全く別個に行われるもので,
3118        いちいち \verb+vert+ featureを指定する必要はない.
3119 \begin{verbatim}
3120 \tfont\S=file:KozMinPr6N-Regular.otf:jfm=ujis % OK
3121 \end{verbatim}
3122  \item \ref{ssec-math}節で述べる,数式中の和文フォントには縦組用和文フォントは指定できない.
3123  \item \texttt{jfm=<name>}\ の部分には縦組用JFMを指定する.現在同梱されているのは,
3124 OTFパッケージの \verb+upnmlminr-v.tfm+ を元にした\texttt{jfm-ujisv.lua}\ のみである.
3125 \end{itemize}
3126 %</ja>
3127
3128 %<en>\subsection{Prefix \texttt{psft}}
3129 %<ja>\subsection{\texttt{psft}プリフィックス}
3130 \label{ssec-psft}
3131 %<*en>
3132 Besides ``\texttt{file:}''\ and ``\texttt{name:}''\ prefixes which
3133 are introduced in the \Pkg{luaotfload} package, 
3134 \LuaTeX-ja adds ``\texttt{psft:}''\ prefix in \verb+\jfont+ (and~\verb+\font+),
3135 to specify a ``name-only'' Japanese font which
3136 will not be embedded to PDF. Typical use of this prefix is to specify
3137 standard, non-embedded Japanese fonts, namely, ``Ryumin-Light'' and
3138 ``GothicBBB-Medium''.
3139
3140 \emph{OpenType font features, such as ``{\tt +jp90}'', 
3141 have no meaning in name-only fonts using ``{\tt psft:}''\ prefix,
3142 because we can't expect what fonts are actually used by the PDF reader.}
3143 Note that \texttt{extend}~and~\texttt{slant} settings (see~above) are supported
3144 with \texttt{psft} prefix, because they are only simple linear transformations.
3145 %</en>
3146 %<*ja>
3147 \Pkg{luaotfload}で使用可能になった
3148 \texttt{file:}\ と \texttt{name:}\ のプリフィックスに加えて,
3149 \verb+\jfont+(と \verb+\font+ プリミティブ)では
3150 \texttt{psft:}プリフィックスを用いることができる.
3151 このプリフィックスを用いることで,PDFには埋め込まれない「名前だけの」
3152 和文フォントを指定することができる.「標準的な」非埋め込み和文フォント,
3153 つまり「Ryumin-Light」「GothicBBB-Medium」の指定でこのプリフィックスが使われる.
3154
3155 \emph{\texttt{psft} プリフィックスの下では
3156 \texttt{+jp90} などのOpenType font featureの効力はない.
3157 非埋込フォントをPDFに使用すると,実際にどのようなフォントが
3158 表示に用いられるか予測できないからである.}\
3159 \texttt{extend} と \texttt{slant} 指定は単なる変形のため
3160 \texttt{psft} プリフィックスでも使用可能である.
3161 %</ja>
3162
3163 %<en>\paragraph{\texttt{cid} key}
3164 %<ja>\paragraph{\texttt{cid}キー}
3165 \label{para-cid}
3166
3167 %<*en>
3168 The default font defined by using \texttt{psft:} prefix is for Japanese typesetting;
3169 it is Adobe-Japan1-6 CID-keyed font.
3170 One can specify \texttt{cid} key to use other CID-keyed non-embedded fonts
3171 for Chinese or Korean typesetting.
3172 %</en>
3173 %<*ja>
3174 標準で\texttt{psft:}プリフィックスで定義されるフォントは日本語用のもので
3175 あり,Adobe-Japan1-6のCIDに対応したものとなる.しかし,\LuaTeX-jaは中国語
3176 の組版にも威力を発揮することが分かり,日本語フォントでない非埋込フォント
3177 の対応も必要となった.そのために追加されたのが\texttt{cid}キーである.
3178
3179 \texttt{cid}キーに値を指定すると,そのCIDを持った非埋込フォントを定義することができる:
3180 %</ja>
3181 \begin{lstlisting}[numbers=left]
3182 \jfont\testJ={psft:Ryumin-Light:cid=Adobe-Japan1-6;jfm=jis}     % Japanese
3183 \jfont\testD={psft:Ryumin-Light:jfm=jis}                        % default value is Adobe-Japan1-6
3184 \jfont\testC={psft:AdobeMingStd-Light:cid=Adobe-CNS1-6;jfm=jis} % Traditional Chinese
3185 \jfont\testG={psft:SimSun:cid=Adobe-GB1-5;jfm=jis}              % Simplified Chinese
3186 \jfont\testK={psft:Batang:cid=Adobe-Korea1-2;jfm=jis}           % Korean
3187 \end{lstlisting}
3188 %<*en>
3189 Note that the code above specifies \texttt{jfm-jis.lua}, which is for Japanese fonts,
3190 as JFM for Chinese and Korean fonts.
3191 %</en>
3192 %<*ja>
3193 上のコードでは中国語・韓国語用フォントに対してもJFMに
3194 日本語用の\texttt{jfm-jis.lua}を指定しているので注意されたい.
3195 %</ja>
3196
3197 %<*en>
3198 At present, \LuaTeX-ja supports only 4 values written in the sample code above.
3199 Specifying other values, e.g.,
3200 %</en>
3201 %<*ja>
3202 今のところ,\LuaTeX-jaは上のサンプルコード中に書いた4つの値しかサポートしていない.
3203 %</ja>
3204 \begin{lstlisting}
3205 \jfont\test={psft:Ryumin-Light:cid=Adobe-Japan2;jfm=jis}
3206 \end{lstlisting}
3207 %<*en>
3208 produces the following error:
3209 %</en>
3210 %<*ja>
3211 のようにそれら以外の値を指定すると,エラーが発生する:
3212 %</ja>
3213 \begin{lstlisting}[numbers=left]
3214 ! Package luatexja Error: bad cid key `Adobe-Japan2'.
3215
3216 See the luatexja package documentation for explanation.
3217 Type  H <return>  for immediate help.
3218 <to be read again>
3219                    \par
3220 l.78
3221
3222 ? h
3223 I couldn't find any non-embedded font information for the CID
3224 `Adobe-Japan2'. For now, I'll use `Adobe-Japan1-6'.
3225 Please contact the LuaTeX-ja project team.
3226 ?
3227 \end{lstlisting}
3228
3229 %<en>\subsection{Structure of a JFM File}
3230 %<ja>\subsection{JFMファイルの構造}
3231 \label{ssec-jfm-str}
3232 %<en>A JFM file is a Lua script which has only one function call:
3233 %<ja>JFMファイルはただ一つの関数呼び出しを含むLuaスクリプトである:
3234 \begin{verbatim}
3235 luatexja.jfont.define_jfm { ... }
3236 \end{verbatim}
3237 %<*en>
3238 Real data are stored in the table which indicated above by
3239 \verb+{ ... }+.  So, the rest of this subsection are devoted to describe the
3240 structure of this table.  Note that all lengths in a JFM file are
3241 floating-point numbers in design-size unit.
3242 %</en>
3243 %<*ja>
3244 実際のデータは上で \verb+{ ... }+ で示されたテーブルの中に格納されている.
3245 以下ではこのテーブルの構造について記す.
3246 なお,JFMファイル中の長さは全てdesign-sizeを単位とする浮動小数点数であることに
3247 注意する.
3248 %</ja>
3249
3250 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}\advance\leftmargin1\zw}
3251
3252 \item[dir=<direction>]
3253 %<en>(required)
3254 %<ja>(必須)
3255
3256 %<*en>
3257 The direction of JFM. \texttt{'yoko'}~(horizontal)
3258 or \texttt{'tate'}~(vertical) are supported.
3259 %</en>
3260 %<*ja>
3261 JFMの書字方向.\texttt{'yoko'}(横組)と \texttt{'tate'}(縦組)がサポートされる.
3262 %</ja>
3263
3264 \item[zw=<length>]
3265 %<en>(required)
3266 %<ja>(必須)
3267
3268 %<en>The amount of the length of the ``full-width''.
3269 %<ja>「全角幅」の長さ.
3270
3271 \item[zh=<length>]
3272 %<en>(required)
3273 %<ja>(必須)
3274
3275 %<en>The amount of the ``full-height'' (height + depth). 
3276 %<ja>「全角高さ」(height + depth)の長さ.通常は全角幅と同じ長さになるだろう.
3277
3278 \item[kanjiskip=\{<natural>, <stretch>, <shrink>\}]
3279 %<en>(optional)
3280 %<ja>(任意)
3281
3282 %<*en>
3283 This field specifies the ``ideal'' amount of \Param{\hyperlink{fld:kanjiskip}{kanjiskip}}. As noted
3284              in Subsection~\ref{subs-kskip}, if the parameter
3285              \Param{\hyperlink{fld:kanjiskip}{kanjiskip}} is \verb+\maxdimen+, the value specified
3286              in this field is actually used (if this field is not specified in
3287              JFM, it is regarded as 0\,pt). Note that <stretch> and <shrink>
3288              fields are in design-size unit too.
3289 %</en>
3290 %<*ja>
3291 理想的な\Param{\hyperlink{fld:kanjiskip}{kanjiskip}}の量を指定する.\ref{subs-kskip}節で述べたように,
3292 もし\Param{\hyperlink{fld:kanjiskip}{kanjiskip}}が \verb+\maxdimen+ の値ならば,このフィールドで指定された
3293 値が実際には用いられる(指定なしは0\,ptとして扱われる).<stretch>と<shrink>のフィールドもdesign-size
3294 が単位であることに注意せよ.
3295 %</ja>
3296
3297 \item[xkanjiskip=\{<natural>, <stretch>, <shrink>\}]
3298 %<en>(optional)
3299 %<ja>(任意)
3300
3301 %<*en>
3302 Like the \texttt{kanjiskip} field, this field specifies the ``ideal''
3303              amount of \Param{\hyperlink{fld:xks}{xkanjiskip}}.
3304 %</en>
3305 %<*ja>
3306 \texttt{kanjiskip}フィールドと同様に,\Param{\hyperlink{fld:xks}{xkanjiskip}}の理想的な量を
3307 指定する.
3308 %</ja>
3309 \end{list}
3310
3311 %<*en>
3312 \paragraph{Character classes}
3313 Besides from above fields, a JFM file have several sub-tables those
3314 indices are natural numbers.  The table indexed by~$i\in\omega$ stores
3315 information of \emph{character class}~$i$. At least, the character class~0 is
3316 always present, so each JFM file must have a sub-table whose index is
3317 \texttt{[0]}.  Each sub-table (its numerical index is denoted by $i$) has
3318 the following fields:
3319 %</en>
3320 %<*ja>
3321 \paragraph{文字クラス}
3322 上記のフィールドに加えて,JFMファイルはそのインデックスが自然数であるいくつかの
3323 サブテーブルを持つ.インデックスが$i\in\omega$であるテーブルは\emph{文字クラス}$i$の
3324 情報を格納する.少なくとも,文字クラス0は常に存在するので,JFMファイルはインデックス
3325 が\texttt{[0]}のサブテーブルを持たなければならない.それぞれのサブテーブル
3326 (そのインデックスを$i$で表わす)は以下のフィールドを持つ:
3327 %</ja>
3328
3329 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}\advance\leftmargin1\zw}
3330 \item[chars=\{<character>, ...\}]
3331 %<en>(required except character class~0)
3332 %<ja>(文字クラス0を除いて必須)
3333
3334 %<*en>
3335 This field is a list of characters which are in this character
3336              type~$i$. This field is optional if $i=0$, since all
3337              \textbf{JAchar} which do not belong  any character classes other
3338              than 0 are in the character class 0
3339              (hence, the character class~0 contains most of
3340              \textbf{JAchar}s). In the list, character(s) can be specified in the following form:
3341 \begin{itemize}
3342 \item a Unicode code point
3343 \item the character itself (as a Lua string, like \hbox{\ltjsetparameter{autoxspacing=false}\verb+'あ'+})
3344 \item a string like \hbox{\ltjsetparameter{autoxspacing=false}\verb+'あ*'+} (the character followed by an asterisk)
3345 \item several ``imaginary'' characters (We will describe these later.)
3346 \end{itemize}
3347 %</en>
3348 %<*ja>
3349 このフィールドは文字クラス$i$に属する文字のリストである.このフィールドは$i=0$の
3350 場合には任意である(文字クラス0には,0以外の文字クラスに属するものを
3351 除いた全ての\textbf{JAchar}が属するから).このリスト中で文字を指定するには,以下の方法がある:
3352 \begin{itemize}
3353 \item Unicode におけるコード番号
3354 \item 「\hbox{\ltjsetparameter{autoxspacing=false}\verb+'あ'+}」のような,文字それ自体
3355 \item 「\hbox{\ltjsetparameter{autoxspacing=false}\verb+'あ*'+}」のような,文字それ自体の後にアスタリスクをつけたもの
3356 \item いくつかの「仮想的な文字」(後に説明する)
3357 \end{itemize}
3358 %</ja>
3359
3360 \item[width=<length>, height=<length>, depth=<length>, italic=<length>]
3361 %<en>(required)
3362 %<ja>(必須)
3363
3364 %<*en>
3365 Specifythe width of characters in character class~$i$, the height, the depth and
3366 the amount of italic correction. All characters in character class~$i$ are regarded that its width, height, and depth are
3367 as values of these fields.
3368
3369 But there is one exception: \texttt{width} field can be \texttt{'prop'}. 
3370 This means that width of a character becomes that of its ``real'' glyph.
3371 %</en>
3372 %<*ja>
3373 文字クラス$i$に属する文字の幅,高さ,深さ,イタリック補正の量を指定する.
3374 文字クラス$i$に属する全ての文字は,その幅,高さ,深さがこのフィールドで指定した
3375 値であるものとして扱われる.
3376
3377 例外として,\emph{\texttt{width} フィールドには数値以外に \texttt{'prop'} が指定可能である}.
3378 この場合,文字の幅はその「実際の」グリフの幅となる.OpenTypeの \texttt{prop} featureと併用
3379              すれば,これによってプロポーショナル組を行うことができる.
3380 %</ja>
3381
3382 \item[left=<length>, down=<length>, align=<align>]\
3383
3384 %<*en>
3385 These fields are for adjusting the position of the ``real'' glyph. Legal
3386              values of \texttt{align} field are \texttt{'left'},
3387              \texttt{'middle'}, and \texttt{'right'}. If one of these
3388              3~fields are omitted, \texttt{left} and \texttt{down} are
3389              treated as~0, and \texttt{align} field is treated as
3390              \texttt{'left'}.
3391 The effects of these 3~fields are indicated in Figure~\ref{fig-pos}.
3392 %</en>
3393 %<*ja>
3394 これらのフィールドは実際のグリフの位置を調整するためにある.
3395 \texttt{align} フィールドに指定できる値は \texttt{'left'}, \texttt{'middle'},
3396 \texttt{'right'} のいずれかである.もしこれら3つのフィールドのうちの1つが省かれた
3397 場合,\texttt{left} と \texttt{down} は0,\texttt{align} フィールドは
3398 \ \texttt{'left'} であるものとして扱われる.
3399 これら3つのフィールドの意味については図\ref{fig-pos}で説明する.
3400 %</ja>
3401
3402 %<*en>
3403 In most cases, \texttt{left} and \texttt{down} fields are~0, while
3404 it is not uncommon that the \texttt{align} field is \texttt{'middle'} or \texttt{'right'}.
3405 For example, setting the \texttt{align} field to \texttt{'right'} is practically needed
3406 when the current character class is the class for opening delimiters'.
3407 %</en>
3408 %<*ja>
3409 多くの場合,\texttt{left}と\texttt{down}は0である一方,
3410 \texttt{align}フィールドが\texttt{'middle'}や\texttt{'right'}であることは
3411 珍しいことではない.
3412 例えば,\texttt{align}フィールドを\texttt{'right'}に指定することは,
3413 文字クラスが開き括弧類であるときに実際必要である.
3414 %</ja>
3415
3416 \begin{figure}[!tb]
3417 \begin{minipage}{0.4\textwidth}%
3418 \begin{center}\unitlength=10pt\small
3419 \begin{picture}(15,12)(-1,-4)
3420 \color{black!10!white}% real glyph :step1
3421 \put(0,0){\vrule width 12\unitlength height 8\unitlength depth 3\unitlength}
3422
3423 \color{red!20!white}% real glyph :step1
3424 \put(-1,-1.5){\vrule width 6\unitlength height 7\unitlength depth 2.5\unitlength}
3425
3426 \color{red}% real glyph
3427 \thicklines
3428 \put(-1,-1.5){\vector(0,1){7}\vector(0,-1){2.5}\vector(1,0){6}}
3429 \put(5,-1.5){\line(0,1){7}\line(0,-1){2.5}}
3430 \put(-1,5.5){\line(1,0){6}}
3431 \put(-1,-4){\line(1,0){6}}
3432
3433 \color{green!20!white}% real glyph :step1
3434 \put(3,0){\vrule width 6\unitlength height 7\unitlength depth 2.5\unitlength}
3435
3436 \color{black}% real glyph :step1
3437 \thicklines
3438 \put(0,0){\vector(0,1){8}\line(0,-1){3}\vector(1,0){12}}
3439 \put(12,0){\line(0,1){8}\vector(0,-1){3}}
3440 \put(0,8){\line(1,0){12}}
3441 \put(0,-3){\line(1,0){12}}
3442 \put(0.2,4){\makebox(0,0)[l]{\texttt{height}}}
3443 \put(12.2,-1.5){\makebox(0,0)[l]{\texttt{depth}}}
3444 \put(6,0.2){\makebox(0,0)[b]{\texttt{width}}}
3445
3446 \color{green!50!black}% real glyph :step1
3447 \thicklines
3448 \put(3,0){\vector(0,1){7}\vector(0,-1){2.5}\vector(1,0){6}}
3449 \put(9,0){\line(0,1){7}\line(0,-1){2.5}}
3450 \put(3,7){\line(1,0){6}}
3451 \put(3,-2.5){\line(1,0){6}}
3452 \newsavebox{\eqdist}
3453 \savebox{\eqdist}(0,0)[b]{%
3454   \thinlines
3455   \put(-0.08,0.2){\line(0,-1){0.4}}%
3456   \put(0.08,0.2){\line(0,-1){0.4}}}
3457 \put(1.5,0){\usebox{\eqdist}}
3458 \put(10.5,0){\usebox{\eqdist}}
3459
3460 \color{blue}% shifted
3461 \thicklines
3462 \put(3,-1.5){\vector(-1,0){4}}
3463 \put(1,-1.7){\makebox(0,0)[t]{\texttt{left}}}
3464 \put(3,0){\vector(0,-1){1.5}}
3465 \put(3.2,-0.75){\makebox(0,0)[l]{\texttt{down}}}
3466 \end{picture}
3467 \end{center}
3468 \end{minipage}%
3469 \begin{minipage}{0.6\textwidth}%
3470 %<*en>
3471 Consider a node containing Japanese character whose value of the \texttt{align}
3472 field is \texttt{'middle'}.
3473 %</en>
3474 %<*ja>
3475 \texttt{align}フィールドの値が\texttt{'middle'}である和文文字を含むノードを
3476 考えよう.
3477 %</ja>
3478 \begin{itemize}
3479 \item
3480 %<*en>
3481 The black rectangle is a frame of the node.
3482 Its width, height, and depth are specified by JFM.
3483 %</en>
3484 %<*ja>
3485 黒色の長方形はノードの枠である.
3486 その幅,高さ,深さはJFMによって指定される.
3487 %</ja>
3488 \item
3489 %<*en>
3490 Since the \texttt{align} field is \texttt{'middle'},
3491 the ``real'' glyph is centered horizontally (the green rectangle).
3492 %</en>
3493 %<*ja>
3494 \texttt{align}フィールドは\texttt{middle}なので,実際のグリフは
3495 水平方向の中心に配置される(緑色の長方形).
3496 %</ja>
3497 \item
3498 %<*en>
3499 Furthermore, the glyph is shifted according to values of fields
3500       \texttt{left} and \texttt{down}. The ultimate position of the real
3501       glyph is indicated by the red rectangle.
3502 %</en>
3503 %<*ja>
3504 さらに,グリフは\texttt{left}と\texttt{down}の値に従ってシフトされる.
3505 最終的な実際のグリフの位置は赤色の長方形で示された位置になる.
3506 %</ja>
3507 \end{itemize}
3508 \end{minipage}
3509 \medskip
3510
3511 \caption{%
3512 %<en>The position of the real glyph
3513 %<ja>「実際の」グリフの位置
3514 }
3515 \label{fig-pos}
3516 \end{figure}
3517
3518 \item[kern={\{[$j$]=<kern>, [$j'$]=\{<kern>, [<ratio>]\}, ...\}}]
3519
3520 \item[glue={\{[$j$]=\{<width>, <stretch>, <shrink>, [<priority>], [<ratio>]\}, ...\}}]
3521 %<*ja>
3522 文字クラス$i$の文字と$j$の文字の間に挿入されるkernやglueの量を指定する.
3523
3524              <priority>は \Pkg{luatexja-adjust} による優先順位付き
3525              行長調整(\ref{ssec-adj}節)が有効なときのみ意味を持つ.
3526 このフィールドは省略可能であり,行調整処理におけるこのglueの優先
3527              度を$-2$から$+2$の間の整数で指定する.大きい値ほど「伸びやすく,縮みやすい」
3528              ことを意味する.省略時の値
3529              は0であり,範囲外の値が指定されたときの動作は未定義である.
3530
3531 <ratio>も省略可能フィールドであり,$-1$から$+1$の実数値をとる.省略時の値は0である.
3532 \begin{itemize}
3533 \item $-1$はこのグルーが「前の文字」由来であることを示す.
3534 \item $+1$はこのグルーが「後の文字」由来であることを示す.
3535 \item それ以外の値は,「前の文字」由来のグルーと「後の文字」由来の
3536 グルーが混合されていることを示す.
3537 \end{itemize}
3538 なお,このフィールドの値は\Param{\hyperlink{fld:diffjfm}{differentjfm}}の値が
3539 \texttt{pleft},~\texttt{pright},~\texttt{paverage}の値のときのみ実際に用いられる.
3540
3541 例えば,\cite{x4051}では,句点と中点の間には,
3542 句点由来の二分空きと中点由来の四分空きが挿入されるが,この場合には
3543 \begin{itemize}
3544 \item <width>には$0.5+0.25=0.75$を指定する.
3545 \item <ratio>には次の値を指定する.
3546 \[
3547  -1\cdot \frac{0.5}{0.5+0.25} + 1 \cdot \frac{0.25}{0.5+0.25} = -\frac13
3548 \]
3549 \end{itemize}
3550 %</ja>
3551 %<*en>
3552
3553
3554 Specifies the width of kern or glue which will be inserted 
3555 between characters in character class~$i$ and those in character class~$j$.
3556
3557 <priority> is an integer in $[-2,2]$ (treated as 0 if omitted), and this is
3558 used only in line adjustment with priority by \Pkg{luatexja-adjust}
3559 (see Subsection~\ref{ssec-adj}). Higher value means the glue is easy to shretch,
3560 and is also easy to shrink.
3561
3562 <ratio> is also an optional value between $-1$ and 1. For example,
3563 Thw width of a glue between an ideographic full stop ``。''
3564 and a fullwidth middle dot ``・'' is three-fourth of fullwidth,
3565 namely halfwidth from the ideographic full stop, and
3566 quarter-width from the fullwidth middle dot.  In this case,
3567 we specify <ratio> to
3568 \[
3569   -1\cdot \frac{0.5}{0.5+0.25} + 1 \cdot \frac{0.25}{0.5+0.25} = -\frac13.
3570 \]
3571 %</en>
3572
3573
3574 \item[end\_stretch=<kern>]
3575 \item[end\_shrink=<kern>]
3576 %<*ja>
3577 これらのフィールドは省略可能である.
3578 優先順位付き行長調整が有効であり,かつ現在の文字クラスの文字が行
3579              末に来た時に,行長を詰める調整・伸ばす調整のた
3580              めにこの文字と行末の間に挿入可能なカーンの大きさを指定する.
3581 %</ja>
3582
3583 \end{list}
3584
3585 %<*ja>
3586 \paragraph{文字クラスの決定}
3587 文字からその文字の属する文字クラスを算出する過程は少々複雑である.
3588 次の内容を一部に含んだ \texttt{jfm-test.lua} を用いて説明する.
3589 %</ja>
3590 %<*en>
3591 \paragraph{Character to character classes}
3592 We explain how the character class of a character is determined,
3593 using  \texttt{jfm-test.lua} which contains the following:
3594 %</en>
3595 \begin{lstlisting}
3596    [0] = {
3597       chars = { '漢', 'ヒ*' },
3598       align = 'left', left = 0.0, down = 0.0,
3599       width = 1.0, height = 0.88, depth = 0.12, italic=0.0,
3600    },
3601    [2000] = {
3602       chars = { '。', '、*', 'ヒ' },
3603       align = 'left', left = 0.0, down = 0.0,
3604       width = 0.5, height = 0.88, depth = 0.12, italic=0.0,
3605    },
3606 \end{lstlisting}
3607 %<ja>句点「。」の幅は二分であるので
3608 %<en>Now consider the following input/output:
3609 \begin{LTXexample}[width=0.3\textwidth]
3610 \jfont\a=file:KozMinPr6N-Regular.otf:jfm=test;+vert
3611 \setbox0\hbox{\a 。\inhibitglue 漢}
3612 \the\wd0
3613 \end{LTXexample}
3614 %<*en>
3615 Now we look why the above source outputs 20\,pt, not 15\,pt.
3616 \begin{enumerate}
3617 \item The ideographic full stop ``。'' is converted to its vertical form ``\char"FE12''~(\texttt{U+FE12}), %"
3618 by \verb+vert+ feature.
3619 \item The character class of ``\char"FE12'' is zero, hence its width is fullwidth.%"
3620 \item The character class of ``漢'', hence its width is fullwidth.
3621 \item \verb+\inhibitglue+ makes that no glue will be inserted between ``。'' and ``漢''.
3622 \item Hence the width of \verb+\hbox+ equals to 20\,pt.
3623 \end{enumerate}
3624 This example shows that the character class of a character is determined \emph{after
3625 applying font features by \Pkg{luaotfload}}.
3626 %</en>
3627 %<*ja>
3628 では,全角二分(15.0\,pt)となるのが自然……と思うかもしれないが,上の実行結果では20\,ptとなっている.
3629 それは以下の事情によるものである:
3630 \begin{enumerate}
3631 \item \verb+vert+ featureによって句点(\texttt{U+3002})が縦書き用のグリフと置き換わる(\Pkg{luaotfload} による処理).
3632 \item この縦書き用句点のグリフは \texttt{U+FE12} であるため,その文字クラスは0となる.
3633 \item 以上により文字クラス0とみなされるため,結果として「。」の幅は全角だと認識されてしまう.
3634 \end{enumerate}
3635 この例は,\emph{文字クラスの決定はfont featureの適用によるグリフ置換の後に行われる}ことを
3636 示している.
3637 %</ja>
3638
3639 %<*en>
3640 However, a starred specificaion like ``\texttt{'、*'}'' changes the rule.
3641 Consider the following input:
3642 %</en>
3643 %<*ja>
3644 但し,「\texttt{'、*'}」のようにアスタリスクつきの指定があると,
3645 状況は異なる.
3646 %</ja>
3647 \begin{LTXexample}[width=0.3\textwidth]
3648 \jfont\a=file:KozMinPr6N-Regular.otf:jfm=test;+vert
3649 \a 漢、\inhibitglue 漢
3650 \end{LTXexample}
3651 %<*en>
3652 Here, the character class of the ideographic comma ``、''~(\texttt{U+3001}) is determined
3653 as following:
3654 \begin{enumerate}
3655 \item As the case of ``。'', the ideographic comma ``、'' is converted to its vertical
3656       form ``\char"FE11''~(\texttt{U+FE11}).%"
3657 \item The character class of ``\char"FE11'' is zero.
3658 \item However, \LuaTeX-ja remembers that this ``\char"FE11'' is obtained from ``、'' by
3659       font features. The character class of ``、'' is \emph{non-zero value}, namely, 2000.
3660 \item Hence the ideographic comma ``、'' in above belongs the character class~2000.
3661 \end{enumerate}
3662 %</en>
3663 %<*ja>
3664 ここで,読点「、」(\texttt{U+3001})の文字クラスは,以下のようにして決まる.
3665 \begin{enumerate}
3666 \item とりあえず句点の時と同じように,\Pkg{luaotfload} によって縦書き用読点のグリフに置き換わる.
3667 \item 置換後のグリフは \texttt{U+FE11} であり,そのままでは文字クラスは0と判定される.
3668 \item ところが,JFMには「\texttt{'、*'}」指定があるので,置換前の横書き用読点のグリフによって文字クラスを判定する.
3669 \item 結果として,上の出力例中の読点の文字クラスは2000となる.
3670 \end{enumerate}
3671 %</ja>
3672
3673 %<*ja>
3674 なお,「\texttt{'\hbox{}ヒ*'}」のようにアスタリスクつきの指定があっても,
3675 置換後のグリフで判定した文字クラスの値が0でなければ,そちらをそのまま作用する.
3676 \begin{LTXexample}[width=0.3\textwidth]
3677 \jfont\a=file:KozMinPr6N-Regular.otf:jfm=test;+hwid
3678 \a 漢ヒひ
3679 \end{LTXexample}
3680 上の例では,
3681 \texttt{hwid} featureにより,「ヒ」が半角の「ヒ」に置き換わるが,
3682 文字クラスは「ヒ」の属する0\emph{ではなく},「ヒ」の属する2000となる.
3683 %</ja>
3684
3685 %<ja>\paragraph{仮想的な文字}
3686 %<en>\paragraph{Imaginary characters}
3687 %<*en>
3688 As described before, you can specify several \emph{imaginary characters} in
3689 \texttt{chars} field. The most of these characters are regarded as the
3690 characters of class 0 in \pTeX.
3691 As a result, \LuaTeX-ja can control typesetting finer than \pTeX.
3692 The following is the list of imaginary characters:
3693 %</en>
3694 %<*ja>
3695 上で説明した通り,\texttt{chars}フィールド中にはいくつかの「特殊文字」も
3696 指定可能である.これらは,大半が\pTeX のJFMグルーの挿入処理ではみな「文字
3697 クラス0の文字」として扱われていた文字であり,その結果として\pTeX より細か
3698 い組版調整ができるようになっている.以下でその一覧を述べる:
3699 %</ja>
3700
3701 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}\advance\leftmargin1\zw}
3702 %%\item['diffmet']
3703 %%<en>Used at a boundary between two \textbf{JAchar}s whose JFM or size is different.
3704 %%<ja>JFMやサイズが異なる2つの\textbf{JAchar}の間の境界として用いられる.
3705
3706 \item['boxbdd']
3707 %<en>The beginning/ending of a hbox, and the beginning of a noindented (i.e., began by \verb+\noindent+) paragraph.
3708 %<ja>hboxの先頭と末尾,及びインデントされていない(\verb+\noindent+ で開始された)段落の先頭を表す.
3709
3710 \item['parbdd']
3711 %<en>The beginning of an (indented) paragraph.
3712 %<ja>通常の(\verb+\noindent+ で開始されていない)段落の先頭.
3713
3714 \item['jcharbdd']
3715 %<en>A boundary between \textbf{JAchar} and anything else (such as \textbf{ALchar}, kern, glue,\,\ldots).
3716 %<ja>和文文字と「その他のもの」(欧文文字,glue,kern等)との境界.
3717
3718 \item[$-1$]
3719 %<en>The left/right boundary of an inline math formula.
3720 %<ja>行中数式と地の文との境界.
3721 \end{list}
3722
3723 %<en>\paragraph{Porting JFM from \pTeX}
3724 %<ja>\paragraph{\pTeX 用和文用TFMの移植}
3725
3726 % ToDo: English version.
3727
3728 %<*en>
3729 See Japanese version of this manual.
3730 %</en>
3731
3732 %<*ja>
3733 以下に,\pTeX 用に作られた和文用TFMを\LuaTeX-ja用に移植する場合の注意点を挙げておく.
3734 \begin{itemize}
3735 \item 実際に出力される和文フォントのサイズがdesign sizeとなる.
3736 このため,例えば$1\,\textrm{zw}$がdesign sizeの0.962216倍であるJISフォン
3737       トメトリック等を移植する場合は,次のようにするべきである:
3738 \begin{itemize}
3739 \item JFM中の全ての数値を$1/0.962216$倍しておく.
3740 \item \TeX ソース中で使用するところで,サイズ指定を0.962216倍にする.
3741       \LaTeX でのフォント宣言なら,例えば次のように:
3742 \begin{verbatim}
3743 \DeclareFontShape{JY3}{mc}{m}{n}{<-> s*[0.962216] psft:Ryumin-Light:jfm=jis}{}
3744 \end{verbatim}
3745 \end{itemize}
3746 \item 上に述べた特殊文字は,\texttt{'boxbdd'}を除き文字クラスを全部0とする
3747       (JFM中に単に書かなければよい).
3748 \item \texttt{'boxbdd'}については,それのみで一つの文字クラスを形成し,その
3749       文字クラスに関してはグルー/カーンの設定はしない.
3750
3751 これは,\pTeX では,
3752       hboxの先頭・末尾とインデントされていない(\verb+\noindent+ で開始さ
3753       れた)段落の先頭にはJFMグルーは入らないという仕様を実現させるためである.
3754 \item \pTeX の組版を再現させようというのが目的であれば以上の注意を守れば十分である.
3755
3756 ところで,\pTeX では通常の段落の先頭にJFMグルーが残るという仕様があるので,
3757       段落先頭の開き括弧は全角二分下がりになる.全角下がりを実現させるに
3758       は,段落の最初に手動で \verb+\inhibitglue+ を追加するか,あるいは
3759       \ \verb+\everypar+ のハックを行い,それを自動化させるしかなかった.
3760
3761 一方,\LuaTeX-jaでは,\texttt{'parbdd'}によって,それがJFM側で調整できるよ
3762 うになった.例えば,\LuaTeX-ja同梱のJFMのように,\texttt{'boxbdd'}と同じ文字クラスに
3763 \texttt{'parbdd'}を入れれば全角下がりとなる.
3764
3765 \begin{LTXexample}[width=0.4\textwidth]
3766 \jfont\g=KozMinPr6N-Regular:jfm=test \g
3767 \parindent1\zw\noindent{}◆◆◆◆◆
3768 \par 「◆◆←二分下がり
3769 \par 【◆◆←全角下がり
3770 \par 〔◆◆←全角二分下がり
3771 \end{LTXexample}
3772 \end{itemize}
3773
3774 但し,\verb+\everypar+ を利用している場合にはこの仕組みは正しく動かない.
3775 そのような例としては箇条書き中の \verb+\item+ で始まる段落があり,\Pkg{ltjsclasses}では
3776 人工的に「\texttt{'parbdd'}の意味を持つ」whatsitノードを作ることによって対処している%
3777 \footnote{\texttt{ltjsclasses.dtx} を参照されたい.
3778 JFM側で一部の対処ができることにより,\Pkg{jsclasses}のようにif文の判定はしていない.}.
3779 %</ja>
3780
3781
3782 %<en>\subsection{Math Font Family}
3783 %<ja>\subsection{数式フォントファミリ}
3784 \label{ssec-math}
3785
3786 %<*en>
3787 \TeX\ handles fonts in math formulas by 16~font families\footnote{Omega,
3788 Aleph, \LuaTeX~and $\varepsilon$-\kern-.125em(u)\pTeX\ can handles 256~families, but
3789 an external package is needed to support this in plain \TeX\ and
3790 \LaTeX.}, and each family has three fonts:
3791 \verb+\textfont+, \verb+\scriptfont+ and \verb+\scriptscriptfont+.
3792 %</en>
3793 %<*ja>
3794 \TeX\ は数式フォントを16のファミリ\footnote{Omega, Aleph, \LuaTeX,そして
3795   $\varepsilon$-\kern-.125em(u)\pTeX\ では256の数式ファミリを扱うことができるが,
3796   これをサポートするためにplain \TeX と\LaTeX では外部パッケージを読み込む必要が
3797   ある.}で管理し,それぞれのファミリは3つのフォントを持っている:
3798 \verb+\textfont+, \verb+\scriptfont+ そして \verb+\scriptscriptfont+ である.
3799 %</ja>
3800
3801 %<*en>
3802 \LuaTeX-ja's handling of Japanese fonts in math formulas is similar;
3803 Table~\ref{tab-math} shows counterparts to \TeX's primitives for math
3804 font families. There is no relation between the value of
3805 \verb+\fam+ and that of \verb+\jfam+; with appropriate settings,
3806 you can set both \verb+\fam+ and \verb+\jfam+ to the same value.
3807 %</en>
3808 %<*ja>
3809 \LuaTeX-jaの数式中での和文フォントの扱いも同様である.
3810 表\ref{tab-math}は数式フォントファミリに対する \TeX のプリミティブと対応する
3811 ものを示している.\verb+\fam+ と \verb+\jfam+ の値の間には関係はなく,
3812 適切な設定の下では \verb+\fam+ と \verb+\jfam+ の両方に同じ値を設定することができる.
3813 %</ja>
3814
3815 \begin{table}[!tb]
3816 %<en>\caption{Commands for Japanese math fonts}
3817 %<ja>\caption{和文数式フォントに対する命令}
3818 \label{tab-math}
3819 %<en>\medskip
3820 \centering
3821 \def\{{\char`\{}\def\}{\char`\}}\small
3822 \begin{tabular}{ll}
3823 \toprule
3824 %<en>\bf Japanese fonts&\bf alphabetic fonts\\
3825 %<ja>\bf 和文フォント&\bf 欧文フォント\\
3826 \midrule
3827 \verb+\jfam+${}\in [0,256)$&\verb+\fam+\\
3828 \tt\Param{jatextfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\verb+\textfont+<fam>=<font\_cs>\\
3829 \tt\Param{jascriptfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\verb+\scriptfont+<fam>=<font\_cs>\\
3830 \tt\Param{jascriptscriptfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\verb+\scriptscriptfont+<fam>=<font\_cs>\\
3831 \bottomrule
3832 \end{tabular}
3833 \end{table}
3834
3835 %<en>\subsection{Callbacks}
3836 %<ja>\subsection{コールバック}
3837
3838 %<*en>
3839 \LuaTeX-ja also has several callbacks. These callbacks can
3840 be accessed via \verb+luatexbase.add_to_callback+ function and so on, as other callbacks.
3841 %</en>
3842 %<*ja>
3843 \LuaTeX 自体のものに加えて,\LuaTeX-jaもコールバックを持っている.
3844 これらのコールバックには,他のコールバックと同様に \verb+luatexbase.add_to_callback+
3845 関数などを用いることでアクセスすることができる.
3846 %</ja>
3847 \begin{list}{}%
3848 {\def\makelabel#1{\bfseries#1}}
3849 %<en>\item[\texttt{luatexja.load\_jfm} callback]
3850 %<ja>\item[\texttt{luatexja.load\_jfm}コールバック]
3851 %<*en>
3852 With this callback you can overwrite JFMs.
3853 This callback is called when a new JFM is loaded.
3854 %</en>
3855 %<*ja>
3856 このコールバックを用いることでJFMを上書きすることができる.
3857 このコールバックは新しいJFMが読み込まれるときに呼び出される.
3858 %</ja>
3859
3860 \begin{lstlisting}[numbers=left]
3861 function (<table> jfm_info, <string> jfm_name)
3862   return <table> new_jfm_info
3863 end
3864 \end{lstlisting}
3865
3866 %<*en>
3867 The argument \verb+jfm_info+ contains a table similar to the table in a JFM file, except
3868 this argument has \texttt{chars} field which contains character codes
3869              whose character class is not~0.
3870 %</en>
3871 %<*ja>
3872 引数 \verb+jfm_info+ はJFMファイルのテーブルと似たものが格納されるが,
3873 クラス0を除いた文字のコードを含んだ\texttt{chars}フィールドを持つ点が異なる.
3874 %</ja>
3875
3876 %<*en>
3877 An example of this callback is the \texttt{ltjarticle} class, with
3878              forcefully assigning character class~0 to \texttt{'parbdd'}
3879              in the JFM \texttt{jfm-min.lua}.
3880 %</en>
3881 %<*ja>
3882 このコールバックの使用例は\texttt{ltjarticle}クラスにあり,
3883 \texttt{jfm-min.lua}中の\texttt{'parbdd'}を強制的にクラス0に割り当てている.
3884 %</ja>
3885
3886 %<en>\item[\texttt{luatexja.define\_jfont} callback]
3887 %<ja>\item[\texttt{luatexja.define\_jfont}コールバック]
3888 %<*en>
3889 This callback and the next callback form a pair, and you can assign characters 
3890  which do not have fixed code points in Unicode to non-zero character classes.
3891 This \texttt{luatexja.define\_font} callback is called just when new Japanese font is loaded.
3892 %</en>
3893 %<*ja>
3894 このコールバックと次のコールバックは組をなしており,Unicode中に固定された文字コード
3895 番号を持たない文字を非零の文字クラスに割り当てることができる.
3896 このコールバックは新しい和文フォントが読み込まれたときに呼び出される.
3897 %</ja>
3898
3899 \begin{lstlisting}[numbers=left]
3900 function (<table> jfont_info, <number> font_number)
3901   return <table> new_jfont_info
3902 end
3903 \end{lstlisting}
3904 %<*en>
3905 \verb+jfont_info+ has the following fields,
3906 \emph{which may not overwritten by a user}:
3907 \begin{description}
3908 \item[\texttt{size}]
3909 The font size specified at \verb+\jfont+ in scaled points ($1\,\mathrm{sp}=2^{-16}\,\mathrm{pt}$).
3910 \item[\texttt{zw}, \texttt{zh}, \texttt{kanjiskip}, \texttt{xkanjiskip}]
3911 These are scaled value of those specified by the JFM, by the font size.
3912 \item[\texttt{jfm}]
3913 The internal number of the JFM.
3914 \item[\texttt{var}]
3915 The value of \texttt{jfmvar}~key, which is specified at \verb+\jfont+.
3916 The default value is the empty string.
3917 \item[\texttt{chars}]
3918 The mapping table from character codes to its character classes.\\
3919 The specification \texttt{[i].chars=\{<character>, ...\}} in the JFM will be  stored in this
3920            field as \texttt{chars=\{[<character>]=\,$i$, ...\}}.
3921 \item[\texttt{char\_type}]
3922 For $i\in\omega$, \texttt{char\_type[$i$]} is information of characters whose class is
3923            $i$, and has the following fields:
3924 \begin{itemize}
3925  \item \texttt{width},~\texttt{height}, \texttt{depth}, 
3926   \texttt{italic}, \texttt{down},~\texttt{left}\ are just 
3927        scaled value of those specified by the JFM, by the font size.
3928  \item \texttt{align} is a number which is determined from \texttt{align}~field in the JFM:
3929 \[
3930  \begin{cases}
3931   0&\text{\texttt{'left'} and the default value}\\0.5&\text{\tt 'middle'}\\1&\text{\tt 'right'}
3932  \end{cases}
3933 \]
3934 \item For $j\in \omega$, \texttt{[$j$]} stores a kern or a glue which will be inserted 
3935 between character class~$i$ and class~$j$.
3936
3937 If a kern will be inserted, the value of this field is \texttt{[$j$]=\{false, <kern\_node>, <ratio>\}},
3938 where <kern\_node> is a node\footnote{%
3939  This version of \LuaTeX-ja uses ``direct access
3940       model'' for accessing nodes, if possible. }.
3941 If a glue will be inserted, we have \texttt{[$j$]=\{false, <spec\_node>, <ratio>, <icflag>\}},
3942 where <spec\_node> is also a node, and $\text{<icflag>}=\textit{from\_jfm}+\text{<priority>}$.
3943 \end{itemize}
3944 \end{description}
3945 %</en>
3946 %<*ja>
3947 \verb+jfont_info+ は最低限以下のフィールドを持つが,これらを書き換えてはならない:
3948 \begin{description}
3949 \item[\texttt{size}]
3950 実際に使われるフォントサイズ(sp単位).$1\,\mathrm{sp}=2^{-16}\,\mathrm{pt}$.
3951 \item[\texttt{zw}, \texttt{zh}, \texttt{kanjiskip}, \texttt{xkanjiskip}]
3952 JFMファイルで指定されているそれぞれの値をフォントサイズに合わせてスケーリングしたものを
3953 sp単位で格納している.
3954 \item[\texttt{jfm}]
3955 利用されているJFMを識別するための番号.
3956 \item[\texttt{var}]
3957 \verb+\jfont+で指定された \texttt{jfmvar} キーの値(未指定のときは空文字列).
3958 \item[\texttt{chars}]
3959 文字コードから文字クラスへの対応が記述されたテーブル.\\
3960 JFM内の \texttt{[i].chars=\{<character>, ...\}} という指定は\ 
3961 \texttt{chars=\{[<character>]=\,$i$, ...\}} という形式に変換されている.
3962 \item[\texttt{char\_type}]
3963 $i\in\omega$に対して,\texttt{char\_type[$i$]} は文字クラス$i$の文字の寸法を格納しており,
3964 以下のフィールドを持つ.
3965 \begin{itemize}
3966  \item \texttt{width},~\texttt{height}, \texttt{depth}, 
3967   \texttt{italic}, \texttt{down},~\texttt{left}\ は
3968 JFMで指定されているそれぞれの値をスケーリングしたものである.
3969  \item \texttt{align} はJFMで指定されている値によって,
3970 \[
3971  \begin{cases}
3972   0&\text{\texttt{'left'}や省略時}\\0.5&\text{\tt 'middle'}\\1&\text{\tt 'right'}
3973  \end{cases}
3974 \]
3975 のいずれかの値をとる.
3976 \item $j\in \omega$に対して,\texttt{[$j$]} は文字クラス$i$の文字と$j$の文字の間に挿入されるkern
3977       やglueを格納している.
3978 間に入るものがkernであれば,このフィールドの値は\ 
3979 \texttt{[$j$]=\{false, <kern\_node>, <ratio>\}} である.
3980 <kern\_node>はkernを表すノードそのものである\footnote{%
3981 本バージョンでは利用可能ならばノードのアクセス手法にdirect access
3982       modelを用いている.そのため,例えば\LuaTeX\ beta-0.78.2では,単なる自然数のようにし
3983       か見えないことに注意.
3984 }.
3985 glueであれば,\texttt{[$j$]=\{false, <spec\_node>, <ratio>, <icflag>\}} である.
3986 <spec\_node>はglueの長さを表すノードそのものであり,
3987       $\text{<icflag>}=\textit{from\_jfm}+\text{<priority>}$である.
3988 \end{itemize}
3989 \end{description}
3990 %</ja>
3991
3992 %<*en>
3993 The returned table \verb+new_jfont_info+ also should include these fields, but
3994 you are free to add more fields (to use them in the \texttt{luatexja.find\_char\_class} callback).
3995 The \verb+font_number+ is a font number.
3996 %</en>
3997 %<*ja>
3998 戻り値の \verb+new_jfont_info+ テーブルも上に述べたフィールドをそのまま含まなければならないが,
3999 それ以外にユーザが勝手にフィールドを付け加えることは自由である.
4000 \verb+font_number+ はフォント番号である.
4001 %</ja>
4002
4003 %<*en>
4004 A good example of this and the next callbacks is the \Pkg{luatexja-otf}
4005              package, supporting \verb+"AJ1-xxx"+ form for Adobe-Japan1
4006              CID characters in a JFM. This callback doesn't replace any
4007              code of \LuaTeX-ja.
4008 %</en>
4009 %<*ja>
4010 これと次のコールバックの良い使用例は\Pkg{luatexja-otf}パッケージであり,
4011 JFM中でAdobe-Japan1 CIDの文字を \verb+"AJ1-xxx"+ の形で指定するために
4012 用いられている.
4013 %</ja>
4014
4015 %<en>\item[\texttt{luatexja.find\_char\_class} callback]
4016 %<ja>\item[\texttt{luatexja.find\_char\_class}コールバック]
4017 %<*en>
4018 This callback is called just when \LuaTeX-ja is trying to determine which
4019              character class a character \verb+chr_code+ belongs.
4020 A function used in this callback should be in the following form:
4021 %</en>
4022 %<*ja>
4023 このコールバックは\LuaTeX-jaが \verb+chr_code+ の文字がどの文字クラスに
4024 属するかを決定しようとする際に呼び出される.
4025 このコールバックで呼び出される関数は次の形をしていなければならない:
4026 %</ja>
4027 \begin{lstlisting}[numbers=left]
4028 function (<number> char_class, <table> jfont_info, <number> chr_code)
4029   if char_class~=0 then return char_class
4030   else
4031     ....
4032     return (<number> new_char_class or 0)
4033   end
4034 end
4035 \end{lstlisting}
4036
4037 %<*en>
4038 The argument \verb+char_class+ is the result of \LuaTeX-ja's default
4039              routine or previous function calls in this callback, hence
4040              this argument may not be 0. Moreover, the returned
4041              \verb+new_char_class+ should be as same as \verb+char_class+ when \verb+char_class+
4042              is not~0, otherwise you will overwrite the \LuaTeX-ja's
4043              default routine.
4044 %</en>
4045 %<*ja>
4046 引数 \verb+char_class+ は\LuaTeX-jaのデフォルトルーチンか,このコールバックの
4047 直前の関数呼び出しの結果を含んでおり,したがってこの値は0ではないかもしれない.
4048 さらに,戻り値の \verb+new_char_class+ は \verb+char_class+ が非零のときには
4049 \verb+char_class+ の値と同じであるべきで,そうでないときは\LuaTeX-jaの
4050 デフォルトルーチンを書き換えることになる.
4051 %</ja>
4052
4053 %<en>\item[\texttt{luatexja.set\_width} callback]
4054 %<ja>\item[\texttt{luatexja.set\_width}コールバック]
4055 %<*en>
4056 This callback is called when \LuaTeX-ja is trying to encapsule a
4057              \textbf{JAchar} \textit{glyph\_node}, to adjust its
4058              dimension and position.
4059 %</en>
4060 %<*ja>
4061 このコールバックは\LuaTeX-jaが\textbf{JAchar}の寸法と位置を調節するために
4062 その\textit{glyph\_node}をカプセル化しようとする際に呼び出される.
4063 %</ja>
4064 \begin{lstlisting}[numbers=left]
4065 function (<table> shift_info, <table> jfont_info, <number> char_class)
4066   return <table> new_shift_info
4067 end
4068 \end{lstlisting}
4069
4070 %<*en>
4071 The argument \verb+shift_info+ and the returned \verb+new_shift_info+ have
4072 \texttt{down} and \texttt{left} fields, which are the amount of shifting
4073              down/left the character in a scaled point.
4074 %</en>
4075 %<*ja>
4076 引数 \verb+shift_info+ と戻り値の \verb+new_shift_info+ は
4077 \texttt{down}と\texttt{left}のフィールドを持ち,これらの値は
4078 文字の下/左へのシフト量(sp単位)である.
4079 %</ja>
4080
4081 %<*en>
4082 A good example is \Pkg{test/valign.lua}.
4083 After loading this file, the vertical position of glyphs is automatically
4084 adjusted; the ratio $(\hbox{height}:\hbox{depth})$ of glyphs is adjusted
4085 to be that of letters in the character class~0. For example, suppose that
4086 \begin{itemize}
4087 \item The setting of the JFM: $(\hbox{height})=88x$, $(\hbox{depth})=12x$
4088   (the standard values of Japanese OpenType fonts);
4089 \item The value of the real font: $(\hbox{height})=28y$, $(\hbox{depth})=5y$
4090   (the standard values of Japanese TrueType fonts).
4091 \end{itemize}
4092 Then, the position of glyphs is shifted up by
4093 %</en>
4094 %<*ja>
4095 良い例が\Pkg{test/valign.lua}である.このファイルが読み込まれた状態では,
4096              JFM内で規定された文字クラス0の文字における$(\hbox{高
4097              さ}):(\hbox{深さ})$の比になるように,実際のフォントの出力上
4098              下位置が自動調整される.例えば,
4099 \begin{itemize}
4100 \item JFM側の設定:$(\hbox{高さ})=88x$, $(\hbox{深さ})=12x$%
4101 (和文OpenTypeフォントの標準値)
4102 \item 実フォント側の数値:$(\hbox{高さ})=28y$, $(\hbox{深さ})=5y$(和文TrueTypeフォントの標準値)
4103 \end{itemize}
4104 となっていたとする.すると,実際の文字の出力位置は,以下の量だけ上にぜらされることとなる:
4105 %</ja>
4106 \[
4107  \frac{88x}{88x+12x} (28y+5y) - 28y = \frac{26}{25}y= 1.04y.
4108 \]
4109 \end{list}
4110
4111
4112
4113 %<en>\section{Parameters}
4114 %<ja>\section{パラメータ}
4115 \subsection{\texttt{\textbackslash ltjsetparameter}}
4116 \label{ssec-param}
4117
4118 %<*en>
4119 As described before, \verb+\ltjsetparameter+ and \verb+\ltjgetparameter+ are
4120 commands for accessing most parameters of \LuaTeX-ja. One of the main
4121 reason that \LuaTeX-ja didn't adopted the syntax similar to that of \pTeX\
4122 (\textit{e.g.},~\verb+\prebreakpenalty`)=10000+)
4123 is the position of \verb+hpack_filter+ callback in the source
4124 of \LuaTeX, see Section~\ref{sec-para}.
4125 %</en>
4126 %<*ja>
4127 先に述べたように,\verb+\ltjsetparameter+ と \verb+\ltjgetparameter+ は
4128 \LuaTeX-jaのほとんどのパラメータにアクセスするための命令である.
4129 \LuaTeX-jaが\pTeX のような文法(例えば,\verb+\prebreakpenalty`)=10000+)を
4130 採用しない理由の一つは,\LuaTeX のソースにおける \verb+hpack_filter+
4131 コールバックの位置にある.\ref{sec-para}章を参照.
4132 %</ja>
4133
4134 %<*en>
4135 \verb+\ltjsetparameter+ and \verb+\ltjglobalsetparameter+ are commands
4136 for assigning parameters. These take one argument which is a
4137 \texttt{<key>=<value>} list. 
4138 The list of allowed keys are described in the next subsection.
4139 The difference between
4140 \verb+\ltjsetparameter+ and \verb+\ltjglobalsetparameter+ is only the
4141 scope of assignment;
4142 \verb+\ltjsetparameter+ does a local assignment and
4143 \verb+\ltjglobalsetparameter+ does a global one.
4144 They also obey the value of \verb+\globaldefs+,
4145 like other assignment.
4146 %</en>
4147 %<*ja>
4148 \verb+\ltjsetparameter+ と \verb+\ltjglobalsetparameter+ はパラメータを
4149 指定するための命令である.これらは\texttt{<key>=<value>}のリストを
4150 引数としてとる.許されるキーの一覧は次の節にある.
4151 \verb+\ltjsetparameter+ と \verb+\ltjglobalsetparameter+ の違いはスコープの
4152 違いのみで,
4153 \verb+\ltjsetparameter+ はローカルな指定,\verb+\ltjglobalsetparameter+ は
4154 グローバルな指定を行う.
4155 これらは他のパラメータ指定と同様に \verb+\globaldefs+ の値に従う.
4156 %</ja>
4157
4158 %<*en>
4159 The following is the list of parameters which can be specified by the
4160 \verb+\ltjsetparameter+ command. [\verb+\cs+] indicates the counterpart
4161 in \pTeX, and symbols beside each parameter has the following meaning:
4162 %</en>
4163 %<*ja>
4164 以下は \verb+\ltjsetparameter+ に指定することができるパラメータの一覧である.
4165 [\verb+\cs+]は\pTeX における対応物を示す.
4166 また,それぞれのパラメータの右上にある記号には次の意味がある:
4167 %</ja>
4168 \begin{itemize}
4169 %<*en>
4170 \item ``\ast'' : values at the end of a paragraph or a hbox are
4171 adopted in the whole paragraph or the whole hbox.
4172 %</en>
4173 %<*ja>
4174 \item ``\ast'':段落やhboxの終端での値がその段落/hbox全体で用いられる.
4175 %</ja>
4176 %<*en>
4177 \item ``\dagger'': assignments are always global.
4178 %</en>
4179 %<*ja>
4180 \item ``\dagger'':指定は常にグローバルになる.
4181 %</ja>
4182 \end{itemize}
4183
4184 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}\advance\leftmargin1\zw}
4185 \item[\Param{jcharwidowpenalty}\,=<penalty>$^\ast$] [\verb+\jcharwidowpenalty+]
4186 %<*en>
4187 Penalty value for suppressing orphans. This penalty is inserted just
4188              after the last \textbf{JAchar} which is not regarded as a
4189              (Japanese) punctuation mark.
4190 %</en>
4191 %<*ja>
4192 パラグラフの最後の字が孤立して改行されるのを防ぐためのペナルティの値.
4193 このペナルティは(日本語の)句読点として扱われない最後の\textbf{JAchar}の直後に
4194 挿入される.
4195 %</ja>
4196
4197 \item[\Param{kcatcode}\,=\{<chr\_code>,<natural number>\}$^\ast$]\
4198 %<*en>
4199 An additional attributes which each character whose character code is <chr\_code> has.
4200 At the present version, the lowermost bit of <natural number> indicates
4201              whether the character is considered as a punctuation mark
4202              (see the description of \Param{jcharwidowpenalty} above).
4203 %</en>
4204 %<*ja>
4205 文字コードが<chr\_code>の文字が持つ付加的な属性値(attribute).
4206 現在のバージョンでは,<natural number>の最下位ビットが,その文字が句読点と
4207 みなされるかどうかを表している(上の\Param{jcharwidowpenalty}の記述を参照).
4208 %</ja>
4209
4210 \item[\Param{\hypertarget{fld:prebp}{prebreakpenalty}}\,=\{<chr\_code>,<penalty>\}$^\ast$] [\verb+\prebreakpenalty+]\
4211 %<*ja>
4212 文字コード<chr\_code>の\textbf{JAchar}が行頭にくることを抑止するために,
4213              この文字の前に挿入/追加されるペナルティの量を指定する.
4214
4215 例えば閉じ括弧「〗」は絶対に行頭にきてはならないので,
4216 \begin{verbatim}
4217 \ltjsetparameter{prebreakpenalty={`〙,10000}}
4218 \end{verbatim}
4219 と,最大値の10000が標準で指定されている.他にも,小書きのカナなど,絶対禁止とい
4220              うわけではないができれば行頭にはきて欲しくない場合に,0と
4221              10000の間の値を指定するのも有用であろう.
4222 %</ja>
4223 %<*en>
4224 Set a penalty which is inserted automatically before the character <chr\_code>,
4225 to prevent a line starts from this character. For example, a line cannot started
4226 with one of closing brackets ``〗'', so \LuaTeX-ja sets
4227 \begin{verbatim}
4228 \ltjsetparameter{prebreakpenalty={`〙,10000}}
4229 \end{verbatim}
4230 by default.
4231 %</en>
4232
4233
4234 \item[\Param{\hypertarget{fld:postbp}{postbreakpenalty}}\,=\{<chr\_code>,<penalty>\}$^\ast$] [\verb+\postbreakpenalty+]
4235 %<*ja>
4236 文字コード<chr\_code>の\textbf{JAchar}が行末にくることを抑止するために,
4237              この文字の後に挿入/追加されるペナルティの量を指定する.
4238
4239 \pTeX では,\verb+\prebreakpenalty+, \verb+\postbreakpenalty+において,
4240 \begin{itemize}
4241 \item 一つの文字に対して,pre, postどちらか一つしか指定することができなかっ
4242       た(後から指定した方で上書きされる).
4243 \item pre, post合わせて256文字分の情報を格納することしかできなかった.
4244 \end{itemize}
4245 という制限があったが,\LuaTeX-jaではこれらの制限は解消されている.
4246 %</ja>
4247 %<*en>
4248 Set a penalty which is inserted automatically after the character <chr\_code>,
4249 to prevent a line ends with this character. 
4250 \pTeX\ has following restrictions on \verb+\prebreakpenalty+ and \verb+\postbreakpenalty+,
4251 but they don't exist in \LuaTeX-ja:
4252 \begin{itemize}
4253  \item Both \verb+\prebreakpenalty+ and \verb+\postbreakpenalty+ cannot be set
4254 for the same character.
4255  \item We can set \verb+\prebreakpenalty+ and \verb+\postbreakpenalty+  up to 256~characters.
4256 \end{itemize}
4257 %</en>
4258
4259 \item[\Param{jatextfont}\,=\{<jfam>,<jfont\_cs>\}$^\ast$]
4260 %<en>[\verb+\textfont+ in \TeX]
4261 %<ja>[\TeX の \verb+\textfont+]
4262 \item[\Param{jascriptfont}\,=\{<jfam>,<jfont\_cs>\}$^\ast$]
4263 %<en>[\verb+\scriptfont+ in \TeX]
4264 %<ja>[\TeX の \verb+\scriptfont+]
4265 \item[\Param{jascriptscriptfont}\,=\{<jfam>,<jfont\_cs>\}$^\ast$]
4266 %<en>[\verb+\scriptscriptfont+ in \TeX]
4267 %<ja>[\TeX の \verb+\scriptscriptfont+]
4268 \item[\Param{yjabaselineshift}\,=<dimen>]\
4269 \item[\Param{yalbaselineshift}\,=<dimen>] [\verb+\ybaselineshift+]
4270 \item[\Param{tjabaselineshift}\,=<dimen>]\
4271 \item[\Param{talbaselineshift}\,=<dimen>] [\verb+\tbaselineshift+]
4272
4273 \item[\Param{jaxspmode}\,=\{<chr\_code>,<mode>\}$^\ast$]
4274
4275 %<*en>
4276 Setting whether inserting \Param{\hyperlink{fld:xks}{xkanjiskip}} is allowed before/after a \textbf{JAchar} whose character code is <chr\_code>.
4277 The followings are allowed for <mode>:
4278 %</en>
4279 %<*ja>
4280 文字コードが<chr\_code>の\textbf{JAchar}の前/後ろに\Param{\hyperlink{fld:xks}{xkanjiskip}}の
4281 挿入を許すかどうかの設定.
4282 以下の<mode>が許される:
4283 %</ja>
4284 \begin{description}
4285 %<en>\item[0, \texttt{inhibit}] Insertion of \Param{\hyperlink{fld:xks}{xkanjiskip}} is inhibited before the character, nor after the character.
4286 %<ja>\item[0, \texttt{inhibit}] \Param{\hyperlink{fld:xks}{xkanjiskip}}の挿入は文字の前/後ろのいずれでも禁止される.
4287 %<en>\item[1, \texttt{preonly}] Insertion of \Param{\hyperlink{fld:xks}{xkanjiskip}} is allowed before the character, but not after.
4288 %<ja>\item[1, \texttt{preonly}] \Param{\hyperlink{fld:xks}{xkanjiskip}}の挿入は文字の前では許されるが,後ろでは許されない.
4289 %<en>\item[2, \texttt{postonly}] Insertion of \Param{\hyperlink{fld:xks}{xkanjiskip}} is allowed after the character, but not before.
4290 %<ja>\item[2, \texttt{postonly}] \Param{\hyperlink{fld:xks}{xkanjiskip}}の挿入は文字の後ろでは許されるが,前では許されない.
4291 %<en>\item[3, \texttt{allow}] Insertion of \Param{\hyperlink{fld:xks}{xkanjiskip}} is allowed both before the character and after the character. This is the default value.
4292 %<ja>\item[3, \texttt{allow}] \Param{\hyperlink{fld:xks}{xkanjiskip}}の挿入は文字の前/後ろのいずれでも許される.これがデフォルトの値である.
4293 \end{description}
4294 %<*en>
4295 This parameter is similar to the \verb+\inhibitxspcode+ primitive of \pTeX, but not compatible with \verb+\inhibitxspcode+.
4296 %</en>
4297 %<*ja>
4298 このパラメータは\pTeX の \verb+\inhibitxspcode+ プリミティブと似ているが,
4299 互換性はない.
4300 %</ja>
4301 \item[\Param{alxspmode}\,=\{<chr\_code>,<mode>\}$^\ast$] [\verb+\xspcode+]
4302
4303 %<*en>
4304 Setting whether inserting \Param{\hyperlink{fld:xks}{xkanjiskip}} is allowed before/after a
4305              \textbf{ALchar} whose character code is <chr\_code>.
4306              The followings are allowed for <mode>:
4307 %</en>
4308 %<*ja>
4309 文字コードが<chr\_code>の\textbf{ALchar}の前/後ろに\Param{\hyperlink{fld:xks}{xkanjiskip}}の
4310 挿入を許すかどうかの設定.
4311 以下の<mode>が許される:
4312 %</ja>
4313 \begin{description}
4314 %<en>\item[0, \texttt{inhibit}] Insertion of \Param{\hyperlink{fld:xks}{xkanjiskip}} is inhibited before the character, nor after the character.
4315 %<ja>\item[0, \texttt{inhibit}] \Param{\hyperlink{fld:xks}{xkanjiskip}}の挿入は文字の前/後ろのいずれでも禁止される.
4316 %<en>\item[1, \texttt{preonly}] Insertion of \Param{\hyperlink{fld:xks}{xkanjiskip}} is allowed before the character, but not after.
4317 %<ja>\item[1, \texttt{preonly}] \Param{\hyperlink{fld:xks}{xkanjiskip}}の挿入は文字の前では許されるが,後ろでは許されない.
4318 %<en>\item[2, \texttt{postonly}] Insertion of \Param{\hyperlink{fld:xks}{xkanjiskip}} is allowed after the character, but not before.
4319 %<ja>\item[2, \texttt{postonly}] \Param{\hyperlink{fld:xks}{xkanjiskip}}の挿入は文字の後ろでは許されるが,前では許されない.
4320 %<en>\item[3, \texttt{allow}] Insertion of \Param{\hyperlink{fld:xks}{xkanjiskip}} is allowed before the character and after the character. This is the default value.
4321 %<ja>\item[3, \texttt{allow}] \Param{\hyperlink{fld:xks}{xkanjiskip}}の挿入は文字の前/後ろのいずれでも許される.これがデフォルトの値である.
4322 \end{description}
4323 %<*en>
4324 Note that parameters \Param{jaxspmode} and \Param{alxspmode} share a common table, hence these two parameters are synonyms of each other.
4325 %</en>
4326 %<*ja>
4327 \Param{jaxspmode}と\Param{alxspmode}は共通のテーブルを用いているため,
4328 これら2つのパラメータは互いの異名となっていることに注意する.
4329 %</ja>
4330
4331 \item[\Param{autospacing}\,=<bool>] [\verb+\autospacing+]
4332 \item[\Param{autoxspacing}\,=<bool>] [\verb+\autoxspacing+]
4333 \item[\Param{\hypertarget{fld:kanjiskip}{kanjiskip}}\,=<skip>$^\ast$] [\verb+\kanjiskip+]
4334 %<*ja>
4335 デフォルトで2つの\textbf{JAchar}の間に挿入されるグルーである.
4336 通常では,\pTeX と同じようにフォントサイズに比例して変わることはない.
4337 しかし,自然長が \verb+\maxdimen+ の場合は,例外的に和文フォントのJFM側で指定されている
4338 値を採用(こちらはフォントサイズに比例)することになっている.
4339 %</ja>
4340
4341 \item[\Param{\hypertarget{fld:xks}{xkanjiskip}}\,=<skip>$^\ast$] [\verb+\xkanjiskip+]
4342 %<*ja>
4343 デフォルトで\textbf{JAchar}と\textbf{ALchar}の間に挿入されるグルーである.
4344 \Param{\hyperlink{fld:kanjiskip}{kanjiskip}}と同じように,通常ではフォントサイズに比例して変わることはないが,
4345 自然長が \verb+\maxdimen+ の場合が例外である.
4346 %</ja>
4347
4348
4349 \item[\Param{\hypertarget{fld:diffjfm}{differentjfm}}\,=<mode>$^\dagger$]
4350
4351 %<*en>
4352 Specify how glues/kerns between two \textbf{JAchar}s whose JFM (or size) are different.
4353 The allowed arguments are the followings:
4354 %</en>
4355 %<*ja>
4356 JFM(もしくはサイズ)が異なる2つの\textbf{JAchar}の間にグルー/カーンをどのように
4357 入れるかを指定する.
4358 許される値は以下の通り:
4359 %</ja>
4360 \begin{quote}
4361 \texttt{average}, 
4362 \texttt{both}, 
4363 \texttt{large}, 
4364 \texttt{small}, 
4365 \texttt{pleft}, 
4366 \texttt{pright}, 
4367 \texttt{paverage}
4368 \end{quote}
4369 %<*en>
4370 The default value is \texttt{paverage}. \dots
4371 %</en>
4372 %<*ja>
4373 デフォルト値は \texttt{paverage} である.
4374 各々の値による差異の詳細は\ref{ssec-cluster-wa}節の「『右空白』の算出」を参照してほしい.
4375 %</ja>
4376
4377 \item[\Param{jacharrange}\,=<ranges>]
4378 \item[\Param{kansujichar}\,=\{<digit>, <chr\_code>\}$^\ast$] [\verb+\kansujichar+]
4379 \end{list}
4380
4381 \subsection{\texttt{\textbackslash ltjgetparameter}}
4382 \label{ssec-getpar}
4383 %<*en>
4384 \verb+\ltjgetparameter+ is a conteol sequence for acquiring parameters. It
4385 always takes a parameter name as first argument.
4386 %</en>
4387 %<*ja>
4388 \verb+\ltjgetparameter+ はパラメータの値を取得するための命令であり,
4389 常にパラメータの名前を第一引数にとる.
4390 %</ja>
4391 \begin{LTXexample}
4392 \ltjgetparameter{differentjfm},
4393 \ltjgetparameter{autospacing},
4394 \ltjgetparameter{kanjiskip},
4395 \ltjgetparameter{prebreakpenalty}{`)}.
4396 \end{LTXexample}
4397
4398 %<*en>
4399 \emph{The return value of\/ {\normalfont\tt\textbackslash ltjgetparameter} is
4400 always a string}. This is outputted by \texttt{tex.write()}, so any
4401 character other than space~``\texttt{\char32}''~(\texttt{U+0020}) has the category code
4402 12~(other), while the space has 10~(space).
4403 %</en>
4404 %<*ja>
4405 \emph{{\normalfont\tt\textbackslash ltjgetparameter}の戻り値は常に文字列である.}
4406 これは\texttt{tex.write()}によって出力しているためで,空白「\texttt{\char32}」
4407 (\texttt{U+0020})を除いた文字のカテゴリーコードは全て12~(other)となる.
4408 一方,空白のカテゴリーコードは10~(space)である.
4409 %</ja>
4410
4411 \begin{itemize}
4412 \item 
4413 %<*en>
4414 If first argument is one of the
4415 following, no  additional argument is needed.
4416 %</en>
4417 %<*ja>
4418 第1引数が次のいずれかの場合には,追加の引数は必要ない.
4419 %</ja>
4420 \begin{quote}
4421 \sffamily 
4422 jcharwidowpenalty, yjabaselineshift, yalbaselineshift, autospacing, autoxspacing,\\
4423 kanjiskip, xkanjiskip, differentjfm
4424 \end{quote}
4425 %<*en>
4426 Note that \verb+\ltjgetparameter{autospacing}+~and~\verb+\ltjgetparameter{autoxspacing}+
4427 returns 1 or 0, not 
4428 \texttt{true}~nor~\texttt{false}.
4429 %</en>
4430 %<*ja>
4431 \verb+\ltjgetparameter{autospacing}+ と \verb+\ltjgetparameter{autoxspacing}+ は,
4432 \texttt{true}や\texttt{false}を返すの\emph{ではなく},
4433 1と0のいずれかを返すことに注意,
4434 %</ja>
4435
4436 \item 
4437 %<*en>
4438 If first argument is one of the
4439 following, an additional argument---a character code, for example---is needed.
4440 %</en>
4441 %<*ja>
4442 第1引数が次のいずれかの場合には,さらに文字コードを第二引数としてとる.
4443 %</ja>
4444 \begin{quote}
4445 \sffamily 
4446 kcatcode, prebreakpenalty, postbreakpenalty, jaxspmode, alxspmode
4447 \end{quote} 
4448 %<*en>
4449 \verb+\ltjgetparameter{jaxspmode}{...}+~and~\verb+\ltjgetparameter{alxspmode}{...}+
4450 returns 0,~1, 2,~or~3, instead of \texttt{preonly} etc.
4451 %</en>
4452 %<*ja>
4453 \verb+\ltjgetparameter{jaxspmode}{...}+ や \verb+\ltjgetparameter{alxspmode}{...}+\ 
4454 は,\texttt{preonly} などといった文字列ではなく,0から3までの値を返す.
4455 %</ja>
4456
4457 \item
4458 %<*en>
4459 \verb+\ltjgetparameter{jacharrange}{+<range>\verb+}+ returns \texttt{0}
4460 if ``characters which belong to the character range~<range> are \textbf{JAchar}'',
4461 \texttt{1} if ``\dots are \textbf{ALchar}''.
4462 Although there is no character range~$-1$, specifying $-1$ to <range> does not cause an
4463       error (returns 1).
4464 %</en>
4465 %<*ja>
4466 \verb+\ltjgetparameter{jacharrange}{+<range>\verb+}+ は,<range>が\textbf{JAchar}達の
4467 範囲ならば0を,そうでなければ1を返す.「$-1$番の文字範囲」は存在しないが,<range>に$-1$を
4468 指定してもエラーは発生しない(1を返す).
4469 %</ja>
4470
4471 \item
4472 %<*en>
4473 For an integer~<digit> between 0~and~9,
4474      \verb+\ltjgetparameter{kansujichar}{+<digit>\verb+}+ returns the character code
4475 of the result of \verb+\kansuji+<digit>.
4476 %</en>
4477 %<*ja>
4478 0--9の数<digit>に対して,
4479 \verb+\ltjgetparameter{kansujichar}{+<digit>\verb+}+ は,\verb+\kansuji+<digit>で出力され
4480      る文字の文字コードを返す.
4481 %</ja>
4482
4483
4484 \item 
4485 %<*en>
4486 The following parameter names \emph{cannot be specified} in \verb+\ltjgetparameter+.
4487 %</en>
4488 %<*ja>
4489 次のパラメータ名を \verb+\ltjgetparameter+ に指定することはできない.
4490 %</ja>
4491 \begin{quote}
4492 \sffamily 
4493 jatextfont, jascriptfont, jascriptscriptfont, jacharrange
4494 \end{quote}
4495
4496 \item 
4497 %<*en>
4498 \verb+\ltjgetparameter{chartorange}{+<chr\_code>\verb+}+ returns 
4499 the range number which <chr\_code> belongs to
4500 (although there is no parameter named ``chartorange''). 
4501
4502 If <chr\_code> is between 0 and 127, this <chr\_code> does not belong to
4503 any character range. In this case,
4504       \verb+\ltjgetparameter{chartorange}{+<chr\_code>\verb+}+
4505 returns $-1$.
4506
4507 Hence, one can know whether <chr\_code> is \textbf{JAchar} or not
4508 by the following:
4509 %</en>
4510 %<*ja>
4511 \verb+\ltjgetparameter{chartorange}{+<chr\_code>\verb+}+ によって
4512 <chr\_code>の属する文字範囲の番号を知ることができる.
4513
4514 <chr\_code>に0--127の値を指定した場合(このとき,<chr\_code>が属する
4515 文字範囲は存在しない)は$-1$が返る.
4516
4517 そのため,<chr\_code>が\textbf{JAchar}か\textbf{ALchar}かは
4518 次で知ることができる:
4519 %</ja>
4520 \begin{quote}
4521 \ttfamily \verb+\ltjgetparameter{jacharrange}{\ltjgetparameter{chartorange}{+%
4522   <chr\_code>\verb+}}+\\\null\hfill\verb+% 0 if JAchar, 1 if ALchar+
4523 \end{quote}
4524
4525 \end{itemize}
4526
4527
4528
4529
4530 %<en>\section{Other Commands for plain \TeX\ and \LaTeXe}
4531 %<ja>\section{plainでも\LaTeX でも利用可能なその他の命令}
4532 %<en>\subsection{Commands for Compatibility with \pTeX}
4533 %<ja>\subsection{\pTeX 互換用命令}
4534
4535 %<*en>
4536 The following commands are implemented for compatibility with \pTeX.
4537 Note that the former five commands don't support JIS~X~0213, but only JIS~X~0208.
4538 The last \verb+\kansuji+ converts an integer into its Chinese numerals.
4539 %</en>
4540 %<*ja>
4541 以下の命令は\pTeX との互換性のために実装されている.そのため,JIS~X~0213には対応せず,
4542 \pTeX と同じようにJIS~X~0208の範囲しかサポートしていない.
4543 %</ja>
4544 \begin{center}
4545 \verb+\kuten+, \verb+\jis+, \verb+\euc+, \verb+\sjis+, \verb+\jis+, \verb+\kansuji+
4546 \end{center}
4547 %<*en>
4548 These six commands takes an internal integer, and returns a \emph{string}.
4549 %</en>
4550 %<*ja>
4551 これら6命令は内部整数を引数とするが,実行結果は\textbf{文字列}であることに注意.
4552 %</ja>
4553 \begin{LTXexample}
4554 \newcount\hoge
4555 \hoge="2423 %"
4556 \the\hoge, \kansuji\hoge\\
4557 \jis\hoge, \char\jis\hoge\\
4558 \kansuji1701
4559 \end{LTXexample}
4560
4561 %<*en>
4562 To change characters of Chinese numerals for each digit, set \Param{kansujichar} parameter:
4563 \begin{LTXexample}
4564 \ltjsetparameter{kansujichar={1,`壹}}
4565 \ltjsetparameter{kansujichar={7,`漆}}
4566 \ltjsetparameter{kansujichar={0,`零}}
4567 \kansuji1701
4568 \end{LTXexample}
4569 %</en>
4570
4571
4572 %<en>\subsection{\texttt{\textbackslash inhibitglue}}
4573 %<ja>\subsection{\texttt{\textbackslash inhibitglue}}
4574 %<*en>
4575 \verb+\inhibitglue+ suppresses the insertion of \textbf{JAglue}.
4576 The following is an example, using a special JFM that there will be a glue between
4577 the beginning of a box and ``あ'', and also between ``あ''~and~``ウ''.
4578 %</en>
4579 %<*ja>
4580 \verb+\inhibitglue+ は\textbf{JAglue}の挿入を抑制する.
4581 以下は,ボックスの始めと「あ」の間,「あ」「ウ」の間にグルーが入る特別なJFMを用いた例で
4582 ある.
4583 %</ja>
4584
4585 \begin{LTXexample}[width=0.4\textwidth]
4586 \jfont\g=file:KozMinPr6N-Regular.otf:jfm=test \g
4587 \fbox{\hbox{あウあ\inhibitglue ウ}}
4588 \inhibitglue\par\noindent あ1
4589 \par\inhibitglue\noindent あ2
4590 \par\noindent\inhibitglue あ3
4591 \par\hrule\noindent あoff\inhibitglue ice
4592 \end{LTXexample}
4593
4594 %<*en>
4595 With the help of this example, we remark the specification of \verb+\inhibitglue+:
4596 %</en>
4597 %<*ja>
4598 この例を援用して,\verb+\inhibitglue+ の仕様について述べる.
4599 %</ja>
4600 \begin{itemize}
4601 %<*en>
4602 \item The call of \verb+\inhibitglue+ in the (internal) vertical mode is
4603       simply ignored.
4604 %</en>
4605 %<*ja>
4606 \item \verb+\inhibitglue+ の垂直モード中での呼び出しは意味を持たない.
4607 4行目の入力で有効にならないのは,\verb+\inhibitglue+ の時点では垂直モードであり,
4608 \verb+\noindent+ の時点で水平モードになるからである.
4609 %</ja>
4610
4611 %<*en>
4612 \item The call of \verb+\inhibitglue+ in the (restricted) horizontal
4613       mode is only effective on the spot; does not get over boundary of
4614       paragraphs. Moreover, \verb+\inhibitglue+ cancels ligatures and
4615       kernings, as shown in the last line of above example.
4616 %</en>
4617 %<*ja>
4618 \item \verb+\inhibitglue+ の(制限された)水平モード中での呼び出しはその場でのみ
4619   有効であり,段落の境界を乗り越えない.
4620   さらに,\verb+\inhibitglue+ は上の例の最終行のように(欧文における)リガチャとカーニングを
4621   打ち消す.これは,\verb+\inhibitglue+ が内部的には「現在のリスト中にwhatsitノードを
4622   追加する」ことを行なっているからである.
4623 %</ja>
4624
4625 %<*en>
4626 \item The call of \verb+\inhibitglue+ in math mode is just ignored.
4627 %</en>
4628 %<*ja>
4629 \item \verb+\inhibitglue+ を数式モード中で呼び出した場合はただ無視される.
4630 %</ja>
4631
4632 %<*ja>
4633 \item \LaTeX で\LuaTeX-ja を使用する場合は,
4634 \verb+\inhibitglue+ の代わりとして \verb+\<+ を使うことができる.
4635 既に \verb+\<+ が定義されていた場合は,\LuaTeX-ja の読み込みで強制的に上書きされるので
4636 注意すること.
4637 %</ja>
4638 \end{itemize}
4639
4640
4641 \subsection{\texttt{\textbackslash ltjdeclarealtfont}}
4642 \label{ssec-altfont}
4643 %<*en>
4644 Using \verb+\ltjdeclarealtfont+, one can ``compose'' more than one Japanese fonts.
4645 This \verb+\ltjdeclarealtfont+ uses in the following form:
4646 \begin{quote}
4647 \ttfamily \textbackslash ltjdeclarealtfont<base\_font\_cs><alt\_font\_cs>{<range>}
4648 \end{quote}
4649 where  <base\_font\_cs>~and~<alt\_font\_cs> are defined by \verb+\jfont+.
4650 Its meaning is
4651 \begin{quote}
4652 If the current Japanese font is <base\_font\_cs>, characters which belong to <range>
4653 is typeset by another Japanese font <alt\_font\_cs>, instead of <base\_font\_cs>.
4654 \end{quote}
4655
4656 <range> is a comma-separated list of character codes, but also accepts negative integers:
4657 $-n$~($n≥1$) means that all characters of character classes~$n$, with respect to JFM used
4658 by <base\_font\_cs>. Note that characters which do not exist in <alt\_font\_cs> are
4659 ignored.
4660
4661 For example, if \verb+\hoge+ uses \texttt{jfm-ujis.lua}, the standard JFM of \LuaTeX-ja,
4662 then 
4663 \begin{verbatim}
4664 \ltjdeclarealtfont\hoge\piyo{"3000-"30FF, {-1}-{-1}}
4665 \end{verbatim}
4666 does
4667 \begin{quote}
4668 If the current Japanese font is \verb+\hoge+, \texttt{U+3000}--\texttt{U+30FF}
4669 and characters in class~1 (ideographic opening brackets) 
4670 are typeset by \verb+\piyo+.
4671 \end{quote}
4672 %</en>
4673 %<*ja>
4674 \verb+\jfont+ の書式を見ればわかるように,基本的には\LuaTeX-jaにおける1つの和文フォントに
4675 使用出来る「実際のフォント」は1つである.
4676 しかし,\verb+\ltjdeclarealtfont+ を用いると,この原則から外れることができる.
4677
4678 \verb+\ltjdeclarealtfont+ は以下の書式で使用する:
4679 \begin{quote}
4680 \ttfamily \textbackslash ltjdeclarealtfont<base\_font\_cs><alt\_font\_cs>{<range>}
4681 \end{quote}
4682 これは「現在の和文フォント」が<base\_font\_cs>であるとき,
4683 <range>に属する文字は<alt\_font\_cs>を用いて組版される,という意味である.
4684 \begin{itemize}
4685  \item <base\_font\_cs>, <alt\_font\_cs>は
4686 \verb+\jfont+ によって定義された和文フォントである.
4687  \item <range>は文字コードの範囲を表すコンマ区切りのリストであるが,
4688    例外として負数$-n$は「<base\_font\_cs>のJFMの文字クラス$n$に属する全ての文字」
4689    を意味する.
4690
4691 <range>中に<alt\_font\_cs>中に実際には存在しない文字が指定された場合は,
4692 その文字に対する設定は無視される.
4693 \end{itemize}
4694
4695 例えば,\verb+\hoge+ のJFMが\LuaTeX-ja標準の
4696 \ \texttt{jfm-ujis.lua} であった場合,
4697 \begin{verbatim}
4698 \ltjdeclarealtfont\hoge\piyo{"3000-"30FF, {-1}-{-1}}
4699 \end{verbatim}
4700 は「\verb+\hoge+ を利用しているとき,
4701 \texttt{U+3000}--\texttt{U+30FF}と
4702 文字クラス1(開き括弧類)中の文字だけは \verb+\piyo+ を用いる」
4703 ことを設定する.\verb+{-1}-{-1}+ という変わった指定の仕方をしているのは,
4704 普通に \texttt{-1} と指定したのでは正しく$-1$と読み取られないという
4705 マクロの都合による.
4706 %</ja>
4707
4708
4709
4710 %<en>\section{Commands for \LaTeXe}
4711 %<ja>\section{\LaTeXe 用の命令}
4712
4713 %<en>\subsection{Patch for NFSS2}
4714 %<ja>\subsection{NFSS2へのパッチ}
4715 \label{ssec-nfsspat}
4716
4717 \begin{figure}[!tb]
4718 \begin{LTXexample}[pos=b]
4719 \DeclareKanjiFamily{JY3}{edm}{}
4720 \DeclareFontShape{JY3}{edm}{m}{n}    {<-> s*KozMinPr6N-Regular:jfm=ujis;}{}
4721 \DeclareFontShape{JY3}{edm}{m}{green}{<-> s*KozMinPr6N-Regular:jfm=ujis;color=007F00}{}
4722 \DeclareFontShape{JY3}{edm}{m}{blue} {<-> s*KozMinPr6N-Regular:jfm=ujis;color=0000FF}{}
4723 \DeclareAlternateKanjiFont{JY3}{edm}{m}{n}{JY3}{edm}{m}{green}{"4E00-"67FF,{-2}-{-2}}
4724 \DeclareAlternateKanjiFont{JY3}{edm}{m}{n}{JY3}{edm}{m}{blue}{ "6800-"9FFF}
4725 {\kanjifamily{edm}\selectfont
4726 日本国民は、正当に選挙された国会における代表者を通じて行動し、……}
4727 \end{LTXexample}
4728 %<ja>\caption{\texttt{\textbackslash DeclareAlternateKanjiFont} の使用例}
4729 %<en>\caption{An example of \texttt{\textbackslash DeclareAlternateKanjiFont}}
4730 \label{fig:altkanji}
4731 \end{figure}
4732
4733 %<*en>
4734 Japanese patch for NFSS2 in \LuaTeX-ja
4735 is based on \texttt{plfonts.dtx} which plays the same role in \pLaTeXe.
4736 We will describe
4737 commands which are not described in Subsection~\ref{ssec-chgfnt}.
4738 %</en>
4739 %<*ja>
4740 \LuaTeX-jaのNFSS2への日本語パッチは
4741 \pLaTeXe で同様の役割を果たす \texttt{plfonts.dtx} をベースに,
4742 和文エンコーディングの管理等をLuaで書きなおしたものである.
4743 ここでは\ref{ssec-chgfnt}節で述べていなかった命令について
4744 記述しておく.
4745 %</ja>
4746
4747 \begin{cslist}%
4748 \par\smallskip\par\hskip-\leftskip{\bfseries%
4749 %<ja>追加の長さ変数達
4750 %<en>additonal dimensions
4751 }\par
4752
4753 %<*en>
4754 Like \pLaTeXe, \LuaTeX-ja defines the following dimensions 
4755 for information of current Japanese font:
4756 %</en>
4757 %<*ja>
4758 \pLaTeXe と同様に,\LuaTeX-jaは「現在の和文フォントの情報」を格納する長さ変数
4759 %</ja>
4760 {\let\item=\origitem
4761 \begin{quote}
4762  \verb+\cht+~(height), \verb+\cdp+~(depth), \verb+\cHT+~(sum of former two),\\
4763  \verb+\cwd+~(width), \verb+\cvs+~(lineskip), \verb+\chs+~(equals to \verb+\cwd+)
4764 \end{quote}}
4765 %<en>and its \verb+\normalsize+ version:
4766 %<ja>と,その \verb+\normalsize+ 版である
4767 {\let\item=\origitem
4768 \begin{quote}
4769  \verb+\Cht+~(height), \verb+\Cdp+~(depth),
4770  \verb+\Cwd+~(width), \\\verb+\Cvs+~(equals to \verb+\baselineskip+), 
4771  \verb+\Chs+~(equals to \verb+\cwd+)%
4772 %<en>.
4773 \end{quote}}
4774 %<*ja>
4775 を定義している.なお,\verb+\cwd+ と \verb+\zw+,また
4776 \verb+\cHT+ と \verb+\zh+ は一致しない可能性がある.なぜなら,
4777 \verb+\cwd+,~\verb+\cHT+ は「あ」の寸法から決定されるのに対し,
4778 \verb+\zw+ と \verb+\zh+ はJFMに指定された値に過ぎないからである.
4779 %</ja>
4780 %<*en>
4781 Note that \verb+\cwd+~and~\verb+\cHT+ may  differ from \verb+\zw+~and~\verb+\zh+
4782 respectively.
4783 On the one hand the former dimensions are determined from the character ``あ'',
4784 but on the other hand \verb+\zw+~and~\verb+\zh+ are specified by JFM.
4785 %</en>
4786
4787
4788 \item[DeclareYokoKanjiEncoding\{<encoding>\}\{<text-settings>\}\{<math-settings>\}]
4789 \item[DeclareYokoKanjiEncoding\{<encoding>\}\{<text-settings>\}\{<math-settings>\}]
4790
4791 %<*en>
4792 In NFSS2 under \LuaTeX-ja, distinction between alphabetic font families
4793              and Japanese font families are only made by their
4794              encodings. For example, encodings OT1 and T1 are for
4795              alphabetic font families, and a Japanese font family cannot
4796              have these encodings. These command define a new encoding
4797              scheme for Japanese font family.
4798 %</en>
4799 %<*ja>
4800 \LuaTeX-jaのNFSS2においては,欧文フォントファミリと和文フォントファミリは
4801 そのエンコーディングによってのみ区別される.
4802 例えば,OT1とT1のエンコーディングは欧文フォントファミリに対するものであり,
4803 和文フォントファミリはこれらのエンコーディングを持つことはできない.
4804 これらコマンドは横組用・縦組用和文フォントのための新しいエンコーディングを
4805 それぞれ定義する.
4806 %</ja>
4807
4808 \item[DeclareKanjiEncodingDefaults\{<text-settings>\}\{<math-settings>\}]
4809 \item[DeclareKanjiSubstitution\{<encoding>\}\{<family>\}\{<series>\}\{<shape>\}]
4810 \item[DeclareErrorKanjiFont\{<encoding>\}\{<family>\}\{<series>\}\{<shape>\}\{<size>\}]
4811
4812 %<*en>
4813 The above 3~commands are just the counterparts for \verb+\DeclareFontEncodingDefaults+ and~others.
4814 %</en>
4815 %<*ja>
4816 上記3つのコマンドはちょうど \verb+\DeclareFontEncodingDefaults+ などに対応するものである.
4817 %</ja>
4818
4819 \item[reDeclareMathAlphabet\{<unified-cmd>\}\{<al-cmd>\}\{<ja-cmd>\}]
4820
4821 % ToDo: en
4822 %<*ja>
4823 和文・欧文の数式用フォントファミリを一度に変更する命令を作成する.
4824 具体的には,欧文数式用フォントファミリ変更の命令<al-cmd>(\verb+\mathrm+ 等)と,和文数式用フォ
4825              ントファミリ変更の命令<ja-cmd>(\verb+\mathmc+ 等)の2つを同時に行う命令として
4826              <unified-cmd>を(再)定義する.実際の使用では<unified-cmd>と
4827              <al-cmd>に同じものを指定する,すなわち,<al-cmd>で和文側も変
4828              更させるようにするのが一般的と思われる.
4829
4830 本命令は
4831 {\let\item=\origitem
4832 \begin{center}\tt
4833 <unified-cmd>\{<arg>\}\quad$\longrightarrow$\quad
4834 (<al-cmd>の1段展開結果)\{<ja-cmd>の1段展開結果)\{<arg>\}\}
4835 \end{center}
4836 と定義を行うので,使用には注意が必要である:
4837 \vspace{-\medskipamount}
4838 %<en>\advance\linewidth-2em
4839 %<ja>\advance\linewidth-2\zw
4840 \begin{itemize}
4841 \item <al-cmd>,~<ja-cmd>は既に定義されていなければならない.
4842       \verb+\reDeclareMathAlphabet+\\の後に
4843 両命令の内容を再定義しても,<unified-cmd>の内容にそれは反映されない.
4844 \item <al-cmd>,~<ja-cmd>に\verb+\@mathrm+などと \texttt{@} をつけた命令を指定した時の動作は保証できない.
4845 \end{itemize}}
4846 %</ja>
4847
4848 \item[DeclareRelationFont\{<ja-encoding>\}\{<ja-family>\}\{<ja-series>\}\{<ja-shape>\}\\*
4849   \null\hfill\{<al-encoding>\}\{<al-family>\}\{<al-series>\}\{<al-shape>\}]
4850 %<*en>
4851 This command sets the ``accompanied'' alphabetic font family (given by the latter 4~arguments)
4852 with respect to a Japanese font family given by the former 4~arguments.
4853 %</en>
4854 %<*ja>
4855 いわゆる「従属欧文」を設定するための命令である.前半の4引数で表される和文フォントファミリに対して,
4856 そのフォントに対応する「従属欧文」のフォントファミリを後半の4引数により与える.
4857 %</ja>
4858 \item[SetRelationFont]
4859 %<*en>
4860 This command is almost same as \verb+\DeclareRelationFont+, except that this command does a local
4861 assignment, where \verb+\DeclareRelationFont+ does a global assignment.
4862 %</en>
4863 %<*ja>
4864 このコマンドは \verb+\DeclareRelationFont+ とローカルな指定であることを除いて
4865 ほとんど同じである(\verb+\DeclareRelationFont+ はグローバル).
4866 %</ja>
4867
4868 \item[userelfont]
4869 %<*en>
4870 Change current alphabetic font encoding/family/\dots\ to the `accompanied' alphabetic
4871              font family with respect to current Japanese font family,
4872              which was set by
4873              \verb+\DeclareRelationFont+ or \verb+\SetRelationFont+.
4874 Like \verb+\fontfamily+, \verb+\selectfont+ is required to take an effect.
4875 %</en>
4876 %<*ja>
4877 現在の欧文フォントのエンコーディング/ファミリ/…… を,
4878 \verb+\DeclareRelationFont+ か \verb+\SetRelationFont+ で指定された
4879 現在の和文フォントファミリに対応する「従属欧文」フォントファミリに変更する.
4880 \verb+\fontfamily+ のように,有効にするためには \verb+\selectfont+ が必要である.
4881 %</ja>
4882
4883 \item[adjustbaseline]
4884 %<*en>
4885 In \pLaTeXe, \verb+\adjustbaseline+ sets \verb+\tbaselineshift+ 
4886 to match the vertical center of ``M'' and that of ``あ''  in vertical typesetting:
4887 \[
4888 \text{\ttfamily \textbackslash tbaselineshift} \leftarrow 
4889 \frac{(h_{\text{M}}+d_{\text{M}}) - (h_{\text{あ}}+d_{\text{あ}})}2
4890   + d_{\text{あ}} - d_{\text{M}},
4891 \]
4892 where $h_{a}$~and~$d_{a}$ denote the height of ``$a$'' and the depth, respectively.
4893 In \LuaTeX-ja, this \verb+\adjustbaseline+ does same task.
4894 %</en>
4895 %<*ja>
4896 \pLaTeXe では,\verb+\adjustbaseline+ は縦書時に「M」と「あ」の中心線を一致させるために,
4897 \verb+\tbaselineshift+ を設定する役割を持っていた:
4898 \[
4899 \text{\ttfamily \textbackslash tbaselineshift} \leftarrow 
4900 \frac{(h_{\text{M}}+d_{\text{M}}) - (h_{\text{あ}}+d_{\text{あ}})}2
4901   + d_{\text{あ}} - d_{\text{M}},
4902 \]
4903 ここで,$h_{a}$,~$d_{a}$はそれぞれ「$a$」の高さ・深さを表す.
4904 \LuaTeX-jaにおいても\verb+\adjustbaseline+ は同様の処理を行っている.
4905 %</ja>
4906
4907 \item[fontfamily\{<family>\}]
4908 %<*en>
4909 As in \LaTeXe, this command changes current font family (alphabetic, Japanese,~\emph{or both})
4910 to <family>. Which family will be changed is determined as follows:
4911 %</en>
4912 %<*ja>
4913 元々の\LaTeXe におけるものと同様に,このコマンドは現在のフォントファミリ(欧文,
4914 和文,\emph{もしくは両方})を<family>に変更する.
4915 どのファミリが変更されるかは以下のようにして決定される:
4916 %</ja>
4917 {\let\item\origitem
4918 %<en>\advance\linewidth-2em
4919 %<ja>\advance\linewidth-2\zw
4920 \vspace{-\medskipamount}
4921 \begin{itemize}
4922 %<*en>
4923 \item Let current encoding scheme for Japanese fonts be
4924       <ja-enc>. Current Japanese font family will be changed to
4925       <family>, if one of the following two conditions is met:
4926 %</en>
4927 %<*ja>
4928 \item 現在の和文フォントに対するエンコーディングが<ja-enc>であるとしよう.
4929   現在の和文フォントファミリは,以下の2つの条件のうちの1つが満たされているときに
4930   <family>に変更される:
4931 %</ja>
4932 \begin{itemize}
4933 %<*en>
4934 \item The family <family> under the encoding <ja-enc> has been already defined by
4935       \verb+\DeclareKanijFamily+.
4936 %</en>
4937 %<*ja>
4938 \item エンコーディング<ja-enc>におけるファミリ<family>が
4939 既に \verb+\DeclareKanjiFamily+ によって定義されている.
4940 %</ja>
4941 %<*en>
4942 \item A font definition named \texttt{<ja-enc><family>.fd} (the file name is
4943       all lowercase) exists.
4944 %</en>
4945 %<*ja>
4946 \item フォント定義ファイル\texttt{<ja-enc><family>.fd}(ファイル名は全て小文字)が存在する.
4947 %</ja>
4948 \end{itemize}
4949 %<*en>
4950 \item Let current encoding scheme for alphabetic fonts be
4951       <al-enc>. For alphabetic font family, the criterion as above is used.
4952 %</en>
4953 %<*ja>
4954 \item 現在の欧文フォントに対するエンコーディングを<al-enc>とする.
4955   欧文フォントファミリに対しても,上記の基準が用いられる.
4956 %</ja>
4957 %<*en>
4958 \item There is a case which none of the above applies, that is, the font
4959       family named <family> doesn't seem to be defined neither under the
4960       encoding <ja-enc>, nor under <al-enc>.
4961 In this case, the default family for font substitution is used for
4962       alphabetic and Japanese fonts. Note that current encoding will not
4963       be set to <family>, unlike the original implementation in \LaTeX.
4964 %</en>
4965 %<*ja>
4966 \item 上記のいずれもが適用されない,つまり<family>が<ja-enc>と<al-enc>の
4967   どちらでも定義されないような場合がある.
4968   この場合,代替フォントに用いられるデフォルトのフォントファミリが欧文フォントと
4969   和文フォントに用いられる.\LaTeX のオリジナルの実装とは異なり,
4970   現在のエンコーディングは<family>には設定されないことに注意する.
4971 %</ja>
4972 \end{itemize}%
4973 %<en>\vspace{-\medskipamount}
4974 }
4975
4976 \item[DeclareAlternateKanjiFont\{<base-encoding>\}\{<base-family>\}\{<base-series>\}\{<base-shape>\}\\
4977   \null\hfill\{<alt-encoding>\}\{<alt-family>\}\{<alt-series>\}\{<alt-shape>\}\{<range>\}]
4978 %<*ja>
4979 \ref{ssec-altfont}節の\
4980 \verb+\ltjdeclarealtfont+ と同様に,前半の4引数の
4981 和文フォント(基底フォント)のうち<range>中の文字を
4982 第5--第8引数の和文フォントを使って組むように指示する.
4983 使用例を図\nobreak\ref{fig:altkanji}に載せた.
4984
4985 {\let\item\origitem
4986 %<en>\advance\linewidth-2em
4987 %<ja>\advance\linewidth-2\zw
4988 \vspace{-\medskipamount}
4989 \begin{itemize}
4990  \item 
4991 \verb+\ltjdeclarealtfont+ では基底フォント・置き換え先和文フォントはあらかじめ定義されてい
4992              ないといけない(その代わり即時発効)であったが,
4993 \verb+\DeclareAlternateKanjiFont+ の設定が
4994 実際に効力が発揮するのは,書体変更やサイズ変更を行った時,
4995 あるいは(これらを含むが)\verb+\selectfont+ が実行された時である.
4996  \item 
4997 段落やhboxの最後での設定値が段落/hbox全体にわたって通用する点や,
4998 <range>に負数$-n$を指定した場合,それが「基底フォントの文字クラス$n$に属する文字全体」
4999 と解釈されるのは \verb+\ltjdeclarealtfont+ と同じである.
5000 \end{itemize}%
5001 }
5002 %</ja>
5003 %<*en>
5004 As \verb+\ltjdeclarealtfont+~(Subsection~\ref{ssec-altfont}), 
5005 characters in <range> of the Japanese font (we say the \emph{base font})
5006 which specified by first 4 arguments are typeset 
5007 by the Japanese font which specified by fifth to eighth arguments
5008 (we say the \emph{alternate font}).
5009 An example is shown in Figure~\ref{fig:altkanji}.
5010
5011 {\let\item\origitem
5012 %<en>\advance\linewidth-2em
5013 %<ja>\advance\linewidth-2\zw
5014 \vspace{-\medskipamount}
5015 \begin{itemize}
5016  \item 
5017 In \verb+\ltjdeclarealtfont+, the base font and the alternate font must be already defined.
5018 But this \verb+\DeclareAlternateKanjiFont+ is not so.
5019 In other words, \verb+\DeclareAlternateKanjiFont+ is effective only after
5020 current Japanese font is changed, or only after \verb+\selectfont+ is executed.
5021  \item \dots
5022 \end{itemize}%
5023 \vspace{-\medskipamount}
5024 }
5025 %</en>
5026 \end{cslist}
5027
5028 %<*en>
5029 As closing this subsection, we shall introduce an example of
5030 \verb+\SetRelationFont+ and \verb+\userelfont+:
5031 %</en>
5032 %<*ja>
5033 この節の終わりに,\verb+\SetRelationFont+ と \verb+\userelfont+ の例を
5034 紹介しておこう.\verb+\userelfont+ の使用によって,「abc」の部分のフォントが
5035 Avant Garde (OT1/pag/m/n) に変わっていることがわかる.
5036 %</ja>
5037 \begin{LTXexample}[width=0.3\textwidth]
5038 \makeatletter
5039 \SetRelationFont{JY3}{\k@family}{m}{n}{OT1}{pag}{m}{n}
5040   % \k@family: current Japanese font family
5041 \userelfont\selectfont あいうabc
5042 \end{LTXexample}
5043
5044 %<*en>
5045 \section{Addons}
5046 \LuaTeX-ja has several addon packages. 
5047 These addons are written as \LaTeX\ packages, but 
5048 \Pkg{luatexja-otf} and~\Pkg{luatexja-adjust} can be loaded in plain \LuaTeX\
5049 by \verb+\input+.
5050 %</en>
5051 %<*ja>
5052 \section{拡張}
5053 \LuaTeX-jaには(動作には必須ではないが)自由に読み込める拡張が付属している.
5054 これらは\LaTeX のパッケージとして制作しているが,
5055 \Pkg{luatexja-otf}と\Pkg{luatexja-adjust}についてはplain \LuaTeX でも\ 
5056 \verb+\input+ で読み込み可能である.
5057 %</ja>
5058 \subsection{\texttt{luatexja-fontspec.sty}}
5059 \label{ssec-fontspec2}
5060 %<*en>
5061 As described in Subsection~\ref{ssec-fontspec}, this optional package
5062 provides the counterparts for several commands defined in the
5063 \Pkg{fontspec} package.
5064 In addition to OpenType font features in the original \Pkg{fontspec},
5065 the following ``font features'' specifications are allowed for
5066 the commands of Japanese version:
5067 %</en>
5068 %<*ja>
5069 \ref{ssec-fontspec}節で述べたように,この追加パッケージは\Pkg{fontspec}
5070 パッケージで定義されているコマンドに対応する和文フォント用のコマンドを提供する.
5071 \Pkg{fontspec}パッケージで指定可能な各種font featureに加えて,和文版のコマンドには
5072 以下の``font feature''を指定することができる:
5073 %</ja>
5074
5075
5076 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}\advance\leftmargin1\zw}
5077 \item[CID=<name>]
5078 \item[JFM=<name>]
5079 \item[JFM-var=<name>] \
5080
5081 %<*en>
5082 These 3 keys correspond to \texttt{cid}, \texttt{jfm} and
5083 \texttt{jfmvar} keys for \verb+\jfont+ respectively.
5084 \texttt{CID} is effective only when with \texttt{NoEmbed}
5085 described below.
5086 See Subsections~\ref{ssec-jfont} and \ref{ssec-psft} for details.
5087 %</en>
5088 %<*ja>
5089 これら3つのキーはそれぞれ \verb+\jfont+ に対する
5090 \texttt{cid}, \texttt{jfm}, \texttt{jfmvar}キーとそれぞれ対応する.
5091 \texttt{CID} は下の \texttt{NoEmbed} と合わせて用いられたときのみ有効である.
5092 \verb+\jfont+ プリミティブに対する
5093 \texttt{cid}, \texttt{jfm}, \texttt{jfmvar}キーの詳細は\ref{ssec-jfont}節
5094              と\ref{ssec-psft}節を参照.
5095 %</ja>
5096
5097 \item[NoEmbed]
5098 %<*en>
5099 By specifying this key, one can use ``name-only'' Japanese font which
5100 will not be embedded in the output PDF file. See Subsection~\ref{ssec-psft}.
5101 %</en>
5102 %<*ja>
5103 これを指定することで,PDFに埋め込まれない「名前だけ」のフォントを指定することが
5104 できる.\ref{ssec-psft}節を参照.
5105 %</ja>
5106
5107
5108 \begin{figure}[!tb]
5109 \begin{LTXexample}[pos=b]
5110 \jfontspec[
5111   AltFont={
5112     {Range="4E00-"67FF, Color=007F00},
5113     {Range="6800-"9EFF, Color=0000FF},
5114     {Range="3040-"306F, Font=KozGoPr6N-Regular},
5115   }
5116 ]{KozMinPr6N-Regular}
5117 日本国民は、正当に選挙された国会における代表者を通じて行動し、われらとわれらの子孫のために、
5118 諸国民との協和による成果と、わが国全土にわたつて自由のもたらす恵沢を確保し、……
5119 \end{LTXexample}
5120 %<ja>\caption{\texttt{AltFont} の使用例}
5121 %<en>\caption{An example of \texttt{AltFont}}
5122 \label{fig:altkanji-fontspec}
5123 \end{figure}
5124
5125 \item[AltFont]\ 
5126
5127 %<*en>
5128 As \verb+\ltjdeclarealtfont+~(Subsection~\ref{ssec-altfont}) and
5129 \verb+\DeclareAlternateKanjiFont+~(Subsection~\ref{ssec-nfsspat}),
5130 with this key, one can typeset some Japanese characters 
5131 by a different font and/or using different features.
5132 The \texttt{AltFont} feature takes a comma-separated list of comma-separated lists,
5133 as the following:
5134 %</en>
5135 %<*ja>
5136 \ref{ssec-altfont}節の \verb+\ltjdeclarealtfont+ や,
5137 \ref{ssec-nfsspat}節の \verb+\DeclareAlternateKanjiFont+ と同様に,
5138 このキーを用いると一部の文字を異なったフォントやfont featureを使って組むことができる.
5139 \texttt{AltFont} に指定する値は,次のように二重のコンマ区切りリストである:
5140 %</ja>
5141 \begin{lstlisting}[escapechar=\#]
5142 AltFont = {
5143   ...
5144   { Range=#\LARG range>#, #\LARG features>#},
5145   { Range=#\LARG range>#, Font=#\LARG font~name>#, #\LARG features># },
5146   { Range=#\LARG range>#, Font=#\LARG font~name># },
5147   ...
5148 }
5149 \end{lstlisting}
5150 %<*en>
5151 Each sublist should have the \texttt{Range} key
5152 (sublist which does not contain \texttt{Range} key is simply ignored).
5153 A demonstrartion is shown in Figure~\ref{fig:altkanji-fontspec}.
5154 %</en>
5155 %<*ja>
5156 各部分リストには \texttt{Range} キーが必須である(含まれない部分リストは
5157 単純に無視される).
5158 指定例は図\ref{fig:altkanji-fontspec}に示した.
5159 %</ja>
5160 \end{list}
5161
5162 %<*ja>
5163 なお,\Pkg{luatexja-fontspec} 読み込み時には和文フォント定義ファイル%
5164 \texttt{<ja-enc><family>.fd}は全く参照されなくなる.
5165 %</ja>
5166
5167
5168 \subsection{\texttt{luatexja-otf.sty}}
5169 \label{ssec-ltjotf}
5170 %<*en>
5171 This optional package supports typesetting characters in
5172 Adobe-Japan1 character collection 
5173 (or other CID character collecton, if the font is supported). 
5174 The package \Pkg{luatexja-otf} offers the following 2~low-level
5175 commands:
5176 %</en>
5177 %<*ja>
5178 この追加パッケージはAdobe-Japan1(フォント自身が持っていれば,
5179 別のCID文字セットでも可)の文字の出力をサポートする.
5180 \Pkg{luatexja-otf}は以下の2つの低レベルコマンドを提供する:
5181 %</ja>
5182 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}\advance\leftmargin1\zw}
5183 \item[\textbackslash CID\{<number>\}]
5184 %<*en>
5185 Typeset a character whose CID number is <number>.
5186 %</en>
5187 %<*ja>
5188 CID番号が<number>の文字を出力する.
5189 %</ja>
5190
5191 \item[\textbackslash UTF\{<hex\_number>\}]
5192 %<*en>
5193 Typeset a character whose character code is <hex\_number> (in hexadecimal).
5194 This command is similar to \verb+\char"+<hex\_number>,\ %"
5195 but please remind remarks below.
5196 %</en>
5197 %<*ja>
5198 文字コードが(16進で)<hex\_number>の文字を出力する.
5199 このコマンドは \verb+\char"+<hex\_number>と似ているが,下の記述に注意すること.%"
5200 %</ja>
5201 \end{list}
5202
5203 %<*ja>
5204 このパッケージは,\texttt{ajmacros.sty}(\Pkg{otf}パッケージ付属のマクロ集,井上浩一氏作)から
5205 漢字コードをUTF8にしたり,plain \LuaTeX でも利用可能するという
5206 修正を加えた \texttt{luatexja-ajmacros.sty} も自動的に読み込む.
5207 そのため,マクロ集にある \verb+\aj半角+ などのマクロもそのまま使用可能である.
5208 %</ja>
5209
5210 %<en>\paragraph{Remarks}
5211 %<ja>\paragraph{注意}
5212 %<*en>
5213 Characters by \verb+\CID+ and \verb+\UTF+ commands are different from
5214 ordinary characters in the following points:
5215 %</en>
5216 %<*ja>
5217 \verb+\CID+ と \verb+\UTF+ コマンドによって出力される文字は
5218 以下の点で通常の文字と異なる:
5219 %</ja>
5220 \begin{itemize}
5221 %<*en>
5222 \item Always treated as \textbf{JAchar}s.
5223 %</en>
5224 %<*ja>
5225 \item 常に\textbf{JAchar}として扱われる.
5226 %</ja>
5227 %<*en>
5228 \item Processing codes for supporting OpenType features (\textit{e.g.},
5229       glyph replacement and kerning) by the \Pkg{luaotfload} package
5230       is not performed to these characters.
5231 %</en>
5232 %<*ja>
5233 \item OpenType feature(例えばグリフ置換やカーニング)をサポートするための
5234   \Pkg{luaotfload}パッケージのコードはこれらの文字には働かない.
5235 %</ja>
5236 \end{itemize}
5237
5238 %<en>\paragraph{Additional syntax of JFM}
5239 %<ja>\paragraph{JFMへの記法の追加}
5240
5241 %<*en>
5242 The package \Pkg{luatexja-otf} extends the syntax of JFM; the entries of \texttt{
5243 chars} table in JFM now allows a string in the form
5244 \verb+'AJ1-xxx'+, which stands for the character
5245 whose CID number in Adobe-Japan1 is \verb+xxx+.
5246
5247 This extened notation is used in the standard JFM \texttt{jfm-ujis.lua}
5248 to typeset halfwidth Hiragana glyphs (CID~516--598) in halfwidth.
5249 %</en>
5250 %<*ja>
5251 \Pkg{luatexja-otf}パッケージを読み込むと,
5252 JFMの\texttt{chars}テーブルのエントリとして \verb+'AJ1-xxx'+ の形の文字列が
5253 使えるようになる.これはAdobe-Japan1におけるCID番号が \verb+xxx+ の文字を表す.
5254
5255 この拡張記法は,標準JFM~\texttt{jfm-ujis.lua}で,半角ひらがなのグリフ(CID~516--598)を
5256 正しく半角幅で組むために利用されている.
5257 %</ja>
5258
5259 %<*en>
5260 \paragraph{IVS support}
5261 Recent fonts support Ideographic Variation Selector (IVS).
5262 It seems that \Pkg{luaotfload} and \Pkg{fontspec} packages do not support
5263 IVS, so we implemented IVS support in \Pkg{luatexja-otf}.
5264 \emph{IVS support is experimental; if you want to enable this, load
5265 \Pkg{luatexja-otf} and execute the following:}
5266 %</en>
5267 %<*ja>
5268 \paragraph{IVSサポート}
5269 最近のOpenTypeフォントやTrueTypeフォントには,
5270 \texttt{U+E0100}--\texttt{U+E01EF}の範囲の「文字」
5271 (漢字用異体字セレクタ)を後置することによって
5272 字形を指定する仕組み(IVS)が含まれている.
5273 執筆時点の2013年12月では,\Pkg{luaotfload}や\Pkg{fontspec}パッケージ類は
5274 IVSに対応してはいないようである.これらのパッケージで対応してくれるのが理想的だが,
5275 それまでのつなぎとして,\Pkg{luatexja-otf}パッケージ内にIVS対応を仕込んでおいた.
5276
5277 \medskip
5278
5279 \emph{IVS対応は試験的なものである.
5280 有効にするには,\Pkg{luatexja-otf}パッケージを読み込んだ上で以下の命令を実行する%
5281 \footnote{この命令を2回以上実行しても意味がない.}:}
5282 %</ja>
5283 \begin{verbatim}
5284 \directlua{luatexja.otf.enable_ivs()}
5285 \end{verbatim}
5286 %<ja> すると,上の命令を実行した箇所以降では,以下のようにIVSによる字形指定が有効となる.
5287 %<en> After executing the command above, you can use IVS like the following:
5288 \begin{LTXexample}
5289 \Large
5290 \jfontspec{KozMinPr6N-Regular}
5291 奈良県葛󠄀城市と,東京都葛󠄁飾区.\\
5292 こんにちは,渡
5293 邉󠄀邉󠄁邉󠄂邉󠄃邉󠄄
5294 邉󠄅邉󠄆邉󠄇邉󠄈邉󠄉
5295 邉󠄊邉󠄋邉󠄌邉󠄍邉󠄎
5296 さん.
5297 \end{LTXexample}
5298 %<*ja>
5299 左上側の入力においては,漢字用異体字セレクタを明示するため,
5300 例えばVariation~Selector~18 (\texttt{U+E0101})を\IVSB{18}のように表記している.
5301 %</ja>
5302 \medskip
5303
5304 %<*en>
5305 Specifying glyph variants by IVS precedes glyph replacement by font features.
5306 For example, only ``葛'' in ``葛西'' is changed by font features
5307 \texttt{jp78}~or~\texttt{jp90}, which does not followed by any variation selector.
5308 %</en>
5309 %<*ja>
5310 また,IVSによる字形指定は,font featureによるそれに優先されることとした.
5311 下の例において,\texttt{jp78}, \texttt{jp90} 指定で字形が変化した文字は
5312 異体字セレクタが続いていない「葛西」中の「葛」のみである.
5313 %</ja>
5314 \begin{LTXexample}
5315  \def\TEST#1{%
5316    {\jfontspec[#1]{KozMinPr6N-Regular}%
5317    葛󠄀城市,葛󠄁飾区,葛西}\\}
5318  指定なし:\TEST{}
5319  \texttt{jp78}:\TEST{CJKShape=JIS1978}
5320  \texttt{jp90}:\TEST{CJKShape=JIS1990}
5321 \end{LTXexample}
5322
5323 %<*ja>
5324 現状では,\TeX 側のインターフェースとなる \Pkg{luatexja-otf.sty} は一切変更していない
5325 ので,ZRさんによる\Pkg{PXipamjm}パッケージ%
5326 \footnote{\url{https://github.com/zr-tex8r/PXipamjm}. 説明は彼のブログ記事
5327 「pxipamjm パッケージの説明書のような何か(\url{http://d.hatena.ne.jp/zrbabbler/20131221})」
5328 にある.}
5329 にあるような気の利いた命令はまだない.
5330 異体字の一覧表示を行いたい場合は,gitリポジトリ内の \texttt{test/test19-ivs.tex} 中にある
5331 Lua・\TeX コードが参考になるだろう.
5332 %</ja>
5333
5334
5335 \subsection{\texttt{luatexja-adjust.sty}}
5336 \label{ssec-adj}
5337 \begin{figure}[t]
5338 \def\sq{%
5339   \hbox to 1\zw{\hss\fboxsep=-.5\fboxrule\fbox{%
5340    \hskip\dimexpr-.5\zw-.2pt\vrule width.4pt height.08\zw depth.12\zw%
5341   \hskip\dimexpr.5\zw-.2pt\relax}\hss}}
5342 \def\sb{\hbox to 1\zw{\hss\fboxsep=-.5\fboxrule\fbox{%
5343   ■\hskip\dimexpr-.5\zw-.2pt\vrule width.4pt height.08\zw depth.12\zw%
5344   \hskip\dimexpr.5\zw-.2pt\relax}\hss}}
5345 \newbox\gridbox
5346 \def\outbox#1{{\Large%
5347   \ltjsetparameter{kanjiskip=0pt plus .2\zw minus .2\zw}%
5348   \setbox\gridbox=\hbox to 20\zw{\sq\sq\sq\sq\sb\sq\sq\sq\sq\sb\sq\sq\sq\sq\sb\sq\sq\sq\sq\sb}%
5349   \hbox{\textcolor{cyan!50!white}{\copy\gridbox}\hskip-20\zw%
5350   \vbox{\hsize=20\zw\noindent\leftskip0pt\rightskip0pt\parfillskip0pt#1}\vrule}%
5351 }}
5352
5353 {\centering
5354 \begin{tabular}{lc}
5355 \toprule
5356 no adjustment&\outbox{以上の原理は,「包除原理」とよく呼ばれるが\hskip-.5\zw\null}\\
5357 without priority&%
5358 \ltjdisableadjust
5359 \outbox{以上の原理は,「包除原理」とよく呼ばれるが}%
5360 \ltjenableadjust\\
5361 with priority&%
5362 \outbox{以上の原理は,「包除原理」とよく呼ばれるが}
5363 %<en>\ltjdisableadjust
5364 \\
5365 \bottomrule
5366 \end{tabular}\par}
5367 \smallskip
5368
5369 Note: the value of 
5370 \Param{\hyperlink{fld:kanjiskip}{kanjiskip}} is 0\,pt${}^{+1/5\,\mathrm{em}}_{-1/5\,\mathrm{em}}$ in this figure,
5371 for making the difference obvious.
5372 %<ja>\caption{行長調整}\label{fig-adj}
5373 %<en>\caption{Line adjustment}\label{fig-adj}
5374 \end{figure}
5375
5376
5377 %<*en>
5378 (see Japanese version of this manual)
5379 %</en>
5380 %<*ja>
5381 \pTeX では,行長調整において優先度の概念が存在しなかったため,図
5382 \ref{fig-adj}上段における半角分の半端は,図\ref{fig-adj}中段のように,鍵
5383 括弧周辺の空白と和文間空白(\Param{\hyperlink{fld:kanjiskip}{kanjiskip}})の両方によって負担される.し
5384 かし,「日本語組版処理の要件」\cite{jlreq}やJIS~X~4051~\cite{x4051}におい
5385 ては,このような状況では半端は鍵括弧周辺の空白のみで負担し,その他の和文
5386 文字はベタ組で組まれる(図\ref{fig-adj}下段)ことになっている.この追加
5387 パッケージは\cite{jlreq}や\cite{x4051}における規定のような,優先順位付き
5388 の行長調整を提供する.詳細な仕様については\ref{sec-adjspec}章を参照してほしい.
5389 \begin{itemize}
5390  \item 優先度付き行長調整は,段落を行分割した後に個々の行について行われるものである.
5391 そのため,行分割の位置は変化することはない.
5392
5393 また,\verb+\hbox to ... {...}+ のような「幅が指定されたhbox」では無効である.
5394  \item 優先度付き行長調整を行うと,和文処理グルーの自然長は変化しないが,伸び量や縮み量は
5395 一般に変化する.そのため,既に組まれた段落を \verb+\unhbox+ などを利用して組み直す処理を
5396 行う場合には注意が必要である.
5397 \end{itemize}
5398
5399
5400 \Pkg{luatexja-adjust} は,以下の命令を提供する.これらはすべてグローバルに効力を発揮する.
5401
5402 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}\advance\leftmargin1\zw}
5403 \item[\textbackslash ltjdisableadjust]
5404 優先順位付きの行長調整を無効化する.
5405
5406 \item[\textbackslash ltjenableadjust]
5407 優先順位付きの行長調整を有効化する.
5408
5409 \item[\textsf{adjust}\,=<bool>] \verb+\ltjsetparameter+ で指定可能な追加パラメータであり,
5410 <bool>が\textit{true}なら \verb+\ltjenableadjust+ を,
5411 そうでなければ \verb+\ltjdisableadjust+ を実行する.
5412 \end{list}
5413 %</ja>
5414
5415 \subsection{\texttt{luatexja-ruby.sty}}
5416 %<*en>
5417 This addon package provides functionality of ``ruby'' (\emph{furigana}) annotations 
5418 using callbacks of \LuaTeX-ja. 
5419 There is no detailed manual of \Pkg{luatexja-ruby.sty} in English.
5420 (Japanese manual is another PDF file, \url{luatexja-ruby.pdf}.) 
5421 %</en>
5422 %<*ja>
5423 この追加パッケージは,\LuaTeX-jaの機能を利用したルビ(振り仮名)の組版機能を提供する.
5424 前後の文字種に応じた前後への自動進入や,
5425 行頭形・行中形・行末形の自動的な使い分けが特徴である.
5426
5427 ルビ組版に設定可能な項目や注意事項が多いため,本追加パッケージの詳細な説明は
5428 使用例と共に \url{luatexja-ruby.pdf}\ という別ファイルに載せている.
5429 この節では簡単な使用方法のみ述べる.
5430 %</ja>
5431
5432 \begin{description}
5433 %<*en>
5434  \item[Group-ruby]
5435 By default, ruby characters (the second argument of \verb+\ruby+)
5436 are attached to base characters (the first argument), as one object.
5437 This type of ruby is called \emph{group-ruby}.
5438 %</en>
5439 %<*ja>
5440  \item[グループルビ] 標準ではグループルビの形で組まれる.第1引数に親文字,
5441 第2引数にルビを記述する.
5442 %</ja>
5443 \begin{LTXexample}[width=0.3\textwidth]
5444 東西線\ruby{妙典}{みようでん}駅は……\\
5445 東西線の\ruby{妙典}{みようでん}駅は……\\
5446 東西線の\ruby{妙典}{みようでん}という駅……\\
5447 東西線\ruby{葛西}{かさい}駅は……
5448 \end{LTXexample}
5449 %<*en> 
5450 As the above example, ruby hangover is allowed on the Hiragana before/after 
5451 its base characters.
5452 %</en>
5453 %<ja> この例のように,標準では前後の平仮名にルビ全角までかかるようになっている.
5454
5455 %<*en>
5456 \item[Mono-ruby]
5457 To attach ruby characters to each base characters (\emph{mono-ruby}),
5458 one should use \verb+\ruby+ multiple times:
5459 %</en>
5460 %<*ja>
5461  \item[モノルビ] 親文字を1文字にするとモノルビとなる.
5462 2文字以上の熟語をモノルビの形で組みたい場合は,面倒でも
5463 その数だけ \verb+\ruby+ を書く必要がある.
5464 %</ja>
5465 \begin{LTXexample}[width=0.3\textwidth]
5466 東西線の\ruby{妙}{みよう}\ruby{典}{でん}駅は……
5467 \end{LTXexample}
5468
5469 %<*en>
5470  \item[Jukugo-ruby]
5471 Vertical bar~\verb+|+ denotes a boundary of \emph{groups}.
5472 %</en>
5473 %<*ja>
5474  \item[熟語ルビ] 引数内の縦棒 \verb+|+ はグループの区切りを表し,
5475 複数グループのルビは熟語ルビとして組まれる.
5476 \cite{x4051}にあるように,
5477 どのグループでも「親文字」が対応するルビ以上の長さの場合は
5478 各グループごとに,そうでないときは全体をまとめて1つのグループルビとして組まれる.
5479 \cite{jlreq}で規定されている組み方とは異なるので注意.
5480 %</ja>
5481 \begin{LTXexample}
5482 \ruby{妙|典}{みよう|でん}\
5483 \ruby{葛|西}{か|さい}\
5484 \ruby{神楽|坂}{かぐら|ざか}
5485 \end{LTXexample}
5486 %<*en>
5487 If there are multiple groups in one \verb+\ruby+ call,
5488 A linebreak between two groups is allowed.
5489 %</en>
5490 %<ja> 複数ルビではグループとグループの間で改行が可能である.
5491 \begin{LTXexample}[width=0.3\textwidth]
5492 \vbox{\hsize=6\zw\noindent
5493   \hbox to 2.5\zw{}\ruby{京|急|蒲|田}{けい|きゆう|かま|た}
5494   \hbox to 2.5\zw{}\ruby{京|急|蒲|田}{けい|きゆう|かま|た}
5495   \hbox to   3\zw{}\ruby{京|急|蒲|田}{けい|きゆう|かま|た}
5496 }
5497 \end{LTXexample}
5498 \end{description}
5499
5500 %<*en>
5501 If the width of ruby characters are longer than that of base characters,
5502 \verb+\ruby+ automatically selects the appropriate form
5503 among the line-head form, the line-middle form, and the line-end form.
5504 %</en>
5505 %<*ja>
5506 また,ルビ文字のほうが親文字よりも長い場合は,自動的に
5507 行頭形・行中形・行末形のいずれか適切なものを選択する.
5508 %</ja>
5509 \begin{LTXexample}[width=0.3\textwidth]
5510 \vbox{\hsize=8\zw\noindent
5511 \null\kern3\zw ……を\ruby{承}{うけたまわ}る
5512      \kern1\zw ……を\ruby{承}{うけたまわ}る\\
5513 \null\kern5\zw ……を\ruby{承}{うけたまわ}る
5514 }
5515 \end{LTXexample}
5516
5517
5518
5519
5520
5521
5522 %<en>\part{Implementations}
5523 %<ja>\part{実装}
5524 \label{part-imp}
5525 %<en>\section{Storing Parameters}
5526 %<ja>\section{パラメータの保持}
5527 \label{sec-para}
5528 %<en>\subsection{Used Dimensions, Attributes and Whatsit Nodes}
5529 %<ja>\subsection{\LuaTeX-jaで用いられるレジスタとwhatsitノード}
5530
5531 %<*en>
5532 Here the following is the list of dimensions and attributes which are used in \LuaTeX-ja.
5533 %</en>
5534 %<*ja>
5535 以下は\LuaTeX-jaで用いられる寸法レジスタ(dimension),属性レジスタ(attribute)の
5536 リストである.
5537 %</ja>
5538 \begin{list}{}{%
5539 \def\makelabel{\ttfamily}\advance\leftmargin1\zw
5540 \def\dim#1{\item[\textbackslash #1\ \textrm{(dimension)}]}
5541 \def\cnt#1{\item[\textbackslash #1\ \textrm{(counter)}]}
5542 \def\attr#1{\item[\textbackslash #1\ \textrm{(attribute)}]}
5543 }
5544
5545 \dim{jQ}
5546 %<*en>
5547 \verb+\jQ+ is equal to
5548                         $1\,\textrm{Q}=0.25\,\textrm{mm}$, where ``Q''~(also called ``級'') is
5549                         a unit used in Japanese phototypesetting. 
5550 So one should not change the value of this dimension.
5551 %</en>
5552 %<*ja>
5553 \verb+\jQ+ は写植で用いられた$1\,\textrm{Q}=0.25\,\textrm{mm}$%
5554 (「級」とも書かれる)に等しい.したがって,
5555 この寸法レジスタの値を変更してはならない.
5556 %</ja>
5557
5558 \dim{jH}
5559 %<*en>
5560 There is also a unit called ``歯'' which equals to $0.25\,\textrm{mm}$ and
5561                          used in Japanese phototypesetting. 
5562 This \verb+\jH+ is the same \verb+\dimen+ register as \verb+\jQ+.
5563 %</en>
5564 %<*ja>
5565 同じく写植で用いられていた単位として「歯」があり,これも$0.25\,\textrm{mm}$と
5566 等しい.この \verb+\jH+ は \verb+\jQ+ と同じ寸法レジスタを指す.
5567 %</ja>
5568
5569 \dim{ltj@zw}
5570 %<*en>
5571 A temporal register for the ``full-width'' of current Japanese font.
5572 The command \verb+\zw+ sets this register to the correct value, and
5573 ``return'' this register itself.
5574 %</en>
5575 %<*ja>
5576 現在の和文フォントの「全角幅」を保持する一時レジスタ.
5577 \verb+\zw+ 命令は,このレジスタを適切な値に設定した後,
5578 「このレジスタ自体を返す」.
5579 %</ja>
5580
5581 \dim{ltj@zh}
5582 %<*en>
5583 A temporal register for the ``full-height'' (usually the sum of height of imaginary body and its depth) of current Japanese font.
5584 The command \verb+\zh+ sets this register to the correct value, and
5585 ``return'' this register itself.
5586 %</en>
5587 %<*ja>
5588 現在の和文フォントの「全角高さ」(通常,高さと深さの和)を保持する一時レジスタ.
5589 \verb+\zh+ 命令は,このレジスタを適切な値に設定した後,
5590 「このレジスタ自体を返す」.
5591 %</ja>
5592
5593 \attr{jfam}
5594 %<*en>
5595 Current number of Japanese font family for math formulas.
5596 %</en>
5597 %<*ja>
5598 数式用の和文フォントファミリの現在の番号.
5599 %</ja>
5600
5601 \attr{ltj@curjfnt}
5602 %<*en>
5603 The font index of current Japanese font for horizontal direction.
5604 %</en>
5605 %<*ja>
5606 現在の横組用和文フォントのフォント番号.
5607 %</ja>
5608
5609 \attr{ltj@curtfnt}
5610 %<*en>
5611 The font index of current Japanese font for vertical direction.
5612 %</en>
5613 %<*ja>
5614 現在の縦組用和文フォントのフォント番号.
5615 %</ja>
5616
5617 \attr{ltj@charclass}
5618 %<*en>
5619 The character class of Japanese \textit{glyph\_node}.
5620 %</en>
5621 %<*ja>
5622 和文文字の\textit{glyph\_node}の文字クラス.
5623 %</ja>
5624
5625 \attr{ltj@yablshift}
5626 %<*en>
5627 The amount of shifting the baseline of alphabetic fonts in scaled point ($2^{-16}\,\textrm{pt}$).
5628 %</en>
5629 %<*ja>
5630 スケールド・ポイント($2^{-16}\,\textrm{pt}$)を単位とした欧文フォントのベースラインの移動量.
5631 %</ja>
5632
5633 \attr{ltj@ykblshift}
5634 %<*en>
5635 The amount of shifting the baseline of Japanese fonts in scaled point ($2^{-16}\,\textrm{pt}$).
5636 %</en>
5637 %<*ja>
5638 スケールド・ポイント($2^{-16}\,\textrm{pt}$)を単位とした和文フォントのベースラインの移動量.
5639 %</ja>
5640
5641 \attr{ltj@tablshift}
5642 \attr{ltj@tkblshift}
5643
5644 \attr{ltj@autospc}
5645 %<*en>
5646 Whether the auto insertion of \Param{\hyperlink{fld:kanjiskip}{kanjiskip}} is allowed at the node.
5647 %</en>
5648 %<*ja>
5649 そのノードで\Param{\hyperlink{fld:kanjiskip}{kanjiskip}}の自動挿入が許されるかどうか.
5650 %</ja>
5651
5652 \attr{ltj@autoxspc}
5653 %<*en>
5654 Whether the auto insertion of \Param{\hyperlink{fld:xks}{xkanjiskip}} is allowed at the node.
5655 %</en>
5656 %<*ja>
5657 そのノードで\Param{\hyperlink{fld:xks}{xkanjiskip}}の自動挿入が許されるかどうか.
5658 %</ja>
5659
5660 \attr{ltj@icflag}
5661 %<*en>
5662 An attribute for distinguishing ``kinds'' of a node. One of the following value is
5663 assigned to this attribute:
5664 %</en>
5665 %<*ja>
5666 ノードの「種類」を区別するための属性.以下のうちのひとつが値として割り当てられる:
5667 %</ja>
5668 \begin{description}
5669 \item[\textit{italic} (1)]
5670 %<*en>
5671 Kerns from italic correction (\verb+\/+), or from kerning information of a Japanese font.
5672 These kerns are ``ignored'' in the insertion process of \textbf{JAglue},
5673 unlike explicit \verb+\kern+.
5674 %</en>
5675 %<*ja>
5676 イタリック補正(\verb+\/+)によるカーン,
5677 または \Pkg{luaotfload} によって挿入されたフォントのカーニング情報由来のカーン.
5678 これらのカーンは通常の \verb+\kern+ とは異なり,
5679 \textbf{JAglue}の挿入処理においては透過する.
5680 %</ja>
5681
5682 \item[\textit{packed} (2)]
5683
5684 \item[\textit{kinsoku} (3)]
5685 %<*en>
5686 Penalties inserted for the word-wrapping process (\emph{kinsoku shori}) of Japanese characters.
5687 %</en>
5688 %<ja>禁則処理のために挿入されたペナルティ.
5689 \item[\mathversion{bold}$(\textit{from\_jfm}-2)$--$(\textit{from\_jfm}+2)$~(4--8)]
5690 %<en>Glues/kerns from JFM.
5691 %<ja>JFM由来のグルー/カーン.
5692 \item[\textit{kanji\_skip}~(9), \textit{kanji\_skip\_jfm}~(10)]
5693 %<en>Glues from \Param{\hyperlink{fld:kanjiskip}{kanjiskip}}.
5694 %<ja>和文間空白\Param{\hyperlink{fld:kanjiskip}{kanjiskip}}を表すグルー.
5695 \item[\textit{xkanji\_skip}~(11), \textit{xkanji\_skip\_jfm}~(12)]
5696 %<en>Glues from \Param{\hyperlink{fld:xks}{xkanjiskip}}.
5697 %<ja>和欧文間空白\Param{\hyperlink{fld:xks}{xkanjiskip}}を表すグルー.
5698 \item[\textit{processed} (13)]
5699 %<en>Nodes which is already processed by \ldots.
5700 %<ja>\LuaTeX-ja の内部処理によって既に処理されたノード.
5701 \item[\textit{ic\_processed} (14)]
5702 %<*en>
5703 Glues from an italic correction, but already processed in the insertion process of \textbf{JAglue}s.
5704 %</en>
5705 %<ja>イタリック補正に由来するグルーであって,既に \textbf{JAglue} 挿入処理にかかったもの.
5706 \item[\textit{boxbdd} (15)]
5707 %<en>Glues/kerns that inserted just the beginning or the ending of an hbox or a paragraph.
5708 %<ja>hboxか段落の最初か最後に挿入されたグルー/カーン.
5709 \end{description}
5710
5711 %<*ja>
5712 また,挿入処理の結果であるリストの最初のノードでは,\verb+\ltj@icflag+ の値に
5713 \textit{processed\_begin\_flag}~(128)が追加される.これによって,\verb+\unhbox+ が
5714 連続した場合でも「ボックスの境界」が識別できるようになっている.
5715 %</ja>
5716
5717 \attr{ltj@kcat$i$}
5718 %<*en>
5719 Where $i$~is a natural number which is less than~7.
5720 These 7~attributes store bit~vectors indicating which character block is regarded as a block of \textbf{JAchar}s.
5721 %</en>
5722 %<*ja>
5723 $i$は7より小さい自然数.
5724 これら7つの属性レジスタは,どの文字ブロックが\textbf{JAchar}のブロックとして
5725 扱われるかを示すビットベクトルを格納する.
5726 %</ja>
5727
5728 \cnt{ltj@dir@count}
5729 %<*ja>
5730 現在の組方向を表す.
5731 %</ja>
5732 \begin{description}
5733 \item[\textit{dir\_dtou} (1)]
5734 \item[\textit{dir\_tate} (3)]
5735 \item[\textit{dir\_yoko} (4)]
5736 \end{description}
5737
5738 \attr{ltj@dir}
5739 %<*ja>
5740 ボックスにおける組方向を示す.上記の3つの値(1,~3,~4)の他に,
5741 それらに次を加えた値(17,~19, 20, 33, 35,~36)もとり得る.
5742 %</ja>
5743 \begin{description}
5744 \item[\textit{dir\_node\_auto} (16)]
5745 \item[\textit{dir\_node\_manual} (32)]
5746 \end{description}
5747
5748
5749 \end{list}
5750
5751 %<*en>
5752 Furthermore, \LuaTeX-ja uses several user-defined whatsit nodes for
5753 inrernal processing. All those nodes except \emph{direction} whatsits 
5754 store a natural number (hence its \texttt{type} is 100). 
5755 \emph{direction} whatsits store a node list, hence its \texttt{type} is 110.
5756 Their \texttt{user\_id} (used for distinguish user-defined whatsits) 
5757 are allocated by \texttt{luatexbase.newuserwhatsitid}.
5758 %</en>
5759 %<*ja>
5760 さらに,\LuaTeX-jaはいくつかのuser-defined whatsit nodeを内部処理に用いる.
5761 \textit{direction} whatsitはノードリストを格納するが,
5762 それ以外のwhatsitノードの \texttt{type} は100であり,ノードは自然数を格納している.
5763 user-defined whatsitを識別するための \texttt{user\_id} は\ 
5764 \texttt{luatexbase.newuserwhatsitid} により確保されており,
5765 下の見出しは単なる識別用でしかない.
5766 %</ja>
5767 \begin{description}
5768 \item[\textit{inhibitglue}]
5769 %<*en>
5770 Nodes for indicating that \verb+\inhibitglue+ is
5771            specified. The \texttt{value} field of these nodes doesn't matter.
5772 %</en>
5773 %<*ja>
5774 \verb+\inhibitglue+ が指定されたことを示すノード.これらのノードの\ 
5775 \texttt{value} フィールドは意味を持たない.
5776 %</ja>
5777
5778 \item[\textit{stack\_marker}]
5779 %<*en>
5780 Nodes for \LuaTeX-ja's stack system (see the next
5781            subsection). The \texttt{value} field of these nodes is
5782            current group level.
5783 %</en>
5784 %<*ja>
5785 \LuaTeX-jaのスタックシステム(次の節を参照)のためのノード.
5786 これらのノードの \texttt{value} フィールドは現在のグループネストレベルを表す.
5787 %</ja>
5788
5789 \item[\textit{char\_by\_cid}]
5790 %<*en>
5791 Nodes for \textbf{JAchar} which the callback process of
5792            \Pkg{luaotfload} won't be applied, and the character code is
5793            stored in the \texttt{value} field. Each node of this type are 
5794            converted to a \textit{glyph\_node} \emph{after}
5795            the callback process of luaotfload.
5796 Nodes of this type is used in \verb+\CID+, \verb+\UTF+ and IVS support.
5797 %</en>
5798 %<*ja>
5799 \Pkg{luaotfload}のコールバックによる処理が適用されない\textbf{JAchar}のためのノードで,
5800 \texttt{value} フィールドに文字コードが格納されている.
5801 この種類のノードはそれぞれが\Pkg{luaotfload}のコールバックの処理の
5802 \emph{後で}\textit{glyph\_node}に変換される.
5803 \verb+\CID+, \verb+\UTF+やIVS対応処理でこの種類のノードが利用されている.
5804 %</ja>
5805
5806 \item[\textit{replace\_vs}]
5807 %<*en>
5808 Similar to \textit{char\_by\_cid} whatsits above.
5809 These nodes are for \textbf{ALchar} which the callback process of
5810            \Pkg{luaotfload} won't be applied.
5811 %</en>
5812 %<*ja>
5813 上の\textit{char\_by\_cid}と同様に,
5814 これらのノードは\Pkg{luaotfload}のコールバックによる処理が適用されない\textbf{ALchar}のた
5815            めものである.
5816 %</ja>
5817
5818 \item[\textit{begin\_par}]
5819 %<*en>
5820 Nodes for indicating beginning of a paragraph.
5821 A paragraph which is started by \verb+\item+ in list-like environments has a horizontal box
5822 for its label before the actual contents. So \dots
5823 %</en>
5824 %<*ja>
5825 「段落の開始」を意味するノード.
5826 list環境,itemize環境などにおいて,\verb+\item+ で始まる各項目は……
5827 %</ja>
5828
5829 \item[\textit{direction}]
5830
5831 \end{description}
5832
5833 %<*en>
5834 These whatsits will be removed during the process of inserting \textbf{JAglue}s.
5835 %</en>
5836 %<*ja>
5837 これらのwhatsitノードは\textbf{JAglue}の挿入処理の間に取り除かれる.
5838 %</ja>
5839
5840 %<en>\subsection{Stack System of \LuaTeX-ja}
5841 %<ja>\subsection{\LuaTeX-jaのスタックシステム}
5842 \label{ssec-stack}
5843
5844 %<en>\paragraph{Background}
5845 %<ja>\paragraph{背景}
5846 %<*en>
5847 \LuaTeX-ja has its own stack system, and most parameters of \LuaTeX-ja
5848 are stored in it. To clarify the reason, imagine the parameter
5849 \Param{\hyperlink{fld:kanjiskip}{kanjiskip}} is stored by a skip, and consider the following
5850 source:
5851 %</en>
5852 %<*ja>
5853 \LuaTeX-jaは独自のスタックシステムを持ち,\LuaTeX-jaのほとんどのパラメータは
5854 これを用いて保持されている.その理由を明らかにするために,
5855 \Param{\hyperlink{fld:kanjiskip}{kanjiskip}}パラメータがスキップレジスタで保持されているとし,
5856 以下のコードを考えてみよう:
5857 %</ja>
5858 \begin{LTXexample}
5859 \ltjsetparameter{kanjiskip=0pt}ふがふが.%
5860 \setbox0=\hbox{%
5861   \ltjsetparameter{kanjiskip=5pt}ほげほげ}
5862 \box0.ぴよぴよ\par
5863 \end{LTXexample}
5864
5865 %<*en>
5866 As described in Subsection~\ref{ssec-param}, the only effective value of
5867 \Param{\hyperlink{fld:kanjiskip}{kanjiskip}} in an hbox is the latest value, so the value of
5868 \Param{\hyperlink{fld:kanjiskip}{kanjiskip}} which applied in the entire hbox should be 5\,pt.
5869 However, by the implementation method of \LuaTeX, this ``5\,pt'' cannot be
5870 known from any callbacks.  In the \texttt{tex/packaging.w}, which is a
5871 file in the source of \LuaTeX, there are the following codes:
5872 %</en>
5873 %<*ja>
5874 \ref{ssec-param}節で述べたように,あるhboxの中で効力を持つ
5875 \Param{\hyperlink{fld:kanjiskip}{kanjiskip}}の値は最後に現れた値のみであり,したがってボックス全体に適用される
5876 \Param{\hyperlink{fld:kanjiskip}{kanjiskip}}は5\,ptであるべきである.しかし,\LuaTeX の実
5877 装を観察すると,この5\,ptという長さはどのコールバックからも知ることはできないことがわかる.
5878 \LuaTeX のソースファイルの1つ \texttt{tex/packaging.w} の中に,
5879 以下のコードがある:
5880 %</ja>
5881 \begin{lstlisting}[numbers=left,firstnumber=1226]
5882 void package(int c)
5883 {
5884     scaled h;                   /* height of box */
5885     halfword p;                 /* first node in a box */
5886     scaled d;                   /* max depth */
5887     int grp;
5888     grp = cur_group;
5889     d = box_max_depth;
5890     unsave();
5891     save_ptr -= 4;
5892     if (cur_list.mode_field == -hmode) {
5893         cur_box = filtered_hpack(cur_list.head_field,
5894                                  cur_list.tail_field, saved_value(1),
5895                                  saved_level(1), grp, saved_level(2));
5896         subtype(cur_box) = HLIST_SUBTYPE_HBOX;
5897 \end{lstlisting}
5898 %<*en>
5899 Notice that \texttt{unsave()} is executed \emph{before}
5900 \texttt{filtered\_hpack()}, where \texttt{hpack\_filter} callback is
5901 executed) here. So ``5\,pt'' in the above source is orphaned at
5902 \texttt{unsave()}, and hence it can't be accessed from \texttt{hpack\_filter}
5903 callback.
5904 %</en>
5905 %<*ja>
5906 \texttt{unsave()} が \texttt{filtered\_hpack()}(これは \texttt{hpack\_filter} コールバックが
5907 実行されるところである)の\emph{前に}実行されていることに注意する.
5908 したがって,上記ソース中で5\,ptは \texttt{unsave()} のところで捨てられ,
5909 \texttt{hpack\_filter} コールバックからはアクセスすることができない.
5910 %</ja>
5911
5912 %<en>\paragraph{Implementation}
5913 %<ja>\paragraph{解決法}
5914
5915 %<*en>
5916 The code of stack system is based on that in a post of Dev-luatex mailing list\footnote{%
5917 \texttt{[Dev-luatex] tex.currentgrouplevel}, a post at 2008/8/19 by Jonathan Sauer.}.
5918 %</en>
5919 %<*ja>
5920 スタックシステムのコードはDev-luatexメーリングリストのある投稿\footnote{%
5921 \texttt{[Dev-luatex] tex.currentgrouplevel}: Jonathan Sauerによる2008/8/19の投稿.}を
5922 ベースにしている.
5923 %</ja>
5924
5925 %<*en>
5926 These are two \TeX\ count registers for maintaining information:
5927 \verb+\ltj@@stack+ for the stack level, and \verb+\ltj@@group@level+ for
5928 the \TeX's group level when the last assignment was done.  Parameters
5929 are stored in one big table named \texttt{charprop\_stack\_table}, where
5930 \texttt{charprop\_stack\_table[$i$]} stores data of stack level~$i$. If
5931 a new stack level is created by \verb+\ltjsetparameter+, all data of the
5932 previous level is copied.
5933 %</en>
5934 %<*ja>
5935 情報を保持するために,2つの\TeX の整数レジスタを用いている:
5936 \verb+\ltj@@stack+ にスタックレベル,\verb+\ltj@@group@level+ に最後の代入が
5937 なされた時点での\TeX のグループレベルを保持している.
5938 パラメータは\texttt{charprop\_stack\_table}という名前のひとつの大きなテーブルに
5939 格納される.ここで,\texttt{charprop\_stack\_table[$i$]}はスタックレベル$i$の
5940 データを格納している.もし新しいスタックレベルが \verb+\ltjsetparameter+ によって
5941 生成されたら,前のレベルの全てのデータがコピーされる.
5942 %</ja>
5943
5944 %<*en>
5945 To resolve the problem mentioned in above paragraph ``Background'', \LuaTeX-ja uses
5946 another trick. When the stack level is about to be increased, a whatsit
5947 node whose type, subtype and value are 44~(\textit{user\_defined}),
5948 \textit{stack\_marker} and the current group level respectively is appended to the current
5949 list (we refer this node by \textit{stack\_flag}). This enables us to
5950 know whether assignment is done just inside a hbox. Suppose that the
5951 stack level is~$s$ and the \TeX's group level is~$t$ just after the hbox
5952 group, then:
5953 %</en>
5954 %<*ja>
5955 上の「背景」で述べた問題を解決するために,\LuaTeX-jaでは次の手法を用いる:
5956 スタックレベルが増加するするとき,type, subtype, valueがそれぞれ
5957 44~(\textit{user\_defined}), \textit{stack\_marker},そして現在のグループレベルであるwhatsitノード
5958 を現在のリストに付け加える(このノードを\textit{stack\_flag}とする).
5959 これにより,あるhboxの中で代入がなされたかどうかを知ることが可能
5960 となる.スタックレベルを$s$,そのhbox groupの直後の\TeX のグループレベルを
5961 $t$とすると:
5962 %</ja>
5963 \begin{itemize}
5964 %<*en>
5965 \item If there is no \textit{stack\_flag} node in the list of the contents of the hbox, then
5966       no assignment was occurred inside the hbox. Hence values of
5967       parameters at the end of the hbox are stored in the stack
5968       level~$s$.
5969 %</en>
5970 %<*ja>
5971 \item もしそのhboxの中身を表すリストの中に\textit{stack\_flag}ノードがなければ,
5972   hboxの中では代入は起こらなかったということになる.
5973   したがって,そのhboxの終わりにおけるパラメータの値はスタックレベル$s$に
5974   格納されている.
5975 %</ja>
5976
5977 %<*en>
5978 \item If there is a \textit{stack\_flag} node whose value is~$t+1$, then
5979       an assignment was occurred just inside the hbox group. Hence
5980       values of parameters at the end of the hbox are stored in the
5981       stack level~$s+1$.
5982 %</en>
5983 %<*ja>
5984 \item もし値が$t+1$の\textit{stack\_flag}ノードがあれば,その
5985   hboxの中で代入が起こったことになる.
5986   したがって,hboxの終わりにおけるパラメータの値はスタックレベル$s+1$に
5987   格納されている.
5988 %</ja>
5989
5990 %<*en>
5991 \item If there are \textit{stack\_flag} nodes but all of their values
5992       are more than~$t+1$, then an assignment was occurred in the box,
5993       but it is done in more internal group. Hence values of
5994       parameters at the end of the hbox are stored in the stack
5995       level~$s$.
5996 %</en>
5997 %<*ja>
5998 \item もし\textit{stack\_flag}ノードがあるがそれらの値が全て$t+1$より大きい
5999   場合,そのボックスの中で代入が起こったが,それは「より内部の」グループで
6000   起こったということになる.したがって,hboxの終わりでのパラメータの
6001   値はスタックレベル$s$に格納されている.
6002 %</ja>
6003 \end{itemize}
6004
6005 %<*en>
6006 Note that to work this trick correctly, assignments to
6007 \verb+\ltj@@stack+ and \verb+\ltj@@group@level+ have to be local always,
6008 regardless the value of \verb+\globaldefs+.
6009 To solve this problem, we use another trick: the assignment 
6010 \hbox{\verb+\directlua{tex.globaldefs=0}+} is always local.
6011 %</en>
6012 %<*ja>
6013 このトリックを正しく働かせるためには,\verb+\ltj@@stack+ と \verb+\ltj@@group@level+ への
6014 代入は \verb+\globaldefs+ の値によらず常にローカルでなければならないことに注意する.
6015 この問題は \hbox{\verb+\directlua{tex.globaldefs=0}+}(この代入は常にローカル)を
6016 用いることで解決している.
6017 %</ja>
6018
6019 %<*en>
6020 \subsection{Lua Functions of the Stack System}
6021 In this subsection, we will see how a user use \LuaTeX-ja's stack system to
6022 store some data which obeys the grouping of \TeX.
6023 %</en>
6024 %<*ja>
6025 \subsection{スタックシステムで使用される関数}
6026 本節では,ユーザが\LuaTeX-jaのスタックシステムを使用して,
6027 \TeX のグルーピングに従うような
6028 独自のデータを取り扱う方法を述べる.
6029 %</ja>
6030
6031 %<*en>
6032 The following function can be used to store data into a stack:
6033 \begin{verbatim}
6034 luatexja.stack.set_stack_table(index, <any> data)
6035 \end{verbatim}
6036 Any values which except \texttt{nil}~and~NaN are usable as \textit{index}. 
6037 However, a user should use only negative integers or strings as \textit{index}, 
6038 since natural numbers are used by \LuaTeX-ja itself.
6039 Also, whether \textit{data} is stored locally or globally 
6040 is determined by \texttt{luatexja.isglobal}
6041 (stored globally if and only if \texttt{luatexja.isglobal == 'global'}).
6042 %</en>
6043 %<*ja>
6044 スタックに値を設定するには,以下のLua関数を呼びだせば良い:
6045 \begin{verbatim}
6046 luatexja.stack.set_stack_table(<any> index, <any> data)
6047 \end{verbatim}
6048 直感的には,スタックテーブル中のインデックス\textit{index}の値を\textit{data}にする,という意味である.
6049 \textit{index}の値としては \texttt{nil} とNaN以外の任意の値を使えるが,
6050 自然数は\LuaTeX-jaが使用する(将来の拡張用も含む)ので,
6051 ユーザが使用する場合は負の整数値か文字列の値にすることが望ましい.
6052 また,ローカルに設定されるかグローバルに設定されるかは,\texttt{luatexja.isglobal} の値に依存する
6053 (グローバルに設定されるのは,\texttt{luatexja.isglobal == 'global'} であるちょうどその時).
6054 %</ja>
6055
6056 %<*en>
6057 Stored data can be obtained as the return value of
6058 \begin{verbatim}
6059 luatexja.stack.get_stack_table(index, <any> default, <number> level)
6060 \end{verbatim}
6061 where \textit{level} is the stack level, which is usually the value of \verb+\ltj@@stack+, 
6062 and \textit{default} is the default value which will be returned if no values are stored 
6063 in the stack table whose level is \textit{level}.
6064 %</en>
6065 %<*ja>
6066 スタックの値は,
6067 \begin{verbatim}
6068 luatexja.stack.get_stack_table(<any> index, <any> default, <number> level)
6069 \end{verbatim}
6070 の戻り値で取得できる.\textit{level}はスタックレベルであり,
6071 通常は \verb+\ltj@@stack+ の値を指定することになるだろう.
6072 \textit{default}はレベル\textit{level}のスタックに値が設定されていなかった場合に
6073 返すデフォルト値である.
6074 %</ja>
6075
6076 \begin{figure}[tb]
6077 \begin{lstlisting}[numbers=left, firstnumber=380]
6078 \protected\def\ltj@setpar@global{%
6079   \relax\ifnum\globaldefs>0\directlua{luatexja.isglobal='global'}%
6080     \else\directlua{luatexja.isglobal=''}\fi
6081 }
6082 \protected\def\ltjsetparameter#1{%
6083   \ltj@setpar@global\setkeys[ltj]{japaram}{#1}\ignorespaces}
6084 \protected\def\ltjglobalsetparameter#1{%
6085   \relax\ifnum\globaldefs<0\directlua{luatexja.isglobal=''}%
6086     \else\directlua{luatexja.isglobal='global'}\fi%
6087   \setkeys[ltj]{japaram}{#1}\ignorespaces}
6088 \end{lstlisting} 
6089 %<ja>\caption{パラメータ設定命令の定義}
6090 %<en>\caption{Definiton of parameter setting commands}
6091 \label{fig:setpar-def}
6092 \end{figure}
6093
6094 %<*en>
6095 \subsection{Extending Parameters}
6096 Keys for \verb+\ltjsetparameter+~and~\verb+\ltjgetparameter+ can be extended, 
6097 as in \Pkg{luatexja-adjust}.
6098 %</en>
6099 %<*ja>
6100 \subsection{パラメータの拡張}
6101 ここでは,\Pkg{luatexja-adjust}で行なっているように,
6102 \verb+\ltjsetparameter+,~\verb+\ltjgetparameter+に指定可能なキーを追加する方法
6103 を述べる.
6104 %</ja>
6105
6106 %<*en>
6107 \paragraph{Setting parameters}
6108 Figure~\ref{fig:setpar-def} shows the ``most outer'' definition of 
6109 two commands, 
6110 \verb+\ltjsetparameter+ and \verb+\ltjglobalsetparameter+.
6111 Most important part is the last \verb+\setkeys+, 
6112 which is offered by the \Pkg{xkeyval} package.
6113
6114 Hence, to add a key in \verb+\ltjsetparameter+, one only have to add a key
6115 whose prefix is \texttt{ltj} and whose family is \texttt{japaram}, as the following.
6116 \begin{verbatim}
6117 \define@key[ltj]{japaram}{...}{...}
6118 \end{verbatim}
6119
6120 \verb+\ltjsetparameter+~and~\verb+\ltjglobalsetparameter+ automatically sets
6121 \texttt{luatexja.isglobal}. Its meaning is the following.
6122 \begin{align}
6123  \texttt{luatexja.isglobal} = 
6124 \begin{cases}
6125  \texttt{'global'}&\text{global}\\
6126  \texttt{''}&\text{local}
6127 \end{cases}
6128 \end{align}
6129 This is determined not only by command name
6130 (\verb+\ltjsetparameter+~or~\verb+\ltjglobalsetparameter+), 
6131 but also by the value of \verb+\globaldefs+.
6132 %</en>
6133 %<*ja>
6134 \paragraph{パラメータの設定}
6135 \verb+\ltjsetparameter+ と,\verb+\ltjglobalsetparameter+ の定義は図\ref{fig:setpar-def}の
6136 のようになっている.
6137 本質的なのは最後の \verb+\setkeys+ で,これは\Pkg{xkeyval}パッケージの提供する命令である.
6138
6139 このため,\verb+\ltjsetparameter+ に指定可能なパラメータを追加するには,
6140 <prefix>を \texttt{ltj},<family>を \texttt{japaram} としたキーを
6141 \begin{verbatim}
6142 \define@key[ltj]{japaram}{...}{...}
6143 \end{verbatim}
6144 のように定義すれば良いだけである.
6145 なお,パラメータ指定がグローバルかローカルかどうかを示す \texttt{luatexja.isglobal} が,
6146 \begin{align}
6147  \texttt{luatexja.isglobal} = 
6148 \begin{cases}
6149  \texttt{'global'}&\text{パラメータ設定はグローバル}\\
6150  \texttt{''}&\text{パラメータ設定はローカル}
6151 \end{cases}
6152 \end{align}
6153 として自動的にセットされる\footnote{命令が \texttt{\textbackslash ltjglobalsetparameter} かどうかだけでは
6154 なく,実行時の \texttt{\textbackslash globaldefs} の値にも依存して定まる.}.
6155 %</ja>
6156
6157 %<*ja>
6158 \paragraph{パラメータの取得}
6159 一方,\verb+\ltjgetparameter+ はLuaスクリプトによって実装されている.
6160 値を取得するのに追加引数の要らないパラメータについては,\verb+luatexja.unary_pars+\ 
6161 内に処理内容を記述した関数を定義すれば良い.例えば,Luaスクリプトで
6162 \begin{lstlisting}[numbers=left] 
6163 function luatexja.unary_pars.hoge (t)
6164   return 42
6165 end
6166 \end{lstlisting}
6167 を実行すると,\verb+\ltjgetparameter{hoge}+ は \texttt{42} という\emph{文字列}を返す.
6168 関数 \verb+luatexja.unary_pars.hoge+ の引数$t$は,\ref{ssec-stack}節で述べた
6169 \LuaTeX-jaのスタックシステムにおけるスタックレベルである.
6170 戻り値はいかなる値であっても,最終的には文字列として出力されることに注意.
6171
6172 一方,追加引数(\emph{数値しか許容しない})が必要なパラメータについては,
6173 まずLuaスクリプトで処理内容の本体を記述しておく:
6174 \begin{lstlisting}[numbers=left] 
6175 function luatexja.binary_pars.fuga (c, t)
6176   return tostring(c) .. ', ' .. tostring(42)
6177 end
6178 \end{lstlisting}
6179 引数$t$は,先に述べた通りのスタックレベルである.一方,引数$c$は\ 
6180 \verb+\ltjgetparameter+ の第2引数を表す数値である.
6181 しかしこれだけでは駄目で,
6182 \begin{verbatim}
6183 \ltj@@decl@array@param{fuga}
6184 \end{verbatim}
6185 を実行し,\TeX インターフェース側に
6186 「\verb+\ltjgetparameter{fuga}+ は追加引数が必要」ということを通知する必要がある.
6187 %</ja>
6188
6189 %<en>\section{Linebreak after a Japanese Character}
6190 %<ja>\section{和文文字直後の改行}
6191 \label{sec-lbreak}
6192 %<en>\subsection{Reference: Behavior in \pTeX}
6193 %<ja>\subsection{参考:\pTeX の動作}
6194 %<*en>
6195 In~\pTeX, a line break after a Japanese character doesn't emit a space,
6196 since words are not separated by spaces in Japanese writings. However,
6197 this feature isn't fully implemented in \LuaTeX-ja due to the
6198 specification of callbacks in~\LuaTeX. To clarify the difference between
6199 \pTeX~and~\LuaTeX, We briefly describe the handling of a line break in~\pTeX, in
6200 this subsection.
6201
6202 \pTeX's input processor can be described in terms of a finite state
6203 automaton, as that of~\TeX\ in~Section~2.5 of~\cite{texbytopic}. The
6204 internal states are as follows:
6205 \begin{itemize}
6206 \item State~$N$: new line
6207 \item State~$S$: skipping spaces
6208 \item State~$M$: middle of line
6209 \item State~$K$: after a Japanese character
6210 \end{itemize}
6211 The first three states---$N$,~$S$, and~$M$---are as same as \TeX's input
6212 processor.  State~$K$ is similar to state~$M$, and is entered after
6213 Japanese characters.  The diagram of state transitions are indicated in
6214 Figure~\ref{fig-ptexipro}.  Note that \pTeX\ doesn't leave state~$K$
6215 after ``beginning/ending of a group'' characters.
6216 %</en>
6217
6218 %<*ja>
6219 欧文では文章の改行は単語間でしか行わない.そのため,\TeX では,(文字の直後の)改行は
6220 空白文字と同じ扱いとして扱われる.一方,和文ではほとんどどこでも改行が可能なため,
6221 \pTeX では和文文字の直後の改行は単純に無視されるようになっている.
6222
6223 このような動作は,\pTeX が\TeX からエンジンとして拡張されたことによって可能になったことである.
6224 \pTeX の入力処理部は,\TeX におけるそれと同じように,有限オートマトンとして記述することができ,
6225 以下に述べるような4状態を持っている.
6226
6227 \begin{itemize}
6228 \item State~$N$: 行の開始.
6229 \item State~$S$: 空白読み飛ばし.
6230 \item State~$M$: 行中.
6231 \item State~$K$: 行中(和文文字の後).
6232 \end{itemize}
6233 また,状態遷移は,図\ref{fig-ptexipro}のようになっており,図中の数字は
6234 カテゴリーコードを表している.最初の3状態は\TeX の入力処理部と同じであり,
6235 図中から状態$K$と「$j$」と書かれた矢印を取り除けば,\TeX の入力処理部と同
6236 じものになる.
6237
6238 この図から分かることは,
6239 \begin{quote}
6240 行が和文文字(とグループ境界文字)で終わっていれば,改行は無視される
6241 \end{quote}
6242 ということである.
6243 %</ja>
6244
6245 \begin{figure}[!tb]
6246 \let\sp\textvisiblespace\small
6247 \begin{minipage}{.6\textwidth}%
6248 \begin{center}
6249 \unitlength=6.5mm\sf\mathversion{bold}
6250 \begin{tikzpicture}[
6251   ->, auto, shorten >=1pt
6252 ]
6253 \node [shape=rectangle, font=\scriptsize] (init) at (2,7) {start};
6254 \node [shape=circle,draw, fill=blue!20] (newline) at (4,7) {$N$};
6255 \node [shape=circle,draw, fill=blue!20] (midline) at (4,4) {$M$};
6256 \node [shape=circle,draw, fill=blue!20] (skipspc) at (8,7) {$S$};
6257 \node [shape=circle,draw, fill=red!20]  (kanji) at (8,4) {$K$};
6258 \node [shape=rectangle,draw, fill=green!20] (scanacs) at (6,8) {scan a c.s.};
6259 \node (endk) at (8,2.5) {} ;
6260 \node (endm) at (4,2.5) {} ;
6261 \node (ends) at (8,8.5) {} ;
6262 \node (endn) at (4,8.5) {} ;
6263 \begin{scope}[font=\scriptsize]
6264 \path (newline) edge [bend right]    node [left]{G, O} (midline)
6265       (init)    edge                 node {} (newline)
6266       (midline) edge [bend right=10] node {10} (skipspc)
6267       (skipspc) edge [bend right]    node [left,right=10,above=7]{G, O} (midline)
6268       (skipspc) edge [loop right]    node {10} (skipspc)
6269       (newline) edge [loop right]    node {10} (newline)
6270       (scanacs) edge [bend left]     node [left=3,below]{$(*)$} (skipspc)
6271       (scanacs) edge [bend right]    node [right=30,above=20]{$(*)$} (midline)
6272       (midline) edge                 node {5\ [\sp]} (endm)
6273       (midline) edge [loop left]     node {G, O} (midline)
6274       (skipspc) edge                 node [right] {5} (ends)
6275       (newline) edge                 node {5 [{\tt\textbackslash par}]} (endn);
6276 \begin{scope}[red]
6277 \path (newline) edge [bend right]    node [right=25,below=3]{J} (kanji)
6278       (midline) edge                 node [below]{J} (kanji)
6279       (kanji)   edge [bend left]     node {O} (midline)
6280       (kanji)   edge                 node {10} (skipspc)
6281       (kanji)   edge [loop right]    node {G, J} (kanji)
6282       (skipspc) edge [bend left]     node {J} (kanji)
6283       (kanji)   edge                 node {5} (endk)
6284 ;
6285 \end{scope}
6286 \end{scope}
6287 \end{tikzpicture}
6288 \end{center}
6289 \end{minipage}%
6290 \begin{minipage}{.4\textwidth}
6291 \begin{description}
6292 \item[\textsf{G}] Beginning of group (usually \verb+{+)\\
6293  and ending of group (usually \verb+}+).
6294 \item[\textsf{J}] Japanese characters.
6295 \item[\textsf{5}] \textit{end-of-line} (usually \verb+^+\verb+^J+).
6296 \item[\textsf{10}] space (usually \sp).
6297 \item[\textsf{O}] other characters, whose category code is in $\{3,4,6,7,8,11,12,13\}$.
6298 \item[\textsf{[\sp]}, \textsf{[{\tt\textbackslash par}]}]
6299 emits a space, or~\verb+\par+.
6300 \end{description}
6301 \end{minipage}
6302 \begin{itemize}
6303 \item We omitted about category codes
6304 9~(\textit{ignored}), 14~(\textit{comment}), and~15~(\textit{invalid})
6305 from the above diagram. We also ignored the input like ``\verb+^+\verb+^A+'' or ``\verb+^+\verb+^df+''.
6306 \item When a character whose category code is 0 (\textit{escape character}) is seen by \TeX,
6307 the input processor scans a control sequence (\textsf{scan a c.s.}).
6308 These paths are not shown in the above diagram.
6309
6310 After that, the state is changed to State~$S$ (skipping blanks) in most cases, but
6311 to State~$M$ (middle of line) sometimes.
6312 \end{itemize}
6313 %<en>\caption{State transitions of \pTeX's input processor}
6314 %<ja>\caption{\pTeX の入力処理部の状態遷移}
6315 \label{fig-ptexipro}
6316 \end{figure}
6317
6318
6319 %<en>\subsection{Behavior in \LuaTeX-ja}
6320 %<ja>\subsection{\LuaTeX-jaの動作}
6321 %<*en>
6322 States in the input processor of \LuaTeX\ is the same as that of \TeX,
6323 and they can't be customized by any callbacks. Hence, we can only use
6324 \verb+process_input_buffer+ and \verb+token_filter+ callbacks for to
6325 suppress a space by a line break which is after Japanese characters.
6326
6327 However, \verb+token_filter+ callback cannot be used either, since a
6328 character in category code 5~(\textit{end-of-line}) is converted into an space
6329 token \emph{in the input processor}.  So we can use only the
6330 \verb+process_input_buffer+ callback.  This means that suppressing a
6331 space must be done \emph{just before} an input line is read.
6332
6333 Considering these situations, handling of an end-of-line in \LuaTeX-ja are as follows:
6334 \begin{quote}
6335 A character \texttt{U+FFFFF} (its category code is set to 14~(\textit{comment}) by
6336 \LuaTeX-ja) is appended to an input line, \emph{before \LuaTeX\ actually
6337 process it}, if and only if the following three conditions are satisfied:
6338 \begin{enumerate}
6339 \item The category code of \verb+\endlinechar+%
6340 \footnote{Usually, it is $\langle$\textit{return}$\rangle$
6341       (whose character code is 13).} is 5~(\textit{end-of-line}).
6342 \item The category code of \texttt{U+FFFFF} itself is 14~(\textit{comment}).
6343 \item The input line matches the following ``regular expression'':
6344 \[
6345   (\text{any char})^*(\textbf{JAchar})
6346   \bigl(\{\text{catcode}=1\}\cup\{\text{catcode}=2\}\bigr)^*
6347 \]
6348 \end{enumerate}
6349 \end{quote}
6350
6351 \paragraph{Remark}
6352 The following example shows the major difference from the behavior of \pTeX.
6353 \begin{LTXexample}
6354 \fontspec[Ligatures=TeX]{TeX Gyre Termes}
6355 \ltjsetparameter{autoxspacing=false}
6356 \ltjsetparameter{jacharrange={-6}}xあ
6357 y\ltjsetparameter{jacharrange={+6}}zい
6358 u
6359 \end{LTXexample}
6360 It is not strange that ``あ'' does not printed in the above output.
6361 This is because \TeX\ Gyre\ Termes does not contain ``あ'', and because 
6362 ``あ'' in line~3 is considered as an \textbf{ALchar}.
6363
6364 Note that there is no space before ``y'' in the output, but
6365 there is a space before ``u''. This follows from following reasons:
6366 \begin{itemize}
6367 \item When line~3 is processed by \texttt{process\_input\_buffer} callback,
6368 ``あ'' is considered as an \textbf{JAchar}.
6369 Since  line~3 ends with an \textbf{JAchar}, 
6370 the comment character \texttt{U+FFFFF} is appended to this line,
6371 and hence the linebreak immediately after this line is ignored.
6372 \item When line~4 is processed by \texttt{process\_input\_buffer} callback,
6373 ``い'' is considered as an \textbf{ALchar}.
6374 Since  line~4 ends with an \textbf{ALchar}, the linebreak immediately after this line
6375 emits a space.
6376 \end{itemize}
6377 %</en>
6378
6379 %<*ja>
6380 \LuaTeX の入力処理部は\TeX のそれと全く同じであり,コールバックによりユーザが
6381 カスタマイズすることはできない.このため,改行抑制の目的でユーザが利用で
6382 きそうなコールバックとしては,\verb+process_input_buffer+や
6383 \verb+token_filter+に限られてしまう.しかし,\TeX の入力処理部をよく見る
6384 と,後者も役には経たないことが分かる:改行文字は,入力処理部によってトー
6385 クン化される時に,カテゴリーコード10の32番文字へと置き換えられてしまうた
6386 め,\verb+token_filter+で非標準なトークン読み出しを行おうとしても,空白文
6387 字由来のトークンと,改行文字由来のトークンは区別できないのだ.
6388
6389 すると,我々のとれる道は,\verb+process_input_buffer+を用いて
6390 \LuaTeX の入力処理部に引き渡される前に入力文字列を編集するというものしかない.
6391 以上を踏まえ,\LuaTeX-jaにおける「和文文字直後の改行抑制」の処理は,次のようになっている:
6392
6393 \begin{quote}
6394 各入力行に対し,\emph{その入力行が読まれる前の内部状態で}
6395 以下の3条件が満たされている場合,\LuaTeX-jaは\texttt{U+FFFFF}の文字
6396 \footnote{この文字はコメント文字として扱われるように\LuaTeX-ja内部で設定をしている.}
6397 を末尾に追加する.よって,その場合に改行は空白とは見做されないこととなる.
6398 \begin{enumerate}
6399 \item \verb+\endlinechar+の文字\footnote{普通は,改行文字(文字コード13番)である.}
6400 のカテゴリーコードが5~(\textit{end-of-line})である.
6401 \item \texttt{U+FFFFF}のカテゴリーコードが14~(\textit{comment})である.
6402 \item 入力行は次の「正規表現」にマッチしている:
6403 \[
6404   (\text{any char})^*(\textbf{JAchar})
6405   \bigl(\{\text{catcode}=1\}\cup\{\text{catcode}=2\}\bigr)^*
6406 \]
6407 \end{enumerate}
6408 \end{quote}
6409
6410 この仕様は,前節で述べた\pTeX の仕様にできるだけ近づけたものとなっている.条件1.は,
6411 \texttt{verbatim}系環境などの日本語対応マクロを書かなくてすませるためのものである.
6412
6413 しかしながら,\pTeX と完全に同じ挙動が実現できたわけではない.
6414 次のように,和文文字の範囲を変更したちょうどその行においては挙動が異なる:
6415 \begin{LTXexample}
6416 \fontspec[Ligatures=TeX]{TeX Gyre Termes}
6417 \ltjsetparameter{autoxspacing=false}
6418 \ltjsetparameter{jacharrange={-6}}xあ
6419 y\ltjsetparameter{jacharrange={+6}}zい
6420 u
6421 \end{LTXexample}
6422 上ソース中の「あ」は欧文文字扱いであり.
6423 ここで使用している欧文フォント\TeX\ Gyre Termesは「あ」を含まない.
6424 よって,出力に「あ」は現れないことは不思議ではない.
6425 それでも,\pTeX とまったく同じ挙動を示すならば,出力は
6426 「\hbox{\ltjsetparameter{autoxspacing=false}x yzいu}」となるはずである.しかし,実際には
6427 上のように異なる挙動となっているが,それは以下の理由による:
6428 \begin{itemize}
6429 \item 3行目を \texttt{process\_input\_buffer} で処理する時点では,
6430       「あ」は和文文字扱いである.よって3行目は和文文字で終わることになり,
6431       コメント文字 \texttt{U+FFFFF} が追加される.
6432       よって,直後の改行文字は無視されることになり,空白は入らない.
6433 \item 4行目を \texttt{process\_input\_buffer} で処理する時点では,
6434       「い」は欧文文字扱いである.よって4行目は欧文文字で終わることになり,
6435       直後の改行文字は空白に置き換わる.
6436 \end{itemize}
6437 このため,トラブルを避けるために,和文文字の範囲を\verb+\ltjsetparameter+で編集した場合,
6438 その行はそこで改行するようにした方がいいだろう.
6439 %</ja>
6440
6441 %<*ja>
6442
6443 %<en>\section{Insertion of JFM glues, \Param{kanjiskip} and \Param{xkanjiskip}}
6444 %<ja>\section{JFMグルーの挿入,\Param{kanjiskip}と\Param{xkanjiskip}}
6445 \label{sec-jfmglue}
6446 %<en>\subsection{Overview}
6447 %<ja>\subsection{概要}
6448
6449 \LuaTeX-jaにおける \textbf{JAglue} の挿入方法は,\pTeX のそれとは全く異なる.
6450 \pTeX では次のような仕様であった:
6451 \begin{itemize}
6452 \item JFMグルーの挿入は,和文文字を表すトークンを元に水平リストに(文字を表す)<char\_node>を
6453 追加する過程で行われる.
6454 \item \Param{\hyperlink{fld:xks}{xkanjiskip}}の挿入は,hboxへのパッケージングや行分割前に行われる.
6455 \item \Param{\hyperlink{fld:kanjiskip}{kanjiskip}}はノードとしては挿入されない.パッケージングや行分割の計算時に
6456 「和文文字を表す2つの<char\_node>の間には\Param{\hyperlink{fld:kanjiskip}{kanjiskip}}がある」ものとみなされる.
6457 \end{itemize}
6458 しかし,\LuaTeX-jaでは,hboxへのパッケージングや行分割前に全ての
6459 \textbf{JAglue},即ちJFMグルー・\Param{\hyperlink{fld:xks}{xkanjiskip}}・\Param{\hyperlink{fld:kanjiskip}{kanjiskip}}の
6460 3種類を一度に挿入することになっている.これは,\LuaTeX において欧文の合字・
6461 カーニング処理がノードベースになったことに対応する変更である.
6462
6463 \LuaTeX-jaにおける\textbf{JAglue}挿入処理では,次節で定義する
6464 「クラスタ」を単位にして行われる.大雑把にいうと,「クラスタ」は文字とそれに付随す
6465 るノード達(アクセント位置補正用のカーンや,イタリック補正)をまとめたもの
6466 であり,2つのクラスタの間には,ペナルティ,\verb+\vadjust+,whatsitなど,行組版
6467 には関係しないものがある.
6468
6469
6470 %<en>\subsection{Definition of a Cluster}
6471 %<ja>\subsection{「クラスタ」の定義}
6472
6473 \def\OA{$\text{\sf O}_{\text{\sf A}}$}
6474 \def\OB{$\text{\sf O}_{\text{\sf B}}$}
6475 \begin{defn}
6476 %<*en>
6477 A \emph{cluster} is a list of consecutive nodes in one of the following forms,
6478 with the \textit{id} of it:
6479 %</en>
6480 %<*ja>
6481 \emph{クラスタ}は以下の形のうちのどれかひとつをとる連続的なノードのリストである:
6482 %</ja>
6483 \begin{enumerate}
6484 %<*en>
6485 \item Nodes whose value of\ \verb+\ltj@icflag+ is in $[3,15)$.  These
6486       nodes come from a hbox which is already packaged, by unpackaging
6487       (\verb+\unhbox+).
6488       The \textit{id} is \textit{id\_pbox}.
6489 %</en>
6490 %<*ja>
6491 \item その \verb+\ltj@icflag+ の値が$[3,15)$に入るノードのリスト.
6492   これらのノードはある既にパッケージングされたhboxから \verb+\unhbox+ で
6493   アンパックされたものである.
6494   その\textit{id}は\textit{id\_pbox}である.
6495 %</ja>
6496
6497 %<*en>
6498 \item A inline math formula, including two \textit{math\_node}s at the boundary of it.
6499       The \textit{id} is \textit{id\_math}.
6500 %</en>
6501 %<*ja>
6502 \item インライン数式でその境界に2つの\textit{math\_node}を含むもの.
6503   その\textit{id}は\textit{id\_math}である.
6504 %</ja>
6505
6506 %<*en>
6507 \item A \textit{glyph\_node}~$p$ with nodes which relate with it:
6508 %</en>
6509 %<*ja>
6510 \item \textit{glpyh\_node}~$p$とそれに関係するノード:
6511 %</ja>
6512 \begin{enumerate}
6513 %<*en>
6514 \item A kern for the italic correction of~$p$.
6515 %</en>
6516 %<*ja>
6517 \item $p$のイタリック補正のためのカーン.
6518 %</ja>
6519
6520 %<*en>
6521 \item An accent attached to $p$ by \verb+\accent+.
6522 %</en>
6523 %<*ja>
6524 \item \verb+\accent+ による$p$に付随したアクセント.
6525 %</ja>
6526 \end{enumerate}
6527 \[
6528 \overbrace{%
6529  \Node{kern}{$\mathit{subtype}=2$}\longrightarrow
6530 \left\{\begin{array}{c}
6531 \Node{glyph}{accent}\\\noalign{\medskip}
6532 \Node{hbox}{accent (shifted vert.)}
6533 \end{array}\right\}\longrightarrow
6534 \Node{kern}{$\mathit{subtype}=2$}}^{\text{(a)}}
6535 \longrightarrow
6536 \Node{glyph}{$p$}\longrightarrow
6537 \overbrace{%
6538 \Node{kern}{italic corr.}}^{\text{(b)}}
6539 \]
6540
6541 %<*en>
6542 The \textit{id} is \textit{id\_jglyph} or
6543 \textit{id\_glyph}, according to whether the \textit{glyph\_node}
6544 represents a Japanese character or not.
6545 %</en>
6546 %<*ja>
6547 \textit{id}は\textit{glyph\_node}が和文文字を表すかどうかによって
6548 \textit{id\_jglyph},もしくは\textit{id\_glyph}となる.
6549 %</ja>
6550
6551 %<*en>
6552 \item An box-like node, that is, an hbox, a vbox, a rule (\verb+\vrule+) and an \textit{unset\_node}.
6553 The \textit{id} is \textit{id\_hlist} if the node is an
6554       hbox which is not shifted vertically, or \textit{id\_box\_like}
6555       otherwise.
6556 %</en>
6557 %<*ja>
6558 \item ボックス様のノード,つまり水平ボックス,垂直ボックス,罫線 (\verb+\vrule+),
6559   そして\textit{unset\_node}.
6560   その\textit{id}は垂直に移動していないhboxならば\textit{id\_hlist},
6561   そうでなければ\textit{id\_box\_like}となる.
6562 %</ja>
6563
6564 %<*en>
6565 \item A glue, a kern whose subtype is not 2~(\textit{accent}), and a discretionary break.
6566 The \textit{id} is \textit{id\_glue}, \textit{id\_kern}
6567       and \textit{id\_disc}, respectively.
6568 %</en>
6569 %<*ja>
6570 \item グルー,subtypeが 2~(\textit{accent})ではないカーン,そして任意改行.
6571   その\textit{id}はそれぞれ\textit{id\_glue}, \textit{id\_kern},そして
6572   \textit{id\_disc}である.
6573 %</ja>
6574 \end{enumerate}
6575 %<*en>
6576 Let \textit{Np}, \textit{Nq} and \textit{Nr} denote a cluster.
6577 %</en>
6578 %<*ja>
6579 以下では\textit{Np}, \textit{Nq}, \textit{Nr}でクラスタを表す.
6580 %</ja>
6581 \end{defn}
6582
6583 \paragraph{\textit{id}の意味}
6584 $\mathit{Np}.\mathit{id}$の意味を述べるとともに,
6585 「先頭の文字」を表す\textit{glyph\_node}~$\mathit{Np}.\mathit{head}$と,
6586 「最後の文字」を表す\textit{glyph\_node}~$\mathit{Np}.\mathit{tail}$を次のように定義する.
6587 直感的に言うと,\textit{Np}は$\mathit{Np}.\mathit{head}$で始まり$\mathit{Np}.\mathit{tail}$で終わるような単語,
6588 と見做すことができる.これら$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$は
6589 説明用に準備した概念であって,実際のLuaコード中にそのように書かれているわけではないことに注意.
6590
6591 \begin{description}
6592 \item[\textit{id\_jglyph}] 和文文字.\\
6593 $\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$は,その和文文字を表している
6594 \textit{glyph\_node}そのものである.
6595 \item[\textit{id\_glyph}] 和文文字を表していない\textit{glyph\_node}~$p$.\\
6596 多くの場合,$p$は欧文文字を格納しているが,「ffi」などの合字によって作られた
6597 \textit{glyph\_node}である可能性もある.
6598 前者の場合,$\mathit{Np}.\mathit{head}$,~$\mathit{Np}.\mathit{tail} = p$である.
6599 一方,後者の場合,
6600 \begin{itemize}
6601 \item $\mathit{Np}.\mathit{head}$は,
6602 合字の構成要素の先頭→(その\textit{glyph\_node}における)合字の構成要素の先頭→……
6603 と再帰的に検索していってたどり着いた\textit{glyph\_node}である.
6604 \item $\mathit{Np}.\mathit{last}$は,同様に末尾→末尾→と検索してたどり着いた\textit{glyph\_node}である.
6605 \end{itemize}
6606 \item[\textit{id\_math}] インライン数式.\\
6607 便宜的に,$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$ともに
6608 「文字コード$-1$の欧文文字」とおく.
6609 \item[\textit{id\_hlist}] 縦方向にシフトされていないhbox.\\
6610 この場合,$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$はそれぞれ$p$の内容を表すリストの,
6611 先頭・末尾のノードである.
6612 \begin{itemize}
6613 \item 状況によっては,\TeX ソースで言うと
6614 \begin{verbatim}
6615 \hbox{\hbox{abc}...\hbox{\lower1pt\hbox{xyz}}}
6616 \end{verbatim}
6617 のように,$p$の内容が別のhboxで開始・終了している可能性も十分あり得る.そのような場合,
6618 $\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$の算出は,
6619 \emph{垂直方向にシフトされていない}hboxの
6620 場合だけ内部を再帰的に探索する.例えば上の例では,$\mathit{Np}.\mathit{head}$は文字「a」を表すノードであり,
6621 一方$\mathit{Np}.\mathit{tail}$は垂直方向にシフトされたhbox,
6622 \verb+\lower1pt\hbox{xyz}+ に対応するノードである.
6623 \item また,先頭にアクセント付きの文字がきたり,末尾にイタリック補正用のカーンが
6624 来ることもあり得る.この場合は,クラスタの定義のところにもあったように,それらは無視して算出を行う.
6625 \item 最初・最後のノードが合字によって作られた\textit{glyph\_node}のときは,それぞれに対して\textit{id\_glyph}%
6626 と同様に再帰的に構成要素をたどっていく.
6627 \end{itemize}
6628 \item[\textit{id\_pbox}] 「既に処理された」ノードのリストであり,これらのノードが二度処理を受けないために
6629 まとめて1つのクラスタとして取り扱うだけである.
6630 \textit{id\_hlist}と同じ方法で$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$を算出する,
6631 \item[\textit{id\_disc}] discretionary break (\verb+\discretionary{pre}{post}{nobreak}+).\\
6632 \textit{id\_hlist}と同じ方法で$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$を算出するが,
6633 第3引数の \texttt{nobreak}(行分割が行われない時の内容)を使う.言い換えれば,ここで行分割が発生した時の状況は
6634 全く考慮に入れない.
6635 \item[\textit{id\_box\_like}] \textit{id\_hlist}とならないboxや,rule.\\
6636 この場合は,$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$のデータは利用されないので,2つの算出は無意味である.
6637 敢えて明示するならば,$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$は共にnil値である.
6638 \item[他] 以上にない\textit{id}に対しても,$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$の算出は無意味.
6639 \end{description}
6640
6641 \paragraph{クラスタの別の分類}
6642 さらに,JFMグルー挿入処理の実際の説明により便利なように,\textit{id}とは別のクラスタの分類を行っておく.
6643 挿入処理では2つの隣り合ったクラスタの間に
6644 空白等の実際の挿入を行うことは前に書いたが,ここでの説明では,問題にしているクラスタ\textit{Np}は「後ろ側」のクラスタである
6645 とする.「前側」のクラスタについては,以下の説明で\textit{head}が\textit{last}に置き換わることに注意すること.
6646 \begin{description}
6647 \item[和文A] リスト中に直接出現している和文文字.
6648 \textit{id}が\textit{id\_jglyph}であるか,\\
6649 \textit{id}が\textit{id\_pbox}であって$\mathit{Np}.\mathit{head}$が\textbf{JAchar}であるとき.
6650
6651 \item[和文B] リスト中のhboxの中身の先頭として出現した和文文字.和文Aとの違いは,これの前に
6652 JFMグルーの挿入が行われない(\Param{\hyperlink{fld:xks}{xkanjiskip}},~\Param{\hyperlink{fld:kanjiskip}{kanjiskip}}は入り得る)ことである.\\
6653 \textit{id}が\textit{id\_hlist}か\textit{id\_disc}であって$\mathit{Np}.\mathit{head}$が\textbf{JAchar}であるとき.
6654
6655 \item[欧文] リスト中に直接/hboxの中身として出現している欧文文字.次の3つの場合が該当:
6656 \begin{itemize}
6657 \item \textit{id}が\textit{id\_glyph}である.
6658 \item \textit{id}が\textit{id\_math}である.
6659 \item \textit{id}が\textit{id\_pbox}か\textit{id\_hlist}か\textit{id\_disc}であって,$\mathit{Np}.\mathit{head}$が\textbf{ALchar}.
6660 \end{itemize}
6661 \item[箱] box,またはそれに類似するもの.次の2つが該当:
6662 \begin{itemize}
6663 \item \textit{id}が\textit{id\_pbox}か\textit{id\_hlist}か\textit{id\_disc}であって,$\mathit{Np}.\mathit{head}$が\textit{glyph\_node}でない.
6664 \item \textit{id}が\textit{id\_box\_like}である.
6665 \end{itemize}
6666
6667 \end{description}
6668
6669 \subsection{段落/hboxの先頭や末尾}
6670 \paragraph{先頭部の処理}
6671 まず,段落/hboxの一番最初にあるクラスタ\textit{Np}を探索する.
6672 hboxの場合は何の問題もないが,段落の場合では以下のノード達を事前に読み飛ばしておく:
6673 \begin{itemize}
6674 \item \verb+\parindent+ 由来のhbox($\mathit{subtype}=3$)
6675 \item \textit{subtype}が44~(\textit{user\_defined})でないようなwhatsit
6676 \end{itemize}
6677 これは,\verb+\parindent+由来のhboxがクラスタを構成しないようにするためである.
6678
6679 次に,\textit{Np}の直前に空白$g$を必要なら挿入する:
6680 \begin{enumerate}
6681 \item この処理が働くような\textit{Np}は\textsf{和文A}である.
6682 \item 問題のリストが字下げありの段落(\verb+\parindent+ 由来のhboxあり)の場合は,
6683 この空白$g$は「文字コード \texttt{'parbdd'} の文字」と\textit{Np}の間に入るグルー/カーンである.
6684 \item そうでないとき(\verb+noindent+ で開始された段落やhbox)は,
6685 $g$は「文字コード \texttt{'boxbdd'} の文字」と\textit{Np}の間に入るグルー/カーンである.
6686 \end{enumerate}
6687 ただし,もし$g$がglueであった場合,この挿入によって\textit{Np}による行分割が新たに可能になるべきではない.
6688 そこで,以下の場合には,$g$の直前に \verb+\penalty10000+ を挿入する:
6689 \begin{itemize}
6690 \item 問題にしているリストが段落であり,かつ
6691 \item \textit{Np}の前には予めペナルティがなく,$g$はglue.
6692 \end{itemize}
6693
6694 \paragraph{末尾の処理}
6695 末尾の処理は,問題のリストが段落のものかhboxのものかによって異なる.
6696 後者の場合は容易い:最後のクラスタを\textit{Nq}とおくと,\textit{Nq}と「文字コード\ 
6697 \texttt{'boxbdd'} の文字」の間に入るグルー/カーンを,
6698 \textit{Nq}の直後に挿入するのみである.
6699
6700 一方.前者(段落)の場合は,リストの末尾は常に \verb+\penalty10000+ と,
6701 \verb+\parfillskip+ 由来のグルーが存在する.%よって,最後のクラスタ\textit{Np}は
6702 %この \verb+\parfillskip+ 由来のグルーとなり,実質的な中身の最後はその1つ前のクラスタ\textit{Nq}となる.
6703 段落の最後の「通常の和文文字${}+{}$句点」が独立した行となるのを防ぐために,
6704 \Param{jcharwidowpenalty}の値の分だけ適切な場所のペナルティを増やす.
6705
6706 ペナルティ量を増やす場所は,\textit{head}が\textbf{JAchar}であり,
6707 かつその文字の\Param{kcatcode}が偶数であるような
6708 最後のクラスタの直前にあるものたちである%
6709 \footnote{大雑把に言えば,\Param{kcatcode}が奇数であるような\textbf{JAchar}%
6710 を約物として考えていることになる.
6711 \Param{kcatcode}の最下位ビットはこの\Param{jcharwidowpenalty}用にのみ利用される.}.
6712
6713 \subsection{概観と典型例:2つの「和文A」の場合}
6714 \label{ssec-cluster-wa}
6715 先に述べたように,2つの隣り合ったクラスタ,\textit{Nq}と\textit{Np}の間には,
6716 ペナルティ,\verb+\vadjust+,whatsitなど,行組版には関係しないものがある.模式的に表すと,
6717 \[
6718  \Node{cluster}{\textit{Nq}}\longrightarrow
6719 \overbrace{
6720 \Node{penalty}{$p$}\longrightarrow \cdots\longrightarrow \Node{whatsit}{}}^{\textrm{(a)}}
6721 \longrightarrow \Node{cluster}{\textit{Np}}
6722 \]
6723 のようになっている.間の(a)に相当する部分には,何のノードもない場合ももちろんあり得る.
6724 そうして,JFMグルー挿入後には,この2クラスタ間は次のようになる:
6725 \[
6726  \Node{cluster}{\textit{Nq}}\longrightarrow%\Node{kern}{左空白}\longrightarrow
6727 \overbrace{
6728 \Node{penalty}{$p+x$}\longrightarrow \cdots\longrightarrow 
6729 \Node{whatsit}{}}^{\textrm{(a)}}\longrightarrow 
6730 \Node{glue or kern}{\raisebox{-.2\zw}{右空白}}\longrightarrow
6731 \Node{cluster}{\textit{Np}}
6732 \]
6733
6734 以後,\emph{典型的な例として,クラスタ\textit{Nq}と\textit{Np}が共に\textsf{\textmd{和文A}}である場合を見ていこう,}
6735 この場合が全ての場合の基本となる.
6736
6737 \paragraph{「右空白」の算出}
6738 まず,「右空白」にあたる量を算出する.通常はこれが,隣り合った2つの和文文字間に入る空白量となる.
6739 \begin{description}
6740 \item[JFM由来{[M]}] JFMの文字クラス指定によって入る空白を以下によって求める.この段階で空白量が未定義(未指定)だった場合,
6741       デフォルト値\Param{\hyperlink{fld:kanjiskip}{kanjiskip}}を採用することとなるので,次へ.
6742 \begin{enumerate}
6743 \item もし両クラスタの間で \verb+\inhibitglue+ が実行されていた場合(証としてwhatsitノードが自動挿入される),
6744       代わりに\Param{\hyperlink{fld:kanjiskip}{kanjiskip}}が挿入されることとなる.次へ.
6745 \item \textit{Nq}と\textit{Np}が同じJFM・同じ\texttt{jfmvar}キー・同じサイズの和文フォントであったならば,
6746       共通に使っているJFM内で挿入される空白(グルーかカーン)が決まっているか調べ,決まっていればそれを採用.
6747 \item 1.でも2.でもない場合は,JFM・\texttt{jfmvar}・サイズの3つ組は\textit{Nq}と\textit{Np}で異なる.
6748 この場合,まず
6749 \[
6750 \vcenter{\halign{\hfil$#:={}$&\inhibitglue#\inhibitglue\cr
6751 gb&(\textit{Nq}と「使用フォントが\textit{Nq}のそれと同じで,\hfil\cr
6752 \omit&\quad 文字コードが\textit{Np}のそれの文字」との間に入るグルー/カーン)\hfil\cr
6753 ga&(\inhibitglue 「使用フォントが\textit{Np}のそれと同じで,\hfil\cr
6754 \omit&\quad 文字コードが\textit{Nq}のそれの文字」と\textit{Np}との間に入るグルー/カーン)\hfil\cr
6755 }}
6756 \]
6757 として,前側の文字のJFMを使った時の空白(グルー/カーン)と,後側の文字のJFMを使った時のそれを求める.
6758
6759 $\mathit{gb}$,~$\mathit{ga}$それぞれに対する<ratio>の値を$d_b$,~$d_a$とする.
6760 \begin{itemize}
6761 \item 
6762 $\mathit{ga}$と$\mathit{gb}$の両方が未定義であるならば,JFM由来のグルーは挿入されず,
6763 \Param{\hyperlink{fld:kanjiskip}{kanjiskip}}を採用することとなる.
6764 どちらか片方のみが未定義であるならば,次のステップでその未定義の方は長さ0のkernで,<ratio>の値は0であるかのように扱われる.
6765 \item 
6766 \Param{\hyperlink{fld:diffjfm}{diffrentjfm}}の値が \texttt{pleft}, \texttt{pright},
6767       \texttt{paverage} のとき,
6768 <ratio>の指定に従って比例配分を行う.
6769 JFM由来のグルー/カーンは以下の値となる:
6770 \[
6771  f\left(\frac{1-d_b}2\textit{gb} + \frac{1+d_b}2\textit{ga},
6772 \frac{1-d_a}2\textit{gb} + \frac{1+d_a}2\textit{ga}\right)
6773 \]
6774 ここで.$f(x,y)$は
6775 \[
6776  f(x,y)=\begin{cases}
6777 x&\text{if\ }\Param{\hyperlink{fld:diffjfm}{diffrentjfm}}=\texttt{pleft};\\
6778 y&\text{if\ }\Param{\hyperlink{fld:diffjfm}{diffrentjfm}}=\texttt{pright};\\
6779 (x+y)/2&\text{if\ }\Param{\hyperlink{fld:diffjfm}{diffrentjfm}}=\texttt{paverage};
6780 \end{cases}.
6781 \]
6782 \item 
6783 \Param{differentjfm}がそれ以外の値の時は,<ratio>の値は無視され,JFM由来のグルー/カーンは以下の値となる:
6784 \[
6785  f(\textit{gb},\textit{ga})
6786 \]
6787 ここで.$f(x,y)$は
6788 \[
6789  f(x,y)=\begin{cases}
6790 \min(x,y)&\text{if\ }\Param{\hyperlink{fld:diffjfm}{diffrentjfm}}=\texttt{small};\\
6791 \max(x,y)&\text{if\ }\Param{\hyperlink{fld:diffjfm}{diffrentjfm}}=\texttt{large};\\
6792 (x+y)/2&\text{if\ }\Param{\hyperlink{fld:diffjfm}{diffrentjfm}}=\texttt{average};\\
6793 x+y&\text{if\ }\Param{\hyperlink{fld:diffjfm}{diffrentjfm}}=\texttt{both};
6794 \end{cases}.
6795 \]
6796 \end{itemize}
6797 \end{enumerate}
6798
6799 例えば,
6800 \begin{verbatim}
6801 \jfont\foo=psft:Ryumin-Light:jfm=ujis;-kern
6802 \jfont\bar=psft:GothicBBB-Medium:jfm=ujis;-kern
6803 \jfont\baz=psft:GothicBBB-Medium:jfm=ujis;jfmvar=piyo;-kern
6804 \end{verbatim}
6805 という3フォントを考え,
6806 \[
6807  \overbrace{\Node{glyph}{{\tt\textbackslash foo}, `あ'}}^{p}
6808 \longrightarrow \overbrace{\Node{glyph}{{\tt\textbackslash bar}, `い'}}^{q}
6809 \longrightarrow \overbrace{\Node{glyph}{{\tt\textbackslash baz}, `う'}}^{r}
6810 \]
6811 という3ノードを考える(それぞれ単独でクラスタをなす).
6812 この場合,$p$と$q$の間は,実フォントが異なるにもかかわらず2.の状況となる一方で,
6813 $q$と$r$の間は(実フォントが同じなのに)\texttt{jfmvar} キーの内容が異なるので3.の状況となる.
6814 \item[\Param{kanjiskip}~{[K]}] 上の[M]において空白が定まらなかった場合,
6815 以下で定めた量「右空白」として採用する.
6816 この段階においては,\verb+\inhibitglue+ は効力を持たないため,
6817 結果として,2つの和文文字間には常に何らかのグルー/カーンが挿入されることとなる.
6818 \begin{enumerate}
6819 \item 両クラスタ(厳密には$\mathit{Nq}.\mathit{tail}$,$\mathit{Np}.\mathit{head}$)の中身の文字コードに対する
6820 \Param{autospacing}パラメタが両方ともfalseだった場合は,長さ0のglueとする.
6821 \item ユーザ側から見た\Param{\hyperlink{fld:kanjiskip}{kanjiskip}}パラメタの自然長が${\tt \textbackslash maxdimen}=(2^{30}-1)\,{\rm sp}$で
6822 なければ,\Param{\hyperlink{fld:kanjiskip}{kanjiskip}}パラメタの値を持つglueを採用する.
6823 \item 2.でない場合は,\textit{Nq}, \textit{Np}で使われているJFMに指定されている\Param{\hyperlink{fld:kanjiskip}{kanjiskip}}の値を用いる.
6824 どちらか片方のクラスタだけが和文文字(\textsf{和文A}・\textsf{和文B})のときは,そちらのクラスタで使われている
6825 JFM由来の値だけを用いる.もし両者で使われているJFMが異なった場合は,上の[M]~3.と同様の方法を用いて調整する.
6826 \end{enumerate}
6827 \end{description}
6828 %\paragraph{「左空白」の算出とそれに伴う補正}
6829 %「左空白」は過去のバージョンでは定義していたが,このバージョンでは
6830 %挿入は一切行われない(機能自体削除している).
6831 %しかし,仕様は流動的であり,将来復活する可能性もあるため,マニュアル中の記述は今のところ極力変更しない.
6832 \paragraph{禁則用ペナルティの挿入}
6833 まず,
6834 \[
6835  a:=(\text{\textit{Nq}{\footnotemark}の文字に対する\Param{\hyperlink{fld:postbp}{postbreakpenalty}}の値})
6836 +(\text{\textit{Np}{\footnotemark}の文字に対する\Param{\hyperlink{fld:prebp}{prebreakpenalty}}の値})
6837 \]
6838 とおく\footnotetext{厳密にはそれぞれ$\mathit{Nq}.\mathit{tail}$,$\mathit{Np}.\mathit{head}$.}.
6839 ペナルティは通常$[-10000,10000]$の整数値をとり,また$\pm 10000$は正負の無限大を意味することになっているが,この$a$の
6840 算出では単純な整数の加減算を行う.
6841
6842 $a$は禁則処理用に\textit{Nq}と\textit{Np}の間に加えられるべきペナルティ量である.
6843 \begin{description}
6844 \item[P-normal~{[PN]}]
6845 \textit{Nq}と\textit{Np}の間の(a)部分にペナルティ(\textit{penalty\_node})があれば処理は簡単である:
6846 それらの各ノードにおいて,ペナルティ値を($\pm 10000$を無限大として扱いつつ)$a$だけ増加させればよい.
6847 また,$10000 + (-10000) = 0$としている.
6848
6849 少々困るのは,(a)部分にペナルティが存在していない場合である.
6850 直感的に,補正すべき量$a$が0でないとき,その値をもつ\textit{penalty\_node}を作って
6851 「右空白」の(もし未定義なら\textit{Np}の)直前に挿入……
6852 ということになるが,実際には僅かにこれより複雑である.
6853 \begin{itemize}
6854 \item 「右空白」がカーンであるとき,
6855 それは「\textit{Nq}と\textit{Np}の間で改行は許されない」ことを意図している.そのため,
6856 この場合は$a\neq 0$であってもペナルティの挿入はしない.
6857 \item そうでないないときは,$a\neq 0$ならば\textit{penalty\_node}を作って挿入する.
6858 %\item 「左空白」がカーンとしてきっちり定義されている時(このとき,「右空白」はカーンでない),
6859 %この「左空白」の直後での行分割を許容しないといけないので,$a=0$であっても
6860 %\textit{penalty\_node}を作って挿入する.
6861 %\item 以上のどれでもないときは,$a\neq 0$ならば\textit{penalty\_node}を作って挿入する.
6862 \end{itemize}
6863 \end{description}
6864
6865 \def\gkf#1#2#3{\sf$\displaystyle\vphantom{\Bigg(}%
6866   \frac{\hbox to 4\zw{\hss#2\hss}}{\hbox{#3}}$}
6867 \begin{table}[t]
6868 %<en>\caption{Summary of JFM glues}
6869 %<ja>\caption{JFM グルーの概要}
6870 \label{tab-jfmglue}
6871 %<en>\medskip
6872 \begin{center}
6873 \small
6874 \begin{tabular}{c|cccccc}
6875 \toprule
6876 {\bf\textit{Np}}↓&\sf 和文A&\sf 和文B&\sf 欧文&\sf 箱&\sf glue&\sf kern\\\midrule
6877 \sf 和文A&
6878 \gkf{E}{M→K}{PN}&
6879 \gkf{---}{\OA →K}{PN}&
6880 \gkf{---}{\OA →X}{PN}&
6881 \gkf{---}{\OA}{PA}&
6882 \gkf{---}{\OA}{PN}&
6883 \gkf{---}{\OA}{PS}\\
6884 \sf 和文B&
6885 \gkf{E}{\OB→K}{PA}&
6886 \gkf{---}{K}{PS}&
6887 \gkf{---}{X}{PS}\\
6888 \sf 欧文&
6889 \gkf{E}{\OB →X}{PA}&
6890 \gkf{---}{X}{PS}\cr
6891 \sf 箱&\gkf{E}{\OB}{PA}\\
6892 \sf glue&\gkf{E}{\OB}{PN}\\
6893 \sf kern&\gkf{E}{\OB}{PS}\\
6894 \bottomrule
6895 \end{tabular}
6896 \end{center}
6897 \begin{quote}
6898 %<*en>
6899 In the table above, {\small\gkf{E}{M→K}{PN}} means that
6900 %</en>
6901 %<*ja>
6902 上の表において,{\small\gkf{E}{M→K}{PN}}は次の意味である:
6903 %</ja>
6904 \begin{enumerate}
6905 %<*en>
6906 \item To determine the ``right-space'', \LuaTeX-ja first attempts by the method ``\textsf{JFM-origin~[M]}''.
6907 If this attempt fails, \LuaTeX-ja use the method ``\textsf{\Param{kanjiskip}~[K]}''.
6908 %</en>
6909 %<*ja>
6910 \item 「右空白」を決めるために,\LuaTeX-ja はまず「JFM由来{[M]}」の方法を試みる.
6911   これが失敗したら,\LuaTeX-ja は「\Param{kanjiskip}~{[K]}」の方法を試みる.
6912 %</ja>
6913
6914 % %<*en>
6915 % \item The ``left space'' between \textit{Nq}~and~\textit{Np} is 
6916 %   determined by the method ``\textsf{line-end~[E]}''.
6917 % %</en>
6918 % %<*ja>
6919 % \item \textit{Nq} と \textit{Np} の間の「左空白」は「\textsf{line-end~[E]}」の
6920 %   方法で決定される.
6921 % %</ja>
6922
6923 %<*en>
6924 \item \LuaTeX-ja adopts the method ``\textsf{P-normal~[PN]}'' to adjust the penalty 
6925   between two clusters for \emph{kinsoku shori}.
6926 %</en>
6927 %<*ja>
6928 \item \LuaTeX-jaは2つのクラスタの間の禁則処理用のペナルティを設定するために「\textsf{P-normal~[PN]}」の方法を採用する.
6929 %</ja>
6930 \end{enumerate}
6931 \end{quote}
6932 \end{table}
6933
6934 \subsection{その他の場合}
6935 本節の内容は表\ref{tab-jfmglue}にまとめてある.
6936
6937 \paragraph{和文Aと欧文の間}
6938 \textit{Nq}が\textsf{和文A}で,\textit{Np}が\textsf{欧文}の場合,JFMグルー挿入処理は次のようにして行われる.
6939 \begin{itemize}
6940 \item 「右空白」については,まず以下に述べる\textsf{Boundary-B~[\OB]}により空白を決定しようと試みる.
6941 それが失敗した場合は,\textsf{\Param{\hyperlink{fld:xks}{xkanjiskip}}~[X]}によって定める.
6942 %\item 「左空白」については,既に述べた\textsf{line-end~[E]}をそのまま採用する.それに伴う「右空白」の補正も%同じ.
6943 \item 禁則用ペナルティも,以前述べた\textsf{P-normal~[PN]}と同じである.
6944 \end{itemize}
6945 \begin{description}
6946 \item[Boundary-B~{[\OB]}] 和文文字と「和文でないもの」との間に入る空白を以下によって求め,
6947 未定義でなければそれを「右空白」として採用する.
6948 \textsf{JFM-origin~[M]}の変種と考えて良い.
6949 これによって定まる空白の典型例は,和文の閉じ括弧と欧文文字の間に入る半角アキである.
6950 \begin{enumerate}
6951 \item もし両クラスタの間で \verb+\inhibitglue+ が実行されていた場合%
6952 (証としてwhatsitノードが自動挿入される),「右空白」は未定義.
6953 \item そうでなければ,
6954 \textit{Nq}と「文字コードが {\tt'jcharbdd'} の文字」との間に入るグルー/カーンとして定まる.
6955 \end{enumerate}
6956 \item[\Param{xkanjiskip}~{[X]}]
6957 この段階では,\textsf{\Param{kanjiskip}~[K]}のときと同じように,
6958 以下で定めた量を「右空白」として採用する.
6959 \verb+\inhibitglue+ は効力を持たない.
6960 \begin{enumerate}
6961 \item 以下のいずれかの場合は,\Param{\hyperlink{fld:xks}{xkanjiskip}}の挿入は抑止される.しかし,実際には行分割を許容するために,長さ0のglueを採用する:
6962 \begin{itemize}
6963 \item 両クラスタにおいて,それらの中身の文字コードに対する\Param{autoxspacing}パラメタが共にfalseである.
6964 \item \textit{Nq}の中身の文字コードについて,「直後への\Param{\hyperlink{fld:xks}{xkanjiskip}}の挿入」が禁止されている
6965 (つまり,\Param{jaxspmode}~(or \Param{alxspmode})パラメタが2以上).
6966 \item \textit{Np}の中身の文字コードについて,「直前への\Param{\hyperlink{fld:xks}{xkanjiskip}}の挿入」が禁止されている
6967 (つまり,\Param{jaxspmode}~(or \Param{alxspmode})パラメタが偶数).
6968 \end{itemize}
6969 \item ユーザ側から見た\Param{\hyperlink{fld:xks}{xkanjiskip}}パラメタの自然長が${\tt \textbackslash maxdimen}=(2^{30}-1)\,{\rm sp}$で
6970 なければ,\Param{\hyperlink{fld:xks}{xkanjiskip}}パラメタの値を持つglueを採用する.
6971 \item 2.でない場合は,\textit{Nq}, \textit{Np}(\textsf{和文A}/\textsf{和文B}なのは片方だけ)
6972 で使われているJFMに指定されている\Param{\hyperlink{fld:xks}{xkanjiskip}}の値を用いる.
6973 \end{enumerate}
6974 \end{description}
6975
6976 \paragraph{欧文と和文Aの間}
6977 \textit{Nq}が\textsf{欧文}で,\textit{Np}が\textsf{和文A}の場合,JFMグルー挿入処理は上の場合とほぼ同じである.
6978 \textsf{和文A}のクラスタが逆になるので,\textsf{Boundary-A~[\OA]}の部分が変わるだけ.
6979 \begin{itemize}
6980 \item 「右空白」については,まず以下に述べる\textsf{Boundary-A~[\OA]}により空白を決定しようと試みる.
6981 それが失敗した場合は,\textsf{\Param{\hyperlink{fld:xks}{xkanjiskip}}~[X]}によって定める.
6982 %\item \textit{Nq}が和文でないので,「左空白」は算出されない.
6983 \item 禁則用ペナルティは,以前述べた\textsf{P-normal~[PN]}と同じである.
6984 \end{itemize}
6985 \begin{description}
6986 \item[Boundary-A~{[\OA]}] 「和文でないもの」と和文文字との間に入る空白を以下によって求め,
6987 未定義でなければそれを「右空白」として採用する.
6988 \textsf{JFM-origin~[M]}の変種と考えて良い.
6989 これによって定まる空白の典型例は,欧文文字と和文の開き括弧との間に入る半角アキである.
6990 \begin{enumerate}
6991 \item もし両クラスタの間で \verb+\inhibitglue+ が実行されていた場合(証としてwhatsitノードが自動挿入される),次へ.
6992 \item そうでなければ,
6993 「文字コードが {\tt'jcharbdd'} の文字」と\textit{Np}との間に入るグルー/カーンとして定まる.
6994 \end{enumerate}
6995 \end{description}
6996
6997 \paragraph{和文Aと箱・グルー・カーンの間}
6998 \textit{Nq}が\textsf{和文A}で,\textit{Np}が\textsf{箱}・グルー・カーンのいずれかであった場合,
6999 両者の間に挿入されるJFMグルーについては同じ処理である.しかし,そこでの行分割に対する仕様が異なるので,
7000 ペナルティの挿入処理は若干異なったものとなっている.
7001
7002 \begin{itemize}
7003 \item 「右空白」については,既に述べた\textsf{Boundary-B~[\OB]}により空白を決定しようと試みる.
7004 それが失敗した場合は,「右空白」は挿入されない.
7005 %\item 「左空白」については,既に述べた\textsf{line-end~[E]}の算出方法をそのまま採用する.それに伴う「右空白」の補正も同じ.
7006 \item 禁則用ペナルティの処理は,後ろのクラスタ\textit{Np}の種類によって異なる.
7007 なお,$\mathit{Np}.\mathit{head}$は無意味であるから,
7008 「$\mathit{Np}.\mathit{head}$に対する\Param{\hyperlink{fld:prebp}{prebreakpenalty}}の値」は0とみなされる.言い換えれば,
7009 \[
7010  a:=(\text{\textit{Nq}の文字に対する\Param{\hyperlink{fld:postbp}{postbreakpenalty}}の値}).
7011 \]
7012 \begin{description}
7013 \item[箱] \textit{Np}が\textsf{箱}であった場合は,両クラスタの間での行分割は
7014 (明示的に両クラスタの間に \verb+\penalty10000+ があった場合を除き)いつも許容される.そのため,
7015 ペナルティ処理は,後に述べる\textsf{P-allow~[PA]}が\textsf{P-normal~[PN]}の代わりに用いられる.
7016 \item[グルー] \textit{Np}がグルーの場合,ペナルティ処理は\textsf{P-normal~[PN]}を用いる.
7017 \item[カーン] \textit{Np}がカーンであった場合は,両クラスタの間での行分割は
7018 (明示的に両クラスタの間にペナルティがあった場合を除き)許容されない.
7019 ペナルティ処理は,後に述べる\textsf{P-suppress~[PS]}を使う.
7020 \end{description}
7021 これらの\textsf{P-normal~[PN]},\textsf{P-allow~[PA]},\textsf{P-suppress~[PS]}の違いは,
7022 \textit{Nq}と\textit{Np}の間(以前の図だと(a)の部分)にペナルティが存在しない場合にのみ存在する.
7023 \end{itemize}
7024
7025 \begin{description}
7026 \item[P-allow~{[PA]}]
7027 \textit{Nq}と\textit{Np}の間の(a)部分にペナルティがあれば,\textsf{P-normal~[PN]}と同様に,
7028 それらの各ノードにおいてペナルティ値を$a$だけ増加させる.
7029
7030 (a)部分にペナルティが存在していない場合,
7031 \LuaTeX-ja は\textit{Nq}と\textit{Np}の間の行分割を可能にしようとする.
7032 そのために,以下の場合に$a$をもつ\textit{penalty\_node}を作って
7033 「右空白」の(もし未定義なら\textit{Np}の)直前に挿入する:
7034 \begin{itemize}
7035 \item 「右空白」がグルーでない(カーンか未定義)であるとき.
7036 %\item 「左空白」がカーンとしてきっちり定義されている時.
7037 \end{itemize}
7038
7039 \item[P-suppress~{[PS]}]
7040 \textit{Nq}と\textit{Np}の間の(a)部分にペナルティがあれば,\textsf{P-normal~[PN]}と同様に,
7041 それらの各ノードにおいてペナルティ値を$a$だけ増加させる.
7042
7043 (a)部分にペナルティが存在していない場合,
7044 \textit{Nq}と\textit{Np}の間の行分割は元々不可能のはずだったのであるが,
7045 \LuaTeX-ja はそれをわざわざ行分割可能にはしない.
7046 そのため,「右空白」がglueであれば,その直前に \verb+\penalty10000+ を挿入する.
7047 \end{description}
7048
7049 なお,「右空白」はカーンの%,「左空白」は未定義の
7050 \[
7051  \overbrace{\Node{glyph}{`あ'}}^{\mathit{Nq}}\longrightarrow \overbrace{\Node{glue}{1\,pt}}^{\mathit{Np}}
7052 \]
7053 のような状況を考える.
7054 このとき,$a$,即ち「あ」の\Param{\hyperlink{fld:postbp}{postbreakpenalty}}がいかなる値であっても,
7055 この2クラスタ間は最終的に
7056 \begin{equation}
7057  \overbrace{\Node{glyph}{`あ'}}^{\mathit{Nq}}\longrightarrow
7058 \Node{kern}{右空白}\longrightarrow \overbrace{\Node{glue}{1\,pt}}^{\mathit{Np}}
7059 \label{eq-gref}
7060 \end{equation}
7061 となり,$a$分のペナルティは挿入されないことに注意して欲しい.
7062 \Param{\hyperlink{fld:postbp}{postbreakpenalty}}は($a$は)殆どの場合が非負の値と考えられ,そのような場合では
7063 \eqref{eq-gref}と
7064 \[
7065  \overbrace{\Node{glyph}{`あ'}}^{\mathit{Nq}}\longrightarrow
7066 \Node{penalty}{$a$}\longrightarrow
7067 \Node{kern}{右空白}\longrightarrow \overbrace{\Node{glue}{1\,pt}}^{\mathit{Np}}
7068 \]
7069 との間に差異は生じない%
7070 \footnote{kern$\rightarrow$glueが1つの行分割可能点(行分割に伴うペナルティは0)
7071 であるため,たとえ$a=10000$であっても,\textit{Nq}と\textit{Np}の間で行分割を禁止することはできない.}.
7072
7073 \paragraph{箱・グルー・カーンと和文Aの間}
7074 \textit{Np}が\textsf{箱}・グルー・カーンのいずれかで,\textit{Np}が\textsf{和文A}であった場合は,
7075 すぐ上の(\textit{Nq}と\textit{Np}の順序が逆になっている)場合と同じである.
7076 %が,「左空白」がなくなることにのみ注意.
7077 \begin{itemize}
7078 \item 「右空白」については,既に述べた\textsf{Boundary-A~[\OA]}により空白を決定しようと試みる.
7079 それが失敗した場合は,「右空白」は挿入されない.
7080 %\item \textit{Nq}が和文でないので,「左空白」は算出されない.
7081 \item 禁則用ペナルティの処理は,\textit{Nq}の種類によって異なる.
7082 $\mathit{Nq}.\mathit{tail}$は無意味なので,
7083 \[
7084  a:=(\text{\textit{Np}の文字に対する\Param{\hyperlink{fld:prebp}{prebreakpenalty}}の値}).
7085 \]
7086 \begin{description}
7087 \item[箱] \textit{Nq}が\textsf{箱}の場合は,\textsf{P-allow~[PA]}を用いる.
7088 \item[グルー] \textit{Nq}がグルーの場合は,\textsf{P-normal~[PN]}を用いる.
7089 \item[カーン] \textit{Nq}がカーンの場合は,\textsf{P-suppress~[PS]}を用いる.
7090 \end{description}
7091 \end{itemize}
7092
7093 \paragraph{和文Aと和文Bの違い}
7094 先に述べたように,\textsf{和文B}はhboxの中身の先頭(or 末尾)として出現している
7095 和文文字である.リスト内に直接ノードとして現れている和文文字(\textsf{和文A})との違いは,
7096 \begin{itemize}
7097 \item \textsf{和文B}に対しては,JFMの文字クラス指定から定まる空白
7098 \textsf{JFM-origin~[M]},\textsf{Boundary-A~[\OA]},\textsf{Boundary-B~[\OB]})の挿入は行われない.
7099 %「左空白」の算出も行われない.
7100 例えば,
7101 \begin{itemize}
7102 \item 片方が\textsf{和文A},もう片方が\textsf{和文B}のクラスタの場合,
7103 \textsf{Boundary-A~[\OA]}または\textsf{Boundary-B~[\OB]}の挿入を試み,それがダメなら
7104 \Param{kanjiskip}~\textsf{[K]}の挿入を行う.
7105 \item \textsf{和文B}の2つのクラスタの間には,\Param{kanjiskip}~\textsf{[K]}が自動的に入る.
7106 \end{itemize}
7107 \item \textsf{和文B}と箱・グルー・カーンが隣接したとき(どちらが前かは関係ない),間にJFMグルー・ペナルティの挿入は一切しない.
7108 \item \textsf{和文B}と\textsf{和文B},また\textsf{和文B}と\textsf{欧文}とが隣接した時は,禁則用ペナルティ挿入処理は
7109 \textsf{P-suppress~[PS]}が用いられる.
7110 \item \textsf{和文B}の文字に対する\Param{\hyperlink{fld:prebp}{prebreakpenalty}},~\Param{\hyperlink{fld:postbp}{postbreakpenalty}}の値は使われず,0として計算される.
7111 \end{itemize}
7112
7113
7114 次が具体例である:
7115 \begin{LTXexample}
7116 あ.\inhibitglue A\\
7117 \hbox{あ.}A\\
7118 あ.A
7119 \end{LTXexample}
7120 \begin{itemize}
7121 \item 1行目の\verb+\inhibitglue+は\textsf{Boundary-B~[\OB]}の処理のみを抑止するので,ピリオドと「A」の間には
7122 \Param{\hyperlink{fld:xks}{xkanjiskip}}(四分アキ)が入ることに注意.
7123 \item 2行目のピリオドと「A」の間においては,前者が\textsf{和文B}となる(hboxの中身の末尾として登場しているから)ので,
7124 そもそも\textsf{Boundary-B~[\OB]}の処理は行われない.よって,\Param{\hyperlink{fld:xks}{xkanjiskip}}が入ることとなる.
7125 \item 3行目では,ピリオドの属するクラスタは\textsf{和文A}である.これによって,
7126 ピリオドと「A」の間には\textsf{Boundary-B~[\OB]}由来の半角アキが入ることになる.
7127 \end{itemize}
7128 %</ja>
7129
7130 %<en>\section{Patch for the \Pkg{listings} Package}
7131 %<ja>\section{\Pkg{listings} パッケージへの対応}
7132
7133 %<*en>
7134 It is well-known that the \Pkg{listings} package outputs weird results
7135 for Japanese input.
7136 The \Pkg{listings} package makes most of letters active and assigns
7137 output command for each letter~(\cite{listings}).
7138 But Japanese characters are not included in these activated letters.
7139 For \pTeX{} series, there is no method to make Japanese characters active;
7140 a patch \Pkg{jlisting.sty}~(\cite{jlisting}) resolves the problem forcibly.
7141 %</en>
7142 %<*ja>
7143 \Pkg{listings} パッケージが,そのままでは日本語をまともに出力できないこと
7144 はよく知られている.きちんと整形して出力するために,\Pkg{listings}パッケー
7145 ジは内部で「ほとんどの文字」をアクティブにし,各文字に対してその文字の出
7146 力命令を割り当てている(\cite{listings}).
7147 しかし,そこでアクティブにする文字の中に,和文文
7148 字がないためである.\pTeX 系列では,和文文字をアクティブにする手法がなく,
7149 \Pkg{jlisting.sty} というパッチ(\cite{jlisting})を用いることで無理やり解決していた.
7150 %</ja>
7151
7152 %<*en>
7153 In \LuaTeX-ja, the problem is resolved by using the \verb+process_input_buffer+ callback.
7154 The callback function inserts the output command (active character \texttt{U+FFFFF})
7155 before each letter above \texttt{U+0080}.
7156 This method can omits the process to make all Japanese characters active
7157 (most of the activated characters are not used in many cases).
7158 %</en>
7159 %<*ja>
7160 \LuaTeX-jaでは,\verb+process_input_buffer+ コールバックを利用することで,
7161 「各行に出現する\texttt{U+0080}以降の文字に対して,それらの出力命令を前置する」
7162 という方法をとっている.出力命令としては,アクティブ文字化した \texttt{U+FFFFF} を用いている.
7163 これにより,(入力には使用されていないかもしれない)和文文字をもすべてアクティブ化する手間もなく,
7164 見通しが良い実装になっている.
7165 %</ja>
7166
7167
7168 %<*en>
7169 If the \Pkg{listings} package  and \LuaTeX-ja were loaded,
7170 then the patch \Pkg{lltjp-listings} is loaded automatically at \verb+\begin{document}+.
7171 %</en>
7172 %<*ja>
7173 \LuaTeX-ja で利用される \Pkg{listings} パッケージへのパッチ \Pkg{lltjp-listings} は,
7174 \Pkg{listings} と\LuaTeX-jaを読み込んでおけば,
7175 \verb+\begin{document}+ の箇所において自動的に読み込まれるので,通常はあまり
7176 意識する必要はない.
7177 %</ja>
7178
7179 %<en>\subsection{Notes}
7180 %<ja>\subsection{注意}
7181 %<*en>
7182 \paragraph{Escaping to \LaTeX}
7183 We used the \verb+process_input_buffer+ callback to output \textbf{JAchar}s.
7184 But it has a drawback; any commands whose name contains a \textbf{JAchar}
7185 cannot be used in any ``escape to \LaTeX''.
7186
7187 Consider the following input:
7188 %</en>
7189 %<*ja>
7190 \paragraph{\LaTeX へのエスケープ}
7191 日本語対応を行うために \verb+process_input_buffer+ を使用したことで,
7192 \texttt{texcl},~\texttt{escapeinside}といった\emph{「\LaTeX へのエスケープ」中では,
7193 \textbf{JAchar}を名称の一部に含む制御綴は使用不可能}である.
7194 例えば次のような入力を考えよう:
7195 %</ja>
7196 \begin{verbatim*}
7197 \begin{lstlisting}[escapechar=\#]
7198 #\ほげ xぴよ#
7199 \end{lstlisting}
7200 \end{verbatim*}
7201 %<en>The line~2 is transformed by the callback to
7202 %<ja>ここで,2行目は \verb+process_input_buffer+ の作用により,
7203 \begin{lstlisting}[showspaces, escapechar=\!]
7204 #\!\IVSA FFFFF!ほ!\IVSA FFFFF !げ x!\IVSA FFFFF !ぴ!\IVSA FFFFF !よ#
7205 \end{lstlisting}
7206 %<*en>
7207 before the line is actually processed.
7208 In the escape (between the character ``\verb+#+''), 
7209 the category code of \texttt{U+FFFFF} is set to 9~(\emph{ignored}).
7210 Hence the control symbol ``\verb+\+\IVSA FFFFF'' will be executed,
7211 instead of ``\verb+\ほげ+''.
7212 %</en>
7213 %<*ja>
7214 と変換されてから,実際の処理に回される.
7215 「\verb+#+」で挟まれた「\LaTeX へのエスケープ」中では\
7216 \texttt{U+FFFFF} のカテゴリーコードは9~(\textit{ignored})となるので,
7217 結局「\verb+\ほげ+」の代わりに
7218 「\verb+\+\IVSA FFFFF」というcontrol symbolが実行されることになる.
7219 %</ja>
7220
7221 %<*ja>
7222 \paragraph{異体字セレクタの扱い}
7223 \texttt{lstlisting} 環境などの内部にある異体字セレクタを扱うため,
7224 \Pkg{lltjp-listings} では \texttt{vsraw} と \texttt{vscmd} という2つのキーを追加した.
7225 しかし,\Pkg{lltjp-listings} が実際にロードされるのは \verb+\begin{document}+\ 
7226 のところであるので,プリアンブル内ではこれらの追加キーは使用できない.
7227
7228 \texttt{vsraw}は,ブール値の値をとるキーであり,標準ではfalseである.
7229 \begin{itemize}
7230  \item trueの場合は,異体字セレクタは「直前の文字に続けて」出力される.
7231 もしもIVSサポート(\ref{ssec-ltjotf}節)が有効になっていた場合は,
7232 以下の例(左側は入力,右側はその出力)のようになる.
7233 \begin{LTXexample}
7234 \begin{lstlisting}[vsraw=true]
7235 葛󠄀城市,葛󠄁飾区,葛西
7236 \end{lstlisting}
7237 \end{LTXexample}
7238 \item falseの場合は,異体字セレクタは適当な命令によって「見える形で」出力される.
7239 どのような形で出力されるかを規定するのが \texttt{vscmd} キーであり,
7240 \Pkg{lltjp-listings} の標準設定では以下の例の右側のように出力される.
7241 \begin{LTXexample}
7242 \begin{lstlisting}[vsraw=false, 
7243    vscmd=\ltjlistingsvsstdcmd]
7244 葛󠄀城市,葛󠄁飾区,葛西
7245 \end{lstlisting}
7246 \end{LTXexample}
7247 ちなみに,本ドキュメントでは次のようにしている:
7248 \begin{lstlisting}[numbers=left]
7249 \def\IVSA#1#2#3#4#5{%
7250   \textcolor{blue}{\raisebox{3.5pt}{\tt%
7251     \fboxsep=0.5pt\fbox{\tiny \oalign{0#1#2\crcr#3#4#5\crcr}}}}%
7252 }
7253 {\catcode`\%=11
7254   \gdef\IVSB#1{\expandafter\IVSA\directlua{
7255     local cat_str = luatexbase.catcodetables['string']
7256     tex.sprint(cat_str, string.format('%X', 0xE00EF+#1))
7257 }}}
7258 \lstset{vscmd=\IVSB}
7259 \end{lstlisting}
7260 \end{itemize}
7261 既定の出力命令を復活させたい場合は\ \verb+vsraw=\ltjlistingsvsstdcmd+\ 
7262 とすれば良い.
7263 %</ja>
7264
7265 %<en>\subsection{Class of Characters}
7266 %<ja>\subsection{文字種}
7267
7268 %<en>Roughly speaking, the \Pkg{listings} package processes input as follows:
7269 %<ja>\Pkg{listings} パッケージの内部では,大雑把に言うと
7270 \begin{enumerate}
7271 %<en>\item Collects \textit{letters} and \textit{digits}, which can be used for the name of identifiers.
7272 %<ja>\item 識別子として使える文字 (``letter'',~``digit'') たちを集める.
7273 %<en>\item When reading an \textit{other}, outputs the collected character string (with modification, if needed).
7274 %<ja>\item letterでもdigitでもない文字が現れた時に,収集した文字列を(必要なら修飾して)出力する.
7275 %<en>\item Collects \textit{others}.
7276 %<ja>\item 今度は逆に,letterでない文字たちをletterが現れるまで集める.
7277 %<en>\item When reading a \textit{letter} or a \textit{digit}, outputs the collected character string.
7278 %<ja>\item letterが出現したら集めた文字列を出力する.
7279 %<en>\item Turns back to 1.
7280 %<ja>\item 1.に戻る.
7281 \end{enumerate}
7282 %<*en>
7283 By the above process, line breaks inside of an identifier are blocked.
7284 A flag \verb+\lst@ifletter+ indicates whether the previous character can be used
7285 for the name of identifiers or not.
7286 %</en>
7287 %<*ja>
7288 という処理が行われている.これにより,識別子の途中では行分割が行われないようになっている.
7289 直前の文字が識別子として使えるか否かは \verb+\lst@ifletter+ というフラグに格納されている.
7290 %</ja>
7291
7292 %<*en>
7293 For Japanese characters, line breaks are permitted on both sides
7294 except for brackets, dashes, etc.
7295 Hence the patch \Pkg{lltjp-listings} introduces 
7296 a new flag \verb+\lst@ifkanji+, which indicates
7297 whether the previous character is a Japanese character or not.
7298 For illustration, we introduce following classes of characters:
7299 %</en>
7300 %<*ja>
7301 さて,日本語の処理である.殆どの和文文字の前後では行分割が可能であるが,その一方で
7302 括弧類や音引きなどでは禁則処理が必要なことから,\Pkg{lltjp-listings} では,
7303 直前が和文文字であるかを示すフラグ \verb+\lst@ifkanji+ を新たに導入した.
7304 以降,説明のために以下のように文字を分類する:
7305 %</ja>
7306 \begin{center}
7307 \small
7308 \begin{tabular}{lccccc}
7309 \toprule
7310 &Letter&Other&Kanji&Open&Close\\\midrule
7311 \verb+\lst@ifletter+&T&F&T&F&T\\
7312 \verb+\lst@ifkanji+&F&F&T&T&F\\
7313 %<en>Meaning&char in an identifier&other alphabet&%
7314 %<en>most of Japanese char&opening brackets&closing brackets\\
7315 %<ja>意図&識別子中の文字&その他欧文文字&殆どの和文文字&開き括弧類&閉じ括弧類\\
7316 \bottomrule
7317 \end{tabular}
7318 \end{center}
7319 %<*en>
7320 Note that \textit{digits} in the \Pkg{listings} package can be Letter or
7321 Other according to circumstances.
7322 %</en>
7323 %<*ja>
7324 なお,本来の\Pkg{listings} パッケージでの分類``digit''は,
7325 出現状況によって,上の表のLetterとOtherのどちらにもなりうる.
7326 また,KanjiとCloseは \verb+\lst@ifletter+ と \verb+\lst@ifkanji+ の値が一致しているが,
7327 これは間違いではない.
7328 %</ja>
7329
7330 %<*en>
7331 For example, let us consider the case an Open comes after a Letter.
7332 Since an Open represents Japanese open brackets,
7333 it is preferred to be permitted to insert line break after the Letter.
7334 Therefore, the collected character string is output in this case.
7335 %</en>
7336 %<*ja>
7337 例えば,Letterの直後にOpenが来た場合を考える.
7338 文字種Openは和文開き括弧類を想定しているので,Letterの直後では行分割が可能であることが望ましい.
7339 そのため,この場合では,すでに収集されている文字列を出力することで行分割を許容するようにした.
7340 %</ja>
7341
7342 %<*en>
7343 The following table summarizes $5\times 5=25$ cases:
7344 %</en>
7345 %<*ja>
7346 同じように,$5\times 5=25$通り全てについて書くと,次のようになる:
7347 %</ja>
7348 \begin{center}
7349 \small
7350 \begin{tabular}{llccccc}
7351 \toprule
7352 %<*en>
7353 &&\multicolumn{4}{c}{Next}\\\cmidrule(lr){3-7}
7354 &&\hbox to 4em{\hss Letter\hss}&\hbox to 4em{\hss Other\hss}
7355 &\hbox to 4em{\hss Kanji\hss}&\hbox to 4em{\hss Open\hss}&Close\\\midrule
7356 &Letter&collects&\multicolumn{3}{c}{\hrulefill \ outputs\ \hrulefill}&collects\\
7357 &Other&outputs&collects&\multicolumn{2}{c}{\hrulefill \ outputs\ \hrulefill}&collects\\
7358 Prev&Kanji&\multicolumn{4}{c}{\hrulefill \ outputs\ \hrulefill}&collects\\
7359 &Open&\multicolumn{5}{c}{\hrulefill \ collects\ \hrulefill}\\
7360 &Close&\multicolumn{4}{c}{\hrulefill \ outputs\ \hrulefill}&collects\\
7361 %</en>
7362 %<*ja>
7363 &&\multicolumn{4}{c}{後ろ側の文字}\\\cmidrule(lr){3-7}
7364 &&\hbox to 4em{\hss Letter\hss}&\hbox to 4em{\hss Other\hss}
7365 &\hbox to 4em{\hss Kanji\hss}&\hbox to 4em{\hss Open\hss}&Close\\\midrule
7366 直&Letter&収集&\multicolumn{3}{c}{\hrulefill \ 出力\ \hrulefill}&収集\\
7367 前&Other&出力&収集&\multicolumn{2}{c}{\hrulefill \ 出力\ \hrulefill}&収集\\
7368 文&Kanji&\multicolumn{4}{c}{\hrulefill \ 出力\ \hrulefill}&収集\\
7369 字&Open&\multicolumn{5}{c}{\hrulefill \ 収集\ \hrulefill}\\
7370 種&Close&\multicolumn{4}{c}{\hrulefill \ 出力\ \hrulefill}&収集\\
7371 %</ja>
7372 \bottomrule
7373 \end{tabular}
7374 \end{center}
7375 %<en>In the above table,
7376 %<ja>上の表において,
7377 \begin{itemize}
7378 %<en>\item ``outputs'' means to output the collected character string (i.e., line breaking is permitted there).
7379 %<ja>\item 「出力」は,それまでに集めた文字列を出力(≒ここで行分割可能)を意味する.
7380
7381 %<en>\item ``collects'' means to append the next character to the collected character string (i.e., line breaking is prohibited there).
7382 %<ja>\item 「収集」は,後側の文字を,現在収集された文字列に追加(行分割不可)を意味する.
7383 \end{itemize}
7384
7385 %<*en> 
7386 Charatcers above \texttt{U+0080} \emph{except Variation Selectors}
7387 are classified into above 5~classes by the following rules:
7388 %</en>
7389 %<*ja>
7390 \texttt{U+0080}以降の\emph{異体字セレクタ以外の}各文字が
7391 Letter, Other, Kanji, Open, Closeのどれに属するかは次によって決まる:
7392 %</ja>
7393 \begin{itemize}
7394 %<en>\item \textbf{ALchar}s above \texttt{U+0080} are classified as Letter.
7395 %<ja>\item (\texttt{U+0080}以降の)\textbf{ALchar}は,すべてLetter扱いである.
7396
7397 %<en>\item \textbf{JAchar}s are classified in the order as follows:
7398 %<ja>\item \textbf{JAchar}については,以下の順序に従って文字種を決める:
7399 \begin{enumerate}
7400 %<en>\item Characters whose \Param{\hyperlink{fld:prebp}{prebreakpenalty}} is greater than or equal to 0 are classified as Open.
7401 %<ja>\item \Param{\hyperlink{fld:prebp}{prebreakpenalty}}が0以上の文字はOpen扱いである.
7402
7403 %<en>\item Characters whose \Param{\hyperlink{fld:postbp}{postbreakpenalty}} is greater than or equal to 0 are classified as Close.
7404 %<ja>\item \Param{\hyperlink{fld:postbp}{postbreakpenalty}}が0以上の文字はClose扱いである.
7405
7406 %<en>\item Characters that don't satisfy the above two conditions are classified as Kanji.
7407 %<ja>\item 上の3条件のどちらにも当てはまらなかった文字は,Kanji扱いである.
7408 \end{enumerate}
7409 \end{itemize}
7410
7411 %<*en>
7412 The width of halfwidth kana (\texttt{U+FF61}--\texttt{U+FF9F}) 
7413 is same as the width of \textbf{ALchar};
7414 the width of the other \textbf{JAchar}s is double the width of \textbf{ALchar}.
7415 %</en>
7416 %<*ja>
7417 なお,半角カナ(U+FF61--U+FF9F)以外の\textbf{JAchar}は欧文文字2文字分の幅をとるものとみなされる.
7418 半角カナは欧文文字1文字分の幅となる.
7419 %</ja>
7420
7421 %<*en>
7422 This classification process is executed every time a character appears in
7423 the \texttt{lstlisting} environment or other environments/commands.
7424 %</en>
7425 %<*ja>
7426 これらの文字種決定は,実際に \texttt{lstlisting} 環境などの内部で文字が出てくるたびに行われる.
7427 %</ja>
7428
7429 %<*ja>
7430 \section{和文の行長補正方法}
7431 \label{sec-adjspec}
7432 \Pkg{luatexja-adjust} で提供される優先順位付きの行長調整の詳細を述
7433 べる.大まかに述べると,次のようになる.
7434 \begin{itemize}
7435 \item 通常の\TeX の行分割方法に従って,段落を行分割する.この段階では,行
7436       長に半端が出た場合,その半端分は\textbf{JAglue}(\Param{\hyperlink{fld:xks}{xkanjiskip}},
7437       \Param{\hyperlink{fld:kanjiskip}{kanjiskip}},JFMグルー)と
7438       それ以外のグルーの全てで(優先順位なく)負担される.
7439 \item その後,\texttt{post\_linebreak\_filter} callbackを使い,\emph{段
7440       落中の各行ごとに},行末文字の位置を調整したり,優先度付きの行長調整
7441       を実現するためにグルーの伸縮度を調整する.
7442       その処理においては,グルーの自然長と\textbf{JAglue}以外の
7443       グルーの伸び量・縮み量は変更せず,必要に応じて\textbf{JAglue}の伸び量・縮み量のみを
7444       変更する設計とした.
7445
7446 \Pkg{luatexja-adjust} の作用は,この処理を行うcallbackを追加するだけであり,
7447       この章の残りではcallbackでの処理について解説する.
7448 \end{itemize}
7449
7450 \paragraph{準備:合計伸縮量の計算}
7451 グルーの伸縮度(\texttt{plus} や \texttt{minus} で指定されている値)には,
7452 有限値の他に,\texttt{fi},\texttt{fil},\texttt{fill},\texttt{filll}と
7453 いう4つの無限大レベル(後ろの方ほど大きい)があり,行の調整に
7454 \texttt{fi} などの\emph{無限大レベルの伸縮度が用いられている場合は,そ
7455 の行に対しての処理を中止}する.
7456
7457 よって,以降,問題にしている行の行長調整は伸縮度が有限長のグルーを用いて
7458 行われているとして良い.さらに,簡単のため,この行はグルーが広げられている
7459 (自然長で組むと望ましい行長よりの短い)場合しか扱わない.
7460
7461 まず,段落中の行中のグルーを
7462 \begin{itemize}
7463 \item \textbf{JAglue}ではないグルー
7464 \item JFMグルー(優先度\footnote{%
7465   \ref{ssec-jfm-str}節にあるように,
7466   各JFMグルーには$-2$から2までの優先度がついている.}%
7467 別にまとめられる)
7468 \item 和欧文間空白(\Param{\hyperlink{fld:xks}{xkanjiskip}})
7469 \item 和文間空白(\Param{\hyperlink{fld:kanjiskip}{kanjiskip}})
7470 \end{itemize}
7471 の$1+1+5+1=8$つに類別し,それぞれの種別ごとに
7472 許容されている伸び量(\texttt{stretch}の値)の合計を計算する.
7473 また,行長と自然長との差を\textit{total}とおく.
7474
7475
7476 \subsection{行末文字の位置調整}
7477 行末が文字クラス$n$の\textbf{JAchar}であった場合,
7478 それを動かすことによって,\textit{total}のうち
7479 \textbf{JAglue}が負担する分を少なくしようとする.
7480 この行末文字の左右の移動可能量は,
7481 JFM中にある文字クラス$n$の定義の
7482 \texttt{end\_stretch},~\texttt{end\_shrink}フィールドに
7483 全角単位の値として記述されている.
7484
7485 例えば,行末文字が句点「。」であり,そこで用いられているJFM中に
7486 \begin{verbatim}
7487   [2] = {
7488     chars = { '。', ... }, width = 0.5, ...,
7489     end_stretch = 0.5, end_shrink = 0.5,
7490   }, 
7491 \end{verbatim}
7492 という指定があった場合,この行末の句点は
7493 \begin{itemize}
7494 \item 通常の\TeX の行分割処理で「半角以上の詰め」が行われていた場合,
7495 この行中の\textbf{JAglue}の負担を軽減するため,
7496 行末の句点を半角だけ右に移動する(ぶら下げ組を行う).
7497 \item 通常の\TeX の行分割処理で「半角以上の空き」が行われていた場合,
7498 逆に行末句点を半角左に移動させる(見た目的に全角取りとなる).
7499 \item 以上のどちらでもない場合,行末句点の位置調整は行わない.
7500 \end{itemize}
7501 となる.
7502
7503 行末文字を移動した場合,その分だけ\textit{total}の値を引いておく.
7504
7505 \subsection{グルーの調整}
7506 \textit{total}の分だけが,行中のグルーの伸び量に応じて負担されることになる.
7507 負担するグルーの優先度は以下の順であり,
7508 できるだけ\Param{\hyperlink{fld:kanjiskip}{kanjiskip}}を自然長のままにすることを
7509 試みている.
7510 \begin{enumerate}\def\labelenumi{(\Alph{enumi})}
7511  \item \textbf{JAglue}以外のグルー
7512  \item 優先度2のJFMグルー
7513  \item 優先度1のJFMグルー
7514  \item 優先度0のJFMグルー
7515  \item 優先度$-1$のJFMグルー
7516  \item 優先度$-2$のJFMグルー
7517  \item \Param{\hyperlink{fld:xks}{xkanjiskip}}
7518  \item \Param{\hyperlink{fld:kanjiskip}{kanjiskip}}
7519 \end{enumerate}
7520 \begin{enumerate}
7521  \item 行末の和文文字を移動したことで$\textit{total}=0$となれば,
7522 調整の必要はなく,行が格納されているhboxの
7523 \texttt{glue\_set}, \texttt{glue\_sign}, \texttt{glue\_order}を再計算すればよい.
7524 以降,$\textit{total}\neq 0$と仮定する.
7525  \item \textit{total}が「\textbf{JAglue}以外のグルーの伸び量の合計」(以下,(A)の伸び量の
7526        合計,と称す)よりも小さければ,
7527 それらのグルーに\textit{total}を負担させ,\textbf{JAglue}達自身は自然長で組むことができる.
7528 よって,以下の処理を行う:
7529 \begin{enumerate}
7530 \item 各\textbf{JAglue}の伸び量を0とする.
7531 \item 行が格納されているhboxの
7532 \texttt{glue\_set}, \texttt{glue\_sign}, \texttt{glue\_order}を再計算する.
7533 これによって,\textit{total}は\textbf{JAglue}以外のグルーによって負担される.
7534 \end{enumerate}
7535 \item \textit{total}が「(A)の伸び量の合計」以上ならば,(A)--(H)のどこまで負担すれば
7536 \textit{total}以上になるかを計算する.
7537 例えば,
7538 \[\catcode`\<=12
7539  \textit{total} = (\text{(A)--(B)の伸び量の合計}) + p\cdot (\text{(C)の伸び量の合計}),
7540  \qquad 0\le p<1
7541 \]
7542 であった場合,各グルーは次のように組まれる:
7543 \begin{itemize}
7544  \item (A),~(B)に属するグルーは各グルーで許された伸び量まで伸ばす.
7545  \item (C)に属するグルーはそれぞれ$p\times (\text{伸び量})$だけ伸びる.
7546  \item (D)--(H)に属するグルーは自然長のまま.
7547 \end{itemize}
7548 実際には,前に述べた「設計」に従い,次のように処理している:
7549 \begin{enumerate}
7550 \item (C)に属するグルーの伸び量を$p$倍する.
7551 \item (D)--(H)に属するグルーの伸び量を0とする.
7552 \item 行が格納されているhboxの
7553 \texttt{glue\_set}, \texttt{glue\_sign}, \texttt{glue\_order}を再計算する.
7554 これによって,\textit{total}は\textbf{JAglue}以外のグルーによって負担される.
7555 \end{enumerate}
7556 \item \textit{total}が(A)--(H)の伸び量の合計よりも大きい場合,どうしようもないので
7557       \verb+^^;+何もしない.
7558 \end{enumerate}
7559
7560 %</ja>
7561
7562 %<*ja>
7563 \section{IVS対応}
7564 \verb+luatexja.otf.enable_ivs()+ を実行し,IVS対応を有効にした状態では,
7565 \verb+pre_linebreak_filter+ や \verb+hpack_filter+ コールバックには
7566 次の4つが順に実行される状態となっている:
7567 \begin{description}
7568 \item[\tt ltj.do\_ivs] \textit{glyph\_node}~$p$の直後に,異体字セレクタ(を表す\textit{glyph\_node})
7569 が連続した場合に,$p$のフォントに対応したが持つ「異体字情報」に従って出力するグリフを変える.
7570
7571 しかし,単に$p.\textit{char}$を変更するだけでは,後から
7572 font featureの適用(すぐ下)により置換される可能性がある.そのため,
7573 \verb+\CID+ や \verb+\UTF+ と同じように,\textit{glyph\_node}~$p$の代わりに
7574 \texttt{user\_id} が\textit{char\_by\_cid}であるようなuser-defined whatsitを用いている.
7575 \item[(\Pkg{luaotfload} によるfont featureの適用)]
7576 \item[\tt ltj.otf] \texttt{user\_id} が\textit{char\_by\_cid}であるようなuser-defined whatsitを
7577 きちんと\textit{glyph\_node}に変換する.この処理は,\verb+\CID+, \verb+\UTF+やIVSによる置換が,
7578 font featureの適用で上書きされてしまうのを防止するためである.
7579 \item[\tt ltj.main\_process] \textbf{JAglue}の挿入処理(\ref{sec-jfmglue}章)と,
7580 JFMの指定に従って各\textbf{JAchar}の「寸法を補正」することを行う.
7581 \end{description}
7582
7583 問題は各フォントの持っているIVS情報をどのように取得するか,である.
7584 \Pkg{luaotfload} はフォント番号<font\_number>の情報を\ 
7585 \texttt{fonts.hashes.identifiers[<font\_number>]} 以下に格納している.
7586 しかし,OpenTypeフォントのIVS情報は格納されていないようである%
7587 \footnote{TrueTypeフォントに関しては,
7588 \begin{center}
7589 \texttt{fonts.hashes.idenfiers[<font\_number>]%
7590   .resources.variants[<selector>][<base\_char>]}
7591 \end{center}
7592 に,<base\_char>番の文字の後に異体字セレクタ<selector>が続いた場合に
7593 出力すべきグリフが書かれてある.}.
7594 %例えば,小塚明朝Pr6N~Rでは,
7595
7596 一方,\LuaTeX 内部の \texttt{fontloader} の返すテーブルには
7597 OpenTypeフォントでもTrueTypeフォントでもIVS情報が格納されている.
7598 具体的には……
7599
7600 そのため,\LuaTeX-jaのIVS対応においては,\LuaTeX 内部の\ 
7601 \texttt{fontloader} を直接用いることで,フォントのIVS情報を取得している.
7602 20140114.0以降でキャッシュを用いるようにした要因はここにあり,
7603 \texttt{fontloader} の呼び出しでかなり時間を消費することから,
7604 %%% to_table を使わなくしたことで,メモリ使用量は減った
7605 IVS情報をキャッシュに保存することで2回目以降の実行時間を節約している.
7606
7607
7608 \section{複数フォントの「合成」(未完)}
7609
7610 \section{\LuaTeX-jaにおけるキャッシュ}
7611 \Pkg{luaotfload}パッケージが,各TrueType・]OpenTypeフォントの情報を
7612 キャッシュとして保存しているのと同様の方法で,
7613 \LuaTeX-jaもいくつかのキャッシュファイルを作成するようになった.
7614 \begin{itemize}
7615  \item 通常,キャッシュは\texttt{\$TEXMFVAR/luatexja/}以下に保存され,
7616 そこから読み込みが行われる.
7617  \item 「通常の」テキスト形式のキャッシュ(拡張子は \texttt{.lua})以外にも,
7618 それをバイナリ形式(バイトコード)に変換したものもサポートしている.
7619 \begin{itemize}
7620  \item \LuaTeX とLuaJIT\TeX ではバイトコードの形式が異なるため,バイナリ形式の
7621 キャッシュは共有できない.\LuaTeX 用のバイナリキャッシュは \texttt{.luc},
7622 LuaJIT\TeX 用のは \texttt{.lub} と拡張子を変えることで対応している.
7623  \item キャッシュを読み込む時,同名のバイナリキャッシュがあれば,
7624 テキスト形式のものよりそちらを優先して読み込む.
7625  \item テキスト形式のキャッシュが更新/作成される際は,そのバイナリ版も
7626 同時に更新される.
7627 また,(バイナリ版が見つからず)テキスト形式のキャッシュ側が読み込まれたときは,
7628 \LuaTeX-jaはバイナリキャッシュを作成する.
7629 \end{itemize}
7630 \end{itemize}
7631 %</ja>
7632 %<*en>
7633 \section{Cache Management of \LuaTeX-ja}
7634 \LuaTeX-ja creates some cache files to reduce the loading time. 
7635 in a similar way to the \Pkg{luaotfload} package:
7636 \begin{itemize}
7637  \item Cache files are usually stored in (and loaded from)
7638 \texttt{\$TEXMFVAR/luatexja/}.
7639  \item In addition to caches of the text form (the extension is ``\texttt{.lua}''),
7640 caches of the \emph{binary}, precompiled form are supported.
7641 \begin{itemize}
7642  \item We cannot share same binary cache for \LuaTeX\ and LuaJIT\TeX.
7643 Hence we distinguish them by their extension, ``\texttt{.luc}'' for \LuaTeX\
7644 and ``\texttt{.lub}'' for LuaJIT\TeX.
7645  \item In loading a cache, the binary cache precedes 
7646 the text form.
7647  \item When \LuaTeX-ja updates a cache \texttt{hoge.lua}, 
7648 its binary version is also updated.
7649 \end{itemize}
7650 \end{itemize}
7651 %</en>
7652
7653 %<*ja>
7654 \subsection{キャッシュの使用箇所}
7655
7656 \LuaTeX-ja では以下の3種類のキャッシュを使用している:
7657 \begin{list}{}%
7658 {\def\makelabel#1{\ttfamily#1}}
7659 \item[ltj-cid-auto-adobe-japan1.lua] 
7660 Ryumin-Lightのような非埋め込みフォントの情報を格納しており,
7661 (それらが\LuaTeX-jaの標準和文フォントなので)\LuaTeX-jaの読み込み時に自動で読まれる.
7662 生成には\texttt{UniJIS2004-UTF32-H}, \texttt{Adobe-Japan1-UCS2}という2つの
7663 CMapが必要である.
7664
7665 \pageref{para-cid}ページで述べたように,\texttt{cid}キーを使って
7666 非埋め込みの中国語・韓国語フォントを定義する場合,同様のキャッシュが生成される.
7667 キャッシュの名称,必要となるCMapについては表\ref{tab:cid-cache}を参照して欲しい.
7668
7669 \item[ivs\_***.lua]
7670 フォント``\texttt{***}''における異体字情報を格納している.構造は以下の通り:
7671 %</ja>
7672 %<*en>
7673 \subsection{Use of Cache}
7674
7675 \LuaTeX-ja uses the following cache:
7676 \begin{list}{}%
7677 {\def\makelabel#1{\ttfamily#1}}
7678 \item[ltj-cid-auto-adobe-japan1.lua] 
7679 The font table of a CID-keyed non-embedded Japanese font.
7680 This is loaded in every run.
7681 It is created from two CMaps, \texttt{UniJIS2004-UTF32-H} and
7682              \texttt{Adobe-Japan1-UCS2}, 
7683 and this is why these two CMaps are needed in the first run of \LuaTeX-ja.
7684
7685 Similar caches are created as Table~\ref{tab:cid-cache}, 
7686 if you specified \texttt{cid} key in \verb+\jfont+
7687 to use other CID-keyed non-embedded fonts for Chinese or Korean,
7688 as in Page~\pageref{para-cid}.
7689
7690 \item[ivs\_***.lua]
7691 This file stores the table of Unicode variants in a font ``\texttt{***}''. 
7692 The structure of the table is the following:
7693 %</en>
7694
7695 \begin{table}[!tb]
7696  \centering\small
7697 \caption{\texttt{cid} key and corresponding files}
7698 \label{tab:cid-cache}
7699 \vspace*{\medskipamount}
7700 \begin{tabular}{>{\tt}l>{\tt}l>{\tt}l>{\tt}l}
7701 \toprule
7702 \bf \texttt{cid} key&\bf name of the cache &
7703 \multicolumn{2}{c}{\bf used CMaps}\\
7704 \midrule
7705 Adobe-Japan1-*&ltj-cid-auto-adobe-japan1.lua&UniJIS2004-UTF32-H&Adobe-Japan1-UCS2\\
7706 Adobe-Korea1-*&ltj-cid-auto-adobe-korea1.lua&UniKS-UTF32-H&Adobe-Korea1-UCS2\\
7707 Adobe-GB1-*&ltj-cid-auto-adobe-gb1.lua&UniGB-UTF32-H&Adobe-GB1-UCS2\\
7708 Adobe-CNS1-*&ltj-cid-auto-adobe-cns1.lua&UniCNS-UTF32-H&Adobe-CNS1-UCS2\\
7709 \bottomrule
7710 \end{tabular}
7711 \end{table}
7712
7713 \begin{lstlisting}
7714 return {
7715  {
7716   [10955]={    -- U+2ACB "Subset Of Above Not Equal To"
7717    [65024]=983879, -- <2ACB FE00>
7718   },
7719   [37001]={    -- U+9089 "邉"
7720    [0]=37001,  --   <9089 E0100>
7721    991049,     --   <9089 E0101>
7722    ...
7723   },
7724   ...
7725  },
7726  ["chksum"]="FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", -- checksum of the fontfile
7727  ["version"]=4, -- version of the cache
7728 }
7729 \end{lstlisting}
7730 %<*ja>
7731 \item[ltj-jisx0208.\{luc|lub\}]
7732 \LuaTeX-ja配布中の\texttt{ltj-jisx0208.lua}をバイナリ化したものである.
7733 これはJIS~X~0208とUnicodeとの変換テーブルであり,
7734 \pTeX との互換目的の文字コード変換命令で用いられる.
7735 %</ja>
7736 %<*en>
7737 \item[ltj-jisx0208.\{luc|lub\}]
7738 The binary version of \texttt{ltj-jisx0208.lua}. 
7739 This is the conversion table between JIS~X~0208 and Unicode
7740 which is used in Kanji-code conversion commands for compatibility with \pTeX.
7741 %</en>
7742 \end{list}
7743
7744 %<*en>
7745 \subsection{Internal}
7746 Cache management system of \LuaTeX-ja is stored in \texttt{luatexja.base}
7747 (\texttt{ltj-base.lua}).
7748 There are three public functions for cache management in \texttt{luatexja.base}, 
7749 where <filename> stands for the filename \emph{without suffix}:
7750 \begin{list}{}%
7751 {\def\makelabel#1{\ttfamily#1}}
7752 \item[save\_cache(<filename>, <data>)]
7753 Save a non-nil table <data> into a cache <filename>.
7754 Both the text form <filename>\texttt{.lua} and its binary version 
7755 are created or updated.
7756
7757 \item[save\_cache\_luc(<filename>, <data>{[, <serialized\_data>]})]\ 
7758
7759 Same as \texttt{save\_cache}, except that only the binary cache is updated. 
7760 The third argument <serialized\_data> is not usually given.
7761 But if this is given, it is treated as a string representation of <data>.
7762
7763 \item[load\_cache(<filename>, <outdate>)]
7764 Load the cache <filename>.
7765 <outdate> is a function which takes one argument (the contents of the cache),
7766 and its return value is whether the cache is outdated.
7767
7768 \texttt{load\_cache} first tries to 
7769 read the binary cache <filename>\texttt{.\{luc|lub\}}.
7770 If its contents is up-to-date, \texttt{load\_cache} returns the contents.
7771 If the binary cache is not found or 
7772 its contents is outdated, \texttt{load\_cache} tries to 
7773 read the text form <filename>\texttt{.lua}.
7774 Hence, the return value of \texttt{load\_cache} is non-nil,
7775 if and only if the updated cache is found.
7776 \end{list}
7777 %</en>
7778 %<*ja>
7779 \subsection{内部命令}
7780 \LuaTeX-jaにおけるキャッシュ管理は,\texttt{luatexja.base}~(\texttt{ltj-base.lua})に
7781 実装しており,以下の3関数が公開されている.
7782 ここで,<filename>は保存するキャッシュのファイル名を\emph{拡張子なしで}指定する.
7783 \begin{list}{}%
7784 {\def\makelabel#1{\ttfamily#1}}
7785 \item[save\_cache(<filename>, <data>)]
7786 nilでない<data>をキャッシュ<filename>に保存する.
7787 テキスト形式の<filename>\texttt{.lua}のみならず,
7788 そのバイナリ版も作成/更新される.
7789
7790 \item[save\_cache\_luc(<filename>, <data>{[, <serialized\_data>]})]\ 
7791
7792 \texttt{save\_cache}と同様だが,バイナリキャッシュのみが更新される.
7793 第3引数<serialized\_data>が与えられた場合,それを
7794 <data>の文字列化表現として使用する.
7795 そのため,<serialized\_data>は普通は指定しないことになるだろう.
7796
7797 \item[load\_cache(<filename>, <outdate>)]
7798 キャッシュ<filename>を読み込む.
7799 <outdate>は1引数(キャッシュの中身)をとる関数であり,
7800 その戻り値は「キャッシュの更新が必要」かどうかを示すブール値でないといけない.
7801
7802 \texttt{load\_cache}は,まずバイナリキャッシュ<filename>\texttt{.\{luc|lub\}}を
7803 読みこむ.もしその内容が「新しい」,つまり<outdate>の評価結果が \texttt{false} なら
7804 \texttt{load\_cache}はこのバイナリキャッシュの中身を返す.
7805 もしバイナリキャッシュが見つからなかったか,「古すぎる」ならばテキスト版
7806              <filename>\texttt{.lua}を読み込み,その値を返す.
7807
7808 以上より,\texttt{load\_cache}自体がnilでない値を返すのは,ちょうど「新しい」キャッシュが
7809 見つかった場合である.
7810 \end{list}
7811 %</ja>
7812
7813
7814 %<*ja>
7815 \section{縦組の実装}
7816
7817
7818 %</ja>
7819
7820 \begin{thebibliography}{99}
7821   \addcontentsline{toc}{section}{\refname}
7822 \bibitem{texbytopic}
7823 Victor Eijkhout. \newblock \textit{\TeX\ by Topic, A \TeX nician's Reference}, Addison-Wesley, 1992.
7824 \bibitem{listings} C.\ Heinz, B.\ Moses. \newblock The \textsf{Listings} Package.
7825 \bibitem{uptex} Takuji Tanaka. \newblock
7826 upTeX---Unicode version of pTeX with CJK extensions, 
7827 TUG 2013, October 2013.
7828 %<ja>\newblock
7829 %<en>\\\null\hfill
7830 \url{http://tug.org/tug2013/slides/TUG2013_upTeX.pdf}
7831 \bibitem{jlisting} Thor Watanabe. \newblock Listings\ -\ MyTeXpert. 
7832 %<en>\newblock
7833 %<ja>\\\null\hfill
7834 \url{http://mytexpert.sourceforge.jp/index.php?Listings}
7835 \bibitem{jlreq}  W3C Japanese Layout Task Force~(ed). \newblock
7836 Requirements for Japanese Text Layout (W3C Working Group Note), 2011, 2012. \newblock
7837 \url{http://www.w3.org/TR/jlreq/}%
7838 %<ja> \\日本語訳の書籍版:W3C日本語組版タスクフォース(編),『W3C技術ノート 日本語組版処理の要件』,東京電機大学出版局,2012.
7839 \bibitem{min10} 乙部厳己.min10フォントについて.\\\null\hfill
7840 \url{http://argent.shinshu-u.ac.jp/~otobe/tex/files/min10.pdf}
7841 \bibitem{x4051} 日本工業規格(Japanese Industrial Standard). JIS~X~4051,
7842 日本語文書の組版方法(Formatting rules for Japanese documents), 1993, 1995, 2004.
7843 \bibitem{ptexdoc} 濱野尚人,田村明史,倉沢良一.\TeX の出版への応用—縦組み機能の組み込み—.
7844 \\\null\hfill\texttt{.../texmf-dist/doc/ptex/base/ptexdoc.pdf}
7845 \bibitem{ptextug} Hisato Hamano. \newblock 
7846 \textit{Vertical Typesetting with \TeX}, TUGBoat~\textbf{11}(3), 346--352, 1990.
7847 \end{thebibliography}
7848
7849 \newpage
7850 \appendix
7851
7852 \section{Package versions used in this document}
7853 This document was typeset using the following packages:
7854
7855 \medskip
7856
7857 {\makeatletter\tt\footnotesize
7858   \def\@pkglist#1{%
7859     \filename@parse{#1}\def\@temp{sty}
7860     \ifx\@temp\filename@ext
7861       \edef\reserved@a{%
7862         \filename@base.%
7863         \ifx\filename@ext\relax tex\else\filename@ext\fi}%
7864       \leavevmode\hskip-13em\hbox to 13em{\filename@area\reserved@a\hss}%
7865       \csname ver@\reserved@a\endcsname\par
7866     \fi
7867   }%
7868 \parindent0pt\leftskip13em
7869 \ltjpkglist
7870
7871 \makeatother}
7872 \end{document}
7873 %</!showexpl>
7874 %<*showexpl>
7875 %%
7876 %% config file for showexpl.sty
7877 %%
7878 %% Copyright The LuaTeX-ja project team, 2012
7879 %%
7880 \ProvidesFile{showexpl.cfg}
7881   [2012/05/20 v0.01 Definitions for the showexpl package (luatexja)]
7882 \lstset{}
7883 \def\SX@Info{}
7884 \endinput
7885 %</*showexpl>