OSDN Git Service

5ee0134a5229c0a05f13cb0e24894a16f667ba36
[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 \paragraph{\texttt{\textbackslash wd} 等の代替命令}
2753
2754 \pTeX のように現在の組方向に応じたボックスの寸法の取得・設定を行うため,
2755 次の命令を新設した.
2756
2757 \begin{cslist}
2758
2759  \item[ltjgetwd\{<num>\}\textrm{, }\textbackslash ltjgetht\{<num>\}\textrm{, }%
2760   \textbackslash ltjgetdp\{<num>\}] 
2761 現在の組方向に応じたボックスの寸法の取得を行う.結果は内部長さであるため,
2762 {\let\item=\origitem
2763 \begin{verbatim}
2764 \dimexpr 2\ltjgetwd{42}-3pt\relax, \the\ltjgetwd{1701}
2765 \end{verbatim}
2766 のように \verb+\wd+<num> の代わりとして扱うことができる.引数が1桁の場合は,
2767 \verb+\ltjgetwd3+ のように引数をグループで括らなくても良いが,そうでない場合は
2768 (通常の命令への引数のように)\verb+\ltjgetwd{42}+ とグループに括る必要がある.
2769 使用例は以下の通りである.
2770 \begin{LTXexample}[width=0.3\textwidth]
2771 \parindent0pt
2772 \setbox32767=\hbox{\yoko よこぐみ}
2773 \fboxsep=0mm\fbox{\copy32767}
2774 \vbox{\hsize=20mm 
2775 \yoko YOKO \the\ltjgetwd{32767}, \\
2776   \the\ltjgetht{32767}, \\ \the\ltjgetdp{32767}.}
2777 \vbox{\hsize=20mm\raggedleft
2778 \tate TATE \the\ltjgetwd{32767}, \\
2779   \the\ltjgetht{32767}, \\ \the\ltjgetdp{32767}.}
2780 \vbox{\hsize=20mm\raggedleft
2781 \dtou DTOU \the\ltjgetwd{32767}, \\
2782   \the\ltjgetht{32767}, \\ \the\ltjgetdp{32767}.}
2783 \end{LTXexample}}
2784
2785  \item[ltjsetwd<num>=<dimen>\textrm{, }\textbackslash ltjsetht<num>=<dimen>\textrm{, }%
2786   \textbackslash ltjsetdp<num>=<dimen>]
2787 現在の組方向に応じたボックスの寸法の設定を行う.\verb+\afterassignment+ を2回利用して
2788 実装しているので,次の4通りは全て同じ意味である.
2789 {\let\item=\origitem
2790 \begin{verbatim}
2791 \ltjsetwd42 20pt,  \ltjsetwd42=20pt,  \ltjsetwd=42 20pt,  \ltjsetwd=42=20pt
2792 \end{verbatim}
2793 }%
2794
2795 設定値は組方向ごとに独立して記録される.
2796
2797 \end{cslist} 
2798
2799 \subsection{組方向の取得・条件判断}
2800 「現在の組方向」や「<num>番のボックスの組方向」は,以下の命令によって
2801 知ることができる.
2802
2803 \begin{cslist}
2804  \item[ifydir\textrm{, }\textbackslash iftdir\textrm{, }\textbackslash ifddir]
2805 現在の組方向が横組(\verb+\yoko+),縦組(\verb+\tate+),\verb+\dtou+ 方向であるかを
2806 それぞれ判定する.
2807
2808  \item[ifybox\{<num>\}\textrm{, }\textbackslash iftbox\{<num>\}\textrm{, }%
2809   \textbackslash ifdbox\{<num>\}]
2810 <num>番のレジスタの中身が横組ボックス,縦組ボックス,\verb+\dtou+ 方向の
2811 ボックスか否かをそれぞれ判定する.
2812
2813 \end{cslist}
2814
2815 \subsection{プリミティブの再定義}
2816 異なる組方向に対応するために,以下に挙げるプリミティブは
2817 \LuaTeX-jaによる前処理もしくは後処理が行われるように
2818 \ \verb+\protected\def+ により再定義してある.
2819 \begin{cslist}
2820  \item[unhbox<num>\textrm{, }\textbackslash unvbox<num>]
2821  ボックスの組方向が現在のリストと異なる場合は事前にエラーメッセージを出力する.
2822  \pTeX と異なり,エラーを無視して無理矢理 \verb+\unhbox+, \verb+\unvbox+ を
2823  続行させることもできるが,その場合の組版結果は保証しない.
2824  \item[vadjust\{<material>\}] 一旦プリミティブ本来の挙動を行う.その後,<material>の組方向が
2825  周囲の垂直リストの組方向と一致しない場合にエラーを出力し,
2826  該当の \verb+\vadjust+ を無効にする.
2827  \item[lastbox] 異なる組方向のボックスを配置した場合に位置合わせ用に作られるノード類を
2828  除去し,正しく「中身」のボックスが返されるように前処理をする.
2829 \end{cslist}
2830
2831 %</ja>
2832
2833 %<en>\section{Font Metric and Japanese Font}
2834 %<ja>\section{フォントメトリックと和文フォント}
2835 %<en>\subsection{\texttt{\textbackslash jfont}}
2836 %<ja>\subsection{\texttt{\textbackslash jfont} 命令}
2837 \label{ssec-jfont}
2838
2839 %<*en>
2840 To load a font as a Japanese font (for horizontal direction), you must use the
2841 \verb+\jfont+ instead of~\verb+\font+, while
2842 \verb+\jfont+ admits the same syntax used in~\verb+\font+.
2843 \LuaTeX-ja automatically loads \Pkg{luaotfload} package,
2844 so TrueType/OpenType fonts with features can be used for Japanese fonts:
2845 %</en>
2846 %<*ja>
2847 フォントを(横組用)和文フォントとして読み込むためには,\verb+\jfont+ を
2848 \verb+\font+ プリミティブの代わりに用いる.
2849 \verb+\jfont+ の文法は \verb+\font+ と同じである.
2850 \LuaTeX-jaは\Pkg{luaotfload}パッケージを自動的に読み込むので,
2851 TrueType/OpenTypeフォントにfeatureを指定したものを和文フォントとして用いる
2852 ことができる:
2853 %</ja>
2854 \begin{LTXexample}[width=0.3\textwidth]
2855 \jfont\tradgt={file:KozMinPr6N-Regular.otf:script=latn;%
2856   +trad;-kern;jfm=ujis} at 14pt
2857 \tradgt 当/体/医/区
2858 \end{LTXexample}
2859
2860 %<*en>
2861 Note that the defined control sequence
2862 (\verb+\tradgt+ in the example above) using \verb+\jfont+ is not a
2863 \textit{font\_def} token,  but a macro.
2864 Hence the input like \verb+\fontname\tradgt+
2865 causes a error.  We denote control sequences which are defined in
2866 \verb+\jfont+ by <jfont\_cs>.
2867 %</en>
2868 %<*ja>
2869 なお,\verb+\jfont+ で定義された制御綴(上の例だと \verb+\tradgt+)
2870 は\textit{font\_def}トークンではなくマクロである.従って,\verb+\fontname\tradgt+ のような
2871 入力はエラーとなる.以下では \verb+\jfont+ で定義された
2872 制御綴を<jfont\_cs>で表す.
2873 %</ja>
2874
2875 \paragraph{JFM}
2876 %<*en>
2877 As noted in Introduction, a JFM has measurements of characters and
2878 glues/kerns that are automatically inserted for Japanese
2879 typesetting. The structure of JFM will be described in the next
2880 subsection. At the calling of \verb+\jfont+, you must specify
2881 which JFM will be used for this font by the following keys:
2882 %</en>
2883 %<*ja>
2884 「はじめに」の節で述べたように,JFMは文字と和文組版で自動的に挿入される
2885 グルー/カーンの寸法情報を持っている.JFMの構造は次の節で述べる.
2886 \verb+\jfont+ 命令の呼び出しの際には,どのJFMを用いるのかを以下のキーで
2887 指定する必要がある:
2888 %</ja>
2889
2890
2891 \begin{table}[t]
2892 %<en>\caption{Differences between JFMs shipped with \LuaTeX-ja}
2893 %<ja>\caption{\LuaTeX-ja に同梱されている JFM の違い}
2894 %<en>\medskip
2895 \label{tab-difjfm}
2896 \ltjsetparameter{jacharrange={+3}}
2897 \centering\small
2898 \def\r#1{{\jfont\g=file:KozMinPr6N-Regular.otf:jfm=#1 at 14.43324pt \g
2899 \setbox0=\vtop{\hsize=7\zw\noindent ◆◆◆◆◆◆◆
2900 ある日モモちゃんがお使いで迷子になって泣きました.}\copy0
2901 \vrule height 0pt depth \dp0}}
2902 \def\s#1{{\jfont\g=file:KozMinPr6N-Regular.otf:jfm=#1 at 14.43324pt \g
2903 \setbox0=\vtop{\hsize=7\zw\noindent ちょっと!何}\copy0}}
2904 \def\t#1{{\jfont\g=file:KozMinPr6N-Regular.otf:jfm=#1 at 19.24432pt \g
2905 \setbox0=\hbox{漢}%
2906 \vrule width 0.4pt height\ht0 depth\dp0\kern-.2pt\copy0
2907 \kern-\wd0\vrule width\wd0height .2pt depth .2pt
2908 \kern-\wd0\raise\ht0\hbox{\vrule width\wd0height .2pt depth .2pt}%
2909 \kern-\wd0\lower\dp0\hbox{\vrule width\wd0height .2pt depth .2pt}%
2910 \kern-.2pt\vrule width 0.4pt height\ht0 depth \dp0}}
2911 \begin{tabular}{rccc}
2912 \toprule
2913 &\tt jfm-ujis.lua&\tt jfm-jis.lua&\tt jfm-min.lua\\
2914 \midrule
2915 %<en>Example~1~\cite{min10}
2916 %<ja>例1~\cite{min10}
2917 &\r{ujis}&\r{jis}&\r{min}\\
2918 %<en>Example~2
2919 %<ja>例2
2920 &\s{ujis}&\s{jis}&\s{min}\\
2921 Bounding Box&\t{ujis}&\t{jis}&\t{min}\\
2922 \bottomrule
2923 \end{tabular}
2924 \ltjsetparameter{jacharrange={-3}}
2925 \end{table}
2926
2927
2928 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}\advance\leftmargin1\zw}
2929 \item[jfm=<name>]
2930 %<*en>
2931 Specify the name of (horizontal) JFM. 
2932 If specified JFM has not been loaded, \LuaTeX-ja search and load
2933 a file named \texttt{jfm-<name>.lua}.
2934
2935 The following JFMs are shipped with \LuaTeX-ja:
2936 %</en>
2937 %<*ja>
2938 用いる(横組用)JFMの名前を指定する.もし以前に指定されたJFMが読み込まれていなければ,
2939 \texttt{jfm-<name>.lua}を読み込む.以下の横組用JFMが\LuaTeX-jaには同梱されている:
2940 %</ja>
2941 \begin{description}
2942 %<*en>
2943 \item[\tt jfm-ujis.lua] A standard JFM in \LuaTeX-ja. This JFM is
2944   based on \verb+upnmlminr-h.tfm+, a metric for UTF/OTF package that
2945   is used in \upTeX. When you use the \Pkg{luatexja-otf} package, you should use this JFM.
2946 %</en>
2947 %<*ja>
2948 \item[\tt jfm-ujis.lua] \LuaTeX-jaの標準JFMである.このJFMは\upTeX で
2949   用いられるUTF/OTFパッケージ用の和文用TFMである \verb+upnmlminr-h.tfm+ を
2950   元にしている.\Pkg{luatexja-otf}パッケージを使うときはこのJFMを指定するべきである.
2951 %</ja>
2952 %<*en>
2953 \item[\tt jfm-jis.lua] A counterpart for \verb+jis.tfm+, ``JIS font
2954   metric'' which is widely used in \pTeX. A major difference between
2955   \texttt{jfm-ujis.lua} and this \texttt{jfm-jis.lua} is that
2956   most characters under \texttt{jfm-ujis.lua} are square-shaped,
2957   while that under \texttt{jfm-jis.lua} are horizontal
2958   rectangles.
2959 %</en>
2960 %<*ja>
2961 \item[\tt jfm-jis.lua] \pTeX で広く用いられている「JISフォントメトリック」
2962   \verb+jis.tfm+ に相当するJFMである.\texttt{jfm-ujis.lua} とこの
2963   \texttt{jfm-jis.lua} の主な違いは,\texttt{jfm-ujis.lua} ではほとんどの文字が
2964   正方形状であるのに対し,\texttt{jfm-jis.lua} では横長の長方形状であることと,
2965   \texttt{jfm-ujis.lua} では「?」「!」の直後に半角空白が挿入されることである.
2966 %</ja>
2967 %<*en>
2968 \item[\tt jfm-min.lua] A counterpart for \verb+min10.tfm+, which is one
2969   of the default Japanese font metric shipped with \pTeX. 
2970 %</en>
2971 %<*ja> 
2972 \item[\tt jfm-min.lua] \pTeX に同梱されているデフォルトの和文用TFM
2973   である \verb+min10.tfm+ に相当する.
2974 %</ja>
2975 \end{description}
2976 %<*en>
2977 The difference among these three~JFMs is  shown in Table~\ref{tab-difjfm}.
2978 %</en>
2979 %<*ja>
2980 これら3つのJFMの違いは表\ref{tab-difjfm}に示した.
2981 %</ja>
2982
2983 \begin{figure}
2984 \begin{LTXexample}[width=0.3\textwidth]
2985 \ltjsetparameter{differentjfm=both}
2986 \jfont\F=file:KozMinPr6N-Regular.otf:jfm=ujis
2987 \jfont\G=file:KozGoPr6N-Medium.otf:jfm=ujis
2988 \jfont\H=file:KozGoPr6N-Medium.otf:jfm=ujis;jfmvar=hoge
2989 \F ){\G 【】}( % halfwidth space
2990    ){\H 『』}( % fullwidth space
2991
2992 ほげ,{\G 「ほげ」}(ほげ)\par
2993 ほげ,{\H 「ほげ」}(ほげ)% pTeX-like
2994
2995 \ltjsetparameter{differentjfm=paverage}
2996 \end{LTXexample}
2997 \caption{Example of \texttt{jfmvar} key}
2998 \label{fig:jfmvar}
2999 \end{figure}
3000
3001 %<*en>
3002 \item[jfmvar=<string>] Sometimes there is a need that \ldots.
3003 %</en>
3004 %<*ja>
3005 \item[jfmvar=<string>] 標準では,JFMとサイズが同じで,
3006   実フォントだけが異なる2つの和文フォントは「区別されない」.例えば
3007 図\ref{fig:jfmvar}において,最初の「)」と「【」の実フォントは異なるが,
3008 JFMもサイズも同じなので,普通に「)【」と入力した時と同じように半角空きとなる.
3009
3010 しかし,JFMとサイズが同じであっても,\texttt{jfmvar} キーの異なる
3011 2つの和文フォント,例えば図\ref{fig:jfmvar}で言う \verb+\F+ と \verb+\H+,
3012 は「区別される」.異なる和文フォントに異なる \texttt{jfmvar} キーを割り当て,
3013 かつ\Param{differentjfm}パラメータを \texttt{both} に設定すれば,
3014 \pTeX と似た状況で組版されることになる.
3015 %</ja>
3016 \end{list}
3017
3018 \begin{figure}
3019 \begin{LTXexample}[pos=t]
3020 \newcommand\test{\vrule ダイナミックダイクマ\vrule\\}
3021 \jfont\KMFW = KozMinPr6N-Regular:jfm=prop;-kern at 17pt
3022 \jfont\KMFK = KozMinPr6N-Regular:jfm=prop at 17pt % kern is activated
3023 \jfont\KMPW = KozMinPr6N-Regular:jfm=prop;script=dflt;+pwid;-kern at 17pt
3024 \jfont\KMPK = KozMinPr6N-Regular:jfm=prop;script=dflt;+pwid;+kern at 17pt
3025 \begin{multicols}{2}
3026 \ltjsetparameter{kanjiskip=0pt}
3027 {\KMFW\test \KMFK\test \KMPW\test \KMPK\test}
3028
3029 \ltjsetparameter{kanjiskip=3pt}
3030 {\KMFW\test \KMFK\test \KMPW\test \KMPK\test}
3031 \end{multicols}
3032 \end{LTXexample}
3033 \caption{Kerning information and \Param{kanjiskip}}
3034 \label{fig:kern-jfm}
3035 \end{figure}
3036
3037 %<en>\paragraph{Using kerning information in a font}
3038 %<ja>\paragraph{ペアカーニング情報の使用}
3039 \label{para-kern}
3040 %<*en>
3041 Some fonts have information for inter-glyph spacing. 
3042 This version of \LuaTeX-ja treats kerning spaces like an italic correction;
3043 any glue and/or kern from the JFM and a kerning space can coexist.
3044 See Figure~\ref{fig:kern-jfm} for detail.
3045
3046 Note that in \verb+\setmainjfont+ etc.\ which are provided by \Pkg{luatexja-fontspec}
3047 package, kerning option is set \emph{off} (\texttt{Kerning=Off}) by default,
3048 because of the compatibility with previous versions of \LuaTeX-ja.
3049 %</en>
3050 %<*ja>
3051 いくつかのフォントはグリフ間のスペースについての情報を持っている.
3052 このカーニング情報は以前の\LuaTeX-ja とはあまり相性が良くなかったが,
3053 本バージョンではカーニングによる空白はイタリック補正と同様に扱うことになっている.
3054 つまり,カーニング由来の空白とJFM由来のグルー・カーンは同時に入りうる.
3055 図\ref{fig:kern-jfm}を参照.
3056 \begin{itemize}
3057  \item \emph{\texttt{\textbackslash jfont} や,
3058 NFSS2用の命令(\ref{ssec-chgfnt}節,\ref{ssec-nfsspat}節)における指定では
3059 カーニング情報は標準で使用する}ことになっているようである.
3060 言い換えれば,カーニング情報を使用しない設定にするには,面倒でも
3061 \begin{verbatim}
3062 \jfont\hoge=KozMinPr6N-Regular:jfm=ujis;-kern at 3.5mm
3063 \DeclareFontShape{JY3}{fuga}{m}{n} {<-> s*KozMinPr6N-Regular:jfm=ujis;-kern}{}
3064 \end{verbatim}
3065 のように,\texttt{-kern} という指定を自分で追架しなければいけない.
3066  \item 
3067 一方,\emph{\Pkg{luatexja-fontspec} の提供する \texttt{\textbackslash setmainjfont}\ 
3068 などの命令の標準設定ではカーニング情報は使用しない}(\texttt{Kerning=Off})
3069 ことになっている.これは以前のバージョンの\LuaTeX-jaとの互換性のためである.
3070 \end{itemize}
3071 %</ja>
3072
3073 %<*ja>
3074 \paragraph{\texttt{extend}と\texttt{slant}}
3075 OpenType font featureと見かけ上同じような形式で指定できるものに,
3076 \begin{description}
3077 \item[\texttt{extend=}<extend>] 横方向に<extend>倍拡大する.
3078 \item[\texttt{slant=}<slant>] <slant>に指定された割合だけ傾ける.
3079 \end{description}  
3080 の2つがある.
3081 \texttt{extend}や\texttt{slant}を指定した場合は,それに応じたJFMを指定すべきである%
3082 \footnote{\LuaTeX-jaでは,これらに対するJFMを特に提供することはしない予定である.}.
3083 例えば,次の例では無理やり通常のJFMを使っているために,文字間隔やイタリック補正量が
3084 正しくない:
3085 %</ja>
3086 %<*en>
3087 \paragraph{\texttt{extend} and \texttt{slant}}
3088 The following setting can be specified as OpenType font features:
3089 \begin{description}
3090 \item[\texttt{extend=}<extend>] expand the font horizontally by <extend>.
3091 \item[\texttt{slant=}<slant>] slant the font.
3092 \end{description}
3093 Note that \LuaTeX-ja doesn't adjust JFMs by these \texttt{extend} and \texttt{slant}
3094 settings; you have to write new JFMs on purpose. 
3095 For example, the following example uses the standard JFM \texttt{jfm-ujis.lua}, hence
3096 letter-spacing and the width of italic correction are not correct:
3097 %</en>
3098 \begin{LTXexample}[width=0.3\textwidth]
3099 \jfont\E=file:KozMinPr6N-Regular.otf:extend=1.5;jfm=ujis;-kern
3100 \E あいうえお
3101
3102 \jfont\S=file:KozMinPr6N-Regular.otf:slant=1;jfm=ujis;-kern
3103 \S あいう\/ABC
3104 \end{LTXexample}
3105
3106 %<en>\subsection{\texttt{\textbackslash tfont}}
3107 %<ja>\subsection{\texttt{\textbackslash tfont} 命令}
3108
3109 %<*en>
3110 ...
3111 %</en>
3112 %<*ja>
3113 \verb+\tfont+ はフォントを縦組用の和文フォントとして読み込む命令であり,
3114 \verb+\jfont+ の文法は \verb+\jfont+ と同じである.
3115 \verb+\tfont+ で定義された縦組用和文フォントは,
3116 以下の点が \verb+\jfont+ による横組用和文フォントとは異なる:
3117 \begin{itemize}
3118  \item 出力時に,自動的に「\verb+vert+ feature相当」のグリフ置換が行われる.
3119        これは,\Pkg{luaotfload}による各種featureのサポートとは全く別個に行われるもので,
3120        いちいち \verb+vert+ featureを指定する必要はない.
3121 \begin{verbatim}
3122 \tfont\S=file:KozMinPr6N-Regular.otf:jfm=ujis % OK
3123 \end{verbatim}
3124  \item \ref{ssec-math}節で述べる,数式中の和文フォントには縦組用和文フォントは指定できない.
3125  \item \texttt{jfm=<name>}\ の部分には縦組用JFMを指定する.現在同梱されているのは,
3126 OTFパッケージの \verb+upnmlminr-v.tfm+ を元にした\texttt{jfm-ujisv.lua}\ のみである.
3127 \end{itemize}
3128 %</ja>
3129
3130 %<en>\subsection{Prefix \texttt{psft}}
3131 %<ja>\subsection{\texttt{psft}プリフィックス}
3132 \label{ssec-psft}
3133 %<*en>
3134 Besides ``\texttt{file:}''\ and ``\texttt{name:}''\ prefixes which
3135 are introduced in the \Pkg{luaotfload} package, 
3136 \LuaTeX-ja adds ``\texttt{psft:}''\ prefix in \verb+\jfont+ (and~\verb+\font+),
3137 to specify a ``name-only'' Japanese font which
3138 will not be embedded to PDF. Typical use of this prefix is to specify
3139 standard, non-embedded Japanese fonts, namely, ``Ryumin-Light'' and
3140 ``GothicBBB-Medium''.
3141
3142 \emph{OpenType font features, such as ``{\tt +jp90}'', 
3143 have no meaning in name-only fonts using ``{\tt psft:}''\ prefix,
3144 because we can't expect what fonts are actually used by the PDF reader.}
3145 Note that \texttt{extend}~and~\texttt{slant} settings (see~above) are supported
3146 with \texttt{psft} prefix, because they are only simple linear transformations.
3147 %</en>
3148 %<*ja>
3149 \Pkg{luaotfload}で使用可能になった
3150 \texttt{file:}\ と \texttt{name:}\ のプリフィックスに加えて,
3151 \verb+\jfont+(と \verb+\font+ プリミティブ)では
3152 \texttt{psft:}プリフィックスを用いることができる.
3153 このプリフィックスを用いることで,PDFには埋め込まれない「名前だけの」
3154 和文フォントを指定することができる.「標準的な」非埋め込み和文フォント,
3155 つまり「Ryumin-Light」「GothicBBB-Medium」の指定でこのプリフィックスが使われる.
3156
3157 \emph{\texttt{psft} プリフィックスの下では
3158 \texttt{+jp90} などのOpenType font featureの効力はない.
3159 非埋込フォントをPDFに使用すると,実際にどのようなフォントが
3160 表示に用いられるか予測できないからである.}\
3161 \texttt{extend} と \texttt{slant} 指定は単なる変形のため
3162 \texttt{psft} プリフィックスでも使用可能である.
3163 %</ja>
3164
3165 %<en>\paragraph{\texttt{cid} key}
3166 %<ja>\paragraph{\texttt{cid}キー}
3167 \label{para-cid}
3168
3169 %<*en>
3170 The default font defined by using \texttt{psft:} prefix is for Japanese typesetting;
3171 it is Adobe-Japan1-6 CID-keyed font.
3172 One can specify \texttt{cid} key to use other CID-keyed non-embedded fonts
3173 for Chinese or Korean typesetting.
3174 %</en>
3175 %<*ja>
3176 標準で\texttt{psft:}プリフィックスで定義されるフォントは日本語用のもので
3177 あり,Adobe-Japan1-6のCIDに対応したものとなる.しかし,\LuaTeX-jaは中国語
3178 の組版にも威力を発揮することが分かり,日本語フォントでない非埋込フォント
3179 の対応も必要となった.そのために追加されたのが\texttt{cid}キーである.
3180
3181 \texttt{cid}キーに値を指定すると,そのCIDを持った非埋込フォントを定義することができる:
3182 %</ja>
3183 \begin{lstlisting}[numbers=left]
3184 \jfont\testJ={psft:Ryumin-Light:cid=Adobe-Japan1-6;jfm=jis}     % Japanese
3185 \jfont\testD={psft:Ryumin-Light:jfm=jis}                        % default value is Adobe-Japan1-6
3186 \jfont\testC={psft:AdobeMingStd-Light:cid=Adobe-CNS1-6;jfm=jis} % Traditional Chinese
3187 \jfont\testG={psft:SimSun:cid=Adobe-GB1-5;jfm=jis}              % Simplified Chinese
3188 \jfont\testK={psft:Batang:cid=Adobe-Korea1-2;jfm=jis}           % Korean
3189 \end{lstlisting}
3190 %<*en>
3191 Note that the code above specifies \texttt{jfm-jis.lua}, which is for Japanese fonts,
3192 as JFM for Chinese and Korean fonts.
3193 %</en>
3194 %<*ja>
3195 上のコードでは中国語・韓国語用フォントに対してもJFMに
3196 日本語用の\texttt{jfm-jis.lua}を指定しているので注意されたい.
3197 %</ja>
3198
3199 %<*en>
3200 At present, \LuaTeX-ja supports only 4 values written in the sample code above.
3201 Specifying other values, e.g.,
3202 %</en>
3203 %<*ja>
3204 今のところ,\LuaTeX-jaは上のサンプルコード中に書いた4つの値しかサポートしていない.
3205 %</ja>
3206 \begin{lstlisting}
3207 \jfont\test={psft:Ryumin-Light:cid=Adobe-Japan2;jfm=jis}
3208 \end{lstlisting}
3209 %<*en>
3210 produces the following error:
3211 %</en>
3212 %<*ja>
3213 のようにそれら以外の値を指定すると,エラーが発生する:
3214 %</ja>
3215 \begin{lstlisting}[numbers=left]
3216 ! Package luatexja Error: bad cid key `Adobe-Japan2'.
3217
3218 See the luatexja package documentation for explanation.
3219 Type  H <return>  for immediate help.
3220 <to be read again>
3221                    \par
3222 l.78
3223
3224 ? h
3225 I couldn't find any non-embedded font information for the CID
3226 `Adobe-Japan2'. For now, I'll use `Adobe-Japan1-6'.
3227 Please contact the LuaTeX-ja project team.
3228 ?
3229 \end{lstlisting}
3230
3231 %<en>\subsection{Structure of a JFM File}
3232 %<ja>\subsection{JFMファイルの構造}
3233 \label{ssec-jfm-str}
3234 %<en>A JFM file is a Lua script which has only one function call:
3235 %<ja>JFMファイルはただ一つの関数呼び出しを含むLuaスクリプトである:
3236 \begin{verbatim}
3237 luatexja.jfont.define_jfm { ... }
3238 \end{verbatim}
3239 %<*en>
3240 Real data are stored in the table which indicated above by
3241 \verb+{ ... }+.  So, the rest of this subsection are devoted to describe the
3242 structure of this table.  Note that all lengths in a JFM file are
3243 floating-point numbers in design-size unit.
3244 %</en>
3245 %<*ja>
3246 実際のデータは上で \verb+{ ... }+ で示されたテーブルの中に格納されている.
3247 以下ではこのテーブルの構造について記す.
3248 なお,JFMファイル中の長さは全てdesign-sizeを単位とする浮動小数点数であることに
3249 注意する.
3250 %</ja>
3251
3252 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}\advance\leftmargin1\zw}
3253
3254 \item[dir=<direction>]
3255 %<en>(required)
3256 %<ja>(必須)
3257
3258 %<*en>
3259 The direction of JFM. \texttt{'yoko'}~(horizontal)
3260 or \texttt{'tate'}~(vertical) are supported.
3261 %</en>
3262 %<*ja>
3263 JFMの書字方向.\texttt{'yoko'}(横組)と \texttt{'tate'}(縦組)がサポートされる.
3264 %</ja>
3265
3266 \item[zw=<length>]
3267 %<en>(required)
3268 %<ja>(必須)
3269
3270 %<en>The amount of the length of the ``full-width''.
3271 %<ja>「全角幅」の長さ.
3272
3273 \item[zh=<length>]
3274 %<en>(required)
3275 %<ja>(必須)
3276
3277 %<en>The amount of the ``full-height'' (height + depth). 
3278 %<ja>「全角高さ」(height + depth)の長さ.通常は全角幅と同じ長さになるだろう.
3279
3280 \item[kanjiskip=\{<natural>, <stretch>, <shrink>\}]
3281 %<en>(optional)
3282 %<ja>(任意)
3283
3284 %<*en>
3285 This field specifies the ``ideal'' amount of \Param{\hyperlink{fld:kanjiskip}{kanjiskip}}. As noted
3286              in Subsection~\ref{subs-kskip}, if the parameter
3287              \Param{\hyperlink{fld:kanjiskip}{kanjiskip}} is \verb+\maxdimen+, the value specified
3288              in this field is actually used (if this field is not specified in
3289              JFM, it is regarded as 0\,pt). Note that <stretch> and <shrink>
3290              fields are in design-size unit too.
3291 %</en>
3292 %<*ja>
3293 理想的な\Param{\hyperlink{fld:kanjiskip}{kanjiskip}}の量を指定する.\ref{subs-kskip}節で述べたように,
3294 もし\Param{\hyperlink{fld:kanjiskip}{kanjiskip}}が \verb+\maxdimen+ の値ならば,このフィールドで指定された
3295 値が実際には用いられる(指定なしは0\,ptとして扱われる).<stretch>と<shrink>のフィールドもdesign-size
3296 が単位であることに注意せよ.
3297 %</ja>
3298
3299 \item[xkanjiskip=\{<natural>, <stretch>, <shrink>\}]
3300 %<en>(optional)
3301 %<ja>(任意)
3302
3303 %<*en>
3304 Like the \texttt{kanjiskip} field, this field specifies the ``ideal''
3305              amount of \Param{\hyperlink{fld:xks}{xkanjiskip}}.
3306 %</en>
3307 %<*ja>
3308 \texttt{kanjiskip}フィールドと同様に,\Param{\hyperlink{fld:xks}{xkanjiskip}}の理想的な量を
3309 指定する.
3310 %</ja>
3311 \end{list}
3312
3313 %<*en>
3314 \paragraph{Character classes}
3315 Besides from above fields, a JFM file have several sub-tables those
3316 indices are natural numbers.  The table indexed by~$i\in\omega$ stores
3317 information of \emph{character class}~$i$. At least, the character class~0 is
3318 always present, so each JFM file must have a sub-table whose index is
3319 \texttt{[0]}.  Each sub-table (its numerical index is denoted by $i$) has
3320 the following fields:
3321 %</en>
3322 %<*ja>
3323 \paragraph{文字クラス}
3324 上記のフィールドに加えて,JFMファイルはそのインデックスが自然数であるいくつかの
3325 サブテーブルを持つ.インデックスが$i\in\omega$であるテーブルは\emph{文字クラス}$i$の
3326 情報を格納する.少なくとも,文字クラス0は常に存在するので,JFMファイルはインデックス
3327 が\texttt{[0]}のサブテーブルを持たなければならない.それぞれのサブテーブル
3328 (そのインデックスを$i$で表わす)は以下のフィールドを持つ:
3329 %</ja>
3330
3331 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}\advance\leftmargin1\zw}
3332 \item[chars=\{<character>, ...\}]
3333 %<en>(required except character class~0)
3334 %<ja>(文字クラス0を除いて必須)
3335
3336 %<*en>
3337 This field is a list of characters which are in this character
3338              type~$i$. This field is optional if $i=0$, since all
3339              \textbf{JAchar} which do not belong  any character classes other
3340              than 0 are in the character class 0
3341              (hence, the character class~0 contains most of
3342              \textbf{JAchar}s). In the list, character(s) can be specified in the following form:
3343 \begin{itemize}
3344 \item a Unicode code point
3345 \item the character itself (as a Lua string, like \hbox{\ltjsetparameter{autoxspacing=false}\verb+'あ'+})
3346 \item a string like \hbox{\ltjsetparameter{autoxspacing=false}\verb+'あ*'+} (the character followed by an asterisk)
3347 \item several ``imaginary'' characters (We will describe these later.)
3348 \end{itemize}
3349 %</en>
3350 %<*ja>
3351 このフィールドは文字クラス$i$に属する文字のリストである.このフィールドは$i=0$の
3352 場合には任意である(文字クラス0には,0以外の文字クラスに属するものを
3353 除いた全ての\textbf{JAchar}が属するから).このリスト中で文字を指定するには,以下の方法がある:
3354 \begin{itemize}
3355 \item Unicode におけるコード番号
3356 \item 「\hbox{\ltjsetparameter{autoxspacing=false}\verb+'あ'+}」のような,文字それ自体
3357 \item 「\hbox{\ltjsetparameter{autoxspacing=false}\verb+'あ*'+}」のような,文字それ自体の後にアスタリスクをつけたもの
3358 \item いくつかの「仮想的な文字」(後に説明する)
3359 \end{itemize}
3360 %</ja>
3361
3362 \item[width=<length>, height=<length>, depth=<length>, italic=<length>]
3363 %<en>(required)
3364 %<ja>(必須)
3365
3366 %<*en>
3367 Specifythe width of characters in character class~$i$, the height, the depth and
3368 the amount of italic correction. All characters in character class~$i$ are regarded that its width, height, and depth are
3369 as values of these fields.
3370
3371 But there is one exception: \texttt{width} field can be \texttt{'prop'}. 
3372 This means that width of a character becomes that of its ``real'' glyph.
3373 %</en>
3374 %<*ja>
3375 文字クラス$i$に属する文字の幅,高さ,深さ,イタリック補正の量を指定する.
3376 文字クラス$i$に属する全ての文字は,その幅,高さ,深さがこのフィールドで指定した
3377 値であるものとして扱われる.
3378
3379 例外として,\emph{\texttt{width} フィールドには数値以外に \texttt{'prop'} が指定可能である}.
3380 この場合,文字の幅はその「実際の」グリフの幅となる.OpenTypeの \texttt{prop} featureと併用
3381              すれば,これによってプロポーショナル組を行うことができる.
3382 %</ja>
3383
3384 \item[left=<length>, down=<length>, align=<align>]\
3385
3386 %<*en>
3387 These fields are for adjusting the position of the ``real'' glyph. Legal
3388              values of \texttt{align} field are \texttt{'left'},
3389              \texttt{'middle'}, and \texttt{'right'}. If one of these
3390              3~fields are omitted, \texttt{left} and \texttt{down} are
3391              treated as~0, and \texttt{align} field is treated as
3392              \texttt{'left'}.
3393 The effects of these 3~fields are indicated in Figure~\ref{fig-pos}.
3394 %</en>
3395 %<*ja>
3396 これらのフィールドは実際のグリフの位置を調整するためにある.
3397 \texttt{align} フィールドに指定できる値は \texttt{'left'}, \texttt{'middle'},
3398 \texttt{'right'} のいずれかである.もしこれら3つのフィールドのうちの1つが省かれた
3399 場合,\texttt{left} と \texttt{down} は0,\texttt{align} フィールドは
3400 \ \texttt{'left'} であるものとして扱われる.
3401 これら3つのフィールドの意味については図\ref{fig-pos}で説明する.
3402 %</ja>
3403
3404 %<*en>
3405 In most cases, \texttt{left} and \texttt{down} fields are~0, while
3406 it is not uncommon that the \texttt{align} field is \texttt{'middle'} or \texttt{'right'}.
3407 For example, setting the \texttt{align} field to \texttt{'right'} is practically needed
3408 when the current character class is the class for opening delimiters'.
3409 %</en>
3410 %<*ja>
3411 多くの場合,\texttt{left}と\texttt{down}は0である一方,
3412 \texttt{align}フィールドが\texttt{'middle'}や\texttt{'right'}であることは
3413 珍しいことではない.
3414 例えば,\texttt{align}フィールドを\texttt{'right'}に指定することは,
3415 文字クラスが開き括弧類であるときに実際必要である.
3416 %</ja>
3417
3418 \begin{figure}[!tb]
3419 \begin{minipage}{0.4\textwidth}%
3420 \begin{center}\unitlength=10pt\small
3421 \begin{picture}(15,12)(-1,-4)
3422 \color{black!10!white}% real glyph :step1
3423 \put(0,0){\vrule width 12\unitlength height 8\unitlength depth 3\unitlength}
3424
3425 \color{red!20!white}% real glyph :step1
3426 \put(-1,-1.5){\vrule width 6\unitlength height 7\unitlength depth 2.5\unitlength}
3427
3428 \color{red}% real glyph
3429 \thicklines
3430 \put(-1,-1.5){\vector(0,1){7}\vector(0,-1){2.5}\vector(1,0){6}}
3431 \put(5,-1.5){\line(0,1){7}\line(0,-1){2.5}}
3432 \put(-1,5.5){\line(1,0){6}}
3433 \put(-1,-4){\line(1,0){6}}
3434
3435 \color{green!20!white}% real glyph :step1
3436 \put(3,0){\vrule width 6\unitlength height 7\unitlength depth 2.5\unitlength}
3437
3438 \color{black}% real glyph :step1
3439 \thicklines
3440 \put(0,0){\vector(0,1){8}\line(0,-1){3}\vector(1,0){12}}
3441 \put(12,0){\line(0,1){8}\vector(0,-1){3}}
3442 \put(0,8){\line(1,0){12}}
3443 \put(0,-3){\line(1,0){12}}
3444 \put(0.2,4){\makebox(0,0)[l]{\texttt{height}}}
3445 \put(12.2,-1.5){\makebox(0,0)[l]{\texttt{depth}}}
3446 \put(6,0.2){\makebox(0,0)[b]{\texttt{width}}}
3447
3448 \color{green!50!black}% real glyph :step1
3449 \thicklines
3450 \put(3,0){\vector(0,1){7}\vector(0,-1){2.5}\vector(1,0){6}}
3451 \put(9,0){\line(0,1){7}\line(0,-1){2.5}}
3452 \put(3,7){\line(1,0){6}}
3453 \put(3,-2.5){\line(1,0){6}}
3454 \newsavebox{\eqdist}
3455 \savebox{\eqdist}(0,0)[b]{%
3456   \thinlines
3457   \put(-0.08,0.2){\line(0,-1){0.4}}%
3458   \put(0.08,0.2){\line(0,-1){0.4}}}
3459 \put(1.5,0){\usebox{\eqdist}}
3460 \put(10.5,0){\usebox{\eqdist}}
3461
3462 \color{blue}% shifted
3463 \thicklines
3464 \put(3,-1.5){\vector(-1,0){4}}
3465 \put(1,-1.7){\makebox(0,0)[t]{\texttt{left}}}
3466 \put(3,0){\vector(0,-1){1.5}}
3467 \put(3.2,-0.75){\makebox(0,0)[l]{\texttt{down}}}
3468 \end{picture}
3469 \end{center}
3470 \end{minipage}%
3471 \begin{minipage}{0.6\textwidth}%
3472 %<*en>
3473 Consider a node containing Japanese character whose value of the \texttt{align}
3474 field is \texttt{'middle'}.
3475 %</en>
3476 %<*ja>
3477 \texttt{align}フィールドの値が\texttt{'middle'}である和文文字を含むノードを
3478 考えよう.
3479 %</ja>
3480 \begin{itemize}
3481 \item
3482 %<*en>
3483 The black rectangle is a frame of the node.
3484 Its width, height, and depth are specified by JFM.
3485 %</en>
3486 %<*ja>
3487 黒色の長方形はノードの枠である.
3488 その幅,高さ,深さはJFMによって指定される.
3489 %</ja>
3490 \item
3491 %<*en>
3492 Since the \texttt{align} field is \texttt{'middle'},
3493 the ``real'' glyph is centered horizontally (the green rectangle).
3494 %</en>
3495 %<*ja>
3496 \texttt{align}フィールドは\texttt{middle}なので,実際のグリフは
3497 水平方向の中心に配置される(緑色の長方形).
3498 %</ja>
3499 \item
3500 %<*en>
3501 Furthermore, the glyph is shifted according to values of fields
3502       \texttt{left} and \texttt{down}. The ultimate position of the real
3503       glyph is indicated by the red rectangle.
3504 %</en>
3505 %<*ja>
3506 さらに,グリフは\texttt{left}と\texttt{down}の値に従ってシフトされる.
3507 最終的な実際のグリフの位置は赤色の長方形で示された位置になる.
3508 %</ja>
3509 \end{itemize}
3510 \end{minipage}
3511 \medskip
3512
3513 \caption{%
3514 %<en>The position of the real glyph
3515 %<ja>「実際の」グリフの位置
3516 }
3517 \label{fig-pos}
3518 \end{figure}
3519
3520 \item[kern={\{[$j$]=<kern>, [$j'$]=\{<kern>, [<ratio>]\}, ...\}}]
3521
3522 \item[glue={\{[$j$]=\{<width>, <stretch>, <shrink>, [<priority>], [<ratio>]\}, ...\}}]
3523 %<*ja>
3524 文字クラス$i$の文字と$j$の文字の間に挿入されるkernやglueの量を指定する.
3525
3526              <priority>は \Pkg{luatexja-adjust} による優先順位付き
3527              行長調整(\ref{ssec-adj}節)が有効なときのみ意味を持つ.
3528 このフィールドは省略可能であり,行調整処理におけるこのglueの優先
3529              度を$-2$から$+2$の間の整数で指定する.大きい値ほど「伸びやすく,縮みやすい」
3530              ことを意味する.省略時の値
3531              は0であり,範囲外の値が指定されたときの動作は未定義である.
3532
3533 <ratio>も省略可能フィールドであり,$-1$から$+1$の実数値をとる.省略時の値は0である.
3534 \begin{itemize}
3535 \item $-1$はこのグルーが「前の文字」由来であることを示す.
3536 \item $+1$はこのグルーが「後の文字」由来であることを示す.
3537 \item それ以外の値は,「前の文字」由来のグルーと「後の文字」由来の
3538 グルーが混合されていることを示す.
3539 \end{itemize}
3540 なお,このフィールドの値は\Param{\hyperlink{fld:diffjfm}{differentjfm}}の値が
3541 \texttt{pleft},~\texttt{pright},~\texttt{paverage}の値のときのみ実際に用いられる.
3542
3543 例えば,\cite{x4051}では,句点と中点の間には,
3544 句点由来の二分空きと中点由来の四分空きが挿入されるが,この場合には
3545 \begin{itemize}
3546 \item <width>には$0.5+0.25=0.75$を指定する.
3547 \item <ratio>には次の値を指定する.
3548 \[
3549  -1\cdot \frac{0.5}{0.5+0.25} + 1 \cdot \frac{0.25}{0.5+0.25} = -\frac13
3550 \]
3551 \end{itemize}
3552 %</ja>
3553 %<*en>
3554
3555
3556 Specifies the width of kern or glue which will be inserted 
3557 between characters in character class~$i$ and those in character class~$j$.
3558
3559 <priority> is an integer in $[-2,2]$ (treated as 0 if omitted), and this is
3560 used only in line adjustment with priority by \Pkg{luatexja-adjust}
3561 (see Subsection~\ref{ssec-adj}). Higher value means the glue is easy to shretch,
3562 and is also easy to shrink.
3563
3564 <ratio> is also an optional value between $-1$ and 1. For example,
3565 Thw width of a glue between an ideographic full stop ``。''
3566 and a fullwidth middle dot ``・'' is three-fourth of fullwidth,
3567 namely halfwidth from the ideographic full stop, and
3568 quarter-width from the fullwidth middle dot.  In this case,
3569 we specify <ratio> to
3570 \[
3571   -1\cdot \frac{0.5}{0.5+0.25} + 1 \cdot \frac{0.25}{0.5+0.25} = -\frac13.
3572 \]
3573 %</en>
3574
3575
3576 \item[end\_stretch=<kern>]
3577 \item[end\_shrink=<kern>]
3578 %<*ja>
3579 これらのフィールドは省略可能である.
3580 優先順位付き行長調整が有効であり,かつ現在の文字クラスの文字が行
3581              末に来た時に,行長を詰める調整・伸ばす調整のた
3582              めにこの文字と行末の間に挿入可能なカーンの大きさを指定する.
3583 %</ja>
3584
3585 \end{list}
3586
3587 %<*ja>
3588 \paragraph{文字クラスの決定}
3589 文字からその文字の属する文字クラスを算出する過程は少々複雑である.
3590 次の内容を一部に含んだ \texttt{jfm-test.lua} を用いて説明する.
3591 %</ja>
3592 %<*en>
3593 \paragraph{Character to character classes}
3594 We explain how the character class of a character is determined,
3595 using  \texttt{jfm-test.lua} which contains the following:
3596 %</en>
3597 \begin{lstlisting}
3598    [0] = {
3599       chars = { '漢', 'ヒ*' },
3600       align = 'left', left = 0.0, down = 0.0,
3601       width = 1.0, height = 0.88, depth = 0.12, italic=0.0,
3602    },
3603    [2000] = {
3604       chars = { '。', '、*', 'ヒ' },
3605       align = 'left', left = 0.0, down = 0.0,
3606       width = 0.5, height = 0.88, depth = 0.12, italic=0.0,
3607    },
3608 \end{lstlisting}
3609 %<ja>句点「。」の幅は二分であるので
3610 %<en>Now consider the following input/output:
3611 \begin{LTXexample}[width=0.3\textwidth]
3612 \jfont\a=file:KozMinPr6N-Regular.otf:jfm=test;+vert
3613 \setbox0\hbox{\a 。\inhibitglue 漢}
3614 \the\wd0
3615 \end{LTXexample}
3616 %<*en>
3617 Now we look why the above source outputs 20\,pt, not 15\,pt.
3618 \begin{enumerate}
3619 \item The ideographic full stop ``。'' is converted to its vertical form ``\char"FE12''~(\texttt{U+FE12}), %"
3620 by \verb+vert+ feature.
3621 \item The character class of ``\char"FE12'' is zero, hence its width is fullwidth.%"
3622 \item The character class of ``漢'', hence its width is fullwidth.
3623 \item \verb+\inhibitglue+ makes that no glue will be inserted between ``。'' and ``漢''.
3624 \item Hence the width of \verb+\hbox+ equals to 20\,pt.
3625 \end{enumerate}
3626 This example shows that the character class of a character is determined \emph{after
3627 applying font features by \Pkg{luaotfload}}.
3628 %</en>
3629 %<*ja>
3630 では,全角二分(15.0\,pt)となるのが自然……と思うかもしれないが,上の実行結果では20\,ptとなっている.
3631 それは以下の事情によるものである:
3632 \begin{enumerate}
3633 \item \verb+vert+ featureによって句点(\texttt{U+3002})が縦書き用のグリフと置き換わる(\Pkg{luaotfload} による処理).
3634 \item この縦書き用句点のグリフは \texttt{U+FE12} であるため,その文字クラスは0となる.
3635 \item 以上により文字クラス0とみなされるため,結果として「。」の幅は全角だと認識されてしまう.
3636 \end{enumerate}
3637 この例は,\emph{文字クラスの決定はfont featureの適用によるグリフ置換の後に行われる}ことを
3638 示している.
3639 %</ja>
3640
3641 %<*en>
3642 However, a starred specificaion like ``\texttt{'、*'}'' changes the rule.
3643 Consider the following input:
3644 %</en>
3645 %<*ja>
3646 但し,「\texttt{'、*'}」のようにアスタリスクつきの指定があると,
3647 状況は異なる.
3648 %</ja>
3649 \begin{LTXexample}[width=0.3\textwidth]
3650 \jfont\a=file:KozMinPr6N-Regular.otf:jfm=test;+vert
3651 \a 漢、\inhibitglue 漢
3652 \end{LTXexample}
3653 %<*en>
3654 Here, the character class of the ideographic comma ``、''~(\texttt{U+3001}) is determined
3655 as following:
3656 \begin{enumerate}
3657 \item As the case of ``。'', the ideographic comma ``、'' is converted to its vertical
3658       form ``\char"FE11''~(\texttt{U+FE11}).%"
3659 \item The character class of ``\char"FE11'' is zero.
3660 \item However, \LuaTeX-ja remembers that this ``\char"FE11'' is obtained from ``、'' by
3661       font features. The character class of ``、'' is \emph{non-zero value}, namely, 2000.
3662 \item Hence the ideographic comma ``、'' in above belongs the character class~2000.
3663 \end{enumerate}
3664 %</en>
3665 %<*ja>
3666 ここで,読点「、」(\texttt{U+3001})の文字クラスは,以下のようにして決まる.
3667 \begin{enumerate}
3668 \item とりあえず句点の時と同じように,\Pkg{luaotfload} によって縦書き用読点のグリフに置き換わる.
3669 \item 置換後のグリフは \texttt{U+FE11} であり,そのままでは文字クラスは0と判定される.
3670 \item ところが,JFMには「\texttt{'、*'}」指定があるので,置換前の横書き用読点のグリフによって文字クラスを判定する.
3671 \item 結果として,上の出力例中の読点の文字クラスは2000となる.
3672 \end{enumerate}
3673 %</ja>
3674
3675 %<*ja>
3676 なお,「\texttt{'\hbox{}ヒ*'}」のようにアスタリスクつきの指定があっても,
3677 置換後のグリフで判定した文字クラスの値が0でなければ,そちらをそのまま作用する.
3678 \begin{LTXexample}[width=0.3\textwidth]
3679 \jfont\a=file:KozMinPr6N-Regular.otf:jfm=test;+hwid
3680 \a 漢ヒひ
3681 \end{LTXexample}
3682 上の例では,
3683 \texttt{hwid} featureにより,「ヒ」が半角の「ヒ」に置き換わるが,
3684 文字クラスは「ヒ」の属する0\emph{ではなく},「ヒ」の属する2000となる.
3685 %</ja>
3686
3687 %<ja>\paragraph{仮想的な文字}
3688 %<en>\paragraph{Imaginary characters}
3689 %<*en>
3690 As described before, you can specify several \emph{imaginary characters} in
3691 \texttt{chars} field. The most of these characters are regarded as the
3692 characters of class 0 in \pTeX.
3693 As a result, \LuaTeX-ja can control typesetting finer than \pTeX.
3694 The following is the list of imaginary characters:
3695 %</en>
3696 %<*ja>
3697 上で説明した通り,\texttt{chars}フィールド中にはいくつかの「特殊文字」も
3698 指定可能である.これらは,大半が\pTeX のJFMグルーの挿入処理ではみな「文字
3699 クラス0の文字」として扱われていた文字であり,その結果として\pTeX より細か
3700 い組版調整ができるようになっている.以下でその一覧を述べる:
3701 %</ja>
3702
3703 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}\advance\leftmargin1\zw}
3704 %%\item['diffmet']
3705 %%<en>Used at a boundary between two \textbf{JAchar}s whose JFM or size is different.
3706 %%<ja>JFMやサイズが異なる2つの\textbf{JAchar}の間の境界として用いられる.
3707
3708 \item['boxbdd']
3709 %<en>The beginning/ending of a hbox, and the beginning of a noindented (i.e., began by \verb+\noindent+) paragraph.
3710 %<ja>hboxの先頭と末尾,及びインデントされていない(\verb+\noindent+ で開始された)段落の先頭を表す.
3711
3712 \item['parbdd']
3713 %<en>The beginning of an (indented) paragraph.
3714 %<ja>通常の(\verb+\noindent+ で開始されていない)段落の先頭.
3715
3716 \item['jcharbdd']
3717 %<en>A boundary between \textbf{JAchar} and anything else (such as \textbf{ALchar}, kern, glue,\,\ldots).
3718 %<ja>和文文字と「その他のもの」(欧文文字,glue,kern等)との境界.
3719
3720 \item[$-1$]
3721 %<en>The left/right boundary of an inline math formula.
3722 %<ja>行中数式と地の文との境界.
3723 \end{list}
3724
3725 %<en>\paragraph{Porting JFM from \pTeX}
3726 %<ja>\paragraph{\pTeX 用和文用TFMの移植}
3727
3728 % ToDo: English version.
3729
3730 %<*en>
3731 See Japanese version of this manual.
3732 %</en>
3733
3734 %<*ja>
3735 以下に,\pTeX 用に作られた和文用TFMを\LuaTeX-ja用に移植する場合の注意点を挙げておく.
3736 \begin{itemize}
3737 \item 実際に出力される和文フォントのサイズがdesign sizeとなる.
3738 このため,例えば$1\,\textrm{zw}$がdesign sizeの0.962216倍であるJISフォン
3739       トメトリック等を移植する場合は,次のようにするべきである:
3740 \begin{itemize}
3741 \item JFM中の全ての数値を$1/0.962216$倍しておく.
3742 \item \TeX ソース中で使用するところで,サイズ指定を0.962216倍にする.
3743       \LaTeX でのフォント宣言なら,例えば次のように:
3744 \begin{verbatim}
3745 \DeclareFontShape{JY3}{mc}{m}{n}{<-> s*[0.962216] psft:Ryumin-Light:jfm=jis}{}
3746 \end{verbatim}
3747 \end{itemize}
3748 \item 上に述べた特殊文字は,\texttt{'boxbdd'}を除き文字クラスを全部0とする
3749       (JFM中に単に書かなければよい).
3750 \item \texttt{'boxbdd'}については,それのみで一つの文字クラスを形成し,その
3751       文字クラスに関してはグルー/カーンの設定はしない.
3752
3753 これは,\pTeX では,
3754       hboxの先頭・末尾とインデントされていない(\verb+\noindent+ で開始さ
3755       れた)段落の先頭にはJFMグルーは入らないという仕様を実現させるためである.
3756 \item \pTeX の組版を再現させようというのが目的であれば以上の注意を守れば十分である.
3757
3758 ところで,\pTeX では通常の段落の先頭にJFMグルーが残るという仕様があるので,
3759       段落先頭の開き括弧は全角二分下がりになる.全角下がりを実現させるに
3760       は,段落の最初に手動で \verb+\inhibitglue+ を追加するか,あるいは
3761       \ \verb+\everypar+ のハックを行い,それを自動化させるしかなかった.
3762
3763 一方,\LuaTeX-jaでは,\texttt{'parbdd'}によって,それがJFM側で調整できるよ
3764 うになった.例えば,\LuaTeX-ja同梱のJFMのように,\texttt{'boxbdd'}と同じ文字クラスに
3765 \texttt{'parbdd'}を入れれば全角下がりとなる.
3766
3767 \begin{LTXexample}[width=0.4\textwidth]
3768 \jfont\g=KozMinPr6N-Regular:jfm=test \g
3769 \parindent1\zw\noindent{}◆◆◆◆◆
3770 \par 「◆◆←二分下がり
3771 \par 【◆◆←全角下がり
3772 \par 〔◆◆←全角二分下がり
3773 \end{LTXexample}
3774 \end{itemize}
3775
3776 但し,\verb+\everypar+ を利用している場合にはこの仕組みは正しく動かない.
3777 そのような例としては箇条書き中の \verb+\item+ で始まる段落があり,\Pkg{ltjsclasses}では
3778 人工的に「\texttt{'parbdd'}の意味を持つ」whatsitノードを作ることによって対処している%
3779 \footnote{\texttt{ltjsclasses.dtx} を参照されたい.
3780 JFM側で一部の対処ができることにより,\Pkg{jsclasses}のようにif文の判定はしていない.}.
3781 %</ja>
3782
3783
3784 %<en>\subsection{Math Font Family}
3785 %<ja>\subsection{数式フォントファミリ}
3786 \label{ssec-math}
3787
3788 %<*en>
3789 \TeX\ handles fonts in math formulas by 16~font families\footnote{Omega,
3790 Aleph, \LuaTeX~and $\varepsilon$-\kern-.125em(u)\pTeX\ can handles 256~families, but
3791 an external package is needed to support this in plain \TeX\ and
3792 \LaTeX.}, and each family has three fonts:
3793 \verb+\textfont+, \verb+\scriptfont+ and \verb+\scriptscriptfont+.
3794 %</en>
3795 %<*ja>
3796 \TeX\ は数式フォントを16のファミリ\footnote{Omega, Aleph, \LuaTeX,そして
3797   $\varepsilon$-\kern-.125em(u)\pTeX\ では256の数式ファミリを扱うことができるが,
3798   これをサポートするためにplain \TeX と\LaTeX では外部パッケージを読み込む必要が
3799   ある.}で管理し,それぞれのファミリは3つのフォントを持っている:
3800 \verb+\textfont+, \verb+\scriptfont+ そして \verb+\scriptscriptfont+ である.
3801 %</ja>
3802
3803 %<*en>
3804 \LuaTeX-ja's handling of Japanese fonts in math formulas is similar;
3805 Table~\ref{tab-math} shows counterparts to \TeX's primitives for math
3806 font families. There is no relation between the value of
3807 \verb+\fam+ and that of \verb+\jfam+; with appropriate settings,
3808 you can set both \verb+\fam+ and \verb+\jfam+ to the same value.
3809 %</en>
3810 %<*ja>
3811 \LuaTeX-jaの数式中での和文フォントの扱いも同様である.
3812 表\ref{tab-math}は数式フォントファミリに対する \TeX のプリミティブと対応する
3813 ものを示している.\verb+\fam+ と \verb+\jfam+ の値の間には関係はなく,
3814 適切な設定の下では \verb+\fam+ と \verb+\jfam+ の両方に同じ値を設定することができる.
3815 %</ja>
3816
3817 \begin{table}[!tb]
3818 %<en>\caption{Commands for Japanese math fonts}
3819 %<ja>\caption{和文数式フォントに対する命令}
3820 \label{tab-math}
3821 %<en>\medskip
3822 \centering
3823 \def\{{\char`\{}\def\}{\char`\}}\small
3824 \begin{tabular}{ll}
3825 \toprule
3826 %<en>\bf Japanese fonts&\bf alphabetic fonts\\
3827 %<ja>\bf 和文フォント&\bf 欧文フォント\\
3828 \midrule
3829 \verb+\jfam+${}\in [0,256)$&\verb+\fam+\\
3830 \tt\Param{jatextfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\verb+\textfont+<fam>=<font\_cs>\\
3831 \tt\Param{jascriptfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\verb+\scriptfont+<fam>=<font\_cs>\\
3832 \tt\Param{jascriptscriptfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\verb+\scriptscriptfont+<fam>=<font\_cs>\\
3833 \bottomrule
3834 \end{tabular}
3835 \end{table}
3836
3837 %<en>\subsection{Callbacks}
3838 %<ja>\subsection{コールバック}
3839
3840 %<*en>
3841 \LuaTeX-ja also has several callbacks. These callbacks can
3842 be accessed via \verb+luatexbase.add_to_callback+ function and so on, as other callbacks.
3843 %</en>
3844 %<*ja>
3845 \LuaTeX 自体のものに加えて,\LuaTeX-jaもコールバックを持っている.
3846 これらのコールバックには,他のコールバックと同様に \verb+luatexbase.add_to_callback+
3847 関数などを用いることでアクセスすることができる.
3848 %</ja>
3849 \begin{list}{}%
3850 {\def\makelabel#1{\bfseries#1}}
3851 %<en>\item[\texttt{luatexja.load\_jfm} callback]
3852 %<ja>\item[\texttt{luatexja.load\_jfm}コールバック]
3853 %<*en>
3854 With this callback you can overwrite JFMs.
3855 This callback is called when a new JFM is loaded.
3856 %</en>
3857 %<*ja>
3858 このコールバックを用いることでJFMを上書きすることができる.
3859 このコールバックは新しいJFMが読み込まれるときに呼び出される.
3860 %</ja>
3861
3862 \begin{lstlisting}[numbers=left]
3863 function (<table> jfm_info, <string> jfm_name)
3864   return <table> new_jfm_info
3865 end
3866 \end{lstlisting}
3867
3868 %<*en>
3869 The argument \verb+jfm_info+ contains a table similar to the table in a JFM file, except
3870 this argument has \texttt{chars} field which contains character codes
3871              whose character class is not~0.
3872 %</en>
3873 %<*ja>
3874 引数 \verb+jfm_info+ はJFMファイルのテーブルと似たものが格納されるが,
3875 クラス0を除いた文字のコードを含んだ\texttt{chars}フィールドを持つ点が異なる.
3876 %</ja>
3877
3878 %<*en>
3879 An example of this callback is the \texttt{ltjarticle} class, with
3880              forcefully assigning character class~0 to \texttt{'parbdd'}
3881              in the JFM \texttt{jfm-min.lua}.
3882 %</en>
3883 %<*ja>
3884 このコールバックの使用例は\texttt{ltjarticle}クラスにあり,
3885 \texttt{jfm-min.lua}中の\texttt{'parbdd'}を強制的にクラス0に割り当てている.
3886 %</ja>
3887
3888 %<en>\item[\texttt{luatexja.define\_jfont} callback]
3889 %<ja>\item[\texttt{luatexja.define\_jfont}コールバック]
3890 %<*en>
3891 This callback and the next callback form a pair, and you can assign characters 
3892  which do not have fixed code points in Unicode to non-zero character classes.
3893 This \texttt{luatexja.define\_font} callback is called just when new Japanese font is loaded.
3894 %</en>
3895 %<*ja>
3896 このコールバックと次のコールバックは組をなしており,Unicode中に固定された文字コード
3897 番号を持たない文字を非零の文字クラスに割り当てることができる.
3898 このコールバックは新しい和文フォントが読み込まれたときに呼び出される.
3899 %</ja>
3900
3901 \begin{lstlisting}[numbers=left]
3902 function (<table> jfont_info, <number> font_number)
3903   return <table> new_jfont_info
3904 end
3905 \end{lstlisting}
3906 %<*en>
3907 \verb+jfont_info+ has the following fields,
3908 \emph{which may not overwritten by a user}:
3909 \begin{description}
3910 \item[\texttt{size}]
3911 The font size specified at \verb+\jfont+ in scaled points ($1\,\mathrm{sp}=2^{-16}\,\mathrm{pt}$).
3912 \item[\texttt{zw}, \texttt{zh}, \texttt{kanjiskip}, \texttt{xkanjiskip}]
3913 These are scaled value of those specified by the JFM, by the font size.
3914 \item[\texttt{jfm}]
3915 The internal number of the JFM.
3916 \item[\texttt{var}]
3917 The value of \texttt{jfmvar}~key, which is specified at \verb+\jfont+.
3918 The default value is the empty string.
3919 \item[\texttt{chars}]
3920 The mapping table from character codes to its character classes.\\
3921 The specification \texttt{[i].chars=\{<character>, ...\}} in the JFM will be  stored in this
3922            field as \texttt{chars=\{[<character>]=\,$i$, ...\}}.
3923 \item[\texttt{char\_type}]
3924 For $i\in\omega$, \texttt{char\_type[$i$]} is information of characters whose class is
3925            $i$, and has the following fields:
3926 \begin{itemize}
3927  \item \texttt{width},~\texttt{height}, \texttt{depth}, 
3928   \texttt{italic}, \texttt{down},~\texttt{left}\ are just 
3929        scaled value of those specified by the JFM, by the font size.
3930  \item \texttt{align} is a number which is determined from \texttt{align}~field in the JFM:
3931 \[
3932  \begin{cases}
3933   0&\text{\texttt{'left'} and the default value}\\0.5&\text{\tt 'middle'}\\1&\text{\tt 'right'}
3934  \end{cases}
3935 \]
3936 \item For $j\in \omega$, \texttt{[$j$]} stores a kern or a glue which will be inserted 
3937 between character class~$i$ and class~$j$.
3938
3939 If a kern will be inserted, the value of this field is \texttt{[$j$]=\{false, <kern\_node>, <ratio>\}},
3940 where <kern\_node> is a node\footnote{%
3941  This version of \LuaTeX-ja uses ``direct access
3942       model'' for accessing nodes, if possible. }.
3943 If a glue will be inserted, we have \texttt{[$j$]=\{false, <spec\_node>, <ratio>, <icflag>\}},
3944 where <spec\_node> is also a node, and $\text{<icflag>}=\textit{from\_jfm}+\text{<priority>}$.
3945 \end{itemize}
3946 \end{description}
3947 %</en>
3948 %<*ja>
3949 \verb+jfont_info+ は最低限以下のフィールドを持つが,これらを書き換えてはならない:
3950 \begin{description}
3951 \item[\texttt{size}]
3952 実際に使われるフォントサイズ(sp単位).$1\,\mathrm{sp}=2^{-16}\,\mathrm{pt}$.
3953 \item[\texttt{zw}, \texttt{zh}, \texttt{kanjiskip}, \texttt{xkanjiskip}]
3954 JFMファイルで指定されているそれぞれの値をフォントサイズに合わせてスケーリングしたものを
3955 sp単位で格納している.
3956 \item[\texttt{jfm}]
3957 利用されているJFMを識別するための番号.
3958 \item[\texttt{var}]
3959 \verb+\jfont+で指定された \texttt{jfmvar} キーの値(未指定のときは空文字列).
3960 \item[\texttt{chars}]
3961 文字コードから文字クラスへの対応が記述されたテーブル.\\
3962 JFM内の \texttt{[i].chars=\{<character>, ...\}} という指定は\ 
3963 \texttt{chars=\{[<character>]=\,$i$, ...\}} という形式に変換されている.
3964 \item[\texttt{char\_type}]
3965 $i\in\omega$に対して,\texttt{char\_type[$i$]} は文字クラス$i$の文字の寸法を格納しており,
3966 以下のフィールドを持つ.
3967 \begin{itemize}
3968  \item \texttt{width},~\texttt{height}, \texttt{depth}, 
3969   \texttt{italic}, \texttt{down},~\texttt{left}\ は
3970 JFMで指定されているそれぞれの値をスケーリングしたものである.
3971  \item \texttt{align} はJFMで指定されている値によって,
3972 \[
3973  \begin{cases}
3974   0&\text{\texttt{'left'}や省略時}\\0.5&\text{\tt 'middle'}\\1&\text{\tt 'right'}
3975  \end{cases}
3976 \]
3977 のいずれかの値をとる.
3978 \item $j\in \omega$に対して,\texttt{[$j$]} は文字クラス$i$の文字と$j$の文字の間に挿入されるkern
3979       やglueを格納している.
3980 間に入るものがkernであれば,このフィールドの値は\ 
3981 \texttt{[$j$]=\{false, <kern\_node>, <ratio>\}} である.
3982 <kern\_node>はkernを表すノードそのものである\footnote{%
3983 本バージョンでは利用可能ならばノードのアクセス手法にdirect access
3984       modelを用いている.そのため,例えば\LuaTeX\ beta-0.78.2では,単なる自然数のようにし
3985       か見えないことに注意.
3986 }.
3987 glueであれば,\texttt{[$j$]=\{false, <spec\_node>, <ratio>, <icflag>\}} である.
3988 <spec\_node>はglueの長さを表すノードそのものであり,
3989       $\text{<icflag>}=\textit{from\_jfm}+\text{<priority>}$である.
3990 \end{itemize}
3991 \end{description}
3992 %</ja>
3993
3994 %<*en>
3995 The returned table \verb+new_jfont_info+ also should include these fields, but
3996 you are free to add more fields (to use them in the \texttt{luatexja.find\_char\_class} callback).
3997 The \verb+font_number+ is a font number.
3998 %</en>
3999 %<*ja>
4000 戻り値の \verb+new_jfont_info+ テーブルも上に述べたフィールドをそのまま含まなければならないが,
4001 それ以外にユーザが勝手にフィールドを付け加えることは自由である.
4002 \verb+font_number+ はフォント番号である.
4003 %</ja>
4004
4005 %<*en>
4006 A good example of this and the next callbacks is the \Pkg{luatexja-otf}
4007              package, supporting \verb+"AJ1-xxx"+ form for Adobe-Japan1
4008              CID characters in a JFM. This callback doesn't replace any
4009              code of \LuaTeX-ja.
4010 %</en>
4011 %<*ja>
4012 これと次のコールバックの良い使用例は\Pkg{luatexja-otf}パッケージであり,
4013 JFM中でAdobe-Japan1 CIDの文字を \verb+"AJ1-xxx"+ の形で指定するために
4014 用いられている.
4015 %</ja>
4016
4017 %<en>\item[\texttt{luatexja.find\_char\_class} callback]
4018 %<ja>\item[\texttt{luatexja.find\_char\_class}コールバック]
4019 %<*en>
4020 This callback is called just when \LuaTeX-ja is trying to determine which
4021              character class a character \verb+chr_code+ belongs.
4022 A function used in this callback should be in the following form:
4023 %</en>
4024 %<*ja>
4025 このコールバックは\LuaTeX-jaが \verb+chr_code+ の文字がどの文字クラスに
4026 属するかを決定しようとする際に呼び出される.
4027 このコールバックで呼び出される関数は次の形をしていなければならない:
4028 %</ja>
4029 \begin{lstlisting}[numbers=left]
4030 function (<number> char_class, <table> jfont_info, <number> chr_code)
4031   if char_class~=0 then return char_class
4032   else
4033     ....
4034     return (<number> new_char_class or 0)
4035   end
4036 end
4037 \end{lstlisting}
4038
4039 %<*en>
4040 The argument \verb+char_class+ is the result of \LuaTeX-ja's default
4041              routine or previous function calls in this callback, hence
4042              this argument may not be 0. Moreover, the returned
4043              \verb+new_char_class+ should be as same as \verb+char_class+ when \verb+char_class+
4044              is not~0, otherwise you will overwrite the \LuaTeX-ja's
4045              default routine.
4046 %</en>
4047 %<*ja>
4048 引数 \verb+char_class+ は\LuaTeX-jaのデフォルトルーチンか,このコールバックの
4049 直前の関数呼び出しの結果を含んでおり,したがってこの値は0ではないかもしれない.
4050 さらに,戻り値の \verb+new_char_class+ は \verb+char_class+ が非零のときには
4051 \verb+char_class+ の値と同じであるべきで,そうでないときは\LuaTeX-jaの
4052 デフォルトルーチンを書き換えることになる.
4053 %</ja>
4054
4055 %<en>\item[\texttt{luatexja.set\_width} callback]
4056 %<ja>\item[\texttt{luatexja.set\_width}コールバック]
4057 %<*en>
4058 This callback is called when \LuaTeX-ja is trying to encapsule a
4059              \textbf{JAchar} \textit{glyph\_node}, to adjust its
4060              dimension and position.
4061 %</en>
4062 %<*ja>
4063 このコールバックは\LuaTeX-jaが\textbf{JAchar}の寸法と位置を調節するために
4064 その\textit{glyph\_node}をカプセル化しようとする際に呼び出される.
4065 %</ja>
4066 \begin{lstlisting}[numbers=left]
4067 function (<table> shift_info, <table> jfont_info, <number> char_class)
4068   return <table> new_shift_info
4069 end
4070 \end{lstlisting}
4071
4072 %<*en>
4073 The argument \verb+shift_info+ and the returned \verb+new_shift_info+ have
4074 \texttt{down} and \texttt{left} fields, which are the amount of shifting
4075              down/left the character in a scaled point.
4076 %</en>
4077 %<*ja>
4078 引数 \verb+shift_info+ と戻り値の \verb+new_shift_info+ は
4079 \texttt{down}と\texttt{left}のフィールドを持ち,これらの値は
4080 文字の下/左へのシフト量(sp単位)である.
4081 %</ja>
4082
4083 %<*en>
4084 A good example is \Pkg{test/valign.lua}.
4085 After loading this file, the vertical position of glyphs is automatically
4086 adjusted; the ratio $(\hbox{height}:\hbox{depth})$ of glyphs is adjusted
4087 to be that of letters in the character class~0. For example, suppose that
4088 \begin{itemize}
4089 \item The setting of the JFM: $(\hbox{height})=88x$, $(\hbox{depth})=12x$
4090   (the standard values of Japanese OpenType fonts);
4091 \item The value of the real font: $(\hbox{height})=28y$, $(\hbox{depth})=5y$
4092   (the standard values of Japanese TrueType fonts).
4093 \end{itemize}
4094 Then, the position of glyphs is shifted up by
4095 %</en>
4096 %<*ja>
4097 良い例が\Pkg{test/valign.lua}である.このファイルが読み込まれた状態では,
4098              JFM内で規定された文字クラス0の文字における$(\hbox{高
4099              さ}):(\hbox{深さ})$の比になるように,実際のフォントの出力上
4100              下位置が自動調整される.例えば,
4101 \begin{itemize}
4102 \item JFM側の設定:$(\hbox{高さ})=88x$, $(\hbox{深さ})=12x$%
4103 (和文OpenTypeフォントの標準値)
4104 \item 実フォント側の数値:$(\hbox{高さ})=28y$, $(\hbox{深さ})=5y$(和文TrueTypeフォントの標準値)
4105 \end{itemize}
4106 となっていたとする.すると,実際の文字の出力位置は,以下の量だけ上にぜらされることとなる:
4107 %</ja>
4108 \[
4109  \frac{88x}{88x+12x} (28y+5y) - 28y = \frac{26}{25}y= 1.04y.
4110 \]
4111 \end{list}
4112
4113
4114
4115 %<en>\section{Parameters}
4116 %<ja>\section{パラメータ}
4117 \subsection{\texttt{\textbackslash ltjsetparameter}}
4118 \label{ssec-param}
4119
4120 %<*en>
4121 As described before, \verb+\ltjsetparameter+ and \verb+\ltjgetparameter+ are
4122 commands for accessing most parameters of \LuaTeX-ja. One of the main
4123 reason that \LuaTeX-ja didn't adopted the syntax similar to that of \pTeX\
4124 (\textit{e.g.},~\verb+\prebreakpenalty`)=10000+)
4125 is the position of \verb+hpack_filter+ callback in the source
4126 of \LuaTeX, see Section~\ref{sec-para}.
4127 %</en>
4128 %<*ja>
4129 先に述べたように,\verb+\ltjsetparameter+ と \verb+\ltjgetparameter+ は
4130 \LuaTeX-jaのほとんどのパラメータにアクセスするための命令である.
4131 \LuaTeX-jaが\pTeX のような文法(例えば,\verb+\prebreakpenalty`)=10000+)を
4132 採用しない理由の一つは,\LuaTeX のソースにおける \verb+hpack_filter+
4133 コールバックの位置にある.\ref{sec-para}章を参照.
4134 %</ja>
4135
4136 %<*en>
4137 \verb+\ltjsetparameter+ and \verb+\ltjglobalsetparameter+ are commands
4138 for assigning parameters. These take one argument which is a
4139 \texttt{<key>=<value>} list. 
4140 The list of allowed keys are described in the next subsection.
4141 The difference between
4142 \verb+\ltjsetparameter+ and \verb+\ltjglobalsetparameter+ is only the
4143 scope of assignment;
4144 \verb+\ltjsetparameter+ does a local assignment and
4145 \verb+\ltjglobalsetparameter+ does a global one.
4146 They also obey the value of \verb+\globaldefs+,
4147 like other assignment.
4148 %</en>
4149 %<*ja>
4150 \verb+\ltjsetparameter+ と \verb+\ltjglobalsetparameter+ はパラメータを
4151 指定するための命令である.これらは\texttt{<key>=<value>}のリストを
4152 引数としてとる.許されるキーの一覧は次の節にある.
4153 \verb+\ltjsetparameter+ と \verb+\ltjglobalsetparameter+ の違いはスコープの
4154 違いのみで,
4155 \verb+\ltjsetparameter+ はローカルな指定,\verb+\ltjglobalsetparameter+ は
4156 グローバルな指定を行う.
4157 これらは他のパラメータ指定と同様に \verb+\globaldefs+ の値に従う.
4158 %</ja>
4159
4160 %<*en>
4161 The following is the list of parameters which can be specified by the
4162 \verb+\ltjsetparameter+ command. [\verb+\cs+] indicates the counterpart
4163 in \pTeX, and symbols beside each parameter has the following meaning:
4164 %</en>
4165 %<*ja>
4166 以下は \verb+\ltjsetparameter+ に指定することができるパラメータの一覧である.
4167 [\verb+\cs+]は\pTeX における対応物を示す.
4168 また,それぞれのパラメータの右上にある記号には次の意味がある:
4169 %</ja>
4170 \begin{itemize}
4171 %<*en>
4172 \item ``\ast'' : values at the end of a paragraph or a hbox are
4173 adopted in the whole paragraph or the whole hbox.
4174 %</en>
4175 %<*ja>
4176 \item ``\ast'':段落やhboxの終端での値がその段落/hbox全体で用いられる.
4177 %</ja>
4178 %<*en>
4179 \item ``\dagger'': assignments are always global.
4180 %</en>
4181 %<*ja>
4182 \item ``\dagger'':指定は常にグローバルになる.
4183 %</ja>
4184 \end{itemize}
4185
4186 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}\advance\leftmargin1\zw}
4187 \item[\Param{jcharwidowpenalty}\,=<penalty>$^\ast$] [\verb+\jcharwidowpenalty+]
4188 %<*en>
4189 Penalty value for suppressing orphans. This penalty is inserted just
4190              after the last \textbf{JAchar} which is not regarded as a
4191              (Japanese) punctuation mark.
4192 %</en>
4193 %<*ja>
4194 パラグラフの最後の字が孤立して改行されるのを防ぐためのペナルティの値.
4195 このペナルティは(日本語の)句読点として扱われない最後の\textbf{JAchar}の直後に
4196 挿入される.
4197 %</ja>
4198
4199 \item[\Param{kcatcode}\,=\{<chr\_code>,<natural number>\}$^\ast$]\
4200 %<*en>
4201 An additional attributes which each character whose character code is <chr\_code> has.
4202 At the present version, the lowermost bit of <natural number> indicates
4203              whether the character is considered as a punctuation mark
4204              (see the description of \Param{jcharwidowpenalty} above).
4205 %</en>
4206 %<*ja>
4207 文字コードが<chr\_code>の文字が持つ付加的な属性値(attribute).
4208 現在のバージョンでは,<natural number>の最下位ビットが,その文字が句読点と
4209 みなされるかどうかを表している(上の\Param{jcharwidowpenalty}の記述を参照).
4210 %</ja>
4211
4212 \item[\Param{\hypertarget{fld:prebp}{prebreakpenalty}}\,=\{<chr\_code>,<penalty>\}$^\ast$] [\verb+\prebreakpenalty+]\
4213 %<*ja>
4214 文字コード<chr\_code>の\textbf{JAchar}が行頭にくることを抑止するために,
4215              この文字の前に挿入/追加されるペナルティの量を指定する.
4216
4217 例えば閉じ括弧「〗」は絶対に行頭にきてはならないので,
4218 \begin{verbatim}
4219 \ltjsetparameter{prebreakpenalty={`〙,10000}}
4220 \end{verbatim}
4221 と,最大値の10000が標準で指定されている.他にも,小書きのカナなど,絶対禁止とい
4222              うわけではないができれば行頭にはきて欲しくない場合に,0と
4223              10000の間の値を指定するのも有用であろう.
4224 %</ja>
4225 %<*en>
4226 Set a penalty which is inserted automatically before the character <chr\_code>,
4227 to prevent a line starts from this character. For example, a line cannot started
4228 with one of closing brackets ``〗'', so \LuaTeX-ja sets
4229 \begin{verbatim}
4230 \ltjsetparameter{prebreakpenalty={`〙,10000}}
4231 \end{verbatim}
4232 by default.
4233 %</en>
4234
4235
4236 \item[\Param{\hypertarget{fld:postbp}{postbreakpenalty}}\,=\{<chr\_code>,<penalty>\}$^\ast$] [\verb+\postbreakpenalty+]
4237 %<*ja>
4238 文字コード<chr\_code>の\textbf{JAchar}が行末にくることを抑止するために,
4239              この文字の後に挿入/追加されるペナルティの量を指定する.
4240
4241 \pTeX では,\verb+\prebreakpenalty+, \verb+\postbreakpenalty+において,
4242 \begin{itemize}
4243 \item 一つの文字に対して,pre, postどちらか一つしか指定することができなかっ
4244       た(後から指定した方で上書きされる).
4245 \item pre, post合わせて256文字分の情報を格納することしかできなかった.
4246 \end{itemize}
4247 という制限があったが,\LuaTeX-jaではこれらの制限は解消されている.
4248 %</ja>
4249 %<*en>
4250 Set a penalty which is inserted automatically after the character <chr\_code>,
4251 to prevent a line ends with this character. 
4252 \pTeX\ has following restrictions on \verb+\prebreakpenalty+ and \verb+\postbreakpenalty+,
4253 but they don't exist in \LuaTeX-ja:
4254 \begin{itemize}
4255  \item Both \verb+\prebreakpenalty+ and \verb+\postbreakpenalty+ cannot be set
4256 for the same character.
4257  \item We can set \verb+\prebreakpenalty+ and \verb+\postbreakpenalty+  up to 256~characters.
4258 \end{itemize}
4259 %</en>
4260
4261 \item[\Param{jatextfont}\,=\{<jfam>,<jfont\_cs>\}$^\ast$]
4262 %<en>[\verb+\textfont+ in \TeX]
4263 %<ja>[\TeX の \verb+\textfont+]
4264 \item[\Param{jascriptfont}\,=\{<jfam>,<jfont\_cs>\}$^\ast$]
4265 %<en>[\verb+\scriptfont+ in \TeX]
4266 %<ja>[\TeX の \verb+\scriptfont+]
4267 \item[\Param{jascriptscriptfont}\,=\{<jfam>,<jfont\_cs>\}$^\ast$]
4268 %<en>[\verb+\scriptscriptfont+ in \TeX]
4269 %<ja>[\TeX の \verb+\scriptscriptfont+]
4270 \item[\Param{yjabaselineshift}\,=<dimen>]\
4271 \item[\Param{yalbaselineshift}\,=<dimen>] [\verb+\ybaselineshift+]
4272 \item[\Param{tjabaselineshift}\,=<dimen>]\
4273 \item[\Param{talbaselineshift}\,=<dimen>] [\verb+\tbaselineshift+]
4274
4275 \item[\Param{jaxspmode}\,=\{<chr\_code>,<mode>\}$^\ast$]
4276
4277 %<*en>
4278 Setting whether inserting \Param{\hyperlink{fld:xks}{xkanjiskip}} is allowed before/after a \textbf{JAchar} whose character code is <chr\_code>.
4279 The followings are allowed for <mode>:
4280 %</en>
4281 %<*ja>
4282 文字コードが<chr\_code>の\textbf{JAchar}の前/後ろに\Param{\hyperlink{fld:xks}{xkanjiskip}}の
4283 挿入を許すかどうかの設定.
4284 以下の<mode>が許される:
4285 %</ja>
4286 \begin{description}
4287 %<en>\item[0, \texttt{inhibit}] Insertion of \Param{\hyperlink{fld:xks}{xkanjiskip}} is inhibited before the character, nor after the character.
4288 %<ja>\item[0, \texttt{inhibit}] \Param{\hyperlink{fld:xks}{xkanjiskip}}の挿入は文字の前/後ろのいずれでも禁止される.
4289 %<en>\item[1, \texttt{preonly}] Insertion of \Param{\hyperlink{fld:xks}{xkanjiskip}} is allowed before the character, but not after.
4290 %<ja>\item[1, \texttt{preonly}] \Param{\hyperlink{fld:xks}{xkanjiskip}}の挿入は文字の前では許されるが,後ろでは許されない.
4291 %<en>\item[2, \texttt{postonly}] Insertion of \Param{\hyperlink{fld:xks}{xkanjiskip}} is allowed after the character, but not before.
4292 %<ja>\item[2, \texttt{postonly}] \Param{\hyperlink{fld:xks}{xkanjiskip}}の挿入は文字の後ろでは許されるが,前では許されない.
4293 %<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.
4294 %<ja>\item[3, \texttt{allow}] \Param{\hyperlink{fld:xks}{xkanjiskip}}の挿入は文字の前/後ろのいずれでも許される.これがデフォルトの値である.
4295 \end{description}
4296 %<*en>
4297 This parameter is similar to the \verb+\inhibitxspcode+ primitive of \pTeX, but not compatible with \verb+\inhibitxspcode+.
4298 %</en>
4299 %<*ja>
4300 このパラメータは\pTeX の \verb+\inhibitxspcode+ プリミティブと似ているが,
4301 互換性はない.
4302 %</ja>
4303 \item[\Param{alxspmode}\,=\{<chr\_code>,<mode>\}$^\ast$] [\verb+\xspcode+]
4304
4305 %<*en>
4306 Setting whether inserting \Param{\hyperlink{fld:xks}{xkanjiskip}} is allowed before/after a
4307              \textbf{ALchar} whose character code is <chr\_code>.
4308              The followings are allowed for <mode>:
4309 %</en>
4310 %<*ja>
4311 文字コードが<chr\_code>の\textbf{ALchar}の前/後ろに\Param{\hyperlink{fld:xks}{xkanjiskip}}の
4312 挿入を許すかどうかの設定.
4313 以下の<mode>が許される:
4314 %</ja>
4315 \begin{description}
4316 %<en>\item[0, \texttt{inhibit}] Insertion of \Param{\hyperlink{fld:xks}{xkanjiskip}} is inhibited before the character, nor after the character.
4317 %<ja>\item[0, \texttt{inhibit}] \Param{\hyperlink{fld:xks}{xkanjiskip}}の挿入は文字の前/後ろのいずれでも禁止される.
4318 %<en>\item[1, \texttt{preonly}] Insertion of \Param{\hyperlink{fld:xks}{xkanjiskip}} is allowed before the character, but not after.
4319 %<ja>\item[1, \texttt{preonly}] \Param{\hyperlink{fld:xks}{xkanjiskip}}の挿入は文字の前では許されるが,後ろでは許されない.
4320 %<en>\item[2, \texttt{postonly}] Insertion of \Param{\hyperlink{fld:xks}{xkanjiskip}} is allowed after the character, but not before.
4321 %<ja>\item[2, \texttt{postonly}] \Param{\hyperlink{fld:xks}{xkanjiskip}}の挿入は文字の後ろでは許されるが,前では許されない.
4322 %<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.
4323 %<ja>\item[3, \texttt{allow}] \Param{\hyperlink{fld:xks}{xkanjiskip}}の挿入は文字の前/後ろのいずれでも許される.これがデフォルトの値である.
4324 \end{description}
4325 %<*en>
4326 Note that parameters \Param{jaxspmode} and \Param{alxspmode} share a common table, hence these two parameters are synonyms of each other.
4327 %</en>
4328 %<*ja>
4329 \Param{jaxspmode}と\Param{alxspmode}は共通のテーブルを用いているため,
4330 これら2つのパラメータは互いの異名となっていることに注意する.
4331 %</ja>
4332
4333 \item[\Param{autospacing}\,=<bool>] [\verb+\autospacing+]
4334 \item[\Param{autoxspacing}\,=<bool>] [\verb+\autoxspacing+]
4335 \item[\Param{\hypertarget{fld:kanjiskip}{kanjiskip}}\,=<skip>$^\ast$] [\verb+\kanjiskip+]
4336 %<*ja>
4337 デフォルトで2つの\textbf{JAchar}の間に挿入されるグルーである.
4338 通常では,\pTeX と同じようにフォントサイズに比例して変わることはない.
4339 しかし,自然長が \verb+\maxdimen+ の場合は,例外的に和文フォントのJFM側で指定されている
4340 値を採用(こちらはフォントサイズに比例)することになっている.
4341 %</ja>
4342
4343 \item[\Param{\hypertarget{fld:xks}{xkanjiskip}}\,=<skip>$^\ast$] [\verb+\xkanjiskip+]
4344 %<*ja>
4345 デフォルトで\textbf{JAchar}と\textbf{ALchar}の間に挿入されるグルーである.
4346 \Param{\hyperlink{fld:kanjiskip}{kanjiskip}}と同じように,通常ではフォントサイズに比例して変わることはないが,
4347 自然長が \verb+\maxdimen+ の場合が例外である.
4348 %</ja>
4349
4350
4351 \item[\Param{\hypertarget{fld:diffjfm}{differentjfm}}\,=<mode>$^\dagger$]
4352
4353 %<*en>
4354 Specify how glues/kerns between two \textbf{JAchar}s whose JFM (or size) are different.
4355 The allowed arguments are the followings:
4356 %</en>
4357 %<*ja>
4358 JFM(もしくはサイズ)が異なる2つの\textbf{JAchar}の間にグルー/カーンをどのように
4359 入れるかを指定する.
4360 許される値は以下の通り:
4361 %</ja>
4362 \begin{quote}
4363 \texttt{average}, 
4364 \texttt{both}, 
4365 \texttt{large}, 
4366 \texttt{small}, 
4367 \texttt{pleft}, 
4368 \texttt{pright}, 
4369 \texttt{paverage}
4370 \end{quote}
4371 %<*en>
4372 The default value is \texttt{paverage}. \dots
4373 %</en>
4374 %<*ja>
4375 デフォルト値は \texttt{paverage} である.
4376 各々の値による差異の詳細は\ref{ssec-cluster-wa}節の「『右空白』の算出」を参照してほしい.
4377 %</ja>
4378
4379 \item[\Param{jacharrange}\,=<ranges>]
4380 \item[\Param{kansujichar}\,=\{<digit>, <chr\_code>\}$^\ast$] [\verb+\kansujichar+]
4381 \end{list}
4382
4383 \subsection{\texttt{\textbackslash ltjgetparameter}}
4384 \label{ssec-getpar}
4385 %<*en>
4386 \verb+\ltjgetparameter+ is a conteol sequence for acquiring parameters. It
4387 always takes a parameter name as first argument.
4388 %</en>
4389 %<*ja>
4390 \verb+\ltjgetparameter+ はパラメータの値を取得するための命令であり,
4391 常にパラメータの名前を第一引数にとる.
4392 %</ja>
4393 \begin{LTXexample}
4394 \ltjgetparameter{differentjfm},
4395 \ltjgetparameter{autospacing},
4396 \ltjgetparameter{kanjiskip},
4397 \ltjgetparameter{prebreakpenalty}{`)}.
4398 \end{LTXexample}
4399
4400 %<*en>
4401 \emph{The return value of\/ {\normalfont\tt\textbackslash ltjgetparameter} is
4402 always a string}. This is outputted by \texttt{tex.write()}, so any
4403 character other than space~``\texttt{\char32}''~(\texttt{U+0020}) has the category code
4404 12~(other), while the space has 10~(space).
4405 %</en>
4406 %<*ja>
4407 \emph{{\normalfont\tt\textbackslash ltjgetparameter}の戻り値は常に文字列である.}
4408 これは\texttt{tex.write()}によって出力しているためで,空白「\texttt{\char32}」
4409 (\texttt{U+0020})を除いた文字のカテゴリーコードは全て12~(other)となる.
4410 一方,空白のカテゴリーコードは10~(space)である.
4411 %</ja>
4412
4413 \begin{itemize}
4414 \item 
4415 %<*en>
4416 If first argument is one of the
4417 following, no  additional argument is needed.
4418 %</en>
4419 %<*ja>
4420 第1引数が次のいずれかの場合には,追加の引数は必要ない.
4421 %</ja>
4422 \begin{quote}
4423 \sffamily 
4424 jcharwidowpenalty, yjabaselineshift, yalbaselineshift, autospacing, autoxspacing,\\
4425 kanjiskip, xkanjiskip, differentjfm
4426 \end{quote}
4427 %<*en>
4428 Note that \verb+\ltjgetparameter{autospacing}+~and~\verb+\ltjgetparameter{autoxspacing}+
4429 returns 1 or 0, not 
4430 \texttt{true}~nor~\texttt{false}.
4431 %</en>
4432 %<*ja>
4433 \verb+\ltjgetparameter{autospacing}+ と \verb+\ltjgetparameter{autoxspacing}+ は,
4434 \texttt{true}や\texttt{false}を返すの\emph{ではなく},
4435 1と0のいずれかを返すことに注意,
4436 %</ja>
4437
4438 \item 
4439 %<*en>
4440 If first argument is one of the
4441 following, an additional argument---a character code, for example---is needed.
4442 %</en>
4443 %<*ja>
4444 第1引数が次のいずれかの場合には,さらに文字コードを第二引数としてとる.
4445 %</ja>
4446 \begin{quote}
4447 \sffamily 
4448 kcatcode, prebreakpenalty, postbreakpenalty, jaxspmode, alxspmode
4449 \end{quote} 
4450 %<*en>
4451 \verb+\ltjgetparameter{jaxspmode}{...}+~and~\verb+\ltjgetparameter{alxspmode}{...}+
4452 returns 0,~1, 2,~or~3, instead of \texttt{preonly} etc.
4453 %</en>
4454 %<*ja>
4455 \verb+\ltjgetparameter{jaxspmode}{...}+ や \verb+\ltjgetparameter{alxspmode}{...}+\ 
4456 は,\texttt{preonly} などといった文字列ではなく,0から3までの値を返す.
4457 %</ja>
4458
4459 \item
4460 %<*en>
4461 \verb+\ltjgetparameter{jacharrange}{+<range>\verb+}+ returns \texttt{0}
4462 if ``characters which belong to the character range~<range> are \textbf{JAchar}'',
4463 \texttt{1} if ``\dots are \textbf{ALchar}''.
4464 Although there is no character range~$-1$, specifying $-1$ to <range> does not cause an
4465       error (returns 1).
4466 %</en>
4467 %<*ja>
4468 \verb+\ltjgetparameter{jacharrange}{+<range>\verb+}+ は,<range>が\textbf{JAchar}達の
4469 範囲ならば0を,そうでなければ1を返す.「$-1$番の文字範囲」は存在しないが,<range>に$-1$を
4470 指定してもエラーは発生しない(1を返す).
4471 %</ja>
4472
4473 \item
4474 %<*en>
4475 For an integer~<digit> between 0~and~9,
4476      \verb+\ltjgetparameter{kansujichar}{+<digit>\verb+}+ returns the character code
4477 of the result of \verb+\kansuji+<digit>.
4478 %</en>
4479 %<*ja>
4480 0--9の数<digit>に対して,
4481 \verb+\ltjgetparameter{kansujichar}{+<digit>\verb+}+ は,\verb+\kansuji+<digit>で出力され
4482      る文字の文字コードを返す.
4483 %</ja>
4484
4485
4486 \item 
4487 %<*en>
4488 The following parameter names \emph{cannot be specified} in \verb+\ltjgetparameter+.
4489 %</en>
4490 %<*ja>
4491 次のパラメータ名を \verb+\ltjgetparameter+ に指定することはできない.
4492 %</ja>
4493 \begin{quote}
4494 \sffamily 
4495 jatextfont, jascriptfont, jascriptscriptfont, jacharrange
4496 \end{quote}
4497
4498 \item 
4499 %<*en>
4500 \verb+\ltjgetparameter{chartorange}{+<chr\_code>\verb+}+ returns 
4501 the range number which <chr\_code> belongs to
4502 (although there is no parameter named ``chartorange''). 
4503
4504 If <chr\_code> is between 0 and 127, this <chr\_code> does not belong to
4505 any character range. In this case,
4506       \verb+\ltjgetparameter{chartorange}{+<chr\_code>\verb+}+
4507 returns $-1$.
4508
4509 Hence, one can know whether <chr\_code> is \textbf{JAchar} or not
4510 by the following:
4511 %</en>
4512 %<*ja>
4513 \verb+\ltjgetparameter{chartorange}{+<chr\_code>\verb+}+ によって
4514 <chr\_code>の属する文字範囲の番号を知ることができる.
4515
4516 <chr\_code>に0--127の値を指定した場合(このとき,<chr\_code>が属する
4517 文字範囲は存在しない)は$-1$が返る.
4518
4519 そのため,<chr\_code>が\textbf{JAchar}か\textbf{ALchar}かは
4520 次で知ることができる:
4521 %</ja>
4522 \begin{quote}
4523 \ttfamily \verb+\ltjgetparameter{jacharrange}{\ltjgetparameter{chartorange}{+%
4524   <chr\_code>\verb+}}+\\\null\hfill\verb+% 0 if JAchar, 1 if ALchar+
4525 \end{quote}
4526
4527 \end{itemize}
4528
4529
4530
4531
4532 %<en>\section{Other Commands for plain \TeX\ and \LaTeXe}
4533 %<ja>\section{plainでも\LaTeX でも利用可能なその他の命令}
4534 %<en>\subsection{Commands for Compatibility with \pTeX}
4535 %<ja>\subsection{\pTeX 互換用命令}
4536
4537 %<*en>
4538 The following commands are implemented for compatibility with \pTeX.
4539 Note that the former five commands don't support JIS~X~0213, but only JIS~X~0208.
4540 The last \verb+\kansuji+ converts an integer into its Chinese numerals.
4541 %</en>
4542 %<*ja>
4543 以下の命令は\pTeX との互換性のために実装されている.そのため,JIS~X~0213には対応せず,
4544 \pTeX と同じようにJIS~X~0208の範囲しかサポートしていない.
4545 %</ja>
4546 \begin{center}
4547 \verb+\kuten+, \verb+\jis+, \verb+\euc+, \verb+\sjis+, \verb+\jis+, \verb+\kansuji+
4548 \end{center}
4549 %<*en>
4550 These six commands takes an internal integer, and returns a \emph{string}.
4551 %</en>
4552 %<*ja>
4553 これら6命令は内部整数を引数とするが,実行結果は\textbf{文字列}であることに注意.
4554 %</ja>
4555 \begin{LTXexample}
4556 \newcount\hoge
4557 \hoge="2423 %"
4558 \the\hoge, \kansuji\hoge\\
4559 \jis\hoge, \char\jis\hoge\\
4560 \kansuji1701
4561 \end{LTXexample}
4562
4563 %<*en>
4564 To change characters of Chinese numerals for each digit, set \Param{kansujichar} parameter:
4565 \begin{LTXexample}
4566 \ltjsetparameter{kansujichar={1,`壹}}
4567 \ltjsetparameter{kansujichar={7,`漆}}
4568 \ltjsetparameter{kansujichar={0,`零}}
4569 \kansuji1701
4570 \end{LTXexample}
4571 %</en>
4572
4573
4574 %<en>\subsection{\texttt{\textbackslash inhibitglue}}
4575 %<ja>\subsection{\texttt{\textbackslash inhibitglue}}
4576 %<*en>
4577 \verb+\inhibitglue+ suppresses the insertion of \textbf{JAglue}.
4578 The following is an example, using a special JFM that there will be a glue between
4579 the beginning of a box and ``あ'', and also between ``あ''~and~``ウ''.
4580 %</en>
4581 %<*ja>
4582 \verb+\inhibitglue+ は\textbf{JAglue}の挿入を抑制する.
4583 以下は,ボックスの始めと「あ」の間,「あ」「ウ」の間にグルーが入る特別なJFMを用いた例で
4584 ある.
4585 %</ja>
4586
4587 \begin{LTXexample}[width=0.4\textwidth]
4588 \jfont\g=file:KozMinPr6N-Regular.otf:jfm=test \g
4589 \fbox{\hbox{あウあ\inhibitglue ウ}}
4590 \inhibitglue\par\noindent あ1
4591 \par\inhibitglue\noindent あ2
4592 \par\noindent\inhibitglue あ3
4593 \par\hrule\noindent あoff\inhibitglue ice
4594 \end{LTXexample}
4595
4596 %<*en>
4597 With the help of this example, we remark the specification of \verb+\inhibitglue+:
4598 %</en>
4599 %<*ja>
4600 この例を援用して,\verb+\inhibitglue+ の仕様について述べる.
4601 %</ja>
4602 \begin{itemize}
4603 %<*en>
4604 \item The call of \verb+\inhibitglue+ in the (internal) vertical mode is
4605       simply ignored.
4606 %</en>
4607 %<*ja>
4608 \item \verb+\inhibitglue+ の垂直モード中での呼び出しは意味を持たない.
4609 4行目の入力で有効にならないのは,\verb+\inhibitglue+ の時点では垂直モードであり,
4610 \verb+\noindent+ の時点で水平モードになるからである.
4611 %</ja>
4612
4613 %<*en>
4614 \item The call of \verb+\inhibitglue+ in the (restricted) horizontal
4615       mode is only effective on the spot; does not get over boundary of
4616       paragraphs. Moreover, \verb+\inhibitglue+ cancels ligatures and
4617       kernings, as shown in the last line of above example.
4618 %</en>
4619 %<*ja>
4620 \item \verb+\inhibitglue+ の(制限された)水平モード中での呼び出しはその場でのみ
4621   有効であり,段落の境界を乗り越えない.
4622   さらに,\verb+\inhibitglue+ は上の例の最終行のように(欧文における)リガチャとカーニングを
4623   打ち消す.これは,\verb+\inhibitglue+ が内部的には「現在のリスト中にwhatsitノードを
4624   追加する」ことを行なっているからである.
4625 %</ja>
4626
4627 %<*en>
4628 \item The call of \verb+\inhibitglue+ in math mode is just ignored.
4629 %</en>
4630 %<*ja>
4631 \item \verb+\inhibitglue+ を数式モード中で呼び出した場合はただ無視される.
4632 %</ja>
4633
4634 %<*ja>
4635 \item \LaTeX で\LuaTeX-ja を使用する場合は,
4636 \verb+\inhibitglue+ の代わりとして \verb+\<+ を使うことができる.
4637 既に \verb+\<+ が定義されていた場合は,\LuaTeX-ja の読み込みで強制的に上書きされるので
4638 注意すること.
4639 %</ja>
4640 \end{itemize}
4641
4642
4643 \subsection{\texttt{\textbackslash ltjdeclarealtfont}}
4644 \label{ssec-altfont}
4645 %<*en>
4646 Using \verb+\ltjdeclarealtfont+, one can ``compose'' more than one Japanese fonts.
4647 This \verb+\ltjdeclarealtfont+ uses in the following form:
4648 \begin{quote}
4649 \ttfamily \textbackslash ltjdeclarealtfont<base\_font\_cs><alt\_font\_cs>{<range>}
4650 \end{quote}
4651 where  <base\_font\_cs>~and~<alt\_font\_cs> are defined by \verb+\jfont+.
4652 Its meaning is
4653 \begin{quote}
4654 If the current Japanese font is <base\_font\_cs>, characters which belong to <range>
4655 is typeset by another Japanese font <alt\_font\_cs>, instead of <base\_font\_cs>.
4656 \end{quote}
4657
4658 <range> is a comma-separated list of character codes, but also accepts negative integers:
4659 $-n$~($n≥1$) means that all characters of character classes~$n$, with respect to JFM used
4660 by <base\_font\_cs>. Note that characters which do not exist in <alt\_font\_cs> are
4661 ignored.
4662
4663 For example, if \verb+\hoge+ uses \texttt{jfm-ujis.lua}, the standard JFM of \LuaTeX-ja,
4664 then 
4665 \begin{verbatim}
4666 \ltjdeclarealtfont\hoge\piyo{"3000-"30FF, {-1}-{-1}}
4667 \end{verbatim}
4668 does
4669 \begin{quote}
4670 If the current Japanese font is \verb+\hoge+, \texttt{U+3000}--\texttt{U+30FF}
4671 and characters in class~1 (ideographic opening brackets) 
4672 are typeset by \verb+\piyo+.
4673 \end{quote}
4674 %</en>
4675 %<*ja>
4676 \verb+\jfont+ の書式を見ればわかるように,基本的には\LuaTeX-jaにおける1つの和文フォントに
4677 使用出来る「実際のフォント」は1つである.
4678 しかし,\verb+\ltjdeclarealtfont+ を用いると,この原則から外れることができる.
4679
4680 \verb+\ltjdeclarealtfont+ は以下の書式で使用する:
4681 \begin{quote}
4682 \ttfamily \textbackslash ltjdeclarealtfont<base\_font\_cs><alt\_font\_cs>{<range>}
4683 \end{quote}
4684 これは「現在の和文フォント」が<base\_font\_cs>であるとき,
4685 <range>に属する文字は<alt\_font\_cs>を用いて組版される,という意味である.
4686 \begin{itemize}
4687  \item <base\_font\_cs>, <alt\_font\_cs>は
4688 \verb+\jfont+ によって定義された和文フォントである.
4689  \item <range>は文字コードの範囲を表すコンマ区切りのリストであるが,
4690    例外として負数$-n$は「<base\_font\_cs>のJFMの文字クラス$n$に属する全ての文字」
4691    を意味する.
4692
4693 <range>中に<alt\_font\_cs>中に実際には存在しない文字が指定された場合は,
4694 その文字に対する設定は無視される.
4695 \end{itemize}
4696
4697 例えば,\verb+\hoge+ のJFMが\LuaTeX-ja標準の
4698 \ \texttt{jfm-ujis.lua} であった場合,
4699 \begin{verbatim}
4700 \ltjdeclarealtfont\hoge\piyo{"3000-"30FF, {-1}-{-1}}
4701 \end{verbatim}
4702 は「\verb+\hoge+ を利用しているとき,
4703 \texttt{U+3000}--\texttt{U+30FF}と
4704 文字クラス1(開き括弧類)中の文字だけは \verb+\piyo+ を用いる」
4705 ことを設定する.\verb+{-1}-{-1}+ という変わった指定の仕方をしているのは,
4706 普通に \texttt{-1} と指定したのでは正しく$-1$と読み取られないという
4707 マクロの都合による.
4708 %</ja>
4709
4710
4711
4712 %<en>\section{Commands for \LaTeXe}
4713 %<ja>\section{\LaTeXe 用の命令}
4714
4715 %<en>\subsection{Patch for NFSS2}
4716 %<ja>\subsection{NFSS2へのパッチ}
4717 \label{ssec-nfsspat}
4718
4719 \begin{figure}[!tb]
4720 \begin{LTXexample}[pos=b]
4721 \DeclareKanjiFamily{JY3}{edm}{}
4722 \DeclareFontShape{JY3}{edm}{m}{n}    {<-> s*KozMinPr6N-Regular:jfm=ujis;}{}
4723 \DeclareFontShape{JY3}{edm}{m}{green}{<-> s*KozMinPr6N-Regular:jfm=ujis;color=007F00}{}
4724 \DeclareFontShape{JY3}{edm}{m}{blue} {<-> s*KozMinPr6N-Regular:jfm=ujis;color=0000FF}{}
4725 \DeclareAlternateKanjiFont{JY3}{edm}{m}{n}{JY3}{edm}{m}{green}{"4E00-"67FF,{-2}-{-2}}
4726 \DeclareAlternateKanjiFont{JY3}{edm}{m}{n}{JY3}{edm}{m}{blue}{ "6800-"9FFF}
4727 {\kanjifamily{edm}\selectfont
4728 日本国民は、正当に選挙された国会における代表者を通じて行動し、……}
4729 \end{LTXexample}
4730 %<ja>\caption{\texttt{\textbackslash DeclareAlternateKanjiFont} の使用例}
4731 %<en>\caption{An example of \texttt{\textbackslash DeclareAlternateKanjiFont}}
4732 \label{fig:altkanji}
4733 \end{figure}
4734
4735 %<*en>
4736 Japanese patch for NFSS2 in \LuaTeX-ja
4737 is based on \texttt{plfonts.dtx} which plays the same role in \pLaTeXe.
4738 We will describe
4739 commands which are not described in Subsection~\ref{ssec-chgfnt}.
4740 %</en>
4741 %<*ja>
4742 \LuaTeX-jaのNFSS2への日本語パッチは
4743 \pLaTeXe で同様の役割を果たす \texttt{plfonts.dtx} をベースに,
4744 和文エンコーディングの管理等をLuaで書きなおしたものである.
4745 ここでは\ref{ssec-chgfnt}節で述べていなかった命令について
4746 記述しておく.
4747 %</ja>
4748
4749 \begin{cslist}%
4750 \par\smallskip\par\hskip-\leftskip{\bfseries%
4751 %<ja>追加の長さ変数達
4752 %<en>additonal dimensions
4753 }\par
4754
4755 %<*en>
4756 Like \pLaTeXe, \LuaTeX-ja defines the following dimensions 
4757 for information of current Japanese font:
4758 %</en>
4759 %<*ja>
4760 \pLaTeXe と同様に,\LuaTeX-jaは「現在の和文フォントの情報」を格納する長さ変数
4761 %</ja>
4762 {\let\item=\origitem
4763 \begin{quote}
4764  \verb+\cht+~(height), \verb+\cdp+~(depth), \verb+\cHT+~(sum of former two),\\
4765  \verb+\cwd+~(width), \verb+\cvs+~(lineskip), \verb+\chs+~(equals to \verb+\cwd+)
4766 \end{quote}}
4767 %<en>and its \verb+\normalsize+ version:
4768 %<ja>と,その \verb+\normalsize+ 版である
4769 {\let\item=\origitem
4770 \begin{quote}
4771  \verb+\Cht+~(height), \verb+\Cdp+~(depth),
4772  \verb+\Cwd+~(width), \\\verb+\Cvs+~(equals to \verb+\baselineskip+), 
4773  \verb+\Chs+~(equals to \verb+\cwd+)%
4774 %<en>.
4775 \end{quote}}
4776 %<*ja>
4777 を定義している.なお,\verb+\cwd+ と \verb+\zw+,また
4778 \verb+\cHT+ と \verb+\zh+ は一致しない可能性がある.なぜなら,
4779 \verb+\cwd+,~\verb+\cHT+ は「あ」の寸法から決定されるのに対し,
4780 \verb+\zw+ と \verb+\zh+ はJFMに指定された値に過ぎないからである.
4781 %</ja>
4782 %<*en>
4783 Note that \verb+\cwd+~and~\verb+\cHT+ may  differ from \verb+\zw+~and~\verb+\zh+
4784 respectively.
4785 On the one hand the former dimensions are determined from the character ``あ'',
4786 but on the other hand \verb+\zw+~and~\verb+\zh+ are specified by JFM.
4787 %</en>
4788
4789
4790 \item[DeclareYokoKanjiEncoding\{<encoding>\}\{<text-settings>\}\{<math-settings>\}]
4791 \item[DeclareYokoKanjiEncoding\{<encoding>\}\{<text-settings>\}\{<math-settings>\}]
4792
4793 %<*en>
4794 In NFSS2 under \LuaTeX-ja, distinction between alphabetic font families
4795              and Japanese font families are only made by their
4796              encodings. For example, encodings OT1 and T1 are for
4797              alphabetic font families, and a Japanese font family cannot
4798              have these encodings. These command define a new encoding
4799              scheme for Japanese font family.
4800 %</en>
4801 %<*ja>
4802 \LuaTeX-jaのNFSS2においては,欧文フォントファミリと和文フォントファミリは
4803 そのエンコーディングによってのみ区別される.
4804 例えば,OT1とT1のエンコーディングは欧文フォントファミリに対するものであり,
4805 和文フォントファミリはこれらのエンコーディングを持つことはできない.
4806 これらコマンドは横組用・縦組用和文フォントのための新しいエンコーディングを
4807 それぞれ定義する.
4808 %</ja>
4809
4810 \item[DeclareKanjiEncodingDefaults\{<text-settings>\}\{<math-settings>\}]
4811 \item[DeclareKanjiSubstitution\{<encoding>\}\{<family>\}\{<series>\}\{<shape>\}]
4812 \item[DeclareErrorKanjiFont\{<encoding>\}\{<family>\}\{<series>\}\{<shape>\}\{<size>\}]
4813
4814 %<*en>
4815 The above 3~commands are just the counterparts for \verb+\DeclareFontEncodingDefaults+ and~others.
4816 %</en>
4817 %<*ja>
4818 上記3つのコマンドはちょうど \verb+\DeclareFontEncodingDefaults+ などに対応するものである.
4819 %</ja>
4820
4821 \item[reDeclareMathAlphabet\{<unified-cmd>\}\{<al-cmd>\}\{<ja-cmd>\}]
4822
4823 % ToDo: en
4824 %<*ja>
4825 和文・欧文の数式用フォントファミリを一度に変更する命令を作成する.
4826 具体的には,欧文数式用フォントファミリ変更の命令<al-cmd>(\verb+\mathrm+ 等)と,和文数式用フォ
4827              ントファミリ変更の命令<ja-cmd>(\verb+\mathmc+ 等)の2つを同時に行う命令として
4828              <unified-cmd>を(再)定義する.実際の使用では<unified-cmd>と
4829              <al-cmd>に同じものを指定する,すなわち,<al-cmd>で和文側も変
4830              更させるようにするのが一般的と思われる.
4831
4832 本命令は
4833 {\let\item=\origitem
4834 \begin{center}\tt
4835 <unified-cmd>\{<arg>\}\quad$\longrightarrow$\quad
4836 (<al-cmd>の1段展開結果)\{<ja-cmd>の1段展開結果)\{<arg>\}\}
4837 \end{center}
4838 と定義を行うので,使用には注意が必要である:
4839 \vspace{-\medskipamount}
4840 %<en>\advance\linewidth-2em
4841 %<ja>\advance\linewidth-2\zw
4842 \begin{itemize}
4843 \item <al-cmd>,~<ja-cmd>は既に定義されていなければならない.
4844       \verb+\reDeclareMathAlphabet+\\の後に
4845 両命令の内容を再定義しても,<unified-cmd>の内容にそれは反映されない.
4846 \item <al-cmd>,~<ja-cmd>に\verb+\@mathrm+などと \texttt{@} をつけた命令を指定した時の動作は保証できない.
4847 \end{itemize}}
4848 %</ja>
4849
4850 \item[DeclareRelationFont\{<ja-encoding>\}\{<ja-family>\}\{<ja-series>\}\{<ja-shape>\}\\*
4851   \null\hfill\{<al-encoding>\}\{<al-family>\}\{<al-series>\}\{<al-shape>\}]
4852 %<*en>
4853 This command sets the ``accompanied'' alphabetic font family (given by the latter 4~arguments)
4854 with respect to a Japanese font family given by the former 4~arguments.
4855 %</en>
4856 %<*ja>
4857 いわゆる「従属欧文」を設定するための命令である.前半の4引数で表される和文フォントファミリに対して,
4858 そのフォントに対応する「従属欧文」のフォントファミリを後半の4引数により与える.
4859 %</ja>
4860 \item[SetRelationFont]
4861 %<*en>
4862 This command is almost same as \verb+\DeclareRelationFont+, except that this command does a local
4863 assignment, where \verb+\DeclareRelationFont+ does a global assignment.
4864 %</en>
4865 %<*ja>
4866 このコマンドは \verb+\DeclareRelationFont+ とローカルな指定であることを除いて
4867 ほとんど同じである(\verb+\DeclareRelationFont+ はグローバル).
4868 %</ja>
4869
4870 \item[userelfont]
4871 %<*en>
4872 Change current alphabetic font encoding/family/\dots\ to the `accompanied' alphabetic
4873              font family with respect to current Japanese font family,
4874              which was set by
4875              \verb+\DeclareRelationFont+ or \verb+\SetRelationFont+.
4876 Like \verb+\fontfamily+, \verb+\selectfont+ is required to take an effect.
4877 %</en>
4878 %<*ja>
4879 現在の欧文フォントのエンコーディング/ファミリ/…… を,
4880 \verb+\DeclareRelationFont+ か \verb+\SetRelationFont+ で指定された
4881 現在の和文フォントファミリに対応する「従属欧文」フォントファミリに変更する.
4882 \verb+\fontfamily+ のように,有効にするためには \verb+\selectfont+ が必要である.
4883 %</ja>
4884
4885 \item[adjustbaseline]
4886 %<*en>
4887 In \pLaTeXe, \verb+\adjustbaseline+ sets \verb+\tbaselineshift+ 
4888 to match the vertical center of ``M'' and that of ``あ''  in vertical typesetting:
4889 \[
4890 \text{\ttfamily \textbackslash tbaselineshift} \leftarrow 
4891 \frac{(h_{\text{M}}+d_{\text{M}}) - (h_{\text{あ}}+d_{\text{あ}})}2
4892   + d_{\text{あ}} - d_{\text{M}},
4893 \]
4894 where $h_{a}$~and~$d_{a}$ denote the height of ``$a$'' and the depth, respectively.
4895 In \LuaTeX-ja, this \verb+\adjustbaseline+ does same task.
4896 %</en>
4897 %<*ja>
4898 \pLaTeXe では,\verb+\adjustbaseline+ は縦書時に「M」と「あ」の中心線を一致させるために,
4899 \verb+\tbaselineshift+ を設定する役割を持っていた:
4900 \[
4901 \text{\ttfamily \textbackslash tbaselineshift} \leftarrow 
4902 \frac{(h_{\text{M}}+d_{\text{M}}) - (h_{\text{あ}}+d_{\text{あ}})}2
4903   + d_{\text{あ}} - d_{\text{M}},
4904 \]
4905 ここで,$h_{a}$,~$d_{a}$はそれぞれ「$a$」の高さ・深さを表す.
4906 \LuaTeX-jaにおいても\verb+\adjustbaseline+ は同様の処理を行っている.
4907 %</ja>
4908
4909 \item[fontfamily\{<family>\}]
4910 %<*en>
4911 As in \LaTeXe, this command changes current font family (alphabetic, Japanese,~\emph{or both})
4912 to <family>. Which family will be changed is determined as follows:
4913 %</en>
4914 %<*ja>
4915 元々の\LaTeXe におけるものと同様に,このコマンドは現在のフォントファミリ(欧文,
4916 和文,\emph{もしくは両方})を<family>に変更する.
4917 どのファミリが変更されるかは以下のようにして決定される:
4918 %</ja>
4919 {\let\item\origitem
4920 %<en>\advance\linewidth-2em
4921 %<ja>\advance\linewidth-2\zw
4922 \vspace{-\medskipamount}
4923 \begin{itemize}
4924 %<*en>
4925 \item Let current encoding scheme for Japanese fonts be
4926       <ja-enc>. Current Japanese font family will be changed to
4927       <family>, if one of the following two conditions is met:
4928 %</en>
4929 %<*ja>
4930 \item 現在の和文フォントに対するエンコーディングが<ja-enc>であるとしよう.
4931   現在の和文フォントファミリは,以下の2つの条件のうちの1つが満たされているときに
4932   <family>に変更される:
4933 %</ja>
4934 \begin{itemize}
4935 %<*en>
4936 \item The family <family> under the encoding <ja-enc> has been already defined by
4937       \verb+\DeclareKanijFamily+.
4938 %</en>
4939 %<*ja>
4940 \item エンコーディング<ja-enc>におけるファミリ<family>が
4941 既に \verb+\DeclareKanjiFamily+ によって定義されている.
4942 %</ja>
4943 %<*en>
4944 \item A font definition named \texttt{<ja-enc><family>.fd} (the file name is
4945       all lowercase) exists.
4946 %</en>
4947 %<*ja>
4948 \item フォント定義ファイル\texttt{<ja-enc><family>.fd}(ファイル名は全て小文字)が存在する.
4949 %</ja>
4950 \end{itemize}
4951 %<*en>
4952 \item Let current encoding scheme for alphabetic fonts be
4953       <al-enc>. For alphabetic font family, the criterion as above is used.
4954 %</en>
4955 %<*ja>
4956 \item 現在の欧文フォントに対するエンコーディングを<al-enc>とする.
4957   欧文フォントファミリに対しても,上記の基準が用いられる.
4958 %</ja>
4959 %<*en>
4960 \item There is a case which none of the above applies, that is, the font
4961       family named <family> doesn't seem to be defined neither under the
4962       encoding <ja-enc>, nor under <al-enc>.
4963 In this case, the default family for font substitution is used for
4964       alphabetic and Japanese fonts. Note that current encoding will not
4965       be set to <family>, unlike the original implementation in \LaTeX.
4966 %</en>
4967 %<*ja>
4968 \item 上記のいずれもが適用されない,つまり<family>が<ja-enc>と<al-enc>の
4969   どちらでも定義されないような場合がある.
4970   この場合,代替フォントに用いられるデフォルトのフォントファミリが欧文フォントと
4971   和文フォントに用いられる.\LaTeX のオリジナルの実装とは異なり,
4972   現在のエンコーディングは<family>には設定されないことに注意する.
4973 %</ja>
4974 \end{itemize}%
4975 %<en>\vspace{-\medskipamount}
4976 }
4977
4978 \item[DeclareAlternateKanjiFont\{<base-encoding>\}\{<base-family>\}\{<base-series>\}\{<base-shape>\}\\
4979   \null\hfill\{<alt-encoding>\}\{<alt-family>\}\{<alt-series>\}\{<alt-shape>\}\{<range>\}]
4980 %<*ja>
4981 \ref{ssec-altfont}節の\
4982 \verb+\ltjdeclarealtfont+ と同様に,前半の4引数の
4983 和文フォント(基底フォント)のうち<range>中の文字を
4984 第5--第8引数の和文フォントを使って組むように指示する.
4985 使用例を図\nobreak\ref{fig:altkanji}に載せた.
4986
4987 {\let\item\origitem
4988 %<en>\advance\linewidth-2em
4989 %<ja>\advance\linewidth-2\zw
4990 \vspace{-\medskipamount}
4991 \begin{itemize}
4992  \item 
4993 \verb+\ltjdeclarealtfont+ では基底フォント・置き換え先和文フォントはあらかじめ定義されてい
4994              ないといけない(その代わり即時発効)であったが,
4995 \verb+\DeclareAlternateKanjiFont+ の設定が
4996 実際に効力が発揮するのは,書体変更やサイズ変更を行った時,
4997 あるいは(これらを含むが)\verb+\selectfont+ が実行された時である.
4998  \item 
4999 段落やhboxの最後での設定値が段落/hbox全体にわたって通用する点や,
5000 <range>に負数$-n$を指定した場合,それが「基底フォントの文字クラス$n$に属する文字全体」
5001 と解釈されるのは \verb+\ltjdeclarealtfont+ と同じである.
5002 \end{itemize}%
5003 }
5004 %</ja>
5005 %<*en>
5006 As \verb+\ltjdeclarealtfont+~(Subsection~\ref{ssec-altfont}), 
5007 characters in <range> of the Japanese font (we say the \emph{base font})
5008 which specified by first 4 arguments are typeset 
5009 by the Japanese font which specified by fifth to eighth arguments
5010 (we say the \emph{alternate font}).
5011 An example is shown in Figure~\ref{fig:altkanji}.
5012
5013 {\let\item\origitem
5014 %<en>\advance\linewidth-2em
5015 %<ja>\advance\linewidth-2\zw
5016 \vspace{-\medskipamount}
5017 \begin{itemize}
5018  \item 
5019 In \verb+\ltjdeclarealtfont+, the base font and the alternate font must be already defined.
5020 But this \verb+\DeclareAlternateKanjiFont+ is not so.
5021 In other words, \verb+\DeclareAlternateKanjiFont+ is effective only after
5022 current Japanese font is changed, or only after \verb+\selectfont+ is executed.
5023  \item \dots
5024 \end{itemize}%
5025 \vspace{-\medskipamount}
5026 }
5027 %</en>
5028 \end{cslist}
5029
5030 %<*en>
5031 As closing this subsection, we shall introduce an example of
5032 \verb+\SetRelationFont+ and \verb+\userelfont+:
5033 %</en>
5034 %<*ja>
5035 この節の終わりに,\verb+\SetRelationFont+ と \verb+\userelfont+ の例を
5036 紹介しておこう.\verb+\userelfont+ の使用によって,「abc」の部分のフォントが
5037 Avant Garde (OT1/pag/m/n) に変わっていることがわかる.
5038 %</ja>
5039 \begin{LTXexample}[width=0.3\textwidth]
5040 \makeatletter
5041 \SetRelationFont{JY3}{\k@family}{m}{n}{OT1}{pag}{m}{n}
5042   % \k@family: current Japanese font family
5043 \userelfont\selectfont あいうabc
5044 \end{LTXexample}
5045
5046 %<*en>
5047 \section{Addons}
5048 \LuaTeX-ja has several addon packages. 
5049 These addons are written as \LaTeX\ packages, but 
5050 \Pkg{luatexja-otf} and~\Pkg{luatexja-adjust} can be loaded in plain \LuaTeX\
5051 by \verb+\input+.
5052 %</en>
5053 %<*ja>
5054 \section{拡張}
5055 \LuaTeX-jaには(動作には必須ではないが)自由に読み込める拡張が付属している.
5056 これらは\LaTeX のパッケージとして制作しているが,
5057 \Pkg{luatexja-otf}と\Pkg{luatexja-adjust}についてはplain \LuaTeX でも\ 
5058 \verb+\input+ で読み込み可能である.
5059 %</ja>
5060 \subsection{\texttt{luatexja-fontspec.sty}}
5061 \label{ssec-fontspec2}
5062 %<*en>
5063 As described in Subsection~\ref{ssec-fontspec}, this optional package
5064 provides the counterparts for several commands defined in the
5065 \Pkg{fontspec} package.
5066 In addition to OpenType font features in the original \Pkg{fontspec},
5067 the following ``font features'' specifications are allowed for
5068 the commands of Japanese version:
5069 %</en>
5070 %<*ja>
5071 \ref{ssec-fontspec}節で述べたように,この追加パッケージは\Pkg{fontspec}
5072 パッケージで定義されているコマンドに対応する和文フォント用のコマンドを提供する.
5073 \Pkg{fontspec}パッケージで指定可能な各種font featureに加えて,和文版のコマンドには
5074 以下の``font feature''を指定することができる:
5075 %</ja>
5076
5077
5078 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}\advance\leftmargin1\zw}
5079 \item[CID=<name>]
5080 \item[JFM=<name>]
5081 \item[JFM-var=<name>] \
5082
5083 %<*en>
5084 These 3 keys correspond to \texttt{cid}, \texttt{jfm} and
5085 \texttt{jfmvar} keys for \verb+\jfont+ respectively.
5086 \texttt{CID} is effective only when with \texttt{NoEmbed}
5087 described below.
5088 See Subsections~\ref{ssec-jfont} and \ref{ssec-psft} for details.
5089 %</en>
5090 %<*ja>
5091 これら3つのキーはそれぞれ \verb+\jfont+ に対する
5092 \texttt{cid}, \texttt{jfm}, \texttt{jfmvar}キーとそれぞれ対応する.
5093 \texttt{CID} は下の \texttt{NoEmbed} と合わせて用いられたときのみ有効である.
5094 \verb+\jfont+ プリミティブに対する
5095 \texttt{cid}, \texttt{jfm}, \texttt{jfmvar}キーの詳細は\ref{ssec-jfont}節
5096              と\ref{ssec-psft}節を参照.
5097 %</ja>
5098
5099 \item[NoEmbed]
5100 %<*en>
5101 By specifying this key, one can use ``name-only'' Japanese font which
5102 will not be embedded in the output PDF file. See Subsection~\ref{ssec-psft}.
5103 %</en>
5104 %<*ja>
5105 これを指定することで,PDFに埋め込まれない「名前だけ」のフォントを指定することが
5106 できる.\ref{ssec-psft}節を参照.
5107 %</ja>
5108
5109
5110 \begin{figure}[!tb]
5111 \begin{LTXexample}[pos=b]
5112 \jfontspec[
5113   AltFont={
5114     {Range="4E00-"67FF, Color=007F00},
5115     {Range="6800-"9EFF, Color=0000FF},
5116     {Range="3040-"306F, Font=KozGoPr6N-Regular},
5117   }
5118 ]{KozMinPr6N-Regular}
5119 日本国民は、正当に選挙された国会における代表者を通じて行動し、われらとわれらの子孫のために、
5120 諸国民との協和による成果と、わが国全土にわたつて自由のもたらす恵沢を確保し、……
5121 \end{LTXexample}
5122 %<ja>\caption{\texttt{AltFont} の使用例}
5123 %<en>\caption{An example of \texttt{AltFont}}
5124 \label{fig:altkanji-fontspec}
5125 \end{figure}
5126
5127 \item[AltFont]\ 
5128
5129 %<*en>
5130 As \verb+\ltjdeclarealtfont+~(Subsection~\ref{ssec-altfont}) and
5131 \verb+\DeclareAlternateKanjiFont+~(Subsection~\ref{ssec-nfsspat}),
5132 with this key, one can typeset some Japanese characters 
5133 by a different font and/or using different features.
5134 The \texttt{AltFont} feature takes a comma-separated list of comma-separated lists,
5135 as the following:
5136 %</en>
5137 %<*ja>
5138 \ref{ssec-altfont}節の \verb+\ltjdeclarealtfont+ や,
5139 \ref{ssec-nfsspat}節の \verb+\DeclareAlternateKanjiFont+ と同様に,
5140 このキーを用いると一部の文字を異なったフォントやfont featureを使って組むことができる.
5141 \texttt{AltFont} に指定する値は,次のように二重のコンマ区切りリストである:
5142 %</ja>
5143 \begin{lstlisting}[escapechar=\#]
5144 AltFont = {
5145   ...
5146   { Range=#\LARG range>#, #\LARG features>#},
5147   { Range=#\LARG range>#, Font=#\LARG font~name>#, #\LARG features># },
5148   { Range=#\LARG range>#, Font=#\LARG font~name># },
5149   ...
5150 }
5151 \end{lstlisting}
5152 %<*en>
5153 Each sublist should have the \texttt{Range} key
5154 (sublist which does not contain \texttt{Range} key is simply ignored).
5155 A demonstrartion is shown in Figure~\ref{fig:altkanji-fontspec}.
5156 %</en>
5157 %<*ja>
5158 各部分リストには \texttt{Range} キーが必須である(含まれない部分リストは
5159 単純に無視される).
5160 指定例は図\ref{fig:altkanji-fontspec}に示した.
5161 %</ja>
5162 \end{list}
5163
5164 %<*ja>
5165 なお,\Pkg{luatexja-fontspec} 読み込み時には和文フォント定義ファイル%
5166 \texttt{<ja-enc><family>.fd}は全く参照されなくなる.
5167 %</ja>
5168
5169
5170 \subsection{\texttt{luatexja-otf.sty}}
5171 \label{ssec-ltjotf}
5172 %<*en>
5173 This optional package supports typesetting characters in
5174 Adobe-Japan1 character collection 
5175 (or other CID character collecton, if the font is supported). 
5176 The package \Pkg{luatexja-otf} offers the following 2~low-level
5177 commands:
5178 %</en>
5179 %<*ja>
5180 この追加パッケージはAdobe-Japan1(フォント自身が持っていれば,
5181 別のCID文字セットでも可)の文字の出力をサポートする.
5182 \Pkg{luatexja-otf}は以下の2つの低レベルコマンドを提供する:
5183 %</ja>
5184 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}\advance\leftmargin1\zw}
5185 \item[\textbackslash CID\{<number>\}]
5186 %<*en>
5187 Typeset a character whose CID number is <number>.
5188 %</en>
5189 %<*ja>
5190 CID番号が<number>の文字を出力する.
5191 %</ja>
5192
5193 \item[\textbackslash UTF\{<hex\_number>\}]
5194 %<*en>
5195 Typeset a character whose character code is <hex\_number> (in hexadecimal).
5196 This command is similar to \verb+\char"+<hex\_number>,\ %"
5197 but please remind remarks below.
5198 %</en>
5199 %<*ja>
5200 文字コードが(16進で)<hex\_number>の文字を出力する.
5201 このコマンドは \verb+\char"+<hex\_number>と似ているが,下の記述に注意すること.%"
5202 %</ja>
5203 \end{list}
5204
5205 %<*ja>
5206 このパッケージは,\texttt{ajmacros.sty}(\Pkg{otf}パッケージ付属のマクロ集,井上浩一氏作)から
5207 漢字コードをUTF8にしたり,plain \LuaTeX でも利用可能するという
5208 修正を加えた \texttt{luatexja-ajmacros.sty} も自動的に読み込む.
5209 そのため,マクロ集にある \verb+\aj半角+ などのマクロもそのまま使用可能である.
5210 %</ja>
5211
5212 %<en>\paragraph{Remarks}
5213 %<ja>\paragraph{注意}
5214 %<*en>
5215 Characters by \verb+\CID+ and \verb+\UTF+ commands are different from
5216 ordinary characters in the following points:
5217 %</en>
5218 %<*ja>
5219 \verb+\CID+ と \verb+\UTF+ コマンドによって出力される文字は
5220 以下の点で通常の文字と異なる:
5221 %</ja>
5222 \begin{itemize}
5223 %<*en>
5224 \item Always treated as \textbf{JAchar}s.
5225 %</en>
5226 %<*ja>
5227 \item 常に\textbf{JAchar}として扱われる.
5228 %</ja>
5229 %<*en>
5230 \item Processing codes for supporting OpenType features (\textit{e.g.},
5231       glyph replacement and kerning) by the \Pkg{luaotfload} package
5232       is not performed to these characters.
5233 %</en>
5234 %<*ja>
5235 \item OpenType feature(例えばグリフ置換やカーニング)をサポートするための
5236   \Pkg{luaotfload}パッケージのコードはこれらの文字には働かない.
5237 %</ja>
5238 \end{itemize}
5239
5240 %<en>\paragraph{Additional syntax of JFM}
5241 %<ja>\paragraph{JFMへの記法の追加}
5242
5243 %<*en>
5244 The package \Pkg{luatexja-otf} extends the syntax of JFM; the entries of \texttt{
5245 chars} table in JFM now allows a string in the form
5246 \verb+'AJ1-xxx'+, which stands for the character
5247 whose CID number in Adobe-Japan1 is \verb+xxx+.
5248
5249 This extened notation is used in the standard JFM \texttt{jfm-ujis.lua}
5250 to typeset halfwidth Hiragana glyphs (CID~516--598) in halfwidth.
5251 %</en>
5252 %<*ja>
5253 \Pkg{luatexja-otf}パッケージを読み込むと,
5254 JFMの\texttt{chars}テーブルのエントリとして \verb+'AJ1-xxx'+ の形の文字列が
5255 使えるようになる.これはAdobe-Japan1におけるCID番号が \verb+xxx+ の文字を表す.
5256
5257 この拡張記法は,標準JFM~\texttt{jfm-ujis.lua}で,半角ひらがなのグリフ(CID~516--598)を
5258 正しく半角幅で組むために利用されている.
5259 %</ja>
5260
5261 %<*en>
5262 \paragraph{IVS support}
5263 Recent fonts support Ideographic Variation Selector (IVS).
5264 It seems that \Pkg{luaotfload} and \Pkg{fontspec} packages do not support
5265 IVS, so we implemented IVS support in \Pkg{luatexja-otf}.
5266 \emph{IVS support is experimental; if you want to enable this, load
5267 \Pkg{luatexja-otf} and execute the following:}
5268 %</en>
5269 %<*ja>
5270 \paragraph{IVSサポート}
5271 最近のOpenTypeフォントやTrueTypeフォントには,
5272 \texttt{U+E0100}--\texttt{U+E01EF}の範囲の「文字」
5273 (漢字用異体字セレクタ)を後置することによって
5274 字形を指定する仕組み(IVS)が含まれている.
5275 執筆時点の2013年12月では,\Pkg{luaotfload}や\Pkg{fontspec}パッケージ類は
5276 IVSに対応してはいないようである.これらのパッケージで対応してくれるのが理想的だが,
5277 それまでのつなぎとして,\Pkg{luatexja-otf}パッケージ内にIVS対応を仕込んでおいた.
5278
5279 \medskip
5280
5281 \emph{IVS対応は試験的なものである.
5282 有効にするには,\Pkg{luatexja-otf}パッケージを読み込んだ上で以下の命令を実行する%
5283 \footnote{この命令を2回以上実行しても意味がない.}:}
5284 %</ja>
5285 \begin{verbatim}
5286 \directlua{luatexja.otf.enable_ivs()}
5287 \end{verbatim}
5288 %<ja> すると,上の命令を実行した箇所以降では,以下のようにIVSによる字形指定が有効となる.
5289 %<en> After executing the command above, you can use IVS like the following:
5290 \begin{LTXexample}
5291 \Large
5292 \jfontspec{KozMinPr6N-Regular}
5293 奈良県葛󠄀城市と,東京都葛󠄁飾区.\\
5294 こんにちは,渡
5295 邉󠄀邉󠄁邉󠄂邉󠄃邉󠄄
5296 邉󠄅邉󠄆邉󠄇邉󠄈邉󠄉
5297 邉󠄊邉󠄋邉󠄌邉󠄍邉󠄎
5298 さん.
5299 \end{LTXexample}
5300 %<*ja>
5301 左上側の入力においては,漢字用異体字セレクタを明示するため,
5302 例えばVariation~Selector~18 (\texttt{U+E0101})を\IVSB{18}のように表記している.
5303 %</ja>
5304 \medskip
5305
5306 %<*en>
5307 Specifying glyph variants by IVS precedes glyph replacement by font features.
5308 For example, only ``葛'' in ``葛西'' is changed by font features
5309 \texttt{jp78}~or~\texttt{jp90}, which does not followed by any variation selector.
5310 %</en>
5311 %<*ja>
5312 また,IVSによる字形指定は,font featureによるそれに優先されることとした.
5313 下の例において,\texttt{jp78}, \texttt{jp90} 指定で字形が変化した文字は
5314 異体字セレクタが続いていない「葛西」中の「葛」のみである.
5315 %</ja>
5316 \begin{LTXexample}
5317  \def\TEST#1{%
5318    {\jfontspec[#1]{KozMinPr6N-Regular}%
5319    葛󠄀城市,葛󠄁飾区,葛西}\\}
5320  指定なし:\TEST{}
5321  \texttt{jp78}:\TEST{CJKShape=JIS1978}
5322  \texttt{jp90}:\TEST{CJKShape=JIS1990}
5323 \end{LTXexample}
5324
5325 %<*ja>
5326 現状では,\TeX 側のインターフェースとなる \Pkg{luatexja-otf.sty} は一切変更していない
5327 ので,ZRさんによる\Pkg{PXipamjm}パッケージ%
5328 \footnote{\url{https://github.com/zr-tex8r/PXipamjm}. 説明は彼のブログ記事
5329 「pxipamjm パッケージの説明書のような何か(\url{http://d.hatena.ne.jp/zrbabbler/20131221})」
5330 にある.}
5331 にあるような気の利いた命令はまだない.
5332 異体字の一覧表示を行いたい場合は,gitリポジトリ内の \texttt{test/test19-ivs.tex} 中にある
5333 Lua・\TeX コードが参考になるだろう.
5334 %</ja>
5335
5336
5337 \subsection{\texttt{luatexja-adjust.sty}}
5338 \label{ssec-adj}
5339 \begin{figure}[t]
5340 \def\sq{%
5341   \hbox to 1\zw{\hss\fboxsep=-.5\fboxrule\fbox{%
5342    \hskip\dimexpr-.5\zw-.2pt\vrule width.4pt height.08\zw depth.12\zw%
5343   \hskip\dimexpr.5\zw-.2pt\relax}\hss}}
5344 \def\sb{\hbox to 1\zw{\hss\fboxsep=-.5\fboxrule\fbox{%
5345   ■\hskip\dimexpr-.5\zw-.2pt\vrule width.4pt height.08\zw depth.12\zw%
5346   \hskip\dimexpr.5\zw-.2pt\relax}\hss}}
5347 \newbox\gridbox
5348 \def\outbox#1{{\Large%
5349   \ltjsetparameter{kanjiskip=0pt plus .2\zw minus .2\zw}%
5350   \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}%
5351   \hbox{\textcolor{cyan!50!white}{\copy\gridbox}\hskip-20\zw%
5352   \vbox{\hsize=20\zw\noindent\leftskip0pt\rightskip0pt\parfillskip0pt#1}\vrule}%
5353 }}
5354
5355 {\centering
5356 \begin{tabular}{lc}
5357 \toprule
5358 no adjustment&\outbox{以上の原理は,「包除原理」とよく呼ばれるが\hskip-.5\zw\null}\\
5359 without priority&%
5360 \ltjdisableadjust
5361 \outbox{以上の原理は,「包除原理」とよく呼ばれるが}%
5362 \ltjenableadjust\\
5363 with priority&%
5364 \outbox{以上の原理は,「包除原理」とよく呼ばれるが}
5365 %<en>\ltjdisableadjust
5366 \\
5367 \bottomrule
5368 \end{tabular}\par}
5369 \smallskip
5370
5371 Note: the value of 
5372 \Param{\hyperlink{fld:kanjiskip}{kanjiskip}} is 0\,pt${}^{+1/5\,\mathrm{em}}_{-1/5\,\mathrm{em}}$ in this figure,
5373 for making the difference obvious.
5374 %<ja>\caption{行長調整}\label{fig-adj}
5375 %<en>\caption{Line adjustment}\label{fig-adj}
5376 \end{figure}
5377
5378
5379 %<*en>
5380 (see Japanese version of this manual)
5381 %</en>
5382 %<*ja>
5383 \pTeX では,行長調整において優先度の概念が存在しなかったため,図
5384 \ref{fig-adj}上段における半角分の半端は,図\ref{fig-adj}中段のように,鍵
5385 括弧周辺の空白と和文間空白(\Param{\hyperlink{fld:kanjiskip}{kanjiskip}})の両方によって負担される.し
5386 かし,「日本語組版処理の要件」\cite{jlreq}やJIS~X~4051~\cite{x4051}におい
5387 ては,このような状況では半端は鍵括弧周辺の空白のみで負担し,その他の和文
5388 文字はベタ組で組まれる(図\ref{fig-adj}下段)ことになっている.この追加
5389 パッケージは\cite{jlreq}や\cite{x4051}における規定のような,優先順位付き
5390 の行長調整を提供する.詳細な仕様については\ref{sec-adjspec}章を参照してほしい.
5391 \begin{itemize}
5392  \item 優先度付き行長調整は,段落を行分割した後に個々の行について行われるものである.
5393 そのため,行分割の位置は変化することはない.
5394
5395 また,\verb+\hbox to ... {...}+ のような「幅が指定されたhbox」では無効である.
5396  \item 優先度付き行長調整を行うと,和文処理グルーの自然長は変化しないが,伸び量や縮み量は
5397 一般に変化する.そのため,既に組まれた段落を \verb+\unhbox+ などを利用して組み直す処理を
5398 行う場合には注意が必要である.
5399 \end{itemize}
5400
5401
5402 \Pkg{luatexja-adjust} は,以下の命令を提供する.これらはすべてグローバルに効力を発揮する.
5403
5404 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}\advance\leftmargin1\zw}
5405 \item[\textbackslash ltjdisableadjust]
5406 優先順位付きの行長調整を無効化する.
5407
5408 \item[\textbackslash ltjenableadjust]
5409 優先順位付きの行長調整を有効化する.
5410
5411 \item[\textsf{adjust}\,=<bool>] \verb+\ltjsetparameter+ で指定可能な追加パラメータであり,
5412 <bool>が\textit{true}なら \verb+\ltjenableadjust+ を,
5413 そうでなければ \verb+\ltjdisableadjust+ を実行する.
5414 \end{list}
5415 %</ja>
5416
5417 \subsection{\texttt{luatexja-ruby.sty}}
5418 %<*en>
5419 This addon package provides functionality of ``ruby'' (\emph{furigana}) annotations 
5420 using callbacks of \LuaTeX-ja. 
5421 There is no detailed manual of \Pkg{luatexja-ruby.sty} in English.
5422 (Japanese manual is another PDF file, \url{luatexja-ruby.pdf}.) 
5423 %</en>
5424 %<*ja>
5425 この追加パッケージは,\LuaTeX-jaの機能を利用したルビ(振り仮名)の組版機能を提供する.
5426 前後の文字種に応じた前後への自動進入や,
5427 行頭形・行中形・行末形の自動的な使い分けが特徴である.
5428
5429 ルビ組版に設定可能な項目や注意事項が多いため,本追加パッケージの詳細な説明は
5430 使用例と共に \url{luatexja-ruby.pdf}\ という別ファイルに載せている.
5431 この節では簡単な使用方法のみ述べる.
5432 %</ja>
5433
5434 \begin{description}
5435 %<*en>
5436  \item[Group-ruby]
5437 By default, ruby characters (the second argument of \verb+\ruby+)
5438 are attached to base characters (the first argument), as one object.
5439 This type of ruby is called \emph{group-ruby}.
5440 %</en>
5441 %<*ja>
5442  \item[グループルビ] 標準ではグループルビの形で組まれる.第1引数に親文字,
5443 第2引数にルビを記述する.
5444 %</ja>
5445 \begin{LTXexample}[width=0.3\textwidth]
5446 東西線\ruby{妙典}{みようでん}駅は……\\
5447 東西線の\ruby{妙典}{みようでん}駅は……\\
5448 東西線の\ruby{妙典}{みようでん}という駅……\\
5449 東西線\ruby{葛西}{かさい}駅は……
5450 \end{LTXexample}
5451 %<*en> 
5452 As the above example, ruby hangover is allowed on the Hiragana before/after 
5453 its base characters.
5454 %</en>
5455 %<ja> この例のように,標準では前後の平仮名にルビ全角までかかるようになっている.
5456
5457 %<*en>
5458 \item[Mono-ruby]
5459 To attach ruby characters to each base characters (\emph{mono-ruby}),
5460 one should use \verb+\ruby+ multiple times:
5461 %</en>
5462 %<*ja>
5463  \item[モノルビ] 親文字を1文字にするとモノルビとなる.
5464 2文字以上の熟語をモノルビの形で組みたい場合は,面倒でも
5465 その数だけ \verb+\ruby+ を書く必要がある.
5466 %</ja>
5467 \begin{LTXexample}[width=0.3\textwidth]
5468 東西線の\ruby{妙}{みよう}\ruby{典}{でん}駅は……
5469 \end{LTXexample}
5470
5471 %<*en>
5472  \item[Jukugo-ruby]
5473 Vertical bar~\verb+|+ denotes a boundary of \emph{groups}.
5474 %</en>
5475 %<*ja>
5476  \item[熟語ルビ] 引数内の縦棒 \verb+|+ はグループの区切りを表し,
5477 複数グループのルビは熟語ルビとして組まれる.
5478 \cite{x4051}にあるように,
5479 どのグループでも「親文字」が対応するルビ以上の長さの場合は
5480 各グループごとに,そうでないときは全体をまとめて1つのグループルビとして組まれる.
5481 \cite{jlreq}で規定されている組み方とは異なるので注意.
5482 %</ja>
5483 \begin{LTXexample}
5484 \ruby{妙|典}{みよう|でん}\
5485 \ruby{葛|西}{か|さい}\
5486 \ruby{神楽|坂}{かぐら|ざか}
5487 \end{LTXexample}
5488 %<*en>
5489 If there are multiple groups in one \verb+\ruby+ call,
5490 A linebreak between two groups is allowed.
5491 %</en>
5492 %<ja> 複数ルビではグループとグループの間で改行が可能である.
5493 \begin{LTXexample}[width=0.3\textwidth]
5494 \vbox{\hsize=6\zw\noindent
5495   \hbox to 2.5\zw{}\ruby{京|急|蒲|田}{けい|きゆう|かま|た}
5496   \hbox to 2.5\zw{}\ruby{京|急|蒲|田}{けい|きゆう|かま|た}
5497   \hbox to   3\zw{}\ruby{京|急|蒲|田}{けい|きゆう|かま|た}
5498 }
5499 \end{LTXexample}
5500 \end{description}
5501
5502 %<*en>
5503 If the width of ruby characters are longer than that of base characters,
5504 \verb+\ruby+ automatically selects the appropriate form
5505 among the line-head form, the line-middle form, and the line-end form.
5506 %</en>
5507 %<*ja>
5508 また,ルビ文字のほうが親文字よりも長い場合は,自動的に
5509 行頭形・行中形・行末形のいずれか適切なものを選択する.
5510 %</ja>
5511 \begin{LTXexample}[width=0.3\textwidth]
5512 \vbox{\hsize=8\zw\noindent
5513 \null\kern3\zw ……を\ruby{承}{うけたまわ}る
5514      \kern1\zw ……を\ruby{承}{うけたまわ}る\\
5515 \null\kern5\zw ……を\ruby{承}{うけたまわ}る
5516 }
5517 \end{LTXexample}
5518
5519
5520
5521
5522
5523
5524 %<en>\part{Implementations}
5525 %<ja>\part{実装}
5526 \label{part-imp}
5527 %<en>\section{Storing Parameters}
5528 %<ja>\section{パラメータの保持}
5529 \label{sec-para}
5530 %<en>\subsection{Used Dimensions, Attributes and Whatsit Nodes}
5531 %<ja>\subsection{\LuaTeX-jaで用いられるレジスタとwhatsitノード}
5532
5533 %<*en>
5534 Here the following is the list of dimensions and attributes which are used in \LuaTeX-ja.
5535 %</en>
5536 %<*ja>
5537 以下は\LuaTeX-jaで用いられる寸法レジスタ(dimension),属性レジスタ(attribute)の
5538 リストである.
5539 %</ja>
5540 \begin{list}{}{%
5541 \def\makelabel{\ttfamily}\advance\leftmargin1\zw
5542 \def\dim#1{\item[\textbackslash #1\ \textrm{(dimension)}]}
5543 \def\cnt#1{\item[\textbackslash #1\ \textrm{(counter)}]}
5544 \def\attr#1{\item[\textbackslash #1\ \textrm{(attribute)}]}
5545 }
5546
5547 \dim{jQ}
5548 %<*en>
5549 \verb+\jQ+ is equal to
5550                         $1\,\textrm{Q}=0.25\,\textrm{mm}$, where ``Q''~(also called ``級'') is
5551                         a unit used in Japanese phototypesetting. 
5552 So one should not change the value of this dimension.
5553 %</en>
5554 %<*ja>
5555 \verb+\jQ+ は写植で用いられた$1\,\textrm{Q}=0.25\,\textrm{mm}$%
5556 (「級」とも書かれる)に等しい.したがって,
5557 この寸法レジスタの値を変更してはならない.
5558 %</ja>
5559
5560 \dim{jH}
5561 %<*en>
5562 There is also a unit called ``歯'' which equals to $0.25\,\textrm{mm}$ and
5563                          used in Japanese phototypesetting. 
5564 This \verb+\jH+ is the same \verb+\dimen+ register as \verb+\jQ+.
5565 %</en>
5566 %<*ja>
5567 同じく写植で用いられていた単位として「歯」があり,これも$0.25\,\textrm{mm}$と
5568 等しい.この \verb+\jH+ は \verb+\jQ+ と同じ寸法レジスタを指す.
5569 %</ja>
5570
5571 \dim{ltj@zw}
5572 %<*en>
5573 A temporal register for the ``full-width'' of current Japanese font.
5574 The command \verb+\zw+ sets this register to the correct value, and
5575 ``return'' this register itself.
5576 %</en>
5577 %<*ja>
5578 現在の和文フォントの「全角幅」を保持する一時レジスタ.
5579 \verb+\zw+ 命令は,このレジスタを適切な値に設定した後,
5580 「このレジスタ自体を返す」.
5581 %</ja>
5582
5583 \dim{ltj@zh}
5584 %<*en>
5585 A temporal register for the ``full-height'' (usually the sum of height of imaginary body and its depth) of current Japanese font.
5586 The command \verb+\zh+ sets this register to the correct value, and
5587 ``return'' this register itself.
5588 %</en>
5589 %<*ja>
5590 現在の和文フォントの「全角高さ」(通常,高さと深さの和)を保持する一時レジスタ.
5591 \verb+\zh+ 命令は,このレジスタを適切な値に設定した後,
5592 「このレジスタ自体を返す」.
5593 %</ja>
5594
5595 \attr{jfam}
5596 %<*en>
5597 Current number of Japanese font family for math formulas.
5598 %</en>
5599 %<*ja>
5600 数式用の和文フォントファミリの現在の番号.
5601 %</ja>
5602
5603 \attr{ltj@curjfnt}
5604 %<*en>
5605 The font index of current Japanese font for horizontal direction.
5606 %</en>
5607 %<*ja>
5608 現在の横組用和文フォントのフォント番号.
5609 %</ja>
5610
5611 \attr{ltj@curtfnt}
5612 %<*en>
5613 The font index of current Japanese font for vertical direction.
5614 %</en>
5615 %<*ja>
5616 現在の縦組用和文フォントのフォント番号.
5617 %</ja>
5618
5619 \attr{ltj@charclass}
5620 %<*en>
5621 The character class of Japanese \textit{glyph\_node}.
5622 %</en>
5623 %<*ja>
5624 和文文字の\textit{glyph\_node}の文字クラス.
5625 %</ja>
5626
5627 \attr{ltj@yablshift}
5628 %<*en>
5629 The amount of shifting the baseline of alphabetic fonts in scaled point ($2^{-16}\,\textrm{pt}$).
5630 %</en>
5631 %<*ja>
5632 スケールド・ポイント($2^{-16}\,\textrm{pt}$)を単位とした欧文フォントのベースラインの移動量.
5633 %</ja>
5634
5635 \attr{ltj@ykblshift}
5636 %<*en>
5637 The amount of shifting the baseline of Japanese fonts in scaled point ($2^{-16}\,\textrm{pt}$).
5638 %</en>
5639 %<*ja>
5640 スケールド・ポイント($2^{-16}\,\textrm{pt}$)を単位とした和文フォントのベースラインの移動量.
5641 %</ja>
5642
5643 \attr{ltj@tablshift}
5644 \attr{ltj@tkblshift}
5645
5646 \attr{ltj@autospc}
5647 %<*en>
5648 Whether the auto insertion of \Param{\hyperlink{fld:kanjiskip}{kanjiskip}} is allowed at the node.
5649 %</en>
5650 %<*ja>
5651 そのノードで\Param{\hyperlink{fld:kanjiskip}{kanjiskip}}の自動挿入が許されるかどうか.
5652 %</ja>
5653
5654 \attr{ltj@autoxspc}
5655 %<*en>
5656 Whether the auto insertion of \Param{\hyperlink{fld:xks}{xkanjiskip}} is allowed at the node.
5657 %</en>
5658 %<*ja>
5659 そのノードで\Param{\hyperlink{fld:xks}{xkanjiskip}}の自動挿入が許されるかどうか.
5660 %</ja>
5661
5662 \attr{ltj@icflag}
5663 %<*en>
5664 An attribute for distinguishing ``kinds'' of a node. One of the following value is
5665 assigned to this attribute:
5666 %</en>
5667 %<*ja>
5668 ノードの「種類」を区別するための属性.以下のうちのひとつが値として割り当てられる:
5669 %</ja>
5670 \begin{description}
5671 \item[\textit{italic} (1)]
5672 %<*en>
5673 Kerns from italic correction (\verb+\/+), or from kerning information of a Japanese font.
5674 These kerns are ``ignored'' in the insertion process of \textbf{JAglue},
5675 unlike explicit \verb+\kern+.
5676 %</en>
5677 %<*ja>
5678 イタリック補正(\verb+\/+)によるカーン,
5679 または \Pkg{luaotfload} によって挿入されたフォントのカーニング情報由来のカーン.
5680 これらのカーンは通常の \verb+\kern+ とは異なり,
5681 \textbf{JAglue}の挿入処理においては透過する.
5682 %</ja>
5683
5684 \item[\textit{packed} (2)]
5685
5686 \item[\textit{kinsoku} (3)]
5687 %<*en>
5688 Penalties inserted for the word-wrapping process (\emph{kinsoku shori}) of Japanese characters.
5689 %</en>
5690 %<ja>禁則処理のために挿入されたペナルティ.
5691 \item[\mathversion{bold}$(\textit{from\_jfm}-2)$--$(\textit{from\_jfm}+2)$~(4--8)]
5692 %<en>Glues/kerns from JFM.
5693 %<ja>JFM由来のグルー/カーン.
5694 \item[\textit{kanji\_skip}~(9), \textit{kanji\_skip\_jfm}~(10)]
5695 %<en>Glues from \Param{\hyperlink{fld:kanjiskip}{kanjiskip}}.
5696 %<ja>和文間空白\Param{\hyperlink{fld:kanjiskip}{kanjiskip}}を表すグルー.
5697 \item[\textit{xkanji\_skip}~(11), \textit{xkanji\_skip\_jfm}~(12)]
5698 %<en>Glues from \Param{\hyperlink{fld:xks}{xkanjiskip}}.
5699 %<ja>和欧文間空白\Param{\hyperlink{fld:xks}{xkanjiskip}}を表すグルー.
5700 \item[\textit{processed} (13)]
5701 %<en>Nodes which is already processed by \ldots.
5702 %<ja>\LuaTeX-ja の内部処理によって既に処理されたノード.
5703 \item[\textit{ic\_processed} (14)]
5704 %<*en>
5705 Glues from an italic correction, but already processed in the insertion process of \textbf{JAglue}s.
5706 %</en>
5707 %<ja>イタリック補正に由来するグルーであって,既に \textbf{JAglue} 挿入処理にかかったもの.
5708 \item[\textit{boxbdd} (15)]
5709 %<en>Glues/kerns that inserted just the beginning or the ending of an hbox or a paragraph.
5710 %<ja>hboxか段落の最初か最後に挿入されたグルー/カーン.
5711 \end{description}
5712
5713 %<*ja>
5714 また,挿入処理の結果であるリストの最初のノードでは,\verb+\ltj@icflag+ の値に
5715 \textit{processed\_begin\_flag}~(128)が追加される.これによって,\verb+\unhbox+ が
5716 連続した場合でも「ボックスの境界」が識別できるようになっている.
5717 %</ja>
5718
5719 \attr{ltj@kcat$i$}
5720 %<*en>
5721 Where $i$~is a natural number which is less than~7.
5722 These 7~attributes store bit~vectors indicating which character block is regarded as a block of \textbf{JAchar}s.
5723 %</en>
5724 %<*ja>
5725 $i$は7より小さい自然数.
5726 これら7つの属性レジスタは,どの文字ブロックが\textbf{JAchar}のブロックとして
5727 扱われるかを示すビットベクトルを格納する.
5728 %</ja>
5729
5730 \cnt{ltj@dir@count}
5731 %<*ja>
5732 現在の組方向を表す.
5733 %</ja>
5734 \begin{description}
5735 \item[\textit{dir\_dtou} (1)]
5736 \item[\textit{dir\_tate} (3)]
5737 \item[\textit{dir\_yoko} (4)]
5738 \end{description}
5739
5740 \attr{ltj@dir}
5741 %<*ja>
5742 ボックスにおける組方向を示す.通常のボックスでは上記の3つの値(1,~3,~4)をとり得るが,
5743 内部処理によりそれらに次を加えた値(17,~19, 20, 33, 35,~36)をとるボックスが作られることもあ
5744                          る(\ref{sec-dir-imp}章参照).
5745 %</ja>
5746 \begin{description}
5747 \item[\textit{dir\_node\_auto} (16)]
5748 %<ja> 異なる組方向に配置するために自動的に作られたボックス.
5749 \item[\textit{dir\_node\_manual} (32)]
5750 %<ja> \verb+\ltjsetwd+ によって「ボックスの本来の組方向とは異なる組方向での寸法」を
5751 %<ja> 設定したときに,それを記録するためのボックス.
5752 \end{description}
5753 %<ja> \TeX 側から見える値,つまり \verb+\the\ltj@dir+ の値は常に0である.
5754
5755 \end{list}
5756
5757 %<*en>
5758 Furthermore, \LuaTeX-ja uses several user-defined whatsit nodes for
5759 inrernal processing. All those nodes except \emph{direction} whatsits 
5760 store a natural number (hence its \texttt{type} is 100). 
5761 \emph{direction} whatsits store a node list, hence its \texttt{type} is 110.
5762 Their \texttt{user\_id} (used for distinguish user-defined whatsits) 
5763 are allocated by \texttt{luatexbase.newuserwhatsitid}.
5764 %</en>
5765 %<*ja>
5766 さらに,\LuaTeX-jaはいくつかのuser-defined whatsit nodeを内部処理に用いる.
5767 \textit{direction} whatsitはノードリストを格納するが,
5768 それ以外のwhatsitノードの \texttt{type} は100であり,ノードは自然数を格納している.
5769 user-defined whatsitを識別するための \texttt{user\_id} は\ 
5770 \texttt{luatexbase.newuserwhatsitid} により確保されており,
5771 下の見出しは単なる識別用でしかない.
5772 %</ja>
5773 \begin{description}
5774 \item[\textit{inhibitglue}]
5775 %<*en>
5776 Nodes for indicating that \verb+\inhibitglue+ is
5777            specified. The \texttt{value} field of these nodes doesn't matter.
5778 %</en>
5779 %<*ja>
5780 \verb+\inhibitglue+ が指定されたことを示すノード.これらのノードの\ 
5781 \texttt{value} フィールドは意味を持たない.
5782 %</ja>
5783
5784 \item[\textit{stack\_marker}]
5785 %<*en>
5786 Nodes for \LuaTeX-ja's stack system (see the next
5787            subsection). The \texttt{value} field of these nodes is
5788            current group level.
5789 %</en>
5790 %<*ja>
5791 \LuaTeX-jaのスタックシステム(次の節を参照)のためのノード.
5792 これらのノードの \texttt{value} フィールドは現在のグループネストレベルを表す.
5793 %</ja>
5794
5795 \item[\textit{char\_by\_cid}]
5796 %<*en>
5797 Nodes for \textbf{JAchar} which the callback process of
5798            \Pkg{luaotfload} won't be applied, and the character code is
5799            stored in the \texttt{value} field. Each node of this type are 
5800            converted to a \textit{glyph\_node} \emph{after}
5801            the callback process of luaotfload.
5802 Nodes of this type is used in \verb+\CID+, \verb+\UTF+ and IVS support.
5803 %</en>
5804 %<*ja>
5805 \Pkg{luaotfload}のコールバックによる処理が適用されない\textbf{JAchar}のためのノードで,
5806 \texttt{value} フィールドに文字コードが格納されている.
5807 この種類のノードはそれぞれが\Pkg{luaotfload}のコールバックの処理の
5808 \emph{後で}\textit{glyph\_node}に変換される.
5809 \verb+\CID+, \verb+\UTF+やIVS対応処理でこの種類のノードが利用されている.
5810 %</ja>
5811
5812 \item[\textit{replace\_vs}]
5813 %<*en>
5814 Similar to \textit{char\_by\_cid} whatsits above.
5815 These nodes are for \textbf{ALchar} which the callback process of
5816            \Pkg{luaotfload} won't be applied.
5817 %</en>
5818 %<*ja>
5819 上の\textit{char\_by\_cid}と同様に,
5820 これらのノードは\Pkg{luaotfload}のコールバックによる処理が適用されない\textbf{ALchar}のた
5821            めものである.
5822 %</ja>
5823
5824 \item[\textit{begin\_par}]
5825 %<*en>
5826 Nodes for indicating beginning of a paragraph.
5827 A paragraph which is started by \verb+\item+ in list-like environments has a horizontal box
5828 for its label before the actual contents. So \dots
5829 %</en>
5830 %<*ja>
5831 「段落の開始」を意味するノード.
5832 list環境,itemize環境などにおいて,\verb+\item+ で始まる各項目は……
5833 %</ja>
5834
5835 \item[\textit{direction}]
5836
5837 \end{description}
5838
5839 %<*en>
5840 These whatsits will be removed during the process of inserting \textbf{JAglue}s.
5841 %</en>
5842 %<*ja>
5843 これらのwhatsitノードは\textbf{JAglue}の挿入処理の間に取り除かれる.
5844 %</ja>
5845
5846 %<en>\subsection{Stack System of \LuaTeX-ja}
5847 %<ja>\subsection{\LuaTeX-jaのスタックシステム}
5848 \label{ssec-stack}
5849
5850 %<en>\paragraph{Background}
5851 %<ja>\paragraph{背景}
5852 %<*en>
5853 \LuaTeX-ja has its own stack system, and most parameters of \LuaTeX-ja
5854 are stored in it. To clarify the reason, imagine the parameter
5855 \Param{\hyperlink{fld:kanjiskip}{kanjiskip}} is stored by a skip, and consider the following
5856 source:
5857 %</en>
5858 %<*ja>
5859 \LuaTeX-jaは独自のスタックシステムを持ち,\LuaTeX-jaのほとんどのパラメータは
5860 これを用いて保持されている.その理由を明らかにするために,
5861 \Param{\hyperlink{fld:kanjiskip}{kanjiskip}}パラメータがスキップレジスタで保持されているとし,
5862 以下のコードを考えてみよう:
5863 %</ja>
5864 \begin{LTXexample}
5865 \ltjsetparameter{kanjiskip=0pt}ふがふが.%
5866 \setbox0=\hbox{%
5867   \ltjsetparameter{kanjiskip=5pt}ほげほげ}
5868 \box0.ぴよぴよ\par
5869 \end{LTXexample}
5870
5871 %<*en>
5872 As described in Subsection~\ref{ssec-param}, the only effective value of
5873 \Param{\hyperlink{fld:kanjiskip}{kanjiskip}} in an hbox is the latest value, so the value of
5874 \Param{\hyperlink{fld:kanjiskip}{kanjiskip}} which applied in the entire hbox should be 5\,pt.
5875 However, by the implementation method of \LuaTeX, this ``5\,pt'' cannot be
5876 known from any callbacks.  In the \texttt{tex/packaging.w}, which is a
5877 file in the source of \LuaTeX, there are the following codes:
5878 %</en>
5879 %<*ja>
5880 \ref{ssec-param}節で述べたように,あるhboxの中で効力を持つ
5881 \Param{\hyperlink{fld:kanjiskip}{kanjiskip}}の値は最後に現れた値のみであり,したがってボックス全体に適用される
5882 \Param{\hyperlink{fld:kanjiskip}{kanjiskip}}は5\,ptであるべきである.しかし,\LuaTeX の実
5883 装を観察すると,この5\,ptという長さはどのコールバックからも知ることはできないことがわかる.
5884 \LuaTeX のソースファイルの1つ \texttt{tex/packaging.w} の中に,
5885 以下のコードがある:
5886 %</ja>
5887 \begin{lstlisting}[numbers=left,firstnumber=1226]
5888 void package(int c)
5889 {
5890     scaled h;                   /* height of box */
5891     halfword p;                 /* first node in a box */
5892     scaled d;                   /* max depth */
5893     int grp;
5894     grp = cur_group;
5895     d = box_max_depth;
5896     unsave();
5897     save_ptr -= 4;
5898     if (cur_list.mode_field == -hmode) {
5899         cur_box = filtered_hpack(cur_list.head_field,
5900                                  cur_list.tail_field, saved_value(1),
5901                                  saved_level(1), grp, saved_level(2));
5902         subtype(cur_box) = HLIST_SUBTYPE_HBOX;
5903 \end{lstlisting}
5904 %<*en>
5905 Notice that \texttt{unsave()} is executed \emph{before}
5906 \texttt{filtered\_hpack()}, where \texttt{hpack\_filter} callback is
5907 executed) here. So ``5\,pt'' in the above source is orphaned at
5908 \texttt{unsave()}, and hence it can't be accessed from \texttt{hpack\_filter}
5909 callback.
5910 %</en>
5911 %<*ja>
5912 \texttt{unsave()} が \texttt{filtered\_hpack()}(これは \texttt{hpack\_filter} コールバックが
5913 実行されるところである)の\emph{前に}実行されていることに注意する.
5914 したがって,上記ソース中で5\,ptは \texttt{unsave()} のところで捨てられ,
5915 \texttt{hpack\_filter} コールバックからはアクセスすることができない.
5916 %</ja>
5917
5918 %<en>\paragraph{Implementation}
5919 %<ja>\paragraph{解決法}
5920
5921 %<*en>
5922 The code of stack system is based on that in a post of Dev-luatex mailing list\footnote{%
5923 \texttt{[Dev-luatex] tex.currentgrouplevel}, a post at 2008/8/19 by Jonathan Sauer.}.
5924 %</en>
5925 %<*ja>
5926 スタックシステムのコードはDev-luatexメーリングリストのある投稿\footnote{%
5927 \texttt{[Dev-luatex] tex.currentgrouplevel}: Jonathan Sauerによる2008/8/19の投稿.}を
5928 ベースにしている.
5929 %</ja>
5930
5931 %<*en>
5932 These are two \TeX\ count registers for maintaining information:
5933 \verb+\ltj@@stack+ for the stack level, and \verb+\ltj@@group@level+ for
5934 the \TeX's group level when the last assignment was done.  Parameters
5935 are stored in one big table named \texttt{charprop\_stack\_table}, where
5936 \texttt{charprop\_stack\_table[$i$]} stores data of stack level~$i$. If
5937 a new stack level is created by \verb+\ltjsetparameter+, all data of the
5938 previous level is copied.
5939 %</en>
5940 %<*ja>
5941 情報を保持するために,2つの\TeX の整数レジスタを用いている:
5942 \verb+\ltj@@stack+ にスタックレベル,\verb+\ltj@@group@level+ に最後の代入が
5943 なされた時点での\TeX のグループレベルを保持している.
5944 パラメータは\texttt{charprop\_stack\_table}という名前のひとつの大きなテーブルに
5945 格納される.ここで,\texttt{charprop\_stack\_table[$i$]}はスタックレベル$i$の
5946 データを格納している.もし新しいスタックレベルが \verb+\ltjsetparameter+ によって
5947 生成されたら,前のレベルの全てのデータがコピーされる.
5948 %</ja>
5949
5950 %<*en>
5951 To resolve the problem mentioned in above paragraph ``Background'', \LuaTeX-ja uses
5952 another trick. When the stack level is about to be increased, a whatsit
5953 node whose type, subtype and value are 44~(\textit{user\_defined}),
5954 \textit{stack\_marker} and the current group level respectively is appended to the current
5955 list (we refer this node by \textit{stack\_flag}). This enables us to
5956 know whether assignment is done just inside a hbox. Suppose that the
5957 stack level is~$s$ and the \TeX's group level is~$t$ just after the hbox
5958 group, then:
5959 %</en>
5960 %<*ja>
5961 上の「背景」で述べた問題を解決するために,\LuaTeX-jaでは次の手法を用いる:
5962 スタックレベルが増加するするとき,type, subtype, valueがそれぞれ
5963 44~(\textit{user\_defined}), \textit{stack\_marker},そして現在のグループレベルであるwhatsitノード
5964 を現在のリストに付け加える(このノードを\textit{stack\_flag}とする).
5965 これにより,あるhboxの中で代入がなされたかどうかを知ることが可能
5966 となる.スタックレベルを$s$,そのhbox groupの直後の\TeX のグループレベルを
5967 $t$とすると:
5968 %</ja>
5969 \begin{itemize}
5970 %<*en>
5971 \item If there is no \textit{stack\_flag} node in the list of the contents of the hbox, then
5972       no assignment was occurred inside the hbox. Hence values of
5973       parameters at the end of the hbox are stored in the stack
5974       level~$s$.
5975 %</en>
5976 %<*ja>
5977 \item もしそのhboxの中身を表すリストの中に\textit{stack\_flag}ノードがなければ,
5978   hboxの中では代入は起こらなかったということになる.
5979   したがって,そのhboxの終わりにおけるパラメータの値はスタックレベル$s$に
5980   格納されている.
5981 %</ja>
5982
5983 %<*en>
5984 \item If there is a \textit{stack\_flag} node whose value is~$t+1$, then
5985       an assignment was occurred just inside the hbox group. Hence
5986       values of parameters at the end of the hbox are stored in the
5987       stack level~$s+1$.
5988 %</en>
5989 %<*ja>
5990 \item もし値が$t+1$の\textit{stack\_flag}ノードがあれば,その
5991   hboxの中で代入が起こったことになる.
5992   したがって,hboxの終わりにおけるパラメータの値はスタックレベル$s+1$に
5993   格納されている.
5994 %</ja>
5995
5996 %<*en>
5997 \item If there are \textit{stack\_flag} nodes but all of their values
5998       are more than~$t+1$, then an assignment was occurred in the box,
5999       but it is done in more internal group. Hence values of
6000       parameters at the end of the hbox are stored in the stack
6001       level~$s$.
6002 %</en>
6003 %<*ja>
6004 \item もし\textit{stack\_flag}ノードがあるがそれらの値が全て$t+1$より大きい
6005   場合,そのボックスの中で代入が起こったが,それは「より内部の」グループで
6006   起こったということになる.したがって,hboxの終わりでのパラメータの
6007   値はスタックレベル$s$に格納されている.
6008 %</ja>
6009 \end{itemize}
6010
6011 %<*en>
6012 Note that to work this trick correctly, assignments to
6013 \verb+\ltj@@stack+ and \verb+\ltj@@group@level+ have to be local always,
6014 regardless the value of \verb+\globaldefs+.
6015 To solve this problem, we use another trick: the assignment 
6016 \hbox{\verb+\directlua{tex.globaldefs=0}+} is always local.
6017 %</en>
6018 %<*ja>
6019 このトリックを正しく働かせるためには,\verb+\ltj@@stack+ と \verb+\ltj@@group@level+ への
6020 代入は \verb+\globaldefs+ の値によらず常にローカルでなければならないことに注意する.
6021 この問題は \hbox{\verb+\directlua{tex.globaldefs=0}+}(この代入は常にローカル)を
6022 用いることで解決している.
6023 %</ja>
6024
6025 %<*en>
6026 \subsection{Lua Functions of the Stack System}
6027 In this subsection, we will see how a user use \LuaTeX-ja's stack system to
6028 store some data which obeys the grouping of \TeX.
6029 %</en>
6030 %<*ja>
6031 \subsection{スタックシステムで使用される関数}
6032 本節では,ユーザが\LuaTeX-jaのスタックシステムを使用して,
6033 \TeX のグルーピングに従うような
6034 独自のデータを取り扱う方法を述べる.
6035 %</ja>
6036
6037 %<*en>
6038 The following function can be used to store data into a stack:
6039 \begin{verbatim}
6040 luatexja.stack.set_stack_table(index, <any> data)
6041 \end{verbatim}
6042 Any values which except \texttt{nil}~and~NaN are usable as \textit{index}. 
6043 However, a user should use only negative integers or strings as \textit{index}, 
6044 since natural numbers are used by \LuaTeX-ja itself.
6045 Also, whether \textit{data} is stored locally or globally 
6046 is determined by \texttt{luatexja.isglobal}
6047 (stored globally if and only if \texttt{luatexja.isglobal == 'global'}).
6048 %</en>
6049 %<*ja>
6050 スタックに値を設定するには,以下のLua関数を呼びだせば良い:
6051 \begin{verbatim}
6052 luatexja.stack.set_stack_table(<any> index, <any> data)
6053 \end{verbatim}
6054 直感的には,スタックテーブル中のインデックス\textit{index}の値を\textit{data}にする,という意味である.
6055 \textit{index}の値としては \texttt{nil} とNaN以外の任意の値を使えるが,
6056 自然数は\LuaTeX-jaが使用する(将来の拡張用も含む)ので,
6057 ユーザが使用する場合は負の整数値か文字列の値にすることが望ましい.
6058 また,ローカルに設定されるかグローバルに設定されるかは,\texttt{luatexja.isglobal} の値に依存する
6059 (グローバルに設定されるのは,\texttt{luatexja.isglobal == 'global'} であるちょうどその時).
6060 %</ja>
6061
6062 %<*en>
6063 Stored data can be obtained as the return value of
6064 \begin{verbatim}
6065 luatexja.stack.get_stack_table(index, <any> default, <number> level)
6066 \end{verbatim}
6067 where \textit{level} is the stack level, which is usually the value of \verb+\ltj@@stack+, 
6068 and \textit{default} is the default value which will be returned if no values are stored 
6069 in the stack table whose level is \textit{level}.
6070 %</en>
6071 %<*ja>
6072 スタックの値は,
6073 \begin{verbatim}
6074 luatexja.stack.get_stack_table(<any> index, <any> default, <number> level)
6075 \end{verbatim}
6076 の戻り値で取得できる.\textit{level}はスタックレベルであり,
6077 通常は \verb+\ltj@@stack+ の値を指定することになるだろう.
6078 \textit{default}はレベル\textit{level}のスタックに値が設定されていなかった場合に
6079 返すデフォルト値である.
6080 %</ja>
6081
6082 \begin{figure}[tb]
6083 \begin{lstlisting}[numbers=left, firstnumber=380]
6084 \protected\def\ltj@setpar@global{%
6085   \relax\ifnum\globaldefs>0\directlua{luatexja.isglobal='global'}%
6086     \else\directlua{luatexja.isglobal=''}\fi
6087 }
6088 \protected\def\ltjsetparameter#1{%
6089   \ltj@setpar@global\setkeys[ltj]{japaram}{#1}\ignorespaces}
6090 \protected\def\ltjglobalsetparameter#1{%
6091   \relax\ifnum\globaldefs<0\directlua{luatexja.isglobal=''}%
6092     \else\directlua{luatexja.isglobal='global'}\fi%
6093   \setkeys[ltj]{japaram}{#1}\ignorespaces}
6094 \end{lstlisting} 
6095 %<ja>\caption{パラメータ設定命令の定義}
6096 %<en>\caption{Definiton of parameter setting commands}
6097 \label{fig:setpar-def}
6098 \end{figure}
6099
6100 %<*en>
6101 \subsection{Extending Parameters}
6102 Keys for \verb+\ltjsetparameter+~and~\verb+\ltjgetparameter+ can be extended, 
6103 as in \Pkg{luatexja-adjust}.
6104 %</en>
6105 %<*ja>
6106 \subsection{パラメータの拡張}
6107 ここでは,\Pkg{luatexja-adjust}で行なっているように,
6108 \verb+\ltjsetparameter+,~\verb+\ltjgetparameter+に指定可能なキーを追加する方法
6109 を述べる.
6110 %</ja>
6111
6112 %<*en>
6113 \paragraph{Setting parameters}
6114 Figure~\ref{fig:setpar-def} shows the ``most outer'' definition of 
6115 two commands, 
6116 \verb+\ltjsetparameter+ and \verb+\ltjglobalsetparameter+.
6117 Most important part is the last \verb+\setkeys+, 
6118 which is offered by the \Pkg{xkeyval} package.
6119
6120 Hence, to add a key in \verb+\ltjsetparameter+, one only have to add a key
6121 whose prefix is \texttt{ltj} and whose family is \texttt{japaram}, as the following.
6122 \begin{verbatim}
6123 \define@key[ltj]{japaram}{...}{...}
6124 \end{verbatim}
6125
6126 \verb+\ltjsetparameter+~and~\verb+\ltjglobalsetparameter+ automatically sets
6127 \texttt{luatexja.isglobal}. Its meaning is the following.
6128 \begin{align}
6129  \texttt{luatexja.isglobal} = 
6130 \begin{cases}
6131  \texttt{'global'}&\text{global}\\
6132  \texttt{''}&\text{local}
6133 \end{cases}
6134 \end{align}
6135 This is determined not only by command name
6136 (\verb+\ltjsetparameter+~or~\verb+\ltjglobalsetparameter+), 
6137 but also by the value of \verb+\globaldefs+.
6138 %</en>
6139 %<*ja>
6140 \paragraph{パラメータの設定}
6141 \verb+\ltjsetparameter+ と,\verb+\ltjglobalsetparameter+ の定義は図\ref{fig:setpar-def}の
6142 のようになっている.
6143 本質的なのは最後の \verb+\setkeys+ で,これは\Pkg{xkeyval}パッケージの提供する命令である.
6144
6145 このため,\verb+\ltjsetparameter+ に指定可能なパラメータを追加するには,
6146 <prefix>を \texttt{ltj},<family>を \texttt{japaram} としたキーを
6147 \begin{verbatim}
6148 \define@key[ltj]{japaram}{...}{...}
6149 \end{verbatim}
6150 のように定義すれば良いだけである.
6151 なお,パラメータ指定がグローバルかローカルかどうかを示す \texttt{luatexja.isglobal} が,
6152 \begin{align}
6153  \texttt{luatexja.isglobal} = 
6154 \begin{cases}
6155  \texttt{'global'}&\text{パラメータ設定はグローバル}\\
6156  \texttt{''}&\text{パラメータ設定はローカル}
6157 \end{cases}
6158 \end{align}
6159 として自動的にセットされる\footnote{命令が \texttt{\textbackslash ltjglobalsetparameter} かどうかだけでは
6160 なく,実行時の \texttt{\textbackslash globaldefs} の値にも依存して定まる.}.
6161 %</ja>
6162
6163 %<*ja>
6164 \paragraph{パラメータの取得}
6165 一方,\verb+\ltjgetparameter+ はLuaスクリプトによって実装されている.
6166 値を取得するのに追加引数の要らないパラメータについては,\verb+luatexja.unary_pars+\ 
6167 内に処理内容を記述した関数を定義すれば良い.例えば,Luaスクリプトで
6168 \begin{lstlisting}[numbers=left] 
6169 function luatexja.unary_pars.hoge (t)
6170   return 42
6171 end
6172 \end{lstlisting}
6173 を実行すると,\verb+\ltjgetparameter{hoge}+ は \texttt{42} という\emph{文字列}を返す.
6174 関数 \verb+luatexja.unary_pars.hoge+ の引数$t$は,\ref{ssec-stack}節で述べた
6175 \LuaTeX-jaのスタックシステムにおけるスタックレベルである.
6176 戻り値はいかなる値であっても,最終的には文字列として出力されることに注意.
6177
6178 一方,追加引数(\emph{数値しか許容しない})が必要なパラメータについては,
6179 まずLuaスクリプトで処理内容の本体を記述しておく:
6180 \begin{lstlisting}[numbers=left] 
6181 function luatexja.binary_pars.fuga (c, t)
6182   return tostring(c) .. ', ' .. tostring(42)
6183 end
6184 \end{lstlisting}
6185 引数$t$は,先に述べた通りのスタックレベルである.一方,引数$c$は\ 
6186 \verb+\ltjgetparameter+ の第2引数を表す数値である.
6187 しかしこれだけでは駄目で,
6188 \begin{verbatim}
6189 \ltj@@decl@array@param{fuga}
6190 \end{verbatim}
6191 を実行し,\TeX インターフェース側に
6192 「\verb+\ltjgetparameter{fuga}+ は追加引数が必要」ということを通知する必要がある.
6193 %</ja>
6194
6195 %<en>\section{Linebreak after a Japanese Character}
6196 %<ja>\section{和文文字直後の改行}
6197 \label{sec-lbreak}
6198 %<en>\subsection{Reference: Behavior in \pTeX}
6199 %<ja>\subsection{参考:\pTeX の動作}
6200 %<*en>
6201 In~\pTeX, a line break after a Japanese character doesn't emit a space,
6202 since words are not separated by spaces in Japanese writings. However,
6203 this feature isn't fully implemented in \LuaTeX-ja due to the
6204 specification of callbacks in~\LuaTeX. To clarify the difference between
6205 \pTeX~and~\LuaTeX, We briefly describe the handling of a line break in~\pTeX, in
6206 this subsection.
6207
6208 \pTeX's input processor can be described in terms of a finite state
6209 automaton, as that of~\TeX\ in~Section~2.5 of~\cite{texbytopic}. The
6210 internal states are as follows:
6211 \begin{itemize}
6212 \item State~$N$: new line
6213 \item State~$S$: skipping spaces
6214 \item State~$M$: middle of line
6215 \item State~$K$: after a Japanese character
6216 \end{itemize}
6217 The first three states---$N$,~$S$, and~$M$---are as same as \TeX's input
6218 processor.  State~$K$ is similar to state~$M$, and is entered after
6219 Japanese characters.  The diagram of state transitions are indicated in
6220 Figure~\ref{fig-ptexipro}.  Note that \pTeX\ doesn't leave state~$K$
6221 after ``beginning/ending of a group'' characters.
6222 %</en>
6223
6224 %<*ja>
6225 欧文では文章の改行は単語間でしか行わない.そのため,\TeX では,(文字の直後の)改行は
6226 空白文字と同じ扱いとして扱われる.一方,和文ではほとんどどこでも改行が可能なため,
6227 \pTeX では和文文字の直後の改行は単純に無視されるようになっている.
6228
6229 このような動作は,\pTeX が\TeX からエンジンとして拡張されたことによって可能になったことである.
6230 \pTeX の入力処理部は,\TeX におけるそれと同じように,有限オートマトンとして記述することができ,
6231 以下に述べるような4状態を持っている.
6232
6233 \begin{itemize}
6234 \item State~$N$: 行の開始.
6235 \item State~$S$: 空白読み飛ばし.
6236 \item State~$M$: 行中.
6237 \item State~$K$: 行中(和文文字の後).
6238 \end{itemize}
6239 また,状態遷移は,図\ref{fig-ptexipro}のようになっており,図中の数字は
6240 カテゴリーコードを表している.最初の3状態は\TeX の入力処理部と同じであり,
6241 図中から状態$K$と「$j$」と書かれた矢印を取り除けば,\TeX の入力処理部と同
6242 じものになる.
6243
6244 この図から分かることは,
6245 \begin{quote}
6246 行が和文文字(とグループ境界文字)で終わっていれば,改行は無視される
6247 \end{quote}
6248 ということである.
6249 %</ja>
6250
6251 \begin{figure}[!tb]
6252 \let\sp\textvisiblespace\small
6253 \begin{minipage}{.6\textwidth}%
6254 \begin{center}
6255 \unitlength=6.5mm\sf\mathversion{bold}
6256 \begin{tikzpicture}[
6257   ->, auto, shorten >=1pt
6258 ]
6259 \node [shape=rectangle, font=\scriptsize] (init) at (2,7) {start};
6260 \node [shape=circle,draw, fill=blue!20] (newline) at (4,7) {$N$};
6261 \node [shape=circle,draw, fill=blue!20] (midline) at (4,4) {$M$};
6262 \node [shape=circle,draw, fill=blue!20] (skipspc) at (8,7) {$S$};
6263 \node [shape=circle,draw, fill=red!20]  (kanji) at (8,4) {$K$};
6264 \node [shape=rectangle,draw, fill=green!20] (scanacs) at (6,8) {scan a c.s.};
6265 \node (endk) at (8,2.5) {} ;
6266 \node (endm) at (4,2.5) {} ;
6267 \node (ends) at (8,8.5) {} ;
6268 \node (endn) at (4,8.5) {} ;
6269 \begin{scope}[font=\scriptsize]
6270 \path (newline) edge [bend right]    node [left]{G, O} (midline)
6271       (init)    edge                 node {} (newline)
6272       (midline) edge [bend right=10] node {10} (skipspc)
6273       (skipspc) edge [bend right]    node [left,right=10,above=7]{G, O} (midline)
6274       (skipspc) edge [loop right]    node {10} (skipspc)
6275       (newline) edge [loop right]    node {10} (newline)
6276       (scanacs) edge [bend left]     node [left=3,below]{$(*)$} (skipspc)
6277       (scanacs) edge [bend right]    node [right=30,above=20]{$(*)$} (midline)
6278       (midline) edge                 node {5\ [\sp]} (endm)
6279       (midline) edge [loop left]     node {G, O} (midline)
6280       (skipspc) edge                 node [right] {5} (ends)
6281       (newline) edge                 node {5 [{\tt\textbackslash par}]} (endn);
6282 \begin{scope}[red]
6283 \path (newline) edge [bend right]    node [right=25,below=3]{J} (kanji)
6284       (midline) edge                 node [below]{J} (kanji)
6285       (kanji)   edge [bend left]     node {O} (midline)
6286       (kanji)   edge                 node {10} (skipspc)
6287       (kanji)   edge [loop right]    node {G, J} (kanji)
6288       (skipspc) edge [bend left]     node {J} (kanji)
6289       (kanji)   edge                 node {5} (endk)
6290 ;
6291 \end{scope}
6292 \end{scope}
6293 \end{tikzpicture}
6294 \end{center}
6295 \end{minipage}%
6296 \begin{minipage}{.4\textwidth}
6297 \begin{description}
6298 \item[\textsf{G}] Beginning of group (usually \verb+{+)\\
6299  and ending of group (usually \verb+}+).
6300 \item[\textsf{J}] Japanese characters.
6301 \item[\textsf{5}] \textit{end-of-line} (usually \verb+^+\verb+^J+).
6302 \item[\textsf{10}] space (usually \sp).
6303 \item[\textsf{O}] other characters, whose category code is in $\{3,4,6,7,8,11,12,13\}$.
6304 \item[\textsf{[\sp]}, \textsf{[{\tt\textbackslash par}]}]
6305 emits a space, or~\verb+\par+.
6306 \end{description}
6307 \end{minipage}
6308 \begin{itemize}
6309 \item We omitted about category codes
6310 9~(\textit{ignored}), 14~(\textit{comment}), and~15~(\textit{invalid})
6311 from the above diagram. We also ignored the input like ``\verb+^+\verb+^A+'' or ``\verb+^+\verb+^df+''.
6312 \item When a character whose category code is 0 (\textit{escape character}) is seen by \TeX,
6313 the input processor scans a control sequence (\textsf{scan a c.s.}).
6314 These paths are not shown in the above diagram.
6315
6316 After that, the state is changed to State~$S$ (skipping blanks) in most cases, but
6317 to State~$M$ (middle of line) sometimes.
6318 \end{itemize}
6319 %<en>\caption{State transitions of \pTeX's input processor}
6320 %<ja>\caption{\pTeX の入力処理部の状態遷移}
6321 \label{fig-ptexipro}
6322 \end{figure}
6323
6324
6325 %<en>\subsection{Behavior in \LuaTeX-ja}
6326 %<ja>\subsection{\LuaTeX-jaの動作}
6327 %<*en>
6328 States in the input processor of \LuaTeX\ is the same as that of \TeX,
6329 and they can't be customized by any callbacks. Hence, we can only use
6330 \verb+process_input_buffer+ and \verb+token_filter+ callbacks for to
6331 suppress a space by a line break which is after Japanese characters.
6332
6333 However, \verb+token_filter+ callback cannot be used either, since a
6334 character in category code 5~(\textit{end-of-line}) is converted into an space
6335 token \emph{in the input processor}.  So we can use only the
6336 \verb+process_input_buffer+ callback.  This means that suppressing a
6337 space must be done \emph{just before} an input line is read.
6338
6339 Considering these situations, handling of an end-of-line in \LuaTeX-ja are as follows:
6340 \begin{quote}
6341 A character \texttt{U+FFFFF} (its category code is set to 14~(\textit{comment}) by
6342 \LuaTeX-ja) is appended to an input line, \emph{before \LuaTeX\ actually
6343 process it}, if and only if the following three conditions are satisfied:
6344 \begin{enumerate}
6345 \item The category code of \verb+\endlinechar+%
6346 \footnote{Usually, it is $\langle$\textit{return}$\rangle$
6347       (whose character code is 13).} is 5~(\textit{end-of-line}).
6348 \item The category code of \texttt{U+FFFFF} itself is 14~(\textit{comment}).
6349 \item The input line matches the following ``regular expression'':
6350 \[
6351   (\text{any char})^*(\textbf{JAchar})
6352   \bigl(\{\text{catcode}=1\}\cup\{\text{catcode}=2\}\bigr)^*
6353 \]
6354 \end{enumerate}
6355 \end{quote}
6356
6357 \paragraph{Remark}
6358 The following example shows the major difference from the behavior of \pTeX.
6359 \begin{LTXexample}
6360 \fontspec[Ligatures=TeX]{TeX Gyre Termes}
6361 \ltjsetparameter{autoxspacing=false}
6362 \ltjsetparameter{jacharrange={-6}}xあ
6363 y\ltjsetparameter{jacharrange={+6}}zい
6364 u
6365 \end{LTXexample}
6366 It is not strange that ``あ'' does not printed in the above output.
6367 This is because \TeX\ Gyre\ Termes does not contain ``あ'', and because 
6368 ``あ'' in line~3 is considered as an \textbf{ALchar}.
6369
6370 Note that there is no space before ``y'' in the output, but
6371 there is a space before ``u''. This follows from following reasons:
6372 \begin{itemize}
6373 \item When line~3 is processed by \texttt{process\_input\_buffer} callback,
6374 ``あ'' is considered as an \textbf{JAchar}.
6375 Since  line~3 ends with an \textbf{JAchar}, 
6376 the comment character \texttt{U+FFFFF} is appended to this line,
6377 and hence the linebreak immediately after this line is ignored.
6378 \item When line~4 is processed by \texttt{process\_input\_buffer} callback,
6379 ``い'' is considered as an \textbf{ALchar}.
6380 Since  line~4 ends with an \textbf{ALchar}, the linebreak immediately after this line
6381 emits a space.
6382 \end{itemize}
6383 %</en>
6384
6385 %<*ja>
6386 \LuaTeX の入力処理部は\TeX のそれと全く同じであり,コールバックによりユーザが
6387 カスタマイズすることはできない.このため,改行抑制の目的でユーザが利用で
6388 きそうなコールバックとしては,\verb+process_input_buffer+や
6389 \verb+token_filter+に限られてしまう.しかし,\TeX の入力処理部をよく見る
6390 と,後者も役には経たないことが分かる:改行文字は,入力処理部によってトー
6391 クン化される時に,カテゴリーコード10の32番文字へと置き換えられてしまうた
6392 め,\verb+token_filter+で非標準なトークン読み出しを行おうとしても,空白文
6393 字由来のトークンと,改行文字由来のトークンは区別できないのだ.
6394
6395 すると,我々のとれる道は,\verb+process_input_buffer+を用いて
6396 \LuaTeX の入力処理部に引き渡される前に入力文字列を編集するというものしかない.
6397 以上を踏まえ,\LuaTeX-jaにおける「和文文字直後の改行抑制」の処理は,次のようになっている:
6398
6399 \begin{quote}
6400 各入力行に対し,\emph{その入力行が読まれる前の内部状態で}
6401 以下の3条件が満たされている場合,\LuaTeX-jaは\texttt{U+FFFFF}の文字
6402 \footnote{この文字はコメント文字として扱われるように\LuaTeX-ja内部で設定をしている.}
6403 を末尾に追加する.よって,その場合に改行は空白とは見做されないこととなる.
6404 \begin{enumerate}
6405 \item \verb+\endlinechar+の文字\footnote{普通は,改行文字(文字コード13番)である.}
6406 のカテゴリーコードが5~(\textit{end-of-line})である.
6407 \item \texttt{U+FFFFF}のカテゴリーコードが14~(\textit{comment})である.
6408 \item 入力行は次の「正規表現」にマッチしている:
6409 \[
6410   (\text{any char})^*(\textbf{JAchar})
6411   \bigl(\{\text{catcode}=1\}\cup\{\text{catcode}=2\}\bigr)^*
6412 \]
6413 \end{enumerate}
6414 \end{quote}
6415
6416 この仕様は,前節で述べた\pTeX の仕様にできるだけ近づけたものとなっている.条件1.は,
6417 \texttt{verbatim}系環境などの日本語対応マクロを書かなくてすませるためのものである.
6418
6419 しかしながら,\pTeX と完全に同じ挙動が実現できたわけではない.
6420 次のように,和文文字の範囲を変更したちょうどその行においては挙動が異なる:
6421 \begin{LTXexample}
6422 \fontspec[Ligatures=TeX]{TeX Gyre Termes}
6423 \ltjsetparameter{autoxspacing=false}
6424 \ltjsetparameter{jacharrange={-6}}xあ
6425 y\ltjsetparameter{jacharrange={+6}}zい
6426 u
6427 \end{LTXexample}
6428 上ソース中の「あ」は欧文文字扱いであり.
6429 ここで使用している欧文フォント\TeX\ Gyre Termesは「あ」を含まない.
6430 よって,出力に「あ」は現れないことは不思議ではない.
6431 それでも,\pTeX とまったく同じ挙動を示すならば,出力は
6432 「\hbox{\ltjsetparameter{autoxspacing=false}x yzいu}」となるはずである.しかし,実際には
6433 上のように異なる挙動となっているが,それは以下の理由による:
6434 \begin{itemize}
6435 \item 3行目を \texttt{process\_input\_buffer} で処理する時点では,
6436       「あ」は和文文字扱いである.よって3行目は和文文字で終わることになり,
6437       コメント文字 \texttt{U+FFFFF} が追加される.
6438       よって,直後の改行文字は無視されることになり,空白は入らない.
6439 \item 4行目を \texttt{process\_input\_buffer} で処理する時点では,
6440       「い」は欧文文字扱いである.よって4行目は欧文文字で終わることになり,
6441       直後の改行文字は空白に置き換わる.
6442 \end{itemize}
6443 このため,トラブルを避けるために,和文文字の範囲を\verb+\ltjsetparameter+で編集した場合,
6444 その行はそこで改行するようにした方がいいだろう.
6445 %</ja>
6446
6447 %<*ja>
6448
6449 %<en>\section{Insertion of JFM glues, \Param{kanjiskip} and \Param{xkanjiskip}}
6450 %<ja>\section{JFMグルーの挿入,\Param{kanjiskip}と\Param{xkanjiskip}}
6451 \label{sec-jfmglue}
6452 %<en>\subsection{Overview}
6453 %<ja>\subsection{概要}
6454
6455 \LuaTeX-jaにおける \textbf{JAglue} の挿入方法は,\pTeX のそれとは全く異なる.
6456 \pTeX では次のような仕様であった:
6457 \begin{itemize}
6458 \item JFMグルーの挿入は,和文文字を表すトークンを元に水平リストに(文字を表す)<char\_node>を
6459 追加する過程で行われる.
6460 \item \Param{\hyperlink{fld:xks}{xkanjiskip}}の挿入は,hboxへのパッケージングや行分割前に行われる.
6461 \item \Param{\hyperlink{fld:kanjiskip}{kanjiskip}}はノードとしては挿入されない.パッケージングや行分割の計算時に
6462 「和文文字を表す2つの<char\_node>の間には\Param{\hyperlink{fld:kanjiskip}{kanjiskip}}がある」ものとみなされる.
6463 \end{itemize}
6464 しかし,\LuaTeX-jaでは,hboxへのパッケージングや行分割前に全ての
6465 \textbf{JAglue},即ちJFMグルー・\Param{\hyperlink{fld:xks}{xkanjiskip}}・\Param{\hyperlink{fld:kanjiskip}{kanjiskip}}の
6466 3種類を一度に挿入することになっている.これは,\LuaTeX において欧文の合字・
6467 カーニング処理がノードベースになったことに対応する変更である.
6468
6469 \LuaTeX-jaにおける\textbf{JAglue}挿入処理では,次節で定義する
6470 「クラスタ」を単位にして行われる.大雑把にいうと,「クラスタ」は文字とそれに付随す
6471 るノード達(アクセント位置補正用のカーンや,イタリック補正)をまとめたもの
6472 であり,2つのクラスタの間には,ペナルティ,\verb+\vadjust+,whatsitなど,行組版
6473 には関係しないものがある.
6474
6475
6476 %<en>\subsection{Definition of a Cluster}
6477 %<ja>\subsection{「クラスタ」の定義}
6478
6479 \def\OA{$\text{\sf O}_{\text{\sf A}}$}
6480 \def\OB{$\text{\sf O}_{\text{\sf B}}$}
6481 \begin{defn}
6482 %<*en>
6483 A \emph{cluster} is a list of consecutive nodes in one of the following forms,
6484 with the \textit{id} of it:
6485 %</en>
6486 %<*ja>
6487 \emph{クラスタ}は以下の形のうちのどれかひとつをとる連続的なノードのリストである:
6488 %</ja>
6489 \begin{enumerate}
6490 %<*en>
6491 \item Nodes whose value of\ \verb+\ltj@icflag+ is in $[3,15)$.  These
6492       nodes come from a hbox which is already packaged, by unpackaging
6493       (\verb+\unhbox+).
6494       The \textit{id} is \textit{id\_pbox}.
6495 %</en>
6496 %<*ja>
6497 \item その \verb+\ltj@icflag+ の値が$[3,15)$に入るノードのリスト.
6498   これらのノードはある既にパッケージングされたhboxから \verb+\unhbox+ で
6499   アンパックされたものである.
6500   その\textit{id}は\textit{id\_pbox}である.
6501 %</ja>
6502
6503 %<*en>
6504 \item A inline math formula, including two \textit{math\_node}s at the boundary of it.
6505       The \textit{id} is \textit{id\_math}.
6506 %</en>
6507 %<*ja>
6508 \item インライン数式でその境界に2つの\textit{math\_node}を含むもの.
6509   その\textit{id}は\textit{id\_math}である.
6510 %</ja>
6511
6512 %<*en>
6513 \item A \textit{glyph\_node}~$p$ with nodes which relate with it:
6514 %</en>
6515 %<*ja>
6516 \item \textit{glpyh\_node}~$p$とそれに関係するノード:
6517 %</ja>
6518 \begin{enumerate}
6519 %<*en>
6520 \item A kern for the italic correction of~$p$.
6521 %</en>
6522 %<*ja>
6523 \item $p$のイタリック補正のためのカーン.
6524 %</ja>
6525
6526 %<*en>
6527 \item An accent attached to $p$ by \verb+\accent+.
6528 %</en>
6529 %<*ja>
6530 \item \verb+\accent+ による$p$に付随したアクセント.
6531 %</ja>
6532 \end{enumerate}
6533 \[
6534 \overbrace{%
6535  \Node{kern}{$\mathit{subtype}=2$}\longrightarrow
6536 \left\{\begin{array}{c}
6537 \Node{glyph}{accent}\\\noalign{\medskip}
6538 \Node{hbox}{accent (shifted vert.)}
6539 \end{array}\right\}\longrightarrow
6540 \Node{kern}{$\mathit{subtype}=2$}}^{\text{(a)}}
6541 \longrightarrow
6542 \Node{glyph}{$p$}\longrightarrow
6543 \overbrace{%
6544 \Node{kern}{italic corr.}}^{\text{(b)}}
6545 \]
6546
6547 %<*en>
6548 The \textit{id} is \textit{id\_jglyph} or
6549 \textit{id\_glyph}, according to whether the \textit{glyph\_node}
6550 represents a Japanese character or not.
6551 %</en>
6552 %<*ja>
6553 \textit{id}は\textit{glyph\_node}が和文文字を表すかどうかによって
6554 \textit{id\_jglyph},もしくは\textit{id\_glyph}となる.
6555 %</ja>
6556
6557 %<*en>
6558 \item An box-like node, that is, an hbox, a vbox, a rule (\verb+\vrule+) and an \textit{unset\_node}.
6559 The \textit{id} is \textit{id\_hlist} if the node is an
6560       hbox which is not shifted vertically, or \textit{id\_box\_like}
6561       otherwise.
6562 %</en>
6563 %<*ja>
6564 \item ボックス様のノード,つまり水平ボックス,垂直ボックス,罫線 (\verb+\vrule+),
6565   そして\textit{unset\_node}.
6566   その\textit{id}は垂直に移動していないhboxならば\textit{id\_hlist},
6567   そうでなければ\textit{id\_box\_like}となる.
6568 %</ja>
6569
6570 %<*en>
6571 \item A glue, a kern whose subtype is not 2~(\textit{accent}), and a discretionary break.
6572 The \textit{id} is \textit{id\_glue}, \textit{id\_kern}
6573       and \textit{id\_disc}, respectively.
6574 %</en>
6575 %<*ja>
6576 \item グルー,subtypeが 2~(\textit{accent})ではないカーン,そして任意改行.
6577   その\textit{id}はそれぞれ\textit{id\_glue}, \textit{id\_kern},そして
6578   \textit{id\_disc}である.
6579 %</ja>
6580 \end{enumerate}
6581 %<*en>
6582 Let \textit{Np}, \textit{Nq} and \textit{Nr} denote a cluster.
6583 %</en>
6584 %<*ja>
6585 以下では\textit{Np}, \textit{Nq}, \textit{Nr}でクラスタを表す.
6586 %</ja>
6587 \end{defn}
6588
6589 \paragraph{\textit{id}の意味}
6590 $\mathit{Np}.\mathit{id}$の意味を述べるとともに,
6591 「先頭の文字」を表す\textit{glyph\_node}~$\mathit{Np}.\mathit{head}$と,
6592 「最後の文字」を表す\textit{glyph\_node}~$\mathit{Np}.\mathit{tail}$を次のように定義する.
6593 直感的に言うと,\textit{Np}は$\mathit{Np}.\mathit{head}$で始まり$\mathit{Np}.\mathit{tail}$で終わるような単語,
6594 と見做すことができる.これら$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$は
6595 説明用に準備した概念であって,実際のLuaコード中にそのように書かれているわけではないことに注意.
6596
6597 \begin{description}
6598 \item[\textit{id\_jglyph}] 和文文字.\\
6599 $\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$は,その和文文字を表している
6600 \textit{glyph\_node}そのものである.
6601 \item[\textit{id\_glyph}] 和文文字を表していない\textit{glyph\_node}~$p$.\\
6602 多くの場合,$p$は欧文文字を格納しているが,「ffi」などの合字によって作られた
6603 \textit{glyph\_node}である可能性もある.
6604 前者の場合,$\mathit{Np}.\mathit{head}$,~$\mathit{Np}.\mathit{tail} = p$である.
6605 一方,後者の場合,
6606 \begin{itemize}
6607 \item $\mathit{Np}.\mathit{head}$は,
6608 合字の構成要素の先頭→(その\textit{glyph\_node}における)合字の構成要素の先頭→……
6609 と再帰的に検索していってたどり着いた\textit{glyph\_node}である.
6610 \item $\mathit{Np}.\mathit{last}$は,同様に末尾→末尾→と検索してたどり着いた\textit{glyph\_node}である.
6611 \end{itemize}
6612 \item[\textit{id\_math}] インライン数式.\\
6613 便宜的に,$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$ともに
6614 「文字コード$-1$の欧文文字」とおく.
6615 \item[\textit{id\_hlist}] 縦方向にシフトされていないhbox.\\
6616 この場合,$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$はそれぞれ$p$の内容を表すリストの,
6617 先頭・末尾のノードである.
6618 \begin{itemize}
6619 \item 状況によっては,\TeX ソースで言うと
6620 \begin{verbatim}
6621 \hbox{\hbox{abc}...\hbox{\lower1pt\hbox{xyz}}}
6622 \end{verbatim}
6623 のように,$p$の内容が別のhboxで開始・終了している可能性も十分あり得る.そのような場合,
6624 $\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$の算出は,
6625 \emph{垂直方向にシフトされていない}hboxの
6626 場合だけ内部を再帰的に探索する.例えば上の例では,$\mathit{Np}.\mathit{head}$は文字「a」を表すノードであり,
6627 一方$\mathit{Np}.\mathit{tail}$は垂直方向にシフトされたhbox,
6628 \verb+\lower1pt\hbox{xyz}+ に対応するノードである.
6629 \item また,先頭にアクセント付きの文字がきたり,末尾にイタリック補正用のカーンが
6630 来ることもあり得る.この場合は,クラスタの定義のところにもあったように,それらは無視して算出を行う.
6631 \item 最初・最後のノードが合字によって作られた\textit{glyph\_node}のときは,それぞれに対して\textit{id\_glyph}%
6632 と同様に再帰的に構成要素をたどっていく.
6633 \end{itemize}
6634 \item[\textit{id\_pbox}] 「既に処理された」ノードのリストであり,これらのノードが二度処理を受けないために
6635 まとめて1つのクラスタとして取り扱うだけである.
6636 \textit{id\_hlist}と同じ方法で$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$を算出する,
6637 \item[\textit{id\_disc}] discretionary break (\verb+\discretionary{pre}{post}{nobreak}+).\\
6638 \textit{id\_hlist}と同じ方法で$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$を算出するが,
6639 第3引数の \texttt{nobreak}(行分割が行われない時の内容)を使う.言い換えれば,ここで行分割が発生した時の状況は
6640 全く考慮に入れない.
6641 \item[\textit{id\_box\_like}] \textit{id\_hlist}とならないboxや,rule.\\
6642 この場合は,$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$のデータは利用されないので,2つの算出は無意味である.
6643 敢えて明示するならば,$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$は共にnil値である.
6644 \item[他] 以上にない\textit{id}に対しても,$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$の算出は無意味.
6645 \end{description}
6646
6647 \paragraph{クラスタの別の分類}
6648 さらに,JFMグルー挿入処理の実際の説明により便利なように,\textit{id}とは別のクラスタの分類を行っておく.
6649 挿入処理では2つの隣り合ったクラスタの間に
6650 空白等の実際の挿入を行うことは前に書いたが,ここでの説明では,問題にしているクラスタ\textit{Np}は「後ろ側」のクラスタである
6651 とする.「前側」のクラスタについては,以下の説明で\textit{head}が\textit{last}に置き換わることに注意すること.
6652 \begin{description}
6653 \item[和文A] リスト中に直接出現している和文文字.
6654 \textit{id}が\textit{id\_jglyph}であるか,\\
6655 \textit{id}が\textit{id\_pbox}であって$\mathit{Np}.\mathit{head}$が\textbf{JAchar}であるとき.
6656
6657 \item[和文B] リスト中のhboxの中身の先頭として出現した和文文字.和文Aとの違いは,これの前に
6658 JFMグルーの挿入が行われない(\Param{\hyperlink{fld:xks}{xkanjiskip}},~\Param{\hyperlink{fld:kanjiskip}{kanjiskip}}は入り得る)ことである.\\
6659 \textit{id}が\textit{id\_hlist}か\textit{id\_disc}であって$\mathit{Np}.\mathit{head}$が\textbf{JAchar}であるとき.
6660
6661 \item[欧文] リスト中に直接/hboxの中身として出現している欧文文字.次の3つの場合が該当:
6662 \begin{itemize}
6663 \item \textit{id}が\textit{id\_glyph}である.
6664 \item \textit{id}が\textit{id\_math}である.
6665 \item \textit{id}が\textit{id\_pbox}か\textit{id\_hlist}か\textit{id\_disc}であって,$\mathit{Np}.\mathit{head}$が\textbf{ALchar}.
6666 \end{itemize}
6667 \item[箱] box,またはそれに類似するもの.次の2つが該当:
6668 \begin{itemize}
6669 \item \textit{id}が\textit{id\_pbox}か\textit{id\_hlist}か\textit{id\_disc}であって,$\mathit{Np}.\mathit{head}$が\textit{glyph\_node}でない.
6670 \item \textit{id}が\textit{id\_box\_like}である.
6671 \end{itemize}
6672
6673 \end{description}
6674
6675 \subsection{段落/hboxの先頭や末尾}
6676 \paragraph{先頭部の処理}
6677 まず,段落/hboxの一番最初にあるクラスタ\textit{Np}を探索する.
6678 hboxの場合は何の問題もないが,段落の場合では以下のノード達を事前に読み飛ばしておく:
6679 \begin{itemize}
6680 \item \verb+\parindent+ 由来のhbox($\mathit{subtype}=3$)
6681 \item \textit{subtype}が44~(\textit{user\_defined})でないようなwhatsit
6682 \end{itemize}
6683 これは,\verb+\parindent+由来のhboxがクラスタを構成しないようにするためである.
6684
6685 次に,\textit{Np}の直前に空白$g$を必要なら挿入する:
6686 \begin{enumerate}
6687 \item この処理が働くような\textit{Np}は\textsf{和文A}である.
6688 \item 問題のリストが字下げありの段落(\verb+\parindent+ 由来のhboxあり)の場合は,
6689 この空白$g$は「文字コード \texttt{'parbdd'} の文字」と\textit{Np}の間に入るグルー/カーンである.
6690 \item そうでないとき(\verb+noindent+ で開始された段落やhbox)は,
6691 $g$は「文字コード \texttt{'boxbdd'} の文字」と\textit{Np}の間に入るグルー/カーンである.
6692 \end{enumerate}
6693 ただし,もし$g$がglueであった場合,この挿入によって\textit{Np}による行分割が新たに可能になるべきではない.
6694 そこで,以下の場合には,$g$の直前に \verb+\penalty10000+ を挿入する:
6695 \begin{itemize}
6696 \item 問題にしているリストが段落であり,かつ
6697 \item \textit{Np}の前には予めペナルティがなく,$g$はglue.
6698 \end{itemize}
6699
6700 \paragraph{末尾の処理}
6701 末尾の処理は,問題のリストが段落のものかhboxのものかによって異なる.
6702 後者の場合は容易い:最後のクラスタを\textit{Nq}とおくと,\textit{Nq}と「文字コード\ 
6703 \texttt{'boxbdd'} の文字」の間に入るグルー/カーンを,
6704 \textit{Nq}の直後に挿入するのみである.
6705
6706 一方.前者(段落)の場合は,リストの末尾は常に \verb+\penalty10000+ と,
6707 \verb+\parfillskip+ 由来のグルーが存在する.%よって,最後のクラスタ\textit{Np}は
6708 %この \verb+\parfillskip+ 由来のグルーとなり,実質的な中身の最後はその1つ前のクラスタ\textit{Nq}となる.
6709 段落の最後の「通常の和文文字${}+{}$句点」が独立した行となるのを防ぐために,
6710 \Param{jcharwidowpenalty}の値の分だけ適切な場所のペナルティを増やす.
6711
6712 ペナルティ量を増やす場所は,\textit{head}が\textbf{JAchar}であり,
6713 かつその文字の\Param{kcatcode}が偶数であるような
6714 最後のクラスタの直前にあるものたちである%
6715 \footnote{大雑把に言えば,\Param{kcatcode}が奇数であるような\textbf{JAchar}%
6716 を約物として考えていることになる.
6717 \Param{kcatcode}の最下位ビットはこの\Param{jcharwidowpenalty}用にのみ利用される.}.
6718
6719 \subsection{概観と典型例:2つの「和文A」の場合}
6720 \label{ssec-cluster-wa}
6721 先に述べたように,2つの隣り合ったクラスタ,\textit{Nq}と\textit{Np}の間には,
6722 ペナルティ,\verb+\vadjust+,whatsitなど,行組版には関係しないものがある.模式的に表すと,
6723 \[
6724  \Node{cluster}{\textit{Nq}}\longrightarrow
6725 \overbrace{
6726 \Node{penalty}{$p$}\longrightarrow \cdots\longrightarrow \Node{whatsit}{}}^{\textrm{(a)}}
6727 \longrightarrow \Node{cluster}{\textit{Np}}
6728 \]
6729 のようになっている.間の(a)に相当する部分には,何のノードもない場合ももちろんあり得る.
6730 そうして,JFMグルー挿入後には,この2クラスタ間は次のようになる:
6731 \[
6732  \Node{cluster}{\textit{Nq}}\longrightarrow%\Node{kern}{左空白}\longrightarrow
6733 \overbrace{
6734 \Node{penalty}{$p+x$}\longrightarrow \cdots\longrightarrow 
6735 \Node{whatsit}{}}^{\textrm{(a)}}\longrightarrow 
6736 \Node{glue or kern}{\raisebox{-.2\zw}{右空白}}\longrightarrow
6737 \Node{cluster}{\textit{Np}}
6738 \]
6739
6740 以後,\emph{典型的な例として,クラスタ\textit{Nq}と\textit{Np}が共に\textsf{\textmd{和文A}}である場合を見ていこう,}
6741 この場合が全ての場合の基本となる.
6742
6743 \paragraph{「右空白」の算出}
6744 まず,「右空白」にあたる量を算出する.通常はこれが,隣り合った2つの和文文字間に入る空白量となる.
6745 \begin{description}
6746 \item[JFM由来{[M]}] JFMの文字クラス指定によって入る空白を以下によって求める.この段階で空白量が未定義(未指定)だった場合,
6747       デフォルト値\Param{\hyperlink{fld:kanjiskip}{kanjiskip}}を採用することとなるので,次へ.
6748 \begin{enumerate}
6749 \item もし両クラスタの間で \verb+\inhibitglue+ が実行されていた場合(証としてwhatsitノードが自動挿入される),
6750       代わりに\Param{\hyperlink{fld:kanjiskip}{kanjiskip}}が挿入されることとなる.次へ.
6751 \item \textit{Nq}と\textit{Np}が同じJFM・同じ\texttt{jfmvar}キー・同じサイズの和文フォントであったならば,
6752       共通に使っているJFM内で挿入される空白(グルーかカーン)が決まっているか調べ,決まっていればそれを採用.
6753 \item 1.でも2.でもない場合は,JFM・\texttt{jfmvar}・サイズの3つ組は\textit{Nq}と\textit{Np}で異なる.
6754 この場合,まず
6755 \[
6756 \vcenter{\halign{\hfil$#:={}$&\inhibitglue#\inhibitglue\cr
6757 gb&(\textit{Nq}と「使用フォントが\textit{Nq}のそれと同じで,\hfil\cr
6758 \omit&\quad 文字コードが\textit{Np}のそれの文字」との間に入るグルー/カーン)\hfil\cr
6759 ga&(\inhibitglue 「使用フォントが\textit{Np}のそれと同じで,\hfil\cr
6760 \omit&\quad 文字コードが\textit{Nq}のそれの文字」と\textit{Np}との間に入るグルー/カーン)\hfil\cr
6761 }}
6762 \]
6763 として,前側の文字のJFMを使った時の空白(グルー/カーン)と,後側の文字のJFMを使った時のそれを求める.
6764
6765 $\mathit{gb}$,~$\mathit{ga}$それぞれに対する<ratio>の値を$d_b$,~$d_a$とする.
6766 \begin{itemize}
6767 \item 
6768 $\mathit{ga}$と$\mathit{gb}$の両方が未定義であるならば,JFM由来のグルーは挿入されず,
6769 \Param{\hyperlink{fld:kanjiskip}{kanjiskip}}を採用することとなる.
6770 どちらか片方のみが未定義であるならば,次のステップでその未定義の方は長さ0のkernで,<ratio>の値は0であるかのように扱われる.
6771 \item 
6772 \Param{\hyperlink{fld:diffjfm}{diffrentjfm}}の値が \texttt{pleft}, \texttt{pright},
6773       \texttt{paverage} のとき,
6774 <ratio>の指定に従って比例配分を行う.
6775 JFM由来のグルー/カーンは以下の値となる:
6776 \[
6777  f\left(\frac{1-d_b}2\textit{gb} + \frac{1+d_b}2\textit{ga},
6778 \frac{1-d_a}2\textit{gb} + \frac{1+d_a}2\textit{ga}\right)
6779 \]
6780 ここで.$f(x,y)$は
6781 \[
6782  f(x,y)=\begin{cases}
6783 x&\text{if\ }\Param{\hyperlink{fld:diffjfm}{diffrentjfm}}=\texttt{pleft};\\
6784 y&\text{if\ }\Param{\hyperlink{fld:diffjfm}{diffrentjfm}}=\texttt{pright};\\
6785 (x+y)/2&\text{if\ }\Param{\hyperlink{fld:diffjfm}{diffrentjfm}}=\texttt{paverage};
6786 \end{cases}.
6787 \]
6788 \item 
6789 \Param{differentjfm}がそれ以外の値の時は,<ratio>の値は無視され,JFM由来のグルー/カーンは以下の値となる:
6790 \[
6791  f(\textit{gb},\textit{ga})
6792 \]
6793 ここで.$f(x,y)$は
6794 \[
6795  f(x,y)=\begin{cases}
6796 \min(x,y)&\text{if\ }\Param{\hyperlink{fld:diffjfm}{diffrentjfm}}=\texttt{small};\\
6797 \max(x,y)&\text{if\ }\Param{\hyperlink{fld:diffjfm}{diffrentjfm}}=\texttt{large};\\
6798 (x+y)/2&\text{if\ }\Param{\hyperlink{fld:diffjfm}{diffrentjfm}}=\texttt{average};\\
6799 x+y&\text{if\ }\Param{\hyperlink{fld:diffjfm}{diffrentjfm}}=\texttt{both};
6800 \end{cases}.
6801 \]
6802 \end{itemize}
6803 \end{enumerate}
6804
6805 例えば,
6806 \begin{verbatim}
6807 \jfont\foo=psft:Ryumin-Light:jfm=ujis;-kern
6808 \jfont\bar=psft:GothicBBB-Medium:jfm=ujis;-kern
6809 \jfont\baz=psft:GothicBBB-Medium:jfm=ujis;jfmvar=piyo;-kern
6810 \end{verbatim}
6811 という3フォントを考え,
6812 \[
6813  \overbrace{\Node{glyph}{{\tt\textbackslash foo}, `あ'}}^{p}
6814 \longrightarrow \overbrace{\Node{glyph}{{\tt\textbackslash bar}, `い'}}^{q}
6815 \longrightarrow \overbrace{\Node{glyph}{{\tt\textbackslash baz}, `う'}}^{r}
6816 \]
6817 という3ノードを考える(それぞれ単独でクラスタをなす).
6818 この場合,$p$と$q$の間は,実フォントが異なるにもかかわらず2.の状況となる一方で,
6819 $q$と$r$の間は(実フォントが同じなのに)\texttt{jfmvar} キーの内容が異なるので3.の状況となる.
6820 \item[\Param{kanjiskip}~{[K]}] 上の[M]において空白が定まらなかった場合,
6821 以下で定めた量「右空白」として採用する.
6822 この段階においては,\verb+\inhibitglue+ は効力を持たないため,
6823 結果として,2つの和文文字間には常に何らかのグルー/カーンが挿入されることとなる.
6824 \begin{enumerate}
6825 \item 両クラスタ(厳密には$\mathit{Nq}.\mathit{tail}$,$\mathit{Np}.\mathit{head}$)の中身の文字コードに対する
6826 \Param{autospacing}パラメタが両方ともfalseだった場合は,長さ0のglueとする.
6827 \item ユーザ側から見た\Param{\hyperlink{fld:kanjiskip}{kanjiskip}}パラメタの自然長が${\tt \textbackslash maxdimen}=(2^{30}-1)\,{\rm sp}$で
6828 なければ,\Param{\hyperlink{fld:kanjiskip}{kanjiskip}}パラメタの値を持つglueを採用する.
6829 \item 2.でない場合は,\textit{Nq}, \textit{Np}で使われているJFMに指定されている\Param{\hyperlink{fld:kanjiskip}{kanjiskip}}の値を用いる.
6830 どちらか片方のクラスタだけが和文文字(\textsf{和文A}・\textsf{和文B})のときは,そちらのクラスタで使われている
6831 JFM由来の値だけを用いる.もし両者で使われているJFMが異なった場合は,上の[M]~3.と同様の方法を用いて調整する.
6832 \end{enumerate}
6833 \end{description}
6834 %\paragraph{「左空白」の算出とそれに伴う補正}
6835 %「左空白」は過去のバージョンでは定義していたが,このバージョンでは
6836 %挿入は一切行われない(機能自体削除している).
6837 %しかし,仕様は流動的であり,将来復活する可能性もあるため,マニュアル中の記述は今のところ極力変更しない.
6838 \paragraph{禁則用ペナルティの挿入}
6839 まず,
6840 \[
6841  a:=(\text{\textit{Nq}{\footnotemark}の文字に対する\Param{\hyperlink{fld:postbp}{postbreakpenalty}}の値})
6842 +(\text{\textit{Np}{\footnotemark}の文字に対する\Param{\hyperlink{fld:prebp}{prebreakpenalty}}の値})
6843 \]
6844 とおく\footnotetext{厳密にはそれぞれ$\mathit{Nq}.\mathit{tail}$,$\mathit{Np}.\mathit{head}$.}.
6845 ペナルティは通常$[-10000,10000]$の整数値をとり,また$\pm 10000$は正負の無限大を意味することになっているが,この$a$の
6846 算出では単純な整数の加減算を行う.
6847
6848 $a$は禁則処理用に\textit{Nq}と\textit{Np}の間に加えられるべきペナルティ量である.
6849 \begin{description}
6850 \item[P-normal~{[PN]}]
6851 \textit{Nq}と\textit{Np}の間の(a)部分にペナルティ(\textit{penalty\_node})があれば処理は簡単である:
6852 それらの各ノードにおいて,ペナルティ値を($\pm 10000$を無限大として扱いつつ)$a$だけ増加させればよい.
6853 また,$10000 + (-10000) = 0$としている.
6854
6855 少々困るのは,(a)部分にペナルティが存在していない場合である.
6856 直感的に,補正すべき量$a$が0でないとき,その値をもつ\textit{penalty\_node}を作って
6857 「右空白」の(もし未定義なら\textit{Np}の)直前に挿入……
6858 ということになるが,実際には僅かにこれより複雑である.
6859 \begin{itemize}
6860 \item 「右空白」がカーンであるとき,
6861 それは「\textit{Nq}と\textit{Np}の間で改行は許されない」ことを意図している.そのため,
6862 この場合は$a\neq 0$であってもペナルティの挿入はしない.
6863 \item そうでないないときは,$a\neq 0$ならば\textit{penalty\_node}を作って挿入する.
6864 %\item 「左空白」がカーンとしてきっちり定義されている時(このとき,「右空白」はカーンでない),
6865 %この「左空白」の直後での行分割を許容しないといけないので,$a=0$であっても
6866 %\textit{penalty\_node}を作って挿入する.
6867 %\item 以上のどれでもないときは,$a\neq 0$ならば\textit{penalty\_node}を作って挿入する.
6868 \end{itemize}
6869 \end{description}
6870
6871 \def\gkf#1#2#3{\sf$\displaystyle\vphantom{\Bigg(}%
6872   \frac{\hbox to 4\zw{\hss#2\hss}}{\hbox{#3}}$}
6873 \begin{table}[t]
6874 %<en>\caption{Summary of JFM glues}
6875 %<ja>\caption{JFM グルーの概要}
6876 \label{tab-jfmglue}
6877 %<en>\medskip
6878 \begin{center}
6879 \small
6880 \begin{tabular}{c|cccccc}
6881 \toprule
6882 {\bf\textit{Np}}↓&\sf 和文A&\sf 和文B&\sf 欧文&\sf 箱&\sf glue&\sf kern\\\midrule
6883 \sf 和文A&
6884 \gkf{E}{M→K}{PN}&
6885 \gkf{---}{\OA →K}{PN}&
6886 \gkf{---}{\OA →X}{PN}&
6887 \gkf{---}{\OA}{PA}&
6888 \gkf{---}{\OA}{PN}&
6889 \gkf{---}{\OA}{PS}\\
6890 \sf 和文B&
6891 \gkf{E}{\OB→K}{PA}&
6892 \gkf{---}{K}{PS}&
6893 \gkf{---}{X}{PS}\\
6894 \sf 欧文&
6895 \gkf{E}{\OB →X}{PA}&
6896 \gkf{---}{X}{PS}\cr
6897 \sf 箱&\gkf{E}{\OB}{PA}\\
6898 \sf glue&\gkf{E}{\OB}{PN}\\
6899 \sf kern&\gkf{E}{\OB}{PS}\\
6900 \bottomrule
6901 \end{tabular}
6902 \end{center}
6903 \begin{quote}
6904 %<*en>
6905 In the table above, {\small\gkf{E}{M→K}{PN}} means that
6906 %</en>
6907 %<*ja>
6908 上の表において,{\small\gkf{E}{M→K}{PN}}は次の意味である:
6909 %</ja>
6910 \begin{enumerate}
6911 %<*en>
6912 \item To determine the ``right-space'', \LuaTeX-ja first attempts by the method ``\textsf{JFM-origin~[M]}''.
6913 If this attempt fails, \LuaTeX-ja use the method ``\textsf{\Param{kanjiskip}~[K]}''.
6914 %</en>
6915 %<*ja>
6916 \item 「右空白」を決めるために,\LuaTeX-ja はまず「JFM由来{[M]}」の方法を試みる.
6917   これが失敗したら,\LuaTeX-ja は「\Param{kanjiskip}~{[K]}」の方法を試みる.
6918 %</ja>
6919
6920 % %<*en>
6921 % \item The ``left space'' between \textit{Nq}~and~\textit{Np} is 
6922 %   determined by the method ``\textsf{line-end~[E]}''.
6923 % %</en>
6924 % %<*ja>
6925 % \item \textit{Nq} と \textit{Np} の間の「左空白」は「\textsf{line-end~[E]}」の
6926 %   方法で決定される.
6927 % %</ja>
6928
6929 %<*en>
6930 \item \LuaTeX-ja adopts the method ``\textsf{P-normal~[PN]}'' to adjust the penalty 
6931   between two clusters for \emph{kinsoku shori}.
6932 %</en>
6933 %<*ja>
6934 \item \LuaTeX-jaは2つのクラスタの間の禁則処理用のペナルティを設定するために「\textsf{P-normal~[PN]}」の方法を採用する.
6935 %</ja>
6936 \end{enumerate}
6937 \end{quote}
6938 \end{table}
6939
6940 \subsection{その他の場合}
6941 本節の内容は表\ref{tab-jfmglue}にまとめてある.
6942
6943 \paragraph{和文Aと欧文の間}
6944 \textit{Nq}が\textsf{和文A}で,\textit{Np}が\textsf{欧文}の場合,JFMグルー挿入処理は次のようにして行われる.
6945 \begin{itemize}
6946 \item 「右空白」については,まず以下に述べる\textsf{Boundary-B~[\OB]}により空白を決定しようと試みる.
6947 それが失敗した場合は,\textsf{\Param{\hyperlink{fld:xks}{xkanjiskip}}~[X]}によって定める.
6948 %\item 「左空白」については,既に述べた\textsf{line-end~[E]}をそのまま採用する.それに伴う「右空白」の補正も%同じ.
6949 \item 禁則用ペナルティも,以前述べた\textsf{P-normal~[PN]}と同じである.
6950 \end{itemize}
6951 \begin{description}
6952 \item[Boundary-B~{[\OB]}] 和文文字と「和文でないもの」との間に入る空白を以下によって求め,
6953 未定義でなければそれを「右空白」として採用する.
6954 \textsf{JFM-origin~[M]}の変種と考えて良い.
6955 これによって定まる空白の典型例は,和文の閉じ括弧と欧文文字の間に入る半角アキである.
6956 \begin{enumerate}
6957 \item もし両クラスタの間で \verb+\inhibitglue+ が実行されていた場合%
6958 (証としてwhatsitノードが自動挿入される),「右空白」は未定義.
6959 \item そうでなければ,
6960 \textit{Nq}と「文字コードが {\tt'jcharbdd'} の文字」との間に入るグルー/カーンとして定まる.
6961 \end{enumerate}
6962 \item[\Param{xkanjiskip}~{[X]}]
6963 この段階では,\textsf{\Param{kanjiskip}~[K]}のときと同じように,
6964 以下で定めた量を「右空白」として採用する.
6965 \verb+\inhibitglue+ は効力を持たない.
6966 \begin{enumerate}
6967 \item 以下のいずれかの場合は,\Param{\hyperlink{fld:xks}{xkanjiskip}}の挿入は抑止される.しかし,実際には行分割を許容するために,長さ0のglueを採用する:
6968 \begin{itemize}
6969 \item 両クラスタにおいて,それらの中身の文字コードに対する\Param{autoxspacing}パラメタが共にfalseである.
6970 \item \textit{Nq}の中身の文字コードについて,「直後への\Param{\hyperlink{fld:xks}{xkanjiskip}}の挿入」が禁止されている
6971 (つまり,\Param{jaxspmode}~(or \Param{alxspmode})パラメタが2以上).
6972 \item \textit{Np}の中身の文字コードについて,「直前への\Param{\hyperlink{fld:xks}{xkanjiskip}}の挿入」が禁止されている
6973 (つまり,\Param{jaxspmode}~(or \Param{alxspmode})パラメタが偶数).
6974 \end{itemize}
6975 \item ユーザ側から見た\Param{\hyperlink{fld:xks}{xkanjiskip}}パラメタの自然長が${\tt \textbackslash maxdimen}=(2^{30}-1)\,{\rm sp}$で
6976 なければ,\Param{\hyperlink{fld:xks}{xkanjiskip}}パラメタの値を持つglueを採用する.
6977 \item 2.でない場合は,\textit{Nq}, \textit{Np}(\textsf{和文A}/\textsf{和文B}なのは片方だけ)
6978 で使われているJFMに指定されている\Param{\hyperlink{fld:xks}{xkanjiskip}}の値を用いる.
6979 \end{enumerate}
6980 \end{description}
6981
6982 \paragraph{欧文と和文Aの間}
6983 \textit{Nq}が\textsf{欧文}で,\textit{Np}が\textsf{和文A}の場合,JFMグルー挿入処理は上の場合とほぼ同じである.
6984 \textsf{和文A}のクラスタが逆になるので,\textsf{Boundary-A~[\OA]}の部分が変わるだけ.
6985 \begin{itemize}
6986 \item 「右空白」については,まず以下に述べる\textsf{Boundary-A~[\OA]}により空白を決定しようと試みる.
6987 それが失敗した場合は,\textsf{\Param{\hyperlink{fld:xks}{xkanjiskip}}~[X]}によって定める.
6988 %\item \textit{Nq}が和文でないので,「左空白」は算出されない.
6989 \item 禁則用ペナルティは,以前述べた\textsf{P-normal~[PN]}と同じである.
6990 \end{itemize}
6991 \begin{description}
6992 \item[Boundary-A~{[\OA]}] 「和文でないもの」と和文文字との間に入る空白を以下によって求め,
6993 未定義でなければそれを「右空白」として採用する.
6994 \textsf{JFM-origin~[M]}の変種と考えて良い.
6995 これによって定まる空白の典型例は,欧文文字と和文の開き括弧との間に入る半角アキである.
6996 \begin{enumerate}
6997 \item もし両クラスタの間で \verb+\inhibitglue+ が実行されていた場合(証としてwhatsitノードが自動挿入される),次へ.
6998 \item そうでなければ,
6999 「文字コードが {\tt'jcharbdd'} の文字」と\textit{Np}との間に入るグルー/カーンとして定まる.
7000 \end{enumerate}
7001 \end{description}
7002
7003 \paragraph{和文Aと箱・グルー・カーンの間}
7004 \textit{Nq}が\textsf{和文A}で,\textit{Np}が\textsf{箱}・グルー・カーンのいずれかであった場合,
7005 両者の間に挿入されるJFMグルーについては同じ処理である.しかし,そこでの行分割に対する仕様が異なるので,
7006 ペナルティの挿入処理は若干異なったものとなっている.
7007
7008 \begin{itemize}
7009 \item 「右空白」については,既に述べた\textsf{Boundary-B~[\OB]}により空白を決定しようと試みる.
7010 それが失敗した場合は,「右空白」は挿入されない.
7011 %\item 「左空白」については,既に述べた\textsf{line-end~[E]}の算出方法をそのまま採用する.それに伴う「右空白」の補正も同じ.
7012 \item 禁則用ペナルティの処理は,後ろのクラスタ\textit{Np}の種類によって異なる.
7013 なお,$\mathit{Np}.\mathit{head}$は無意味であるから,
7014 「$\mathit{Np}.\mathit{head}$に対する\Param{\hyperlink{fld:prebp}{prebreakpenalty}}の値」は0とみなされる.言い換えれば,
7015 \[
7016  a:=(\text{\textit{Nq}の文字に対する\Param{\hyperlink{fld:postbp}{postbreakpenalty}}の値}).
7017 \]
7018 \begin{description}
7019 \item[箱] \textit{Np}が\textsf{箱}であった場合は,両クラスタの間での行分割は
7020 (明示的に両クラスタの間に \verb+\penalty10000+ があった場合を除き)いつも許容される.そのため,
7021 ペナルティ処理は,後に述べる\textsf{P-allow~[PA]}が\textsf{P-normal~[PN]}の代わりに用いられる.
7022 \item[グルー] \textit{Np}がグルーの場合,ペナルティ処理は\textsf{P-normal~[PN]}を用いる.
7023 \item[カーン] \textit{Np}がカーンであった場合は,両クラスタの間での行分割は
7024 (明示的に両クラスタの間にペナルティがあった場合を除き)許容されない.
7025 ペナルティ処理は,後に述べる\textsf{P-suppress~[PS]}を使う.
7026 \end{description}
7027 これらの\textsf{P-normal~[PN]},\textsf{P-allow~[PA]},\textsf{P-suppress~[PS]}の違いは,
7028 \textit{Nq}と\textit{Np}の間(以前の図だと(a)の部分)にペナルティが存在しない場合にのみ存在する.
7029 \end{itemize}
7030
7031 \begin{description}
7032 \item[P-allow~{[PA]}]
7033 \textit{Nq}と\textit{Np}の間の(a)部分にペナルティがあれば,\textsf{P-normal~[PN]}と同様に,
7034 それらの各ノードにおいてペナルティ値を$a$だけ増加させる.
7035
7036 (a)部分にペナルティが存在していない場合,
7037 \LuaTeX-ja は\textit{Nq}と\textit{Np}の間の行分割を可能にしようとする.
7038 そのために,以下の場合に$a$をもつ\textit{penalty\_node}を作って
7039 「右空白」の(もし未定義なら\textit{Np}の)直前に挿入する:
7040 \begin{itemize}
7041 \item 「右空白」がグルーでない(カーンか未定義)であるとき.
7042 %\item 「左空白」がカーンとしてきっちり定義されている時.
7043 \end{itemize}
7044
7045 \item[P-suppress~{[PS]}]
7046 \textit{Nq}と\textit{Np}の間の(a)部分にペナルティがあれば,\textsf{P-normal~[PN]}と同様に,
7047 それらの各ノードにおいてペナルティ値を$a$だけ増加させる.
7048
7049 (a)部分にペナルティが存在していない場合,
7050 \textit{Nq}と\textit{Np}の間の行分割は元々不可能のはずだったのであるが,
7051 \LuaTeX-ja はそれをわざわざ行分割可能にはしない.
7052 そのため,「右空白」がglueであれば,その直前に \verb+\penalty10000+ を挿入する.
7053 \end{description}
7054
7055 なお,「右空白」はカーンの%,「左空白」は未定義の
7056 \[
7057  \overbrace{\Node{glyph}{`あ'}}^{\mathit{Nq}}\longrightarrow \overbrace{\Node{glue}{1\,pt}}^{\mathit{Np}}
7058 \]
7059 のような状況を考える.
7060 このとき,$a$,即ち「あ」の\Param{\hyperlink{fld:postbp}{postbreakpenalty}}がいかなる値であっても,
7061 この2クラスタ間は最終的に
7062 \begin{equation}
7063  \overbrace{\Node{glyph}{`あ'}}^{\mathit{Nq}}\longrightarrow
7064 \Node{kern}{右空白}\longrightarrow \overbrace{\Node{glue}{1\,pt}}^{\mathit{Np}}
7065 \label{eq-gref}
7066 \end{equation}
7067 となり,$a$分のペナルティは挿入されないことに注意して欲しい.
7068 \Param{\hyperlink{fld:postbp}{postbreakpenalty}}は($a$は)殆どの場合が非負の値と考えられ,そのような場合では
7069 \eqref{eq-gref}と
7070 \[
7071  \overbrace{\Node{glyph}{`あ'}}^{\mathit{Nq}}\longrightarrow
7072 \Node{penalty}{$a$}\longrightarrow
7073 \Node{kern}{右空白}\longrightarrow \overbrace{\Node{glue}{1\,pt}}^{\mathit{Np}}
7074 \]
7075 との間に差異は生じない%
7076 \footnote{kern$\rightarrow$glueが1つの行分割可能点(行分割に伴うペナルティは0)
7077 であるため,たとえ$a=10000$であっても,\textit{Nq}と\textit{Np}の間で行分割を禁止することはできない.}.
7078
7079 \paragraph{箱・グルー・カーンと和文Aの間}
7080 \textit{Np}が\textsf{箱}・グルー・カーンのいずれかで,\textit{Np}が\textsf{和文A}であった場合は,
7081 すぐ上の(\textit{Nq}と\textit{Np}の順序が逆になっている)場合と同じである.
7082 %が,「左空白」がなくなることにのみ注意.
7083 \begin{itemize}
7084 \item 「右空白」については,既に述べた\textsf{Boundary-A~[\OA]}により空白を決定しようと試みる.
7085 それが失敗した場合は,「右空白」は挿入されない.
7086 %\item \textit{Nq}が和文でないので,「左空白」は算出されない.
7087 \item 禁則用ペナルティの処理は,\textit{Nq}の種類によって異なる.
7088 $\mathit{Nq}.\mathit{tail}$は無意味なので,
7089 \[
7090  a:=(\text{\textit{Np}の文字に対する\Param{\hyperlink{fld:prebp}{prebreakpenalty}}の値}).
7091 \]
7092 \begin{description}
7093 \item[箱] \textit{Nq}が\textsf{箱}の場合は,\textsf{P-allow~[PA]}を用いる.
7094 \item[グルー] \textit{Nq}がグルーの場合は,\textsf{P-normal~[PN]}を用いる.
7095 \item[カーン] \textit{Nq}がカーンの場合は,\textsf{P-suppress~[PS]}を用いる.
7096 \end{description}
7097 \end{itemize}
7098
7099 \paragraph{和文Aと和文Bの違い}
7100 先に述べたように,\textsf{和文B}はhboxの中身の先頭(or 末尾)として出現している
7101 和文文字である.リスト内に直接ノードとして現れている和文文字(\textsf{和文A})との違いは,
7102 \begin{itemize}
7103 \item \textsf{和文B}に対しては,JFMの文字クラス指定から定まる空白
7104 \textsf{JFM-origin~[M]},\textsf{Boundary-A~[\OA]},\textsf{Boundary-B~[\OB]})の挿入は行われない.
7105 %「左空白」の算出も行われない.
7106 例えば,
7107 \begin{itemize}
7108 \item 片方が\textsf{和文A},もう片方が\textsf{和文B}のクラスタの場合,
7109 \textsf{Boundary-A~[\OA]}または\textsf{Boundary-B~[\OB]}の挿入を試み,それがダメなら
7110 \Param{kanjiskip}~\textsf{[K]}の挿入を行う.
7111 \item \textsf{和文B}の2つのクラスタの間には,\Param{kanjiskip}~\textsf{[K]}が自動的に入る.
7112 \end{itemize}
7113 \item \textsf{和文B}と箱・グルー・カーンが隣接したとき(どちらが前かは関係ない),間にJFMグルー・ペナルティの挿入は一切しない.
7114 \item \textsf{和文B}と\textsf{和文B},また\textsf{和文B}と\textsf{欧文}とが隣接した時は,禁則用ペナルティ挿入処理は
7115 \textsf{P-suppress~[PS]}が用いられる.
7116 \item \textsf{和文B}の文字に対する\Param{\hyperlink{fld:prebp}{prebreakpenalty}},~\Param{\hyperlink{fld:postbp}{postbreakpenalty}}の値は使われず,0として計算される.
7117 \end{itemize}
7118
7119
7120 次が具体例である:
7121 \begin{LTXexample}
7122 あ.\inhibitglue A\\
7123 \hbox{あ.}A\\
7124 あ.A
7125 \end{LTXexample}
7126 \begin{itemize}
7127 \item 1行目の\verb+\inhibitglue+は\textsf{Boundary-B~[\OB]}の処理のみを抑止するので,ピリオドと「A」の間には
7128 \Param{\hyperlink{fld:xks}{xkanjiskip}}(四分アキ)が入ることに注意.
7129 \item 2行目のピリオドと「A」の間においては,前者が\textsf{和文B}となる(hboxの中身の末尾として登場しているから)ので,
7130 そもそも\textsf{Boundary-B~[\OB]}の処理は行われない.よって,\Param{\hyperlink{fld:xks}{xkanjiskip}}が入ることとなる.
7131 \item 3行目では,ピリオドの属するクラスタは\textsf{和文A}である.これによって,
7132 ピリオドと「A」の間には\textsf{Boundary-B~[\OB]}由来の半角アキが入ることになる.
7133 \end{itemize}
7134 %</ja>
7135
7136 %<en>\section{Patch for the \Pkg{listings} Package}
7137 %<ja>\section{\Pkg{listings} パッケージへの対応}
7138
7139 %<*en>
7140 It is well-known that the \Pkg{listings} package outputs weird results
7141 for Japanese input.
7142 The \Pkg{listings} package makes most of letters active and assigns
7143 output command for each letter~(\cite{listings}).
7144 But Japanese characters are not included in these activated letters.
7145 For \pTeX{} series, there is no method to make Japanese characters active;
7146 a patch \Pkg{jlisting.sty}~(\cite{jlisting}) resolves the problem forcibly.
7147 %</en>
7148 %<*ja>
7149 \Pkg{listings} パッケージが,そのままでは日本語をまともに出力できないこと
7150 はよく知られている.きちんと整形して出力するために,\Pkg{listings}パッケー
7151 ジは内部で「ほとんどの文字」をアクティブにし,各文字に対してその文字の出
7152 力命令を割り当てている(\cite{listings}).
7153 しかし,そこでアクティブにする文字の中に,和文文
7154 字がないためである.\pTeX 系列では,和文文字をアクティブにする手法がなく,
7155 \Pkg{jlisting.sty} というパッチ(\cite{jlisting})を用いることで無理やり解決していた.
7156 %</ja>
7157
7158 %<*en>
7159 In \LuaTeX-ja, the problem is resolved by using the \verb+process_input_buffer+ callback.
7160 The callback function inserts the output command (active character \texttt{U+FFFFF})
7161 before each letter above \texttt{U+0080}.
7162 This method can omits the process to make all Japanese characters active
7163 (most of the activated characters are not used in many cases).
7164 %</en>
7165 %<*ja>
7166 \LuaTeX-jaでは,\verb+process_input_buffer+ コールバックを利用することで,
7167 「各行に出現する\texttt{U+0080}以降の文字に対して,それらの出力命令を前置する」
7168 という方法をとっている.出力命令としては,アクティブ文字化した \texttt{U+FFFFF} を用いている.
7169 これにより,(入力には使用されていないかもしれない)和文文字をもすべてアクティブ化する手間もなく,
7170 見通しが良い実装になっている.
7171 %</ja>
7172
7173
7174 %<*en>
7175 If the \Pkg{listings} package  and \LuaTeX-ja were loaded,
7176 then the patch \Pkg{lltjp-listings} is loaded automatically at \verb+\begin{document}+.
7177 %</en>
7178 %<*ja>
7179 \LuaTeX-ja で利用される \Pkg{listings} パッケージへのパッチ \Pkg{lltjp-listings} は,
7180 \Pkg{listings} と\LuaTeX-jaを読み込んでおけば,
7181 \verb+\begin{document}+ の箇所において自動的に読み込まれるので,通常はあまり
7182 意識する必要はない.
7183 %</ja>
7184
7185 %<en>\subsection{Notes}
7186 %<ja>\subsection{注意}
7187 %<*en>
7188 \paragraph{Escaping to \LaTeX}
7189 We used the \verb+process_input_buffer+ callback to output \textbf{JAchar}s.
7190 But it has a drawback; any commands whose name contains a \textbf{JAchar}
7191 cannot be used in any ``escape to \LaTeX''.
7192
7193 Consider the following input:
7194 %</en>
7195 %<*ja>
7196 \paragraph{\LaTeX へのエスケープ}
7197 日本語対応を行うために \verb+process_input_buffer+ を使用したことで,
7198 \texttt{texcl},~\texttt{escapeinside}といった\emph{「\LaTeX へのエスケープ」中では,
7199 \textbf{JAchar}を名称の一部に含む制御綴は使用不可能}である.
7200 例えば次のような入力を考えよう:
7201 %</ja>
7202 \begin{verbatim*}
7203 \begin{lstlisting}[escapechar=\#]
7204 #\ほげ xぴよ#
7205 \end{lstlisting}
7206 \end{verbatim*}
7207 %<en>The line~2 is transformed by the callback to
7208 %<ja>ここで,2行目は \verb+process_input_buffer+ の作用により,
7209 \begin{lstlisting}[showspaces, escapechar=\!]
7210 #\!\IVSA FFFFF!ほ!\IVSA FFFFF !げ x!\IVSA FFFFF !ぴ!\IVSA FFFFF !よ#
7211 \end{lstlisting}
7212 %<*en>
7213 before the line is actually processed.
7214 In the escape (between the character ``\verb+#+''), 
7215 the category code of \texttt{U+FFFFF} is set to 9~(\emph{ignored}).
7216 Hence the control symbol ``\verb+\+\IVSA FFFFF'' will be executed,
7217 instead of ``\verb+\ほげ+''.
7218 %</en>
7219 %<*ja>
7220 と変換されてから,実際の処理に回される.
7221 「\verb+#+」で挟まれた「\LaTeX へのエスケープ」中では\
7222 \texttt{U+FFFFF} のカテゴリーコードは9~(\textit{ignored})となるので,
7223 結局「\verb+\ほげ+」の代わりに
7224 「\verb+\+\IVSA FFFFF」というcontrol symbolが実行されることになる.
7225 %</ja>
7226
7227 %<*ja>
7228 \paragraph{異体字セレクタの扱い}
7229 \texttt{lstlisting} 環境などの内部にある異体字セレクタを扱うため,
7230 \Pkg{lltjp-listings} では \texttt{vsraw} と \texttt{vscmd} という2つのキーを追加した.
7231 しかし,\Pkg{lltjp-listings} が実際にロードされるのは \verb+\begin{document}+\ 
7232 のところであるので,プリアンブル内ではこれらの追加キーは使用できない.
7233
7234 \texttt{vsraw}は,ブール値の値をとるキーであり,標準ではfalseである.
7235 \begin{itemize}
7236  \item trueの場合は,異体字セレクタは「直前の文字に続けて」出力される.
7237 もしもIVSサポート(\ref{ssec-ltjotf}節)が有効になっていた場合は,
7238 以下の例(左側は入力,右側はその出力)のようになる.
7239 \begin{LTXexample}
7240 \begin{lstlisting}[vsraw=true]
7241 葛󠄀城市,葛󠄁飾区,葛西
7242 \end{lstlisting}
7243 \end{LTXexample}
7244 \item falseの場合は,異体字セレクタは適当な命令によって「見える形で」出力される.
7245 どのような形で出力されるかを規定するのが \texttt{vscmd} キーであり,
7246 \Pkg{lltjp-listings} の標準設定では以下の例の右側のように出力される.
7247 \begin{LTXexample}
7248 \begin{lstlisting}[vsraw=false, 
7249    vscmd=\ltjlistingsvsstdcmd]
7250 葛󠄀城市,葛󠄁飾区,葛西
7251 \end{lstlisting}
7252 \end{LTXexample}
7253 ちなみに,本ドキュメントでは次のようにしている:
7254 \begin{lstlisting}[numbers=left]
7255 \def\IVSA#1#2#3#4#5{%
7256   \textcolor{blue}{\raisebox{3.5pt}{\tt%
7257     \fboxsep=0.5pt\fbox{\tiny \oalign{0#1#2\crcr#3#4#5\crcr}}}}%
7258 }
7259 {\catcode`\%=11
7260   \gdef\IVSB#1{\expandafter\IVSA\directlua{
7261     local cat_str = luatexbase.catcodetables['string']
7262     tex.sprint(cat_str, string.format('%X', 0xE00EF+#1))
7263 }}}
7264 \lstset{vscmd=\IVSB}
7265 \end{lstlisting}
7266 \end{itemize}
7267 既定の出力命令を復活させたい場合は\ \verb+vsraw=\ltjlistingsvsstdcmd+\ 
7268 とすれば良い.
7269 %</ja>
7270
7271 %<en>\subsection{Class of Characters}
7272 %<ja>\subsection{文字種}
7273
7274 %<en>Roughly speaking, the \Pkg{listings} package processes input as follows:
7275 %<ja>\Pkg{listings} パッケージの内部では,大雑把に言うと
7276 \begin{enumerate}
7277 %<en>\item Collects \textit{letters} and \textit{digits}, which can be used for the name of identifiers.
7278 %<ja>\item 識別子として使える文字 (``letter'',~``digit'') たちを集める.
7279 %<en>\item When reading an \textit{other}, outputs the collected character string (with modification, if needed).
7280 %<ja>\item letterでもdigitでもない文字が現れた時に,収集した文字列を(必要なら修飾して)出力する.
7281 %<en>\item Collects \textit{others}.
7282 %<ja>\item 今度は逆に,letterでない文字たちをletterが現れるまで集める.
7283 %<en>\item When reading a \textit{letter} or a \textit{digit}, outputs the collected character string.
7284 %<ja>\item letterが出現したら集めた文字列を出力する.
7285 %<en>\item Turns back to 1.
7286 %<ja>\item 1.に戻る.
7287 \end{enumerate}
7288 %<*en>
7289 By the above process, line breaks inside of an identifier are blocked.
7290 A flag \verb+\lst@ifletter+ indicates whether the previous character can be used
7291 for the name of identifiers or not.
7292 %</en>
7293 %<*ja>
7294 という処理が行われている.これにより,識別子の途中では行分割が行われないようになっている.
7295 直前の文字が識別子として使えるか否かは \verb+\lst@ifletter+ というフラグに格納されている.
7296 %</ja>
7297
7298 %<*en>
7299 For Japanese characters, line breaks are permitted on both sides
7300 except for brackets, dashes, etc.
7301 Hence the patch \Pkg{lltjp-listings} introduces 
7302 a new flag \verb+\lst@ifkanji+, which indicates
7303 whether the previous character is a Japanese character or not.
7304 For illustration, we introduce following classes of characters:
7305 %</en>
7306 %<*ja>
7307 さて,日本語の処理である.殆どの和文文字の前後では行分割が可能であるが,その一方で
7308 括弧類や音引きなどでは禁則処理が必要なことから,\Pkg{lltjp-listings} では,
7309 直前が和文文字であるかを示すフラグ \verb+\lst@ifkanji+ を新たに導入した.
7310 以降,説明のために以下のように文字を分類する:
7311 %</ja>
7312 \begin{center}
7313 \small
7314 \begin{tabular}{lccccc}
7315 \toprule
7316 &Letter&Other&Kanji&Open&Close\\\midrule
7317 \verb+\lst@ifletter+&T&F&T&F&T\\
7318 \verb+\lst@ifkanji+&F&F&T&T&F\\
7319 %<en>Meaning&char in an identifier&other alphabet&%
7320 %<en>most of Japanese char&opening brackets&closing brackets\\
7321 %<ja>意図&識別子中の文字&その他欧文文字&殆どの和文文字&開き括弧類&閉じ括弧類\\
7322 \bottomrule
7323 \end{tabular}
7324 \end{center}
7325 %<*en>
7326 Note that \textit{digits} in the \Pkg{listings} package can be Letter or
7327 Other according to circumstances.
7328 %</en>
7329 %<*ja>
7330 なお,本来の\Pkg{listings} パッケージでの分類``digit''は,
7331 出現状況によって,上の表のLetterとOtherのどちらにもなりうる.
7332 また,KanjiとCloseは \verb+\lst@ifletter+ と \verb+\lst@ifkanji+ の値が一致しているが,
7333 これは間違いではない.
7334 %</ja>
7335
7336 %<*en>
7337 For example, let us consider the case an Open comes after a Letter.
7338 Since an Open represents Japanese open brackets,
7339 it is preferred to be permitted to insert line break after the Letter.
7340 Therefore, the collected character string is output in this case.
7341 %</en>
7342 %<*ja>
7343 例えば,Letterの直後にOpenが来た場合を考える.
7344 文字種Openは和文開き括弧類を想定しているので,Letterの直後では行分割が可能であることが望ましい.
7345 そのため,この場合では,すでに収集されている文字列を出力することで行分割を許容するようにした.
7346 %</ja>
7347
7348 %<*en>
7349 The following table summarizes $5\times 5=25$ cases:
7350 %</en>
7351 %<*ja>
7352 同じように,$5\times 5=25$通り全てについて書くと,次のようになる:
7353 %</ja>
7354 \begin{center}
7355 \small
7356 \begin{tabular}{llccccc}
7357 \toprule
7358 %<*en>
7359 &&\multicolumn{4}{c}{Next}\\\cmidrule(lr){3-7}
7360 &&\hbox to 4em{\hss Letter\hss}&\hbox to 4em{\hss Other\hss}
7361 &\hbox to 4em{\hss Kanji\hss}&\hbox to 4em{\hss Open\hss}&Close\\\midrule
7362 &Letter&collects&\multicolumn{3}{c}{\hrulefill \ outputs\ \hrulefill}&collects\\
7363 &Other&outputs&collects&\multicolumn{2}{c}{\hrulefill \ outputs\ \hrulefill}&collects\\
7364 Prev&Kanji&\multicolumn{4}{c}{\hrulefill \ outputs\ \hrulefill}&collects\\
7365 &Open&\multicolumn{5}{c}{\hrulefill \ collects\ \hrulefill}\\
7366 &Close&\multicolumn{4}{c}{\hrulefill \ outputs\ \hrulefill}&collects\\
7367 %</en>
7368 %<*ja>
7369 &&\multicolumn{4}{c}{後ろ側の文字}\\\cmidrule(lr){3-7}
7370 &&\hbox to 4em{\hss Letter\hss}&\hbox to 4em{\hss Other\hss}
7371 &\hbox to 4em{\hss Kanji\hss}&\hbox to 4em{\hss Open\hss}&Close\\\midrule
7372 直&Letter&収集&\multicolumn{3}{c}{\hrulefill \ 出力\ \hrulefill}&収集\\
7373 前&Other&出力&収集&\multicolumn{2}{c}{\hrulefill \ 出力\ \hrulefill}&収集\\
7374 文&Kanji&\multicolumn{4}{c}{\hrulefill \ 出力\ \hrulefill}&収集\\
7375 字&Open&\multicolumn{5}{c}{\hrulefill \ 収集\ \hrulefill}\\
7376 種&Close&\multicolumn{4}{c}{\hrulefill \ 出力\ \hrulefill}&収集\\
7377 %</ja>
7378 \bottomrule
7379 \end{tabular}
7380 \end{center}
7381 %<en>In the above table,
7382 %<ja>上の表において,
7383 \begin{itemize}
7384 %<en>\item ``outputs'' means to output the collected character string (i.e., line breaking is permitted there).
7385 %<ja>\item 「出力」は,それまでに集めた文字列を出力(≒ここで行分割可能)を意味する.
7386
7387 %<en>\item ``collects'' means to append the next character to the collected character string (i.e., line breaking is prohibited there).
7388 %<ja>\item 「収集」は,後側の文字を,現在収集された文字列に追加(行分割不可)を意味する.
7389 \end{itemize}
7390
7391 %<*en> 
7392 Charatcers above \texttt{U+0080} \emph{except Variation Selectors}
7393 are classified into above 5~classes by the following rules:
7394 %</en>
7395 %<*ja>
7396 \texttt{U+0080}以降の\emph{異体字セレクタ以外の}各文字が
7397 Letter, Other, Kanji, Open, Closeのどれに属するかは次によって決まる:
7398 %</ja>
7399 \begin{itemize}
7400 %<en>\item \textbf{ALchar}s above \texttt{U+0080} are classified as Letter.
7401 %<ja>\item (\texttt{U+0080}以降の)\textbf{ALchar}は,すべてLetter扱いである.
7402
7403 %<en>\item \textbf{JAchar}s are classified in the order as follows:
7404 %<ja>\item \textbf{JAchar}については,以下の順序に従って文字種を決める:
7405 \begin{enumerate}
7406 %<en>\item Characters whose \Param{\hyperlink{fld:prebp}{prebreakpenalty}} is greater than or equal to 0 are classified as Open.
7407 %<ja>\item \Param{\hyperlink{fld:prebp}{prebreakpenalty}}が0以上の文字はOpen扱いである.
7408
7409 %<en>\item Characters whose \Param{\hyperlink{fld:postbp}{postbreakpenalty}} is greater than or equal to 0 are classified as Close.
7410 %<ja>\item \Param{\hyperlink{fld:postbp}{postbreakpenalty}}が0以上の文字はClose扱いである.
7411
7412 %<en>\item Characters that don't satisfy the above two conditions are classified as Kanji.
7413 %<ja>\item 上の3条件のどちらにも当てはまらなかった文字は,Kanji扱いである.
7414 \end{enumerate}
7415 \end{itemize}
7416
7417 %<*en>
7418 The width of halfwidth kana (\texttt{U+FF61}--\texttt{U+FF9F}) 
7419 is same as the width of \textbf{ALchar};
7420 the width of the other \textbf{JAchar}s is double the width of \textbf{ALchar}.
7421 %</en>
7422 %<*ja>
7423 なお,半角カナ(U+FF61--U+FF9F)以外の\textbf{JAchar}は欧文文字2文字分の幅をとるものとみなされる.
7424 半角カナは欧文文字1文字分の幅となる.
7425 %</ja>
7426
7427 %<*en>
7428 This classification process is executed every time a character appears in
7429 the \texttt{lstlisting} environment or other environments/commands.
7430 %</en>
7431 %<*ja>
7432 これらの文字種決定は,実際に \texttt{lstlisting} 環境などの内部で文字が出てくるたびに行われる.
7433 %</ja>
7434
7435 %<*ja>
7436 \section{和文の行長補正方法}
7437 \label{sec-adjspec}
7438 \Pkg{luatexja-adjust} で提供される優先順位付きの行長調整の詳細を述
7439 べる.大まかに述べると,次のようになる.
7440 \begin{itemize}
7441 \item 通常の\TeX の行分割方法に従って,段落を行分割する.この段階では,行
7442       長に半端が出た場合,その半端分は\textbf{JAglue}(\Param{\hyperlink{fld:xks}{xkanjiskip}},
7443       \Param{\hyperlink{fld:kanjiskip}{kanjiskip}},JFMグルー)と
7444       それ以外のグルーの全てで(優先順位なく)負担される.
7445 \item その後,\texttt{post\_linebreak\_filter} callbackを使い,\emph{段
7446       落中の各行ごとに},行末文字の位置を調整したり,優先度付きの行長調整
7447       を実現するためにグルーの伸縮度を調整する.
7448       その処理においては,グルーの自然長と\textbf{JAglue}以外の
7449       グルーの伸び量・縮み量は変更せず,必要に応じて\textbf{JAglue}の伸び量・縮み量のみを
7450       変更する設計とした.
7451
7452 \Pkg{luatexja-adjust} の作用は,この処理を行うcallbackを追加するだけであり,
7453       この章の残りではcallbackでの処理について解説する.
7454 \end{itemize}
7455
7456 \paragraph{準備:合計伸縮量の計算}
7457 グルーの伸縮度(\texttt{plus} や \texttt{minus} で指定されている値)には,
7458 有限値の他に,\texttt{fi},\texttt{fil},\texttt{fill},\texttt{filll}と
7459 いう4つの無限大レベル(後ろの方ほど大きい)があり,行の調整に
7460 \texttt{fi} などの\emph{無限大レベルの伸縮度が用いられている場合は,そ
7461 の行に対しての処理を中止}する.
7462
7463 よって,以降,問題にしている行の行長調整は伸縮度が有限長のグルーを用いて
7464 行われているとして良い.さらに,簡単のため,この行はグルーが広げられている
7465 (自然長で組むと望ましい行長よりの短い)場合しか扱わない.
7466
7467 まず,段落中の行中のグルーを
7468 \begin{itemize}
7469 \item \textbf{JAglue}ではないグルー
7470 \item JFMグルー(優先度\footnote{%
7471   \ref{ssec-jfm-str}節にあるように,
7472   各JFMグルーには$-2$から2までの優先度がついている.}%
7473 別にまとめられる)
7474 \item 和欧文間空白(\Param{\hyperlink{fld:xks}{xkanjiskip}})
7475 \item 和文間空白(\Param{\hyperlink{fld:kanjiskip}{kanjiskip}})
7476 \end{itemize}
7477 の$1+1+5+1=8$つに類別し,それぞれの種別ごとに
7478 許容されている伸び量(\texttt{stretch}の値)の合計を計算する.
7479 また,行長と自然長との差を\textit{total}とおく.
7480
7481
7482 \subsection{行末文字の位置調整}
7483 行末が文字クラス$n$の\textbf{JAchar}であった場合,
7484 それを動かすことによって,\textit{total}のうち
7485 \textbf{JAglue}が負担する分を少なくしようとする.
7486 この行末文字の左右の移動可能量は,
7487 JFM中にある文字クラス$n$の定義の
7488 \texttt{end\_stretch},~\texttt{end\_shrink}フィールドに
7489 全角単位の値として記述されている.
7490
7491 例えば,行末文字が句点「。」であり,そこで用いられているJFM中に
7492 \begin{verbatim}
7493   [2] = {
7494     chars = { '。', ... }, width = 0.5, ...,
7495     end_stretch = 0.5, end_shrink = 0.5,
7496   }, 
7497 \end{verbatim}
7498 という指定があった場合,この行末の句点は
7499 \begin{itemize}
7500 \item 通常の\TeX の行分割処理で「半角以上の詰め」が行われていた場合,
7501 この行中の\textbf{JAglue}の負担を軽減するため,
7502 行末の句点を半角だけ右に移動する(ぶら下げ組を行う).
7503 \item 通常の\TeX の行分割処理で「半角以上の空き」が行われていた場合,
7504 逆に行末句点を半角左に移動させる(見た目的に全角取りとなる).
7505 \item 以上のどちらでもない場合,行末句点の位置調整は行わない.
7506 \end{itemize}
7507 となる.
7508
7509 行末文字を移動した場合,その分だけ\textit{total}の値を引いておく.
7510
7511 \subsection{グルーの調整}
7512 \textit{total}の分だけが,行中のグルーの伸び量に応じて負担されることになる.
7513 負担するグルーの優先度は以下の順であり,
7514 できるだけ\Param{\hyperlink{fld:kanjiskip}{kanjiskip}}を自然長のままにすることを
7515 試みている.
7516 \begin{enumerate}\def\labelenumi{(\Alph{enumi})}
7517  \item \textbf{JAglue}以外のグルー
7518  \item 優先度2のJFMグルー
7519  \item 優先度1のJFMグルー
7520  \item 優先度0のJFMグルー
7521  \item 優先度$-1$のJFMグルー
7522  \item 優先度$-2$のJFMグルー
7523  \item \Param{\hyperlink{fld:xks}{xkanjiskip}}
7524  \item \Param{\hyperlink{fld:kanjiskip}{kanjiskip}}
7525 \end{enumerate}
7526 \begin{enumerate}
7527  \item 行末の和文文字を移動したことで$\textit{total}=0$となれば,
7528 調整の必要はなく,行が格納されているhboxの
7529 \texttt{glue\_set}, \texttt{glue\_sign}, \texttt{glue\_order}を再計算すればよい.
7530 以降,$\textit{total}\neq 0$と仮定する.
7531  \item \textit{total}が「\textbf{JAglue}以外のグルーの伸び量の合計」(以下,(A)の伸び量の
7532        合計,と称す)よりも小さければ,
7533 それらのグルーに\textit{total}を負担させ,\textbf{JAglue}達自身は自然長で組むことができる.
7534 よって,以下の処理を行う:
7535 \begin{enumerate}
7536 \item 各\textbf{JAglue}の伸び量を0とする.
7537 \item 行が格納されているhboxの
7538 \texttt{glue\_set}, \texttt{glue\_sign}, \texttt{glue\_order}を再計算する.
7539 これによって,\textit{total}は\textbf{JAglue}以外のグルーによって負担される.
7540 \end{enumerate}
7541 \item \textit{total}が「(A)の伸び量の合計」以上ならば,(A)--(H)のどこまで負担すれば
7542 \textit{total}以上になるかを計算する.
7543 例えば,
7544 \[\catcode`\<=12
7545  \textit{total} = (\text{(A)--(B)の伸び量の合計}) + p\cdot (\text{(C)の伸び量の合計}),
7546  \qquad 0\le p<1
7547 \]
7548 であった場合,各グルーは次のように組まれる:
7549 \begin{itemize}
7550  \item (A),~(B)に属するグルーは各グルーで許された伸び量まで伸ばす.
7551  \item (C)に属するグルーはそれぞれ$p\times (\text{伸び量})$だけ伸びる.
7552  \item (D)--(H)に属するグルーは自然長のまま.
7553 \end{itemize}
7554 実際には,前に述べた「設計」に従い,次のように処理している:
7555 \begin{enumerate}
7556 \item (C)に属するグルーの伸び量を$p$倍する.
7557 \item (D)--(H)に属するグルーの伸び量を0とする.
7558 \item 行が格納されているhboxの
7559 \texttt{glue\_set}, \texttt{glue\_sign}, \texttt{glue\_order}を再計算する.
7560 これによって,\textit{total}は\textbf{JAglue}以外のグルーによって負担される.
7561 \end{enumerate}
7562 \item \textit{total}が(A)--(H)の伸び量の合計よりも大きい場合,どうしようもないので
7563       \verb+^^;+何もしない.
7564 \end{enumerate}
7565
7566 %</ja>
7567
7568 %<*ja>
7569 \section{IVS対応}
7570 \verb+luatexja.otf.enable_ivs()+ を実行し,IVS対応を有効にした状態では,
7571 \verb+pre_linebreak_filter+ や \verb+hpack_filter+ コールバックには
7572 次の4つが順に実行される状態となっている:
7573 \begin{description}
7574 \item[\tt ltj.do\_ivs] \textit{glyph\_node}~$p$の直後に,異体字セレクタ(を表す\textit{glyph\_node})
7575 が連続した場合に,$p$のフォントに対応したが持つ「異体字情報」に従って出力するグリフを変える.
7576
7577 しかし,単に$p.\textit{char}$を変更するだけでは,後から
7578 font featureの適用(すぐ下)により置換される可能性がある.そのため,
7579 \verb+\CID+ や \verb+\UTF+ と同じように,\textit{glyph\_node}~$p$の代わりに
7580 \texttt{user\_id} が\textit{char\_by\_cid}であるようなuser-defined whatsitを用いている.
7581 \item[(\Pkg{luaotfload} によるfont featureの適用)]
7582 \item[\tt ltj.otf] \texttt{user\_id} が\textit{char\_by\_cid}であるようなuser-defined whatsitを
7583 きちんと\textit{glyph\_node}に変換する.この処理は,\verb+\CID+, \verb+\UTF+やIVSによる置換が,
7584 font featureの適用で上書きされてしまうのを防止するためである.
7585 \item[\tt ltj.main\_process] \textbf{JAglue}の挿入処理(\ref{sec-jfmglue}章)と,
7586 JFMの指定に従って各\textbf{JAchar}の「寸法を補正」することを行う.
7587 \end{description}
7588
7589 問題は各フォントの持っているIVS情報をどのように取得するか,である.
7590 \Pkg{luaotfload} はフォント番号<font\_number>の情報を\ 
7591 \texttt{fonts.hashes.identifiers[<font\_number>]} 以下に格納している.
7592 しかし,OpenTypeフォントのIVS情報は格納されていないようである%
7593 \footnote{TrueTypeフォントに関しては,
7594 \begin{center}
7595 \texttt{fonts.hashes.idenfiers[<font\_number>]%
7596   .resources.variants[<selector>][<base\_char>]}
7597 \end{center}
7598 に,<base\_char>番の文字の後に異体字セレクタ<selector>が続いた場合に
7599 出力すべきグリフが書かれてある.}.
7600 %例えば,小塚明朝Pr6N~Rでは,
7601
7602 一方,\LuaTeX 内部の \texttt{fontloader} の返すテーブルには
7603 OpenTypeフォントでもTrueTypeフォントでもIVS情報が格納されている.
7604 具体的には……
7605
7606 そのため,\LuaTeX-jaのIVS対応においては,\LuaTeX 内部の\ 
7607 \texttt{fontloader} を直接用いることで,フォントのIVS情報を取得している.
7608 20140114.0以降でキャッシュを用いるようにした要因はここにあり,
7609 \texttt{fontloader} の呼び出しでかなり時間を消費することから,
7610 %%% to_table を使わなくしたことで,メモリ使用量は減った
7611 IVS情報をキャッシュに保存することで2回目以降の実行時間を節約している.
7612
7613
7614 \section{複数フォントの「合成」(未完)}
7615
7616 \section{\LuaTeX-jaにおけるキャッシュ}
7617 \Pkg{luaotfload}パッケージが,各TrueType・]OpenTypeフォントの情報を
7618 キャッシュとして保存しているのと同様の方法で,
7619 \LuaTeX-jaもいくつかのキャッシュファイルを作成するようになった.
7620 \begin{itemize}
7621  \item 通常,キャッシュは\texttt{\$TEXMFVAR/luatexja/}以下に保存され,
7622 そこから読み込みが行われる.
7623  \item 「通常の」テキスト形式のキャッシュ(拡張子は \texttt{.lua})以外にも,
7624 それをバイナリ形式(バイトコード)に変換したものもサポートしている.
7625 \begin{itemize}
7626  \item \LuaTeX とLuaJIT\TeX ではバイトコードの形式が異なるため,バイナリ形式の
7627 キャッシュは共有できない.\LuaTeX 用のバイナリキャッシュは \texttt{.luc},
7628 LuaJIT\TeX 用のは \texttt{.lub} と拡張子を変えることで対応している.
7629  \item キャッシュを読み込む時,同名のバイナリキャッシュがあれば,
7630 テキスト形式のものよりそちらを優先して読み込む.
7631  \item テキスト形式のキャッシュが更新/作成される際は,そのバイナリ版も
7632 同時に更新される.
7633 また,(バイナリ版が見つからず)テキスト形式のキャッシュ側が読み込まれたときは,
7634 \LuaTeX-jaはバイナリキャッシュを作成する.
7635 \end{itemize}
7636 \end{itemize}
7637 %</ja>
7638 %<*en>
7639 \section{Cache Management of \LuaTeX-ja}
7640 \LuaTeX-ja creates some cache files to reduce the loading time. 
7641 in a similar way to the \Pkg{luaotfload} package:
7642 \begin{itemize}
7643  \item Cache files are usually stored in (and loaded from)
7644 \texttt{\$TEXMFVAR/luatexja/}.
7645  \item In addition to caches of the text form (the extension is ``\texttt{.lua}''),
7646 caches of the \emph{binary}, precompiled form are supported.
7647 \begin{itemize}
7648  \item We cannot share same binary cache for \LuaTeX\ and LuaJIT\TeX.
7649 Hence we distinguish them by their extension, ``\texttt{.luc}'' for \LuaTeX\
7650 and ``\texttt{.lub}'' for LuaJIT\TeX.
7651  \item In loading a cache, the binary cache precedes 
7652 the text form.
7653  \item When \LuaTeX-ja updates a cache \texttt{hoge.lua}, 
7654 its binary version is also updated.
7655 \end{itemize}
7656 \end{itemize}
7657 %</en>
7658
7659 %<*ja>
7660 \subsection{キャッシュの使用箇所}
7661
7662 \LuaTeX-ja では以下の3種類のキャッシュを使用している:
7663 \begin{list}{}%
7664 {\def\makelabel#1{\ttfamily#1}}
7665 \item[ltj-cid-auto-adobe-japan1.lua] 
7666 Ryumin-Lightのような非埋め込みフォントの情報を格納しており,
7667 (それらが\LuaTeX-jaの標準和文フォントなので)\LuaTeX-jaの読み込み時に自動で読まれる.
7668 生成には\texttt{UniJIS2004-UTF32-H}, \texttt{Adobe-Japan1-UCS2}という2つの
7669 CMapが必要である.
7670
7671 \pageref{para-cid}ページで述べたように,\texttt{cid}キーを使って
7672 非埋め込みの中国語・韓国語フォントを定義する場合,同様のキャッシュが生成される.
7673 キャッシュの名称,必要となるCMapについては表\ref{tab:cid-cache}を参照して欲しい.
7674
7675 \item[ivs\_***.lua]
7676 フォント``\texttt{***}''における異体字情報を格納している.構造は以下の通り:
7677 %</ja>
7678 %<*en>
7679 \subsection{Use of Cache}
7680
7681 \LuaTeX-ja uses the following cache:
7682 \begin{list}{}%
7683 {\def\makelabel#1{\ttfamily#1}}
7684 \item[ltj-cid-auto-adobe-japan1.lua] 
7685 The font table of a CID-keyed non-embedded Japanese font.
7686 This is loaded in every run.
7687 It is created from two CMaps, \texttt{UniJIS2004-UTF32-H} and
7688              \texttt{Adobe-Japan1-UCS2}, 
7689 and this is why these two CMaps are needed in the first run of \LuaTeX-ja.
7690
7691 Similar caches are created as Table~\ref{tab:cid-cache}, 
7692 if you specified \texttt{cid} key in \verb+\jfont+
7693 to use other CID-keyed non-embedded fonts for Chinese or Korean,
7694 as in Page~\pageref{para-cid}.
7695
7696 \item[ivs\_***.lua]
7697 This file stores the table of Unicode variants in a font ``\texttt{***}''. 
7698 The structure of the table is the following:
7699 %</en>
7700
7701 \begin{table}[!tb]
7702  \centering\small
7703 \caption{\texttt{cid} key and corresponding files}
7704 \label{tab:cid-cache}
7705 \vspace*{\medskipamount}
7706 \begin{tabular}{>{\tt}l>{\tt}l>{\tt}l>{\tt}l}
7707 \toprule
7708 \bf \texttt{cid} key&\bf name of the cache &
7709 \multicolumn{2}{c}{\bf used CMaps}\\
7710 \midrule
7711 Adobe-Japan1-*&ltj-cid-auto-adobe-japan1.lua&UniJIS2004-UTF32-H&Adobe-Japan1-UCS2\\
7712 Adobe-Korea1-*&ltj-cid-auto-adobe-korea1.lua&UniKS-UTF32-H&Adobe-Korea1-UCS2\\
7713 Adobe-GB1-*&ltj-cid-auto-adobe-gb1.lua&UniGB-UTF32-H&Adobe-GB1-UCS2\\
7714 Adobe-CNS1-*&ltj-cid-auto-adobe-cns1.lua&UniCNS-UTF32-H&Adobe-CNS1-UCS2\\
7715 \bottomrule
7716 \end{tabular}
7717 \end{table}
7718
7719 \begin{lstlisting}
7720 return {
7721  {
7722   [10955]={    -- U+2ACB "Subset Of Above Not Equal To"
7723    [65024]=983879, -- <2ACB FE00>
7724   },
7725   [37001]={    -- U+9089 "邉"
7726    [0]=37001,  --   <9089 E0100>
7727    991049,     --   <9089 E0101>
7728    ...
7729   },
7730   ...
7731  },
7732  ["chksum"]="FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", -- checksum of the fontfile
7733  ["version"]=4, -- version of the cache
7734 }
7735 \end{lstlisting}
7736 %<*ja>
7737 \item[ltj-jisx0208.\{luc|lub\}]
7738 \LuaTeX-ja配布中の\texttt{ltj-jisx0208.lua}をバイナリ化したものである.
7739 これはJIS~X~0208とUnicodeとの変換テーブルであり,
7740 \pTeX との互換目的の文字コード変換命令で用いられる.
7741 %</ja>
7742 %<*en>
7743 \item[ltj-jisx0208.\{luc|lub\}]
7744 The binary version of \texttt{ltj-jisx0208.lua}. 
7745 This is the conversion table between JIS~X~0208 and Unicode
7746 which is used in Kanji-code conversion commands for compatibility with \pTeX.
7747 %</en>
7748 \end{list}
7749
7750 %<*en>
7751 \subsection{Internal}
7752 Cache management system of \LuaTeX-ja is stored in \texttt{luatexja.base}
7753 (\texttt{ltj-base.lua}).
7754 There are three public functions for cache management in \texttt{luatexja.base}, 
7755 where <filename> stands for the filename \emph{without suffix}:
7756 \begin{list}{}%
7757 {\def\makelabel#1{\ttfamily#1}}
7758 \item[save\_cache(<filename>, <data>)]
7759 Save a non-nil table <data> into a cache <filename>.
7760 Both the text form <filename>\texttt{.lua} and its binary version 
7761 are created or updated.
7762
7763 \item[save\_cache\_luc(<filename>, <data>{[, <serialized\_data>]})]\ 
7764
7765 Same as \texttt{save\_cache}, except that only the binary cache is updated. 
7766 The third argument <serialized\_data> is not usually given.
7767 But if this is given, it is treated as a string representation of <data>.
7768
7769 \item[load\_cache(<filename>, <outdate>)]
7770 Load the cache <filename>.
7771 <outdate> is a function which takes one argument (the contents of the cache),
7772 and its return value is whether the cache is outdated.
7773
7774 \texttt{load\_cache} first tries to 
7775 read the binary cache <filename>\texttt{.\{luc|lub\}}.
7776 If its contents is up-to-date, \texttt{load\_cache} returns the contents.
7777 If the binary cache is not found or 
7778 its contents is outdated, \texttt{load\_cache} tries to 
7779 read the text form <filename>\texttt{.lua}.
7780 Hence, the return value of \texttt{load\_cache} is non-nil,
7781 if and only if the updated cache is found.
7782 \end{list}
7783 %</en>
7784 %<*ja>
7785 \subsection{内部命令}
7786 \LuaTeX-jaにおけるキャッシュ管理は,\texttt{luatexja.base}~(\texttt{ltj-base.lua})に
7787 実装しており,以下の3関数が公開されている.
7788 ここで,<filename>は保存するキャッシュのファイル名を\emph{拡張子なしで}指定する.
7789 \begin{list}{}%
7790 {\def\makelabel#1{\ttfamily#1}}
7791 \item[save\_cache(<filename>, <data>)]
7792 nilでない<data>をキャッシュ<filename>に保存する.
7793 テキスト形式の<filename>\texttt{.lua}のみならず,
7794 そのバイナリ版も作成/更新される.
7795
7796 \item[save\_cache\_luc(<filename>, <data>{[, <serialized\_data>]})]\ 
7797
7798 \texttt{save\_cache}と同様だが,バイナリキャッシュのみが更新される.
7799 第3引数<serialized\_data>が与えられた場合,それを
7800 <data>の文字列化表現として使用する.
7801 そのため,<serialized\_data>は普通は指定しないことになるだろう.
7802
7803 \item[load\_cache(<filename>, <outdate>)]
7804 キャッシュ<filename>を読み込む.
7805 <outdate>は1引数(キャッシュの中身)をとる関数であり,
7806 その戻り値は「キャッシュの更新が必要」かどうかを示すブール値でないといけない.
7807
7808 \texttt{load\_cache}は,まずバイナリキャッシュ<filename>\texttt{.\{luc|lub\}}を
7809 読みこむ.もしその内容が「新しい」,つまり<outdate>の評価結果が \texttt{false} なら
7810 \texttt{load\_cache}はこのバイナリキャッシュの中身を返す.
7811 もしバイナリキャッシュが見つからなかったか,「古すぎる」ならばテキスト版
7812              <filename>\texttt{.lua}を読み込み,その値を返す.
7813
7814 以上より,\texttt{load\_cache}自体がnilでない値を返すのは,ちょうど「新しい」キャッシュが
7815 見つかった場合である.
7816 \end{list}
7817 %</ja>
7818
7819
7820 %<*ja>
7821 \section{縦組の実装}
7822 \label{sec-dir-imp}
7823 \ref{sec-direction}章の最初でも述べたように,
7824 \LuaTeX-jaは横組(\texttt{TLT})で組んだボックスを回転させる方式で
7825 縦組を実装している.
7826
7827 \LuaTeX-jaにおける縦組の実装は
7828 \pTeX における実装(\cite{ptexdoc,ptextug})をベースにしており,……
7829
7830 \subsection{\textit{direction}~whatsit}
7831 \textit{direction}~whatsitとは,\textit{direction}という特定の \verb+user_id+ を持つ
7832 whatsitのことである.このwhatsitは,以下の3つの役割がある.
7833 \begin{enumerate}
7834 \def\labelenumi{(\roman{enumi})}
7835  \item 「現在作成中のリストの組方向が \verb+\tate+ 等により変更された」ことを表す.\\
7836 「現在の組方向」は \verb+\ltj@dir@count+ というカウンタに格納されているが,それだけでは
7837 \verb+hpack_filter+コールバックなどから正しく処理対象のリストの組方向を正しく取得すること
7838        はできない(\ref{ssec-stack}節参照)ため,このように別途whatsitを用いている.
7839  \item \verb+\hbox+,~\verb+\vbox+によって作成されたボックスの組方向を表す.\\
7840 原則として,ボックスの組方向はattribute \verb+\ltj@dir+ に格納されることになっている.しか
7841        し,新規に作成されるボックスのattributeをコールバックの内部から制御するには,
7842 \verb+tex.setattribute+ による方法しかなく,これは不安定……
7843  \item 「異方向における寸法」の記録用
7844 \end{enumerate}
7845 このように複数の役割をもたせているので,
7846 \begin{verbatim}
7847 % yoko direction
7848 \setbox0=\hbox{\tate B}
7849 \noindent \unhbox0 A
7850 \end{verbatim}
7851 のような場合に,「(ii)の役割の\textit{direction}~whatsitが(i)の役割として認識され,
7852 このリストは縦組とみなされるのではないか?」と思うかもしれない.しかし,
7853 (i)の役割と(ii)の枠割の\textit{direction}~whatsitは \verb+\ltj@icflag+ の値により
7854 区別されているので,そのような混乱は起こらない.
7855
7856
7857 \subsection{異方向のボックスの整合処理}
7858 縦中横など異方向のボックスを配置する場合に,周囲の組方向と大きさを整合させるため,
7859 \LuaTeX-jaでは \verb+\ltj@dir+ が16以降の\textit{hlist\_node}, \textit{vlist\_node}を
7860 用いる.
7861
7862
7863
7864 %</ja>
7865
7866 \begin{thebibliography}{99}
7867   \addcontentsline{toc}{section}{\refname}
7868 \bibitem{texbytopic}
7869 Victor Eijkhout. \newblock \textit{\TeX\ by Topic, A \TeX nician's Reference}, Addison-Wesley, 1992.
7870 \bibitem{listings} C.\ Heinz, B.\ Moses. \newblock The \textsf{Listings} Package.
7871 \bibitem{uptex} Takuji Tanaka. \newblock
7872 upTeX---Unicode version of pTeX with CJK extensions, 
7873 TUG 2013, October 2013.
7874 %<ja>\newblock
7875 %<en>\\\null\hfill
7876 \url{http://tug.org/tug2013/slides/TUG2013_upTeX.pdf}
7877 \bibitem{jlisting} Thor Watanabe. \newblock Listings\ -\ MyTeXpert. 
7878 %<en>\newblock
7879 %<ja>\\\null\hfill
7880 \url{http://mytexpert.sourceforge.jp/index.php?Listings}
7881 \bibitem{jlreq}  W3C Japanese Layout Task Force~(ed). \newblock
7882 Requirements for Japanese Text Layout (W3C Working Group Note), 2011, 2012. \newblock
7883 \url{http://www.w3.org/TR/jlreq/}%
7884 %<ja> \\日本語訳の書籍版:W3C日本語組版タスクフォース(編),『W3C技術ノート 日本語組版処理の要件』,東京電機大学出版局,2012.
7885 \bibitem{min10} 乙部厳己.min10フォントについて.\\\null\hfill
7886 \url{http://argent.shinshu-u.ac.jp/~otobe/tex/files/min10.pdf}
7887 \bibitem{x4051} 日本工業規格(Japanese Industrial Standard). JIS~X~4051,
7888 日本語文書の組版方法(Formatting rules for Japanese documents), 1993, 1995, 2004.
7889 \bibitem{ptexdoc} 濱野尚人,田村明史,倉沢良一.\TeX の出版への応用—縦組み機能の組み込み—.
7890 \\\null\hfill\texttt{.../texmf-dist/doc/ptex/base/ptexdoc.pdf}
7891 \bibitem{ptextug} Hisato Hamano. \newblock 
7892 \textit{Vertical Typesetting with \TeX}, TUGBoat~\textbf{11}(3), 346--352, 1990.
7893 \end{thebibliography}
7894
7895 \newpage
7896 \appendix
7897
7898 \section{Package versions used in this document}
7899 This document was typeset using the following packages:
7900
7901 \medskip
7902
7903 {\makeatletter\tt\footnotesize
7904   \def\@pkglist#1{%
7905     \filename@parse{#1}\def\@temp{sty}
7906     \ifx\@temp\filename@ext
7907       \edef\reserved@a{%
7908         \filename@base.%
7909         \ifx\filename@ext\relax tex\else\filename@ext\fi}%
7910       \leavevmode\hskip-13em\hbox to 13em{\filename@area\reserved@a\hss}%
7911       \csname ver@\reserved@a\endcsname\par
7912     \fi
7913   }%
7914 \parindent0pt\leftskip13em
7915 \ltjpkglist
7916
7917 \makeatother}
7918 \end{document}
7919 %</!showexpl>
7920 %<*showexpl>
7921 %%
7922 %% config file for showexpl.sty
7923 %%
7924 %% Copyright The LuaTeX-ja project team, 2012
7925 %%
7926 \ProvidesFile{showexpl.cfg}
7927   [2012/05/20 v0.01 Definitions for the showexpl package (luatexja)]
7928 \lstset{}
7929 \def\SX@Info{}
7930 \endinput
7931 %</*showexpl>