OSDN Git Service

changed spec. of JFM
[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 %<*en>
20 \usepackage[margin=25mm,lmargin=30mm,rmargin=30mm,footskip=6mm]{geometry}
21 \usepackage{luatexja-adjust}\ltjdisableadjust
22 \parskip=\smallskipamount
23 \renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}%
24     {3.25ex \@plus1ex \@minus.2ex}%
25     {-1em}%
26     {\normalfont\normalsize\bfseries\raisebox{.2ex}{$\mdlgblksquare\mkern1mu$}}}
27 %</en>
28 %<*ja>
29 \usepackage[textwidth=45\zw, lines=45, footskip=6mm]{geometry}
30 \usepackage{luatexja-adjust}%\ltjdisableadjust
31 \advance\leftmargini-1\zw\advance\leftmarginii-1\zw
32 %</ja>
33
34 \usepackage{amsmath,array,tikz,pict2e,multienum,float}
35 \usepackage{booktabs,multicol,luatexja-ruby}
36 \usepackage[all]{xy}
37 \usepackage{lltjext,alltt}
38
39 %%%%%%%% listings
40
41 %%%%%%%% IVS
42
43 \def\IVS#1{\char\numexpr "E0100+#1\relax}%"
44 \def\IVSA#1#2#3#4#5{%
45   \textcolor{blue}{\raisebox{3.5pt}{\tt%
46     \fboxsep=0.5pt\fbox{\tiny \oalign{0#1#2\crcr#3#4#5\crcr}}}}%
47 }
48 {\catcode`\%=11
49   \gdef\IVSB#1{\expandafter\IVSA\directlua{
50     local cat_str = luatexbase.catcodetables['string']
51     tex.sprint(cat_str, string.format('%X', 0xE00EF+#1))
52 }}}
53
54 \usepackage{listings,showexpl,enumitem}
55 \lstset{
56   basicstyle=\ttfamily\small, pos=r, breaklines=true,
57   numbers=none, rframe={}, basewidth=0.5em, numberstyle=\tiny, numbersep=0.5em,
58   explpreset={numberstyle=\tiny, numbers=left, numbersep=1em, columns=fixed}
59 }
60 % Suppress output from showexpl to stdout.
61 \let\SX@Info\relax
62
63 %%%%%%%% colors
64 %% modified from http://jfly.iam.u-tokyo.ac.jp/colorset/
65 \usepackage{transparent}
66 \definecolor{red}{rgb}{1, 0.16, 0}
67 \definecolor{blue}{rgb}{0, 0.25, 1}
68 \definecolor{gray}{rgb}{.50, .53, .56}
69 \definecolor{green}{rgb}{.21, .63, .42}
70 \definecolor{cyan}{rgb}{0.40, .80, 1}
71 \definecolor{b_gray}{rgb}{0.78, 0.78, 0.80}
72 \definecolor{b_pink}{rgb}{1, 0.82, 0.82}
73 \definecolor{b_green}{rgb}{.53, .91, .69}
74 \definecolor{b_cyan}{rgb}{0.70, .92, 98}
75
76 %%%%%%%% hyperref
77 \usepackage{hyperref,bookmark}
78 %<*en>
79 \title{The \LuaTeX-ja package}
80 \author{The \LuaTeX-ja project team}
81 %</en>
82 %<*ja>
83 \title{\LuaTeX-jaパッケージ}
84 \author{\LuaTeX-jaプロジェクトチーム}
85 %</ja>
86 \hypersetup{%
87         unicode,
88         colorlinks,
89         allbordercolors=1 1 1,
90         allcolors=blue,
91 %<*en>
92         pdfauthor={The LuaTeX-ja project team},
93         pdftitle={The LuaTeX-ja package}
94 %</en>
95 %<*ja>
96         pdfauthor={LuaTeX-jaプロジェクトチーム},
97         pdftitle={LuaTeX-jaパッケージ}
98 %</ja>
99 }
100
101 %%%%%%%% definition env.
102 \usepackage{amsthm}
103 \theoremstyle{definition}
104 %<en>\newtheorem{defn}{Definition}
105 %<ja>\newtheorem{defn}{定義}
106
107 %%%%%%%% fonts
108 \usepackage{luatexja-otf}
109 %<ja>\usepackage{lmodern}
110 \directlua{luatexja.otf.enable_ivs()}
111 \usepackage[match]{luatexja-fontspec}
112 \usepackage[kozuka-pr6n]{luatexja-preset}
113 \setmonojfont{KozGoPr6N-Regular.otf}
114 %<*ja>
115 \def\emph#1{\textbf{\textgt{#1}}}
116 \def\headfont{\normalfont\bfseries\gtfamily}
117 \usepackage{amssymb}
118 %</ja>
119 %<*en>
120 \usepackage{unicode-math}
121 \setmainfont[Ligatures=TeX]{TeX Gyre Termes}
122 \setsansfont[Scale=0.95,Ligatures=TeX]{TeX Gyre Heros}
123 \setmathfont{xits-math.otf}
124 \frenchspacing
125 %</en>
126
127 %%%%%%%% logo
128 \usepackage{metalogo}
129 \DeclareRobustCommand\eTeX{\ensuremath{\varepsilon}-\kern-.125em\TeX}
130 \DeclareRobustCommand\LuaTeX{Lua\TeX}
131 \DeclareRobustCommand\pdfTeX{pdf\TeX}
132 \DeclareRobustCommand\pTeX{p\kern-.15em\TeX}
133 \DeclareRobustCommand\upTeX{up\kern-.15em\TeX}
134 \DeclareRobustCommand\pLaTeX{p\kern-.05em\LaTeX}
135 \DeclareRobustCommand\pLaTeXe{p\kern-.05em\LaTeXe}
136 \DeclareRobustCommand\epTeX{\ensuremath{\varepsilon}-\kern-.125em\pTeX}
137
138 %%%%%%%% other macros
139 \newlist{cslist}{description}{1}
140 \setlist[cslist]{%
141     style=nextline,font=\mdseries\ttfamily,
142     before*=\def\<{\char`\<}\def\>{\char`\>}\def\{{\char`\{}\def\}{\char`\}},
143 %<ja> leftmargin=2\zw,
144 %<en> leftmargin=2em,
145 }
146
147 \def\labelenumii{(\arabic{enumii})}
148 \long\def\@makecaption#1#2{%
149   \vskip\abovecaptionskip
150   \sbox\@tempboxa{{\small #1. #2}}%
151   \ifdim \wd\@tempboxa >\hsize
152     {\small #1. #2}\par
153   \else
154     \global \@minipagefalse
155     \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
156   \fi
157   \vskip\belowcaptionskip}
158
159 \def\_{\leavevmode \kern .06em\vbox {\hrule \@width .333em}}
160 \def\cs#1{\texttt{\upshape\textbackslash #1}}
161
162 %%%%%%%%
163 \makeatother
164 %%%%%%%%
165
166 \def\Node#1#2{\,\vcenter{\hbox{\fboxsep=1pt\fbox{\vbox{\small\halign{\hfil##\hfil\cr
167   #1\mathstrut\cr\noalign{\vskip1pt\hrule height.4pt\vskip1pt}\strut#2\cr}}}}}\,}
168 \def\HNode#1#2#3#4{\,\vcenter{\hbox{\fboxsep=1pt\fbox{\vbox{\small\halign{\hfil##\hfil\cr
169   #1\mathstrut\cr\noalign{\vskip1pt\hrule height.4pt\vskip1pt}%
170   width:\hfill\ #2\cr height:\hfill\ #3\cr depth:\hfill\ #4\cr
171   }}}}}\,}
172
173 \protected\def\Param#1{\hyperlink{fld:#1}{\textsf{#1}}} % parameter name
174 \protected\def\DParam#1{\hypertarget{fld:#1}{\textsf{#1}}} % parameter name (definition)
175 \protected\def\Pkg#1{\underline{\smash{\texttt{#1}}}} % packages/classes
176
177
178 \begin{document}
179 \lstset{
180   vscmd=\IVSB
181 }
182
183 \catcode`\<=13
184 \def<#1>{{\normalfont\rm\itshape$\langle$#1\/$\rangle$}}
185 \let\LARG=<
186 \maketitle
187
188 \tableofcontents
189 \bigskip
190
191 %<*en>
192 \textbf{This documentation is far from complete. It may have many
193 grammatical (and contextual) errors.} Also, several parts
194 are written in Japanese only.
195 %</en>
196 %<*ja>
197 \emph{\large 本ドキュメントはまだまだ未完成です.}
198 %</ja>
199
200 \clearpage
201 %<en>\part{User's manual}
202 %<ja>\part{ユーザーズマニュアル}
203
204 %<en>\section{Introduction}
205 %<ja>\section{はじめに}
206
207
208 %<*en>
209 The \LuaTeX-ja package is a macro package for typesetting high-quality
210 Japanese documents when using \LuaTeX.
211 %</en>
212 %<*ja>
213 \LuaTeX-jaパッケージは,次世代標準\TeX である\LuaTeX の上で,\pTeX と同等
214 /それ以上の品質の日本語組版を実現させようとするマクロパッケージである.
215 %</ja>
216 %<en>\subsection{Backgrounds}
217 %<ja>\subsection{背景}
218
219 %<*en>
220 Traditionally, ASCII \pTeX, an extension of \TeX, and its derivatives
221 are used to typeset Japanese documents in \TeX. \pTeX\ is an engine
222 extension of \TeX: so it can produce high-quality Japanese documents
223 without using very complicated macros. But this point is a mixed
224 blessing: \pTeX\ is left behind from other extensions of \TeX,
225 especially \eTeX\ and \pdfTeX, and from changes about
226 Japanese processing in computers (\textit{e.g.}, the UTF-8 encoding).
227 %</en>
228 %<*ja>
229 従来,「\TeX を用いて日本語組版を行う」といったとき,エンジンとしては
230 ASCII \pTeX やそれの拡張物が用いられることが一般的であった.\pTeX は\TeX
231 のエンジン拡張であり,(少々仕様上不便な点はあるものの)商業印刷の分野に
232 も用いられるほどの高品質な日本語組版を可能としている.だが,それは弱点に
233 もなってしまった:\pTeX という(組版的に)満足なものがあったため,海外で
234 行われている数々の\TeX の拡張――例えば\eTeX や\pdfTeX ――や,TrueType,
235 OpenType, Unicodeといった計算機で日本語を扱う際の状況の変化に追従すること
236 を怠ってしまったのだ.
237 %</ja>
238
239 %<*en>
240 Recently extensions of \pTeX, namely \upTeX\ (Unicode-implementation
241 of \pTeX) and \epTeX\ (merging of \pTeX\ and
242 \eTeX\ extension), have developed to fill those gaps to some
243 extent, but gaps still exist.
244 %</en>
245 %<*ja>
246 ここ数年,若干状況は改善されてきた.現在手に入る大半の\pTeX バイナリでは
247 外部UTF-8入力が利用可能となり,さらにUnicode化を推進し,\pTeX の内部処理
248 までUnicode化した\upTeX も開発されている.また,\pTeX に\eTeX 拡張をマー
249 ジした\epTeX も登場し,\TeX\ Live\ 2011では\pLaTeX が\epTeX の上で動作す
250 るようになった.だが,\pdfTeX 拡張(PDF直接出力やmicro-typesetting)を
251 \pTeX に対応させようという動きはなく,海外とのgapは未だにあるのが現状であ
252 る.
253 %</ja>
254
255 %<*en>
256 However, the appearance of \LuaTeX\ changed the whole situation. With
257 using Lua ``callbacks'', users can customize the internal processing of
258 \LuaTeX. So there is no need to modify sources of engines to
259 support Japanese typesetting: to do this, we only have to write Lua
260 scripts for appropriate callbacks.
261 %</en>
262 %<*ja>
263 しかし,\LuaTeX の登場で,状況は大きく変わることになった.Luaコードで
264 ``callback''を書くことにより,\LuaTeX の内部処理に割り込みをかけることが可
265 能となった.これは,エンジン拡張という真似をしなくても,Luaコードとそれに
266 関する\TeX マクロを書けば,エンジン拡張とほぼ同程度のことができるようになっ
267 たということを意味する.\LuaTeX-jaは,このアプローチによってLuaコード・
268 \TeX マクロによって日本語組版を\LuaTeX の上で実現させようという目的で開発
269 が始まったパッケージである.
270 %</ja>
271
272 %<en>\subsection{Major Changes from \pTeX}
273 %<ja>\subsection{\pTeX からの主な変更点}
274 \label{ssec:chgptex}
275
276 %<*en>
277 The \LuaTeX-ja package is under much influence of \pTeX\ engine. The initial
278 target of development was to implement features of \pTeX. However,
279 \emph{\LuaTeX-ja is not a just porting of \pTeX; unnatural
280 specifications/behaviors of \pTeX\ were not adopted}.
281 %</en>
282 %<*ja>
283 \LuaTeX-jaは,\pTeX に多大な影響を受けている.初期の開発目標は,\pTeX の機
284 能をLuaコードにより実装することであった.しかし,開発が進むにつれ,\pTeX
285 の完全な移植は不可能であり,また\pTeX における実装がいささか不可解になっ
286 ているような状況も発見された.そのため,\emph{\LuaTeX-jaは,もはや
287 \pTeX の完全な移植は目標とはしない.\pTeX における不自然な仕様・挙動があ
288 れば,そこは積極的に改める.}
289 %</ja>
290
291 %<*en>
292 The followings are major changes from \pTeX:
293 %</en>
294 %<*ja>
295 以下は \pTeX からの主な変更点である.
296 %</ja>
297
298 \begin{itemize}
299 %<*en>
300 \item A Japanese font is a tuple of a ``real'' font, a Japanese font
301       metric (\emph{JFM}, for short).
302 %</en>
303 %<*ja>
304 \item 和文フォントは(小塚明朝,IPA明朝などの)実際のフォント,和文フォン
305       トメトリック(JFMと呼ぶ\footnote{混乱を防ぐため,p\TeX の意味での
306       JFM (\texttt{min10.tfm}) などは本ドキュメントでは\emph{和文用
307       TFM}とよぶことにする.})の組である.
308 %</ja>
309
310 %<*en>
311 \item In \pTeX, a line break after Japanese character is ignored (and
312       doesn't yield a space), since line breaks (in source files) are
313       permitted almost everywhere in Japanese texts. However, \LuaTeX-ja
314       doesn't have this function completely, because of a specification
315       of \LuaTeX.
316 %</en>
317 %<*ja>
318 \item 日本語の文書中では改行はほとんどどこでも許されるので,\pTeX では和文文字
319       直後の改行は無視される(スペースが入らない)ようになっていた.しかし,
320       \LuaTeX-ja では \LuaTeX の仕様のためにこの機能は完全には実装されていない.
321 %</ja>
322
323 %<*en>
324 \item The insertion process of glues/kerns between two Japanese
325       characters and between a Japanese character and other characters
326       (we refer glues/kerns of both kinds as \textbf{JAglue}) is rewritten from
327       scratch.
328 %</en>
329 %<*ja>
330 \item 2つの和文文字の間や,和文文字と欧文文字の間に入るグルー/カーン
331       (両者をあわせて\textbf{JAglue}と呼ぶ)の挿入処理が0から書き直されている.
332 %</ja>
333
334 \begin{itemize}
335 %<*en>
336 \item As \LuaTeX's internal ligature handling is ``node-based''
337       (\textit{e.g.}, \verb+of{}fice+ doesn't prevent ligatures), the
338       insertion process of \textbf{JAglue} is now ``node-based''.
339 %</en>
340 %<*ja>
341 \item \LuaTeX の内部での合字の扱いは「ノード」を単位として行われるようになっている(例えば,
342       \verb+of{}fice+ で合字は抑制されない).それに合わせ,\textbf{JAglue}の挿入処理も
343       ノード単位で実行される.
344 %</ja>
345
346 %<*en>
347 \item Furthermore, nodes between two characters which have no effects in
348       line break (\textit{e.g.}, \cs{special} node) and kerns from
349       italic correction are ignored in the insertion process.
350 %</en>
351 %<*ja>
352 \item さらに,2つの文字の間にある行末では効果を持たないノード(例えば \cs{special} ノード)や,
353   イタリック補正に伴い挿入されるカーンは挿入処理中では無視される.
354 %</ja>
355
356 %<*en>
357 \item \emph{Caution: due to above two points, many methods which did for the
358       dividing the process of the insertion of \textbf{JAglue} in \pTeX\ are not
359       effective anymore.} In concrete terms, the following two methods are not effective anymore:
360 %</en>
361 %<*ja>
362 \item \emph{注意:上の2つの変更により,従来\textbf{JAglue}の挿入処理を分断するのに
363       使われていたいくつかの方法は用いることができない.具体的には,次の方法はもはや無効である:}
364 %</ja>
365 \begin{lstlisting}
366 ちょ{}っと    ちょ\/っと
367 \end{lstlisting}
368 %<*en>
369       If you want to do so, please put an empty horizontal box (hbox) between it instead:
370 %</en>
371 %<*ja>
372       もし同じことをやりたければ,空の水平ボックス(hbox)を間に挟めばよい:
373 %</ja>
374 \begin{lstlisting}
375 ちょ\hbox{}っと
376 \end{lstlisting}
377
378
379 %<*en>
380 \item In the process, two Japanese fonts which only differ in their ``real''
381       fonts are identified.
382 %</en>
383 %<*ja>
384 \item 処理中では,2つの和文フォントは,実フォントが異なるだけの場合には同一視
385       される.
386 %</ja>
387 \end{itemize}
388
389 %<*ja>
390 \item \LuaTeX-jaでは,\pTeX と同様に漢字・仮名を制御綴内に用いることができ,
391 \cs{西暦} などが正しく動作するようにしている.
392 但し,制御綴中に使える和文文字が\pTeX・\upTeX と全く同じではない(\ref{sec-catcode}章参照).
393 %</ja>
394
395 %<*ja>
396 \item ****版からは,不安定ながらも\LuaTeX-ja における縦組みをサポートしている.
397 \LuaTeX のコールバックの制限などにより,特に異なった組方向のボックスを扱う場合には
398 仕様が異なるので注意.
399 %</ja>
400
401 %<*en>
402 \item Japanese characters in discretionary break (\cs{discretionary}) is not supported.
403 %</en>
404 %<*ja>
405 \item \cs{discretionary} 内に直接和文文字を記述することはサポートされない.和文文字をどう
406       しても使いたい場合は \cs{hbox} で括ること.
407 %</ja>
408 \end{itemize}
409
410 %<*en>
411 For detailed information, see Part~\ref{part-imp}.
412 %</en>
413 %<*ja>
414 詳細については第\ref{part-imp}部を参照.
415 %</ja>
416
417 %<en>\subsection{Notations}
418 %<ja>\subsection{用語と記法}
419
420 %<*en>
421 In this document, the following terms and notations are used:
422 %</en>
423 %<*ja>
424 本ドキュメントでは,以下の用語と記法を用いる:
425 %</ja>
426 \begin{itemize}
427 %<*en>
428 \item Characters are classified into following two types.
429       Note that the classification can be customized by a user
430       (see Subsection~\ref{ssec-setrange}).
431 %</en>
432 %<*ja>
433 \item 文字は次の2種類に分けられる.この類別はユーザが後から変更可能である
434       (\ref{ssec-setrange}節を参照).
435 %</ja>
436 \begin{itemize}
437 %<*en>
438 \item \textbf{JAchar}: standing for characters which used in Japanese typesetting,
439       such as Hiragana,~Katakana, Kanji, and~other Japanese punctuation marks.
440 %</en>
441 %<*ja>
442 \item \textbf{JAchar}: ひらがな,カタカナ,漢字,和文用の約物といった
443       日本語組版に使われる文字のことを指す.
444 %</ja>
445
446 %<en>\item \textbf{ALchar}: standing for all other characters like latin alphabets.
447 %<ja>\item \textbf{ALchar}: ラテンアルファベットを始めとする,その他全ての文字を指す.
448 \end{itemize}
449
450 %<*en>
451 We say \emph{alphabetic fonts} for fonts used in \textbf{ALchar},
452 and \emph{Japanese fonts} for fonts used in \textbf{JAchar}.
453 %</en>
454 %<*ja>
455 そして,\textbf{ALchar}の出力に用いられるフォントを\emph{欧文フォント}と呼び,
456 \textbf{JAchar}の出力に用いられるフォントを\emph{和文フォント}と呼ぶ.
457 %</ja>
458 %<*en>
459 \item A word in a sans-serif font (like \Param{prebreakpenalty})
460       means an internal parameter for Japanese typesetting, and it
461       is used as a key in \cs{ltjsetparameter} command.
462 %</en>
463 %<*ja>
464 \item サンセリフ体で書かれた語(例:\Param{prebreakpenalty})は日本語組版用の
465       パラメータを表し,これらは \cs{ltjsetparameter} 命令のキーとして
466       用いられる.
467 %</ja>
468 %<*en>
469 \item A word in typewriter font with underline (like \Pkg{fontspec})
470       means a package or a class of \LaTeX.
471 %</en>
472 %<*ja>
473 \item 下線付きタイプライタ体の語(例:\Pkg{fontspec})は\LaTeX の
474       パッケージやクラスを表す.
475 %</ja>
476 %<*en>
477 \item In this document, natural numbers start from~zero.
478   $\omega$ denotes the set of all natural numbers.
479 %</en>
480 %<*ja>
481 \item 本ドキュメントでは,自然数は0から始まる.自然数全体の集合は$\omega$と表記する.
482 %</ja>
483 \end{itemize}
484
485 %<en>\subsection{About the Project}
486 %<ja>\subsection{プロジェクトについて}
487
488 %<en>\paragraph{Project Wiki} Project Wiki is under construction.
489 %<ja>\paragraph{プロジェクトWiki} プロジェクトWikiは構築中である.
490 %<*en>
491 \begin{itemize}
492 \item \url{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage%28en%29} (English)
493 \item \url{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage} (Japanese)
494 \item \url{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage%28zh%29} (Chinese)
495 \end{itemize}
496 %</en>
497 %<*ja>
498 \begin{itemize}
499 \item \url{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage}(日本語)
500 \item \url{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage%28en%29}(英語)
501 \item \url{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage%28zh%29}(中国語)
502 \end{itemize}
503 %</ja>
504
505 %<en>This project is hosted by SourceForge.JP.
506 %<ja>本プロジェクトはSourceForge.JPのサービスを用いて運営されている.
507
508 %<en>\paragraph{Members}\
509 %<ja>\paragraph{開発メンバー}\
510
511 %<*en>
512 \begin{multienumerate}
513 \def\labelenumi{$\bullet$}
514 \mitemxxx{Hironori KITAGAWA}{Kazuki MAEDA}{Takayuki YATO}
515 \mitemxxx{Yusuke KUROKI}{Noriyuki ABE}{Munehiro YAMAMOTO}
516 \mitemxxx{Tomoaki HONDA}{Shuzaburo SAITO}{MA Qiyuan}
517 \end{multienumerate}
518 %</en>
519 %<*ja>
520 \begin{multienumerate}
521 \def\labelenumi{$\bullet$}
522 \mitemxxx{北川 弘典}{前田 一貴}{八登 崇之}
523 \mitemxxx{黒木 裕介}{阿部 紀行}{山本 宗宏}
524 \mitemxxx{本田 知亮}{齋藤 修三郎}{馬 起園}
525 \end{multienumerate}
526 %</ja>
527
528 % \paragraph{Acknowledgments} -- 挿入するならここ
529
530 \clearpage
531 %<en>\section{Getting Started}
532 %<ja>\section{使い方}
533 %<en>\subsection{Installation}
534 %<ja>\subsection{インストール}
535
536 %<en>The following packages are needed for the \LuaTeX-ja\ package.
537 %<ja>\LuaTeX-jaパッケージには,次のパッケージ類が必要である.
538 \begin{itemize}
539 \item \LuaTeX\ beta-0.74.0 (or later)
540 \item \Pkg{luaotfload} v2.2 (or later)
541 \item \Pkg{adobemapping} (Adobe cmap and pdfmapping files)
542 \item \Pkg{everysel} (if you want to use \LuaTeX-ja with \LaTeXe)
543 %<en>\item \emph{IPAex fonts(\url{http://ipafont.ipa.go.jp/})}
544 %<ja>\item \emph{IPAexフォント(\url{http://ipafont.ipa.go.jp/})}
545 \end{itemize}
546
547 %<*en>
548 \emph{This version of \LuaTeX-ja no longer supports \TeX~Live~2012 (or older version),
549 since \LuaTeX\ binary and \Pkg{luaotfload} is updated in
550 \TeX~Live~2013.}
551
552 \medskip
553
554 Now \LuaTeX-ja is available from
555 CTAN (in the \texttt{macros/luatex/generic/luatexja} directory), and
556 the following distributions:
557   \begin{itemize}
558   \item MiK\TeX\ (in \texttt{luatexja.tar.lzma}); see the next subsection
559   \item \TeX\ Live (in \texttt{texmf-dist/tex/luatex/luatexja})
560   \item W32\TeX\ (in \texttt{luatexja.tar.xz})
561   \end{itemize}
562 IPAex fonts are also available in these distributions.
563
564 If you are using \TeX~Live~2014, you can install \LuaTeX-ja
565 from \TeX~Live manager (\texttt{tlmgr}):
566 \begin{lstlisting}
567 $ tlmgr install luatexja
568 \end{lstlisting}
569 %</en>
570 %<*ja>
571 \emph{本バージョンの\LuaTeX-jaは\TeX~Live~2012以前では動作しない.}
572 これは,\LuaTeX と\Pkg{luaotfload}が\TeX~Live~2013において更新されたことによる.
573
574 \medskip
575
576 現在,\LuaTeX-jaはCTAN (\texttt{macros/luatex/generic/luatexja})に収録されている他,
577 以下のディストリビューションにも収録されている:
578   \begin{itemize}
579   \item MiK\TeX\ (\texttt{luatexja.tar.lzma})
580   \item \TeX\ Live (\texttt{texmf-dist/tex/luatex/luatexja})
581   \item W32\TeX\ (\texttt{luatexja.tar.xz})
582   \end{itemize}
583 これらのディストリビューションはIPAexフォントも収録している.
584 W32\TeX においてはIPAexフォントは \texttt{luatexja.tar.xz} 内にある.
585
586 例えば\TeX~Live~2014を利用しているなら,\LuaTeX-jaは\TeX~Live manager (\texttt{tlmgr})を
587 使ってインストールすることができる.
588 \begin{lstlisting}
589 $ tlmgr install luatexja
590 \end{lstlisting}
591 %</ja>
592
593 %<en>\paragraph{Manual installation}
594 %<ja>\paragraph{手動インストール方法}
595
596 \begin{enumerate}
597 %<*en>
598 \item Download the source archive, by one of the following method.
599       At the present, \LuaTeX-ja has no \emph{stable} release.
600
601 \begin{itemize}
602 \item Copy the Git repository:
603 \begin{lstlisting}
604 $ git clone git://git.sourceforge.jp/gitroot/luatex-ja/luatexja.git
605 \end{lstlisting}
606 \item Download the \texttt{tar.gz} archive of HEAD in the \texttt{master} branch from
607 \begin{flushleft}
608 \url{http://git.sourceforge.jp/view?p=luatex-ja/luatexja.git;a=snapshot;h=HEAD;sf=tgz}.
609 \end{flushleft}
610 \end{itemize}
611
612 Note that the \texttt{master} branch, and hence the archive in CTAN, are not updated frequently;
613 the forefront of development is not the \texttt{master} branch.
614 %</en>
615 %<*ja>
616 \item ソースアーカイブを以下のいずれかの方法で取得する.現在公開されているのはあくまでも
617       開発版であって,安定版でないことに注意.
618
619 \begin{itemize}
620 \item Gitリポジトリの内容をコピーする:
621 \begin{lstlisting}
622 $ git clone git://git.sourceforge.jp/gitroot/luatex-ja/luatexja.git
623 \end{lstlisting}
624 \item \texttt{master}ブランチのスナップショット(\texttt{tar.gz}形式)をダウンロードする.
625 \begin{flushleft}
626 \url{http://git.sourceforge.jp/view?p=luatex-ja/luatexja.git;a=snapshot;h=HEAD;sf=tgz}.
627 \end{flushleft}
628 \end{itemize}
629 \texttt{master}ブランチ(従って,CTAN内のアーカイブも)はたまにしか更新されないことに注意.
630 主な開発は\texttt{master}の外で行われ,比較的まとまってきたらそれを\texttt{master}に
631 反映させることにしている.
632 %</ja>
633
634 %<*en>
635 \item Extract the archive. You will see \texttt{src/} and several other sub-directories.
636 But only the contents in \texttt{src/} are needed to work \LuaTeX-ja.
637 %</en>
638 %<*ja>
639 \item 「Gitリポジトリをコピー」以外の方法でアーカイブを取得したならば,それを展開する.
640       \texttt{src/}をはじめとしたいくつかのディレクトリができるが,
641       動作には\texttt{src/}以下の内容だけで十分.
642 %</ja>
643
644 %<*en>
645 \item If you downloaded this package from CTAN, you have to run following commands
646     to generate classes
647     and \texttt{ltj-kinsoku.lua} (the file which stores default ``\textit{kinsoku}'' parameters):
648 %</en>
649 %<*ja>
650 \item もしCTANから本パッケージを取得したのであれば,日本語用クラスファイルや
651 標準の禁則処理用パラメータを
652 格納した \texttt{ltj-kinsoku.lua} を生成するために,
653 以下を実行する必要がある:
654 %</ja>
655 \begin{lstlisting}
656 $ cd src
657 $ lualatex ltjclasses.ins
658 $ lualatex ltjsclasses.ins
659 $ lualatex ltjltxdoc.ins
660 $ luatex   ltj-kinsoku_make.tex
661 \end{lstlisting}
662 %<*en>
663 Note that \texttt{*.\{dtx,ins\}} and \texttt{ltj-kinsoku\_make.tex} are not needed in regular use.
664 %</en>
665 %<*ja>
666 ここで使用した \texttt{*.\{dtx,ins\}} と \texttt{ltj-kinsoku\_make.tex} は
667 通常の使用にあたっては必要ない.
668 %</ja>
669
670
671
672 %<*en>
673 \item Copy all the contents of \texttt{src/} into one of your \texttt{TEXMF} tree.
674       \texttt{TEXMF/tex/luatex/luatexja/} is an example location.
675       If you cloned entire Git repository, making a symbolic link of \texttt{src/}
676       instead copying is also good.
677 %</en>
678 %<*ja>
679 \item \texttt{src}の中身を自分の\texttt{TEXMF}ツリーにコピーする.
680       場所の例としては,例えば
681 \begin{quote}
682  \texttt{TEXMF/tex/luatex/luatexja/}
683 \end{quote}
684       がある.
685       シンボリックリンクが利用できる環境で,かつリポジトリを直接取得したのであれば,
686       (更新を容易にするために)コピーではなくリンクを貼ることを勧める.
687 %</ja>
688 %<*en>
689 \item If \texttt{mktexlsr} is needed to update the file name database, make it so.
690 %</en>
691 %<*ja>
692 \item 必要があれば,\texttt{mktexlsr}を実行する.
693 %</ja>
694 \end{enumerate}
695
696 %<en>\subsection{Cautions}
697 %<ja>\subsection{注意点}
698
699 \begin{itemize}
700 %<*en>
701 \item The encoding of your source file must be UTF-8. No other
702       encodings, such as EUC-JP or Shift-JIS, are not supported.
703 %</en>
704 %<*ja>
705 \item 原稿のソースファイルの文字コードはUTF-8固定である.
706       従来日本語の文字コードとして用いられてきたEUC-JPやShift-JISは使用できない.
707 %</ja>
708 %<*en>
709 \item \LuaTeX-ja is very slower than \pTeX.
710 Generally speaking, LuaJIT\TeX\ processes \LuaTeX-ja
711 about 30\% faster than \LuaTeX, but not always.
712 %</en>
713 %<*ja>
714 \item \LuaTeX-jaは動作が\pTeX に比べて非常に遅い.
715 コードを調整して徐々に速くしているが,まだ満足できる速度ではない.
716 LuaJIT\TeX を用いると\LuaTeX のだいたい1.3倍の速度で動くようであるが,
717 IPA mj明朝などの大きいフォントを用いた場合には\LuaTeX よりも遅くなることもある.
718 %</ja>
719 \item%
720 %<*en>
721 \textbf{Note for MiK\TeX\ users}\quad
722 \LuaTeX-ja requires that several CMap files%
723 \footnote{\texttt{UniJIS2004-UTF32-\{H,V\}} and \texttt{Adobe-Japan1-UCS2}.}
724 must be found from \LuaTeX.
725 Strictly speaking, those CMaps are needed
726 only in the first run of \LuaTeX-ja after installing or updating.
727 But it seems that MiK\TeX\ does not satisfy this condition,
728 so you will encounter an error like the following:
729 %</en>
730 %<*ja>
731 \LuaTeX-jaが動作するためには,\emph{導入・更新後の初回起動時に}
732 \texttt{UniJIS2004-UTF32-\{H,V\}}, \texttt{Adobe-Japan1-UCS2}という3つのCMapが
733 \LuaTeX によって見つけられることが必要である.
734 しかしMiK\TeX ではそのようになっていないので,次のエラーが発生するだろう:
735 %</ja>
736 \begin{lstlisting}
737 ! LuaTeX error ...iles (x86)/MiKTeX 2.9/tex/luatex/luatexja/ltj-rmlgbm.lua
738 bad argument #1 to 'open' (string expected, got nil)
739 \end{lstlisting}
740
741 %<*en>
742 If so, please execute a batch file which is written on
743 \href{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage%28en%29}{ the Project Wiki (English)}.
744 This batch file creates a temporary directory, copy CMaps in it,
745 run \LuaTeX-ja in this directory, and finally delete the temporary directory.
746 %</en>
747 %<*ja>
748 そのような場合には,
749 \href{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage%28en%29}{%
750   プロジェクトWiki英語版トップページ}中に書かれているバッチファイルを
751 実行して欲しい.このバッチファイルは,作業用ディレクトリにCMap達を
752 コピーし,その中で\LuaTeX-ja の初回起動を行い,作業用ディレクトリを消す作業をしている.
753 %</ja>
754
755 \end{itemize}
756
757 %<en>\subsection{Using in plain \TeX}
758 %<ja>\subsection{plain \TeX で使う}
759 \label{ssec-plain}
760
761 %<en>To use \LuaTeX-ja in plain \TeX, simply put the following at the beginning of the document:
762 %<ja>\LuaTeX-jaを plain \TeX で使うためには,単に次の行をソースファイルの冒頭に追加すればよい:
763 \begin{lstlisting}
764 \input luatexja.sty
765 \end{lstlisting}
766 %<en>This does minimal settings (like \texttt{ptex.tex}) for typesetting Japanese documents:
767 %<ja>これで(\texttt{ptex.tex}のように)日本語組版のための最低限の設定がなされる:
768
769 \begin{itemize}
770 %<*en>
771 \item The following 12~Japanese fonts are preloaded:
772 \begin{center}\small
773 \begin{tabular}{cccccc}
774 \toprule
775 \textbf{direction}&
776 \textbf{classification}&\textbf{font name}&\bf `10\,pt'&\bf`7\,pt'&\bf`5\,pt'\\\midrule
777 \smash{\raisebox{-1ex}{\emph{yoko} (horizontal)}}&
778 \emph{mincho}&IPAex Mincho&\cs{tenmin}&\cs{sevenmin}&\cs{fivemin}\\
779 &\emph{gothic}&IPAex Gothic&\cs{tengt} &\cs{sevengt} &\cs{fivegt}\\
780 \midrule
781 \smash{\raisebox{-1ex}{\emph{tate} (vertical)}}&
782 \emph{mincho}&IPAex Mincho&\cs{tentmin}&\cs{seventmin}&\cs{fivetmin}\\
783 &\emph{gothic}&IPAex Gothic&\cs{tentgt} &\cs{seventgt} &\cs{fivetgt}\\
784 \bottomrule
785 \end{tabular}
786 \end{center}
787 %</en>
788 %<*ja>
789 \item 以下の12個の和文フォントが定義される:
790 \begin{center}\small
791 \begin{tabular}{cccccc}
792 \toprule
793 \emph{組方向}&\emph{字体}&\emph{フォント名}&\bf `10\,pt'&\bf`7\,pt'&\bf`5\,pt'\\\midrule
794 \smash{\raisebox{-1ex}{横組}}&
795 明朝体&IPAex明朝&\cs{tenmin}&\cs{sevenmin}&\cs{fivemin}\\
796 &ゴシック体&IPAexゴシック&\cs{tengt} &\cs{sevengt} &\cs{fivegt}\\
797 \midrule
798 \smash{\raisebox{-1ex}{縦組}}&
799 明朝体&IPAex明朝&\cs{tentmin}&\cs{seventmin}&\cs{fivetmin}\\
800 &ゴシック体&IPAexゴシック&\cs{tentgt} &\cs{seventgt} &\cs{fivetgt}\\
801 \bottomrule
802 \end{tabular}
803 \end{center}
804 %</ja>
805 \begin{itemize}
806 %<*en>
807 \item With \texttt{luatexja.cfg}, one can use other fonts
808 as ``default'' Japanese fonts (Subsection~\ref{ssec-cfg}).
809 %</en>
810 %<*ja>
811 \item \texttt{luatexja.cfg} を用いることによって,標準和文フォントを
812 IPAexフォントから別のフォントに置き換えることができる.\ref{ssec-cfg}節を参照.
813 %</ja>
814
815 %<*en>
816 \item A character in an alphabetic font is generally smaller than a
817       Japanese font in the same size. So actual size specification of
818       these Japanese fonts is in fact smaller than that of alphabetic
819       fonts, namely scaled by 0.962216.
820 %</en>
821 %<*ja>
822 \item 欧文フォントの文字は和文フォントの文字よりも,同じ文字サイズでも
823       一般に小さくデザインされている.そこで,標準ではこれらの和文フォントの実際のサイズは指定された値よりも
824       小さくなるように設定されており,具体的には指定の0.962216倍にスケールされる.
825       この0.962216という数値も,\pTeX におけるスケーリングを踏襲した値である.
826 %</ja>
827 \end{itemize}
828
829 %<*en>
830 \item The amount of glue that are inserted between a \textbf{JAchar} and
831       an \textbf{ALchar} (the parameter \Param{xkanjiskip}) is set to
832 %</en>
833 %<*ja>
834 \item \textbf{JAchar}と\textbf{ALchar}の間に入るグルー(\Param{xkanjiskip})の
835       量は次のように設定されている:
836 %</ja>
837 \[
838  (0.25\cdot 0.962216\cdot 10\,\mathrm{pt})^{+1\,\text{pt}}_{-1\,\text{pt}}
839  = 2.40554\,\mathrm{pt}^{+1\,\text{pt}}_{-1\,\text{pt}}.
840 \]
841 \end{itemize}
842
843 %<en>\subsection{Using in \LaTeX}
844 %<ja>\subsection{\LaTeX で使う}
845 \label{ssec-ltx}
846
847 %<*en>
848 Using in \LaTeXe\ is basically same. To set up the minimal environment
849 for Japanese, you only have to load \texttt{luatexja.sty}:
850 %</en>
851 %<*ja>
852 \LaTeXe を用いる場合も基本的には同じである.日本語組版のための最低限の環境を
853 設定するためには,\texttt{luatexja.sty}を読み込むだけでよい:
854 %</ja>
855 \begin{lstlisting}
856 \usepackage{luatexja}
857 \end{lstlisting}
858 %<*en>
859 It also does minimal settings (counterparts in \pLaTeX\ are \texttt{%
860 plfonts.dtx} and \texttt{pldefs.ltx}):
861 %</en>
862 %<*ja>
863 これで\pLaTeX の\texttt{plfonts.dtx}と\texttt{pldefs.ltx}に相当する最低限の設定が
864 なされる:
865 %</ja>
866
867 \begin{itemize}
868 %<*en>
869 \item Font encodings for Japanese fonts is \texttt{JY3}~(for horizontal direction) and
870 \texttt{JT3}~(for vertical direction).
871 %</en>
872 %<*ja>
873 \item 和文フォントのエンコーディングとしては,横組用には \texttt{JY3},縦組用には\
874 \texttt{JT3}が用いられる.
875 %</ja>
876
877 %<*en>
878 \item Traditionally, Japanese documents use two typeface categories: \emph{mincho}~(明朝体) and
879  \emph{gothic}~(\textgt{ゴシック体}). \emph{mincho} is used in the main text, while \emph{gothic}
880       is used in the headings or for emphasis.
881 \begin{center}\small
882 \begin{tabular}{lllc}
883 \toprule
884 \textbf{classification}&&&\textbf{family name}\\\midrule
885 \emph{mincho} (明朝体)&\verb+\textmc{...}+&\verb+{\mcfamily ...}+&\cs{mcdefault}\\
886 \emph{gothic} (\textgt{ゴシック体})&\verb+\textgt{...}+&\verb+{\gtfamily ...}+&\cs{gtdefault}\\
887 \bottomrule
888 \end{tabular}
889 \end{center}
890 \item
891 By default, the following fonts are used for \emph{mincho} and \emph{gothic}:
892 \begin{center}\small
893 \begin{tabular}{ccccc}
894 \toprule
895 \textbf{classification}&\textbf{family}&\cs{mdseries}&\cs{bfseries}&\textbf{scale}\\\midrule
896 \emph{mincho} (明朝体)&\tt mc&IPAex Mincho&IPAex Gothic&0.962216\\
897 \emph{gothic} (\textgt{ゴシック体})&\tt gt&IPAex Gothic&IPAex Gothic&0.962216\\
898 \bottomrule
899 \end{tabular}
900 \end{center}
901 Note that the bold series in both family are same as the medium series of \emph{gothic}
902      family. There is no italic nor slanted shape for
903       these \texttt{mc}~and~\texttt{gt}.
904 %</en>
905 %<*ja>
906 \item \pLaTeX と同様に,標準では「明朝体」「ゴシック体」の2種類を用いる:
907 \begin{center}\small
908 \begin{tabular}{cllc}
909 \toprule
910 \emph{字体}&&&\emph{ファミリ名}\\\midrule
911 明朝体&\verb+\textmc{...}+&\verb+{\mcfamily ...}+&\cs{mcdefault}\\
912 \textgt{ゴシック体}&\verb+\textgt{...}+&\verb+{\gtfamily ...}+&\cs{gtdefault}\\
913 \bottomrule
914 \end{tabular}
915 \end{center}
916 \item 標準では,次のフォントファミリが用いられる:
917 \begin{center}\small
918 \begin{tabular}{ccccc}
919 \toprule
920 \emph{字体}&\emph{ファミリ}&\cs{mdseries}&\cs{bfseries}&\emph{スケール}\\\midrule
921 明朝体&\tt mc&IPAex明朝&IPAexゴシック&0.962216\\
922 ゴシック体&\tt gt&IPAexゴシック&IPAexゴシック&0.962216\\
923 \bottomrule
924 \end{tabular}
925 \end{center}
926 どちらのファミリにおいても,そのboldシリーズで使われるフォントは
927 ゴシック体のmediumシリーズで使われるフォントと同じであることに注意.
928 また,どちらのファミリでもイタリック体・スラント体は定義されない.
929 %</ja>
930
931
932 %<en>\item Japanese characters in math mode are typeset by the font family \texttt{mc}.
933 %<ja>\item 数式モード中の和文文字は明朝体(\texttt{mc})で出力される.
934 \end{itemize}
935
936 %<*en>
937 However, above settings are not sufficient for Japanese-based
938 documents. To typeset Japanese-based documents, you are better to use
939 class files other than \texttt{article.cls}, \texttt{book.cls}, and so on.  At
940 the present, we have the counterparts of \Pkg{jclasses} (standard
941 classes in \pLaTeX) and \Pkg{jsclasses} (classes by Haruhiko
942 Okumura), namely, \Pkg{ltjclasses}\footnote{%
943   \texttt{ltjarticle.cls},~\texttt{ltjbook.cls}, \texttt{ltjreport.cls},
944   \texttt{ltjtarticle.cls}, \texttt{ltjtbook.cls}, \texttt{ltjtreport.cls}.
945   The latter \texttt{ltjt*.cls} are for vertically writtened Japanese documents.
946 } and \Pkg{ltjsclasses}\footnote{%
947   \texttt{ltjsarticle.cls},~\texttt{ltjsbook.cls},~\texttt{ltjskiyou.cls}.}.
948 %</en>
949 %<*ja>
950 しかしながら,上記の設定は日本語の文書にとって十分とは言えない.
951 日本語文書を組版するためには,\texttt{article.cls}, \texttt{book.cls}といった
952 欧文用のクラスファイルではなく,和文用のクラスファイルを用いた方がよい.
953 現時点では,\Pkg{jclasses}(\pLaTeX の標準クラス)と\Pkg{jsclasses}
954 (奥村晴彦氏による「\pLaTeXe 新ドキュメントクラス」)に対応するものとして,
955 \Pkg{ltjclasses}\footnote{%
956   横組用は \texttt{ltjarticle.cls},~\texttt{ltjbook.cls}, \texttt{ltjreport.cls} であり,
957   縦組用は \texttt{ltjtarticle.cls}, \texttt{ltjtbook.cls}, \texttt{ltjtreport.cls} である.
958 },
959 \Pkg{ltjsclasses}\footnote{%
960   \texttt{ltjsarticle.cls},~\texttt{ltjsbook.cls},~\texttt{ltjskiyou.cls}.}%
961 がそれぞれ用意されている.
962 %</ja>
963
964 %<*ja>
965 \paragraph{脚注とボトムフロートの出力順序}
966 オリジナルの\LaTeX では脚注がボトムフロートの上に来るようになっており,
967 \pLaTeX では脚注がボトムフロートの下に来るように変更されている.
968
969 \LuaTeX-jaでは「欧文クラスの中にちょっとだけ日本語を入れる」という利用も考慮し,
970 脚注とボトムフロートの順序は\LaTeX 通りとした.もし\pLaTeX の出力順序が好みならば,
971 \Pkg{stfloats}パッケージを利用して
972 \begin{lstlisting}
973  \usepackage{stfloats} \fnbelowfloat
974 \end{lstlisting}
975 のようにすればよい.\Pkg{footmisc}パッケージを \texttt{bottom}\ オプションを指定して
976 読み込むという方法もあるが,それだとボトムフロートと脚注の間が開いてしまう.
977 %</ja>
978
979 %<en>\section{Changing Fonts}
980 %<ja>\section{フォントの変更}
981
982 \subsection{plain \TeX~and~\LaTeXe}
983 \label{ssec-chgfnt}
984
985 \paragraph{plain \TeX}
986 %<*en>
987 To change Japanese fonts in plain \TeX, you must use the command
988 \cs{jfont}~and~\cs{tfont}. So please see Subsection~\ref{ssec-jfont}.
989 %</en>
990 %<*ja>
991 plain \TeX で和文フォントを変更するためには,
992 \pTeX のように \cs{jfont} 命令や \cs{tfont} 命令を直接用いる.
993 \ref{ssec-jfont}節を参照.
994 %</ja>
995
996 \paragraph{\LaTeXe\ (NFSS2)}
997 %<*en>
998 For \LaTeXe, \LuaTeX-ja adopted most of the font selection system of \pLaTeXe\ (in \texttt{plfonts.dtx}).
999 %</en>
1000 %<*ja>
1001 \LaTeXe については,\LuaTeX-jaではフォント選択システムを\pLaTeXe\ (\texttt{plfonts.dtx})
1002 の大部分をそのまま採用している.
1003 %</ja>
1004 \begin{itemize}
1005 %<*en>
1006 \item Commands \cs{fontfamily}, \cs{fontseries},
1007       \cs{fontshape}, and \cs{selectfont} can be used to change
1008       attributes of Japanese fonts.
1009 %</en>
1010 %<*ja>
1011 \item \cs{fontfamily}, \cs{fontseries}, \cs{fontshape}, そして
1012       \cs{selectfont} が和文フォントの属性を変更するために使用できる.
1013 %</ja>
1014
1015 %<*en>
1016 \begin{center}\small
1017 \begin{tabular}{cccccc}
1018 \toprule
1019 &\textbf{encoding}&\textbf{family}&\textbf{series}&\textbf{shape}&\textbf{selection}\\\midrule
1020 alphabetic fonts
1021 &\cs{romanencoding}&\cs{romanfamily}&\cs{romanseries}&\cs{romanshape}
1022 &\cs{useroman}\\
1023 Japanese fonts
1024 &\cs{kanjiencoding}&\cs{kanjifamily}&\cs{kanjiseries}&\cs{kanjishape}
1025 &\cs{usekanji}\\
1026 both&---&--&\cs{fontseries}&\cs{fontshape}&---\\
1027 auto select&\cs{fontencoding}&\cs{fontfamily}&---&---&\cs{usefont}\\
1028 \bottomrule
1029 \end{tabular}
1030 \end{center}
1031 %</en>
1032 %<*ja>
1033 \begin{center}\small
1034 \begin{tabular}{cccccc}
1035 \toprule
1036 &\emph{エンコーディング}&\emph{ファミリ}&\emph{シリーズ}&\emph{シェープ}&\emph{選択}\\\midrule
1037 欧文
1038 &\cs{romanencoding}&\cs{romanfamily}&\cs{romanseries}&\cs{romanshape}
1039 &\cs{useroman}\\
1040 和文
1041 &\cs{kanjiencoding}&\cs{kanjifamily}&\cs{kanjiseries}&\cs{kanjishape}
1042 &\cs{usekanji}\\
1043 両方&---&--&\cs{fontseries}&\cs{fontshape}&---\\
1044 自動選択&\cs{fontencoding}&\cs{fontfamily}&---&---&\cs{usefont}\\
1045 \bottomrule
1046 \end{tabular}
1047 \end{center}
1048 %</ja>
1049
1050 %<*en>
1051       \verb+\fontencoding{+<encoding>\verb+}+ changes the encoding of alphabetic fonts
1052       or Japanese fonts depending on the argument. For example,
1053       \verb+\fontencoding{JY3}+ changes the encoding of Japanese fonts to
1054       \texttt{JY3},and \verb+\fontencoding{T1}+ changes the encoding of
1055       alphabetic fonts to \texttt{T1}.
1056       \cs{fontfamily} also changes the current Japanese font family,
1057       the current alphabetic font family, \emph{or both}.
1058       For the detail, see Subsection~\ref{ssec-nfsspat}.
1059 %</en>
1060 %<*ja>
1061       ここで,\verb+\fontencoding{+<encoding>\verb+}+ は,引数により和文側か欧文
1062       側かのどちらかのエンコーディングを変更する.例えば,
1063       \verb+\fontencoding{JY3}+ は和文フォントのエンコーディングを
1064       \texttt{JY3}に変更し,\verb+\fontencoding{T1}+ は欧文フォント側を
1065       \texttt{T1}へと変更する.\cs{fontfamily} も引数により和文側,欧文
1066       側,\emph{あるいは両方}のフォントファミリを変更する.詳細は
1067       \ref{ssec-nfsspat}節を参照すること.
1068 %</ja>
1069
1070 %<*en>
1071 \item For defining a Japanese font family, use
1072       \cs{DeclareKanjiFamily} instead of
1073       \cs{DeclareFontFamily}. However, in the present implementation,
1074       using \cs{DeclareFontFamily} doesn't cause any problem.
1075 \item Defining a Japanese font shape can be done by usual \cs{DeclareFontShape}:
1076 %</en>
1077 %<*ja>
1078 \item 和文フォントファミリの定義には \cs{DeclareFontFamily} の
1079       代わりに \cs{DeclareKanjiFamily} を用いる.しかし,現在の
1080       実装では \cs{DeclareFontFamily} を用いても問題は生じない.
1081 \item 和文フォントのシェイプを定義するには,通常の \cs{DeclareFontShape} を使えば良い:
1082 %</ja>
1083 \begin{lstlisting}
1084 \DeclareFontShape{JY3}{mc}{bx}{n}{<-> s*KozMinPr6N-Bold:jfm=ujis;-kern}{}
1085     % Kozuka Mincho Pr6N Bold
1086 \end{lstlisting}
1087 %<*ja>
1088 仮名書体を使う場合など,複数の和文フォントを組み合わせて使いたい場合は
1089 \ref{ssec-altfont}節の \cs{ltjdeclarealtfont} と,その\LaTeX 版の\
1090 \cs{DeclareAlternateKanjiFont}(\ref{ssec-nfsspat}節)を参照せよ.
1091 %</ja>
1092 \end{itemize}
1093
1094 %<*en>
1095 \paragraph{Remark: Japanese characters in math mode}
1096 Since \pTeX\ supports Japanese characters in math mode, there are
1097 sources like the following:
1098 %</en>
1099 %<*ja>
1100 \paragraph{注意:数式モード中の和文文字}
1101 \pTeX では,特に何もしないでも数式中に和文文字を記述することができた.そのため,
1102 以下のようなソースが見られた:
1103 %</ja>
1104
1105 \begin{LTXexample}
1106 $f_{高温}$~($f_{\text{high temperature}}$).
1107 \[ y=(x-1)^2+2\quad よって\quad y>0 \]
1108 $5\in 素:=\{\,p\in\mathbb N:\text{$p$ is a prime}\,\}$.
1109 \end{LTXexample}
1110 %<*en>
1111 We (the project members of \LuaTeX-ja) think that using
1112 Japanese characters in math mode are allowed if and only if these are used as identifiers.
1113 In this point of view,
1114 %</en>
1115 %<*ja>
1116 \LuaTeX-jaプロジェクトでは,数式モード中での和文文字はそれらが識別子として用いられる
1117 ときのみ許されると考えている.
1118 この観点から,
1119 %</ja>
1120
1121 \begin{itemize}
1122 %<*en>
1123 \item The lines 1~and~2 above are not correct, since ``高温'' in above is used as a textual label, and
1124 ``よって'' is used as a conjunction.
1125 %</en>
1126 %<*ja>
1127 \item 上記数式のうち1, 2行目は正しくない.なぜならば「高温」が意味のあるラベルと
1128       して,「よって」が接続詞として用いられているからである.
1129 %</ja>
1130 %<en>\item However, the line~3 is correct, since ``素'' is used as an identifier.
1131 %<ja>\item しかしながら,3行目は「素」が単なる識別子として用いられているので正しい.
1132 \end{itemize}
1133 %<en>Hence, in our opinion, the above input should be corrected as:
1134 %<ja>したがって,\LuaTeX-jaプロジェクトの意見としては,上記の入力は次のように直されるべきである:
1135 \begin{LTXexample}
1136 $f_{\text{高温}}$~%
1137 ($f_{\text{high temperature}}$).
1138 \[ y=(x-1)^2+2\quad
1139   \mathrel{\text{よって}}\quad y>0 \]
1140 $5\in 素:=\{\,p\in\mathbb N:\text{$p$ is a prime}\,\}$.
1141 \end{LTXexample}
1142 %<*en>
1143 We also believe that using Japanese characters as identifiers is rare,
1144 hence we don't describe how to change Japanese fonts in math mode in
1145 this chapter. For the method, please see Subsection~\ref{ssec-math}.
1146 %</en>
1147 %<*ja>
1148 また\LuaTeX-jaプロジェクトでは,和文文字が識別子として用いられることはほとんどない
1149 と考えており,したがってこの節では数式モード中の和文フォントを変更する方法については
1150 記述しない.この方法については\ref{ssec-math}節を参照のこと.
1151 %</ja>
1152
1153
1154 \subsection{fontspec}
1155 \label{ssec-fontspec}
1156 %<*en>
1157 To coexist with the \Pkg{fontspec} package, it is needed to load
1158 \Pkg{luatexja-fontspec} package in the preamble, as follows:
1159 \begin{quote}
1160 \ttfamily \textbackslash usepackage[<options>]\{luatexja-fontspec\}
1161 \end{quote}
1162 This \Pkg{luatexja-fontspec} package
1163 automatically loads \Pkg{luatexja} and \Pkg{fontspec}
1164 package, if needed.
1165 %</en>
1166 %<*ja>
1167 \Pkg{fontspec}パッケージと同様の機能を和文フォントに対しても用いる場合,
1168 \Pkg{luatexja-fontspec}パッケージを読み込む:
1169 \begin{quote}
1170 \ttfamily \textbackslash usepackage[<options>]\{luatexja-fontspec\}
1171 \end{quote}
1172 このパッケージ
1173 は必要ならば自動で\Pkg{luatexja}パッケージと\Pkg{fontspec}パッケージを読み込む.
1174 %</ja>
1175
1176 %<*en>
1177 In \Pkg{luatexja-fontspec} package, the following seven~commands are defined as
1178 counterparts of original commands in the \Pkg{fontspec} package:
1179 %</en>
1180 %<*ja>
1181 \Pkg{luatexja-fontspec}パッケージでは,以下の7つのコマンドを\Pkg{fontspec}
1182 パッケージの元のコマンドに対応するものとして定義している:
1183 %</ja>
1184 %<*en>
1185 \begin{center}\small
1186 \begin{tabular}{ccccc}
1187 \toprule
1188 Japanese fonts
1189 &\cs{jfontspec}&\cs{setmainjfont}&\cs{setsansjfont}&\cs{setmonojfont}$^*$\\
1190 alphabetic fonts
1191 &\cs{fontspec}&\cs{setmainfont}&\cs{setsansfont}&\cs{setmonofont}\\
1192 \midrule
1193 Japanese fonts
1194 &\cs{newjfontfamily}&\cs{newjfontface}
1195 &\cs{defaultjfontfeatures}&\cs{addjfontfeatures}\\
1196 alphabetic fonts
1197 &\cs{newfontfamily}&\cs{newfontface}
1198 &\cs{defaultfontfeatures}&\cs{addfontfeatures}\\
1199 \bottomrule
1200 \end{tabular}
1201 \end{center}
1202 %</en>
1203 %<*ja>
1204 \begin{center}\small
1205 \begin{tabular}{cccc}
1206 \toprule
1207 和文
1208 &\cs{jfontspec}&\cs{setmainjfont}&\cs{setsansjfont}\\
1209 欧文
1210 &\cs{fontspec}&\cs{setmainfont}&\cs{setsansfont}\\
1211 \midrule
1212 和文
1213 &\cs{newjfontfamily}&\cs{newjfontface}&\cs{defaultjfontfeatures}\\
1214 欧文
1215 &\cs{newfontfamily}&\cs{newfontface}&\cs{defaultfontfeatures}\\
1216 \midrule
1217 和文
1218 &\cs{addjfontfeatures}\\
1219 欧文
1220 &\cs{addfontfeatures}\\
1221 \bottomrule
1222 \end{tabular}
1223 \end{center}
1224 %</ja>
1225 %<*en>
1226 The package option of \Pkg{luatexja-fontspec} are the followings:
1227 \begin{cslist}
1228  \item[match]
1229 If this option is specified, usual family-changing commands such as
1230 \cs{rmfamily},~\cs{textrm}, \cs{sffamily},~\dots\ also change Japanese font family.
1231
1232 Note that \emph{\cs{setmonojfont} is defined
1233 if and only if this \texttt{\textup{match}} option is specified}.
1234
1235  \item[pass=<opts>]
1236 Specify options <opts> which will be passed to the \Pkg{fontspec} package.
1237 \end{cslist}
1238 The reason that \cs{setmonojfont} is not defined by default is that
1239 it is popular for Japanese fonts that nearly all Japanese glyphs have same
1240 widths.  Also note that kerning information in a font is not used
1241 (that is, \texttt{kern} feature is set off) by default in these seven (or~eight) commands.
1242 This is because of the compatibility with previous versions of \LuaTeX-ja
1243 (see \ref{para-kern}).
1244 %</en>
1245 %<*ja>
1246 \Pkg{luatexja-fontspec} パッケージのオプションは以下の通りである:
1247 \begin{cslist}
1248  \item[match]
1249 このオプションが指定されると,「\pLaTeXe 新ドキュメントクラス」のように\
1250 \cs{rmfamily}, \verb+\textrm{...}+, \cs{sffamily} 等が
1251 欧文フォントだけでなく和文フォントも変更するようになる.
1252
1253 \emph{なお,\cs{setmonojfont} はこの \texttt{match} オプションが
1254 指定された時のみ定義される.}この命令は標準の「タイプライタ体に対応する和文フォント」を指定する.
1255
1256  \item[pass=<opts>]
1257 \Pkg{fontspec} パッケージに渡すオプション <opts> を指定する.
1258 \end{cslist}
1259 標準で \cs{setmonojfont} コマンドが定義されないのは,
1260 和文フォントではほぼ全ての和文文字のグリフが等幅であるのが伝統的であったことによる.
1261 また,これらの和文用のコマンドではフォント内のペアカーニング情報は標準では使用されない,
1262 言い換えれば \texttt{kern} featureは標準では無効化となっている.
1263 これは以前のバージョンの\LuaTeX-jaとの互換性のためである(\ref{para-kern}節を参照).
1264 %</ja>
1265
1266 \begin{LTXexample}[width=0.4\textwidth]
1267 \fontspec[Numbers=OldStyle]{LMSans10-Regular}
1268 \jfontspec[CJKShape=NLC]{KozMinPr6N-Regular}
1269 JIS~X~0213:2004→辻
1270
1271 \jfontspec[CJKShape=JIS1990]{KozMinPr6N-Regular}
1272 JIS~X~0208:1990→辻
1273 \end{LTXexample}
1274
1275 %<en>\subsection{Presets}
1276 %<ja>\subsection{プリセット設定}
1277 \label{ssec-preset}
1278
1279 %<*en>
1280 To use standard Japanese font settings easily, one can load \Pkg{luatexja-preset}
1281 package with several options. This package provides functions in a part of
1282 \Pkg{japanese-otf} package and a part of \Pkg{PXchfon} package by Takayuki Yato,
1283 and loads \Pkg{luatexja-fontspec}, hence \Pkg{fontspec} internally.
1284
1285 If you need to pass some options to \Pkg{fontspec}, load \Pkg{fontspec} manually
1286 before \Pkg{luatexja-preset}:
1287 %</en>
1288 %<*ja>
1289 よく使われている和文フォント設定を一行で指定できるようにしたのが
1290 \Pkg{luatexja-preset}パッケージである.このパッケージは,
1291 \Pkg{otf}パッケージの一部機能と八登崇之氏による\Pkg{PXchfon}パッケージの一部機能とを
1292 合わせたような格好をしており,内部で\Pkg{luatexja-fontspec},従って
1293 \Pkg{fontspec}を読み込んでいる.
1294
1295 もし\Pkg{fontspec}パッケージに何らかのオプションを渡す必要がある
1296 \footnote{例えば,数式フォントまで置換されてしまい,\cs{mathit}によってギリシャ文字の
1297 斜体大文字が出なくなる,など.}場合は,
1298 次のように\Pkg{luatexja-preset}の前に\Pkg{fontspec}を手動で読みこめば良い:
1299 %</ja>
1300 \begin{lstlisting}
1301 \usepackage[no-math]{fontspec}
1302 \usepackage[...]{luatexja-preset}
1303 \end{lstlisting}
1304
1305 %<en>\paragraph{General options}
1306 %<ja>\paragraph{一般的なオプション}
1307 \begin{cslist}[before*=]
1308
1309 \item[nodeluxe]
1310 %<*en>
1311 Use one-weighted \textit{mincho} and \textit{gothic} font families.
1312 This means that \verb+\mcfamily\bfseries+, \verb+\gtfamily\bfseries+ and
1313 \verb+\gtfamily\mdseries+ use the same font.
1314 \emph{This option is enabled by default.}
1315 %</en>
1316 %<*ja>
1317 \LaTeXe 環境下での標準設定のように,明朝体・ゴシック体を各1ウェイトで使用する.
1318 より具体的に言うと,この設定の下では
1319 \ \verb+\mcfamily\bfseries+, \verb+\gtfamily\bfseries+,
1320 \verb+\gtfamily\mdseries+はみな同じフォントとなる.
1321 \emph{このオプションは標準で有効になっている.}
1322 %</ja>
1323 \item[deluxe]
1324 %<*en>
1325 Use \textit{mincho} with two weights (medium~and~bold),
1326 \textit{gothic} with three weights (medium, bold~and~heavy), and \textit{rounded gothic}%
1327 \footnote{Provided by \cs{mgfamily} and \cs{textmg},
1328 because \textit{rounded gothic} is called \textit{maru gothic} (丸ゴシック) in Japanese.}.
1329 The heavy weight of \textit{gothic} can be used by ``changing the family'' \cs{gtebfamily},
1330 or \verb+\textgteb{...}+.
1331 This is because \Pkg{fontspec} package can handle only medium (\cs{mdseries}) and
1332 bold (\cs{bfseries}).
1333 %</en>
1334 %<*ja>
1335 明朝体2ウェイト・ゴシック体3ウェイトと,
1336 丸ゴシック体 (\cs{mgfamily}, \verb+\textmg{...}+) を使用可能とする.
1337 ゴシック体は細字・太字・極太の3ウェイトがあるが,
1338 極太ゴシック体はファミリの切り替え (\cs{gtebfamily}, \verb+\textgteb{...}+) %
1339 で実現している.\Pkg{fontspec}では通常 (\cs{mdseries}) と太字 (\cs{bfseries}) しか扱えないために
1340 このような中途半端な実装になっている.
1341 %</ja>
1342 \item[expert]
1343 %<*en>
1344 Use horizontal/vertical kana alternates, and define a command \cs{rubyfamily} to use kana
1345 characters designed for ruby.
1346 %</en>
1347 %<ja>横組・縦組専用仮名を用いる.また,\cs{rubyfamily} でルビ用仮名が使用可能となる.
1348 \item[bold]
1349 %<en>Substitute bold series of \textit{gothic} for  bold series of \textit{mincho}.
1350 %<ja>「明朝の太字」をゴシック体の太字によって代替する.
1351 \item[90jis]
1352 %<en>Use 90JIS glyph variants if possible.
1353 %<ja>出来る限り90JISの字形を使う.
1354 \item[jis2004]
1355 %<en>Use JIS2004 glyph variants if possible.
1356 %<ja>出来る限りJIS2004の字形を使う.
1357 \item[jis]
1358 %<*en>
1359 Use the JFM \texttt{jfm-jis.lua}, instead of \texttt{jfm-ujis.lua}, which is the default JFM of
1360 \LuaTeX-ja.
1361 %</en>
1362 %<*ja>
1363 用いるJFMを(JISフォントメトリック類似の)\texttt{jfm-jis.lua}にする.このオプションがない時は
1364 \LuaTeX-ja標準の\texttt{jfm-ujis.lua}が用いられる.
1365 %</ja>
1366 \end{cslist}
1367 %<*en>
1368 Note that \texttt{90jis} and \texttt{jis2004} only affect with \textit{mincho},
1369 \textit{gothic} (and possibly \textit{rounded gothic}) defined by this package.
1370 We didn't taken account of  when both \texttt{90jis} and \texttt{jis2004} are specified.
1371 %</en>
1372 %<*ja>
1373 \texttt{90jis}と\texttt{jis2004}については本パッケージで定義された
1374 明朝体・ゴシック体(・丸ゴシック体)にのみ有効である.両オプションが
1375 同時に指定された場合の動作については全く考慮していない.
1376 %</ja>
1377
1378 %<en>\paragraph{Presets for multi weight}
1379 %<ja>\paragraph{多ウェイト用プリセットの一覧}
1380 %<*en>
1381 Besides \texttt{morisawa-pro}~and~\texttt{morisawa-pr6n} presets,
1382 fonts are specified by font name, not by file name.
1383 %</en>
1384 %<*ja>
1385 \texttt{morisawa-pro}, \texttt{morisawa-pr6n}以外はフォントの指定は
1386 (ファイル名でなく)フォント名で行われる.
1387 %</ja>
1388 \begin{cslist}[style=standard]
1389  \item[kozuka-pro] Kozuka Pro (Adobe-Japan1-4) fonts.
1390 %<en>    \\*[-\dimexpr\medskipamount+\baselineskip\relax]
1391  \item[kozuka-pr6] Kozuka Pr6 (Adobe-Japan1-6)  fonts.
1392 %<en>    \\*[-\dimexpr\medskipamount+\baselineskip\relax]
1393  \item[kozuka-pr6n] Kozuka Pr6N (Adobe-Japan1-6, JIS04-savvy) fonts.
1394
1395 %<*en>
1396 Kozuka Pro/Pr6N fonts are bundled with Adobe's software, such as Adobe~InDesign.
1397 There is not rounded gothic family in Kozuka fonts.
1398 %</en>
1399 %<*ja>
1400 小塚Pro書体・Pr6N書体はAdobe InDesign等のAdobe製品にバンドルされている.
1401 「小塚丸ゴシック」は存在しないので,便宜的に小塚ゴシックHによって代用している.
1402 %</ja>
1403 \begin{center}\small
1404 \begin{tabular}{cllll}
1405 \toprule
1406 \bf family&\bf series&\tt kozuka-pro&\tt kozuka-pr6&\tt kozuka-pr6n\\
1407 \midrule
1408  &medium&KozMinPro-Regular&KozMinProVI-Regular&KozMinPr6N-Regular\\
1409 %<en>\smash{\raisebox{1.5ex}{\textit{mincho}}}%
1410 %<ja>\smash{\raisebox{1.5ex}{\gt 明朝}}%
1411  &bold&KozMinPro-Bold&KozMinProVI-Bold&KozMinPr6N-Bold\\
1412 \midrule
1413  &&KozGoPro-Regular*&KozGoProVI-Regular*&KozGoPr6N-Regular*\\
1414  &\smash{\raisebox{1.5ex}{medium}}
1415  &KozGoPro-Medium&KozGoProVI-Medium&KozGoPr6N-Medium\\
1416 \cmidrule(l){2-5}
1417 %<en>\smash{\raisebox{2ex}{\textit{gothic}}}%
1418 %<ja>\smash{\raisebox{2ex}{\gt ゴシック}}%
1419  &bold&KozGoPro-Bold&KozGoProVI-Bold&KozGoPr6N-Bold\\
1420  &heavy&KozGoPro-Heavy&KozGoProVI-Heavy&KozGoPr6N-Heavy\\
1421 \midrule
1422 %<en>\textit{rounded gothic}
1423 %<ja>\gt 丸ゴシック
1424 &&KozGoPro-Heavy&KozGoProVI-Heavy&KozGoPr6N-Heavy\\
1425 \bottomrule
1426 \end{tabular}
1427 \end{center}
1428
1429 %<*en>
1430 In above table, starred fonts (KozGo\dots-Regular) are used for medium series of \textit{gothic},
1431 \emph{if and only if \texttt{deluxe} option is specified}.
1432 %</en>
1433 %<*ja>
1434 上の表において,*つきのフォント(KozGo\dots-Regular)は,\emph{\texttt{deluxe}オプション非指定時に}
1435 ゴシック体細字として用いられる.
1436 %</ja>
1437
1438 %<ja>\medskip
1439
1440  \item[hiragino-pro]  Hiragino Pro (Adobe-Japan1-5) fonts.
1441 %<en>    \\*[-\dimexpr\medskipamount+\baselineskip\relax]
1442  \item[hiragino-pron] Hiragino ProN (Adobe-Japan1-5, JIS04-savvy) fonts.
1443
1444 %<*en>
1445 Hiragino fonts are bundled with Mac OS~X 10.5 or later.
1446 Some editions of a Japanese word-processor ``一太郎2012'' includes Hiragino ProN fonts.
1447 Note that the heavy weight of \textit{gothic} family only supports
1448 Adobe-Japan1-3 character collection (Std/StdN).
1449 %</en>
1450 %<*ja>
1451 ヒラギノフォントは,Mac OS~X以外にも,一太郎2012の上位エディションにもバンドルされている.
1452 極太ゴシックとして用いるヒラギノ角ゴW8は,Adobe-Japan1-3の範囲しかカバーしていない
1453 Std/StdNフォントであり,その他はAdobe-Japan1-5対応である.
1454 %</ja>
1455 \begin{center}\small
1456 \begin{tabular}{clll}
1457 \toprule
1458 \bf family&\bf series&\tt hiragino-pro&\tt hiragino-pron\\
1459 \midrule
1460  &medium&Hiragino~Mincho~Pro~W3&Hiragino~Mincho~ProN~W3\\
1461 %<en>\smash{\raisebox{1.5ex}{\textit{mincho}}}%
1462 %<ja>\smash{\raisebox{1.5ex}{\gt 明朝}}%
1463  &bold&Hiragino~Mincho~Pro~W6&Hiragino~Mincho~ProN~W6\\
1464 \midrule
1465  &&Hiragino~Kaku~Gothic~Pro~W3*&Hiragino~Kaku~Gothic~ProN~W3*\\
1466  &\smash{\raisebox{1.5ex}{medium}}
1467  &Hiragino~Kaku~Gothic~Pro~W6&Hiragino~Kaku~Gothic~ProN~W6\\
1468 \cmidrule(l){2-4}
1469 %<en>\smash{\raisebox{2ex}{\textit{gothic}}}%
1470 %<ja>\smash{\raisebox{2ex}{\gt ゴシック}}%
1471  &bold&Hiragino~Kaku~Gothic~Pro~W6&Hiragino~Kaku~Gothic~ProN~W6\\
1472  &heavy&Hiragino~Kaku~Gothic~Std~W8&Hiragino~Kaku~Gothic~StdN~W8\\
1473 \midrule
1474 %<en>\textit{rounded gothic}
1475 %<ja>\gt 丸ゴシック
1476 &&Hiragino~Maru~Gothic~ProN~W4&Hiragino~Maru~Gothic~ProN~W4\\
1477 \bottomrule
1478 \end{tabular}
1479 \end{center}
1480
1481 %<ja>\newpage
1482
1483  \item[morisawa-pro]  Morisawa Pro (Adobe-Japan1-4) fonts.
1484 %<en>    \\*[-\dimexpr\medskipamount+\baselineskip\relax]
1485  \item[morisawa-pr6n]  Morisawa Pr6N (Adobe-Japan1-6, JIS04-savvy) fonts.
1486
1487 \begin{center}\small
1488 \begin{tabular}{cl>{\tt}l>{\tt}l}
1489 \toprule
1490 \bf family&\bf series&morisawa-pro&morisawa-pr6n\\
1491 \midrule
1492  &medium&A-OTF-RyuminPro-Light.otf&A-OTF-RyuminPr6N-Light.otf\\
1493 %<en>\smash{\raisebox{1.5ex}{\textit{mincho}}}%
1494 %<ja>\smash{\raisebox{1.5ex}{\gt 明朝}}%
1495  &bold&A-OTF-FutoMinA101Pro-Bold.otf&A-OTF-FutoMinA101Pr6N-Bold.otf\\
1496 \midrule
1497  &medium
1498  &A-OTF-GothicBBBPro-Medium.otf&A-OTF-GothicBBBPr6N-Medium.otf\\
1499 %<en>\textit{gothic}%
1500 %<ja>\gt ゴシック
1501  &bold&A-OTF-FutoGoB101Pro-Bold.otf&A-OTF-FutoGoB101Pr6N-Bold.otf\\
1502  &heavy&A-OTF-MidashiGoPro-MB31.otf&A-OTF-MidashiGoPr6N-MB31.otf\\
1503 \midrule
1504 %<en>\textit{rounded gothic}
1505 %<ja>\gt 丸ゴシック
1506 &&A-OTF-Jun101Pro-Light.otf&A-OTF-ShinMGoPr6N-Light.otf\\
1507 \bottomrule
1508 \end{tabular}
1509 \end{center}
1510
1511  \item[yu-win]  Yu fonts bundled with Windows~8.1.
1512 %<en>    \\*[-\dimexpr\medskipamount+\baselineskip\relax]
1513  \item[yu-osx]  Yu fonts bundled with OSX~Mavericks.
1514
1515 \begin{center}\small
1516 \begin{tabular}{clll}
1517 \toprule
1518 \bf family&\bf series&\tt yu-win&\tt yu-osx\\
1519 \midrule
1520  &medium&YuMincho-Regular&YuMincho~Medium\\
1521 %<en>\smash{\raisebox{1.5ex}{\textit{mincho}}}%
1522 %<ja>\smash{\raisebox{1.5ex}{\gt 明朝}}%
1523  &bold&YuMincho-Demibold&YuMincho~Demibold\\
1524 \midrule
1525  &&YuGothic-Regular*&YuGothic~Medium*\\
1526  &\smash{\raisebox{1.5ex}{medium}}
1527  &YuGothic-Bold&YuGothic~Bold\\
1528 \cmidrule(l){2-4}
1529 %<en>\textit{gothic}%
1530 %<ja>\gt ゴシック
1531  &bold&YuGothic-Bold&YuGothic~Bold\\
1532  &heavy&YuGothic-Bold&YuGothic~Bold\\
1533 \midrule
1534 %<en>\textit{rounded gothic}
1535 %<ja>\gt 丸ゴシック
1536 &&YuGothic-Bold&YuGothic~Bold\\
1537 \bottomrule
1538 \end{tabular}
1539 \end{center}
1540
1541 \end{cslist}
1542 %<en>\paragraph{Presets for single weight}
1543 %<ja>\paragraph{単ウェイト用プリセット一覧}
1544 %<*en>
1545 Next, we describe settings for using only single weight.
1546 In four settings below, we use same fonts for medium and bold (and heavy) weights.
1547 (Hence \verb+\mcfamily\bfseries+ and \verb+\mcfamily\mdseries+ yields same Japanese fonts,
1548 even if \texttt{deluxe} option is also specified).
1549 %</en>
1550 %<*ja>
1551 次に,単ウェイト用の設定を述べる.この4設定では「細字」「太字」の区別はない.
1552 また,丸ゴシック体はゴシック体と同じフォントを用いる.
1553 %</ja>
1554 \par\nobreak\medskip
1555 {\centering\small
1556 \begin{tabular}{lllll}
1557 \toprule
1558 &\tt noembed&\tt ipa&\tt ipaex&\tt ms\\
1559 \midrule
1560 %<*en>
1561 \it mincho&Ryumin-Light (non-embedded)
1562 &IPA Mincho&IPAex Mincho&MS Mincho\\
1563 \it gothic&GothicBBB-Medium (non-embedded)
1564 &IPA Gothic&IPAex Gothic&MS Gothic\\
1565 %</en>
1566 %<*ja>
1567 \gtfamily 明朝体&Ryumin-Light(非埋込)
1568 &IPA明朝&IPAex明朝&MS明朝\\
1569 \gtfamily ゴシック体&GothicBBB-Medium(非埋込)
1570 &IPAゴシック&IPAexゴシック&MSゴシック\\
1571 %</ja>
1572 \bottomrule
1573 \end{tabular}\par\medskip}
1574
1575 %<en>\paragraph{Using HG fonts}
1576 %<ja>\paragraph{HGフォントの利用}
1577 %<*en>
1578 We can use HG~fonts bundled with Microsoft~Office for realizing multiple weights.
1579 %</en>
1580 %<*ja>
1581 すぐ前に書いた単ウェイト用設定を,Microsoft Office等に付属するHGフォントを使って
1582 多ウェイト化した設定もある.
1583 %</ja>
1584 \par\nobreak\medskip
1585 {\centering\small
1586 \begin{tabular}{llll}
1587 \toprule
1588 &\tt ipa-hg&\tt ipaex-hg&\tt ms-hg\\
1589 \midrule
1590 %<*en>
1591 \bf mincho medium
1592 &IPA Mincho&IPAex Mincho&MS Mincho\\\midrule
1593 \bf mincho bold&
1594 \multicolumn{3}{c}{HG Mincho E}\\\midrule
1595 \bf Gothic medium\\
1596 ~~without \texttt{deluxe}
1597 &IPA Gothic&IPAex Gothic&MS Gothic\\
1598 ~~with {\tt jis2004}
1599 &IPA Gothic&IPAex Gothic&MS Gothic\\
1600 \cmidrule(lr){1-4}
1601 ~~otherwise&
1602 \multicolumn{3}{c}{HG Gothic M}\\\midrule
1603 \bf gothic bold&
1604 \multicolumn{3}{c}{HG Gothic E}\\\midrule
1605 \bf gothic heavy&
1606 \multicolumn{3}{c}{HG Soei Kaku Gothic UB}\\\midrule
1607 \bf rounded gothic&
1608 \multicolumn{3}{c}{HG Maru Gothic PRO}\\
1609 %</en>
1610 %<*ja>
1611 \gtfamily 明朝体細字
1612 &IPA明朝&IPAex明朝&MS明朝\\\midrule
1613 \gtfamily 明朝体太字&
1614 \multicolumn{3}{c}{HG明朝E}\\\midrule
1615 \gtfamily ゴシック体細字\\
1616  単ウェイト時
1617 &IPAゴシック&IPAexゴシック&MSゴシック\\
1618  {\tt jis2004}指定時
1619 &IPAゴシック&IPAexゴシック&MSゴシック\\
1620 \cmidrule(lr){1-4}
1621  それ以外の時&
1622 \multicolumn{3}{c}{HGゴシックM}\\\midrule
1623 \gtfamily ゴシック体太字&
1624 \multicolumn{3}{c}{HGゴシックE}\\\midrule
1625 \gtfamily ゴシック体極太&
1626 \multicolumn{3}{c}{HG創英角ゴシックUB}\\\midrule
1627 \gtfamily 丸ゴシック体&
1628 \multicolumn{3}{c}{HG丸ゴシック体PRO}\\
1629 %</ja>
1630 \bottomrule
1631 \end{tabular}\par\medskip}
1632
1633 %<*en>
1634 Note that HG~Mincho~E, HG~Gothic~E, HG Soei Kaku Gothic UB, and HG Maru Gothic PRO
1635 are internally specified by:
1636 \begin{description}
1637 \item[default] by font name (\texttt{HGMinchoE}, etc.).
1638 \item[{\tt 90jis}] by file name (\texttt{hgrme.ttc}, \texttt{hgrge.ttc}, \texttt{hgrsgu.ttc}, \texttt{hgrsmp.ttf}).
1639 \item[{\tt jis2004}] by file name (\texttt{hgrme04.ttc}, \texttt{hgrge04.ttc}, \texttt{hgrsgu04.ttc}, \texttt{hgrsmp04.ttf}).
1640 \end{description}
1641 %</en>
1642 %<*ja>
1643 \newpage
1644 なお,HG明朝E・HGゴシックE・HG創英角ゴシックUB・HG丸ゴシック体PROの4つについては,内部で
1645 \begin{description}
1646 \item[標準] フォント名(\texttt{HGMinchoE} など)
1647 \item[{\tt 90jis}指定時] ファイル名 (%
1648 \texttt{hgrme.ttc}, \texttt{hgrge.ttc}, \texttt{hgrsgu.ttc}, \texttt{hgrsmp.ttf})
1649 \item[{\tt jis2004}指定時] ファイル名 (%
1650 \texttt{hgrme04.ttc}, \texttt{hgrge04.ttc}, \texttt{hgrsgu04.ttc}, \texttt{hgrsmp04.ttf})
1651 \end{description}
1652 として指定を行っているので注意すること.
1653 %</ja>
1654
1655
1656 %<*en>
1657 \subsection{\cs{CID}, \cs{UTF}, and macros in \Pkg{japanese-otf} package}
1658 Under \pLaTeX, \Pkg{japanese-otf} package (developed by Shuzaburo Saito) is
1659 used for typesetting characters which is in Adobe-Japan1-6 CID but not
1660 in JIS~X~0208. Since this package is widely used, \LuaTeX-ja
1661 supports some of functions in \Pkg{japanese-otf} package.
1662 If you want to use these functions, load \Pkg{luatexja-otf} package.
1663 %</en>
1664 %<*ja>
1665 \subsection{\cs{CID}, \cs{UTF}と\Pkg{otf}パッケージのマクロ}
1666 \pLaTeX では,JIS~X~0208にないAdobe-Japan1-6の文字を出力するために,
1667 齋藤修三郎氏による\Pkg{otf}パッケージが用いられていた.このパッケージは
1668 広く用いられているため,\LuaTeX-jaにおいても\Pkg{otf}パッケージの機能の
1669 一部をサポートしている.これらの機能を用いるためには\Pkg{luatexja-otf}パッケージ
1670 を読み込めばよい.
1671 %</ja>
1672
1673 \begin{LTXexample}
1674 \jfontspec{KozMinPr6N-Regular.otf}
1675 森\UTF{9DD7}外と内田百\UTF{9592}とが\UTF{9AD9}島屋に行く。
1676
1677 \CID{7652}飾区の\CID{13706}野家,
1678 \CID{1481}城市,葛西駅,
1679 高崎と\CID{8705}\UTF{FA11}
1680
1681 \aj半角{はんかくカタカナ}
1682 \end{LTXexample}
1683
1684 %<*ja>
1685 \Pkg{otf}パッケージでは,それぞれ次のようなオプションが存在した:
1686 \begin{cslist}
1687 \item[deluxe] 明朝体・ゴシック体各2ウェイトと,丸ゴシック体を扱えるようになる.
1688 \item[expert] 仮名が横組・縦組専用のものに切り替わり,ルビ用仮名も
1689 \ \cs{rubyfamily}\ によって扱えるようになる.
1690 \item[bold] ゴシック体を標準で太いウェイトのものに設定する.
1691 \end{cslist}
1692 しかしこれらのオプションは\Pkg{luatexja-otf}パッケージには存在しない.
1693 \Pkg{otf}パッケージが文書中で使用する和文用TFMを自前の物に置き換えていたのに対し,
1694 \Pkg{luatexja-otf}パッケージでは,そのようなことは行わないからである.
1695
1696 これら3オプションについては,
1697 \Pkg{luatexja-preset} パッケージにプリセットを使う時に一緒に指定するか,
1698 あるいは対応する内容を\ref{ssec-chgfnt}節,\ref{ssec-nfsspat}節 (NFSS2) や
1699 \ref{ssec-fontspec}節 (\Pkg{fontspec}) の方法で手動で指定する必要がある.
1700 %</ja>
1701
1702 %<en>\subsection{Changing default Japanese fonts}
1703 %<ja>\subsection{標準和文フォントの変更}
1704 \label{ssec-cfg}
1705 %<*en>
1706 If \texttt{luatexja.cfg} can be seen from \LuaTeX, \LuaTeX-ja automatically reads it.
1707 The main use of \texttt{luatexja.cfg} is for changing default Japanese fonts,
1708 when IPAex fonts cannot be installed in \TeX~system.
1709 One should not overuse this \texttt{luatexja.cfg}; fonts which will be used in
1710 a document should be specified in its source.
1711
1712 For example,
1713 \begin{lstlisting}
1714 \def\ltj@stdmcfont{IPAMincho}
1715 \def\ltj@stdgtfont{IPAGothic}
1716 \end{lstlisting}
1717 makes that IPA~Mincho and IPA~Gothic will be used as default Japanese fonts, instead of
1718 IPAex~Mincho and IPAex~Gothic.
1719
1720 For another example, the following two lines makes that
1721 non-embedded fonts Ryumin-Light~and~GothicBBB-Medium as default Japanese fonts
1722 (as the earlier version of \LuaTeX-ja):
1723 \begin{lstlisting}
1724 \def\ltj@stdmcfont{psft:Ryumin-Light}
1725 \def\ltj@stdgtfont{psft:GothicBBB-Medium}
1726 \end{lstlisting}
1727 %</en>
1728 %<*ja>
1729 \LuaTeX から見える位置に \texttt{luatexja.cfg} があれば,\LuaTeX-jaはそれを読み込む.
1730 このファイルを用いるとplain~\TeX, \LaTeXe における標準和文フォントを
1731 IPAex明朝・IPAexゴシックから変更することができる.
1732 しかし,基本的には\emph{文章中で用いるフォントは(例えば \Pkg{luatexja-preset} などで)
1733 文書ソース内で指定するべき}であり,この \texttt{luatexja.cfg} は,
1734 「IPAexフォントがインストールできない」など,IPAexフォントが使用できない場合にのみ
1735 応急処置的に用いるべきである.
1736
1737 例えば
1738 \begin{lstlisting}
1739 \def\ltj@stdmcfont{IPAMincho}
1740 \def\ltj@stdgtfont{IPAGothic}
1741 \end{lstlisting}
1742 と記述しておけば,標準和文フォントがIPA明朝・IPAゴシックへと変
1743 更される.
1744
1745
1746 なお,20140906.0以前のバージョンのように,
1747 Ryumin-Light, GothicBBB-Mediumという名前の非埋込フォントを用いる場合は
1748 \begin{lstlisting}
1749 \def\ltj@stdmcfont{psft:Ryumin-Light}
1750 \def\ltj@stdgtfont{psft:GothicBBB-Medium}
1751 \end{lstlisting}
1752 と記述すればよい.
1753 %</ja>
1754
1755
1756 %<en>\section{Changing Parameters}
1757 %<ja>\section{パラメータの変更}
1758
1759 %<*en>
1760 There are many parameters in \LuaTeX-ja. And due to the behavior of \LuaTeX,
1761 most of them are not stored as internal register of \TeX, but as an
1762 original storage system in \LuaTeX-ja. Hence, to assign or acquire those
1763 parameters, you have to use commands \cs{ltjsetparameter} and
1764 \cs{ltjgetparameter}.
1765 %</en>
1766 %<*ja>
1767 \LuaTeX-jaには多くのパラメータが存在する.そして\LuaTeX の仕様のために,
1768 その多くは\TeX のレジスタにではなく,\LuaTeX-ja独自の方法で保持されている.
1769 これらのパラメータを設定・取得するためには \cs{ltjsetparameter} と \cs{ltjgetparameter} を
1770 用いる.
1771 %</ja>
1772
1773 %<en>\subsection{Editing the Range of \textbf{JAchar}s}
1774 %<ja>\subsection{\textbf{JAchar}の範囲の設定}
1775 \label{ssec-setrange}
1776
1777 %<*en>
1778 \LuaTeX-ja divides the Unicode codespace \texttt{U+0080}--\texttt{U+10FFFF}
1779 into \emph{character ranges},
1780 numbered 1 to 217. The grouping can be (globally) customized by \cs{ltjdefcharrange}.
1781 The next line adds whole characters in Supplementary Ideographic Plane
1782 and the character ``漢'' to the character range~100.
1783 %</en>
1784 %<*ja>
1785 \LuaTeX-jaは,Unicodeの \texttt{U+0080}--\texttt{U+10FFFF} の空間を
1786 1番から217番までの\emph{文字範囲}に分割している.
1787 区分けは \cs{ltjdefcharrange} を用いることで(グローバルに)変更することができ,
1788 例えば,次は追加漢字面(SIP)にある全ての文字と「漢」を「100番の文字範囲」に追加する.
1789 %</ja>
1790 \begin{lstlisting}
1791 \ltjdefcharrange{100}{"20000-"2FFFF,`漢}
1792 \end{lstlisting}
1793 %<*en>
1794 A character can belong to only one character range.
1795 For example, whole SIP belong to the range~4 in the default setting of \LuaTeX-ja,
1796 and if you execute the above line, then SIP will belong to the range~100 and be
1797 removed from the range~4.
1798 %</en>
1799 %<*ja>
1800 各文字はただ一つの文字範囲に所属することができる.
1801 例えば,SIPは全て\LuaTeX-jaのデフォルトでは4番の文字範囲に
1802 属しているが,上記の指定を行えばSIPは100番に属すようになり,4番からは除かれる.
1803 %</ja>
1804
1805 %<*en>
1806 The distinction between \textbf{ALchar} and \textbf{JAchar} is done for character ranges.
1807 This can be edited by setting the \textsf{jacharrange} parameter.
1808 For example, this is just the default setting of \LuaTeX-ja, and
1809 it sets
1810 \begin{itemize}
1811  \item a character which belongs character ranges 1,~4, and~5 is \textbf{ALchar},
1812  \item a character which belongs character ranges 2,~3, 6, 7, and~8 is \textbf{JAchar}.
1813 \end{itemize}
1814 %</en>
1815 %<*ja>
1816 \textbf{ALchar}と\textbf{JAchar}の区別は文字範囲ごとに行われる.
1817 これは\textsf{jacharrange}パラメータによって編集できる.
1818 例えば,以下は\LuaTeX-jaの初期設定であり,次の内容を設定している:
1819 \begin{itemize}
1820  \item 1番,4番,5番の文字範囲に属する文字は\textbf{ALchar}.
1821  \item 2番,3番,6番,7番,8番の文字範囲に属する文字は\textbf{JAchar}.
1822 \end{itemize}
1823 %</ja>
1824 \begin{lstlisting}
1825 \ltjsetparameter{jacharrange={-1, +2, +3, -4, -5, +6, +7, +8}}
1826 \end{lstlisting}
1827 %<*en>
1828 The argument to \textsf{jacharrange} parameter is a list of non-zero integer.
1829 Negative integer $-n$ in the list means that ``each character in the range~$n$ is an
1830 \textbf{ALchar}'',
1831 and positive integer $+n$ means that ``\dots\ is a \textbf{JAchar}''.
1832 %</en>
1833 %<*ja>
1834 \textsf{jacharrange}パラメータの引数は非零の整数のリストである.
1835 リスト中の負の整数$-n$は「文字範囲$n$に属する文字は\textbf{ALchar}として
1836 扱う」ことを意味し,正の整数$+n$は「\textbf{JAchar}として扱う」ことを意味する.
1837 %</ja>
1838
1839 %<*en>
1840 \paragraph{Default setting}
1841 \LuaTeX-ja predefines eight character ranges for convenience. They are
1842 determined from the following data:
1843 %</en>
1844 %<*ja>
1845 \paragraph{初期設定}
1846 \LuaTeX-jaでは8つの文字範囲を予め定義しており,
1847 これらは以下のデータに基づいて決定している.
1848 %</ja>
1849 \begin{itemize}
1850 %<en>\item Blocks in Unicode~6.0.
1851 %<ja>\item Unicode~6.0のブロック.
1852 %<en>\item The \texttt{Adobe-Japan1-UCS2} mapping between a CID Adobe-Japan1-6 and Unicode.
1853 %<ja>\item Adobe-Japan1-6のCIDとUnicodeの間の対応表\texttt{Adobe-Japan1-UCS2}.
1854 %<en>\item The \Pkg{PXbase} bundle for \upTeX\ by Takayuki Yato.
1855 %<ja>\item 八登崇之氏による\upTeX 用の\Pkg{PXbase}バンドル.
1856 \end{itemize}
1857
1858 %<*en>
1859 Now we describe these eight ranges. The superscript ``J'' or ``A'' after the
1860 number shows whether each character in the range is treated as
1861 \textbf{JAchar}s or not by default. These settings are similar to the
1862 \texttt{prefercjk} settings defined in \texttt{PXbase} bundle.
1863 Any characters above \texttt{U+0080} which does not belong to
1864 these eight ranges belongs to the character range~217.
1865 %</en>
1866 %<*ja>
1867 以下ではこれら8つの文字範囲について記述する.添字のアルファベット「J」「A」
1868 は,その文字範囲内の文字が\textbf{JAchar}か\textbf{ALchar}かを表している.これらの設定は
1869 \texttt{PXbase}バンドルで定義されている\texttt{prefercjk}と類似のものである.
1870 なお,\texttt{U+0080} 以降でこれら8つの文字範囲に属さない文字は,217番の文字範囲に属することになっている.
1871 %</ja>
1872 \begin{description}
1873 %<*en>
1874
1875 \item[Range~8${}^{\text{J}}$] The intersection of the upper half of ISO~8859-1
1876          (Latin-1 Supplement) and JIS~X~0208 (a basic character set for Japanese). This character range
1877          consists of the following characters:
1878 %</en>
1879 %<*ja>
1880 \item[範囲8${}^{\text{J}}$] ISO~8859-1の上位領域(ラテン1補助)と
1881                              JIS~X~0208の共通部分.この文字範囲は
1882                              以下の文字で構成される:
1883 %</ja>
1884 \begin{multicols}{2}
1885 \begin{itemize}
1886 \def\ch#1#2{\item \char"#1\ (\texttt{U+00#1}, #2)}%"
1887 \ch{A7}{Section Sign}
1888 \ch{A8}{Diaeresis}
1889 \ch{B0}{Degree sign}
1890 \ch{B1}{Plus-minus sign}
1891 \ch{B4}{Spacing acute}
1892 \ch{B6}{Paragraph sign}
1893 \ch{D7}{Multiplication sign}
1894 \ch{F7}{Division Sign}
1895 \end{itemize}
1896 \end{multicols}
1897
1898 %<*en>
1899 \item[Range~1${}^{\text{A}}$] Latin characters that some of them are included in Adobe-Japan1-6.
1900 This range consists of the following Unicode ranges, \emph{except characters in the range~8 above}:
1901 %</en>
1902 %<*ja>
1903 \item[範囲1${}^{\text{A}}$] ラテン文字のうち,Adobe-Japan1-6との共通部分があるもの.
1904                              この範囲は以下のUnicodeのブロックのうち
1905                              \emph{範囲8を除いた}部分で構成されている:
1906 %</ja>
1907 \begin{multicols}{2}
1908 \begin{itemize}
1909 \item \texttt{U+0080}--\texttt{U+00FF}: Latin-1 Supplement
1910 \item \texttt{U+0100}--\texttt{U+017F}: Latin Extended-A
1911 \item \texttt{U+0180}--\texttt{U+024F}: Latin Extended-B
1912 \item \texttt{U+0250}--\texttt{U+02AF}: IPA Extensions
1913 \item \texttt{U+02B0}--\texttt{U+02FF}: Spacing Modifier Letters
1914 \item \texttt{U+0300}--\texttt{U+036F}: \\\null\hfill Combining Diacritical Marks
1915 \item \texttt{U+1E00}--\texttt{U+1EFF}: \\\null\hfill Latin Extended Additional
1916 \par\
1917 \end{itemize}
1918 \end{multicols}
1919 %<*en>
1920 \item[Range~2${}^{\text{J}}$] Greek and Cyrillic letters. JIS~X~0208 (hence most of Japanese
1921            fonts) has some of these characters.
1922 %</en>
1923 %<*ja>
1924 \item[範囲2${}^{\text{J}}$] ギリシャ文字とキリル文字.JIS~X~0208(したがってほとんどの
1925                              和文フォント)はこれらの文字を持つ.
1926 %</ja>
1927 \begin{multicols}{2}
1928 \begin{itemize}
1929 \item \texttt{U+0370}--\texttt{U+03FF}: Greek and Coptic
1930 \item \texttt{U+0400}--\texttt{U+04FF}: Cyrillic
1931 \item \texttt{U+1F00}--\texttt{U+1FFF}: Greek Extended
1932 \\\
1933 \end{itemize}
1934 \end{multicols}
1935 %<*en>
1936 \item[Range~3${}^{\text{J}}$] Punctuations and Miscellaneous symbols. The block list is
1937            indicated in Table~\ref{table-rng3}.
1938 %</en>
1939 %<*ja>
1940 \item[範囲3${}^{\text{J}}$] 句読点と記号類.ブロックのリストは表\ref{table-rng3}%
1941                              に示してある.
1942 %</ja>
1943 \begin{table}[!tb]
1944 %<en>\caption{Unicode blocks in predefined character range~3.}\medskip
1945 %<ja>\caption{文字範囲3に指定されているUnicodeブロック.}
1946 \label{table-rng3}
1947 \catcode`\"=13\def"#1#2#3#4{\texttt{U+#1#2#3#4}}%"
1948 \centering\small
1949 \begin{tabular}{llll}
1950 "2000--"206F&General Punctuation&
1951 "2070--"209F&Superscripts and Subscripts\\
1952 "20A0--"20CF&Currency Symbols&
1953 "20D0--"20FF&Comb.\ Diacritical Marks for Symbols\\
1954 "2100--"214F&Letterlike Symbols&
1955 "2150--"218F&Number Forms\\
1956 "2190--"21FF&Arrows&
1957 "2200--"22FF&Mathematical Operators\\
1958 "2300--"23FF&Miscellaneous Technical&
1959 "2400--"243F&Control Pictures\\
1960 "2500--"257F&Box Drawing&
1961 "2580--"259F&Block Elements\\
1962 "25A0--"25FF&Geometric Shapes&
1963 "2600--"26FF&Miscellaneous Symbols\\
1964 "2700--"27BF&Dingbats&
1965 "2900--"297F&Supplemental Arrows-B\\
1966 "2980--"29FF&Misc.\ Mathematical Symbols-B&
1967 "2B00--"2BFF&Miscellaneous Symbols and Arrows
1968 \end{tabular}
1969 \end{table}
1970 %<*en>
1971 \item[Range~4${}^{\text{A}}$] Characters usually not in Japanese fonts. This range consists
1972            of almost all Unicode blocks which are not in other
1973            predefined ranges. Hence, instead of showing the block list,
1974            we put the definition of this range itself:
1975 %</en>
1976 %<*ja>
1977 \item[範囲4${}^{\text{A}}$] 通常和文フォントには含まれていない文字.
1978                              この範囲は他の範囲にないほとんど全てのUnicodeブロック
1979                              で構成されている.したがって,ブロックのリストを示す
1980                              代わりに,範囲の定義そのものを示す:
1981 %</ja>
1982 \begin{lstlisting}
1983 \ltjdefcharrange{4}{%
1984    "500-"10FF, "1200-"1DFF, "2440-"245F, "27C0-"28FF, "2A00-"2AFF,
1985   "2C00-"2E7F, "4DC0-"4DFF, "A4D0-"A82F, "A840-"ABFF, "FB00-"FE0F,
1986   "FE20-"FE2F, "FE70-"FEFF, "10000-"1FFFF, "E000-"F8FF} % non-Japanese
1987 \end{lstlisting}
1988 %<en>\item[Range~5${}^{\text{A}}$] Surrogates and Supplementary Private Use Areas.
1989 %<ja>\item[範囲5${}^{\text{A}}$] 代用符号と補助私用領域.
1990 %<en>\item[Range~6${}^{\text{J}}$] Characters used in Japanese. The block list is indicated in Table~\ref{table-rng6}.
1991 %<ja>\item[範囲6${}^{\text{J}}$] 日本語で用いられる文字.ブロックのリストは表\ref{table-rng6}に示す.
1992 \begin{table}[!tb]
1993 %<en>\caption{Unicode blocks in predefined character range~6.}\medskip
1994 %<ja>\caption{文字範囲6に指定されているUnicodeブロック.}
1995 \label{table-rng6}
1996 \catcode`\"=13\def"#1#2#3#4{\texttt{U+#1#2#3#4}}%"
1997 \centering\small
1998 \begin{tabular}{llll}
1999 "2460--"24FF&Enclosed Alphanumerics&
2000 "2E80--"2EFF&CJK Radicals Supplement\\
2001 "3000--"303F&CJK Symbols and Punctuation&
2002 "3040--"309F&Hiragana\\
2003 "30A0--"30FF&Katakana&
2004 "3190--"319F&Kanbun\\
2005 "31F0--"31FF&Katakana Phonetic Extensions&
2006 "3200--"32FF&Enclosed CJK Letters and Months\\
2007 "3300--"33FF&CJK Compatibility&
2008 "3400--"4DBF&CJK Unified Ideographs Extension A\\
2009 "4E00--"9FFF&CJK Unified Ideographs&
2010 "F900--"FAFF&CJK Compatibility Ideographs\\
2011 "FE10--"FE1F&Vertical Forms&
2012 "FE30--"FE4F&CJK Compatibility Forms\\
2013 "FE50--"FE6F&Small Form Variants&
2014 "{20}000--"{2F}FFF&(Supplementary Ideographic Plane)\\
2015 "{E0}100--"{E0}1EF&Variation Selectors Supplement
2016 \end{tabular}
2017 \end{table}
2018 %<*en>
2019 \item[Range~7${}^{\text{J}}$] Characters used in CJK languages, but not included in  Adobe-Japan1-6.
2020 The block list is indicated in Table~\ref{table-rng7}.
2021 %</en>
2022 %<*ja>
2023 \item[範囲7${}^{\text{J}}$] CJK言語で用いられる文字のうち,Adobe-Japan1-6に
2024                             含まれていないもの.
2025                             ブロックのリストは表\ref{table-rng7}に示す.
2026 %</ja>
2027 \begin{table}[!tb]
2028 %<en>\caption{Unicode blocks in predefined character range~7.}\medskip
2029 %<ja>\caption{文字範囲7に指定されているUnicodeブロック.}
2030 \label{table-rng7}
2031 \catcode`\"=13\def"#1#2#3#4{\texttt{U+#1#2#3#4}}%"
2032 \centering\small
2033 \begin{tabular}{llll}
2034 "1100--"11FF&Hangul Jamo&
2035 "2F00--"2FDF&Kangxi Radicals\\
2036 "2FF0--"2FFF&Ideographic Description Characters&
2037 "3100--"312F&Bopomofo\\
2038 "3130--"318F&Hangul Compatibility Jamo&
2039 "31A0--"31BF&Bopomofo Extended\\
2040 "31C0--"31EF&CJK Strokes&
2041 "A000--"A48F&Yi Syllables\\
2042 "A490--"A4CF&Yi Radicals&
2043 "A830--"A83F&Common Indic Number Forms\\
2044 "AC00--"D7AF&Hangul Syllables&
2045 "D7B0--"D7FF&Hangul Jamo Extended-B
2046 \end{tabular}
2047 \end{table}
2048 \end{description}
2049
2050 %<en>\subsection{\Param{kanjiskip} and \Param{xkanjiskip}}
2051 %<ja>\subsection{\Param{kanjiskip}と\Param{xkanjiskip}}
2052 \label{subs-kskip}
2053
2054 %<en>\textbf{JAglue} is divided into the following three categories:
2055 %<ja>\textbf{JAglue}は以下の3つのカテゴリに分類される:
2056 \begin{itemize}
2057 %<*en>
2058 \item Glues/kerns specified in JFM. If \cs{inhibitglue} is issued
2059       around a Japanese character, this glue will not be inserted at the
2060       place.
2061 %</en>
2062 %<*ja>
2063 \item JFMで指定されたグルー/カーン.もし \cs{inhibitglue} が和文文字の周りで
2064       発行されていれば,このグルーは挿入されない.
2065 %</ja>
2066 %<*en>
2067 \item The default glue which inserted between two \textbf{JAchar}s (\Param{%
2068       kanjiskip}).
2069 %</en>
2070 %<*ja>
2071 \item デフォルトで2つの\textbf{JAchar}の間に挿入されるグルー(\Param{kanjiskip}).
2072 %</ja>
2073 %<*en>
2074 \item The default glue which inserted between a \textbf{JAchar} and an
2075       \textbf{ALchar} (\Param{xkanjiskip}).
2076 %</en>
2077 %<*ja>
2078 \item デフォルトで\textbf{JAchar}と\textbf{ALchar}の間に挿入されるグルー(\Param{xkanjiskip}).
2079 %</ja>
2080 \end{itemize}
2081 %<*en>
2082 The value (a skip) of \Param{kanjiskip} or
2083 \Param{xkanjiskip} can be changed as the following.
2084 Note that only their values \emph{at the end of a paragraph or a hbox are
2085 adopted in the whole paragraph or the whole hbox.
2086 }
2087 %</en>
2088 %<*ja>
2089 \Param{kanjiskip}や\Param{xkanjiskip}の値
2090 は以下のようにして変更可能である.
2091 %</ja>
2092 \begin{lstlisting}
2093 \ltjsetparameter{kanjiskip={0pt plus 0.4pt minus 0.4pt},
2094                  xkanjiskip={0.25\zw plus 1pt minus 1pt}}
2095 \end{lstlisting}
2096 %<*en>
2097 Here \cs{zw} is a internal dimension
2098 which stores fullwidth of the current Japanese font.
2099 This \cs{zw} can be used as the unit \texttt{zw} in \pTeX.
2100
2101 The value of these parameter can be get by \cs{ltjgetparameter}.
2102 Note that the result by \cs{ltjgetparameter} is \emph{not} the internal quantities,
2103 but \emph{a string} (hence \cs{the} cannot be prefixed).
2104 %</en>
2105 %<*ja>
2106 ここで,\cs{zw} は現在の和文フォントの全角幅を表す長さであり,
2107 \pTeX における長さ単位 \texttt{zw} と同じように使用できる.
2108
2109 これらのパラメータの値は以下のように取得できる.
2110 戻り値は内部値ではなく\emph{文字列}である(\cs{the} は前置できない)ことに注意してほしい:
2111 %</ja>
2112 \begin{LTXexample}
2113 kanjiskip: \ltjgetparameter{kanjiskip},\\
2114 xkanjiskip: \ltjgetparameter{xkanjiskip}
2115 \end{LTXexample}
2116
2117 %<*en>
2118 It may occur that JFM contains the data of ``ideal width of
2119 \Param{kanjiskip}''
2120 and/or ``ideal width of \Param{xkanjiskip}''.
2121 To use these data from JFM, set the value of \Param{kanjiskip} or
2122 \Param{xkanjiskip} to \cs{maxdimen}
2123 (these ``ideal width'' cannot be retrived by \cs{ltjgetparameter}).
2124 %</en>
2125 %<*ja>
2126 JFMは「望ましい\Param{kanjiskip}の値」や
2127 「望ましい\Param{xkanjiskip}の値」を持っていることがある.
2128 これらのデータを使うためには,\Param{kanjiskip}や%
2129 \Param{xkanjiskip}の値を \cs{maxdimen} の値に設定すればよいが,
2130 \cs{ltjgetparameter} によって取得することはできないので注意が必要である.
2131 %</ja>
2132
2133 %<en>\subsection{Insertion Setting of \Param{xkanjiskip}}
2134 %<ja>\subsection{\Param{xkanjiskip} の挿入設定}
2135
2136 %<*en>
2137 It is not desirable that \Param{xkanjiskip} is inserted into every
2138 boundary between \textbf{JAchar}s and \textbf{ALchar}s. For example,
2139 \Param{xkanjiskip} should not be inserted after opening parenthesis
2140 (\textit{e.g.}, compare ``(あ'' and ``(\hskip\ltjgetparameter{xkanjiskip}あ'').
2141 \LuaTeX-ja can control whether \Param{xkanjiskip} can be inserted
2142 before/after a character, by changing \Param{jaxspmode} for \textbf{JAchar}s and
2143 \Param{alxspmode} parameters \textbf{ALchar}s respectively.
2144 %</en>
2145 %<*ja>
2146 \Param{xkanjiskip}がすべての\textbf{JAchar}と\textbf{ALchar}の境界に
2147 挿入されるのは望ましいことではない.例えば,\Param{xkanjiskip}は開き括弧の
2148 後には挿入されるべきではない(「(あ」と「(\hskip\ltjgetparameter{xkanjiskip}あ」を
2149 比べてみよ).
2150 \LuaTeX-jaでは\Param{xkanjiskip}をある文字の前/後に挿入するかどうかを,
2151 \textbf{JAchar}に対しては\Param{jaxspmode}を,\textbf{ALchar}に対しては
2152 \Param{alxspmode}をそれぞれ変えることで制御することができる.
2153 %</ja>
2154 \begin{LTXexample}
2155 \ltjsetparameter{jaxspmode={`あ,preonly}, alxspmode={`\!,postonly}}
2156 pあq い!う
2157 \end{LTXexample}
2158
2159 %<*en>
2160 The second argument \texttt{preonly} means that the insertion of
2161 \Param{xkanjiskip} is allowed before this character, but not after.
2162 the other possible values are \texttt{postonly}, \texttt{allow}, and \texttt{inhibit}.
2163 %</en>
2164 %<*ja>
2165 2つ目の引数の \texttt{preonly}は「\Param{xkanjiskip}の挿入はこの文字の
2166 前でのみ許され,後では許さない」ことを意味する.他に指定可能な値は
2167 \texttt{postonly}, \texttt{allow}, \texttt{inhibit}である.
2168 %</ja>
2169
2170 %<*en>
2171 \Param{jaxspmode} and \Param{alxspmode} use a same table to store the parameters
2172 on the current version. Therefore, line~1 in the code above can be rewritten
2173 as follows:
2174 %</en>
2175 %<*ja>
2176 なお,現行の
2177 仕様では,\Param{jaxspmode}, \Param{alxspmode}はテーブルを共有しており,
2178 上のコードの1行目を次のように変えても同じことになる:
2179 %</ja>
2180 \begin{lstlisting}
2181 \ltjsetparameter{alxspmode={`あ,preonly}, jaxspmode={`\!,postonly}}
2182 \end{lstlisting}
2183 %<*en>
2184 One can use also numbers to specify these two parameters (see Subsection~\ref{ssec-param}).
2185 %</en>
2186 %<*ja>
2187 また,これら2パラメータには数値で値を指定することもできる(\ref{ssec-param}節を参照).
2188 %</ja>
2189
2190 %<*en>
2191 If you want to enable/disable all insertions of \Param{kanjiskip} and
2192 \Param{xkanjiskip}, set \Param{autospacing} and \Param{autoxspacing}
2193 parameters to \texttt{true}/\texttt{false}, respectively.
2194 %</en>
2195 %<*ja>
2196 もし全ての\Param{kanjiskip}と\Param{xkanjiskip}の挿入を有効化/無効化
2197 したければ,それぞれ\Param{autospacing}と\Param{autoxspacing}を
2198 \texttt{true}/\texttt{false}に設定すればよい.
2199 %</ja>
2200
2201 %<en>\subsection{Shifting the baseline}
2202 %<ja>\subsection{ベースラインの移動}
2203 %<*en>
2204 To make a match between a Japanese font and an alphabetic font, sometimes
2205 shifting of the baseline of one of the pair is needed. In \pTeX, this is achieved
2206 by setting \cs{ybaselineshift} (or \cs{tbaselineshift}) to a non-zero length (the
2207 baseline of \textbf{ALchar} is shifted below). However, for documents
2208 whose main language is not Japanese, it is good to shift the baseline of
2209 Japanese fonts, but not that of alphabetic fonts.
2210 Because of this, \LuaTeX-ja can independently set the shifting amount
2211 of the baseline of alphabetic fonts and that of Japanese fonts.
2212 \begin{center}
2213  \small
2214 \begin{tabular}{>{\bfseries}lcc}
2215 \toprule
2216 &\bfseries Horizontal writing (\emph{yoko} direction) etc.
2217 &\bfseries Vertical writing(\emph{tate} direction)\\
2218 \midrule
2219 Alphabetic fonts&\Param{yalbaselineshift}
2220      parameter&\Param{talbaselineshift} parameter\\
2221 Japanese fonts&\Param{yjabaselineshift}
2222      parameter&\Param{tjabaselineshift} parameter\\
2223 \bottomrule
2224 \end{tabular}
2225 \end{center}
2226 %</en>
2227 %<*ja>
2228 和文フォントと欧文フォントを合わせるためには,時々どちらかのベースラインの移動が
2229 必要になる.\pTeX ではこれは \cs{ybaselineshift} を設定することで
2230 なされていた(\textbf{ALchar}のベースラインがその分だけ下がる).しかし,日本語が主ではない
2231 文書に対しては,欧文フォントではなく和文フォントのベースラインを移動した方がよい.
2232 このため,\LuaTeX-jaでは欧文フォントのベースラインのシフト量
2233 と和文フォントのベースラインのシフト量を独立に設定できるようになっている.
2234 \begin{center}
2235  \small
2236 \begin{tabular}{>{\bfseries}lcc}
2237 \toprule
2238 &\bfseries 横組など&\bfseries 縦組\\
2239 \midrule
2240 欧文フォントのシフト量&\Param{yalbaselineshift}
2241      parameter&\Param{talbaselineshift} parameter\\
2242 和文フォントのシフト量&\Param{yjabaselineshift}
2243      parameter&\Param{tjabaselineshift} parameter\\
2244 \bottomrule
2245 \end{tabular}
2246 \end{center}
2247 %</ja>
2248
2249 %<*en>
2250 Here the horizontal line in the below example is the baseline of a line.
2251 %</en>
2252 %<*ja>
2253 下の例において引かれている水平線がベースラインである.
2254 %</ja>
2255 \begin{LTXexample}
2256 \vrule width 150pt height 0.4pt depth 0pt \hskip-120pt
2257 \ltjsetparameter{yjabaselineshift=0pt, yalbaselineshift=0pt}abcあいう
2258 \ltjsetparameter{yjabaselineshift=5pt, yalbaselineshift=2pt}abcあいう
2259 \end{LTXexample}
2260
2261 %<*en>
2262 There is an interesting side-effect: characters in different size can be
2263 vertically aligned center in a line, by setting two parameters appropriately.
2264 The following is an example (beware the value is not well tuned):
2265 %</en>
2266 %<*ja>
2267 この機能には面白い使い方がある:2つのパラメータを適切に設定することで,サイズの
2268 異なる文字を中心線に揃えることができる.
2269 以下は一つの例である(値はあまり調整されていないことに注意):
2270 %</ja>
2271 \begin{LTXexample}
2272 xyz漢字
2273 {\scriptsize
2274   \ltjsetparameter{yjabaselineshift=-1pt,
2275     yalbaselineshift=-1pt}
2276   XYZひらがな
2277 }abcかな
2278 \end{LTXexample}
2279
2280 %<*en>
2281 Note that setting positive \Param{yalbaselineshift}~or~\Param{talbaselineshift}
2282 parameters does not increase the depth of one-letter ``syllable'' $p$ of \textbf{Alchar}, if
2283 its left-protrusion~(\cs{lpcode}) and right-protrusion~(\cs{rpcode}) are both non-zero.
2284 This is because
2285 \begin{itemize}
2286 \item These two parameters are implemented by setting yoffset field of a
2287 glyph node, and this does not increase the depth of the glyph.
2288 \item To cope with the above situation, \LuaTeX-ja automatically supplies
2289 a rule in every ``syllable''.
2290 \item However, we cannot use this ``supplying a rule'' method if \dots
2291 \end{itemize}
2292
2293 This problem does not apply for \Param{yjabaselineshift}~nor~\Param{tjabaselineshift}.
2294 %</en>
2295 %<*ja>
2296 なお,以下の場合には1文字の\textbf{ALchar}からなる「音節」の深さは増加しないことに注意.
2297 \begin{itemize}
2298  \item \Param{yalbaselineshift},~\Param{talbaselineshift}パラメータが正になっている.
2299  \item 「音節」を構成する唯一の文字$p$の
2300 左余白への突出量(\cs{lpcode}),右余白への突出量(\cs{rpcode})がどちらも非零である.
2301 \end{itemize}
2302 \Param{yjabaselineshift},~\Param{tjabaselineshift}パラメータについてはこのような問題は起こらない.
2303 %</ja>
2304
2305 %<*ja>
2306 \paragraph{数式における挙動:\pTeX との違い}
2307 \textbf{ALchar}のベースラインを補正する \Param{yalbaselineshift} パラメータは
2308 ほぼ\pTeX における \cs{ybaselineshift} に対応しているものであるが,
2309 数式中の挙動は異なっているので注意が必要である.
2310 例えば,表\ref{tab:math_bsa}のように,数式中に明示的に現れた \cs{hbox} は,
2311 \begin{itemize}
2312  \item \pTeX では,ボックス全体が \cs{ybaselineshift} だとシフトされるので,
2313  表\ref{tab:math_bsa}中の``い''のように,ボックス中の和文文字は
2314  \ \cs{ybaselineshift} だけシフトされ,一方,``for all''のように,
2315  ボックス内の欧文文字は2重にシフトされることになる.
2316  \item 一方,\LuaTeX-jaではそのようなことはおこらず,
2317  数式中に明示的に現れた \cs{hbox} はシフトしない.そのため,
2318  表\ref{tab:math_bsa}中の``い''も``for all''も,それぞれ本文中に
2319  書かれたときと同じ上下位置に組まれる.
2320 \end{itemize}
2321 \begin{table}
2322 \small\centering
2323 \caption{数式関係のベースライン補正($\Param{yalbaselineshift}=10\,\textrm{pt}$)}
2324 \label{tab:math_bsa}
2325 \newdimen\origbaselineskip
2326 \origbaselineskip=\baselineskip
2327 \begin{tabular}{lp{30\zw}}
2328 \toprule
2329 \emph{入力}&\vspace*{\dimexpr-\origbaselineskip-\smallskipamount}
2330 \begin{lstlisting}
2331 数式abc: $あa\hbox{い}$, $\int_0^x t\,dt=x^2\!/2$,
2332 $\Phi\vdash F(x)\ \hbox{for all}\ x\in A$
2333 \end{lstlisting}\\
2334 \noalign{\vskip-\origbaselineskip}
2335 \midrule
2336 \emph{\pTeX}&
2337 {\ltjsetparameter{yalbaselineshift=10pt}%
2338 数式abc: $あa\lower10pt\hbox{い}$, $\int_0^x t\,dt=x^2\!/2$,
2339 $\Phi\vdash F(x)\ \lower10pt\hbox{for all}\ x\in A$
2340 \par}\\
2341 \midrule
2342 \emph{\LuaTeX-ja}&
2343 {\ltjsetparameter{yalbaselineshift=10pt}%
2344 数式abc: $あa\hbox{い}$, $\int_0^x t\,dt=x^2\!/2$,
2345 $\Phi\vdash F(x)\ \hbox{for all}\ x\in A$
2346 \par}\\
2347 \noalign{\vskip-\origbaselineskip}
2348 \bottomrule
2349 \end{tabular}
2350 \end{table}
2351 %</ja>
2352
2353 \clearpage
2354 %<en>\part{Reference}
2355 %<ja>\part{リファレンス}
2356 \label{part-ref}
2357 \suppressfloats[t]
2358 %<*ja>
2359 \section{\LuaTeX-jaにおける \cs{catcode}}
2360 \label{sec-catcode}
2361 \subsection{予備知識:\pTeX と\upTeX における \cs{kcatcode}}
2362 \pTeX,\upTeX においては,和文文字が制御綴内で利用できるかどうか
2363 は \cs{kcatcode} の値によって決定されるのであった.
2364 詳細は表\ref{table-kcat}を参照されたい.
2365 %</ja>
2366 %<*en>
2367 \section{\cs{catcode} in \LuaTeX-ja}
2368 \label{sec-catcode}
2369 \subsection{Preliminaries: \cs{kcatcode} in \pTeX\ and \upTeX}
2370 In \pTeX~and~\upTeX, the value of \cs{kcatcode} determines
2371 whether a Japanese character can be used in a control word.
2372 For the detail, see Table~\ref{table-kcat}.
2373 %</en>
2374
2375 \begin{table}[t]
2376 \small
2377 \caption{\cs{kcatcode} in \upTeX}
2378 \label{table-kcat}
2379 %<en>\medskip
2380
2381 \noindent\hfill
2382 \begin{tabular}{ccccc}
2383 \toprule
2384 \bfseries \cs{kcatcode}&
2385 %<*en>
2386 \bfseries meaning&
2387 \bfseries control word&
2388 \bfseries widow penalty\hbox{}$^*$&
2389 \bfseries linebreak\\
2390 %</en>
2391 %<*ja>
2392 \bfseries 意図&
2393 \bfseries 制御綴中に使用&
2394 \bfseries 文字ウィドウ処理\hbox{}$^*$&
2395 \bfseries 直後での改行\\
2396 %</ja>
2397 \midrule
2398 15&non-cjk&\multicolumn{3}{c}{(treated as usual \LaTeX)}\\
2399 16&kanji&Y&Y&ignored\\
2400 17&kana&Y&Y&ignored\\
2401 18&other&N&N&ignored\\
2402 19&hangul&Y&Y&space\\
2403 \bottomrule
2404 \end{tabular}\hfill\null
2405
2406 \medskip
2407
2408 %<*ja>
2409 文字ウィドウ処理\hbox{}$^*$: 「漢字が一文字だけ次の行に行くのを防ぐ」\
2410 \cs{jcharwidowpenalty} が,
2411 その文字の直前に挿入されうるか否か,を示す.
2412 %</ja>
2413 \end{table}
2414
2415 %<*en>
2416 \cs{kcatcode} can be set by a row of JIS~X~0208 in \pTeX,
2417 and generally by a Unicode block\footnote{%
2418   \upTeX\ divides \texttt{U+FF00}--\texttt{U+FFEF} (Halfwidth and Fullwidth Forms)
2419   into three subblocks, and \cs{kcatcode} can be set by a subblock.
2420 }
2421 in \upTeX. So characters which can be used in a control word
2422 slightly differ between \pTeX~and~\upTeX.
2423 %</en>
2424 %<*ja>
2425 \pTeX では \cs{kcatcode} はJIS~X~0208の区単位,
2426 \upTeX では概ねUnicodeブロック単位\footnote{%
2427   \texttt{U+FF00}--\texttt{U+FFEF} (Halfwidth and Fullwidth Forms)は
2428   「全角英数字」「半角カナ」「その他」と3つに分割されており,
2429   それぞれ別々に \cs{kcatcode} が指定できるようになっている.
2430 }で設定可能になっている.そのため,\pTeX と\upTeX の初期状態では
2431 制御綴内で使用可能な文字が微妙に異なっている.
2432 %</ja>
2433
2434 %<*en>
2435 \subsection{Case of \LuaTeX-ja}
2436 The role of \cs{kcatcode} in \pTeX~and~\upTeX\ can be
2437 divided into the following four kinds,
2438 and \LuaTeX-ja can control these four kinds separately:
2439 \begin{itemize}
2440  \item
2441 \emph{Distinction between \textbf{JAchar} or \textbf{ALchar}}
2442 is controlled by using the character range, see Subsection~\ref{ssec-setrange}.
2443  \item
2444 \emph{Whether the character can be used in a control word}
2445 is controlled by setting \cs{catcode} to 11~(enabled) or 12~(disabled), as usual.
2446  \item
2447 \emph{Whether \Param{jcharwidowpenalty} can be inserted before the character}
2448 is controlled by the lowermost bit of the \Param{kcatcode} parameter.
2449  \item
2450 \emph{Ignoring linebreak after a \textbf{JAchar}} is always ignored.
2451 \end{itemize}
2452 %</en>
2453 %<*ja>
2454 \subsection{\LuaTeX-jaの場合}
2455 \LuaTeX-jaでは,従来の\pTeX・\upTeX における \cs{kcatcode} の役割を
2456 分割している:
2457 \begin{description}
2458  \item[欧文/和文の区別 (\upTeX)]
2459 \cs{ltjdefcharrange} と\textsf{jacharrange}パラメータ(\ref{ssec-setrange}節)
2460  \item[制御綴中に使用可か]
2461 \LuaTeX 自身の \cs{catcode} でよい
2462  \item[\Param{jcharwidowpenalty}が挿入可か]
2463 \Param{kcatcode}パラメータの最下位ビット
2464  \item[直後の改行の無視]
2465 日本語しか想定していないので\textbf{JAchar}については一律有効
2466 \end{description}
2467 %</ja>
2468
2469 %<*en>
2470 Default setting of \cs{catcode} of \LuaTeX\ can be found
2471 in \texttt{luatex-unicode-letters.tex},
2472 which is based on \texttt{unicode-letters.tex} (for \XeTeX).
2473 However, the default setting of \cs{catcode} differs
2474 between \XeTeX\ and \LuaTeX, by the following reasons:
2475 \begin{itemize}
2476  \item \texttt{luatex-unicode-letters.tex} is based on old \texttt{unicode-letters.tex}.
2477  \item The latter half of \texttt{unicode-letters.tex} sets
2478 \cs{catcode} of Kanji and kana characters to 11,
2479 via setting \cs{XeTeXcharclass}.
2480
2481 However, this latter half is simply omitted in
2482 \texttt{luatex-unicode-letters.tex}, hence
2483 \cs{catcode} of Kanji and kana characters remains 12 in \LuaTeX.
2484 \end{itemize}
2485 In other words, Kanji nor kana characters cannot be used in
2486 a control word, in the default setting of \LuaTeX.
2487
2488 This would be inconvenient for \pTeX~users to shifting to \LuaTeX-ja,
2489 since several control words containing Kanji, such as \verb+\西暦+,
2490 are used in \pTeX.
2491 Hence, \LuaTeX-ja have a counterpart of \texttt{unicode-letters.tex}
2492 for \LuaTeX, \emph{to match the \cs{catcode} setting with that of \XeTeX.}
2493 %</en>
2494 %<*ja>
2495 ネイティブにUnicode全部の文字を扱える\XeTeX や\LuaTeX では,
2496 文字が制御綴内で使用できるかは通常の欧文文字と同じく \cs{catcode}
2497 で指定することとなる.\XeTeX における \cs{catcode} の初期設定は\
2498 \texttt{unicode-letters.tex} 中に記述されており,\LuaTeX ではそれを
2499 元にした \texttt{luatex-unicode-letters.tex} を用いている.
2500
2501 だが,\XeTeX における \cs{catcode} の初期設定と
2502 \LuaTeX におけるそれは一致していない:
2503 \begin{itemize}
2504  \item \texttt{luatex-unicode-letters.tex} の元になった\
2505 \texttt{unicode-letters.tex} が古い
2506  \item \texttt{unicode-letters.tex} の後半部では
2507 \cs{XeTeXcharclass} の設定を行なっており,
2508 それによって漢字や仮名の \cs{catcode} が11に設定されている.
2509
2510 しかし,\texttt{luatex-unicode-letters.tex} ではこの「後半部」が
2511 まるごと省略されており,漢字や仮名の \cs{catcode} は12のまま.
2512 \end{itemize}
2513 言い換えると,\LuaTeX の初期状態では漢字や仮名を制御綴内に
2514 使用することはできない.
2515
2516 これでは \pTeX で使用できた \verb+\西暦+ などが使えないこととなり,
2517 \LuaTeX-jaへの移行で手間が生じる.そのため,\LuaTeX-jaでは
2518 \texttt{unicode-letters.tex} の後半部にあたる内容を自前でパッチし,
2519 結果として\textbf{\XeTeX における初期設定と同じになるようにしている.}
2520 %</ja>
2521
2522 \begin{table}
2523  \centering\small
2524 %<en>\caption{Difference of the set of non-kanji JIS~X~0208 characters which can be used in a control word}
2525 %<ja>\caption{制御綴中に使用出来るJIS~X~0208非漢字の違い}
2526 %<en>\medskip
2527 \label{table-kcat-diff}
2528 \def\D#1#2#3#4{%
2529   {\fboxsep0pt\fcolorbox{cyan}{white}%
2530   {\large\char"#1#2#3#4}}\ (\texttt{U+#1#2#3#4})} %"
2531 \leavevmode\hbox to 0pt{\hss\begin{tabular}{cccccc}
2532 \toprule
2533 %<en>&\bf row&\bf col.&\bf \pTeX&\bf \upTeX&\bf\LuaTeX-ja\\
2534 %<ja>&\bf 区&\bf 点&\bf \pTeX&\bf \upTeX&\fontseries{b}\selectfont\LuaTeX-ja\\
2535 \midrule
2536 \D 3000&1&1&N&N&Y\\
2537 \D 30FB&1&6&N&Y&N\\
2538 \D 309B&1&11&N&Y&N\\
2539 \D 309C&1&12&N&Y&N\\
2540 \D FF40&1&14&N&N&Y\\
2541 \D FF3E&1&16&N&N&Y\\
2542 \D FFE3&1&17&N&N&Y\\
2543 \D FF3F&1&18&N&N&Y\\
2544 \D 30FD&1&19&N&Y&Y\\
2545 \D 30FE&1&20&N&Y&Y\\
2546 \D 309D&1&21&N&Y&Y\\
2547 \D 309E&1&22&N&Y&Y\\
2548 \D 3003&1&23&N&N&Y\\
2549 \D 4EDD&1&24&N&Y&Y\\
2550 \D 3005&1&25&N&N&Y\\
2551 \D 3006&1&26&N&N&Y\\
2552 \D 3007&1&27&N&N&Y\\
2553 \D 30FC&1&28&N&Y&Y\\
2554 \bottomrule
2555 \end{tabular}\qquad
2556 \begin{tabular}{cccccc}
2557 \toprule
2558 %<en>&\bf row&\bf col.&\bf \pTeX&\bf \upTeX&\bf\LuaTeX-ja\\
2559 %<ja>&\bf 区&\bf 点&\bf \pTeX&\bf \upTeX&\fontseries{b}\selectfont\LuaTeX-ja\\
2560 \midrule
2561 \D FF0F&1&31&N&N&Y\\
2562 \D FF3C&1&32&N&N&Y\\
2563 \D FF5C&1&35&N&N&Y\\
2564 \D FF0B&1&60&N&N&Y\\
2565 \D FF1D&1&65&N&N&Y\\
2566 \D FF1C&1&67&N&N&Y\\
2567 \D FF1E&1&68&N&N&Y\\
2568 \D FF03&1&84&N&N&Y\\
2569 \D FF06&1&85&N&N&Y\\
2570 \D FF0A&1&86&N&N&Y\\
2571 \D FF20&1&87&N&N&Y\\
2572 \D 3012&2&9&N&N&Y\\
2573 \D 3013&2&14&N&N&Y\\
2574 \D FFE2&2&44&N&N&Y\\
2575 \D 212B&2&82&N&N&Y\\
2576 %<en>\multicolumn{3}{c}{$\vphantom{\D 3000}$\hbox{}Greek letters (row 6)}&Y&N&Y\\
2577 %<en>\multicolumn{3}{c}{$\vphantom{\D 3000}$\hbox{}Cyrillic letters (row 7)}&N&N&Y\\
2578 %<ja>\multicolumn{3}{c}{$\vphantom{\D 3000}$\hbox{}ギリシャ文字(6区)}&Y&N&Y\\
2579 %<ja>\multicolumn{3}{c}{$\vphantom{\D 3000}$\hbox{}キリル文字(7区)}&N&N&Y\\
2580 $\vphantom{\D 3000}$\\
2581 \bottomrule
2582 \end{tabular}\hss}\par
2583 \end{table}
2584
2585 %<*en>
2586 \subsection{Non-kanji Characters in a Control Word}
2587 Because the engine differ, so non-kanji JIS~X~0208 characters
2588 which can be used in a control word differ in \pTeX, in \upTeX,~and~in \LuaTeX-ja.
2589 Table~\ref{table-kcat-diff} shows the difference.
2590 Except for four characters ``・'',~``゛'', ``゜'',~``゠'',
2591 \LuaTeX-ja admits more characters in a control word than \upTeX.
2592 \emph{Note that the ideographic space~\texttt{U+3000} can be used
2593 in a control word in \LuaTeX-ja.}
2594
2595 Difference becomes larger, if we consider
2596 non-kanji JIS~X~0213 characters.
2597 For the detail, see \url{https://github.com/h-kitagawa/kct}.
2598 %</en>
2599 %<*ja>
2600 \subsection{制御綴中に使用出来るJIS非漢字の違い}
2601
2602 エンジンが異なるので,\pTeX, \upTeX, \LuaTeX-ja
2603 において制御綴中に使用可能なJIS~X~0208の文字は異なる.
2604 異なっているところだけを載せると,表\ref{table-kcat-diff}のようになる.
2605 「・」「゛」「゜」「゠」を除けば,\LuaTeX-jaでは\upTeX より多くの文字が
2606 制御綴に使用可能になっている.
2607 \textbf{特に重要なのは,全角空白(\texttt{U+3000})が
2608 \LuaTeX-jaでは制御綴中に使用可能であることである.}
2609
2610 JIS~X~0213の範囲に広げると,差異はさらに大きくなる.
2611 詳細については例えば \url{https://github.com/h-kitagawa/kct} 中の\
2612 \texttt{kct-uni-out.pdf} などを参照すること.
2613 %</ja>
2614
2615
2616 %<*en>
2617 \section{Directions}
2618 \LuaTeX\ supports four $\Omega$-style directions: \texttt{TLT},~\texttt{TRT}, \texttt{RTT}
2619 and \texttt{LTL}.
2620 However, neither directions are not well-suited for typesetting Japanese vertically, hence we
2621 implemented vertical writing by rotating \texttt{TLT}-box by 90~degrees.
2622 %</en>
2623 %<*ja>
2624 \section{縦組}
2625 \label{sec-direction}
2626 \LuaTeX 本体でも,$\Omega$・$\aleph$由来の機能として,複数の組方向をサポートしている.
2627 しかし,\LuaTeX がサポートするのは \texttt{TLT},~\texttt{TRT}, \texttt{RTT},~\texttt{LTL}\
2628 のみであり,日本語の縦組に使うのは望ましくない\footnote{%
2629 和文文字だけならば \texttt{RTT} を使えばなんとかなると思うが,
2630 欧文文字が入ってきた場合はうまくいかず,\texttt{RTR} という組方向が必要になる.
2631 }.そのため,\LuaTeX-jaでは横組(\texttt{TLT})で組んだボックスを回転させる方式で
2632 縦組を実装した.
2633 %</ja>
2634
2635 %<ja>\subsection{サポートする組方向}
2636 \begin{table}[t]
2637 %<ja>\caption{\LuaTeX-ja のサポートする組方向}
2638 %<en>\caption{Directions supported by \LuaTeX-ja}
2639 %<en>\medskip
2640 \label{tab-dir}
2641 \centering\small
2642 \def\obox#1{%
2643   \setbox0=\hbox{\yoko\hbox{#1%
2644   \large\ltjsetparameter{talbaselineshift=0pt}%
2645   \vrule height 25pt width 0.4pt depth 15pt\kern-.2pt%
2646   \raise25pt\hbox to 0pt{\hss\composite{*r^@{>>}}\hss}%
2647   \raise-15pt\hbox to 0pt{\hss\composite{*l^@{>|}}\hss}\kern.2pt%
2648   \vrule height.2pt depth.2pt width 60pt\hbox to 0pt{\hss\composite{*d^@{>}}\hss}\kern-60pt
2649   \hbox to 60pt{\,銀は、Ag\hss}}}%
2650   \raise\dimexpr 0.5\ltjgetdp0-0.5\ltjgetht0\box0%
2651 }
2652 %<*ja>
2653 \begin{tabular}{>{\bfseries}lcccc}
2654 \toprule
2655 &横組&縦組 &\cs{dtou}「dtou方向」&「utod方向」\\
2656 \midrule
2657 命令&\cs{yoko}&\cs{tate}&\cs{dtou}&\cs{utod}\\
2658 字送り方向&水平右向き(→)&垂直下向き(↓)&垂直上向き(↑)&垂直下向き(↓)\\
2659 行送り方向&垂直下向き(↓)&水平左向き(←)&水平右向き(→)&水平左向き(←)\\
2660 使用する和文フォント&横組用(\cs{jfont})&縦組用(\cs{tfont})&
2661 \multicolumn{2}{c}{%
2662   横組用(\cs{jfont})の$90^\circ$回転}\\[\smallskipamount]
2663 組版例\null $^*$ &\obox{\yoko}&\obox{\tate}&\obox{\dtou}&\obox{\utod}\\
2664 \noalign{\medskip}
2665 \bottomrule
2666 \end{tabular}
2667
2668 \medskip\raggedright
2669 \def\R#1{%
2670   \raise0.38\zw\hbox{%
2671     \vrule height.2pt  depth.2pt width2\zw%
2672     \hbox to 0pt{\hss\composite{*d^@{#1}}\hss}%
2673   }%
2674 }
2675 $^*$\ 幅(width),高さ(height),深さ(depth)の増加方向を,
2676 それぞれ「\R{>}」,「\R{>>}」,「\R{>|}」で表している.
2677 \raggedright
2678 %</ja>
2679
2680 %<*en>
2681 \begin{tabular}{>{\bfseries}lcccc}
2682 \toprule
2683 &horizontal (\emph{yoko}~direction)&vertical (\emph{tate}~direction)&%
2684   \emph{dtou} direction&\emph{utod} direction\\
2685 \midrule
2686 Commands&\cs{yoko}&\cs{tate}&\cs{dtou}&\cs{utod}\\
2687 Beginning of the page&Top&Right&Left&Right\\
2688 Beginning of the line&Left&Top&Bottom&Top\\
2689 Used Japanese font&horizontal (\cs{jfont})&vertical (\cs{tfont})&
2690 \multicolumn{2}{c}{%
2691   horizontal ($90^\circ$ rotated)}\\[\smallskipamount]
2692 Example&\obox{\yoko}&\obox{\tate}&\obox{\dtou}&\obox{\utod}\\
2693 \noalign{\medskip}
2694 (Notation used in $\Omega$)&TLT&RTR, RTT&LBL&RTR\\
2695 \bottomrule
2696 \end{tabular}
2697
2698 \medskip\raggedright
2699 \def\R#1{%
2700   \raise0.38\zw\hbox{%
2701     \vrule height.2pt  depth.2pt width2\zw%
2702     \hbox to 0pt{\hss\composite{*d^@{#1}}\hss}%
2703   }%
2704 }
2705 \raggedright
2706 %</en>
2707 \end{table}
2708
2709 %<*en>
2710 \LuaTeX-ja supports four directions, as shown in Table~\ref{tab-dir}.
2711 The second column (\emph{yoko} direction) is just horizontal writing,
2712 and the third column (\emph{tate} direction) is vertical writing.
2713 The fourth column (\emph{dtou} direction) is actually a hidden feature of \pTeX.
2714 We implemented this for debugging purpose.
2715 The fifth column (\emph{utod} direction) corresponds the ``\texttt{tate (math) direction}'' of \pTeX.
2716
2717 Directions can be changed by \cs{yoko},~\cs{tate}, \cs{dtou},~\cs{utod},
2718 only when the current list is null. Also, the direction of a math formula is changed to
2719 \emph{utod}, when the direction outside the math formula is \emph{tate} (vertical writing).
2720 %</en>
2721
2722 %<*ja>
2723 \LuaTeX-jaがサポートする組方向は表\ref{tab-dir}に示す4つである.
2724 4列目の \cs{dtou} は聞き慣れない命令だと思うが,
2725 実は\pTeX に同名の命令が(ドキュメントには書かれていないが)存在する.
2726 Down-TO-Upの意味なのだろう.\cs{dtou} を使用する機会はないだろうが,
2727 \LuaTeX-jaではデバッグ用に実装している.
2728 5列目の \cs{utod} は,\pTeX で言う「縦数式ディレクション」に相当するものである.
2729
2730 組方向は,\cs{yoko},~\cs{tate}, \cs{dtou},~\cs{utod} をそれぞれ使用することで,
2731 現在作成中のリストやボックスが空の時にのみ変更可能である.
2732 また,縦組中の数式内のボックスは\pTeX と同じように組方向が \cs{utod} となる.
2733 %</ja>
2734
2735 %<*en>
2736 \subsection{Boxes in different direction}
2737
2738 As in \pTeX, one can use boxes of different direction in one document.
2739 The below is an example.
2740 \begin{LTXexample}
2741 ここは横組%     yoko
2742 \hbox{\tate %   tate
2743   \hbox{縦組}%  tate
2744   の中に
2745   \hbox{\yoko 横組の内容}% yoko
2746   を挿入する
2747 }
2748 また横組に戻る% yoko
2749 \end{LTXexample}
2750
2751 Table~\ref{tab-diffdir} shows how a box is arranged when
2752 the direction  inside the box and that outside the box differ.
2753 %</en>
2754 %<*ja>
2755 \subsection{異方向のボックス}
2756
2757 縦組の中に「42」などの2桁以上の算用数字を横組で組むなど,
2758 異なる組方向を混在させることがしばしば行われる.
2759 組方向の混在も\pTeX と同じようにできる:
2760 \begin{LTXexample}
2761 ここは横組%     yoko
2762 \hbox{\tate %   tate
2763   \hbox{縦組}%  tate
2764   の中に
2765   \hbox{\yoko 横組の内容}% yoko
2766   を挿入する
2767 }
2768 また横組に戻る% yoko
2769 \end{LTXexample}
2770
2771 異なる組方向のボックスを配置した場合にどう組まれるかの仕様も,\pTeX を
2772 踏襲している.表\ref{tab-diffdir}に示す.
2773 %</ja>
2774
2775 \begin{table}[t]
2776 %<ja>\caption{異方向のボックスの配置}
2777 %<en>\caption{Boxes in different direction}
2778 %<en>\medskip
2779 \label{tab-diffdir}
2780  \centering\small\unitlength3mm
2781  \def\TATEeg{%
2782    \hbox{\smash{\begin{picture}(0,0)(-2,0)
2783      \thicklines
2784      \polyline(-2,0)(-2,-7)(5,-7)(5,0)
2785      \put(0,0){\circle*{0.3}}
2786      \put(2.5,-4){\makebox(0,0){\hbox{\tate\bfseries \emph{tate}/\emph{utod}}}}
2787      \put(0,0){\vector(1,0){5}} \put(2.5,-0.2){\makebox(0,0)[t]{$h_{\mathrm{T}}$}}
2788      \put(0,0){\vector(-1,0){2}}\put(-1,-0.2){\makebox(0,0)[t]{$d_{\mathrm{T}}$}}
2789      \put(0,0){\vector(0,-1){7}}\put(0.2,-3.5){\makebox(0,0)[l]{$w_{\mathrm{T}}$}}
2790    \end{picture}}}
2791  }
2792  \def\DTOUeg{%
2793    \hbox{\smash{\begin{picture}(0,0)(-5,0)
2794      \thicklines
2795      \polyline(-5,0)(-5,7)(2,7)(2,0)
2796      \put(0,0){\circle*{0.3}}
2797      \put(-2.5,4){\makebox(0,0){\hbox{\dtou\bfseries \emph{dtou}}}}
2798      \put(0,0){\vector(-1,0){5}} \put(-2.5,0.3){\makebox(0,0)[b]{$h_{\mathrm{D}}$}}
2799      \put(0,0){\vector(1,0){2}}\put(1,0.3){\makebox(0,0)[b]{$d_{\mathrm{D}}$}}
2800      \put(0,0){\vector(0,1){7}}\put(-0.2,3.5){\makebox(0,0)[r]{$w_{\mathrm{D}}$}}
2801    \end{picture}}}
2802  }
2803  \def\YOKOeg{%
2804    \hbox{\smash{\begin{picture}(0,0)
2805      \thicklines
2806      \polyline(0,5)(7,5)(7,-2)(0,-2)
2807      \put(4,2.5){\makebox(0,0){\hbox{\yoko\bfseries \emph{yoko}}}}
2808      \put(0,0){\circle*{0.3}}
2809      \put(0,0){\vector(0,1){5}} \put(0.3,2.5){\makebox(0,0)[l]{$h_{\mathrm{Y}}$}}
2810      \put(0,0){\vector(0,-1){2}}\put(0.3,-1){\makebox(0,0)[l]{$d_{\mathrm{Y}}$}}
2811      \put(0,0){\vector(1,0){7}}\put(3.5,0.2){\makebox(0,0)[b]{$w_{\mathrm{Y}}$}}
2812    \end{picture}}}
2813  }
2814 \begin{tabular}{ccc}
2815 \toprule
2816 %<ja>\emph{横組中に配置}&\emph{縦組中に配置}&%
2817 %<ja>\emph{組方向 \cs{dtou} 中に配置}\\
2818 %<en>\textbf{typeset in \emph{yoko} direction}
2819 %<en>&\textbf{typeset in \emph{tate} or \emph{utod} direction}
2820 %<en>&\textbf{typeset in \emph{dtou} direction}\\
2821 \midrule
2822  \parbox[c]{15\unitlength}{\begin{picture}(15,15)(0,-4)
2823    \put(0,0){\line(1,0){3.8}}
2824    \put(4,7){\TATEeg}
2825    \put(11.2,0){\line(1,0){3.8}}
2826 %
2827    \put(2,7){\line(1,0){1.8}}
2828    \put(3,3.5){\vector(0,1){3.5}\vector(0,-1){3.5}}
2829    \put(2.8,3.5){\makebox(0,0)[r]{$H_{\mathrm{Y}}$}}
2830    \put(3,-2){\vector(0,1){2}}
2831    \put(2.8,-1){\makebox(0,0)[r]{$D_{\mathrm{Y}}$}}
2832 %
2833    \put(4,7.2){\line(0,1){1.8}}
2834    \put(11,7.2){\line(0,1){1.8}}
2835    \put(6,8){\vector(-1,0){2}}
2836    \put(9,8){\vector(1,0){2}}
2837    \put(7.5,8){\makebox(0,0){$W_{\mathrm{Y}}$}}
2838 %
2839  \end{picture}\vspace{-\baselineskip}
2840    \begin{align*}
2841    W_{\mathrm{Y}} &= h_{\mathrm{T}}+d_{\mathrm{T}},\\
2842    H_{\mathrm{Y}} &= w_{\mathrm{T}},\\
2843    D_{\mathrm{Y}} &=0\,\mathrm{pt}
2844    \end{align*}%
2845  }&
2846  \parbox[c]{15\unitlength}{\begin{picture}(15,15)(0,-4)
2847    \put(7.5,-0.2){\line(0,-1){2.8}}
2848    \put(4,2){\YOKOeg}
2849    \put(7.5, 7.2){\line(0,1){3.8}}
2850 %
2851    \put(2,7){\line(1,0){1.8}}
2852    \put(2,0){\line(1,0){1.8}}
2853    \put(3,5){\vector(0,1){2}}
2854    \put(3,2){\vector(0,-1){2}}
2855    \put(3,3.5){\makebox(0,0){$W_{\mathrm{T}}$}}
2856 %
2857    \put(4,7.2){\line(0,1){1.8}}
2858    \put(11,7.2){\line(0,1){1.8}}
2859    \put(8,8){\vector(-1,0){0.5}\vector(1,0){3}}
2860    \put(7,8){\vector(-1,0){3}\vector(1,0){0.5}}
2861    \put(9.25,8.2){\makebox(0,0)[b]{$H_{\mathrm{T}}$}}
2862    \put(5.75,8.2){\makebox(0,0)[b]{$D_{\mathrm{T}}$}}
2863 %
2864  \end{picture}\vspace{-\baselineskip}
2865    \begin{align*}
2866    W_{\mathrm{T}} &= h_{\mathrm{Y}}+d_{\mathrm{Y}},\\
2867    H_{\mathrm{T}} &= w_{\mathrm{Y}}/2,\\
2868    D_{\mathrm{T}} &= w_{\mathrm{Y}}/2
2869    \end{align*}%
2870  }&
2871  \parbox[c]{15\unitlength}{\begin{picture}(15,15)(0,-4)
2872    \put(11,-0.2){\line(0,-1){2.8}}
2873    \put(4,2){\YOKOeg}
2874    \put(11, 7.2){\line(0,1){3.8}}
2875 %
2876    \put(2,7){\line(1,0){1.8}}
2877    \put(2,0){\line(1,0){1.8}}
2878    \put(3,5){\vector(0,1){2}}
2879    \put(3,2){\vector(0,-1){2}}
2880    \put(3,3.5){\makebox(0,0){$W_{\mathrm{D}}$}}
2881 %
2882    \put(4,7.2){\line(0,1){1.8}}
2883    \put(11,7.2){\line(0,1){1.8}}
2884    \put(7.5,8){\vector(-1,0){3.5}\vector(1,0){3.5}}
2885    \put(13,8){\vector(-1,0){2}}
2886    \put(7.5,8.2){\makebox(0,0)[b]{$H_{\mathrm{D}}$}}
2887    \put(12,8.2){\makebox(0,0)[b]{$D_{\mathrm{D}}$}}
2888 %
2889  \end{picture}\vspace{-\baselineskip}
2890    \begin{align*}
2891    W_{\mathrm{D}} &= h_{\mathrm{Y}}+d_{\mathrm{Y}},\\
2892    H_{\mathrm{D}} &= w_{\mathrm{Y}},\\
2893    D_{\mathrm{D}} &= 0\,\mathrm{pt}
2894    \end{align*}%
2895  }%
2896 \\\midrule
2897  \parbox[c]{15\unitlength}{\begin{picture}(15,15)(0,-4)
2898    \put(0,0){\line(1,0){3.8}}
2899    \put(4,0){\DTOUeg}
2900    \put(11.2,0){\line(1,0){3.8}}
2901 %
2902    \put(2,7){\line(1,0){1.8}}
2903    \put(3,3.5){\vector(0,1){3.5}\vector(0,-1){3.5}}
2904    \put(2.8,3.5){\makebox(0,0)[r]{$H_{\mathrm{Y}}$}}
2905    \put(3,-2){\vector(0,1){2}}
2906    \put(2.8,-1){\makebox(0,0)[r]{$D_{\mathrm{Y}}$}}
2907 %
2908    \put(4,7.2){\line(0,1){1.8}}
2909    \put(11,7.2){\line(0,1){1.8}}
2910    \put(6,8){\vector(-1,0){2}}
2911    \put(9,8){\vector(1,0){2}}
2912    \put(7.5,8){\makebox(0,0){$W_{\mathrm{Y}}$}}
2913 %
2914  \end{picture}\vspace{-\baselineskip}
2915    \begin{align*}
2916    W_{\mathrm{Y}} &= h_{\mathrm{D}}+d_{\mathrm{D}},\\
2917    H_{\mathrm{Y}} &= w_{\mathrm{D}},\\
2918    D_{\mathrm{Y}} &= 0\,pt
2919    \end{align*}%
2920  }&
2921  \parbox[c]{15\unitlength}{\begin{picture}(15,15)(0,-4)
2922    \put(9,-0.2){\line(0,-1){2.8}}
2923    \put(4,0){\DTOUeg}
2924    \put(9, 7.2){\line(0,1){3.8}}
2925 %
2926    \put(2,7){\line(1,0){1.8}}
2927    \put(2,0){\line(1,0){1.8}}
2928    \put(3,5){\vector(0,1){2}}
2929    \put(3,2){\vector(0,-1){2}}
2930    \put(3,3.5){\makebox(0,0){$W_{\mathrm{T}}$}}
2931 %
2932    \put(4,7.2){\line(0,1){1.8}}
2933    \put(11,7.2){\line(0,1){1.8}}
2934    \put(6.5,8){\vector(-1,0){2.5}\vector(1,0){2.5}}
2935    \put(10,8){\vector(-1,0){1}\vector(1,0){1}}
2936    \put(10,8.2){\makebox(0,0)[b]{$H_{\mathrm{T}}$}}
2937    \put(6.5,8.2){\makebox(0,0)[b]{$D_{\mathrm{T}}$}}
2938 %
2939  \end{picture}\vspace{-\baselineskip}
2940    \begin{align*}
2941    W_{\mathrm{T}} &= h_{\mathrm{D}}+d_{\mathrm{D}},\\
2942    H_{\mathrm{T}} &= d_{\mathrm{D}},\\
2943    D_{\mathrm{T}} &= h_{\mathrm{D}}
2944    \end{align*}%
2945  }&
2946  \parbox[c]{15\unitlength}{\begin{picture}(15,15)(0,-4)
2947    \put(6,-0.2){\line(0,-1){2.8}}
2948    \put(4,7){\TATEeg}
2949    \put(6, 7.2){\line(0,1){3.8}}
2950 %
2951    \put(2,7){\line(1,0){1.8}}
2952    \put(2,0){\line(1,0){1.8}}
2953    \put(3,5){\vector(0,1){2}}
2954    \put(3,2){\vector(0,-1){2}}
2955    \put(3,3.5){\makebox(0,0){$W_{\mathrm{D}}$}}
2956 %
2957    \put(4,7.2){\line(0,1){1.8}}
2958    \put(11,7.2){\line(0,1){1.8}}
2959    \put(5,8){\vector(-1,0){1}\vector(1,0){1}}
2960    \put(8.5,8){\vector(-1,0){2.5}\vector(1,0){2.5}}
2961    \put(5,8.2){\makebox(0,0)[b]{$H_{\mathrm{D}}$}}
2962    \put(8.5,8.2){\makebox(0,0)[b]{$D_{\mathrm{D}}$}}
2963 %
2964  \end{picture}\vspace{-\baselineskip}
2965    \begin{align*}
2966    W_{\mathrm{D}} &= w_{\mathrm{T}},\\
2967    H_{\mathrm{D}} &= d_{\mathrm{T}},\\
2968    D_{\mathrm{D}} &= h_{\mathrm{T}}
2969    \end{align*}%
2970  }\\
2971 \bottomrule
2972 \end{tabular}
2973 \end{table}
2974
2975
2976
2977 %<*en>
2978 \paragraph{\cs{wd} and direction}
2979 In \pTeX, \cs{wd},~\cs{ht},~\cs{dp} means the dimensions of a box register
2980 \emph{with respact to the current direction}.
2981 This means that the value of \cs{wd0} etc.\ might differ when the current direction is
2982 different, even if \cs{box0} stores the same box.
2983 However, this no longer applies in \LuaTeX-ja.
2984
2985 \begin{LTXexample}
2986 % yoko direction
2987 \setbox0=\hbox to 20pt{foo}
2988 \the\wd0,~\hbox{\tate\vrule\the\wd0}
2989 \wd0=100pt
2990 \the\wd0,~\hbox{\tate \the\wd0}
2991 \end{LTXexample}
2992
2993 To access box dimensions \emph{with respect to current direction},
2994 one have to use the following commands instead of \cs{wd} wtc.
2995 \begin{cslist}
2996
2997  \item[\cs{ltjgetwd}\{<num>\}\textrm{, }\cs{ltjgetht}\{<num>\}\textrm{, }%
2998   \cs{ltjgetdp}\{<num>\}]
2999 These commands return \emph{an internal dimension} of \cs{box<num>} with respect to
3000 the current direction. One can use these in \cs{dimexpr} primitive, as the followings.
3001 \begin{lstlisting}
3002 \dimexpr 2\ltjgetwd{42}-3pt\relax, \the\ltjgetwd{1701}
3003 \end{lstlisting}
3004 By implementaion,  the argument must be grouped as \verb+\ltjgetwd{42}+,
3005 if the argument consists of more than one token.
3006 \begin{LTXexample}[width=0.3\textwidth]
3007 \parindent0pt
3008 \setbox32767=\hbox{\yoko よこぐみ}
3009 \fboxsep=0mm\fbox{\copy32767}
3010 \vbox{\hsize=20mm
3011 \yoko YOKO \the\ltjgetwd{32767}, \\
3012   \the\ltjgetht{32767}, \\ \the\ltjgetdp{32767}.}
3013 \vbox{\hsize=20mm\raggedleft
3014 \tate TATE \the\ltjgetwd{32767}, \\
3015   \the\ltjgetht{32767}, \\ \the\ltjgetdp{32767}.}
3016 \vbox{\hsize=20mm\raggedleft
3017 \dtou DTOU \the\ltjgetwd{32767}, \\
3018   \the\ltjgetht{32767}, \\ \the\ltjgetdp{32767}.}
3019 \end{LTXexample}
3020
3021  \item[\cs{ltjsetwd}<num>=<dimen>\textrm{, }\cs{ltjsetht}<num>=<dimen>\textrm{, }%
3022   \cs{ltjsetdp}<num>=<dimen>]
3023 These commands set the dimension of \cs{box<num>}. Unlike \cs{ltjgetwd}, one does not need
3024         to group the argument <num>; four calls of \cs{ltjsetwd} below have the same meaning.
3025 \begin{lstlisting}
3026 \ltjsetwd42 20pt,  \ltjsetwd42=20pt,  \ltjsetwd=42 20pt,  \ltjsetwd=42=20pt
3027 \end{lstlisting}
3028
3029 \end{cslist}
3030 %</en>
3031 %<*ja>
3032 \paragraph{\cs{wd} 達と組方向}
3033 ボックスレジスタ \cs{box}<num> にセットされているボックスの幅・高さ・深さの取得や
3034 変更にはそれぞれ \cs{wd},~\cs{ht},~\cs{dp} プリミティブを用いるのであった.
3035 \pTeX ではこれらのプリミティブは,「現在の組方向におけるボックスの寸法」を指すもので,
3036 同じボックスに対しても現在の組方向によって返る値は異なるもであった.
3037
3038 \LuaTeX-jaにおいては状況が異なり,\cs{wd},~\cs{ht},~\cs{dp} が返す値は
3039 現在の組方向には依存しない.下の例のように,横組のボックスが格納されていれば
3040 \cs{wd}等は常に「横組におけるボックスの寸法」を意味する.
3041
3042 \begin{LTXexample}
3043 % yoko direction
3044 \setbox0=\hbox to 20pt{foo}
3045 \the\wd0,~\hbox{\tate\vrule\the\wd0}
3046 \wd0=100pt
3047 \the\wd0,~\hbox{\tate \the\wd0}
3048 \end{LTXexample}
3049
3050 \pTeX のように現在の組方向に応じたボックスの寸法の取得・設定を行うには,
3051 代わりに次の命令を使用する.
3052
3053 \begin{cslist}
3054
3055  \item[\cs{ltjgetwd}\{<num>\}\textrm{, }\cs{ltjgetht}\{<num>\}\textrm{, }%
3056   \cs{ltjgetdp}\{<num>\}]
3057 現在の組方向に応じたボックスの寸法の取得を行う.結果は内部長さであるため,
3058 \begin{lstlisting}
3059 \dimexpr 2\ltjgetwd{42}-3pt\relax, \the\ltjgetwd{1701}
3060 \end{lstlisting}
3061 のように \cs{wd}<num> の代わりとして扱うことができる.引数が1桁の場合は,
3062 \cs{ltjgetwd3} のように引数をグループで括らなくても良いが,そうでない場合は
3063 (通常の命令への引数のように)\verb+\ltjgetwd{42}+ とグループに括る必要がある.
3064 使用例は以下の通りである.
3065 \begin{LTXexample}[width=0.3\textwidth]
3066 \parindent0pt
3067 \setbox32767=\hbox{\yoko よこぐみ}
3068 \fboxsep=0mm\fbox{\copy32767}
3069 \vbox{\hsize=20mm
3070 \yoko YOKO \the\ltjgetwd{32767}, \\
3071   \the\ltjgetht{32767}, \\ \the\ltjgetdp{32767}.}
3072 \vbox{\hsize=20mm\raggedleft
3073 \tate TATE \the\ltjgetwd{32767}, \\
3074   \the\ltjgetht{32767}, \\ \the\ltjgetdp{32767}.}
3075 \vbox{\hsize=20mm\raggedleft
3076 \dtou DTOU \the\ltjgetwd{32767}, \\
3077   \the\ltjgetht{32767}, \\ \the\ltjgetdp{32767}.}
3078 \end{LTXexample}
3079
3080  \item[\cs{ltjsetwd}<num>=<dimen>\textrm{, }\cs{ltjsetht}<num>=<dimen>\textrm{, }%
3081   \cs{ltjsetdp}<num>=<dimen>]
3082 現在の組方向に応じたボックスの寸法の設定を行う.\cs{afterassignment} を2回利用して
3083 実装しているので,次の4通りは全て同じ意味である.
3084 \begin{lstlisting}
3085 \ltjsetwd42 20pt,  \ltjsetwd42=20pt,  \ltjsetwd=42 20pt,  \ltjsetwd=42=20pt
3086 \end{lstlisting}
3087
3088 設定値は「横組」「縦組及び \cs{utod} 方向」「\cs{dtou} 方向」
3089 の3種ごとに独立して記録される.参考として,Gitリポジトリ内の
3090               \verb+test/test55-boxdim_diffdir.{tex,pdf}+ を挙げておく.
3091
3092 \end{cslist}
3093 %</ja>
3094
3095 %<*en>
3096 \subsection{Getting current direction}
3097 The \Param{direction} parameter returns the current direction, and
3098 the \Param{boxdir} parameter (with the argumant <num>)
3099 returns the direction of a box register \cs{box}<num>.
3100 The returned value of these parameters are a \emph{string}:
3101 \begin{center}
3102 \small
3103 \begin{tabular}{>{\bfseries}lccccc}
3104 \toprule
3105 Direction&\emph{yoko}&\emph{tate}&\emph{dtou}&\emph{utod}&(empty)\\
3106 \midrule
3107 Returned value&\texttt{4}&\texttt{3}&\texttt{1}&\texttt{11}&\texttt{0}\\
3108 \bottomrule
3109 \end{tabular}
3110 \end{center}
3111 \begin{LTXexample}[width=0.3\textwidth]
3112 \leavevmode\def\DIR{\ltjgetparameter{direction}}
3113 \hbox{\yoko \DIR}, \hbox{\tate\DIR},
3114 \hbox{\dtou\DIR}, \hbox{\utod\DIR},
3115 \hbox{\tate$\hbox{tate math: \DIR}$}
3116
3117 \setbox2=\hbox{\tate}\ltjgetparameter{boxdir}{2}
3118 \end{LTXexample}
3119 %</en>
3120 %<*ja>
3121 \subsection{組方向の取得}
3122 「現在の組方向」や「<num>番のボックスの組方向」は,
3123 \pTeX では \cs{ifydir} や \cs{ifybox}<num> といった条件判断文を使って
3124 判断することができた.
3125 しかし,\LuaTeX-jaはあくまでも\TeX マクロとLuaコードで
3126 記述されており,それでは新たな条件判断命令を作るのは難しい.
3127
3128 \LuaTeX-jaでは,\Param{direction}パラメータで現在の組方向を,
3129 \Param{boxdir}パラメータ(と追加の引数<num>)によって
3130 \cs{box}<num>の組方向をそれぞれ取得できるようにした.
3131 戻り値は文字列である:
3132 \begin{center}
3133 \small
3134 \begin{tabular}{>{\bfseries}lccccc}
3135 \toprule
3136 組方向&\emph{横組}&\emph{tate縦組}&\emph{dtou方向}&\emph{utod方向}&(未割り当て)\\
3137 \midrule
3138 戻り値&\texttt{4}&\texttt{3}&\texttt{1}&\texttt{11}&\texttt{0}\\
3139 \bottomrule
3140 \end{tabular}
3141 \end{center}
3142
3143 \begin{LTXexample}[width=0.3\textwidth]
3144 \leavevmode\def\DIR{\ltjgetparameter{direction}}
3145 \hbox{\yoko\DIR}, \hbox{\tate\DIR},
3146 \hbox{\dtou\DIR}, \hbox{\utod\DIR},
3147 \hbox{\tate$\hbox{tate math: \DIR}$}
3148
3149 \setbox2=\hbox{\tate}\ltjgetparameter{boxdir}{2}
3150 \end{LTXexample}
3151
3152 これらを用いれば,例えば
3153 \pTeX の \cs{ifydir},~\cs{ifybox200} と同等の条件判断を
3154 \begin{lstlisting}
3155 \ifnum\ltjgetparameter{direction}=4
3156 \ifnum\ltjgetparameter{boxdir}{200}=4
3157 \end{lstlisting}
3158 のように行うことができる.
3159 \cs{iftdir} は少々面倒であるが
3160 \begin{lstlisting}
3161 \ifnum\numexpr
3162   \ltjgetparameter{direction}-(\ltjgetparameter{direction}/8)*8=3
3163 \end{lstlisting}
3164 とすればよい.
3165 %</ja>
3166
3167 %<*en>
3168 \subsection{Overridden box primitives}
3169 To cope with multiple directions, the following primitives are
3170 overridden by \LuaTeX-ja, using~\verb+\protected\def+.
3171 \begin{cslist}[style=standard]
3172  \item[\cs{unhbox}<num>\textrm{, }\cs{unvbox}<num>\textrm{, }\cs{unhcopy}<num>\textrm{, }\cs{unvcopy}<num>]
3173  \item[\cs{vadjust}\{<material>\}]
3174  \item[\cs{lastbox}]
3175  \item[\cs{raise}<dimen><box>\textrm{, }\cs{lower}<dimen><box>\textrm{\ etc., }\cs{vcenter}]
3176  \item[\cs{vcenter}]
3177 \end{cslist}
3178 %</en>
3179 %<*ja>
3180 \subsection{プリミティブの再定義}
3181 異なる組方向に対応するために,以下に挙げるプリミティブは
3182 \LuaTeX-jaによる前処理もしくは後処理が行われるように
3183 \ \verb+\protected\def+ により再定義してある.
3184
3185 \begin{cslist}
3186  \item[\cs{unhbox}<num>\textrm{, }\cs{unvbox}<num>\textrm{, }\cs{unhcopy}<num>\textrm{, }\cs{unvcopy}<num>]
3187  ボックスの組方向が現在のリストと異なる場合は事前にエラーメッセージを出力する.
3188  \pTeX と異なり,エラーを無視して無理矢理 \cs{unhbox}, \cs{unvbox} を
3189  続行させることもできるが,その場合の組版結果は保証しない.
3190  \item[\cs{vadjust}\{<material>\}] 一旦プリミティブ本来の挙動を行う.その後,<material>の組方向が
3191  周囲の垂直リストの組方向と一致しない場合にエラーを出力し,
3192  該当の \cs{vadjust} を無効にする.
3193  \item[\cs{lastbox}] ボックスの「中身」を現在の組方向に合わせるためのノード
3194               (\textit{dir\_box}という)を必要ならば除去し,
3195  正しく「中身」のボックスが返されるように前処理をする.
3196  \item[\cs{raise}<dimen><box>\textrm{, }\cs{lower}<dimen><box>\textrm{\ etc., }\cs{vcenter}]
3197  一方,こちらでは必要に応じて\textit{dir\_box}を作成する前処理を追加している.
3198 \end{cslist}
3199 %</ja>
3200
3201 %<en>\section{Font Metric and Japanese Font}
3202 %<ja>\section{フォントメトリックと和文フォント}
3203 %<en>\subsection{\cs{jfont}}
3204 %<ja>\subsection{\cs{jfont} 命令}
3205 \label{ssec-jfont}
3206
3207 %<*en>
3208 To load a font as a Japanese font (for horizontal direction), you must use the
3209 \cs{jfont} instead of~\cs{font}, while
3210 \cs{jfont} admits the same syntax used in~\cs{font}.
3211 \LuaTeX-ja automatically loads \Pkg{luaotfload} package,
3212 so TrueType/OpenType fonts with features can be used for Japanese fonts:
3213 %</en>
3214 %<*ja>
3215 フォントを(横組用)和文フォントとして読み込むためには,\cs{jfont} を
3216 \ \cs{font} プリミティブの代わりに用いる.
3217 \cs{jfont} の文法は \cs{font} と同じである.
3218 \LuaTeX-jaは\Pkg{luaotfload}パッケージを自動的に読み込むので,
3219 TrueType/OpenTypeフォントにfeatureを指定したものを和文フォントとして用いる
3220 ことができる:
3221 %</ja>
3222 \begin{LTXexample}[width=0.3\textwidth]
3223 \jfont\tradgt={file:KozMinPr6N-Regular.otf:script=latn;%
3224   +trad;-kern;jfm=ujis} at 14pt
3225 \tradgt 当/体/医/区
3226 \end{LTXexample}
3227
3228 %<*en>
3229 Note that the defined control sequence
3230 (\cs{tradgt} in the example above) using \cs{jfont} is not a
3231 \textit{font\_def} token,  but a macro.
3232 Hence the input like \verb+\fontname\tradgt+
3233 causes a error.  We denote control sequences which are defined in
3234 \cs{jfont} by <jfont\_cs>.
3235 %</en>
3236 %<*ja>
3237 なお,\cs{jfont} で定義された制御綴(上の例だと \cs{tradgt})
3238 は\textit{font\_def}トークンではなくマクロである.従って,\verb+\fontname\tradgt+ のような
3239 入力はエラーとなる.以下では \cs{jfont} で定義された
3240 制御綴を<jfont\_cs>で表す.
3241 %</ja>
3242
3243 \paragraph{JFM}
3244 %<*en>
3245 As noted in Introduction, a JFM has measurements of characters and
3246 glues/kerns that are automatically inserted for Japanese
3247 typesetting. The structure of JFM will be described in the next
3248 subsection. At the calling of \cs{jfont}, you must specify
3249 which JFM will be used for this font by the following keys:
3250 %</en>
3251 %<*ja>
3252 「はじめに」の節で述べたように,JFMは文字と和文組版で自動的に挿入される
3253 グルー/カーンの寸法情報を持っている.JFMの構造は次の節で述べる.
3254 \cs{jfont} 命令の呼び出しの際には,どのJFMを用いるのかを以下のキーで
3255 指定する必要がある:
3256 %</ja>
3257
3258
3259 \begin{table}[t]
3260 %<en>\caption{Differences between horizontal JFMs shipped with \LuaTeX-ja}
3261 %<ja>\caption{\LuaTeX-ja に同梱されている横組用JFMの違い}
3262 %<en>\medskip
3263 \label{tab-difjfm}
3264 \ltjsetparameter{jacharrange={+3}}
3265 \centering\small
3266 \def\r#1#2{%
3267   \hbox{\Large\vrule
3268   \parbox[b]{7\zw}{%
3269     \addjfontfeatures{YokoFeatures={Opacity=0.5, Color=#2, JFM=#1}}\noindent
3270     ◆◆◆◆◆◆◆
3271     ある日モモちゃんがお使いで迷子になって泣きました.
3272   }\vrule}}
3273 \def\s#1#2{%
3274   \Large
3275   \parbox[b]{7\zw}{%
3276     \addjfontfeatures{YokoFeatures={Opacity=0.5, Color=#2, JFM=#1}}\noindent
3277     ちょっと!何
3278   }}
3279 \def\t#1#2#3{\hbox to 0pt{\hss%
3280   \setbox0=\hbox{\addjfontfeatures{YokoFeatures={JFM=#1}}\huge #3}%
3281   \textcolor{#2}{\transparent{0.5}\vrule width 0.4pt height\ht0 depth\dp0}\kern-.2pt\copy0
3282   \textcolor{#2}{\transparent{0.5}\kern-\wd0\vrule width\wd0height .2pt depth .2pt
3283   \kern-\wd0\raise\ht0\hbox{\vrule width\wd0height .2pt depth .2pt}%
3284   \kern-\wd0\lower\dp0\hbox{\vrule width\wd0height .2pt depth .2pt}%
3285   \kern-.2pt\vrule width 0.4pt height\ht0 depth \dp0}\hss}}
3286 {\Large\tabcolsep0pt
3287 \begin{tabular}{m{8\zw}m{8\zw}m{8\zw}}
3288 \leavevmode\hbox to 0pt{\r{ujis}{blue}\hss}\r{jis}{black}&
3289 \leavevmode\hbox to 0pt{\r{jis}{black}\hss}\r{min}{red}&
3290 \leavevmode\hbox to 0pt{\r{ujis}{blue}\hss}\r{min}{red}\\
3291 \leavevmode\hbox to 0pt{\s{ujis}{blue}\hss}\s{jis}{black}&
3292 \leavevmode\hbox to 0pt{\s{jis}{black}\hss}\s{min}{red}&
3293 \leavevmode\hbox to 0pt{\s{ujis}{blue}\hss}\s{min}{red}\\
3294 \leavevmode\qquad\t{ujis}{blue}{漢}\t{jis}{black}{漢}\qquad
3295            \t{ujis}{blue}{っ}\t{jis}{black}{っ}&
3296 \leavevmode\qquad\t{jis}{black}{漢}\t{min}{red}{漢}\qquad
3297            \t{jis}{black}{っ}\t{min}{red}{っ}&
3298 \leavevmode\qquad\t{ujis}{blue}{漢}\t{min}{red}{漢}\qquad
3299            \t{ujis}{blue}{っ}\t{min}{red}{っ}\\
3300 \end{tabular}\par}
3301
3302 (\textcolor{blue}{Blue: \texttt{jfm-ujis.lua}},
3303 \textcolor{black}{Black: \texttt{jfm-jis.lua}},
3304 \textcolor{red}{Red: \texttt{jfm-min.lua}})
3305 \ltjsetparameter{jacharrange={-3}}
3306 \end{table}
3307
3308 \begin{cslist}
3309 \item[jfm=<name>]
3310 %<*en>
3311 Specify the name of (horizontal) JFM.
3312 If specified JFM has not been loaded, \LuaTeX-ja search and load
3313 a file named \texttt{jfm-<name>.lua}.
3314
3315 The following JFMs are shipped with \LuaTeX-ja:
3316 %</en>
3317 %<*ja>
3318 用いる(横組用)JFMの名前を指定する.もし以前に指定されたJFMが読み込まれていなければ,
3319 \texttt{jfm-<name>.lua}を読み込む.以下の横組用JFMが\LuaTeX-jaには同梱されている:
3320 %</ja>
3321 \begin{description}
3322 %<*en>
3323 \item[\tt jfm-ujis.lua] A standard JFM in \LuaTeX-ja. This JFM is
3324   based on \verb+upnmlminr-h.tfm+, a metric for UTF/OTF package that
3325   is used in \upTeX. When you use the \Pkg{luatexja-otf} package, you should use this JFM.
3326 %</en>
3327 %<*ja>
3328 \item[\tt jfm-ujis.lua] \LuaTeX-jaの標準JFMである.このJFMは\upTeX で
3329   用いられるUTF/OTFパッケージ用の和文用TFMである \verb+upnmlminr-h.tfm+ を
3330   元にしている.\Pkg{luatexja-otf}パッケージを使うときはこのJFMを指定するべきである.
3331 %</ja>
3332 %<*en>
3333 \item[\tt jfm-jis.lua] A counterpart for \verb+jis.tfm+, ``JIS font
3334   metric'' which is widely used in \pTeX. A major difference between
3335   \texttt{jfm-ujis.lua} and this \texttt{jfm-jis.lua} is that
3336   most characters under \texttt{jfm-ujis.lua} are square-shaped,
3337   while that under \texttt{jfm-jis.lua} are horizontal
3338   rectangles.
3339 %</en>
3340 %<*ja>
3341 \item[\tt jfm-jis.lua] \pTeX で広く用いられている「JISフォントメトリック」
3342   \verb+jis.tfm+ に相当するJFMである.\texttt{jfm-ujis.lua} とこの
3343   \texttt{jfm-jis.lua} の主な違いは,\texttt{jfm-ujis.lua} ではほとんどの文字が
3344   正方形状であるのに対し,\texttt{jfm-jis.lua} では横長の長方形状であることと,
3345   \texttt{jfm-ujis.lua} では「?」「!」の直後に半角空白が挿入されることである.
3346 %</ja>
3347 %<*en>
3348 \item[\tt jfm-min.lua] A counterpart for \verb+min10.tfm+, which is one
3349   of the default Japanese font metric shipped with \pTeX.
3350 %</en>
3351 %<*ja>
3352 \item[\tt jfm-min.lua] \pTeX に同梱されているデフォルトの和文用TFM
3353 (\verb+min10.tfm+)に相当し,行末で文字が揃うようにするために「っ」など一部の文字幅が変わっ
3354            ている.\verb+min10.tfm+ については\cite{min10}が詳しい.
3355 %</ja>
3356 \end{description}
3357 %<*en>
3358 The difference among these three~JFMs is  shown in Table~\ref{tab-difjfm}.
3359 %</en>
3360 %<*ja>
3361 これら3つのJFMの違いは表\ref{tab-difjfm}に示した.表中の文例の一部には,
3362 \cite{min10}の図3,~4のものを用いた.
3363 %</ja>
3364
3365 \begin{figure}
3366 \begin{LTXexample}[width=0.3\textwidth]
3367 \ltjsetparameter{differentjfm=both}
3368 \jfont\F=file:KozMinPr6N-Regular.otf:jfm=ujis
3369 \jfont\G=file:KozGoPr6N-Medium.otf:jfm=ujis
3370 \jfont\H=file:KozGoPr6N-Medium.otf:jfm=ujis;jfmvar=hoge
3371 \F ){\G 【】}( % halfwidth space
3372    ){\H 『』}( % fullwidth space
3373
3374 ほげ,{\G 「ほげ」}(ほげ)\par
3375 ほげ,{\H 「ほげ」}(ほげ)% pTeX-like
3376
3377 \ltjsetparameter{differentjfm=paverage}
3378 \end{LTXexample}
3379 \caption{Example of \texttt{jfmvar} key}
3380 \label{fig:jfmvar}
3381 \end{figure}
3382
3383 %<*en>
3384 \item[jfmvar=<string>]
3385 Sometimes there is a need that \ldots.
3386 %</en>
3387 %<*ja>
3388 \item[jfmvar=<string>]
3389 標準では,JFMとサイズが同じで,
3390   実フォントだけが異なる2つの和文フォントは「区別されない」.例えば
3391 図\ref{fig:jfmvar}において,最初の「)」と「【」の実フォントは異なるが,
3392 JFMもサイズも同じなので,普通に「)【」と入力した時と同じように半角空きとなる.
3393
3394 しかし,JFMとサイズが同じであっても,\texttt{jfmvar} キーの異なる
3395 2つの和文フォント,例えば図\ref{fig:jfmvar}で言う \cs{F} と \cs{H},
3396 は「区別される」.異なる和文フォントに異なる \texttt{jfmvar} キーを割り当て,
3397 かつ\Param{differentjfm}パラメータを \texttt{both} に設定すれば,
3398 \pTeX と似た状況で組版されることになる.
3399 %</ja>
3400 \end{cslist}
3401
3402 \begin{figure}
3403 \begin{LTXexample}[pos=t]
3404 \newcommand\test{\vrule ダイナミックダイクマ\vrule\\}
3405 \jfont\KMFW = KozMinPr6N-Regular:jfm=prop;-kern at 17pt
3406 \jfont\KMFK = KozMinPr6N-Regular:jfm=prop at 17pt % kern is activated
3407 \jfont\KMPW = KozMinPr6N-Regular:jfm=prop;script=dflt;+pwid;-kern at 17pt
3408 \jfont\KMPK = KozMinPr6N-Regular:jfm=prop;script=dflt;+pwid;+kern at 17pt
3409 \begin{multicols}{2}
3410 \ltjsetparameter{kanjiskip=0pt}
3411 {\KMFW\test \KMFK\test \KMPW\test \KMPK\test}
3412
3413 \ltjsetparameter{kanjiskip=3pt}
3414 {\KMFW\test \KMFK\test \KMPW\test \KMPK\test}
3415 \end{multicols}
3416 \end{LTXexample}
3417 \caption{Kerning information and \Param{kanjiskip}}
3418 \label{fig:kern-jfm}
3419 \end{figure}
3420
3421 %<en>\paragraph{Using kerning information in a font}
3422 %<ja>\paragraph{ペアカーニング情報の使用}
3423 \label{para-kern}
3424 %<*en>
3425 Some fonts have information for inter-glyph spacing.
3426 This version of \LuaTeX-ja treats kerning spaces like an italic correction;
3427 any glue and/or kern from the JFM and a kerning space can coexist.
3428 See Figure~\ref{fig:kern-jfm} for detail.
3429
3430 Note that in \cs{setmainjfont} etc.\ which are provided by \Pkg{luatexja-fontspec}
3431 package, kerning option is set \emph{off} (\texttt{Kerning=Off}) by default,
3432 because of the compatibility with previous versions of \LuaTeX-ja.
3433 %</en>
3434 %<*ja>
3435 いくつかのフォントはグリフ間のスペースについての情報を持っている.
3436 このカーニング情報は以前の\LuaTeX-ja とはあまり相性が良くなかったが,
3437 本バージョンではカーニングによる空白はイタリック補正と同様に扱うことになっている.
3438 つまり,カーニング由来の空白とJFM由来のグルー・カーンは同時に入りうる.
3439 図\ref{fig:kern-jfm}を参照.
3440 \begin{itemize}
3441  \item \emph{\cs{jfont} や,
3442 NFSS2用の命令(\ref{ssec-chgfnt}節,\ref{ssec-nfsspat}節)における指定では
3443 カーニング情報は標準で使用する}ことになっているようである.
3444 言い換えれば,カーニング情報を使用しない設定にするには,面倒でも
3445 \begin{lstlisting}
3446 \jfont\hoge=KozMinPr6N-Regular:jfm=ujis;-kern at 3.5mm
3447 \DeclareFontShape{JY3}{fuga}{m}{n} {<-> s*KozMinPr6N-Regular:jfm=ujis;-kern}{}
3448 \end{lstlisting}
3449 のように,\texttt{-kern} という指定を自分で追加しなければいけない.
3450  \item
3451 一方,\emph{\Pkg{luatexja-fontspec} の提供する \cs{setmainjfont}\
3452 などの命令の標準設定ではカーニング情報は使用しない}(\texttt{Kerning=Off})
3453 ことになっている.これは以前のバージョンの\LuaTeX-jaとの互換性のためである.
3454 \end{itemize}
3455 %</ja>
3456
3457 %<*ja>
3458 \paragraph{\texttt{extend}と\texttt{slant}}
3459 OpenType font featureと見かけ上同じような形式で指定できるものに,
3460 \begin{description}
3461 \item[\texttt{extend=}<extend>] 横方向に<extend>倍拡大する.
3462 \item[\texttt{slant=}<slant>] <slant>に指定された割合だけ傾ける.
3463 \end{description}
3464 の2つがある.
3465 \texttt{extend}や\texttt{slant}を指定した場合は,それに応じたJFMを指定すべきである%
3466 \footnote{\LuaTeX-jaでは,これらに対するJFMを特に提供することはしない予定である.}.
3467 例えば,次の例では無理やり通常のJFMを使っているために,文字間隔やイタリック補正量が
3468 正しくない:
3469 %</ja>
3470 %<*en>
3471 \paragraph{\texttt{extend} and \texttt{slant}}
3472 The following setting can be specified as OpenType font features:
3473 \begin{cslist}[style=standard]
3474 \item[\cs{extend=}<extend>] expand the font horizontally by <extend>.
3475 \item[\cs{slant=}<slant>] slant the font.
3476 \end{cslist}
3477 Note that \LuaTeX-ja doesn't adjust JFMs by these \texttt{extend} and \texttt{slant}
3478 settings; you have to write new JFMs on purpose.
3479 For example, the following example uses the standard JFM \texttt{jfm-ujis.lua}, hence
3480 letter-spacing and the width of italic correction are not correct:
3481 %</en>
3482 \begin{LTXexample}[width=0.3\textwidth]
3483 \jfont\E=KozMinPr6N-Regular:extend=1.5;jfm=ujis;-kern
3484 \E あいうえお
3485
3486 \jfont\S=KozMinPr6N-Regular:slant=1;jfm=ujis;-kern
3487 \S あいう\/ABC
3488 \end{LTXexample}
3489
3490 %<en>\subsection{\cs{tfont}}
3491 %<ja>\subsection{\cs{tfont} 命令}
3492
3493
3494 \begin{table}[t]
3495 %<en>\caption{Differences between vertical JFMs shipped with \LuaTeX-ja}
3496 %<ja>\caption{\LuaTeX-ja に同梱されている縦組用 JFM の違い}
3497 %<en>\medskip
3498 \label{tab-difjfm-tate}
3499 \catcode`\<=12\catcode`\>=12
3500 \ltjsetparameter{jacharrange={+3}}
3501 \small
3502
3503 \def\r#1#2{%
3504   \hbox{\tate\Large\vrule
3505   \parbox{7\zw}{%
3506     \addjfontfeatures{TateFeatures={Opacity=0.5, Color=#2, JFM=#1}}\noindent
3507     ◆◆◆◆◆◆◆
3508     ある日モモちゃんがお使いで迷子になって泣きました.
3509   }\vrule}}
3510 \def\s#1#2{%
3511   \hbox{\tate\Large
3512   \parbox{7\zw}{%
3513     \addjfontfeatures{TateFeatures={Opacity=0.5, Color=#2, JFM=#1}}\noindent
3514     ちょっと!何
3515   }}}
3516 \def\t#1#2#3{\hbox to 0pt{\hss%
3517   \setbox0=\hbox{\addjfontfeatures{TateFeatures={JFM=#1}}\huge #3}%
3518   \textcolor{#2}{\transparent{0.5}\vrule width 0.4pt height\ht0 depth\dp0}\kern-.2pt\copy0
3519   \textcolor{#2}{\transparent{0.5}\kern-\wd0\vrule width\wd0height .2pt depth .2pt
3520   \kern-\wd0\raise\ht0\hbox{\vrule width\wd0height .2pt depth .2pt}%
3521   \kern-\wd0\lower\dp0\hbox{\vrule width\wd0height .2pt depth .2pt}%
3522   \kern-.2pt\vrule width 0.4pt height\ht0 depth \dp0}\hss}}
3523
3524 \begin{minipage}{.7\textwidth}
3525 \centering
3526 \leavevmode\hbox to 0pt{\r{ujisv}{blue}\hss}\r{tmin}{red}\quad
3527 \leavevmode\hbox to 0pt{\s{ujisv}{blue}\hss}\s{tmin}{red}\quad
3528 \raise4\zw\hbox{\tate\Large\t{ujisv}{black}{漢}\t{tmin}{red}{漢}\qquad
3529            \t{ujisv}{black}{っ}\t{tmin}{red}{っ}}
3530 \end{minipage}%
3531 \begin{minipage}{.3\textwidth}
3532 \textcolor{blue}{Blue: \texttt{jfm-ujisv.lua}}\\
3533 \textcolor{red}{Red: \texttt{jfm-tmin.lua}}
3534 \end{minipage}
3535 \ltjsetparameter{jacharrange={-3}}
3536 \end{table}
3537
3538 %<*en>
3539 ...
3540 %</en>
3541 %<*ja>
3542 \cs{tfont} はフォントを縦組用の和文フォントとして読み込む命令であり,
3543 \cs{tfont} の文法は \cs{jfont} と同じである.
3544 \cs{tfont} で定義された縦組用和文フォントは,
3545 以下の点が \cs{jfont} による横組用和文フォントとは異なる:
3546 \begin{itemize}
3547  \item 出力時に,自動的に「\verb+vert+ feature相当」のグリフ置換が行われる.
3548        これは,\Pkg{luaotfload}による各種featureのサポートとは全く別個に行われるもので,
3549        いちいち \verb+vert+ featureを指定する必要はない.
3550 \begin{lstlisting}
3551 \tfont\S=file:KozMinPr6N-Regular.otf:jfm=ujis % OK
3552 \end{lstlisting}
3553  \item \ref{ssec-math}節で述べる,数式中の和文フォントには縦組用和文フォントは指定できない.
3554  \item \texttt{jfm=<name>}\ の部分には縦組用JFMを指定する.
3555 以下の縦組用JFMが\LuaTeX-jaには同梱されており,違いを表\ref{tab-difjfm-tate}に示した.
3556 \begin{description}
3557 \item[\tt jfm-ujis.lua] \LuaTeX-jaの標準縦組用JFMである.このJFMは\upTeX で
3558   用いられるUTF/OTFパッケージ用の和文用TFMである \verb+upnmlminr-v.tfm+ を
3559   元にしている.
3560 \item[\tt jfm-min.lua] \pTeX に同梱されているデフォルトの和文用縦組TFM
3561   である \verb+tmin10.tfm+ に相当し,\texttt{min10.tfm} と同様に
3562   「っ」など一部の文字幅が狭められている.
3563 \end{description}
3564 \end{itemize}
3565
3566 なお,\pTeX では,\cs{font},~\cs{jfont},~\cs{tfont}のどれでも欧文フォント・横組用和文フォン
3567 ト・縦組用和文フォントの定義が可能であったが,\LuaTeX-jaではそうでないので注意.
3568 %</ja>
3569
3570 %<en>\subsection{Prefix \texttt{psft}}
3571 %<ja>\subsection{\texttt{psft}プリフィックス}
3572 \label{ssec-psft}
3573 %<*en>
3574 Besides ``\texttt{file:}''\ and ``\texttt{name:}''\ prefixes which
3575 are introduced in the \Pkg{luaotfload} package,
3576 \LuaTeX-ja adds ``\texttt{psft:}''\ prefix in \cs{jfont} (and~\cs{font}),
3577 to specify a ``name-only'' Japanese font which
3578 will not be embedded to PDF.
3579 Note that these non-embedded fonts under current \LuaTeX\ has Identity-H encoding,
3580 and this violates the standard ISO32000-1:2008~(\cite{pdfstd}).
3581
3582 \emph{OpenType font features, such as ``{\tt +jp90}'',
3583 have no meaning in name-only fonts using ``{\tt psft:}''\ prefix,
3584 because we can't expect what fonts are actually used by the PDF reader.}
3585 Note that \texttt{extend}~and~\texttt{slant} settings (see~above) are supported
3586 with \texttt{psft} prefix, because they are only simple linear transformations.
3587 %</en>
3588 %<*ja>
3589 \Pkg{luaotfload}で使用可能になった
3590 \texttt{file:}\ と \texttt{name:}\ のプリフィックスに加えて,
3591 \cs{jfont}(と \cs{font} プリミティブ)では
3592 \texttt{psft:}プリフィックスを用いることができる.
3593 このプリフィックスを用いることで,PDFには埋め込まれない「名前だけの」
3594 和文フォントを指定することができる.
3595 なお,現行の\LuaTeX で非埋め込みフォントを作成するとPDF内でのエンコーディングが
3596 Identity-Hとなり,PDFの標準規格ISO32000-1:2008~(\cite{pdfstd})に非準拠になってしまう
3597 ので注意してほしい.
3598
3599 \emph{\texttt{psft} プリフィックスの下では
3600 \texttt{+jp90} などのOpenType font featureの効力はない.
3601 非埋込フォントをPDFに使用すると,実際にどのようなフォントが
3602 表示に用いられるか予測できないからである.}\
3603 \texttt{extend} と \texttt{slant} 指定は単なる変形のため
3604 \texttt{psft} プリフィックスでも使用可能である.
3605 %</ja>
3606
3607 %<en>\paragraph{\texttt{cid} key}
3608 %<ja>\paragraph{\texttt{cid}キー}
3609 \label{para-cid}
3610
3611 %<*en>
3612 The default font defined by using \texttt{psft:} prefix is for Japanese typesetting;
3613 it is Adobe-Japan1-6 CID-keyed font.
3614 One can specify \texttt{cid} key to use other CID-keyed non-embedded fonts
3615 for Chinese or Korean typesetting.
3616 %</en>
3617 %<*ja>
3618 標準で\texttt{psft:}プリフィックスで定義されるフォントは日本語用のもので
3619 あり,Adobe-Japan1-6のCIDに対応したものとなる.しかし,\LuaTeX-jaは中国語
3620 の組版にも威力を発揮することが分かり,日本語フォントでない非埋込フォント
3621 の対応も必要となった.そのために追加されたのが\texttt{cid}キーである.
3622
3623 \texttt{cid}キーに値を指定すると,そのCIDを持った非埋込フォントを定義することができる:
3624 %</ja>
3625 \begin{lstlisting}[numbers=left]
3626 \jfont\testJ={psft:Ryumin-Light:cid=Adobe-Japan1-6;jfm=jis}     % Japanese
3627 \jfont\testD={psft:Ryumin-Light:jfm=jis}                        % default value is Adobe-Japan1-6
3628 \jfont\testC={psft:AdobeMingStd-Light:cid=Adobe-CNS1-6;jfm=jis} % Traditional Chinese
3629 \jfont\testG={psft:SimSun:cid=Adobe-GB1-5;jfm=jis}              % Simplified Chinese
3630 \jfont\testK={psft:Batang:cid=Adobe-Korea1-2;jfm=jis}           % Korean
3631 \end{lstlisting}
3632 %<*en>
3633 Note that the code above specifies \texttt{jfm-jis.lua}, which is for Japanese fonts,
3634 as JFM for Chinese and Korean fonts.
3635 %</en>
3636 %<*ja>
3637 上のコードでは中国語・韓国語用フォントに対してもJFMに
3638 日本語用の\texttt{jfm-jis.lua}を指定しているので注意されたい.
3639 %</ja>
3640
3641 %<*en>
3642 At present, \LuaTeX-ja supports only 4 values written in the sample code above.
3643 Specifying other values, e.g.,
3644 %</en>
3645 %<*ja>
3646 今のところ,\LuaTeX-jaは上のサンプルコード中に書いた4つの値しかサポートしていない.
3647 %</ja>
3648 \begin{lstlisting}
3649 \jfont\test={psft:Ryumin-Light:cid=Adobe-Japan2;jfm=jis}
3650 \end{lstlisting}
3651 %<*en>
3652 produces the following error:
3653 %</en>
3654 %<*ja>
3655 のようにそれら以外の値を指定すると,エラーが発生する:
3656 %</ja>
3657 \begin{lstlisting}[numbers=left]
3658 ! Package luatexja Error: bad cid key `Adobe-Japan2'.
3659
3660 See the luatexja package documentation for explanation.
3661 Type  H <return>  for immediate help.
3662 <to be read again>
3663                    \par
3664 l.78
3665
3666 ? h
3667 I couldn't find any non-embedded font information for the CID
3668 `Adobe-Japan2'. For now, I'll use `Adobe-Japan1-6'.
3669 Please contact the LuaTeX-ja project team.
3670 ?
3671 \end{lstlisting}
3672
3673 %<en>\subsection{Structure of a JFM File}
3674 %<ja>\subsection{JFMファイルの構造}
3675 \label{ssec-jfm-str}
3676 %<en>A JFM file is a Lua script which has only one function call:
3677 %<ja>JFMファイルはただ一つの関数呼び出しを含むLuaスクリプトである:
3678 \begin{lstlisting}
3679 luatexja.jfont.define_jfm { ... }
3680 \end{lstlisting}
3681 %<*en>
3682 Real data are stored in the table which indicated above by
3683 \verb+{ ... }+.  So, the rest of this subsection are devoted to describe the
3684 structure of this table.  Note that all lengths in a JFM file are
3685 floating-point numbers in design-size unit.
3686 %</en>
3687 %<*ja>
3688 実際のデータは上で \verb+{ ... }+ で示されたテーブルの中に格納されている.
3689 以下ではこのテーブルの構造について記す.
3690 なお,JFMファイル中の長さは全てdesign-sizeを単位とする浮動小数点数であることに
3691 注意する.
3692 %</ja>
3693
3694 \begin{cslist}[style=standard]
3695
3696 \item[dir=<direction>]
3697 %<en>(required)
3698 %<ja>(必須)
3699
3700 %<*en>
3701 The direction of JFM. \texttt{'yoko'}~(horizontal)
3702 or \texttt{'tate'}~(vertical) are supported.
3703 %</en>
3704 %<*ja>
3705 JFMの書字方向.\texttt{'yoko'}(横組)と \texttt{'tate'}(縦組)がサポートされる.
3706 %</ja>
3707
3708 \item[zw=<length>]
3709 %<en>(required)
3710 %<ja>(必須)
3711
3712 %<en>The amount of the length of the ``full-width''.
3713 %<*ja>
3714 「全角幅」の長さ.この量が \cs{zw} の長さとなる.\pTeX では
3715 「全角幅」\texttt{1zw} は「文字クラス0の文字」の幅と決められていたが,
3716 \LuaTeX-jaではここで指定する.
3717 %</ja>
3718
3719 \item[zh=<length>]
3720 %<en>(required)
3721 %<ja>(必須)
3722
3723 %<en>The amount of the ``full-height'' (height + depth).
3724 %<*ja>
3725 「全角高さ」(height + depth)の長さ.通常は全角幅と同じ長さになるだろう.
3726 \pTeX では 「全角高さ」\texttt{1zh} は「文字クラス0の文字」の高さと深さの和と決められていたが,
3727 \LuaTeX-jaではここで指定する.
3728 %</ja>
3729
3730 \item[kanjiskip=\{<natural>, <stretch>, <shrink>\}]
3731 %<en>(optional)
3732 %<ja>(任意)
3733
3734 %<*en>
3735 This field specifies the ``ideal'' amount of \Param{kanjiskip}. As noted
3736              in Subsection~\ref{subs-kskip}, if the parameter
3737              \Param{kanjiskip} is \cs{maxdimen}, the value specified
3738              in this field is actually used (if this field is not specified in
3739              JFM, it is regarded as 0\,pt). Note that <stretch> and <shrink>
3740              fields are in design-size unit too.
3741 %</en>
3742 %<*ja>
3743 理想的な\Param{kanjiskip}の量を指定する.\ref{subs-kskip}節で述べたように,
3744 もし\Param{kanjiskip}が \cs{maxdimen} の値ならば,このフィールドで指定された
3745 値が実際には用いられる(指定なしは0\,ptとして扱われる).<stretch>と<shrink>のフィールドもdesign-size
3746 が単位であることに注意せよ.
3747 %</ja>
3748
3749 \item[xkanjiskip=\{<natural>, <stretch>, <shrink>\}]
3750 %<en>(optional)
3751 %<ja>(任意)
3752
3753 %<*en>
3754 Like the \texttt{kanjiskip} field, this field specifies the ``ideal''
3755              amount of \Param{xkanjiskip}.
3756 %</en>
3757 %<*ja>
3758 \texttt{kanjiskip}フィールドと同様に,\Param{xkanjiskip}の理想的な量を
3759 指定する.
3760 %</ja>
3761 \end{cslist}
3762
3763 %<*en>
3764 \paragraph{Character classes}
3765 Besides from above fields, a JFM file have several sub-tables those
3766 indices are natural numbers.  The table indexed by~$i\in\omega$ stores
3767 information of \emph{character class}~$i$. At least, the character class~0 is
3768 always present, so each JFM file must have a sub-table whose index is
3769 \texttt{[0]}.  Each sub-table (its numerical index is denoted by $i$) has
3770 the following fields:
3771 %</en>
3772 %<*ja>
3773 \paragraph{文字クラス}
3774 上記のフィールドに加えて,JFMファイルはそのインデックスが自然数であるいくつかの
3775 サブテーブルを持つ.インデックスが$i\in\omega$であるテーブルは\emph{文字クラス}$i$の
3776 情報を格納する.少なくとも,文字クラス0は常に存在するので,JFMファイルはインデックス
3777 が\texttt{[0]}のサブテーブルを持たなければならない.それぞれのサブテーブル
3778 (そのインデックスを$i$で表わす)は以下のフィールドを持つ:
3779 %</ja>
3780
3781 \begin{cslist}[style=standard]
3782 \item[chars=\{<character>, ...\}]
3783 %<en>(required except character class~0)
3784 %<ja>(文字クラス0を除いて必須)
3785
3786 %<*en>
3787 This field is a list of characters which are in this character
3788              type~$i$. This field is optional if $i=0$, since all
3789              \textbf{JAchar} which do not belong  any character classes other
3790              than 0 are in the character class 0
3791              (hence, the character class~0 contains most of
3792              \textbf{JAchar}s). In the list, character(s) can be specified in the following form:
3793 \begin{itemize}
3794 \item a Unicode code point
3795 \item the character itself (as a Lua string, like \hbox{\ltjsetparameter{autoxspacing=false}\verb+'あ'+})
3796 \item a string like \hbox{\ltjsetparameter{autoxspacing=false}\verb+'あ*'+} (the character followed by an asterisk)
3797 \item several ``imaginary'' characters (We will describe these later.)
3798 \end{itemize}
3799 %</en>
3800 %<*ja>
3801 このフィールドは文字クラス$i$に属する文字のリストである.このフィールドは$i=0$の
3802 場合には任意である(文字クラス0には,0以外の文字クラスに属するものを
3803 除いた全ての\textbf{JAchar}が属するから).このリスト中で文字を指定するには,以下の方法がある:
3804 \begin{itemize}
3805 \item Unicode におけるコード番号
3806 \item 「\hbox{\ltjsetparameter{autoxspacing=false}\verb+'あ'+}」のような,文字それ自体
3807 \item 「\hbox{\ltjsetparameter{autoxspacing=false}\verb+'あ*'+}」のような,文字それ自体の後にアスタリスクをつけたもの
3808 \item いくつかの「仮想的な文字」(後に説明する)
3809 \end{itemize}
3810 %</ja>
3811
3812 \item[width=<length>, height=<length>, depth=<length>, italic=<length>]
3813 %<en>(required)
3814 %<ja>(必須)
3815
3816 %<*en>
3817 Specify the width of characters in character class~$i$, the height, the depth and
3818 the amount of italic correction. All characters in character class~$i$ are regarded that its width, height, and depth are
3819 as values of these fields.
3820
3821 But there is one exception: \texttt{width} field can be \texttt{'prop'}.
3822 This means that width of a character becomes that of its ``real'' glyph.
3823 %</en>
3824 %<*ja>
3825 文字クラス$i$に属する文字の幅,高さ,深さ,イタリック補正の量を指定する.
3826 文字クラス$i$に属する全ての文字は,その幅,高さ,深さがこのフィールドで指定した
3827 値であるものとして扱われる.
3828
3829 例外として,\emph{\texttt{width} フィールドには数値以外に \texttt{'prop'} が指定可能である}.
3830 この場合,文字の幅はその「実際の」グリフの幅となる.OpenTypeの \texttt{prop} featureと併用
3831              すれば,これによってプロポーショナル組を行うことができる.
3832 %</ja>
3833
3834 \item[left=<length>, down=<length>, align=<align>]\
3835
3836 %<*en>
3837 These fields are for adjusting the position of the ``real'' glyph. Legal
3838              values of \texttt{align} field are \texttt{'left'},
3839              \texttt{'middle'}, and \texttt{'right'}. If one of these
3840              3~fields are omitted, \texttt{left} and \texttt{down} are
3841              treated as~0, and \texttt{align} field is treated as
3842              \texttt{'left'}.
3843 The effects of these 3~fields are indicated in
3844 Figures \ref{fig-pos}~and~\ref{fig-pos-tate}.
3845 %</en>
3846 %<*ja>
3847 これらのフィールドは実際のグリフの位置を調整するためにある.
3848 \texttt{align} フィールドに指定できる値は \texttt{'left'}, \texttt{'middle'},
3849 \texttt{'right'} のいずれかである.もしこれら3つのフィールドのうちの1つが省かれた
3850 場合,\texttt{left} と \texttt{down} は0,\texttt{align} フィールドは
3851 \ \texttt{'left'} であるものとして扱われる.
3852 これら3つのフィールドの意味については図\ref{fig-pos}(横組用和文フォント),
3853 図\ref{fig-pos-tate}(縦組用和文フォント)で説明する.
3854 %</ja>
3855
3856 %<*en>
3857 In most cases, \texttt{left} and \texttt{down} fields are~0, while
3858 it is not uncommon that the \texttt{align} field is \texttt{'middle'} or \texttt{'right'}.
3859 For example, setting the \texttt{align} field to \texttt{'right'} is practically needed
3860 when the current character class is the class for opening delimiters'.
3861 %</en>
3862 %<*ja>
3863 多くの場合,\texttt{left}と\texttt{down}は0である一方,
3864 \texttt{align}フィールドが\texttt{'middle'}や\texttt{'right'}であることは
3865 珍しいことではない.
3866 例えば,\texttt{align}フィールドを\texttt{'right'}に指定することは,
3867 文字クラスが開き括弧類であるときに実際必要である.
3868 %</ja>
3869
3870 \begin{figure}[!tb]
3871 \begin{minipage}{0.4\textwidth}%
3872 \begin{center}\unitlength=10pt\small
3873 \begin{picture}(15,12)(-1,-4)
3874 \color{b_gray}% jfm
3875 \put(0,0){\vrule width 12\unitlength height 8\unitlength depth 3\unitlength}
3876
3877 \color{b_pink}% step1
3878 \put(-1,-1.5){\vrule width 6\unitlength height 7\unitlength depth 2.5\unitlength}
3879
3880 \color{red}% real glyph
3881 \thicklines
3882 \put(-1,-1.5){\vector(0,1){7}\vector(0,-1){2.5}\vector(1,0){6}}
3883 \put(5,-1.5){\line(0,1){7}\line(0,-1){2.5}}
3884 \put(-1,5.5){\line(1,0){6}}
3885 \put(-1,-4){\line(1,0){6}}
3886
3887 \color{b_green}% real glyph
3888 \put(3,0){\vrule width 6\unitlength height 7\unitlength depth 2.5\unitlength}
3889
3890 \color{black}% jfm
3891 \thicklines
3892 \put(0,0){\vector(0,1){8}\line(0,-1){3}\vector(1,0){12}}
3893 \put(12,0){\line(0,1){8}\vector(0,-1){3}}
3894 \put(0,8){\line(1,0){12}}
3895 \put(0,-3){\line(1,0){12}}
3896 \put(0.2,4){\makebox(0,0)[l]{\texttt{height}}}
3897 \put(12.2,-1.5){\makebox(0,0)[l]{\texttt{depth}}}
3898 \put(6,0.2){\makebox(0,0)[b]{\texttt{width}}}
3899
3900 \color{green}% step1
3901 \thicklines
3902 \put(3,0){\vector(0,1){7}\vector(0,-1){2.5}\vector(1,0){6}}
3903 \put(9,0){\line(0,1){7}\line(0,-1){2.5}}
3904 \put(3,7){\line(1,0){6}}
3905 \put(3,-2.5){\line(1,0){6}}
3906 \newsavebox{\eqdist}
3907 \savebox{\eqdist}(0,0)[b]{%
3908   \thinlines
3909   \put(-0.08,0.2){\line(0,-1){0.4}}%
3910   \put(0.08,0.2){\line(0,-1){0.4}}}
3911 \put(1.5,0){\usebox{\eqdist}}
3912 \put(10.5,0){\usebox{\eqdist}}
3913
3914 \color{blue}% shifted
3915 \thicklines
3916 \put(3,-1.5){\vector(-1,0){4}}
3917 \put(1,-1.7){\makebox(0,0)[t]{\texttt{left}}}
3918 \put(3,0){\vector(0,-1){1.5}}
3919 \put(3.2,-0.75){\makebox(0,0)[l]{\texttt{down}}}
3920 \end{picture}
3921 \end{center}
3922 \end{minipage}%
3923 \begin{minipage}{0.6\textwidth}%
3924 %<*en>
3925 Consider a  Japanese character node which belongs to
3926 a character class whose the \texttt{align}
3927 field is \texttt{'middle'}.
3928 %</en>
3929 %<*ja>
3930 \texttt{align}フィールドの値が \texttt{'middle'} であるような文字クラスに属する
3931 和文文字ノードを考えよう.
3932 %</ja>
3933 \begin{itemize}
3934 \item
3935 %<*en>
3936 The black rectangle is the imaginary body of the node.
3937 Its width, height, and depth are specified by JFM.
3938 %</en>
3939 %<*ja>
3940 黒色の長方形はノードの枠であり,
3941 その幅,高さ,深さはJFMによって指定されている.
3942 %</ja>
3943 \item
3944 %<*en>
3945 Since the \texttt{align} field is \texttt{'middle'},
3946 the ``real'' glyph is centered horizontally (the green rectangle) first.
3947 %</en>
3948 %<*ja>
3949 \texttt{align}フィールドは \texttt{'middle'} なので,
3950 実際のグリフの位置はまず水平方向に中央揃えしたものとなる(緑色の長方形).
3951 %</ja>
3952 \item
3953 %<*en>
3954 Furthermore, the glyph is shifted according to values of fields
3955       \texttt{left} and \texttt{down}. The ultimate position of the real
3956       glyph is indicated by the red rectangle.
3957 %</en>
3958 %<*ja>
3959 さらに,グリフは \texttt{left} と \texttt{down} の値に従ってシフトされる.
3960 最終的な実際のグリフの位置は赤色の長方形で示された位置になる.
3961 %</ja>
3962 \end{itemize}
3963 \end{minipage}
3964 \medskip
3965
3966 \caption{%
3967 %<en>The position of the real glyph (horizontal Japanese fonts)
3968 %<ja>横組和文フォントにおける「実際の」グリフの位置
3969 }
3970 \label{fig-pos}
3971 \end{figure}
3972 \begin{figure}[!tb]
3973 \begin{minipage}{0.4\textwidth}%
3974 \begin{center}\unitlength=10pt\small
3975 \begin{picture}(15,12)(-6,0)
3976 \color{b_gray}% jfm
3977 \put(-6,0){\vrule width 12\unitlength height 11\unitlength}
3978
3979 \color{b_pink}% real glyph
3980 \put(-6.5,5.5){\vrule width 8\unitlength height 6\unitlength depth 3\unitlength}
3981
3982 \color{red}% real glyph
3983 \thicklines
3984 \put(-6.5,5.5){\vector(0,1){6}\vector(0,-1){3}\vector(1,0){8}}
3985 \put( 1.5,5.5){\line(0,1){6}\line(0,-1){3}}
3986 \put(-6.5,11.5){\line(1,0){8}}
3987 \put(-6.5,2.5){\line(1,0){8}}
3988
3989 \color{b_green}% step1
3990 \put(-4,3){\vrule width 8\unitlength height 6\unitlength depth 3\unitlength}
3991
3992 \color{black}% jfm
3993 \thicklines
3994 \put(0,11){\vector(1,0){6}\vector(-1,0){6}\vector(0,-1){11}}
3995 \put(0,0){\line(1,0){6}\line(-1,0){6}}
3996 \put(-6,0){\line(0,1){11}}
3997 \put( 6,0){\line(0,1){11}}
3998 \put( 3,10.8){\makebox(0,0)[t]{\texttt{height}}}
3999 \put(-3,10.8){\makebox(0,0)[t]{\texttt{depth}}}
4000 \put(0.2,5.5){\makebox(0,0)[l]{\texttt{width}}}
4001
4002 \color{green}% step1
4003 \thicklines
4004 \put(-4,3){\vector(0,1){6}\vector(0,-1){3}\vector(1,0){8}}
4005 \put( 4,3){\line(0,1){6}\line(0,-1){3}}
4006 \put(-4,9){\line(1,0){8}}
4007 \put(-4,0){\line(1,0){8}}
4008 \savebox{\eqdist}(0,0)[b]{%
4009   \thinlines
4010   \put(-0.08,0.2){\line(0,-1){0.4}}%
4011   \put(0.08,0.2){\line(0,-1){0.4}}}
4012 \put(2,9){\usebox{\eqdist}}
4013 \put(-2,9){\usebox{\eqdist}}
4014
4015
4016 \color{blue}% shifted
4017 \thicklines
4018 \put(-4,3){\vector(0,1){2.5}}
4019 \put(-3.8,4.25){\makebox(0,0)[l]{\texttt{left}}}
4020 \put(-4,5.5){\vector(-1,0){2.5}}
4021 \put(-5.,5.7){\makebox(0,0)[b]{\texttt{down}}}
4022 \end{picture}
4023 \end{center}
4024 \end{minipage}%
4025 \begin{minipage}{0.6\textwidth}%
4026 %<*en>
4027 (\dots)
4028 %</en>
4029 %<*ja>
4030 \texttt{align}フィールドの値が \texttt{'right'} であるような文字クラスに属する
4031 和文文字を考えよう.
4032 \begin{itemize}
4033 \item
4034 実際のグリフの「垂直位置」は,ベースラインが文字の物理的な左右方向の中央を通る
4035 位置となる.
4036 \item
4037 また,この場合\texttt{align}フィールドは \texttt{'right'} なので,
4038 「水平位置」は字送り方向に「右寄せ」したものとなる(緑色の長方形).
4039 その際,高さ・深さは,実フォントのascender, descenderの値が使われる.
4040 \item
4041 その後さらに \texttt{left} と \texttt{down} の値に従ってシフトされる
4042 のは横組用和文フォントと変わらない.
4043 \end{itemize}
4044 %</ja>
4045 \end{minipage}
4046 \medskip
4047
4048 \caption{%
4049 %<en>The position of the real glyph (vertical Japanese fonts)
4050 %<ja>縦組和文フォントにおける「実際の」グリフの位置
4051 }
4052 \label{fig-pos-tate}
4053 \end{figure}
4054
4055 \item[kern={\{[$j$]=<kern>, [$j'$]=\{<kern>, [<ratio>]\}, ...\}}]
4056
4057 \item[glue={\{[$j$]=\{<width>, <stretch>, <shrink>, [<priority>], [<ratio>]\}, ...\}}]\
4058 %<*ja>
4059
4060 文字クラス$i$の文字と$j$の文字の間に挿入されるkernやglueの量を指定する.
4061
4062              <priority>は \Pkg{luatexja-adjust} による優先順位付き
4063              行長調整(\ref{ssec-adj}節)が有効なときのみ意味を持つ.
4064 このフィールドは省略可能であり,行調整処理におけるこのglueの優先
4065              度を$-2$から$+2$の間の整数で指定する.大きい値ほど「伸びやすく,縮みやすい」
4066              ことを意味する.省略時の値
4067              は0であり,範囲外の値が指定されたときの動作は未定義である.
4068
4069 <ratio>も省略可能フィールドであり,$-1$から$+1$の実数値をとる.省略時の値は0である.
4070 \begin{itemize}
4071 \item $-1$はこのグルーが「前の文字」由来であることを示す.
4072 \item $+1$はこのグルーが「後の文字」由来であることを示す.
4073 \item それ以外の値は,「前の文字」由来のグルーと「後の文字」由来の
4074 グルーが混合されていることを示す.
4075 \end{itemize}
4076 なお,このフィールドの値は\Param{differentjfm}の値が
4077 \texttt{pleft},~\texttt{pright},~\texttt{paverage}の値のときのみ実際に用いられる.
4078
4079 例えば,\cite{x4051}では,句点と中点の間には,
4080 句点由来の二分空きと中点由来の四分空きが挿入されるが,この場合には
4081 \begin{itemize}
4082 \item <width>には$0.5+0.25=0.75$を指定する.
4083 \item <ratio>には次の値を指定する.
4084 \[
4085  -1\cdot \frac{0.5}{0.5+0.25} + 1 \cdot \frac{0.25}{0.5+0.25} = -\frac13
4086 \]
4087 \end{itemize}
4088 %</ja>
4089 %<*en>
4090 \
4091
4092 Specifies the width of kern or glue which will be inserted
4093 between characters in character class~$i$ and those in character class~$j$.
4094
4095 <priority> is an integer in $[-2,2]$ (treated as 0 if omitted), and this is
4096 used only in line adjustment with priority by \Pkg{luatexja-adjust}
4097 (see Subsection~\ref{ssec-adj}). Higher value means the glue is easy to shretch,
4098 and is also easy to shrink.
4099
4100 <ratio> is also an optional value between $-1$ and 1. For example,
4101 The width of a glue between an ideographic full stop ``。''
4102 and a fullwidth middle dot ``・'' is three-fourth of fullwidth,
4103 namely halfwidth from the ideographic full stop, and
4104 quarter-width from the fullwidth middle dot.  In this case,
4105 we specify <ratio> to
4106 \[
4107   -1\cdot \frac{0.5}{0.5+0.25} + 1 \cdot \frac{0.25}{0.5+0.25} = -\frac13.
4108 \]
4109 %</en>
4110
4111
4112 \item[end\_stretch=<kern>, end\_shrink=<kern>]
4113 %<*ja>
4114 (任意)
4115
4116 優先順位付き行長調整が有効であり,かつ現在の文字クラスの文字が行
4117              末に来た時に,行長を詰める調整・伸ばす調整のた
4118              めにこの文字と行末の間に挿入可能なカーンの大きさを指定する.
4119 %</ja>
4120
4121 \end{cslist}
4122
4123 %<*ja>
4124 \paragraph{文字クラスの決定}
4125 文字からその文字の属する文字クラスを算出する過程は少々複雑である.
4126 次の内容を一部に含んだ \texttt{jfm-test.lua} を用いて説明する.
4127 %</ja>
4128 %<*en>
4129 \paragraph{Character to character classes}
4130 We explain how the character class of a character is determined,
4131 using  \texttt{jfm-test.lua} which contains the following:
4132 %</en>
4133 \begin{lstlisting}
4134    [0] = {
4135       chars = { '漢' },
4136       align = 'left', left = 0.0, down = 0.0,
4137       width = 1.0, height = 0.88, depth = 0.12, italic=0.0,
4138    },
4139    [2000] = {
4140       chars = { '。', 'ヒ' },
4141       align = 'left', left = 0.0, down = 0.0,
4142       width = 0.5, height = 0.88, depth = 0.12, italic=0.0,
4143    },
4144 \end{lstlisting}
4145 %<ja>ここで,次のような入力とその実行結果を考える:
4146 %<en>Now consider the following input/output:
4147 \begin{LTXexample}[width=0.3\textwidth]
4148 \jfont\a=file:KozMinPr6N-Regular.otf:jfm=test;+hwid
4149 \setbox0\hbox{\a ヒ漢}
4150 \the\wd0
4151 \end{LTXexample}
4152 %<*en>
4153 Now we look why the above source outputs 15\,pt.
4154 \begin{enumerate}
4155 \item The character ``ヒ'' is converted to its half width  form ``ヒ'' by \verb+hwid+ feature.
4156 \item According to the JFM, the character class of ``ヒ'' is 2000, hence its width is halfwidth.
4157 \item The character class of ``漢'' is zero,  hence its width is fullwidth.
4158 \item Hence the width of \cs{hbox} equals to 15\,pt.
4159 \end{enumerate}
4160 This example shows that the character class of a character is generally determined \emph{after
4161 applying font features by \Pkg{luaotfload}}.
4162 %</en>
4163 %<*ja>
4164 上記の出力結果が,15\,ptとなっているのは理由によるものである:
4165 \begin{enumerate}
4166 \item \verb+hwid+ featureによって「ヒ」が半角幅のグリフ「ヒ」と置き換わる(\Pkg{luaotfload} による処理).
4167 \item JFMによれば,この「ヒ」のグリフの文字クラスは2000である.
4168 \item 以上により文字クラス2000とみなされるため,結果として「ヒ」の幅は半角だと認識される.
4169 \end{enumerate}
4170 この例は,\emph{文字クラスの決定はfont featureの適用によるグリフ置換の後に行われる}ことを
4171 示している.
4172 %</ja>
4173
4174 %<*en>
4175 However, ...
4176 Consider the following input:
4177 %</en>
4178 %<*ja>
4179 但し,JFMによって決まる置換後のグリフの文字クラスが0である場合は,
4180 状況は異なる.
4181 %</ja>
4182 \begin{LTXexample}[width=0.3\textwidth]
4183 \jfont\a=file:KozMinPr6N-Regular.otf:jfm=test;+vert
4184 \a 漢。\inhibitglue 漢
4185 \end{LTXexample}
4186 %<*en>
4187 Here, the character class of the ideographic full stop ``。''~(\texttt{U+3002}) is determined
4188 as following:
4189 \begin{enumerate}
4190 \item As the case of ``ヒ'', the ideographic full stop ``。'' is converted to its vertical
4191       form ``\char"FE12''~(\texttt{U+FE12}).%"
4192 \item The character class of ``\char"FE12'' is \emph{zero}.
4193 \item However, \LuaTeX-ja remembers that this ``\char"FE12'' is obtained from ``。'' by
4194       font features. The character class of ``。'' is \emph{non-zero value}, namely, 2000.
4195 \item Hence the ideographic full stop ``。'' in above belongs the character class~2000.
4196 \end{enumerate}
4197 %</en>
4198 %<*ja>
4199 ここで,句点「。」(\texttt{U+3002})の文字クラスは,以下のようにして決まる.
4200 \begin{enumerate}
4201 \item \Pkg{luaotfload} によって縦組用句点のグリフに置き換わる.
4202 \item 置換後のグリフは \texttt{U+FE12} であり,JFMに従えば文字クラスは\emph{0}と判定される.
4203 \item この場合,置換前の横組用句点のグリフによって文字クラスを判定する.
4204 \item 結果として,上の出力例中の句点の文字クラスは2000となる.
4205 \end{enumerate}
4206 %</ja>
4207
4208
4209 %<ja>\paragraph{仮想的な文字}
4210 %<en>\paragraph{Imaginary characters}
4211 %<*en>
4212 As described before, you can specify several \emph{imaginary characters} in
4213 \texttt{chars} field. The most of these characters are regarded as the
4214 characters of class 0 in \pTeX.
4215 As a result, \LuaTeX-ja can control typesetting finer than \pTeX.
4216 The following is the list of imaginary characters:
4217 %</en>
4218 %<*ja>
4219 上で説明した通り,\texttt{chars}フィールド中にはいくつかの「特殊文字」も
4220 指定可能である.これらは,大半が\pTeX のJFMグルーの挿入処理ではみな「文字
4221 クラス0の文字」として扱われていた文字であり,その結果として\pTeX より細か
4222 い組版調整ができるようになっている.以下でその一覧を述べる:
4223 %</ja>
4224
4225 \begin{cslist}
4226 %%\item['diffmet']
4227 %%<en>Used at a boundary between two \textbf{JAchar}s whose JFM or size is different.
4228 %%<ja>JFMやサイズが異なる2つの\textbf{JAchar}の間の境界として用いられる.
4229
4230 \item['boxbdd']
4231 %<en>The beginning/ending of a hbox, and the beginning of a noindented (i.e., began by \cs{noindent}) paragraph.
4232 %<ja>hboxの先頭と末尾,及びインデントされていない(\cs{noindent} で開始された)段落の先頭を表す.
4233
4234 \item['parbdd']
4235 %<en>The beginning of an (indented) paragraph.
4236 %<ja>通常の(\cs{noindent} で開始されていない)段落の先頭.
4237
4238 \item['jcharbdd']
4239 %<en>A boundary between \textbf{JAchar} and anything else (such as \textbf{ALchar}, kern, glue,\,\ldots).
4240 %<ja>和文文字と「その他のもの」(欧文文字,glue,kern等)との境界.
4241
4242 \item[$-1$]
4243 %<en>The left/right boundary of an inline math formula.
4244 %<ja>行中数式と地の文との境界.
4245 \end{cslist}
4246
4247 %<en>\paragraph{Porting JFM from \pTeX}
4248 %<ja>\paragraph{\pTeX 用和文用TFMの移植}
4249
4250 % ToDo: English version.
4251
4252 %<*en>
4253 See Japanese version of this manual.
4254 %</en>
4255
4256 %<*ja>
4257 以下に,\pTeX 用に作られた和文用TFMを\LuaTeX-ja用に移植する場合の注意点を挙げておく.
4258 \begin{itemize}
4259 \item 実際に出力される和文フォントのサイズがdesign sizeとなる.
4260 このため,例えば$1\,\textrm{zw}$がdesign sizeの0.962216倍であるJISフォン
4261       トメトリック等を移植する場合は,次のようにするべきである:
4262 \begin{itemize}
4263 \item JFM中の全ての数値を$1/0.962216$倍しておく.
4264 \item \TeX ソース中で使用するところで,サイズ指定を0.962216倍にする.
4265       \LaTeX でのフォント宣言なら,例えば次のように:
4266 \begin{lstlisting}
4267 \DeclareFontShape{JY3}{mc}{m}{n}{<-> s*[0.962216] psft:Ryumin-Light:jfm=jis}{}
4268 \end{lstlisting}
4269 \end{itemize}
4270 \item 上に述べた特殊文字は,\texttt{'boxbdd'}を除き文字クラスを全部0とする
4271       (JFM中に単に書かなければよい).
4272 \item \texttt{'boxbdd'}については,それのみで一つの文字クラスを形成し,その
4273       文字クラスに関してはグルー/カーンの設定はしない.
4274
4275 これは,\pTeX では,
4276       hboxの先頭・末尾とインデントされていない(\cs{noindent} で開始さ
4277       れた)段落の先頭にはJFMグルーは入らないという仕様を実現させるためである.
4278 \item \pTeX の組版を再現させようというのが目的であれば以上の注意を守れば十分である.
4279
4280 ところで,\pTeX では通常の段落の先頭にJFMグルーが残るという仕様があるので,
4281       段落先頭の開き括弧は全角二分下がりになる.全角下がりを実現させるに
4282       は,段落の最初に手動で \cs{inhibitglue} を追加するか,あるいは
4283       \ \cs{everypar} のハックを行い,それを自動化させるしかなかった.
4284
4285 一方,\LuaTeX-jaでは,\texttt{'parbdd'}によって,それがJFM側で調整できるよ
4286 うになった.例えば,\LuaTeX-ja同梱のJFMのように,\texttt{'boxbdd'}と同じ文字クラスに
4287 \texttt{'parbdd'}を入れれば全角下がりとなる.
4288
4289 \begin{LTXexample}[width=0.4\textwidth]
4290 \jfont\g=KozMinPr6N-Regular:jfm=test \g
4291 \parindent1\zw\noindent{}◆◆◆◆◆
4292 \par 「◆◆←二分下がり
4293 \par 【◆◆←全角下がり
4294 \par 〔◆◆←全角二分下がり
4295 \end{LTXexample}
4296 \end{itemize}
4297
4298 但し,\cs{everypar} を利用している場合にはこの仕組みは正しく動かない.
4299 そのような例としては箇条書き中の \cs{item} で始まる段落があり,\Pkg{ltjsclasses}では
4300 人工的に「\texttt{'parbdd'}の意味を持つ」whatsitノードを作ることによって対処している%
4301 \footnote{\texttt{ltjsclasses.dtx} を参照されたい.
4302 JFM側で一部の対処ができることにより,\Pkg{jsclasses}のようにif文の判定はしていない.}.
4303 %</ja>
4304
4305
4306 %<en>\subsection{Math Font Family}
4307 %<ja>\subsection{数式フォントファミリ}
4308 \label{ssec-math}
4309
4310 %<*en>
4311 \TeX\ handles fonts in math formulas by 16~font families\footnote{Omega,
4312 Aleph, \LuaTeX~and $\varepsilon$-\kern-.125em(u)\pTeX\ can handles 256~families, but
4313 an external package is needed to support this in plain \TeX\ and
4314 \LaTeX.}, and each family has three fonts:
4315 \cs{textfont}, \cs{scriptfont} and \cs{scriptscriptfont}.
4316 %</en>
4317 %<*ja>
4318 \TeX\ は数式フォントを16のファミリ\footnote{Omega, Aleph, \LuaTeX,そして
4319   $\varepsilon$-\kern-.125em(u)\pTeX\ では256の数式ファミリを扱うことができるが,
4320   これをサポートするためにplain \TeX と\LaTeX では外部パッケージを読み込む必要が
4321   ある.}で管理し,それぞれのファミリは3つのフォントを持っている:
4322 \cs{textfont}, \cs{scriptfont} そして \cs{scriptscriptfont} である.
4323 %</ja>
4324
4325 %<*en>
4326 \LuaTeX-ja's handling of Japanese fonts in math formulas is similar;
4327 Table~\ref{tab-math} shows counterparts to \TeX's primitives for math
4328 font families. There is no relation between the value of
4329 \cs{fam} and that of \cs{jfam}; with appropriate settings,
4330 you can set both \cs{fam} and \cs{jfam} to the same value.
4331 Here <jfont\_cs> in the argument of \Param{jatextfont} etc.\ is
4332 a control sequence which is defined by \cs{jfont}, i.e.,
4333 a \emph{horizontal} Japanese font.
4334 %</en>
4335 %<*ja>
4336 \LuaTeX-jaの数式中での和文フォントの扱いも同様である.
4337 表\ref{tab-math}は数式フォントファミリに対する \TeX のプリミティブと対応する
4338 ものを示している.\cs{fam} と \cs{jfam} の値の間には関係はなく,
4339 適切な設定の下では \cs{fam} と \cs{jfam} の両方に同じ値を設定することができる.
4340 \Param{jatextfont} 他の第2引数<jfont\_cs>は,\cs{jfont} で定義された
4341 \emph{横組用}和文フォントである.\cs{tfont} で定義された
4342 \emph{縦組用}和文フォントを指定することは想定していない.
4343 %</ja>
4344
4345 \begin{table}[!tb]
4346 %<en>\caption{Commands for Japanese math fonts}
4347 %<ja>\caption{和文数式フォントに対する命令}
4348 \label{tab-math}
4349 %<en>\medskip
4350 \centering
4351 \def\{{\char`\{}\def\}{\char`\}}\small
4352 \begin{tabular}{ll}
4353 \toprule
4354 %<en>\bf Japanese fonts&\bf alphabetic fonts\\
4355 %<ja>\bf 和文フォント&\bf 欧文フォント\\
4356 \midrule
4357 \cs{jfam}${}\in [0,256)$&\cs{fam}\\
4358 \tt\Param{jatextfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\cs{textfont}<fam>=<font\_cs>\\
4359 \tt\Param{jascriptfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\cs{scriptfont}<fam>=<font\_cs>\\
4360 \tt\Param{jascriptscriptfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\cs{scriptscriptfont}<fam>=<font\_cs>\\
4361 \bottomrule
4362 \end{tabular}
4363 \end{table}
4364
4365 %<en>\subsection{Callbacks}
4366 %<ja>\subsection{コールバック}
4367
4368 %<*en>
4369 \LuaTeX-ja also has several callbacks. These callbacks can
4370 be accessed via \verb+luatexbase.add_to_callback+ function and so on, as other callbacks.
4371 %</en>
4372 %<*ja>
4373 \LuaTeX 自体のものに加えて,\LuaTeX-jaもコールバックを持っている.
4374 これらのコールバックには,他のコールバックと同様に \verb+luatexbase.add_to_callback+
4375 関数などを用いることでアクセスすることができる.
4376 %</ja>
4377 \begin{description}[font=\bfseries, style=nextline]
4378 %<en>\item[\texttt{luatexja.load\_jfm} callback]
4379 %<ja>\item[\texttt{luatexja.load\_jfm}コールバック]
4380 %<*en>
4381 With this callback you can overwrite JFMs.
4382 This callback is called when a new JFM is loaded.
4383 %</en>
4384 %<*ja>
4385 このコールバックを用いることでJFMを上書きすることができる.
4386 このコールバックは新しいJFMが読み込まれるときに呼び出される.
4387 %</ja>
4388
4389 \begin{lstlisting}[numbers=left]
4390 function (<table> jfm_info, <string> jfm_name)
4391   return <table> new_jfm_info
4392 end
4393 \end{lstlisting}
4394
4395 %<*en>
4396 The argument \verb+jfm_info+ contains a table similar to the table in a JFM file, except
4397 this argument has \texttt{chars} field which contains character codes
4398              whose character class is not~0.
4399 %</en>
4400 %<*ja>
4401 引数 \verb+jfm_info+ はJFMファイルのテーブルと似たものが格納されるが,
4402 クラス0を除いた文字のコードを含んだ\texttt{chars}フィールドを持つ点が異なる.
4403 %</ja>
4404
4405 %<*en>
4406 An example of this callback is the \texttt{ltjarticle} class, with
4407              forcefully assigning character class~0 to \texttt{'parbdd'}
4408              in the JFM \texttt{jfm-min.lua}.
4409 %</en>
4410 %<*ja>
4411 このコールバックの使用例は\texttt{ltjarticle}クラスにあり,
4412 \texttt{jfm-min.lua}中の\texttt{'parbdd'}を強制的にクラス0に割り当てている.
4413 %</ja>
4414
4415 %<en>\item[\texttt{luatexja.define\_jfont} callback]
4416 %<ja>\item[\texttt{luatexja.define\_jfont}コールバック]
4417 %<*en>
4418 This callback and the next callback form a pair, and you can assign characters
4419  which do not have fixed code points in Unicode to non-zero character classes.
4420 This \texttt{luatexja.define\_font} callback is called just when new Japanese font is loaded.
4421 %</en>
4422 %<*ja>
4423 このコールバックと次のコールバックは組をなしており,Unicode中に固定された文字コード
4424 番号を持たない文字を非零の文字クラスに割り当てることができる.
4425 このコールバックは新しい和文フォントが読み込まれたときに呼び出される.
4426 %</ja>
4427
4428 \begin{lstlisting}[numbers=left]
4429 function (<table> jfont_info, <number> font_number)
4430   return <table> new_jfont_info
4431 end
4432 \end{lstlisting}
4433 %<*en>
4434 \verb+jfont_info+ has the following fields,
4435 \emph{which may not overwritten by a user}:
4436 \begin{description}
4437 \item[\texttt{size}]
4438 The font size specified at \cs{jfont} in scaled points ($1\,\mathrm{sp}=2^{-16}\,\mathrm{pt}$).
4439 \item[\texttt{zw}, \texttt{zh}, \texttt{kanjiskip}, \texttt{xkanjiskip}]
4440 These are scaled value of those specified by the JFM, by the font size.
4441 \item[\texttt{jfm}]
4442 The internal number of the JFM.
4443 \item[\texttt{var}]
4444 The value of \texttt{jfmvar}~key, which is specified at \cs{jfont}.
4445 The default value is the empty string.
4446 \item[\texttt{chars}]
4447 The mapping table from character codes to its character classes.\\
4448 The specification \texttt{[i].chars=\{<character>, ...\}} in the JFM will be  stored in this
4449            field as \texttt{chars=\{[<character>]=\,$i$, ...\}}.
4450 \item[\texttt{char\_type}]
4451 For $i\in\omega$, \texttt{char\_type[$i$]} is information of characters whose class is
4452            $i$, and has the following fields:
4453 \begin{itemize}
4454  \item \texttt{width},~\texttt{height}, \texttt{depth},
4455   \texttt{italic}, \texttt{down},~\texttt{left}\ are just
4456        scaled value of those specified by the JFM, by the font size.
4457  \item \texttt{align} is a number which is determined from \texttt{align}~field in the JFM:
4458 \[
4459  \begin{cases}
4460   0&\text{\texttt{'left'} and the default value}\\0.5&\text{\tt 'middle'}\\1&\text{\tt 'right'}
4461  \end{cases}
4462 \]
4463 \item For $j\in \omega$, \texttt{[$j$]} stores a kern or a glue which will be inserted
4464 between character class~$i$ and class~$j$.
4465
4466 If a kern will be inserted, the value of this field is \texttt{[$j$]=\{false, <kern\_node>, <ratio>\}},
4467 where <kern\_node> is a node\footnote{%
4468  This version of \LuaTeX-ja uses ``direct access
4469       model'' for accessing nodes, if possible. }.
4470 If a glue will be inserted, we have \texttt{[$j$]=\{false, <spec\_node>, <ratio>, <icflag>\}},
4471 where <spec\_node> is also a node, and $\text{<icflag>}=\textit{from\_jfm}+\text{<priority>}$.
4472 \end{itemize}
4473 \end{description}
4474 %</en>
4475 %<*ja>
4476 \verb+jfont_info+ は最低限以下のフィールドを持つが,これらを書き換えてはならない:
4477 \begin{cslist}
4478 \item[size]
4479 実際に使われるフォントサイズ(sp単位).$1\,\mathrm{sp}=2^{-16}\,\mathrm{pt}$.
4480 \item[zw\textrm{, }zh\textrm{, }kanjiskip\textrm{, }xkanjiskip]
4481 JFMファイルで指定されているそれぞれの値をフォントサイズに合わせてスケーリングしたものを
4482 sp単位で格納している.
4483 \item[jfm]
4484 利用されているJFMを識別するための番号.
4485 \item[var]
4486 \cs{jfont},~\cs{tfont} で指定された \texttt{jfmvar} キーの値(未指定のときは空文字列).
4487 \item[chars]
4488 文字コードから文字クラスへの対応が記述されたテーブル.\\
4489 JFM内の \texttt{[i].chars=\{<character>, ...\}} という指定は\
4490 \texttt{chars=\{[<character>]=\,$i$, ...\}} という形式に変換されている.
4491 \item[char\_type]
4492 $i\in\omega$に対して,\texttt{char\_type[$i$]} は文字クラス$i$の文字の寸法を格納しており,
4493 以下のフィールドを持つ.
4494 \begin{itemize}
4495  \item \texttt{width},~\texttt{height}, \texttt{depth},
4496   \texttt{italic}, \texttt{down},~\texttt{left}\ は
4497 JFMで指定されているそれぞれの値をスケーリングしたものである.
4498  \item \texttt{align} はJFMで指定されている値によって,
4499 \[
4500  \begin{cases}
4501   0&\text{\texttt{'left'}や省略時}\\0.5&\text{\tt 'middle'}\\1&\text{\tt 'right'}
4502  \end{cases}
4503 \]
4504 のいずれかの値をとる.
4505 \item $j\in \omega$に対して,\texttt{[$j$]} は文字クラス$i$の文字と$j$の文字の間に挿入されるkern
4506       やglueを格納している.
4507 間に入るものがkernであれば,このフィールドの値は\
4508 \texttt{[$j$]=\{false, <kern\_node>, <ratio>\}} である.
4509 <kern\_node>はkernを表すノードそのものである\footnote{%
4510 本バージョンでは利用可能ならばノードのアクセス手法にdirect access
4511       modelを用いている.そのため,例えば\LuaTeX\ beta-0.78.2では,単なる自然数のようにし
4512       か見えないことに注意.
4513 }.
4514 glueであれば,\texttt{[$j$]=\{false, <spec\_node>, <ratio>, <icflag>\}} である.
4515 <spec\_node>はglueの長さを表すノードそのものであり,
4516       $\text{<icflag>}=\textit{from\_jfm}+\text{<priority>}$である.
4517 \end{itemize}
4518 \end{cslist}
4519 %</ja>
4520
4521 %<*en>
4522 The returned table \verb+new_jfont_info+ also should include these fields, but
4523 you are free to add more fields (to use them in the \texttt{luatexja.find\_char\_class} callback).
4524 The \verb+font_number+ is a font number.
4525 %</en>
4526 %<*ja>
4527 戻り値の \verb+new_jfont_info+ テーブルも上に述べたフィールドをそのまま含まなければならないが,
4528 それ以外にユーザが勝手にフィールドを付け加えることは自由である.
4529 \verb+font_number+ はフォント番号である.
4530 %</ja>
4531
4532 %<*en>
4533 A good example of this and the next callbacks is the \Pkg{luatexja-otf}
4534              package, supporting \verb+"AJ1-xxx"+ form for Adobe-Japan1
4535              CID characters in a JFM. This callback doesn't replace any
4536              code of \LuaTeX-ja.
4537 %</en>
4538 %<*ja>
4539 これと次のコールバックの良い使用例は\Pkg{luatexja-otf}パッケージであり,
4540 JFM中でAdobe-Japan1 CIDの文字を \verb+"AJ1-xxx"+ の形で指定するために
4541 用いられている.
4542 %</ja>
4543
4544 %<en>\item[\texttt{luatexja.find\_char\_class} callback]
4545 %<ja>\item[\texttt{luatexja.find\_char\_class}コールバック]
4546 %<*en>
4547 This callback is called just when \LuaTeX-ja is trying to determine which
4548              character class a character \verb+chr_code+ belongs.
4549 A function used in this callback should be in the following form:
4550 %</en>
4551 %<*ja>
4552 このコールバックは\LuaTeX-jaが \verb+chr_code+ の文字がどの文字クラスに
4553 属するかを決定しようとする際に呼び出される.
4554 このコールバックで呼び出される関数は次の形をしていなければならない:
4555 %</ja>
4556 \begin{lstlisting}[numbers=left]
4557 function (<number> char_class, <table> jfont_info, <number> chr_code)
4558   if char_class~=0 then return char_class
4559   else
4560     ....
4561     return (<number> new_char_class or 0)
4562   end
4563 end
4564 \end{lstlisting}
4565
4566 %<*en>
4567 The argument \verb+char_class+ is the result of \LuaTeX-ja's default
4568              routine or previous function calls in this callback, hence
4569              this argument may not be 0. Moreover, the returned
4570              \verb+new_char_class+ should be as same as \verb+char_class+ when \verb+char_class+
4571              is not~0, otherwise you will overwrite the \LuaTeX-ja's
4572              default routine.
4573 %</en>
4574 %<*ja>
4575 引数 \verb+char_class+ は\LuaTeX-jaのデフォルトルーチンか,このコールバックの
4576 直前の関数呼び出しの結果を含んでおり,したがってこの値は0ではないかもしれない.
4577 さらに,戻り値の \verb+new_char_class+ は \verb+char_class+ が非零のときには
4578 \verb+char_class+ の値と同じであるべきで,そうでないときは\LuaTeX-jaの
4579 デフォルトルーチンを書き換えることになる.
4580 %</ja>
4581
4582 %<en>\item[\texttt{luatexja.set\_width} callback]
4583 %<ja>\item[\texttt{luatexja.set\_width}コールバック]
4584 %<*en>
4585 This callback is called when \LuaTeX-ja is trying to encapsule a
4586              \textbf{JAchar} \textit{glyph\_node}, to adjust its
4587              dimension and position.
4588 %</en>
4589 %<*ja>
4590 このコールバックは\LuaTeX-jaが\textbf{JAchar}の寸法と位置を調節するために
4591 その\textit{glyph\_node}をカプセル化しようとする際に呼び出される.
4592 %</ja>
4593 \begin{lstlisting}[numbers=left]
4594 function (<table> shift_info, <table> jfont_info, <number> char_class)
4595   return <table> new_shift_info
4596 end
4597 \end{lstlisting}
4598
4599 %<*en>
4600 The argument \verb+shift_info+ and the returned \verb+new_shift_info+ have
4601 \texttt{down} and \texttt{left} fields, which are the amount of shifting
4602              down/left the character in a scaled point.
4603 %</en>
4604 %<*ja>
4605 引数 \verb+shift_info+ と戻り値の \verb+new_shift_info+ は
4606 \texttt{down}と\texttt{left}のフィールドを持ち,これらの値は
4607 文字の下/左へのシフト量(sp単位)である.
4608 %</ja>
4609
4610 %<*en>
4611 A good example is \Pkg{test/valign.lua}.
4612 After loading this file, the vertical position of glyphs is automatically
4613 adjusted; the ratio $(\hbox{height}:\hbox{depth})$ of glyphs is adjusted
4614 to be that of letters in the character class~0. For example, suppose that
4615 \begin{itemize}
4616 \item The setting of the JFM: $(\hbox{height})=88x$, $(\hbox{depth})=12x$
4617   (the standard values of Japanese OpenType fonts);
4618 \item The value of the real font: $(\hbox{height})=28y$, $(\hbox{depth})=5y$
4619   (the standard values of Japanese TrueType fonts).
4620 \end{itemize}
4621 Then, the position of glyphs is shifted up by
4622 %</en>
4623 %<*ja>
4624 良い例が\Pkg{test/valign.lua}である.このファイルが読み込まれた状態では,
4625              JFM内で規定された文字クラス0の文字における$(\hbox{高
4626              さ}):(\hbox{深さ})$の比になるように,実際のフォントの出力上
4627              下位置が自動調整される.例えば,
4628 \begin{itemize}
4629 \item JFM側の設定:$(\hbox{高さ})=88x$, $(\hbox{深さ})=12x$%
4630 (和文OpenTypeフォントの標準値)
4631 \item 実フォント側の数値:$(\hbox{高さ})=28y$, $(\hbox{深さ})=5y$(和文TrueTypeフォントの標準値)
4632 \end{itemize}
4633 となっていたとする.すると,実際の文字の出力位置は,以下の量だけ上にぜらされることとなる:
4634 %</ja>
4635 \[
4636  \frac{88x}{88x+12x} (28y+5y) - 28y = \frac{26}{25}y= 1.04y.
4637 \]
4638 \end{description}
4639
4640
4641
4642 %<en>\section{Parameters}
4643 %<ja>\section{パラメータ}
4644 \subsection{\cs{ltjsetparameter}}
4645 \label{ssec-param}
4646
4647 %<*en>
4648 As described before, \cs{ltjsetparameter} and \cs{ltjgetparameter} are
4649 commands for accessing most parameters of \LuaTeX-ja. One of the main
4650 reason that \LuaTeX-ja didn't adopted the syntax similar to that of \pTeX\
4651 (\textit{e.g.},~\verb+\prebreakpenalty`)=10000+)
4652 is the position of \verb+hpack_filter+ callback in the source
4653 of \LuaTeX, see Section~\ref{sec-para}.
4654 %</en>
4655 %<*ja>
4656 先に述べたように,\LuaTeX-jaのほとんどの内部パラメータにアクセスするには
4657 \cs{ltjsetparameter} と \cs{ltjgetparameter} を用いる.
4658 \LuaTeX-jaが\pTeX のような文法(例えば,\verb+\prebreakpenalty`)=10000+)を
4659 採用しない理由の一つは,\LuaTeX のソースにおける \verb+hpack_filter+
4660 コールバックの位置にある.\ref{sec-para}章を参照.
4661 %</ja>
4662
4663 %<*en>
4664 \cs{ltjsetparameter} and \cs{ltjglobalsetparameter} are commands
4665 for assigning parameters. These take one argument which is a
4666 \texttt{<key>=<value>} list.
4667 The list of allowed keys are described in the next subsection.
4668 The difference between
4669 \cs{ltjsetparameter} and \cs{ltjglobalsetparameter} is only the
4670 scope of assignment;
4671 \cs{ltjsetparameter} does a local assignment and
4672 \cs{ltjglobalsetparameter} does a global one.
4673 They also obey the value of \cs{globaldefs},
4674 like other assignment.
4675 %</en>
4676 %<*ja>
4677 \cs{ltjsetparameter} と \cs{ltjglobalsetparameter} はパラメータを
4678 指定するための命令である.これらは\texttt{<key>=<value>}のリストを
4679 引数としてとる.許されるキーの一覧は次の節にある.
4680 \cs{ltjsetparameter} と \cs{ltjglobalsetparameter} の違いはスコープの
4681 違いのみで,
4682 \cs{ltjsetparameter} はローカルな指定,\cs{ltjglobalsetparameter} は
4683 グローバルな指定を行う.
4684 これらは他のパラメータ指定と同様に \cs{globaldefs} の値に従う.
4685 %</ja>
4686
4687 %<*en>
4688 The following is the list of parameters which can be specified by the
4689 \cs{ltjsetparameter} command. [\cs{cs}] indicates the counterpart
4690 in \pTeX, and symbols beside each parameter has the following meaning:
4691 %</en>
4692 %<*ja>
4693 以下は \cs{ltjsetparameter} に指定することができるパラメータの一覧である.
4694 [\cs{cs}]は\pTeX における対応物を示す.
4695 また,それぞれのパラメータの右上にある記号には次の意味がある:
4696 %</ja>
4697 \begin{itemize}
4698 %<*en>
4699 \item ``\ast'' : values at the end of a paragraph or a hbox are
4700 adopted in the whole paragraph or the whole hbox.
4701 %</en>
4702 %<*ja>
4703 \item ``\ast'':段落やhboxの終端での値がその段落/hbox全体で用いられる.
4704 %</ja>
4705 %<*en>
4706 \item ``\dagger'': assignments are always global.
4707 %</en>
4708 %<*ja>
4709 \item ``\dagger'':指定は常にグローバルになる.
4710 %</ja>
4711 \end{itemize}
4712
4713 \begin{cslist}[style=standard]
4714 \item[\DParam{jcharwidowpenalty}\,=<penalty>$^\ast$] [\cs{jcharwidowpenalty}]\
4715
4716 %<*en>
4717 Penalty value for suppressing orphans. This penalty is inserted just
4718              after the last \textbf{JAchar} which is not regarded as a
4719              (Japanese) punctuation mark.
4720 %</en>
4721 %<*ja>
4722 パラグラフの最後の字が孤立して改行されるのを防ぐためのペナルティの値.
4723 このペナルティは(日本語の)句読点として扱われない最後の\textbf{JAchar}の直後に
4724 挿入される.
4725 %</ja>
4726
4727 \item[\DParam{kcatcode}\,=\{<chr\_code>,<natural number>\}$^\ast$]\
4728
4729 %<*en>
4730 An additional attributes which each character whose character code is <chr\_code> has.
4731 At the present version, the lowermost bit of <natural number> indicates
4732              whether the character is considered as a punctuation mark
4733              (see the description of \Param{jcharwidowpenalty} above).
4734 %</en>
4735 %<*ja>
4736 文字コードが<chr\_code>の文字が持つ付加的な属性値(attribute).
4737 現在のバージョンでは,<natural number>の最下位ビットが,その文字が句読点と
4738 みなされるかどうかを表している(上の\Param{jcharwidowpenalty}の記述を参照).
4739 %</ja>
4740
4741 \item[\DParam{prebreakpenalty}\,=\{<chr\_code>,<penalty>\}$^\ast$] [\cs{prebreakpenalty}]\
4742
4743 %<*ja>
4744 文字コード<chr\_code>の\textbf{JAchar}が行頭にくることを抑止するために,
4745              この文字の前に挿入/追加されるペナルティの量を指定する.
4746
4747 例えば閉じ括弧「〗」は絶対に行頭にきてはならないので,
4748 \begin{lstlisting}
4749 \ltjsetparameter{prebreakpenalty={`〙,10000}}
4750 \end{lstlisting}
4751 と,最大値の10000が標準で指定されている.他にも,小書きのカナなど,絶対禁止とい
4752              うわけではないができれば行頭にはきて欲しくない場合に,0と
4753              10000の間の値を指定するのも有用であろう.
4754 %</ja>
4755 %<*en>
4756 Set a penalty which is inserted automatically before the character <chr\_code>,
4757 to prevent a line starts from this character. For example, a line cannot started
4758 with one of closing brackets ``〗'', so \LuaTeX-ja sets
4759 \begin{lstlisting}
4760 \ltjsetparameter{prebreakpenalty={`〙,10000}}
4761 \end{lstlisting}
4762 by default.
4763 %</en>
4764
4765
4766 \item[\DParam{postbreakpenalty}\,=\{<chr\_code>,<penalty>\}$^\ast$]
4767            [\cs{postbreakpenalty}]\
4768
4769 %<*ja>
4770 文字コード<chr\_code>の\textbf{JAchar}が行末にくることを抑止するために,
4771              この文字の後に挿入/追加されるペナルティの量を指定する.
4772
4773 \pTeX では,\cs{prebreakpenalty}, \cs{postbreakpenalty}において,
4774 \begin{itemize}
4775 \item 一つの文字に対して,pre, postどちらか一つしか指定することができなかっ
4776       た(後から指定した方で上書きされる).
4777 \item pre, post合わせて256文字分の情報を格納することしかできなかった.
4778 \end{itemize}
4779 という制限があったが,\LuaTeX-jaではこれらの制限は解消されている.
4780 %</ja>
4781 %<*en>
4782 Set a penalty which is inserted automatically after the character <chr\_code>,
4783 to prevent a line ends with this character.
4784 \pTeX\ has following restrictions on \cs{prebreakpenalty} and \cs{postbreakpenalty},
4785 but they don't exist in \LuaTeX-ja:
4786 \begin{itemize}
4787  \item Both \cs{prebreakpenalty} and \cs{postbreakpenalty} cannot be set
4788 for the same character.
4789  \item We can set \cs{prebreakpenalty} and \cs{postbreakpenalty}  up to 256~characters.
4790 \end{itemize}
4791 %</en>
4792
4793 \item[\DParam{jatextfont}\,=\{<jfam>,<jfont\_cs>\}$^\ast$]
4794 %<en>[\cs{textfont} in \TeX]
4795 %<ja>[\TeX の \cs{textfont}]
4796 \item[\DParam{jascriptfont}\,=\{<jfam>,<jfont\_cs>\}$^\ast$]
4797 %<en>[\cs{scriptfont} in \TeX]
4798 %<ja>[\TeX の \cs{scriptfont}]
4799 \item[\DParam{jascriptscriptfont}\,=\{<jfam>,<jfont\_cs>\}$^\ast$]
4800 %<en>[\cs{scriptscriptfont} in \TeX]
4801 %<ja>[\TeX の \cs{scriptscriptfont}]
4802 \item[\DParam{yjabaselineshift}\,=<dimen>]\
4803 \item[\DParam{yalbaselineshift}\,=<dimen>] [\cs{ybaselineshift}]
4804 \item[\DParam{tjabaselineshift}\,=<dimen>]\
4805 \item[\DParam{talbaselineshift}\,=<dimen>] [\cs{tbaselineshift}]
4806
4807 \item[\DParam{jaxspmode}\,=\{<chr\_code>,<mode>\}$^\ast$]\
4808
4809 %<*en>
4810 Setting whether inserting \Param{xkanjiskip} is allowed before/after a \textbf{JAchar} whose character code is <chr\_code>.
4811 The followings are allowed for <mode>:
4812 %</en>
4813 %<*ja>
4814 文字コードが<chr\_code>の\textbf{JAchar}の前/後ろに\Param{xkanjiskip}の
4815 挿入を許すかどうかの設定.
4816 以下の<mode>が許される:
4817 %</ja>
4818 \begin{description}
4819 %<en>\item[0, \texttt{inhibit}] Insertion of \Param{xkanjiskip} is inhibited before the character, nor after the character.
4820 %<ja>\item[0, \texttt{inhibit}] \Param{xkanjiskip}の挿入は文字の前/後ろのいずれでも禁止される.
4821 %<en>\item[1, \texttt{preonly}] Insertion of \Param{xkanjiskip} is allowed before the character, but not after.
4822 %<ja>\item[1, \texttt{preonly}] \Param{xkanjiskip}の挿入は文字の前では許されるが,後ろでは許されない.
4823 %<en>\item[2, \texttt{postonly}] Insertion of \Param{xkanjiskip} is allowed after the character, but not before.
4824 %<ja>\item[2, \texttt{postonly}] \Param{xkanjiskip}の挿入は文字の後ろでは許されるが,前では許されない.
4825 %<en>\item[3, \texttt{allow}] Insertion of \Param{xkanjiskip} is allowed both before the character and after the character. This is the default value.
4826 %<ja>\item[3, \texttt{allow}] \Param{xkanjiskip}の挿入は文字の前/後ろのいずれでも許される.これがデフォルトの値である.
4827 \end{description}
4828 %<*en>
4829 This parameter is similar to the \cs{inhibitxspcode} primitive of \pTeX, but not compatible with \cs{inhibitxspcode}.
4830 %</en>
4831 %<*ja>
4832 このパラメータは\pTeX の \cs{inhibitxspcode} プリミティブと似ているが,
4833 互換性はない.
4834 %</ja>
4835 \item[\DParam{alxspmode}\,=\{<chr\_code>,<mode>\}$^\ast$] [\cs{xspcode}]\
4836
4837 %<*en>
4838 Setting whether inserting \Param{xkanjiskip} is allowed before/after a
4839              \textbf{ALchar} whose character code is <chr\_code>.
4840              The followings are allowed for <mode>:
4841 %</en>
4842 %<*ja>
4843 文字コードが<chr\_code>の\textbf{ALchar}の前/後ろに\Param{xkanjiskip}の
4844 挿入を許すかどうかの設定.
4845 以下の<mode>が許される:
4846 %</ja>
4847 \begin{description}
4848 %<en>\item[0, \texttt{inhibit}] Insertion of \Param{xkanjiskip} is inhibited before the character, nor after the character.
4849 %<ja>\item[0, \texttt{inhibit}] \Param{xkanjiskip}の挿入は文字の前/後ろのいずれでも禁止される.
4850 %<en>\item[1, \texttt{preonly}] Insertion of \Param{xkanjiskip} is allowed before the character, but not after.
4851 %<ja>\item[1, \texttt{preonly}] \Param{xkanjiskip}の挿入は文字の前では許されるが,後ろでは許されない.
4852 %<en>\item[2, \texttt{postonly}] Insertion of \Param{xkanjiskip} is allowed after the character, but not before.
4853 %<ja>\item[2, \texttt{postonly}] \Param{xkanjiskip}の挿入は文字の後ろでは許されるが,前では許されない.
4854 %<en>\item[3, \texttt{allow}] Insertion of \Param{xkanjiskip} is allowed before the character and after the character. This is the default value.
4855 %<ja>\item[3, \texttt{allow}] \Param{xkanjiskip}の挿入は文字の前/後ろのいずれでも許される.これがデフォルトの値である.
4856 \end{description}
4857 %<*en>
4858 Note that parameters \Param{jaxspmode} and \Param{alxspmode} share a common table, hence these two parameters are synonyms of each other.
4859 %</en>
4860 %<*ja>
4861 \Param{jaxspmode}と\Param{alxspmode}は共通のテーブルを用いているため,
4862 これら2つのパラメータは互いの別名となっていることに注意する.
4863 %</ja>
4864
4865 \item[\DParam{autospacing}\,=<bool>] [\cs{autospacing}]
4866 \item[\DParam{autoxspacing}\,=<bool>] [\cs{autoxspacing}]
4867 \item[\DParam{kanjiskip}\,=<skip>$^\ast$] [\cs{kanjiskip}]\
4868
4869 %<*ja>
4870 デフォルトで2つの\textbf{JAchar}の間に挿入されるグルーである.
4871 通常では,\pTeX と同じようにフォントサイズに比例して変わることはない.
4872 しかし,自然長が \cs{maxdimen} の場合は,例外的に和文フォントのJFM側で指定されている
4873 値を採用(こちらはフォントサイズに比例)することになっている.
4874 %</ja>
4875
4876 \item[\DParam{xkanjiskip}\,=<skip>$^\ast$] [\cs{xkanjiskip}]\
4877
4878 %<*ja>
4879 デフォルトで\textbf{JAchar}と\textbf{ALchar}の間に挿入されるグルーである.
4880 \Param{kanjiskip}と同じように,通常ではフォントサイズに比例して変わることはないが,
4881 自然長が \cs{maxdimen} の場合が例外である.
4882 %</ja>
4883
4884
4885 \item[\DParam{differentjfm}\,=<mode>$^\dagger$]\
4886
4887 %<*en>
4888 Specify how glues/kerns between two \textbf{JAchar}s whose JFM (or size) are different.
4889 The allowed arguments are the followings:
4890 %</en>
4891 %<*ja>
4892 JFM(もしくはサイズ)が異なる2つの\textbf{JAchar}の間にグルー/カーンをどのように
4893 入れるかを指定する.
4894 許される値は以下の通り:
4895 %</ja>
4896 \begin{quote}
4897 \texttt{average},
4898 \texttt{both},
4899 \texttt{large},
4900 \texttt{small},
4901 \texttt{pleft},
4902 \texttt{pright},
4903 \texttt{paverage}
4904 \end{quote}
4905 %<*en>
4906 The default value is \texttt{paverage}. \dots
4907 %</en>
4908 %<*ja>
4909 デフォルト値は \texttt{paverage} である.
4910 各々の値による差異の詳細は\ref{ssec-cluster-wa}節の「『右空白』の算出」を参照してほしい.
4911 %</ja>
4912
4913 \item[\DParam{jacharrange}\,=<ranges>]
4914 \item[\DParam{kansujichar}\,=\{<digit>, <chr\_code>\}$^\ast$] [\cs{kansujichar}]
4915
4916 \item[\DParam{direction}\,=<dir>\ \hbox{\rm (always local)}]\
4917
4918 %<*en>
4919 Assigning to this parameter has the same effect as
4920 \cs{yoko}~(if $\hbox{<dir>}=4$), \cs{tate}~(if $\hbox{<dir>}=3$),
4921 \cs{dtou}~(if $\hbox{<dir>}=1$) or \cs{utod}~(if $\hbox{<dir>}=11$).
4922 If the argument <dir> is not one of 4,~3, 1~nor~11,
4923 the behavior of this assignment is undefined.
4924 %</en>
4925 %<*ja>
4926 組方向を変更する \cs{yoko}~(if $\hbox{<dir>}=4$), \cs{tate}~(if $\hbox{<dir>}=3$),
4927 \cs{dtou}~(if $\hbox{<dir>}=1$), \cs{utod}~(if $\hbox{<dir>}=11$) と同じ役割を持つ.
4928 利用可能な状況もこれら4命令と同一である.引数<dir>が4,~3, 1,~11のいずれでも無いときの
4929 動作は未定義である.
4930 %</ja>
4931
4932 \end{cslist}
4933
4934 \subsection{\cs{ltjgetparameter}}
4935 \label{ssec-getpar}
4936 %<*en>
4937 \cs{ltjgetparameter} is a control sequence for acquiring parameters. It
4938 always takes a parameter name as first argument.
4939 %</en>
4940 %<*ja>
4941 \cs{ltjgetparameter} はパラメータの値を取得するための命令であり,
4942 常にパラメータの名前を第一引数にとる.
4943 %</ja>
4944 \begin{LTXexample}
4945 \ltjgetparameter{differentjfm},
4946 \ltjgetparameter{autospacing},
4947 \ltjgetparameter{kanjiskip},
4948 \ltjgetparameter{prebreakpenalty}{`)}.
4949 \end{LTXexample}
4950
4951 %<*en>
4952 \emph{The return value of\/ \cs{ltjgetparameter} is
4953 always a string}. This is outputted by \texttt{tex.write()}, so any
4954 character other than space~``\texttt{\char32}''~(\texttt{U+0020}) has the category code
4955 12~(other), while the space has 10~(space).
4956 %</en>
4957 %<*ja>
4958 \emph{\cs{ltjgetparameter} の戻り値は常に文字列である.}
4959 これは\texttt{tex.write()}によって出力しているためで,空白「\texttt{\char32}」
4960 (\texttt{U+0020})を除いた文字のカテゴリーコードは全て12~(other)となる.
4961 一方,空白のカテゴリーコードは10~(space)である.
4962 %</ja>
4963
4964 \begin{itemize}
4965 \item
4966 %<*en>
4967 If first argument is one of the
4968 following, no  additional argument is needed.
4969 %</en>
4970 %<*ja>
4971 第1引数が次のいずれかの場合には,追加の引数は必要ない.
4972 %</ja>
4973 \begin{quote}
4974 \sffamily
4975 jcharwidowpenalty, yjabaselineshift, yalbaselineshift, autospacing, autoxspacing,\\
4976 kanjiskip, xkanjiskip, differentjfm, direction
4977 \end{quote}
4978 %<*en>
4979 Note that \verb+\ltjgetparameter{autospacing}+~and~\verb+\ltjgetparameter{autoxspacing}+
4980 returns 1 or 0, not
4981 \texttt{true}~nor~\texttt{false}.
4982 %</en>
4983 %<*ja>
4984 \verb+\ltjgetparameter{autospacing}+ と \verb+\ltjgetparameter{autoxspacing}+ は,
4985 \texttt{true}や\texttt{false}を返すの\emph{ではなく},
4986 1と0のいずれかを返すことに注意,
4987 %</ja>
4988
4989 \item
4990 %<*en>
4991 If first argument is one of the
4992 following, an additional argument---a character code, for example---is needed.
4993 %</en>
4994 %<*ja>
4995 第1引数が次のいずれかの場合には,さらに文字コードを第二引数としてとる.
4996 %</ja>
4997 \begin{quote}
4998 \sffamily
4999 kcatcode, prebreakpenalty, postbreakpenalty, jaxspmode, alxspmode
5000 \end{quote}
5001 %<*en>
5002 \verb+\ltjgetparameter{jaxspmode}{...}+~and~\verb+\ltjgetparameter{alxspmode}{...}+
5003 returns 0,~1, 2,~or~3, instead of \texttt{preonly} etc.
5004 %</en>
5005 %<*ja>
5006 \verb+\ltjgetparameter{jaxspmode}{...}+ や \verb+\ltjgetparameter{alxspmode}{...}+\
5007 は,\texttt{preonly} などといった文字列ではなく,0から3までの値を返す.
5008 %</ja>
5009
5010 \item
5011 %<*en>
5012 \verb+\ltjgetparameter{jacharrange}{+<range>\verb+}+ returns \texttt{0}
5013 if ``characters which belong to the character range~<range> are \textbf{JAchar}'',
5014 \texttt{1} if ``\dots~are \textbf{ALchar}''.
5015 Although there is no character range~$-1$, specifying $-1$ to <range> does not cause an
5016       error (returns 1).
5017 %</en>
5018 %<*ja>
5019 \verb+\ltjgetparameter{jacharrange}{+<range>\verb+}+ は,<range>が\textbf{JAchar}達の
5020 範囲ならば0を,そうでなければ1を返す.「$-1$番の文字範囲」は存在しないが,<range>に$-1$を
5021 指定してもエラーは発生しない(1を返す).
5022 %</ja>
5023
5024 \item
5025 %<*en>
5026 For an integer~<digit> between 0~and~9,
5027      \verb+\ltjgetparameter{kansujichar}{+<digit>\verb+}+ returns the character code
5028 of the result of \cs{kansuji}<digit>.
5029 %</en>
5030 %<*ja>
5031 0--9の数<digit>に対して,
5032 \verb+\ltjgetparameter{kansujichar}{+<digit>\verb+}+ は,\cs{kansuji}<digit>で出力され
5033      る文字の文字コードを返す.
5034 %</ja>
5035
5036 \item
5037 %<*en>
5038 \verb+\ltjgetparameter{adjustdir}+ returns a integer which represents
5039 the direction of the surrounding vertical list.
5040 As \Param{direction}, the return value 1 means \emph{down-to-up} direction,
5041 3 means \emph{tate} direction (vertical typesetting),
5042 and 4 means \emph{yoko} direction (horizontal typesetting).
5043 %</en>
5044 %<*ja>
5045 \verb+\ltjgetparameter{adjustdir}+ は,周囲のvboxの組方向(言い換えれば,
5046 \cs{vadjust} で用いられる組方向)を表す数値を返す.
5047 \Param{direction}と同様に,1は \cs{dtou} 方向を,
5048 3は縦組みを,4は横組みを表す.
5049 %</ja>
5050
5051 \item
5052 %<*en>
5053 For an integer~<reg\_num> between 0~and~65535,
5054 \verb+\ltjgetparameter{boxdim}{+<reg\_num>\verb+}+ returns the direction of
5055 \cs{box}<reg\_num>. If this box register is void, the returned value is zero.
5056 %</en>
5057 %<*ja>
5058 0--65535の数<reg\_num>に対して,
5059 \verb+\ltjgetparameter{boxdim}{+<reg\_num>\verb+}+ は,\cs{box}<reg\_num>に
5060 格納されているボックスの組方向を表す.もしこのレジスタが空の場合は,0が返される.
5061 %</ja>
5062
5063 \item
5064 %<*en>
5065 The following parameter names \emph{cannot be specified} in \cs{ltjgetparameter}.
5066 %</en>
5067 %<*ja>
5068 次のパラメータ名を \cs{ltjgetparameter} に指定することはできない.
5069 %</ja>
5070 \begin{quote}
5071 \sffamily
5072 jatextfont, jascriptfont, jascriptscriptfont, jacharrange
5073 \end{quote}
5074
5075 \item
5076 %<*en>
5077 \verb+\ltjgetparameter{chartorange}{+<chr\_code>\verb+}+ returns
5078 the range number which <chr\_code> belongs to
5079 (although there is no parameter named ``chartorange'').
5080
5081 If <chr\_code> is between 0 and 127, this <chr\_code> does not belong to
5082 any character range. In this case,
5083       \verb+\ltjgetparameter{chartorange}{+<chr\_code>\verb+}+
5084 returns $-1$.
5085
5086 Hence, one can know whether <chr\_code> is \textbf{JAchar} or not
5087 by the following:
5088 %</en>
5089 %<*ja>
5090 \verb+\ltjgetparameter{chartorange}{+<chr\_code>\verb+}+ によって
5091 <chr\_code>の属する文字範囲の番号を知ることができる.
5092
5093 <chr\_code>に0--127の値を指定した場合(このとき,<chr\_code>が属する
5094 文字範囲は存在しない)は$-1$が返る.
5095
5096 そのため,<chr\_code>が\textbf{JAchar}か\textbf{ALchar}かは
5097 次で知ることができる:
5098 %</ja>
5099 \begin{quote}
5100 \ttfamily \verb+\ltjgetparameter{jacharrange}{\ltjgetparameter{chartorange}{+%
5101   <chr\_code>\verb+}}+\\\null\hfill\verb+% 0 if JAchar, 1 if ALchar+
5102 \end{quote}
5103
5104 \end{itemize}
5105
5106
5107
5108
5109 %<en>\section{Other Commands for plain \TeX\ and \LaTeXe}
5110 %<ja>\section{plainでも\LaTeX でも利用可能なその他の命令}
5111 %<en>\subsection{Commands for Compatibility with \pTeX}
5112 %<ja>\subsection{\pTeX 互換用命令}
5113
5114 %<*en>
5115 The following commands are implemented for compatibility with \pTeX.
5116 Note that the former five commands don't support JIS~X~0213, but only JIS~X~0208.
5117 The last \cs{kansuji} converts an integer into its Chinese numerals.
5118 %</en>
5119 %<*ja>
5120 以下の命令は\pTeX との互換性のために実装されている.そのため,JIS~X~0213には対応せず,
5121 \pTeX と同じようにJIS~X~0208の範囲しかサポートしていない.
5122 %</ja>
5123 \begin{center}
5124 \cs{kuten}, \cs{jis}, \cs{euc}, \cs{sjis}, \cs{jis}, \cs{kansuji}
5125 \end{center}
5126 %<*en>
5127 These six commands takes an internal integer, and returns a \emph{string}.
5128 %</en>
5129 %<*ja>
5130 これら6命令は内部整数を引数とするが,実行結果は\textbf{文字列}であることに注意.
5131 %</ja>
5132 \begin{LTXexample}
5133 \newcount\hoge
5134 \hoge="2423 %"
5135 \the\hoge, \kansuji\hoge\\
5136 \jis\hoge, \char\jis\hoge\\
5137 \kansuji1701
5138 \end{LTXexample}
5139
5140 %<*en>
5141 To change characters of Chinese numerals for each digit, set \Param{kansujichar} parameter:
5142 \begin{LTXexample}
5143 \ltjsetparameter{kansujichar={1,`壹}}
5144 \ltjsetparameter{kansujichar={7,`漆}}
5145 \ltjsetparameter{kansujichar={0,`零}}
5146 \kansuji1701
5147 \end{LTXexample}
5148 %</en>
5149
5150
5151 \subsection{\cs{inhibitglue}}
5152 %<*en>
5153 \cs{inhibitglue} suppresses the insertion of \textbf{JAglue}.
5154 The following is an example, using a special JFM that there will be a glue between
5155 the beginning of a box and ``あ'', and also between ``あ''~and~``ウ''.
5156 %</en>
5157 %<*ja>
5158 \cs{inhibitglue} は\textbf{JAglue}の挿入を抑制する.
5159 以下は,ボックスの始めと「あ」の間,「あ」「ウ」の間にグルーが入る特別なJFMを用いた例で
5160 ある.
5161 %</ja>
5162
5163 \begin{LTXexample}[width=0.4\textwidth]
5164 \jfont\g=file:KozMinPr6N-Regular.otf:jfm=test \g
5165 \fbox{\hbox{あウあ\inhibitglue ウ}}
5166 \inhibitglue\par\noindent あ1
5167 \par\inhibitglue\noindent あ2
5168 \par\noindent\inhibitglue あ3
5169 \par\hrule\noindent あoff\inhibitglue ice
5170 \end{LTXexample}
5171
5172 %<*en>
5173 With the help of this example, we remark the specification of \cs{inhibitglue}:
5174 %</en>
5175 %<*ja>
5176 この例を援用して,\cs{inhibitglue} の仕様について述べる.
5177 %</ja>
5178 \begin{itemize}
5179 %<*en>
5180 \item The call of \cs{inhibitglue} in the (internal) vertical mode is
5181       simply ignored.
5182 %</en>
5183 %<*ja>
5184 \item \cs{inhibitglue} の垂直モード中での呼び出しは意味を持たない.
5185 4行目の入力で有効にならないのは,\cs{inhibitglue} の時点では垂直モードであり,
5186 \cs{noindent} の時点で水平モードになるからである.
5187 %</ja>
5188
5189 %<*en>
5190 \item The call of \cs{inhibitglue} in the (restricted) horizontal
5191       mode is only effective on the spot; does not get over boundary of
5192       paragraphs. Moreover, \cs{inhibitglue} cancels ligatures and
5193       kernings, as shown in the last line of above example.
5194 %</en>
5195 %<*ja>
5196 \item \cs{inhibitglue} の(制限された)水平モード中での呼び出しはその場でのみ
5197   有効であり,段落の境界を乗り越えない.
5198   さらに,\cs{inhibitglue} は上の例の最終行のように(欧文における)リガチャとカーニングを
5199   打ち消す.これは,\cs{inhibitglue} が内部的には「現在のリスト中にwhatsitノードを
5200   追加する」ことを行なっているからである.
5201 %</ja>
5202
5203 %<*en>
5204 \item The call of \cs{inhibitglue} in math mode is just ignored.
5205 %</en>
5206 %<*ja>
5207 \item \cs{inhibitglue} を数式モード中で呼び出した場合はただ無視される.
5208 %</ja>
5209
5210 %<*ja>
5211 \item \LaTeX で\LuaTeX-ja を使用する場合は,
5212 \cs{inhibitglue} の代わりとして \verb+\<+ を使うことができる.
5213 既に \verb+\<+ が定義されていた場合は,\LuaTeX-ja の読み込みで強制的に上書きされるので
5214 注意すること.
5215 %</ja>
5216 \end{itemize}
5217
5218
5219 \subsection{\cs{ltjdeclarealtfont}}
5220 \label{ssec-altfont}
5221 %<*en>
5222 Using \cs{ltjdeclarealtfont}, one can ``compose'' more than one Japanese fonts.
5223 This \cs{ltjdeclarealtfont} uses in the following form:
5224 \begin{quote}
5225 \ttfamily \textbackslash ltjdeclarealtfont<base\_font\_cs><alt\_font\_cs>{<range>}
5226 \end{quote}
5227 where  <base\_font\_cs>~and~<alt\_font\_cs> are defined by \cs{jfont}.
5228 Its meaning is
5229 \begin{quote}
5230 If the current Japanese font is <base\_font\_cs>, characters which belong to <range>
5231 is typeset by another Japanese font <alt\_font\_cs>, instead of <base\_font\_cs>.
5232 \end{quote}
5233
5234 <range> is a comma-separated list of character codes, but also accepts negative integers:
5235 $-n$~($n≥1$) means that all characters of character classes~$n$, with respect to JFM used
5236 by <base\_font\_cs>. Note that characters which do not exist in <alt\_font\_cs> are
5237 ignored.
5238
5239 For example, if \cs{hoge} uses \texttt{jfm-ujis.lua}, the standard JFM of \LuaTeX-ja,
5240 then
5241 \begin{lstlisting}
5242 \ltjdeclarealtfont\hoge\piyo{"3000-"30FF, {-1}-{-1}}
5243 \end{lstlisting}
5244 does
5245 \begin{quote}
5246 If the current Japanese font is \cs{hoge}, \texttt{U+3000}--\texttt{U+30FF}
5247 and characters in class~1 (ideographic opening brackets)
5248 are typeset by \cs{piyo}.
5249 \end{quote}
5250 %</en>
5251 %<*ja>
5252 \cs{jfont} の書式を見ればわかるように,基本的には\LuaTeX-jaにおける1つの和文フォントに
5253 使用出来る「実際のフォント」は1つである.
5254 しかし,\cs{ltjdeclarealtfont} を用いると,この原則から外れることができる.
5255
5256 \cs{ltjdeclarealtfont} は以下の書式で使用する:
5257 \begin{quote}
5258 \ttfamily \textbackslash ltjdeclarealtfont<base\_font\_cs><alt\_font\_cs>{<range>}
5259 \end{quote}
5260 これは「現在の和文フォント」が<base\_font\_cs>であるとき,
5261 <range>に属する文字は<alt\_font\_cs>を用いて組版される,という意味である.
5262 \begin{itemize}
5263  \item <base\_font\_cs>, <alt\_font\_cs>は
5264 \cs{jfont} によって定義された和文フォントである.
5265  \item <range>は文字コードの範囲を表すコンマ区切りのリストであるが,
5266    例外として負数$-n$は「<base\_font\_cs>のJFMの文字クラス$n$に属する全ての文字」
5267    を意味する.
5268
5269 <range>中に<alt\_font\_cs>中に実際には存在しない文字が指定された場合は,
5270 その文字に対する設定は無視される.
5271 \end{itemize}
5272
5273 例えば,\cs{hoge} のJFMが\LuaTeX-ja標準の
5274 \ \texttt{jfm-ujis.lua} であった場合,
5275 \begin{lstlisting}
5276 \ltjdeclarealtfont\hoge\piyo{"3000-"30FF, {-1}-{-1}}
5277 \end{lstlisting}
5278 は「\cs{hoge} を利用しているとき,
5279 \texttt{U+3000}--\texttt{U+30FF}と
5280 文字クラス1(開き括弧類)中の文字だけは \cs{piyo} を用いる」
5281 ことを設定する.\verb+{-1}-{-1}+ という変わった指定の仕方をしているのは,
5282 普通に \texttt{-1} と指定したのでは正しく$-1$と読み取られないという
5283 マクロの都合による.
5284 %</ja>
5285
5286
5287
5288 %<en>\section{Commands for \LaTeXe}
5289 %<ja>\section{\LaTeXe 用の命令}
5290
5291 %<en>\subsection{Patch for NFSS2}
5292 %<ja>\subsection{NFSS2へのパッチ}
5293 \label{ssec-nfsspat}
5294
5295 %<*en>
5296 Japanese patch for NFSS2 in \LuaTeX-ja
5297 is based on \texttt{plfonts.dtx} which plays the same role in \pLaTeXe.
5298 We will describe
5299 commands which are not described in Subsection~\ref{ssec-chgfnt}.
5300 %</en>
5301 %<*ja>
5302 \LuaTeX-jaのNFSS2への日本語パッチは
5303 \pLaTeXe で同様の役割を果たす \texttt{plfonts.dtx} をベースに,
5304 和文エンコーディングの管理等をLuaで書きなおしたものである.
5305 ここでは\ref{ssec-chgfnt}節で述べていなかった命令について
5306 記述しておく.
5307 %</ja>
5308
5309 \begin{cslist}%
5310 \item[\normalfont\bfseries %
5311 %<ja>追加の長さ変数達
5312 %<en>additonal dimensions
5313 ]
5314 %<*en>
5315 Like \pLaTeXe, \LuaTeX-ja defines the following dimensions
5316 for information of current Japanese font:
5317 %</en>
5318 %<*ja>
5319 \pLaTeXe と同様に,\LuaTeX-jaは「現在の和文フォントの情報」を格納する長さ変数
5320 %</ja>
5321 \begin{quote}
5322  \cs{cht}~(height), \cs{cdp}~(depth), \cs{cHT}~(sum of former two),\\
5323  \cs{cwd}~(width), \cs{cvs}~(lineskip), \cs{chs}~(equals to \cs{cwd})
5324 \end{quote}
5325 %<en>and its \cs{normalsize} version:
5326 %<ja>と,その \cs{normalsize} 版である
5327 \begin{quote}
5328  \cs{Cht}~(height), \cs{Cdp}~(depth),
5329  \cs{Cwd}~(width), \\\cs{Cvs}~(equals to \cs{baselineskip}),
5330  \cs{Chs}~(equals to \cs{cwd})%
5331 %<en>.
5332 \end{quote}
5333 %<*ja>
5334 を定義している.なお,\cs{cwd} と \cs{zw},また
5335 \cs{cHT} と \cs{zh} は一致しない可能性がある.なぜなら,
5336 \cs{cwd},~\cs{cHT} は「あ」の寸法から決定されるのに対し,
5337 \cs{zw} と \cs{zh} はJFMに指定された値に過ぎないからである.
5338 %</ja>
5339 %<*en>
5340 Note that \cs{cwd}~and~\cs{cHT} may  differ from \cs{zw}~and~\cs{zh}
5341 respectively.
5342 On the one hand the former dimensions are determined from the character ``あ'',
5343 but on the other hand \cs{zw}~and~\cs{zh} are specified by JFM.
5344 %</en>
5345
5346
5347 \item[\cs{DeclareYokoKanjiEncoding}\{<encoding>\}\{<text-settings>\}\{<math-settings>\}]
5348 %<en>\ \\[\dimexpr-\medskipamount-2\baselineskip\relax]
5349 %<ja>\ \\[\dimexpr-2\baselineskip\relax]
5350 \item[\cs{DeclareTateKanjiEncoding}\{<encoding>\}\{<text-settings>\}\{<math-settings>\}]
5351
5352 %<*en>
5353 In NFSS2 under \LuaTeX-ja, distinction between alphabetic font families
5354              and Japanese font families are only made by their
5355              encodings. For example, encodings OT1 and T1 are for
5356              alphabetic font families, and a Japanese font family cannot
5357              have these encodings. These command define a new encoding
5358              scheme for Japanese font families.
5359 %</en>
5360 %<*ja>
5361 \LuaTeX-jaのNFSS2においては,欧文フォントファミリと和文フォントファミリは
5362 そのエンコーディングによってのみ区別される.
5363 例えば,OT1とT1のエンコーディングは欧文フォントファミリに対するものであり,
5364 和文フォントファミリはこれらのエンコーディングを持つことはできない.
5365 これらコマンドは横組用・縦組用和文フォントのための新しいエンコーディングを
5366 それぞれ定義する.
5367 %</ja>
5368
5369 \item[\cs{DeclareKanjiEncodingDefaults}\{<text-settings>\}\{<math-settings>\}]
5370 %<en>\ \\[\dimexpr-\medskipamount-2\baselineskip\relax]
5371 %<ja>\ \\[\dimexpr-2\baselineskip\relax]
5372 \item[\cs{DeclareKanjiSubstitution}\{<encoding>\}\{<family>\}\{<series>\}\{<shape>\}]
5373 %<en>\ \\[\dimexpr-\medskipamount-2\baselineskip\relax]
5374 %<ja>\ \\[\dimexpr-2\baselineskip\relax]
5375 \item[\cs{DeclareErrorKanjiFont}\{<encoding>\}\{<family>\}\{<series>\}\{<shape>\}\{<size>\}]
5376
5377 %<*en>
5378 The above 3~commands are just the counterparts for \cs{DeclareFontEncodingDefaults} and~others.
5379 %</en>
5380 %<*ja>
5381 上記3つのコマンドはちょうど \cs{DeclareFontEncodingDefaults} などに対応するものである.
5382 %</ja>
5383
5384 \item[\cs{reDeclareMathAlphabet}\{<unified-cmd>\}\{<al-cmd>\}\{<ja-cmd>\}]
5385
5386 % ToDo: en
5387 %<*ja>
5388 和文・欧文の数式用フォントファミリを一度に変更する命令を作成する.
5389 具体的には,欧文数式用フォントファミリ変更の命令<al-cmd>(\cs{mathrm} 等)と,和文数式用フォ
5390              ントファミリ変更の命令<ja-cmd>(\cs{mathmc} 等)の2つを同時に行う命令として
5391              <unified-cmd>を(再)定義する.実際の使用では<unified-cmd>と
5392              <al-cmd>に同じものを指定する,すなわち,<al-cmd>で和文側も変
5393              更させるようにするのが一般的と思われる.
5394
5395 本命令は
5396 \begin{center}\tt
5397 <unified-cmd>\{<arg>\}\quad$\longrightarrow$\quad
5398 (<al-cmd>の1段展開結果)\{<ja-cmd>の1段展開結果)\{<arg>\}\}
5399 \end{center}
5400 と定義を行うので,使用には注意が必要である:
5401 %<en>\vspace{-\medskipamount}
5402 \begin{itemize}
5403 \item <al-cmd>,~<ja-cmd>は既に定義されていなければならない.
5404       \cs{reDeclareMathAlphabet}\\の後に
5405 両命令の内容を再定義しても,<unified-cmd>の内容にそれは反映されない.
5406 \item <al-cmd>,~<ja-cmd>に\verb+\@mathrm+などと \texttt{@} をつけた命令を指定した時の動作は保証できない.
5407 \end{itemize}
5408 %</ja>
5409
5410 \item[\cs{DeclareRelationFont}\{<ja-encoding>\}\{<ja-family>\}\{<ja-series>\}\{<ja-shape>\}\\*
5411   \null\hfill\{<al-encoding>\}\{<al-family>\}\{<al-series>\}\{<al-shape>\}]
5412 %<*en>
5413 This command sets the ``accompanied'' alphabetic font family (given by the latter 4~arguments)
5414 with respect to a Japanese font family given by the former 4~arguments.
5415 %</en>
5416 %<*ja>
5417 いわゆる「従属欧文」を設定するための命令である.前半の4引数で表される和文フォントファミリに対して,
5418 そのフォントに対応する「従属欧文」のフォントファミリを後半の4引数により与える.
5419 %</ja>
5420 \item[\cs{SetRelationFont}]
5421 %<*en>
5422 This command is almost same as \cs{DeclareRelationFont}, except that this command does a local
5423 assignment, where \cs{DeclareRelationFont} does a global assignment.
5424 %</en>
5425 %<*ja>
5426 このコマンドは \cs{DeclareRelationFont} とローカルな指定であることを除いて
5427 ほとんど同じである(\cs{DeclareRelationFont} はグローバル).
5428 %</ja>
5429
5430 \item[\cs{userelfont}]
5431 %<*en>
5432 Change current alphabetic font encoding/family/\dots\ to the `accompanied' alphabetic
5433              font family with respect to current Japanese font family,
5434              which was set by
5435              \cs{DeclareRelationFont} or \cs{SetRelationFont}.
5436 Like \cs{fontfamily}, \cs{selectfont} is required to take an effect.
5437 %</en>
5438 %<*ja>
5439 現在の欧文フォントのエンコーディング/ファミリ/…… を,
5440 \cs{DeclareRelationFont} か \cs{SetRelationFont} で指定された
5441 現在の和文フォントファミリに対応する「従属欧文」フォントファミリに変更する.
5442 \cs{fontfamily} のように,有効にするためには \cs{selectfont} が必要である.
5443 %</ja>
5444
5445 \item[\cs{adjustbaseline}]
5446 %<*en>
5447 In \pLaTeXe, \cs{adjustbaseline} sets \cs{tbaselineshift}
5448 to match the vertical center of ``M'' and that of ``あ''  in vertical typesetting:
5449 \[
5450 \text{\cs{tbaselineshift}} \leftarrow
5451 \frac{(h_{\text{M}}+d_{\text{M}}) - (h_{\text{あ}}+d_{\text{あ}})}2
5452   + d_{\text{あ}} - d_{\text{M}},
5453 \]
5454 where $h_{a}$~and~$d_{a}$ denote the height of ``$a$'' and the depth, respectively.
5455 In \LuaTeX-ja, this \cs{adjustbaseline} does same task.
5456 %</en>
5457 %<*ja>
5458 \pLaTeXe では,\cs{adjustbaseline} は縦組時に「M」と「あ」の中心線を一致させるために,
5459 \cs{tbaselineshift} を設定する役割を持っていた:
5460 \[
5461 \text{\cs{tbaselineshift}} \leftarrow
5462 \frac{(h_{\text{M}}+d_{\text{M}}) - (h_{\text{あ}}+d_{\text{あ}})}2
5463   + d_{\text{あ}} - d_{\text{M}},
5464 \]
5465 ここで,$h_{a}$,~$d_{a}$はそれぞれ「$a$」の高さ・深さを表す.
5466 \LuaTeX-jaにおいても\cs{adjustbaseline} は同様の処理を行っている.
5467 %</ja>
5468
5469 \item[\cs{fontfamily}\{<family>\}]
5470 %<*en>
5471 As in \LaTeXe, this command changes current font family (alphabetic, Japanese,~\emph{or both})
5472 to <family>. Which family will be changed is determined as follows:
5473 %</en>
5474 %<*ja>
5475 元々の\LaTeXe におけるものと同様に,このコマンドは現在のフォントファミリ(欧文,
5476 和文,\emph{もしくは両方})を<family>に変更する.
5477 どのファミリが変更されるかは以下のようにして決定される:
5478 %</ja>
5479 \begin{itemize}
5480 %<*en>
5481 \item Let current encoding scheme for Japanese fonts be
5482       <ja-enc>. Current Japanese font family will be changed to
5483       <family>, if one of the following two conditions is met:
5484 %</en>
5485 %<*ja>
5486 \item 現在の和文フォントに対するエンコーディングが<ja-enc>であるとしよう.
5487   現在の和文フォントファミリは,以下の2つの条件のうちの1つが満たされているときに
5488   <family>に変更される:
5489 %</ja>
5490 \begin{itemize}
5491 %<*en>
5492 \item The family <family> under the encoding <ja-enc> has been already defined by
5493       \cs{DeclareKanijFamily}.
5494 %</en>
5495 %<*ja>
5496 \item エンコーディング<ja-enc>におけるファミリ<family>が
5497 既に \cs{DeclareKanjiFamily} によって定義されている.
5498 %</ja>
5499 %<*en>
5500 \item A font definition named \texttt{<ja-enc><family>.fd} (the file name is
5501       all lowercase) exists.
5502 %</en>
5503 %<*ja>
5504 \item フォント定義ファイル\texttt{<ja-enc><family>.fd}(ファイル名は全て小文字)が存在する.
5505 %</ja>
5506 \end{itemize}
5507 %<*en>
5508 \item Let current encoding scheme for alphabetic fonts be
5509       <al-enc>. For alphabetic font family, the criterion as above is used.
5510 %</en>
5511 %<*ja>
5512 \item 現在の欧文フォントに対するエンコーディングを<al-enc>とする.
5513   欧文フォントファミリに対しても,上記の基準が用いられる.
5514 %</ja>
5515 %<*en>
5516 \item There is a case which none of the above applies, that is, the font
5517       family named <family> doesn't seem to be defined neither under the
5518       encoding <ja-enc>, nor under <al-enc>.
5519 In this case, the default family for font substitution is used for
5520       alphabetic and Japanese fonts. Note that current encoding will not
5521       be set to <family>, unlike the original implementation in \LaTeX.
5522 %</en>
5523 %<*ja>
5524 \item 上記のいずれもが適用されない,つまり<family>が<ja-enc>と<al-enc>の
5525   どちらでも定義されないような場合がある.
5526   この場合,代替フォントに用いられるデフォルトのフォントファミリが欧文フォントと
5527   和文フォントに用いられる.\LaTeX のオリジナルの実装とは異なり,
5528   現在のエンコーディングは<family>には設定されないことに注意する.
5529 %</ja>
5530 \end{itemize}%
5531 %<en>\vspace{-\medskipamount}
5532
5533
5534 \begin{figure}[!tb]
5535 \begin{LTXexample}[pos=b]
5536 \DeclareKanjiFamily{JY3}{edm}{}
5537 \DeclareFontShape{JY3}{edm}{m}{n}    {<-> s*KozMinPr6N-Regular:jfm=ujis;}{}
5538 \DeclareFontShape{JY3}{edm}{m}{green}{<-> s*KozMinPr6N-Regular:jfm=ujis;color=007F00}{}
5539 \DeclareFontShape{JY3}{edm}{m}{blue} {<-> s*KozMinPr6N-Regular:jfm=ujis;color=0000FF}{}
5540 \DeclareAlternateKanjiFont{JY3}{edm}{m}{n}{JY3}{edm}{m}{green}{"4E00-"67FF,{-2}-{-2}}
5541 \DeclareAlternateKanjiFont{JY3}{edm}{m}{n}{JY3}{edm}{m}{blue}{ "6800-"9FFF}
5542 {\kanjifamily{edm}\selectfont
5543 日本国民は、正当に選挙された国会における代表者を通じて行動し、……}
5544 \end{LTXexample}
5545 %<ja>\caption{\cs{DeclareAlternateKanjiFont} の使用例}
5546 %<en>\caption{An example of \cs{DeclareAlternateKanjiFont}}
5547 \label{fig:altkanji}
5548 \end{figure}
5549
5550 \item[\cs{DeclareAlternateKanjiFont}\{<base-encoding>\}\{<base-family>\}\{<base-series>\}\{<base-shape>\}\\
5551   \null\hfill\{<alt-encoding>\}\{<alt-family>\}\{<alt-series>\}\{<alt-shape>\}\{<range>\}]
5552 %<*ja>
5553 \ref{ssec-altfont}節の\
5554 \cs{ltjdeclarealtfont} と同様に,前半の4引数の
5555 和文フォント(基底フォント)のうち<range>中の文字を
5556 第5から第8引数の和文フォントを使って組むように指示する.
5557 使用例を図\nobreak\ref{fig:altkanji}に載せた.
5558
5559 \begin{itemize}
5560  \item
5561 \cs{ltjdeclarealtfont} では基底フォント・置き換え先和文フォントはあらかじめ定義されてい
5562              ないといけない(その代わり即時発効)であったが,
5563 \cs{DeclareAlternateKanjiFont} の設定が
5564 実際に効力が発揮するのは,書体変更やサイズ変更を行った時,
5565 あるいは(これらを含むが)\cs{selectfont} が実行された時である.
5566  \item
5567 段落やhboxの最後での設定値が段落/hbox全体にわたって通用する点や,
5568 <range>に負数$-n$を指定した場合,それが「基底フォントの文字クラス$n$に属する文字全体」
5569 と解釈されるのは \cs{ltjdeclarealtfont} と同じである.
5570 \end{itemize}%
5571 %</ja>
5572 %<*en>
5573 As \cs{ltjdeclarealtfont}~(Subsection~\ref{ssec-altfont}),
5574 characters in <range> of the Japanese font (we say the \emph{base font})
5575 which specified by first 4 arguments are typeset
5576 by the Japanese font which specified by fifth to eighth arguments
5577 (we say the \emph{alternate font}).
5578 An example is shown in Figure~\ref{fig:altkanji}.
5579
5580 \begin{itemize}
5581  \item
5582 In \cs{ltjdeclarealtfont}, the base font and the alternate font must be already defined.
5583 But this \cs{DeclareAlternateKanjiFont} is not so.
5584 In other words, \cs{DeclareAlternateKanjiFont} is effective only after
5585 current Japanese font is changed, or only after \cs{selectfont} is executed.
5586  \item \dots
5587 \end{itemize}%
5588 \vspace{-\medskipamount}
5589 %</en>
5590 \end{cslist}
5591
5592 %<*en>
5593 As closing this subsection, we shall introduce an example of
5594 \cs{SetRelationFont} and \cs{userelfont}:
5595 %</en>
5596 %<*ja>
5597 この節の終わりに,\cs{SetRelationFont} と \cs{userelfont} の例を
5598 紹介しておこう.\cs{userelfont} の使用によって,「abc」の部分のフォントが
5599 Avant Garde (OT1/pag/m/n) に変わっていることがわかる.
5600 %</ja>
5601 \begin{LTXexample}[width=0.3\textwidth]
5602 \makeatletter
5603 \SetRelationFont{JY3}{\k@family}{m}{n}{OT1}{pag}{m}{n}
5604   % \k@family: current Japanese font family
5605 \userelfont\selectfont あいうabc
5606 \end{LTXexample}
5607
5608 %<*en>
5609 \section{Addons}
5610 \LuaTeX-ja has several addon packages.
5611 These addons are written as \LaTeX\ packages, but
5612 \Pkg{luatexja-otf} and~\Pkg{luatexja-adjust} can be loaded in plain \LuaTeX\
5613 by \cs{input}.
5614 %</en>
5615 %<*ja>
5616 \section{拡張}
5617 \LuaTeX-jaには(動作には必須ではないが)自由に読み込める拡張が付属している.
5618 これらは\LaTeX のパッケージとして制作しているが,
5619 \Pkg{luatexja-otf}と\Pkg{luatexja-adjust}についてはplain \LuaTeX でも\
5620 \cs{input} で読み込み可能である.
5621 %</ja>
5622 \subsection{\texttt{luatexja-fontspec.sty}}
5623 \label{ssec-fontspec2}
5624 %<*en>
5625 As described in Subsection~\ref{ssec-fontspec}, this optional package
5626 provides the counterparts for several commands defined in the
5627 \Pkg{fontspec} package (requires \Pkg{fontspec}~v2.4).
5628 In addition to OpenType font features in the original \Pkg{fontspec},
5629 the following ``font features'' specifications are allowed for
5630 the commands of Japanese version:
5631 %</en>
5632 %<*ja>
5633 \ref{ssec-fontspec}節で述べたように,この追加パッケージは\Pkg{fontspec}
5634 パッケージで定義されているコマンドに対応する和文フォント用のコマンドを提供する.
5635 \emph{以下に述べる和文版の命令の説明は \Pkg{fontspec}~v2.4 使用時にのみ当てはまる.}
5636
5637 \Pkg{fontspec}パッケージで指定可能な各種font featureに加えて,和文版のコマンドには
5638 以下の``font feature''を指定することができる:
5639 %</ja>
5640
5641
5642 \begin{cslist}
5643 \item[CID=<name>\textrm{, }JFM=<name>\textrm{, }JFM-var=<name>]
5644
5645 %<*en>
5646 These 3 keys correspond to \texttt{cid}, \texttt{jfm} and
5647 \texttt{jfmvar} keys for \cs{jfont}~and~\cs{tfont} respectively.
5648 See Subsections~\ref{ssec-jfont} and \ref{ssec-psft} for details
5649  of \texttt{cid}, \texttt{jfm} and
5650 \texttt{jfmvar} keys.
5651
5652 The \texttt{CID} key is effective only when with \texttt{NoEmbed}
5653 described below. The same JFM cannot be used in both horizontal Japanese fonts and
5654              vertical Japanese fonts, hence the \texttt{JFM} key
5655 will be actually used in \texttt{YokoFeatures}~and~\texttt{TateFeatures} keys.
5656 %</en>
5657 %<*ja>
5658 これら3つのキーはそれぞれ \cs{jfont},~\cs{tfont}に対する
5659 \texttt{cid}, \texttt{jfm}, \texttt{jfmvar}キーとそれぞれ対応する.
5660 \texttt{cid}, \texttt{jfm}, \texttt{jfmvar}キーの詳細は\ref{ssec-jfont}節
5661              と\ref{ssec-psft}節を参照.
5662
5663 \texttt{CID} キーは下の \texttt{NoEmbed} と合わせて用いられたときのみ有効である.
5664 また,横組用JFMと縦組用JFMは共用できないため,実際に \texttt{JFM} キーを用いる際は
5665 後に述べる\ \texttt{YokoFeatures} キーや \texttt{TateFeatures}\ の中で用いる
5666 ことになる.
5667 %</ja>
5668
5669 \item[NoEmbed]
5670 %<*en>
5671 By specifying this key, one can use ``name-only'' Japanese font which
5672 will not be embedded in the output PDF file. See Subsection~\ref{ssec-psft}.
5673 %</en>
5674 %<*ja>
5675 これを指定することで,PDFに埋め込まれない「名前だけ」のフォントを指定することが
5676 できる.\ref{ssec-psft}節を参照.
5677 %</ja>
5678
5679 \begin{figure}[!tb]
5680 \begin{LTXexample}
5681 \jfontspec[
5682   YokoFeatures={Color=007F00},
5683   TateFeatures={Color=00007F},
5684   TateFont=KozGoPr6N-Regular
5685 ]{KozMinPr6N-Regular}
5686 \hbox{\yoko 横組のテスト}
5687 \hbox{\tate 縦組のテスト}
5688 \end{LTXexample}
5689 %<ja>\caption{\texttt{TateFeatures} 等の使用例}
5690 %<en>\caption{An example of \texttt{TateFeatures} etc.}
5691 \label{fig:yokotate-fontspec}
5692 \end{figure}
5693
5694
5695 \item[TateFeatures=\{<features>\}\textrm{, }TateFont=<font>]
5696 %<en> ...
5697 %<*ja>
5698 縦組において使用されるフォントや,縦組においてのみ適用されるfeature達を
5699 指定する.使用例は図\ref{fig:yokotate-fontspec}参照.
5700 %</ja>
5701
5702 \item[YokoFeatures=\{<features>\}]
5703 %<en> ...
5704 %<*ja>
5705 横組においてのみ適用されるfeature達を
5706 指定する.使用例は図\ref{fig:yokotate-fontspec}参照.
5707 %</ja>
5708
5709
5710 \begin{figure}[!tb]
5711 \begin{LTXexample}[pos=b]
5712 \jfontspec[
5713   AltFont={
5714     {Range="4E00-"67FF, Color=007F00},
5715     {Range="6800-"9EFF, Color=0000FF},
5716     {Range="3040-"306F, Font=KozGoPr6N-Regular},
5717   }
5718 ]{KozMinPr6N-Regular}
5719 日本国民は、正当に選挙された国会における代表者を通じて行動し、われらとわれらの子孫のために、
5720 諸国民との協和による成果と、わが国全土にわたつて自由のもたらす恵沢を確保し、……
5721 \end{LTXexample}
5722 %<ja>\caption{\texttt{AltFont} の使用例}
5723 %<en>\caption{An example of \texttt{AltFont}}
5724 \label{fig:altkanji-fontspec}
5725 \end{figure}
5726
5727 \item[AltFont]
5728
5729 %<*en>
5730 As \cs{ltjdeclarealtfont}~(Subsection~\ref{ssec-altfont}) and
5731 \cs{DeclareAlternateKanjiFont}~(Subsection~\ref{ssec-nfsspat}),
5732 with this key, one can typeset some Japanese characters
5733 by a different font and/or using different features.
5734 The \texttt{AltFont} feature takes a comma-separated list of comma-separated lists,
5735 as the following:
5736 %</en>
5737 %<*ja>
5738 \ref{ssec-altfont}節の \cs{ltjdeclarealtfont} や,
5739 \ref{ssec-nfsspat}節の \cs{DeclareAlternateKanjiFont} と同様に,
5740 このキーを用いると一部の文字を異なったフォントやfont featureを使って組むことができる.
5741 \texttt{AltFont} キーに指定する値は,次のように二重のコンマ区切りリストである:
5742 %</ja>
5743 \begin{lstlisting}[escapechar=\#]
5744 AltFont = {
5745   ...
5746   { Range=#\LARG range>#, #\LARG features>#},
5747   { Range=#\LARG range>#, Font=#\LARG font~name>#, #\LARG features># },
5748   { Range=#\LARG range>#, Font=#\LARG font~name># },
5749   ...
5750 }
5751 \end{lstlisting}
5752 %<*en>
5753 Each sublist should have the \texttt{Range} key
5754 (sublist which does not contain \texttt{Range} key is simply ignored).
5755 A demonstrarion is shown in Figure~\ref{fig:altkanji-fontspec}.
5756 %</en>
5757 %<*ja>
5758 各部分リストには \texttt{Range} キーが必須である(含まれない部分リストは
5759 単純に無視される).指定例は図\ref{fig:altkanji-fontspec}に示した.
5760 %</ja>
5761 \end{cslist}
5762
5763 %<*ja>
5764 なお,\Pkg{luatexja-fontspec} 読み込み時には和文フォント定義ファイル%
5765 \texttt{<ja-enc><family>.fd}は全く参照されなくなる.
5766 %</ja>
5767
5768
5769 %<*en>
5770 \paragraph{Remark on \texttt{AltFont}, \texttt{YokoFeatures}, \texttt{TateFeatures} keys}
5771 In \texttt{AltFont},~\texttt{YokoFeatures},~\texttt{TateFeatures} keys,
5772 one cannot specify per-shape settings such as \texttt{BoldFeatures}.
5773 For example,
5774 \begin{lstlisting}
5775 AltFont = {
5776   { Font=HogeraMin-Light, BoldFont=HogeraMin-Bold,
5777     Range="3000-"30FF, BoldFeatures={Color=007F00} }
5778 }
5779 \end{lstlisting}
5780 does \emph{not} work. Instead, one have to write
5781 \begin{lstlisting}
5782 UprightFeatures = {
5783   AltFont = { { Font=HogeraMin-Light, Range="3000-"30FF, } },
5784 },
5785 BoldFeatures = {
5786   AltFont =  { { Font=HogeraMin-Bold, Range="3000-"30FF, Color=007F00 } },
5787 }
5788 \end{lstlisting}
5789
5790 On the other hand, \texttt{YokoFeatures}, \texttt{TateFeatures} and  \texttt{TateFont}
5791 keys can be specified in each list in the \texttt{AltFont} key. Also,
5792 one can specify \texttt{AltFont} inside \texttt{YokoFeatures},~\texttt{TateFeatures}.
5793 %</en>
5794 %<*ja>
5795 \paragraph{\texttt{AltFont}, \texttt{YokoFeatures}, \texttt{TateFeatures} 等の制限}
5796 \texttt{AltFont},~\texttt{YokoFeatures},~\texttt{TateFeatures}の各キーは
5797 シェイプ別に指定されるべきものであり,
5798 内部では \texttt{BoldFeatures} などのシェイプ別の指定は行うことが出来ない.
5799 例えば.
5800 \begin{lstlisting}
5801 AltFont = {
5802   { Font=HogeraMin-Light, BoldFont=HogeraMin-Bold,
5803     Range="3000-"30FF, BoldFeatures={Color=007F00} }
5804 }
5805 \end{lstlisting}
5806 のように指定することは出来ず,
5807 \begin{lstlisting}
5808 UprightFeatures = {
5809   AltFont = { { Font=HogeraMin-Light, Range="3000-"30FF, } },
5810 },
5811 BoldFeatures = {
5812   AltFont =  { { Font=HogeraMin-Bold, Range="3000-"30FF, Color=007F00 } },
5813 }
5814 \end{lstlisting}
5815 のように指定しなければならない.
5816
5817 一方,\texttt{AltFont} キー内の各リストでは
5818 \ \texttt{YokoFeatures},~\texttt{TateFeatures} 及び \texttt{TateFont} キーを
5819 指定することは可能であり.また\ \texttt{YokoFeatures},~\texttt{TateFeatures} キーの
5820 中身に \texttt{AltFont} を指定することができる.
5821 %</ja>
5822
5823
5824 \subsection{\texttt{luatexja-otf.sty}}
5825 \label{ssec-ltjotf}
5826 %<*en>
5827 This optional package supports typesetting characters in
5828 Adobe-Japan1 character collection
5829 (or other CID character collection, if the font is supported).
5830 The package \Pkg{luatexja-otf} offers the following 2~low-level
5831 commands:
5832 %</en>
5833 %<*ja>
5834 この追加パッケージはAdobe-Japan1(フォント自身が持っていれば,
5835 別のCID文字セットでも可)の文字の出力をサポートする.
5836 \Pkg{luatexja-otf}は以下の2つの低レベルコマンドを提供する:
5837 %</ja>
5838 \begin{cslist}
5839 \item[\cs{CID}\{<number>\}]
5840 %<*en>
5841 Typeset a character whose CID number is <number>.
5842 %</en>
5843 %<*ja>
5844 CID番号が<number>の文字を出力する.
5845 %</ja>
5846
5847 \item[\cs{UTF}\{<hex\_number>\}]
5848 %<*en>
5849 Typeset a character whose character code is <hex\_number> (in hexadecimal).
5850 This command is similar to \verb+\char"+<hex\_number>,\ %"
5851 but please remind remarks below.
5852 %</en>
5853 %<*ja>
5854 文字コードが(16進で)<hex\_number>の文字を出力する.
5855 このコマンドは \verb+\char"+<hex\_number>と似ているが,下の記述に注意すること.%"
5856 %</ja>
5857 \end{cslist}
5858
5859 %<*ja>
5860 このパッケージは,\texttt{ajmacros.sty}(\Pkg{otf}パッケージ付属のマクロ集,井上浩一氏作)から
5861 漢字コードをUTF8にしたり,plain \LuaTeX でも利用可能にするという
5862 修正を加えた \texttt{luatexja-ajmacros.sty} も自動的に読み込む.
5863 そのため,\texttt{ajmacros.sty} マクロ集にある \verb+\aj半角+ などのマクロもそのまま使用可能である.
5864 %</ja>
5865
5866 %<en>\paragraph{Remarks}
5867 %<ja>\paragraph{注意}
5868 %<*en>
5869 Characters by \cs{CID} and \cs{UTF} commands are different from
5870 ordinary characters in the following points:
5871 %</en>
5872 %<*ja>
5873 \cs{CID} と \cs{UTF} コマンドによって出力される文字は
5874 以下の点で通常の文字と異なる:
5875 %</ja>
5876 \begin{itemize}
5877 %<*en>
5878 \item Always treated as \textbf{JAchar}s.
5879 %</en>
5880 %<*ja>
5881 \item 常に\textbf{JAchar}として扱われる.
5882 %</ja>
5883 %<*en>
5884 \item Processing codes for supporting OpenType features (\textit{e.g.},
5885       glyph replacement and kerning) by the \Pkg{luaotfload} package
5886       is not performed to these characters.
5887 %</en>
5888 %<*ja>
5889 \item OpenType feature(例えばグリフ置換やカーニング)をサポートするための
5890   \Pkg{luaotfload}パッケージのコードはこれらの文字には働かない.
5891 %</ja>
5892 \end{itemize}
5893
5894 %<en>\paragraph{Additional syntax of JFM}
5895 %<ja>\paragraph{JFMへの記法の追加}
5896
5897 %<*en>
5898 The package \Pkg{luatexja-otf} extends the syntax of JFM; the entries of \texttt{
5899 chars} table in JFM now allows a string in the form
5900 \verb+'AJ1-xxx'+, which stands for the character
5901 whose CID number in Adobe-Japan1 is \verb+xxx+.
5902
5903 This extended notation is used in the standard JFM \texttt{jfm-ujis.lua}
5904 to typeset halfwidth Hiragana glyphs (CID~516--598) in halfwidth.
5905 %</en>
5906 %<*ja>
5907 \Pkg{luatexja-otf}パッケージを読み込むと,
5908 JFMの\texttt{chars}テーブルのエントリとして \verb+'AJ1-xxx'+ の形の文字列が
5909 使えるようになる.これはAdobe-Japan1におけるCID番号が \verb+xxx+ の文字を表す.
5910
5911 この拡張記法は,標準JFM~\texttt{jfm-ujis.lua}で,半角ひらがなのグリフ(CID~516--598)を
5912 正しく半角幅で組むために利用されている.
5913 %</ja>
5914
5915 %<*en>
5916 \paragraph{IVS support}
5917 Recent fonts support Ideographic Variation Selector (IVS).
5918 It seems that \Pkg{luaotfload} and \Pkg{fontspec} packages do not support
5919 IVS, so we implemented IVS support in \Pkg{luatexja-otf}.
5920 \emph{IVS support is experimental; if you want to enable this, load
5921 \Pkg{luatexja-otf} and execute the following:}
5922 %</en>
5923 %<*ja>
5924 \paragraph{IVSサポート}
5925 最近のOpenTypeフォントやTrueTypeフォントには,
5926 \texttt{U+E0100}--\texttt{U+E01EF}の範囲の「文字」
5927 (漢字用異体字セレクタ)を後置することによって
5928 字形を指定する仕組み(IVS)が含まれている.
5929 執筆時点の2013年12月では,\Pkg{luaotfload}や\Pkg{fontspec}パッケージ類は
5930 IVSに対応してはいないようである.これらのパッケージで対応してくれるのが理想的だが,
5931 それまでのつなぎとして,\Pkg{luatexja-otf}パッケージ内にIVS対応を仕込んでおいた.
5932
5933 \medskip
5934
5935 \emph{IVS対応は試験的なものである.
5936 有効にするには,\Pkg{luatexja-otf}パッケージを読み込んだ上で以下の命令を実行する%
5937 \footnote{この命令を2回以上実行しても意味がない.}:}
5938 %</ja>
5939 \begin{lstlisting}
5940 \directlua{luatexja.otf.enable_ivs()}
5941 \end{lstlisting}
5942 %<ja> すると,上の命令を実行した箇所以降では,以下のようにIVSによる字形指定が有効となる.
5943 %<en> After executing the command above, you can use IVS like the following:
5944 \begin{LTXexample}
5945 \Large
5946 \jfontspec{KozMinPr6N-Regular}
5947 奈良県葛󠄀城市と,東京都葛󠄁飾区.\\
5948 こんにちは,渡
5949 邉󠄀邉󠄁邉󠄂邉󠄃邉󠄄
5950 邉󠄅邉󠄆邉󠄇邉󠄈邉󠄉
5951 邉󠄊邉󠄋邉󠄌邉󠄍邉󠄎
5952 さん.
5953 \end{LTXexample}
5954 %<*ja>
5955 左上側の入力においては,漢字用異体字セレクタを明示するため,
5956 例えばVariation~Selector~18 (\texttt{U+E0101})を\IVSB{18}のように表記している.
5957 %</ja>
5958 \medskip
5959
5960 %<*en>
5961 Specifying glyph variants by IVS precedes glyph replacement by font features.
5962 For example, only ``葛'' in ``葛西'' is changed by font features
5963 \texttt{jp78}~or~\texttt{jp90}, which does not followed by any variation selector.
5964 %</en>
5965 %<*ja>
5966 また,IVSによる字形指定は,font featureによるそれに優先されることとした.
5967 下の例において,\texttt{jp78}, \texttt{jp90} 指定で字形が変化した文字は
5968 異体字セレクタが続いていない「葛西」中の「葛」のみである.
5969 %</ja>
5970 \begin{LTXexample}
5971  \def\TEST#1{%
5972    {\jfontspec[#1]{KozMinPr6N-Regular}%
5973    葛󠄀城市,葛󠄁飾区,葛西}\\}
5974  指定なし:\TEST{}
5975  \texttt{jp78}:\TEST{CJKShape=JIS1978}
5976  \texttt{jp90}:\TEST{CJKShape=JIS1990}
5977 \end{LTXexample}
5978
5979 %<*ja>
5980 現状では,\TeX 側のインターフェースとなる \Pkg{luatexja-otf.sty} は一切変更していない
5981 ので,ZRさんによる\Pkg{PXipamjm}パッケージ%
5982 \footnote{\url{https://github.com/zr-tex8r/PXipamjm}. 説明は彼のブログ記事
5983 「pxipamjm パッケージの説明書のような何か(\url{http://d.hatena.ne.jp/zrbabbler/20131221})」
5984 にある.}
5985 にあるような気の利いた命令はまだない.
5986 異体字の一覧表示を行いたい場合は,gitリポジトリ内の \texttt{test/test19-ivs.tex} 中にある
5987 Lua・\TeX コードが参考になるだろう.
5988 %</ja>
5989
5990
5991 \subsection{\texttt{luatexja-adjust.sty}}
5992 \label{ssec-adj}
5993 \begin{figure}[t]
5994 \def\sq{%
5995   \hbox to 1\zw{\hss\fboxsep=-.5\fboxrule\fbox{%
5996    \hskip\dimexpr-.5\zw-.2pt\vrule width.4pt height.08\zw depth.12\zw%
5997   \hskip\dimexpr.5\zw-.2pt\relax}\hss}}
5998 \def\sb{\hbox to 1\zw{\hss\fboxsep=-.5\fboxrule\fbox{%
5999   ■\hskip\dimexpr-.5\zw-.2pt\vrule width.4pt height.08\zw depth.12\zw%
6000   \hskip\dimexpr.5\zw-.2pt\relax}\hss}}
6001 \newbox\gridbox
6002 \def\outbox#1{{\Large%
6003   \ltjsetparameter{kanjiskip=0pt plus .2\zw minus .2\zw}%
6004   \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}%
6005   \hbox{\textcolor{cyan}{\copy\gridbox}\hskip-20\zw%
6006   \vbox{\hsize=20\zw\noindent\leftskip0pt\rightskip0pt\parfillskip0pt#1}\vrule}%
6007 }}
6008
6009 {\centering
6010 \begin{tabular}{lc}
6011 \toprule
6012 no adjustment&\outbox{以上の原理は,「包除原理」とよく呼ばれるが\hskip-.5\zw\null}\\
6013 without priority&%
6014 \ltjdisableadjust
6015 \outbox{以上の原理は,「包除原理」とよく呼ばれるが}%
6016 \ltjenableadjust\\
6017 with priority&%
6018 \outbox{以上の原理は,「包除原理」とよく呼ばれるが}
6019 %<en>\ltjdisableadjust
6020 \\
6021 \bottomrule
6022 \end{tabular}\par}
6023 \smallskip
6024
6025 Note: the value of
6026 \Param{kanjiskip} is 0\,pt${}^{+1/5\,\mathrm{em}}_{-1/5\,\mathrm{em}}$ in this figure,
6027 for making the difference obvious.
6028 %<ja>\caption{行長調整}\label{fig-adj}
6029 %<en>\caption{Line adjustment}\label{fig-adj}
6030 \end{figure}
6031
6032
6033 %<*en>
6034 (see Japanese version of this manual)
6035 %</en>
6036 %<*ja>
6037 \pTeX では,行長調整において優先度の概念が存在しなかったため,図
6038 \ref{fig-adj}上段における半角分の半端は,図\ref{fig-adj}中段のように,鍵
6039 括弧周辺の空白と和文間空白(\Param{kanjiskip})の両方によって負担される.し
6040 かし,「日本語組版処理の要件」\cite{jlreq}やJIS~X~4051~\cite{x4051}におい
6041 ては,このような状況では半端は鍵括弧周辺の空白のみで負担し,その他の和文
6042 文字はベタ組で組まれる(図\ref{fig-adj}下段)ことになっている.この追加
6043 パッケージは\cite{jlreq}や\cite{x4051}における規定のような,優先順位付き
6044 の行長調整を提供する.詳細な仕様については\ref{sec-adjspec}章を参照してほしい.
6045 \begin{itemize}
6046  \item 優先度付き行長調整は,段落を行分割した後に個々の行について行われるものである.
6047 そのため,行分割の位置は変化することはない.
6048
6049 また,\verb+\hbox to ... {...}+ のような「幅が指定されたhbox」では無効である.
6050  \item 優先度付き行長調整を行うと,和文処理グルーの自然長は変化しないが,伸び量や縮み量は
6051 一般に変化する.そのため,既に組まれた段落を \cs{unhbox} などを利用して組み直す処理を
6052 行う場合には注意が必要である.
6053 \end{itemize}
6054
6055
6056 \Pkg{luatexja-adjust} は,以下の命令を提供する.これらはすべてグローバルに効力を発揮する.
6057
6058 \begin{cslist}
6059 \item[\cs{ltjdisableadjust}]
6060 優先順位付きの行長調整を無効化する.
6061
6062 \item[\cs{ltjenableadjust}]
6063 優先順位付きの行長調整を有効化する.
6064
6065 \item[\textsf{adjust}\,=<bool>] \cs{ltjsetparameter} で指定可能な追加パラメータであり,
6066 <bool>が\textit{true}なら \cs{ltjenableadjust} を,
6067 そうでなければ \cs{ltjdisableadjust} を実行する.
6068 \end{cslist}
6069 %</ja>
6070
6071 \subsection{\texttt{luatexja-ruby.sty}}
6072 %<*en>
6073 This addon package provides functionality of ``ruby'' (\emph{furigana}) annotations
6074 using callbacks of \LuaTeX-ja.
6075 There is no detailed manual of \Pkg{luatexja-ruby.sty} in English.
6076 (Japanese manual is another PDF file, \url{luatexja-ruby.pdf}.)
6077 %</en>
6078 %<*ja>
6079 この追加パッケージは,\LuaTeX-jaの機能を利用したルビ(振り仮名)の組版機能を提供する.
6080 前後の文字種に応じた前後への自動進入や,
6081 行頭形・行中形・行末形の自動的な使い分けが特徴である.
6082
6083 ルビ組版に設定可能な項目や注意事項が多いため,本追加パッケージの詳細な説明は
6084 使用例と共に \url{luatexja-ruby.pdf}\ という別ファイルに載せている.
6085 この節では簡単な使用方法のみ述べる.
6086 %</ja>
6087
6088 \begin{description}
6089 %<*en>
6090  \item[Group-ruby]
6091 By default, ruby characters (the second argument of \cs{ruby})
6092 are attached to base characters (the first argument), as one object.
6093 This type of ruby is called \emph{group-ruby}.
6094 %</en>
6095 %<*ja>
6096  \item[グループルビ] 標準ではグループルビの形で組まれる.第1引数に親文字,
6097 第2引数にルビを記述する.
6098 %</ja>
6099 \begin{LTXexample}[width=0.3\textwidth]
6100 東西線\ruby{妙典}{みようでん}駅は……\\
6101 東西線の\ruby{妙典}{みようでん}駅は……\\
6102 東西線の\ruby{妙典}{みようでん}という駅……\\
6103 東西線\ruby{葛西}{かさい}駅は……
6104 \end{LTXexample}
6105 %<*en>
6106 As the above example, ruby hangover is allowed on the Hiragana before/after
6107 its base characters.
6108 %</en>
6109 %<ja> この例のように,標準では前後の平仮名にルビ全角までかかるようになっている.
6110
6111 %<*en>
6112 \item[Mono-ruby]
6113 To attach ruby characters to each base characters (\emph{mono-ruby}),
6114 one should use \cs{ruby} multiple times:
6115 %</en>
6116 %<*ja>
6117  \item[モノルビ] 親文字を1文字にするとモノルビとなる.
6118 2文字以上の熟語をモノルビの形で組みたい場合は,面倒でも
6119 その数だけ \cs{ruby} を書く必要がある.
6120 %</ja>
6121 \begin{LTXexample}[width=0.3\textwidth]
6122 東西線の\ruby{妙}{みよう}\ruby{典}{でん}駅は……
6123 \end{LTXexample}
6124
6125 %<*en>
6126  \item[Jukugo-ruby]
6127 Vertical bar~\verb+|+ denotes a boundary of \emph{groups}.
6128 %</en>
6129 %<*ja>
6130  \item[熟語ルビ] 引数内の縦棒 \verb+|+ はグループの区切りを表し,
6131 複数グループのルビは熟語ルビとして組まれる.
6132 \cite{x4051}にあるように,
6133 どのグループでも「親文字」が対応するルビ以上の長さの場合は
6134 各グループごとに,そうでないときは全体をまとめて1つのグループルビとして組まれる.
6135 \cite{jlreq}で規定されている組み方とは異なるので注意.
6136 %</ja>
6137 \begin{LTXexample}
6138 \ruby{妙|典}{みよう|でん}\
6139 \ruby{葛|西}{か|さい}\
6140 \ruby{神楽|坂}{かぐら|ざか}
6141 \end{LTXexample}
6142 %<*en>
6143 If there are multiple groups in one \cs{ruby} call,
6144 A linebreak between two groups is allowed.
6145 %</en>
6146 %<ja> 複数ルビではグループとグループの間で改行が可能である.
6147 \begin{LTXexample}[width=0.3\textwidth]
6148 \vbox{\hsize=6\zw\noindent
6149   \hbox to 2.5\zw{}\ruby{京|急|蒲|田}{けい|きゆう|かま|た}
6150   \hbox to 2.5\zw{}\ruby{京|急|蒲|田}{けい|きゆう|かま|た}
6151   \hbox to   3\zw{}\ruby{京|急|蒲|田}{けい|きゆう|かま|た}
6152 }
6153 \end{LTXexample}
6154 \end{description}
6155
6156 %<*en>
6157 If the width of ruby characters are longer than that of base characters,
6158 \cs{ruby} automatically selects the appropriate form
6159 among the line-head form, the line-middle form, and the line-end form.
6160 %</en>
6161 %<*ja>
6162 また,ルビ文字のほうが親文字よりも長い場合は,自動的に
6163 行頭形・行中形・行末形のいずれか適切なものを選択する.
6164 %</ja>
6165 \begin{LTXexample}[width=0.3\textwidth]
6166 \vbox{\hsize=8\zw\noindent
6167 \null\kern3\zw ……を\ruby{承}{うけたまわ}る
6168      \kern1\zw ……を\ruby{承}{うけたまわ}る\\
6169 \null\kern5\zw ……を\ruby{承}{うけたまわ}る
6170 }
6171 \end{LTXexample}
6172
6173
6174 %<*ja>
6175 \subsection{\texttt{lltjext.sty}}
6176 \pLaTeX では縦組用の拡張として \Pkg{plext} パッケージが用意されていたが,
6177 それを\LuaTeX-ja用に書きなおしたものが本追加パッケージ \Pkg{lltjext} である.
6178
6179 従来の \Pkg{plext} パッケージとの違いは,
6180 {\catcode`\<=12
6181 \begin{itemize}
6182  \item 組方向オプション \texttt{<y>}(横組),\texttt{<t>}(縦組),
6183 \texttt{<z>}\ の他に\ \texttt{<d>}(dtou方向),\texttt{<u>}(utod方向)を追加した.
6184 \texttt{<z>} と \texttt{<u>} の違いは,\texttt{<z>} が(\Pkg{plext} パッケージと同様に)
6185 周囲の組方向が縦組のときにしか意味を持たない
6186        のに対し,\texttt{<u>} にはそのような制限がないことである.
6187
6188  \item \Pkg{plext} パッケージでは,表組(\texttt{tabular} 環境,\texttt{align} 環境等)や
6189 \texttt{minipage} 環境,\cs{parbox} 命令において,
6190 垂直位置指定 \texttt{[t]},~\texttt{[b]} の挙動が非読み込み時と微妙に変わることがあった.
6191
6192 \Pkg{lltjext} パッケージでは,垂直位置指定が\LaTeXe と同様の挙動(以下に示す)に
6193 なるように修正した.
6194 \begin{itemize}
6195  \item \texttt{[t]} オプション指定時は,ボックスのベースラインが中身の1行目のベースライン
6196        (1行目の上に罫線などが来た時は,ボックスの上端)に一致するように配置する.
6197  \item \texttt{[b]} オプション指定時は,ボックスのベースラインが中身の最終行のベースライン
6198        (中身の最後が罫線などの時は,ボックスの下端)に一致するように配置する.
6199  \item それ以外のときは,ボックスの中央が「数式の軸」に一致するように配置する.
6200 \end{itemize}
6201
6202  \item 連数字用命令 \cs{rensuji} における位置合わせオプション \texttt{[l]}, \texttt{[c]},
6203        \texttt{[r]} の挙動を若干変更した.
6204
6205 \end{itemize}
6206 }
6207 %</ja>
6208 %<*en>
6209 \subsection{\texttt{lltjext.sty}}
6210 \pLaTeX\ supplies additional macros for vertical writing in the \Pkg{plext} package.
6211 The \Pkg{lltjext} package which we want to describe here is the \LuaTeX-ja
6212 counterpart of the \Pkg{plext} package.
6213 %</en>
6214
6215 %<*ja>
6216 念の為,本 \Pkg{lltjext} パッケージで追加・変更している命令の一覧を載せておく.
6217 \begin{cslist}
6218 \item[tabular\textrm{, }array\textrm{, }minipage環境]
6219 これらの環境は,
6220 \begin{lstlisting}
6221 \begin{tabular}<dir>[pos]{table spec} ... \end{tabular}
6222 \begin{array}<dir>[pos]{table spec}   ... \end{array}
6223 \begin{minipage}<dir>[pos]{width}     ... \end{minipage}
6224 \end{lstlisting}
6225 のように,組方向オプション \texttt{\<dir\>} が拡張されている.
6226 既に述べたように,組方向オプションに指定できる値は以下の5つであり,
6227 それ以外を指定した時や無指定時は周囲の組方向と同じ組方向になる.
6228 \begin{description}
6229  \item[y] 横組(\cs{yoko})
6230  \item[t] 縦組(\cs{tate})
6231  \item[z] 周囲が縦組の時はutod方向,それ以外はそのまま
6232  \item[d] dtou方向
6233  \item[u] utod方向
6234 \end{description}
6235 \item[\cs{parbox}\<<dir>\>{[<pos>]}\{<width>\}\{<contents>\}]
6236 \cs{parbox} 命令も同様に,組方向の指定ができるように拡張されている.
6237
6238 \item[\cs{pbox}\<<dir>\>{[<width>][<pos>]}\{<contents>\}]
6239 組方向<dir>で<contents>の中身をLRモードで組む命令である.
6240 <width>が正の値であるときは,ボックス全体の幅がその値となる.
6241 その際,中身は<pos>の値に従い,左寄せ(\texttt{l}),右揃え(\texttt{r}),
6242 中央揃え(それ以外)される.
6243 \item[picture環境]
6244 図表作成に用いる \texttt{picture} 環境も,
6245 \begin{lstlisting}
6246 \begin{picture}<dir>(x_size, y_size)(x_offset,y_offset)
6247   ...
6248 \end{picture}
6249 \end{lstlisting}
6250 と組方向が指定できるように拡張されている.
6251 $x$成分の増加方向は字送り方向,$y$成分の増加方向は行送り方向の\emph{反対方向}となる.
6252 \Pkg{plext} パッケージと同様に
6253 内部ではベースライン補正(\Param{yalbaselineshift}パラメータなど)の影響を受けないように,
6254 \cs{put},~\cs{line}, \cs{vector}, \cs{dashbox}, \cs{oval},~\cs{circle}も
6255 ベースライン補正を受けないように再定義されている.
6256
6257 \item[\cs{rensuji}{[<pos>]}\{<contents>\}\textrm{, }\cs{rensujiskip}]
6258
6259 \item[\cs{Kanji}\{<counter\_name>\}]
6260
6261 \item[\cs{kasen}\{<contents>\}\textrm{, }\cs{bou}\{<contents>\}\textrm{,
6262                      }\cs{boutenchar}]
6263
6264 \item[参照番号]
6265 \end{cslist}
6266 %</ja>
6267 %<*en>
6268 \begin{cslist}
6269 \item[tabular\textrm{, }array\textrm{, }minipage\textrm{ environments}]
6270 These environments are extended by \texttt{\<dir\>}, which specifies the direction,
6271 as follows:
6272 \begin{lstlisting}
6273 \begin{tabular}<dir>[pos]{table spec} ... \end{tabular}
6274 \begin{array}<dir>[pos]{table spec}   ... \end{array}
6275 \begin{minipage}<dir>[pos]{width}     ... \end{minipage}
6276 \end{lstlisting}
6277 This option permits one of the following five values. If none of them is specified,
6278 the direction inside the environment is same as that outside the enviromnent.
6279 \begin{description}
6280  \item[y] \emph{yoko} direction (horizontal writing)
6281  \item[t] \emph{tate} direction (vertical writing)
6282  \item[z] \emph{utod} direction if direction outside the env.\ is \emph{tate}.
6283  \item[d] \emph{dtou} direction
6284  \item[u] \emph{utod} direction
6285 \end{description}
6286 \item[\cs{parbox}\<<dir>\>{[<pos>]}\{<width>\}\{<contents>\}]
6287 \cs{parbox} command is also extended by \texttt{\<dir\>}.
6288
6289 \item[\cs{pbox}\<<dir>\>{[<width>][<pos>]}\{<contents>\}]
6290 This commands typeset <contents> in LR-mode, in <dir> direction.
6291 If <width> is positive, the width of the box becomes this <width>.
6292 In this case, <contents> will be aligned \dots
6293
6294 \item[picture\textrm{environment}]
6295
6296 \item[\cs{rensuji}{[<pos>]}\{<contents>\}\textrm{, }\cs{rensujiskip}]
6297
6298 \item[\cs{Kanji}\{<counter\_name>\}]
6299
6300 \item[\cs{kasen}\{<contents>\}\textrm{, }\cs{bou}\{<contents>\}\textrm{,
6301                      }\cs{boutenchar}]
6302
6303 \item[参照番号]
6304 \end{cslist}
6305 %</en>
6306
6307
6308
6309 %<en>\part{Implementations}
6310 %<ja>\part{実装}
6311 \label{part-imp}
6312 %<en>\section{Storing Parameters}
6313 %<ja>\section{パラメータの保持}
6314 \label{sec-para}
6315 %<en>\subsection{Used Dimensions, Attributes and Whatsit Nodes}
6316 %<ja>\subsection{\LuaTeX-jaで用いられるレジスタとwhatsitノード}
6317
6318 %<*en>
6319 Here the following is the list of dimensions and attributes which are used in \LuaTeX-ja.
6320 %</en>
6321 %<*ja>
6322 以下は\LuaTeX-jaで用いられる寸法レジスタ(dimension),属性レジスタ(attribute)の
6323 リストである.
6324 %</ja>
6325 \begin{list}{}{%
6326 \def\makelabel{\ttfamily}\advance\leftmargin1\zw
6327 \def\dim#1{\item[\textbackslash #1\ \textrm{(dimension)}]}
6328 \def\cnt#1{\item[\textbackslash #1\ \textrm{(counter)}]}
6329 \def\attr#1{\item[\textbackslash #1\ \textrm{(attribute)}]}
6330 }
6331
6332 \dim{jQ}
6333 %<*en>
6334 \cs{jQ} is equal to
6335                         $1\,\textrm{Q}=0.25\,\textrm{mm}$, where ``Q''~(also called ``級'') is
6336                         a unit used in Japanese phototypesetting.
6337 So one should not change the value of this dimension.
6338 %</en>
6339 %<*ja>
6340 \cs{jQ} は写植で用いられた$1\,\textrm{Q}=0.25\,\textrm{mm}$%
6341 (「級」とも書かれる)に等しい.したがって,
6342 この寸法レジスタの値を変更してはならない.
6343 %</ja>
6344
6345 \dim{jH}
6346 %<*en>
6347 There is also a unit called ``歯'' which equals to $0.25\,\textrm{mm}$ and
6348                          used in Japanese phototypesetting.
6349 This \cs{jH} is the same \cs{dimen} register as \cs{jQ}.
6350 %</en>
6351 %<*ja>
6352 同じく写植で用いられていた単位として「歯」があり,これも$0.25\,\textrm{mm}$と
6353 等しい.この \cs{jH} は \cs{jQ} と同じ寸法レジスタを指す.
6354 %</ja>
6355
6356 \dim{ltj@zw}
6357 %<*en>
6358 A temporal register for the ``full-width'' of current Japanese font.
6359 The command \cs{zw} sets this register to the correct value, and
6360 ``return'' this register itself.
6361 %</en>
6362 %<*ja>
6363 現在の和文フォントの「全角幅」を保持する一時レジスタ.
6364 \cs{zw} 命令は,このレジスタを適切な値に設定した後,
6365 「このレジスタ自体を返す」.
6366 %</ja>
6367
6368 \dim{ltj@zh}
6369 %<*en>
6370 A temporal register for the ``full-height'' (usually the sum of height of imaginary body and its depth) of current Japanese font.
6371 The command \cs{zh} sets this register to the correct value, and
6372 ``return'' this register itself.
6373 %</en>
6374 %<*ja>
6375 現在の和文フォントの「全角高さ」(通常,高さと深さの和)を保持する一時レジスタ.
6376 \cs{zh} 命令は,このレジスタを適切な値に設定した後,
6377 「このレジスタ自体を返す」.
6378 %</ja>
6379
6380 \attr{jfam}
6381 %<*en>
6382 Current number of Japanese font family for math formulas.
6383 %</en>
6384 %<*ja>
6385 数式用の和文フォントファミリの現在の番号.
6386 %</ja>
6387
6388 \attr{ltj@curjfnt}
6389 %<*en>
6390 The font index of current Japanese font for horizontal direction.
6391 %</en>
6392 %<*ja>
6393 現在の横組用和文フォントのフォント番号.
6394 %</ja>
6395
6396 \attr{ltj@curtfnt}
6397 %<*en>
6398 The font index of current Japanese font for vertical direction.
6399 %</en>
6400 %<*ja>
6401 現在の縦組用和文フォントのフォント番号.
6402 %</ja>
6403
6404 \attr{ltj@charclass}
6405 %<*en>
6406 The character class of Japanese \textit{glyph\_node}.
6407 %</en>
6408 %<*ja>
6409 和文文字の\textit{glyph\_node}の文字クラス.
6410 %</ja>
6411
6412 \attr{ltj@yablshift}
6413 %<*en>
6414 The amount of shifting the baseline of alphabetic fonts in scaled point ($2^{-16}\,\textrm{pt}$).
6415 %</en>
6416 %<*ja>
6417 スケールド・ポイント($2^{-16}\,\textrm{pt}$)を単位とした欧文フォントのベースラインの移動量.
6418 %</ja>
6419
6420 \attr{ltj@ykblshift}
6421 %<*en>
6422 The amount of shifting the baseline of Japanese fonts in scaled point ($2^{-16}\,\textrm{pt}$).
6423 %</en>
6424 %<*ja>
6425 スケールド・ポイント($2^{-16}\,\textrm{pt}$)を単位とした和文フォントのベースラインの移動量.
6426 %</ja>
6427
6428 \attr{ltj@tablshift}
6429 \attr{ltj@tkblshift}
6430
6431 \attr{ltj@autospc}
6432 %<*en>
6433 Whether the auto insertion of \Param{kanjiskip} is allowed at the node.
6434 %</en>
6435 %<*ja>
6436 そのノードで\Param{kanjiskip}の自動挿入が許されるかどうか.
6437 %</ja>
6438
6439 \attr{ltj@autoxspc}
6440 %<*en>
6441 Whether the auto insertion of \Param{xkanjiskip} is allowed at the node.
6442 %</en>
6443 %<*ja>
6444 そのノードで\Param{xkanjiskip}の自動挿入が許されるかどうか.
6445 %</ja>
6446
6447 \attr{ltj@icflag}
6448 %<*en>
6449 An attribute for distinguishing ``kinds'' of a node. One of the following value is
6450 assigned to this attribute:
6451 %</en>
6452 %<*ja>
6453 ノードの「種類」を区別するための属性.以下のうちのひとつが値として割り当てられる:
6454 %</ja>
6455 \begin{description}
6456 \item[\textit{italic} (1)]
6457 %<*en>
6458 Kerns from italic correction (\verb+\/+), or from kerning information of a Japanese font.
6459 These kerns are ``ignored'' in the insertion process of \textbf{JAglue},
6460 unlike explicit \cs{kern}.
6461 %</en>
6462 %<*ja>
6463 イタリック補正(\verb+\/+)によるカーン,
6464 または \Pkg{luaotfload} によって挿入されたフォントのカーニング情報由来のカーン.
6465 これらのカーンは通常の \cs{kern} とは異なり,
6466 \textbf{JAglue}の挿入処理においては透過する.
6467 %</ja>
6468
6469 \item[\textit{packed} (2)]
6470
6471 \item[\textit{kinsoku} (3)]
6472 %<*en>
6473 Penalties inserted for the word-wrapping process (\emph{kinsoku shori}) of Japanese characters.
6474 %</en>
6475 %<ja>禁則処理のために挿入されたペナルティ.
6476 \item[\mathversion{bold}$(\textit{from\_jfm}-2)$--$(\textit{from\_jfm}+2)$~(4--8)]
6477 %<en>Glues/kerns from JFM.
6478 %<ja>JFM由来のグルー/カーン.
6479 \item[\textit{kanji\_skip}~(9), \textit{kanji\_skip\_jfm}~(10)]
6480 %<en>Glues from \Param{kanjiskip}.
6481 %<ja>和文間空白\Param{kanjiskip}を表すグルー.
6482 \item[\textit{xkanji\_skip}~(11), \textit{xkanji\_skip\_jfm}~(12)]
6483 %<en>Glues from \Param{xkanjiskip}.
6484 %<ja>和欧文間空白\Param{xkanjiskip}を表すグルー.
6485 \item[\textit{processed} (13)]
6486 %<en>Nodes which is already processed by \ldots.
6487 %<ja>\LuaTeX-ja の内部処理によって既に処理されたノード.
6488 \item[\textit{ic\_processed} (14)]
6489 %<*en>
6490 Glues from an italic correction, but already processed in the insertion process of \textbf{JAglue}s.
6491 %</en>
6492 %<ja>イタリック補正に由来するグルーであって,既に \textbf{JAglue} 挿入処理にかかったもの.
6493 \item[\textit{boxbdd} (15)]
6494 %<en>Glues/kerns that inserted just the beginning or the ending of an hbox or a paragraph.
6495 %<ja>hboxか段落の最初か最後に挿入されたグルー/カーン.
6496 \end{description}
6497
6498 %<*ja>
6499 また,挿入処理の結果であるリストの最初のノードでは,\verb+\ltj@icflag+ の値に
6500 \textit{processed\_begin\_flag}~(128)が追加される.これによって,\cs{unhbox} が
6501 連続した場合でも「ボックスの境界」が識別できるようになっている.
6502 %</ja>
6503
6504 \attr{ltj@kcat\,$i$}
6505 %<*en>
6506 Where $i$~is a natural number which is less than~7.
6507 These 7~attributes store bit~vectors indicating which character block is regarded as a block of \textbf{JAchar}s.
6508 %</en>
6509 %<*ja>
6510 $i$は7より小さい自然数.
6511 これら7つの属性レジスタは,どの文字ブロックが\textbf{JAchar}のブロックとして
6512 扱われるかを示すビットベクトルを格納する.
6513 %</ja>
6514
6515 \attr{ltj@dir}
6516 %<*ja>
6517 \textit{direction}~whatsit(後述)において組方向を示すために,あるいは\textit{dir\_box}の
6518                          組方向を用いる.\textit{direction}~whatsitにおいては値は
6519 \begin{quote}
6520  \textit{dir\_dtou} (1), \textit{dir\_tate} (3),
6521  \textit{dir\_yoko} (4), \textit{dir\_utod} (11)
6522 \end{quote}
6523 のいずれかであり,\textit{dir\_box}ではこれらに次を加えた値をとる(\ref{sec-dir-imp}章参照).
6524 %</ja>
6525 \begin{description}
6526 \item[\textit{dir\_node\_auto} (128)]
6527 %<ja> 異なる組方向に配置するために自動的に作られたボックス.
6528 \item[\textit{dir\_node\_manual} (256)]
6529 %<ja> \cs{ltjsetwd} によって「ボックスの本来の組方向とは異なる組方向での寸法」を
6530 %<ja> 設定したときに,それを記録するためのボックス.
6531 \end{description}
6532 %<ja> \TeX 側から見える値,つまり \verb+\the\ltj@dir+ の値は常に0である.
6533
6534 \end{list}
6535
6536 %<*en>
6537 Furthermore, \LuaTeX-ja uses several user-defined whatsit nodes for
6538 internal processing. All those nodes except \emph{direction} whatsits
6539 store a natural number (hence its \texttt{type} is 100).
6540 \emph{direction} whatsits store a node list, hence its \texttt{type} is 110.
6541 Their \texttt{user\_id} (used for distinguish user-defined whatsits)
6542 are allocated by \texttt{luatexbase.newuserwhatsitid}.
6543 %</en>
6544 %<*ja>
6545 さらに,\LuaTeX-jaはいくつかのuser-defined whatsit nodeを内部処理に用いる.
6546 \textit{direction} whatsitはノードリストを格納するが,
6547 それ以外のwhatsitノードの \texttt{type} は100であり,ノードは自然数を格納している.
6548 user-defined whatsitを識別するための \texttt{user\_id} は\
6549 \texttt{luatexbase.newuserwhatsitid} により確保されており,
6550 下の見出しは単なる識別用でしかない.
6551 %</ja>
6552 \begin{description}
6553 \item[\textit{inhibitglue}]
6554 %<*en>
6555 Nodes for indicating that \cs{inhibitglue} is
6556            specified. The \texttt{value} field of these nodes doesn't matter.
6557 %</en>
6558 %<*ja>
6559 \cs{inhibitglue} が指定されたことを示すノード.これらのノードの\
6560 \texttt{value} フィールドは意味を持たない.
6561 %</ja>
6562
6563 \item[\textit{stack\_marker}]
6564 %<*en>
6565 Nodes for \LuaTeX-ja's stack system (see the next
6566            subsection). The \texttt{value} field of these nodes is
6567            current group level.
6568 %</en>
6569 %<*ja>
6570 \LuaTeX-jaのスタックシステム(次の節を参照)のためのノード.
6571 これらのノードの \texttt{value} フィールドは現在のグループネストレベルを表す.
6572 %</ja>
6573
6574 \item[\textit{char\_by\_cid}]
6575 %<*en>
6576 Nodes for \textbf{JAchar} which the callback process of
6577            \Pkg{luaotfload} won't be applied, and the character code is
6578            stored in the \texttt{value} field. Each node of this type are
6579            converted to a \textit{glyph\_node} \emph{after}
6580            the callback process of luaotfload.
6581 Nodes of this type is used in \cs{CID}, \cs{UTF} and IVS support.
6582 %</en>
6583 %<*ja>
6584 \Pkg{luaotfload}のコールバックによる処理が適用されない\textbf{JAchar}のためのノードで,
6585 \texttt{value} フィールドに文字コードが格納されている.
6586 この種類のノードはそれぞれが\Pkg{luaotfload}のコールバックの処理の
6587 \emph{後で}\textit{glyph\_node}に変換される.
6588 \cs{CID}, \cs{UTF}やIVS対応処理でこの種類のノードが利用されている.
6589 %</ja>
6590
6591 \item[\textit{replace\_vs}]
6592 %<*en>
6593 Similar to \textit{char\_by\_cid} whatsits above.
6594 These nodes are for \textbf{ALchar} which the callback process of
6595            \Pkg{luaotfload} won't be applied.
6596 %</en>
6597 %<*ja>
6598 上の\textit{char\_by\_cid}と同様に,
6599 これらのノードは\Pkg{luaotfload}のコールバックによる処理が適用されない\textbf{ALchar}のた
6600            めものである.
6601 %</ja>
6602
6603 \item[\textit{begin\_par}]
6604 %<*en>
6605 Nodes for indicating beginning of a paragraph.
6606 A paragraph which is started by \cs{item} in list-like environments has a horizontal box
6607 for its label before the actual contents. So \dots
6608 %</en>
6609 %<*ja>
6610 「段落の開始」を意味するノード.
6611 list環境,itemize環境などにおいて,\cs{item} で始まる各項目は……
6612 %</ja>
6613
6614 \item[\textit{direction}]
6615
6616 \end{description}
6617
6618 %<*en>
6619 These whatsits will be removed during the process of inserting \textbf{JAglue}s.
6620 %</en>
6621 %<*ja>
6622 これらのwhatsitノードは\textbf{JAglue}の挿入処理の間に取り除かれる.
6623 %</ja>
6624
6625 %<en>\subsection{Stack System of \LuaTeX-ja}
6626 %<ja>\subsection{\LuaTeX-jaのスタックシステム}
6627 \label{ssec-stack}
6628
6629 %<en>\paragraph{Background}
6630 %<ja>\paragraph{背景}
6631 %<*en>
6632 \LuaTeX-ja has its own stack system, and most parameters of \LuaTeX-ja
6633 are stored in it. To clarify the reason, imagine the parameter
6634 \Param{kanjiskip} is stored by a skip, and consider the following
6635 source:
6636 %</en>
6637 %<*ja>
6638 \LuaTeX-jaは独自のスタックシステムを持ち,\LuaTeX-jaのほとんどのパラメータは
6639 これを用いて保持されている.その理由を明らかにするために,
6640 \Param{kanjiskip}パラメータがスキップレジスタで保持されているとし,
6641 以下のコードを考えてみよう:
6642 %</ja>
6643 \begin{LTXexample}
6644 \ltjsetparameter{kanjiskip=0pt}ふがふが.%
6645 \setbox0=\hbox{%
6646   \ltjsetparameter{kanjiskip=5pt}ほげほげ}
6647 \box0.ぴよぴよ\par
6648 \end{LTXexample}
6649
6650 %<*en>
6651 As described in Subsection~\ref{ssec-param}, the only effective value of
6652 \Param{kanjiskip} in an hbox is the latest value, so the value of
6653 \Param{kanjiskip} which applied in the entire hbox should be 5\,pt.
6654 However, by the implementation method of \LuaTeX, this ``5\,pt'' cannot be
6655 known from any callbacks.  In the \texttt{tex/packaging.w}, which is a
6656 file in the source of \LuaTeX, there are the following codes:
6657 %</en>
6658 %<*ja>
6659 \ref{ssec-param}節で述べたように,あるhboxの中で効力を持つ
6660 \Param{kanjiskip}の値は最後に現れた値のみであり,したがってボックス全体に適用される
6661 \Param{kanjiskip}は5\,ptであるべきである.しかし,\LuaTeX の実
6662 装を観察すると,この5\,ptという長さはどのコールバックからも知ることはできないことがわかる.
6663 \LuaTeX のソースファイルの1つ \texttt{tex/packaging.w} の中に,
6664 以下のコードがある:
6665 %</ja>
6666 \begin{lstlisting}[numbers=left,firstnumber=1226]
6667 void package(int c)
6668 {
6669     scaled h;                   /* height of box */
6670     halfword p;                 /* first node in a box */
6671     scaled d;                   /* max depth */
6672     int grp;
6673     grp = cur_group;
6674     d = box_max_depth;
6675     unsave();
6676     save_ptr -= 4;
6677     if (cur_list.mode_field == -hmode) {
6678         cur_box = filtered_hpack(cur_list.head_field,
6679                                  cur_list.tail_field, saved_value(1),
6680                                  saved_level(1), grp, saved_level(2));
6681         subtype(cur_box) = HLIST_SUBTYPE_HBOX;
6682 \end{lstlisting}
6683 %<*en>
6684 Notice that \texttt{unsave()} is executed \emph{before}
6685 \texttt{filtered\_hpack()}, where \texttt{hpack\_filter} callback is
6686 executed) here. So ``5\,pt'' in the above source is orphaned at
6687 \texttt{unsave()}, and hence it can't be accessed from \texttt{hpack\_filter}
6688 callback.
6689 %</en>
6690 %<*ja>
6691 \texttt{unsave()} が \texttt{filtered\_hpack()}(これは \texttt{hpack\_filter} コールバックが
6692 実行されるところである)の\emph{前に}実行されていることに注意する.
6693 したがって,上記ソース中で5\,ptは \texttt{unsave()} のところで捨てられ,
6694 \texttt{hpack\_filter} コールバックからはアクセスすることができない.
6695 %</ja>
6696
6697 %<en>\paragraph{Implementation}
6698 %<ja>\paragraph{解決法}
6699
6700 %<*en>
6701 The code of stack system is based on that in a post of Dev-luatex mailing list\footnote{%
6702 \texttt{[Dev-luatex] tex.currentgrouplevel}, a post at 2008/8/19 by Jonathan Sauer.}.
6703 %</en>
6704 %<*ja>
6705 スタックシステムのコードはDev-luatexメーリングリストのある投稿\footnote{%
6706 \texttt{[Dev-luatex] tex.currentgrouplevel}: Jonathan Sauerによる2008/8/19の投稿.}を
6707 ベースにしている.
6708 %</ja>
6709
6710 %<*en>
6711 These are two \TeX\ count registers for maintaining information:
6712 \verb+\ltj@@stack+ for the stack level, and \verb+\ltj@@group@level+ for
6713 the \TeX's group level when the last assignment was done.  Parameters
6714 are stored in one big table named \texttt{charprop\_stack\_table}, where
6715 \texttt{charprop\_stack\_table[$i$]} stores data of stack level~$i$. If
6716 a new stack level is created by \cs{ltjsetparameter}, all data of the
6717 previous level is copied.
6718 %</en>
6719 %<*ja>
6720 情報を保持するために,2つの\TeX の整数レジスタを用いている:
6721 \verb+\ltj@@stack+ にスタックレベル,\verb+\ltj@@group@level+ に最後の代入が
6722 なされた時点での\TeX のグループレベルを保持している.
6723 パラメータは\texttt{charprop\_stack\_table}という名前のひとつの大きなテーブルに
6724 格納される.ここで,\texttt{charprop\_stack\_table[$i$]}はスタックレベル$i$の
6725 データを格納している.もし新しいスタックレベルが \cs{ltjsetparameter} によって
6726 生成されたら,前のレベルの全てのデータがコピーされる.
6727 %</ja>
6728
6729 %<*en>
6730 To resolve the problem mentioned in above paragraph ``Background'', \LuaTeX-ja uses
6731 another trick. When the stack level is about to be increased, a whatsit
6732 node whose type, subtype and value are 44~(\textit{user\_defined}),
6733 \textit{stack\_marker} and the current group level respectively is appended to the current
6734 list (we refer this node by \textit{stack\_flag}). This enables us to
6735 know whether assignment is done just inside a hbox. Suppose that the
6736 stack level is~$s$ and the \TeX's group level is~$t$ just after the hbox
6737 group, then:
6738 %</en>
6739 %<*ja>
6740 上の「背景」で述べた問題を解決するために,\LuaTeX-jaでは次の手法を用いる:
6741 スタックレベルが増加するするとき,type, subtype, valueがそれぞれ
6742 44~(\textit{user\_defined}), \textit{stack\_marker},そして現在のグループレベルであるwhatsitノード
6743 を現在のリストに付け加える(このノードを\textit{stack\_flag}とする).
6744 これにより,あるhboxの中で代入がなされたかどうかを知ることが可能
6745 となる.スタックレベルを$s$,そのhbox groupの直後の\TeX のグループレベルを
6746 $t$とすると:
6747 %</ja>
6748 \begin{itemize}
6749 %<*en>
6750 \item If there is no \textit{stack\_flag} node in the list of the contents of the hbox, then
6751       no assignment was occurred inside the hbox. Hence values of
6752       parameters at the end of the hbox are stored in the stack
6753       level~$s$.
6754 %</en>
6755 %<*ja>
6756 \item もしそのhboxの中身を表すリストの中に\textit{stack\_flag}ノードがなければ,
6757   hboxの中では代入は起こらなかったということになる.
6758   したがって,そのhboxの終わりにおけるパラメータの値はスタックレベル$s$に
6759   格納されている.
6760 %</ja>
6761
6762 %<*en>
6763 \item If there is a \textit{stack\_flag} node whose value is~$t+1$, then
6764       an assignment was occurred just inside the hbox group. Hence
6765       values of parameters at the end of the hbox are stored in the
6766       stack level~$s+1$.
6767 %</en>
6768 %<*ja>
6769 \item もし値が$t+1$の\textit{stack\_flag}ノードがあれば,その
6770   hboxの中で代入が起こったことになる.
6771   したがって,hboxの終わりにおけるパラメータの値はスタックレベル$s+1$に
6772   格納されている.
6773 %</ja>
6774
6775 %<*en>
6776 \item If there are \textit{stack\_flag} nodes but all of their values
6777       are more than~$t+1$, then an assignment was occurred in the box,
6778       but it is done in more internal group. Hence values of
6779       parameters at the end of the hbox are stored in the stack
6780       level~$s$.
6781 %</en>
6782 %<*ja>
6783 \item もし\textit{stack\_flag}ノードがあるがそれらの値が全て$t+1$より大きい
6784   場合,そのボックスの中で代入が起こったが,それは「より内部の」グループで
6785   起こったということになる.したがって,hboxの終わりでのパラメータの
6786   値はスタックレベル$s$に格納されている.
6787 %</ja>
6788 \end{itemize}
6789
6790 %<*en>
6791 Note that to work this trick correctly, assignments to
6792 \verb+\ltj@@stack+ and \verb+\ltj@@group@level+ have to be local always,
6793 regardless the value of \cs{globaldefs}.
6794 To solve this problem, we use another trick: the assignment
6795 \hbox{\verb+\directlua{tex.globaldefs=0}+} is always local.
6796 %</en>
6797 %<*ja>
6798 このトリックを正しく働かせるためには,\verb+\ltj@@stack+ と \verb+\ltj@@group@level+ への
6799 代入は \cs{globaldefs} の値によらず常にローカルでなければならないことに注意する.
6800 この問題は \hbox{\verb+\directlua{tex.globaldefs=0}+}(この代入は常にローカル)を
6801 用いることで解決している.
6802 %</ja>
6803
6804 %<*en>
6805 \subsection{Lua Functions of the Stack System}
6806 In this subsection, we will see how a user use \LuaTeX-ja's stack system to
6807 store some data which obeys the grouping of \TeX.
6808 %</en>
6809 %<*ja>
6810 \subsection{スタックシステムで使用される関数}
6811 本節では,ユーザが\LuaTeX-jaのスタックシステムを使用して,
6812 \TeX のグルーピングに従うような
6813 独自のデータを取り扱う方法を述べる.
6814 %</ja>
6815
6816 %<*en>
6817 The following function can be used to store data into a stack:
6818 \begin{lstlisting}
6819 luatexja.stack.set_stack_table(index, <any> data)
6820 \end{lstlisting}
6821 Any values which except \texttt{nil}~and~NaN are usable as \textit{index}.
6822 However, a user should use only negative integers or strings as \textit{index},
6823 since natural numbers are used by \LuaTeX-ja itself.
6824 Also, whether \textit{data} is stored locally or globally
6825 is determined by \texttt{luatexja.isglobal}
6826 (stored globally if and only if \texttt{luatexja.isglobal == 'global'}).
6827 %</en>
6828 %<*ja>
6829 スタックに値を設定するには,以下のLua関数を呼び出せば良い:
6830 \begin{lstlisting}
6831 luatexja.stack.set_stack_table(<any> index, <any> data)
6832 \end{lstlisting}
6833 直感的には,スタックテーブル中のインデックス\textit{index}の値を\textit{data}にする,という意味である.
6834 \textit{index}の値としては \texttt{nil} とNaN以外の任意の値を使えるが,
6835 自然数は\LuaTeX-jaが使用する(将来の拡張用も含む)ので,
6836 ユーザが使用する場合は負の整数値か文字列の値にすることが望ましい.
6837 また,ローカルに設定されるかグローバルに設定されるかは,\texttt{luatexja.isglobal} の値に依存する
6838 (グローバルに設定されるのは,\texttt{luatexja.isglobal == 'global'} であるちょうどその時).
6839 %</ja>
6840
6841 %<*en>
6842 Stored data can be obtained as the return value of
6843 \begin{lstlisting}
6844 luatexja.stack.get_stack_table(index, <any> default, <number> level)
6845 \end{lstlisting}
6846 where \textit{level} is the stack level, which is usually the value of \verb+\ltj@@stack+,
6847 and \textit{default} is the default value which will be returned if no values are stored
6848 in the stack table whose level is \textit{level}.
6849 %</en>
6850 %<*ja>
6851 スタックの値は,
6852 \begin{lstlisting}
6853 luatexja.stack.get_stack_table(<any> index, <any> default, <number> level)
6854 \end{lstlisting}
6855 の戻り値で取得できる.\textit{level}はスタックレベルであり,
6856 通常は \verb+\ltj@@stack+ の値を指定することになるだろう.
6857 \textit{default}はレベル\textit{level}のスタックに値が設定されていなかった場合に
6858 返すデフォルト値である.
6859 %</ja>
6860
6861 \begin{figure}[tb]
6862 \begin{lstlisting}[numbers=left, firstnumber=380]
6863 \protected\def\ltj@setpar@global{%
6864   \relax\ifnum\globaldefs>0\directlua{luatexja.isglobal='global'}%
6865     \else\directlua{luatexja.isglobal=''}\fi
6866 }
6867 \protected\def\ltjsetparameter#1{%
6868   \ltj@setpar@global\setkeys[ltj]{japaram}{#1}\ignorespaces}
6869 \protected\def\ltjglobalsetparameter#1{%
6870   \relax\ifnum\globaldefs<0\directlua{luatexja.isglobal=''}%
6871     \else\directlua{luatexja.isglobal='global'}\fi%
6872   \setkeys[ltj]{japaram}{#1}\ignorespaces}
6873 \end{lstlisting}
6874 %<ja>\caption{パラメータ設定命令の定義}
6875 %<en>\caption{Definiton of parameter setting commands}
6876 \label{fig:setpar-def}
6877 \end{figure}
6878
6879 %<*en>
6880 \subsection{Extending Parameters}
6881 Keys for \cs{ltjsetparameter}~and~\cs{ltjgetparameter} can be extended,
6882 as in \Pkg{luatexja-adjust}.
6883 %</en>
6884 %<*ja>
6885 \subsection{パラメータの拡張}
6886 ここでは,\Pkg{luatexja-adjust}で行なっているように,
6887 \cs{ltjsetparameter},~\cs{ltjgetparameter}に指定可能なキーを追加する方法
6888 を述べる.
6889 %</ja>
6890
6891 %<*en>
6892 \paragraph{Setting parameters}
6893 Figure~\ref{fig:setpar-def} shows the ``most outer'' definition of
6894 two commands,
6895 \cs{ltjsetparameter} and \cs{ltjglobalsetparameter}.
6896 Most important part is the last \cs{setkeys},
6897 which is offered by the \Pkg{xkeyval} package.
6898
6899 Hence, to add a key in \cs{ltjsetparameter}, one only have to add a key
6900 whose prefix is \texttt{ltj} and whose family is \texttt{japaram}, as the following.
6901 \begin{lstlisting}
6902 \define@key[ltj]{japaram}{...}{...}
6903 \end{lstlisting}
6904
6905 \cs{ltjsetparameter}~and~\cs{ltjglobalsetparameter} automatically sets
6906 \texttt{luatexja.isglobal}. Its meaning is the following.
6907 \begin{align}
6908  \texttt{luatexja.isglobal} =
6909 \begin{cases}
6910  \texttt{'global'}&\text{global}\\
6911  \texttt{''}&\text{local}
6912 \end{cases}
6913 \end{align}
6914 This is determined not only by command name
6915 (\cs{ltjsetparameter}~or~\cs{ltjglobalsetparameter}),
6916 but also by the value of \cs{globaldefs}.
6917 %</en>
6918 %<*ja>
6919 \paragraph{パラメータの設定}
6920 \cs{ltjsetparameter} と,\cs{ltjglobalsetparameter} の定義は図\ref{fig:setpar-def}の
6921 のようになっている.
6922 本質的なのは最後の \cs{setkeys} で,これは\Pkg{xkeyval}パッケージの提供する命令である.
6923
6924 このため,\cs{ltjsetparameter} に指定可能なパラメータを追加するには,
6925 <prefix>を \texttt{ltj},<family>を \texttt{japaram} としたキーを
6926 \begin{lstlisting}
6927 \define@key[ltj]{japaram}{...}{...}
6928 \end{lstlisting}
6929 のように定義すれば良いだけである.
6930 なお,パラメータ指定がグローバルかローカルかどうかを示す \texttt{luatexja.isglobal} が,
6931 \begin{align}
6932  \texttt{luatexja.isglobal} =
6933 \begin{cases}
6934  \texttt{'global'}&\text{パラメータ設定はグローバル}\\
6935  \texttt{''}&\text{パラメータ設定はローカル}
6936 \end{cases}
6937 \end{align}
6938 として自動的にセットされる\footnote{命令が \cs{ltjglobalsetparameter} かどうかだけでは
6939 なく,実行時の \cs{globaldefs} の値にも依存して定まる.}.
6940 %</ja>
6941
6942 %<*en>
6943 \paragraph{Getting parameters}
6944 \cs{ltjgetparameter} is implemented by a Lua script.
6945
6946 For parameters that do not need additional arguments, one only have to
6947 define a function in the table \verb+luatexja.unary_pars+.
6948 For example, with the following function,
6949 \verb+\ltjgetparameter{hoge}+ returns a \emph{string} \texttt{42}.
6950 \begin{lstlisting}[numbers=left]
6951 function luatexja.unary_pars.hoge (t)
6952   return 42
6953 end
6954 \end{lstlisting}
6955 Here the argument of \verb+luatexja.unary_pars.hoge+ is
6956 the stack level of \LuaTeX-ja's stack system (see Subsection~\ref{ssec-stack}).
6957
6958 On the other hand, for parameters that need an additional argument
6959 (this must be an integer), one have to define a function in
6960 \verb+luatexja.binary_pars+ first. For example,
6961 \begin{lstlisting}[numbers=left]
6962 function luatexja.binary_pars.fuga (c, t)
6963   return tostring(c) .. ', ' .. tostring(42)
6964 end
6965 \end{lstlisting}
6966 Here the first argument $t$ is the stack level, as before.
6967 The second argument $c$ is just the second argument of \cs{ltjgetparameter}.
6968
6969 For parameters that need an additional argument, one also have to
6970 execute the \TeX\ code like
6971 \begin{lstlisting}
6972 \ltj@@decl@array@param{fuga}
6973 \end{lstlisting}
6974 to indicate that ``the parameter \texttt{fuga} needs an additional argument''.
6975 %</en>
6976 %<*ja>
6977 \paragraph{パラメータの取得}
6978 一方,\cs{ltjgetparameter} はLuaスクリプトによって実装されている.
6979 値を取得するのに追加引数の要らないパラメータについては,\verb+luatexja.unary_pars+\
6980 内に処理内容を記述した関数を定義すれば良い.例えば,Luaスクリプトで
6981 \begin{lstlisting}[numbers=left]
6982 function luatexja.unary_pars.hoge (t)
6983   return 42
6984 end
6985 \end{lstlisting}
6986 を実行すると,\verb+\ltjgetparameter{hoge}+ は \texttt{42} という\emph{文字列}を返す.
6987 関数 \verb+luatexja.unary_pars.hoge+ の引数$t$は,\ref{ssec-stack}節で述べた
6988 \LuaTeX-jaのスタックシステムにおけるスタックレベルである.
6989 戻り値はいかなる値であっても,最終的には文字列として出力されることに注意.
6990
6991 一方,追加引数(\emph{数値しか許容しない})が必要なパラメータについては,
6992 まずLuaスクリプトで処理内容の本体を記述しておく:
6993 \begin{lstlisting}[numbers=left]
6994 function luatexja.binary_pars.fuga (c, t)
6995   return tostring(c) .. ', ' .. tostring(42)
6996 end
6997 \end{lstlisting}
6998 引数$t$は,先に述べた通りのスタックレベルである.一方,引数$c$は\
6999 \cs{ltjgetparameter} の第2引数を表す数値である.
7000 しかしこれだけでは駄目で,
7001 \begin{lstlisting}
7002 \ltj@@decl@array@param{fuga}
7003 \end{lstlisting}
7004 を実行し,\TeX インターフェース側に
7005 「\verb+\ltjgetparameter{fuga}+ は追加引数が必要」ということを通知する必要がある.
7006 %</ja>
7007
7008 %<en>\section{Linebreak after a Japanese Character}
7009 %<ja>\section{和文文字直後の改行}
7010 \label{sec-lbreak}
7011 %<en>\subsection{Reference: Behavior in \pTeX}
7012 %<ja>\subsection{参考:\pTeX の動作}
7013 %<*en>
7014 In~\pTeX, a line break after a Japanese character doesn't emit a space,
7015 since words are not separated by spaces in Japanese writings. However,
7016 this feature isn't fully implemented in \LuaTeX-ja due to the
7017 specification of callbacks in~\LuaTeX. To clarify the difference between
7018 \pTeX~and~\LuaTeX, We briefly describe the handling of a line break in~\pTeX, in
7019 this subsection.
7020
7021 \pTeX's input processor can be described in terms of a finite state
7022 automaton, as that of~\TeX\ in~Section~2.5 of~\cite{texbytopic}. The
7023 internal states are as follows:
7024 \begin{itemize}
7025 \item State~$N$: new line
7026 \item State~$S$: skipping spaces
7027 \item State~$M$: middle of line
7028 \item State~$K$: after a Japanese character
7029 \end{itemize}
7030 The first three states---$N$,~$S$, and~$M$---are as same as \TeX's input
7031 processor.  State~$K$ is similar to state~$M$, and is entered after
7032 Japanese characters.  The diagram of state transitions are indicated in
7033 Figure~\ref{fig-ptexipro}.  Note that \pTeX\ doesn't leave state~$K$
7034 after ``beginning/ending of a group'' characters.
7035 %</en>
7036
7037 %<*ja>
7038 欧文では文章の改行は単語間でしか行わない.そのため,\TeX では,(文字の直後の)改行は
7039 空白文字と同じ扱いとして扱われる.一方,和文ではほとんどどこでも改行が可能なため,
7040 \pTeX では和文文字の直後の改行は単純に無視されるようになっている.
7041
7042 このような動作は,\pTeX が\TeX からエンジンとして拡張されたことによって可能になったことである.
7043 \pTeX の入力処理部は,\TeX におけるそれと同じように,有限オートマトンとして記述することができ,
7044 以下に述べるような4状態を持っている.
7045
7046 \begin{itemize}
7047 \item State~$N$: 行の開始.
7048 \item State~$S$: 空白読み飛ばし.
7049 \item State~$M$: 行中.
7050 \item State~$K$: 行中(和文文字の後).
7051 \end{itemize}
7052 また,状態遷移は,図\ref{fig-ptexipro}のようになっており,図中の数字は
7053 カテゴリーコードを表している.最初の3状態は\TeX の入力処理部と同じであり,
7054 図中から状態$K$と「$j$」と書かれた矢印を取り除けば,\TeX の入力処理部と同
7055 じものになる.
7056
7057 この図から分かることは,
7058 \begin{quote}
7059 行が和文文字(とグループ境界文字)で終わっていれば,改行は無視される
7060 \end{quote}
7061 ということである.
7062 %</ja>
7063
7064 \begin{figure}[!tb]
7065 \let\sp\textvisiblespace\small
7066 \begin{minipage}{.6\textwidth}%
7067 \begin{center}
7068 \unitlength=6.5mm\sf\mathversion{bold}
7069 \begin{tikzpicture}[
7070   ->, auto, shorten >=1pt
7071 ]
7072 \node [shape=rectangle, font=\scriptsize] (init) at (2,7) {start};
7073 \node [shape=circle,draw, fill=b_cyan] (newline) at (4,7) {$N$};
7074 \node [shape=circle,draw, fill=b_cyan] (midline) at (4,4) {$M$};
7075 \node [shape=circle,draw, fill=b_cyan] (skipspc) at (8,7) {$S$};
7076 \node [shape=circle,draw, fill=b_pink]  (kanji) at (8,4) {$K$};
7077 \node [shape=rectangle,draw, fill=b_green] (scanacs) at (6,8) {scan a c.s.};
7078 \node (endk) at (8,2.5) {} ;
7079 \node (endm) at (4,2.5) {} ;
7080 \node (ends) at (8,8.5) {} ;
7081 \node (endn) at (4,8.5) {} ;
7082 \begin{scope}[font=\scriptsize]
7083 \path (newline) edge [bend right]    node [left]{G, O} (midline)
7084       (init)    edge                 node {} (newline)
7085       (midline) edge [bend right=10] node {10} (skipspc)
7086       (skipspc) edge [bend right]    node [left,right=10,above=7]{G, O} (midline)
7087       (skipspc) edge [loop right]    node {10} (skipspc)
7088       (newline) edge [loop right]    node {10} (newline)
7089       (scanacs) edge [bend left]     node [left=3,below]{$(*)$} (skipspc)
7090       (scanacs) edge [bend right]    node [right=30,above=20]{$(*)$} (midline)
7091       (midline) edge                 node {5\ [\sp]} (endm)
7092       (midline) edge [loop left]     node {G, O} (midline)
7093       (skipspc) edge                 node [right] {5} (ends)
7094       (newline) edge                 node {5 [\cs{par}]} (endn);
7095 \begin{scope}[red]
7096 \path (newline) edge [bend right]    node [right=25,below=3]{J} (kanji)
7097       (midline) edge                 node [below]{J} (kanji)
7098       (kanji)   edge [bend left]     node {O} (midline)
7099       (kanji)   edge                 node {10} (skipspc)
7100       (kanji)   edge [loop right]    node {G, J} (kanji)
7101       (skipspc) edge [bend left]     node {J} (kanji)
7102       (kanji)   edge                 node {5} (endk)
7103 ;
7104 \end{scope}
7105 \end{scope}
7106 \end{tikzpicture}
7107 \end{center}
7108 \end{minipage}%
7109 \begin{minipage}{.4\textwidth}
7110 \begin{description}
7111 \item[\textsf{G}] Beginning of group (usually \verb+{+)\\
7112  and ending of group (usually \verb+}+).
7113 \item[\textsf{J}] Japanese characters.
7114 \item[\textsf{5}] \textit{end-of-line} (usually \verb+^+\verb+^J+).
7115 \item[\textsf{10}] space (usually \sp).
7116 \item[\textsf{O}] other characters, whose category code is in $\{3,4,6,7,8,11,12,13\}$.
7117 \item[\textsf{[\sp]}, \textsf{[\cs{par}]}]
7118 emits a space, or~\cs{par}.
7119 \end{description}
7120 \end{minipage}
7121 \begin{itemize}
7122 \item We omitted about category codes
7123 9~(\textit{ignored}), 14~(\textit{comment}), and~15~(\textit{invalid})
7124 from the above diagram. We also ignored the input like ``\verb+^+\verb+^A+'' or ``\verb+^+\verb+^df+''.
7125 \item When a character whose category code is 0 (\textit{escape character}) is seen by \TeX,
7126 the input processor scans a control sequence (\textsf{scan a c.s.}).
7127 These paths are not shown in the above diagram.
7128
7129 After that, the state is changed to State~$S$ (skipping blanks) in most cases, but
7130 to State~$M$ (middle of line) sometimes.
7131 \end{itemize}
7132 %<en>\caption{State transitions of \pTeX's input processor}
7133 %<ja>\caption{\pTeX の入力処理部の状態遷移}
7134 \label{fig-ptexipro}
7135 \end{figure}
7136
7137
7138 %<en>\subsection{Behavior in \LuaTeX-ja}
7139 %<ja>\subsection{\LuaTeX-jaの動作}
7140 %<*en>
7141 States in the input processor of \LuaTeX\ is the same as that of \TeX,
7142 and they can't be customized by any callbacks. Hence, we can only use
7143 \verb+process_input_buffer+ and \verb+token_filter+ callbacks for to
7144 suppress a space by a line break which is after Japanese characters.
7145
7146 However, \verb+token_filter+ callback cannot be used either, since a
7147 character in category code 5~(\textit{end-of-line}) is converted into an space
7148 token \emph{in the input processor}.  So we can use only the
7149 \verb+process_input_buffer+ callback.  This means that suppressing a
7150 space must be done \emph{just before} an input line is read.
7151
7152 Considering these situations, handling of an end-of-line in \LuaTeX-ja are as follows:
7153 \begin{quote}
7154 A character \texttt{U+FFFFF} (its category code is set to 14~(\textit{comment}) by
7155 \LuaTeX-ja) is appended to an input line, \emph{before \LuaTeX\ actually
7156 process it}, if and only if the following three conditions are satisfied:
7157 \begin{enumerate}
7158 \item The category code of \cs{endlinechar}%
7159 \footnote{Usually, it is $\langle$\textit{return}$\rangle$
7160       (whose character code is 13).} is 5~(\textit{end-of-line}).
7161 \item The category code of \texttt{U+FFFFF} itself is 14~(\textit{comment}).
7162 \item The input line matches the following ``regular expression'':
7163 \[
7164   (\text{any char})^*(\textbf{JAchar})
7165   \bigl(\{\text{catcode}=1\}\cup\{\text{catcode}=2\}\bigr)^*
7166 \]
7167 \end{enumerate}
7168 \end{quote}
7169
7170 \paragraph{Remark}
7171 The following example shows the major difference from the behavior of \pTeX.
7172 \begin{LTXexample}
7173 \fontspec[Ligatures=TeX]{TeX Gyre Termes}
7174 \ltjsetparameter{autoxspacing=false}
7175 \ltjsetparameter{jacharrange={-6}}xあ
7176 y\ltjsetparameter{jacharrange={+6}}zい
7177 u
7178 \end{LTXexample}
7179 It is not strange that ``あ'' does not printed in the above output.
7180 This is because \TeX\ Gyre\ Termes does not contain ``あ'', and because
7181 ``あ'' in line~3 is considered as an \textbf{ALchar}.
7182
7183 Note that there is no space before ``y'' in the output, but
7184 there is a space before ``u''. This follows from following reasons:
7185 \begin{itemize}
7186 \item When line~3 is processed by \texttt{process\_input\_buffer} callback,
7187 ``あ'' is considered as an \textbf{JAchar}.
7188 Since  line~3 ends with an \textbf{JAchar},
7189 the comment character \texttt{U+FFFFF} is appended to this line,
7190 and hence the linebreak immediately after this line is ignored.
7191 \item When line~4 is processed by \texttt{process\_input\_buffer} callback,
7192 ``い'' is considered as an \textbf{ALchar}.
7193 Since  line~4 ends with an \textbf{ALchar}, the linebreak immediately after this line
7194 emits a space.
7195 \end{itemize}
7196 %</en>
7197
7198 %<*ja>
7199 \LuaTeX の入力処理部は\TeX のそれと全く同じであり,コールバックによりユーザが
7200 カスタマイズすることはできない.このため,改行抑制の目的でユーザが利用で
7201 きそうなコールバックとしては,\verb+process_input_buffer+や
7202 \verb+token_filter+に限られてしまう.しかし,\TeX の入力処理部をよく見る
7203 と,後者も役には経たないことが分かる:改行文字は,入力処理部によってトー
7204 クン化される時に,カテゴリーコード10の32番文字へと置き換えられてしまうた
7205 め,\verb+token_filter+で非標準なトークン読み出しを行おうとしても,空白文
7206 字由来のトークンと,改行文字由来のトークンは区別できないのだ.
7207
7208 すると,我々のとれる道は,\verb+process_input_buffer+を用いて
7209 \LuaTeX の入力処理部に引き渡される前に入力文字列を編集するというものしかない.
7210 以上を踏まえ,\LuaTeX-jaにおける「和文文字直後の改行抑制」の処理は,次のようになっている:
7211
7212 \begin{quote}
7213 各入力行に対し,\emph{その入力行が読まれる前の内部状態で}
7214 以下の3条件が満たされている場合,\LuaTeX-jaは\texttt{U+FFFFF}の文字
7215 \footnote{この文字はコメント文字として扱われるように\LuaTeX-ja内部で設定をしている.}
7216 を末尾に追加する.よって,その場合に改行は空白とは見做されないこととなる.
7217 \begin{enumerate}
7218 \item \cs{endlinechar}の文字\footnote{普通は,改行文字(文字コード13番)である.}
7219 のカテゴリーコードが5~(\textit{end-of-line})である.
7220 \item \texttt{U+FFFFF}のカテゴリーコードが14~(\textit{comment})である.
7221 \item 入力行は次の「正規表現」にマッチしている:
7222 \[
7223   (\text{any char})^*(\textbf{JAchar})
7224   \bigl(\{\text{catcode}=1\}\cup\{\text{catcode}=2\}\bigr)^*
7225 \]
7226 \end{enumerate}
7227 \end{quote}
7228
7229 この仕様は,前節で述べた\pTeX の仕様にできるだけ近づけたものとなっている.条件1.は,
7230 \texttt{lstlisting}系環境などの日本語対応マクロを書かなくてすませるためのものである.
7231
7232 しかしながら,\pTeX と完全に同じ挙動が実現できたわけではない.
7233 次のように,和文文字の範囲を変更したちょうどその行においては挙動が異なる:
7234 \begin{LTXexample}
7235 \fontspec[Ligatures=TeX]{TeX Gyre Termes}
7236 \ltjsetparameter{autoxspacing=false}
7237 \ltjsetparameter{jacharrange={-6}}xあ
7238 y\ltjsetparameter{jacharrange={+6}}zい
7239 u
7240 \end{LTXexample}
7241 上ソース中の「あ」は欧文文字扱いであり.
7242 ここで使用している欧文フォント\TeX\ Gyre Termesは「あ」を含まない.
7243 よって,出力に「あ」は現れないことは不思議ではない.
7244 それでも,\pTeX とまったく同じ挙動を示すならば,出力は
7245 「\hbox{\ltjsetparameter{autoxspacing=false}x yzいu}」となるはずである.しかし,実際には
7246 上のように異なる挙動となっているが,それは以下の理由による:
7247 \begin{itemize}
7248 \item 3行目を \texttt{process\_input\_buffer} で処理する時点では,
7249       「あ」は和文文字扱いである.よって3行目は和文文字で終わることになり,
7250       コメント文字 \texttt{U+FFFFF} が追加される.
7251       よって,直後の改行文字は無視されることになり,空白は入らない.
7252 \item 4行目を \texttt{process\_input\_buffer} で処理する時点では,
7253       「い」は欧文文字扱いである.よって4行目は欧文文字で終わることになり,
7254       直後の改行文字は空白に置き換わる.
7255 \end{itemize}
7256 このため,トラブルを避けるために,和文文字の範囲を\cs{ltjsetparameter}で編集した場合,
7257 その行はそこで改行するようにした方がいいだろう.
7258 %</ja>
7259
7260 %<*ja>
7261
7262 %<en>\section{Insertion of JFM glues, \Param{kanjiskip} and \Param{xkanjiskip}}
7263 %<ja>\section{JFMグルーの挿入,\Param{kanjiskip}と\Param{xkanjiskip}}
7264 \label{sec-jfmglue}
7265 %<en>\subsection{Overview}
7266 %<ja>\subsection{概要}
7267
7268 \LuaTeX-jaにおける \textbf{JAglue} の挿入方法は,\pTeX のそれとは全く異なる.
7269 \pTeX では次のような仕様であった:
7270 \begin{itemize}
7271 \item JFMグルーの挿入は,和文文字を表すトークンを元に水平リストに(文字を表す)<char\_node>を
7272 追加する過程で行われる.
7273 \item \Param{xkanjiskip}の挿入は,hboxへのパッケージングや行分割前に行われる.
7274 \item \Param{kanjiskip}はノードとしては挿入されない.パッケージングや行分割の計算時に
7275 「和文文字を表す2つの<char\_node>の間には\Param{kanjiskip}がある」ものとみなされる.
7276 \end{itemize}
7277 しかし,\LuaTeX-jaでは,hboxへのパッケージングや行分割前に全ての
7278 \textbf{JAglue},即ちJFMグルー・\Param{xkanjiskip}・\Param{kanjiskip}の
7279 3種類を一度に挿入することになっている.これは,\LuaTeX において欧文の合字・
7280 カーニング処理がノードベースになったことに対応する変更である.
7281
7282 \LuaTeX-jaにおける\textbf{JAglue}挿入処理では,次節で定義する
7283 「クラスタ」を単位にして行われる.大雑把にいうと,「クラスタ」は文字とそれに付随す
7284 るノード達(アクセント位置補正用のカーンや,イタリック補正)をまとめたもの
7285 であり,2つのクラスタの間には,ペナルティ,\cs{vadjust},whatsitなど,行組版
7286 には関係しないものがある.
7287
7288
7289 %<en>\subsection{Definition of a Cluster}
7290 %<ja>\subsection{「クラスタ」の定義}
7291
7292 \def\OA{$\text{\sf O}_{\text{\sf A}}$}
7293 \def\OB{$\text{\sf O}_{\text{\sf B}}$}
7294 \begin{defn}
7295 %<*en>
7296 A \emph{cluster} is consecutive nodes in one of the following forms,
7297 with the \textit{id} of it:
7298 %</en>
7299 %<*ja>
7300 \emph{クラスタ}は以下の形のうちのどれかひとつをとるノードのリストである:
7301 %</ja>
7302 \begin{enumerate}
7303 %<*en>
7304 \item Nodes whose value of\ \verb+\ltj@icflag+ is in $[3,15)$.  These
7305       nodes come from a hbox which is already packaged, by unpackaging
7306       (\cs{unhbox}).
7307       The \textit{id} of the cluster is \textit{id\_pbox}.
7308 %</en>
7309 %<*ja>
7310 \item その \verb+\ltj@icflag+ の値が$[3,15)$に入るノードのリスト.
7311   これらのノードはある既にパッケージングされたhboxから \cs{unhbox} で
7312   アンパックされたものである.
7313   この場合,クラスタの\textit{id}は\textit{id\_pbox}である.
7314 %</ja>
7315
7316 %<*en>
7317 \item A inline math formula, including two \textit{math\_node}s at the boundary of it.
7318       The \textit{id} of the cluster is \textit{id\_math}.
7319 %</en>
7320 %<*ja>
7321 \item インライン数式でその境界に2つの\textit{math\_node}を含むもの.
7322   この場合,クラスタの\textit{id}は\textit{id\_math}である.
7323 %</ja>
7324
7325 %<*en>
7326 \item A \textit{glyph\_node}~$p$, which represents a \textbf{JAchar}, with nodes which relate with it:
7327 %</en>
7328 %<*ja>
7329 \item \textbf{JAchar}を表す\textit{glyph\_node}~$p$とそれに関係するノード:
7330 %</ja>
7331 \begin{enumerate}
7332 %<*en>
7333 \item[(a)] A kern for the italic correction of~$p$.
7334 %</en>
7335 %<*ja>
7336 \item[(a)] $p$のイタリック補正のためのカーン.
7337 %</ja>
7338
7339 %<*en>
7340 \item[(b)] An accent attached to $p$ by \cs{accent}.
7341 %</en>
7342 %<*ja>
7343 \item[(b)] \cs{accent} による$p$に付随したアクセント.
7344 %</ja>
7345 \end{enumerate}
7346 \[
7347 \overbrace{%
7348  \Node{kern}{$\mathit{subtype}=2$}\longrightarrow
7349 \left\{\begin{array}{c}
7350 \Node{glyph}{accent}\\\noalign{\medskip}
7351 \Node{hbox}{accent (shifted vert.)}
7352 \end{array}\right\}\longrightarrow
7353 \Node{kern}{$\mathit{subtype}=2$}}^{\text{(a)}}
7354 \longrightarrow
7355 \Node{glyph}{$p$}\longrightarrow
7356 \overbrace{%
7357 \Node{kern}{italic corr.}}^{\text{(b)}}
7358 \]
7359
7360 %<*en>
7361 In this case, the \textit{id} is \textit{id\_jglyph}.
7362 %</en>
7363 %<*ja>
7364 この場合の\textit{id}は\textit{id\_jglyph}である.
7365 %</ja>
7366
7367 %<*en>
7368 \item A list which begins from a \textit{glyph\_node} which represents a \textbf{ALchar},
7369       and consists of \textbf{ALchar} \textit{glyph\_node}s,
7370       kerns for adjusting accents~(its subtype is 2), kerns for italic corrections and
7371       kerns which are automatically inserted by \LuaTeX~or~luaotfload.
7372       In this case, the \textit{id} is \textit{id\_glyph}.
7373 %</en>
7374 %<*ja>
7375 \item \textbf{ALchar}を表す\textit{glyph\_node},\cs{accent} によるアクセント位置補正用の
7376       カーン(subtypeが2),そしてイタリック補正・カーニングによって挿入されたカーン達が連続
7377       したもの.この場合の\textit{id}は\textit{id\_glyph}である.
7378 %</ja>
7379
7380 %<*en>
7381 \item An box-like node, that is, an hbox, a vbox, a rule (\cs{vrule}) and an \textit{unset\_node}.
7382 The \textit{id} of the cluster is \textit{id\_hlist} if the node is an
7383       hbox which is not shifted vertically, or \textit{id\_box\_like}
7384       otherwise.
7385 %</en>
7386 %<*ja>
7387 \item 水平ボックス(hbox),垂直ボックス,罫線 (\cs{vrule}),
7388   そして\textit{unset\_node}.
7389   クラスタの\textit{id}は垂直に移動していないhboxならば\textit{id\_hlist},
7390   そうでなければ\textit{id\_box\_like}となる.
7391 %</ja>
7392
7393 %<*en>
7394 \item A glue, a kern whose subtype is not 2~(\textit{accent}), and a discretionary break.
7395 The \textit{id} of the cluster is \textit{id\_glue}, \textit{id\_kern}
7396       and \textit{id\_disc}, respectively.
7397 %</en>
7398 %<*ja>
7399 \item グルー,subtypeが 2~(\textit{accent})ではないカーン,そしてdiscretionary break.
7400   その\textit{id} of the clusterはそれぞれ\textit{id\_glue}, \textit{id\_kern},そして
7401   \textit{id\_disc}である.
7402 %</ja>
7403 \end{enumerate}
7404 %<*en>
7405 We use \textit{Np}, \textit{Nq} and \textit{Nr} to denote a cluster.
7406 %</en>
7407 %<*ja>
7408 以下では\textit{Np}, \textit{Nq}, \textit{Nr}でクラスタを表す.
7409 %</ja>
7410 \end{defn}
7411
7412 \paragraph{\textit{id}の意味}
7413 $\mathit{Np}.\mathit{id}$の意味を述べるとともに,
7414 「先頭の文字」を表す\textit{glyph\_node}~$\mathit{Np}.\mathit{head}$と,
7415 「最後の文字」を表す\textit{glyph\_node}~$\mathit{Np}.\mathit{tail}$を次のように定義する.
7416 直感的に言うと,\textit{Np}は$\mathit{Np}.\mathit{head}$で始まり$\mathit{Np}.\mathit{tail}$で終わるような単語,
7417 と見做すことができる.これら$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$は
7418 説明用に準備した概念であって,実際のLuaコード中にそのように書かれているわけではないことに注意.
7419
7420 \begin{description}
7421 \item[\textit{id\_jglyph}] 和文文字.\\
7422 $\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$は,その和文文字を表している
7423 \textit{glyph\_node}そのものである.
7424 \item[\textit{id\_glyph}] 和文文字を表していない\textit{glyph\_node}~$p$.\\
7425 多くの場合,$p$は欧文文字を格納しているが,「ffi」などの合字によって作られた
7426 \textit{glyph\_node}である可能性もある.
7427 前者の場合,$\mathit{Np}.\mathit{head}$,~$\mathit{Np}.\mathit{tail} = p$である.
7428 一方,後者の場合,
7429 \begin{itemize}
7430 \item $\mathit{Np}.\mathit{head}$は,
7431 合字の構成要素の先頭→(その\textit{glyph\_node}における)合字の構成要素の先頭→……
7432 と再帰的に検索していってたどり着いた\textit{glyph\_node}である.
7433 \item $\mathit{Np}.\mathit{last}$は,同様に末尾→末尾→と検索してたどり着いた\textit{glyph\_node}である.
7434 \end{itemize}
7435 \item[\textit{id\_math}] インライン数式.\\
7436 便宜的に,$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$ともに
7437 「文字コード$-1$の欧文文字」とおく.
7438 \item[\textit{id\_hlist}] 縦方向にシフトされていないhbox.\\
7439 この場合,$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$はそれぞれ$p$の内容を表すリストの,
7440 先頭・末尾のノードである.
7441 \medskip
7442 \begin{itemize}
7443 \item 状況によっては,\TeX ソースで言うと
7444 \begin{lstlisting}
7445 \hbox{\hbox{abc}...\hbox{\lower1pt\hbox{xyz}}}
7446 \end{lstlisting}
7447 のように,$p$の内容が別のhboxで開始・終了している可能性も十分あり得る.そのような場合,
7448 $\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$の算出は,
7449 \emph{垂直方向にシフトされていない}hboxの
7450 場合だけ内部を再帰的に探索する.例えば上の例では,$\mathit{Np}.\mathit{head}$は文字「a」を表すノードであり,
7451 一方$\mathit{Np}.\mathit{tail}$は垂直方向にシフトされたhbox,
7452 \verb+\lower1pt\hbox{xyz}+ に対応するノードである.
7453 \item また,先頭にアクセント付きの文字がきたり,末尾にイタリック補正用のカーンが
7454 来ることもあり得る.この場合は,クラスタの定義のところにもあったように,それらは無視して算出を行う.
7455 \item 最初・最後のノードが合字によって作られた\textit{glyph\_node}のときは,それぞれに対して\textit{id\_glyph}%
7456 と同様に再帰的に構成要素をたどっていく.
7457 \end{itemize}
7458 \item[\textit{id\_pbox}] 「既に処理された」ノードのリストであり,これらのノードが二度処理を受けないために
7459 まとめて1つのクラスタとして取り扱うだけである.
7460 \textit{id\_hlist}と同じ方法で$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$を算出する,
7461 \item[\textit{id\_disc}] discretionary break (\verb+\discretionary{pre}{post}{nobreak}+).\\
7462 \textit{id\_hlist}と同じ方法で$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$を算出するが,
7463 第3引数の \texttt{nobreak}(行分割が行われない時の内容)を使う.言い換えれば,ここで行分割が発生した時の状況は
7464 全く考慮に入れない.
7465 \item[\textit{id\_box\_like}] \textit{id\_hlist}とならないboxや,rule.\\
7466 この場合は,$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$のデータは利用されないので,2つの算出は無意味である.
7467 敢えて明示するならば,$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$は共にnil値である.
7468 \item[他] 以上にない\textit{id}に対しても,$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$の算出は無意味.
7469 \end{description}
7470
7471 \paragraph{クラスタの別の分類}
7472 さらに,JFMグルー挿入処理の実際の説明により便利なように,\textit{id}とは別のクラスタの分類を行っておく.
7473 挿入処理では2つの隣り合ったクラスタの間に
7474 空白等の実際の挿入を行うことは前に書いたが,ここでの説明では,問題にしているクラスタ\textit{Np}は「後ろ側」のクラスタである
7475 とする.「前側」のクラスタについては,以下の説明で\textit{head}が\textit{last}に置き換わることに注意すること.
7476 \begin{description}
7477 \item[和文A] リスト中に直接出現している和文文字.
7478 \textit{id}が\textit{id\_jglyph}であるか,\\
7479 \textit{id}が\textit{id\_pbox}であって$\mathit{Np}.\mathit{head}$が\textbf{JAchar}であるとき.
7480
7481 \item[和文B] リスト中のhboxの中身の先頭として出現した和文文字.和文Aとの違いは,これの前に
7482 JFMグルーの挿入が行われない(\Param{xkanjiskip},~\Param{kanjiskip}は入り得る)ことである.\\
7483 \textit{id}が\textit{id\_hlist}か\textit{id\_disc}であって$\mathit{Np}.\mathit{head}$が\textbf{JAchar}であるとき.
7484
7485 \item[欧文] リスト中に直接/hboxの中身として出現している欧文文字.次の3つの場合が該当:
7486 \begin{itemize}
7487 \item \textit{id}が\textit{id\_glyph}である.
7488 \item \textit{id}が\textit{id\_math}である.
7489 \item \textit{id}が\textit{id\_pbox}か\textit{id\_hlist}か\textit{id\_disc}であって,$\mathit{Np}.\mathit{head}$が\textbf{ALchar}.
7490 \end{itemize}
7491 \item[箱] box,またはそれに類似するもの.次の2つが該当:
7492 \begin{itemize}
7493 \item \textit{id}が\textit{id\_pbox}か\textit{id\_hlist}か\textit{id\_disc}であって,$\mathit{Np}.\mathit{head}$が\textit{glyph\_node}でない.
7494 \item \textit{id}が\textit{id\_box\_like}である.
7495 \end{itemize}
7496
7497 \end{description}
7498
7499 \subsection{段落/hboxの先頭や末尾}
7500 \paragraph{先頭部の処理}
7501 まず,段落/hboxの一番最初にあるクラスタ\textit{Np}を探索する.
7502 hboxの場合は何の問題もないが,段落の場合では以下のノード達を事前に読み飛ばしておく:
7503 \begin{itemize}
7504 \item \cs{parindent} 由来のhbox($\mathit{subtype}=3$)
7505 \item \textit{subtype}が44~(\textit{user\_defined})でないようなwhatsit
7506 \end{itemize}
7507 これは,\cs{parindent}由来のhboxがクラスタを構成しないようにするためである.
7508
7509 次に,\textit{Np}の直前に空白$g$を必要なら挿入する:
7510 \begin{enumerate}
7511 \item この処理が働くような\textit{Np}は\textsf{和文A}である.
7512 \item 問題のリストが字下げありの段落(\cs{parindent} 由来のhboxあり)の場合は,
7513 この空白$g$は「文字コード \texttt{'parbdd'} の文字」と\textit{Np}の間に入るグルー/カーンである.
7514 \item そうでないとき(\verb+noindent+ で開始された段落やhbox)は,
7515 $g$は「文字コード \texttt{'boxbdd'} の文字」と\textit{Np}の間に入るグルー/カーンである.
7516 \end{enumerate}
7517 ただし,もし$g$がglueであった場合,この挿入によって\textit{Np}による行分割が新たに可能になるべきではない.
7518 そこで,以下の場合には,$g$の直前に \cs{penalty10000} を挿入する:
7519 \begin{itemize}
7520 \item 問題にしているリストが段落であり,かつ
7521 \item \textit{Np}の前には予めペナルティがなく,$g$はglue.
7522 \end{itemize}
7523
7524 \paragraph{末尾の処理}
7525 末尾の処理は,問題のリストが段落のものかhboxのものかによって異なる.
7526 後者の場合は容易い:最後のクラスタを\textit{Nq}とおくと,\textit{Nq}と「文字コード\
7527 \texttt{'boxbdd'} の文字」の間に入るグルー/カーンを,
7528 \textit{Nq}の直後に挿入するのみである.
7529
7530 一方.前者(段落)の場合は,リストの末尾は常に \cs{penalty10000} と,
7531 \cs{parfillskip} 由来のグルーが存在する.%よって,最後のクラスタ\textit{Np}は
7532 %この \cs{parfillskip} 由来のグルーとなり,実質的な中身の最後はその1つ前のクラスタ\textit{Nq}となる.
7533 段落の最後の「通常の和文文字${}+{}$句点」が独立した行となるのを防ぐために,
7534 \Param{jcharwidowpenalty}の値の分だけ適切な場所のペナルティを増やす.
7535
7536 ペナルティ量を増やす場所は,\textit{head}が\textbf{JAchar}であり,
7537 かつその文字の\Param{kcatcode}が偶数であるような
7538 最後のクラスタの直前にあるものたちである%
7539 \footnote{大雑把に言えば,\Param{kcatcode}が奇数であるような\textbf{JAchar}%
7540 を約物として考えていることになる.
7541 \Param{kcatcode}の最下位ビットはこの\Param{jcharwidowpenalty}用にのみ利用される.}.
7542
7543 \subsection{概観と典型例:2つの「和文A」の場合}
7544 \label{ssec-cluster-wa}
7545 先に述べたように,2つの隣り合ったクラスタ,\textit{Nq}と\textit{Np}の間には,
7546 ペナルティ,\cs{vadjust},whatsitなど,行組版には関係しないものがある.模式的に表すと,
7547 \[
7548  \Node{cluster}{\textit{Nq}}\longrightarrow
7549 \overbrace{
7550 \Node{penalty}{$p$}\longrightarrow \cdots\longrightarrow \Node{whatsit}{}}^{\textrm{(a)}}
7551 \longrightarrow \Node{cluster}{\textit{Np}}
7552 \]
7553 のようになっている.間の(a)に相当する部分には,何のノードもない場合ももちろんあり得る.
7554 そうして,JFMグルー挿入後には,この2クラスタ間は次のようになる:
7555 \[
7556  \Node{cluster}{\textit{Nq}}\longrightarrow%\Node{kern}{左空白}\longrightarrow
7557 \overbrace{
7558 \Node{penalty}{$p+x$}\longrightarrow \cdots\longrightarrow
7559 \Node{whatsit}{}}^{\textrm{(a)}}\longrightarrow
7560 \Node{glue or kern}{\raisebox{-.2\zw}{右空白}}\longrightarrow
7561 \Node{cluster}{\textit{Np}}
7562 \]
7563
7564 以後,\emph{典型的な例として,クラスタ\textit{Nq}と\textit{Np}が共に\textsf{\textmd{和文A}}である場合を見ていこう,}
7565 この場合が全ての場合の基本となる.
7566
7567 \paragraph{「右空白」の算出}
7568 まず,「右空白」にあたる量を算出する.通常はこれが,隣り合った2つの和文文字間に入る空白量となる.
7569 \begin{description}
7570 \item[JFM由来{[M]}] JFMの文字クラス指定によって入る空白を以下によって求める.この段階で空白量が未定義(未指定)だった場合,
7571       デフォルト値\Param{kanjiskip}を採用することとなるので,次へ.
7572 \begin{enumerate}
7573 \item もし両クラスタの間で \cs{inhibitglue} が実行されていた場合(証としてwhatsitノードが自動挿入される),
7574       代わりに\Param{kanjiskip}が挿入されることとなる.次へ.
7575 \item \textit{Nq}と\textit{Np}が同じJFM・同じ\texttt{jfmvar}キー・同じサイズの和文フォントであったならば,
7576       共通に使っているJFM内で挿入される空白(グルーかカーン)が決まっているか調べ,決まっていればそれを採用.
7577 \item 1.でも2.でもない場合は,JFM・\texttt{jfmvar}・サイズの3つ組は\textit{Nq}と\textit{Np}で異なる.
7578 この場合,まず
7579 \[
7580 \vcenter{\halign{\hfil$#:={}$&\inhibitglue#\inhibitglue\cr
7581 gb&(\textit{Nq}と「使用フォントが\textit{Nq}のそれと同じで,\hfil\cr
7582 \omit&\quad 文字コードが\textit{Np}のそれの文字」との間に入るグルー/カーン)\hfil\cr
7583 ga&(\inhibitglue 「使用フォントが\textit{Np}のそれと同じで,\hfil\cr
7584 \omit&\quad 文字コードが\textit{Nq}のそれの文字」と\textit{Np}との間に入るグルー/カーン)\hfil\cr
7585 }}
7586 \]
7587 として,前側の文字のJFMを使った時の空白(グルー/カーン)と,後側の文字のJFMを使った時のそれを求める.
7588
7589 $\mathit{gb}$,~$\mathit{ga}$それぞれに対する<ratio>の値を$d_b$,~$d_a$とする.
7590 \begin{itemize}
7591 \item
7592 $\mathit{ga}$と$\mathit{gb}$の両方が未定義であるならば,JFM由来のグルーは挿入されず,
7593 \Param{kanjiskip}を採用することとなる.
7594 どちらか片方のみが未定義であるならば,次のステップでその未定義の方は長さ0のkernで,<ratio>の値は0であるかのように扱われる.
7595 \item
7596 \Param{diffrentjfm}の値が \texttt{pleft}, \texttt{pright},
7597       \texttt{paverage} のとき,
7598 <ratio>の指定に従って比例配分を行う.
7599 JFM由来のグルー/カーンは以下の値となる:
7600 \[
7601  f\left(\frac{1-d_b}2\textit{gb} + \frac{1+d_b}2\textit{ga},
7602 \frac{1-d_a}2\textit{gb} + \frac{1+d_a}2\textit{ga}\right)
7603 \]
7604 ここで.$f(x,y)$は
7605 \[
7606  f(x,y)=\begin{cases}
7607 x&\text{if\ }\Param{diffrentjfm}=\texttt{pleft};\\
7608 y&\text{if\ }\Param{diffrentjfm}=\texttt{pright};\\
7609 (x+y)/2&\text{if\ }\Param{diffrentjfm}=\texttt{paverage};
7610 \end{cases}.
7611 \]
7612 \item
7613 \Param{differentjfm}がそれ以外の値の時は,<ratio>の値は無視され,JFM由来のグルー/カーンは以下の値となる:
7614 \[
7615  f(\textit{gb},\textit{ga})
7616 \]
7617 ここで.$f(x,y)$は
7618 \[
7619  f(x,y)=\begin{cases}
7620 \min(x,y)&\text{if\ }\Param{diffrentjfm}=\texttt{small};\\
7621 \max(x,y)&\text{if\ }\Param{diffrentjfm}=\texttt{large};\\
7622 (x+y)/2&\text{if\ }\Param{diffrentjfm}=\texttt{average};\\
7623 x+y&\text{if\ }\Param{diffrentjfm}=\texttt{both};
7624 \end{cases}.
7625 \]
7626 \end{itemize}
7627 \end{enumerate}
7628
7629 例えば,
7630 \begin{lstlisting}
7631 \jfont\foo=psft:Ryumin-Light:jfm=ujis;-kern
7632 \jfont\bar=psft:GothicBBB-Medium:jfm=ujis;-kern
7633 \jfont\baz=psft:GothicBBB-Medium:jfm=ujis;jfmvar=piyo;-kern
7634 \end{lstlisting}
7635 という3フォントを考え,
7636 \[
7637  \overbrace{\Node{glyph}{\cs{ foo}, `あ'}}^{p}
7638 \longrightarrow \overbrace{\Node{glyph}{\cs{bar}, `い'}}^{q}
7639 \longrightarrow \overbrace{\Node{glyph}{\cs{baz}, `う'}}^{r}
7640 \]
7641 という3ノードを考える(それぞれ単独でクラスタをなす).
7642 この場合,$p$と$q$の間は,実フォントが異なるにもかかわらず2.の状況となる一方で,
7643 $q$と$r$の間は(実フォントが同じなのに)\texttt{jfmvar} キーの内容が異なるので3.の状況となる.
7644 \item[\Param{kanjiskip}~{[K]}] 上の[M]において空白が定まらなかった場合,
7645 以下で定めた量「右空白」として採用する.
7646 この段階においては,\cs{inhibitglue} は効力を持たないため,
7647 結果として,2つの和文文字間には常に何らかのグルー/カーンが挿入されることとなる.
7648 \begin{enumerate}
7649 \item 両クラスタ(厳密には$\mathit{Nq}.\mathit{tail}$,$\mathit{Np}.\mathit{head}$)の中身の文字コードに対する
7650 \Param{autospacing}パラメタが両方ともfalseだった場合は,長さ0のglueとする.
7651 \item ユーザ側から見た\Param{kanjiskip}パラメタの自然長が$\cs{maxdimen}=(2^{30}-1)\,{\rm sp}$で
7652 なければ,\Param{kanjiskip}パラメタの値を持つglueを採用する.
7653 \item 2.でない場合は,\textit{Nq}, \textit{Np}で使われているJFMに指定されている\Param{kanjiskip}の値を用いる.
7654 どちらか片方のクラスタだけが和文文字(\textsf{和文A}・\textsf{和文B})のときは,そちらのクラスタで使われている
7655 JFM由来の値だけを用いる.もし両者で使われているJFMが異なった場合は,上の[M]~3.と同様の方法を用いて調整する.
7656 \end{enumerate}
7657 \end{description}
7658 %\paragraph{「左空白」の算出とそれに伴う補正}
7659 %「左空白」は過去のバージョンでは定義していたが,このバージョンでは
7660 %挿入は一切行われない(機能自体削除している).
7661 %しかし,仕様は流動的であり,将来復活する可能性もあるため,マニュアル中の記述は今のところ極力変更しない.
7662 \paragraph{禁則用ペナルティの挿入}
7663 まず,
7664 \[
7665  a:=(\text{\textit{Nq}{\footnotemark}の文字に対する\Param{postbreakpenalty}の値})
7666 +(\text{\textit{Np}{\footnotemark}の文字に対する\Param{prebreakpenalty}の値})
7667 \]
7668 とおく\footnotetext{厳密にはそれぞれ$\mathit{Nq}.\mathit{tail}$,$\mathit{Np}.\mathit{head}$.}.
7669 ペナルティは通常$[-10000,10000]$の整数値をとり,また$\pm 10000$は正負の無限大を意味することになっているが,この$a$の
7670 算出では単純な整数の加減算を行う.
7671
7672 $a$は禁則処理用に\textit{Nq}と\textit{Np}の間に加えられるべきペナルティ量である.
7673 \begin{description}
7674 \item[P-normal~{[PN]}]
7675 \textit{Nq}と\textit{Np}の間の(a)部分にペナルティ(\textit{penalty\_node})があれば処理は簡単である:
7676 それらの各ノードにおいて,ペナルティ値を($\pm 10000$を無限大として扱いつつ)$a$だけ増加させればよい.
7677 また,$10000 + (-10000) = 0$としている.
7678
7679 少々困るのは,(a)部分にペナルティが存在していない場合である.
7680 直感的に,補正すべき量$a$が0でないとき,その値をもつ\textit{penalty\_node}を作って
7681 「右空白」の(もし未定義なら\textit{Np}の)直前に挿入……
7682 ということになるが,実際には僅かにこれより複雑である.
7683 \begin{itemize}
7684 \item 「右空白」がカーンであるとき,
7685 それは「\textit{Nq}と\textit{Np}の間で改行は許されない」ことを意図している.そのため,
7686 この場合は$a\neq 0$であってもペナルティの挿入はしない.
7687 \item そうでないないときは,$a\neq 0$ならば\textit{penalty\_node}を作って挿入する.
7688 %\item 「左空白」がカーンとしてきっちり定義されている時(このとき,「右空白」はカーンでない),
7689 %この「左空白」の直後での行分割を許容しないといけないので,$a=0$であっても
7690 %\textit{penalty\_node}を作って挿入する.
7691 %\item 以上のどれでもないときは,$a\neq 0$ならば\textit{penalty\_node}を作って挿入する.
7692 \end{itemize}
7693 \end{description}
7694
7695 \def\gkf#1#2#3{\sf$\displaystyle\vphantom{\Bigg(}%
7696   \frac{\hbox to 4\zw{\hss#2\hss}}{\hbox{#3}}$}
7697 \begin{table}[t]
7698 %<en>\caption{Summary of JFM glues}
7699 %<ja>\caption{JFM グルーの概要}
7700 \label{tab-jfmglue}
7701 %<en>\medskip
7702 \begin{center}
7703 \small
7704 \begin{tabular}{c|cccccc}
7705 \toprule
7706 {\bf\textit{Np}}↓&\sf 和文A&\sf 和文B&\sf 欧文&\sf 箱&\sf glue&\sf kern\\\midrule
7707 \sf 和文A&
7708 \gkf{E}{M→K}{PN}&
7709 \gkf{---}{\OA →K}{PN}&
7710 \gkf{---}{\OA →X}{PN}&
7711 \gkf{---}{\OA}{PA}&
7712 \gkf{---}{\OA}{PN}&
7713 \gkf{---}{\OA}{PS}\\
7714 \sf 和文B&
7715 \gkf{E}{\OB→K}{PA}&
7716 \gkf{---}{K}{PS}&
7717 \gkf{---}{X}{PS}\\
7718 \sf 欧文&
7719 \gkf{E}{\OB →X}{PA}&
7720 \gkf{---}{X}{PS}\cr
7721 \sf 箱&\gkf{E}{\OB}{PA}\\
7722 \sf glue&\gkf{E}{\OB}{PN}\\
7723 \sf kern&\gkf{E}{\OB}{PS}\\
7724 \bottomrule
7725 \end{tabular}
7726 \end{center}
7727 \begin{quote}
7728 %<*en>
7729 In the table above, {\small\gkf{E}{M→K}{PN}} means that
7730 %</en>
7731 %<*ja>
7732 上の表において,{\small\gkf{E}{M→K}{PN}}は次の意味である:
7733 %</ja>
7734 \begin{enumerate}
7735 %<*en>
7736 \item To determine the ``right-space'', \LuaTeX-ja first attempts by the method ``\textsf{JFM-origin~[M]}''.
7737 If this attempt fails, \LuaTeX-ja use the method ``\textsf{\Param{kanjiskip}~[K]}''.
7738 %</en>
7739 %<*ja>
7740 \item 「右空白」を決めるために,\LuaTeX-ja はまず「JFM由来{[M]}」の方法を試みる.
7741   これが失敗したら,\LuaTeX-ja は「\Param{kanjiskip}~{[K]}」の方法を試みる.
7742 %</ja>
7743
7744 % %<*en>
7745 % \item The ``left space'' between \textit{Nq}~and~\textit{Np} is
7746 %   determined by the method ``\textsf{line-end~[E]}''.
7747 % %</en>
7748 % %<*ja>
7749 % \item \textit{Nq} と \textit{Np} の間の「左空白」は「\textsf{line-end~[E]}」の
7750 %   方法で決定される.
7751 % %</ja>
7752
7753 %<*en>
7754 \item \LuaTeX-ja adopts the method ``\textsf{P-normal~[PN]}'' to adjust the penalty
7755   between two clusters for \emph{kinsoku shori}.
7756 %</en>
7757 %<*ja>
7758 \item \LuaTeX-jaは2つのクラスタの間の禁則処理用のペナルティを設定するために「\textsf{P-normal~[PN]}」の方法を採用する.
7759 %</ja>
7760 \end{enumerate}
7761 \end{quote}
7762 \end{table}
7763
7764 \subsection{その他の場合}
7765 本節の内容は表\ref{tab-jfmglue}にまとめてある.
7766
7767 \paragraph{和文Aと欧文の間}
7768 \textit{Nq}が\textsf{和文A}で,\textit{Np}が\textsf{欧文}の場合,JFMグルー挿入処理は次のようにして行われる.
7769 \begin{itemize}
7770 \item 「右空白」については,まず以下に述べる\textsf{Boundary-B~[\OB]}により空白を決定しようと試みる.
7771 それが失敗した場合は,\textsf{\Param{xkanjiskip}~[X]}によって定める.
7772 %\item 「左空白」については,既に述べた\textsf{line-end~[E]}をそのまま採用する.それに伴う「右空白」の補正も%同じ.
7773 \item 禁則用ペナルティも,以前述べた\textsf{P-normal~[PN]}と同じである.
7774 \end{itemize}
7775 \begin{description}
7776 \item[Boundary-B~{[\OB]}] 和文文字と「和文でないもの」との間に入る空白を以下によって求め,
7777 未定義でなければそれを「右空白」として採用する.
7778 \textsf{JFM-origin~[M]}の変種と考えて良い.
7779 これによって定まる空白の典型例は,和文の閉じ括弧と欧文文字の間に入る半角アキである.
7780 \begin{enumerate}
7781 \item もし両クラスタの間で \cs{inhibitglue} が実行されていた場合%
7782 (証としてwhatsitノードが自動挿入される),「右空白」は未定義.
7783 \item そうでなければ,
7784 \textit{Nq}と「文字コードが {\tt'jcharbdd'} の文字」との間に入るグルー/カーンとして定まる.
7785 \end{enumerate}
7786 \item[\Param{xkanjiskip}~{[X]}]
7787 この段階では,\textsf{\Param{kanjiskip}~[K]}のときと同じように,
7788 以下で定めた量を「右空白」として採用する.
7789 \cs{inhibitglue} は効力を持たない.
7790 \begin{enumerate}
7791 \item 以下のいずれかの場合は,\Param{xkanjiskip}の挿入は抑止される.しかし,実際には行分割を許容するために,長さ0のglueを採用する:
7792 \begin{itemize}
7793 \item 両クラスタにおいて,それらの中身の文字コードに対する\Param{autoxspacing}パラメタが共にfalseである.
7794 \item \textit{Nq}の中身の文字コードについて,「直後への\Param{xkanjiskip}の挿入」が禁止されている
7795 (つまり,\Param{jaxspmode}~(or \Param{alxspmode})パラメタが2以上).
7796 \item \textit{Np}の中身の文字コードについて,「直前への\Param{xkanjiskip}の挿入」が禁止されている
7797 (つまり,\Param{jaxspmode}~(or \Param{alxspmode})パラメタが偶数).
7798 \end{itemize}
7799 \item ユーザ側から見た\Param{xkanjiskip}パラメタの自然長が$\cs{maxdimen}=(2^{30}-1)\,{\rm sp}$で
7800 なければ,\Param{xkanjiskip}パラメタの値を持つglueを採用する.
7801 \item 2.でない場合は,\textit{Nq}, \textit{Np}(\textsf{和文A}/\textsf{和文B}なのは片方だけ)
7802 で使われているJFMに指定されている\Param{xkanjiskip}の値を用いる.
7803 \end{enumerate}
7804 \end{description}
7805
7806 \paragraph{欧文と和文Aの間}
7807 \textit{Nq}が\textsf{欧文}で,\textit{Np}が\textsf{和文A}の場合,JFMグルー挿入処理は上の場合とほぼ同じである.
7808 \textsf{和文A}のクラスタが逆になるので,\textsf{Boundary-A~[\OA]}の部分が変わるだけ.
7809 \begin{itemize}
7810 \item 「右空白」については,まず以下に述べる\textsf{Boundary-A~[\OA]}により空白を決定しようと試みる.
7811 それが失敗した場合は,\textsf{\Param{xkanjiskip}~[X]}によって定める.
7812 %\item \textit{Nq}が和文でないので,「左空白」は算出されない.
7813 \item 禁則用ペナルティは,以前述べた\textsf{P-normal~[PN]}と同じである.
7814 \end{itemize}
7815 \begin{description}
7816 \item[Boundary-A~{[\OA]}] 「和文でないもの」と和文文字との間に入る空白を以下によって求め,
7817 未定義でなければそれを「右空白」として採用する.
7818 \textsf{JFM-origin~[M]}の変種と考えて良い.
7819 これによって定まる空白の典型例は,欧文文字と和文の開き括弧との間に入る半角アキである.
7820 \begin{enumerate}
7821 \item もし両クラスタの間で \cs{inhibitglue} が実行されていた場合(証としてwhatsitノードが自動挿入される),次へ.
7822 \item そうでなければ,
7823 「文字コードが {\tt'jcharbdd'} の文字」と\textit{Np}との間に入るグルー/カーンとして定まる.
7824 \end{enumerate}
7825 \end{description}
7826
7827 \paragraph{和文Aと箱・グルー・カーンの間}
7828 \textit{Nq}が\textsf{和文A}で,\textit{Np}が\textsf{箱}・グルー・カーンのいずれかであった場合,
7829 両者の間に挿入されるJFMグルーについては同じ処理である.しかし,そこでの行分割に対する仕様が異なるので,
7830 ペナルティの挿入処理は若干異なったものとなっている.
7831
7832 \begin{itemize}
7833 \item 「右空白」については,既に述べた\textsf{Boundary-B~[\OB]}により空白を決定しようと試みる.
7834 それが失敗した場合は,「右空白」は挿入されない.
7835 %\item 「左空白」については,既に述べた\textsf{line-end~[E]}の算出方法をそのまま採用する.それに伴う「右空白」の補正も同じ.
7836 \item 禁則用ペナルティの処理は,後ろのクラスタ\textit{Np}の種類によって異なる.
7837 なお,$\mathit{Np}.\mathit{head}$は無意味であるから,
7838 「$\mathit{Np}.\mathit{head}$に対する\Param{prebreakpenalty}の値」は0とみなされる.言い換えれば,
7839 \[
7840  a:=(\text{\textit{Nq}の文字に対する\Param{postbreakpenalty}の値}).
7841 \]
7842 \begin{description}
7843 \item[箱] \textit{Np}が\textsf{箱}であった場合は,両クラスタの間での行分割は
7844 (明示的に両クラスタの間に \cs{penalty10000} があった場合を除き)いつも許容される.そのため,
7845 ペナルティ処理は,後に述べる\textsf{P-allow~[PA]}が\textsf{P-normal~[PN]}の代わりに用いられる.
7846 \item[グルー] \textit{Np}がグルーの場合,ペナルティ処理は\textsf{P-normal~[PN]}を用いる.
7847 \item[カーン] \textit{Np}がカーンであった場合は,両クラスタの間での行分割は
7848 (明示的に両クラスタの間にペナルティがあった場合を除き)許容されない.
7849 ペナルティ処理は,後に述べる\textsf{P-suppress~[PS]}を使う.
7850 \end{description}
7851 これらの\textsf{P-normal~[PN]},\textsf{P-allow~[PA]},\textsf{P-suppress~[PS]}の違いは,
7852 \textit{Nq}と\textit{Np}の間(以前の図だと(a)の部分)にペナルティが存在しない場合にのみ存在する.
7853 \end{itemize}
7854
7855 \begin{description}
7856 \item[P-allow~{[PA]}]
7857 \textit{Nq}と\textit{Np}の間の(a)部分にペナルティがあれば,\textsf{P-normal~[PN]}と同様に,
7858 それらの各ノードにおいてペナルティ値を$a$だけ増加させる.
7859
7860 (a)部分にペナルティが存在していない場合,
7861 \LuaTeX-ja は\textit{Nq}と\textit{Np}の間の行分割を可能にしようとする.
7862 そのために,以下のいずれかの場合に$a$をもつ\textit{penalty\_node}を作って
7863 「右空白」の(もし未定義なら\textit{Np}の)直前に挿入する:
7864 \begin{itemize}
7865 \item 「右空白」がグルーでない(カーンか未定義)であるとき.
7866 \item $a\neq 0$のときは,「右空白」がグルーであっても\textit{penalty\_node}を作る.
7867 \end{itemize}
7868
7869 \item[P-suppress~{[PS]}]
7870 \textit{Nq}と\textit{Np}の間の(a)部分にペナルティがあれば,\textsf{P-normal~[PN]}と同様に,
7871 それらの各ノードにおいてペナルティ値を$a$だけ増加させる.
7872
7873 (a)部分にペナルティが存在していない場合,
7874 \textit{Nq}と\textit{Np}の間の行分割は元々不可能のはずだったのであるが,
7875 \LuaTeX-ja はそれをわざわざ行分割可能にはしない.
7876 そのため,「右空白」がglueであれば,その直前に \cs{penalty10000} を挿入する.
7877 \end{description}
7878
7879 なお,「右空白」はカーンの%,「左空白」は未定義の
7880 \[
7881  \overbrace{\Node{glyph}{`あ'}}^{\mathit{Nq}}\longrightarrow \overbrace{\Node{glue}{1\,pt}}^{\mathit{Np}}
7882 \]
7883 のような状況を考える.
7884 このとき,$a$,即ち「あ」の\Param{postbreakpenalty}がいかなる値であっても,
7885 この2クラスタ間は最終的に
7886 \begin{equation}
7887  \overbrace{\Node{glyph}{`あ'}}^{\mathit{Nq}}\longrightarrow
7888 \Node{kern}{右空白}\longrightarrow \overbrace{\Node{glue}{1\,pt}}^{\mathit{Np}}
7889 \label{eq-gref}
7890 \end{equation}
7891 となり,$a$分のペナルティは挿入されないことに注意して欲しい.
7892 \Param{postbreakpenalty}は($a$は)殆どの場合が非負の値と考えられ,そのような場合では
7893 \eqref{eq-gref}と
7894 \[
7895  \overbrace{\Node{glyph}{`あ'}}^{\mathit{Nq}}\longrightarrow
7896 \Node{penalty}{$a$}\longrightarrow
7897 \Node{kern}{右空白}\longrightarrow \overbrace{\Node{glue}{1\,pt}}^{\mathit{Np}}
7898 \]
7899 との間に差異は生じない%
7900 \footnote{kern$\rightarrow$glueが1つの行分割可能点(行分割に伴うペナルティは0)
7901 であるため,たとえ$a=10000$であっても,\textit{Nq}と\textit{Np}の間で行分割を禁止することはできない.}.
7902
7903 \paragraph{箱・グルー・カーンと和文Aの間}
7904 \textit{Np}が\textsf{箱}・グルー・カーンのいずれかで,\textit{Np}が\textsf{和文A}であった場合は,
7905 すぐ上の(\textit{Nq}と\textit{Np}の順序が逆になっている)場合と同じである.
7906 %が,「左空白」がなくなることにのみ注意.
7907 \begin{itemize}
7908 \item 「右空白」については,既に述べた\textsf{Boundary-A~[\OA]}により空白を決定しようと試みる.
7909 それが失敗した場合は,「右空白」は挿入されない.
7910 %\item \textit{Nq}が和文でないので,「左空白」は算出されない.
7911 \item 禁則用ペナルティの処理は,\textit{Nq}の種類によって異なる.
7912 $\mathit{Nq}.\mathit{tail}$は無意味なので,
7913 \[
7914  a:=(\text{\textit{Np}の文字に対する\Param{prebreakpenalty}の値}).
7915 \]
7916 \begin{description}
7917 \item[箱] \textit{Nq}が\textsf{箱}の場合は,\textsf{P-allow~[PA]}を用いる.
7918 \item[グルー] \textit{Nq}がグルーの場合は,\textsf{P-normal~[PN]}を用いる.
7919 \item[カーン] \textit{Nq}がカーンの場合は,\textsf{P-suppress~[PS]}を用いる.
7920 \end{description}
7921 \end{itemize}
7922
7923 \paragraph{和文Aと和文Bの違い}
7924 先に述べたように,\textsf{和文B}はhboxの中身の先頭(or 末尾)として出現している
7925 和文文字である.リスト内に直接ノードとして現れている和文文字(\textsf{和文A})との違いは,
7926 \begin{itemize}
7927 \item \textsf{和文B}に対しては,JFMの文字クラス指定から定まる空白
7928 \textsf{JFM-origin~[M]},\textsf{Boundary-A~[\OA]},\textsf{Boundary-B~[\OB]})の挿入は行われない.
7929 %「左空白」の算出も行われない.
7930 例えば,
7931 \begin{itemize}
7932 \item 片方が\textsf{和文A},もう片方が\textsf{和文B}のクラスタの場合,
7933 \textsf{Boundary-A~[\OA]}または\textsf{Boundary-B~[\OB]}の挿入を試み,それがダメなら
7934 \Param{kanjiskip}~\textsf{[K]}の挿入を行う.
7935 \item \textsf{和文B}の2つのクラスタの間には,\Param{kanjiskip}~\textsf{[K]}が自動的に入る.
7936 \end{itemize}
7937 \item \textsf{和文B}と箱・グルー・カーンが隣接したとき(どちらが前かは関係ない),間にJFMグルー・ペナルティの挿入は一切しない.
7938 \item \textsf{和文B}と\textsf{和文B},また\textsf{和文B}と\textsf{欧文}とが隣接した時は,禁則用ペナルティ挿入処理は
7939 \textsf{P-suppress~[PS]}が用いられる.
7940 \item \textsf{和文B}の文字に対する\Param{prebreakpenalty},~\Param{postbreakpenalty}の値は使われず,0として計算される.
7941 \end{itemize}
7942
7943
7944 次が具体例である:
7945 \begin{LTXexample}
7946 あ.\inhibitglue A\\
7947 \hbox{あ.}A\\
7948 あ.A
7949 \end{LTXexample}
7950 \begin{itemize}
7951 \item 1行目の\cs{inhibitglue}は\textsf{Boundary-B~[\OB]}の処理のみを抑止するので,ピリオドと「A」の間には
7952 \Param{xkanjiskip}(四分アキ)が入ることに注意.
7953 \item 2行目のピリオドと「A」の間においては,前者が\textsf{和文B}となる(hboxの中身の末尾として登場しているから)ので,
7954 そもそも\textsf{Boundary-B~[\OB]}の処理は行われない.よって,\Param{xkanjiskip}が入ることとなる.
7955 \item 3行目では,ピリオドの属するクラスタは\textsf{和文A}である.これによって,
7956 ピリオドと「A」の間には\textsf{Boundary-B~[\OB]}由来の半角アキが入ることになる.
7957 \end{itemize}
7958 %</ja>
7959
7960 %<en>\section{Patch for the \Pkg{listings} Package}
7961 %<ja>\section{\Pkg{listings} パッケージへの対応}
7962
7963 %<*en>
7964 It is well-known that the \Pkg{listings} package outputs weird results
7965 for Japanese input.
7966 The \Pkg{listings} package makes most of letters active and assigns
7967 output command for each letter~(\cite{listings}).
7968 But Japanese characters are not included in these activated letters.
7969 For \pTeX{} series, there is no method to make Japanese characters active;
7970 a patch \Pkg{jlisting.sty}~(\cite{jlisting}) resolves the problem forcibly.
7971 %</en>
7972 %<*ja>
7973 \Pkg{listings} パッケージが,そのままでは日本語をまともに出力できないこと
7974 はよく知られている.きちんと整形して出力するために,\Pkg{listings}パッケー
7975 ジは内部で「ほとんどの文字」をアクティブにし,各文字に対してその文字の出
7976 力命令を割り当てている(\cite{listings}).
7977 しかし,そこでアクティブにする文字の中に,和文文
7978 字がないためである.\pTeX 系列では,和文文字をアクティブにする手法がなく,
7979 \Pkg{jlisting.sty} というパッチ(\cite{jlisting})を用いることで無理やり解決していた.
7980 %</ja>
7981
7982 %<*en>
7983 In \LuaTeX-ja, the problem is resolved by using the \verb+process_input_buffer+ callback.
7984 The callback function inserts the output command (active character \texttt{U+FFFFF})
7985 before each letter above \texttt{U+0080}.
7986 This method can omits the process to make all Japanese characters active
7987 (most of the activated characters are not used in many cases).
7988 %</en>
7989 %<*ja>
7990 \LuaTeX-jaでは,\verb+process_input_buffer+ コールバックを利用することで,
7991 「各行に出現する\texttt{U+0080}以降の文字に対して,それらの出力命令を前置する」
7992 という方法をとっている.出力命令としては,アクティブ文字化した \texttt{U+FFFFF} を用いている.
7993 これにより,(入力には使用されていないかもしれない)和文文字をもすべてアクティブ化する手間もなく,
7994 見通しが良い実装になっている.
7995 %</ja>
7996
7997
7998 %<*en>
7999 If the \Pkg{listings} package  and \LuaTeX-ja were loaded,
8000 then the patch \Pkg{lltjp-listings} is loaded automatically at \verb+\begin{document}+.
8001 %</en>
8002 %<*ja>
8003 \LuaTeX-ja で利用される \Pkg{listings} パッケージへのパッチ \Pkg{lltjp-listings} は,
8004 \Pkg{listings} と\LuaTeX-jaを読み込んでおけば,
8005 \verb+\begin{document}+ の箇所において自動的に読み込まれるので,通常はあまり
8006 意識する必要はない.
8007 %</ja>
8008
8009 %<en>\subsection{Notes}
8010 %<ja>\subsection{注意}
8011 %<*en>
8012 \paragraph{Escaping to \LaTeX}
8013 We used the \verb+process_input_buffer+ callback to output \textbf{JAchar}s.
8014 But it has a drawback; any commands whose name contains a \textbf{JAchar}
8015 cannot be used in any ``escape to \LaTeX''.
8016
8017 Consider the following input:
8018 %</en>
8019 %<*ja>
8020 \paragraph{\LaTeX へのエスケープ}
8021 日本語対応を行うために \verb+process_input_buffer+ を使用したことで,
8022 \texttt{texcl},~\texttt{escapeinside}といった\emph{「\LaTeX へのエスケープ」中では,
8023 \textbf{JAchar}を名称の一部に含む制御綴は使用不可能}である.
8024 例えば次のような入力を考えよう:
8025 %</ja>
8026 \begin{verbatim*}
8027 \begin{lstlisting}[escapechar=\#]
8028 #\ほげ xぴよ#
8029 \end{lstlisting}
8030 \end{verbatim*}
8031 %<en>The line~2 is transformed by the callback to
8032 %<ja>ここで,2行目は \verb+process_input_buffer+ の作用により,
8033 \begin{lstlisting}[showspaces, escapechar=\!]
8034 #\!\IVSA FFFFF!ほ!\IVSA FFFFF!げ x!\IVSA FFFFF!ぴ!\IVSA FFFFF!よ#
8035 \end{lstlisting}
8036 %<*en>
8037 before the line is actually processed.
8038 In the escape (between the character ``\verb+#+''),
8039 the category code of \texttt{U+FFFFF} is set to 9~(\emph{ignored}).
8040 Hence the control symbol ``\cs{}\IVSA FFFFF'' will be executed,
8041 instead of ``\verb+\ほげ+''.
8042 %</en>
8043 %<*ja>
8044 と変換されてから,実際の処理に回される.
8045 「\verb+#+」で挟まれた「\LaTeX へのエスケープ」中では\
8046 \texttt{U+FFFFF} のカテゴリーコードは9~(\textit{ignored})となるので,
8047 結局「\verb+\ほげ+」の代わりに
8048 「\cs{}\IVSA FFFFF」というcontrol symbolが実行されることになる.
8049 %</ja>
8050
8051 %<*ja>
8052 \paragraph{異体字セレクタの扱い}
8053 \texttt{lstlisting} 環境などの内部にある異体字セレクタを扱うため,
8054 \Pkg{lltjp-listings} では \texttt{vsraw} と \texttt{vscmd} という2つのキーを追加した.
8055 しかし,\Pkg{lltjp-listings} が実際に読み込まれるのは \verb+\begin{document}+\
8056 のところであるので,プリアンブル内ではこれらの追加キーは使用できない.
8057
8058 \texttt{vsraw}は,ブール値の値をとるキーであり,標準ではfalseである.
8059 \begin{itemize}
8060  \item trueの場合は,異体字セレクタは「直前の文字に続けて」出力される.
8061 もしもIVSサポート(\ref{ssec-ltjotf}節)が有効になっていた場合は,
8062 以下の例(左側は入力,右側はその出力)のようになる.
8063 \begin{LTXexample}
8064 \begin{lstlisting}[vsraw=true]
8065 葛󠄀城市,葛󠄁飾区,葛西
8066 \end{lstlisting}
8067 \end{LTXexample}
8068 \item falseの場合は,異体字セレクタは適当な命令によって「見える形で」出力される.
8069 どのような形で出力されるかを規定するのが \texttt{vscmd} キーであり,
8070 \Pkg{lltjp-listings} の標準設定では以下の例の右側のように出力される.
8071 \begin{LTXexample}
8072 \begin{lstlisting}[vsraw=false,
8073    vscmd=\ltjlistingsvsstdcmd]
8074 葛󠄀城市,葛󠄁飾区,葛西
8075 \end{lstlisting}
8076 \end{LTXexample}
8077 ちなみに,本ドキュメントでは次のようにしている:
8078 \begin{lstlisting}[numbers=left]
8079 \def\IVSA#1#2#3#4#5{%
8080   \textcolor{blue}{\raisebox{3.5pt}{\tt%
8081     \fboxsep=0.5pt\fbox{\tiny \oalign{0#1#2\crcr#3#4#5\crcr}}}}%
8082 }
8083 {\catcode`\%=11
8084   \gdef\IVSB#1{\expandafter\IVSA\directlua{
8085     local cat_str = luatexbase.catcodetables['string']
8086     tex.sprint(cat_str, string.format('%X', 0xE00EF+#1))
8087 }}}
8088 \lstset{vscmd=\IVSB}
8089 \end{lstlisting}
8090 \end{itemize}
8091 既定の出力命令を復活させたい場合は\ \verb+vsraw=\ltjlistingsvsstdcmd+\
8092 とすれば良い.
8093 %</ja>
8094
8095 %<en>\subsection{Class of Characters}
8096 %<ja>\subsection{文字種}
8097
8098 %<en>Roughly speaking, the \Pkg{listings} package processes input as follows:
8099 %<ja>\Pkg{listings} パッケージの内部では,大雑把に言うと
8100 \begin{enumerate}
8101 %<en>\item Collects \textit{letters} and \textit{digits}, which can be used for the name of identifiers.
8102 %<ja>\item 識別子として使える文字 (``letter'',~``digit'') たちを集める.
8103 %<en>\item When reading an \textit{other}, outputs the collected character string (with modification, if needed).
8104 %<ja>\item letterでもdigitでもない文字が現れた時に,収集した文字列を(必要なら修飾して)出力する.
8105 %<en>\item Collects \textit{others}.
8106 %<ja>\item 今度は逆に,letterでない文字たちをletterが現れるまで集める.
8107 %<en>\item When reading a \textit{letter} or a \textit{digit}, outputs the collected character string.
8108 %<ja>\item letterが出現したら集めた文字列を出力する.
8109 %<en>\item Turns back to 1.
8110 %<ja>\item 1.に戻る.
8111 \end{enumerate}
8112 %<*en>
8113 By the above process, line breaks inside of an identifier are blocked.
8114 A flag \verb+\lst@ifletter+ indicates whether the previous character can be used
8115 for the name of identifiers or not.
8116 %</en>
8117 %<*ja>
8118 という処理が行われている.これにより,識別子の途中では行分割が行われないようになっている.
8119 直前の文字が識別子として使えるか否かは \verb+\lst@ifletter+ というフラグに格納されている.
8120 %</ja>
8121
8122 %<*en>
8123 For Japanese characters, line breaks are permitted on both sides
8124 except for brackets, dashes, etc.
8125 Hence the patch \Pkg{lltjp-listings} introduces
8126 a new flag \verb+\lst@ifkanji+, which indicates
8127 whether the previous character is a Japanese character or not.
8128 For illustration, we introduce following classes of characters:
8129 %</en>
8130 %<*ja>
8131 さて,日本語の処理である.殆どの和文文字の前後では行分割が可能であるが,その一方で
8132 括弧類や音引きなどでは禁則処理が必要なことから,\Pkg{lltjp-listings} では,
8133 直前が和文文字であるかを示すフラグ \verb+\lst@ifkanji+ を新たに導入した.
8134 以降,説明のために以下のように文字を分類する:
8135 %</ja>
8136 \begin{center}
8137 \small
8138 \begin{tabular}{lccccc}
8139 \toprule
8140 &Letter&Other&Kanji&Open&Close\\\midrule
8141 \verb+\lst@ifletter+&T&F&T&F&T\\
8142 \verb+\lst@ifkanji+&F&F&T&T&F\\
8143 %<en>Meaning&char in an identifier&other alphabet&%
8144 %<en>most of Japanese char&opening brackets&closing brackets\\
8145 %<ja>意図&識別子中の文字&その他欧文文字&殆どの和文文字&開き括弧類&閉じ括弧類\\
8146 \bottomrule
8147 \end{tabular}
8148 \end{center}
8149 %<*en>
8150 Note that \textit{digits} in the \Pkg{listings} package can be Letter or
8151 Other according to circumstances.
8152 %</en>
8153 %<*ja>
8154 なお,本来の\Pkg{listings} パッケージでの分類``digit''は,
8155 出現状況によって,上の表のLetterとOtherのどちらにもなりうる.
8156 また,KanjiとCloseは \verb+\lst@ifletter+ と \verb+\lst@ifkanji+ の値が一致しているが,
8157 これは間違いではない.
8158 %</ja>
8159
8160 %<*en>
8161 For example, let us consider the case an Open comes after a Letter.
8162 Since an Open represents Japanese open brackets,
8163 it is preferred to be permitted to insert line break after the Letter.
8164 Therefore, the collected character string is output in this case.
8165 %</en>
8166 %<*ja>
8167 例えば,Letterの直後にOpenが来た場合を考える.
8168 文字種Openは和文開き括弧類を想定しているので,Letterの直後では行分割が可能であることが望ましい.
8169 そのため,この場合では,すでに収集されている文字列を出力することで行分割を許容するようにした.
8170 %</ja>
8171
8172 %<*en>
8173 The following table summarizes $5\times 5=25$ cases:
8174 %</en>
8175 %<*ja>
8176 同じように,$5\times 5=25$通り全てについて書くと,次のようになる:
8177 %</ja>
8178 \begin{center}
8179 \small
8180 \begin{tabular}{llccccc}
8181 \toprule
8182 %<*en>
8183 &&\multicolumn{4}{c}{Next}\\\cmidrule(lr){3-7}
8184 &&\hbox to 4em{\hss Letter\hss}&\hbox to 4em{\hss Other\hss}
8185 &\hbox to 4em{\hss Kanji\hss}&\hbox to 4em{\hss Open\hss}&Close\\\midrule
8186 &Letter&collects&\multicolumn{3}{c}{\hrulefill \ outputs\ \hrulefill}&collects\\
8187 &Other&outputs&collects&\multicolumn{2}{c}{\hrulefill \ outputs\ \hrulefill}&collects\\
8188 Prev&Kanji&\multicolumn{4}{c}{\hrulefill \ outputs\ \hrulefill}&collects\\
8189 &Open&\multicolumn{5}{c}{\hrulefill \ collects\ \hrulefill}\\
8190 &Close&\multicolumn{4}{c}{\hrulefill \ outputs\ \hrulefill}&collects\\
8191 %</en>
8192 %<*ja>
8193 &&\multicolumn{4}{c}{後ろ側の文字}\\\cmidrule(lr){3-7}
8194 &&\hbox to 4em{\hss Letter\hss}&\hbox to 4em{\hss Other\hss}
8195 &\hbox to 4em{\hss Kanji\hss}&\hbox to 4em{\hss Open\hss}&Close\\\midrule
8196 直&Letter&収集&\multicolumn{3}{c}{\hrulefill \ 出力\ \hrulefill}&収集\\
8197 前&Other&出力&収集&\multicolumn{2}{c}{\hrulefill \ 出力\ \hrulefill}&収集\\
8198 文&Kanji&\multicolumn{4}{c}{\hrulefill \ 出力\ \hrulefill}&収集\\
8199 字&Open&\multicolumn{5}{c}{\hrulefill \ 収集\ \hrulefill}\\
8200 種&Close&\multicolumn{4}{c}{\hrulefill \ 出力\ \hrulefill}&収集\\
8201 %</ja>
8202 \bottomrule
8203 \end{tabular}
8204 \end{center}
8205 %<en>In the above table,
8206 %<ja>上の表において,
8207 \begin{itemize}
8208 %<en>\item ``outputs'' means to output the collected character string (i.e., line breaking is permitted there).
8209 %<ja>\item 「出力」は,それまでに集めた文字列を出力(≒ここで行分割可能)を意味する.
8210
8211 %<en>\item ``collects'' means to append the next character to the collected character string (i.e., line breaking is prohibited there).
8212 %<ja>\item 「収集」は,後側の文字を,現在収集された文字列に追加(行分割不可)を意味する.
8213 \end{itemize}
8214
8215 %<*en>
8216 Characters above \texttt{U+0080} \emph{except Variation Selectors}
8217 are classified into above 5~classes by the following rules:
8218 %</en>
8219 %<*ja>
8220 \texttt{U+0080}以降の\emph{異体字セレクタ以外の}各文字が
8221 Letter, Other, Kanji, Open, Closeのどれに属するかは次によって決まる:
8222 %</ja>
8223 \begin{itemize}
8224 %<en>\item \textbf{ALchar}s above \texttt{U+0080} are classified as Letter.
8225 %<ja>\item (\texttt{U+0080}以降の)\textbf{ALchar}は,すべてLetter扱いである.
8226
8227 %<en>\item \textbf{JAchar}s are classified in the order as follows:
8228 %<ja>\item \textbf{JAchar}については,以下の順序に従って文字種を決める:
8229 \begin{enumerate}
8230 %<en>\item Characters whose \Param{prebreakpenalty} is greater than or equal to 0 are classified as Open.
8231 %<ja>\item \Param{prebreakpenalty}が0以上の文字はOpen扱いである.
8232
8233 %<en>\item Characters whose \Param{postbreakpenalty} is greater than or equal to 0 are classified as Close.
8234 %<ja>\item \Param{postbreakpenalty}が0以上の文字はClose扱いである.
8235
8236 %<en>\item Characters that don't satisfy the above two conditions are classified as Kanji.
8237 %<ja>\item 上の3条件のどちらにも当てはまらなかった文字は,Kanji扱いである.
8238 \end{enumerate}
8239 \end{itemize}
8240
8241 %<*en>
8242 The width of halfwidth kana (\texttt{U+FF61}--\texttt{U+FF9F})
8243 is same as the width of \textbf{ALchar};
8244 the width of the other \textbf{JAchar}s is double the width of \textbf{ALchar}.
8245 %</en>
8246 %<*ja>
8247 なお,半角カナ(U+FF61--U+FF9F)以外の\textbf{JAchar}は欧文文字2文字分の幅をとるものとみなされる.
8248 半角カナは欧文文字1文字分の幅となる.
8249 %</ja>
8250
8251 %<*en>
8252 This classification process is executed every time a character appears in
8253 the \texttt{lstlisting} environment or other environments/commands.
8254 %</en>
8255 %<*ja>
8256 これらの文字種決定は,実際に \texttt{lstlisting} 環境などの内部で文字が出てくるたびに行われる.
8257 %</ja>
8258
8259 %<*ja>
8260 \section{和文の行長補正方法}
8261 \label{sec-adjspec}
8262 \Pkg{luatexja-adjust} で提供される優先順位付きの行長調整の詳細を述
8263 べる.大まかに述べると,次のようになる.
8264 \begin{itemize}
8265 \item 通常の\TeX の行分割方法に従って,段落を行分割する.この段階では,行
8266       長に半端が出た場合,その半端分は\textbf{JAglue}(\Param{xkanjiskip},
8267       \Param{kanjiskip},JFMグルー)と
8268       それ以外のグルーの全てで(優先順位なく)負担される.
8269 \item その後,\texttt{post\_linebreak\_filter} callbackを使い,\emph{段
8270       落中の各行ごとに},行末文字の位置を調整したり,優先度付きの行長調整
8271       を実現するためにグルーの伸縮度を調整する.
8272       その処理においては,グルーの自然長と\textbf{JAglue}以外の
8273       グルーの伸び量・縮み量は変更せず,必要に応じて\textbf{JAglue}の伸び量・縮み量のみを
8274       変更する設計とした.
8275
8276 \Pkg{luatexja-adjust} の作用は,この処理を行うcallbackを追加するだけであり,
8277       この章の残りではcallbackでの処理について解説する.
8278 \end{itemize}
8279
8280 \paragraph{準備:合計伸縮量の計算}
8281 グルーの伸縮度(\texttt{plus} や \texttt{minus} で指定されている値)には,
8282 有限値の他に,\texttt{fi},\texttt{fil},\texttt{fill},\texttt{filll}と
8283 いう4つの無限大レベル(後ろの方ほど大きい)があり,行の調整に
8284 \texttt{fi} などの\emph{無限大レベルの伸縮度が用いられている場合は,そ
8285 の行に対しての処理を中止}する.
8286
8287 よって,以降,問題にしている行の行長調整は伸縮度が有限長のグルーを用いて
8288 行われているとして良い.さらに,簡単のため,この行はグルーが広げられている
8289 (自然長で組むと望ましい行長よりの短い)場合しか扱わない.
8290
8291 まず,段落中の行中のグルーを
8292 \begin{itemize}
8293 \item \textbf{JAglue}ではないグルー
8294 \item JFMグルー(優先度\footnote{%
8295   \ref{ssec-jfm-str}節にあるように,
8296   各JFMグルーには$-2$から2までの優先度がついている.}%
8297 別にまとめられる)
8298 \item 和欧文間空白(\Param{xkanjiskip})
8299 \item 和文間空白(\Param{kanjiskip})
8300 \end{itemize}
8301 の$1+1+5+1=8$つに類別し,それぞれの種別ごとに
8302 許容されている伸び量(\texttt{stretch}の値)の合計を計算する.
8303 また,行長と自然長との差を\textit{total}とおく.
8304
8305
8306 \subsection{行末文字の位置調整}
8307 行末が文字クラス$n$の\textbf{JAchar}であった場合,
8308 それを動かすことによって,\textit{total}のうち
8309 \textbf{JAglue}が負担する分を少なくしようとする.
8310 この行末文字の左右の移動可能量は,
8311 JFM中にある文字クラス$n$の定義の
8312 \texttt{end\_stretch},~\texttt{end\_shrink}フィールドに
8313 全角単位の値として記述されている.
8314
8315 例えば,行末文字が句点「。」であり,そこで用いられているJFM中に
8316 \begin{lstlisting}
8317   [2] = {
8318     chars = { '。', ... }, width = 0.5, ...,
8319     end_stretch = 0.5, end_shrink = 0.5,
8320   },
8321 \end{lstlisting}
8322 という指定があった場合,この行末の句点は
8323 \begin{itemize}
8324 \item 通常の\TeX の行分割処理で「半角以上の詰め」が行われていた場合,
8325 この行中の\textbf{JAglue}の負担を軽減するため,
8326 行末の句点を半角だけ右に移動する(ぶら下げ組を行う).
8327 \item 通常の\TeX の行分割処理で「半角以上の空き」が行われていた場合,
8328 逆に行末句点を半角左に移動させる(見た目的に全角取りとなる).
8329 \item 以上のどちらでもない場合,行末句点の位置調整は行わない.
8330 \end{itemize}
8331 となる.
8332
8333 行末文字を移動した場合,その分だけ\textit{total}の値を引いておく.
8334
8335 \subsection{グルーの調整}
8336 \textit{total}の分だけが,行中のグルーの伸び量に応じて負担されることになる.
8337 負担するグルーの優先度は以下の順であり,
8338 できるだけ\Param{kanjiskip}を自然長のままにすることを
8339 試みている.
8340 \begin{enumerate}\def\labelenumi{(\Alph{enumi})}
8341  \item \textbf{JAglue}以外のグルー
8342  \item 優先度2のJFMグルー
8343  \item 優先度1のJFMグルー
8344  \item 優先度0のJFMグルー
8345  \item 優先度$-1$のJFMグルー
8346  \item 優先度$-2$のJFMグルー
8347  \item \Param{xkanjiskip}
8348  \item \Param{kanjiskip}
8349 \end{enumerate}
8350 \begin{enumerate}
8351  \item 行末の和文文字を移動したことで$\textit{total}=0$となれば,
8352 調整の必要はなく,行が格納されているhboxの
8353 \texttt{glue\_set}, \texttt{glue\_sign}, \texttt{glue\_order}を再計算すればよい.
8354 以降,$\textit{total}\neq 0$と仮定する.
8355  \item \textit{total}が「\textbf{JAglue}以外のグルーの伸び量の合計」(以下,(A)の伸び量の
8356        合計,と称す)よりも小さければ,
8357 それらのグルーに\textit{total}を負担させ,\textbf{JAglue}達自身は自然長で組むことができる.
8358 よって,以下の処理を行う:
8359 \begin{enumerate}
8360 \item 各\textbf{JAglue}の伸び量を0とする.
8361 \item 行が格納されているhboxの
8362 \texttt{glue\_set}, \texttt{glue\_sign}, \texttt{glue\_order}を再計算する.
8363 これによって,\textit{total}は\textbf{JAglue}以外のグルーによって負担される.
8364 \end{enumerate}
8365 \item \textit{total}が「(A)の伸び量の合計」以上ならば,(A)--(H)のどこまで負担すれば
8366 \textit{total}以上になるかを計算する.
8367 例えば,
8368 \[\catcode`\<=12
8369  \textit{total} = (\text{(A)--(B)の伸び量の合計}) + p\cdot (\text{(C)の伸び量の合計}),
8370  \qquad 0\le p<1
8371 \]
8372 であった場合,各グルーは次のように組まれる:
8373 \begin{itemize}
8374  \item (A),~(B)に属するグルーは各グルーで許された伸び量まで伸ばす.
8375  \item (C)に属するグルーはそれぞれ$p\times (\text{伸び量})$だけ伸びる.
8376  \item (D)--(H)に属するグルーは自然長のまま.
8377 \end{itemize}
8378 実際には,前に述べた「設計」に従い,次のように処理している:
8379 \begin{enumerate}
8380 \item (C)に属するグルーの伸び量を$p$倍する.
8381 \item (D)--(H)に属するグルーの伸び量を0とする.
8382 \item 行が格納されているhboxの
8383 \texttt{glue\_set}, \texttt{glue\_sign}, \texttt{glue\_order}を再計算する.
8384 これによって,\textit{total}は\textbf{JAglue}以外のグルーによって負担される.
8385 \end{enumerate}
8386 \item \textit{total}が(A)--(H)の伸び量の合計よりも大きい場合,どうしようもないので
8387       \verb+^^;+何もしない.
8388 \end{enumerate}
8389
8390 %</ja>
8391
8392 %<*ja>
8393 \section{IVS対応}
8394 \verb+luatexja.otf.enable_ivs()+ を実行し,IVS対応を有効にした状態では,
8395 \verb+pre_linebreak_filter+ や \verb+hpack_filter+ コールバックには
8396 次の4つが順に実行される状態となっている:
8397 \begin{description}
8398 \item[\tt ltj.do\_ivs] \textit{glyph\_node}~$p$の直後に,異体字セレクタ(を表す\textit{glyph\_node})
8399 が連続した場合に,$p$のフォントに対応したが持つ「異体字情報」に従って出力するグリフを変える.
8400
8401 しかし,単に$p.\textit{char}$を変更するだけでは,後から
8402 font featureの適用(すぐ下)により置換される可能性がある.そのため,
8403 \cs{CID} や \cs{UTF} と同じように,\textit{glyph\_node}~$p$の代わりに
8404 \texttt{user\_id} が\textit{char\_by\_cid}であるようなuser-defined whatsitを用いている.
8405 \item[(\Pkg{luaotfload} によるfont featureの適用)]
8406 \item[\tt ltj.otf] \texttt{user\_id} が\textit{char\_by\_cid}であるようなuser-defined whatsitを
8407 きちんと\textit{glyph\_node}に変換する.この処理は,\cs{CID}, \cs{UTF}やIVSによる置換が,
8408 font featureの適用で上書きされてしまうのを防止するためである.
8409 \item[\tt ltj.main\_process] \textbf{JAglue}の挿入処理(\ref{sec-jfmglue}章)と,
8410 JFMの指定に従って各\textbf{JAchar}の「寸法を補正」することを行う.
8411 \end{description}
8412
8413 問題は各フォントの持っているIVS情報をどのように取得するか,である.
8414 \Pkg{luaotfload} はフォント番号<font\_number>の情報を\
8415 \texttt{fonts.hashes.identifiers[<font\_number>]} 以下に格納している.
8416 しかし,OpenTypeフォントのIVS情報は格納されていないようである%
8417 \footnote{TrueTypeフォントに関しては,
8418 \begin{center}
8419 \texttt{fonts.hashes.idenfiers[<font\_number>]%
8420   .resources.variants[<selector>][<base\_char>]}
8421 \end{center}
8422 に,<base\_char>番の文字の後に異体字セレクタ<selector>が続いた場合に
8423 出力すべきグリフが書かれてある.}.
8424 %例えば,小塚明朝Pr6N~Rでは,
8425
8426 一方,\LuaTeX 内部の \texttt{fontloader} の返すテーブルには
8427 OpenTypeフォントでもTrueTypeフォントでもIVS情報が格納されている.
8428 具体的には……
8429
8430 そのため,\LuaTeX-jaのIVS対応においては,\LuaTeX 内部の\
8431 \texttt{fontloader} を直接用いることで,フォントのIVS情報を取得している.
8432 20140114.0以降でキャッシュを用いるようにした要因はここにあり,
8433 \texttt{fontloader} の呼び出しでかなり時間を消費することから,
8434 %%% to_table を使わなくしたことで,メモリ使用量は減った
8435 IVS情報をキャッシュに保存することで2回目以降の実行時間を節約している.
8436
8437
8438 \section{複数フォントの「合成」(未完)}
8439
8440 \section{\LuaTeX-jaにおけるキャッシュ}
8441 \Pkg{luaotfload}パッケージが,各TrueType・OpenTypeフォントの情報を
8442 キャッシュとして保存しているのと同様の方法で,
8443 \LuaTeX-jaもいくつかのキャッシュファイルを作成するようになった.
8444 \begin{itemize}
8445  \item 通常,キャッシュは\texttt{\$TEXMFVAR/luatexja/}以下に保存され,
8446 そこから読み込みが行われる.
8447  \item 「通常の」テキスト形式のキャッシュ(拡張子は \texttt{.lua})以外にも,
8448 それをバイナリ形式(バイトコード)に変換したものもサポートしている.
8449 \begin{itemize}
8450  \item \LuaTeX とLuaJIT\TeX ではバイトコードの形式が異なるため,バイナリ形式の
8451 キャッシュは共有できない.\LuaTeX 用のバイナリキャッシュは \texttt{.luc},
8452 LuaJIT\TeX 用のは \texttt{.lub} と拡張子を変えることで対応している.
8453  \item キャッシュを読み込む時,同名のバイナリキャッシュがあれば,
8454 テキスト形式のものよりそちらを優先して読み込む.
8455  \item テキスト形式のキャッシュが更新/作成される際は,そのバイナリ版も
8456 同時に更新される.
8457 また,(バイナリ版が見つからず)テキスト形式のキャッシュ側が読み込まれたときは,
8458 \LuaTeX-jaはバイナリキャッシュを作成する.
8459 \end{itemize}
8460 \end{itemize}
8461 %</ja>
8462 %<*en>
8463 \section{Cache Management of \LuaTeX-ja}
8464 \LuaTeX-ja creates some cache files to reduce the loading time.
8465 in a similar way to the \Pkg{luaotfload} package:
8466 \begin{itemize}
8467  \item Cache files are usually stored in (and loaded from)
8468 \texttt{\$TEXMFVAR/luatexja/}.
8469  \item In addition to caches of the text form (the extension is ``\texttt{.lua}''),
8470 caches of the \emph{binary}, precompiled form are supported.
8471 \begin{itemize}
8472  \item We cannot share same binary cache for \LuaTeX\ and LuaJIT\TeX.
8473 Hence we distinguish them by their extension, ``\texttt{.luc}'' for \LuaTeX\
8474 and ``\texttt{.lub}'' for LuaJIT\TeX.
8475  \item In loading a cache, the binary cache precedes
8476 the text form.
8477  \item When \LuaTeX-ja updates a cache \texttt{hoge.lua},
8478 its binary version is also updated.
8479 \end{itemize}
8480 \end{itemize}
8481 %</en>
8482
8483 %<*ja>
8484 \subsection{キャッシュの使用箇所}
8485
8486 \LuaTeX-ja では以下の3種類のキャッシュを使用している:
8487 \begin{cslist}
8488 \item[ltj-cid-auto-adobe-japan1.lua]
8489 Ryumin-Lightのような非埋め込みフォントの情報を格納しており,
8490 (それらが\LuaTeX-jaの標準和文フォントなので)\LuaTeX-jaの読み込み時に自動で読まれる.
8491 生成には\texttt{UniJIS2004-UTF32-\{H, V\}}, \texttt{Adobe-Japan1-UCS2}という3つの
8492 CMapが必要である.
8493
8494 \pageref{para-cid}ページで述べたように,\texttt{cid}キーを使って
8495 非埋め込みの中国語・韓国語フォントを定義する場合,同様のキャッシュが生成される.
8496 キャッシュの名称,必要となるCMapについては表\ref{tab:cid-cache}を参照して欲しい.
8497
8498 \item[ivs\_***.lua]
8499 フォント``\texttt{***}''における異体字情報を格納している.構造は以下の通り:
8500 %</ja>
8501 %<*en>
8502 \subsection{Use of Cache}
8503
8504 \LuaTeX-ja uses the following cache:
8505 \begin{cslist}
8506 \item[ltj-cid-auto-adobe-japan1.lua]
8507 The font table of a CID-keyed non-embedded Japanese font.
8508 This is loaded in every run.
8509 It is created from two CMaps, \texttt{UniJIS2004-UTF32-H} and
8510              \texttt{Adobe-Japan1-UCS2},
8511 and this is why these two CMaps are needed in the first run of \LuaTeX-ja.
8512
8513 Similar caches are created as Table~\ref{tab:cid-cache},
8514 if you specified \texttt{cid} key in \cs{jfont}
8515 to use other CID-keyed non-embedded fonts for Chinese or Korean,
8516 as in Page~\pageref{para-cid}.
8517
8518 \item[ivs\_***.lua]
8519 This file stores the table of Unicode variants in a font ``\texttt{***}''.
8520 The structure of the table is the following:
8521 %</en>
8522
8523 \begin{table}[!tb]
8524  \centering\small
8525 \caption{\texttt{cid} key and corresponding files}
8526 \label{tab:cid-cache}
8527 \vspace*{\medskipamount}
8528 \begin{tabular}{>{\tt}l>{\tt}l>{\tt}l>{\tt}l}
8529 \toprule
8530 \bf \texttt{cid} key&\bf name of the cache &
8531 \multicolumn{2}{c}{\bf used CMaps}\\
8532 \midrule
8533 Adobe-Japan1-*&ltj-cid-auto-adobe-japan1.lua&UniJIS2004-UTF32-H&Adobe-Japan1-UCS2\\
8534 Adobe-Korea1-*&ltj-cid-auto-adobe-korea1.lua&UniKS-UTF32-H&Adobe-Korea1-UCS2\\
8535 Adobe-GB1-*&ltj-cid-auto-adobe-gb1.lua&UniGB-UTF32-H&Adobe-GB1-UCS2\\
8536 Adobe-CNS1-*&ltj-cid-auto-adobe-cns1.lua&UniCNS-UTF32-H&Adobe-CNS1-UCS2\\
8537 \bottomrule
8538 \end{tabular}
8539 \end{table}
8540
8541 \begin{lstlisting}
8542 return {
8543  {
8544   [10955]={    -- U+2ACB "Subset Of Above Not Equal To"
8545    [65024]=983879, -- <2ACB FE00>
8546   },
8547   [37001]={    -- U+9089 "邉"
8548    [0]=37001,  --   <9089 E0100>
8549    991049,     --   <9089 E0101>
8550    ...
8551   },
8552   ...
8553  },
8554  ["chksum"]="FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", -- checksum of the fontfile
8555  ["version"]=4, -- version of the cache
8556 }
8557 \end{lstlisting}
8558 %<*ja>
8559 \item[ltj-jisx0208.\{luc|lub\}]
8560 \LuaTeX-ja配布中の\texttt{ltj-jisx0208.lua}をバイナリ化したものである.
8561 これはJIS~X~0208とUnicodeとの変換テーブルであり,
8562 \pTeX との互換目的の文字コード変換命令で用いられる.
8563 %</ja>
8564 %<*en>
8565 \item[ltj-jisx0208.\{luc|lub\}]
8566 The binary version of \texttt{ltj-jisx0208.lua}.
8567 This is the conversion table between JIS~X~0208 and Unicode
8568 which is used in Kanji-code conversion commands for compatibility with \pTeX.
8569 %</en>
8570 \end{cslist}
8571
8572 %<*en>
8573 \subsection{Internal}
8574 Cache management system of \LuaTeX-ja is stored in \texttt{luatexja.base}
8575 (\texttt{ltj-base.lua}).
8576 There are three public functions for cache management in \texttt{luatexja.base},
8577 where <filename> stands for the file name \emph{without suffix}:
8578 \begin{cslist}
8579 \item[save\_cache(<filename>, <data>)]
8580 Save a non-nil table <data> into a cache <filename>.
8581 Both the text form <filename>\texttt{.lua} and its binary version
8582 are created or updated.
8583
8584 \item[save\_cache\_luc(<filename>, <data>{[, <serialized\_data>]})]
8585
8586 Same as \texttt{save\_cache}, except that only the binary cache is updated.
8587 The third argument <serialized\_data> is not usually given.
8588 But if this is given, it is treated as a string representation of <data>.
8589
8590 \item[load\_cache(<filename>, <outdate>)]
8591 Load the cache <filename>.
8592 <outdate> is a function which takes one argument (the contents of the cache),
8593 and its return value is whether the cache is outdated.
8594
8595 \texttt{load\_cache} first tries to
8596 read the binary cache <filename>\texttt{.\{luc|lub\}}.
8597 If its contents is up-to-date, \texttt{load\_cache} returns the contents.
8598 If the binary cache is not found or
8599 its contents is outdated, \texttt{load\_cache} tries to
8600 read the text form <filename>\texttt{.lua}.
8601 Hence, the return value of \texttt{load\_cache} is non-nil,
8602 if and only if the updated cache is found.
8603 \end{cslist}
8604 %</en>
8605 %<*ja>
8606 \subsection{内部命令}
8607 \LuaTeX-jaにおけるキャッシュ管理は,\texttt{luatexja.base}~(\texttt{ltj-base.lua})に
8608 実装しており,以下の3関数が公開されている.
8609 ここで,<filename>は保存するキャッシュのファイル名を\emph{拡張子なしで}指定する.
8610 \begin{cslist}
8611 \item[save\_cache(<filename>, <data>)]
8612 nilでない<data>をキャッシュ<filename>に保存する.
8613 テキスト形式の<filename>\texttt{.lua}のみならず,
8614 そのバイナリ版も作成/更新される.
8615
8616 \item[save\_cache\_luc(<filename>, <data>{[, <serialized\_data>]})]
8617
8618 \texttt{save\_cache}と同様だが,バイナリキャッシュのみが更新される.
8619 第3引数<serialized\_data>が与えられた場合,それを
8620 <data>の文字列化表現として使用する.
8621 そのため,<serialized\_data>は普通は指定しないことになるだろう.
8622
8623 \item[load\_cache(<filename>, <outdate>)]
8624 キャッシュ<filename>を読み込む.
8625 <outdate>は1引数(キャッシュの中身)をとる関数であり,
8626 その戻り値は「キャッシュの更新が必要」かどうかを示すブール値でないといけない.
8627
8628 \texttt{load\_cache}は,まずバイナリキャッシュ<filename>\texttt{.\{luc|lub\}}を
8629 読みこむ.もしその内容が「新しい」,つまり<outdate>の評価結果が \texttt{false} なら
8630 \texttt{load\_cache}はこのバイナリキャッシュの中身を返す.
8631 もしバイナリキャッシュが見つからなかったか,「古すぎる」ならばテキスト版
8632              <filename>\texttt{.lua}を読み込み,その値を返す.
8633
8634 以上より,\texttt{load\_cache}自体がnilでない値を返すのは,ちょうど「新しい」キャッシュが
8635 見つかった場合である.
8636 \end{cslist}
8637 %</ja>
8638
8639
8640 %<*ja>
8641 \section{縦組の実装}
8642 \label{sec-dir-imp}
8643 \ref{sec-direction}章の最初でも述べたように,
8644 \LuaTeX-jaは横組(\texttt{TLT})で組んだボックスを回転させる方式で
8645 縦組を実装している.
8646
8647 \LuaTeX-jaにおける縦組の実装は
8648 \pTeX における実装(\cite{ptexdoc,ptextug})をベースにしている.
8649
8650 \subsection{direction~whatsit}
8651 \textit{direction}~whatsitとは,\textit{direction}という特定の \verb+user_id+ を持つ
8652 whatsitのことであり,以下のタイミングで作られる.
8653 \begin{itemize}
8654  \item 組方向を \cs{tate} 等で変更したとき.
8655  \item \cs{hbox}, \cs{vbox}, \cs{vtop} による明示的なボックスの開始時.\\
8656 \verb+\hbox{}+, \verb+\vbox{}+ といった,
8657 \begin{itemize}
8658  \item \cs{tate} 等によりボックス内部の組方向を変更していない
8659  \item ボックスの中身のリストが空である
8660 \end{itemize}
8661 場合は,\LuaTeX の \verb+hpack_filter+, \verb+vpack_filter+ といった
8662 callbackに処理が回らない.そこで,\LuaTeX-ja では,\cs{everyhbox}, \cs{everyvbox} を利用す
8663        ることで各ボックスの先頭に確実に追加するようにしている\footnote{%
8664   問題は \cs{hbox to 25pt\{\}} という状況である.実際のこのボックスの中身は空でない(少な
8665        くともdirection whatsitがある)ため,何も対策をしなければhpack時にUnderfill警告が発
8666        生してしまうことになる.\LuaTeX-jaではそうならないように「\cs{hbadness},
8667        \cs{vbadness} を一時的に10000に変更し,hpack, vpack後に元の値に戻す」処理を行ってい
8668        る.
8669 }.
8670  \item \cs{vsplit}によってvboxを分割した時の「残り」.
8671  \item \LuaTeX-ja読み込み前に作成したボックスの寸法を \cs{ltjsetwd} 等によって変更した時.
8672 \end{itemize}
8673 なお,\verb+\vtop{...}+ の場合は,先頭にdirection whatsitを置くと
8674 ボックスの高さが常に0\,ptになるという問題が発生する.そのため,この場合に限っては
8675 vpack時にdirection whatsitをリストの2番目に移動させている.
8676
8677 direction whatsitはあくまでも組方向処理のための補助的なノードであるので,
8678 \cs{unhbox}, \cs{unhcopy} によってボックスの中身が展開される時には展開直前に削除される.
8679 これは
8680 \begin{lstlisting}
8681  % yoko direction
8682 \setbox0=\hbox{\tate B}
8683 \noindent % 水平モードに入る.この時点でのリストの中身は空
8684 \unhbox0 A
8685 \end{lstlisting}
8686 といった場合に,段落が縦組で組まれたり,あるいは
8687 \begin{lstlisting}
8688 \setbox0=\hbox{}
8689 \leavevmode \hbox{A}\unhbox0
8690 \setbox1=\lastbox % \box1 はどうなる?
8691 \end{lstlisting}
8692 で \cs{box1} が \cs{hbox\{A\}} でなく空になってしまうことを防ぐためである.
8693
8694
8695 \subsection{\textit{dir\_box}}
8696 縦中横など異方向のボックスを配置する場合に,周囲の組方向と大きさを整合させるため,
8697 \LuaTeX-jaでは \verb+\ltj@dir+ が128以降の\textit{hlist\_node}, \textit{vlist\_node}を
8698 用いる.これらは\pTeX における\textit{dir\_node}の役割と同じ果たしており,
8699 この文章中では\textit{dir\_box}と呼称する.
8700
8701 \subsubsection{異方向のボックスの整合}
8702 \textit{dir\_box}の第一の使用目的は,異方向のボックスの大きさを整合させることである.
8703 例えば,
8704 \begin{lstlisting}
8705  % yoko direction
8706 平成\hbox{\tate 26}年
8707 \end{lstlisting}
8708 は段落中で
8709 \[
8710  \xymatrix{
8711    {}\Node{glyph}{`平'}\ar[r]&{}\Node{glyph}{`成'}\ar[r]&
8712    {}\HNode{hlist}{10.00003}{3.02779}{0.0}\ar[r]\ar[d]^{\text{中身}}&{}\Node{glyph}{`年'}\\
8713    &&{}\Node{whatsit}{\cs{tate}}\ar[r]&{}\Node{glyph}{`2'}\ar[r]&{}\Node{glyph}{`6'}
8714  }
8715 \]
8716 というリストを作る.その後,この段落が終了したときに,
8717 \LuaTeX-jaの\textbf{JAglue}挿入処理が行われ
8718 \[
8719  \xymatrix{
8720    {}\Node{glyph}{`平'}\ar[r]
8721   &{}\textcolor{blue}{\Node{glue}{\Param{xkanjiskip}}}\ar[r]
8722   &{}\Node{glyph}{`成'}\ar[r]
8723   &{}\textcolor{blue}{\Node{penalty}{0}}
8724     \ar`r[d] `[l] `[ddll] `[dl] [dl]
8725   \\
8726   &&{}\textcolor{red}{\HNode{hlist}{3.02779}{10.00003}{0.0}}\ar[r]\ar[d]^{\text{中身}}
8727   &{}\textcolor{blue}{\Node{penalty}{0}}\ar[r]
8728   &{}\Node{glyph}{`年'}\\
8729   &&{}\HNode{\textit{dir\_box} (\cs{yoko})}{10.00003}{3.02779}{0.0}\ar[d]^{\text{中身}}\\
8730   &&{}\Node{whatsit}{\cs{tate}}\ar[r]&{}\Node{glyph}{`2'}\ar[r]&{}\Node{glyph}{`6'}
8731  }
8732 \]
8733 のようになる(青字は\textbf{JAglue},赤字が整合処理のための\textit{dir\_box}である).
8734 \TeX の \cs{showbox} 形式で書けば
8735
8736 \medskip{\narrowbaselines\ttfamily\obeylines\parindent0pt
8737 \catcode`\@=0 @catcode`@\=12
8738 .\tenmin 平
8739 @textcolor{blue}{.\glue 0.0 plus 0.4 minus 0.4}
8740 .\tenmin 成
8741 @textcolor{blue}{.\penalty 0}
8742 @textcolor{red}{.\hbox(10.00003+0.0)x3.02779, direction TLT}
8743 ..\hbox(3.02779+0.0)x10.00003, direction TLT
8744 ...\whatsit4=[]
8745 ...\tenrm 2
8746 ...\tenrm 6
8747 @textcolor{blue}{.\penalty 0}
8748 .\tenmin 年
8749 }\medskip
8750
8751 \noindent である.
8752
8753 なお,\cs{raise},~\cs{lower}, \cs{moveleft},~\cs{moveright} といったボックス移動命令では.
8754 移動を正しく表現するために段落やボックスの途中でも異方向のボックスは\textit{dir\_box}にカ
8755 プセル化している.
8756 例えば
8757 \begin{lstlisting}
8758  % yoko direction
8759 平成\raise1pt\hbox{\tate 26}年\showlists
8760 \end{lstlisting}
8761 は以下のような結果を得る.
8762
8763 \medskip{\narrowbaselines\ttfamily\obeylines\parindent0pt
8764 \catcode`\@=0 @catcode`@\=12
8765 (前略)
8766 \tenrm 平
8767 \tenrm 成
8768 @textcolor{red}{\hbox(10.00003+0.0)x3.02779, shifted -1.0, direction TLT}
8769 .\hbox(3.02779+0.0)x10.00003, direction TLT
8770 ..\whatsit4=[]
8771 ..\tenrm 2
8772 ..\tenrm 6
8773 \tenrm 年
8774 }\medskip
8775
8776 また,メインの垂直リストに異方向のボックスが追加される場合にも同様に即座に
8777 \textit{dir\_box}にカプセル化している.ページ分割のタイミングを正
8778 しく\TeX が判断するためである.
8779 \cs{lastbox} によるボックスの取得では,\textit{dir\_box}は削除される.
8780
8781 \subsubsection{異方向のボックス寸法の格納}
8782 第二の使用目的は,現在の組方向がボックス本来の組方向とは異なる状況で,
8783 \cs{ltjsetwd} によってボックス寸法を設定されたことを記録することである.
8784
8785 例えば
8786 \begin{lstlisting}[numbers=left]
8787 \setbox0=\hbox{\vrule width 10pt height 5pt depth 2pt}
8788 \setbox1=\hbox{\tate\ltjsetwd0=20pt}
8789 \wd0=9pt
8790 \setbox1=\hbox{\dtou\ltjsetwd0=20pt}
8791 \setbox0=\hbox{\dtou a\box0}
8792 \end{lstlisting}
8793 というコードを考える.1行目で \cs{box0} には横組の
8794 幅10\,pt,高さ5\,pt,深さ2\,ptのボックスが代入される.
8795 よって,
8796 \begin{itemize}
8797  \item 縦組下では \cs{box0} は幅7\,pt,高さ・深さ5\,ptのボックスとして扱われる.
8798  \item \cs{dtou} 下では \cs{box0} は幅7\,pt,高さ10\,pt,深さ0\,ptのボックスとして扱われる.
8799 \end{itemize}
8800 このとき,\cs{box0} の\emph{中身}は
8801 \[
8802  \xymatrix{
8803    {}\Node{whatsit}{\cs{yoko}}\ar[r]&{}\Node{rule}{}
8804  }
8805 \]
8806 である.
8807
8808 さて,2行目で縦組時の \cs{box0} の幅が20\,ptに設定される.この情報が
8809 direction~whatsit内部のノードリストに,\textit{dir\_box}として格納される:
8810 \[
8811  \xymatrix{
8812    {}\Node{whatsit}{\cs{yoko}}\ar[r]\ar[d]_{\text{中身}}&{}\Node{rule}{}\\
8813    {}\textcolor{red}{\HNode{\textit{dir\_box} (\cs{tate})}{20.0}{5.0}{5.0}}
8814  }
8815 \]
8816
8817 次に,3行目では横組時の,つまり \cs{box0} 本来の組方向での深さが9\,ptに変更される.
8818 このとき,\cs{box0} は
8819 \begin{itemize}
8820  \item 縦組下では寸法代入が既に行われているので,2行目で作成された\textit{dir\_box}の通り
8821        に幅20\,pt,高さ・深さ5\,ptのボックスとして扱われる.
8822  \item \cs{dtou} 下ではまだ寸法代入が行われていないので,
8823 \cs{box0} の寸法変更に追従し,幅7\,pt,高さ9\,pt,深さ0\,ptのボックスとして扱われる.
8824 \end{itemize}
8825
8826 4行目では \cs{dtou} 下での\cs{box0} の幅が20\,ptに設定されるので,2行目と同じように
8827 \[
8828  \xymatrix{
8829    {}\Node{whatsit}{\cs{yoko}}\ar[r]\ar[d]_{\text{中身}}&{}\Node{rule}{}\\
8830    {}\textcolor{red}{\HNode{\textit{dir\_box} (\cs{dtou})}{20.0}{9.0}{0.0}}\ar[r]&
8831    {}\HNode{\textit{dir\_box} (\cs{tate})}{20.0}{5.0}{5.0}
8832  }
8833 \]
8834 と\textit{dir\_box}が作成される.
8835
8836 このように寸法代入によってつくられた\textit{dir\_box}は,前節の整合過程のときに再利用され
8837 る.上記の例でいえば,5行目を実行した後の \cs{box0} の内容は
8838 \[
8839  \xymatrix{
8840    {}\Node{whatsit}{\cs{dtou}}\ar[r]&
8841    {}\Node{glyph}{`a'}\ar[r]&
8842    {}\textcolor{red}{\HNode{\textit{dir\_box} (\cs{dtou})}{20.0}{9.0}{0.0}}\ar[d]_{\text{中身}}\\
8843    &&{}\HNode{hlist}{9.0}{5.0}{2.0}\ar[d]_{\text{中身}}\\
8844    &&{}\Node{whatsit}{\cs{yoko}}\ar[r]&{}\Node{rule}{}
8845  }
8846 \]
8847 のようになる.
8848 %</ja>
8849
8850 \newpage
8851 \begin{thebibliography}{99}
8852   \addcontentsline{toc}{section}{\refname}
8853 \bibitem{texbytopic}
8854 Victor Eijkhout. \newblock \textit{\TeX\ by Topic, A \TeX nician's Reference}, Addison-Wesley, 1992.
8855 \bibitem{listings} C.\ Heinz, B.\ Moses. \newblock The \textsf{Listings} Package.
8856 \bibitem{uptex} Takuji Tanaka. \newblock
8857 upTeX---Unicode version of pTeX with CJK extensions,
8858 TUG 2013, October 2013.
8859 %<ja>\newblock
8860 %<en>\\\null\hfill
8861 \url{http://tug.org/tug2013/slides/TUG2013_upTeX.pdf}
8862 \bibitem{jlisting} Thor Watanabe. \newblock Listings\ -\ MyTeXpert.
8863 %<en>\newblock
8864 %<ja>\\\null\hfill
8865 \url{http://mytexpert.sourceforge.jp/index.php?Listings}
8866 \bibitem{jlreq}  W3C Japanese Layout Task Force~(ed). \newblock
8867 Requirements for Japanese Text Layout (W3C Working Group Note), 2011, 2012. \newblock
8868 \url{http://www.w3.org/TR/jlreq/}%
8869 %<ja> \\日本語訳の書籍版:W3C日本語組版タスクフォース(編),『W3C技術ノート 日本語組版処理の要件』,東京電機大学出版局,2012.
8870 \bibitem{min10} 乙部厳己.min10フォントについて.\\\null\hfill
8871 \url{http://argent.shinshu-u.ac.jp/~otobe/tex/files/min10.pdf}
8872 \bibitem{x4051} 日本工業規格(Japanese Industrial Standard). JIS~X~4051,
8873 日本語文書の組版方法(Formatting rules for Japanese documents), 1993, 1995, 2004.
8874 \bibitem{ptexdoc} 濱野尚人,田村明史,倉沢良一.\TeX の出版への応用—縦組み機能の組み込み—.
8875 \\\null\hfill\texttt{.../texmf-dist/doc/ptex/base/ptexdoc.pdf}
8876 \bibitem{ptextug} Hisato Hamano. \newblock
8877 \textit{Vertical Typesetting with \TeX}, TUGBoat~\textbf{11}(3), 346--352, 1990.
8878 \bibitem{pdfstd} International Organization for Standardization. \newblock
8879 ISO 32000-1:2008, \textit{Document management -- Portable document format -- Part 1: PDF
8880       1.7}, 2008. \newblock
8881 \\\null\hfill
8882 \url{http://www.iso.org/iso/iso\_catalogue/catalogue_tc/catalogue\_detail.htm?csnumber=51502}
8883 \end{thebibliography}
8884
8885 \end{document}
8886 %</!showexpl>
8887 %<*showexpl>
8888 %%
8889 %% config file for showexpl.sty
8890 %%
8891 %% Copyright The LuaTeX-ja project team, 2012
8892 %%
8893 \ProvidesFile{showexpl.cfg}
8894   [2012/05/20 v0.01 Definitions for the showexpl package (luatexja)]
8895 \lstset{}
8896 \def\SX@Info{}
8897 \endinput
8898 %</*showexpl>