OSDN Git Service

Improved impl. of \utod.
[luatex-ja/luatexja.git] / doc / luatexja.dtx
1 %<*!showexpl>
2 %#! lualatex -shell-escape
3
4 % To typeset this manual, you need following two fonts:
5 %  - KozMinPr6N-Regular.otf
6 %  - KozGoPr6N-Medium.otf
7 %  - KozGoPr6N-Regular.otf
8
9 %%%%% section ==> 章
10 %%%%% subsection => 節
11
12 %<en>\documentclass[a4paper,titlepage]{article}
13 %<ja>\documentclass[a4paper,titlepage]{ltjsarticle}
14
15 %%%%%%%%
16 \makeatletter
17 %%%%%%%%
18
19 %%%%%%%% record loaded packages
20 \let\ltjpkglist\empty
21 \newif\if@real@append@list
22 \def\@append@newentry#1#2{{%
23   \@real@append@listtrue \def\@tempa{#2}%
24   \let\@pkglist\@append@newentry@pkglist#1%
25   \if@real@append@list
26     \let\@pkglist=\relax\xdef#1{#1\@pkglist{#2}}%
27   \fi}}
28 \def\@append@newentry@pkglist#1{%
29   \def\@tempb{#1}%
30   \ifx\@tempa\@tempb\@real@append@listfalse\fi}
31 \def\@addtofilelist#1{\@append@newentry\ltjpkglist{#1}}
32 \let\@listfiles\empty
33
34 %<*en>
35 \usepackage[margin=25mm,lmargin=30mm,rmargin=30mm,footskip=6mm]{geometry}
36 \usepackage{luatexja-adjust}\ltjdisableadjust
37 \parskip=\smallskipamount
38 \renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}%
39     {3.25ex \@plus1ex \@minus.2ex}%
40     {-1em}%
41     {\normalfont\normalsize\bfseries\raisebox{.2ex}{$\mdlgblksquare\mkern1mu$}}}
42 %</en>
43 %<*ja>
44 \usepackage[textwidth=45\zw, lines=45, footskip=6mm]{geometry}
45 \usepackage{luatexja-adjust}%\ltjdisableadjust
46 \advance\leftmargini-1\zw\advance\leftmarginii-1\zw
47 %</ja>
48
49 \usepackage{amsmath,array,tikz,pict2e,multienum,float}
50 \usepackage{booktabs,multicol,luatexja-ruby}
51 \usepackage{xy}
52
53 %%%%%%%% listings
54
55 %%%%%%%% IVS
56
57 \def\IVS#1{\char\numexpr "E0100+#1\relax}%"
58 \def\IVSA#1#2#3#4#5{%
59   \textcolor{blue}{\raisebox{3.5pt}{\tt%
60     \fboxsep=0.5pt\fbox{\tiny \oalign{0#1#2\crcr#3#4#5\crcr}}}}%
61 }
62 {\catcode`\%=11
63   \gdef\IVSB#1{\expandafter\IVSA\directlua{
64     local cat_str = luatexbase.catcodetables['string']
65     tex.sprint(cat_str, string.format('%X', 0xE00EF+#1))
66 }}}
67
68 \usepackage{listings,showexpl}
69 \lstset{
70   basicstyle=\ttfamily\small, pos=r, breaklines=true,
71   numbers=none, rframe={}, basewidth=0.5em, numberstyle=\tiny, numbersep=0.5em,
72   explpreset={numberstyle=\tiny, numbers=left, numbersep=1em, columns=fixed}
73 }
74 % Suppress output from showexpl to stdout.
75 \let\SX@Info\relax
76
77 %%%%%%%% hyperref
78 \usepackage{hyperref,bookmark}
79 %<*en>
80 \title{The \LuaTeX-ja package}
81 \author{The \LuaTeX-ja project team}
82 %</en>
83 %<*ja>
84 \title{\LuaTeX-jaパッケージ}
85 \author{\LuaTeX-jaプロジェクトチーム}
86 %</ja>
87 \hypersetup{%
88         unicode,
89         colorlinks,
90         allbordercolors=1 1 1,
91         allcolors=blue,
92 %<*en>
93         pdfauthor={The LuaTeX-ja project team},
94         pdftitle={The LuaTeX-ja package}
95 %</en>
96 %<*ja>
97         pdfauthor={LuaTeX-jaプロジェクトチーム},
98         pdftitle={LuaTeX-jaパッケージ}
99 %</ja>
100 }
101
102 %%%%%%%% definition env.
103 \usepackage{amsthm}
104 \theoremstyle{definition}
105 %<en>\newtheorem{defn}{Definition}
106 %<ja>\newtheorem{defn}{定義}
107
108 %%%%%%%% fonts
109 \usepackage{luatexja-otf}
110 %<ja>\usepackage{lmodern}
111 \directlua{luatexja.otf.enable_ivs()}
112 \usepackage[match]{luatexja-fontspec}
113 \usepackage[kozuka-pr6n]{luatexja-preset}
114 \setmonojfont{KozGoPr6N-Regular.otf}
115 %<*ja>
116 \def\emph#1{\textbf{\textgt{#1}}}
117 \def\headfont{\normalfont\bfseries\gtfamily}
118 \usepackage{amssymb}
119 %</ja>
120 %<*en>
121 \usepackage{unicode-math}
122 \setmainfont[Ligatures=TeX]{TeX Gyre Termes}
123 \setsansfont[Scale=0.95,Ligatures=TeX]{TeX Gyre Heros}
124 \setmathfont{xits-math.otf}
125 \frenchspacing
126 %</en>
127
128 %%%%%%%% logo
129 \usepackage{metalogo}
130 \DeclareRobustCommand\eTeX{\ensuremath{\varepsilon}-\kern-.125em\TeX}
131 \DeclareRobustCommand\LuaTeX{Lua\TeX}
132 \DeclareRobustCommand\pdfTeX{pdf\TeX}
133 \DeclareRobustCommand\pTeX{p\kern-.15em\TeX}
134 \DeclareRobustCommand\upTeX{up\kern-.15em\TeX}
135 \DeclareRobustCommand\pLaTeX{p\kern-.05em\LaTeX}
136 \DeclareRobustCommand\pLaTeXe{p\kern-.05em\LaTeXe}
137 \DeclareRobustCommand\epTeX{\ensuremath{\varepsilon}-\kern-.125em\pTeX}
138
139 %%%%%%%% other macros
140 \newenvironment{cslist}{%
141 %<ja>  \leftskip2\zw
142 %<en>  \leftskip2em
143   \parindent=0pt\def\makelabel##1{{\tt\textbackslash ##1}}
144   \def\{{\char`\{}\def\}{\char`\}}
145   \let\origitem=\item
146   \def\item[##1]{\par\smallskip\par\hskip-\leftskip\makelabel{##1}\par}
147   \@totalleftmargin\leftskip
148 }{\par%
149 %<en>\medskip
150 }
151
152 \def\labelenumii{(\arabic{enumii})}
153 \long\def\@makecaption#1#2{%
154   \vskip\abovecaptionskip
155   \sbox\@tempboxa{{\small #1. #2}}%
156   \ifdim \wd\@tempboxa >\hsize
157     {\small #1. #2}\par
158   \else
159     \global \@minipagefalse
160     \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
161   \fi
162   \vskip\belowcaptionskip}
163
164 \def\_{\leavevmode \kern .06em\vbox {\hrule \@width .333em}}
165
166 %%%%%%%%
167 \makeatother
168 %%%%%%%%
169
170 \def\Node#1#2{\,\vcenter{\hbox{\fboxsep=1pt\fbox{\vbox{\small\halign{\hfil##\hfil\cr
171   #1\mathstrut\cr\noalign{\hrule height.4pt}\strut#2\cr}}}}\,}}
172
173 \protected\def\Param#1{\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.}, \verb+\special+ node) and kerns from
349       italic correction are ignored in the insertion process.
350 %</en>
351 %<*ja>
352 \item さらに,2つの文字の間にある行末では効果を持たないノード(例えば \verb+\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{verbatim}
366 ちょ{}っと    ちょ\/っと
367 \end{verbatim}
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{verbatim}
375 ちょ\hbox{}っと
376 \end{verbatim}
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 \verb+\西暦+ などが正しく動作するようにしている.
392 但し,制御綴中に使える和文文字が\pTeX・\upTeX と全く同じではないことに注意すること.
393 %</ja>
394
395 %<*ja>
396 \item ****版からは,不安定ながらも\LuaTeX-ja における縦組みをサポートしている.
397 \LuaTeX のコールバックの制限などにより,特に異なった組方向のボックスを扱う場合には
398 仕様が異なるので注意すること.
399 %</ja>
400 \end{itemize}
401
402 %<*en>
403 For detailed information, see Part~\ref{part-imp}.
404 %</en>
405 %<*ja>
406 詳細については第\ref{part-imp}部を参照.
407 %</ja>
408
409 %<en>\subsection{Notations}
410 %<ja>\subsection{用語と記法}
411
412 %<*en>
413 In this document, the following terms and notations are used:
414 %</en>
415 %<*ja>
416 本ドキュメントでは,以下の用語と記法を用いる:
417 %</ja>
418 \begin{itemize}
419 %<*en>
420 \item Characters are classified into following two types.
421       Note that the classification can be customized by a user
422       (see Subsection~\ref{ssec-setrange}).
423 %</en>
424 %<*ja>
425 \item 文字は次の2種類に分けられる.この類別はユーザが後から変更可能である
426       (\ref{ssec-setrange}節を参照).
427 %</ja>
428 \begin{itemize}
429 %<*en>
430 \item \textbf{JAchar}: standing for characters which used in Japanese typesetting,
431       such as Hiragana,~Katakana, Kanji, and~other Japanese punctuation marks.
432 %</en>
433 %<*ja>
434 \item \textbf{JAchar}: ひらがな,カタカナ,漢字,和文用の約物といった
435       日本語組版に使われる文字のことを指す.
436 %</ja>
437
438 %<en>\item \textbf{ALchar}: standing for all other characters like latin alphabets.
439 %<ja>\item \textbf{ALchar}: ラテンアルファベットを始めとする,その他全ての文字を指す.
440 \end{itemize}
441
442 %<*en>
443 We say \emph{alphabetic fonts} for fonts used in \textbf{ALchar},
444 and \emph{Japanese fonts} for fonts used in \textbf{JAchar}.
445 %</en>
446 %<*ja>
447 そして,\textbf{ALchar}の出力に用いられるフォントを\emph{欧文フォント}と呼び,
448 \textbf{JAchar}の出力に用いられるフォントを\emph{和文フォント}と呼ぶ.
449 %</ja>
450 %<*en>
451 \item A word in a sans-serif font (like \Param{prebreakpenalty})
452       means an internal parameter for Japanese typesetting, and it
453       is used as a key in \verb+\ltjsetparameter+ command.
454 %</en>
455 %<*ja>
456 \item サンセリフ体で書かれた語(例:\Param{prebreakpenalty})は日本語組版用の
457       パラメータを表し,これらは \verb+\ltjsetparameter+ コマンドのキーとして
458       用いられる.
459 %</ja>
460 %<*en>
461 \item A word in typewriter font with underline (like \Pkg{fontspec})
462       means a package or a class of \LaTeX.
463 %</en>
464 %<*ja>
465 \item 下線付きタイプライタ体の語(例:\Pkg{fontspec})は\LaTeX の
466       パッケージやクラスを表す.
467 %</ja>
468 %<*en>
469 \item In this document, natural numbers start from~zero.
470   $\omega$ denotes the set of all natural numbers.
471 %</en>
472 %<*ja>
473 \item 本ドキュメントでは,自然数は0から始まる.自然数全体の集合は$\omega$と表記する.
474 %</ja>
475 \end{itemize}
476
477 %<en>\subsection{About the Project}
478 %<ja>\subsection{プロジェクトについて}
479
480 %<en>\paragraph{Project Wiki} Project Wiki is under construction.
481 %<ja>\paragraph{プロジェクトWiki} プロジェクトWikiは構築中である.
482 %<*en>
483 \begin{itemize}
484 \item \url{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage%28en%29} (English)
485 \item \url{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage} (Japanese)
486 \item \url{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage%28zh%29} (Chinese)
487 \end{itemize}
488 %</en>
489 %<*ja>
490 \begin{itemize}
491 \item \url{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage}(日本語)
492 \item \url{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage%28en%29}(英語)
493 \item \url{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage%28zh%29}(中国語)
494 \end{itemize}
495 %</ja>
496
497 %<en>This project is hosted by SourceForge.JP.
498 %<ja>本プロジェクトはSourceForge.JPのサービスを用いて運営されている.
499
500 %<en>\paragraph{Members}\
501 %<ja>\paragraph{開発メンバー}\
502
503 %<*en>
504 \begin{multienumerate}
505 \def\labelenumi{$\bullet$}
506 \mitemxxx{Hironori KITAGAWA}{Kazuki MAEDA}{Takayuki YATO}
507 \mitemxxx{Yusuke KUROKI}{Noriyuki ABE}{Munehiro YAMAMOTO}
508 \mitemxxx{Tomoaki HONDA}{Shuzaburo SAITO}{MA Qiyuan}
509 \end{multienumerate}
510 %</en>
511 %<*ja>
512 \begin{multienumerate}
513 \def\labelenumi{$\bullet$}
514 \mitemxxx{北川 弘典}{前田 一貴}{八登 崇之}
515 \mitemxxx{黒木 裕介}{阿部 紀行}{山本 宗宏}
516 \mitemxxx{本田 知亮}{齋藤 修三郎}{馬 起園}
517 \end{multienumerate}
518 %</ja>
519
520 % \paragraph{Acknowledgments} -- 挿入するならここ
521
522 \clearpage
523 %<en>\section{Getting Started}
524 %<ja>\section{使い方}
525 %<en>\subsection{Installation}
526 %<ja>\subsection{インストール}
527
528 %<en>To install the \LuaTeX-ja\ package, you will need:
529 %<ja>\LuaTeX-jaパッケージのインストールには,次のものが必要である.
530 \begin{itemize}
531 \item \LuaTeX\ beta-0.74.0 (or later)
532 \item \Pkg{luaotfload} v2.2 (or later)
533 \item \Pkg{luatexbase} v0.6
534 \item \Pkg{xunicode} v0.981~(2011/09/09)
535 \item \Pkg{adobemapping} (Adobe cmap and pdfmapping files)
536 \item \Pkg{everysel}
537 \end{itemize}
538
539 %<*en>
540 \emph{This version of \LuaTeX-ja no longer supports \TeX~Live~2012 (or older version),
541 since \LuaTeX\ binary and \Pkg{luaotfload} is updated in
542 \TeX~Live~2013.}
543
544 \medskip
545
546 Now \LuaTeX-ja is available from the following archive and distributions:
547   \begin{itemize}
548   \item CTAN (in the \texttt{macros/luatex/generic/luatexja} directory)
549   \item MiK\TeX\ (in \texttt{luatexja.tar.lzma}); see the next subsection
550   \item \TeX\ Live (in \texttt{texmf-dist/tex/luatex/luatexja})
551   \item W32\TeX\ (in \texttt{luatexja.tar.xz})
552   \end{itemize}
553
554 If you are using \TeX~Live~2013, you can install \LuaTeX-ja
555 from \TeX~Live manager (\texttt{tlmgr}):
556 \begin{verbatim}
557 $ tlmgr install luatexja
558 \end{verbatim}
559 %</en>
560 %<*ja>
561 \emph{本バージョンの\LuaTeX-jaは\TeX~Live~2012以前では動作しない.}
562 これは,\LuaTeX と\Pkg{luaotfload}が\TeX~Live~2013において更新されたことによる.
563
564 \medskip
565
566 現在,\LuaTeX-jaは以下のアーカイブ,およびディストリビューションに収録されている:
567   \begin{itemize}
568   \item CTAN (\texttt{macros/luatex/generic/luatexja})
569   \item MiK\TeX\ (\texttt{luatexja.tar.lzma})
570   \item \TeX\ Live (\texttt{texmf-dist/tex/luatex/luatexja})
571   \item W32\TeX\ (\texttt{luatexja.tar.xz})
572   \end{itemize}
573
574 例えば\TeX~Live~2013以降を利用しているなら,\LuaTeX-jaは\TeX~Live manager (\texttt{tlmgr})を
575 使ってインストールすることができる.
576 \begin{verbatim}
577 $ tlmgr install luatexja
578 \end{verbatim}
579 %</ja>
580
581 %<en>\paragraph{Manual installation}
582 %<ja>\paragraph{手動インストール方法}
583
584 \begin{enumerate}
585 %<*en>
586 \item Download the source archive, by one of the following method.
587       At the present, \LuaTeX-ja has no \emph{stable} release.
588
589 \begin{itemize}
590 \item Copy the Git repository:
591 \begin{verbatim}
592 $ git clone git://git.sourceforge.jp/gitroot/luatex-ja/luatexja.git
593 \end{verbatim}
594 \item Download the \texttt{tar.gz} archive of HEAD in the \texttt{master} branch from
595 \begin{flushleft}
596 \url{http://git.sourceforge.jp/view?p=luatex-ja/luatexja.git;a=snapshot;h=HEAD;sf=tgz}.
597 \end{flushleft}
598 \end{itemize}
599
600 Note that the \texttt{master} branch, and hence the archive in CTAN, are not updated frequently;
601 the forefront of development is not the \texttt{master} branch.
602 %</en>
603 %<*ja>
604 \item ソースアーカイブを以下のいずれかの方法で取得する.現在公開されているのはあくまでも
605       開発版であって,安定版でないことに注意.
606
607 \begin{itemize}
608 \item Gitリポジトリの内容をコピーする:
609 \begin{verbatim}
610 $ git clone git://git.sourceforge.jp/gitroot/luatex-ja/luatexja.git
611 \end{verbatim}
612 \item \texttt{master}ブランチのスナップショット(\texttt{tar.gz}形式)をダウンロードする.
613 \begin{flushleft}
614 \url{http://git.sourceforge.jp/view?p=luatex-ja/luatexja.git;a=snapshot;h=HEAD;sf=tgz}.
615 \end{flushleft}
616 \end{itemize}
617 \texttt{master}ブランチ(従って,CTAN内のアーカイブも)はたまにしか更新されないことに注意.
618 主な開発は\texttt{master}の外で行われ,比較的まとまってきたらそれを\texttt{master}に
619 反映させることにしている.
620 %</ja>
621
622 %<*en>
623 \item Extract the archive. You will see \texttt{src/} and several other sub-directories.
624 But only the contents in \texttt{src/} are needed to work \LuaTeX-ja.
625 %</en>
626 %<*ja>
627 \item 「Gitリポジトリをコピー」以外の方法でアーカイブを取得したならば,それを展開する.
628       \texttt{src/}をはじめとしたいくつかのディレクトリができるが,
629       動作には\texttt{src/}以下の内容だけで十分.
630 %</ja>
631
632 %<*en>
633 \item If you downloaded this package from CTAN, you have to run following commands
634     to generate classes
635     and \texttt{ltj-kinsoku.lua} (the file which stores default ``\textit{kinsoku}'' parameters):
636 %</en>
637 %<*ja>
638 \item もしCTANから本パッケージを取得したのであれば,日本語用クラスファイルや
639 標準の禁則処理用パラメータを
640 格納した \texttt{ltj-kinsoku.lua} を生成するために,
641 以下を実行する必要がある:
642 %</ja>
643 \begin{verbatim}
644 $ cd src
645 $ lualatex ltjclasses.ins
646 $ lualatex ltjsclasses.ins
647 $ lualatex ltjltxdoc.ins
648 $ luatex   ltj-kinsoku_make.tex
649 \end{verbatim}
650 %<*en>
651 Note that \texttt{*.\{dtx,ins\}} and \texttt{ltj-kinsoku\_make.tex} are not needed in regular use.
652 %</en>
653 %<*ja>
654 ここで使用した \texttt{*.\{dtx,ins\}} と \texttt{ltj-kinsoku\_make.tex} は
655 通常の使用にあたっては必要ない.
656 %</ja>
657
658
659
660 %<*en>
661 \item Copy all the contents of \texttt{src/} into one of your \texttt{TEXMF} tree.
662       \texttt{TEXMF/tex/luatex/luatexja/} is an example location.
663       If you cloned entire Git repository, making a symbolic link of \texttt{src/}
664       instead copying is also good.
665 %</en>
666 %<*ja>
667 \item \texttt{src}の中身を自分の\texttt{TEXMF}ツリーにコピーする.
668       場所の例としては,例えば\texttt{TEXMF/tex/luatex/luatexja/}がある.
669       シンボリックリンクが利用できる環境で,かつリポジトリを直接取得したのであれば,
670       (更新を容易にするために)コピーではなくリンクを貼ることを勧める.
671 %</ja>
672 %<*en>
673 \item If \texttt{mktexlsr} is needed to update the file name database, make it so.
674 %</en>
675 %<*ja>
676 \item 必要があれば,\texttt{mktexlsr}を実行する.
677 %</ja>
678 \end{enumerate}
679
680 %<en>\subsection{Cautions}
681 %<ja>\subsection{注意点}
682
683 \begin{itemize}
684 %<*en>
685 \item The encoding of your source file must be UTF-8. No other
686       encodings, such as EUC-JP or Shift-JIS, are not supported.
687 %</en>
688 %<*ja>
689 \item 原稿のソースファイルの文字コードはUTF-8固定である.
690       従来日本語の文字コードとして用いられてきたEUC-JPやShift-JISは使用できない.
691 %</ja>
692 %<*en>
693 \item \LuaTeX-ja is very slower than \pTeX.
694 Generally speaking, LuaJIT\TeX\ processes \LuaTeX-ja
695 about 30\% faster than \LuaTeX, but not always.
696 %</en>
697 %<*ja>
698 \item \LuaTeX-jaは動作が\pTeX に比べて非常に遅い.
699 コードを調整して徐々に速くしているが,まだ満足できる速度ではない.
700 LuaJIT\TeX を用いると\LuaTeX のだいたい1.3倍の速度で動くようであるが,
701 IPA mj明朝などの大きいフォントを用いた場合には\LuaTeX よりも遅くなることもある.
702 %</ja>
703 \item%
704 %<*en>
705 \textbf{Note for MiK\TeX\ users}\quad
706 \LuaTeX-ja requires that several CMap files%
707 \footnote{\texttt{UniJIS2004-UTF32-\{H,V\}} and \texttt{Adobe-Japan1-UCS2}.}
708 must be found from \LuaTeX.
709 Strictly speaking, those CMaps are needed
710 only in the first run of \LuaTeX-ja after installing or updating.
711 But it seems that MiK\TeX\ does not satisfy this condition,
712 so you will encounter an error like the following:
713 %</en>
714 %<*ja>
715 \LuaTeX-jaが動作するためには,\emph{導入・更新後の初回起動時に}
716 \texttt{UniJIS2004-UTF32-\{H,V\}}, \texttt{Adobe-Japan1-UCS2}という3つのCMapが
717 \LuaTeX によって見つけられることが必要である.
718 しかしMiK\TeX ではそのようになっていないので,次のエラーが発生するだろう:
719 %</ja>
720 \begin{verbatim}
721 ! LuaTeX error ...iles (x86)/MiKTeX 2.9/tex/luatex/luatexja/ltj-rmlgbm.lua
722 bad argument #1 to 'open' (string expected, got nil)
723 \end{verbatim}
724
725 %<*en>
726 If so, please execute a batch file which is written on
727 \href{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage%28en%29}{ the Project Wiki (English)}.
728 This batch file creates a temporary directory, copy CMaps in it,
729 run \LuaTeX-ja in this directory, and finally delete the temporary directory.
730 %</en>
731 %<*ja>
732 そのような場合には,
733 \href{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage%28en%29}{%
734   プロジェクトWiki英語版トップページ}中に書かれているバッチファイルを
735 実行して欲しい.このバッチファイルは,作業用ディレクトリにCMap達を
736 コピーし,その中で\LuaTeX-ja の初回起動を行い,作業用ディレクトリを消す作業をしている.
737 %</ja>
738
739 \end{itemize}
740
741 %<en>\subsection{Using in plain \TeX}
742 %<ja>\subsection{plain \TeX で使う}
743 \label{ssec-plain}
744
745 %<en>To use \LuaTeX-ja in plain \TeX, simply put the following at the beginning of the document:
746 %<ja>\LuaTeX-jaを plain \TeX で使うためには,単に次の行をソースファイルの冒頭に追加すればよい:
747 \begin{verbatim}
748 \input luatexja.sty
749 \end{verbatim}
750 %<en>This does minimal settings (like \texttt{ptex.tex}) for typesetting Japanese documents:
751 %<ja>これで(\texttt{ptex.tex}のように)日本語組版のための最低限の設定がなされる:
752
753 \begin{itemize}
754 %<*en>
755 \item The following 12~Japanese fonts are preloaded:
756 \begin{center}\small
757 \begin{tabular}{cccccc}
758 \toprule
759 \textbf{direction}&
760 \textbf{classification}&\textbf{font name}&\bf `10\,pt'&\bf`7\,pt'&\bf`5\,pt'\\\midrule
761 \smash{\raisebox{-1ex}{\emph{yoko} (horizontal)}}&
762 \emph{mincho}&Ryumin-Light    &\verb+\tenmin+&\verb+\sevenmin+&\verb+\fivemin+\\
763 \emph{gothic}&GothicBBB-Medium&\verb+\tengt+ &\verb+\sevengt+ &\verb+\fivegt+\\
764 \midrule
765 \smash{\raisebox{-1ex}{\emph{tate} (vertical)}}&
766 \emph{mincho}&Ryumin-Light    &\verb+\tentmin+&\verb+\seventmin+&\verb+\fivetmin+\\
767 \emph{gothic}&GothicBBB-Medium&\verb+\tentgt+ &\verb+\seventgt+ &\verb+\fivetgt+\\
768 \bottomrule
769 \end{tabular}
770 \end{center}
771 %</en>
772 %<*ja>
773 \item 以下の12個の和文フォントが定義される:
774 \begin{center}\small
775 \begin{tabular}{cccccc}
776 \toprule
777 \emph{組方向}&\emph{字体}&\emph{フォント名}&\bf `10\,pt'&\bf`7\,pt'&\bf`5\,pt'\\\midrule
778 \smash{\raisebox{-1ex}{横組}}&
779 明朝体&Ryumin-Light    &\verb+\tenmin+&\verb+\sevenmin+&\verb+\fivemin+\\
780 ゴシック体&GothicBBB-Medium&\verb+\tengt+ &\verb+\sevengt+ &\verb+\fivegt+\\
781 \midrule
782 \smash{\raisebox{-1ex}{縦組}}&
783 明朝体&Ryumin-Light    &\verb+\tentmin+&\verb+\seventmin+&\verb+\fivetmin+\\
784 ゴシック体&GothicBBB-Medium&\verb+\tentgt+ &\verb+\seventgt+ &\verb+\fivetgt+\\
785 \bottomrule
786 \end{tabular}
787 \end{center}
788 %</ja>
789 \begin{itemize}
790 %<*en>
791 \item It is widely accepted that fonts ``Ryumin-Light'' and
792       ``GothicBBB-Medium'' aren't embedded into PDF files, and a PDF reader
793       substitute them by some external Japanese fonts (\textit{e.g.},
794       Ryumin-Light is substituted with Kozuka Mincho in Adobe Reader).
795       We adopt this custom to the default setting.
796 %</en>
797 %<*ja>
798 \item ``Ryumin-Light''と``GothicBBB-Medium''はPDFファイルに埋め込まずに
799       名前参照のみで用いることが広く受け入れられており,この場合PDFリーダーが
800       適切な外部フォントで代用する(例えば,Adobe ReaderではRyumin-Lightは
801       小塚明朝で代替される).そこで,これらを引き続きデフォルトのフォントと
802       して採用する.
803 %</ja>
804
805 %<*en>
806 \item A character in an alphabetic font is generally smaller than a
807       Japanese font in the same size. So actual size specification of
808       these Japanese fonts is in fact smaller than that of alphabetic
809       fonts, namely scaled by 0.962216.
810 %</en>
811 %<*ja>
812 \item 欧文フォントの文字は和文フォントの文字よりも,同じ文字サイズでも
813       一般に小さくデザインされている.そこで,標準ではこれらの和文フォントの実際のサイズは指定された値よりも
814       小さくなるように設定されており,具体的には指定の0.962216倍にスケールされる.
815       この0.962216という数値も,\pTeX におけるスケーリングを踏襲した値である.
816 %</ja>
817 \end{itemize}
818
819 %<*en>
820 \item The amount of glue that are inserted between a \textbf{JAchar} and
821       an \textbf{ALchar} (the parameter \Param{xkanjiskip}) is set to
822 %</en>
823 %<*ja>
824 \item \textbf{JAchar}と\textbf{ALchar}の間に入るグルー(\Param{xkanjiskip})の
825       量は次のように設定されている:
826 %</ja>
827 \[
828  (0.25\cdot 0.962216\cdot 10\,\mathrm{pt})^{+1\,\text{pt}}_{-1\,\text{pt}}
829  = 2.40554\,\mathrm{pt}^{+1\,\text{pt}}_{-1\,\text{pt}}.
830 \]
831 \end{itemize}
832
833 %<en>\subsection{Using in \LaTeX}
834 %<ja>\subsection{\LaTeX で使う}
835 \label{ssec-ltx}
836
837 \paragraph{\LaTeXe}
838
839 %<*en>
840 Using in \LaTeXe\ is basically same. To set up the minimal environment
841 for Japanese, you only have to load \texttt{luatexja.sty}:
842 %</en>
843 %<*ja>
844 \LaTeXe を用いる場合も基本的には同じである.日本語組版のための最低限の環境を
845 設定するためには,\texttt{luatexja.sty}を読み込むだけでよい:
846 %</ja>
847 \begin{verbatim}
848 \usepackage{luatexja}
849 \end{verbatim}
850 %<*en>
851 It also does minimal settings (counterparts in \pLaTeX\ are \texttt{%
852 plfonts.dtx} and \texttt{pldefs.ltx}):
853 %</en>
854 %<*ja>
855 これで\pLaTeX の\texttt{plfonts.dtx}と\texttt{pldefs.ltx}に相当する最低限の設定が
856 なされる:
857 %</ja>
858
859 \begin{itemize}
860 %<*en>
861 \item The font encoding for Japanese fonts (for horizontal direction) is \texttt{JY3}.\\
862 \texttt{JT3} is used for Japanese fonts for vertical direction.
863 %</en>
864 %<*ja>
865 \item 和文フォントのエンコーディングとしては,横組用には \texttt{JY3},縦組用には\
866 \texttt{JT3}が用いられる.
867 %</ja>
868
869 %<*en>
870 \item Traditionally, Japanese documents use two typeface category: \emph{mincho}~(明朝体) and
871  \emph{gothic}~(\textgt{ゴシック体}). \emph{mincho} is used in the main text, while \emph{gothic}
872       is used in the headings or for emphasis.
873 \begin{center}\small
874 \begin{tabular}{lllc}
875 \toprule
876 \textbf{classification}&&&\textbf{family name}\\\midrule
877 \emph{mincho} (明朝体)&\verb+\textmc{...}+&\verb+{\mcfamily ...}+&\verb+\mcdefault+\\
878 \emph{gothic} (\textgt{ゴシック体})&\verb+\textgt{...}+&\verb+{\gtfamily ...}+&\verb+\gtdefault+\\
879 \bottomrule
880 \end{tabular}
881 \end{center}
882 \item
883 By default, the following fonts are used for \emph{mincho} and \emph{gothic}:
884 \begin{center}\small
885 \begin{tabular}{ccccc}
886 \toprule
887 \textbf{classification}&\textbf{family name}&\verb+\mdseries+&\verb+\bfseries+&\textbf{scale}\\\midrule
888 \emph{mincho} (明朝体)&\tt mc&Ryumin-Light    &GothicBBB-Medium&0.962216\\
889 \emph{gothic} (\textgt{ゴシック体})&\tt gt&GothicBBB-Medium&GothicBBB-Medium&0.962216\\
890 \bottomrule
891 \end{tabular}
892 \end{center}
893 Note that the bold series in both family are same as the medium series of \emph{gothic} family.
894 This is a convention in \pLaTeX. This is trace that there were only 2~fonts (these are Ryumin-Light
895 and GothicBBB-Medium) in early years of DTP. There is no italic nor slanted shape for
896       these \texttt{mc}~and~\texttt{gt}.
897 %</en>
898 %<*ja>
899 \item \pLaTeX と同様に,標準では「明朝体」「ゴシック体」の2種類を用いる:
900 \begin{center}\small
901 \begin{tabular}{cllc}
902 \toprule
903 \emph{字体}&&&\emph{ファミリ名}\\\midrule
904 明朝体&\verb+\textmc{...}+&\verb+{\mcfamily ...}+&\verb+\mcdefault+\\
905 \textgt{ゴシック体}&\verb+\textgt{...}+&\verb+{\gtfamily ...}+&\verb+\gtdefault+\\
906 \bottomrule
907 \end{tabular}
908 \end{center}
909 \item 標準では,次のフォントファミリが用いられる:
910 \begin{center}\small
911 \begin{tabular}{ccccc}
912 \toprule
913 \emph{字体}&\emph{ファミリ}&\verb+\mdseries+&\verb+\bfseries+&\emph{スケール}\\\midrule
914 明朝体&\tt mc&Ryumin-Light    &GothicBBB-Medium&0.962216\\
915 ゴシック体&\tt gt&GothicBBB-Medium&GothicBBB-Medium&0.962216\\
916 \bottomrule
917 \end{tabular}
918 \end{center}
919 どちらのファミリにおいても,そのboldシリーズで使われるフォントは
920 ゴシック体のmediumシリーズで使われるフォントと同じあることに注意.
921 これは初期のDTPにおいて和文フォントが2つ(それがちょうど\
922 Ryumin-Light, GothicBBB-Mediumだった)しか利用できなかった時の名残であり,\pLaTeX{}
923 での標準設定とも同じである.
924 %</ja>
925
926
927 %<en>\item Japanese characters in math mode are typeset by the font family \texttt{mc}.
928 %<ja>\item 数式モード中の和文文字は明朝体(\texttt{mc})で出力される.
929 \end{itemize}
930
931 %<*en>
932 However, above settings are not sufficient for Japanese-based
933 documents. To typeset Japanese-based documents, you are better to use
934 class files other than \texttt{article.cls}, \texttt{book.cls}, and so on.  At
935 the present, we have the counterparts of \Pkg{jclasses} (standard
936 classes in \pLaTeX) and \Pkg{jsclasses} (classes by Haruhiko
937 Okumura), namely, \Pkg{ltjclasses} and \Pkg{ltjsclasses}.
938 %</en>
939 %<*ja>
940 しかしながら,上記の設定は日本語の文書にとって十分とは言えない.
941 日本語文書を組版するためには,\texttt{article.cls}, \texttt{book.cls}といった
942 欧文用のクラスファイルではなく,和文用のクラスファイルを用いた方がよい.
943 現時点では,\Pkg{jclasses}(\pLaTeX の標準クラス)と\Pkg{jsclasses}
944 (奥村晴彦氏による「\pLaTeXe 新ドキュメントクラス」)に対応するものとして,\Pkg{ltjclasses},
945 \Pkg{ltjsclasses}がそれぞれ用意されている.
946 %</ja>
947
948 %<en>\section{Changing Fonts}
949 %<ja>\section{フォントの変更}
950
951 \subsection{plain \TeX~and~\LaTeXe}
952 \label{ssec-chgfnt}
953
954 \paragraph{plain \TeX}
955 %<*en>
956 To change Japanese fonts in plain \TeX, you must use the command
957 \verb+\jfont+~and~\verb+\tfont+. So please see Subsection~\ref{ssec-jfont}.
958 %</en>
959 %<*ja>
960 plain \TeX で和文フォントを変更するためには,
961 \pTeX のように \verb+\jfont+ 命令や \verb+\tfont+ 命令を直接用いる.
962 \ref{ssec-jfont}節を参照.
963 %</ja>
964
965 \paragraph{\LaTeXe\ (NFSS2)}
966 %<*en>
967 For \LaTeXe, \LuaTeX-ja adopted most of the font selection system of \pLaTeXe\ (in \texttt{plfonts.dtx}).
968 %</en>
969 %<*ja>
970 \LaTeXe については,\LuaTeX-jaではフォント選択システムを\pLaTeXe\ (\texttt{plfonts.dtx})
971 の大部分をそのまま採用している.
972 %</ja>
973 \begin{itemize}
974 %<*en>
975 \item Commands \verb+\fontfamily+, \verb+\fontseries+,
976       \verb+\fontshape+, and \verb+\selectfont+ can be used to change
977       attributes of Japanese fonts.
978 %</en>
979 %<*ja>
980 \item \verb+\fontfamily+, \verb+\fontseries+, \verb+\fontshape+, そして
981       \verb+\selectfont+ が和文フォントの属性を変更するために使用できる.
982 %</ja>
983
984 %<*en>
985 \begin{center}\small
986 \begin{tabular}{cccccc}
987 \toprule
988 &\textbf{encoding}&\textbf{family}&\textbf{series}&\textbf{shape}&\textbf{selection}\\\midrule
989 alphabetic fonts
990 &\verb+\romanencoding+&\verb+\romanfamily+&\verb+\romanseries+&\verb+\romanshape+
991 &\verb+\useroman+\\
992 Japanese fonts
993 &\verb+\kanjiencoding+&\verb+\kanjifamily+&\verb+\kanjiseries+&\verb+\kanjishape+
994 &\verb+\usekanji+\\
995 both&---&--&\verb+\fontseries+&\verb+\fontshape+&---\\
996 auto select&\verb+\fontencoding+&\verb+\fontfamily+&---&---&\verb+\usefont+\\
997 \bottomrule
998 \end{tabular}
999 \end{center}
1000 %</en>
1001 %<*ja>
1002 \begin{center}\small
1003 \begin{tabular}{cccccc}
1004 \toprule
1005 &\emph{エンコーディング}&\emph{ファミリ}&\emph{シリーズ}&\emph{シェープ}&\emph{選択}\\\midrule
1006 欧文
1007 &\verb+\romanencoding+&\verb+\romanfamily+&\verb+\romanseries+&\verb+\romanshape+
1008 &\verb+\useroman+\\
1009 和文
1010 &\verb+\kanjiencoding+&\verb+\kanjifamily+&\verb+\kanjiseries+&\verb+\kanjishape+
1011 &\verb+\usekanji+\\
1012 両方&---&--&\verb+\fontseries+&\verb+\fontshape+&---\\
1013 自動選択&\verb+\fontencoding+&\verb+\fontfamily+&---&---&\verb+\usefont+\\
1014 \bottomrule
1015 \end{tabular}
1016 \end{center}
1017 %</ja>
1018
1019 %<*en>
1020       \verb+\fontencoding{+<encoding>\verb+}+ changes the encoding of alphabetic fonts
1021       or Japanese fonts depending on the argument. For example,
1022       \verb+\fontencoding{JY3}+ changes the encoding of Japanese fonts to
1023       \texttt{JY3},and \verb+\fontencoding{T1}+ changes the encoding of
1024       alphabetic fonts to \texttt{T1}.
1025       \verb+\fontfamily+ also changes the current Japanese font family,
1026       the current alphabetic font family, \emph{or both}.
1027       For the detail, see Subsection~\ref{ssec-nfsspat}.
1028 %</en>
1029 %<*ja>
1030       ここで,\verb+\fontencoding{+<encoding>\verb+}+ は,引数により和文側か欧文
1031       側かのどちらかのエンコーディングを変更する.例えば,
1032       \verb+\fontencoding{JY3}+ は和文フォントのエンコーディングを
1033       \texttt{JY3}に変更し,\verb+\fontencoding{T1}+ は欧文フォント側を
1034       \texttt{T1}へと変更する.\verb+\fontfamily+ も引数により和文側,欧文
1035       側,\emph{あるいは両方}のフォントファミリを変更する.詳細は
1036       \ref{ssec-nfsspat}節を参照すること.
1037 %</ja>
1038
1039 %<*en>
1040 \item For defining a Japanese font family, use
1041       \verb+\DeclareKanjiFamily+ instead of
1042       \verb+\DeclareFontFamily+. However, in the present implementation,
1043       using \verb+\DeclareFontFamily+ doesn't cause any problem.
1044 \item Defining a Japanese font shape can be done by usual \verb+\DeclareFontShape+:
1045 %</en>
1046 %<*ja>
1047 \item 和文フォントファミリの定義には \verb+\DeclareFontFamily+ の
1048       代わりに \verb+\DeclareKanjiFamily+ を用いる.しかし,現在の
1049       実装では \verb+\DeclareFontFamily+ を用いても問題は生じない.
1050 \item 和文フォントのシェイプを定義するには,通常の \verb+\DeclareFontShape+ を使えば良い:
1051 %</ja>
1052 \begin{verbatim}
1053 \DeclareFontShape{JY3}{mc}{bx}{n}{<-> s*KozMinPr6N-Bold:jfm=ujis;-kern}{}
1054     % Kozuka Mincho Pr6N Bold
1055 \end{verbatim}
1056 %<*ja>
1057 仮名書体を使う場合など,複数の和文フォントを組み合わせて使いたい場合は
1058 \ref{ssec-altfont}節の \verb+\ltjdeclarealtfont+ と,その\LaTeX 版の\
1059 \verb+\DeclareAlternateKanjiFont+(\ref{ssec-nfsspat}節)を参照せよ.
1060 %</ja>
1061 \end{itemize}
1062
1063 %<*en>
1064 \paragraph{Remark: Japanese characters in math mode}
1065 Since \pTeX\ supports Japanese characters in math mode, there are
1066 sources like the following:
1067 %</en>
1068 %<*ja>
1069 \paragraph{注意:数式モード中の和文文字}
1070 \pTeX では,特に何もしないでも数式中に和文文字を記述することができた.そのため,
1071 以下のようなソースが見られた:
1072 %</ja>
1073
1074 \begin{LTXexample}
1075 $f_{高温}$~($f_{\text{high temperature}}$).
1076 \[ y=(x-1)^2+2\quad よって\quad y>0 \]
1077 $5\in 素:=\{\,p\in\mathbb N:\text{$p$ is a prime}\,\}$.
1078 \end{LTXexample}
1079 %<*en>
1080 We (the project members of \LuaTeX-ja) think that using
1081 Japanese characters in math mode are allowed if and only if these are used as identifiers.
1082 In this point of view,
1083 %</en>
1084 %<*ja>
1085 \LuaTeX-jaプロジェクトでは,数式モード中での和文文字はそれらが識別子として用いられる
1086 ときのみ許されると考えている.
1087 この観点から,
1088 %</ja>
1089
1090 \begin{itemize}
1091 %<*en>
1092 \item The lines 1~and~2 above are not correct, since ``高温'' in above is used as a textual label, and
1093 ``よって'' is used as a conjunction.
1094 %</en>
1095 %<*ja>
1096 \item 上記数式のうち1, 2行目は正しくない.なぜならば「高温」が意味のあるラベルと
1097       して,「よって」が接続詞として用いられているからである.
1098 %</ja>
1099 %<en>\item However, the line~3 is correct, since ``素'' is used as an identifier.
1100 %<ja>\item しかしながら,3行目は「素」が単なる識別子として用いられているので正しい.
1101 \end{itemize}
1102 %<en>Hence, in our opinion, the above input should be corrected as:
1103 %<ja>したがって,\LuaTeX-jaプロジェクトの意見としては,上記の入力は次のように直されるべきである:
1104 \begin{LTXexample}
1105 $f_{\text{高温}}$~%
1106 ($f_{\text{high temperature}}$).
1107 \[ y=(x-1)^2+2\quad
1108   \mathrel{\text{よって}}\quad y>0 \]
1109 $5\in 素:=\{\,p\in\mathbb N:\text{$p$ is a prime}\,\}$.
1110 \end{LTXexample}
1111 %<*en>
1112 We also believe that using Japanese characters as identifiers is rare,
1113 hence we don't describe how to change Japanese fonts in math mode in
1114 this chapter. For the method, please see Subsection~\ref{ssec-math}.
1115 %</en>
1116 %<*ja>
1117 また\LuaTeX-jaプロジェクトでは,和文文字が識別子として用いられることはほとんどない
1118 と考えており,したがってこの節では数式モード中の和文フォントを変更する方法については
1119 記述しない.この方法については\ref{ssec-math}節を参照のこと.
1120 %</ja>
1121
1122
1123 \subsection{fontspec}
1124 \label{ssec-fontspec}
1125 %<*en>
1126 To coexist with the \Pkg{fontspec} package, it is needed to load
1127 \Pkg{luatexja-fontspec} package in the preamble, as follows:
1128 \begin{quote}
1129 \ttfamily \textbackslash usepackage[<options>]\{luatexja-fontspec\}
1130 \end{quote}
1131 This \Pkg{luatexja-fontspec} package
1132 automatically loads \Pkg{luatexja} and \Pkg{fontspec}
1133 package, if needed.
1134 %</en>
1135 %<*ja>
1136 \Pkg{fontspec}パッケージと同様の機能を和文フォントに対しても用いる場合,
1137 \Pkg{luatexja-fontspec}パッケージを読み込む:
1138 \begin{quote}
1139 \ttfamily \textbackslash usepackage[<options>]\{luatexja-fontspec\}
1140 \end{quote}
1141 このパッケージ
1142 は必要ならば自動で\Pkg{luatexja}パッケージと\Pkg{fontspec}パッケージを読み込む.
1143 %</ja>
1144
1145 %<*en>
1146 In \Pkg{luatexja-fontspec} package, the following seven~commands are defined as
1147 counterparts of original commands in the \Pkg{fontspec} package:
1148 %</en>
1149 %<*ja>
1150 \Pkg{luatexja-fontspec}パッケージでは,以下の7つのコマンドを\Pkg{fontspec}
1151 パッケージの元のコマンドに対応するものとして定義している:
1152 %</ja>
1153 %<*en>
1154 \begin{center}\small
1155 \begin{tabular}{ccccc}
1156 \toprule
1157 Japanese fonts
1158 &\verb+\jfontspec+&\verb+\setmainjfont+&\verb+\setsansjfont+&\verb+\setmonojfont+$^*$\\
1159 alphabetic fonts
1160 &\verb+\fontspec+&\verb+\setmainfont+&\verb+\setsansfont+&\verb+\setmonofont+\\
1161 \midrule
1162 Japanese fonts
1163 &\verb+\newjfontfamily+&\verb+\newjfontface+
1164 &\verb+\defaultjfontfeatures+&\verb+\addjfontfeatures+\\
1165 alphabetic fonts
1166 &\verb+\newfontfamily+&\verb+\newfontface+
1167 &\verb+\defaultfontfeatures+&\verb+\addfontfeatures+\\
1168 \bottomrule
1169 \end{tabular}
1170 \end{center}
1171 %</en>
1172 %<*ja>
1173 \begin{center}\small
1174 \begin{tabular}{cccc}
1175 \toprule
1176 和文
1177 &\verb+\jfontspec+&\verb+\setmainjfont+&\verb+\setsansjfont+\\
1178 欧文
1179 &\verb+\fontspec+&\verb+\setmainfont+&\verb+\setsansfont+\\
1180 \midrule
1181 和文
1182 &\verb+\newjfontfamily+&\verb+\newjfontface+&\verb+\defaultjfontfeatures+\\
1183 欧文
1184 &\verb+\newfontfamily+&\verb+\newfontface+&\verb+\defaultfontfeatures+\\
1185 \midrule
1186 和文
1187 &\verb+\addjfontfeatures+\\
1188 欧文
1189 &\verb+\addfontfeatures+\\
1190 \bottomrule
1191 \end{tabular}
1192 \end{center}
1193 %</ja>
1194 %<*en>
1195 The package option of \Pkg{luatexja-fontspec} are the followings:
1196 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}\advance\leftmargin1\zw}
1197  \item[match] If this option is specified, usual family-changing commands such as
1198 \verb+\rmfamily+,~\verb+\textrm+, \verb+\sffamily+,~\dots\ also change Japanese font family.
1199
1200 Note that \emph{\texttt{\textup{\textbackslash setmonojfont}} is defined
1201 if and only if this \texttt{\textup{match}} option is specified}.
1202
1203  \item[pass=<opts>]
1204 Specify options <opts> which will be passed to the \Pkg{fontspec} package.
1205 \end{list}
1206 The reason that \verb+\setmonojfont+ is not defined by default is that
1207 it is popular for Japanese fonts that nearly all Japanese glyphs have same
1208 widths.  Also note that kerning information in a font is not used
1209 (that is, \texttt{kern} feature is set off) by default in these seven (or~eight) commands.
1210 This is because of the compatibility with previous versions of \LuaTeX-ja
1211 (see \ref{para-kern}).
1212 %</en>
1213 %<*ja>
1214 \Pkg{luatexja-fontspec} パッケージのオプションは以下の通りである:
1215 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}\advance\leftmargin1\zw}
1216  \item[match] このオプションが指定されると,「\pLaTeXe 新ドキュメントクラス」のように\
1217 \verb+\rmfamily+, \verb+\textrm{...}+, \verb+\sffamily+ 等が
1218 欧文フォントだけでなく和文フォントも変更するようになる.
1219
1220 \emph{なお,{\tt \textbackslash setmonojfont} はこの \texttt{match} オプションが
1221 指定された時のみ定義される.}この命令は標準の「タイプライタ体に対応する和文フォント」を指定する.
1222
1223  \item[pass=<opts>]
1224 \Pkg{fontspec} パッケージに渡すオプション <opts> を指定する.
1225 \end{list}
1226 標準で \verb+\setmonojfont+ コマンドが定義されないのは,
1227 和文フォントではほぼ全ての和文文字のグリフが等幅であるのが伝統的であったことによる.
1228 また,これらの和文用のコマンドではフォント内のペアカーニング情報は標準では使用されない,
1229 言い換えれば \texttt{kern} featureは標準では無効化となっている.
1230 これは以前のバージョンの\LuaTeX-jaとの互換性のためである(\ref{para-kern}節を参照).
1231 %</ja>
1232
1233 \begin{LTXexample}[width=0.4\textwidth]
1234 \fontspec[Numbers=OldStyle]{LMSans10-Regular}
1235 \jfontspec[CJKShape=NLC]{KozMinPr6N-Regular}
1236 JIS~X~0213:2004→辻
1237
1238 \jfontspec[CJKShape=JIS1990]{KozMinPr6N-Regular}
1239 JIS~X~0208:1990→辻
1240 \end{LTXexample}
1241
1242 %<en>\subsection{Presets}
1243 %<ja>\subsection{プリセット設定}
1244 \label{ssec-preset}
1245
1246 %<*en>
1247 To use standard Japanese font settings easily, one can load \Pkg{luatexja-preset}
1248 package with several options. This package provides functions in a part of
1249 \Pkg{japanese-otf} package and a part of \Pkg{PXchfon} package by Takayuki Yato,
1250 and loads \Pkg{luatexja-fontspec}, hence \Pkg{fontspec} internally.
1251
1252 If you need to pass some options to \Pkg{fontspec}, load \Pkg{fontspec} manually
1253 before \Pkg{luatexja-preset}:
1254 %</en>
1255 %<*ja>
1256 よく使われている和文フォント設定を一行で指定できるようにしたのが
1257 \Pkg{luatexja-preset}パッケージである.このパッケージは,
1258 \Pkg{otf}パッケージの一部機能と八登崇之氏による\Pkg{PXchfon}パッケージの一部機能とを
1259 合わせたような格好をしており,内部で\Pkg{luatexja-fontspec},従って
1260 \Pkg{fontspec}を読み込んでいる.
1261
1262 もし\Pkg{fontspec}パッケージに何らかのオプションを渡す必要がある
1263 \footnote{例えば,数式フォントまで置換されてしまい,\texttt{\textbackslash mathit}によってギリシャ文字の
1264 斜体大文字が出なくなる,など.}場合は,
1265 次のように\Pkg{luatexja-preset}の前に\Pkg{fontspec}を手動で読みこめば良い:
1266 %</ja>
1267 \begin{verbatim}
1268 \usepackage[no-math]{fontspec}
1269 \usepackage[...]{luatexja-preset}
1270 \end{verbatim}
1271
1272 %<en>\paragraph{General options}
1273 %<ja>\paragraph{一般的なオプション}
1274 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}\advance\leftmargin1\zw}
1275 \item[nodeluxe]
1276 %<*en>
1277 Use one-weighted \textit{mincho} and \textit{gothic} font families.
1278 This means that \verb+\mcfamily\bfseries+, \verb+\gtfamily\bfseries+ and
1279 \verb+\gtfamily\mdseries+ use the same font.
1280 \emph{This option is enabled by default.}
1281 %</en>
1282 %<*ja>
1283 \LaTeXe 環境下での標準設定のように,明朝体・ゴシック体を各1ウェイトで使用する.
1284 より具体的に言うと,この設定の下では
1285 \verb+\mcfamily\bfseries+, \verb+\gtfamily\bfseries+, \verb+\gtfamily\mdseries+は
1286 みな同じフォントとなる.\emph{このオプションは標準で有効になっている.}
1287 %</ja>
1288 \item[deluxe]
1289 %<*en>
1290 Use \textit{mincho} with two weights (medium~and~bold),
1291 \textit{gothic} with three weights (medium, bold~and~heavy), and \textit{rounded gothic}%
1292 \footnote{Provided by \texttt{\textbackslash mgfamily} and \texttt{\textbackslash textmg\{...\}},
1293 because \textit{rounded gothic} is called \textit{maru gothic} (丸ゴシック) in Japanese.}.
1294 The heavy weight of \textit{gothic} can be used by ``changing the family'' \verb+\gtebfamily+,
1295 or \verb+\textgteb{...}+.
1296 This is because \Pkg{fontspec} package can handle only medium (\verb+\mdseries+) and
1297 bold (\verb+\bfseries+).
1298 %</en>
1299 %<*ja>
1300 明朝体2ウェイト・ゴシック体3ウェイトと,
1301 丸ゴシック体 (\verb+\mgfamily+, \verb+\textmg{...}+) を使用可能とする.
1302 ゴシック体は細字・太字・極太の3ウェイトがあるが,
1303 極太ゴシック体はファミリの切り替え (\verb+\gtebfamily+, \verb+\textgteb{...}+) %
1304 で実現している.\Pkg{fontspec}では通常 (\verb+\mdseries+) と太字 (\verb+\bfseries+) しか扱えないために
1305 このような中途半端な実装になっている.
1306 %</ja>
1307 \item[expert]
1308 %<*en>
1309 Use horizontal kana alternates, and define a command \verb+\rubyfamily+ to use kana
1310 characters designed for ruby.
1311 %</en>
1312 %<ja>横組専用仮名を用いる.また,\verb+\rubyfamily+ でルビ用仮名が使用可能となる.
1313 \item[bold]
1314 %<en>Substitute bold series of \textit{gothic} for  bold series of \textit{mincho}.
1315 %<ja>「明朝の太字」をゴシック体の太字によって代替する.
1316 \item[90jis]
1317 %<en>Use 90JIS glyph variants if possible.
1318 %<ja>出来る限り90JISの字形を使う.
1319 \item[jis2004]
1320 %<en>Use JIS2004 glyph variants if possible.
1321 %<ja>出来る限りJIS2004の字形を使う.
1322 \item[jis]
1323 %<*en>
1324 Use the JFM \texttt{jfm-jis.lua}, instead of \texttt{jfm-ujis.lua}, which is the default JFM of
1325 \LuaTeX-ja.
1326 %</en>
1327 %<*ja>
1328 用いるJFMを(JISフォントメトリック類似の)\texttt{jfm-jis.lua}にする.このオプションがない時は
1329 \LuaTeX-ja標準の\texttt{jfm-ujis.lua}が用いられる.
1330 %</ja>
1331 \end{list}
1332 %<*en>
1333 Note that \texttt{90jis} and \texttt{jis2004} only affect with \textit{mincho},
1334 \textit{gothic} (and possibly \textit{rounded gothic}) defined by this package.
1335 We didn't taken account of  when both \texttt{90jis} and \texttt{jis2004} are specified.
1336 %</en>
1337 %<*ja>
1338 \texttt{90jis}と\texttt{jis2004}については本パッケージで定義された
1339 明朝体・ゴシック体(・丸ゴシック体)にのみ有効である.両オプションが
1340 同時に指定された場合の動作については全く考慮していない.
1341 %</ja>
1342
1343 %<en>\paragraph{Presets for multi weight}
1344 %<ja>\paragraph{多ウェイト用プリセットの一覧}
1345 %<*en>
1346 Besides \texttt{morisawa-pro}~and~\texttt{morisawa-pr6n} presets,
1347 fonts are specified by font name, not by file name.
1348 %</en>
1349 %<*ja>
1350 \texttt{morisawa-pro}, \texttt{morisawa-pr6n}以外はフォントの指定は
1351 (ファイル名でなく)フォント名で行われる.
1352 %</ja>
1353 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}\advance\leftmargin1\zw}
1354  \item[kozuka-pro] Kozuka Pro (Adobe-Japan1-4) fonts.
1355 %<en>    \\[-\dimexpr\medskipamount+\baselineskip\relax]
1356  \item[kozuka-pr6] Kozuka Pr6 (Adobe-Japan1-6)  fonts.
1357 %<en>    \\[-\dimexpr\medskipamount+\baselineskip\relax]
1358  \item[kozuka-pr6n] Kozuka Pr6N (Adobe-Japan1-6, JIS04-savvy) fonts.
1359
1360 %<*en>
1361 Kozuka Pro/Pr6N fonts are bundled with Adobe's software, such as Adobe~InDesign.
1362 There is not rounded gothic family in Kozuka fonts.
1363 %</en>
1364 %<*ja>
1365 小塚Pro書体・Pr6N書体はAdobe InDesign等のAdobe製品にバンドルされている.
1366 「小塚丸ゴシック」は存在しないので,便宜的に小塚ゴシックHによって代用している.
1367 %</ja>
1368 \begin{center}\small
1369 \begin{tabular}{cllll}
1370 \toprule
1371 \bf family&\bf series&\tt kozuka-pro&\tt kozuka-pr6&\tt kozuka-pr6n\\
1372 \midrule
1373  &medium&KozMinPro-Regular&KozMinProVI-Regular&KozMinPr6N-Regular\\
1374 %<en>\smash{\raisebox{1.5ex}{\textit{mincho}}}%
1375 %<ja>\smash{\raisebox{1.5ex}{\gt 明朝}}%
1376  &bold&KozMinPro-Bold&KozMinProVI-Bold&KozMinPr6N-Bold\\
1377 \midrule
1378  &&KozGoPro-Regular*&KozGoProVI-Regular*&KozGoPr6N-Regular*\\
1379  &\smash{\raisebox{1.5ex}{medium}}
1380  &KozGoPro-Medium&KozGoProVI-Medium&KozGoPr6N-Medium\\
1381 \cmidrule(l){2-5}
1382 %<en>\smash{\raisebox{2ex}{\textit{gothic}}}%
1383 %<ja>\smash{\raisebox{2ex}{\gt ゴシック}}%
1384  &bold&KozGoPro-Bold&KozGoProVI-Bold&KozGoPr6N-Bold\\
1385  &heavy&KozGoPro-Heavy&KozGoProVI-Heavy&KozGoPr6N-Heavy\\
1386 \midrule
1387 %<en>\textit{rounded gothic}
1388 %<ja>\gt 丸ゴシック
1389 &&KozGoPro-Heavy&KozGoProVI-Heavy&KozGoPr6N-Heavy\\
1390 \bottomrule
1391 \end{tabular}
1392 \end{center}
1393
1394 %<*en>
1395 In above table, starred fonts (KozGo\dots-Regular) are used for medium series of \textit{gothic},
1396 \emph{if and only if \texttt{deluxe} option is specified}.
1397 %</en>
1398 %<*ja>
1399 上の表において,*つきのフォント(KozGo\dots-Regular)は,\emph{\texttt{deluxe}オプション非指定時に}
1400 ゴシック体細字として用いられる.
1401 %</ja>
1402
1403 %<ja>\medskip
1404
1405  \item[hiragino-pro]  Hiragino Pro (Adobe-Japan1-5) fonts.
1406 %<en>    \\[-\dimexpr\medskipamount+\baselineskip\relax]
1407  \item[hiragino-pron] Hiragino ProN (Adobe-Japan1-5, JIS04-savvy) fonts.
1408
1409 %<*en>
1410 Hiragino fonts are bundled with Mac OS~X 10.5 or later.
1411 Some editions of a Japanese word-processor ``一太郎2012'' includes Hiragino ProN fonts.
1412 Note that the heavy weight of \textit{gothic} family only supports
1413 Adobe-Japan1-3 character collection (Std/StdN).
1414 %</en>
1415 %<*ja>
1416 ヒラギノフォントは,Mac OS~X以外にも,一太郎2012の上位エディションにもバンドルされている.
1417 極太ゴシックとして用いるヒラギノ角ゴW8は,Adobe-Japan1-3の範囲しかカバーしていない
1418 Std/StdNフォントであり,その他はAdobe-Japan1-5対応である.
1419 %</ja>
1420 \begin{center}\small
1421 \begin{tabular}{clll}
1422 \toprule
1423 \bf family&\bf series&\tt hiragino-pro&\tt hiragino-pron\\
1424 \midrule
1425  &medium&Hiragino~Mincho~Pro~W3&Hiragino~Mincho~ProN~W3\\
1426 %<en>\smash{\raisebox{1.5ex}{\textit{mincho}}}%
1427 %<ja>\smash{\raisebox{1.5ex}{\gt 明朝}}%
1428  &bold&Hiragino~Mincho~Pro~W6&Hiragino~Mincho~ProN~W6\\
1429 \midrule
1430  &&Hiragino~Kaku~Gothic~Pro~W3*&Hiragino~Kaku~Gothic~ProN~W3*\\
1431  &\smash{\raisebox{1.5ex}{medium}}
1432  &Hiragino~Kaku~Gothic~Pro~W6&Hiragino~Kaku~Gothic~ProN~W6\\
1433 \cmidrule(l){2-4}
1434 %<en>\smash{\raisebox{2ex}{\textit{gothic}}}%
1435 %<ja>\smash{\raisebox{2ex}{\gt ゴシック}}%
1436  &bold&Hiragino~Kaku~Gothic~Pro~W6&Hiragino~Kaku~Gothic~ProN~W6\\
1437  &heavy&Hiragino~Kaku~Gothic~Std~W8&Hiragino~Kaku~Gothic~StdN~W8\\
1438 \midrule
1439 %<en>\textit{rounded gothic}
1440 %<ja>\gt 丸ゴシック
1441 &&Hiragino~Maru~Gothic~ProN~W4&Hiragino~Maru~Gothic~ProN~W4\\
1442 \bottomrule
1443 \end{tabular}
1444 \end{center}
1445
1446 %<ja>\medskip
1447
1448  \item[morisawa-pro]  Morisawa Pro (Adobe-Japan1-4) fonts.
1449 %<en>    \\[-\dimexpr\medskipamount+\baselineskip\relax]
1450  \item[morisawa-pr6n]  Morisawa Pr6N (Adobe-Japan1-6, JIS04-savvy) fonts.
1451 \begin{center}\small
1452 \begin{tabular}{cl>{\tt}l>{\tt}l}
1453 \toprule
1454 \bf family&\bf series&morisawa-pro&morisawa-pr6n\\
1455 \midrule
1456  &medium&A-OTF-RyuminPro-Light.otf&A-OTF-RyuminPr6N-Light.otf\\
1457 %<en>\smash{\raisebox{1.5ex}{\textit{mincho}}}%
1458 %<ja>\smash{\raisebox{1.5ex}{\gt 明朝}}%
1459  &bold&A-OTF-FutoMinA101Pro-Bold.otf&A-OTF-FutoMinA101Pr6N-Bold.otf\\
1460 \midrule
1461  &medium
1462  &A-OTF-GothicBBBPro-Medium.otf&A-OTF-GothicBBBPr6N-Medium.otf\\
1463 %<en>\textit{gothic}%
1464 %<ja>\gt ゴシック
1465  &bold&A-OTF-FutoGoB101Pro-Bold.otf&A-OTF-FutoGoB101Pr6N-Bold.otf\\
1466  &heavy&A-OTF-MidashiGoPro-MB31.otf&A-OTF-MidashiGoPr6N-MB31.otf\\
1467 \midrule
1468 %<en>\textit{rounded gothic}
1469 %<ja>\gt 丸ゴシック
1470 &&A-OTF-Jun101Pro-Light.otf&A-OTF-ShinMGoPr6N-Light.otf\\
1471 \bottomrule
1472 \end{tabular}
1473 \end{center}
1474
1475  \item[yu-win]  Yu fonts bundled with Windows~8.1.
1476 %<en>    \\[-\dimexpr\medskipamount+\baselineskip\relax]
1477  \item[yu-osx]  Yu fonts bundled with OSX~Mavericks.
1478 \begin{center}\small
1479 \begin{tabular}{clll}
1480 \toprule
1481 \bf family&\bf series&\tt yu-win&\tt yu-osx\\
1482 \midrule
1483  &medium&YuMincho-Regular&YuMincho~Medium\\
1484 %<en>\smash{\raisebox{1.5ex}{\textit{mincho}}}%
1485 %<ja>\smash{\raisebox{1.5ex}{\gt 明朝}}%
1486  &bold&YuMincho-Demibold&YuMincho~Demibold\\
1487 \midrule
1488  &&YuGothic-Regular*&YuGothic~Medium*\\
1489  &\smash{\raisebox{1.5ex}{medium}}
1490  &YuGothic-Bold&YuGothic~Bold\\
1491 \cmidrule(l){2-4}
1492 %<en>\textit{gothic}%
1493 %<ja>\gt ゴシック
1494  &bold&YuGothic-Bold&YuGothic~Bold\\
1495  &heavy&YuGothic-Bold&YuGothic~Bold\\
1496 \midrule
1497 %<en>\textit{rounded gothic}
1498 %<ja>\gt 丸ゴシック
1499 &&YuGothic-Bold&YuGothic~Bold\\
1500 \bottomrule
1501 \end{tabular}
1502 \end{center}
1503
1504 \end{list}
1505 %<en>\paragraph{Presets for single weight}
1506 %<ja>\paragraph{単ウェイト用プリセット一覧}
1507 %<*en>
1508 Next, we describe settings for using only single weight.
1509 In four settings below, we use same fonts for medium and bold (and heavy) weights.
1510 (Hence \verb+\mcfamily\bfseries+ and \verb+\mcfamily\mdseries+ yields same Japanese fonts,
1511 even if \texttt{deluxe} option is also specified).
1512 %</en>
1513 %<*ja>
1514 次に,単ウェイト用の設定を述べる.この4設定では「細字」「太字」の区別はない.
1515 また,丸ゴシック体はゴシック体と同じフォントを用いる.
1516 %</ja>
1517 \par\nobreak\medskip
1518 {\centering\small
1519 \begin{tabular}{lllll}
1520 \toprule
1521 &\tt noembed&\tt ipa&\tt ipaex&\tt ms\\
1522 \midrule
1523 %<*en>
1524 \it mincho&Ryumin-Light (non-embedded)
1525 &IPAMincho&IPAexMincho&MS Mincho\\
1526 \it gothic&GothicBBB-Medium (non-embedded)
1527 &IPAGothic&IPAexGothic&MS Gothic\\
1528 %</en>
1529 %<*ja>
1530 \gtfamily 明朝体&Ryumin-Light(非埋込)
1531 &IPA明朝&IPAex明朝&MS明朝\\
1532 \gtfamily ゴシック体&GothicBBB-Medium(非埋込)
1533 &IPAゴシック&IPAexゴシック&MSゴシック\\
1534 %</ja>
1535 \bottomrule
1536 \end{tabular}\par\medskip}
1537
1538
1539 %<en>\paragraph{Using HG fonts}
1540 %<ja>\paragraph{HGフォントの利用}
1541 %<*en>
1542 We can use HG~fonts bundled with Microsoft~Office for realizing multiple weights.
1543 %</en>
1544 %<*ja>
1545 すぐ前に書いた単ウェイト用設定を,Microsoft Office等に付属するHGフォントを使って
1546 多ウェイト化した設定もある.
1547 %</ja>
1548 \par\nobreak\medskip
1549 {\centering\small
1550 \begin{tabular}{llll}
1551 \toprule
1552 &\tt ipa-hg&\tt ipaex-hg&\tt ms-hg\\
1553 \midrule
1554 %<*en>
1555 \bf mincho medium
1556 &IPAMincho&IPAexMincho&MS Mincho\\\midrule
1557 \bf mincho bold&
1558 \multicolumn{3}{c}{HG Mincho E}\\\midrule
1559 \bf Gothic medium\\
1560 ~~without \texttt{deluxe}
1561 &IPAGothic&IPAexGothic&MS Gothic\\
1562 ~~with {\tt jis2004}
1563 &IPAGothic&IPAexGothic&MS Gothic\\
1564 \cmidrule(lr){1-4}
1565 ~~otherwise&
1566 \multicolumn{3}{c}{HG Gothic M}\\\midrule
1567 \bf gothic bold&
1568 \multicolumn{3}{c}{HG Gothic E}\\\midrule
1569 \bf gothic heavy&
1570 \multicolumn{3}{c}{HG Soei Kaku Gothic UB}\\\midrule
1571 \bf rounded gothic&
1572 \multicolumn{3}{c}{HG Maru Gothic PRO}\\
1573 %</en>
1574 %<*ja>
1575 \gtfamily 明朝体細字
1576 &IPA明朝&IPAex明朝&MS明朝\\\midrule
1577 \gtfamily 明朝体太字&
1578 \multicolumn{3}{c}{HG明朝E}\\\midrule
1579 \gtfamily ゴシック体細字\\
1580  単ウェイト時
1581 &IPAゴシック&IPAexゴシック&MSゴシック\\
1582  {\tt jis2004}指定時
1583 &IPAゴシック&IPAexゴシック&MSゴシック\\
1584 \cmidrule(lr){1-4}
1585  それ以外の時&
1586 \multicolumn{3}{c}{HGゴシックM}\\\midrule
1587 \gtfamily ゴシック体太字&
1588 \multicolumn{3}{c}{HGゴシックE}\\\midrule
1589 \gtfamily ゴシック体極太&
1590 \multicolumn{3}{c}{HG創英角ゴシックUB}\\\midrule
1591 \gtfamily 丸ゴシック体&
1592 \multicolumn{3}{c}{HG丸ゴシック体PRO}\\
1593 %</ja>
1594 \bottomrule
1595 \end{tabular}\par\medskip}
1596
1597 %<*en>
1598 Note that HG~Mincho~E, HG~Gothic~E, HG Soei Kaku Gothic UB, and HG Maru Gothic PRO
1599 are internally specified by:
1600 \begin{description}
1601 \item[default] by font name (\texttt{HGMinchoE}, etc.).
1602 \item[{\tt 90jis}] by file name (\texttt{hgrme.ttc}, \texttt{hgrge.ttc}, \texttt{hgrsgu.ttc}, \texttt{hgrsmp.ttf}).
1603 \item[{\tt jis2004}] by file name (\texttt{hgrme04.ttc}, \texttt{hgrge04.ttc}, \texttt{hgrsgu04.ttc}, \texttt{hgrsmp04.ttf}).
1604 \end{description}
1605 %</en>
1606 %<*ja>
1607 なお,HG明朝E・HGゴシックE・HG創英角ゴシックUB・HG丸ゴシック体PROの4つについては,内部で
1608 \begin{description}
1609 \item[標準] フォント名(\texttt{HGMinchoE} など)
1610 \item[{\tt 90jis}指定時] ファイル名 (%
1611 \texttt{hgrme.ttc}, \texttt{hgrge.ttc}, \texttt{hgrsgu.ttc}, \texttt{hgrsmp.ttf})
1612 \item[{\tt jis2004}指定時] ファイル名 (%
1613 \texttt{hgrme04.ttc}, \texttt{hgrge04.ttc}, \texttt{hgrsgu04.ttc}, \texttt{hgrsmp04.ttf})
1614 \end{description}
1615 として指定を行っているので注意すること.
1616 %</ja>
1617
1618
1619 %<*en>
1620 \subsection{\texttt{\textbackslash CID}, \texttt{\textbackslash UTF}, and macros in \Pkg{japanese-otf} package}
1621 Under \pLaTeX, \Pkg{japanese-otf} package (developed by Shuzaburo Saito) is
1622 used for typesetting characters which is in Adobe-Japan1-6 CID but not
1623 in JIS~X~0208. Since this package is widely used, \LuaTeX-ja
1624 supports some of functions in \Pkg{japanese-otf} package.
1625 If you want to use these functions, load \Pkg{luatexja-otf} package.
1626 %</en>
1627 %<*ja>
1628 \subsection{\texttt{\textbackslash CID}, \texttt{\textbackslash UTF}と\Pkg{otf}パッケージのマクロ}
1629 \pLaTeX では,JIS~X~0208にないAdobe-Japan1-6の文字を出力するために,
1630 齋藤修三郎氏による\Pkg{otf}パッケージが用いられていた.このパッケージは
1631 広く用いられているため,\LuaTeX-jaにおいても\Pkg{otf}パッケージの機能の
1632 一部をサポートしている.これらの機能を用いるためには\Pkg{luatexja-otf}パッケージ
1633 を読み込めばよい.
1634 %</ja>
1635
1636 \begin{LTXexample}
1637 \jfontspec{KozMinPr6N-Regular.otf}
1638 森\UTF{9DD7}外と内田百\UTF{9592}とが\UTF{9AD9}島屋に行く。
1639
1640 \CID{7652}飾区の\CID{13706}野家,
1641 \CID{1481}城市,葛西駅,
1642 高崎と\CID{8705}\UTF{FA11}
1643
1644 \aj半角{はんかくカタカナ}
1645 \end{LTXexample}
1646
1647 %<*ja>
1648 \Pkg{otf}パッケージでは,それぞれ次のようなオプションが存在した:
1649 \begin{description}
1650 \item[\texttt{deluxe}] 明朝体・ゴシック体各2ウェイトと,丸ゴシック体を扱えるようになる.
1651 \item[\texttt{expert}] 仮名が横組・縦組専用のものに切り替わり,ルビ用仮名も扱えるようになる.
1652 \item[\texttt{bold}] ゴシック体を標準で太いウェイトのものに設定する.
1653 \end{description}
1654 しかしこれらのオプションは\Pkg{luatexja-otf}パッケージには存在しない.
1655 \Pkg{otf}パッケージが文書中で使用する和文用TFMを自前の物に置き換えていたのに対し,
1656 \Pkg{luatexja-otf}パッケージでは,そのようなことは行わないからである.
1657
1658 これら3オプションについては,
1659 \Pkg{luatexja-preset} パッケージにプリセットを使う時に一緒に指定するか,
1660 あるいは対応する内容を\ref{ssec-chgfnt}節,\ref{ssec-nfsspat}節 (NFSS2) や
1661 \ref{ssec-fontspec}節 (\Pkg{fontspec}) の方法で手動で指定する必要がある.
1662 %</ja>
1663
1664
1665 %<en>\section{Changing Parameters}
1666 %<ja>\section{パラメータの変更}
1667
1668 %<*en>
1669 There are many parameters in \LuaTeX-ja. And due to the behavior of \LuaTeX,
1670 most of them are not stored as internal register of \TeX, but as an
1671 original storage system in \LuaTeX-ja. Hence, to assign or acquire those
1672 parameters, you have to use commands \verb+\ltjsetparameter+ and
1673 \verb+\ltjgetparameter+.
1674 %</en>
1675 %<*ja>
1676 \LuaTeX-jaには多くのパラメータが存在する.そして\LuaTeX の仕様のために,
1677 その多くは\TeX のレジスタにではなく,\LuaTeX-ja独自の方法で保持されている.
1678 これらのパラメータを設定・取得するためには \verb+\ltjsetparameter+ と \verb+\ltjgetparameter+ を
1679 用いる.
1680 %</ja>
1681
1682 %<en>\subsection{Editing the Range of \textbf{JAchar}s}
1683 %<ja>\subsection{\textbf{JAchar}の範囲の設定}
1684 \label{ssec-setrange}
1685
1686 %<*en>
1687 \LuaTeX-ja divides the Unicode codespace \texttt{U+0080}--\texttt{U+10FFFF}
1688 into \emph{character ranges},
1689 numbered 1 to 217. The grouping can be (globally) customized by \verb+\ltjdefcharrange+.
1690 The next line adds whole characters in Supplementary Ideographic Plane
1691 and the character ``漢'' to the character range~100.
1692 %</en>
1693 %<*ja>
1694 \LuaTeX-jaは,Unicodeの \texttt{U+0080}--\texttt{U+10FFFF} の空間を
1695 1番から217番までの\emph{文字範囲}に分割している.
1696 区分けは \verb+\ltjdefcharrange+ を用いることで(グローバルに)変更することができ,
1697 例えば,次は追加漢字面(SIP)にある全ての文字と「漢」を「100番の文字範囲」に追加する.
1698 %</ja>
1699 \begin{lstlisting}
1700 \ltjdefcharrange{100}{"20000-"2FFFF,`漢}
1701 \end{lstlisting}
1702 %<*en>
1703 A character can belong to only one character range.
1704 For example, whole SIP belong to the range~4 in the default setting of \LuaTeX-ja,
1705 and if you execute the above line, then SIP will belong to the range~100 and be
1706 removed from the range~4.
1707 %</en>
1708 %<*ja>
1709 各文字はただ一つの文字範囲に所属することができる.
1710 例えば,SIPは全て\LuaTeX-jaのデフォルトでは4番の文字範囲に
1711 属しているが,上記の指定を行えばSIPは100番に属すようになり,4番からは除かれる.
1712 %</ja>
1713
1714 %<*en>
1715 The distinction between \textbf{ALchar} and \textbf{JAchar} is done for character ranges.
1716 This can be edited by setting the \textsf{jacharrange} parameter.
1717 For example, this is just the default setting of \LuaTeX-ja, and
1718 it sets
1719 \begin{itemize}
1720  \item a character which belongs character ranges 1,~4, and~5 is \textbf{ALchar},
1721  \item a character which belongs character ranges 2,~3, 6, 7, and~8 is \textbf{JAchar}.
1722 \end{itemize}
1723 %</en>
1724 %<*ja>
1725 \textbf{ALchar}と\textbf{JAchar}の区別は文字範囲ごとに行われる.
1726 これは\textsf{jacharrange}パラメータによって編集できる.
1727 例えば,以下は\LuaTeX-jaの初期設定であり,次の内容を設定している:
1728 \begin{itemize}
1729  \item 1番,4番,5番の文字範囲に属する文字は\textbf{ALchar}.
1730  \item 2番,3番,6番,7番,8番の文字範囲に属する文字は\textbf{JAchar}.
1731 \end{itemize}
1732 %</ja>
1733 \begin{verbatim}
1734 \ltjsetparameter{jacharrange={-1, +2, +3, -4, -5, +6, +7, +8}}
1735 \end{verbatim}
1736 %<*en>
1737 The argument to \textsf{jacharrange} parameter is a list of non-zero integer.
1738 Negative integer $-n$ in the list means that ``each character in the range~$n$ is an
1739 \textbf{ALchar}'',
1740 and positive integer $+n$ means that ``\dots\ is a \textbf{JAchar}''.
1741 %</en>
1742 %<*ja>
1743 \textsf{jacharrange}パラメータの引数は非零の整数のリストである.
1744 リスト中の負の整数$-n$は「文字範囲$n$に属する文字は\textbf{ALchar}として
1745 扱う」ことを意味し,正の整数$+n$は「\textbf{JAchar}として扱う」ことを意味する.
1746 %</ja>
1747
1748 %<*en>
1749 \paragraph{Default setting}
1750 \LuaTeX-ja predefines eight character ranges for convenience. They are
1751 determined from the following data:
1752 %</en>
1753 %<*ja>
1754 \paragraph{初期設定}
1755 \LuaTeX-jaでは8つの文字範囲を予め定義しており,
1756 これらは以下のデータに基づいて決定している.
1757 %</ja>
1758 \begin{itemize}
1759 %<en>\item Blocks in Unicode~6.0.
1760 %<ja>\item Unicode~6.0のブロック.
1761 %<en>\item The \texttt{Adobe-Japan1-UCS2} mapping between a CID Adobe-Japan1-6 and Unicode.
1762 %<ja>\item Adobe-Japan1-6のCIDとUnicodeの間の対応表\texttt{Adobe-Japan1-UCS2}.
1763 %<en>\item The \Pkg{PXbase} bundle for \upTeX\ by Takayuki Yato.
1764 %<ja>\item 八登崇之氏による\upTeX 用の\Pkg{PXbase}バンドル.
1765 \end{itemize}
1766
1767 %<*en>
1768 Now we describe these eight ranges. The superscript ``J'' or ``A'' after the
1769 number shows whether each character in the range is treated as
1770 \textbf{JAchar}s or not by default. These settings are similar to the
1771 \texttt{prefercjk} settings defined in \texttt{PXbase} bundle.
1772 Any characters above \texttt{U+0080} which does not belong to
1773 these eight ranges belongs to the character range~217.
1774 %</en>
1775 %<*ja>
1776 以下ではこれら8つの文字範囲について記述する.添字のアルファベット「J」「A」
1777 は,その文字範囲内の文字が\textbf{JAchar}か\textbf{ALchar}かを表している.これらの設定は
1778 \texttt{PXbase}バンドルで定義されている\texttt{prefercjk}と類似のものである.
1779 なお,\texttt{U+0080} 以降でこれら8つの文字範囲に属さない文字は,217番の文字範囲に属することになっている.
1780 %</ja>
1781 \begin{description}
1782 %<*en>
1783 \item[Range~8${}^{\text{J}}$] The intersection of the upper half of ISO~8859-1
1784          (Latin-1 Supplement) and JIS~X~0208 (a basic character set for Japanese). This character range
1785          consists of the following characters:
1786 %</en>
1787 %<*ja>
1788 \item[範囲8${}^{\text{J}}$] ISO~8859-1の上位領域(ラテン1補助)と
1789                              JIS~X~0208の共通部分.この文字範囲は
1790                              以下の文字で構成される:
1791 %</ja>
1792 \begin{multicols}{2}
1793 \begin{itemize}
1794 \def\ch#1#2{\item \char"#1\ (\texttt{U+00#1}, #2)}%"
1795 \ch{A7}{Section Sign}
1796 \ch{A8}{Diaeresis}
1797 \ch{B0}{Degree sign}
1798 \ch{B1}{Plus-minus sign}
1799 \ch{B4}{Spacing acute}
1800 \ch{B6}{Paragraph sign}
1801 \ch{D7}{Multiplication sign}
1802 \ch{F7}{Division Sign}
1803 \end{itemize}
1804 \end{multicols}
1805
1806 %<*en>
1807 \item[Range~1${}^{\text{A}}$] Latin characters that some of them are included in Adobe-Japan1-6.
1808 This range consists of the following Unicode ranges, \emph{except characters in the range~8 above}:
1809 %</en>
1810 %<*ja>
1811 \item[範囲1${}^{\text{A}}$] ラテン文字のうち,Adobe-Japan1-6との共通部分があるもの.
1812                              この範囲は以下のUnicodeのブロックのうち
1813                              \emph{範囲8を除いた}部分で構成されている:
1814 %</ja>
1815 \begin{multicols}{2}
1816 \begin{itemize}
1817 \item \texttt{U+0080}--\texttt{U+00FF}: Latin-1 Supplement
1818 \item \texttt{U+0100}--\texttt{U+017F}: Latin Extended-A
1819 \item \texttt{U+0180}--\texttt{U+024F}: Latin Extended-B
1820 \item \texttt{U+0250}--\texttt{U+02AF}: IPA Extensions
1821 \item \texttt{U+02B0}--\texttt{U+02FF}: Spacing Modifier Letters
1822 \item \texttt{U+0300}--\texttt{U+036F}: \\\null\hfill Combining Diacritical Marks
1823 \item \texttt{U+1E00}--\texttt{U+1EFF}: \\\null\hfill Latin Extended Additional
1824 \par\
1825 \end{itemize}
1826 \end{multicols}
1827 %<*en>
1828 \item[Range~2${}^{\text{J}}$] Greek and Cyrillic letters. JIS~X~0208 (hence most of Japanese
1829            fonts) has some of these characters.
1830 %</en>
1831 %<*ja>
1832 \item[範囲2${}^{\text{J}}$] ギリシャ文字とキリル文字.JIS~X~0208(したがってほとんどの
1833                              和文フォント)はこれらの文字を持つ.
1834 %</ja>
1835 \begin{multicols}{2}
1836 \begin{itemize}
1837 \item \texttt{U+0370}--\texttt{U+03FF}: Greek and Coptic
1838 \item \texttt{U+0400}--\texttt{U+04FF}: Cyrillic
1839 \item \texttt{U+1F00}--\texttt{U+1FFF}: Greek Extended
1840 \\\
1841 \end{itemize}
1842 \end{multicols}
1843 %<*en>
1844 \item[Range~3${}^{\text{J}}$] Punctuations and Miscellaneous symbols. The block list is
1845            indicated in Table~\ref{table-rng3}.
1846 %</en>
1847 %<*ja>
1848 \item[範囲3${}^{\text{J}}$] 句読点と記号類.ブロックのリストは表\ref{table-rng3}%
1849                              に示してある.
1850 %</ja>
1851 \begin{table}[!tb]
1852 %<en>\caption{Unicode blocks in predefined character range~3.}
1853 %<ja>\caption{文字範囲3に指定されているUnicodeブロック.}
1854 \label{table-rng3}
1855 \catcode`\"=13\def"#1#2#3#4{\texttt{U+#1#2#3#4}}%"
1856 \centering\small
1857 \begin{tabular}{llll}
1858 "2000--"206F&General Punctuation&
1859 "2070--"209F&Superscripts and Subscripts\\
1860 "20A0--"20CF&Currency Symbols&
1861 "20D0--"20FF&Comb.\ Diacritical Marks for Symbols\\
1862 "2100--"214F&Letterlike Symbols&
1863 "2150--"218F&Number Forms\\
1864 "2190--"21FF&Arrows&
1865 "2200--"22FF&Mathematical Operators\\
1866 "2300--"23FF&Miscellaneous Technical&
1867 "2400--"243F&Control Pictures\\
1868 "2500--"257F&Box Drawing&
1869 "2580--"259F&Block Elements\\
1870 "25A0--"25FF&Geometric Shapes&
1871 "2600--"26FF&Miscellaneous Symbols\\
1872 "2700--"27BF&Dingbats&
1873 "2900--"297F&Supplemental Arrows-B\\
1874 "2980--"29FF&Misc.\ Mathematical Symbols-B&
1875 "2B00--"2BFF&Miscellaneous Symbols and Arrows
1876 \end{tabular}
1877 \end{table}
1878 %<*en>
1879 \item[Range~4${}^{\text{A}}$] Characters usually not in Japanese fonts. This range consists
1880            of almost all Unicode blocks which are not in other
1881            predefined ranges. Hence, instead of showing the block list,
1882            we put the definition of this range itself:
1883 %</en>
1884 %<*ja>
1885 \item[範囲4${}^{\text{A}}$] 通常和文フォントには含まれていない文字.
1886                              この範囲は他の範囲にないほとんど全てのUnicodeブロック
1887                              で構成されている.したがって,ブロックのリストを示す
1888                              代わりに,範囲の定義そのものを示す:
1889 %</ja>
1890 \begin{lstlisting}
1891 \ltjdefcharrange{4}{%
1892    "500-"10FF, "1200-"1DFF, "2440-"245F, "27C0-"28FF, "2A00-"2AFF,
1893   "2C00-"2E7F, "4DC0-"4DFF, "A4D0-"A82F, "A840-"ABFF, "FB00-"FE0F,
1894   "FE20-"FE2F, "FE70-"FEFF, "10000-"1FFFF, "E000-"F8FF} % non-Japanese
1895 \end{lstlisting}
1896 %<en>\item[Range~5${}^{\text{A}}$] Surrogates and Supplementary Private Use Areas.
1897 %<ja>\item[範囲5${}^{\text{A}}$] 代用符号と補助私用領域.
1898 %<en>\item[Range~6${}^{\text{J}}$] Characters used in Japanese. The block list is indicated in Table~\ref{table-rng6}.
1899 %<ja>\item[範囲6${}^{\text{J}}$] 日本語で用いられる文字.ブロックのリストは表\ref{table-rng6}に示す.
1900 \begin{table}[!tb]
1901 %<en>\caption{Unicode blocks in predefined character range~6.}
1902 %<ja>\caption{文字範囲6に指定されているUnicodeブロック.}
1903 \label{table-rng6}
1904 \catcode`\"=13\def"#1#2#3#4{\texttt{U+#1#2#3#4}}%"
1905 \centering\small
1906 \begin{tabular}{llll}
1907 "2460--"24FF&Enclosed Alphanumerics&
1908 "2E80--"2EFF&CJK Radicals Supplement\\
1909 "3000--"303F&CJK Symbols and Punctuation&
1910 "3040--"309F&Hiragana\\
1911 "30A0--"30FF&Katakana&
1912 "3190--"319F&Kanbun\\
1913 "31F0--"31FF&Katakana Phonetic Extensions&
1914 "3200--"32FF&Enclosed CJK Letters and Months\\
1915 "3300--"33FF&CJK Compatibility&
1916 "3400--"4DBF&CJK Unified Ideographs Extension A\\
1917 "4E00--"9FFF&CJK Unified Ideographs&
1918 "F900--"FAFF&CJK Compatibility Ideographs\\
1919 "FE10--"FE1F&Vertical Forms&
1920 "FE30--"FE4F&CJK Compatibility Forms\\
1921 "FE50--"FE6F&Small Form Variants&
1922 "{20}000--"{2F}FFF&(Supplementary Ideographic Plane)\\
1923 "{E0}100--"{E0}1EF&Variation Selectors Supplement
1924 \end{tabular}
1925 \end{table}
1926 %<*en>
1927 \item[Range~7${}^{\text{J}}$] Characters used in CJK languages, but not included in  Adobe-Japan1-6.
1928 The block list is indicated in Table~\ref{table-rng7}.
1929 %</en>
1930 %<*ja>
1931 \item[範囲7${}^{\text{J}}$] CJK言語で用いられる文字のうち,Adobe-Japan1-6に
1932                             含まれていないもの.
1933                             ブロックのリストは表\ref{table-rng7}に示す.
1934 %</ja>
1935 \begin{table}[!tb]
1936 %<en>\caption{Unicode blocks in predefined character range~7.}
1937 %<ja>\caption{文字範囲7に指定されているUnicodeブロック.}
1938 \label{table-rng7}
1939 \catcode`\"=13\def"#1#2#3#4{\texttt{U+#1#2#3#4}}%"
1940 \centering\small
1941 \begin{tabular}{llll}
1942 "1100--"11FF&Hangul Jamo&
1943 "2F00--"2FDF&Kangxi Radicals\\
1944 "2FF0--"2FFF&Ideographic Description Characters&
1945 "3100--"312F&Bopomofo\\
1946 "3130--"318F&Hangul Compatibility Jamo&
1947 "31A0--"31BF&Bopomofo Extended\\
1948 "31C0--"31EF&CJK Strokes&
1949 "A000--"A48F&Yi Syllables\\
1950 "A490--"A4CF&Yi Radicals&
1951 "A830--"A83F&Common Indic Number Forms\\
1952 "AC00--"D7AF&Hangul Syllables&
1953 "D7B0--"D7FF&Hangul Jamo Extended-B
1954 \end{tabular}
1955 \end{table}
1956 \end{description}
1957
1958
1959 %<en>\subsection{\Param{kanjiskip} and \Param{xkanjiskip}}
1960 %<ja>\subsection{\Param{kanjiskip}と\Param{xkanjiskip}}
1961 \label{subs-kskip}
1962
1963 %<en>\textbf{JAglue} is divided into the following three categories:
1964 %<ja>\textbf{JAglue}は以下の3つのカテゴリに分類される:
1965 \begin{itemize}
1966 %<*en>
1967 \item Glues/kerns specified in JFM. If \verb+\inhibitglue+ is issued
1968       around a Japanese character, this glue will not be inserted at the
1969       place.
1970 %</en>
1971 %<*ja>
1972 \item JFMで指定されたグルー/カーン.もし \verb+\inhibitglue+ が和文文字の周りで
1973       発行されていれば,このグルーは挿入されない.
1974 %</ja>
1975 %<*en>
1976 \item The default glue which inserted between two \textbf{JAchar}s (\Param{%
1977       kanjiskip}).
1978 %</en>
1979 %<*ja>
1980 \item デフォルトで2つの\textbf{JAchar}の間に挿入されるグルー(\Param{kanjiskip}).
1981 %</ja>
1982 %<*en>
1983 \item The default glue which inserted between a \textbf{JAchar} and an
1984       \textbf{ALchar} (\Param{xkanjiskip}).
1985 %</en>
1986 %<*ja>
1987 \item デフォルトで\textbf{JAchar}と\textbf{ALchar}の間に挿入されるグルー(\Param{xkanjiskip}).
1988 %</ja>
1989 \end{itemize}
1990 %<*en>
1991 The value (a skip) of \Param{kanjiskip} or
1992 \Param{xkanjiskip} can be changed as the following.
1993 Note that only their values \emph{at the end of a paragraph or a hbox are
1994 adopted in the whole paragraph or the whole hbox.
1995 }
1996 %</en>
1997 %<*ja>
1998 \Param{kanjiskip}や\Param{xkanjiskip}の値
1999 は以下のようにして変更可能である.
2000 %</ja>
2001 \begin{lstlisting}
2002 \ltjsetparameter{kanjiskip={0pt plus 0.4pt minus 0.4pt},
2003                  xkanjiskip={0.25\zw plus 1pt minus 1pt}}
2004 \end{lstlisting}
2005 %<*en>
2006 Here \verb+\zw+ is a internal dimension
2007 which stores fullwidth of the current Japanese font.
2008 This \verb+\zw+ can be used as the unit \texttt{zw} in \pTeX.
2009
2010 The value of these parameter can be get by \verb+\ltjgetparameter+.
2011 Note that the result by \verb+\ltjgetparameter+ is \emph{not} the internal quantities,
2012 but \emph{a string} (hence \verb+\the+ cannot be prefixed).
2013 %</en>
2014 %<*ja>
2015 ここで,\verb+\zw+ は現在の和文フォントの全角幅を表す長さであり,
2016 \pTeX における長さ単位 \texttt{zw} と同じように使用できる.
2017
2018 これらのパラメータの値は以下のように取得できる.
2019 戻り値は内部値ではなく\emph{文字列}である(\verb+\the+ は前置できない)ことに注意してほしい:
2020 %</ja>
2021 \begin{LTXexample}
2022 kanjiskip: \ltjgetparameter{kanjiskip},\\
2023 xkanjiskip: \ltjgetparameter{xkanjiskip}
2024 \end{LTXexample}
2025
2026 %<*en>
2027 It may occur that JFM contains the data of ``ideal width of
2028 \Param{kanjiskip}''
2029 and/or ``ideal width of \Param{xkanjiskip}''.
2030 To use these data from JFM, set the value of \Param{kanjiskip} or
2031 \Param{xkanjiskip} to \verb+\maxdimen+
2032 (these ``ideal width'' cannot be retrived by \verb+\ltjgetparameter+).
2033 %</en>
2034 %<*ja>
2035 JFMは「望ましい\Param{kanjiskip}の値」や
2036 「望ましい\Param{xkanjiskip}の値」を持っていることがある.
2037 これらのデータを使うためには,\Param{kanjiskip}や%
2038 \Param{xkanjiskip}の値を \verb+\maxdimen+ の値に設定すればよいが,
2039 \verb+\ltjgetparameter+ によって取得することはできないので注意が必要である.
2040 %</ja>
2041
2042 %<en>\subsection{Insertion Setting of \Param{xkanjiskip}}
2043 %<ja>\subsection{\Param{xkanjiskip} の挿入設定}
2044
2045 %<*en>
2046 It is not desirable that \Param{xkanjiskip} is inserted into every
2047 boundary between \textbf{JAchar}s and \textbf{ALchar}s. For example,
2048 \Param{xkanjiskip} should not be inserted after opening parenthesis
2049 (\textit{e.g.}, compare ``(あ'' and ``(\hskip\ltjgetparameter{xkanjiskip}あ'').
2050 \LuaTeX-ja can control whether \Param{xkanjiskip} can be inserted
2051 before/after a character, by changing \Param{jaxspmode} for \textbf{JAchar}s and
2052 \Param{alxspmode} parameters \textbf{ALchar}s respectively.
2053 %</en>
2054 %<*ja>
2055 \Param{xkanjiskip}がすべての\textbf{JAchar}と\textbf{ALchar}の境界に
2056 挿入されるのは望ましいことではない.例えば,\Param{xkanjiskip}は開き括弧の
2057 後には挿入されるべきではない(「(あ」と「(\hskip\ltjgetparameter{xkanjiskip}あ」を
2058 比べてみよ).
2059 \LuaTeX-jaでは\Param{xkanjiskip}をある文字の前/後に挿入するかどうかを,
2060 \textbf{JAchar}に対しては\Param{jaxspmode}を,\textbf{ALchar}に対しては
2061 \Param{alxspmode}をそれぞれ変えることで制御することができる.
2062 %</ja>
2063 \begin{LTXexample}
2064 \ltjsetparameter{jaxspmode={`あ,preonly}, alxspmode={`\!,postonly}}
2065 pあq い!う
2066 \end{LTXexample}
2067
2068 %<*en>
2069 The second argument \texttt{preonly} means that the insertion of
2070 \Param{xkanjiskip} is allowed before this character, but not after.
2071 the other possible values are \texttt{postonly}, \texttt{allow}, and \texttt{inhibit}.
2072 %</en>
2073 %<*ja>
2074 2つ目の引数の \texttt{preonly}は「\Param{xkanjiskip}の挿入はこの文字の
2075 前でのみ許され,後では許さない」ことを意味する.他に指定可能な値は
2076 \texttt{postonly}, \texttt{allow}, \texttt{inhibit}である.
2077 %</ja>
2078
2079 %<*en>
2080 \Param{jaxspmode} and \Param{alxspmode} use a same table to store the parameters
2081 on the current version. Therefore, line~1 in the code above can be rewritten
2082 as follows:
2083 %</en>
2084 %<*ja>
2085 なお,現行の
2086 仕様では,\Param{jaxspmode}, \Param{alxspmode}はテーブルを共有しており,
2087 上のコードの1行目を次のように変えても同じことになる:
2088 %</ja>
2089 \begin{verbatim}
2090 \ltjsetparameter{alxspmode={`あ,preonly}, jaxspmode={`\!,postonly}}
2091 \end{verbatim}
2092 %<*en>
2093 One can use also numbers to specify these two parameters (see Subsection~\ref{ssec-param}).
2094 %</en>
2095 %<*ja>
2096 また,これら2パラメータには数値で値を指定することもできる(\ref{ssec-param}節を参照).
2097 %</ja>
2098
2099 %<*en>
2100 If you want to enable/disable all insertions of \Param{kanjiskip} and
2101 \Param{xkanjiskip}, set \Param{autospacing} and \Param{autoxspacing}
2102 parameters to \texttt{true}/\texttt{false}, respectively.
2103 %</en>
2104 %<*ja>
2105 もし全ての\Param{kanjiskip}と\Param{xkanjiskip}の挿入を有効化/無効化
2106 したければ,それぞれ\Param{autospacing}と\Param{autoxspacing}を
2107 \texttt{true}/\texttt{false}に設定すればよい.
2108 %</ja>
2109
2110 %<en>\subsection{Shifting the baseline}
2111 %<ja>\subsection{ベースラインの移動}
2112 %<*en>
2113 To make a match between a Japanese font and an alphabetic font, sometimes
2114 shifting of the baseline of one of the pair is needed. In \pTeX, this is achieved
2115 by setting \verb+\ybaselineshift+ to a non-zero length (the
2116 baseline of \textbf{ALchar} is shifted below). However, for documents
2117 whose main language is not Japanese, it is good to shift the baseline of
2118 Japanese fonts, but not that of alphabetic fonts.
2119 Because of this, \LuaTeX-ja can independently set the shifting amount
2120 of the baseline of alphabetic fonts (\Param{yalbaselineshift}
2121 parameter) and that of Japanese fonts (\Param{yjabaselineshift}
2122 parameter).
2123 %</en>
2124 %<*ja>
2125 和文フォントと欧文フォントを合わせるためには,時々どちらかのベースラインの移動が
2126 必要になる.\pTeX ではこれは \verb+\ybaselineshift+ を設定することで
2127 なされていた(\textbf{ALchar}のベースラインがその分だけ下がる).しかし,日本語が主ではない
2128 文書に対しては,欧文フォントではなく和文フォントのベースラインを移動した方がよい.
2129 このため,\LuaTeX-jaでは欧文フォントのベースラインのシフト量
2130 (\Param{yalbaselineshift}パラメータ)と和文フォントのベースラインのシフト量
2131 (\Param{yjabaselineshift}パラメータ)を独立に設定できるようになっている.
2132 %</ja>
2133
2134 \begin{LTXexample}
2135 \vrule width 150pt height 0.4pt depth 0pt \hskip-120pt
2136 \ltjsetparameter{yjabaselineshift=0pt, yalbaselineshift=0pt}abcあいう
2137 \ltjsetparameter{yjabaselineshift=5pt, yalbaselineshift=2pt}abcあいう
2138 \end{LTXexample}
2139 %<*en>
2140 Here the horizontal line in above is the baseline of a line.
2141 %</en>
2142 %<*ja>
2143 上の例において引かれている水平線がベースラインである.
2144 %</ja>
2145
2146 %<*en>
2147 There is an interesting side-effect: characters in different size can be
2148 vertically aligned center in a line, by setting two parameters appropriately.
2149 The following is an example (beware the value is not well tuned):
2150 %</en>
2151 %<*ja>
2152 この機能には面白い使い方がある:2つのパラメータを適切に設定することで,サイズの
2153 異なる文字を中心線に揃えることができる.
2154 以下は一つの例である(値はあまり調整されていないことに注意):
2155 %</ja>
2156 \begin{LTXexample}
2157 xyz漢字
2158 {\scriptsize
2159   \ltjsetparameter{yjabaselineshift=-1pt,
2160     yalbaselineshift=-1pt}
2161   XYZひらがな
2162 }abcかな
2163 \end{LTXexample}
2164
2165
2166 %<*ja>
2167 \paragraph{数式における挙動:\pTeX との違い}
2168 \textbf{ALchar}のベースラインを補正する \Param{yalbaselineshift} パラメータは
2169 ほぼ\pTeX における \verb+\ybaselineshift+ に対応しているものであるが,
2170 数式中の挙動は異なっているので注意が必要である.
2171 例えば,表\ref{tab:math_bsa}のように,数式中に明示的に現れた \verb+\hbox+ は,
2172 \begin{itemize}
2173  \item \pTeX では,ボックス全体が \verb+\ybaselineshift+ だとシフトされるので,
2174  表\ref{tab:math_bsa}中の``い''のように,ボックス中の和文文字は
2175  \verb+\ybaselineshift+だけシフトされ,一方,``for all''のように,
2176  ボックス内の欧文文字は2重にシフトされることになる.
2177  \item 一方,\LuaTeX-jaではそのようなことはおこらず,
2178  数式中に明示的に現れた \verb+\hbox+ はシフトしない.そのため,
2179  表\ref{tab:math_bsa}中の``い''も``for all''も,それぞれ本文中に
2180  書かれたときと同じ上下位置に組まれる.
2181 \end{itemize}
2182 \begin{table}
2183 \small\centering
2184 \caption{数式関係のベースライン補正($\Param{yalbaselineshift}=10\,\textrm{pt}$)}
2185 \label{tab:math_bsa}
2186 \newdimen\origbaselineskip
2187 \origbaselineskip=\baselineskip
2188 \begin{tabular}{lp{30\zw}}
2189 \toprule
2190 \emph{入力}&\vspace*{\dimexpr-\origbaselineskip-\smallskipamount}
2191 \begin{verbatim}
2192 数式abc: $あa\hbox{い}$, $\int_0^x t\,dt=x^2\!/2$,
2193 $\Phi\vdash F(x)\ \hbox{for all}\ x\in A$
2194 \end{verbatim}\\
2195 \noalign{\vskip-\origbaselineskip}
2196 \midrule
2197 \emph{\pTeX}&
2198 {\ltjsetparameter{yalbaselineshift=10pt}%
2199 数式abc: $あa\lower10pt\hbox{い}$, $\int_0^x t\,dt=x^2\!/2$,
2200 $\Phi\vdash F(x)\ \lower10pt\hbox{for all}\ x\in A$
2201 \par}\\
2202 \midrule
2203 \emph{\LuaTeX-ja}&
2204 {\ltjsetparameter{yalbaselineshift=10pt}%
2205 数式abc: $あa\hbox{い}$, $\int_0^x t\,dt=x^2\!/2$,
2206 $\Phi\vdash F(x)\ \hbox{for all}\ x\in A$
2207 \par}\\
2208 \noalign{\vskip-\origbaselineskip}
2209 \bottomrule
2210 \end{tabular}
2211 \end{table}
2212 %</ja>
2213
2214 %<en>\part{Reference}
2215 %<ja>\part{リファレンス}
2216 \label{part-ref}
2217
2218 %<*ja>
2219 \section{\LuaTeX-jaにおける \texttt{\textbackslash catcode}}
2220 \subsection{予備知識:\pTeX と\upTeX における \texttt{\textbackslash kcatcode}}
2221 \pTeX,\upTeX においては,和文文字が制御綴内で利用できるかどうか
2222 は \verb+\kcatcode+ の値によって決定されるのであった.
2223 詳細は表\ref{table-kcat}を参照されたい.
2224 %</ja>
2225 %<*en>
2226 \section{\texttt{\textbackslash catcode} in \LuaTeX-ja}
2227 \subsection{Preliminaries: \texttt{\textbackslash kcatcode} in \pTeX\ and \upTeX}
2228 In \pTeX~and~\upTeX, the value of \verb+\kcatcode+ determines
2229 whether a Japanese character can be used in a control word.
2230 For the detail, see Table~\ref{table-kcat}.
2231 %</en>
2232
2233 \begin{table}[t]
2234 \small
2235 \caption{\texttt{\textbackslash kcatcode} in \upTeX}
2236 \label{table-kcat}
2237 %<en>\medskip
2238
2239 \noindent\hfill
2240 \begin{tabular}{ccccc}
2241 \toprule
2242 \bfseries \verb+\kcatcode+&
2243 %<*en>
2244 \bfseries meaning&
2245 \bfseries control word&
2246 \bfseries widow penalty\hbox{}$^*$&
2247 \bfseries linebreak\\
2248 %</en>
2249 %<*ja>
2250 \bfseries 意図&
2251 \bfseries 制御綴中に使用&
2252 \bfseries 文字ウィドウ処理\hbox{}$^*$&
2253 \bfseries 直後での改行\\
2254 %</ja>
2255 \midrule
2256 15&non-cjk&\multicolumn{3}{c}{(treated as usual \LaTeX)}\\
2257 16&kanji&Y&Y&ignored\\
2258 17&kana&Y&Y&ignored\\
2259 18&other&N&N&ignored\\
2260 19&hangul&Y&Y&space\\
2261 \bottomrule
2262 \end{tabular}\hfill\null
2263
2264 \medskip
2265
2266 %<*ja>
2267 文字ウィドウ処理\hbox{}$^*$: 「漢字が一文字だけ次の行に行くのを防ぐ」\
2268 \texttt{\textbackslash jcharwidowpenalty} が,
2269 その文字の直前に挿入されうるか否か,を示す.
2270 %</ja>
2271 \end{table}
2272
2273 %<*en>
2274 \verb+\kcatcode+ can be set by a row of JIS~X~0208 in \pTeX,
2275 and generally by a Unicode block\footnote{%
2276   \upTeX\ divides \texttt{U+FF00}--\texttt{U+FFEF} (Halfwidth and Fullwidth Forms)
2277   into three subblocks, and \texttt{\textbackslash kcatcode} can be set by a subblock.
2278 }
2279 in \upTeX. So characters which can be used in a control word
2280 slightly differ between \pTeX~and~\upTeX.
2281 %</en>
2282 %<*ja>
2283 \pTeX では \verb+\kcatcode+ はJIS~X~0208の区単位,
2284 \upTeX では概ねUnicodeブロック単位\footnote{%
2285   \texttt{U+FF00}--\texttt{U+FFEF} (Halfwidth and Fullwidth Forms)は
2286   「全角英数字」「半角カナ」「その他」と3つに分割されており,
2287   それぞれ別々に \texttt{\textbackslash kcatcode} が指定できるようになっている.
2288 }で設定可能になっている.そのため,\pTeX と\upTeX の初期状態では
2289 制御綴内で使用可能な文字が微妙に異なっている.
2290 %</ja>
2291
2292 %<*en>
2293 \subsection{Case of \LuaTeX-ja}
2294 The role of \verb+\kcatcode+ in \pTeX~and~\upTeX\ can be
2295 divided into the following four kinds,
2296 and \LuaTeX-ja can control these four kinds separately:
2297 \begin{itemize}
2298  \item
2299 \emph{Distinction between \textbf{JAchar} or \textbf{ALchar}}
2300 is controlled by using the character range, see Subsection~\ref{ssec-setrange}.
2301  \item
2302 \emph{Whether the character can be used in a control word}
2303 is controlled by setting \verb+\catcode+ to 11~(enabled) or 12~(disabled), as usual.
2304  \item
2305 \emph{Whether \Param{jcharwidowpenalty} can be inserted before the character}
2306 is controlled by the lowermost bit of the \Param{kcatcode} parameter.
2307  \item
2308 \emph{Ignoring linebreak after a \textbf{JAchar}} is always ignored.
2309 \end{itemize}
2310 %</en>
2311 %<*ja>
2312 \subsection{\LuaTeX-jaの場合}
2313 \LuaTeX-jaでは,従来の\pTeX・\upTeX における \verb+\kcatcode+ の役割を
2314 分割している:
2315 \begin{description}
2316  \item[欧文/和文の区別 (\upTeX)]
2317 \verb+\ltjdefcharrange+ と\textsf{jacharrange}パラメータ(\ref{ssec-setrange}節)
2318  \item[制御綴中に使用可か]
2319 \LuaTeX 自身の \verb+\catcode+ でよい
2320  \item[\Param{jcharwidowpenalty}が挿入可か]
2321 \Param{kcatcode}パラメータの最下位ビット
2322  \item[直後の改行の無視]
2323 日本語しか想定していないので\textbf{JAchar}については一律有効
2324 \end{description}
2325 %</ja>
2326
2327 %<*en>
2328 Default setting of \verb+\catcode+ of \LuaTeX\ can be found
2329 in \texttt{luatex-unicode-letters.tex},
2330 which is based on \texttt{unicode-letters.tex} (for \XeTeX).
2331 However, the default setting of \verb+\catcode+ differs
2332 between \XeTeX\ and \LuaTeX, by the following reasons:
2333 \begin{itemize}
2334  \item \texttt{luatex-unicode-letters.tex} is based on old \texttt{unicode-letters.tex}.
2335  \item The latter half of \texttt{unicode-letters.tex} sets
2336 \verb+\catcode+ of Kanji and kana characters to 11,
2337 via setting \verb+\XeTeXcharclass+.
2338
2339 However, this latter half is simply omitted in
2340 \texttt{luatex-unicode-letters.tex}, hence
2341 \verb+\catcode+ of Kanji and kana characters remains 12 in \LuaTeX.
2342 \end{itemize}
2343 In other words, Kanji nor kana characters cannot be used in
2344 a control word, in the default setting of \LuaTeX.
2345
2346 This would be inconvenient for \pTeX~users to shifting to \LuaTeX-ja,
2347 since several control words containing Kanji, such as \verb+\西暦+,
2348 are used in \pTeX.
2349 Hence, \LuaTeX-ja have a counterpart of \texttt{unicode-letters.tex}
2350 for \LuaTeX, \emph{to match the \texttt{\textbackslash catcode} setting with that of \XeTeX.}
2351 %</en>
2352 %<*ja>
2353 ネイティブにUnicode全部の文字を扱える\XeTeX や\LuaTeX では,
2354 文字が制御綴内で使用できるかは通常の欧文文字と同じく \verb+\catcode+
2355 で指定することとなる.\XeTeX における \verb+\catcode+ の初期設定は\
2356 \texttt{unicode-letters.tex} 中に記述されており,\LuaTeX ではそれを
2357 元にした \texttt{luatex-unicode-letters.tex} を用いている.
2358
2359 だが,\XeTeX における \verb+\catcode+ の初期設定と
2360 \LuaTeX におけるそれは一致していない:
2361 \begin{itemize}
2362  \item \texttt{luatex-unicode-letters.tex} の元になった\
2363 \texttt{unicode-letters.tex} が古い
2364  \item \texttt{unicode-letters.tex} の後半部では
2365 \verb+\XeTeXcharclass+ の設定を行なっており,
2366 それによって漢字や仮名の \verb+\catcode+ が11に設定されている.
2367
2368 しかし,\texttt{luatex-unicode-letters.tex} ではこの「後半部」が
2369 まるごと省略されており,漢字や仮名の \verb+\catcode+ は12のまま.
2370 \end{itemize}
2371 言い換えると,\LuaTeX の初期状態では漢字や仮名を制御綴内に
2372 使用することはできない.
2373
2374 これでは \pTeX で使用できた \verb+\西暦+ などが使えないこととなり,
2375 \LuaTeX-jaへの移行で手間が生じる.そのため,\LuaTeX-jaでは
2376 \texttt{unicode-letters.tex} の後半部にあたる内容を自前でパッチし,
2377 結果として\textbf{\XeTeX における初期設定と同じになるようにしている.}
2378 %</ja>
2379
2380 \begin{table}
2381  \centering\small
2382 %<en>\caption{Difference of the set of non-kanji JIS~X~0208 characters which can be used in a control word}
2383 %<ja>\caption{制御綴中に使用出来るJIS~X~0208非漢字の違い}
2384 %<en>\medskip
2385 \label{table-kcat-diff}
2386 \def\D#1#2#3#4{%
2387   {\fboxsep0pt\fcolorbox{cyan}{white}%
2388   {\large\char"#1#2#3#4}}\ (\texttt{U+#1#2#3#4})} %"
2389 \leavevmode\hbox to 0pt{\hss\begin{tabular}{cccccc}
2390 \toprule
2391 %<en>&\bf row&\bf col.&\bf \pTeX&\bf \upTeX&\bf\LuaTeX-ja\\
2392 %<ja>&\bf 区&\bf 点&\bf \pTeX&\bf \upTeX&\fontseries{b}\selectfont\LuaTeX-ja\\
2393 \midrule
2394 \D 3000&1&1&N&N&Y\\
2395 \D 30FB&1&6&N&Y&N\\
2396 \D 309B&1&11&N&Y&N\\
2397 \D 309C&1&12&N&Y&N\\
2398 \D FF40&1&14&N&N&Y\\
2399 \D FF3E&1&16&N&N&Y\\
2400 \D FFE3&1&17&N&N&Y\\
2401 \D FF3F&1&18&N&N&Y\\
2402 \D 30FD&1&19&N&Y&Y\\
2403 \D 30FE&1&20&N&Y&Y\\
2404 \D 309D&1&21&N&Y&Y\\
2405 \D 309E&1&22&N&Y&Y\\
2406 \D 3003&1&23&N&N&Y\\
2407 \D 4EDD&1&24&N&Y&Y\\
2408 \D 3005&1&25&N&N&Y\\
2409 \D 3006&1&26&N&N&Y\\
2410 \D 3007&1&27&N&N&Y\\
2411 \D 30FC&1&28&N&Y&Y\\
2412 \bottomrule
2413 \end{tabular}\qquad
2414 \begin{tabular}{cccccc}
2415 \toprule
2416 %<en>&\bf row&\bf col.&\bf \pTeX&\bf \upTeX&\bf\LuaTeX-ja\\
2417 %<ja>&\bf 区&\bf 点&\bf \pTeX&\bf \upTeX&\fontseries{b}\selectfont\LuaTeX-ja\\
2418 \midrule
2419 \D FF0F&1&31&N&N&Y\\
2420 \D FF3C&1&32&N&N&Y\\
2421 \D FF5C&1&35&N&N&Y\\
2422 \D FF0B&1&60&N&N&Y\\
2423 \D FF1D&1&65&N&N&Y\\
2424 \D FF1C&1&67&N&N&Y\\
2425 \D FF1E&1&68&N&N&Y\\
2426 \D FF03&1&84&N&N&Y\\
2427 \D FF06&1&85&N&N&Y\\
2428 \D FF0A&1&86&N&N&Y\\
2429 \D FF20&1&87&N&N&Y\\
2430 \D 3012&2&9&N&N&Y\\
2431 \D 3013&2&14&N&N&Y\\
2432 \D FFE2&2&44&N&N&Y\\
2433 \D 212B&2&82&N&N&Y\\
2434 %<en>\multicolumn{3}{c}{$\vphantom{\D 3000}$\hbox{}Greek letters (row 6)}&Y&N&Y\\
2435 %<en>\multicolumn{3}{c}{$\vphantom{\D 3000}$\hbox{}Cyrillic letters (row 7)}&N&N&Y\\
2436 %<ja>\multicolumn{3}{c}{$\vphantom{\D 3000}$\hbox{}ギリシャ文字(6区)}&Y&N&Y\\
2437 %<ja>\multicolumn{3}{c}{$\vphantom{\D 3000}$\hbox{}キリル文字(7区)}&N&N&Y\\
2438 $\vphantom{\D 3000}$\\
2439 \bottomrule
2440 \end{tabular}\hss}\par
2441 \end{table}
2442
2443 %<*en>
2444 \subsection{Non-kanji Characters in a Control Word}
2445 Because the engine differ, so non-kanji JIS~X~0208 characters
2446 which can be used in a control word differ in \pTeX, in \upTeX,~and~in \LuaTeX-ja.
2447 Table~\ref{table-kcat-diff} shows the difference.
2448 Except for four characters ``・'',~``゛'', ``゜'',~``゠'',
2449 \LuaTeX-ja admits more characters in a control word than \upTeX.
2450 \emph{Note that the ideographic space~\texttt{U+3000} can be used
2451 in a control word in \LuaTeX-ja.}
2452
2453 Difference becomes larger, if we consider
2454 non-kanji JIS~X~0213 characters.
2455 For the detail, see \url{https://github.com/h-kitagawa/kct}.
2456 %</en>
2457 %<*ja>
2458 \subsection{制御綴中に使用出来るJIS非漢字の違い}
2459
2460 エンジンが異なるので,\pTeX, \upTeX, \LuaTeX-ja
2461 において制御綴中に使用可能なJIS~X~0208の文字は異なる.
2462 異なっているところだけを載せると,表\ref{table-kcat-diff}のようになる.
2463 「・」「゛」「゜」「゠」を除けば,\LuaTeX-jaでは\upTeX より多くの文字が
2464 制御綴に使用可能になっている.
2465 \textbf{特に重要なのは,全角空白(\texttt{U+3000})が
2466 \LuaTeX-jaでは制御綴中に使用可能であることである.}
2467
2468 JIS~X~0213の範囲に広げると,差異はさらに大きくなる.
2469 詳細については例えば \url{https://github.com/h-kitagawa/kct} 中の\
2470 \texttt{kct-uni-out.pdf} などを参照すること.
2471 %</ja>
2472
2473
2474
2475
2476 %<*ja>
2477 \section{縦組}
2478 \label{sec-direction}
2479 \LuaTeX 本体でも,$\Omega$・$\aleph$由来の機能として,複数の組方向をサポートしている.
2480 しかし,\LuaTeX がサポートするのは \texttt{TLT},~\texttt{TRT}, \texttt{RTT},~\texttt{LTL}\
2481 のみであり,日本語の縦組に使うのは望ましくない\footnote{%
2482 和文文字だけならば \texttt{RTT} を使えばなんとかなると思うが,
2483 欧文文字が入ってきた場合はうまくいかず,\texttt{RTR} という組方向が必要になる.
2484 }.そのため,\LuaTeX-jaでは横組(\texttt{TLT})で組んだボックスを回転させる方式で
2485 縦組を実装した.
2486
2487 \subsection{サポートする組方向}
2488 \begin{table}[t]
2489 \caption{\LuaTeX-ja のサポートする組方向}
2490 %<en>\medskip
2491 \label{tab-dir}
2492 \centering\small
2493 \def\obox#1{%
2494   \setbox0=\hbox{\yoko\hbox{#1%
2495   \large\ltjsetparameter{talbaselineshift=0pt}%
2496   \vrule height 25pt width 0.4pt depth 15pt\kern-.2pt%
2497   \raise25pt\hbox to 0pt{\hss\composite{*r^@{>>}}\hss}%
2498   \raise-15pt\hbox to 0pt{\hss\composite{*l^@{>|}}\hss}\kern.2pt%
2499   \vrule height.2pt depth.2pt width 60pt\hbox to 0pt{\hss\composite{*d^@{>}}\hss}\kern-60pt
2500   \hbox to 60pt{\,銀は、Ag\hss}}}%
2501   \raise\dimexpr 0.5\ltjgetdp0-0.5\ltjgetht0\box0%
2502 }
2503 \begin{tabular}{>{\bfseries}lcccc}
2504 \toprule
2505 &\texttt{\textbackslash yoko}(横組)&\texttt{\textbackslash tate}(縦組)
2506  &\texttt{\textbackslash dtou}&\texttt{\textbackslash utod}\\
2507 \midrule
2508 字送り方向&水平右向き(→)&垂直下向き(↓)&垂直上向き(↑)&垂直下向き(↓)\\
2509 行送り方向&垂直下向き(↓)&水平左向き(←)&水平右向き(→)&水平左向き(←)\\
2510 使用する和文フォント&横組用(\verb+\jfont+)&縦組用(\verb+\tfont+)&
2511 \multicolumn{2}{c}{%
2512   横組用(\texttt{\textbackslash jfont})の$90^\circ$回転}\\[\smallskipamount]
2513 組版例\null $^*$ &\obox{\yoko}&\obox{\tate}&\obox{\dtou}&\obox{\utod}\\
2514 \noalign{\medskip}
2515 \bottomrule
2516 \end{tabular}
2517
2518 \medskip\raggedright
2519 \def\R#1{%
2520   \raise0.38\zw\hbox{%
2521     \vrule height.2pt  depth.2pt width2\zw%
2522     \hbox to 0pt{\hss\composite{*d^@{#1}}\hss}%
2523   }%
2524 }
2525 $^*$\ 幅(width),高さ(height),深さ(depth)の増加方向を,
2526 それぞれ「\R{>}」,「\R{>>}」,「\R{>|}」で表している.
2527 \raggedright
2528
2529 \end{table}
2530
2531 \LuaTeX-jaがサポートする組方向は表\ref{tab-dir}に示す4つである.
2532 4列目の \verb+\dtou+ は聞き慣れない命令だと思うが,
2533 実は\pTeX に同名の命令が(ドキュメントには書かれていないが)存在する.
2534 Down-TO-Upの意味なのだろう.\verb+\dtou+ を使用する機会はないだろうが,
2535 \LuaTeX-jaではデバッグ用に実装している.
2536 5列目の \verb+\utod+ は,\pTeX で言う「縦数式ディレクション」に相当するものである.
2537
2538 組方向は,\verb+\yoko+,~\verb+\tate+, \verb+\dtou+,~\verb+\utod+ をそれぞれ使用することで,
2539 現在作成中のリストやボックスが空の時にのみ変更可能である.
2540 また,縦組中の数式内のボックスは\pTeX と同じように組方向が \verb+\utod+ となる.
2541
2542 \subsection{異方向のボックス}
2543
2544 縦組の中に「42」などの2桁以上の算用数字を横組で組むなど,
2545 異なる組方向を混在させることがしばしば行われる.
2546 組方向の混在も\pTeX と同じようにできる:
2547 \begin{LTXexample}
2548 ここは横組%     yoko
2549 \hbox{\tate %   tate
2550   \hbox{縦組}%  tate
2551   の中に
2552   \hbox{\yoko 横組の内容}% yoko
2553   を挿入する
2554 }
2555 また横組に戻る% yoko
2556 \end{LTXexample}
2557
2558 異なる組方向のボックスを配置した場合にどう組まれるかの仕様も,\pTeX を
2559 踏襲している.表\ref{tab-diffdir}に示す.
2560
2561 \begin{table}[t]
2562 \caption{異方向のボックスの配置}
2563 %<en>\medskip
2564 \label{tab-diffdir}
2565  \centering\small\unitlength3mm
2566  \def\TATEeg{%
2567    \hbox{\smash{\begin{picture}(0,0)(-2,0)
2568      \thicklines
2569      \polyline(-2,0)(-2,-7)(5,-7)(5,0)
2570      \put(0,0){\circle*{0.3}}
2571      \put(0,0){\vector(1,0){5}} \put(2.5,-0.2){\makebox(0,0)[t]{$h_{\mathrm{T}}$}}
2572      \put(0,0){\vector(-1,0){2}}\put(-1,-0.2){\makebox(0,0)[t]{$d_{\mathrm{T}}$}}
2573      \put(0,0){\vector(0,-1){7}}\put(0.2,-3.5){\makebox(0,0)[l]{$w_{\mathrm{T}}$}}
2574    \end{picture}}}
2575  }
2576  \def\DTOUeg{%
2577    \hbox{\smash{\begin{picture}(0,0)(-5,0)
2578      \thicklines
2579      \polyline(-5,0)(-5,7)(2,7)(2,0)
2580      \put(0,0){\circle*{0.3}}
2581      \put(0,0){\vector(-1,0){5}} \put(-2.5,0.3){\makebox(0,0)[b]{$h_{\mathrm{D}}$}}
2582      \put(0,0){\vector(1,0){2}}\put(1,0.3){\makebox(0,0)[b]{$d_{\mathrm{D}}$}}
2583      \put(0,0){\vector(0,1){7}}\put(-0.2,3.5){\makebox(0,0)[r]{$w_{\mathrm{D}}$}}
2584    \end{picture}}}
2585  }
2586  \def\YOKOeg{%
2587    \hbox{\smash{\begin{picture}(0,0)
2588      \thicklines
2589      \polyline(0,5)(7,5)(7,-2)(0,-2)
2590      \put(0,0){\circle*{0.3}}
2591      \put(0,0){\vector(0,1){5}} \put(0.3,2.5){\makebox(0,0)[l]{$h_{\mathrm{Y}}$}}
2592      \put(0,0){\vector(0,-1){2}}\put(0.3,-1){\makebox(0,0)[l]{$d_{\mathrm{Y}}$}}
2593      \put(0,0){\vector(1,0){7}}\put(3.5,0.2){\makebox(0,0)[b]{$w_{\mathrm{Y}}$}}
2594    \end{picture}}}
2595  }
2596 \begin{tabular}{ccc}
2597 \toprule
2598 \emph{横組中に配置}&\emph{縦組中に配置}&%
2599 \emph{組方向\hskip\ltjgetparameter{xkanjiskip}\texttt{\textbackslash dtou}中に配置}\\
2600 \midrule
2601  \parbox[c]{15\unitlength}{\begin{picture}(15,15)(0,-4)
2602    \put(0,0){\line(1,0){3.8}}
2603    \put(4,7){\TATEeg}
2604    \put(11.2,0){\line(1,0){3.8}}
2605 %
2606    \put(2,7){\line(1,0){1.8}}
2607    \put(3,3.5){\vector(0,1){3.5}\vector(0,-1){3.5}}
2608    \put(2.8,3.5){\makebox(0,0)[r]{$H_{\mathrm{Y}}$}}
2609    \put(3,-2){\vector(0,1){2}}
2610    \put(2.8,-1){\makebox(0,0)[r]{$D_{\mathrm{Y}}$}}
2611 %
2612    \put(4,7.2){\line(0,1){1.8}}
2613    \put(11,7.2){\line(0,1){1.8}}
2614    \put(6,8){\vector(-1,0){2}}
2615    \put(9,8){\vector(1,0){2}}
2616    \put(7.5,8){\makebox(0,0){$W_{\mathrm{Y}}$}}
2617 %
2618  \end{picture}\vspace{-\baselineskip}
2619    \begin{align*}
2620    W_{\mathrm{Y}} &= h_{\mathrm{T}}+d_{\mathrm{T}},\\
2621    H_{\mathrm{Y}} &= w_{\mathrm{T}},\\
2622    D_{\mathrm{Y}} &=0\,\mathrm{pt}
2623    \end{align*}%
2624  }&
2625  \parbox[c]{15\unitlength}{\begin{picture}(15,15)(0,-4)
2626    \put(7.5,-0.2){\line(0,-1){2.8}}
2627    \put(4,2){\YOKOeg}
2628    \put(7.5, 7.2){\line(0,1){3.8}}
2629 %
2630    \put(2,7){\line(1,0){1.8}}
2631    \put(2,0){\line(1,0){1.8}}
2632    \put(3,5){\vector(0,1){2}}
2633    \put(3,2){\vector(0,-1){2}}
2634    \put(3,3.5){\makebox(0,0){$W_{\mathrm{T}}$}}
2635 %
2636    \put(4,7.2){\line(0,1){1.8}}
2637    \put(11,7.2){\line(0,1){1.8}}
2638    \put(8,8){\vector(-1,0){0.5}\vector(1,0){3}}
2639    \put(7,8){\vector(-1,0){3}\vector(1,0){0.5}}
2640    \put(9.25,8.2){\makebox(0,0)[b]{$H_{\mathrm{T}}$}}
2641    \put(5.75,8.2){\makebox(0,0)[b]{$D_{\mathrm{T}}$}}
2642 %
2643  \end{picture}\vspace{-\baselineskip}
2644    \begin{align*}
2645    W_{\mathrm{T}} &= h_{\mathrm{Y}}+d_{\mathrm{Y}},\\
2646    H_{\mathrm{T}} &= w_{\mathrm{Y}}/2,\\
2647    D_{\mathrm{T}} &= w_{\mathrm{Y}}/2
2648    \end{align*}%
2649  }&
2650  \parbox[c]{15\unitlength}{\begin{picture}(15,15)(0,-4)
2651    \put(11,-0.2){\line(0,-1){2.8}}
2652    \put(4,2){\YOKOeg}
2653    \put(11, 7.2){\line(0,1){3.8}}
2654 %
2655    \put(2,7){\line(1,0){1.8}}
2656    \put(2,0){\line(1,0){1.8}}
2657    \put(3,5){\vector(0,1){2}}
2658    \put(3,2){\vector(0,-1){2}}
2659    \put(3,3.5){\makebox(0,0){$W_{\mathrm{D}}$}}
2660 %
2661    \put(4,7.2){\line(0,1){1.8}}
2662    \put(11,7.2){\line(0,1){1.8}}
2663    \put(7.5,8){\vector(-1,0){3.5}\vector(1,0){3.5}}
2664    \put(13,8){\vector(-1,0){2}}
2665    \put(7.5,8.2){\makebox(0,0)[b]{$H_{\mathrm{D}}$}}
2666    \put(12,8.2){\makebox(0,0)[b]{$D_{\mathrm{D}}$}}
2667 %
2668  \end{picture}\vspace{-\baselineskip}
2669    \begin{align*}
2670    W_{\mathrm{D}} &= h_{\mathrm{Y}}+d_{\mathrm{Y}},\\
2671    H_{\mathrm{D}} &= w_{\mathrm{Y}},\\
2672    D_{\mathrm{D}} &= 0\,\mathrm{pt}
2673    \end{align*}%
2674  }%
2675 \\\midrule
2676  \parbox[c]{15\unitlength}{\begin{picture}(15,15)(0,-4)
2677    \put(0,0){\line(1,0){3.8}}
2678    \put(4,0){\DTOUeg}
2679    \put(11.2,0){\line(1,0){3.8}}
2680 %
2681    \put(2,7){\line(1,0){1.8}}
2682    \put(3,3.5){\vector(0,1){3.5}\vector(0,-1){3.5}}
2683    \put(2.8,3.5){\makebox(0,0)[r]{$H_{\mathrm{Y}}$}}
2684    \put(3,-2){\vector(0,1){2}}
2685    \put(2.8,-1){\makebox(0,0)[r]{$D_{\mathrm{Y}}$}}
2686 %
2687    \put(4,7.2){\line(0,1){1.8}}
2688    \put(11,7.2){\line(0,1){1.8}}
2689    \put(6,8){\vector(-1,0){2}}
2690    \put(9,8){\vector(1,0){2}}
2691    \put(7.5,8){\makebox(0,0){$W_{\mathrm{Y}}$}}
2692 %
2693  \end{picture}\vspace{-\baselineskip}
2694    \begin{align*}
2695    W_{\mathrm{Y}} &= h_{\mathrm{D}}+d_{\mathrm{D}},\\
2696    H_{\mathrm{Y}} &= w_{\mathrm{D}},\\
2697    D_{\mathrm{Y}} &= 0\,pt
2698    \end{align*}%
2699  }&
2700  \parbox[c]{15\unitlength}{\begin{picture}(15,15)(0,-4)
2701    \put(9,-0.2){\line(0,-1){2.8}}
2702    \put(4,0){\DTOUeg}
2703    \put(9, 7.2){\line(0,1){3.8}}
2704 %
2705    \put(2,7){\line(1,0){1.8}}
2706    \put(2,0){\line(1,0){1.8}}
2707    \put(3,5){\vector(0,1){2}}
2708    \put(3,2){\vector(0,-1){2}}
2709    \put(3,3.5){\makebox(0,0){$W_{\mathrm{T}}$}}
2710 %
2711    \put(4,7.2){\line(0,1){1.8}}
2712    \put(11,7.2){\line(0,1){1.8}}
2713    \put(6.5,8){\vector(-1,0){2.5}\vector(1,0){2.5}}
2714    \put(10,8){\vector(-1,0){1}\vector(1,0){1}}
2715    \put(10,8.2){\makebox(0,0)[b]{$H_{\mathrm{T}}$}}
2716    \put(6.5,8.2){\makebox(0,0)[b]{$D_{\mathrm{T}}$}}
2717 %
2718  \end{picture}\vspace{-\baselineskip}
2719    \begin{align*}
2720    W_{\mathrm{T}} &= h_{\mathrm{D}}+d_{\mathrm{D}},\\
2721    H_{\mathrm{T}} &= d_{\mathrm{D}},\\
2722    D_{\mathrm{T}} &= h_{\mathrm{D}}
2723    \end{align*}%
2724  }&
2725  \parbox[c]{15\unitlength}{\begin{picture}(15,15)(0,-4)
2726    \put(6,-0.2){\line(0,-1){2.8}}
2727    \put(4,7){\TATEeg}
2728    \put(6, 7.2){\line(0,1){3.8}}
2729 %
2730    \put(2,7){\line(1,0){1.8}}
2731    \put(2,0){\line(1,0){1.8}}
2732    \put(3,5){\vector(0,1){2}}
2733    \put(3,2){\vector(0,-1){2}}
2734    \put(3,3.5){\makebox(0,0){$W_{\mathrm{D}}$}}
2735 %
2736    \put(4,7.2){\line(0,1){1.8}}
2737    \put(11,7.2){\line(0,1){1.8}}
2738    \put(5,8){\vector(-1,0){1}\vector(1,0){1}}
2739    \put(8.5,8){\vector(-1,0){2.5}\vector(1,0){2.5}}
2740    \put(5,8.2){\makebox(0,0)[b]{$H_{\mathrm{D}}$}}
2741    \put(8.5,8.2){\makebox(0,0)[b]{$D_{\mathrm{D}}$}}
2742 %
2743  \end{picture}\vspace{-\baselineskip}
2744    \begin{align*}
2745    W_{\mathrm{D}} &= w_{\mathrm{T}},\\
2746    H_{\mathrm{D}} &= d_{\mathrm{T}},\\
2747    D_{\mathrm{D}} &= h_{\mathrm{T}}
2748    \end{align*}%
2749  }\\
2750 \bottomrule
2751 \end{tabular}
2752 \end{table}
2753
2754
2755 \paragraph{\texttt{\textbackslash wd} は組方向には対応しない}
2756 ボックスレジスタ \verb+\box+<num> にセットされているボックスの幅・高さ・深さの取得や
2757 変更にはそれぞれ \verb+\wd+,~\verb+\ht+,~\verb+\dp+ プリミティブを用いるのであった.
2758 \pTeX ではこれらのプリミティブは,「現在の組方向におけるボックスの寸法」を指すものであった.
2759
2760 \LuaTeX-jaにおいては状況が異なり,\verb+\wd+,~\verb+\ht+,~\verb+\dp+ は\emph{組方向が
2761 混在する状況においては正しく機能しない}.具体的には,現在の組方向に依存しないことが挙げられる.
2762 \begin{LTXexample}
2763 % yoko direction
2764 \setbox0=\hbox to 20pt{foo}
2765 \the\wd0,~\hbox{\tate\vrule\the\wd0}
2766 \wd0=100pt
2767 \the\wd0,~\hbox{\tate \the\wd0}
2768 \end{LTXexample}
2769
2770 \paragraph{\texttt{\textbackslash wd} 等の代替命令}
2771
2772 \pTeX のように現在の組方向に応じたボックスの寸法の取得・設定を行うため,
2773 次の命令を新設した.
2774
2775 \begin{cslist}
2776
2777  \item[ltjgetwd\{<num>\}\textrm{, }\textbackslash ltjgetht\{<num>\}\textrm{, }%
2778   \textbackslash ltjgetdp\{<num>\}]
2779 現在の組方向に応じたボックスの寸法の取得を行う.結果は内部長さであるため,
2780 {\let\item=\origitem
2781 \begin{verbatim}
2782 \dimexpr 2\ltjgetwd{42}-3pt\relax, \the\ltjgetwd{1701}
2783 \end{verbatim}
2784 のように \verb+\wd+<num> の代わりとして扱うことができる.引数が1桁の場合は,
2785 \verb+\ltjgetwd3+ のように引数をグループで括らなくても良いが,そうでない場合は
2786 (通常の命令への引数のように)\verb+\ltjgetwd{42}+ とグループに括る必要がある.
2787 使用例は以下の通りである.
2788 \begin{LTXexample}[width=0.3\textwidth]
2789 \parindent0pt
2790 \setbox32767=\hbox{\yoko よこぐみ}
2791 \fboxsep=0mm\fbox{\copy32767}
2792 \vbox{\hsize=20mm
2793 \yoko YOKO \the\ltjgetwd{32767}, \\
2794   \the\ltjgetht{32767}, \\ \the\ltjgetdp{32767}.}
2795 \vbox{\hsize=20mm\raggedleft
2796 \tate TATE \the\ltjgetwd{32767}, \\
2797   \the\ltjgetht{32767}, \\ \the\ltjgetdp{32767}.}
2798 \vbox{\hsize=20mm\raggedleft
2799 \dtou DTOU \the\ltjgetwd{32767}, \\
2800   \the\ltjgetht{32767}, \\ \the\ltjgetdp{32767}.}
2801 \end{LTXexample}}
2802
2803  \item[ltjsetwd<num>=<dimen>\textrm{, }\textbackslash ltjsetht<num>=<dimen>\textrm{, }%
2804   \textbackslash ltjsetdp<num>=<dimen>]
2805 現在の組方向に応じたボックスの寸法の設定を行う.\verb+\afterassignment+ を2回利用して
2806 実装しているので,次の4通りは全て同じ意味である.
2807 {\let\item=\origitem
2808 \begin{verbatim}
2809 \ltjsetwd42 20pt,  \ltjsetwd42=20pt,  \ltjsetwd=42 20pt,  \ltjsetwd=42=20pt
2810 \end{verbatim}
2811 }%
2812
2813 設定値は組方向ごとに独立して記録される.
2814
2815 \end{cslist}
2816
2817 \subsection{組方向の取得}
2818 「現在の組方向」や「<num>番のボックスの組方向」は,
2819 \pTeX では\verb+\ifydir+ や \verb+\ifybox+<num> といった条件判断文を使って
2820 判断することができた.
2821 しかし,\LuaTeX-jaはあくまでも\TeX マクロとLuaコードで
2822 記述されており,それでは新たな条件判断命令を作るのは難しい.
2823
2824 \LuaTeX-jaでは,\Param{direction}パラメータで現在の組方向を,
2825 \Param{boxdir}パラメータによってボックスの組方向をそれぞれ取得できるようにした.
2826 戻り値は1文字の数字(文字列)であり,1は \verb+\dtou+ 方向を,
2827 3は縦組を,4は横組,11は \verb+\utod+ 方向を表す:
2828 \begin{LTXexample}[width=0.3\textwidth]
2829 \leavevmode\def\DIR{\ltjgetparameter{direction}}
2830 \hbox{\yoko \DIR}, \hbox{\tate\DIR}, \hbox{\dtou\DIR}, \hbox{\utod\DIR}
2831
2832 \setbox2=\hbox{\tate}\ltjgetparameter{boxdir}{2}
2833 \end{LTXexample}
2834
2835 これらを用いれば,例えば
2836 \pTeX の \verb+\ifydir+, \verb+\iftbox200+ と同等の条件判断を
2837 \begin{verbatim}
2838 \ifnum\ltjgetparameter{direction}=4
2839 \ifnum\ltjgetparameter{boxdir}{200}=3
2840 \end{verbatim}
2841 のように行うことができる.
2842
2843 \subsection{プリミティブの再定義}
2844 異なる組方向に対応するために,以下に挙げるプリミティブは
2845 \LuaTeX-jaによる前処理もしくは後処理が行われるように
2846 \ \verb+\protected\def+ により再定義してある.
2847 \begin{cslist}
2848  \item[unhbox<num>\textrm{, }\textbackslash unvbox<num>]
2849  ボックスの組方向が現在のリストと異なる場合は事前にエラーメッセージを出力する.
2850  \pTeX と異なり,エラーを無視して無理矢理 \verb+\unhbox+, \verb+\unvbox+ を
2851  続行させることもできるが,その場合の組版結果は保証しない.
2852  \item[vadjust\{<material>\}] 一旦プリミティブ本来の挙動を行う.その後,<material>の組方向が
2853  周囲の垂直リストの組方向と一致しない場合にエラーを出力し,
2854  該当の \verb+\vadjust+ を無効にする.
2855  \item[lastbox] 異なる組方向のボックスを配置した場合に位置合わせ用に作られるノード類を
2856  除去し,正しく「中身」のボックスが返されるように前処理をする.
2857 \end{cslist}
2858
2859 %</ja>
2860
2861 %<en>\section{Font Metric and Japanese Font}
2862 %<ja>\section{フォントメトリックと和文フォント}
2863 %<en>\subsection{\texttt{\textbackslash jfont}}
2864 %<ja>\subsection{\texttt{\textbackslash jfont} 命令}
2865 \label{ssec-jfont}
2866
2867 %<*en>
2868 To load a font as a Japanese font (for horizontal direction), you must use the
2869 \verb+\jfont+ instead of~\verb+\font+, while
2870 \verb+\jfont+ admits the same syntax used in~\verb+\font+.
2871 \LuaTeX-ja automatically loads \Pkg{luaotfload} package,
2872 so TrueType/OpenType fonts with features can be used for Japanese fonts:
2873 %</en>
2874 %<*ja>
2875 フォントを(横組用)和文フォントとして読み込むためには,\verb+\jfont+ を
2876 \verb+\font+ プリミティブの代わりに用いる.
2877 \verb+\jfont+ の文法は \verb+\font+ と同じである.
2878 \LuaTeX-jaは\Pkg{luaotfload}パッケージを自動的に読み込むので,
2879 TrueType/OpenTypeフォントにfeatureを指定したものを和文フォントとして用いる
2880 ことができる:
2881 %</ja>
2882 \begin{LTXexample}[width=0.3\textwidth]
2883 \jfont\tradgt={file:KozMinPr6N-Regular.otf:script=latn;%
2884   +trad;-kern;jfm=ujis} at 14pt
2885 \tradgt 当/体/医/区
2886 \end{LTXexample}
2887
2888 %<*en>
2889 Note that the defined control sequence
2890 (\verb+\tradgt+ in the example above) using \verb+\jfont+ is not a
2891 \textit{font\_def} token,  but a macro.
2892 Hence the input like \verb+\fontname\tradgt+
2893 causes a error.  We denote control sequences which are defined in
2894 \verb+\jfont+ by <jfont\_cs>.
2895 %</en>
2896 %<*ja>
2897 なお,\verb+\jfont+ で定義された制御綴(上の例だと \verb+\tradgt+)
2898 は\textit{font\_def}トークンではなくマクロである.従って,\verb+\fontname\tradgt+ のような
2899 入力はエラーとなる.以下では \verb+\jfont+ で定義された
2900 制御綴を<jfont\_cs>で表す.
2901 %</ja>
2902
2903 \paragraph{JFM}
2904 %<*en>
2905 As noted in Introduction, a JFM has measurements of characters and
2906 glues/kerns that are automatically inserted for Japanese
2907 typesetting. The structure of JFM will be described in the next
2908 subsection. At the calling of \verb+\jfont+, you must specify
2909 which JFM will be used for this font by the following keys:
2910 %</en>
2911 %<*ja>
2912 「はじめに」の節で述べたように,JFMは文字と和文組版で自動的に挿入される
2913 グルー/カーンの寸法情報を持っている.JFMの構造は次の節で述べる.
2914 \verb+\jfont+ 命令の呼び出しの際には,どのJFMを用いるのかを以下のキーで
2915 指定する必要がある:
2916 %</ja>
2917
2918
2919 \begin{table}[t]
2920 %<en>\caption{Differences between JFMs shipped with \LuaTeX-ja}
2921 %<ja>\caption{\LuaTeX-ja に同梱されている JFM の違い}
2922 %<en>\medskip
2923 \label{tab-difjfm}
2924 \ltjsetparameter{jacharrange={+3}}
2925 \centering\small
2926 \def\r#1{{\jfont\g=file:KozMinPr6N-Regular.otf:jfm=#1 at 14.43324pt \g
2927 \setbox0=\vtop{\hsize=7\zw\noindent ◆◆◆◆◆◆◆
2928 ある日モモちゃんがお使いで迷子になって泣きました.}\copy0
2929 \vrule height 0pt depth \dp0}}
2930 \def\s#1{{\jfont\g=file:KozMinPr6N-Regular.otf:jfm=#1 at 14.43324pt \g
2931 \setbox0=\vtop{\hsize=7\zw\noindent ちょっと!何}\copy0}}
2932 \def\t#1{{\jfont\g=file:KozMinPr6N-Regular.otf:jfm=#1 at 19.24432pt \g
2933 \setbox0=\hbox{漢}%
2934 \vrule width 0.4pt height\ht0 depth\dp0\kern-.2pt\copy0
2935 \kern-\wd0\vrule width\wd0height .2pt depth .2pt
2936 \kern-\wd0\raise\ht0\hbox{\vrule width\wd0height .2pt depth .2pt}%
2937 \kern-\wd0\lower\dp0\hbox{\vrule width\wd0height .2pt depth .2pt}%
2938 \kern-.2pt\vrule width 0.4pt height\ht0 depth \dp0}}
2939 \begin{tabular}{rccc}
2940 \toprule
2941 &\tt jfm-ujis.lua&\tt jfm-jis.lua&\tt jfm-min.lua\\
2942 \midrule
2943 %<en>Example~1~\cite{min10}
2944 %<ja>例1~\cite{min10}
2945 &\r{ujis}&\r{jis}&\r{min}\\
2946 %<en>Example~2
2947 %<ja>例2
2948 &\s{ujis}&\s{jis}&\s{min}\\
2949 Bounding Box&\t{ujis}&\t{jis}&\t{min}\\
2950 \bottomrule
2951 \end{tabular}
2952 \ltjsetparameter{jacharrange={-3}}
2953 \end{table}
2954
2955
2956 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}\advance\leftmargin1\zw}
2957 \item[jfm=<name>]
2958 %<*en>
2959 Specify the name of (horizontal) JFM.
2960 If specified JFM has not been loaded, \LuaTeX-ja search and load
2961 a file named \texttt{jfm-<name>.lua}.
2962
2963 The following JFMs are shipped with \LuaTeX-ja:
2964 %</en>
2965 %<*ja>
2966 用いる(横組用)JFMの名前を指定する.もし以前に指定されたJFMが読み込まれていなければ,
2967 \texttt{jfm-<name>.lua}を読み込む.以下の横組用JFMが\LuaTeX-jaには同梱されている:
2968 %</ja>
2969 \begin{description}
2970 %<*en>
2971 \item[\tt jfm-ujis.lua] A standard JFM in \LuaTeX-ja. This JFM is
2972   based on \verb+upnmlminr-h.tfm+, a metric for UTF/OTF package that
2973   is used in \upTeX. When you use the \Pkg{luatexja-otf} package, you should use this JFM.
2974 %</en>
2975 %<*ja>
2976 \item[\tt jfm-ujis.lua] \LuaTeX-jaの標準JFMである.このJFMは\upTeX で
2977   用いられるUTF/OTFパッケージ用の和文用TFMである \verb+upnmlminr-h.tfm+ を
2978   元にしている.\Pkg{luatexja-otf}パッケージを使うときはこのJFMを指定するべきである.
2979 %</ja>
2980 %<*en>
2981 \item[\tt jfm-jis.lua] A counterpart for \verb+jis.tfm+, ``JIS font
2982   metric'' which is widely used in \pTeX. A major difference between
2983   \texttt{jfm-ujis.lua} and this \texttt{jfm-jis.lua} is that
2984   most characters under \texttt{jfm-ujis.lua} are square-shaped,
2985   while that under \texttt{jfm-jis.lua} are horizontal
2986   rectangles.
2987 %</en>
2988 %<*ja>
2989 \item[\tt jfm-jis.lua] \pTeX で広く用いられている「JISフォントメトリック」
2990   \verb+jis.tfm+ に相当するJFMである.\texttt{jfm-ujis.lua} とこの
2991   \texttt{jfm-jis.lua} の主な違いは,\texttt{jfm-ujis.lua} ではほとんどの文字が
2992   正方形状であるのに対し,\texttt{jfm-jis.lua} では横長の長方形状であることと,
2993   \texttt{jfm-ujis.lua} では「?」「!」の直後に半角空白が挿入されることである.
2994 %</ja>
2995 %<*en>
2996 \item[\tt jfm-min.lua] A counterpart for \verb+min10.tfm+, which is one
2997   of the default Japanese font metric shipped with \pTeX.
2998 %</en>
2999 %<*ja>
3000 \item[\tt jfm-min.lua] \pTeX に同梱されているデフォルトの和文用TFM
3001   である \verb+min10.tfm+ に相当する.
3002 %</ja>
3003 \end{description}
3004 %<*en>
3005 The difference among these three~JFMs is  shown in Table~\ref{tab-difjfm}.
3006 %</en>
3007 %<*ja>
3008 これら3つのJFMの違いは表\ref{tab-difjfm}に示した.
3009 %</ja>
3010
3011 \begin{figure}
3012 \begin{LTXexample}[width=0.3\textwidth]
3013 \ltjsetparameter{differentjfm=both}
3014 \jfont\F=file:KozMinPr6N-Regular.otf:jfm=ujis
3015 \jfont\G=file:KozGoPr6N-Medium.otf:jfm=ujis
3016 \jfont\H=file:KozGoPr6N-Medium.otf:jfm=ujis;jfmvar=hoge
3017 \F ){\G 【】}( % halfwidth space
3018    ){\H 『』}( % fullwidth space
3019
3020 ほげ,{\G 「ほげ」}(ほげ)\par
3021 ほげ,{\H 「ほげ」}(ほげ)% pTeX-like
3022
3023 \ltjsetparameter{differentjfm=paverage}
3024 \end{LTXexample}
3025 \caption{Example of \texttt{jfmvar} key}
3026 \label{fig:jfmvar}
3027 \end{figure}
3028
3029 %<*en>
3030 \item[jfmvar=<string>] Sometimes there is a need that \ldots.
3031 %</en>
3032 %<*ja>
3033 \item[jfmvar=<string>] 標準では,JFMとサイズが同じで,
3034   実フォントだけが異なる2つの和文フォントは「区別されない」.例えば
3035 図\ref{fig:jfmvar}において,最初の「)」と「【」の実フォントは異なるが,
3036 JFMもサイズも同じなので,普通に「)【」と入力した時と同じように半角空きとなる.
3037
3038 しかし,JFMとサイズが同じであっても,\texttt{jfmvar} キーの異なる
3039 2つの和文フォント,例えば図\ref{fig:jfmvar}で言う \verb+\F+ と \verb+\H+,
3040 は「区別される」.異なる和文フォントに異なる \texttt{jfmvar} キーを割り当て,
3041 かつ\Param{differentjfm}パラメータを \texttt{both} に設定すれば,
3042 \pTeX と似た状況で組版されることになる.
3043 %</ja>
3044 \end{list}
3045
3046 \begin{figure}
3047 \begin{LTXexample}[pos=t]
3048 \newcommand\test{\vrule ダイナミックダイクマ\vrule\\}
3049 \jfont\KMFW = KozMinPr6N-Regular:jfm=prop;-kern at 17pt
3050 \jfont\KMFK = KozMinPr6N-Regular:jfm=prop at 17pt % kern is activated
3051 \jfont\KMPW = KozMinPr6N-Regular:jfm=prop;script=dflt;+pwid;-kern at 17pt
3052 \jfont\KMPK = KozMinPr6N-Regular:jfm=prop;script=dflt;+pwid;+kern at 17pt
3053 \begin{multicols}{2}
3054 \ltjsetparameter{kanjiskip=0pt}
3055 {\KMFW\test \KMFK\test \KMPW\test \KMPK\test}
3056
3057 \ltjsetparameter{kanjiskip=3pt}
3058 {\KMFW\test \KMFK\test \KMPW\test \KMPK\test}
3059 \end{multicols}
3060 \end{LTXexample}
3061 \caption{Kerning information and \Param{kanjiskip}}
3062 \label{fig:kern-jfm}
3063 \end{figure}
3064
3065 %<en>\paragraph{Using kerning information in a font}
3066 %<ja>\paragraph{ペアカーニング情報の使用}
3067 \label{para-kern}
3068 %<*en>
3069 Some fonts have information for inter-glyph spacing.
3070 This version of \LuaTeX-ja treats kerning spaces like an italic correction;
3071 any glue and/or kern from the JFM and a kerning space can coexist.
3072 See Figure~\ref{fig:kern-jfm} for detail.
3073
3074 Note that in \verb+\setmainjfont+ etc.\ which are provided by \Pkg{luatexja-fontspec}
3075 package, kerning option is set \emph{off} (\texttt{Kerning=Off}) by default,
3076 because of the compatibility with previous versions of \LuaTeX-ja.
3077 %</en>
3078 %<*ja>
3079 いくつかのフォントはグリフ間のスペースについての情報を持っている.
3080 このカーニング情報は以前の\LuaTeX-ja とはあまり相性が良くなかったが,
3081 本バージョンではカーニングによる空白はイタリック補正と同様に扱うことになっている.
3082 つまり,カーニング由来の空白とJFM由来のグルー・カーンは同時に入りうる.
3083 図\ref{fig:kern-jfm}を参照.
3084 \begin{itemize}
3085  \item \emph{\texttt{\textbackslash jfont} や,
3086 NFSS2用の命令(\ref{ssec-chgfnt}節,\ref{ssec-nfsspat}節)における指定では
3087 カーニング情報は標準で使用する}ことになっているようである.
3088 言い換えれば,カーニング情報を使用しない設定にするには,面倒でも
3089 \begin{verbatim}
3090 \jfont\hoge=KozMinPr6N-Regular:jfm=ujis;-kern at 3.5mm
3091 \DeclareFontShape{JY3}{fuga}{m}{n} {<-> s*KozMinPr6N-Regular:jfm=ujis;-kern}{}
3092 \end{verbatim}
3093 のように,\texttt{-kern} という指定を自分で追加しなければいけない.
3094  \item
3095 一方,\emph{\Pkg{luatexja-fontspec} の提供する \texttt{\textbackslash setmainjfont}\
3096 などの命令の標準設定ではカーニング情報は使用しない}(\texttt{Kerning=Off})
3097 ことになっている.これは以前のバージョンの\LuaTeX-jaとの互換性のためである.
3098 \end{itemize}
3099 %</ja>
3100
3101 %<*ja>
3102 \paragraph{\texttt{extend}と\texttt{slant}}
3103 OpenType font featureと見かけ上同じような形式で指定できるものに,
3104 \begin{description}
3105 \item[\texttt{extend=}<extend>] 横方向に<extend>倍拡大する.
3106 \item[\texttt{slant=}<slant>] <slant>に指定された割合だけ傾ける.
3107 \end{description}
3108 の2つがある.
3109 \texttt{extend}や\texttt{slant}を指定した場合は,それに応じたJFMを指定すべきである%
3110 \footnote{\LuaTeX-jaでは,これらに対するJFMを特に提供することはしない予定である.}.
3111 例えば,次の例では無理やり通常のJFMを使っているために,文字間隔やイタリック補正量が
3112 正しくない:
3113 %</ja>
3114 %<*en>
3115 \paragraph{\texttt{extend} and \texttt{slant}}
3116 The following setting can be specified as OpenType font features:
3117 \begin{description}
3118 \item[\texttt{extend=}<extend>] expand the font horizontally by <extend>.
3119 \item[\texttt{slant=}<slant>] slant the font.
3120 \end{description}
3121 Note that \LuaTeX-ja doesn't adjust JFMs by these \texttt{extend} and \texttt{slant}
3122 settings; you have to write new JFMs on purpose.
3123 For example, the following example uses the standard JFM \texttt{jfm-ujis.lua}, hence
3124 letter-spacing and the width of italic correction are not correct:
3125 %</en>
3126 \begin{LTXexample}[width=0.3\textwidth]
3127 \jfont\E=file:KozMinPr6N-Regular.otf:extend=1.5;jfm=ujis;-kern
3128 \E あいうえお
3129
3130 \jfont\S=file:KozMinPr6N-Regular.otf:slant=1;jfm=ujis;-kern
3131 \S あいう\/ABC
3132 \end{LTXexample}
3133
3134 %<en>\subsection{\texttt{\textbackslash tfont}}
3135 %<ja>\subsection{\texttt{\textbackslash tfont} 命令}
3136
3137 %<*en>
3138 ...
3139 %</en>
3140 %<*ja>
3141 \verb+\tfont+ はフォントを縦組用の和文フォントとして読み込む命令であり,
3142 \verb+\jfont+ の文法は \verb+\jfont+ と同じである.
3143 \verb+\tfont+ で定義された縦組用和文フォントは,
3144 以下の点が \verb+\jfont+ による横組用和文フォントとは異なる:
3145 \begin{itemize}
3146  \item 出力時に,自動的に「\verb+vert+ feature相当」のグリフ置換が行われる.
3147        これは,\Pkg{luaotfload}による各種featureのサポートとは全く別個に行われるもので,
3148        いちいち \verb+vert+ featureを指定する必要はない.
3149 \begin{verbatim}
3150 \tfont\S=file:KozMinPr6N-Regular.otf:jfm=ujis % OK
3151 \end{verbatim}
3152  \item \ref{ssec-math}節で述べる,数式中の和文フォントには縦組用和文フォントは指定できない.
3153  \item \texttt{jfm=<name>}\ の部分には縦組用JFMを指定する.現在同梱されているのは,
3154 OTFパッケージの \verb+upnmlminr-v.tfm+ を元にした\texttt{jfm-ujisv.lua}\ のみである.
3155 \end{itemize}
3156 %</ja>
3157
3158 %<en>\subsection{Prefix \texttt{psft}}
3159 %<ja>\subsection{\texttt{psft}プリフィックス}
3160 \label{ssec-psft}
3161 %<*en>
3162 Besides ``\texttt{file:}''\ and ``\texttt{name:}''\ prefixes which
3163 are introduced in the \Pkg{luaotfload} package,
3164 \LuaTeX-ja adds ``\texttt{psft:}''\ prefix in \verb+\jfont+ (and~\verb+\font+),
3165 to specify a ``name-only'' Japanese font which
3166 will not be embedded to PDF. Typical use of this prefix is to specify
3167 standard, non-embedded Japanese fonts, namely, ``Ryumin-Light'' and
3168 ``GothicBBB-Medium''.
3169
3170 \emph{OpenType font features, such as ``{\tt +jp90}'',
3171 have no meaning in name-only fonts using ``{\tt psft:}''\ prefix,
3172 because we can't expect what fonts are actually used by the PDF reader.}
3173 Note that \texttt{extend}~and~\texttt{slant} settings (see~above) are supported
3174 with \texttt{psft} prefix, because they are only simple linear transformations.
3175 %</en>
3176 %<*ja>
3177 \Pkg{luaotfload}で使用可能になった
3178 \texttt{file:}\ と \texttt{name:}\ のプリフィックスに加えて,
3179 \verb+\jfont+(と \verb+\font+ プリミティブ)では
3180 \texttt{psft:}プリフィックスを用いることができる.
3181 このプリフィックスを用いることで,PDFには埋め込まれない「名前だけの」
3182 和文フォントを指定することができる.「標準的な」非埋め込み和文フォント,
3183 つまり「Ryumin-Light」「GothicBBB-Medium」の指定でこのプリフィックスが使われる.
3184
3185 \emph{\texttt{psft} プリフィックスの下では
3186 \texttt{+jp90} などのOpenType font featureの効力はない.
3187 非埋込フォントをPDFに使用すると,実際にどのようなフォントが
3188 表示に用いられるか予測できないからである.}\
3189 \texttt{extend} と \texttt{slant} 指定は単なる変形のため
3190 \texttt{psft} プリフィックスでも使用可能である.
3191 %</ja>
3192
3193 %<en>\paragraph{\texttt{cid} key}
3194 %<ja>\paragraph{\texttt{cid}キー}
3195 \label{para-cid}
3196
3197 %<*en>
3198 The default font defined by using \texttt{psft:} prefix is for Japanese typesetting;
3199 it is Adobe-Japan1-6 CID-keyed font.
3200 One can specify \texttt{cid} key to use other CID-keyed non-embedded fonts
3201 for Chinese or Korean typesetting.
3202 %</en>
3203 %<*ja>
3204 標準で\texttt{psft:}プリフィックスで定義されるフォントは日本語用のもので
3205 あり,Adobe-Japan1-6のCIDに対応したものとなる.しかし,\LuaTeX-jaは中国語
3206 の組版にも威力を発揮することが分かり,日本語フォントでない非埋込フォント
3207 の対応も必要となった.そのために追加されたのが\texttt{cid}キーである.
3208
3209 \texttt{cid}キーに値を指定すると,そのCIDを持った非埋込フォントを定義することができる:
3210 %</ja>
3211 \begin{lstlisting}[numbers=left]
3212 \jfont\testJ={psft:Ryumin-Light:cid=Adobe-Japan1-6;jfm=jis}     % Japanese
3213 \jfont\testD={psft:Ryumin-Light:jfm=jis}                        % default value is Adobe-Japan1-6
3214 \jfont\testC={psft:AdobeMingStd-Light:cid=Adobe-CNS1-6;jfm=jis} % Traditional Chinese
3215 \jfont\testG={psft:SimSun:cid=Adobe-GB1-5;jfm=jis}              % Simplified Chinese
3216 \jfont\testK={psft:Batang:cid=Adobe-Korea1-2;jfm=jis}           % Korean
3217 \end{lstlisting}
3218 %<*en>
3219 Note that the code above specifies \texttt{jfm-jis.lua}, which is for Japanese fonts,
3220 as JFM for Chinese and Korean fonts.
3221 %</en>
3222 %<*ja>
3223 上のコードでは中国語・韓国語用フォントに対してもJFMに
3224 日本語用の\texttt{jfm-jis.lua}を指定しているので注意されたい.
3225 %</ja>
3226
3227 %<*en>
3228 At present, \LuaTeX-ja supports only 4 values written in the sample code above.
3229 Specifying other values, e.g.,
3230 %</en>
3231 %<*ja>
3232 今のところ,\LuaTeX-jaは上のサンプルコード中に書いた4つの値しかサポートしていない.
3233 %</ja>
3234 \begin{lstlisting}
3235 \jfont\test={psft:Ryumin-Light:cid=Adobe-Japan2;jfm=jis}
3236 \end{lstlisting}
3237 %<*en>
3238 produces the following error:
3239 %</en>
3240 %<*ja>
3241 のようにそれら以外の値を指定すると,エラーが発生する:
3242 %</ja>
3243 \begin{lstlisting}[numbers=left]
3244 ! Package luatexja Error: bad cid key `Adobe-Japan2'.
3245
3246 See the luatexja package documentation for explanation.
3247 Type  H <return>  for immediate help.
3248 <to be read again>
3249                    \par
3250 l.78
3251
3252 ? h
3253 I couldn't find any non-embedded font information for the CID
3254 `Adobe-Japan2'. For now, I'll use `Adobe-Japan1-6'.
3255 Please contact the LuaTeX-ja project team.
3256 ?
3257 \end{lstlisting}
3258
3259 %<en>\subsection{Structure of a JFM File}
3260 %<ja>\subsection{JFMファイルの構造}
3261 \label{ssec-jfm-str}
3262 %<en>A JFM file is a Lua script which has only one function call:
3263 %<ja>JFMファイルはただ一つの関数呼び出しを含むLuaスクリプトである:
3264 \begin{verbatim}
3265 luatexja.jfont.define_jfm { ... }
3266 \end{verbatim}
3267 %<*en>
3268 Real data are stored in the table which indicated above by
3269 \verb+{ ... }+.  So, the rest of this subsection are devoted to describe the
3270 structure of this table.  Note that all lengths in a JFM file are
3271 floating-point numbers in design-size unit.
3272 %</en>
3273 %<*ja>
3274 実際のデータは上で \verb+{ ... }+ で示されたテーブルの中に格納されている.
3275 以下ではこのテーブルの構造について記す.
3276 なお,JFMファイル中の長さは全てdesign-sizeを単位とする浮動小数点数であることに
3277 注意する.
3278 %</ja>
3279
3280 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}\advance\leftmargin1\zw}
3281
3282 \item[dir=<direction>]
3283 %<en>(required)
3284 %<ja>(必須)
3285
3286 %<*en>
3287 The direction of JFM. \texttt{'yoko'}~(horizontal)
3288 or \texttt{'tate'}~(vertical) are supported.
3289 %</en>
3290 %<*ja>
3291 JFMの書字方向.\texttt{'yoko'}(横組)と \texttt{'tate'}(縦組)がサポートされる.
3292 %</ja>
3293
3294 \item[zw=<length>]
3295 %<en>(required)
3296 %<ja>(必須)
3297
3298 %<en>The amount of the length of the ``full-width''.
3299 %<ja>「全角幅」の長さ.
3300
3301 \item[zh=<length>]
3302 %<en>(required)
3303 %<ja>(必須)
3304
3305 %<en>The amount of the ``full-height'' (height + depth).
3306 %<ja>「全角高さ」(height + depth)の長さ.通常は全角幅と同じ長さになるだろう.
3307
3308 \item[kanjiskip=\{<natural>, <stretch>, <shrink>\}]
3309 %<en>(optional)
3310 %<ja>(任意)
3311
3312 %<*en>
3313 This field specifies the ``ideal'' amount of \Param{kanjiskip}. As noted
3314              in Subsection~\ref{subs-kskip}, if the parameter
3315              \Param{kanjiskip} is \verb+\maxdimen+, the value specified
3316              in this field is actually used (if this field is not specified in
3317              JFM, it is regarded as 0\,pt). Note that <stretch> and <shrink>
3318              fields are in design-size unit too.
3319 %</en>
3320 %<*ja>
3321 理想的な\Param{kanjiskip}の量を指定する.\ref{subs-kskip}節で述べたように,
3322 もし\Param{kanjiskip}が \verb+\maxdimen+ の値ならば,このフィールドで指定された
3323 値が実際には用いられる(指定なしは0\,ptとして扱われる).<stretch>と<shrink>のフィールドもdesign-size
3324 が単位であることに注意せよ.
3325 %</ja>
3326
3327 \item[xkanjiskip=\{<natural>, <stretch>, <shrink>\}]
3328 %<en>(optional)
3329 %<ja>(任意)
3330
3331 %<*en>
3332 Like the \texttt{kanjiskip} field, this field specifies the ``ideal''
3333              amount of \Param{xkanjiskip}.
3334 %</en>
3335 %<*ja>
3336 \texttt{kanjiskip}フィールドと同様に,\Param{xkanjiskip}の理想的な量を
3337 指定する.
3338 %</ja>
3339 \end{list}
3340
3341 %<*en>
3342 \paragraph{Character classes}
3343 Besides from above fields, a JFM file have several sub-tables those
3344 indices are natural numbers.  The table indexed by~$i\in\omega$ stores
3345 information of \emph{character class}~$i$. At least, the character class~0 is
3346 always present, so each JFM file must have a sub-table whose index is
3347 \texttt{[0]}.  Each sub-table (its numerical index is denoted by $i$) has
3348 the following fields:
3349 %</en>
3350 %<*ja>
3351 \paragraph{文字クラス}
3352 上記のフィールドに加えて,JFMファイルはそのインデックスが自然数であるいくつかの
3353 サブテーブルを持つ.インデックスが$i\in\omega$であるテーブルは\emph{文字クラス}$i$の
3354 情報を格納する.少なくとも,文字クラス0は常に存在するので,JFMファイルはインデックス
3355 が\texttt{[0]}のサブテーブルを持たなければならない.それぞれのサブテーブル
3356 (そのインデックスを$i$で表わす)は以下のフィールドを持つ:
3357 %</ja>
3358
3359 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}\advance\leftmargin1\zw}
3360 \item[chars=\{<character>, ...\}]
3361 %<en>(required except character class~0)
3362 %<ja>(文字クラス0を除いて必須)
3363
3364 %<*en>
3365 This field is a list of characters which are in this character
3366              type~$i$. This field is optional if $i=0$, since all
3367              \textbf{JAchar} which do not belong  any character classes other
3368              than 0 are in the character class 0
3369              (hence, the character class~0 contains most of
3370              \textbf{JAchar}s). In the list, character(s) can be specified in the following form:
3371 \begin{itemize}
3372 \item a Unicode code point
3373 \item the character itself (as a Lua string, like \hbox{\ltjsetparameter{autoxspacing=false}\verb+'あ'+})
3374 \item a string like \hbox{\ltjsetparameter{autoxspacing=false}\verb+'あ*'+} (the character followed by an asterisk)
3375 \item several ``imaginary'' characters (We will describe these later.)
3376 \end{itemize}
3377 %</en>
3378 %<*ja>
3379 このフィールドは文字クラス$i$に属する文字のリストである.このフィールドは$i=0$の
3380 場合には任意である(文字クラス0には,0以外の文字クラスに属するものを
3381 除いた全ての\textbf{JAchar}が属するから).このリスト中で文字を指定するには,以下の方法がある:
3382 \begin{itemize}
3383 \item Unicode におけるコード番号
3384 \item 「\hbox{\ltjsetparameter{autoxspacing=false}\verb+'あ'+}」のような,文字それ自体
3385 \item 「\hbox{\ltjsetparameter{autoxspacing=false}\verb+'あ*'+}」のような,文字それ自体の後にアスタリスクをつけたもの
3386 \item いくつかの「仮想的な文字」(後に説明する)
3387 \end{itemize}
3388 %</ja>
3389
3390 \item[width=<length>, height=<length>, depth=<length>, italic=<length>]
3391 %<en>(required)
3392 %<ja>(必須)
3393
3394 %<*en>
3395 Specify the width of characters in character class~$i$, the height, the depth and
3396 the amount of italic correction. All characters in character class~$i$ are regarded that its width, height, and depth are
3397 as values of these fields.
3398
3399 But there is one exception: \texttt{width} field can be \texttt{'prop'}.
3400 This means that width of a character becomes that of its ``real'' glyph.
3401 %</en>
3402 %<*ja>
3403 文字クラス$i$に属する文字の幅,高さ,深さ,イタリック補正の量を指定する.
3404 文字クラス$i$に属する全ての文字は,その幅,高さ,深さがこのフィールドで指定した
3405 値であるものとして扱われる.
3406
3407 例外として,\emph{\texttt{width} フィールドには数値以外に \texttt{'prop'} が指定可能である}.
3408 この場合,文字の幅はその「実際の」グリフの幅となる.OpenTypeの \texttt{prop} featureと併用
3409              すれば,これによってプロポーショナル組を行うことができる.
3410 %</ja>
3411
3412 \item[left=<length>, down=<length>, align=<align>]\
3413
3414 %<*en>
3415 These fields are for adjusting the position of the ``real'' glyph. Legal
3416              values of \texttt{align} field are \texttt{'left'},
3417              \texttt{'middle'}, and \texttt{'right'}. If one of these
3418              3~fields are omitted, \texttt{left} and \texttt{down} are
3419              treated as~0, and \texttt{align} field is treated as
3420              \texttt{'left'}.
3421 The effects of these 3~fields are indicated in Figure~\ref{fig-pos}.
3422 %</en>
3423 %<*ja>
3424 これらのフィールドは実際のグリフの位置を調整するためにある.
3425 \texttt{align} フィールドに指定できる値は \texttt{'left'}, \texttt{'middle'},
3426 \texttt{'right'} のいずれかである.もしこれら3つのフィールドのうちの1つが省かれた
3427 場合,\texttt{left} と \texttt{down} は0,\texttt{align} フィールドは
3428 \ \texttt{'left'} であるものとして扱われる.
3429 これら3つのフィールドの意味については図\ref{fig-pos}で説明する.
3430 %</ja>
3431
3432 %<*en>
3433 In most cases, \texttt{left} and \texttt{down} fields are~0, while
3434 it is not uncommon that the \texttt{align} field is \texttt{'middle'} or \texttt{'right'}.
3435 For example, setting the \texttt{align} field to \texttt{'right'} is practically needed
3436 when the current character class is the class for opening delimiters'.
3437 %</en>
3438 %<*ja>
3439 多くの場合,\texttt{left}と\texttt{down}は0である一方,
3440 \texttt{align}フィールドが\texttt{'middle'}や\texttt{'right'}であることは
3441 珍しいことではない.
3442 例えば,\texttt{align}フィールドを\texttt{'right'}に指定することは,
3443 文字クラスが開き括弧類であるときに実際必要である.
3444 %</ja>
3445
3446 \begin{figure}[!tb]
3447 \begin{minipage}{0.4\textwidth}%
3448 \begin{center}\unitlength=10pt\small
3449 \begin{picture}(15,12)(-1,-4)
3450 \color{black!10!white}% real glyph :step1
3451 \put(0,0){\vrule width 12\unitlength height 8\unitlength depth 3\unitlength}
3452
3453 \color{red!20!white}% real glyph :step1
3454 \put(-1,-1.5){\vrule width 6\unitlength height 7\unitlength depth 2.5\unitlength}
3455
3456 \color{red}% real glyph
3457 \thicklines
3458 \put(-1,-1.5){\vector(0,1){7}\vector(0,-1){2.5}\vector(1,0){6}}
3459 \put(5,-1.5){\line(0,1){7}\line(0,-1){2.5}}
3460 \put(-1,5.5){\line(1,0){6}}
3461 \put(-1,-4){\line(1,0){6}}
3462
3463 \color{green!20!white}% real glyph :step1
3464 \put(3,0){\vrule width 6\unitlength height 7\unitlength depth 2.5\unitlength}
3465
3466 \color{black}% real glyph :step1
3467 \thicklines
3468 \put(0,0){\vector(0,1){8}\line(0,-1){3}\vector(1,0){12}}
3469 \put(12,0){\line(0,1){8}\vector(0,-1){3}}
3470 \put(0,8){\line(1,0){12}}
3471 \put(0,-3){\line(1,0){12}}
3472 \put(0.2,4){\makebox(0,0)[l]{\texttt{height}}}
3473 \put(12.2,-1.5){\makebox(0,0)[l]{\texttt{depth}}}
3474 \put(6,0.2){\makebox(0,0)[b]{\texttt{width}}}
3475
3476 \color{green!50!black}% real glyph :step1
3477 \thicklines
3478 \put(3,0){\vector(0,1){7}\vector(0,-1){2.5}\vector(1,0){6}}
3479 \put(9,0){\line(0,1){7}\line(0,-1){2.5}}
3480 \put(3,7){\line(1,0){6}}
3481 \put(3,-2.5){\line(1,0){6}}
3482 \newsavebox{\eqdist}
3483 \savebox{\eqdist}(0,0)[b]{%
3484   \thinlines
3485   \put(-0.08,0.2){\line(0,-1){0.4}}%
3486   \put(0.08,0.2){\line(0,-1){0.4}}}
3487 \put(1.5,0){\usebox{\eqdist}}
3488 \put(10.5,0){\usebox{\eqdist}}
3489
3490 \color{blue}% shifted
3491 \thicklines
3492 \put(3,-1.5){\vector(-1,0){4}}
3493 \put(1,-1.7){\makebox(0,0)[t]{\texttt{left}}}
3494 \put(3,0){\vector(0,-1){1.5}}
3495 \put(3.2,-0.75){\makebox(0,0)[l]{\texttt{down}}}
3496 \end{picture}
3497 \end{center}
3498 \end{minipage}%
3499 \begin{minipage}{0.6\textwidth}%
3500 %<*en>
3501 Consider a node containing Japanese character whose value of the \texttt{align}
3502 field is \texttt{'middle'}.
3503 %</en>
3504 %<*ja>
3505 \texttt{align}フィールドの値が\texttt{'middle'}である和文文字を含むノードを
3506 考えよう.
3507 %</ja>
3508 \begin{itemize}
3509 \item
3510 %<*en>
3511 The black rectangle is a frame of the node.
3512 Its width, height, and depth are specified by JFM.
3513 %</en>
3514 %<*ja>
3515 黒色の長方形はノードの枠である.
3516 その幅,高さ,深さはJFMによって指定される.
3517 %</ja>
3518 \item
3519 %<*en>
3520 Since the \texttt{align} field is \texttt{'middle'},
3521 the ``real'' glyph is centered horizontally (the green rectangle).
3522 %</en>
3523 %<*ja>
3524 \texttt{align}フィールドは\texttt{middle}なので,実際のグリフは
3525 水平方向の中心に配置される(緑色の長方形).
3526 %</ja>
3527 \item
3528 %<*en>
3529 Furthermore, the glyph is shifted according to values of fields
3530       \texttt{left} and \texttt{down}. The ultimate position of the real
3531       glyph is indicated by the red rectangle.
3532 %</en>
3533 %<*ja>
3534 さらに,グリフは\texttt{left}と\texttt{down}の値に従ってシフトされる.
3535 最終的な実際のグリフの位置は赤色の長方形で示された位置になる.
3536 %</ja>
3537 \end{itemize}
3538 \end{minipage}
3539 \medskip
3540
3541 \caption{%
3542 %<en>The position of the real glyph
3543 %<ja>「実際の」グリフの位置
3544 }
3545 \label{fig-pos}
3546 \end{figure}
3547
3548 \item[kern={\{[$j$]=<kern>, [$j'$]=\{<kern>, [<ratio>]\}, ...\}}]
3549
3550 \item[glue={\{[$j$]=\{<width>, <stretch>, <shrink>, [<priority>], [<ratio>]\}, ...\}}]
3551 %<*ja>
3552 文字クラス$i$の文字と$j$の文字の間に挿入されるkernやglueの量を指定する.
3553
3554              <priority>は \Pkg{luatexja-adjust} による優先順位付き
3555              行長調整(\ref{ssec-adj}節)が有効なときのみ意味を持つ.
3556 このフィールドは省略可能であり,行調整処理におけるこのglueの優先
3557              度を$-2$から$+2$の間の整数で指定する.大きい値ほど「伸びやすく,縮みやすい」
3558              ことを意味する.省略時の値
3559              は0であり,範囲外の値が指定されたときの動作は未定義である.
3560
3561 <ratio>も省略可能フィールドであり,$-1$から$+1$の実数値をとる.省略時の値は0である.
3562 \begin{itemize}
3563 \item $-1$はこのグルーが「前の文字」由来であることを示す.
3564 \item $+1$はこのグルーが「後の文字」由来であることを示す.
3565 \item それ以外の値は,「前の文字」由来のグルーと「後の文字」由来の
3566 グルーが混合されていることを示す.
3567 \end{itemize}
3568 なお,このフィールドの値は\Param{differentjfm}の値が
3569 \texttt{pleft},~\texttt{pright},~\texttt{paverage}の値のときのみ実際に用いられる.
3570
3571 例えば,\cite{x4051}では,句点と中点の間には,
3572 句点由来の二分空きと中点由来の四分空きが挿入されるが,この場合には
3573 \begin{itemize}
3574 \item <width>には$0.5+0.25=0.75$を指定する.
3575 \item <ratio>には次の値を指定する.
3576 \[
3577  -1\cdot \frac{0.5}{0.5+0.25} + 1 \cdot \frac{0.25}{0.5+0.25} = -\frac13
3578 \]
3579 \end{itemize}
3580 %</ja>
3581 %<*en>
3582 \
3583
3584 Specifies the width of kern or glue which will be inserted
3585 between characters in character class~$i$ and those in character class~$j$.
3586
3587 <priority> is an integer in $[-2,2]$ (treated as 0 if omitted), and this is
3588 used only in line adjustment with priority by \Pkg{luatexja-adjust}
3589 (see Subsection~\ref{ssec-adj}). Higher value means the glue is easy to shretch,
3590 and is also easy to shrink.
3591
3592 <ratio> is also an optional value between $-1$ and 1. For example,
3593 The width of a glue between an ideographic full stop ``。''
3594 and a fullwidth middle dot ``・'' is three-fourth of fullwidth,
3595 namely halfwidth from the ideographic full stop, and
3596 quarter-width from the fullwidth middle dot.  In this case,
3597 we specify <ratio> to
3598 \[
3599   -1\cdot \frac{0.5}{0.5+0.25} + 1 \cdot \frac{0.25}{0.5+0.25} = -\frac13.
3600 \]
3601 %</en>
3602
3603
3604 \item[end\_stretch=<kern>]
3605 \item[end\_shrink=<kern>]
3606 %<*ja>
3607 これらのフィールドは省略可能である.
3608 優先順位付き行長調整が有効であり,かつ現在の文字クラスの文字が行
3609              末に来た時に,行長を詰める調整・伸ばす調整のた
3610              めにこの文字と行末の間に挿入可能なカーンの大きさを指定する.
3611 %</ja>
3612
3613 \end{list}
3614
3615 %<*ja>
3616 \paragraph{文字クラスの決定}
3617 文字からその文字の属する文字クラスを算出する過程は少々複雑である.
3618 次の内容を一部に含んだ \texttt{jfm-test.lua} を用いて説明する.
3619 %</ja>
3620 %<*en>
3621 \paragraph{Character to character classes}
3622 We explain how the character class of a character is determined,
3623 using  \texttt{jfm-test.lua} which contains the following:
3624 %</en>
3625 \begin{lstlisting}
3626    [0] = {
3627       chars = { '漢', 'ヒ*' },
3628       align = 'left', left = 0.0, down = 0.0,
3629       width = 1.0, height = 0.88, depth = 0.12, italic=0.0,
3630    },
3631    [2000] = {
3632       chars = { '。', '、*', 'ヒ' },
3633       align = 'left', left = 0.0, down = 0.0,
3634       width = 0.5, height = 0.88, depth = 0.12, italic=0.0,
3635    },
3636 \end{lstlisting}
3637 %<ja>句点「。」の幅は二分であるので
3638 %<en>Now consider the following input/output:
3639 \begin{LTXexample}[width=0.3\textwidth]
3640 \jfont\a=file:KozMinPr6N-Regular.otf:jfm=test;+vert
3641 \setbox0\hbox{\a 。\inhibitglue 漢}
3642 \the\wd0
3643 \end{LTXexample}
3644 %<*en>
3645 Now we look why the above source outputs 20\,pt, not 15\,pt.
3646 \begin{enumerate}
3647 \item The ideographic full stop ``。'' is converted to its vertical form ``\char"FE12''~(\texttt{U+FE12}), %"
3648 by \verb+vert+ feature.
3649 \item The character class of ``\char"FE12'' is zero, hence its width is fullwidth.%"
3650 \item The character class of ``漢'', hence its width is fullwidth.
3651 \item \verb+\inhibitglue+ makes that no glue will be inserted between ``。'' and ``漢''.
3652 \item Hence the width of \verb+\hbox+ equals to 20\,pt.
3653 \end{enumerate}
3654 This example shows that the character class of a character is determined \emph{after
3655 applying font features by \Pkg{luaotfload}}.
3656 %</en>
3657 %<*ja>
3658 では,全角二分(15.0\,pt)となるのが自然……と思うかもしれないが,上の実行結果では20\,ptとなっている.
3659 それは以下の事情によるものである:
3660 \begin{enumerate}
3661 \item \verb+vert+ featureによって句点(\texttt{U+3002})が縦組用のグリフと置き換わる(\Pkg{luaotfload} による処理).
3662 \item この縦組用句点のグリフは \texttt{U+FE12} であるため,その文字クラスは0となる.
3663 \item 以上により文字クラス0とみなされるため,結果として「。」の幅は全角だと認識されてしまう.
3664 \end{enumerate}
3665 この例は,\emph{文字クラスの決定はfont featureの適用によるグリフ置換の後に行われる}ことを
3666 示している.
3667 %</ja>
3668
3669 %<*en>
3670 However, a starred specification like ``\texttt{'、*'}'' changes the rule.
3671 Consider the following input:
3672 %</en>
3673 %<*ja>
3674 但し,「\texttt{'、*'}」のようにアスタリスクつきの指定があると,
3675 状況は異なる.
3676 %</ja>
3677 \begin{LTXexample}[width=0.3\textwidth]
3678 \jfont\a=file:KozMinPr6N-Regular.otf:jfm=test;+vert
3679 \a 漢、\inhibitglue 漢
3680 \end{LTXexample}
3681 %<*en>
3682 Here, the character class of the ideographic comma ``、''~(\texttt{U+3001}) is determined
3683 as following:
3684 \begin{enumerate}
3685 \item As the case of ``。'', the ideographic comma ``、'' is converted to its vertical
3686       form ``\char"FE11''~(\texttt{U+FE11}).%"
3687 \item The character class of ``\char"FE11'' is zero.
3688 \item However, \LuaTeX-ja remembers that this ``\char"FE11'' is obtained from ``、'' by
3689       font features. The character class of ``、'' is \emph{non-zero value}, namely, 2000.
3690 \item Hence the ideographic comma ``、'' in above belongs the character class~2000.
3691 \end{enumerate}
3692 %</en>
3693 %<*ja>
3694 ここで,読点「、」(\texttt{U+3001})の文字クラスは,以下のようにして決まる.
3695 \begin{enumerate}
3696 \item とりあえず句点の時と同じように,\Pkg{luaotfload} によって縦組用読点のグリフに置き換わる.
3697 \item 置換後のグリフは \texttt{U+FE11} であり,そのままでは文字クラスは0と判定される.
3698 \item ところが,JFMには「\texttt{'、*'}」指定があるので,置換前の横組用読点のグリフによって文字クラスを判定する.
3699 \item 結果として,上の出力例中の読点の文字クラスは2000となる.
3700 \end{enumerate}
3701 %</ja>
3702
3703 %<*ja>
3704 なお,「\texttt{'\hbox{}ヒ*'}」のようにアスタリスクつきの指定があっても,
3705 置換後のグリフで判定した文字クラスの値が0でなければ,そちらをそのまま作用する.
3706 \begin{LTXexample}[width=0.3\textwidth]
3707 \jfont\a=file:KozMinPr6N-Regular.otf:jfm=test;+hwid
3708 \a 漢ヒひ
3709 \end{LTXexample}
3710 上の例では,
3711 \texttt{hwid} featureにより,「ヒ」が半角の「ヒ」に置き換わるが,
3712 文字クラスは「ヒ」の属する0\emph{ではなく},「ヒ」の属する2000となる.
3713 %</ja>
3714
3715 %<ja>\paragraph{仮想的な文字}
3716 %<en>\paragraph{Imaginary characters}
3717 %<*en>
3718 As described before, you can specify several \emph{imaginary characters} in
3719 \texttt{chars} field. The most of these characters are regarded as the
3720 characters of class 0 in \pTeX.
3721 As a result, \LuaTeX-ja can control typesetting finer than \pTeX.
3722 The following is the list of imaginary characters:
3723 %</en>
3724 %<*ja>
3725 上で説明した通り,\texttt{chars}フィールド中にはいくつかの「特殊文字」も
3726 指定可能である.これらは,大半が\pTeX のJFMグルーの挿入処理ではみな「文字
3727 クラス0の文字」として扱われていた文字であり,その結果として\pTeX より細か
3728 い組版調整ができるようになっている.以下でその一覧を述べる:
3729 %</ja>
3730
3731 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}\advance\leftmargin1\zw}
3732 %%\item['diffmet']
3733 %%<en>Used at a boundary between two \textbf{JAchar}s whose JFM or size is different.
3734 %%<ja>JFMやサイズが異なる2つの\textbf{JAchar}の間の境界として用いられる.
3735
3736 \item['boxbdd']
3737 %<en>The beginning/ending of a hbox, and the beginning of a noindented (i.e., began by \verb+\noindent+) paragraph.
3738 %<ja>hboxの先頭と末尾,及びインデントされていない(\verb+\noindent+ で開始された)段落の先頭を表す.
3739
3740 \item['parbdd']
3741 %<en>The beginning of an (indented) paragraph.
3742 %<ja>通常の(\verb+\noindent+ で開始されていない)段落の先頭.
3743
3744 \item['jcharbdd']
3745 %<en>A boundary between \textbf{JAchar} and anything else (such as \textbf{ALchar}, kern, glue,\,\ldots).
3746 %<ja>和文文字と「その他のもの」(欧文文字,glue,kern等)との境界.
3747
3748 \item[$-1$]
3749 %<en>The left/right boundary of an inline math formula.
3750 %<ja>行中数式と地の文との境界.
3751 \end{list}
3752
3753 %<en>\paragraph{Porting JFM from \pTeX}
3754 %<ja>\paragraph{\pTeX 用和文用TFMの移植}
3755
3756 % ToDo: English version.
3757
3758 %<*en>
3759 See Japanese version of this manual.
3760 %</en>
3761
3762 %<*ja>
3763 以下に,\pTeX 用に作られた和文用TFMを\LuaTeX-ja用に移植する場合の注意点を挙げておく.
3764 \begin{itemize}
3765 \item 実際に出力される和文フォントのサイズがdesign sizeとなる.
3766 このため,例えば$1\,\textrm{zw}$がdesign sizeの0.962216倍であるJISフォン
3767       トメトリック等を移植する場合は,次のようにするべきである:
3768 \begin{itemize}
3769 \item JFM中の全ての数値を$1/0.962216$倍しておく.
3770 \item \TeX ソース中で使用するところで,サイズ指定を0.962216倍にする.
3771       \LaTeX でのフォント宣言なら,例えば次のように:
3772 \begin{verbatim}
3773 \DeclareFontShape{JY3}{mc}{m}{n}{<-> s*[0.962216] psft:Ryumin-Light:jfm=jis}{}
3774 \end{verbatim}
3775 \end{itemize}
3776 \item 上に述べた特殊文字は,\texttt{'boxbdd'}を除き文字クラスを全部0とする
3777       (JFM中に単に書かなければよい).
3778 \item \texttt{'boxbdd'}については,それのみで一つの文字クラスを形成し,その
3779       文字クラスに関してはグルー/カーンの設定はしない.
3780
3781 これは,\pTeX では,
3782       hboxの先頭・末尾とインデントされていない(\verb+\noindent+ で開始さ
3783       れた)段落の先頭にはJFMグルーは入らないという仕様を実現させるためである.
3784 \item \pTeX の組版を再現させようというのが目的であれば以上の注意を守れば十分である.
3785
3786 ところで,\pTeX では通常の段落の先頭にJFMグルーが残るという仕様があるので,
3787       段落先頭の開き括弧は全角二分下がりになる.全角下がりを実現させるに
3788       は,段落の最初に手動で \verb+\inhibitglue+ を追加するか,あるいは
3789       \ \verb+\everypar+ のハックを行い,それを自動化させるしかなかった.
3790
3791 一方,\LuaTeX-jaでは,\texttt{'parbdd'}によって,それがJFM側で調整できるよ
3792 うになった.例えば,\LuaTeX-ja同梱のJFMのように,\texttt{'boxbdd'}と同じ文字クラスに
3793 \texttt{'parbdd'}を入れれば全角下がりとなる.
3794
3795 \begin{LTXexample}[width=0.4\textwidth]
3796 \jfont\g=KozMinPr6N-Regular:jfm=test \g
3797 \parindent1\zw\noindent{}◆◆◆◆◆
3798 \par 「◆◆←二分下がり
3799 \par 【◆◆←全角下がり
3800 \par 〔◆◆←全角二分下がり
3801 \end{LTXexample}
3802 \end{itemize}
3803
3804 但し,\verb+\everypar+ を利用している場合にはこの仕組みは正しく動かない.
3805 そのような例としては箇条書き中の \verb+\item+ で始まる段落があり,\Pkg{ltjsclasses}では
3806 人工的に「\texttt{'parbdd'}の意味を持つ」whatsitノードを作ることによって対処している%
3807 \footnote{\texttt{ltjsclasses.dtx} を参照されたい.
3808 JFM側で一部の対処ができることにより,\Pkg{jsclasses}のようにif文の判定はしていない.}.
3809 %</ja>
3810
3811
3812 %<en>\subsection{Math Font Family}
3813 %<ja>\subsection{数式フォントファミリ}
3814 \label{ssec-math}
3815
3816 %<*en>
3817 \TeX\ handles fonts in math formulas by 16~font families\footnote{Omega,
3818 Aleph, \LuaTeX~and $\varepsilon$-\kern-.125em(u)\pTeX\ can handles 256~families, but
3819 an external package is needed to support this in plain \TeX\ and
3820 \LaTeX.}, and each family has three fonts:
3821 \verb+\textfont+, \verb+\scriptfont+ and \verb+\scriptscriptfont+.
3822 %</en>
3823 %<*ja>
3824 \TeX\ は数式フォントを16のファミリ\footnote{Omega, Aleph, \LuaTeX,そして
3825   $\varepsilon$-\kern-.125em(u)\pTeX\ では256の数式ファミリを扱うことができるが,
3826   これをサポートするためにplain \TeX と\LaTeX では外部パッケージを読み込む必要が
3827   ある.}で管理し,それぞれのファミリは3つのフォントを持っている:
3828 \verb+\textfont+, \verb+\scriptfont+ そして \verb+\scriptscriptfont+ である.
3829 %</ja>
3830
3831 %<*en>
3832 \LuaTeX-ja's handling of Japanese fonts in math formulas is similar;
3833 Table~\ref{tab-math} shows counterparts to \TeX's primitives for math
3834 font families. There is no relation between the value of
3835 \verb+\fam+ and that of \verb+\jfam+; with appropriate settings,
3836 you can set both \verb+\fam+ and \verb+\jfam+ to the same value.
3837 %</en>
3838 %<*ja>
3839 \LuaTeX-jaの数式中での和文フォントの扱いも同様である.
3840 表\ref{tab-math}は数式フォントファミリに対する \TeX のプリミティブと対応する
3841 ものを示している.\verb+\fam+ と \verb+\jfam+ の値の間には関係はなく,
3842 適切な設定の下では \verb+\fam+ と \verb+\jfam+ の両方に同じ値を設定することができる.
3843 %</ja>
3844
3845 \begin{table}[!tb]
3846 %<en>\caption{Commands for Japanese math fonts}
3847 %<ja>\caption{和文数式フォントに対する命令}
3848 \label{tab-math}
3849 %<en>\medskip
3850 \centering
3851 \def\{{\char`\{}\def\}{\char`\}}\small
3852 \begin{tabular}{ll}
3853 \toprule
3854 %<en>\bf Japanese fonts&\bf alphabetic fonts\\
3855 %<ja>\bf 和文フォント&\bf 欧文フォント\\
3856 \midrule
3857 \verb+\jfam+${}\in [0,256)$&\verb+\fam+\\
3858 \tt\Param{jatextfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\verb+\textfont+<fam>=<font\_cs>\\
3859 \tt\Param{jascriptfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\verb+\scriptfont+<fam>=<font\_cs>\\
3860 \tt\Param{jascriptscriptfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\verb+\scriptscriptfont+<fam>=<font\_cs>\\
3861 \bottomrule
3862 \end{tabular}
3863 \end{table}
3864
3865 %<en>\subsection{Callbacks}
3866 %<ja>\subsection{コールバック}
3867
3868 %<*en>
3869 \LuaTeX-ja also has several callbacks. These callbacks can
3870 be accessed via \verb+luatexbase.add_to_callback+ function and so on, as other callbacks.
3871 %</en>
3872 %<*ja>
3873 \LuaTeX 自体のものに加えて,\LuaTeX-jaもコールバックを持っている.
3874 これらのコールバックには,他のコールバックと同様に \verb+luatexbase.add_to_callback+
3875 関数などを用いることでアクセスすることができる.
3876 %</ja>
3877 \begin{list}{}%
3878 {\def\makelabel#1{\bfseries#1}}
3879 %<en>\item[\texttt{luatexja.load\_jfm} callback]
3880 %<ja>\item[\texttt{luatexja.load\_jfm}コールバック]
3881 %<*en>
3882 With this callback you can overwrite JFMs.
3883 This callback is called when a new JFM is loaded.
3884 %</en>
3885 %<*ja>
3886 このコールバックを用いることでJFMを上書きすることができる.
3887 このコールバックは新しいJFMが読み込まれるときに呼び出される.
3888 %</ja>
3889
3890 \begin{lstlisting}[numbers=left]
3891 function (<table> jfm_info, <string> jfm_name)
3892   return <table> new_jfm_info
3893 end
3894 \end{lstlisting}
3895
3896 %<*en>
3897 The argument \verb+jfm_info+ contains a table similar to the table in a JFM file, except
3898 this argument has \texttt{chars} field which contains character codes
3899              whose character class is not~0.
3900 %</en>
3901 %<*ja>
3902 引数 \verb+jfm_info+ はJFMファイルのテーブルと似たものが格納されるが,
3903 クラス0を除いた文字のコードを含んだ\texttt{chars}フィールドを持つ点が異なる.
3904 %</ja>
3905
3906 %<*en>
3907 An example of this callback is the \texttt{ltjarticle} class, with
3908              forcefully assigning character class~0 to \texttt{'parbdd'}
3909              in the JFM \texttt{jfm-min.lua}.
3910 %</en>
3911 %<*ja>
3912 このコールバックの使用例は\texttt{ltjarticle}クラスにあり,
3913 \texttt{jfm-min.lua}中の\texttt{'parbdd'}を強制的にクラス0に割り当てている.
3914 %</ja>
3915
3916 %<en>\item[\texttt{luatexja.define\_jfont} callback]
3917 %<ja>\item[\texttt{luatexja.define\_jfont}コールバック]
3918 %<*en>
3919 This callback and the next callback form a pair, and you can assign characters
3920  which do not have fixed code points in Unicode to non-zero character classes.
3921 This \texttt{luatexja.define\_font} callback is called just when new Japanese font is loaded.
3922 %</en>
3923 %<*ja>
3924 このコールバックと次のコールバックは組をなしており,Unicode中に固定された文字コード
3925 番号を持たない文字を非零の文字クラスに割り当てることができる.
3926 このコールバックは新しい和文フォントが読み込まれたときに呼び出される.
3927 %</ja>
3928
3929 \begin{lstlisting}[numbers=left]
3930 function (<table> jfont_info, <number> font_number)
3931   return <table> new_jfont_info
3932 end
3933 \end{lstlisting}
3934 %<*en>
3935 \verb+jfont_info+ has the following fields,
3936 \emph{which may not overwritten by a user}:
3937 \begin{description}
3938 \item[\texttt{size}]
3939 The font size specified at \verb+\jfont+ in scaled points ($1\,\mathrm{sp}=2^{-16}\,\mathrm{pt}$).
3940 \item[\texttt{zw}, \texttt{zh}, \texttt{kanjiskip}, \texttt{xkanjiskip}]
3941 These are scaled value of those specified by the JFM, by the font size.
3942 \item[\texttt{jfm}]
3943 The internal number of the JFM.
3944 \item[\texttt{var}]
3945 The value of \texttt{jfmvar}~key, which is specified at \verb+\jfont+.
3946 The default value is the empty string.
3947 \item[\texttt{chars}]
3948 The mapping table from character codes to its character classes.\\
3949 The specification \texttt{[i].chars=\{<character>, ...\}} in the JFM will be  stored in this
3950            field as \texttt{chars=\{[<character>]=\,$i$, ...\}}.
3951 \item[\texttt{char\_type}]
3952 For $i\in\omega$, \texttt{char\_type[$i$]} is information of characters whose class is
3953            $i$, and has the following fields:
3954 \begin{itemize}
3955  \item \texttt{width},~\texttt{height}, \texttt{depth},
3956   \texttt{italic}, \texttt{down},~\texttt{left}\ are just
3957        scaled value of those specified by the JFM, by the font size.
3958  \item \texttt{align} is a number which is determined from \texttt{align}~field in the JFM:
3959 \[
3960  \begin{cases}
3961   0&\text{\texttt{'left'} and the default value}\\0.5&\text{\tt 'middle'}\\1&\text{\tt 'right'}
3962  \end{cases}
3963 \]
3964 \item For $j\in \omega$, \texttt{[$j$]} stores a kern or a glue which will be inserted
3965 between character class~$i$ and class~$j$.
3966
3967 If a kern will be inserted, the value of this field is \texttt{[$j$]=\{false, <kern\_node>, <ratio>\}},
3968 where <kern\_node> is a node\footnote{%
3969  This version of \LuaTeX-ja uses ``direct access
3970       model'' for accessing nodes, if possible. }.
3971 If a glue will be inserted, we have \texttt{[$j$]=\{false, <spec\_node>, <ratio>, <icflag>\}},
3972 where <spec\_node> is also a node, and $\text{<icflag>}=\textit{from\_jfm}+\text{<priority>}$.
3973 \end{itemize}
3974 \end{description}
3975 %</en>
3976 %<*ja>
3977 \verb+jfont_info+ は最低限以下のフィールドを持つが,これらを書き換えてはならない:
3978 \begin{description}
3979 \item[\texttt{size}]
3980 実際に使われるフォントサイズ(sp単位).$1\,\mathrm{sp}=2^{-16}\,\mathrm{pt}$.
3981 \item[\texttt{zw}, \texttt{zh}, \texttt{kanjiskip}, \texttt{xkanjiskip}]
3982 JFMファイルで指定されているそれぞれの値をフォントサイズに合わせてスケーリングしたものを
3983 sp単位で格納している.
3984 \item[\texttt{jfm}]
3985 利用されているJFMを識別するための番号.
3986 \item[\texttt{var}]
3987 \verb+\jfont+で指定された \texttt{jfmvar} キーの値(未指定のときは空文字列).
3988 \item[\texttt{chars}]
3989 文字コードから文字クラスへの対応が記述されたテーブル.\\
3990 JFM内の \texttt{[i].chars=\{<character>, ...\}} という指定は\
3991 \texttt{chars=\{[<character>]=\,$i$, ...\}} という形式に変換されている.
3992 \item[\texttt{char\_type}]
3993 $i\in\omega$に対して,\texttt{char\_type[$i$]} は文字クラス$i$の文字の寸法を格納しており,
3994 以下のフィールドを持つ.
3995 \begin{itemize}
3996  \item \texttt{width},~\texttt{height}, \texttt{depth},
3997   \texttt{italic}, \texttt{down},~\texttt{left}\ は
3998 JFMで指定されているそれぞれの値をスケーリングしたものである.
3999  \item \texttt{align} はJFMで指定されている値によって,
4000 \[
4001  \begin{cases}
4002   0&\text{\texttt{'left'}や省略時}\\0.5&\text{\tt 'middle'}\\1&\text{\tt 'right'}
4003  \end{cases}
4004 \]
4005 のいずれかの値をとる.
4006 \item $j\in \omega$に対して,\texttt{[$j$]} は文字クラス$i$の文字と$j$の文字の間に挿入されるkern
4007       やglueを格納している.
4008 間に入るものがkernであれば,このフィールドの値は\
4009 \texttt{[$j$]=\{false, <kern\_node>, <ratio>\}} である.
4010 <kern\_node>はkernを表すノードそのものである\footnote{%
4011 本バージョンでは利用可能ならばノードのアクセス手法にdirect access
4012       modelを用いている.そのため,例えば\LuaTeX\ beta-0.78.2では,単なる自然数のようにし
4013       か見えないことに注意.
4014 }.
4015 glueであれば,\texttt{[$j$]=\{false, <spec\_node>, <ratio>, <icflag>\}} である.
4016 <spec\_node>はglueの長さを表すノードそのものであり,
4017       $\text{<icflag>}=\textit{from\_jfm}+\text{<priority>}$である.
4018 \end{itemize}
4019 \end{description}
4020 %</ja>
4021
4022 %<*en>
4023 The returned table \verb+new_jfont_info+ also should include these fields, but
4024 you are free to add more fields (to use them in the \texttt{luatexja.find\_char\_class} callback).
4025 The \verb+font_number+ is a font number.
4026 %</en>
4027 %<*ja>
4028 戻り値の \verb+new_jfont_info+ テーブルも上に述べたフィールドをそのまま含まなければならないが,
4029 それ以外にユーザが勝手にフィールドを付け加えることは自由である.
4030 \verb+font_number+ はフォント番号である.
4031 %</ja>
4032
4033 %<*en>
4034 A good example of this and the next callbacks is the \Pkg{luatexja-otf}
4035              package, supporting \verb+"AJ1-xxx"+ form for Adobe-Japan1
4036              CID characters in a JFM. This callback doesn't replace any
4037              code of \LuaTeX-ja.
4038 %</en>
4039 %<*ja>
4040 これと次のコールバックの良い使用例は\Pkg{luatexja-otf}パッケージであり,
4041 JFM中でAdobe-Japan1 CIDの文字を \verb+"AJ1-xxx"+ の形で指定するために
4042 用いられている.
4043 %</ja>
4044
4045 %<en>\item[\texttt{luatexja.find\_char\_class} callback]
4046 %<ja>\item[\texttt{luatexja.find\_char\_class}コールバック]
4047 %<*en>
4048 This callback is called just when \LuaTeX-ja is trying to determine which
4049              character class a character \verb+chr_code+ belongs.
4050 A function used in this callback should be in the following form:
4051 %</en>
4052 %<*ja>
4053 このコールバックは\LuaTeX-jaが \verb+chr_code+ の文字がどの文字クラスに
4054 属するかを決定しようとする際に呼び出される.
4055 このコールバックで呼び出される関数は次の形をしていなければならない:
4056 %</ja>
4057 \begin{lstlisting}[numbers=left]
4058 function (<number> char_class, <table> jfont_info, <number> chr_code)
4059   if char_class~=0 then return char_class
4060   else
4061     ....
4062     return (<number> new_char_class or 0)
4063   end
4064 end
4065 \end{lstlisting}
4066
4067 %<*en>
4068 The argument \verb+char_class+ is the result of \LuaTeX-ja's default
4069              routine or previous function calls in this callback, hence
4070              this argument may not be 0. Moreover, the returned
4071              \verb+new_char_class+ should be as same as \verb+char_class+ when \verb+char_class+
4072              is not~0, otherwise you will overwrite the \LuaTeX-ja's
4073              default routine.
4074 %</en>
4075 %<*ja>
4076 引数 \verb+char_class+ は\LuaTeX-jaのデフォルトルーチンか,このコールバックの
4077 直前の関数呼び出しの結果を含んでおり,したがってこの値は0ではないかもしれない.
4078 さらに,戻り値の \verb+new_char_class+ は \verb+char_class+ が非零のときには
4079 \verb+char_class+ の値と同じであるべきで,そうでないときは\LuaTeX-jaの
4080 デフォルトルーチンを書き換えることになる.
4081 %</ja>
4082
4083 %<en>\item[\texttt{luatexja.set\_width} callback]
4084 %<ja>\item[\texttt{luatexja.set\_width}コールバック]
4085 %<*en>
4086 This callback is called when \LuaTeX-ja is trying to encapsule a
4087              \textbf{JAchar} \textit{glyph\_node}, to adjust its
4088              dimension and position.
4089 %</en>
4090 %<*ja>
4091 このコールバックは\LuaTeX-jaが\textbf{JAchar}の寸法と位置を調節するために
4092 その\textit{glyph\_node}をカプセル化しようとする際に呼び出される.
4093 %</ja>
4094 \begin{lstlisting}[numbers=left]
4095 function (<table> shift_info, <table> jfont_info, <number> char_class)
4096   return <table> new_shift_info
4097 end
4098 \end{lstlisting}
4099
4100 %<*en>
4101 The argument \verb+shift_info+ and the returned \verb+new_shift_info+ have
4102 \texttt{down} and \texttt{left} fields, which are the amount of shifting
4103              down/left the character in a scaled point.
4104 %</en>
4105 %<*ja>
4106 引数 \verb+shift_info+ と戻り値の \verb+new_shift_info+ は
4107 \texttt{down}と\texttt{left}のフィールドを持ち,これらの値は
4108 文字の下/左へのシフト量(sp単位)である.
4109 %</ja>
4110
4111 %<*en>
4112 A good example is \Pkg{test/valign.lua}.
4113 After loading this file, the vertical position of glyphs is automatically
4114 adjusted; the ratio $(\hbox{height}:\hbox{depth})$ of glyphs is adjusted
4115 to be that of letters in the character class~0. For example, suppose that
4116 \begin{itemize}
4117 \item The setting of the JFM: $(\hbox{height})=88x$, $(\hbox{depth})=12x$
4118   (the standard values of Japanese OpenType fonts);
4119 \item The value of the real font: $(\hbox{height})=28y$, $(\hbox{depth})=5y$
4120   (the standard values of Japanese TrueType fonts).
4121 \end{itemize}
4122 Then, the position of glyphs is shifted up by
4123 %</en>
4124 %<*ja>
4125 良い例が\Pkg{test/valign.lua}である.このファイルが読み込まれた状態では,
4126              JFM内で規定された文字クラス0の文字における$(\hbox{高
4127              さ}):(\hbox{深さ})$の比になるように,実際のフォントの出力上
4128              下位置が自動調整される.例えば,
4129 \begin{itemize}
4130 \item JFM側の設定:$(\hbox{高さ})=88x$, $(\hbox{深さ})=12x$%
4131 (和文OpenTypeフォントの標準値)
4132 \item 実フォント側の数値:$(\hbox{高さ})=28y$, $(\hbox{深さ})=5y$(和文TrueTypeフォントの標準値)
4133 \end{itemize}
4134 となっていたとする.すると,実際の文字の出力位置は,以下の量だけ上にぜらされることとなる:
4135 %</ja>
4136 \[
4137  \frac{88x}{88x+12x} (28y+5y) - 28y = \frac{26}{25}y= 1.04y.
4138 \]
4139 \end{list}
4140
4141
4142
4143 %<en>\section{Parameters}
4144 %<ja>\section{パラメータ}
4145 \subsection{\texttt{\textbackslash ltjsetparameter}}
4146 \label{ssec-param}
4147
4148 %<*en>
4149 As described before, \verb+\ltjsetparameter+ and \verb+\ltjgetparameter+ are
4150 commands for accessing most parameters of \LuaTeX-ja. One of the main
4151 reason that \LuaTeX-ja didn't adopted the syntax similar to that of \pTeX\
4152 (\textit{e.g.},~\verb+\prebreakpenalty`)=10000+)
4153 is the position of \verb+hpack_filter+ callback in the source
4154 of \LuaTeX, see Section~\ref{sec-para}.
4155 %</en>
4156 %<*ja>
4157 先に述べたように,\verb+\ltjsetparameter+ と \verb+\ltjgetparameter+ は
4158 \LuaTeX-jaのほとんどのパラメータにアクセスするための命令である.
4159 \LuaTeX-jaが\pTeX のような文法(例えば,\verb+\prebreakpenalty`)=10000+)を
4160 採用しない理由の一つは,\LuaTeX のソースにおける \verb+hpack_filter+
4161 コールバックの位置にある.\ref{sec-para}章を参照.
4162 %</ja>
4163
4164 %<*en>
4165 \verb+\ltjsetparameter+ and \verb+\ltjglobalsetparameter+ are commands
4166 for assigning parameters. These take one argument which is a
4167 \texttt{<key>=<value>} list.
4168 The list of allowed keys are described in the next subsection.
4169 The difference between
4170 \verb+\ltjsetparameter+ and \verb+\ltjglobalsetparameter+ is only the
4171 scope of assignment;
4172 \verb+\ltjsetparameter+ does a local assignment and
4173 \verb+\ltjglobalsetparameter+ does a global one.
4174 They also obey the value of \verb+\globaldefs+,
4175 like other assignment.
4176 %</en>
4177 %<*ja>
4178 \verb+\ltjsetparameter+ と \verb+\ltjglobalsetparameter+ はパラメータを
4179 指定するための命令である.これらは\texttt{<key>=<value>}のリストを
4180 引数としてとる.許されるキーの一覧は次の節にある.
4181 \verb+\ltjsetparameter+ と \verb+\ltjglobalsetparameter+ の違いはスコープの
4182 違いのみで,
4183 \verb+\ltjsetparameter+ はローカルな指定,\verb+\ltjglobalsetparameter+ は
4184 グローバルな指定を行う.
4185 これらは他のパラメータ指定と同様に \verb+\globaldefs+ の値に従う.
4186 %</ja>
4187
4188 %<*en>
4189 The following is the list of parameters which can be specified by the
4190 \verb+\ltjsetparameter+ command. [\verb+\cs+] indicates the counterpart
4191 in \pTeX, and symbols beside each parameter has the following meaning:
4192 %</en>
4193 %<*ja>
4194 以下は \verb+\ltjsetparameter+ に指定することができるパラメータの一覧である.
4195 [\verb+\cs+]は\pTeX における対応物を示す.
4196 また,それぞれのパラメータの右上にある記号には次の意味がある:
4197 %</ja>
4198 \begin{itemize}
4199 %<*en>
4200 \item ``\ast'' : values at the end of a paragraph or a hbox are
4201 adopted in the whole paragraph or the whole hbox.
4202 %</en>
4203 %<*ja>
4204 \item ``\ast'':段落やhboxの終端での値がその段落/hbox全体で用いられる.
4205 %</ja>
4206 %<*en>
4207 \item ``\dagger'': assignments are always global.
4208 %</en>
4209 %<*ja>
4210 \item ``\dagger'':指定は常にグローバルになる.
4211 %</ja>
4212 \end{itemize}
4213
4214 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}\advance\leftmargin1\zw}
4215 \item[\DParam{jcharwidowpenalty}\,=<penalty>$^\ast$] [\verb+\jcharwidowpenalty+]
4216 %<*en>
4217 Penalty value for suppressing orphans. This penalty is inserted just
4218              after the last \textbf{JAchar} which is not regarded as a
4219              (Japanese) punctuation mark.
4220 %</en>
4221 %<*ja>
4222 パラグラフの最後の字が孤立して改行されるのを防ぐためのペナルティの値.
4223 このペナルティは(日本語の)句読点として扱われない最後の\textbf{JAchar}の直後に
4224 挿入される.
4225 %</ja>
4226
4227 \item[\DParam{kcatcode}\,=\{<chr\_code>,<natural number>\}$^\ast$]\
4228 %<*en>
4229 An additional attributes which each character whose character code is <chr\_code> has.
4230 At the present version, the lowermost bit of <natural number> indicates
4231              whether the character is considered as a punctuation mark
4232              (see the description of \Param{jcharwidowpenalty} above).
4233 %</en>
4234 %<*ja>
4235 文字コードが<chr\_code>の文字が持つ付加的な属性値(attribute).
4236 現在のバージョンでは,<natural number>の最下位ビットが,その文字が句読点と
4237 みなされるかどうかを表している(上の\Param{jcharwidowpenalty}の記述を参照).
4238 %</ja>
4239
4240 \item[\DParam{prebreakpenalty}\,=\{<chr\_code>,<penalty>\}$^\ast$] [\verb+\prebreakpenalty+]\
4241 %<*ja>
4242 文字コード<chr\_code>の\textbf{JAchar}が行頭にくることを抑止するために,
4243              この文字の前に挿入/追加されるペナルティの量を指定する.
4244
4245 例えば閉じ括弧「〗」は絶対に行頭にきてはならないので,
4246 \begin{verbatim}
4247 \ltjsetparameter{prebreakpenalty={`〙,10000}}
4248 \end{verbatim}
4249 と,最大値の10000が標準で指定されている.他にも,小書きのカナなど,絶対禁止とい
4250              うわけではないができれば行頭にはきて欲しくない場合に,0と
4251              10000の間の値を指定するのも有用であろう.
4252 %</ja>
4253 %<*en>
4254 Set a penalty which is inserted automatically before the character <chr\_code>,
4255 to prevent a line starts from this character. For example, a line cannot started
4256 with one of closing brackets ``〗'', so \LuaTeX-ja sets
4257 \begin{verbatim}
4258 \ltjsetparameter{prebreakpenalty={`〙,10000}}
4259 \end{verbatim}
4260 by default.
4261 %</en>
4262
4263
4264 \item[\DParam{postbreakpenalty}\,=\{<chr\_code>,<penalty>\}$^\ast$] [\verb+\postbreakpenalty+]
4265 %<*ja>
4266 文字コード<chr\_code>の\textbf{JAchar}が行末にくることを抑止するために,
4267              この文字の後に挿入/追加されるペナルティの量を指定する.
4268
4269 \pTeX では,\verb+\prebreakpenalty+, \verb+\postbreakpenalty+において,
4270 \begin{itemize}
4271 \item 一つの文字に対して,pre, postどちらか一つしか指定することができなかっ
4272       た(後から指定した方で上書きされる).
4273 \item pre, post合わせて256文字分の情報を格納することしかできなかった.
4274 \end{itemize}
4275 という制限があったが,\LuaTeX-jaではこれらの制限は解消されている.
4276 %</ja>
4277 %<*en>
4278 Set a penalty which is inserted automatically after the character <chr\_code>,
4279 to prevent a line ends with this character.
4280 \pTeX\ has following restrictions on \verb+\prebreakpenalty+ and \verb+\postbreakpenalty+,
4281 but they don't exist in \LuaTeX-ja:
4282 \begin{itemize}
4283  \item Both \verb+\prebreakpenalty+ and \verb+\postbreakpenalty+ cannot be set
4284 for the same character.
4285  \item We can set \verb+\prebreakpenalty+ and \verb+\postbreakpenalty+  up to 256~characters.
4286 \end{itemize}
4287 %</en>
4288
4289 \item[\DParam{jatextfont}\,=\{<jfam>,<jfont\_cs>\}$^\ast$]
4290 %<en>[\verb+\textfont+ in \TeX]
4291 %<ja>[\TeX の \verb+\textfont+]
4292 \item[\DParam{jascriptfont}\,=\{<jfam>,<jfont\_cs>\}$^\ast$]
4293 %<en>[\verb+\scriptfont+ in \TeX]
4294 %<ja>[\TeX の \verb+\scriptfont+]
4295 \item[\DParam{jascriptscriptfont}\,=\{<jfam>,<jfont\_cs>\}$^\ast$]
4296 %<en>[\verb+\scriptscriptfont+ in \TeX]
4297 %<ja>[\TeX の \verb+\scriptscriptfont+]
4298 \item[\DParam{yjabaselineshift}\,=<dimen>]\
4299 \item[\DParam{yalbaselineshift}\,=<dimen>] [\verb+\ybaselineshift+]
4300 \item[\DParam{tjabaselineshift}\,=<dimen>]\
4301 \item[\DParam{talbaselineshift}\,=<dimen>] [\verb+\tbaselineshift+]
4302
4303 \item[\DParam{jaxspmode}\,=\{<chr\_code>,<mode>\}$^\ast$]
4304
4305 %<*en>
4306 Setting whether inserting \Param{xkanjiskip} is allowed before/after a \textbf{JAchar} whose character code is <chr\_code>.
4307 The followings are allowed for <mode>:
4308 %</en>
4309 %<*ja>
4310 文字コードが<chr\_code>の\textbf{JAchar}の前/後ろに\Param{xkanjiskip}の
4311 挿入を許すかどうかの設定.
4312 以下の<mode>が許される:
4313 %</ja>
4314 \begin{description}
4315 %<en>\item[0, \texttt{inhibit}] Insertion of \Param{xkanjiskip} is inhibited before the character, nor after the character.
4316 %<ja>\item[0, \texttt{inhibit}] \Param{xkanjiskip}の挿入は文字の前/後ろのいずれでも禁止される.
4317 %<en>\item[1, \texttt{preonly}] Insertion of \Param{xkanjiskip} is allowed before the character, but not after.
4318 %<ja>\item[1, \texttt{preonly}] \Param{xkanjiskip}の挿入は文字の前では許されるが,後ろでは許されない.
4319 %<en>\item[2, \texttt{postonly}] Insertion of \Param{xkanjiskip} is allowed after the character, but not before.
4320 %<ja>\item[2, \texttt{postonly}] \Param{xkanjiskip}の挿入は文字の後ろでは許されるが,前では許されない.
4321 %<en>\item[3, \texttt{allow}] Insertion of \Param{xkanjiskip} is allowed both before the character and after the character. This is the default value.
4322 %<ja>\item[3, \texttt{allow}] \Param{xkanjiskip}の挿入は文字の前/後ろのいずれでも許される.これがデフォルトの値である.
4323 \end{description}
4324 %<*en>
4325 This parameter is similar to the \verb+\inhibitxspcode+ primitive of \pTeX, but not compatible with \verb+\inhibitxspcode+.
4326 %</en>
4327 %<*ja>
4328 このパラメータは\pTeX の \verb+\inhibitxspcode+ プリミティブと似ているが,
4329 互換性はない.
4330 %</ja>
4331 \item[\DParam{alxspmode}\,=\{<chr\_code>,<mode>\}$^\ast$] [\verb+\xspcode+]
4332
4333 %<*en>
4334 Setting whether inserting \Param{xkanjiskip} is allowed before/after a
4335              \textbf{ALchar} whose character code is <chr\_code>.
4336              The followings are allowed for <mode>:
4337 %</en>
4338 %<*ja>
4339 文字コードが<chr\_code>の\textbf{ALchar}の前/後ろに\Param{xkanjiskip}の
4340 挿入を許すかどうかの設定.
4341 以下の<mode>が許される:
4342 %</ja>
4343 \begin{description}
4344 %<en>\item[0, \texttt{inhibit}] Insertion of \Param{xkanjiskip} is inhibited before the character, nor after the character.
4345 %<ja>\item[0, \texttt{inhibit}] \Param{xkanjiskip}の挿入は文字の前/後ろのいずれでも禁止される.
4346 %<en>\item[1, \texttt{preonly}] Insertion of \Param{xkanjiskip} is allowed before the character, but not after.
4347 %<ja>\item[1, \texttt{preonly}] \Param{xkanjiskip}の挿入は文字の前では許されるが,後ろでは許されない.
4348 %<en>\item[2, \texttt{postonly}] Insertion of \Param{xkanjiskip} is allowed after the character, but not before.
4349 %<ja>\item[2, \texttt{postonly}] \Param{xkanjiskip}の挿入は文字の後ろでは許されるが,前では許されない.
4350 %<en>\item[3, \texttt{allow}] Insertion of \Param{xkanjiskip} is allowed before the character and after the character. This is the default value.
4351 %<ja>\item[3, \texttt{allow}] \Param{xkanjiskip}の挿入は文字の前/後ろのいずれでも許される.これがデフォルトの値である.
4352 \end{description}
4353 %<*en>
4354 Note that parameters \Param{jaxspmode} and \Param{alxspmode} share a common table, hence these two parameters are synonyms of each other.
4355 %</en>
4356 %<*ja>
4357 \Param{jaxspmode}と\Param{alxspmode}は共通のテーブルを用いているため,
4358 これら2つのパラメータは互いの異名となっていることに注意する.
4359 %</ja>
4360
4361 \item[\DParam{autospacing}\,=<bool>] [\verb+\autospacing+]
4362 \item[\DParam{autoxspacing}\,=<bool>] [\verb+\autoxspacing+]
4363 \item[\DParam{kanjiskip}\,=<skip>$^\ast$] [\verb+\kanjiskip+]
4364 %<*ja>
4365 デフォルトで2つの\textbf{JAchar}の間に挿入されるグルーである.
4366 通常では,\pTeX と同じようにフォントサイズに比例して変わることはない.
4367 しかし,自然長が \verb+\maxdimen+ の場合は,例外的に和文フォントのJFM側で指定されている
4368 値を採用(こちらはフォントサイズに比例)することになっている.
4369 %</ja>
4370
4371 \item[\DParam{xkanjiskip}\,=<skip>$^\ast$] [\verb+\xkanjiskip+]
4372 %<*ja>
4373 デフォルトで\textbf{JAchar}と\textbf{ALchar}の間に挿入されるグルーである.
4374 \Param{kanjiskip}と同じように,通常ではフォントサイズに比例して変わることはないが,
4375 自然長が \verb+\maxdimen+ の場合が例外である.
4376 %</ja>
4377
4378
4379 \item[\DParam{differentjfm}\,=<mode>$^\dagger$]
4380
4381 %<*en>
4382 Specify how glues/kerns between two \textbf{JAchar}s whose JFM (or size) are different.
4383 The allowed arguments are the followings:
4384 %</en>
4385 %<*ja>
4386 JFM(もしくはサイズ)が異なる2つの\textbf{JAchar}の間にグルー/カーンをどのように
4387 入れるかを指定する.
4388 許される値は以下の通り:
4389 %</ja>
4390 \begin{quote}
4391 \texttt{average},
4392 \texttt{both},
4393 \texttt{large},
4394 \texttt{small},
4395 \texttt{pleft},
4396 \texttt{pright},
4397 \texttt{paverage}
4398 \end{quote}
4399 %<*en>
4400 The default value is \texttt{paverage}. \dots
4401 %</en>
4402 %<*ja>
4403 デフォルト値は \texttt{paverage} である.
4404 各々の値による差異の詳細は\ref{ssec-cluster-wa}節の「『右空白』の算出」を参照してほしい.
4405 %</ja>
4406
4407 \item[\DParam{jacharrange}\,=<ranges>]
4408 \item[\DParam{kansujichar}\,=\{<digit>, <chr\_code>\}$^\ast$] [\verb+\kansujichar+]
4409
4410 \item[\DParam{direction}\,=<dir>\ \hbox{\rm (always local)}]
4411
4412 %<*ja>
4413 組方向を変更する \verb+\yoko+~(if $\hbox{<dir>}=4$), \verb+\tate+~(if $\hbox{<dir>}=3$),
4414 \verb+\dtou+~(if $\hbox{<dir>}=1$), \verb+\utod+~(if $\hbox{<dir>}=11$) と同じ役割を持つ.
4415 利用可能な状況もこれら4命令と同一である.引数<dir>が4,~3, 1,~11のいずれでも無いときの
4416 動作は未定義である.
4417 %</ja>
4418
4419 \end{list}
4420
4421 \subsection{\texttt{\textbackslash ltjgetparameter}}
4422 \label{ssec-getpar}
4423 %<*en>
4424 \verb+\ltjgetparameter+ is a control sequence for acquiring parameters. It
4425 always takes a parameter name as first argument.
4426 %</en>
4427 %<*ja>
4428 \verb+\ltjgetparameter+ はパラメータの値を取得するための命令であり,
4429 常にパラメータの名前を第一引数にとる.
4430 %</ja>
4431 \begin{LTXexample}
4432 \ltjgetparameter{differentjfm},
4433 \ltjgetparameter{autospacing},
4434 \ltjgetparameter{kanjiskip},
4435 \ltjgetparameter{prebreakpenalty}{`)}.
4436 \end{LTXexample}
4437
4438 %<*en>
4439 \emph{The return value of\/ {\normalfont\tt\textbackslash ltjgetparameter} is
4440 always a string}. This is outputted by \texttt{tex.write()}, so any
4441 character other than space~``\texttt{\char32}''~(\texttt{U+0020}) has the category code
4442 12~(other), while the space has 10~(space).
4443 %</en>
4444 %<*ja>
4445 \emph{{\normalfont\tt\textbackslash ltjgetparameter}の戻り値は常に文字列である.}
4446 これは\texttt{tex.write()}によって出力しているためで,空白「\texttt{\char32}」
4447 (\texttt{U+0020})を除いた文字のカテゴリーコードは全て12~(other)となる.
4448 一方,空白のカテゴリーコードは10~(space)である.
4449 %</ja>
4450
4451 \begin{itemize}
4452 \item
4453 %<*en>
4454 If first argument is one of the
4455 following, no  additional argument is needed.
4456 %</en>
4457 %<*ja>
4458 第1引数が次のいずれかの場合には,追加の引数は必要ない.
4459 %</ja>
4460 \begin{quote}
4461 \sffamily
4462 jcharwidowpenalty, yjabaselineshift, yalbaselineshift, autospacing, autoxspacing,\\
4463 kanjiskip, xkanjiskip, differentjfm, direction
4464 \end{quote}
4465 %<*en>
4466 Note that \verb+\ltjgetparameter{autospacing}+~and~\verb+\ltjgetparameter{autoxspacing}+
4467 returns 1 or 0, not
4468 \texttt{true}~nor~\texttt{false}.
4469 %</en>
4470 %<*ja>
4471 \verb+\ltjgetparameter{autospacing}+ と \verb+\ltjgetparameter{autoxspacing}+ は,
4472 \texttt{true}や\texttt{false}を返すの\emph{ではなく},
4473 1と0のいずれかを返すことに注意,
4474 %</ja>
4475
4476 \item
4477 %<*en>
4478 If first argument is one of the
4479 following, an additional argument---a character code, for example---is needed.
4480 %</en>
4481 %<*ja>
4482 第1引数が次のいずれかの場合には,さらに文字コードを第二引数としてとる.
4483 %</ja>
4484 \begin{quote}
4485 \sffamily
4486 kcatcode, prebreakpenalty, postbreakpenalty, jaxspmode, alxspmode
4487 \end{quote}
4488 %<*en>
4489 \verb+\ltjgetparameter{jaxspmode}{...}+~and~\verb+\ltjgetparameter{alxspmode}{...}+
4490 returns 0,~1, 2,~or~3, instead of \texttt{preonly} etc.
4491 %</en>
4492 %<*ja>
4493 \verb+\ltjgetparameter{jaxspmode}{...}+ や \verb+\ltjgetparameter{alxspmode}{...}+\
4494 は,\texttt{preonly} などといった文字列ではなく,0から3までの値を返す.
4495 %</ja>
4496
4497 \item
4498 %<*en>
4499 \verb+\ltjgetparameter{jacharrange}{+<range>\verb+}+ returns \texttt{0}
4500 if ``characters which belong to the character range~<range> are \textbf{JAchar}'',
4501 \texttt{1} if ``\dots are \textbf{ALchar}''.
4502 Although there is no character range~$-1$, specifying $-1$ to <range> does not cause an
4503       error (returns 1).
4504 %</en>
4505 %<*ja>
4506 \verb+\ltjgetparameter{jacharrange}{+<range>\verb+}+ は,<range>が\textbf{JAchar}達の
4507 範囲ならば0を,そうでなければ1を返す.「$-1$番の文字範囲」は存在しないが,<range>に$-1$を
4508 指定してもエラーは発生しない(1を返す).
4509 %</ja>
4510
4511 \item
4512 %<*en>
4513 For an integer~<digit> between 0~and~9,
4514      \verb+\ltjgetparameter{kansujichar}{+<digit>\verb+}+ returns the character code
4515 of the result of \verb+\kansuji+<digit>.
4516 %</en>
4517 %<*ja>
4518 0--9の数<digit>に対して,
4519 \verb+\ltjgetparameter{kansujichar}{+<digit>\verb+}+ は,\verb+\kansuji+<digit>で出力され
4520      る文字の文字コードを返す.
4521 %</ja>
4522
4523 \item
4524 %<*en>
4525 \verb+\ltjgetparameter{adjustdir}+ returns a integer which represents
4526 the direction of the surrounding vertical list.
4527 As \Param{direction}, the return value 1 means \emph{down-to-up} direction,
4528 3 means \emph{tate} direction (vertical typesetting),
4529 and 4 means \emph{yoko} direction (horizontal typesetting).
4530 %</en>
4531 %<*ja>
4532 \verb+\ltjgetparameter{adjustdir}+ は,周囲のvboxの組方向(言い換えれば,
4533 \verb+\vadjust+ で用いられる組方向)を表す数値を返す.
4534 \Param{direction}と同様に,1は \verb+\dtou+ 方向を,
4535 3は縦組みを,4は横組みを表す.
4536 %</ja>
4537
4538 \item
4539 %<*en>
4540 For an integer~<reg\_num> between 0~and~65535,
4541 \verb+\ltjgetparameter{boxdim}{+<reg\_num>\verb+}+ returns the direction of
4542 \verb+\box+<reg\_num>. If this box is void, the returned value is zero.
4543 %</en>
4544 %<*ja>
4545 0--65535の数<reg\_num>に対して,
4546 \verb+\ltjgetparameter{boxdim}{+<reg\_num>\verb+}+ は,\verb+\box+<reg\_num>に
4547 格納されているボックスの組方向を表す.もしこのレジスタが空の場合は,0が返される.
4548 %</ja>
4549
4550 \item
4551 %<*en>
4552 The following parameter names \emph{cannot be specified} in \verb+\ltjgetparameter+.
4553 %</en>
4554 %<*ja>
4555 次のパラメータ名を \verb+\ltjgetparameter+ に指定することはできない.
4556 %</ja>
4557 \begin{quote}
4558 \sffamily
4559 jatextfont, jascriptfont, jascriptscriptfont, jacharrange
4560 \end{quote}
4561
4562 \item
4563 %<*en>
4564 \verb+\ltjgetparameter{chartorange}{+<chr\_code>\verb+}+ returns
4565 the range number which <chr\_code> belongs to
4566 (although there is no parameter named ``chartorange'').
4567
4568 If <chr\_code> is between 0 and 127, this <chr\_code> does not belong to
4569 any character range. In this case,
4570       \verb+\ltjgetparameter{chartorange}{+<chr\_code>\verb+}+
4571 returns $-1$.
4572
4573 Hence, one can know whether <chr\_code> is \textbf{JAchar} or not
4574 by the following:
4575 %</en>
4576 %<*ja>
4577 \verb+\ltjgetparameter{chartorange}{+<chr\_code>\verb+}+ によって
4578 <chr\_code>の属する文字範囲の番号を知ることができる.
4579
4580 <chr\_code>に0--127の値を指定した場合(このとき,<chr\_code>が属する
4581 文字範囲は存在しない)は$-1$が返る.
4582
4583 そのため,<chr\_code>が\textbf{JAchar}か\textbf{ALchar}かは
4584 次で知ることができる:
4585 %</ja>
4586 \begin{quote}
4587 \ttfamily \verb+\ltjgetparameter{jacharrange}{\ltjgetparameter{chartorange}{+%
4588   <chr\_code>\verb+}}+\\\null\hfill\verb+% 0 if JAchar, 1 if ALchar+
4589 \end{quote}
4590
4591 \end{itemize}
4592
4593
4594
4595
4596 %<en>\section{Other Commands for plain \TeX\ and \LaTeXe}
4597 %<ja>\section{plainでも\LaTeX でも利用可能なその他の命令}
4598 %<en>\subsection{Commands for Compatibility with \pTeX}
4599 %<ja>\subsection{\pTeX 互換用命令}
4600
4601 %<*en>
4602 The following commands are implemented for compatibility with \pTeX.
4603 Note that the former five commands don't support JIS~X~0213, but only JIS~X~0208.
4604 The last \verb+\kansuji+ converts an integer into its Chinese numerals.
4605 %</en>
4606 %<*ja>
4607 以下の命令は\pTeX との互換性のために実装されている.そのため,JIS~X~0213には対応せず,
4608 \pTeX と同じようにJIS~X~0208の範囲しかサポートしていない.
4609 %</ja>
4610 \begin{center}
4611 \verb+\kuten+, \verb+\jis+, \verb+\euc+, \verb+\sjis+, \verb+\jis+, \verb+\kansuji+
4612 \end{center}
4613 %<*en>
4614 These six commands takes an internal integer, and returns a \emph{string}.
4615 %</en>
4616 %<*ja>
4617 これら6命令は内部整数を引数とするが,実行結果は\textbf{文字列}であることに注意.
4618 %</ja>
4619 \begin{LTXexample}
4620 \newcount\hoge
4621 \hoge="2423 %"
4622 \the\hoge, \kansuji\hoge\\
4623 \jis\hoge, \char\jis\hoge\\
4624 \kansuji1701
4625 \end{LTXexample}
4626
4627 %<*en>
4628 To change characters of Chinese numerals for each digit, set \Param{kansujichar} parameter:
4629 \begin{LTXexample}
4630 \ltjsetparameter{kansujichar={1,`壹}}
4631 \ltjsetparameter{kansujichar={7,`漆}}
4632 \ltjsetparameter{kansujichar={0,`零}}
4633 \kansuji1701
4634 \end{LTXexample}
4635 %</en>
4636
4637
4638 %<en>\subsection{\texttt{\textbackslash inhibitglue}}
4639 %<ja>\subsection{\texttt{\textbackslash inhibitglue}}
4640 %<*en>
4641 \verb+\inhibitglue+ suppresses the insertion of \textbf{JAglue}.
4642 The following is an example, using a special JFM that there will be a glue between
4643 the beginning of a box and ``あ'', and also between ``あ''~and~``ウ''.
4644 %</en>
4645 %<*ja>
4646 \verb+\inhibitglue+ は\textbf{JAglue}の挿入を抑制する.
4647 以下は,ボックスの始めと「あ」の間,「あ」「ウ」の間にグルーが入る特別なJFMを用いた例で
4648 ある.
4649 %</ja>
4650
4651 \begin{LTXexample}[width=0.4\textwidth]
4652 \jfont\g=file:KozMinPr6N-Regular.otf:jfm=test \g
4653 \fbox{\hbox{あウあ\inhibitglue ウ}}
4654 \inhibitglue\par\noindent あ1
4655 \par\inhibitglue\noindent あ2
4656 \par\noindent\inhibitglue あ3
4657 \par\hrule\noindent あoff\inhibitglue ice
4658 \end{LTXexample}
4659
4660 %<*en>
4661 With the help of this example, we remark the specification of \verb+\inhibitglue+:
4662 %</en>
4663 %<*ja>
4664 この例を援用して,\verb+\inhibitglue+ の仕様について述べる.
4665 %</ja>
4666 \begin{itemize}
4667 %<*en>
4668 \item The call of \verb+\inhibitglue+ in the (internal) vertical mode is
4669       simply ignored.
4670 %</en>
4671 %<*ja>
4672 \item \verb+\inhibitglue+ の垂直モード中での呼び出しは意味を持たない.
4673 4行目の入力で有効にならないのは,\verb+\inhibitglue+ の時点では垂直モードであり,
4674 \verb+\noindent+ の時点で水平モードになるからである.
4675 %</ja>
4676
4677 %<*en>
4678 \item The call of \verb+\inhibitglue+ in the (restricted) horizontal
4679       mode is only effective on the spot; does not get over boundary of
4680       paragraphs. Moreover, \verb+\inhibitglue+ cancels ligatures and
4681       kernings, as shown in the last line of above example.
4682 %</en>
4683 %<*ja>
4684 \item \verb+\inhibitglue+ の(制限された)水平モード中での呼び出しはその場でのみ
4685   有効であり,段落の境界を乗り越えない.
4686   さらに,\verb+\inhibitglue+ は上の例の最終行のように(欧文における)リガチャとカーニングを
4687   打ち消す.これは,\verb+\inhibitglue+ が内部的には「現在のリスト中にwhatsitノードを
4688   追加する」ことを行なっているからである.
4689 %</ja>
4690
4691 %<*en>
4692 \item The call of \verb+\inhibitglue+ in math mode is just ignored.
4693 %</en>
4694 %<*ja>
4695 \item \verb+\inhibitglue+ を数式モード中で呼び出した場合はただ無視される.
4696 %</ja>
4697
4698 %<*ja>
4699 \item \LaTeX で\LuaTeX-ja を使用する場合は,
4700 \verb+\inhibitglue+ の代わりとして \verb+\<+ を使うことができる.
4701 既に \verb+\<+ が定義されていた場合は,\LuaTeX-ja の読み込みで強制的に上書きされるので
4702 注意すること.
4703 %</ja>
4704 \end{itemize}
4705
4706
4707 \subsection{\texttt{\textbackslash ltjdeclarealtfont}}
4708 \label{ssec-altfont}
4709 %<*en>
4710 Using \verb+\ltjdeclarealtfont+, one can ``compose'' more than one Japanese fonts.
4711 This \verb+\ltjdeclarealtfont+ uses in the following form:
4712 \begin{quote}
4713 \ttfamily \textbackslash ltjdeclarealtfont<base\_font\_cs><alt\_font\_cs>{<range>}
4714 \end{quote}
4715 where  <base\_font\_cs>~and~<alt\_font\_cs> are defined by \verb+\jfont+.
4716 Its meaning is
4717 \begin{quote}
4718 If the current Japanese font is <base\_font\_cs>, characters which belong to <range>
4719 is typeset by another Japanese font <alt\_font\_cs>, instead of <base\_font\_cs>.
4720 \end{quote}
4721
4722 <range> is a comma-separated list of character codes, but also accepts negative integers:
4723 $-n$~($n≥1$) means that all characters of character classes~$n$, with respect to JFM used
4724 by <base\_font\_cs>. Note that characters which do not exist in <alt\_font\_cs> are
4725 ignored.
4726
4727 For example, if \verb+\hoge+ uses \texttt{jfm-ujis.lua}, the standard JFM of \LuaTeX-ja,
4728 then
4729 \begin{verbatim}
4730 \ltjdeclarealtfont\hoge\piyo{"3000-"30FF, {-1}-{-1}}
4731 \end{verbatim}
4732 does
4733 \begin{quote}
4734 If the current Japanese font is \verb+\hoge+, \texttt{U+3000}--\texttt{U+30FF}
4735 and characters in class~1 (ideographic opening brackets)
4736 are typeset by \verb+\piyo+.
4737 \end{quote}
4738 %</en>
4739 %<*ja>
4740 \verb+\jfont+ の書式を見ればわかるように,基本的には\LuaTeX-jaにおける1つの和文フォントに
4741 使用出来る「実際のフォント」は1つである.
4742 しかし,\verb+\ltjdeclarealtfont+ を用いると,この原則から外れることができる.
4743
4744 \verb+\ltjdeclarealtfont+ は以下の書式で使用する:
4745 \begin{quote}
4746 \ttfamily \textbackslash ltjdeclarealtfont<base\_font\_cs><alt\_font\_cs>{<range>}
4747 \end{quote}
4748 これは「現在の和文フォント」が<base\_font\_cs>であるとき,
4749 <range>に属する文字は<alt\_font\_cs>を用いて組版される,という意味である.
4750 \begin{itemize}
4751  \item <base\_font\_cs>, <alt\_font\_cs>は
4752 \verb+\jfont+ によって定義された和文フォントである.
4753  \item <range>は文字コードの範囲を表すコンマ区切りのリストであるが,
4754    例外として負数$-n$は「<base\_font\_cs>のJFMの文字クラス$n$に属する全ての文字」
4755    を意味する.
4756
4757 <range>中に<alt\_font\_cs>中に実際には存在しない文字が指定された場合は,
4758 その文字に対する設定は無視される.
4759 \end{itemize}
4760
4761 例えば,\verb+\hoge+ のJFMが\LuaTeX-ja標準の
4762 \ \texttt{jfm-ujis.lua} であった場合,
4763 \begin{verbatim}
4764 \ltjdeclarealtfont\hoge\piyo{"3000-"30FF, {-1}-{-1}}
4765 \end{verbatim}
4766 は「\verb+\hoge+ を利用しているとき,
4767 \texttt{U+3000}--\texttt{U+30FF}と
4768 文字クラス1(開き括弧類)中の文字だけは \verb+\piyo+ を用いる」
4769 ことを設定する.\verb+{-1}-{-1}+ という変わった指定の仕方をしているのは,
4770 普通に \texttt{-1} と指定したのでは正しく$-1$と読み取られないという
4771 マクロの都合による.
4772 %</ja>
4773
4774
4775
4776 %<en>\section{Commands for \LaTeXe}
4777 %<ja>\section{\LaTeXe 用の命令}
4778
4779 %<en>\subsection{Patch for NFSS2}
4780 %<ja>\subsection{NFSS2へのパッチ}
4781 \label{ssec-nfsspat}
4782
4783 \begin{figure}[!tb]
4784 \begin{LTXexample}[pos=b]
4785 \DeclareKanjiFamily{JY3}{edm}{}
4786 \DeclareFontShape{JY3}{edm}{m}{n}    {<-> s*KozMinPr6N-Regular:jfm=ujis;}{}
4787 \DeclareFontShape{JY3}{edm}{m}{green}{<-> s*KozMinPr6N-Regular:jfm=ujis;color=007F00}{}
4788 \DeclareFontShape{JY3}{edm}{m}{blue} {<-> s*KozMinPr6N-Regular:jfm=ujis;color=0000FF}{}
4789 \DeclareAlternateKanjiFont{JY3}{edm}{m}{n}{JY3}{edm}{m}{green}{"4E00-"67FF,{-2}-{-2}}
4790 \DeclareAlternateKanjiFont{JY3}{edm}{m}{n}{JY3}{edm}{m}{blue}{ "6800-"9FFF}
4791 {\kanjifamily{edm}\selectfont
4792 日本国民は、正当に選挙された国会における代表者を通じて行動し、……}
4793 \end{LTXexample}
4794 %<ja>\caption{\texttt{\textbackslash DeclareAlternateKanjiFont} の使用例}
4795 %<en>\caption{An example of \texttt{\textbackslash DeclareAlternateKanjiFont}}
4796 \label{fig:altkanji}
4797 \end{figure}
4798
4799 %<*en>
4800 Japanese patch for NFSS2 in \LuaTeX-ja
4801 is based on \texttt{plfonts.dtx} which plays the same role in \pLaTeXe.
4802 We will describe
4803 commands which are not described in Subsection~\ref{ssec-chgfnt}.
4804 %</en>
4805 %<*ja>
4806 \LuaTeX-jaのNFSS2への日本語パッチは
4807 \pLaTeXe で同様の役割を果たす \texttt{plfonts.dtx} をベースに,
4808 和文エンコーディングの管理等をLuaで書きなおしたものである.
4809 ここでは\ref{ssec-chgfnt}節で述べていなかった命令について
4810 記述しておく.
4811 %</ja>
4812
4813 \begin{cslist}%
4814 \par\smallskip\par\hskip-\leftskip{\bfseries%
4815 %<ja>追加の長さ変数達
4816 %<en>additonal dimensions
4817 }\par
4818
4819 %<*en>
4820 Like \pLaTeXe, \LuaTeX-ja defines the following dimensions
4821 for information of current Japanese font:
4822 %</en>
4823 %<*ja>
4824 \pLaTeXe と同様に,\LuaTeX-jaは「現在の和文フォントの情報」を格納する長さ変数
4825 %</ja>
4826 {\let\item=\origitem
4827 \begin{quote}
4828  \verb+\cht+~(height), \verb+\cdp+~(depth), \verb+\cHT+~(sum of former two),\\
4829  \verb+\cwd+~(width), \verb+\cvs+~(lineskip), \verb+\chs+~(equals to \verb+\cwd+)
4830 \end{quote}}
4831 %<en>and its \verb+\normalsize+ version:
4832 %<ja>と,その \verb+\normalsize+ 版である
4833 {\let\item=\origitem
4834 \begin{quote}
4835  \verb+\Cht+~(height), \verb+\Cdp+~(depth),
4836  \verb+\Cwd+~(width), \\\verb+\Cvs+~(equals to \verb+\baselineskip+),
4837  \verb+\Chs+~(equals to \verb+\cwd+)%
4838 %<en>.
4839 \end{quote}}
4840 %<*ja>
4841 を定義している.なお,\verb+\cwd+ と \verb+\zw+,また
4842 \verb+\cHT+ と \verb+\zh+ は一致しない可能性がある.なぜなら,
4843 \verb+\cwd+,~\verb+\cHT+ は「あ」の寸法から決定されるのに対し,
4844 \verb+\zw+ と \verb+\zh+ はJFMに指定された値に過ぎないからである.
4845 %</ja>
4846 %<*en>
4847 Note that \verb+\cwd+~and~\verb+\cHT+ may  differ from \verb+\zw+~and~\verb+\zh+
4848 respectively.
4849 On the one hand the former dimensions are determined from the character ``あ'',
4850 but on the other hand \verb+\zw+~and~\verb+\zh+ are specified by JFM.
4851 %</en>
4852
4853
4854 \item[DeclareYokoKanjiEncoding\{<encoding>\}\{<text-settings>\}\{<math-settings>\}]
4855 \item[DeclareYokoKanjiEncoding\{<encoding>\}\{<text-settings>\}\{<math-settings>\}]
4856
4857 %<*en>
4858 In NFSS2 under \LuaTeX-ja, distinction between alphabetic font families
4859              and Japanese font families are only made by their
4860              encodings. For example, encodings OT1 and T1 are for
4861              alphabetic font families, and a Japanese font family cannot
4862              have these encodings. These command define a new encoding
4863              scheme for Japanese font family.
4864 %</en>
4865 %<*ja>
4866 \LuaTeX-jaのNFSS2においては,欧文フォントファミリと和文フォントファミリは
4867 そのエンコーディングによってのみ区別される.
4868 例えば,OT1とT1のエンコーディングは欧文フォントファミリに対するものであり,
4869 和文フォントファミリはこれらのエンコーディングを持つことはできない.
4870 これらコマンドは横組用・縦組用和文フォントのための新しいエンコーディングを
4871 それぞれ定義する.
4872 %</ja>
4873
4874 \item[DeclareKanjiEncodingDefaults\{<text-settings>\}\{<math-settings>\}]
4875 \item[DeclareKanjiSubstitution\{<encoding>\}\{<family>\}\{<series>\}\{<shape>\}]
4876 \item[DeclareErrorKanjiFont\{<encoding>\}\{<family>\}\{<series>\}\{<shape>\}\{<size>\}]
4877
4878 %<*en>
4879 The above 3~commands are just the counterparts for \verb+\DeclareFontEncodingDefaults+ and~others.
4880 %</en>
4881 %<*ja>
4882 上記3つのコマンドはちょうど \verb+\DeclareFontEncodingDefaults+ などに対応するものである.
4883 %</ja>
4884
4885 \item[reDeclareMathAlphabet\{<unified-cmd>\}\{<al-cmd>\}\{<ja-cmd>\}]
4886
4887 % ToDo: en
4888 %<*ja>
4889 和文・欧文の数式用フォントファミリを一度に変更する命令を作成する.
4890 具体的には,欧文数式用フォントファミリ変更の命令<al-cmd>(\verb+\mathrm+ 等)と,和文数式用フォ
4891              ントファミリ変更の命令<ja-cmd>(\verb+\mathmc+ 等)の2つを同時に行う命令として
4892              <unified-cmd>を(再)定義する.実際の使用では<unified-cmd>と
4893              <al-cmd>に同じものを指定する,すなわち,<al-cmd>で和文側も変
4894              更させるようにするのが一般的と思われる.
4895
4896 本命令は
4897 {\let\item=\origitem
4898 \begin{center}\tt
4899 <unified-cmd>\{<arg>\}\quad$\longrightarrow$\quad
4900 (<al-cmd>の1段展開結果)\{<ja-cmd>の1段展開結果)\{<arg>\}\}
4901 \end{center}
4902 と定義を行うので,使用には注意が必要である:
4903 \vspace{-\medskipamount}
4904 %<en>\advance\linewidth-2em
4905 %<ja>\advance\linewidth-2\zw
4906 \begin{itemize}
4907 \item <al-cmd>,~<ja-cmd>は既に定義されていなければならない.
4908       \verb+\reDeclareMathAlphabet+\\の後に
4909 両命令の内容を再定義しても,<unified-cmd>の内容にそれは反映されない.
4910 \item <al-cmd>,~<ja-cmd>に\verb+\@mathrm+などと \texttt{@} をつけた命令を指定した時の動作は保証できない.
4911 \end{itemize}}
4912 %</ja>
4913
4914 \item[DeclareRelationFont\{<ja-encoding>\}\{<ja-family>\}\{<ja-series>\}\{<ja-shape>\}\\*
4915   \null\hfill\{<al-encoding>\}\{<al-family>\}\{<al-series>\}\{<al-shape>\}]
4916 %<*en>
4917 This command sets the ``accompanied'' alphabetic font family (given by the latter 4~arguments)
4918 with respect to a Japanese font family given by the former 4~arguments.
4919 %</en>
4920 %<*ja>
4921 いわゆる「従属欧文」を設定するための命令である.前半の4引数で表される和文フォントファミリに対して,
4922 そのフォントに対応する「従属欧文」のフォントファミリを後半の4引数により与える.
4923 %</ja>
4924 \item[SetRelationFont]
4925 %<*en>
4926 This command is almost same as \verb+\DeclareRelationFont+, except that this command does a local
4927 assignment, where \verb+\DeclareRelationFont+ does a global assignment.
4928 %</en>
4929 %<*ja>
4930 このコマンドは \verb+\DeclareRelationFont+ とローカルな指定であることを除いて
4931 ほとんど同じである(\verb+\DeclareRelationFont+ はグローバル).
4932 %</ja>
4933
4934 \item[userelfont]
4935 %<*en>
4936 Change current alphabetic font encoding/family/\dots\ to the `accompanied' alphabetic
4937              font family with respect to current Japanese font family,
4938              which was set by
4939              \verb+\DeclareRelationFont+ or \verb+\SetRelationFont+.
4940 Like \verb+\fontfamily+, \verb+\selectfont+ is required to take an effect.
4941 %</en>
4942 %<*ja>
4943 現在の欧文フォントのエンコーディング/ファミリ/…… を,
4944 \verb+\DeclareRelationFont+ か \verb+\SetRelationFont+ で指定された
4945 現在の和文フォントファミリに対応する「従属欧文」フォントファミリに変更する.
4946 \verb+\fontfamily+ のように,有効にするためには \verb+\selectfont+ が必要である.
4947 %</ja>
4948
4949 \item[adjustbaseline]
4950 %<*en>
4951 In \pLaTeXe, \verb+\adjustbaseline+ sets \verb+\tbaselineshift+
4952 to match the vertical center of ``M'' and that of ``あ''  in vertical typesetting:
4953 \[
4954 \text{\ttfamily \textbackslash tbaselineshift} \leftarrow
4955 \frac{(h_{\text{M}}+d_{\text{M}}) - (h_{\text{あ}}+d_{\text{あ}})}2
4956   + d_{\text{あ}} - d_{\text{M}},
4957 \]
4958 where $h_{a}$~and~$d_{a}$ denote the height of ``$a$'' and the depth, respectively.
4959 In \LuaTeX-ja, this \verb+\adjustbaseline+ does same task.
4960 %</en>
4961 %<*ja>
4962 \pLaTeXe では,\verb+\adjustbaseline+ は縦組時に「M」と「あ」の中心線を一致させるために,
4963 \verb+\tbaselineshift+ を設定する役割を持っていた:
4964 \[
4965 \text{\ttfamily \textbackslash tbaselineshift} \leftarrow
4966 \frac{(h_{\text{M}}+d_{\text{M}}) - (h_{\text{あ}}+d_{\text{あ}})}2
4967   + d_{\text{あ}} - d_{\text{M}},
4968 \]
4969 ここで,$h_{a}$,~$d_{a}$はそれぞれ「$a$」の高さ・深さを表す.
4970 \LuaTeX-jaにおいても\verb+\adjustbaseline+ は同様の処理を行っている.
4971 %</ja>
4972
4973 \item[fontfamily\{<family>\}]
4974 %<*en>
4975 As in \LaTeXe, this command changes current font family (alphabetic, Japanese,~\emph{or both})
4976 to <family>. Which family will be changed is determined as follows:
4977 %</en>
4978 %<*ja>
4979 元々の\LaTeXe におけるものと同様に,このコマンドは現在のフォントファミリ(欧文,
4980 和文,\emph{もしくは両方})を<family>に変更する.
4981 どのファミリが変更されるかは以下のようにして決定される:
4982 %</ja>
4983 {\let\item\origitem
4984 %<en>\advance\linewidth-2em
4985 %<ja>\advance\linewidth-2\zw
4986 \vspace{-\medskipamount}
4987 \begin{itemize}
4988 %<*en>
4989 \item Let current encoding scheme for Japanese fonts be
4990       <ja-enc>. Current Japanese font family will be changed to
4991       <family>, if one of the following two conditions is met:
4992 %</en>
4993 %<*ja>
4994 \item 現在の和文フォントに対するエンコーディングが<ja-enc>であるとしよう.
4995   現在の和文フォントファミリは,以下の2つの条件のうちの1つが満たされているときに
4996   <family>に変更される:
4997 %</ja>
4998 \begin{itemize}
4999 %<*en>
5000 \item The family <family> under the encoding <ja-enc> has been already defined by
5001       \verb+\DeclareKanijFamily+.
5002 %</en>
5003 %<*ja>
5004 \item エンコーディング<ja-enc>におけるファミリ<family>が
5005 既に \verb+\DeclareKanjiFamily+ によって定義されている.
5006 %</ja>
5007 %<*en>
5008 \item A font definition named \texttt{<ja-enc><family>.fd} (the file name is
5009       all lowercase) exists.
5010 %</en>
5011 %<*ja>
5012 \item フォント定義ファイル\texttt{<ja-enc><family>.fd}(ファイル名は全て小文字)が存在する.
5013 %</ja>
5014 \end{itemize}
5015 %<*en>
5016 \item Let current encoding scheme for alphabetic fonts be
5017       <al-enc>. For alphabetic font family, the criterion as above is used.
5018 %</en>
5019 %<*ja>
5020 \item 現在の欧文フォントに対するエンコーディングを<al-enc>とする.
5021   欧文フォントファミリに対しても,上記の基準が用いられる.
5022 %</ja>
5023 %<*en>
5024 \item There is a case which none of the above applies, that is, the font
5025       family named <family> doesn't seem to be defined neither under the
5026       encoding <ja-enc>, nor under <al-enc>.
5027 In this case, the default family for font substitution is used for
5028       alphabetic and Japanese fonts. Note that current encoding will not
5029       be set to <family>, unlike the original implementation in \LaTeX.
5030 %</en>
5031 %<*ja>
5032 \item 上記のいずれもが適用されない,つまり<family>が<ja-enc>と<al-enc>の
5033   どちらでも定義されないような場合がある.
5034   この場合,代替フォントに用いられるデフォルトのフォントファミリが欧文フォントと
5035   和文フォントに用いられる.\LaTeX のオリジナルの実装とは異なり,
5036   現在のエンコーディングは<family>には設定されないことに注意する.
5037 %</ja>
5038 \end{itemize}%
5039 %<en>\vspace{-\medskipamount}
5040 }
5041
5042 \item[DeclareAlternateKanjiFont\{<base-encoding>\}\{<base-family>\}\{<base-series>\}\{<base-shape>\}\\
5043   \null\hfill\{<alt-encoding>\}\{<alt-family>\}\{<alt-series>\}\{<alt-shape>\}\{<range>\}]
5044 %<*ja>
5045 \ref{ssec-altfont}節の\
5046 \verb+\ltjdeclarealtfont+ と同様に,前半の4引数の
5047 和文フォント(基底フォント)のうち<range>中の文字を
5048 第5--第8引数の和文フォントを使って組むように指示する.
5049 使用例を図\nobreak\ref{fig:altkanji}に載せた.
5050
5051 {\let\item\origitem
5052 %<en>\advance\linewidth-2em
5053 %<ja>\advance\linewidth-2\zw
5054 \vspace{-\medskipamount}
5055 \begin{itemize}
5056  \item
5057 \verb+\ltjdeclarealtfont+ では基底フォント・置き換え先和文フォントはあらかじめ定義されてい
5058              ないといけない(その代わり即時発効)であったが,
5059 \verb+\DeclareAlternateKanjiFont+ の設定が
5060 実際に効力が発揮するのは,書体変更やサイズ変更を行った時,
5061 あるいは(これらを含むが)\verb+\selectfont+ が実行された時である.
5062  \item
5063 段落やhboxの最後での設定値が段落/hbox全体にわたって通用する点や,
5064 <range>に負数$-n$を指定した場合,それが「基底フォントの文字クラス$n$に属する文字全体」
5065 と解釈されるのは \verb+\ltjdeclarealtfont+ と同じである.
5066 \end{itemize}%
5067 }
5068 %</ja>
5069 %<*en>
5070 As \verb+\ltjdeclarealtfont+~(Subsection~\ref{ssec-altfont}),
5071 characters in <range> of the Japanese font (we say the \emph{base font})
5072 which specified by first 4 arguments are typeset
5073 by the Japanese font which specified by fifth to eighth arguments
5074 (we say the \emph{alternate font}).
5075 An example is shown in Figure~\ref{fig:altkanji}.
5076
5077 {\let\item\origitem
5078 %<en>\advance\linewidth-2em
5079 %<ja>\advance\linewidth-2\zw
5080 \vspace{-\medskipamount}
5081 \begin{itemize}
5082  \item
5083 In \verb+\ltjdeclarealtfont+, the base font and the alternate font must be already defined.
5084 But this \verb+\DeclareAlternateKanjiFont+ is not so.
5085 In other words, \verb+\DeclareAlternateKanjiFont+ is effective only after
5086 current Japanese font is changed, or only after \verb+\selectfont+ is executed.
5087  \item \dots
5088 \end{itemize}%
5089 \vspace{-\medskipamount}
5090 }
5091 %</en>
5092 \end{cslist}
5093
5094 %<*en>
5095 As closing this subsection, we shall introduce an example of
5096 \verb+\SetRelationFont+ and \verb+\userelfont+:
5097 %</en>
5098 %<*ja>
5099 この節の終わりに,\verb+\SetRelationFont+ と \verb+\userelfont+ の例を
5100 紹介しておこう.\verb+\userelfont+ の使用によって,「abc」の部分のフォントが
5101 Avant Garde (OT1/pag/m/n) に変わっていることがわかる.
5102 %</ja>
5103 \begin{LTXexample}[width=0.3\textwidth]
5104 \makeatletter
5105 \SetRelationFont{JY3}{\k@family}{m}{n}{OT1}{pag}{m}{n}
5106   % \k@family: current Japanese font family
5107 \userelfont\selectfont あいうabc
5108 \end{LTXexample}
5109
5110 %<*en>
5111 \section{Addons}
5112 \LuaTeX-ja has several addon packages.
5113 These addons are written as \LaTeX\ packages, but
5114 \Pkg{luatexja-otf} and~\Pkg{luatexja-adjust} can be loaded in plain \LuaTeX\
5115 by \verb+\input+.
5116 %</en>
5117 %<*ja>
5118 \section{拡張}
5119 \LuaTeX-jaには(動作には必須ではないが)自由に読み込める拡張が付属している.
5120 これらは\LaTeX のパッケージとして制作しているが,
5121 \Pkg{luatexja-otf}と\Pkg{luatexja-adjust}についてはplain \LuaTeX でも\
5122 \verb+\input+ で読み込み可能である.
5123 %</ja>
5124 \subsection{\texttt{luatexja-fontspec.sty}}
5125 \label{ssec-fontspec2}
5126 %<*en>
5127 As described in Subsection~\ref{ssec-fontspec}, this optional package
5128 provides the counterparts for several commands defined in the
5129 \Pkg{fontspec} package.
5130 In addition to OpenType font features in the original \Pkg{fontspec},
5131 the following ``font features'' specifications are allowed for
5132 the commands of Japanese version:
5133 %</en>
5134 %<*ja>
5135 \ref{ssec-fontspec}節で述べたように,この追加パッケージは\Pkg{fontspec}
5136 パッケージで定義されているコマンドに対応する和文フォント用のコマンドを提供する.
5137 \Pkg{fontspec}パッケージで指定可能な各種font featureに加えて,和文版のコマンドには
5138 以下の``font feature''を指定することができる:
5139 %</ja>
5140
5141
5142 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}\advance\leftmargin1\zw}
5143 \item[CID=<name>]
5144 \item[JFM=<name>]
5145 \item[JFM-var=<name>] \
5146
5147 %<*en>
5148 These 3 keys correspond to \texttt{cid}, \texttt{jfm} and
5149 \texttt{jfmvar} keys for \verb+\jfont+ respectively.
5150 \texttt{CID} is effective only when with \texttt{NoEmbed}
5151 described below.
5152 See Subsections~\ref{ssec-jfont} and \ref{ssec-psft} for details.
5153 %</en>
5154 %<*ja>
5155 これら3つのキーはそれぞれ \verb+\jfont+ に対する
5156 \texttt{cid}, \texttt{jfm}, \texttt{jfmvar}キーとそれぞれ対応する.
5157 \texttt{CID} は下の \texttt{NoEmbed} と合わせて用いられたときのみ有効である.
5158 \verb+\jfont+ プリミティブに対する
5159 \texttt{cid}, \texttt{jfm}, \texttt{jfmvar}キーの詳細は\ref{ssec-jfont}節
5160              と\ref{ssec-psft}節を参照.
5161 %</ja>
5162
5163 \item[NoEmbed]
5164 %<*en>
5165 By specifying this key, one can use ``name-only'' Japanese font which
5166 will not be embedded in the output PDF file. See Subsection~\ref{ssec-psft}.
5167 %</en>
5168 %<*ja>
5169 これを指定することで,PDFに埋め込まれない「名前だけ」のフォントを指定することが
5170 できる.\ref{ssec-psft}節を参照.
5171 %</ja>
5172
5173
5174 \begin{figure}[!tb]
5175 \begin{LTXexample}[pos=b]
5176 \jfontspec[
5177   AltFont={
5178     {Range="4E00-"67FF, Color=007F00},
5179     {Range="6800-"9EFF, Color=0000FF},
5180     {Range="3040-"306F, Font=KozGoPr6N-Regular},
5181   }
5182 ]{KozMinPr6N-Regular}
5183 日本国民は、正当に選挙された国会における代表者を通じて行動し、われらとわれらの子孫のために、
5184 諸国民との協和による成果と、わが国全土にわたつて自由のもたらす恵沢を確保し、……
5185 \end{LTXexample}
5186 %<ja>\caption{\texttt{AltFont} の使用例}
5187 %<en>\caption{An example of \texttt{AltFont}}
5188 \label{fig:altkanji-fontspec}
5189 \end{figure}
5190
5191 \item[AltFont]\
5192
5193 %<*en>
5194 As \verb+\ltjdeclarealtfont+~(Subsection~\ref{ssec-altfont}) and
5195 \verb+\DeclareAlternateKanjiFont+~(Subsection~\ref{ssec-nfsspat}),
5196 with this key, one can typeset some Japanese characters
5197 by a different font and/or using different features.
5198 The \texttt{AltFont} feature takes a comma-separated list of comma-separated lists,
5199 as the following:
5200 %</en>
5201 %<*ja>
5202 \ref{ssec-altfont}節の \verb+\ltjdeclarealtfont+ や,
5203 \ref{ssec-nfsspat}節の \verb+\DeclareAlternateKanjiFont+ と同様に,
5204 このキーを用いると一部の文字を異なったフォントやfont featureを使って組むことができる.
5205 \texttt{AltFont} に指定する値は,次のように二重のコンマ区切りリストである:
5206 %</ja>
5207 \begin{lstlisting}[escapechar=\#]
5208 AltFont = {
5209   ...
5210   { Range=#\LARG range>#, #\LARG features>#},
5211   { Range=#\LARG range>#, Font=#\LARG font~name>#, #\LARG features># },
5212   { Range=#\LARG range>#, Font=#\LARG font~name># },
5213   ...
5214 }
5215 \end{lstlisting}
5216 %<*en>
5217 Each sublist should have the \texttt{Range} key
5218 (sublist which does not contain \texttt{Range} key is simply ignored).
5219 A demonstrarion is shown in Figure~\ref{fig:altkanji-fontspec}.
5220 %</en>
5221 %<*ja>
5222 各部分リストには \texttt{Range} キーが必須である(含まれない部分リストは
5223 単純に無視される).
5224 指定例は図\ref{fig:altkanji-fontspec}に示した.
5225 %</ja>
5226 \end{list}
5227
5228 %<*ja>
5229 なお,\Pkg{luatexja-fontspec} 読み込み時には和文フォント定義ファイル%
5230 \texttt{<ja-enc><family>.fd}は全く参照されなくなる.
5231 %</ja>
5232
5233
5234 \subsection{\texttt{luatexja-otf.sty}}
5235 \label{ssec-ltjotf}
5236 %<*en>
5237 This optional package supports typesetting characters in
5238 Adobe-Japan1 character collection
5239 (or other CID character collection, if the font is supported).
5240 The package \Pkg{luatexja-otf} offers the following 2~low-level
5241 commands:
5242 %</en>
5243 %<*ja>
5244 この追加パッケージはAdobe-Japan1(フォント自身が持っていれば,
5245 別のCID文字セットでも可)の文字の出力をサポートする.
5246 \Pkg{luatexja-otf}は以下の2つの低レベルコマンドを提供する:
5247 %</ja>
5248 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}\advance\leftmargin1\zw}
5249 \item[\textbackslash CID\{<number>\}]
5250 %<*en>
5251 Typeset a character whose CID number is <number>.
5252 %</en>
5253 %<*ja>
5254 CID番号が<number>の文字を出力する.
5255 %</ja>
5256
5257 \item[\textbackslash UTF\{<hex\_number>\}]
5258 %<*en>
5259 Typeset a character whose character code is <hex\_number> (in hexadecimal).
5260 This command is similar to \verb+\char"+<hex\_number>,\ %"
5261 but please remind remarks below.
5262 %</en>
5263 %<*ja>
5264 文字コードが(16進で)<hex\_number>の文字を出力する.
5265 このコマンドは \verb+\char"+<hex\_number>と似ているが,下の記述に注意すること.%"
5266 %</ja>
5267 \end{list}
5268
5269 %<*ja>
5270 このパッケージは,\texttt{ajmacros.sty}(\Pkg{otf}パッケージ付属のマクロ集,井上浩一氏作)から
5271 漢字コードをUTF8にしたり,plain \LuaTeX でも利用可能するという
5272 修正を加えた \texttt{luatexja-ajmacros.sty} も自動的に読み込む.
5273 そのため,マクロ集にある \verb+\aj半角+ などのマクロもそのまま使用可能である.
5274 %</ja>
5275
5276 %<en>\paragraph{Remarks}
5277 %<ja>\paragraph{注意}
5278 %<*en>
5279 Characters by \verb+\CID+ and \verb+\UTF+ commands are different from
5280 ordinary characters in the following points:
5281 %</en>
5282 %<*ja>
5283 \verb+\CID+ と \verb+\UTF+ コマンドによって出力される文字は
5284 以下の点で通常の文字と異なる:
5285 %</ja>
5286 \begin{itemize}
5287 %<*en>
5288 \item Always treated as \textbf{JAchar}s.
5289 %</en>
5290 %<*ja>
5291 \item 常に\textbf{JAchar}として扱われる.
5292 %</ja>
5293 %<*en>
5294 \item Processing codes for supporting OpenType features (\textit{e.g.},
5295       glyph replacement and kerning) by the \Pkg{luaotfload} package
5296       is not performed to these characters.
5297 %</en>
5298 %<*ja>
5299 \item OpenType feature(例えばグリフ置換やカーニング)をサポートするための
5300   \Pkg{luaotfload}パッケージのコードはこれらの文字には働かない.
5301 %</ja>
5302 \end{itemize}
5303
5304 %<en>\paragraph{Additional syntax of JFM}
5305 %<ja>\paragraph{JFMへの記法の追加}
5306
5307 %<*en>
5308 The package \Pkg{luatexja-otf} extends the syntax of JFM; the entries of \texttt{
5309 chars} table in JFM now allows a string in the form
5310 \verb+'AJ1-xxx'+, which stands for the character
5311 whose CID number in Adobe-Japan1 is \verb+xxx+.
5312
5313 This extended notation is used in the standard JFM \texttt{jfm-ujis.lua}
5314 to typeset halfwidth Hiragana glyphs (CID~516--598) in halfwidth.
5315 %</en>
5316 %<*ja>
5317 \Pkg{luatexja-otf}パッケージを読み込むと,
5318 JFMの\texttt{chars}テーブルのエントリとして \verb+'AJ1-xxx'+ の形の文字列が
5319 使えるようになる.これはAdobe-Japan1におけるCID番号が \verb+xxx+ の文字を表す.
5320
5321 この拡張記法は,標準JFM~\texttt{jfm-ujis.lua}で,半角ひらがなのグリフ(CID~516--598)を
5322 正しく半角幅で組むために利用されている.
5323 %</ja>
5324
5325 %<*en>
5326 \paragraph{IVS support}
5327 Recent fonts support Ideographic Variation Selector (IVS).
5328 It seems that \Pkg{luaotfload} and \Pkg{fontspec} packages do not support
5329 IVS, so we implemented IVS support in \Pkg{luatexja-otf}.
5330 \emph{IVS support is experimental; if you want to enable this, load
5331 \Pkg{luatexja-otf} and execute the following:}
5332 %</en>
5333 %<*ja>
5334 \paragraph{IVSサポート}
5335 最近のOpenTypeフォントやTrueTypeフォントには,
5336 \texttt{U+E0100}--\texttt{U+E01EF}の範囲の「文字」
5337 (漢字用異体字セレクタ)を後置することによって
5338 字形を指定する仕組み(IVS)が含まれている.
5339 執筆時点の2013年12月では,\Pkg{luaotfload}や\Pkg{fontspec}パッケージ類は
5340 IVSに対応してはいないようである.これらのパッケージで対応してくれるのが理想的だが,
5341 それまでのつなぎとして,\Pkg{luatexja-otf}パッケージ内にIVS対応を仕込んでおいた.
5342
5343 \medskip
5344
5345 \emph{IVS対応は試験的なものである.
5346 有効にするには,\Pkg{luatexja-otf}パッケージを読み込んだ上で以下の命令を実行する%
5347 \footnote{この命令を2回以上実行しても意味がない.}:}
5348 %</ja>
5349 \begin{verbatim}
5350 \directlua{luatexja.otf.enable_ivs()}
5351 \end{verbatim}
5352 %<ja> すると,上の命令を実行した箇所以降では,以下のようにIVSによる字形指定が有効となる.
5353 %<en> After executing the command above, you can use IVS like the following:
5354 \begin{LTXexample}
5355 \Large
5356 \jfontspec{KozMinPr6N-Regular}
5357 奈良県葛󠄀城市と,東京都葛󠄁飾区.\\
5358 こんにちは,渡
5359 邉󠄀邉󠄁邉󠄂邉󠄃邉󠄄
5360 邉󠄅邉󠄆邉󠄇邉󠄈邉󠄉
5361 邉󠄊邉󠄋邉󠄌邉󠄍邉󠄎
5362 さん.
5363 \end{LTXexample}
5364 %<*ja>
5365 左上側の入力においては,漢字用異体字セレクタを明示するため,
5366 例えばVariation~Selector~18 (\texttt{U+E0101})を\IVSB{18}のように表記している.
5367 %</ja>
5368 \medskip
5369
5370 %<*en>
5371 Specifying glyph variants by IVS precedes glyph replacement by font features.
5372 For example, only ``葛'' in ``葛西'' is changed by font features
5373 \texttt{jp78}~or~\texttt{jp90}, which does not followed by any variation selector.
5374 %</en>
5375 %<*ja>
5376 また,IVSによる字形指定は,font featureによるそれに優先されることとした.
5377 下の例において,\texttt{jp78}, \texttt{jp90} 指定で字形が変化した文字は
5378 異体字セレクタが続いていない「葛西」中の「葛」のみである.
5379 %</ja>
5380 \begin{LTXexample}
5381  \def\TEST#1{%
5382    {\jfontspec[#1]{KozMinPr6N-Regular}%
5383    葛󠄀城市,葛󠄁飾区,葛西}\\}
5384  指定なし:\TEST{}
5385  \texttt{jp78}:\TEST{CJKShape=JIS1978}
5386  \texttt{jp90}:\TEST{CJKShape=JIS1990}
5387 \end{LTXexample}
5388
5389 %<*ja>
5390 現状では,\TeX 側のインターフェースとなる \Pkg{luatexja-otf.sty} は一切変更していない
5391 ので,ZRさんによる\Pkg{PXipamjm}パッケージ%
5392 \footnote{\url{https://github.com/zr-tex8r/PXipamjm}. 説明は彼のブログ記事
5393 「pxipamjm パッケージの説明書のような何か(\url{http://d.hatena.ne.jp/zrbabbler/20131221})」
5394 にある.}
5395 にあるような気の利いた命令はまだない.
5396 異体字の一覧表示を行いたい場合は,gitリポジトリ内の \texttt{test/test19-ivs.tex} 中にある
5397 Lua・\TeX コードが参考になるだろう.
5398 %</ja>
5399
5400
5401 \subsection{\texttt{luatexja-adjust.sty}}
5402 \label{ssec-adj}
5403 \begin{figure}[t]
5404 \def\sq{%
5405   \hbox to 1\zw{\hss\fboxsep=-.5\fboxrule\fbox{%
5406    \hskip\dimexpr-.5\zw-.2pt\vrule width.4pt height.08\zw depth.12\zw%
5407   \hskip\dimexpr.5\zw-.2pt\relax}\hss}}
5408 \def\sb{\hbox to 1\zw{\hss\fboxsep=-.5\fboxrule\fbox{%
5409   ■\hskip\dimexpr-.5\zw-.2pt\vrule width.4pt height.08\zw depth.12\zw%
5410   \hskip\dimexpr.5\zw-.2pt\relax}\hss}}
5411 \newbox\gridbox
5412 \def\outbox#1{{\Large%
5413   \ltjsetparameter{kanjiskip=0pt plus .2\zw minus .2\zw}%
5414   \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}%
5415   \hbox{\textcolor{cyan!50!white}{\copy\gridbox}\hskip-20\zw%
5416   \vbox{\hsize=20\zw\noindent\leftskip0pt\rightskip0pt\parfillskip0pt#1}\vrule}%
5417 }}
5418
5419 {\centering
5420 \begin{tabular}{lc}
5421 \toprule
5422 no adjustment&\outbox{以上の原理は,「包除原理」とよく呼ばれるが\hskip-.5\zw\null}\\
5423 without priority&%
5424 \ltjdisableadjust
5425 \outbox{以上の原理は,「包除原理」とよく呼ばれるが}%
5426 \ltjenableadjust\\
5427 with priority&%
5428 \outbox{以上の原理は,「包除原理」とよく呼ばれるが}
5429 %<en>\ltjdisableadjust
5430 \\
5431 \bottomrule
5432 \end{tabular}\par}
5433 \smallskip
5434
5435 Note: the value of
5436 \Param{kanjiskip} is 0\,pt${}^{+1/5\,\mathrm{em}}_{-1/5\,\mathrm{em}}$ in this figure,
5437 for making the difference obvious.
5438 %<ja>\caption{行長調整}\label{fig-adj}
5439 %<en>\caption{Line adjustment}\label{fig-adj}
5440 \end{figure}
5441
5442
5443 %<*en>
5444 (see Japanese version of this manual)
5445 %</en>
5446 %<*ja>
5447 \pTeX では,行長調整において優先度の概念が存在しなかったため,図
5448 \ref{fig-adj}上段における半角分の半端は,図\ref{fig-adj}中段のように,鍵
5449 括弧周辺の空白と和文間空白(\Param{kanjiskip})の両方によって負担される.し
5450 かし,「日本語組版処理の要件」\cite{jlreq}やJIS~X~4051~\cite{x4051}におい
5451 ては,このような状況では半端は鍵括弧周辺の空白のみで負担し,その他の和文
5452 文字はベタ組で組まれる(図\ref{fig-adj}下段)ことになっている.この追加
5453 パッケージは\cite{jlreq}や\cite{x4051}における規定のような,優先順位付き
5454 の行長調整を提供する.詳細な仕様については\ref{sec-adjspec}章を参照してほしい.
5455 \begin{itemize}
5456  \item 優先度付き行長調整は,段落を行分割した後に個々の行について行われるものである.
5457 そのため,行分割の位置は変化することはない.
5458
5459 また,\verb+\hbox to ... {...}+ のような「幅が指定されたhbox」では無効である.
5460  \item 優先度付き行長調整を行うと,和文処理グルーの自然長は変化しないが,伸び量や縮み量は
5461 一般に変化する.そのため,既に組まれた段落を \verb+\unhbox+ などを利用して組み直す処理を
5462 行う場合には注意が必要である.
5463 \end{itemize}
5464
5465
5466 \Pkg{luatexja-adjust} は,以下の命令を提供する.これらはすべてグローバルに効力を発揮する.
5467
5468 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}\advance\leftmargin1\zw}
5469 \item[\textbackslash ltjdisableadjust]
5470 優先順位付きの行長調整を無効化する.
5471
5472 \item[\textbackslash ltjenableadjust]
5473 優先順位付きの行長調整を有効化する.
5474
5475 \item[\textsf{adjust}\,=<bool>] \verb+\ltjsetparameter+ で指定可能な追加パラメータであり,
5476 <bool>が\textit{true}なら \verb+\ltjenableadjust+ を,
5477 そうでなければ \verb+\ltjdisableadjust+ を実行する.
5478 \end{list}
5479 %</ja>
5480
5481 \subsection{\texttt{luatexja-ruby.sty}}
5482 %<*en>
5483 This addon package provides functionality of ``ruby'' (\emph{furigana}) annotations
5484 using callbacks of \LuaTeX-ja.
5485 There is no detailed manual of \Pkg{luatexja-ruby.sty} in English.
5486 (Japanese manual is another PDF file, \url{luatexja-ruby.pdf}.)
5487 %</en>
5488 %<*ja>
5489 この追加パッケージは,\LuaTeX-jaの機能を利用したルビ(振り仮名)の組版機能を提供する.
5490 前後の文字種に応じた前後への自動進入や,
5491 行頭形・行中形・行末形の自動的な使い分けが特徴である.
5492
5493 ルビ組版に設定可能な項目や注意事項が多いため,本追加パッケージの詳細な説明は
5494 使用例と共に \url{luatexja-ruby.pdf}\ という別ファイルに載せている.
5495 この節では簡単な使用方法のみ述べる.
5496 %</ja>
5497
5498 \begin{description}
5499 %<*en>
5500  \item[Group-ruby]
5501 By default, ruby characters (the second argument of \verb+\ruby+)
5502 are attached to base characters (the first argument), as one object.
5503 This type of ruby is called \emph{group-ruby}.
5504 %</en>
5505 %<*ja>
5506  \item[グループルビ] 標準ではグループルビの形で組まれる.第1引数に親文字,
5507 第2引数にルビを記述する.
5508 %</ja>
5509 \begin{LTXexample}[width=0.3\textwidth]
5510 東西線\ruby{妙典}{みようでん}駅は……\\
5511 東西線の\ruby{妙典}{みようでん}駅は……\\
5512 東西線の\ruby{妙典}{みようでん}という駅……\\
5513 東西線\ruby{葛西}{かさい}駅は……
5514 \end{LTXexample}
5515 %<*en>
5516 As the above example, ruby hangover is allowed on the Hiragana before/after
5517 its base characters.
5518 %</en>
5519 %<ja> この例のように,標準では前後の平仮名にルビ全角までかかるようになっている.
5520
5521 %<*en>
5522 \item[Mono-ruby]
5523 To attach ruby characters to each base characters (\emph{mono-ruby}),
5524 one should use \verb+\ruby+ multiple times:
5525 %</en>
5526 %<*ja>
5527  \item[モノルビ] 親文字を1文字にするとモノルビとなる.
5528 2文字以上の熟語をモノルビの形で組みたい場合は,面倒でも
5529 その数だけ \verb+\ruby+ を書く必要がある.
5530 %</ja>
5531 \begin{LTXexample}[width=0.3\textwidth]
5532 東西線の\ruby{妙}{みよう}\ruby{典}{でん}駅は……
5533 \end{LTXexample}
5534
5535 %<*en>
5536  \item[Jukugo-ruby]
5537 Vertical bar~\verb+|+ denotes a boundary of \emph{groups}.
5538 %</en>
5539 %<*ja>
5540  \item[熟語ルビ] 引数内の縦棒 \verb+|+ はグループの区切りを表し,
5541 複数グループのルビは熟語ルビとして組まれる.
5542 \cite{x4051}にあるように,
5543 どのグループでも「親文字」が対応するルビ以上の長さの場合は
5544 各グループごとに,そうでないときは全体をまとめて1つのグループルビとして組まれる.
5545 \cite{jlreq}で規定されている組み方とは異なるので注意.
5546 %</ja>
5547 \begin{LTXexample}
5548 \ruby{妙|典}{みよう|でん}\
5549 \ruby{葛|西}{か|さい}\
5550 \ruby{神楽|坂}{かぐら|ざか}
5551 \end{LTXexample}
5552 %<*en>
5553 If there are multiple groups in one \verb+\ruby+ call,
5554 A linebreak between two groups is allowed.
5555 %</en>
5556 %<ja> 複数ルビではグループとグループの間で改行が可能である.
5557 \begin{LTXexample}[width=0.3\textwidth]
5558 \vbox{\hsize=6\zw\noindent
5559   \hbox to 2.5\zw{}\ruby{京|急|蒲|田}{けい|きゆう|かま|た}
5560   \hbox to 2.5\zw{}\ruby{京|急|蒲|田}{けい|きゆう|かま|た}
5561   \hbox to   3\zw{}\ruby{京|急|蒲|田}{けい|きゆう|かま|た}
5562 }
5563 \end{LTXexample}
5564 \end{description}
5565
5566 %<*en>
5567 If the width of ruby characters are longer than that of base characters,
5568 \verb+\ruby+ automatically selects the appropriate form
5569 among the line-head form, the line-middle form, and the line-end form.
5570 %</en>
5571 %<*ja>
5572 また,ルビ文字のほうが親文字よりも長い場合は,自動的に
5573 行頭形・行中形・行末形のいずれか適切なものを選択する.
5574 %</ja>
5575 \begin{LTXexample}[width=0.3\textwidth]
5576 \vbox{\hsize=8\zw\noindent
5577 \null\kern3\zw ……を\ruby{承}{うけたまわ}る
5578      \kern1\zw ……を\ruby{承}{うけたまわ}る\\
5579 \null\kern5\zw ……を\ruby{承}{うけたまわ}る
5580 }
5581 \end{LTXexample}
5582
5583
5584
5585
5586
5587
5588 %<en>\part{Implementations}
5589 %<ja>\part{実装}
5590 \label{part-imp}
5591 %<en>\section{Storing Parameters}
5592 %<ja>\section{パラメータの保持}
5593 \label{sec-para}
5594 %<en>\subsection{Used Dimensions, Attributes and Whatsit Nodes}
5595 %<ja>\subsection{\LuaTeX-jaで用いられるレジスタとwhatsitノード}
5596
5597 %<*en>
5598 Here the following is the list of dimensions and attributes which are used in \LuaTeX-ja.
5599 %</en>
5600 %<*ja>
5601 以下は\LuaTeX-jaで用いられる寸法レジスタ(dimension),属性レジスタ(attribute)の
5602 リストである.
5603 %</ja>
5604 \begin{list}{}{%
5605 \def\makelabel{\ttfamily}\advance\leftmargin1\zw
5606 \def\dim#1{\item[\textbackslash #1\ \textrm{(dimension)}]}
5607 \def\cnt#1{\item[\textbackslash #1\ \textrm{(counter)}]}
5608 \def\attr#1{\item[\textbackslash #1\ \textrm{(attribute)}]}
5609 }
5610
5611 \dim{jQ}
5612 %<*en>
5613 \verb+\jQ+ is equal to
5614                         $1\,\textrm{Q}=0.25\,\textrm{mm}$, where ``Q''~(also called ``級'') is
5615                         a unit used in Japanese phototypesetting.
5616 So one should not change the value of this dimension.
5617 %</en>
5618 %<*ja>
5619 \verb+\jQ+ は写植で用いられた$1\,\textrm{Q}=0.25\,\textrm{mm}$%
5620 (「級」とも書かれる)に等しい.したがって,
5621 この寸法レジスタの値を変更してはならない.
5622 %</ja>
5623
5624 \dim{jH}
5625 %<*en>
5626 There is also a unit called ``歯'' which equals to $0.25\,\textrm{mm}$ and
5627                          used in Japanese phototypesetting.
5628 This \verb+\jH+ is the same \verb+\dimen+ register as \verb+\jQ+.
5629 %</en>
5630 %<*ja>
5631 同じく写植で用いられていた単位として「歯」があり,これも$0.25\,\textrm{mm}$と
5632 等しい.この \verb+\jH+ は \verb+\jQ+ と同じ寸法レジスタを指す.
5633 %</ja>
5634
5635 \dim{ltj@zw}
5636 %<*en>
5637 A temporal register for the ``full-width'' of current Japanese font.
5638 The command \verb+\zw+ sets this register to the correct value, and
5639 ``return'' this register itself.
5640 %</en>
5641 %<*ja>
5642 現在の和文フォントの「全角幅」を保持する一時レジスタ.
5643 \verb+\zw+ 命令は,このレジスタを適切な値に設定した後,
5644 「このレジスタ自体を返す」.
5645 %</ja>
5646
5647 \dim{ltj@zh}
5648 %<*en>
5649 A temporal register for the ``full-height'' (usually the sum of height of imaginary body and its depth) of current Japanese font.
5650 The command \verb+\zh+ sets this register to the correct value, and
5651 ``return'' this register itself.
5652 %</en>
5653 %<*ja>
5654 現在の和文フォントの「全角高さ」(通常,高さと深さの和)を保持する一時レジスタ.
5655 \verb+\zh+ 命令は,このレジスタを適切な値に設定した後,
5656 「このレジスタ自体を返す」.
5657 %</ja>
5658
5659 \attr{jfam}
5660 %<*en>
5661 Current number of Japanese font family for math formulas.
5662 %</en>
5663 %<*ja>
5664 数式用の和文フォントファミリの現在の番号.
5665 %</ja>
5666
5667 \attr{ltj@curjfnt}
5668 %<*en>
5669 The font index of current Japanese font for horizontal direction.
5670 %</en>
5671 %<*ja>
5672 現在の横組用和文フォントのフォント番号.
5673 %</ja>
5674
5675 \attr{ltj@curtfnt}
5676 %<*en>
5677 The font index of current Japanese font for vertical direction.
5678 %</en>
5679 %<*ja>
5680 現在の縦組用和文フォントのフォント番号.
5681 %</ja>
5682
5683 \attr{ltj@charclass}
5684 %<*en>
5685 The character class of Japanese \textit{glyph\_node}.
5686 %</en>
5687 %<*ja>
5688 和文文字の\textit{glyph\_node}の文字クラス.
5689 %</ja>
5690
5691 \attr{ltj@yablshift}
5692 %<*en>
5693 The amount of shifting the baseline of alphabetic fonts in scaled point ($2^{-16}\,\textrm{pt}$).
5694 %</en>
5695 %<*ja>
5696 スケールド・ポイント($2^{-16}\,\textrm{pt}$)を単位とした欧文フォントのベースラインの移動量.
5697 %</ja>
5698
5699 \attr{ltj@ykblshift}
5700 %<*en>
5701 The amount of shifting the baseline of Japanese fonts in scaled point ($2^{-16}\,\textrm{pt}$).
5702 %</en>
5703 %<*ja>
5704 スケールド・ポイント($2^{-16}\,\textrm{pt}$)を単位とした和文フォントのベースラインの移動量.
5705 %</ja>
5706
5707 \attr{ltj@tablshift}
5708 \attr{ltj@tkblshift}
5709
5710 \attr{ltj@autospc}
5711 %<*en>
5712 Whether the auto insertion of \Param{kanjiskip} is allowed at the node.
5713 %</en>
5714 %<*ja>
5715 そのノードで\Param{kanjiskip}の自動挿入が許されるかどうか.
5716 %</ja>
5717
5718 \attr{ltj@autoxspc}
5719 %<*en>
5720 Whether the auto insertion of \Param{xkanjiskip} is allowed at the node.
5721 %</en>
5722 %<*ja>
5723 そのノードで\Param{xkanjiskip}の自動挿入が許されるかどうか.
5724 %</ja>
5725
5726 \attr{ltj@icflag}
5727 %<*en>
5728 An attribute for distinguishing ``kinds'' of a node. One of the following value is
5729 assigned to this attribute:
5730 %</en>
5731 %<*ja>
5732 ノードの「種類」を区別するための属性.以下のうちのひとつが値として割り当てられる:
5733 %</ja>
5734 \begin{description}
5735 \item[\textit{italic} (1)]
5736 %<*en>
5737 Kerns from italic correction (\verb+\/+), or from kerning information of a Japanese font.
5738 These kerns are ``ignored'' in the insertion process of \textbf{JAglue},
5739 unlike explicit \verb+\kern+.
5740 %</en>
5741 %<*ja>
5742 イタリック補正(\verb+\/+)によるカーン,
5743 または \Pkg{luaotfload} によって挿入されたフォントのカーニング情報由来のカーン.
5744 これらのカーンは通常の \verb+\kern+ とは異なり,
5745 \textbf{JAglue}の挿入処理においては透過する.
5746 %</ja>
5747
5748 \item[\textit{packed} (2)]
5749
5750 \item[\textit{kinsoku} (3)]
5751 %<*en>
5752 Penalties inserted for the word-wrapping process (\emph{kinsoku shori}) of Japanese characters.
5753 %</en>
5754 %<ja>禁則処理のために挿入されたペナルティ.
5755 \item[\mathversion{bold}$(\textit{from\_jfm}-2)$--$(\textit{from\_jfm}+2)$~(4--8)]
5756 %<en>Glues/kerns from JFM.
5757 %<ja>JFM由来のグルー/カーン.
5758 \item[\textit{kanji\_skip}~(9), \textit{kanji\_skip\_jfm}~(10)]
5759 %<en>Glues from \Param{kanjiskip}.
5760 %<ja>和文間空白\Param{kanjiskip}を表すグルー.
5761 \item[\textit{xkanji\_skip}~(11), \textit{xkanji\_skip\_jfm}~(12)]
5762 %<en>Glues from \Param{xkanjiskip}.
5763 %<ja>和欧文間空白\Param{xkanjiskip}を表すグルー.
5764 \item[\textit{processed} (13)]
5765 %<en>Nodes which is already processed by \ldots.
5766 %<ja>\LuaTeX-ja の内部処理によって既に処理されたノード.
5767 \item[\textit{ic\_processed} (14)]
5768 %<*en>
5769 Glues from an italic correction, but already processed in the insertion process of \textbf{JAglue}s.
5770 %</en>
5771 %<ja>イタリック補正に由来するグルーであって,既に \textbf{JAglue} 挿入処理にかかったもの.
5772 \item[\textit{boxbdd} (15)]
5773 %<en>Glues/kerns that inserted just the beginning or the ending of an hbox or a paragraph.
5774 %<ja>hboxか段落の最初か最後に挿入されたグルー/カーン.
5775 \end{description}
5776
5777 %<*ja>
5778 また,挿入処理の結果であるリストの最初のノードでは,\verb+\ltj@icflag+ の値に
5779 \textit{processed\_begin\_flag}~(128)が追加される.これによって,\verb+\unhbox+ が
5780 連続した場合でも「ボックスの境界」が識別できるようになっている.
5781 %</ja>
5782
5783 \attr{ltj@kcat$i$}
5784 %<*en>
5785 Where $i$~is a natural number which is less than~7.
5786 These 7~attributes store bit~vectors indicating which character block is regarded as a block of \textbf{JAchar}s.
5787 %</en>
5788 %<*ja>
5789 $i$は7より小さい自然数.
5790 これら7つの属性レジスタは,どの文字ブロックが\textbf{JAchar}のブロックとして
5791 扱われるかを示すビットベクトルを格納する.
5792 %</ja>
5793
5794 \attr{ltj@dir}
5795 %<*ja>
5796 ボックスにおける組方向を示す.通常のボックスでは
5797 \begin{description}
5798 \item[\textit{dir\_dtou} (1)]
5799 \item[\textit{dir\_tate} (3)]
5800 \item[\textit{dir\_yoko} (4)]
5801 \end{description}
5802 のいずれかに次を加えた値(17,~19, 20, 33, 35,~36)をとるボックスが作られることもあ
5803                          る(\ref{sec-dir-imp}章参照).
5804 %</ja>
5805 \begin{description}
5806 \item[\textit{dir\_node\_auto} (16)]
5807 %<ja> 異なる組方向に配置するために自動的に作られたボックス.
5808 \item[\textit{dir\_node\_manual} (32)]
5809 %<ja> \verb+\ltjsetwd+ によって「ボックスの本来の組方向とは異なる組方向での寸法」を
5810 %<ja> 設定したときに,それを記録するためのボックス.
5811 \end{description}
5812 %<ja> \TeX 側から見える値,つまり \verb+\the\ltj@dir+ の値は常に0である.
5813
5814 \end{list}
5815
5816 %<*en>
5817 Furthermore, \LuaTeX-ja uses several user-defined whatsit nodes for
5818 internal processing. All those nodes except \emph{direction} whatsits
5819 store a natural number (hence its \texttt{type} is 100).
5820 \emph{direction} whatsits store a node list, hence its \texttt{type} is 110.
5821 Their \texttt{user\_id} (used for distinguish user-defined whatsits)
5822 are allocated by \texttt{luatexbase.newuserwhatsitid}.
5823 %</en>
5824 %<*ja>
5825 さらに,\LuaTeX-jaはいくつかのuser-defined whatsit nodeを内部処理に用いる.
5826 \textit{direction} whatsitはノードリストを格納するが,
5827 それ以外のwhatsitノードの \texttt{type} は100であり,ノードは自然数を格納している.
5828 user-defined whatsitを識別するための \texttt{user\_id} は\
5829 \texttt{luatexbase.newuserwhatsitid} により確保されており,
5830 下の見出しは単なる識別用でしかない.
5831 %</ja>
5832 \begin{description}
5833 \item[\textit{inhibitglue}]
5834 %<*en>
5835 Nodes for indicating that \verb+\inhibitglue+ is
5836            specified. The \texttt{value} field of these nodes doesn't matter.
5837 %</en>
5838 %<*ja>
5839 \verb+\inhibitglue+ が指定されたことを示すノード.これらのノードの\
5840 \texttt{value} フィールドは意味を持たない.
5841 %</ja>
5842
5843 \item[\textit{stack\_marker}]
5844 %<*en>
5845 Nodes for \LuaTeX-ja's stack system (see the next
5846            subsection). The \texttt{value} field of these nodes is
5847            current group level.
5848 %</en>
5849 %<*ja>
5850 \LuaTeX-jaのスタックシステム(次の節を参照)のためのノード.
5851 これらのノードの \texttt{value} フィールドは現在のグループネストレベルを表す.
5852 %</ja>
5853
5854 \item[\textit{char\_by\_cid}]
5855 %<*en>
5856 Nodes for \textbf{JAchar} which the callback process of
5857            \Pkg{luaotfload} won't be applied, and the character code is
5858            stored in the \texttt{value} field. Each node of this type are
5859            converted to a \textit{glyph\_node} \emph{after}
5860            the callback process of luaotfload.
5861 Nodes of this type is used in \verb+\CID+, \verb+\UTF+ and IVS support.
5862 %</en>
5863 %<*ja>
5864 \Pkg{luaotfload}のコールバックによる処理が適用されない\textbf{JAchar}のためのノードで,
5865 \texttt{value} フィールドに文字コードが格納されている.
5866 この種類のノードはそれぞれが\Pkg{luaotfload}のコールバックの処理の
5867 \emph{後で}\textit{glyph\_node}に変換される.
5868 \verb+\CID+, \verb+\UTF+やIVS対応処理でこの種類のノードが利用されている.
5869 %</ja>
5870
5871 \item[\textit{replace\_vs}]
5872 %<*en>
5873 Similar to \textit{char\_by\_cid} whatsits above.
5874 These nodes are for \textbf{ALchar} which the callback process of
5875            \Pkg{luaotfload} won't be applied.
5876 %</en>
5877 %<*ja>
5878 上の\textit{char\_by\_cid}と同様に,
5879 これらのノードは\Pkg{luaotfload}のコールバックによる処理が適用されない\textbf{ALchar}のた
5880            めものである.
5881 %</ja>
5882
5883 \item[\textit{begin\_par}]
5884 %<*en>
5885 Nodes for indicating beginning of a paragraph.
5886 A paragraph which is started by \verb+\item+ in list-like environments has a horizontal box
5887 for its label before the actual contents. So \dots
5888 %</en>
5889 %<*ja>
5890 「段落の開始」を意味するノード.
5891 list環境,itemize環境などにおいて,\verb+\item+ で始まる各項目は……
5892 %</ja>
5893
5894 \item[\textit{direction}]
5895
5896 \end{description}
5897
5898 %<*en>
5899 These whatsits will be removed during the process of inserting \textbf{JAglue}s.
5900 %</en>
5901 %<*ja>
5902 これらのwhatsitノードは\textbf{JAglue}の挿入処理の間に取り除かれる.
5903 %</ja>
5904
5905 %<en>\subsection{Stack System of \LuaTeX-ja}
5906 %<ja>\subsection{\LuaTeX-jaのスタックシステム}
5907 \label{ssec-stack}
5908
5909 %<en>\paragraph{Background}
5910 %<ja>\paragraph{背景}
5911 %<*en>
5912 \LuaTeX-ja has its own stack system, and most parameters of \LuaTeX-ja
5913 are stored in it. To clarify the reason, imagine the parameter
5914 \Param{kanjiskip} is stored by a skip, and consider the following
5915 source:
5916 %</en>
5917 %<*ja>
5918 \LuaTeX-jaは独自のスタックシステムを持ち,\LuaTeX-jaのほとんどのパラメータは
5919 これを用いて保持されている.その理由を明らかにするために,
5920 \Param{kanjiskip}パラメータがスキップレジスタで保持されているとし,
5921 以下のコードを考えてみよう:
5922 %</ja>
5923 \begin{LTXexample}
5924 \ltjsetparameter{kanjiskip=0pt}ふがふが.%
5925 \setbox0=\hbox{%
5926   \ltjsetparameter{kanjiskip=5pt}ほげほげ}
5927 \box0.ぴよぴよ\par
5928 \end{LTXexample}
5929
5930 %<*en>
5931 As described in Subsection~\ref{ssec-param}, the only effective value of
5932 \Param{kanjiskip} in an hbox is the latest value, so the value of
5933 \Param{kanjiskip} which applied in the entire hbox should be 5\,pt.
5934 However, by the implementation method of \LuaTeX, this ``5\,pt'' cannot be
5935 known from any callbacks.  In the \texttt{tex/packaging.w}, which is a
5936 file in the source of \LuaTeX, there are the following codes:
5937 %</en>
5938 %<*ja>
5939 \ref{ssec-param}節で述べたように,あるhboxの中で効力を持つ
5940 \Param{kanjiskip}の値は最後に現れた値のみであり,したがってボックス全体に適用される
5941 \Param{kanjiskip}は5\,ptであるべきである.しかし,\LuaTeX の実
5942 装を観察すると,この5\,ptという長さはどのコールバックからも知ることはできないことがわかる.
5943 \LuaTeX のソースファイルの1つ \texttt{tex/packaging.w} の中に,
5944 以下のコードがある:
5945 %</ja>
5946 \begin{lstlisting}[numbers=left,firstnumber=1226]
5947 void package(int c)
5948 {
5949     scaled h;                   /* height of box */
5950     halfword p;                 /* first node in a box */
5951     scaled d;                   /* max depth */
5952     int grp;
5953     grp = cur_group;
5954     d = box_max_depth;
5955     unsave();
5956     save_ptr -= 4;
5957     if (cur_list.mode_field == -hmode) {
5958         cur_box = filtered_hpack(cur_list.head_field,
5959                                  cur_list.tail_field, saved_value(1),
5960                                  saved_level(1), grp, saved_level(2));
5961         subtype(cur_box) = HLIST_SUBTYPE_HBOX;
5962 \end{lstlisting}
5963 %<*en>
5964 Notice that \texttt{unsave()} is executed \emph{before}
5965 \texttt{filtered\_hpack()}, where \texttt{hpack\_filter} callback is
5966 executed) here. So ``5\,pt'' in the above source is orphaned at
5967 \texttt{unsave()}, and hence it can't be accessed from \texttt{hpack\_filter}
5968 callback.
5969 %</en>
5970 %<*ja>
5971 \texttt{unsave()} が \texttt{filtered\_hpack()}(これは \texttt{hpack\_filter} コールバックが
5972 実行されるところである)の\emph{前に}実行されていることに注意する.
5973 したがって,上記ソース中で5\,ptは \texttt{unsave()} のところで捨てられ,
5974 \texttt{hpack\_filter} コールバックからはアクセスすることができない.
5975 %</ja>
5976
5977 %<en>\paragraph{Implementation}
5978 %<ja>\paragraph{解決法}
5979
5980 %<*en>
5981 The code of stack system is based on that in a post of Dev-luatex mailing list\footnote{%
5982 \texttt{[Dev-luatex] tex.currentgrouplevel}, a post at 2008/8/19 by Jonathan Sauer.}.
5983 %</en>
5984 %<*ja>
5985 スタックシステムのコードはDev-luatexメーリングリストのある投稿\footnote{%
5986 \texttt{[Dev-luatex] tex.currentgrouplevel}: Jonathan Sauerによる2008/8/19の投稿.}を
5987 ベースにしている.
5988 %</ja>
5989
5990 %<*en>
5991 These are two \TeX\ count registers for maintaining information:
5992 \verb+\ltj@@stack+ for the stack level, and \verb+\ltj@@group@level+ for
5993 the \TeX's group level when the last assignment was done.  Parameters
5994 are stored in one big table named \texttt{charprop\_stack\_table}, where
5995 \texttt{charprop\_stack\_table[$i$]} stores data of stack level~$i$. If
5996 a new stack level is created by \verb+\ltjsetparameter+, all data of the
5997 previous level is copied.
5998 %</en>
5999 %<*ja>
6000 情報を保持するために,2つの\TeX の整数レジスタを用いている:
6001 \verb+\ltj@@stack+ にスタックレベル,\verb+\ltj@@group@level+ に最後の代入が
6002 なされた時点での\TeX のグループレベルを保持している.
6003 パラメータは\texttt{charprop\_stack\_table}という名前のひとつの大きなテーブルに
6004 格納される.ここで,\texttt{charprop\_stack\_table[$i$]}はスタックレベル$i$の
6005 データを格納している.もし新しいスタックレベルが \verb+\ltjsetparameter+ によって
6006 生成されたら,前のレベルの全てのデータがコピーされる.
6007 %</ja>
6008
6009 %<*en>
6010 To resolve the problem mentioned in above paragraph ``Background'', \LuaTeX-ja uses
6011 another trick. When the stack level is about to be increased, a whatsit
6012 node whose type, subtype and value are 44~(\textit{user\_defined}),
6013 \textit{stack\_marker} and the current group level respectively is appended to the current
6014 list (we refer this node by \textit{stack\_flag}). This enables us to
6015 know whether assignment is done just inside a hbox. Suppose that the
6016 stack level is~$s$ and the \TeX's group level is~$t$ just after the hbox
6017 group, then:
6018 %</en>
6019 %<*ja>
6020 上の「背景」で述べた問題を解決するために,\LuaTeX-jaでは次の手法を用いる:
6021 スタックレベルが増加するするとき,type, subtype, valueがそれぞれ
6022 44~(\textit{user\_defined}), \textit{stack\_marker},そして現在のグループレベルであるwhatsitノード
6023 を現在のリストに付け加える(このノードを\textit{stack\_flag}とする).
6024 これにより,あるhboxの中で代入がなされたかどうかを知ることが可能
6025 となる.スタックレベルを$s$,そのhbox groupの直後の\TeX のグループレベルを
6026 $t$とすると:
6027 %</ja>
6028 \begin{itemize}
6029 %<*en>
6030 \item If there is no \textit{stack\_flag} node in the list of the contents of the hbox, then
6031       no assignment was occurred inside the hbox. Hence values of
6032       parameters at the end of the hbox are stored in the stack
6033       level~$s$.
6034 %</en>
6035 %<*ja>
6036 \item もしそのhboxの中身を表すリストの中に\textit{stack\_flag}ノードがなければ,
6037   hboxの中では代入は起こらなかったということになる.
6038   したがって,そのhboxの終わりにおけるパラメータの値はスタックレベル$s$に
6039   格納されている.
6040 %</ja>
6041
6042 %<*en>
6043 \item If there is a \textit{stack\_flag} node whose value is~$t+1$, then
6044       an assignment was occurred just inside the hbox group. Hence
6045       values of parameters at the end of the hbox are stored in the
6046       stack level~$s+1$.
6047 %</en>
6048 %<*ja>
6049 \item もし値が$t+1$の\textit{stack\_flag}ノードがあれば,その
6050   hboxの中で代入が起こったことになる.
6051   したがって,hboxの終わりにおけるパラメータの値はスタックレベル$s+1$に
6052   格納されている.
6053 %</ja>
6054
6055 %<*en>
6056 \item If there are \textit{stack\_flag} nodes but all of their values
6057       are more than~$t+1$, then an assignment was occurred in the box,
6058       but it is done in more internal group. Hence values of
6059       parameters at the end of the hbox are stored in the stack
6060       level~$s$.
6061 %</en>
6062 %<*ja>
6063 \item もし\textit{stack\_flag}ノードがあるがそれらの値が全て$t+1$より大きい
6064   場合,そのボックスの中で代入が起こったが,それは「より内部の」グループで
6065   起こったということになる.したがって,hboxの終わりでのパラメータの
6066   値はスタックレベル$s$に格納されている.
6067 %</ja>
6068 \end{itemize}
6069
6070 %<*en>
6071 Note that to work this trick correctly, assignments to
6072 \verb+\ltj@@stack+ and \verb+\ltj@@group@level+ have to be local always,
6073 regardless the value of \verb+\globaldefs+.
6074 To solve this problem, we use another trick: the assignment
6075 \hbox{\verb+\directlua{tex.globaldefs=0}+} is always local.
6076 %</en>
6077 %<*ja>
6078 このトリックを正しく働かせるためには,\verb+\ltj@@stack+ と \verb+\ltj@@group@level+ への
6079 代入は \verb+\globaldefs+ の値によらず常にローカルでなければならないことに注意する.
6080 この問題は \hbox{\verb+\directlua{tex.globaldefs=0}+}(この代入は常にローカル)を
6081 用いることで解決している.
6082 %</ja>
6083
6084 %<*en>
6085 \subsection{Lua Functions of the Stack System}
6086 In this subsection, we will see how a user use \LuaTeX-ja's stack system to
6087 store some data which obeys the grouping of \TeX.
6088 %</en>
6089 %<*ja>
6090 \subsection{スタックシステムで使用される関数}
6091 本節では,ユーザが\LuaTeX-jaのスタックシステムを使用して,
6092 \TeX のグルーピングに従うような
6093 独自のデータを取り扱う方法を述べる.
6094 %</ja>
6095
6096 %<*en>
6097 The following function can be used to store data into a stack:
6098 \begin{verbatim}
6099 luatexja.stack.set_stack_table(index, <any> data)
6100 \end{verbatim}
6101 Any values which except \texttt{nil}~and~NaN are usable as \textit{index}.
6102 However, a user should use only negative integers or strings as \textit{index},
6103 since natural numbers are used by \LuaTeX-ja itself.
6104 Also, whether \textit{data} is stored locally or globally
6105 is determined by \texttt{luatexja.isglobal}
6106 (stored globally if and only if \texttt{luatexja.isglobal == 'global'}).
6107 %</en>
6108 %<*ja>
6109 スタックに値を設定するには,以下のLua関数を呼び出せば良い:
6110 \begin{verbatim}
6111 luatexja.stack.set_stack_table(<any> index, <any> data)
6112 \end{verbatim}
6113 直感的には,スタックテーブル中のインデックス\textit{index}の値を\textit{data}にする,という意味である.
6114 \textit{index}の値としては \texttt{nil} とNaN以外の任意の値を使えるが,
6115 自然数は\LuaTeX-jaが使用する(将来の拡張用も含む)ので,
6116 ユーザが使用する場合は負の整数値か文字列の値にすることが望ましい.
6117 また,ローカルに設定されるかグローバルに設定されるかは,\texttt{luatexja.isglobal} の値に依存する
6118 (グローバルに設定されるのは,\texttt{luatexja.isglobal == 'global'} であるちょうどその時).
6119 %</ja>
6120
6121 %<*en>
6122 Stored data can be obtained as the return value of
6123 \begin{verbatim}
6124 luatexja.stack.get_stack_table(index, <any> default, <number> level)
6125 \end{verbatim}
6126 where \textit{level} is the stack level, which is usually the value of \verb+\ltj@@stack+,
6127 and \textit{default} is the default value which will be returned if no values are stored
6128 in the stack table whose level is \textit{level}.
6129 %</en>
6130 %<*ja>
6131 スタックの値は,
6132 \begin{verbatim}
6133 luatexja.stack.get_stack_table(<any> index, <any> default, <number> level)
6134 \end{verbatim}
6135 の戻り値で取得できる.\textit{level}はスタックレベルであり,
6136 通常は \verb+\ltj@@stack+ の値を指定することになるだろう.
6137 \textit{default}はレベル\textit{level}のスタックに値が設定されていなかった場合に
6138 返すデフォルト値である.
6139 %</ja>
6140
6141 \begin{figure}[tb]
6142 \begin{lstlisting}[numbers=left, firstnumber=380]
6143 \protected\def\ltj@setpar@global{%
6144   \relax\ifnum\globaldefs>0\directlua{luatexja.isglobal='global'}%
6145     \else\directlua{luatexja.isglobal=''}\fi
6146 }
6147 \protected\def\ltjsetparameter#1{%
6148   \ltj@setpar@global\setkeys[ltj]{japaram}{#1}\ignorespaces}
6149 \protected\def\ltjglobalsetparameter#1{%
6150   \relax\ifnum\globaldefs<0\directlua{luatexja.isglobal=''}%
6151     \else\directlua{luatexja.isglobal='global'}\fi%
6152   \setkeys[ltj]{japaram}{#1}\ignorespaces}
6153 \end{lstlisting}
6154 %<ja>\caption{パラメータ設定命令の定義}
6155 %<en>\caption{Definiton of parameter setting commands}
6156 \label{fig:setpar-def}
6157 \end{figure}
6158
6159 %<*en>
6160 \subsection{Extending Parameters}
6161 Keys for \verb+\ltjsetparameter+~and~\verb+\ltjgetparameter+ can be extended,
6162 as in \Pkg{luatexja-adjust}.
6163 %</en>
6164 %<*ja>
6165 \subsection{パラメータの拡張}
6166 ここでは,\Pkg{luatexja-adjust}で行なっているように,
6167 \verb+\ltjsetparameter+,~\verb+\ltjgetparameter+に指定可能なキーを追加する方法
6168 を述べる.
6169 %</ja>
6170
6171 %<*en>
6172 \paragraph{Setting parameters}
6173 Figure~\ref{fig:setpar-def} shows the ``most outer'' definition of
6174 two commands,
6175 \verb+\ltjsetparameter+ and \verb+\ltjglobalsetparameter+.
6176 Most important part is the last \verb+\setkeys+,
6177 which is offered by the \Pkg{xkeyval} package.
6178
6179 Hence, to add a key in \verb+\ltjsetparameter+, one only have to add a key
6180 whose prefix is \texttt{ltj} and whose family is \texttt{japaram}, as the following.
6181 \begin{verbatim}
6182 \define@key[ltj]{japaram}{...}{...}
6183 \end{verbatim}
6184
6185 \verb+\ltjsetparameter+~and~\verb+\ltjglobalsetparameter+ automatically sets
6186 \texttt{luatexja.isglobal}. Its meaning is the following.
6187 \begin{align}
6188  \texttt{luatexja.isglobal} =
6189 \begin{cases}
6190  \texttt{'global'}&\text{global}\\
6191  \texttt{''}&\text{local}
6192 \end{cases}
6193 \end{align}
6194 This is determined not only by command name
6195 (\verb+\ltjsetparameter+~or~\verb+\ltjglobalsetparameter+),
6196 but also by the value of \verb+\globaldefs+.
6197 %</en>
6198 %<*ja>
6199 \paragraph{パラメータの設定}
6200 \verb+\ltjsetparameter+ と,\verb+\ltjglobalsetparameter+ の定義は図\ref{fig:setpar-def}の
6201 のようになっている.
6202 本質的なのは最後の \verb+\setkeys+ で,これは\Pkg{xkeyval}パッケージの提供する命令である.
6203
6204 このため,\verb+\ltjsetparameter+ に指定可能なパラメータを追加するには,
6205 <prefix>を \texttt{ltj},<family>を \texttt{japaram} としたキーを
6206 \begin{verbatim}
6207 \define@key[ltj]{japaram}{...}{...}
6208 \end{verbatim}
6209 のように定義すれば良いだけである.
6210 なお,パラメータ指定がグローバルかローカルかどうかを示す \texttt{luatexja.isglobal} が,
6211 \begin{align}
6212  \texttt{luatexja.isglobal} =
6213 \begin{cases}
6214  \texttt{'global'}&\text{パラメータ設定はグローバル}\\
6215  \texttt{''}&\text{パラメータ設定はローカル}
6216 \end{cases}
6217 \end{align}
6218 として自動的にセットされる\footnote{命令が \texttt{\textbackslash ltjglobalsetparameter} かどうかだけでは
6219 なく,実行時の \texttt{\textbackslash globaldefs} の値にも依存して定まる.}.
6220 %</ja>
6221
6222 %<*ja>
6223 \paragraph{パラメータの取得}
6224 一方,\verb+\ltjgetparameter+ はLuaスクリプトによって実装されている.
6225 値を取得するのに追加引数の要らないパラメータについては,\verb+luatexja.unary_pars+\
6226 内に処理内容を記述した関数を定義すれば良い.例えば,Luaスクリプトで
6227 \begin{lstlisting}[numbers=left]
6228 function luatexja.unary_pars.hoge (t)
6229   return 42
6230 end
6231 \end{lstlisting}
6232 を実行すると,\verb+\ltjgetparameter{hoge}+ は \texttt{42} という\emph{文字列}を返す.
6233 関数 \verb+luatexja.unary_pars.hoge+ の引数$t$は,\ref{ssec-stack}節で述べた
6234 \LuaTeX-jaのスタックシステムにおけるスタックレベルである.
6235 戻り値はいかなる値であっても,最終的には文字列として出力されることに注意.
6236
6237 一方,追加引数(\emph{数値しか許容しない})が必要なパラメータについては,
6238 まずLuaスクリプトで処理内容の本体を記述しておく:
6239 \begin{lstlisting}[numbers=left]
6240 function luatexja.binary_pars.fuga (c, t)
6241   return tostring(c) .. ', ' .. tostring(42)
6242 end
6243 \end{lstlisting}
6244 引数$t$は,先に述べた通りのスタックレベルである.一方,引数$c$は\
6245 \verb+\ltjgetparameter+ の第2引数を表す数値である.
6246 しかしこれだけでは駄目で,
6247 \begin{verbatim}
6248 \ltj@@decl@array@param{fuga}
6249 \end{verbatim}
6250 を実行し,\TeX インターフェース側に
6251 「\verb+\ltjgetparameter{fuga}+ は追加引数が必要」ということを通知する必要がある.
6252 %</ja>
6253
6254 %<en>\section{Linebreak after a Japanese Character}
6255 %<ja>\section{和文文字直後の改行}
6256 \label{sec-lbreak}
6257 %<en>\subsection{Reference: Behavior in \pTeX}
6258 %<ja>\subsection{参考:\pTeX の動作}
6259 %<*en>
6260 In~\pTeX, a line break after a Japanese character doesn't emit a space,
6261 since words are not separated by spaces in Japanese writings. However,
6262 this feature isn't fully implemented in \LuaTeX-ja due to the
6263 specification of callbacks in~\LuaTeX. To clarify the difference between
6264 \pTeX~and~\LuaTeX, We briefly describe the handling of a line break in~\pTeX, in
6265 this subsection.
6266
6267 \pTeX's input processor can be described in terms of a finite state
6268 automaton, as that of~\TeX\ in~Section~2.5 of~\cite{texbytopic}. The
6269 internal states are as follows:
6270 \begin{itemize}
6271 \item State~$N$: new line
6272 \item State~$S$: skipping spaces
6273 \item State~$M$: middle of line
6274 \item State~$K$: after a Japanese character
6275 \end{itemize}
6276 The first three states---$N$,~$S$, and~$M$---are as same as \TeX's input
6277 processor.  State~$K$ is similar to state~$M$, and is entered after
6278 Japanese characters.  The diagram of state transitions are indicated in
6279 Figure~\ref{fig-ptexipro}.  Note that \pTeX\ doesn't leave state~$K$
6280 after ``beginning/ending of a group'' characters.
6281 %</en>
6282
6283 %<*ja>
6284 欧文では文章の改行は単語間でしか行わない.そのため,\TeX では,(文字の直後の)改行は
6285 空白文字と同じ扱いとして扱われる.一方,和文ではほとんどどこでも改行が可能なため,
6286 \pTeX では和文文字の直後の改行は単純に無視されるようになっている.
6287
6288 このような動作は,\pTeX が\TeX からエンジンとして拡張されたことによって可能になったことである.
6289 \pTeX の入力処理部は,\TeX におけるそれと同じように,有限オートマトンとして記述することができ,
6290 以下に述べるような4状態を持っている.
6291
6292 \begin{itemize}
6293 \item State~$N$: 行の開始.
6294 \item State~$S$: 空白読み飛ばし.
6295 \item State~$M$: 行中.
6296 \item State~$K$: 行中(和文文字の後).
6297 \end{itemize}
6298 また,状態遷移は,図\ref{fig-ptexipro}のようになっており,図中の数字は
6299 カテゴリーコードを表している.最初の3状態は\TeX の入力処理部と同じであり,
6300 図中から状態$K$と「$j$」と書かれた矢印を取り除けば,\TeX の入力処理部と同
6301 じものになる.
6302
6303 この図から分かることは,
6304 \begin{quote}
6305 行が和文文字(とグループ境界文字)で終わっていれば,改行は無視される
6306 \end{quote}
6307 ということである.
6308 %</ja>
6309
6310 \begin{figure}[!tb]
6311 \let\sp\textvisiblespace\small
6312 \begin{minipage}{.6\textwidth}%
6313 \begin{center}
6314 \unitlength=6.5mm\sf\mathversion{bold}
6315 \begin{tikzpicture}[
6316   ->, auto, shorten >=1pt
6317 ]
6318 \node [shape=rectangle, font=\scriptsize] (init) at (2,7) {start};
6319 \node [shape=circle,draw, fill=blue!20] (newline) at (4,7) {$N$};
6320 \node [shape=circle,draw, fill=blue!20] (midline) at (4,4) {$M$};
6321 \node [shape=circle,draw, fill=blue!20] (skipspc) at (8,7) {$S$};
6322 \node [shape=circle,draw, fill=red!20]  (kanji) at (8,4) {$K$};
6323 \node [shape=rectangle,draw, fill=green!20] (scanacs) at (6,8) {scan a c.s.};
6324 \node (endk) at (8,2.5) {} ;
6325 \node (endm) at (4,2.5) {} ;
6326 \node (ends) at (8,8.5) {} ;
6327 \node (endn) at (4,8.5) {} ;
6328 \begin{scope}[font=\scriptsize]
6329 \path (newline) edge [bend right]    node [left]{G, O} (midline)
6330       (init)    edge                 node {} (newline)
6331       (midline) edge [bend right=10] node {10} (skipspc)
6332       (skipspc) edge [bend right]    node [left,right=10,above=7]{G, O} (midline)
6333       (skipspc) edge [loop right]    node {10} (skipspc)
6334       (newline) edge [loop right]    node {10} (newline)
6335       (scanacs) edge [bend left]     node [left=3,below]{$(*)$} (skipspc)
6336       (scanacs) edge [bend right]    node [right=30,above=20]{$(*)$} (midline)
6337       (midline) edge                 node {5\ [\sp]} (endm)
6338       (midline) edge [loop left]     node {G, O} (midline)
6339       (skipspc) edge                 node [right] {5} (ends)
6340       (newline) edge                 node {5 [{\tt\textbackslash par}]} (endn);
6341 \begin{scope}[red]
6342 \path (newline) edge [bend right]    node [right=25,below=3]{J} (kanji)
6343       (midline) edge                 node [below]{J} (kanji)
6344       (kanji)   edge [bend left]     node {O} (midline)
6345       (kanji)   edge                 node {10} (skipspc)
6346       (kanji)   edge [loop right]    node {G, J} (kanji)
6347       (skipspc) edge [bend left]     node {J} (kanji)
6348       (kanji)   edge                 node {5} (endk)
6349 ;
6350 \end{scope}
6351 \end{scope}
6352 \end{tikzpicture}
6353 \end{center}
6354 \end{minipage}%
6355 \begin{minipage}{.4\textwidth}
6356 \begin{description}
6357 \item[\textsf{G}] Beginning of group (usually \verb+{+)\\
6358  and ending of group (usually \verb+}+).
6359 \item[\textsf{J}] Japanese characters.
6360 \item[\textsf{5}] \textit{end-of-line} (usually \verb+^+\verb+^J+).
6361 \item[\textsf{10}] space (usually \sp).
6362 \item[\textsf{O}] other characters, whose category code is in $\{3,4,6,7,8,11,12,13\}$.
6363 \item[\textsf{[\sp]}, \textsf{[{\tt\textbackslash par}]}]
6364 emits a space, or~\verb+\par+.
6365 \end{description}
6366 \end{minipage}
6367 \begin{itemize}
6368 \item We omitted about category codes
6369 9~(\textit{ignored}), 14~(\textit{comment}), and~15~(\textit{invalid})
6370 from the above diagram. We also ignored the input like ``\verb+^+\verb+^A+'' or ``\verb+^+\verb+^df+''.
6371 \item When a character whose category code is 0 (\textit{escape character}) is seen by \TeX,
6372 the input processor scans a control sequence (\textsf{scan a c.s.}).
6373 These paths are not shown in the above diagram.
6374
6375 After that, the state is changed to State~$S$ (skipping blanks) in most cases, but
6376 to State~$M$ (middle of line) sometimes.
6377 \end{itemize}
6378 %<en>\caption{State transitions of \pTeX's input processor}
6379 %<ja>\caption{\pTeX の入力処理部の状態遷移}
6380 \label{fig-ptexipro}
6381 \end{figure}
6382
6383
6384 %<en>\subsection{Behavior in \LuaTeX-ja}
6385 %<ja>\subsection{\LuaTeX-jaの動作}
6386 %<*en>
6387 States in the input processor of \LuaTeX\ is the same as that of \TeX,
6388 and they can't be customized by any callbacks. Hence, we can only use
6389 \verb+process_input_buffer+ and \verb+token_filter+ callbacks for to
6390 suppress a space by a line break which is after Japanese characters.
6391
6392 However, \verb+token_filter+ callback cannot be used either, since a
6393 character in category code 5~(\textit{end-of-line}) is converted into an space
6394 token \emph{in the input processor}.  So we can use only the
6395 \verb+process_input_buffer+ callback.  This means that suppressing a
6396 space must be done \emph{just before} an input line is read.
6397
6398 Considering these situations, handling of an end-of-line in \LuaTeX-ja are as follows:
6399 \begin{quote}
6400 A character \texttt{U+FFFFF} (its category code is set to 14~(\textit{comment}) by
6401 \LuaTeX-ja) is appended to an input line, \emph{before \LuaTeX\ actually
6402 process it}, if and only if the following three conditions are satisfied:
6403 \begin{enumerate}
6404 \item The category code of \verb+\endlinechar+%
6405 \footnote{Usually, it is $\langle$\textit{return}$\rangle$
6406       (whose character code is 13).} is 5~(\textit{end-of-line}).
6407 \item The category code of \texttt{U+FFFFF} itself is 14~(\textit{comment}).
6408 \item The input line matches the following ``regular expression'':
6409 \[
6410   (\text{any char})^*(\textbf{JAchar})
6411   \bigl(\{\text{catcode}=1\}\cup\{\text{catcode}=2\}\bigr)^*
6412 \]
6413 \end{enumerate}
6414 \end{quote}
6415
6416 \paragraph{Remark}
6417 The following example shows the major difference from the behavior of \pTeX.
6418 \begin{LTXexample}
6419 \fontspec[Ligatures=TeX]{TeX Gyre Termes}
6420 \ltjsetparameter{autoxspacing=false}
6421 \ltjsetparameter{jacharrange={-6}}xあ
6422 y\ltjsetparameter{jacharrange={+6}}zい
6423 u
6424 \end{LTXexample}
6425 It is not strange that ``あ'' does not printed in the above output.
6426 This is because \TeX\ Gyre\ Termes does not contain ``あ'', and because
6427 ``あ'' in line~3 is considered as an \textbf{ALchar}.
6428
6429 Note that there is no space before ``y'' in the output, but
6430 there is a space before ``u''. This follows from following reasons:
6431 \begin{itemize}
6432 \item When line~3 is processed by \texttt{process\_input\_buffer} callback,
6433 ``あ'' is considered as an \textbf{JAchar}.
6434 Since  line~3 ends with an \textbf{JAchar},
6435 the comment character \texttt{U+FFFFF} is appended to this line,
6436 and hence the linebreak immediately after this line is ignored.
6437 \item When line~4 is processed by \texttt{process\_input\_buffer} callback,
6438 ``い'' is considered as an \textbf{ALchar}.
6439 Since  line~4 ends with an \textbf{ALchar}, the linebreak immediately after this line
6440 emits a space.
6441 \end{itemize}
6442 %</en>
6443
6444 %<*ja>
6445 \LuaTeX の入力処理部は\TeX のそれと全く同じであり,コールバックによりユーザが
6446 カスタマイズすることはできない.このため,改行抑制の目的でユーザが利用で
6447 きそうなコールバックとしては,\verb+process_input_buffer+や
6448 \verb+token_filter+に限られてしまう.しかし,\TeX の入力処理部をよく見る
6449 と,後者も役には経たないことが分かる:改行文字は,入力処理部によってトー
6450 クン化される時に,カテゴリーコード10の32番文字へと置き換えられてしまうた
6451 め,\verb+token_filter+で非標準なトークン読み出しを行おうとしても,空白文
6452 字由来のトークンと,改行文字由来のトークンは区別できないのだ.
6453
6454 すると,我々のとれる道は,\verb+process_input_buffer+を用いて
6455 \LuaTeX の入力処理部に引き渡される前に入力文字列を編集するというものしかない.
6456 以上を踏まえ,\LuaTeX-jaにおける「和文文字直後の改行抑制」の処理は,次のようになっている:
6457
6458 \begin{quote}
6459 各入力行に対し,\emph{その入力行が読まれる前の内部状態で}
6460 以下の3条件が満たされている場合,\LuaTeX-jaは\texttt{U+FFFFF}の文字
6461 \footnote{この文字はコメント文字として扱われるように\LuaTeX-ja内部で設定をしている.}
6462 を末尾に追加する.よって,その場合に改行は空白とは見做されないこととなる.
6463 \begin{enumerate}
6464 \item \verb+\endlinechar+の文字\footnote{普通は,改行文字(文字コード13番)である.}
6465 のカテゴリーコードが5~(\textit{end-of-line})である.
6466 \item \texttt{U+FFFFF}のカテゴリーコードが14~(\textit{comment})である.
6467 \item 入力行は次の「正規表現」にマッチしている:
6468 \[
6469   (\text{any char})^*(\textbf{JAchar})
6470   \bigl(\{\text{catcode}=1\}\cup\{\text{catcode}=2\}\bigr)^*
6471 \]
6472 \end{enumerate}
6473 \end{quote}
6474
6475 この仕様は,前節で述べた\pTeX の仕様にできるだけ近づけたものとなっている.条件1.は,
6476 \texttt{verbatim}系環境などの日本語対応マクロを書かなくてすませるためのものである.
6477
6478 しかしながら,\pTeX と完全に同じ挙動が実現できたわけではない.
6479 次のように,和文文字の範囲を変更したちょうどその行においては挙動が異なる:
6480 \begin{LTXexample}
6481 \fontspec[Ligatures=TeX]{TeX Gyre Termes}
6482 \ltjsetparameter{autoxspacing=false}
6483 \ltjsetparameter{jacharrange={-6}}xあ
6484 y\ltjsetparameter{jacharrange={+6}}zい
6485 u
6486 \end{LTXexample}
6487 上ソース中の「あ」は欧文文字扱いであり.
6488 ここで使用している欧文フォント\TeX\ Gyre Termesは「あ」を含まない.
6489 よって,出力に「あ」は現れないことは不思議ではない.
6490 それでも,\pTeX とまったく同じ挙動を示すならば,出力は
6491 「\hbox{\ltjsetparameter{autoxspacing=false}x yzいu}」となるはずである.しかし,実際には
6492 上のように異なる挙動となっているが,それは以下の理由による:
6493 \begin{itemize}
6494 \item 3行目を \texttt{process\_input\_buffer} で処理する時点では,
6495       「あ」は和文文字扱いである.よって3行目は和文文字で終わることになり,
6496       コメント文字 \texttt{U+FFFFF} が追加される.
6497       よって,直後の改行文字は無視されることになり,空白は入らない.
6498 \item 4行目を \texttt{process\_input\_buffer} で処理する時点では,
6499       「い」は欧文文字扱いである.よって4行目は欧文文字で終わることになり,
6500       直後の改行文字は空白に置き換わる.
6501 \end{itemize}
6502 このため,トラブルを避けるために,和文文字の範囲を\verb+\ltjsetparameter+で編集した場合,
6503 その行はそこで改行するようにした方がいいだろう.
6504 %</ja>
6505
6506 %<*ja>
6507
6508 %<en>\section{Insertion of JFM glues, \Param{kanjiskip} and \Param{xkanjiskip}}
6509 %<ja>\section{JFMグルーの挿入,\Param{kanjiskip}と\Param{xkanjiskip}}
6510 \label{sec-jfmglue}
6511 %<en>\subsection{Overview}
6512 %<ja>\subsection{概要}
6513
6514 \LuaTeX-jaにおける \textbf{JAglue} の挿入方法は,\pTeX のそれとは全く異なる.
6515 \pTeX では次のような仕様であった:
6516 \begin{itemize}
6517 \item JFMグルーの挿入は,和文文字を表すトークンを元に水平リストに(文字を表す)<char\_node>を
6518 追加する過程で行われる.
6519 \item \Param{xkanjiskip}の挿入は,hboxへのパッケージングや行分割前に行われる.
6520 \item \Param{kanjiskip}はノードとしては挿入されない.パッケージングや行分割の計算時に
6521 「和文文字を表す2つの<char\_node>の間には\Param{kanjiskip}がある」ものとみなされる.
6522 \end{itemize}
6523 しかし,\LuaTeX-jaでは,hboxへのパッケージングや行分割前に全ての
6524 \textbf{JAglue},即ちJFMグルー・\Param{xkanjiskip}・\Param{kanjiskip}の
6525 3種類を一度に挿入することになっている.これは,\LuaTeX において欧文の合字・
6526 カーニング処理がノードベースになったことに対応する変更である.
6527
6528 \LuaTeX-jaにおける\textbf{JAglue}挿入処理では,次節で定義する
6529 「クラスタ」を単位にして行われる.大雑把にいうと,「クラスタ」は文字とそれに付随す
6530 るノード達(アクセント位置補正用のカーンや,イタリック補正)をまとめたもの
6531 であり,2つのクラスタの間には,ペナルティ,\verb+\vadjust+,whatsitなど,行組版
6532 には関係しないものがある.
6533
6534
6535 %<en>\subsection{Definition of a Cluster}
6536 %<ja>\subsection{「クラスタ」の定義}
6537
6538 \def\OA{$\text{\sf O}_{\text{\sf A}}$}
6539 \def\OB{$\text{\sf O}_{\text{\sf B}}$}
6540 \begin{defn}
6541 %<*en>
6542 A \emph{cluster} is a list of consecutive nodes in one of the following forms,
6543 with the \textit{id} of it:
6544 %</en>
6545 %<*ja>
6546 \emph{クラスタ}は以下の形のうちのどれかひとつをとる連続的なノードのリストである:
6547 %</ja>
6548 \begin{enumerate}
6549 %<*en>
6550 \item Nodes whose value of\ \verb+\ltj@icflag+ is in $[3,15)$.  These
6551       nodes come from a hbox which is already packaged, by unpackaging
6552       (\verb+\unhbox+).
6553       The \textit{id} is \textit{id\_pbox}.
6554 %</en>
6555 %<*ja>
6556 \item その \verb+\ltj@icflag+ の値が$[3,15)$に入るノードのリスト.
6557   これらのノードはある既にパッケージングされたhboxから \verb+\unhbox+ で
6558   アンパックされたものである.
6559   その\textit{id}は\textit{id\_pbox}である.
6560 %</ja>
6561
6562 %<*en>
6563 \item A inline math formula, including two \textit{math\_node}s at the boundary of it.
6564       The \textit{id} is \textit{id\_math}.
6565 %</en>
6566 %<*ja>
6567 \item インライン数式でその境界に2つの\textit{math\_node}を含むもの.
6568   その\textit{id}は\textit{id\_math}である.
6569 %</ja>
6570
6571 %<*en>
6572 \item A \textit{glyph\_node}~$p$ with nodes which relate with it:
6573 %</en>
6574 %<*ja>
6575 \item \textit{glpyh\_node}~$p$とそれに関係するノード:
6576 %</ja>
6577 \begin{enumerate}
6578 %<*en>
6579 \item A kern for the italic correction of~$p$.
6580 %</en>
6581 %<*ja>
6582 \item $p$のイタリック補正のためのカーン.
6583 %</ja>
6584
6585 %<*en>
6586 \item An accent attached to $p$ by \verb+\accent+.
6587 %</en>
6588 %<*ja>
6589 \item \verb+\accent+ による$p$に付随したアクセント.
6590 %</ja>
6591 \end{enumerate}
6592 \[
6593 \overbrace{%
6594  \Node{kern}{$\mathit{subtype}=2$}\longrightarrow
6595 \left\{\begin{array}{c}
6596 \Node{glyph}{accent}\\\noalign{\medskip}
6597 \Node{hbox}{accent (shifted vert.)}
6598 \end{array}\right\}\longrightarrow
6599 \Node{kern}{$\mathit{subtype}=2$}}^{\text{(a)}}
6600 \longrightarrow
6601 \Node{glyph}{$p$}\longrightarrow
6602 \overbrace{%
6603 \Node{kern}{italic corr.}}^{\text{(b)}}
6604 \]
6605
6606 %<*en>
6607 The \textit{id} is \textit{id\_jglyph} or
6608 \textit{id\_glyph}, according to whether the \textit{glyph\_node}
6609 represents a Japanese character or not.
6610 %</en>
6611 %<*ja>
6612 \textit{id}は\textit{glyph\_node}が和文文字を表すかどうかによって
6613 \textit{id\_jglyph},もしくは\textit{id\_glyph}となる.
6614 %</ja>
6615
6616 %<*en>
6617 \item An box-like node, that is, an hbox, a vbox, a rule (\verb+\vrule+) and an \textit{unset\_node}.
6618 The \textit{id} is \textit{id\_hlist} if the node is an
6619       hbox which is not shifted vertically, or \textit{id\_box\_like}
6620       otherwise.
6621 %</en>
6622 %<*ja>
6623 \item ボックス様のノード,つまり水平ボックス,垂直ボックス,罫線 (\verb+\vrule+),
6624   そして\textit{unset\_node}.
6625   その\textit{id}は垂直に移動していないhboxならば\textit{id\_hlist},
6626   そうでなければ\textit{id\_box\_like}となる.
6627 %</ja>
6628
6629 %<*en>
6630 \item A glue, a kern whose subtype is not 2~(\textit{accent}), and a discretionary break.
6631 The \textit{id} is \textit{id\_glue}, \textit{id\_kern}
6632       and \textit{id\_disc}, respectively.
6633 %</en>
6634 %<*ja>
6635 \item グルー,subtypeが 2~(\textit{accent})ではないカーン,そして任意改行.
6636   その\textit{id}はそれぞれ\textit{id\_glue}, \textit{id\_kern},そして
6637   \textit{id\_disc}である.
6638 %</ja>
6639 \end{enumerate}
6640 %<*en>
6641 Let \textit{Np}, \textit{Nq} and \textit{Nr} denote a cluster.
6642 %</en>
6643 %<*ja>
6644 以下では\textit{Np}, \textit{Nq}, \textit{Nr}でクラスタを表す.
6645 %</ja>
6646 \end{defn}
6647
6648 \paragraph{\textit{id}の意味}
6649 $\mathit{Np}.\mathit{id}$の意味を述べるとともに,
6650 「先頭の文字」を表す\textit{glyph\_node}~$\mathit{Np}.\mathit{head}$と,
6651 「最後の文字」を表す\textit{glyph\_node}~$\mathit{Np}.\mathit{tail}$を次のように定義する.
6652 直感的に言うと,\textit{Np}は$\mathit{Np}.\mathit{head}$で始まり$\mathit{Np}.\mathit{tail}$で終わるような単語,
6653 と見做すことができる.これら$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$は
6654 説明用に準備した概念であって,実際のLuaコード中にそのように書かれているわけではないことに注意.
6655
6656 \begin{description}
6657 \item[\textit{id\_jglyph}] 和文文字.\\
6658 $\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$は,その和文文字を表している
6659 \textit{glyph\_node}そのものである.
6660 \item[\textit{id\_glyph}] 和文文字を表していない\textit{glyph\_node}~$p$.\\
6661 多くの場合,$p$は欧文文字を格納しているが,「ffi」などの合字によって作られた
6662 \textit{glyph\_node}である可能性もある.
6663 前者の場合,$\mathit{Np}.\mathit{head}$,~$\mathit{Np}.\mathit{tail} = p$である.
6664 一方,後者の場合,
6665 \begin{itemize}
6666 \item $\mathit{Np}.\mathit{head}$は,
6667 合字の構成要素の先頭→(その\textit{glyph\_node}における)合字の構成要素の先頭→……
6668 と再帰的に検索していってたどり着いた\textit{glyph\_node}である.
6669 \item $\mathit{Np}.\mathit{last}$は,同様に末尾→末尾→と検索してたどり着いた\textit{glyph\_node}である.
6670 \end{itemize}
6671 \item[\textit{id\_math}] インライン数式.\\
6672 便宜的に,$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$ともに
6673 「文字コード$-1$の欧文文字」とおく.
6674 \item[\textit{id\_hlist}] 縦方向にシフトされていないhbox.\\
6675 この場合,$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$はそれぞれ$p$の内容を表すリストの,
6676 先頭・末尾のノードである.
6677 \begin{itemize}
6678 \item 状況によっては,\TeX ソースで言うと
6679 \begin{verbatim}
6680 \hbox{\hbox{abc}...\hbox{\lower1pt\hbox{xyz}}}
6681 \end{verbatim}
6682 のように,$p$の内容が別のhboxで開始・終了している可能性も十分あり得る.そのような場合,
6683 $\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$の算出は,
6684 \emph{垂直方向にシフトされていない}hboxの
6685 場合だけ内部を再帰的に探索する.例えば上の例では,$\mathit{Np}.\mathit{head}$は文字「a」を表すノードであり,
6686 一方$\mathit{Np}.\mathit{tail}$は垂直方向にシフトされたhbox,
6687 \verb+\lower1pt\hbox{xyz}+ に対応するノードである.
6688 \item また,先頭にアクセント付きの文字がきたり,末尾にイタリック補正用のカーンが
6689 来ることもあり得る.この場合は,クラスタの定義のところにもあったように,それらは無視して算出を行う.
6690 \item 最初・最後のノードが合字によって作られた\textit{glyph\_node}のときは,それぞれに対して\textit{id\_glyph}%
6691 と同様に再帰的に構成要素をたどっていく.
6692 \end{itemize}
6693 \item[\textit{id\_pbox}] 「既に処理された」ノードのリストであり,これらのノードが二度処理を受けないために
6694 まとめて1つのクラスタとして取り扱うだけである.
6695 \textit{id\_hlist}と同じ方法で$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$を算出する,
6696 \item[\textit{id\_disc}] discretionary break (\verb+\discretionary{pre}{post}{nobreak}+).\\
6697 \textit{id\_hlist}と同じ方法で$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$を算出するが,
6698 第3引数の \texttt{nobreak}(行分割が行われない時の内容)を使う.言い換えれば,ここで行分割が発生した時の状況は
6699 全く考慮に入れない.
6700 \item[\textit{id\_box\_like}] \textit{id\_hlist}とならないboxや,rule.\\
6701 この場合は,$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$のデータは利用されないので,2つの算出は無意味である.
6702 敢えて明示するならば,$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$は共にnil値である.
6703 \item[他] 以上にない\textit{id}に対しても,$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$の算出は無意味.
6704 \end{description}
6705
6706 \paragraph{クラスタの別の分類}
6707 さらに,JFMグルー挿入処理の実際の説明により便利なように,\textit{id}とは別のクラスタの分類を行っておく.
6708 挿入処理では2つの隣り合ったクラスタの間に
6709 空白等の実際の挿入を行うことは前に書いたが,ここでの説明では,問題にしているクラスタ\textit{Np}は「後ろ側」のクラスタである
6710 とする.「前側」のクラスタについては,以下の説明で\textit{head}が\textit{last}に置き換わることに注意すること.
6711 \begin{description}
6712 \item[和文A] リスト中に直接出現している和文文字.
6713 \textit{id}が\textit{id\_jglyph}であるか,\\
6714 \textit{id}が\textit{id\_pbox}であって$\mathit{Np}.\mathit{head}$が\textbf{JAchar}であるとき.
6715
6716 \item[和文B] リスト中のhboxの中身の先頭として出現した和文文字.和文Aとの違いは,これの前に
6717 JFMグルーの挿入が行われない(\Param{xkanjiskip},~\Param{kanjiskip}は入り得る)ことである.\\
6718 \textit{id}が\textit{id\_hlist}か\textit{id\_disc}であって$\mathit{Np}.\mathit{head}$が\textbf{JAchar}であるとき.
6719
6720 \item[欧文] リスト中に直接/hboxの中身として出現している欧文文字.次の3つの場合が該当:
6721 \begin{itemize}
6722 \item \textit{id}が\textit{id\_glyph}である.
6723 \item \textit{id}が\textit{id\_math}である.
6724 \item \textit{id}が\textit{id\_pbox}か\textit{id\_hlist}か\textit{id\_disc}であって,$\mathit{Np}.\mathit{head}$が\textbf{ALchar}.
6725 \end{itemize}
6726 \item[箱] box,またはそれに類似するもの.次の2つが該当:
6727 \begin{itemize}
6728 \item \textit{id}が\textit{id\_pbox}か\textit{id\_hlist}か\textit{id\_disc}であって,$\mathit{Np}.\mathit{head}$が\textit{glyph\_node}でない.
6729 \item \textit{id}が\textit{id\_box\_like}である.
6730 \end{itemize}
6731
6732 \end{description}
6733
6734 \subsection{段落/hboxの先頭や末尾}
6735 \paragraph{先頭部の処理}
6736 まず,段落/hboxの一番最初にあるクラスタ\textit{Np}を探索する.
6737 hboxの場合は何の問題もないが,段落の場合では以下のノード達を事前に読み飛ばしておく:
6738 \begin{itemize}
6739 \item \verb+\parindent+ 由来のhbox($\mathit{subtype}=3$)
6740 \item \textit{subtype}が44~(\textit{user\_defined})でないようなwhatsit
6741 \end{itemize}
6742 これは,\verb+\parindent+由来のhboxがクラスタを構成しないようにするためである.
6743
6744 次に,\textit{Np}の直前に空白$g$を必要なら挿入する:
6745 \begin{enumerate}
6746 \item この処理が働くような\textit{Np}は\textsf{和文A}である.
6747 \item 問題のリストが字下げありの段落(\verb+\parindent+ 由来のhboxあり)の場合は,
6748 この空白$g$は「文字コード \texttt{'parbdd'} の文字」と\textit{Np}の間に入るグルー/カーンである.
6749 \item そうでないとき(\verb+noindent+ で開始された段落やhbox)は,
6750 $g$は「文字コード \texttt{'boxbdd'} の文字」と\textit{Np}の間に入るグルー/カーンである.
6751 \end{enumerate}
6752 ただし,もし$g$がglueであった場合,この挿入によって\textit{Np}による行分割が新たに可能になるべきではない.
6753 そこで,以下の場合には,$g$の直前に \verb+\penalty10000+ を挿入する:
6754 \begin{itemize}
6755 \item 問題にしているリストが段落であり,かつ
6756 \item \textit{Np}の前には予めペナルティがなく,$g$はglue.
6757 \end{itemize}
6758
6759 \paragraph{末尾の処理}
6760 末尾の処理は,問題のリストが段落のものかhboxのものかによって異なる.
6761 後者の場合は容易い:最後のクラスタを\textit{Nq}とおくと,\textit{Nq}と「文字コード\
6762 \texttt{'boxbdd'} の文字」の間に入るグルー/カーンを,
6763 \textit{Nq}の直後に挿入するのみである.
6764
6765 一方.前者(段落)の場合は,リストの末尾は常に \verb+\penalty10000+ と,
6766 \verb+\parfillskip+ 由来のグルーが存在する.%よって,最後のクラスタ\textit{Np}は
6767 %この \verb+\parfillskip+ 由来のグルーとなり,実質的な中身の最後はその1つ前のクラスタ\textit{Nq}となる.
6768 段落の最後の「通常の和文文字${}+{}$句点」が独立した行となるのを防ぐために,
6769 \Param{jcharwidowpenalty}の値の分だけ適切な場所のペナルティを増やす.
6770
6771 ペナルティ量を増やす場所は,\textit{head}が\textbf{JAchar}であり,
6772 かつその文字の\Param{kcatcode}が偶数であるような
6773 最後のクラスタの直前にあるものたちである%
6774 \footnote{大雑把に言えば,\Param{kcatcode}が奇数であるような\textbf{JAchar}%
6775 を約物として考えていることになる.
6776 \Param{kcatcode}の最下位ビットはこの\Param{jcharwidowpenalty}用にのみ利用される.}.
6777
6778 \subsection{概観と典型例:2つの「和文A」の場合}
6779 \label{ssec-cluster-wa}
6780 先に述べたように,2つの隣り合ったクラスタ,\textit{Nq}と\textit{Np}の間には,
6781 ペナルティ,\verb+\vadjust+,whatsitなど,行組版には関係しないものがある.模式的に表すと,
6782 \[
6783  \Node{cluster}{\textit{Nq}}\longrightarrow
6784 \overbrace{
6785 \Node{penalty}{$p$}\longrightarrow \cdots\longrightarrow \Node{whatsit}{}}^{\textrm{(a)}}
6786 \longrightarrow \Node{cluster}{\textit{Np}}
6787 \]
6788 のようになっている.間の(a)に相当する部分には,何のノードもない場合ももちろんあり得る.
6789 そうして,JFMグルー挿入後には,この2クラスタ間は次のようになる:
6790 \[
6791  \Node{cluster}{\textit{Nq}}\longrightarrow%\Node{kern}{左空白}\longrightarrow
6792 \overbrace{
6793 \Node{penalty}{$p+x$}\longrightarrow \cdots\longrightarrow
6794 \Node{whatsit}{}}^{\textrm{(a)}}\longrightarrow
6795 \Node{glue or kern}{\raisebox{-.2\zw}{右空白}}\longrightarrow
6796 \Node{cluster}{\textit{Np}}
6797 \]
6798
6799 以後,\emph{典型的な例として,クラスタ\textit{Nq}と\textit{Np}が共に\textsf{\textmd{和文A}}である場合を見ていこう,}
6800 この場合が全ての場合の基本となる.
6801
6802 \paragraph{「右空白」の算出}
6803 まず,「右空白」にあたる量を算出する.通常はこれが,隣り合った2つの和文文字間に入る空白量となる.
6804 \begin{description}
6805 \item[JFM由来{[M]}] JFMの文字クラス指定によって入る空白を以下によって求める.この段階で空白量が未定義(未指定)だった場合,
6806       デフォルト値\Param{kanjiskip}を採用することとなるので,次へ.
6807 \begin{enumerate}
6808 \item もし両クラスタの間で \verb+\inhibitglue+ が実行されていた場合(証としてwhatsitノードが自動挿入される),
6809       代わりに\Param{kanjiskip}が挿入されることとなる.次へ.
6810 \item \textit{Nq}と\textit{Np}が同じJFM・同じ\texttt{jfmvar}キー・同じサイズの和文フォントであったならば,
6811       共通に使っているJFM内で挿入される空白(グルーかカーン)が決まっているか調べ,決まっていればそれを採用.
6812 \item 1.でも2.でもない場合は,JFM・\texttt{jfmvar}・サイズの3つ組は\textit{Nq}と\textit{Np}で異なる.
6813 この場合,まず
6814 \[
6815 \vcenter{\halign{\hfil$#:={}$&\inhibitglue#\inhibitglue\cr
6816 gb&(\textit{Nq}と「使用フォントが\textit{Nq}のそれと同じで,\hfil\cr
6817 \omit&\quad 文字コードが\textit{Np}のそれの文字」との間に入るグルー/カーン)\hfil\cr
6818 ga&(\inhibitglue 「使用フォントが\textit{Np}のそれと同じで,\hfil\cr
6819 \omit&\quad 文字コードが\textit{Nq}のそれの文字」と\textit{Np}との間に入るグルー/カーン)\hfil\cr
6820 }}
6821 \]
6822 として,前側の文字のJFMを使った時の空白(グルー/カーン)と,後側の文字のJFMを使った時のそれを求める.
6823
6824 $\mathit{gb}$,~$\mathit{ga}$それぞれに対する<ratio>の値を$d_b$,~$d_a$とする.
6825 \begin{itemize}
6826 \item
6827 $\mathit{ga}$と$\mathit{gb}$の両方が未定義であるならば,JFM由来のグルーは挿入されず,
6828 \Param{kanjiskip}を採用することとなる.
6829 どちらか片方のみが未定義であるならば,次のステップでその未定義の方は長さ0のkernで,<ratio>の値は0であるかのように扱われる.
6830 \item
6831 \Param{diffrentjfm}の値が \texttt{pleft}, \texttt{pright},
6832       \texttt{paverage} のとき,
6833 <ratio>の指定に従って比例配分を行う.
6834 JFM由来のグルー/カーンは以下の値となる:
6835 \[
6836  f\left(\frac{1-d_b}2\textit{gb} + \frac{1+d_b}2\textit{ga},
6837 \frac{1-d_a}2\textit{gb} + \frac{1+d_a}2\textit{ga}\right)
6838 \]
6839 ここで.$f(x,y)$は
6840 \[
6841  f(x,y)=\begin{cases}
6842 x&\text{if\ }\Param{diffrentjfm}=\texttt{pleft};\\
6843 y&\text{if\ }\Param{diffrentjfm}=\texttt{pright};\\
6844 (x+y)/2&\text{if\ }\Param{diffrentjfm}=\texttt{paverage};
6845 \end{cases}.
6846 \]
6847 \item
6848 \Param{differentjfm}がそれ以外の値の時は,<ratio>の値は無視され,JFM由来のグルー/カーンは以下の値となる:
6849 \[
6850  f(\textit{gb},\textit{ga})
6851 \]
6852 ここで.$f(x,y)$は
6853 \[
6854  f(x,y)=\begin{cases}
6855 \min(x,y)&\text{if\ }\Param{diffrentjfm}=\texttt{small};\\
6856 \max(x,y)&\text{if\ }\Param{diffrentjfm}=\texttt{large};\\
6857 (x+y)/2&\text{if\ }\Param{diffrentjfm}=\texttt{average};\\
6858 x+y&\text{if\ }\Param{diffrentjfm}=\texttt{both};
6859 \end{cases}.
6860 \]
6861 \end{itemize}
6862 \end{enumerate}
6863
6864 例えば,
6865 \begin{verbatim}
6866 \jfont\foo=psft:Ryumin-Light:jfm=ujis;-kern
6867 \jfont\bar=psft:GothicBBB-Medium:jfm=ujis;-kern
6868 \jfont\baz=psft:GothicBBB-Medium:jfm=ujis;jfmvar=piyo;-kern
6869 \end{verbatim}
6870 という3フォントを考え,
6871 \[
6872  \overbrace{\Node{glyph}{{\tt\textbackslash foo}, `あ'}}^{p}
6873 \longrightarrow \overbrace{\Node{glyph}{{\tt\textbackslash bar}, `い'}}^{q}
6874 \longrightarrow \overbrace{\Node{glyph}{{\tt\textbackslash baz}, `う'}}^{r}
6875 \]
6876 という3ノードを考える(それぞれ単独でクラスタをなす).
6877 この場合,$p$と$q$の間は,実フォントが異なるにもかかわらず2.の状況となる一方で,
6878 $q$と$r$の間は(実フォントが同じなのに)\texttt{jfmvar} キーの内容が異なるので3.の状況となる.
6879 \item[\Param{kanjiskip}~{[K]}] 上の[M]において空白が定まらなかった場合,
6880 以下で定めた量「右空白」として採用する.
6881 この段階においては,\verb+\inhibitglue+ は効力を持たないため,
6882 結果として,2つの和文文字間には常に何らかのグルー/カーンが挿入されることとなる.
6883 \begin{enumerate}
6884 \item 両クラスタ(厳密には$\mathit{Nq}.\mathit{tail}$,$\mathit{Np}.\mathit{head}$)の中身の文字コードに対する
6885 \Param{autospacing}パラメタが両方ともfalseだった場合は,長さ0のglueとする.
6886 \item ユーザ側から見た\Param{kanjiskip}パラメタの自然長が${\tt \textbackslash maxdimen}=(2^{30}-1)\,{\rm sp}$で
6887 なければ,\Param{kanjiskip}パラメタの値を持つglueを採用する.
6888 \item 2.でない場合は,\textit{Nq}, \textit{Np}で使われているJFMに指定されている\Param{kanjiskip}の値を用いる.
6889 どちらか片方のクラスタだけが和文文字(\textsf{和文A}・\textsf{和文B})のときは,そちらのクラスタで使われている
6890 JFM由来の値だけを用いる.もし両者で使われているJFMが異なった場合は,上の[M]~3.と同様の方法を用いて調整する.
6891 \end{enumerate}
6892 \end{description}
6893 %\paragraph{「左空白」の算出とそれに伴う補正}
6894 %「左空白」は過去のバージョンでは定義していたが,このバージョンでは
6895 %挿入は一切行われない(機能自体削除している).
6896 %しかし,仕様は流動的であり,将来復活する可能性もあるため,マニュアル中の記述は今のところ極力変更しない.
6897 \paragraph{禁則用ペナルティの挿入}
6898 まず,
6899 \[
6900  a:=(\text{\textit{Nq}{\footnotemark}の文字に対する\Param{postbreakpenalty}の値})
6901 +(\text{\textit{Np}{\footnotemark}の文字に対する\Param{prebreakpenalty}の値})
6902 \]
6903 とおく\footnotetext{厳密にはそれぞれ$\mathit{Nq}.\mathit{tail}$,$\mathit{Np}.\mathit{head}$.}.
6904 ペナルティは通常$[-10000,10000]$の整数値をとり,また$\pm 10000$は正負の無限大を意味することになっているが,この$a$の
6905 算出では単純な整数の加減算を行う.
6906
6907 $a$は禁則処理用に\textit{Nq}と\textit{Np}の間に加えられるべきペナルティ量である.
6908 \begin{description}
6909 \item[P-normal~{[PN]}]
6910 \textit{Nq}と\textit{Np}の間の(a)部分にペナルティ(\textit{penalty\_node})があれば処理は簡単である:
6911 それらの各ノードにおいて,ペナルティ値を($\pm 10000$を無限大として扱いつつ)$a$だけ増加させればよい.
6912 また,$10000 + (-10000) = 0$としている.
6913
6914 少々困るのは,(a)部分にペナルティが存在していない場合である.
6915 直感的に,補正すべき量$a$が0でないとき,その値をもつ\textit{penalty\_node}を作って
6916 「右空白」の(もし未定義なら\textit{Np}の)直前に挿入……
6917 ということになるが,実際には僅かにこれより複雑である.
6918 \begin{itemize}
6919 \item 「右空白」がカーンであるとき,
6920 それは「\textit{Nq}と\textit{Np}の間で改行は許されない」ことを意図している.そのため,
6921 この場合は$a\neq 0$であってもペナルティの挿入はしない.
6922 \item そうでないないときは,$a\neq 0$ならば\textit{penalty\_node}を作って挿入する.
6923 %\item 「左空白」がカーンとしてきっちり定義されている時(このとき,「右空白」はカーンでない),
6924 %この「左空白」の直後での行分割を許容しないといけないので,$a=0$であっても
6925 %\textit{penalty\_node}を作って挿入する.
6926 %\item 以上のどれでもないときは,$a\neq 0$ならば\textit{penalty\_node}を作って挿入する.
6927 \end{itemize}
6928 \end{description}
6929
6930 \def\gkf#1#2#3{\sf$\displaystyle\vphantom{\Bigg(}%
6931   \frac{\hbox to 4\zw{\hss#2\hss}}{\hbox{#3}}$}
6932 \begin{table}[t]
6933 %<en>\caption{Summary of JFM glues}
6934 %<ja>\caption{JFM グルーの概要}
6935 \label{tab-jfmglue}
6936 %<en>\medskip
6937 \begin{center}
6938 \small
6939 \begin{tabular}{c|cccccc}
6940 \toprule
6941 {\bf\textit{Np}}↓&\sf 和文A&\sf 和文B&\sf 欧文&\sf 箱&\sf glue&\sf kern\\\midrule
6942 \sf 和文A&
6943 \gkf{E}{M→K}{PN}&
6944 \gkf{---}{\OA →K}{PN}&
6945 \gkf{---}{\OA →X}{PN}&
6946 \gkf{---}{\OA}{PA}&
6947 \gkf{---}{\OA}{PN}&
6948 \gkf{---}{\OA}{PS}\\
6949 \sf 和文B&
6950 \gkf{E}{\OB→K}{PA}&
6951 \gkf{---}{K}{PS}&
6952 \gkf{---}{X}{PS}\\
6953 \sf 欧文&
6954 \gkf{E}{\OB →X}{PA}&
6955 \gkf{---}{X}{PS}\cr
6956 \sf 箱&\gkf{E}{\OB}{PA}\\
6957 \sf glue&\gkf{E}{\OB}{PN}\\
6958 \sf kern&\gkf{E}{\OB}{PS}\\
6959 \bottomrule
6960 \end{tabular}
6961 \end{center}
6962 \begin{quote}
6963 %<*en>
6964 In the table above, {\small\gkf{E}{M→K}{PN}} means that
6965 %</en>
6966 %<*ja>
6967 上の表において,{\small\gkf{E}{M→K}{PN}}は次の意味である:
6968 %</ja>
6969 \begin{enumerate}
6970 %<*en>
6971 \item To determine the ``right-space'', \LuaTeX-ja first attempts by the method ``\textsf{JFM-origin~[M]}''.
6972 If this attempt fails, \LuaTeX-ja use the method ``\textsf{\Param{kanjiskip}~[K]}''.
6973 %</en>
6974 %<*ja>
6975 \item 「右空白」を決めるために,\LuaTeX-ja はまず「JFM由来{[M]}」の方法を試みる.
6976   これが失敗したら,\LuaTeX-ja は「\Param{kanjiskip}~{[K]}」の方法を試みる.
6977 %</ja>
6978
6979 % %<*en>
6980 % \item The ``left space'' between \textit{Nq}~and~\textit{Np} is
6981 %   determined by the method ``\textsf{line-end~[E]}''.
6982 % %</en>
6983 % %<*ja>
6984 % \item \textit{Nq} と \textit{Np} の間の「左空白」は「\textsf{line-end~[E]}」の
6985 %   方法で決定される.
6986 % %</ja>
6987
6988 %<*en>
6989 \item \LuaTeX-ja adopts the method ``\textsf{P-normal~[PN]}'' to adjust the penalty
6990   between two clusters for \emph{kinsoku shori}.
6991 %</en>
6992 %<*ja>
6993 \item \LuaTeX-jaは2つのクラスタの間の禁則処理用のペナルティを設定するために「\textsf{P-normal~[PN]}」の方法を採用する.
6994 %</ja>
6995 \end{enumerate}
6996 \end{quote}
6997 \end{table}
6998
6999 \subsection{その他の場合}
7000 本節の内容は表\ref{tab-jfmglue}にまとめてある.
7001
7002 \paragraph{和文Aと欧文の間}
7003 \textit{Nq}が\textsf{和文A}で,\textit{Np}が\textsf{欧文}の場合,JFMグルー挿入処理は次のようにして行われる.
7004 \begin{itemize}
7005 \item 「右空白」については,まず以下に述べる\textsf{Boundary-B~[\OB]}により空白を決定しようと試みる.
7006 それが失敗した場合は,\textsf{\Param{xkanjiskip}~[X]}によって定める.
7007 %\item 「左空白」については,既に述べた\textsf{line-end~[E]}をそのまま採用する.それに伴う「右空白」の補正も%同じ.
7008 \item 禁則用ペナルティも,以前述べた\textsf{P-normal~[PN]}と同じである.
7009 \end{itemize}
7010 \begin{description}
7011 \item[Boundary-B~{[\OB]}] 和文文字と「和文でないもの」との間に入る空白を以下によって求め,
7012 未定義でなければそれを「右空白」として採用する.
7013 \textsf{JFM-origin~[M]}の変種と考えて良い.
7014 これによって定まる空白の典型例は,和文の閉じ括弧と欧文文字の間に入る半角アキである.
7015 \begin{enumerate}
7016 \item もし両クラスタの間で \verb+\inhibitglue+ が実行されていた場合%
7017 (証としてwhatsitノードが自動挿入される),「右空白」は未定義.
7018 \item そうでなければ,
7019 \textit{Nq}と「文字コードが {\tt'jcharbdd'} の文字」との間に入るグルー/カーンとして定まる.
7020 \end{enumerate}
7021 \item[\Param{xkanjiskip}~{[X]}]
7022 この段階では,\textsf{\Param{kanjiskip}~[K]}のときと同じように,
7023 以下で定めた量を「右空白」として採用する.
7024 \verb+\inhibitglue+ は効力を持たない.
7025 \begin{enumerate}
7026 \item 以下のいずれかの場合は,\Param{xkanjiskip}の挿入は抑止される.しかし,実際には行分割を許容するために,長さ0のglueを採用する:
7027 \begin{itemize}
7028 \item 両クラスタにおいて,それらの中身の文字コードに対する\Param{autoxspacing}パラメタが共にfalseである.
7029 \item \textit{Nq}の中身の文字コードについて,「直後への\Param{xkanjiskip}の挿入」が禁止されている
7030 (つまり,\Param{jaxspmode}~(or \Param{alxspmode})パラメタが2以上).
7031 \item \textit{Np}の中身の文字コードについて,「直前への\Param{xkanjiskip}の挿入」が禁止されている
7032 (つまり,\Param{jaxspmode}~(or \Param{alxspmode})パラメタが偶数).
7033 \end{itemize}
7034 \item ユーザ側から見た\Param{xkanjiskip}パラメタの自然長が${\tt \textbackslash maxdimen}=(2^{30}-1)\,{\rm sp}$で
7035 なければ,\Param{xkanjiskip}パラメタの値を持つglueを採用する.
7036 \item 2.でない場合は,\textit{Nq}, \textit{Np}(\textsf{和文A}/\textsf{和文B}なのは片方だけ)
7037 で使われているJFMに指定されている\Param{xkanjiskip}の値を用いる.
7038 \end{enumerate}
7039 \end{description}
7040
7041 \paragraph{欧文と和文Aの間}
7042 \textit{Nq}が\textsf{欧文}で,\textit{Np}が\textsf{和文A}の場合,JFMグルー挿入処理は上の場合とほぼ同じである.
7043 \textsf{和文A}のクラスタが逆になるので,\textsf{Boundary-A~[\OA]}の部分が変わるだけ.
7044 \begin{itemize}
7045 \item 「右空白」については,まず以下に述べる\textsf{Boundary-A~[\OA]}により空白を決定しようと試みる.
7046 それが失敗した場合は,\textsf{\Param{xkanjiskip}~[X]}によって定める.
7047 %\item \textit{Nq}が和文でないので,「左空白」は算出されない.
7048 \item 禁則用ペナルティは,以前述べた\textsf{P-normal~[PN]}と同じである.
7049 \end{itemize}
7050 \begin{description}
7051 \item[Boundary-A~{[\OA]}] 「和文でないもの」と和文文字との間に入る空白を以下によって求め,
7052 未定義でなければそれを「右空白」として採用する.
7053 \textsf{JFM-origin~[M]}の変種と考えて良い.
7054 これによって定まる空白の典型例は,欧文文字と和文の開き括弧との間に入る半角アキである.
7055 \begin{enumerate}
7056 \item もし両クラスタの間で \verb+\inhibitglue+ が実行されていた場合(証としてwhatsitノードが自動挿入される),次へ.
7057 \item そうでなければ,
7058 「文字コードが {\tt'jcharbdd'} の文字」と\textit{Np}との間に入るグルー/カーンとして定まる.
7059 \end{enumerate}
7060 \end{description}
7061
7062 \paragraph{和文Aと箱・グルー・カーンの間}
7063 \textit{Nq}が\textsf{和文A}で,\textit{Np}が\textsf{箱}・グルー・カーンのいずれかであった場合,
7064 両者の間に挿入されるJFMグルーについては同じ処理である.しかし,そこでの行分割に対する仕様が異なるので,
7065 ペナルティの挿入処理は若干異なったものとなっている.
7066
7067 \begin{itemize}
7068 \item 「右空白」については,既に述べた\textsf{Boundary-B~[\OB]}により空白を決定しようと試みる.
7069 それが失敗した場合は,「右空白」は挿入されない.
7070 %\item 「左空白」については,既に述べた\textsf{line-end~[E]}の算出方法をそのまま採用する.それに伴う「右空白」の補正も同じ.
7071 \item 禁則用ペナルティの処理は,後ろのクラスタ\textit{Np}の種類によって異なる.
7072 なお,$\mathit{Np}.\mathit{head}$は無意味であるから,
7073 「$\mathit{Np}.\mathit{head}$に対する\Param{prebreakpenalty}の値」は0とみなされる.言い換えれば,
7074 \[
7075  a:=(\text{\textit{Nq}の文字に対する\Param{postbreakpenalty}の値}).
7076 \]
7077 \begin{description}
7078 \item[箱] \textit{Np}が\textsf{箱}であった場合は,両クラスタの間での行分割は
7079 (明示的に両クラスタの間に \verb+\penalty10000+ があった場合を除き)いつも許容される.そのため,
7080 ペナルティ処理は,後に述べる\textsf{P-allow~[PA]}が\textsf{P-normal~[PN]}の代わりに用いられる.
7081 \item[グルー] \textit{Np}がグルーの場合,ペナルティ処理は\textsf{P-normal~[PN]}を用いる.
7082 \item[カーン] \textit{Np}がカーンであった場合は,両クラスタの間での行分割は
7083 (明示的に両クラスタの間にペナルティがあった場合を除き)許容されない.
7084 ペナルティ処理は,後に述べる\textsf{P-suppress~[PS]}を使う.
7085 \end{description}
7086 これらの\textsf{P-normal~[PN]},\textsf{P-allow~[PA]},\textsf{P-suppress~[PS]}の違いは,
7087 \textit{Nq}と\textit{Np}の間(以前の図だと(a)の部分)にペナルティが存在しない場合にのみ存在する.
7088 \end{itemize}
7089
7090 \begin{description}
7091 \item[P-allow~{[PA]}]
7092 \textit{Nq}と\textit{Np}の間の(a)部分にペナルティがあれば,\textsf{P-normal~[PN]}と同様に,
7093 それらの各ノードにおいてペナルティ値を$a$だけ増加させる.
7094
7095 (a)部分にペナルティが存在していない場合,
7096 \LuaTeX-ja は\textit{Nq}と\textit{Np}の間の行分割を可能にしようとする.
7097 そのために,以下の場合に$a$をもつ\textit{penalty\_node}を作って
7098 「右空白」の(もし未定義なら\textit{Np}の)直前に挿入する:
7099 \begin{itemize}
7100 \item 「右空白」がグルーでない(カーンか未定義)であるとき.
7101 %\item 「左空白」がカーンとしてきっちり定義されている時.
7102 \end{itemize}
7103
7104 \item[P-suppress~{[PS]}]
7105 \textit{Nq}と\textit{Np}の間の(a)部分にペナルティがあれば,\textsf{P-normal~[PN]}と同様に,
7106 それらの各ノードにおいてペナルティ値を$a$だけ増加させる.
7107
7108 (a)部分にペナルティが存在していない場合,
7109 \textit{Nq}と\textit{Np}の間の行分割は元々不可能のはずだったのであるが,
7110 \LuaTeX-ja はそれをわざわざ行分割可能にはしない.
7111 そのため,「右空白」がglueであれば,その直前に \verb+\penalty10000+ を挿入する.
7112 \end{description}
7113
7114 なお,「右空白」はカーンの%,「左空白」は未定義の
7115 \[
7116  \overbrace{\Node{glyph}{`あ'}}^{\mathit{Nq}}\longrightarrow \overbrace{\Node{glue}{1\,pt}}^{\mathit{Np}}
7117 \]
7118 のような状況を考える.
7119 このとき,$a$,即ち「あ」の\Param{postbreakpenalty}がいかなる値であっても,
7120 この2クラスタ間は最終的に
7121 \begin{equation}
7122  \overbrace{\Node{glyph}{`あ'}}^{\mathit{Nq}}\longrightarrow
7123 \Node{kern}{右空白}\longrightarrow \overbrace{\Node{glue}{1\,pt}}^{\mathit{Np}}
7124 \label{eq-gref}
7125 \end{equation}
7126 となり,$a$分のペナルティは挿入されないことに注意して欲しい.
7127 \Param{postbreakpenalty}は($a$は)殆どの場合が非負の値と考えられ,そのような場合では
7128 \eqref{eq-gref}と
7129 \[
7130  \overbrace{\Node{glyph}{`あ'}}^{\mathit{Nq}}\longrightarrow
7131 \Node{penalty}{$a$}\longrightarrow
7132 \Node{kern}{右空白}\longrightarrow \overbrace{\Node{glue}{1\,pt}}^{\mathit{Np}}
7133 \]
7134 との間に差異は生じない%
7135 \footnote{kern$\rightarrow$glueが1つの行分割可能点(行分割に伴うペナルティは0)
7136 であるため,たとえ$a=10000$であっても,\textit{Nq}と\textit{Np}の間で行分割を禁止することはできない.}.
7137
7138 \paragraph{箱・グルー・カーンと和文Aの間}
7139 \textit{Np}が\textsf{箱}・グルー・カーンのいずれかで,\textit{Np}が\textsf{和文A}であった場合は,
7140 すぐ上の(\textit{Nq}と\textit{Np}の順序が逆になっている)場合と同じである.
7141 %が,「左空白」がなくなることにのみ注意.
7142 \begin{itemize}
7143 \item 「右空白」については,既に述べた\textsf{Boundary-A~[\OA]}により空白を決定しようと試みる.
7144 それが失敗した場合は,「右空白」は挿入されない.
7145 %\item \textit{Nq}が和文でないので,「左空白」は算出されない.
7146 \item 禁則用ペナルティの処理は,\textit{Nq}の種類によって異なる.
7147 $\mathit{Nq}.\mathit{tail}$は無意味なので,
7148 \[
7149  a:=(\text{\textit{Np}の文字に対する\Param{prebreakpenalty}の値}).
7150 \]
7151 \begin{description}
7152 \item[箱] \textit{Nq}が\textsf{箱}の場合は,\textsf{P-allow~[PA]}を用いる.
7153 \item[グルー] \textit{Nq}がグルーの場合は,\textsf{P-normal~[PN]}を用いる.
7154 \item[カーン] \textit{Nq}がカーンの場合は,\textsf{P-suppress~[PS]}を用いる.
7155 \end{description}
7156 \end{itemize}
7157
7158 \paragraph{和文Aと和文Bの違い}
7159 先に述べたように,\textsf{和文B}はhboxの中身の先頭(or 末尾)として出現している
7160 和文文字である.リスト内に直接ノードとして現れている和文文字(\textsf{和文A})との違いは,
7161 \begin{itemize}
7162 \item \textsf{和文B}に対しては,JFMの文字クラス指定から定まる空白
7163 \textsf{JFM-origin~[M]},\textsf{Boundary-A~[\OA]},\textsf{Boundary-B~[\OB]})の挿入は行われない.
7164 %「左空白」の算出も行われない.
7165 例えば,
7166 \begin{itemize}
7167 \item 片方が\textsf{和文A},もう片方が\textsf{和文B}のクラスタの場合,
7168 \textsf{Boundary-A~[\OA]}または\textsf{Boundary-B~[\OB]}の挿入を試み,それがダメなら
7169 \Param{kanjiskip}~\textsf{[K]}の挿入を行う.
7170 \item \textsf{和文B}の2つのクラスタの間には,\Param{kanjiskip}~\textsf{[K]}が自動的に入る.
7171 \end{itemize}
7172 \item \textsf{和文B}と箱・グルー・カーンが隣接したとき(どちらが前かは関係ない),間にJFMグルー・ペナルティの挿入は一切しない.
7173 \item \textsf{和文B}と\textsf{和文B},また\textsf{和文B}と\textsf{欧文}とが隣接した時は,禁則用ペナルティ挿入処理は
7174 \textsf{P-suppress~[PS]}が用いられる.
7175 \item \textsf{和文B}の文字に対する\Param{prebreakpenalty},~\Param{postbreakpenalty}の値は使われず,0として計算される.
7176 \end{itemize}
7177
7178
7179 次が具体例である:
7180 \begin{LTXexample}
7181 あ.\inhibitglue A\\
7182 \hbox{あ.}A\\
7183 あ.A
7184 \end{LTXexample}
7185 \begin{itemize}
7186 \item 1行目の\verb+\inhibitglue+は\textsf{Boundary-B~[\OB]}の処理のみを抑止するので,ピリオドと「A」の間には
7187 \Param{xkanjiskip}(四分アキ)が入ることに注意.
7188 \item 2行目のピリオドと「A」の間においては,前者が\textsf{和文B}となる(hboxの中身の末尾として登場しているから)ので,
7189 そもそも\textsf{Boundary-B~[\OB]}の処理は行われない.よって,\Param{xkanjiskip}が入ることとなる.
7190 \item 3行目では,ピリオドの属するクラスタは\textsf{和文A}である.これによって,
7191 ピリオドと「A」の間には\textsf{Boundary-B~[\OB]}由来の半角アキが入ることになる.
7192 \end{itemize}
7193 %</ja>
7194
7195 %<en>\section{Patch for the \Pkg{listings} Package}
7196 %<ja>\section{\Pkg{listings} パッケージへの対応}
7197
7198 %<*en>
7199 It is well-known that the \Pkg{listings} package outputs weird results
7200 for Japanese input.
7201 The \Pkg{listings} package makes most of letters active and assigns
7202 output command for each letter~(\cite{listings}).
7203 But Japanese characters are not included in these activated letters.
7204 For \pTeX{} series, there is no method to make Japanese characters active;
7205 a patch \Pkg{jlisting.sty}~(\cite{jlisting}) resolves the problem forcibly.
7206 %</en>
7207 %<*ja>
7208 \Pkg{listings} パッケージが,そのままでは日本語をまともに出力できないこと
7209 はよく知られている.きちんと整形して出力するために,\Pkg{listings}パッケー
7210 ジは内部で「ほとんどの文字」をアクティブにし,各文字に対してその文字の出
7211 力命令を割り当てている(\cite{listings}).
7212 しかし,そこでアクティブにする文字の中に,和文文
7213 字がないためである.\pTeX 系列では,和文文字をアクティブにする手法がなく,
7214 \Pkg{jlisting.sty} というパッチ(\cite{jlisting})を用いることで無理やり解決していた.
7215 %</ja>
7216
7217 %<*en>
7218 In \LuaTeX-ja, the problem is resolved by using the \verb+process_input_buffer+ callback.
7219 The callback function inserts the output command (active character \texttt{U+FFFFF})
7220 before each letter above \texttt{U+0080}.
7221 This method can omits the process to make all Japanese characters active
7222 (most of the activated characters are not used in many cases).
7223 %</en>
7224 %<*ja>
7225 \LuaTeX-jaでは,\verb+process_input_buffer+ コールバックを利用することで,
7226 「各行に出現する\texttt{U+0080}以降の文字に対して,それらの出力命令を前置する」
7227 という方法をとっている.出力命令としては,アクティブ文字化した \texttt{U+FFFFF} を用いている.
7228 これにより,(入力には使用されていないかもしれない)和文文字をもすべてアクティブ化する手間もなく,
7229 見通しが良い実装になっている.
7230 %</ja>
7231
7232
7233 %<*en>
7234 If the \Pkg{listings} package  and \LuaTeX-ja were loaded,
7235 then the patch \Pkg{lltjp-listings} is loaded automatically at \verb+\begin{document}+.
7236 %</en>
7237 %<*ja>
7238 \LuaTeX-ja で利用される \Pkg{listings} パッケージへのパッチ \Pkg{lltjp-listings} は,
7239 \Pkg{listings} と\LuaTeX-jaを読み込んでおけば,
7240 \verb+\begin{document}+ の箇所において自動的に読み込まれるので,通常はあまり
7241 意識する必要はない.
7242 %</ja>
7243
7244 %<en>\subsection{Notes}
7245 %<ja>\subsection{注意}
7246 %<*en>
7247 \paragraph{Escaping to \LaTeX}
7248 We used the \verb+process_input_buffer+ callback to output \textbf{JAchar}s.
7249 But it has a drawback; any commands whose name contains a \textbf{JAchar}
7250 cannot be used in any ``escape to \LaTeX''.
7251
7252 Consider the following input:
7253 %</en>
7254 %<*ja>
7255 \paragraph{\LaTeX へのエスケープ}
7256 日本語対応を行うために \verb+process_input_buffer+ を使用したことで,
7257 \texttt{texcl},~\texttt{escapeinside}といった\emph{「\LaTeX へのエスケープ」中では,
7258 \textbf{JAchar}を名称の一部に含む制御綴は使用不可能}である.
7259 例えば次のような入力を考えよう:
7260 %</ja>
7261 \begin{verbatim*}
7262 \begin{lstlisting}[escapechar=\#]
7263 #\ほげ xぴよ#
7264 \end{lstlisting}
7265 \end{verbatim*}
7266 %<en>The line~2 is transformed by the callback to
7267 %<ja>ここで,2行目は \verb+process_input_buffer+ の作用により,
7268 \begin{lstlisting}[showspaces, escapechar=\!]
7269 #\!\IVSA FFFFF!ほ!\IVSA FFFFF !げ x!\IVSA FFFFF !ぴ!\IVSA FFFFF !よ#
7270 \end{lstlisting}
7271 %<*en>
7272 before the line is actually processed.
7273 In the escape (between the character ``\verb+#+''),
7274 the category code of \texttt{U+FFFFF} is set to 9~(\emph{ignored}).
7275 Hence the control symbol ``\verb+\+\IVSA FFFFF'' will be executed,
7276 instead of ``\verb+\ほげ+''.
7277 %</en>
7278 %<*ja>
7279 と変換されてから,実際の処理に回される.
7280 「\verb+#+」で挟まれた「\LaTeX へのエスケープ」中では\
7281 \texttt{U+FFFFF} のカテゴリーコードは9~(\textit{ignored})となるので,
7282 結局「\verb+\ほげ+」の代わりに
7283 「\verb+\+\IVSA FFFFF」というcontrol symbolが実行されることになる.
7284 %</ja>
7285
7286 %<*ja>
7287 \paragraph{異体字セレクタの扱い}
7288 \texttt{lstlisting} 環境などの内部にある異体字セレクタを扱うため,
7289 \Pkg{lltjp-listings} では \texttt{vsraw} と \texttt{vscmd} という2つのキーを追加した.
7290 しかし,\Pkg{lltjp-listings} が実際に読み込まれるのは \verb+\begin{document}+\
7291 のところであるので,プリアンブル内ではこれらの追加キーは使用できない.
7292
7293 \texttt{vsraw}は,ブール値の値をとるキーであり,標準ではfalseである.
7294 \begin{itemize}
7295  \item trueの場合は,異体字セレクタは「直前の文字に続けて」出力される.
7296 もしもIVSサポート(\ref{ssec-ltjotf}節)が有効になっていた場合は,
7297 以下の例(左側は入力,右側はその出力)のようになる.
7298 \begin{LTXexample}
7299 \begin{lstlisting}[vsraw=true]
7300 葛󠄀城市,葛󠄁飾区,葛西
7301 \end{lstlisting}
7302 \end{LTXexample}
7303 \item falseの場合は,異体字セレクタは適当な命令によって「見える形で」出力される.
7304 どのような形で出力されるかを規定するのが \texttt{vscmd} キーであり,
7305 \Pkg{lltjp-listings} の標準設定では以下の例の右側のように出力される.
7306 \begin{LTXexample}
7307 \begin{lstlisting}[vsraw=false,
7308    vscmd=\ltjlistingsvsstdcmd]
7309 葛󠄀城市,葛󠄁飾区,葛西
7310 \end{lstlisting}
7311 \end{LTXexample}
7312 ちなみに,本ドキュメントでは次のようにしている:
7313 \begin{lstlisting}[numbers=left]
7314 \def\IVSA#1#2#3#4#5{%
7315   \textcolor{blue}{\raisebox{3.5pt}{\tt%
7316     \fboxsep=0.5pt\fbox{\tiny \oalign{0#1#2\crcr#3#4#5\crcr}}}}%
7317 }
7318 {\catcode`\%=11
7319   \gdef\IVSB#1{\expandafter\IVSA\directlua{
7320     local cat_str = luatexbase.catcodetables['string']
7321     tex.sprint(cat_str, string.format('%X', 0xE00EF+#1))
7322 }}}
7323 \lstset{vscmd=\IVSB}
7324 \end{lstlisting}
7325 \end{itemize}
7326 既定の出力命令を復活させたい場合は\ \verb+vsraw=\ltjlistingsvsstdcmd+\
7327 とすれば良い.
7328 %</ja>
7329
7330 %<en>\subsection{Class of Characters}
7331 %<ja>\subsection{文字種}
7332
7333 %<en>Roughly speaking, the \Pkg{listings} package processes input as follows:
7334 %<ja>\Pkg{listings} パッケージの内部では,大雑把に言うと
7335 \begin{enumerate}
7336 %<en>\item Collects \textit{letters} and \textit{digits}, which can be used for the name of identifiers.
7337 %<ja>\item 識別子として使える文字 (``letter'',~``digit'') たちを集める.
7338 %<en>\item When reading an \textit{other}, outputs the collected character string (with modification, if needed).
7339 %<ja>\item letterでもdigitでもない文字が現れた時に,収集した文字列を(必要なら修飾して)出力する.
7340 %<en>\item Collects \textit{others}.
7341 %<ja>\item 今度は逆に,letterでない文字たちをletterが現れるまで集める.
7342 %<en>\item When reading a \textit{letter} or a \textit{digit}, outputs the collected character string.
7343 %<ja>\item letterが出現したら集めた文字列を出力する.
7344 %<en>\item Turns back to 1.
7345 %<ja>\item 1.に戻る.
7346 \end{enumerate}
7347 %<*en>
7348 By the above process, line breaks inside of an identifier are blocked.
7349 A flag \verb+\lst@ifletter+ indicates whether the previous character can be used
7350 for the name of identifiers or not.
7351 %</en>
7352 %<*ja>
7353 という処理が行われている.これにより,識別子の途中では行分割が行われないようになっている.
7354 直前の文字が識別子として使えるか否かは \verb+\lst@ifletter+ というフラグに格納されている.
7355 %</ja>
7356
7357 %<*en>
7358 For Japanese characters, line breaks are permitted on both sides
7359 except for brackets, dashes, etc.
7360 Hence the patch \Pkg{lltjp-listings} introduces
7361 a new flag \verb+\lst@ifkanji+, which indicates
7362 whether the previous character is a Japanese character or not.
7363 For illustration, we introduce following classes of characters:
7364 %</en>
7365 %<*ja>
7366 さて,日本語の処理である.殆どの和文文字の前後では行分割が可能であるが,その一方で
7367 括弧類や音引きなどでは禁則処理が必要なことから,\Pkg{lltjp-listings} では,
7368 直前が和文文字であるかを示すフラグ \verb+\lst@ifkanji+ を新たに導入した.
7369 以降,説明のために以下のように文字を分類する:
7370 %</ja>
7371 \begin{center}
7372 \small
7373 \begin{tabular}{lccccc}
7374 \toprule
7375 &Letter&Other&Kanji&Open&Close\\\midrule
7376 \verb+\lst@ifletter+&T&F&T&F&T\\
7377 \verb+\lst@ifkanji+&F&F&T&T&F\\
7378 %<en>Meaning&char in an identifier&other alphabet&%
7379 %<en>most of Japanese char&opening brackets&closing brackets\\
7380 %<ja>意図&識別子中の文字&その他欧文文字&殆どの和文文字&開き括弧類&閉じ括弧類\\
7381 \bottomrule
7382 \end{tabular}
7383 \end{center}
7384 %<*en>
7385 Note that \textit{digits} in the \Pkg{listings} package can be Letter or
7386 Other according to circumstances.
7387 %</en>
7388 %<*ja>
7389 なお,本来の\Pkg{listings} パッケージでの分類``digit''は,
7390 出現状況によって,上の表のLetterとOtherのどちらにもなりうる.
7391 また,KanjiとCloseは \verb+\lst@ifletter+ と \verb+\lst@ifkanji+ の値が一致しているが,
7392 これは間違いではない.
7393 %</ja>
7394
7395 %<*en>
7396 For example, let us consider the case an Open comes after a Letter.
7397 Since an Open represents Japanese open brackets,
7398 it is preferred to be permitted to insert line break after the Letter.
7399 Therefore, the collected character string is output in this case.
7400 %</en>
7401 %<*ja>
7402 例えば,Letterの直後にOpenが来た場合を考える.
7403 文字種Openは和文開き括弧類を想定しているので,Letterの直後では行分割が可能であることが望ましい.
7404 そのため,この場合では,すでに収集されている文字列を出力することで行分割を許容するようにした.
7405 %</ja>
7406
7407 %<*en>
7408 The following table summarizes $5\times 5=25$ cases:
7409 %</en>
7410 %<*ja>
7411 同じように,$5\times 5=25$通り全てについて書くと,次のようになる:
7412 %</ja>
7413 \begin{center}
7414 \small
7415 \begin{tabular}{llccccc}
7416 \toprule
7417 %<*en>
7418 &&\multicolumn{4}{c}{Next}\\\cmidrule(lr){3-7}
7419 &&\hbox to 4em{\hss Letter\hss}&\hbox to 4em{\hss Other\hss}
7420 &\hbox to 4em{\hss Kanji\hss}&\hbox to 4em{\hss Open\hss}&Close\\\midrule
7421 &Letter&collects&\multicolumn{3}{c}{\hrulefill \ outputs\ \hrulefill}&collects\\
7422 &Other&outputs&collects&\multicolumn{2}{c}{\hrulefill \ outputs\ \hrulefill}&collects\\
7423 Prev&Kanji&\multicolumn{4}{c}{\hrulefill \ outputs\ \hrulefill}&collects\\
7424 &Open&\multicolumn{5}{c}{\hrulefill \ collects\ \hrulefill}\\
7425 &Close&\multicolumn{4}{c}{\hrulefill \ outputs\ \hrulefill}&collects\\
7426 %</en>
7427 %<*ja>
7428 &&\multicolumn{4}{c}{後ろ側の文字}\\\cmidrule(lr){3-7}
7429 &&\hbox to 4em{\hss Letter\hss}&\hbox to 4em{\hss Other\hss}
7430 &\hbox to 4em{\hss Kanji\hss}&\hbox to 4em{\hss Open\hss}&Close\\\midrule
7431 直&Letter&収集&\multicolumn{3}{c}{\hrulefill \ 出力\ \hrulefill}&収集\\
7432 前&Other&出力&収集&\multicolumn{2}{c}{\hrulefill \ 出力\ \hrulefill}&収集\\
7433 文&Kanji&\multicolumn{4}{c}{\hrulefill \ 出力\ \hrulefill}&収集\\
7434 字&Open&\multicolumn{5}{c}{\hrulefill \ 収集\ \hrulefill}\\
7435 種&Close&\multicolumn{4}{c}{\hrulefill \ 出力\ \hrulefill}&収集\\
7436 %</ja>
7437 \bottomrule
7438 \end{tabular}
7439 \end{center}
7440 %<en>In the above table,
7441 %<ja>上の表において,
7442 \begin{itemize}
7443 %<en>\item ``outputs'' means to output the collected character string (i.e., line breaking is permitted there).
7444 %<ja>\item 「出力」は,それまでに集めた文字列を出力(≒ここで行分割可能)を意味する.
7445
7446 %<en>\item ``collects'' means to append the next character to the collected character string (i.e., line breaking is prohibited there).
7447 %<ja>\item 「収集」は,後側の文字を,現在収集された文字列に追加(行分割不可)を意味する.
7448 \end{itemize}
7449
7450 %<*en>
7451 Characters above \texttt{U+0080} \emph{except Variation Selectors}
7452 are classified into above 5~classes by the following rules:
7453 %</en>
7454 %<*ja>
7455 \texttt{U+0080}以降の\emph{異体字セレクタ以外の}各文字が
7456 Letter, Other, Kanji, Open, Closeのどれに属するかは次によって決まる:
7457 %</ja>
7458 \begin{itemize}
7459 %<en>\item \textbf{ALchar}s above \texttt{U+0080} are classified as Letter.
7460 %<ja>\item (\texttt{U+0080}以降の)\textbf{ALchar}は,すべてLetter扱いである.
7461
7462 %<en>\item \textbf{JAchar}s are classified in the order as follows:
7463 %<ja>\item \textbf{JAchar}については,以下の順序に従って文字種を決める:
7464 \begin{enumerate}
7465 %<en>\item Characters whose \Param{prebreakpenalty} is greater than or equal to 0 are classified as Open.
7466 %<ja>\item \Param{prebreakpenalty}が0以上の文字はOpen扱いである.
7467
7468 %<en>\item Characters whose \Param{postbreakpenalty} is greater than or equal to 0 are classified as Close.
7469 %<ja>\item \Param{postbreakpenalty}が0以上の文字はClose扱いである.
7470
7471 %<en>\item Characters that don't satisfy the above two conditions are classified as Kanji.
7472 %<ja>\item 上の3条件のどちらにも当てはまらなかった文字は,Kanji扱いである.
7473 \end{enumerate}
7474 \end{itemize}
7475
7476 %<*en>
7477 The width of halfwidth kana (\texttt{U+FF61}--\texttt{U+FF9F})
7478 is same as the width of \textbf{ALchar};
7479 the width of the other \textbf{JAchar}s is double the width of \textbf{ALchar}.
7480 %</en>
7481 %<*ja>
7482 なお,半角カナ(U+FF61--U+FF9F)以外の\textbf{JAchar}は欧文文字2文字分の幅をとるものとみなされる.
7483 半角カナは欧文文字1文字分の幅となる.
7484 %</ja>
7485
7486 %<*en>
7487 This classification process is executed every time a character appears in
7488 the \texttt{lstlisting} environment or other environments/commands.
7489 %</en>
7490 %<*ja>
7491 これらの文字種決定は,実際に \texttt{lstlisting} 環境などの内部で文字が出てくるたびに行われる.
7492 %</ja>
7493
7494 %<*ja>
7495 \section{和文の行長補正方法}
7496 \label{sec-adjspec}
7497 \Pkg{luatexja-adjust} で提供される優先順位付きの行長調整の詳細を述
7498 べる.大まかに述べると,次のようになる.
7499 \begin{itemize}
7500 \item 通常の\TeX の行分割方法に従って,段落を行分割する.この段階では,行
7501       長に半端が出た場合,その半端分は\textbf{JAglue}(\Param{xkanjiskip},
7502       \Param{kanjiskip},JFMグルー)と
7503       それ以外のグルーの全てで(優先順位なく)負担される.
7504 \item その後,\texttt{post\_linebreak\_filter} callbackを使い,\emph{段
7505       落中の各行ごとに},行末文字の位置を調整したり,優先度付きの行長調整
7506       を実現するためにグルーの伸縮度を調整する.
7507       その処理においては,グルーの自然長と\textbf{JAglue}以外の
7508       グルーの伸び量・縮み量は変更せず,必要に応じて\textbf{JAglue}の伸び量・縮み量のみを
7509       変更する設計とした.
7510
7511 \Pkg{luatexja-adjust} の作用は,この処理を行うcallbackを追加するだけであり,
7512       この章の残りではcallbackでの処理について解説する.
7513 \end{itemize}
7514
7515 \paragraph{準備:合計伸縮量の計算}
7516 グルーの伸縮度(\texttt{plus} や \texttt{minus} で指定されている値)には,
7517 有限値の他に,\texttt{fi},\texttt{fil},\texttt{fill},\texttt{filll}と
7518 いう4つの無限大レベル(後ろの方ほど大きい)があり,行の調整に
7519 \texttt{fi} などの\emph{無限大レベルの伸縮度が用いられている場合は,そ
7520 の行に対しての処理を中止}する.
7521
7522 よって,以降,問題にしている行の行長調整は伸縮度が有限長のグルーを用いて
7523 行われているとして良い.さらに,簡単のため,この行はグルーが広げられている
7524 (自然長で組むと望ましい行長よりの短い)場合しか扱わない.
7525
7526 まず,段落中の行中のグルーを
7527 \begin{itemize}
7528 \item \textbf{JAglue}ではないグルー
7529 \item JFMグルー(優先度\footnote{%
7530   \ref{ssec-jfm-str}節にあるように,
7531   各JFMグルーには$-2$から2までの優先度がついている.}%
7532 別にまとめられる)
7533 \item 和欧文間空白(\Param{xkanjiskip})
7534 \item 和文間空白(\Param{kanjiskip})
7535 \end{itemize}
7536 の$1+1+5+1=8$つに類別し,それぞれの種別ごとに
7537 許容されている伸び量(\texttt{stretch}の値)の合計を計算する.
7538 また,行長と自然長との差を\textit{total}とおく.
7539
7540
7541 \subsection{行末文字の位置調整}
7542 行末が文字クラス$n$の\textbf{JAchar}であった場合,
7543 それを動かすことによって,\textit{total}のうち
7544 \textbf{JAglue}が負担する分を少なくしようとする.
7545 この行末文字の左右の移動可能量は,
7546 JFM中にある文字クラス$n$の定義の
7547 \texttt{end\_stretch},~\texttt{end\_shrink}フィールドに
7548 全角単位の値として記述されている.
7549
7550 例えば,行末文字が句点「。」であり,そこで用いられているJFM中に
7551 \begin{verbatim}
7552   [2] = {
7553     chars = { '。', ... }, width = 0.5, ...,
7554     end_stretch = 0.5, end_shrink = 0.5,
7555   },
7556 \end{verbatim}
7557 という指定があった場合,この行末の句点は
7558 \begin{itemize}
7559 \item 通常の\TeX の行分割処理で「半角以上の詰め」が行われていた場合,
7560 この行中の\textbf{JAglue}の負担を軽減するため,
7561 行末の句点を半角だけ右に移動する(ぶら下げ組を行う).
7562 \item 通常の\TeX の行分割処理で「半角以上の空き」が行われていた場合,
7563 逆に行末句点を半角左に移動させる(見た目的に全角取りとなる).
7564 \item 以上のどちらでもない場合,行末句点の位置調整は行わない.
7565 \end{itemize}
7566 となる.
7567
7568 行末文字を移動した場合,その分だけ\textit{total}の値を引いておく.
7569
7570 \subsection{グルーの調整}
7571 \textit{total}の分だけが,行中のグルーの伸び量に応じて負担されることになる.
7572 負担するグルーの優先度は以下の順であり,
7573 できるだけ\Param{kanjiskip}を自然長のままにすることを
7574 試みている.
7575 \begin{enumerate}\def\labelenumi{(\Alph{enumi})}
7576  \item \textbf{JAglue}以外のグルー
7577  \item 優先度2のJFMグルー
7578  \item 優先度1のJFMグルー
7579  \item 優先度0のJFMグルー
7580  \item 優先度$-1$のJFMグルー
7581  \item 優先度$-2$のJFMグルー
7582  \item \Param{xkanjiskip}
7583  \item \Param{kanjiskip}
7584 \end{enumerate}
7585 \begin{enumerate}
7586  \item 行末の和文文字を移動したことで$\textit{total}=0$となれば,
7587 調整の必要はなく,行が格納されているhboxの
7588 \texttt{glue\_set}, \texttt{glue\_sign}, \texttt{glue\_order}を再計算すればよい.
7589 以降,$\textit{total}\neq 0$と仮定する.
7590  \item \textit{total}が「\textbf{JAglue}以外のグルーの伸び量の合計」(以下,(A)の伸び量の
7591        合計,と称す)よりも小さければ,
7592 それらのグルーに\textit{total}を負担させ,\textbf{JAglue}達自身は自然長で組むことができる.
7593 よって,以下の処理を行う:
7594 \begin{enumerate}
7595 \item 各\textbf{JAglue}の伸び量を0とする.
7596 \item 行が格納されているhboxの
7597 \texttt{glue\_set}, \texttt{glue\_sign}, \texttt{glue\_order}を再計算する.
7598 これによって,\textit{total}は\textbf{JAglue}以外のグルーによって負担される.
7599 \end{enumerate}
7600 \item \textit{total}が「(A)の伸び量の合計」以上ならば,(A)--(H)のどこまで負担すれば
7601 \textit{total}以上になるかを計算する.
7602 例えば,
7603 \[\catcode`\<=12
7604  \textit{total} = (\text{(A)--(B)の伸び量の合計}) + p\cdot (\text{(C)の伸び量の合計}),
7605  \qquad 0\le p<1
7606 \]
7607 であった場合,各グルーは次のように組まれる:
7608 \begin{itemize}
7609  \item (A),~(B)に属するグルーは各グルーで許された伸び量まで伸ばす.
7610  \item (C)に属するグルーはそれぞれ$p\times (\text{伸び量})$だけ伸びる.
7611  \item (D)--(H)に属するグルーは自然長のまま.
7612 \end{itemize}
7613 実際には,前に述べた「設計」に従い,次のように処理している:
7614 \begin{enumerate}
7615 \item (C)に属するグルーの伸び量を$p$倍する.
7616 \item (D)--(H)に属するグルーの伸び量を0とする.
7617 \item 行が格納されているhboxの
7618 \texttt{glue\_set}, \texttt{glue\_sign}, \texttt{glue\_order}を再計算する.
7619 これによって,\textit{total}は\textbf{JAglue}以外のグルーによって負担される.
7620 \end{enumerate}
7621 \item \textit{total}が(A)--(H)の伸び量の合計よりも大きい場合,どうしようもないので
7622       \verb+^^;+何もしない.
7623 \end{enumerate}
7624
7625 %</ja>
7626
7627 %<*ja>
7628 \section{IVS対応}
7629 \verb+luatexja.otf.enable_ivs()+ を実行し,IVS対応を有効にした状態では,
7630 \verb+pre_linebreak_filter+ や \verb+hpack_filter+ コールバックには
7631 次の4つが順に実行される状態となっている:
7632 \begin{description}
7633 \item[\tt ltj.do\_ivs] \textit{glyph\_node}~$p$の直後に,異体字セレクタ(を表す\textit{glyph\_node})
7634 が連続した場合に,$p$のフォントに対応したが持つ「異体字情報」に従って出力するグリフを変える.
7635
7636 しかし,単に$p.\textit{char}$を変更するだけでは,後から
7637 font featureの適用(すぐ下)により置換される可能性がある.そのため,
7638 \verb+\CID+ や \verb+\UTF+ と同じように,\textit{glyph\_node}~$p$の代わりに
7639 \texttt{user\_id} が\textit{char\_by\_cid}であるようなuser-defined whatsitを用いている.
7640 \item[(\Pkg{luaotfload} によるfont featureの適用)]
7641 \item[\tt ltj.otf] \texttt{user\_id} が\textit{char\_by\_cid}であるようなuser-defined whatsitを
7642 きちんと\textit{glyph\_node}に変換する.この処理は,\verb+\CID+, \verb+\UTF+やIVSによる置換が,
7643 font featureの適用で上書きされてしまうのを防止するためである.
7644 \item[\tt ltj.main\_process] \textbf{JAglue}の挿入処理(\ref{sec-jfmglue}章)と,
7645 JFMの指定に従って各\textbf{JAchar}の「寸法を補正」することを行う.
7646 \end{description}
7647
7648 問題は各フォントの持っているIVS情報をどのように取得するか,である.
7649 \Pkg{luaotfload} はフォント番号<font\_number>の情報を\
7650 \texttt{fonts.hashes.identifiers[<font\_number>]} 以下に格納している.
7651 しかし,OpenTypeフォントのIVS情報は格納されていないようである%
7652 \footnote{TrueTypeフォントに関しては,
7653 \begin{center}
7654 \texttt{fonts.hashes.idenfiers[<font\_number>]%
7655   .resources.variants[<selector>][<base\_char>]}
7656 \end{center}
7657 に,<base\_char>番の文字の後に異体字セレクタ<selector>が続いた場合に
7658 出力すべきグリフが書かれてある.}.
7659 %例えば,小塚明朝Pr6N~Rでは,
7660
7661 一方,\LuaTeX 内部の \texttt{fontloader} の返すテーブルには
7662 OpenTypeフォントでもTrueTypeフォントでもIVS情報が格納されている.
7663 具体的には……
7664
7665 そのため,\LuaTeX-jaのIVS対応においては,\LuaTeX 内部の\
7666 \texttt{fontloader} を直接用いることで,フォントのIVS情報を取得している.
7667 20140114.0以降でキャッシュを用いるようにした要因はここにあり,
7668 \texttt{fontloader} の呼び出しでかなり時間を消費することから,
7669 %%% to_table を使わなくしたことで,メモリ使用量は減った
7670 IVS情報をキャッシュに保存することで2回目以降の実行時間を節約している.
7671
7672
7673 \section{複数フォントの「合成」(未完)}
7674
7675 \section{\LuaTeX-jaにおけるキャッシュ}
7676 \Pkg{luaotfload}パッケージが,各TrueType・OpenTypeフォントの情報を
7677 キャッシュとして保存しているのと同様の方法で,
7678 \LuaTeX-jaもいくつかのキャッシュファイルを作成するようになった.
7679 \begin{itemize}
7680  \item 通常,キャッシュは\texttt{\$TEXMFVAR/luatexja/}以下に保存され,
7681 そこから読み込みが行われる.
7682  \item 「通常の」テキスト形式のキャッシュ(拡張子は \texttt{.lua})以外にも,
7683 それをバイナリ形式(バイトコード)に変換したものもサポートしている.
7684 \begin{itemize}
7685  \item \LuaTeX とLuaJIT\TeX ではバイトコードの形式が異なるため,バイナリ形式の
7686 キャッシュは共有できない.\LuaTeX 用のバイナリキャッシュは \texttt{.luc},
7687 LuaJIT\TeX 用のは \texttt{.lub} と拡張子を変えることで対応している.
7688  \item キャッシュを読み込む時,同名のバイナリキャッシュがあれば,
7689 テキスト形式のものよりそちらを優先して読み込む.
7690  \item テキスト形式のキャッシュが更新/作成される際は,そのバイナリ版も
7691 同時に更新される.
7692 また,(バイナリ版が見つからず)テキスト形式のキャッシュ側が読み込まれたときは,
7693 \LuaTeX-jaはバイナリキャッシュを作成する.
7694 \end{itemize}
7695 \end{itemize}
7696 %</ja>
7697 %<*en>
7698 \section{Cache Management of \LuaTeX-ja}
7699 \LuaTeX-ja creates some cache files to reduce the loading time.
7700 in a similar way to the \Pkg{luaotfload} package:
7701 \begin{itemize}
7702  \item Cache files are usually stored in (and loaded from)
7703 \texttt{\$TEXMFVAR/luatexja/}.
7704  \item In addition to caches of the text form (the extension is ``\texttt{.lua}''),
7705 caches of the \emph{binary}, precompiled form are supported.
7706 \begin{itemize}
7707  \item We cannot share same binary cache for \LuaTeX\ and LuaJIT\TeX.
7708 Hence we distinguish them by their extension, ``\texttt{.luc}'' for \LuaTeX\
7709 and ``\texttt{.lub}'' for LuaJIT\TeX.
7710  \item In loading a cache, the binary cache precedes
7711 the text form.
7712  \item When \LuaTeX-ja updates a cache \texttt{hoge.lua},
7713 its binary version is also updated.
7714 \end{itemize}
7715 \end{itemize}
7716 %</en>
7717
7718 %<*ja>
7719 \subsection{キャッシュの使用箇所}
7720
7721 \LuaTeX-ja では以下の3種類のキャッシュを使用している:
7722 \begin{list}{}%
7723 {\def\makelabel#1{\ttfamily#1}}
7724 \item[ltj-cid-auto-adobe-japan1.lua]
7725 Ryumin-Lightのような非埋め込みフォントの情報を格納しており,
7726 (それらが\LuaTeX-jaの標準和文フォントなので)\LuaTeX-jaの読み込み時に自動で読まれる.
7727 生成には\texttt{UniJIS2004-UTF32-H}, \texttt{Adobe-Japan1-UCS2}という2つの
7728 CMapが必要である.
7729
7730 \pageref{para-cid}ページで述べたように,\texttt{cid}キーを使って
7731 非埋め込みの中国語・韓国語フォントを定義する場合,同様のキャッシュが生成される.
7732 キャッシュの名称,必要となるCMapについては表\ref{tab:cid-cache}を参照して欲しい.
7733
7734 \item[ivs\_***.lua]
7735 フォント``\texttt{***}''における異体字情報を格納している.構造は以下の通り:
7736 %</ja>
7737 %<*en>
7738 \subsection{Use of Cache}
7739
7740 \LuaTeX-ja uses the following cache:
7741 \begin{list}{}%
7742 {\def\makelabel#1{\ttfamily#1}}
7743 \item[ltj-cid-auto-adobe-japan1.lua]
7744 The font table of a CID-keyed non-embedded Japanese font.
7745 This is loaded in every run.
7746 It is created from two CMaps, \texttt{UniJIS2004-UTF32-H} and
7747              \texttt{Adobe-Japan1-UCS2},
7748 and this is why these two CMaps are needed in the first run of \LuaTeX-ja.
7749
7750 Similar caches are created as Table~\ref{tab:cid-cache},
7751 if you specified \texttt{cid} key in \verb+\jfont+
7752 to use other CID-keyed non-embedded fonts for Chinese or Korean,
7753 as in Page~\pageref{para-cid}.
7754
7755 \item[ivs\_***.lua]
7756 This file stores the table of Unicode variants in a font ``\texttt{***}''.
7757 The structure of the table is the following:
7758 %</en>
7759
7760 \begin{table}[!tb]
7761  \centering\small
7762 \caption{\texttt{cid} key and corresponding files}
7763 \label{tab:cid-cache}
7764 \vspace*{\medskipamount}
7765 \begin{tabular}{>{\tt}l>{\tt}l>{\tt}l>{\tt}l}
7766 \toprule
7767 \bf \texttt{cid} key&\bf name of the cache &
7768 \multicolumn{2}{c}{\bf used CMaps}\\
7769 \midrule
7770 Adobe-Japan1-*&ltj-cid-auto-adobe-japan1.lua&UniJIS2004-UTF32-H&Adobe-Japan1-UCS2\\
7771 Adobe-Korea1-*&ltj-cid-auto-adobe-korea1.lua&UniKS-UTF32-H&Adobe-Korea1-UCS2\\
7772 Adobe-GB1-*&ltj-cid-auto-adobe-gb1.lua&UniGB-UTF32-H&Adobe-GB1-UCS2\\
7773 Adobe-CNS1-*&ltj-cid-auto-adobe-cns1.lua&UniCNS-UTF32-H&Adobe-CNS1-UCS2\\
7774 \bottomrule
7775 \end{tabular}
7776 \end{table}
7777
7778 \begin{lstlisting}
7779 return {
7780  {
7781   [10955]={    -- U+2ACB "Subset Of Above Not Equal To"
7782    [65024]=983879, -- <2ACB FE00>
7783   },
7784   [37001]={    -- U+9089 "邉"
7785    [0]=37001,  --   <9089 E0100>
7786    991049,     --   <9089 E0101>
7787    ...
7788   },
7789   ...
7790  },
7791  ["chksum"]="FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", -- checksum of the fontfile
7792  ["version"]=4, -- version of the cache
7793 }
7794 \end{lstlisting}
7795 %<*ja>
7796 \item[ltj-jisx0208.\{luc|lub\}]
7797 \LuaTeX-ja配布中の\texttt{ltj-jisx0208.lua}をバイナリ化したものである.
7798 これはJIS~X~0208とUnicodeとの変換テーブルであり,
7799 \pTeX との互換目的の文字コード変換命令で用いられる.
7800 %</ja>
7801 %<*en>
7802 \item[ltj-jisx0208.\{luc|lub\}]
7803 The binary version of \texttt{ltj-jisx0208.lua}.
7804 This is the conversion table between JIS~X~0208 and Unicode
7805 which is used in Kanji-code conversion commands for compatibility with \pTeX.
7806 %</en>
7807 \end{list}
7808
7809 %<*en>
7810 \subsection{Internal}
7811 Cache management system of \LuaTeX-ja is stored in \texttt{luatexja.base}
7812 (\texttt{ltj-base.lua}).
7813 There are three public functions for cache management in \texttt{luatexja.base},
7814 where <filename> stands for the file name \emph{without suffix}:
7815 \begin{list}{}%
7816 {\def\makelabel#1{\ttfamily#1}}
7817 \item[save\_cache(<filename>, <data>)]
7818 Save a non-nil table <data> into a cache <filename>.
7819 Both the text form <filename>\texttt{.lua} and its binary version
7820 are created or updated.
7821
7822 \item[save\_cache\_luc(<filename>, <data>{[, <serialized\_data>]})]\
7823
7824 Same as \texttt{save\_cache}, except that only the binary cache is updated.
7825 The third argument <serialized\_data> is not usually given.
7826 But if this is given, it is treated as a string representation of <data>.
7827
7828 \item[load\_cache(<filename>, <outdate>)]
7829 Load the cache <filename>.
7830 <outdate> is a function which takes one argument (the contents of the cache),
7831 and its return value is whether the cache is outdated.
7832
7833 \texttt{load\_cache} first tries to
7834 read the binary cache <filename>\texttt{.\{luc|lub\}}.
7835 If its contents is up-to-date, \texttt{load\_cache} returns the contents.
7836 If the binary cache is not found or
7837 its contents is outdated, \texttt{load\_cache} tries to
7838 read the text form <filename>\texttt{.lua}.
7839 Hence, the return value of \texttt{load\_cache} is non-nil,
7840 if and only if the updated cache is found.
7841 \end{list}
7842 %</en>
7843 %<*ja>
7844 \subsection{内部命令}
7845 \LuaTeX-jaにおけるキャッシュ管理は,\texttt{luatexja.base}~(\texttt{ltj-base.lua})に
7846 実装しており,以下の3関数が公開されている.
7847 ここで,<filename>は保存するキャッシュのファイル名を\emph{拡張子なしで}指定する.
7848 \begin{list}{}%
7849 {\def\makelabel#1{\ttfamily#1}}
7850 \item[save\_cache(<filename>, <data>)]
7851 nilでない<data>をキャッシュ<filename>に保存する.
7852 テキスト形式の<filename>\texttt{.lua}のみならず,
7853 そのバイナリ版も作成/更新される.
7854
7855 \item[save\_cache\_luc(<filename>, <data>{[, <serialized\_data>]})]\
7856
7857 \texttt{save\_cache}と同様だが,バイナリキャッシュのみが更新される.
7858 第3引数<serialized\_data>が与えられた場合,それを
7859 <data>の文字列化表現として使用する.
7860 そのため,<serialized\_data>は普通は指定しないことになるだろう.
7861
7862 \item[load\_cache(<filename>, <outdate>)]
7863 キャッシュ<filename>を読み込む.
7864 <outdate>は1引数(キャッシュの中身)をとる関数であり,
7865 その戻り値は「キャッシュの更新が必要」かどうかを示すブール値でないといけない.
7866
7867 \texttt{load\_cache}は,まずバイナリキャッシュ<filename>\texttt{.\{luc|lub\}}を
7868 読みこむ.もしその内容が「新しい」,つまり<outdate>の評価結果が \texttt{false} なら
7869 \texttt{load\_cache}はこのバイナリキャッシュの中身を返す.
7870 もしバイナリキャッシュが見つからなかったか,「古すぎる」ならばテキスト版
7871              <filename>\texttt{.lua}を読み込み,その値を返す.
7872
7873 以上より,\texttt{load\_cache}自体がnilでない値を返すのは,ちょうど「新しい」キャッシュが
7874 見つかった場合である.
7875 \end{list}
7876 %</ja>
7877
7878
7879 %<*ja>
7880 \section{縦組の実装}
7881 \label{sec-dir-imp}
7882 \ref{sec-direction}章の最初でも述べたように,
7883 \LuaTeX-jaは横組(\texttt{TLT})で組んだボックスを回転させる方式で
7884 縦組を実装している.
7885
7886 \LuaTeX-jaにおける縦組の実装は
7887 \pTeX における実装(\cite{ptexdoc,ptextug})をベースにしており,……
7888
7889 \subsection{\textit{direction}~whatsit}
7890 \textit{direction}~whatsitとは,\textit{direction}という特定の \verb+user_id+ を持つ
7891 whatsitのことである.このwhatsitは,以下の3つの役割がある.
7892 \begin{enumerate}
7893 \def\labelenumi{(\roman{enumi})}
7894  \item 「現在作成中のリストの組方向が \verb+\tate+ 等により変更された」ことを表す.\\
7895 「現在の組方向」は \verb+\ltj@dir@count+ というカウンタに格納されているが,それだけでは
7896 \verb+hpack_filter+コールバックなどから正しく処理対象のリストの組方向を正しく取得すること
7897        はできない(\ref{ssec-stack}節参照)ため,このように別途whatsitを用いている.
7898  \item \verb+\hbox+,~\verb+\vbox+によって作成されたボックスの組方向を表す.\\
7899 原則として,ボックスの組方向はattribute \verb+\ltj@dir+ に格納されることになっている.しか
7900        し,新規に作成されるボックスのattributeをコールバックの内部から制御するには,
7901 \verb+tex.setattribute+ による方法しかなく,これは不安定である.
7902
7903 なお,この役割のdirection whatsitは,次の(iii)の役割も一緒に持っている.
7904  \item 「異方向における寸法」の記録用.\\
7905 例えば \verb+\box0+ に横組のボックスが格納されている時,縦組や \verb+\dtou+ 方向
7906 における寸法値は((ii)の役割として作成された)direction~whatsitが
7907 格納しているノードリストに格納される.
7908 \end{enumerate}
7909 このように複数の役割をもたせているので,
7910 \begin{verbatim}
7911 % yoko direction
7912 \setbox0=\hbox{\tate B}
7913 \noindent \unhbox0 A
7914 \end{verbatim}
7915 のような場合に,「(ii)の役割の\textit{direction}~whatsitが(i)の役割として認識され,
7916 このリストは縦組とみなされるのではないか?」と思うかもしれない.しかし,
7917 (i)の役割と(ii)の枠割の\textit{direction}~whatsitは \verb+\ltj@icflag+ の値により
7918 区別されているので,そのような混乱は起こらない.
7919
7920 \medskip
7921 (ii)の役割のdirection whatsitは,各ボックスの内容を表すリストの先頭に挿入されるが,
7922 例外が以下の2つある:
7923 \begin{itemize}
7924  \item \verb+\hbox{}+, \verb+\vbox{}+ といった,
7925 \begin{itemize}
7926  \item \verb+\tate+ 等によりボックス内部の組方向を変更していない
7927  \item ボックスの中身のリストが空である
7928 \end{itemize}
7929 場合は,\LuaTeX の \verb+hpack_filter+, \verb+vpack_filter+ といった
7930 callbackに処理が回らないので,この場合にはdirection whatsitは挿入されない.
7931  \item \verb+\vtop{...}+ の場合は,先頭にdirection whatsitを置くと
7932 ボックスの高さが正しく設定されない.そのため,この場合に限っては
7933 direction whatsitはリストの2番目に挿入されることとなる.
7934 \end{itemize}
7935
7936 \subsection{異方向のボックスの整合処理}
7937 縦中横など異方向のボックスを配置する場合に,周囲の組方向と大きさを整合させるため,
7938 \LuaTeX-jaでは \verb+\ltj@dir+ が128以降の\textit{hlist\_node}, \textit{vlist\_node}を
7939 用いる.これらは\pTeX における\textit{dir\_node}の役割と同じ果たしており,
7940 この文章中でも\textit{dir\_node}と呼称する.
7941
7942 %</ja>
7943
7944 \begin{thebibliography}{99}
7945   \addcontentsline{toc}{section}{\refname}
7946 \bibitem{texbytopic}
7947 Victor Eijkhout. \newblock \textit{\TeX\ by Topic, A \TeX nician's Reference}, Addison-Wesley, 1992.
7948 \bibitem{listings} C.\ Heinz, B.\ Moses. \newblock The \textsf{Listings} Package.
7949 \bibitem{uptex} Takuji Tanaka. \newblock
7950 upTeX---Unicode version of pTeX with CJK extensions,
7951 TUG 2013, October 2013.
7952 %<ja>\newblock
7953 %<en>\\\null\hfill
7954 \url{http://tug.org/tug2013/slides/TUG2013_upTeX.pdf}
7955 \bibitem{jlisting} Thor Watanabe. \newblock Listings\ -\ MyTeXpert.
7956 %<en>\newblock
7957 %<ja>\\\null\hfill
7958 \url{http://mytexpert.sourceforge.jp/index.php?Listings}
7959 \bibitem{jlreq}  W3C Japanese Layout Task Force~(ed). \newblock
7960 Requirements for Japanese Text Layout (W3C Working Group Note), 2011, 2012. \newblock
7961 \url{http://www.w3.org/TR/jlreq/}%
7962 %<ja> \\日本語訳の書籍版:W3C日本語組版タスクフォース(編),『W3C技術ノート 日本語組版処理の要件』,東京電機大学出版局,2012.
7963 \bibitem{min10} 乙部厳己.min10フォントについて.\\\null\hfill
7964 \url{http://argent.shinshu-u.ac.jp/~otobe/tex/files/min10.pdf}
7965 \bibitem{x4051} 日本工業規格(Japanese Industrial Standard). JIS~X~4051,
7966 日本語文書の組版方法(Formatting rules for Japanese documents), 1993, 1995, 2004.
7967 \bibitem{ptexdoc} 濱野尚人,田村明史,倉沢良一.\TeX の出版への応用—縦組み機能の組み込み—.
7968 \\\null\hfill\texttt{.../texmf-dist/doc/ptex/base/ptexdoc.pdf}
7969 \bibitem{ptextug} Hisato Hamano. \newblock
7970 \textit{Vertical Typesetting with \TeX}, TUGBoat~\textbf{11}(3), 346--352, 1990.
7971 \end{thebibliography}
7972
7973 \newpage
7974 \appendix
7975
7976 \section{Package versions used in this document}
7977 This document was typeset using the following packages:
7978
7979 \medskip
7980
7981 {\makeatletter\tt\footnotesize
7982   \def\@pkglist#1{%
7983     \filename@parse{#1}\def\@temp{sty}
7984     \ifx\@temp\filename@ext
7985       \edef\reserved@a{%
7986         \filename@base.%
7987         \ifx\filename@ext\relax tex\else\filename@ext\fi}%
7988       \leavevmode\hskip-13em\hbox to 13em{\filename@area\reserved@a\hss}%
7989       \csname ver@\reserved@a\endcsname\par
7990     \fi
7991   }%
7992 \parindent0pt\leftskip13em
7993 \ltjpkglist
7994
7995 \makeatother}
7996 \end{document}
7997 %</!showexpl>
7998 %<*showexpl>
7999 %%
8000 %% config file for showexpl.sty
8001 %%
8002 %% Copyright The LuaTeX-ja project team, 2012
8003 %%
8004 \ProvidesFile{showexpl.cfg}
8005   [2012/05/20 v0.01 Definitions for the showexpl package (luatexja)]
8006 \lstset{}
8007 \def\SX@Info{}
8008 \endinput
8009 %</*showexpl>