OSDN Git Service

luatexja-preset.sty: added "moga-mobo" option.
[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 \directlua{if jit then jit.on() end}
19
20 \usepackage{amsmath,array,tikz,pict2e,multienum,float}
21 \usepackage{booktabs,multicol,luatexja-ruby}
22 \usepackage[all]{xy}
23 \usepackage{lltjext,alltt}
24
25 %%%%%%%% fonts
26 \usepackage{luatexja-otf}
27 \directlua{luatexja.otf.enable_ivs()}
28 \usepackage[match]{luatexja-fontspec}
29 \usepackage[kozuka-pr6n]{luatexja-preset}
30 \usepackage{unicode-math}
31 \setmainfont[Ligatures=TeX]{Linux Libertine O}
32 \setsansfont[Scale=0.95,Ligatures=TeX]{TeX Gyre Heros}
33 \setmonofont[Scale=MatchLowercase, ItalicFont=lmmono10-italic.otf,
34   BoldFont=lmmonolt10-bold.otf, BoldItalicFont=lmmonolt10-boldoblique.otf
35 ]{lmmono10-regular.otf}
36 \setmonojfont{KozGoPr6N-Regular.otf}
37 \setmathfont[Scale=MatchLowercase]{xits-math.otf}
38 %<*ja>
39 \def\emph#1{\textbf{\textgt{#1}}}
40 \def\headfont{\normalfont\bfseries\gtfamily}\normalsize
41 %</ja>
42 %<en>\frenchspacing
43
44 %<*en>
45 \usepackage[margin=25mm,lmargin=30mm,rmargin=30mm,footskip=6mm]{geometry}
46 \usepackage{luatexja-adjust}\ltjdisableadjust
47 \parskip=\smallskipamount
48 \renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}%
49     {3.25ex \@plus1ex \@minus.2ex}%
50     {-1em}%
51     {\normalfont\normalsize\bfseries\raisebox{.2ex}{$\mdlgblksquare\mkern1mu$}}}
52 %</en>
53 %<*ja>
54 \usepackage[textwidth=45\zw, lines=45, footskip=6mm]{geometry}
55 \usepackage{luatexja-adjust}%\ltjdisableadjust
56 \advance\leftmargini-1\zw\advance\leftmarginii-1\zw
57 %</ja>
58
59 %%%%%%%% listings
60
61 %%%%%%%% IVS
62
63 \def\IVS#1{\char\numexpr "E0100+#1\relax}%"
64 \def\IVSA#1#2#3#4#5{%
65   \textcolor{blue}{\raisebox{3.5pt}{\tt%
66     \fboxsep=0.5pt\fbox{\tiny \oalign{0#1#2\crcr#3#4#5\crcr}}}}%
67 }
68 {\catcode`\%=11
69   \gdef\IVSB#1{\expandafter\IVSA\directlua{
70     local cat_str = luatexbase.catcodetables['string']
71     tex.sprint(cat_str, string.format('%X', 0xE00EF+#1))
72 }}}
73
74 \usepackage{listings,showexpl,enumitem}
75 \lstset{
76   basicstyle=\ttfamily\small, pos=r, breaklines=true,
77   numbers=none, rframe={}, basewidth=0.5em, numberstyle=\tiny, numbersep=0.5em,
78   explpreset={numberstyle=\tiny, numbers=left, numbersep=1em, columns=fixed}
79 }
80 % Suppress output from showexpl to stdout.
81 \let\SX@Info\relax
82
83 %%%%%%%% colors
84 %% modified from http://jfly.iam.u-tokyo.ac.jp/colorset/
85 \usepackage{transparent}
86 \definecolor{red}{rgb}{1, 0.16, 0}
87 \definecolor{blue}{rgb}{0, 0.25, 1}
88 \definecolor{gray}{rgb}{.50, .53, .56}
89 \definecolor{green}{rgb}{.21, .63, .42}
90 \definecolor{cyan}{rgb}{0.40, .80, 1}
91 \definecolor{b_gray}{rgb}{0.78, 0.78, 0.80}
92 \definecolor{b_pink}{rgb}{1, 0.82, 0.82}
93 \definecolor{b_green}{rgb}{.53, .91, .69}
94 \definecolor{b_cyan}{rgb}{0.70, .92, 98}
95
96 %%%%%%%% hyperref
97 \usepackage{hyperref,bookmark}
98 %<*en>
99 \title{The \LuaTeX-ja package}
100 \author{The \LuaTeX-ja project team}
101 %</en>
102 %<*ja>
103 \title{\LuaTeX-jaパッケージ}
104 \author{\LuaTeX-jaプロジェクトチーム}
105 %</ja>
106 \hypersetup{%
107         unicode,
108         colorlinks,
109         allbordercolors=1 1 1,
110         allcolors=blue,
111 %<*en>
112         pdfauthor={The LuaTeX-ja project team},
113         pdftitle={The LuaTeX-ja package}
114 %</en>
115 %<*ja>
116         pdfauthor={LuaTeX-jaプロジェクトチーム},
117         pdftitle={LuaTeX-jaパッケージ}
118 %</ja>
119 }
120
121 %%%%%%%% definition env.
122 \usepackage{amsthm}
123 \theoremstyle{definition}
124 %<en>\newtheorem{defn}{Definition}
125 %<ja>\newtheorem{defn}{定義}
126
127 %%%%%%%% logo
128 \usepackage{metalogo}
129 \DeclareRobustCommand\eTeX{\ensuremath{\varepsilon}-\kern-.125em\TeX}
130 \DeclareRobustCommand\LuaTeX{Lua\TeX}
131 \DeclareRobustCommand\pdfTeX{pdf\TeX}
132 \DeclareRobustCommand\pTeX{p\kern-.15em\TeX}
133 \DeclareRobustCommand\upTeX{up\kern-.15em\TeX}
134 \DeclareRobustCommand\pLaTeX{p\kern-.05em\LaTeX}
135 \DeclareRobustCommand\pLaTeXe{p\kern-.05em\LaTeXe}
136 \DeclareRobustCommand\epTeX{\ensuremath{\varepsilon}-\pTeX}
137
138 %%%%%%%% other macros
139 \newlist{cslist}{description}{1}
140 \setlist[cslist]{%
141     style=nextline,font=\mdseries\ttfamily,
142     before*=\def\<{\char`\<}\def\>{\char`\>}\def\{{\char`\{}\def\}{\char`\}},
143 %<ja> leftmargin=2\zw,
144 %<en> leftmargin=2em,
145 }
146
147 \def\labelenumii{(\arabic{enumii})}
148 \long\def\@makecaption#1#2{%
149   \vskip\abovecaptionskip
150   \sbox\@tempboxa{{\small #1. #2}}%
151   \ifdim \wd\@tempboxa >\hsize
152     {\small #1. #2}\par
153   \else
154     \global \@minipagefalse
155     \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
156   \fi
157   \vskip\belowcaptionskip}
158
159 \def\_{\leavevmode \kern .06em\vbox {\hrule \@width .333em}}
160 \def\cs#1{\texttt{\upshape\textbackslash #1}}
161
162 %%%%%%%%
163 \makeatother
164 %%%%%%%%
165
166 \def\Node#1#2{\,\vcenter{\hbox{\fboxsep=1pt\fbox{\vbox{\small\halign{\hfil##\hfil\cr
167   #1\mathstrut\cr\noalign{\vskip1pt\hrule height.4pt\vskip1pt}\strut#2\cr}}}}}\,}
168 \def\HNode#1#2#3#4{\,\vcenter{\hbox{\fboxsep=1pt\fbox{\vbox{\small\halign{\hfil##\hfil\cr
169   #1\mathstrut\cr\noalign{\vskip1pt\hrule height.4pt\vskip1pt}%
170   width:\hfill\ #2\cr height:\hfill\ #3\cr depth:\hfill\ #4\cr
171   }}}}}\,}
172
173 \protected\def\Param#1{\hyperlink{fld:#1}{\textsf{#1}}} % parameter name
174 \protected\def\DParam#1{\hypertarget{fld:#1}{\textsf{#1}}} % parameter name (definition)
175 \protected\def\Pkg#1{\underline{\smash{\texttt{#1}}}} % packages/classes
176
177
178 \begin{document}
179 \lstset{
180   vscmd=\IVSB
181 }
182
183 \catcode`\<=13
184 \def<#1>{{\normalfont\rm\itshape$\langle$#1\/$\rangle$}}
185 \let\LARG=<
186 \maketitle
187
188 \tableofcontents
189 \bigskip
190
191 %<*en>
192 \textbf{This documentation is far from complete. It may have many
193 grammatical (and contextual) errors.} Also, several parts
194 are written in Japanese only.
195 %</en>
196 %<*ja>
197 \emph{\large 本ドキュメントはまだまだ未完成です.}
198 %</ja>
199
200 \clearpage
201 %<en>\part{User's manual}
202 %<ja>\part{ユーザーズマニュアル}
203
204 %<en>\section{Introduction}
205 %<ja>\section{はじめに}
206
207
208 %<*en>
209 The \LuaTeX-ja package is a macro package for typesetting high-quality
210 Japanese documents when using \LuaTeX.
211 %</en>
212 %<*ja>
213 \LuaTeX-jaパッケージは,次世代標準\TeX である\LuaTeX の上で,\pTeX と同等
214 /それ以上の品質の日本語組版を実現させようとするマクロパッケージである.
215 %</ja>
216 %<en>\subsection{Backgrounds}
217 %<ja>\subsection{背景}
218
219 %<*en>
220 Traditionally, ASCII \pTeX, an extension of \TeX, and its derivatives
221 are used to typeset Japanese documents in \TeX. \pTeX\ is an engine
222 extension of \TeX: so it can produce high-quality Japanese documents
223 without using very complicated macros. But this point is a mixed
224 blessing: \pTeX\ is left behind from other extensions of \TeX,
225 especially \eTeX\ and \pdfTeX, and from changes about
226 Japanese processing in computers (\textit{e.g.}, the UTF-8 encoding).
227 %</en>
228 %<*ja>
229 従来,「\TeX を用いて日本語組版を行う」といったとき,エンジンとしては
230 ASCII \pTeX やそれの拡張物が用いられることが一般的であった.\pTeX は\TeX
231 のエンジン拡張であり,(少々仕様上不便な点はあるものの)商業印刷の分野に
232 も用いられるほどの高品質な日本語組版を可能としている.だが,それは弱点に
233 もなってしまった.\pTeX という(組版的に)満足なものがあったため,海外で
234 行われている数々の\TeX の拡張――例えば\eTeX や\pdfTeX ――や,TrueType,
235 OpenType, Unicodeといった計算機で日本語を扱う際の状況の変化に追従すること
236 を怠ってしまったのだ.
237 %</ja>
238
239 %<*en>
240 Recently extensions of \pTeX, namely \upTeX\ (Unicode-implementation
241 of \pTeX) and \epTeX\ (merging of \pTeX\ and
242 \eTeX\ extension), have developed to fill those gaps to some
243 extent, but gaps still exist.
244 %</en>
245 %<*ja>
246 ここ数年,若干状況は改善されてきた.現在手に入る大半の\pTeX バイナリでは
247 外部UTF-8入力が利用可能となり,さらにUnicode化を推進し,\pTeX の内部処理
248 までUnicode化した\upTeX も開発されている.また,\pTeX に\eTeX 拡張をマー
249 ジした\epTeX も登場し,\TeX\ Live\ 2011では\pLaTeX が\epTeX の上で動作す
250 るようになった.だが,\pdfTeX 拡張(PDF直接出力やmicro-typesetting)を
251 \pTeX に対応させようという動きはなく,海外とのgapは未だにあるのが現状であ
252 る.
253 %</ja>
254
255 %<*en>
256 However, the appearance of \LuaTeX\ changed the whole situation. With
257 using Lua ``callbacks'', users can customize the internal processing of
258 \LuaTeX. So there is no need to modify sources of engines to
259 support Japanese typesetting: to do this, we only have to write Lua
260 scripts for appropriate callbacks.
261 %</en>
262 %<*ja>
263 しかし,\LuaTeX の登場で,状況は大きく変わることになった.Luaコードで
264 ``callback''を書くことにより,\LuaTeX の内部処理に割り込みをかけることが可
265 能となった.これは,エンジン拡張という真似をしなくても,Luaコードとそれに
266 関する\TeX マクロを書けば,エンジン拡張とほぼ同程度のことができるようになっ
267 たということを意味する.\LuaTeX-jaは,このアプローチによってLuaコード・
268 \TeX マクロによって日本語組版を\LuaTeX の上で実現させようという目的で開発
269 が始まったパッケージである.
270 %</ja>
271
272 %<en>\subsection{Major Changes from \pTeX}
273 %<ja>\subsection{\pTeX からの主な変更点}
274 \label{ssec:chgptex}
275
276 %<*en>
277 The \LuaTeX-ja package is under much influence of \pTeX\ engine. The initial
278 target of development was to implement features of \pTeX. However, 
279 implementing all feature of \pTeX\ is impossible, 
280 since all process of \LuaTeX-ja must be implemented only by Lua and \TeX\ macros.
281 Hence \emph{\LuaTeX-ja is not a just porting of \pTeX; unnatural
282 specifications/behaviors of \pTeX\ were not adopted}.
283 %</en>
284 %<*ja>
285 \LuaTeX-jaは,\pTeX に多大な影響を受けている.初期の開発目標は,\pTeX の機
286 能をLuaコードにより実装することであった.しかし,(\pTeX はエンジン拡張であったのに対し)
287 \LuaTeX-jaはLuaコードと\TeX マクロを用いて全てを実装していなければならないため,\pTeX
288 の完全な移植は不可能であり,また\pTeX における実装がいささか不可解になっ
289 ているような状況も発見された.そのため,\emph{\LuaTeX-jaは,もはや
290 \pTeX の完全な移植は目標とはしない.\pTeX における不自然な仕様・挙動があ
291 れば,そこは積極的に改める.}
292 %</ja>
293
294 %<*en>
295 The followings are major changes from \pTeX.
296 For more detailed information, see Part~\ref{part-imp} or other sections of this manual.
297 %</en>
298 %<*ja>
299 以下は \pTeX からの主な変更点である.
300 より詳細については第\ref{part-imp}部など本文書の残りを参照.
301 %</ja>
302
303 %<*en>
304 \paragraph{Command names} \pTeX\ addes several primitives, such as \cs{kanjiskip}, 
305 \cs{prebreakpenalty},~and,~\cs{ifydir}. They can be used as follows:
306 %</en>
307 %<*ja>
308 \paragraph{命令の名称} 例えば\pTeX で追加された次のようなプリミティブ
309 %</ja>
310 \begin{verbatim}
311 \kanjiskip=10pt  \dimen0=kanjiskip
312 \tbaselineshift=0.1zw
313 \dimen0=\tbaselineshift
314 \prebreakpenalty`ぁ=100
315 \ifydir ... \fi
316 \end{verbatim}
317 %<en> However, we cannot use them under \LuaTeX-ja. 
318 %<en> Instead of them, we have to write as the following.
319 %<ja> は\LuaTeX-jaには存在しない.\LuaTeX-jaでは以下のように記述することになる.
320 \begin{verbatim}
321 \ltjsetparameter{kanjiskip=10pt}  \dimen0=\ltjgetparameter{kanjiskip}
322 \ltjsetparameter{talbaselineshift=0.1\zw}
323 \dimen0=\ltjgetparameter{talbaselineshift}
324 \ltjsetparameter{prebreakpenalty={`ぁ,100}}
325 \ifnum\ltjgetparemeter{direction}=4 ... \fi
326 \end{verbatim}
327 %<*en> 
328 Note that \pTeX\ adds new two useful units, namely \texttt{zw}~and~\texttt{zh}.
329 As shown above, they are changed by \cs{zw}~and\cs{zh} respectively, in \LuaTeX-ja.
330 %</en>
331 %<*ja>
332 特に注意してほしいのは,\pTeX で追加された \texttt{zw} と \texttt{zh} という単位を
333 \LuaTeX-ja で扱うには,\cs{zw}, \cs{zh} と制御綴の形にしないといけないという点である.
334 %</ja>
335
336 %<*en>
337 \paragraph{Linebreak after a Japanese character}
338 In \pTeX, a line break after Japanese character is ignored (and
339       doesn't yield a space), since line breaks (in source files) are
340       permitted almost everywhere in Japanese texts. However, \LuaTeX-ja
341       doesn't have this feature completely, because of a specification
342       of \LuaTeX. For the detail, see Section~\ref{sec-lbreak}.
343 %</en>
344 %<*ja>
345 \paragraph{和文文字直後の改行}
346 日本語の文書中では改行はほとんどどこでも許されるので,\pTeX では和文文字
347       直後の改行は無視される(スペースが入らない)ようになっていた.しかし,
348       \LuaTeX-ja では \LuaTeX の仕様のためにこの機能は完全には実装されていない.
349       詳しくは\ref{sec-lbreak}章を参照.
350 %</ja>
351
352 %<*en>
353
354 \paragraph{Spaces related to Japanese characters}
355 The insertion process of glues/kerns between two Japanese
356       characters and between a Japanese character and other characters
357       (we refer glues/kerns of both kinds as \textbf{JAglue}) is rewritten from
358       scratch.
359 %</en>
360 %<*ja>
361 \paragraph{和文関連の空白}
362 2つの和文文字の間や,和文文字と欧文文字の間に入るグルー/カーン
363       (両者をあわせて\textbf{JAglue}と呼ぶ)の挿入処理が0から書き直されている.
364 %</ja>
365
366 \begin{itemize}
367 %<*en>
368 \item As \LuaTeX's internal ligature handling is ``node-based''
369       (\textit{e.g.}, \verb+of{}fice+ doesn't prevent ligatures), the
370       insertion process of \textbf{JAglue} is now ``node-based''.
371 %</en>
372 %<*ja>
373 \item \LuaTeX の内部での合字の扱いは「ノード」を単位として行われるようになっている(例えば,
374       \verb+of{}fice+ で合字は抑制されない).それに合わせ,\textbf{JAglue}の挿入処理も
375       ノード単位で実行される.
376 %</ja>
377
378 %<*en>
379 \item Furthermore, nodes between two characters which have no effects in
380       line break (\textit{e.g.}, \cs{special} node) and kerns from
381       italic correction are ignored in the insertion process.
382 %</en>
383 %<*ja>
384 \item さらに,2つの文字の間にある行末では効果を持たないノード(例えば \cs{special} ノード)や,
385   イタリック補正に伴い挿入されるカーンは挿入処理中では無視される.
386 %</ja>
387
388 %<*en>
389 \item \emph{Caution: due to above two points, many methods which did for the
390       dividing the process of the insertion of \textbf{JAglue} in \pTeX\ are not
391       effective anymore.} In concrete terms, the following two methods are not effective anymore:
392 %</en>
393 %<*ja>
394 \item \emph{注意:上の2つの変更により,従来\textbf{JAglue}の挿入処理を分断するのに
395       使われていたいくつかの方法は用いることができない.具体的には,次の方法はもはや無効である:}
396 %</ja>
397 \begin{lstlisting}
398 ちょ{}っと    ちょ\/っと
399 \end{lstlisting}
400 %<*en>
401       If you want to do so, please put an empty horizontal box (hbox) between it instead:
402 %</en>
403 %<*ja>
404       もし同じことをやりたければ,空の水平ボックス(hbox)を間に挟めばよい:
405 %</ja>
406 \begin{lstlisting}
407 ちょ\hbox{}っと
408 \end{lstlisting}
409
410 %<*en>
411 \item In the process, two Japanese fonts which only differ in their ``real''
412       fonts are identified.
413 %</en>
414 %<*ja>
415 \item 処理中では,2つの和文フォントは,実フォントが異なるだけの場合には同一視
416       される.
417 %</ja>
418 \end{itemize}
419
420 %<*en>
421 \paragraph{Directions}
422 From this version, \LuaTeX-ja supports vertical writing;
423 but this feature must \emph{not} be confused with $\Omega$-style direction support of \LuaTeX\
424 itself. ...
425 %</en>
426 %<*ja>
427 \paragraph{組方向}
428 本版からは,不安定ながらも\LuaTeX-ja における縦組みをサポートしている.
429 なお,\LuaTeX 本体も,$\Omega$流の組方向をサポートしているが,それとは全くの別物であること
430 に注意してほしい.
431 \LuaTeX のコールバックや実装により,特に異なった組方向のボックスを扱う場合には
432 \cs{wd}, \cs{ht}, \cs{dp}等の仕様が異なるので注意.詳細は第\ref{sec-direction}節を参照.
433 %</ja>
434
435 %<*en>
436 \paragraph{\cs{discretionary}}
437 Japanese characters in discretionary break (\cs{discretionary}) is not supported.
438 %</en>
439 %<*ja>
440 \paragraph{\cs{discretionary}}
441  \cs{discretionary} 内に直接和文文字を記述することは,\pTeX においても想定されていなかった
442  感があるが.\LuaTeX-jaにおいても想定していない.和文文字をどう
443       しても使いたい場合は \cs{hbox} で括ること.
444 %</ja>
445
446
447
448 %<en>\subsection{Notations}
449 %<ja>\subsection{用語と記法}
450
451 %<*en>
452 In this document, the following terms and notations are used:
453 %</en>
454 %<*ja>
455 本ドキュメントでは,以下の用語と記法を用いる:
456 %</ja>
457 \begin{itemize}
458 %<*en>
459 \item Characters are classified into following two types.
460       Note that the classification can be customized by a user
461       (see Subsection~\ref{ssec-setrange}).
462 %</en>
463 %<*ja>
464 \item 文字は次の2種類に分けられる.この類別は固定されているものではなく,ユーザが後から変更可能である
465       (\ref{ssec-setrange}節を参照).
466 %</ja>
467 \begin{itemize}
468 %<*en>
469 \item \textbf{JAchar}: standing for characters which is used in Japanese typesetting,
470       such as Hiragana,~Katakana, Kanji, and~other Japanese punctuation marks.
471 %</en>
472 %<*ja>
473 \item \textbf{JAchar}: ひらがな,カタカナ,漢字,和文用の約物といった
474       日本語組版に使われる文字のことを指す.
475 %</ja>
476
477 %<en>\item \textbf{ALchar}: standing for all other characters like latin alphabets.
478 %<ja>\item \textbf{ALchar}: ラテンアルファベットを始めとする,その他全ての文字を指す.
479 \end{itemize}
480
481 %<*en>
482 We say \emph{alphabetic fonts} for fonts used in \textbf{ALchar},
483 and \emph{Japanese fonts} for fonts used in \textbf{JAchar}.
484 %</en>
485 %<*ja>
486 そして,\textbf{ALchar}の出力に用いられるフォントを\emph{欧文フォント}と呼び,
487 \textbf{JAchar}の出力に用いられるフォントを\emph{和文フォント}と呼ぶ.
488 %</ja>
489 %<*en>
490 \item A word in a sans-serif font (like \Param{prebreakpenalty})
491       means an internal parameter for Japanese typesetting, and it
492       is used as a key in \cs{ltjsetparameter} command.
493 %</en>
494 %<*ja>
495 \item サンセリフ体で書かれた語(例:\Param{prebreakpenalty})は日本語組版用の
496       パラメータを表し,これらは \cs{ltjsetparameter} 命令のキーとして
497       用いられる.
498 %</ja>
499 %<*en>
500 \item A word in typewriter font with underline (like \Pkg{fontspec})
501       means a package or a class of \LaTeX.
502 %</en>
503 %<*ja>
504 \item 下線付きタイプライタ体の語(例:\Pkg{fontspec})は\LaTeX の
505       パッケージやクラスを表す.
506 %</ja>
507 %<*en>
508 \item In this document, natural numbers start from~zero.
509   $\omega$ denotes the set of all natural numbers.
510 %</en>
511 %<*ja>
512 \item 本ドキュメントでは,自然数は0から始まる.自然数全体の集合は$\omega$と表記する.
513 %</ja>
514 \end{itemize}
515
516 %<en>\subsection{About the Project}
517 %<ja>\subsection{プロジェクトについて}
518
519 %<en>\paragraph{Project Wiki} Project Wiki is under construction.
520 %<ja>\paragraph{プロジェクトWiki} プロジェクトWikiは構築中である.
521 %<*en>
522 \begin{itemize}
523 \item \url{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage%28en%29} (English)
524 \item \url{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage} (Japanese)
525 \item \url{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage%28zh%29} (Chinese)
526 \end{itemize}
527 %</en>
528 %<*ja>
529 \begin{itemize}
530 \item \url{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage}(日本語)
531 \item \url{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage%28en%29}(英語)
532 \item \url{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage%28zh%29}(中国語)
533 \end{itemize}
534 %</ja>
535
536 %<en>This project is hosted by SourceForge.JP.
537 %<ja>本プロジェクトはSourceForge.JPのサービスを用いて運営されている.
538
539 %<en>\paragraph{Members}\
540 %<ja>\paragraph{開発メンバー}\
541
542 %<*en>
543 \begin{multienumerate}
544 \def\labelenumi{$\bullet$}
545 \mitemxxx{Hironori KITAGAWA}{Kazuki MAEDA}{Takayuki YATO}
546 \mitemxxx{Yusuke KUROKI}{Noriyuki ABE}{Munehiro YAMAMOTO}
547 \mitemxxx{Tomoaki HONDA}{Shuzaburo SAITO}{MA Qiyuan}
548 \end{multienumerate}
549 %</en>
550 %<*ja>
551 \begin{multienumerate}
552 \def\labelenumi{$\bullet$}
553 \mitemxxx{北川 弘典}{前田 一貴}{八登 崇之}
554 \mitemxxx{黒木 裕介}{阿部 紀行}{山本 宗宏}
555 \mitemxxx{本田 知亮}{齋藤 修三郎}{馬 起園}
556 \end{multienumerate}
557 %</ja>
558
559 % \paragraph{Acknowledgments} -- 挿入するならここ
560
561 \clearpage
562 %<en>\section{Getting Started}
563 %<ja>\section{使い方}
564 %<en>\subsection{Installation}
565 %<ja>\subsection{インストール}
566
567 %<en>The following packages are needed for the \LuaTeX-ja\ package.
568 %<ja>\LuaTeX-jaパッケージには,次のパッケージ類が必要である.
569 \begin{itemize}
570 \item \LuaTeX\ beta-0.80.0 (or later)
571 \item \Pkg{luaotfload} v2.5 (or later)
572 \item \Pkg{adobemapping} (Adobe cmap and pdfmapping files)
573 \item \Pkg{everysel} (if you want to use \LuaTeX-ja with \LaTeXe)
574 %<en>\item \emph{IPAex fonts}(\url{http://ipafont.ipa.go.jp/})
575 %<ja>\item \emph{IPAexフォント(\url{http://ipafont.ipa.go.jp/})}
576 \end{itemize}
577
578 %<*en>
579 \emph{This version of \LuaTeX-ja no longer supports \TeX~Live~2013 (or older version).
580 If you want to use this version with \TeX~Live~2014, you have to build a development
581 version of \LuaTeX\ from its source.}
582
583 \medskip
584
585 Now \LuaTeX-ja is available from
586 CTAN (in the \texttt{macros/luatex/generic/luatexja} directory), and
587 the following distributions:
588   \begin{itemize}
589   \item MiK\TeX\ (in \texttt{luatexja.tar.lzma}); see the next subsection
590   \item \TeX\ Live (in \texttt{texmf-dist/tex/luatex/luatexja})
591   \item W32\TeX\ (in \texttt{luatexja.tar.xz})
592   \end{itemize}
593 IPAex fonts are also available in these distributions.
594 %</en>
595 %<*ja>
596 \emph{本バージョンの\LuaTeX-jaは\TeX~Live~2013以前では動作しない.\TeX~Live~2014で
597 用いたい場合は,自力で\LuaTeX 開発版をソースからビルドする必要がある.}
598
599 \medskip
600
601 現在,\LuaTeX-jaはCTAN (\texttt{macros/luatex/generic/luatexja})に収録されている他,
602 以下のディストリビューションにも収録されている:
603   \begin{itemize}
604   \item MiK\TeX\ (\texttt{luatexja.tar.lzma})
605   \item \TeX\ Live (\texttt{texmf-dist/tex/luatex/luatexja})
606   \item W32\TeX\ (\texttt{luatexja.tar.xz})
607   \end{itemize}
608 これらのディストリビューションはIPAexフォントも収録している.
609 W32\TeX においてはIPAexフォントは \texttt{luatexja.tar.xz} 内にある.
610 %</ja>
611
612 % %<*ja>
613 % 例えば\TeX~Live~2015を利用しているなら,\LuaTeX-jaは\TeX~Live manager (\texttt{tlmgr})を
614 % 使ってインストールすることができる.
615 % \begin{lstlisting}
616 % $ tlmgr install luatexja
617 % \end{lstlisting}
618 % %</ja>
619 % %<*en>
620 % If you are using \TeX~Live~2015, you can install \LuaTeX-ja
621 % from \TeX~Live manager (\texttt{tlmgr}):
622 % \begin{lstlisting}
623 % $ tlmgr install luatexja
624 % \end{lstlisting}
625 % %</en>
626
627 %<en>\paragraph{Manual installation}
628 %<ja>\paragraph{手動インストール方法}
629
630 \begin{enumerate}
631 %<*en>
632 \item Download the source, by one of the following method.
633       At the present, \LuaTeX-ja has no \emph{stable} release.
634
635 \begin{itemize}
636 \item Clone the Git repository:
637 \begin{lstlisting}
638 $ git clone git://git.sourceforge.jp/gitroot/luatex-ja/luatexja.git
639 \end{lstlisting}
640 \item Download the \texttt{tar.gz} archive of HEAD in the \texttt{master} branch from
641 \begin{flushleft}
642 \url{http://git.sourceforge.jp/view?p=luatex-ja/luatexja.git;a=snapshot;h=HEAD;sf=tgz}.
643 \end{flushleft}
644 \end{itemize}
645
646 Note that the \texttt{master} branch, and hence the archive in CTAN, are not updated frequently;
647 the forefront of development is not the \texttt{master} branch.
648 %</en>
649 %<*ja>
650 \item ソースを以下のいずれかの方法で取得する.現在公開されているのはあくまでも
651       開発版であって,安定版でないことに注意.
652
653 \begin{itemize}
654 \item Gitリポジトリをクローンする:
655 \begin{lstlisting}
656 $ git clone git://git.sourceforge.jp/gitroot/luatex-ja/luatexja.git
657 \end{lstlisting}
658 \item \texttt{master}ブランチのスナップショット(\texttt{tar.gz}形式)をダウンロードする.
659 \begin{flushleft}
660 \url{http://git.sourceforge.jp/view?p=luatex-ja/luatexja.git;a=snapshot;h=HEAD;sf=tgz}.
661 \end{flushleft}
662 \end{itemize}
663 \texttt{master}ブランチ(従って,CTAN内のアーカイブも)はたまにしか更新されないことに注意.
664 主な開発は\texttt{master}の外で行われ,比較的まとまってきたらそれを\texttt{master}に
665 反映させることにしている.
666 %</ja>
667
668 %<*en>
669 \item Extract the archive. You will see \texttt{src/} and several other sub-directories.
670 But only the contents in \texttt{src/} are needed to work \LuaTeX-ja.
671 %</en>
672 %<*ja>
673 \item 「Gitリポジトリをクローン」以外の方法でアーカイブを取得したならば,それを展開する.
674       \texttt{src/}をはじめとしたいくつかのディレクトリができるが,
675       動作には\texttt{src/}以下の内容だけで十分.
676 %</ja>
677
678 %<*en>
679 \item If you downloaded this package from CTAN, you have to run following commands
680     to generate classes
681     and \texttt{ltj-kinsoku.lua} (the file which stores default ``\textit{kinsoku}'' parameters):
682 %</en>
683 %<*ja>
684 \item もしCTANから本パッケージを取得したのであれば,日本語用クラスファイルや
685 標準の禁則処理用パラメータを
686 格納した \texttt{ltj-kinsoku.lua} を生成するために,
687 以下を実行する必要がある:
688 %</ja>
689 \begin{lstlisting}
690 $ cd src
691 $ lualatex ltjclasses.ins
692 $ lualatex ltjsclasses.ins
693 $ lualatex ltjltxdoc.ins
694 $ luatex   ltj-kinsoku_make.tex
695 \end{lstlisting}
696 %<*en>
697 Note that \texttt{*.\{dtx,ins\}} and \texttt{ltj-kinsoku\_make.tex} are not needed in regular use.
698 %</en>
699 %<*ja>
700 ここで使用した \texttt{*.\{dtx,ins\}} と \texttt{ltj-kinsoku\_make.tex} は
701 通常の使用にあたっては必要ない.
702 %</ja>
703
704
705
706 %<*en>
707 \item Copy all the contents of \texttt{src/} into one of your \texttt{TEXMF} tree.
708       \texttt{TEXMF/tex/luatex/luatexja/} is an example location.
709       If you cloned entire Git repository, making a symbolic link of \texttt{src/}
710       instead copying is also good.
711 %</en>
712 %<*ja>
713 \item \texttt{src}の中身を自分の\texttt{TEXMF}ツリーにコピーする.
714       場所の例としては,例えば
715 \begin{quote}
716  \texttt{TEXMF/tex/luatex/luatexja/}
717 \end{quote}
718       がある.
719       シンボリックリンクが利用できる環境で,かつリポジトリを直接取得したのであれば,
720       (更新を容易にするために)コピーではなくリンクを貼ることを勧める.
721 %</ja>
722 %<*en>
723 \item If \texttt{mktexlsr} is needed to update the file name database, make it so.
724 %</en>
725 %<*ja>
726 \item 必要があれば,\texttt{mktexlsr}を実行する.
727 %</ja>
728 \end{enumerate}
729
730 %<*en>
731 \subsection{Cautions}
732 For changes from \pTeX, see Subsection~\ref{ssec:chgptex}.
733 %</en>
734 %<*ja>
735 \subsection{注意点}
736 \pTeX からの変更点として,\ref{ssec:chgptex}節も熟読するのが望ましい.
737 ここでは一般的な注意点を述べる.
738 %</ja>
739 \begin{itemize}
740 %<*en>
741 \item The encoding of your source file must be UTF-8. No other
742       encodings, such as EUC-JP or Shift-JIS, are not supported.
743 %</en>
744 %<*ja>
745 \item 原稿のソースファイルの文字コードはUTF-8固定である.
746       従来日本語の文字コードとして用いられてきたEUC-JPやShift-JISは使用できない.
747 %</ja>
748 %<*en>
749 \item \LuaTeX-ja is very slower than \pTeX.
750 Generally speaking, LuaJIT\TeX\ processes \LuaTeX-ja
751 about 30\% faster than \LuaTeX, but not always.
752 %</en>
753 %<*ja>
754 \item \LuaTeX-jaは動作が\pTeX に比べて非常に遅い.
755 コードを調整して徐々に速くしているが,まだ満足できる速度ではない.
756 LuaJIT\TeX を用いると\LuaTeX のだいたい1.3倍の速度で動くようであるが,
757 IPA mj明朝などの大きいフォントを用いた場合には\LuaTeX よりも遅くなることもある.
758 %</ja>
759 \item%
760 %<*en>
761 \textbf{Note for MiK\TeX\ users}\quad
762 \LuaTeX-ja requires that several CMap files%
763 \footnote{\texttt{UniJIS2004-UTF32-\{H,V\}} and \texttt{Adobe-Japan1-UCS2}.}
764 must be found from \LuaTeX.
765 Strictly speaking, those CMaps are needed
766 only in the first run of \LuaTeX-ja after installing or updating.
767 But it seems that MiK\TeX\ does not satisfy this condition,
768 so you will encounter an error like the following:
769 %</en>
770 %<*ja>
771 \LuaTeX-jaが動作するためには,\emph{導入・更新後の初回起動時に}
772 \texttt{UniJIS2004-UTF32-\{H,V\}}, \texttt{Adobe-Japan1-UCS2}という3つのCMapが
773 \LuaTeX によって見つけられることが必要である.
774 しかしMiK\TeX ではそのようになっていないので,次のエラーが発生するだろう:
775 %</ja>
776 \begin{lstlisting}
777 ! LuaTeX error ...iles (x86)/MiKTeX 2.9/tex/luatex/luatexja/ltj-rmlgbm.lua
778 bad argument #1 to 'open' (string expected, got nil)
779 \end{lstlisting}
780
781 %<*en>
782 If so, please execute a batch file which is written on
783 \href{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage%28en%29}{ the Project Wiki (English)}.
784 This batch file creates a temporary directory, copy CMaps in it,
785 run \LuaTeX-ja in this directory, and finally delete the temporary directory.
786 %</en>
787 %<*ja>
788 そのような場合には,
789 \href{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage%28en%29}{%
790   プロジェクトWiki英語版トップページ}中に書かれているバッチファイルを
791 実行して欲しい.このバッチファイルは,作業用ディレクトリにCMap達を
792 コピーし,その中で\LuaTeX-ja の初回起動を行い,作業用ディレクトリを消す作業をしている.
793 %</ja>
794
795 \end{itemize}
796
797 %<en>\subsection{Using in plain \TeX}
798 %<ja>\subsection{plain \TeX で使う}
799 \label{ssec-plain}
800
801 %<en>To use \LuaTeX-ja in plain \TeX, simply put the following at the beginning of the document:
802 %<ja>\LuaTeX-jaを plain \TeX で使うためには,単に次の行をソースファイルの冒頭に追加すればよい:
803 \begin{lstlisting}
804 \input luatexja.sty
805 \end{lstlisting}
806 %<en>This does minimal settings (like \texttt{ptex.tex}) for typesetting Japanese documents:
807 %<ja>これで(\texttt{ptex.tex}のように)日本語組版のための最低限の設定がなされる:
808
809 \begin{itemize}
810 %<*en>
811 \item The following 12~Japanese fonts are preloaded:
812 \begin{center}\small
813 \begin{tabular}{cccccc}
814 \toprule
815 \textbf{direction}&
816 \textbf{classification}&\textbf{font name}&\bf `10\,pt'&\bf`7\,pt'&\bf`5\,pt'\\\midrule
817 \smash{\raisebox{-1ex}{\emph{yoko} (horizontal)}}&
818 \emph{mincho}&IPAex Mincho&\cs{tenmin}&\cs{sevenmin}&\cs{fivemin}\\
819 &\emph{gothic}&IPAex Gothic&\cs{tengt} &\cs{sevengt} &\cs{fivegt}\\
820 \midrule
821 \smash{\raisebox{-1ex}{\emph{tate} (vertical)}}&
822 \emph{mincho}&IPAex Mincho&\cs{tentmin}&\cs{seventmin}&\cs{fivetmin}\\
823 &\emph{gothic}&IPAex Gothic&\cs{tentgt} &\cs{seventgt} &\cs{fivetgt}\\
824 \bottomrule
825 \end{tabular}
826 \end{center}
827 %</en>
828 %<*ja>
829 \item 以下の12個の和文フォントが定義される:
830 \begin{center}\small
831 \begin{tabular}{cccccc}
832 \toprule
833 \emph{組方向}&\emph{字体}&\emph{フォント名}&\bf `10\,pt'&\bf`7\,pt'&\bf`5\,pt'\\\midrule
834 \smash{\raisebox{-1ex}{横組}}&
835 明朝体&IPAex明朝&\cs{tenmin}&\cs{sevenmin}&\cs{fivemin}\\
836 &ゴシック体&IPAexゴシック&\cs{tengt} &\cs{sevengt} &\cs{fivegt}\\
837 \midrule
838 \smash{\raisebox{-1ex}{縦組}}&
839 明朝体&IPAex明朝&\cs{tentmin}&\cs{seventmin}&\cs{fivetmin}\\
840 &ゴシック体&IPAexゴシック&\cs{tentgt} &\cs{seventgt} &\cs{fivetgt}\\
841 \bottomrule
842 \end{tabular}
843 \end{center}
844 %</ja>
845 \begin{itemize}
846 %<*en>
847 \item With \texttt{luatexja.cfg}, one can use other fonts
848 as ``default'' Japanese fonts (Subsection~\ref{ssec-cfg}).
849 %</en>
850 %<*ja>
851 \item \texttt{luatexja.cfg} を用いることによって,標準和文フォントを
852 IPAexフォントから別のフォントに置き換えることができる.\ref{ssec-cfg}節を参照.
853 %</ja>
854
855 %<*en>
856 \item A character in an alphabetic font is generally smaller than a
857       Japanese font in the same size. So actual size specification of
858       these Japanese fonts is in fact smaller than that of alphabetic
859       fonts, namely scaled by 0.962216.
860 %</en>
861 %<*ja>
862 \item 欧文フォントの文字は和文フォントの文字よりも,同じ文字サイズでも
863       一般に小さくデザインされている.そこで,標準ではこれらの和文フォントの実際のサイズは指定された値よりも
864       小さくなるように設定されており,具体的には指定の0.962216倍にスケールされる.
865       この0.962216という数値も,\pTeX におけるスケーリングを踏襲した値である.
866 %</ja>
867 \end{itemize}
868
869 %<*en>
870 \item The amount of glue that are inserted between a \textbf{JAchar} and
871       an \textbf{ALchar} (the parameter \Param{xkanjiskip}) is set to
872 %</en>
873 %<*ja>
874 \item \textbf{JAchar}と\textbf{ALchar}の間に入るグルー(\Param{xkanjiskip})の
875       量は次のように設定されている:
876 %</ja>
877 \[
878  (0.25\cdot 0.962216\cdot 10\,\mathrm{pt})^{+1\,\text{pt}}_{-1\,\text{pt}}
879  = 2.40554\,\mathrm{pt}^{+1\,\text{pt}}_{-1\,\text{pt}}.
880 \]
881 \end{itemize}
882
883 %<en>\subsection{Using in \LaTeX}
884 %<ja>\subsection{\LaTeX で使う}
885 \label{ssec-ltx}
886
887 %<*en>
888 Using in \LaTeXe\ is basically same. To set up the minimal environment
889 for Japanese, you only have to load \texttt{luatexja.sty}:
890 %</en>
891 %<*ja>
892 \LaTeXe を用いる場合も基本的には同じである.日本語組版のための最低限の環境を
893 設定するためには,\texttt{luatexja.sty}を読み込むだけでよい:
894 %</ja>
895 \begin{lstlisting}
896 \usepackage{luatexja}
897 \end{lstlisting}
898 %<*en>
899 It also does minimal settings (counterparts in \pLaTeX\ are \texttt{%
900 plfonts.dtx} and \texttt{pldefs.ltx}):
901 %</en>
902 %<*ja>
903 これで\pLaTeX の\texttt{plfonts.dtx}と\texttt{pldefs.ltx}に相当する最低限の設定が
904 なされる:
905 %</ja>
906
907 \begin{itemize}
908 %<*en>
909 \item Font encodings for Japanese fonts is \texttt{JY3}~(for horizontal direction) and
910 \texttt{JT3}~(for vertical direction).
911 %</en>
912 %<*ja>
913 \item 和文フォントのエンコーディングとしては,横組用には \texttt{JY3},縦組用には\
914 \texttt{JT3}が用いられる.
915 %</ja>
916
917 %<*en>
918 \item Traditionally, Japanese documents use two typeface categories: \emph{mincho}~(明朝体) and
919  \emph{gothic}~(\textgt{ゴシック体}). \emph{mincho} is used in the main text, while \emph{gothic}
920       is used in the headings or for emphasis.
921 \begin{center}\small
922 \begin{tabular}{lllc}
923 \toprule
924 \textbf{classification}&&&\textbf{family name}\\\midrule
925 \emph{mincho} (明朝体)&\verb+\textmc{...}+&\verb+{\mcfamily ...}+&\cs{mcdefault}\\
926 \emph{gothic} (\textgt{ゴシック体})&\verb+\textgt{...}+&\verb+{\gtfamily ...}+&\cs{gtdefault}\\
927 \bottomrule
928 \end{tabular}
929 \end{center}
930 \item
931 By default, the following fonts are used for \emph{mincho} and \emph{gothic}:
932 \begin{center}\small
933 \begin{tabular}{ccccc}
934 \toprule
935 \textbf{classification}&\textbf{family}&\cs{mdseries}&\cs{bfseries}&\textbf{scale}\\\midrule
936 \emph{mincho} (明朝体)&\tt mc&IPAex Mincho&IPAex Gothic&0.962216\\
937 \emph{gothic} (\textgt{ゴシック体})&\tt gt&IPAex Gothic&IPAex Gothic&0.962216\\
938 \bottomrule
939 \end{tabular}
940 \end{center}
941 Note that the bold series in both family are same as the medium series of \emph{gothic}
942      family. There is no italic nor slanted shape for
943       these \texttt{mc}~and~\texttt{gt}.
944 %</en>
945 %<*ja>
946 \item \pLaTeX と同様に,標準では「明朝体」「ゴシック体」の2種類を用いる:
947 \begin{center}\small
948 \begin{tabular}{cllc}
949 \toprule
950 \emph{字体}&&&\emph{ファミリ名}\\\midrule
951 明朝体&\verb+\textmc{...}+&\verb+{\mcfamily ...}+&\cs{mcdefault}\\
952 \textgt{ゴシック体}&\verb+\textgt{...}+&\verb+{\gtfamily ...}+&\cs{gtdefault}\\
953 \bottomrule
954 \end{tabular}
955 \end{center}
956 \item 標準では,次のフォントファミリが用いられる:
957 \begin{center}\small
958 \begin{tabular}{ccccc}
959 \toprule
960 \emph{字体}&\emph{ファミリ}&\cs{mdseries}&\cs{bfseries}&\emph{スケール}\\\midrule
961 明朝体&\tt mc&IPAex明朝&IPAexゴシック&0.962216\\
962 ゴシック体&\tt gt&IPAexゴシック&IPAexゴシック&0.962216\\
963 \bottomrule
964 \end{tabular}
965 \end{center}
966 どちらのファミリにおいても,そのboldシリーズで使われるフォントは
967 ゴシック体のmediumシリーズで使われるフォントと同じであることに注意.
968 また,どちらのファミリでもイタリック体・スラント体は定義されない.
969 %</ja>
970
971 %<en>\item Japanese characters in math mode are typeset by the font family \texttt{mc}.
972 %<ja>\item 数式モード中の和文文字は明朝体(\texttt{mc})で出力される.
973
974 %<*en>
975 \item If you use the \Pkg{beamer} class with the default font theme (which uses sans serif
976       fonts) and with \LuaTeX-ja, you might want to change default Japanese fonts to
977       \emph{gothic} family. The following line  changes  the default Japanese font family
978       to \emph{gothic}:
979 %</en>
980 %<*ja>
981 \item \Pkg{beamer}クラスを既定のフォント設定で使う場合,既定欧文フォントがサンセリフなの
982       で,既定和文フォントもゴシック体にしたいと思うかもしれない.その場合はプリアンブルに
983 次を書けばよい:
984 %</ja>
985 \begin{lstlisting}
986  \renewcommand{\kanjifamilydefault}{\gtdefault}
987 \end{lstlisting}
988
989
990 \end{itemize}
991
992 %<*en>
993 However, above settings are not sufficient for Japanese-based
994 documents. To typeset Japanese-based documents, you are better to use
995 class files other than \texttt{article.cls}, \texttt{book.cls}, and so on.  At
996 the present, we have the counterparts of \Pkg{jclasses} (standard
997 classes in \pLaTeX) and \Pkg{jsclasses} (classes by Haruhiko
998 Okumura), namely, \Pkg{ltjclasses}\footnote{%
999   \texttt{ltjarticle.cls},~\texttt{ltjbook.cls}, \texttt{ltjreport.cls},
1000   \texttt{ltjtarticle.cls}, \texttt{ltjtbook.cls}, \texttt{ltjtreport.cls}.
1001   The latter \texttt{ltjt*.cls} are for vertically writtened Japanese documents.
1002 } and \Pkg{ltjsclasses}\footnote{%
1003   \texttt{ltjsarticle.cls},~\texttt{ltjsbook.cls},~\texttt{ltjskiyou.cls}.}.
1004 %</en>
1005 %<*ja>
1006 しかしながら,上記の設定は日本語の文書にとって十分とは言えない.
1007 日本語文書を組版するためには,\texttt{article.cls}, \texttt{book.cls}といった
1008 欧文用のクラスファイルではなく,和文用のクラスファイルを用いた方がよい.
1009 現時点では,\Pkg{jclasses}(\pLaTeX の標準クラス)と\Pkg{jsclasses}
1010 (奥村晴彦氏による「\pLaTeXe 新ドキュメントクラス」)に対応するものとして,
1011 \Pkg{ltjclasses}\footnote{%
1012   横組用は \texttt{ltjarticle.cls},~\texttt{ltjbook.cls}, \texttt{ltjreport.cls} であり,
1013   縦組用は \texttt{ltjtarticle.cls}, \texttt{ltjtbook.cls}, \texttt{ltjtreport.cls} である.
1014 },
1015 \Pkg{ltjsclasses}\footnote{%
1016   \texttt{ltjsarticle.cls},~\texttt{ltjsbook.cls},~\texttt{ltjskiyou.cls}.}%
1017 がそれぞれ用意されている.
1018 %</ja>
1019
1020 %<*ja>
1021 \paragraph{脚注とボトムフロートの出力順序}
1022 オリジナルの\LaTeX では脚注がボトムフロートの上に来るようになっており,
1023 \pLaTeX では脚注がボトムフロートの下に来るように変更されている.
1024
1025 \LuaTeX-jaでは「欧文クラスの中にちょっとだけ日本語を入れる」という利用も考慮し,
1026 脚注とボトムフロートの順序は\LaTeX 通りとした.もし\pLaTeX の出力順序が好みならば,
1027 \Pkg{stfloats}パッケージを利用して
1028 \begin{lstlisting}
1029  \usepackage{stfloats}\fnbelowfloat
1030 \end{lstlisting}
1031 のようにすればよい.\Pkg{footmisc}パッケージを \texttt{bottom}\ オプションを指定して
1032 読み込むという方法もあるが,それだとボトムフロートと脚注の間が開いてしまう.
1033 %</ja>
1034 %%% ↑は英訳しない
1035
1036 %<*en>
1037 \paragraph{\Pkg{geometry} package and classes for vertical writing}
1038 It is well-known that the \Pkg{geometry} package produces the following error, when classes for
1039 vertical writing is used:
1040 %</en>
1041 %<*ja>
1042 \paragraph{縦組での\Pkg{geometry}パッケージ}
1043 \pLaTeX の縦組用標準クラスファイルでは\Pkg{geometry}パッケージを利用することは出来ず,
1044 %</ja>
1045 \begin{lstlisting}
1046 ! Incompatible direction list can't be unboxed.
1047 \@begindvi ->\unvbox \@begindvibox 
1048                                    \global \let \@begindvi \@empty 
1049 \end{lstlisting}
1050 %<*en>
1051 Now, \LuaTeX-ja automatically applies the patch \Pkg{lltjp-geometry} to the
1052 \Pkg{geometry} package, when the direction of the document is \emph{tate} (vertical
1053 writing).
1054 This patch \Pkg{lltjp-geometry} also can be used in \pLaTeX; for the detail, please refer 
1055 \url{lltjp-geometry.pdf}~(Japanese).
1056 %</en>
1057 %<*ja>
1058 というようなエラーが発生することが知られている.
1059 \LuaTeX-jaでは, \texttt{ltjtarticle.cls} といった縦組クラスの下でも
1060 \Pkg{geometry}パッケージが利用できるようにパッチ\Pkg{lltjp-geometry}パッケージを自動的に当てている.
1061
1062 なお,\Pkg{lltjp-geometry}パッケージは\pTeX 系列でも明示的に読み込むことによって
1063 使用可能である.詳細や注意事項は \url{lltjp-geometry.pdf} を参照のこと.
1064 %</ja>
1065
1066
1067 %<en>\section{Changing Fonts}
1068 %<ja>\section{フォントの変更}
1069
1070 \subsection{plain \TeX~and~\LaTeXe}
1071 \label{ssec-chgfnt}
1072
1073 \paragraph{plain \TeX}
1074 %<*en>
1075 To change Japanese fonts in plain \TeX, you must use the command
1076 \cs{jfont}~and~\cs{tfont}. So please see Subsection~\ref{ssec-jfont}.
1077 %</en>
1078 %<*ja>
1079 plain \TeX で和文フォントを変更するためには,
1080 \pTeX のように \cs{jfont} 命令や \cs{tfont} 命令を直接用いる.
1081 \ref{ssec-jfont}節を参照.
1082 %</ja>
1083
1084 \paragraph{\LaTeXe\ (NFSS2)}
1085 %<*en>
1086 For \LaTeXe, \LuaTeX-ja adopted most of the font selection system of \pLaTeXe\ (in \texttt{plfonts.dtx}).
1087 %</en>
1088 %<*ja>
1089 \LaTeX で用いる際には,\pLaTeXe\ (\texttt{plfonts.dtx})用のフォント選択機構の大部分を流用している.
1090 %</ja>
1091 \begin{itemize}
1092 %<*en>
1093 \item Commands \cs{fontfamily}, \cs{fontseries},
1094       \cs{fontshape}, and \cs{selectfont} can be used to change
1095       attributes of Japanese fonts.
1096 %</en>
1097 %<*ja>
1098 \item 和文フォントの属性を変更するには,\cs{fontfamily}, \cs{fontseries}, \cs{fontshape},
1099       そしてそれらを反映させるために \cs{selectfont} を用いればよい.
1100 %</ja>
1101
1102 %<*en>
1103 \begin{center}\small
1104 \begin{tabular}{cccccc}
1105 \toprule
1106 &\textbf{encoding}&\textbf{family}&\textbf{series}&\textbf{shape}&\textbf{selection}\\\midrule
1107 alphabetic fonts
1108 &\cs{romanencoding}&\cs{romanfamily}&\cs{romanseries}&\cs{romanshape}
1109 &\cs{useroman}\\
1110 Japanese fonts
1111 &\cs{kanjiencoding}&\cs{kanjifamily}&\cs{kanjiseries}&\cs{kanjishape}
1112 &\cs{usekanji}\\
1113 both&---&--&\cs{fontseries}&\cs{fontshape}&---\\
1114 auto select&\cs{fontencoding}&\cs{fontfamily}&---&---&\cs{usefont}\\
1115 \bottomrule
1116 \end{tabular}
1117 \end{center}
1118 %</en>
1119 %<*ja>
1120 \begin{center}\small
1121 \begin{tabular}{cccccc}
1122 \toprule
1123 &\emph{エンコーディング}&\emph{ファミリ}&\emph{シリーズ}&\emph{シェープ}&\emph{選択}\\\midrule
1124 欧文
1125 &\cs{romanencoding}&\cs{romanfamily}&\cs{romanseries}&\cs{romanshape}
1126 &\cs{useroman}\\
1127 和文
1128 &\cs{kanjiencoding}&\cs{kanjifamily}&\cs{kanjiseries}&\cs{kanjishape}
1129 &\cs{usekanji}\\
1130 両方&---&--&\cs{fontseries}&\cs{fontshape}&---\\
1131 自動選択&\cs{fontencoding}&\cs{fontfamily}&---&---&\cs{usefont}\\
1132 \bottomrule
1133 \end{tabular}
1134 \end{center}
1135 %</ja>
1136
1137 %<*en>
1138       \verb+\fontencoding{+<encoding>\verb+}+ changes the encoding of alphabetic fonts
1139       or Japanese fonts depending on the argument. For example,
1140       \verb+\fontencoding{JY3}+ changes the encoding of Japanese fonts to
1141       \texttt{JY3},and \verb+\fontencoding{T1}+ changes the encoding of
1142       alphabetic fonts to \texttt{T1}.
1143       \cs{fontfamily} also changes the current Japanese font family,
1144       the current alphabetic font family, \emph{or both}.
1145       For the detail, see Subsection~\ref{ssec-nfsspat}.
1146 %</en>
1147 %<*ja>
1148       ここで,\verb+\fontencoding{+<encoding>\verb+}+ は,引数により和文側か欧文
1149       側かのどちらかのエンコーディングを変更する.例えば,
1150       \verb+\fontencoding{JY3}+ は和文フォントのエンコーディングを
1151       \texttt{JY3}に変更し,\verb+\fontencoding{T1}+ は欧文フォント側を
1152       \texttt{T1}へと変更する.\cs{fontfamily} も引数により和文側,欧文
1153       側,\emph{あるいは両方}のフォントファミリを変更する.詳細は
1154       \ref{ssec-nfsspat}節を参照すること.
1155 %</ja>
1156
1157 %<*en>
1158 \item For defining a Japanese font family, use
1159       \cs{DeclareKanjiFamily} instead of
1160       \cs{DeclareFontFamily}. However, in the present implementation,
1161       using \cs{DeclareFontFamily} doesn't cause any problem.
1162 \item Defining a Japanese font shape can be done by usual \cs{DeclareFontShape}:
1163 %</en>
1164 %<*ja>
1165 \item 和文フォントファミリの定義には \cs{DeclareFontFamily} の
1166       代わりに \cs{DeclareKanjiFamily} を用いる.しかし,現在の
1167       実装では \cs{DeclareFontFamily} を用いても問題は生じない.
1168 \item 和文フォントのシェイプを定義するには,通常の \cs{DeclareFontShape} を使えば良い:
1169 %</ja>
1170 \begin{lstlisting}
1171 \DeclareFontShape{JY3}{mc}{bx}{n}{<-> s*KozMinPr6N-Bold:jfm=ujis;-kern}{}
1172     % Kozuka Mincho Pr6N Bold
1173 \end{lstlisting}
1174 %<*ja>
1175 仮名書体を使う場合など,複数の和文フォントを組み合わせて使いたい場合は
1176 \ref{ssec-altfont}節の \cs{ltjdeclarealtfont} と,その\LaTeX 版の\
1177 \cs{DeclareAlternateKanjiFont}(\ref{ssec-nfsspat}節)を参照せよ.
1178 %</ja>
1179
1180 \end{itemize}
1181
1182 %<*en>
1183 \paragraph{Remark: Japanese characters in math mode}
1184 Since \pTeX\ supports Japanese characters in math mode, there are
1185 sources like the following:
1186 %</en>
1187 %<*ja>
1188 \paragraph{注意:数式モード中の和文文字}
1189 \pTeX では,特に何もしないでも数式中に和文文字を記述することができた.そのため,
1190 以下のようなソースが見られた:
1191 %</ja>
1192
1193 \begin{LTXexample}
1194 $f_{高温}$~($f_{\text{high temperature}}$).
1195 \[ y=(x-1)^2+2\quad よって\quad y>0 \]
1196 $5\in 素:=\{\,p\in\mathbb N:\text{$p$ is a prime}\,\}$.
1197 \end{LTXexample}
1198 %<*en>
1199 We (the project members of \LuaTeX-ja) think that using
1200 Japanese characters in math mode are allowed if and only if these are used as identifiers.
1201 In this point of view,
1202 %</en>
1203 %<*ja>
1204 \LuaTeX-jaプロジェクトでは,数式モード中での和文文字はそれらが識別子として用いられる
1205 ときのみ許されると考えている.
1206 この観点から,
1207 %</ja>
1208
1209 \begin{itemize}
1210 %<*en>
1211 \item The lines 1~and~2 above are not correct, since ``高温'' in above is used as a textual label, and
1212 ``よって'' is used as a conjunction.
1213 %</en>
1214 %<*ja>
1215 \item 上記数式のうち1, 2行目は正しくない.なぜならば「高温」が意味のあるラベルと
1216       して,「よって」が接続詞として用いられているからである.
1217 %</ja>
1218 %<en>\item However, the line~3 is correct, since ``素'' is used as an identifier.
1219 %<ja>\item しかしながら,3行目は「素」が単なる識別子として用いられているので正しい.
1220 \end{itemize}
1221 %<en>Hence, in our opinion, the above input should be corrected as:
1222 %<ja>したがって,\LuaTeX-jaプロジェクトの意見としては,上記の入力は次のように直されるべきである:
1223 \begin{LTXexample}
1224 $f_{\text{高温}}$~%
1225 ($f_{\text{high temperature}}$).
1226 \[ y=(x-1)^2+2\quad
1227   \mathrel{\text{よって}}\quad y>0 \]
1228 $5\in 素:=\{\,p\in\mathbb N:\text{$p$ is a prime}\,\}$.
1229 \end{LTXexample}
1230 %<*en>
1231 We also believe that using Japanese characters as identifiers is rare,
1232 hence we don't describe how to change Japanese fonts in math mode in
1233 this chapter. For the method, please see Subsection~\ref{ssec-math}.
1234 %</en>
1235 %<*ja>
1236 また\LuaTeX-jaプロジェクトでは,和文文字が識別子として用いられることはほとんどない
1237 と考えており,したがってこの節では数式モード中の和文フォントを変更する方法については
1238 記述しない.この方法については\ref{ssec-math}節を参照のこと.
1239 %</ja>
1240
1241
1242 \subsection{fontspec}
1243 \label{ssec-fontspec}
1244 %<*en>
1245 To coexist with the \Pkg{fontspec} package, it is needed to load
1246 the \Pkg{luatexja-fontspec} package in the preamble, as follows:
1247 \begin{quote}
1248 \ttfamily \textbackslash usepackage[<options>]\{luatexja-fontspec\}
1249 \end{quote}
1250 This \Pkg{luatexja-fontspec} package
1251 automatically loads \Pkg{luatexja} and \Pkg{fontspec}
1252 packages, if needed.
1253 %</en>
1254 %<*ja>
1255 \Pkg{fontspec}パッケージと同様の機能を和文フォントに対しても用いる場合,
1256 \Pkg{luatexja-fontspec}パッケージを読み込めばよい.
1257 \begin{quote}
1258 \ttfamily \textbackslash usepackage[<options>]\{luatexja-fontspec\}
1259 \end{quote}
1260 このパッケージ
1261 は必要ならば自動で\Pkg{luatexja}パッケージと\Pkg{fontspec}パッケージを読み込む.
1262 %</ja>
1263
1264 %<*en>
1265 In the \Pkg{luatexja-fontspec} package, the following seven~commands are defined as
1266 counterparts of original commands in the \Pkg{fontspec} package:
1267 %</en>
1268 %<*ja>
1269 \Pkg{luatexja-fontspec}パッケージでは,以下の7つのコマンドを\Pkg{fontspec}
1270 パッケージの元のコマンドに対応するものとして定義している:
1271 %</ja>
1272 %<*en>
1273 \begin{center}\small
1274 \begin{tabular}{ccccc}
1275 \toprule
1276 Japanese fonts
1277 &\cs{jfontspec}&\cs{setmainjfont}&\cs{setsansjfont}&\cs{setmonojfont}$^*$\\
1278 alphabetic fonts
1279 &\cs{fontspec}&\cs{setmainfont}&\cs{setsansfont}&\cs{setmonofont}\\
1280 \midrule
1281 Japanese fonts
1282 &\cs{newjfontfamily}&\cs{newjfontface}
1283 &\cs{defaultjfontfeatures}&\cs{addjfontfeatures}\\
1284 alphabetic fonts
1285 &\cs{newfontfamily}&\cs{newfontface}
1286 &\cs{defaultfontfeatures}&\cs{addfontfeatures}\\
1287 \bottomrule
1288 \end{tabular}
1289 \end{center}
1290 %</en>
1291 %<*ja>
1292 \begin{center}\small
1293 \begin{tabular}{cccc}
1294 \toprule
1295 和文
1296 &\cs{jfontspec}&\cs{setmainjfont}&\cs{setsansjfont}\\
1297 欧文
1298 &\cs{fontspec}&\cs{setmainfont}&\cs{setsansfont}\\
1299 \midrule
1300 和文
1301 &\cs{newjfontfamily}&\cs{newjfontface}&\cs{defaultjfontfeatures}\\
1302 欧文
1303 &\cs{newfontfamily}&\cs{newfontface}&\cs{defaultfontfeatures}\\
1304 \midrule
1305 和文
1306 &\cs{addjfontfeatures}\\
1307 欧文
1308 &\cs{addfontfeatures}\\
1309 \bottomrule
1310 \end{tabular}
1311 \end{center}
1312 %</ja>
1313 %<*en>
1314 The package option of \Pkg{luatexja-fontspec} are the followings:
1315 \begin{cslist}
1316  \item[match]
1317 If this option is specified, usual family-changing commands such as
1318 \cs{rmfamily},~\cs{textrm}, \cs{sffamily},~\dots\ also change Japanese font family.
1319
1320 Note that \emph{\cs{setmonojfont} is defined
1321 if and only if this \texttt{\textup{match}} option is specified}.
1322
1323  \item[pass=<opts>]
1324 Specify options <opts> which will be passed to the \Pkg{fontspec} package.
1325 \end{cslist}
1326 The reason that \cs{setmonojfont} is not defined by default is that
1327 it is popular for Japanese fonts that nearly all Japanese glyphs have same
1328 widths.  Also note that kerning information in a font is not used
1329 (that is, \texttt{kern} feature is set off) by default in these seven (or~eight) commands.
1330 This is because of the compatibility with previous versions of \LuaTeX-ja
1331 (see \ref{para-kern}).
1332
1333 Below is an example of \cs{jfontspec}.
1334 %</en>
1335 %<*ja>
1336 \Pkg{luatexja-fontspec} パッケージのオプションは以下の通りである:
1337 \begin{cslist}
1338  \item[match]
1339 このオプションが指定されると,「\pLaTeXe 新ドキュメントクラス」のように\
1340 \cs{rmfamily}, \verb+\textrm{...}+, \cs{sffamily} 等が
1341 欧文フォントだけでなく和文フォントも変更するようになる.
1342
1343 \emph{なお,\cs{setmonojfont} はこの \texttt{match} オプションが
1344 指定された時のみ定義される.}この命令は標準の「タイプライタ体に対応する和文フォント」を指定する.
1345
1346  \item[pass=<opts>]
1347 \Pkg{fontspec} パッケージに渡すオプション <opts> を指定する.
1348 \end{cslist}
1349 標準で \cs{setmonojfont} コマンドが定義されないのは,
1350 和文フォントではほぼ全ての和文文字のグリフが等幅であるのが伝統的であったことによる.
1351 また,これらの和文用のコマンドではフォント内のペアカーニング情報は標準では使用されない,
1352 言い換えれば \texttt{kern} featureは標準では無効化となっている.
1353 これは以前のバージョンの\LuaTeX-jaとの互換性のためである(\ref{para-kern}節を参照).
1354
1355 以下に\cs{jfontspec}の使用例を示す.
1356 %</ja>
1357
1358 \begin{LTXexample}[width=0.4\textwidth]
1359 \jfontspec[CJKShape=NLC]{KozMinPr6N-Regular}
1360 JIS~X~0213:2004→辻\par
1361 \jfontspec[CJKShape=JIS1990]{KozMinPr6N-Regular}
1362 JIS~X~0208:1990→辻
1363 \end{LTXexample}
1364
1365 %<en>\subsection{Presets}
1366 %<ja>\subsection{プリセット設定}
1367 \label{ssec-preset}
1368
1369 %<*en>
1370 To use standard Japanese font settings easily, one can load the \Pkg{luatexja-preset}
1371 package with several options. This package provides functions in a part of
1372 \Pkg{japanese-otf} package and a part of \Pkg{PXchfon} package by Takayuki Yato.
1373 %</en>
1374 %<*ja>
1375 よく使われている和文フォント設定を一行で指定できるようにしたのが
1376 \Pkg{luatexja-preset}パッケージである.このパッケージは,
1377 \Pkg{otf}パッケージの一部機能と八登崇之氏による\Pkg{PXchfon}パッケージの一部機能とを
1378 合わせたような格好をしている.
1379 %</ja>
1380
1381 %<en>\paragraph{General options}
1382 %<ja>\paragraph{一般的なオプション}
1383 \begin{cslist}[before*=]
1384
1385 \item[fontspec]
1386 %<*en>
1387 With this option, Japanese fonts are selected using functionality of 
1388 the \Pkg{luatexja-fontspec} package. This means that the \Pkg{fontspec} package is
1389              automatically loaded by this package.
1390 \emph{This option is enabled by default.}
1391
1392 If you need to pass some options to \Pkg{fontspec}, load \Pkg{fontspec} manually
1393 before \Pkg{luatexja-preset}:
1394 %</en>
1395 %<*ja>
1396 \Pkg{luatexja-fontspec}パッケージの機能を用いて和文フォントを選択する.
1397 これは,\Pkg{fontspec}パッケージが自動で読み込まれることを意味する.
1398 \emph{このオプションは標準で有効になっている.}
1399
1400 もし\Pkg{fontspec}パッケージに何らかのオプションを渡す必要がある
1401 \footnote{例えば,数式フォントまで置換されてしまい,\cs{mathit}によってギリシャ文字の
1402 斜体大文字が出なくなる,など.}場合は,
1403 次のように\Pkg{luatexja-preset}の前に\Pkg{fontspec}を手動で読みこめば良い:
1404 %</ja>
1405 \begin{lstlisting}
1406 \usepackage[no-math]{fontspec}
1407 \usepackage[...]{luatexja-preset}
1408 \end{lstlisting}
1409
1410 \item[nfssonly]
1411 %<*ja>
1412 \LaTeX 標準のフォント選択機構(NFSS2)を用いて
1413 \texttt{ltjpm}(明朝),\texttt{ltjpg}(ゴシック),それに後に述べる \texttt{deluxe} オプ
1414              ションが指定された場合には \texttt{ltjpmg}(丸ゴシック)という
1415 3つの和文フォントファミリを定義し,これらを用いる.
1416
1417 欧文フォントの指定で\Pkg{fontspec}パッケージを読み込んでいる場合でも
1418 \begin{lstlisting}
1419 \usepackage{fontspec}
1420 \usepackage[hiragino-pron,nfssonly]{luatexja-preset}
1421 \end{lstlisting}
1422 のように「和文側では\Pkg{fontspec}の機能は使わない,つまり\Pkg{luatexja-fontspec}は読み込
1423              まない」ことは可能である.一方,,
1424 パッケージ読み込み時に既に\Pkg{luatexja-fontspec}パッケージが読み込まれて
1425              いる場合は \texttt{nfssonly} オプションは無視される.
1426 %</ja>
1427
1428 \item[nodeluxe]
1429 %<*en>
1430 Use one-weighted \textit{mincho} and \textit{gothic} font families.
1431 This means that \verb+\mcfamily\bfseries+, \verb+\gtfamily\bfseries+ and
1432 \verb+\gtfamily\mdseries+ use the same font.
1433 \emph{This option is enabled by default.}
1434 %</en>
1435 %<*ja>
1436 \LaTeXe 環境下の標準設定のように,明朝体・ゴシック体を各1ウェイトで使用する.
1437 より具体的に言うと,この設定の下では
1438 \ \verb+\mcfamily\bfseries+, \verb+\gtfamily\bfseries+,
1439 \verb+\gtfamily\mdseries+はみな同じフォントとなる.
1440 \emph{このオプションは標準で有効になっている.}
1441 %</ja>
1442 \item[deluxe]
1443 %<*en>
1444 Use \textit{mincho} with two weights (medium~and~bold),
1445 \textit{gothic} with three weights (medium, bold~and~heavy), and \textit{rounded gothic}%
1446 \footnote{Provided by \cs{mgfamily} and \cs{textmg},
1447 because \textit{rounded gothic} is called \textit{maru gothic} (丸ゴシック) in Japanese.}.
1448 The heavy weight of \textit{gothic} can be used by ``changing the family'' \cs{gtebfamily},
1449 or \verb+\textgteb{...}+.
1450 This is because the \Pkg{fontspec} package can handle only medium (\cs{mdseries}) and
1451 bold (\cs{bfseries}).
1452 %</en>
1453 %<*ja>
1454 明朝体2ウェイト・ゴシック体3ウェイトと,
1455 丸ゴシック体 (\cs{mgfamily}, \verb+\textmg{...}+) を使用可能とする.
1456 ゴシック体は中字・太字・極太の3ウェイトがあるが,
1457 極太ゴシック体を使う場合,
1458 \begin{itemize}
1459  \item \cs{gtebfamily}, \verb+\textgteb{...}+
1460  \item \cs{ebseries} (周囲がゴシック体のとき,\texttt{nfssonly} オプション指定時のみ)
1461 \end{itemize}
1462 のいずれかを用いる.標準で \cs{ebseries} が準備されていないのは,バージョンが古い
1463 \Pkg{fontspec}では中字(\cs{mdseries})と太字(\cs{bfseries})しか扱えなかった名残である.
1464 %</ja>
1465 \item[expert]
1466 %<*en>
1467 Use horizontal/vertical kana alternates, and define a command \cs{rubyfamily} to use kana
1468 characters designed for ruby.
1469 %</en>
1470 %<*ja>
1471 横組・縦組専用仮名を用いる.また,\cs{rubyfamily} でルビ用仮名が使用可能となる\footnote{%
1472   \cs{rubyfamily}とはいいつつ,実際にはフォントファミリを切り替えるのではない(通常では
1473   font featureの追加,\texttt{nfssonly} 指定時にはシェイプを \texttt{rb} に切り替え).
1474 }.
1475 %</ja>
1476 \item[bold]
1477 %<en>Substitute bold series of \textit{gothic} for  bold series of \textit{mincho}.
1478 %<ja>「明朝の太字」をゴシック体の太字によって代替する.
1479 \item[90jis]
1480 %<en>Use 90JIS glyph variants if possible.
1481 %<ja>出来る限り90JISの字形を使う.
1482 \item[jis2004]
1483 %<en>Use JIS2004 glyph variants if possible.
1484 %<ja>出来る限りJIS2004の字形を使う.
1485 \item[jis]
1486 %<*en>
1487 Use the JFM \texttt{jfm-jis.lua}, instead of \texttt{jfm-ujis.lua}, which is the default JFM of
1488 \LuaTeX-ja.
1489 %</en>
1490 %<*ja>
1491 用いるJFMを(JISフォントメトリック類似の)\texttt{jfm-jis.lua}にする.このオプションがない時は
1492 \LuaTeX-ja標準の\texttt{jfm-ujis.lua}が用いられる.
1493 %</ja>
1494 \end{cslist}
1495 %<*en>
1496 Note that \texttt{90jis} and \texttt{jis2004} only affect with \textit{mincho},
1497 \textit{gothic} (and possibly \textit{rounded gothic}) defined by this package.
1498 We didn't taken account of  when both \texttt{90jis} and \texttt{jis2004} are specified.
1499 %</en>
1500 %<*ja>
1501 \texttt{90jis}と\texttt{jis2004}については本パッケージで定義された
1502 明朝体・ゴシック体(・丸ゴシック体)にのみ有効である.両オプションが
1503 同時に指定された場合の動作については全く考慮していない.
1504 %</ja>
1505
1506 %<en>\paragraph{Presets for multi weight}
1507 %<ja>\paragraph{多ウェイト用プリセットの一覧}
1508 %<*en>
1509 Besides \texttt{morisawa-pro}~and~\texttt{morisawa-pr6n} presets,
1510 fonts are specified by font name, not by file name.
1511 In following tables, starred fonts (e.g.~KozGo\dots-Regular) are used for medium series of \textit{gothic},
1512 \emph{if and only if \texttt{deluxe} option is specified}.
1513 %</en>
1514 %<*ja>
1515 \texttt{morisawa-pro}, \texttt{morisawa-pr6n}以外はフォントの指定は
1516 (ファイル名でなく)フォント名で行われる.
1517 以下の表において,*\,つきのフォント(e,g,~KozGo\dots-Regular)は,\emph{\texttt{deluxe}オプション指定時に}
1518 ゴシック体細字として用いられるものを示している.
1519 %</ja>
1520 \begin{cslist}[style=standard]
1521  \item[kozuka-pro] Kozuka Pro (Adobe-Japan1-4) fonts.
1522 %<en>    \\*[-\dimexpr\medskipamount+\baselineskip\relax]
1523  \item[kozuka-pr6] Kozuka Pr6 (Adobe-Japan1-6)  fonts.
1524 %<en>    \\*[-\dimexpr\medskipamount+\baselineskip\relax]
1525  \item[kozuka-pr6n] Kozuka Pr6N (Adobe-Japan1-6, JIS04-savvy) fonts.
1526
1527 %<*en>
1528 Kozuka Pro/Pr6N fonts are bundled with Adobe's software, such as Adobe~InDesign.
1529 There is not rounded gothic family in Kozuka fonts.
1530 %</en>
1531 %<*ja>
1532 小塚Pro書体・Pr6N書体はAdobe InDesign等のAdobe製品にバンドルされている.
1533 「小塚丸ゴシック」は存在しないので,便宜的に小塚ゴシックHによって代用している.
1534 %</ja>
1535 \begin{center}\small
1536 \begin{tabular}{cllll}
1537 \toprule
1538 \bf family&\bf series&\tt kozuka-pro&\tt kozuka-pr6&\tt kozuka-pr6n\\
1539 \midrule
1540  &medium&KozMinPro-Regular&KozMinProVI-Regular&KozMinPr6N-Regular\\
1541 %<en>\smash{\raisebox{1.5ex}{\textit{mincho}}}%
1542 %<ja>\smash{\raisebox{1.5ex}{\gt 明朝}}%
1543  &bold&KozMinPro-Bold&KozMinProVI-Bold&KozMinPr6N-Bold\\
1544 \midrule
1545  &&KozGoPro-Regular*&KozGoProVI-Regular*&KozGoPr6N-Regular*\\
1546  &\smash{\raisebox{1.5ex}{medium}}
1547  &KozGoPro-Medium&KozGoProVI-Medium&KozGoPr6N-Medium\\
1548 \cmidrule(l){2-5}
1549 %<en>\smash{\raisebox{2ex}{\textit{gothic}}}%
1550 %<ja>\smash{\raisebox{2ex}{\gt ゴシック}}%
1551  &bold&KozGoPro-Bold&KozGoProVI-Bold&KozGoPr6N-Bold\\
1552  &heavy&KozGoPro-Heavy&KozGoProVI-Heavy&KozGoPr6N-Heavy\\
1553 \midrule
1554 %<en>\textit{rounded gothic}
1555 %<ja>\gt 丸ゴシック
1556 &&KozGoPro-Heavy&KozGoProVI-Heavy&KozGoPr6N-Heavy\\
1557 \bottomrule
1558 \end{tabular}
1559 \end{center}
1560
1561 %<ja>\newpage
1562
1563  \item[hiragino-pro]  Hiragino Pro (Adobe-Japan1-5) fonts.
1564 %<en>    \\*[-\dimexpr\medskipamount+\baselineskip\relax]
1565  \item[hiragino-pron] Hiragino ProN (Adobe-Japan1-5, JIS04-savvy) fonts.
1566
1567 %<*en>
1568 Hiragino fonts are bundled with Mac OS~X 10.5 or later.
1569 Some editions of a Japanese word-processor ``一太郎2012'' includes Hiragino ProN fonts.
1570 Note that the heavy weight of \textit{gothic} family only supports
1571 Adobe-Japan1-3 character collection (Std/StdN).
1572 %</en>
1573 %<*ja>
1574 ヒラギノフォントは,Mac OS~X以外にも,一太郎2012の上位エディションにもバンドルされている.
1575 極太ゴシックとして用いるヒラギノ角ゴW8は,Adobe-Japan1-3の範囲しかカバーしていない
1576 Std/StdNフォントであり,その他はAdobe-Japan1-5対応である.
1577 %</ja>
1578 \begin{center}\small
1579 \begin{tabular}{clll}
1580 \toprule
1581 \bf family&\bf series&\tt hiragino-pro&\tt hiragino-pron\\
1582 \midrule
1583  &medium&Hiragino~Mincho~Pro~W3&Hiragino~Mincho~ProN~W3\\
1584 %<en>\smash{\raisebox{1.5ex}{\textit{mincho}}}%
1585 %<ja>\smash{\raisebox{1.5ex}{\gt 明朝}}%
1586  &bold&Hiragino~Mincho~Pro~W6&Hiragino~Mincho~ProN~W6\\
1587 \midrule
1588  &&Hiragino~Kaku~Gothic~Pro~W3*&Hiragino~Kaku~Gothic~ProN~W3*\\
1589  &\smash{\raisebox{1.5ex}{medium}}
1590  &Hiragino~Kaku~Gothic~Pro~W6&Hiragino~Kaku~Gothic~ProN~W6\\
1591 \cmidrule(l){2-4}
1592 %<en>\smash{\raisebox{2ex}{\textit{gothic}}}%
1593 %<ja>\smash{\raisebox{2ex}{\gt ゴシック}}%
1594  &bold&Hiragino~Kaku~Gothic~Pro~W6&Hiragino~Kaku~Gothic~ProN~W6\\
1595  &heavy&Hiragino~Kaku~Gothic~Std~W8&Hiragino~Kaku~Gothic~StdN~W8\\
1596 \midrule
1597 %<en>\textit{rounded gothic}
1598 %<ja>\gt 丸ゴシック
1599 &&Hiragino~Maru~Gothic~ProN~W4&Hiragino~Maru~Gothic~ProN~W4\\
1600 \bottomrule
1601 \end{tabular}
1602 \end{center}
1603
1604 %<ja>\medskip
1605
1606  \item[morisawa-pro]  Morisawa Pro (Adobe-Japan1-4) fonts.
1607 %<en>    \\*[-\dimexpr\medskipamount+\baselineskip\relax]
1608  \item[morisawa-pr6n]  Morisawa Pr6N (Adobe-Japan1-6, JIS04-savvy) fonts.
1609
1610 \begin{center}\small
1611 \begin{tabular}{cl>{\tt}l>{\tt}l}
1612 \toprule
1613 \bf family&\bf series&morisawa-pro&morisawa-pr6n\\
1614 \midrule
1615  &medium&A-OTF-RyuminPro-Light.otf&A-OTF-RyuminPr6N-Light.otf\\
1616 %<en>\smash{\raisebox{1.5ex}{\textit{mincho}}}%
1617 %<ja>\smash{\raisebox{1.5ex}{\gt 明朝}}%
1618  &bold&A-OTF-FutoMinA101Pro-Bold.otf&A-OTF-FutoMinA101Pr6N-Bold.otf\\
1619 \midrule
1620  &medium
1621  &A-OTF-GothicBBBPro-Medium.otf&A-OTF-GothicBBBPr6N-Medium.otf\\
1622 %<en>\textit{gothic}%
1623 %<ja>\gt ゴシック
1624  &bold&A-OTF-FutoGoB101Pro-Bold.otf&A-OTF-FutoGoB101Pr6N-Bold.otf\\
1625  &heavy&A-OTF-MidashiGoPro-MB31.otf&A-OTF-MidashiGoPr6N-MB31.otf\\
1626 \midrule
1627 %<en>\textit{rounded gothic}
1628 %<ja>\gt 丸ゴシック
1629 &&A-OTF-Jun101Pro-Light.otf&A-OTF-ShinMGoPr6N-Light.otf\\
1630 \bottomrule
1631 \end{tabular}
1632 \end{center}
1633
1634  \item[yu-win]  Yu fonts bundled with Windows~8.1.
1635 %<en>    \\*[-\dimexpr\medskipamount+\baselineskip\relax]
1636  \item[yu-osx]  Yu fonts bundled with OSX~Mavericks.
1637
1638 \begin{center}\small
1639 \begin{tabular}{clll}
1640 \toprule
1641 \bf family&\bf series&\tt yu-win&\tt yu-osx\\
1642 \midrule
1643  &medium&YuMincho-Regular&YuMincho~Medium\\
1644 %<en>\smash{\raisebox{1.5ex}{\textit{mincho}}}%
1645 %<ja>\smash{\raisebox{1.5ex}{\gt 明朝}}%
1646  &bold&YuMincho-Demibold&YuMincho~Demibold\\
1647 \midrule
1648  &&YuGothic-Regular*&YuGothic~Medium*\\
1649  &\smash{\raisebox{1.5ex}{medium}}
1650  &YuGothic-Bold&YuGothic~Bold\\
1651 \cmidrule(l){2-4}
1652 %<en>\textit{gothic}%
1653 %<ja>\gt ゴシック
1654  &bold&YuGothic-Bold&YuGothic~Bold\\
1655  &heavy&YuGothic-Bold&YuGothic~Bold\\
1656 \midrule
1657 %<en>\textit{rounded gothic}
1658 %<ja>\gt 丸ゴシック
1659 &&YuGothic-Bold&YuGothic~Bold\\
1660 \bottomrule
1661 \end{tabular}
1662 \end{center}
1663
1664  \item[moga-mobo]  MogaMincho, MogaGothic, and MoboGothic.
1665 These fonts can be downloaded from
1666 \url{http://yozvox.web.fc2.com/82A882B782B782DF8374834883938367.html}.
1667
1668 \begin{center}\small
1669 \begin{tabular}{clll}
1670 \toprule
1671 \bf family&\bf series&\bf default, \texttt{90jis}~option&\bf \texttt{jis2004} option\\
1672 \midrule
1673  &medium&Moga90Mincho&MogaMincho\\
1674 %<en>\smash{\raisebox{1.5ex}{\textit{mincho}}}%
1675 %<ja>\smash{\raisebox{1.5ex}{\gt 明朝}}%
1676  &bold&Moga90Mincho Bold&MogaMincho Bold\\
1677 \midrule
1678  &&Moga90Gothic&MogaGothic\\
1679  &\smash{\raisebox{1.5ex}{medium}}
1680  &Moga90Gothic&MogaGothic\\
1681 \cmidrule(l){2-4}
1682 %<en>\textit{gothic}%
1683 %<ja>\gt ゴシック
1684  &bold&Moga90Gothic Bold&MogaGothic Bold\\
1685  &heavy&Moga90Gothic Bold&MogaGothic Bold\\
1686 \midrule
1687 %<en>\textit{rounded gothic}
1688 %<ja>\gt 丸ゴシック
1689 &&Mobo90Gothic&MoboGothic\\
1690 \bottomrule
1691 \end{tabular}
1692 \end{center}
1693
1694
1695 \end{cslist}
1696 %<en>\paragraph{Presets for single weight}
1697 %<ja>\paragraph{単ウェイト用プリセット一覧}
1698 %<*en>
1699 Next, we describe settings for using only single weight.
1700 %</en>
1701 %<*ja>
1702 次に,単ウェイト用の設定を述べる.この4設定では
1703 明朝体太字・丸ゴシック体はゴシック体と同じフォントが用いられる.
1704 %</ja>
1705 \par\nobreak\medskip
1706 {\centering\small
1707 \begin{tabular}{lllll}
1708 \toprule
1709 &\tt noembed&\tt ipa&\tt ipaex&\tt ms\\
1710 \midrule
1711 %<*en>
1712 \it mincho&Ryumin-Light (non-embedded)
1713 &IPA Mincho&IPAex Mincho&MS Mincho\\
1714 \it gothic&GothicBBB-Medium (non-embedded)
1715 &IPA Gothic&IPAex Gothic&MS Gothic\\
1716 %</en>
1717 %<*ja>
1718 \gtfamily 明朝体&Ryumin-Light(非埋込)
1719 &IPA明朝&IPAex明朝&MS明朝\\
1720 \gtfamily ゴシック体&GothicBBB-Medium(非埋込)
1721 &IPAゴシック&IPAexゴシック&MSゴシック\\
1722 %</ja>
1723 \bottomrule
1724 \end{tabular}\par\medskip}
1725
1726 %<en>\paragraph{Using HG fonts}
1727 %<ja>\paragraph{HGフォントの利用}
1728 %<*en>
1729 We can use HG~fonts bundled with Microsoft~Office for realizing multiple weights.
1730 %</en>
1731 %<*ja>
1732 すぐ前に書いた単ウェイト用設定を,Microsoft Office等に付属するHGフォントを使って
1733 多ウェイト化した設定もある.
1734 %</ja>
1735 \par\nobreak\medskip
1736 {\centering\small
1737 \begin{tabular}{llll}
1738 \toprule
1739 &\tt ipa-hg&\tt ipaex-hg&\tt ms-hg\\
1740 \midrule
1741 %<*en>
1742 \bf mincho medium
1743 &IPA Mincho&IPAex Mincho&MS Mincho\\\midrule
1744 \bf mincho bold&
1745 \multicolumn{3}{c}{HG Mincho E}\\\midrule
1746 \bf Gothic medium\\
1747 ~~without \texttt{deluxe}
1748 &IPA Gothic&IPAex Gothic&MS Gothic\\
1749 ~~with {\tt jis2004}
1750 &IPA Gothic&IPAex Gothic&MS Gothic\\
1751 \cmidrule(lr){1-4}
1752 ~~otherwise&
1753 \multicolumn{3}{c}{HG Gothic M}\\\midrule
1754 \bf gothic bold&
1755 \multicolumn{3}{c}{HG Gothic E}\\\midrule
1756 \bf gothic heavy&
1757 \multicolumn{3}{c}{HG Soei Kaku Gothic UB}\\\midrule
1758 \bf rounded gothic&
1759 \multicolumn{3}{c}{HG Maru Gothic PRO}\\
1760 %</en>
1761 %<*ja>
1762 \gtfamily 明朝体中字
1763 &IPA明朝&IPAex明朝&MS明朝\\\midrule
1764 \gtfamily 明朝体太字&
1765 \multicolumn{3}{c}{HG明朝E}\\\midrule
1766 \gtfamily ゴシック体中字\\
1767  単ウェイト時
1768 &IPAゴシック&IPAexゴシック&MSゴシック\\
1769  {\tt jis2004}指定時
1770 &IPAゴシック&IPAexゴシック&MSゴシック\\
1771 \cmidrule(lr){1-4}
1772  それ以外の時&
1773 \multicolumn{3}{c}{HGゴシックM}\\\midrule
1774 \gtfamily ゴシック体太字&
1775 \multicolumn{3}{c}{HGゴシックE}\\\midrule
1776 \gtfamily ゴシック体極太&
1777 \multicolumn{3}{c}{HG創英角ゴシックUB}\\\midrule
1778 \gtfamily 丸ゴシック体&
1779 \multicolumn{3}{c}{HG丸ゴシック体PRO}\\
1780 %</ja>
1781 \bottomrule
1782 \end{tabular}\par\medskip}
1783
1784 %<*en>
1785 Note that HG~Mincho~E, HG~Gothic~E, HG Soei Kaku Gothic UB, and HG Maru Gothic PRO
1786 are internally specified by:
1787 \begin{description}
1788 \item[default] by font name (\texttt{HGMinchoE}, etc.).
1789 \item[{\tt 90jis}] by file name (\texttt{hgrme.ttc}, \texttt{hgrge.ttc}, \texttt{hgrsgu.ttc}, \texttt{hgrsmp.ttf}).
1790 \item[{\tt jis2004}] by file name (\texttt{hgrme04.ttc}, \texttt{hgrge04.ttc}, \texttt{hgrsgu04.ttc}, \texttt{hgrsmp04.ttf}).
1791 \end{description}
1792 %</en>
1793 %<*ja>
1794 なお,HG明朝E・HGゴシックE・HG創英角ゴシックUB・HG丸ゴシック体PROの4つについては,内部で
1795 \begin{description}
1796 \item[標準] フォント名(\texttt{HGMinchoE} など)
1797 \item[{\tt 90jis}指定時] ファイル名 (%
1798 \texttt{hgrme.ttc}, \texttt{hgrge.ttc}, \texttt{hgrsgu.ttc}, \texttt{hgrsmp.ttf})
1799 \item[{\tt jis2004}指定時] ファイル名 (%
1800 \texttt{hgrme04.ttc}, \texttt{hgrge04.ttc}, \texttt{hgrsgu04.ttc}, \texttt{hgrsmp04.ttf})
1801 \end{description}
1802 として指定を行っているので注意すること.
1803 %</ja>
1804
1805
1806 %<*en>
1807 \subsection{\cs{CID}, \cs{UTF}, and macros in \Pkg{japanese-otf} package}
1808 Under \pLaTeX, \Pkg{japanese-otf} package (developed by Shuzaburo Saito) is
1809 used for typesetting characters which is in Adobe-Japan1-6 CID but not
1810 in JIS~X~0208. Since this package is widely used, \LuaTeX-ja
1811 supports some of functions in the \Pkg{japanese-otf} package, 
1812 as an external package \Pkg{luatexja-otf}.
1813 %</en>
1814 %<*ja>
1815 \subsection{\cs{CID}, \cs{UTF}と\Pkg{otf}パッケージのマクロ}
1816 \pLaTeX では,JIS~X~0208にないAdobe-Japan1-6の文字を出力するために,
1817 齋藤修三郎氏による\Pkg{otf}パッケージが用いられていた.このパッケージは
1818 広く用いられているため,\LuaTeX-jaにおいても\Pkg{otf}パッケージの機能の
1819 一部を(\Pkg{luatexja-otf}という別のパッケージとして)実装した.
1820 %</ja>
1821
1822 \begin{LTXexample}
1823 \jfontspec{KozMinPr6N-Regular.otf}
1824 森\UTF{9DD7}外と内田百\UTF{9592}とが\UTF{9AD9}島屋に行く。
1825
1826 \CID{7652}飾区の\CID{13706}野家,
1827 \CID{1481}城市,葛西駅,
1828 高崎と\CID{8705}\UTF{FA11}
1829
1830 \aj半角{はんかくカタカナ}
1831 \end{LTXexample}
1832
1833 %<*ja>
1834 \Pkg{otf}パッケージでは,それぞれ次のようなオプションが存在した:
1835 \begin{cslist}
1836 \item[deluxe] 明朝体・ゴシック体各3ウェイトと,丸ゴシック体を扱えるようになる.
1837 \item[expert] 仮名が横組・縦組専用のものに切り替わり,ルビ用仮名も
1838 \ \cs{rubyfamily}\ によって扱えるようになる.
1839 \item[bold] ゴシック体を標準で太いウェイトのものに設定する.
1840 \end{cslist}
1841 しかしこれらのオプションは\Pkg{luatexja-otf}パッケージには存在しない.
1842 \Pkg{otf}パッケージが文書中で使用する和文用TFMを自前の物に置き換えていたのに対し,
1843 \Pkg{luatexja-otf}パッケージでは,そのようなことは行わないからである.
1844
1845 これら3オプションについては,
1846 \Pkg{luatexja-preset} パッケージにプリセットを使う時に一緒に指定するか,
1847 あるいは対応する内容を\ref{ssec-chgfnt}節,\ref{ssec-nfsspat}節 (NFSS2) や
1848 \ref{ssec-fontspec}節 (\Pkg{fontspec}) の方法で手動で指定する必要がある.
1849 %</ja>
1850
1851 %<en>\subsection{Changing default Japanese fonts}
1852 %<ja>\subsection{標準和文フォントの変更}
1853 \label{ssec-cfg}
1854 %<*en>
1855 If \texttt{luatexja.cfg} can be seen from \LuaTeX, \LuaTeX-ja automatically reads it.
1856 The main use of \texttt{luatexja.cfg} is for changing default Japanese fonts,
1857 when IPAex fonts cannot be installed in \TeX~system.
1858 One should not overuse this \texttt{luatexja.cfg}; fonts which will be used in
1859 a document should be specified in its source.
1860
1861 For example,
1862 \begin{lstlisting}
1863 \def\ltj@stdmcfont{IPAMincho}
1864 \def\ltj@stdgtfont{IPAGothic}
1865 \end{lstlisting}
1866 makes that IPA~Mincho and IPA~Gothic will be used as default Japanese fonts, instead of
1867 IPAex~Mincho and IPAex~Gothic.
1868
1869 For another example, the following two lines makes that
1870 non-embedded fonts Ryumin-Light~and~GothicBBB-Medium as default Japanese fonts
1871 (as the earlier version of \LuaTeX-ja):
1872 \begin{lstlisting}
1873 \def\ltj@stdmcfont{psft:Ryumin-Light}
1874 \def\ltj@stdgtfont{psft:GothicBBB-Medium}
1875 \end{lstlisting}
1876 %</en>
1877 %<*ja>
1878 \LuaTeX から見える位置に \texttt{luatexja.cfg} があれば,\LuaTeX-jaはそれを読み込む.
1879 このファイルを用いるとplain~\TeX, \LaTeXe における標準和文フォントを
1880 IPAex明朝・IPAexゴシックから変更することができる.
1881 しかし,基本的には\emph{文章中で用いるフォントは(例えば \Pkg{luatexja-preset} などで)
1882 文書ソース内で指定するべき}であり,この \texttt{luatexja.cfg} は,
1883 「IPAexフォントがインストールできない」など,IPAexフォントが使用できない場合にのみ
1884 応急処置的に用いるべきである.
1885
1886 例えば
1887 \begin{lstlisting}
1888 \def\ltj@stdmcfont{IPAMincho}
1889 \def\ltj@stdgtfont{IPAGothic}
1890 \end{lstlisting}
1891 と記述しておけば,標準和文フォントがIPA明朝・IPAゴシックへと変
1892 更される.
1893
1894
1895 なお,20140906.0以前のバージョンのように,
1896 Ryumin-Light, GothicBBB-Mediumという名前の非埋込フォントを用いる場合は
1897 \begin{lstlisting}
1898 \def\ltj@stdmcfont{psft:Ryumin-Light}
1899 \def\ltj@stdgtfont{psft:GothicBBB-Medium}
1900 \end{lstlisting}
1901 と記述すればよい.
1902 %</ja>
1903
1904
1905 %<en>\section{Changing Parameters}
1906 %<ja>\section{パラメータの変更}
1907
1908 %<*en>
1909 There are many parameters in \LuaTeX-ja. And due to the behavior of \LuaTeX,
1910 most of them are not stored as internal register of \TeX, but as an
1911 original storage system in \LuaTeX-ja. Hence, to assign or acquire those
1912 parameters, you have to use commands \cs{ltjsetparameter} and
1913 \cs{ltjgetparameter}.
1914 %</en>
1915 %<*ja>
1916 \LuaTeX-jaには多くのパラメータが存在する.そして\LuaTeX の仕様のために,
1917 その多くは\TeX のレジスタにではなく,\LuaTeX-ja独自の方法で保持されている.
1918 これらのパラメータを設定・取得するためには \cs{ltjsetparameter} と \cs{ltjgetparameter} を
1919 用いる.
1920 %</ja>
1921
1922 %<en>\subsection{Editing the Range of \textbf{JAchar}s}
1923 %<ja>\subsection{\textbf{JAchar}の範囲の設定}
1924 \label{ssec-setrange}
1925
1926 %<*en>
1927 \LuaTeX-ja divides the Unicode codespace \texttt{U+0080}--\texttt{U+10FFFF}
1928 into \emph{character ranges},
1929 numbered 1 to 217. The grouping can be (globally) customized by \cs{ltjdefcharrange}.
1930 The next line adds whole characters in Supplementary Ideographic Plane
1931 and the character ``漢'' to the character range~100.
1932 %</en>
1933 %<*ja>
1934 \LuaTeX-jaは,Unicodeの \texttt{U+0080}--\texttt{U+10FFFF} の空間を
1935 1番から217番までの\emph{文字範囲}に分割している.
1936 区分けは \cs{ltjdefcharrange} を用いることで(グローバルに)変更することができ,
1937 例えば,次は追加漢字面(SIP)にある全ての文字と「漢」を「100番の文字範囲」に追加する.
1938 %</ja>
1939 \begin{lstlisting}
1940 \ltjdefcharrange{100}{"20000-"2FFFF,`漢}
1941 \end{lstlisting}
1942 %<*en>
1943 A character can belong to only one character range.
1944 For example, whole SIP belong to the range~4 in the default setting of \LuaTeX-ja,
1945 and if you execute the above line, then SIP will belong to the range~100 and be
1946 removed from the range~4.
1947 %</en>
1948 %<*ja>
1949 各文字はただ一つの文字範囲に所属することができる.
1950 例えば,SIPは全て\LuaTeX-jaのデフォルトでは4番の文字範囲に
1951 属しているが,上記の指定を行えばSIPは100番に属すようになり,4番からは除かれる.
1952 %</ja>
1953
1954 %<*en>
1955 The distinction between \textbf{ALchar} and \textbf{JAchar} is done for character ranges.
1956 This can be edited by setting the \textsf{jacharrange} parameter.
1957 For example, this is just the default setting of \LuaTeX-ja, and
1958 it sets
1959 \begin{itemize}
1960  \item a character which belongs character ranges 1,~4, and~5 is \textbf{ALchar},
1961  \item a character which belongs character ranges 2,~3, 6, 7, and~8 is \textbf{JAchar}.
1962 \end{itemize}
1963 %</en>
1964 %<*ja>
1965 \textbf{ALchar}と\textbf{JAchar}の区別は文字範囲ごとに行われる.
1966 これは\textsf{jacharrange}パラメータによって編集できる.
1967 例えば,以下は\LuaTeX-jaの初期設定であり,次の内容を設定している:
1968 \begin{itemize}
1969  \item 1番,4番,5番の文字範囲に属する文字は\textbf{ALchar}.
1970  \item 2番,3番,6番,7番,8番の文字範囲に属する文字は\textbf{JAchar}.
1971 \end{itemize}
1972 %</ja>
1973 \begin{lstlisting}
1974 \ltjsetparameter{jacharrange={-1, +2, +3, -4, -5, +6, +7, +8}}
1975 \end{lstlisting}
1976 %<*en>
1977 The argument to \textsf{jacharrange} parameter is a list of non-zero integer.
1978 Negative integer $-n$ in the list means that ``each character in the range~$n$ is an
1979 \textbf{ALchar}'',
1980 and positive integer $+n$ means that ``\dots\ is a \textbf{JAchar}''.
1981 %</en>
1982 %<*ja>
1983 \textsf{jacharrange}パラメータの引数は非零の整数のリストである.
1984 リスト中の負の整数$-n$は「文字範囲$n$に属する文字は\textbf{ALchar}として
1985 扱う」ことを意味し,正の整数$+n$は「\textbf{JAchar}として扱う」ことを意味する.
1986 %</ja>
1987
1988 %<*en>
1989 \paragraph{Default setting}
1990 \LuaTeX-ja predefines eight character ranges for convenience. They are
1991 determined from the following data:
1992 %</en>
1993 %<*ja>
1994 \paragraph{初期設定}
1995 \LuaTeX-jaでは8つの文字範囲を予め定義しており,
1996 これらは以下のデータに基づいて決定している.
1997 %</ja>
1998 \begin{itemize}
1999 %<en>\item Blocks in Unicode~6.0.
2000 %<ja>\item Unicode~6.0のブロック.
2001 %<en>\item The \texttt{Adobe-Japan1-UCS2} mapping between a CID Adobe-Japan1-6 and Unicode.
2002 %<ja>\item Adobe-Japan1-6のCIDとUnicodeの間の対応表\texttt{Adobe-Japan1-UCS2}.
2003 %<en>\item The \Pkg{PXbase} bundle for \upTeX\ by Takayuki Yato.
2004 %<ja>\item 八登崇之氏による\upTeX 用の\Pkg{PXbase}バンドル.
2005 \end{itemize}
2006
2007 %<*en>
2008 Now we describe these eight ranges. The superscript ``J'' or ``A'' after the
2009 number shows whether each character in the range is treated as
2010 \textbf{JAchar}s or not by default. These settings are similar to the
2011 \texttt{prefercjk} settings defined in \texttt{PXbase} bundle.
2012 Any characters above \texttt{U+0080} which does not belong to
2013 these eight ranges belongs to the character range~217.
2014 %</en>
2015 %<*ja>
2016 以下ではこれら8つの文字範囲について記述する.添字のアルファベット「J」「A」
2017 は,その文字範囲内の文字が\textbf{JAchar}か\textbf{ALchar}かを表している.これらの設定は
2018 \texttt{PXbase}バンドルで定義されている\texttt{prefercjk}と類似のものである.
2019 なお,\texttt{U+0080} 以降でこれら8つの文字範囲に属さない文字は,217番の文字範囲に属することになっている.
2020 %</ja>
2021 \begin{description}
2022 %<*en>
2023
2024 \item[Range~8${}^{\kern.1em\text{J}}$] The intersection of the upper half of ISO~8859-1
2025          (Latin-1 Supplement) and JIS~X~0208 (a basic character set for Japanese). This character range
2026          consists of the following characters:
2027 %</en>
2028 %<*ja>
2029 \item[範囲8${}^{\kern.1em\text{J}}$] ISO~8859-1の上位領域(ラテン1補助)と
2030                              JIS~X~0208の共通部分.この文字範囲は
2031                              以下の文字で構成される:
2032 %</ja>
2033 \begin{multicols}{2}
2034 \begin{itemize}
2035 \def\ch#1#2{\item \char"#1\ (\texttt{U+00#1}, #2)}%"
2036 \ch{A7}{Section Sign}
2037 \ch{A8}{Diaeresis}
2038 \ch{B0}{Degree sign}
2039 \ch{B1}{Plus-minus sign}
2040 \ch{B4}{Spacing acute}
2041 \ch{B6}{Paragraph sign}
2042 \ch{D7}{Multiplication sign}
2043 \ch{F7}{Division Sign}
2044 \end{itemize}
2045 \end{multicols}
2046
2047 %<*en>
2048 \item[Range~1${}^{\text{A}}$] Latin characters that some of them are included in Adobe-Japan1-6.
2049 This range consists of the following Unicode ranges, \emph{except characters in the range~8 above}:
2050 %</en>
2051 %<*ja>
2052 \item[範囲1${}^{\text{A}}$] ラテン文字のうち,Adobe-Japan1-6との共通部分があるもの.
2053                              この範囲は以下のUnicodeのブロックのうち
2054                              \emph{範囲8を除いた}部分で構成されている:
2055 %</ja>
2056 \begin{multicols}{2}
2057 \begin{itemize}
2058 \item \texttt{U+0080}--\texttt{U+00FF}: Latin-1 Supplement
2059 \item \texttt{U+0100}--\texttt{U+017F}: Latin Extended-A
2060 \item \texttt{U+0180}--\texttt{U+024F}: Latin Extended-B
2061 \item \texttt{U+0250}--\texttt{U+02AF}: IPA Extensions
2062 \item \texttt{U+02B0}--\texttt{U+02FF}: Spacing Modifier Letters
2063 \item \texttt{U+0300}--\texttt{U+036F}: \\\null\hfill Combining Diacritical Marks
2064 \item \texttt{U+1E00}--\texttt{U+1EFF}: \\\null\hfill Latin Extended Additional
2065 \par\
2066 \end{itemize}
2067 \end{multicols}
2068 %<*en>
2069 \item[Range~2${}^{\text{\kern.1emJ}}$] Greek and Cyrillic letters. JIS~X~0208 (hence most of Japanese
2070            fonts) has some of these characters.
2071 %</en>
2072 %<*ja>
2073 \item[範囲2${}^{\text{\kern.1emJ}}$] ギリシャ文字とキリル文字.JIS~X~0208(したがってほとんどの
2074                              和文フォント)はこれらの文字を持つ.
2075 %</ja>
2076 \begin{multicols}{2}
2077 \begin{itemize}
2078 \item \texttt{U+0370}--\texttt{U+03FF}: Greek and Coptic
2079 \item \texttt{U+0400}--\texttt{U+04FF}: Cyrillic
2080 \item \texttt{U+1F00}--\texttt{U+1FFF}: Greek Extended
2081 \\\
2082 \end{itemize}
2083 \end{multicols}
2084 %<*en>
2085 \item[Range~3${}^{\text{\kern.1emJ}}$] Punctuations and Miscellaneous symbols. The block list is
2086            indicated in Table~\ref{table-rng3}.
2087 %</en>
2088 %<*ja>
2089 \item[範囲3${}^{\text{\kern.1emJ}}$] 句読点と記号類.ブロックのリストは表\ref{table-rng3}%
2090                              に示してある.
2091 %</ja>
2092 \begin{table}[!tb]
2093 %<en>\caption{Unicode blocks in predefined character range~3.}\medskip
2094 %<ja>\caption{文字範囲3に指定されているUnicodeブロック.}
2095 \label{table-rng3}
2096 \catcode`\"=13\def"#1#2#3#4{\texttt{U+#1#2#3#4}}%"
2097 \centering\small
2098 \begin{tabular}{llll}
2099 "2000--"206F&General Punctuation&
2100 "2070--"209F&Superscripts and Subscripts\\
2101 "20A0--"20CF&Currency Symbols&
2102 "20D0--"20FF&Comb.\ Diacritical Marks for Symbols\\
2103 "2100--"214F&Letterlike Symbols&
2104 "2150--"218F&Number Forms\\
2105 "2190--"21FF&Arrows&
2106 "2200--"22FF&Mathematical Operators\\
2107 "2300--"23FF&Miscellaneous Technical&
2108 "2400--"243F&Control Pictures\\
2109 "2500--"257F&Box Drawing&
2110 "2580--"259F&Block Elements\\
2111 "25A0--"25FF&Geometric Shapes&
2112 "2600--"26FF&Miscellaneous Symbols\\
2113 "2700--"27BF&Dingbats&
2114 "2900--"297F&Supplemental Arrows-B\\
2115 "2980--"29FF&Misc.\ Mathematical Symbols-B&
2116 "2B00--"2BFF&Miscellaneous Symbols and Arrows
2117 \end{tabular}
2118 \end{table}
2119 %<*en>
2120 \item[Range~4${}^{\text{A}}$] Characters usually not in Japanese fonts. This range consists
2121            of almost all Unicode blocks which are not in other
2122            predefined ranges. Hence, instead of showing the block list,
2123            we put the definition of this range itself:
2124 %</en>
2125 %<*ja>
2126 \item[範囲4${}^{\text{A}}$] 通常和文フォントには含まれていない文字.
2127                              この範囲は他の範囲にないほとんど全てのUnicodeブロック
2128                              で構成されている.したがって,ブロックのリストを示す
2129                              代わりに,範囲の定義そのものを示す:
2130 %</ja>
2131 \begin{lstlisting}
2132 \ltjdefcharrange{4}{%
2133    "500-"10FF, "1200-"1DFF, "2440-"245F, "27C0-"28FF, "2A00-"2AFF,
2134   "2C00-"2E7F, "4DC0-"4DFF, "A4D0-"A82F, "A840-"ABFF, "FB00-"FE0F,
2135   "FE20-"FE2F, "FE70-"FEFF, "10000-"1FFFF, "E000-"F8FF} % non-Japanese
2136 \end{lstlisting}
2137 %<en>\item[Range~5${}^{\text{A}}$] Surrogates and Supplementary Private Use Areas.
2138 %<ja>\item[範囲5${}^{\text{A}}$] 代用符号と補助私用領域.
2139 %<en>\item[Range~6${}^{\text{\kern.1emJ}}$] Characters used in Japanese. The block list is indicated in Table~\ref{table-rng6}.
2140 %<ja>\item[範囲6${}^{\text{\kern.1emJ}}$] 日本語で用いられる文字.ブロックのリストは表\ref{table-rng6}に示す.
2141 \begin{table}[!tb]
2142 %<en>\caption{Unicode blocks in predefined character range~6.}\medskip
2143 %<ja>\caption{文字範囲6に指定されているUnicodeブロック.}
2144 \label{table-rng6}
2145 \catcode`\"=13\def"#1#2#3#4{\texttt{U+#1#2#3#4}}%"
2146 \centering\small
2147 \begin{tabular}{llll}
2148 "2460--"24FF&Enclosed Alphanumerics&
2149 "2E80--"2EFF&CJK Radicals Supplement\\
2150 "3000--"303F&CJK Symbols and Punctuation&
2151 "3040--"309F&Hiragana\\
2152 "30A0--"30FF&Katakana&
2153 "3190--"319F&Kanbun\\
2154 "31F0--"31FF&Katakana Phonetic Extensions&
2155 "3200--"32FF&Enclosed CJK Letters and Months\\
2156 "3300--"33FF&CJK Compatibility&
2157 "3400--"4DBF&CJK Unified Ideographs Extension A\\
2158 "4E00--"9FFF&CJK Unified Ideographs&
2159 "F900--"FAFF&CJK Compatibility Ideographs\\
2160 "FE10--"FE1F&Vertical Forms&
2161 "FE30--"FE4F&CJK Compatibility Forms\\
2162 "FE50--"FE6F&Small Form Variants&
2163 "{20}000--"{2F}FFF&(Supplementary Ideographic Plane)\\
2164 "{E0}100--"{E0}1EF&Variation Selectors Supplement
2165 \end{tabular}
2166 \end{table}
2167 %<*en>
2168 \item[Range~7${}^{\text{\kern.1emJ}}$] Characters used in CJK languages, but not included in  Adobe-Japan1-6.
2169 The block list is indicated in Table~\ref{table-rng7}.
2170 %</en>
2171 %<*ja>
2172 \item[範囲7${}^{\text{\kern.1emJ}}$] CJK言語で用いられる文字のうち,Adobe-Japan1-6に
2173                             含まれていないもの.
2174                             ブロックのリストは表\ref{table-rng7}に示す.
2175 %</ja>
2176 \begin{table}[!tb]
2177 %<en>\caption{Unicode blocks in predefined character range~7.}\medskip
2178 %<ja>\caption{文字範囲7に指定されているUnicodeブロック.}
2179 \label{table-rng7}
2180 \catcode`\"=13\def"#1#2#3#4{\texttt{U+#1#2#3#4}}%"
2181 \centering\small
2182 \begin{tabular}{llll}
2183 "1100--"11FF&Hangul Jamo&
2184 "2F00--"2FDF&Kangxi Radicals\\
2185 "2FF0--"2FFF&Ideographic Description Characters&
2186 "3100--"312F&Bopomofo\\
2187 "3130--"318F&Hangul Compatibility Jamo&
2188 "31A0--"31BF&Bopomofo Extended\\
2189 "31C0--"31EF&CJK Strokes&
2190 "A000--"A48F&Yi Syllables\\
2191 "A490--"A4CF&Yi Radicals&
2192 "A830--"A83F&Common Indic Number Forms\\
2193 "AC00--"D7AF&Hangul Syllables&
2194 "D7B0--"D7FF&Hangul Jamo Extended-B
2195 \end{tabular}
2196 \end{table}
2197 \end{description}
2198
2199 %<en>\subsection{\Param{kanjiskip} and \Param{xkanjiskip}}
2200 %<ja>\subsection{\Param{kanjiskip}と\Param{xkanjiskip}}
2201 \label{subs-kskip}
2202
2203 %<en>\textbf{JAglue} is divided into the following three categories:
2204 %<ja>\textbf{JAglue}は以下の3つのカテゴリに分類される:
2205 \begin{itemize}
2206 %<*en>
2207 \item Glues/kerns specified in JFM. If \cs{inhibitglue} is issued
2208       around a Japanese character, this glue will not be inserted at the
2209       place.
2210 %</en>
2211 %<*ja>
2212 \item JFMで指定されたグルー/カーン.もし \cs{inhibitglue} が和文文字の周りで
2213       発行されていれば,このグルーは挿入されない.
2214 %</ja>
2215 %<*en>
2216 \item The default glue which inserted between two \textbf{JAchar}s (\Param{%
2217       kanjiskip}).
2218 %</en>
2219 %<*ja>
2220 \item デフォルトで2つの\textbf{JAchar}の間に挿入されるグルー(\Param{kanjiskip}).
2221 %</ja>
2222 %<*en>
2223 \item The default glue which inserted between a \textbf{JAchar} and an
2224       \textbf{ALchar} (\Param{xkanjiskip}).
2225 %</en>
2226 %<*ja>
2227 \item デフォルトで\textbf{JAchar}と\textbf{ALchar}の間に挿入されるグルー(\Param{xkanjiskip}).
2228 %</ja>
2229 \end{itemize}
2230 %<*en>
2231 The value (a skip) of \Param{kanjiskip} or
2232 \Param{xkanjiskip} can be changed as the following.
2233 Note that only their values \emph{at the end of a paragraph or a hbox are
2234 adopted in the whole paragraph or the whole hbox.
2235 }
2236 %</en>
2237 %<*ja>
2238 \Param{kanjiskip}や\Param{xkanjiskip}の値
2239 は以下のようにして変更可能である.
2240 %</ja>
2241 \begin{lstlisting}
2242 \ltjsetparameter{kanjiskip={0pt plus 0.4pt minus 0.4pt},
2243                  xkanjiskip={0.25\zw plus 1pt minus 1pt}}
2244 \end{lstlisting}
2245 %<*en>
2246 Here \cs{zw} is a internal dimension
2247 which stores fullwidth of the current Japanese font.
2248 This \cs{zw} can be used as the unit \texttt{zw} in \pTeX.
2249
2250 The value of these parameter can be get by \cs{ltjgetparameter}.
2251 Note that the result by \cs{ltjgetparameter} is \emph{not} the internal quantities,
2252 but \emph{a string} (hence \cs{the} cannot be prefixed).
2253 %</en>
2254 %<*ja>
2255 ここで,\cs{zw} は現在の和文フォントの全角幅を表す長さであり,
2256 \pTeX における長さ単位 \texttt{zw} と同じように使用できる.
2257
2258 これらのパラメータの値は以下のように取得できる.
2259 戻り値は内部値ではなく\emph{文字列}である(\cs{the} は前置できない)ことに注意してほしい:
2260 %</ja>
2261 \begin{LTXexample}
2262 kanjiskip: \ltjgetparameter{kanjiskip},\\
2263 xkanjiskip: \ltjgetparameter{xkanjiskip}
2264 \end{LTXexample}
2265
2266 %<*en>
2267 It may occur that JFM contains the data of ``ideal width of
2268 \Param{kanjiskip}''
2269 and/or ``ideal width of \Param{xkanjiskip}''.
2270 To use these data from JFM, set the value of \Param{kanjiskip} or
2271 \Param{xkanjiskip} to \cs{maxdimen}
2272 (these ``ideal width'' cannot be retrived by \cs{ltjgetparameter}).
2273 %</en>
2274 %<*ja>
2275 JFMは「望ましい\Param{kanjiskip}の値」や
2276 「望ましい\Param{xkanjiskip}の値」を持っていることがある.
2277 これらのデータを使うためには,\Param{kanjiskip}や%
2278 \Param{xkanjiskip}の値を \cs{maxdimen} の値に設定すればよいが,
2279 \cs{ltjgetparameter} によって取得することはできないので注意が必要である.
2280 %</ja>
2281
2282 %<en>\subsection{Insertion Setting of \Param{xkanjiskip}}
2283 %<ja>\subsection{\Param{xkanjiskip} の挿入設定}
2284
2285 %<*en>
2286 It is not desirable that \Param{xkanjiskip} is inserted into every
2287 boundary between \textbf{JAchar}s and \textbf{ALchar}s. For example,
2288 \Param{xkanjiskip} should not be inserted after opening parenthesis
2289 (\textit{e.g.}, compare ``(あ'' and ``(\hskip\ltjgetparameter{xkanjiskip}あ'').
2290 \LuaTeX-ja can control whether \Param{xkanjiskip} can be inserted
2291 before/after a character, by changing \Param{jaxspmode} for \textbf{JAchar}s and
2292 \Param{alxspmode} parameters \textbf{ALchar}s respectively.
2293 %</en>
2294 %<*ja>
2295 \Param{xkanjiskip}がすべての\textbf{JAchar}と\textbf{ALchar}の境界に
2296 挿入されるのは望ましいことではない.例えば,\Param{xkanjiskip}は開き括弧の
2297 後には挿入されるべきではない(「(あ」と「(\hskip\ltjgetparameter{xkanjiskip}あ」を
2298 比べてみよ).
2299 \LuaTeX-jaでは\Param{xkanjiskip}をある文字の前/後に挿入するかどうかを,
2300 \textbf{JAchar}に対しては\Param{jaxspmode}を,\textbf{ALchar}に対しては
2301 \Param{alxspmode}をそれぞれ変えることで制御することができる.
2302 %</ja>
2303 \begin{LTXexample}
2304 \ltjsetparameter{jaxspmode={`あ,preonly}, alxspmode={`\!,postonly}}
2305 pあq い!う
2306 \end{LTXexample}
2307
2308 %<*en>
2309 The second argument \texttt{preonly} means that the insertion of
2310 \Param{xkanjiskip} is allowed before this character, but not after.
2311 the other possible values are \texttt{postonly}, \texttt{allow}, and \texttt{inhibit}.
2312 %</en>
2313 %<*ja>
2314 2つ目の引数の \texttt{preonly}は「\Param{xkanjiskip}の挿入はこの文字の
2315 前でのみ許され,後では許さない」ことを意味する.他に指定可能な値は
2316 \texttt{postonly}, \texttt{allow}, \texttt{inhibit}である.
2317 %</ja>
2318
2319 %<*en>
2320 \Param{jaxspmode} and \Param{alxspmode} use a same table to store the parameters
2321 on the current version. Therefore, line~1 in the code above can be rewritten
2322 as follows:
2323 %</en>
2324 %<*ja>
2325 なお,現行の
2326 仕様では,\Param{jaxspmode}, \Param{alxspmode}はテーブルを共有しており,
2327 上のコードの1行目を次のように変えても同じことになる:
2328 %</ja>
2329 \begin{lstlisting}
2330 \ltjsetparameter{alxspmode={`あ,preonly}, jaxspmode={`\!,postonly}}
2331 \end{lstlisting}
2332 %<*en>
2333 One can use also numbers to specify these two parameters (see Subsection~\ref{ssec-param}).
2334 %</en>
2335 %<*ja>
2336 また,これら2パラメータには数値で値を指定することもできる(\ref{ssec-param}節を参照).
2337 %</ja>
2338
2339 %<*en>
2340 If you want to enable/disable all insertions of \Param{kanjiskip} and
2341 \Param{xkanjiskip}, set \Param{autospacing} and \Param{autoxspacing}
2342 parameters to \texttt{true}/\texttt{false}, respectively.
2343 %</en>
2344 %<*ja>
2345 もし全ての\Param{kanjiskip}と\Param{xkanjiskip}の挿入を有効化/無効化
2346 したければ,それぞれ\Param{autospacing}と\Param{autoxspacing}を
2347 \texttt{true}/\texttt{false}に設定すればよい.
2348 %</ja>
2349
2350 %<en>\subsection{Shifting the baseline}
2351 %<ja>\subsection{ベースラインの移動}
2352 %<*en>
2353 To make a match between a Japanese font and an alphabetic font, sometimes
2354 shifting of the baseline of one of the pair is needed. In \pTeX, this is achieved
2355 by setting \cs{ybaselineshift} (or \cs{tbaselineshift}) to a non-zero length (the
2356 baseline of \textbf{ALchar} is shifted below). However, for documents
2357 whose main language is not Japanese, it is good to shift the baseline of
2358 Japanese fonts, but not that of alphabetic fonts.
2359 Because of this, \LuaTeX-ja can independently set the shifting amount
2360 of the baseline of alphabetic fonts and that of Japanese fonts.
2361 \begin{center}
2362  \small
2363 \begin{tabular}{>{\bfseries}lcc}
2364 \toprule
2365 &\bfseries Horizontal writing (\emph{yoko} direction) etc.
2366 &\bfseries Vertical writing(\emph{tate} direction)\\
2367 \midrule
2368 Alphabetic fonts&\Param{yalbaselineshift}
2369      parameter&\Param{talbaselineshift} parameter\\
2370 Japanese fonts&\Param{yjabaselineshift}
2371      parameter&\Param{tjabaselineshift} parameter\\
2372 \bottomrule
2373 \end{tabular}
2374 \end{center}
2375 %</en>
2376 %<*ja>
2377 和文フォントと欧文フォントを合わせるためには,時々どちらかのベースラインの移動が
2378 必要になる.\pTeX ではこれは \cs{ybaselineshift}(または\cs{tbaselineshift})を設定することで
2379 なされていた(\textbf{ALchar}のベースラインがその分だけ下がる).しかし,日本語が主ではない
2380 文書に対しては,欧文フォントではなく和文フォントのベースラインを移動した方がよい.
2381 このため,\LuaTeX-jaでは欧文フォントのベースラインのシフト量
2382 と和文フォントのベースラインのシフト量を独立に設定できるようになっている.
2383 \begin{center}
2384  \small
2385 \begin{tabular}{>{\bfseries}lcc}
2386 \toprule
2387 &\bfseries 横組など&\bfseries 縦組\\
2388 \midrule
2389 欧文フォントのシフト量&\Param{yalbaselineshift}
2390      parameter&\Param{talbaselineshift} parameter\\
2391 和文フォントのシフト量&\Param{yjabaselineshift}
2392      parameter&\Param{tjabaselineshift} parameter\\
2393 \bottomrule
2394 \end{tabular}
2395 \end{center}
2396 %</ja>
2397
2398 %<*en>
2399 Here the horizontal line in the below example is the baseline of a line.
2400 %</en>
2401 %<*ja>
2402 下の例において引かれている水平線がベースラインである.
2403 %</ja>
2404 \begin{LTXexample}
2405 \vrule width 150pt height 0.4pt depth 0pt \hskip-120pt
2406 \ltjsetparameter{yjabaselineshift=0pt, yalbaselineshift=0pt}abcあいう
2407 \ltjsetparameter{yjabaselineshift=5pt, yalbaselineshift=2pt}abcあいう
2408 \end{LTXexample}
2409
2410 %<*en>
2411 There is an interesting side-effect: characters in different size can be
2412 vertically aligned center in a line, by setting two parameters appropriately.
2413 The following is an example (beware the value is not well tuned):
2414 %</en>
2415 %<*ja>
2416 この機能には面白い使い方がある:2つのパラメータを適切に設定することで,サイズの
2417 異なる文字を中心線に揃えることができる.
2418 以下は一つの例である(値はあまり調整されていないことに注意):
2419 %</ja>
2420 \begin{LTXexample}
2421 xyz漢字
2422 {\scriptsize
2423   \ltjsetparameter{yjabaselineshift=-1pt,
2424     yalbaselineshift=-1pt}
2425   XYZひらがな
2426 }abcかな
2427 \end{LTXexample}
2428
2429 %<*en>
2430 Note that setting positive \Param{yalbaselineshift}~or~\Param{talbaselineshift}
2431 parameters does not increase the depth of one-letter ``syllable'' $p$ of \textbf{Alchar}, if
2432 its left-protrusion~(\cs{lpcode}) and right-protrusion~(\cs{rpcode}) are both non-zero.
2433 This is because
2434 \begin{itemize}
2435 \item These two parameters are implemented by setting yoffset field of a
2436 glyph node, and this does not increase the depth of the glyph.
2437 \item To cope with the above situation, \LuaTeX-ja automatically supplies
2438 a rule in every ``syllable''.
2439 \item However, we cannot use this ``supplying a rule'' method if \dots
2440 \end{itemize}
2441
2442 This problem does not apply for \Param{yjabaselineshift}~nor~\Param{tjabaselineshift}.
2443 %</en>
2444 %<*ja>
2445 なお,以下の場合には1文字の\textbf{ALchar}からなる「音節」の深さは増加しないことに注意.
2446 \begin{itemize}
2447  \item \Param{yalbaselineshift},~\Param{talbaselineshift}パラメータが正になっている.
2448  \item 「音節」を構成する唯一の文字$p$の
2449 左余白への突出量(\cs{lpcode}),右余白への突出量(\cs{rpcode})がどちらも非零である.
2450 \end{itemize}
2451 \Param{yjabaselineshift},~\Param{tjabaselineshift}パラメータについてはこのような問題は起こらない.
2452 %</ja>
2453
2454 %<*ja>
2455 \paragraph{数式における挙動:\pTeX との違い}
2456 \textbf{ALchar}のベースラインを補正する \Param{yalbaselineshift} パラメータは
2457 ほぼ\pTeX における \cs{ybaselineshift} に対応しているものであるが,
2458 数式中の挙動は異なっているので注意が必要である.
2459 例えば,表\ref{tab:math_bsa}のように,数式中に明示的に現れた \cs{hbox} は,
2460 \begin{itemize}
2461  \item \pTeX では,ボックス全体が \cs{ybaselineshift} だとシフトされるので,
2462  表\ref{tab:math_bsa}中の``い''のように,ボックス中の和文文字は
2463  \ \cs{ybaselineshift} だけシフトされ,一方,``for all''のように,
2464  ボックス内の欧文文字は2重にシフトされることになる.
2465  \item 一方,\LuaTeX-jaではそのようなことはおこらず,
2466  数式中に明示的に現れた \cs{hbox} はシフトしない.そのため,
2467  表\ref{tab:math_bsa}中の``い''も``for all''も,それぞれ本文中に
2468  書かれたときと同じ上下位置に組まれる.
2469 \end{itemize}
2470 \begin{table}
2471 \small\centering
2472 \caption{数式関係のベースライン補正($\Param{yalbaselineshift}=10\,\textrm{pt}$)}
2473 \label{tab:math_bsa}
2474 \newdimen\origbaselineskip
2475 \origbaselineskip=\baselineskip
2476 \begin{tabular}{lp{30\zw}}
2477 \toprule
2478 \emph{入力}&\vspace*{\dimexpr-\origbaselineskip-\smallskipamount}
2479 \begin{lstlisting}
2480 数式abc: $あa\hbox{い}$, $\int_0^x t\,dt=x^2\!/2$,
2481 $\Phi\vdash F(x)\ \hbox{for all}\ x\in A$
2482 \end{lstlisting}\\
2483 \noalign{\vskip-\origbaselineskip}
2484 \midrule
2485 \emph{\pTeX}&
2486 {\ltjsetparameter{yalbaselineshift=10pt}%
2487 数式abc: $あa\lower10pt\hbox{い}$, $\int_0^x t\,dt=x^2\!/2$,
2488 $\Phi\vdash F(x)\ \lower10pt\hbox{for all}\ x\in A$
2489 \par}\\
2490 \midrule
2491 \emph{\LuaTeX-ja}&
2492 {\ltjsetparameter{yalbaselineshift=10pt}%
2493 数式abc: $あa\hbox{い}$, $\int_0^x t\,dt=x^2\!/2$,
2494 $\Phi\vdash F(x)\ \hbox{for all}\ x\in A$
2495 \par}\\
2496 \noalign{\vskip-\origbaselineskip}
2497 \bottomrule
2498 \end{tabular}
2499 \end{table}
2500 %</ja>
2501
2502 %<*en>
2503 \subsection{\emph{kinsoku} parameters and OpenType features}
2504 Among parameters which related to Japanese word-wrapping process (\emph{kinsoku shori}),
2505 \begin{quote}
2506  \Param{jaxspmode},~\Param{alxspmode}, \Param{prebreakpenalty}, 
2507  \Param{postbreakpenalty}~and~\Param{kcatcode}
2508 \end{quote}
2509 are stored by each character codes. ...
2510
2511 For example, a fullwidth katakana ``ア'' on line~10 in the below input is replaced to
2512 its halfwidth variant ``ア'', by \verb+hwid+ feature. 
2513 However, the penalty inserted after it is 10 which is the \Param{postbreakpenalty} of
2514 ``ア'', not 20.
2515 %</en>
2516 %<*ja>
2517 \subsection{禁則処理関連パラメータとfont feature}
2518 禁則処理や \Param{kanjiskip}, \Param{xkanjiskip} の挿入に関連したパラメータのうち
2519 \begin{quote}
2520  \Param{jaxspmode},~\Param{alxspmode}, \Param{prebreakpenalty},
2521  \Param{postbreakpenalty}, \Param{kcatcode}
2522 \end{quote}
2523 は,文字コードごとに設定する量である.
2524
2525 \Pkg{fontspec}パッケージを使う(\ref{ssec-fontspec}節)場合など,
2526 各種のOpenType featureを適用することもあると思うが,前段落に述べたパラメータ類は,
2527 \emph{OpenType featureの適用前の文字コードによって判定される.}
2528 例えば,以下の例において10行目の「ア」は,\verb+hwid+ featureの適用により半角カタカナの「ア」
2529 に置き換わる.しかし,その直後に挿入される \Param{postbreakpenalty}は,置換前の「ア」に対する値10である.
2530 %</ja>
2531
2532 \begin{LTXexample}[width=0.2\textwidth]
2533 \ltjsetparameter{postbreakpenalty={`ア, 10}}
2534 \ltjsetparameter{postbreakpenalty={`ア, 20}}
2535
2536 \newcommand\showpostpena[1]{%
2537   \leavevmode\setbox0=\hbox{#1\hbox{}}%
2538   \unhbox0\setbox0=\lastbox\the\lastpenalty}
2539
2540 \showpostpena{ア},
2541 \showpostpena{ア},
2542 {\addjfontfeatures{CharacterWidth=Half}\showpostpena{ア}}
2543 \end{LTXexample}
2544
2545 \clearpage
2546 %<en>\part{Reference}
2547 %<ja>\part{リファレンス}
2548 \label{part-ref}
2549 \suppressfloats[t]
2550 %<*ja>
2551 \section{\LuaTeX-jaにおける \cs{catcode}}
2552 \label{sec-catcode}
2553 \subsection{予備知識:\pTeX と\upTeX における \cs{kcatcode}}
2554 \pTeX,\upTeX においては,和文文字が制御綴内で利用できるかどうか
2555 は \cs{kcatcode} の値によって決定されるのであった.
2556 詳細は表\ref{table-kcat}を参照されたい.
2557 %</ja>
2558 %<*en>
2559 \section{\cs{catcode} in \LuaTeX-ja}
2560 \label{sec-catcode}
2561 \subsection{Preliminaries: \cs{kcatcode} in \pTeX\ and \upTeX}
2562 In \pTeX~and~\upTeX, the value of \cs{kcatcode} determines
2563 whether a Japanese character can be used in a control word.
2564 For the detail, see Table~\ref{table-kcat}.
2565 %</en>
2566
2567 \begin{table}[t]
2568 \small
2569 \caption{\cs{kcatcode} in \upTeX}
2570 \label{table-kcat}
2571 %<en>\medskip
2572
2573 \noindent\hfill
2574 \begin{tabular}{ccccc}
2575 \toprule
2576 \bfseries \cs{kcatcode}&
2577 %<*en>
2578 \bfseries meaning&
2579 \bfseries control word&
2580 \bfseries widow penalty\hbox{}$^*$&
2581 \bfseries linebreak\\
2582 %</en>
2583 %<*ja>
2584 \bfseries 意図&
2585 \bfseries 制御綴中に使用&
2586 \bfseries 文字ウィドウ処理\hbox{}$^*$&
2587 \bfseries 直後での改行\\
2588 %</ja>
2589 \midrule
2590 15&non-cjk&\multicolumn{3}{c}{(treated as usual \LaTeX)}\\
2591 16&kanji&Y&Y&ignored\\
2592 17&kana&Y&Y&ignored\\
2593 18&other&N&N&ignored\\
2594 19&hangul&Y&Y&space\\
2595 \bottomrule
2596 \end{tabular}\hfill\null
2597
2598 \medskip
2599
2600 %<*ja>
2601 文字ウィドウ処理\hbox{}$^*$: 「漢字が一文字だけ次の行に行くのを防ぐ」\
2602 \cs{jcharwidowpenalty} が,
2603 その文字の直前に挿入されうるか否か,を示す.
2604 %</ja>
2605 \end{table}
2606
2607 %<*en>
2608 \cs{kcatcode} can be set by a row of JIS~X~0208 in \pTeX,
2609 and generally by a Unicode block\footnote{%
2610   \upTeX\ divides \texttt{U+FF00}--\texttt{U+FFEF} (Halfwidth and Fullwidth Forms)
2611   into three subblocks, and \cs{kcatcode} can be set by a subblock.
2612 }
2613 in \upTeX. So characters which can be used in a control word
2614 slightly differ between \pTeX~and~\upTeX.
2615 %</en>
2616 %<*ja>
2617 \pTeX では \cs{kcatcode} はJIS~X~0208の区単位,
2618 \upTeX では概ねUnicodeブロック単位\footnote{%
2619   \texttt{U+FF00}--\texttt{U+FFEF} (Halfwidth and Fullwidth Forms)は
2620   「全角英数字」「半角カナ」「その他」と3つに分割されており,
2621   それぞれ別々に \cs{kcatcode} が指定できるようになっている.
2622 }で設定可能になっている.そのため,\pTeX と\upTeX の初期状態では
2623 制御綴内で使用可能な文字が微妙に異なっている.
2624 %</ja>
2625
2626 %<*en>
2627 \subsection{Case of \LuaTeX-ja}
2628 The role of \cs{kcatcode} in \pTeX~and~\upTeX\ can be
2629 divided into the following four kinds,
2630 and \LuaTeX-ja can control these four kinds separately:
2631 \begin{itemize}
2632  \item
2633 \emph{Distinction between \textbf{JAchar} or \textbf{ALchar}}
2634 is controlled by using the character range, see Subsection~\ref{ssec-setrange}.
2635  \item
2636 \emph{Whether the character can be used in a control word}
2637 is controlled by setting \cs{catcode} to 11~(enabled) or 12~(disabled), as usual.
2638  \item
2639 \emph{Whether \Param{jcharwidowpenalty} can be inserted before the character}
2640 is controlled by the lowermost bit of the \Param{kcatcode} parameter.
2641  \item
2642 \emph{Ignoring linebreak after a \textbf{JAchar}} is always ignored.
2643 \end{itemize}
2644 %</en>
2645 %<*ja>
2646 \subsection{\LuaTeX-jaの場合}
2647 \LuaTeX-jaでは,従来の\pTeX・\upTeX における \cs{kcatcode} の役割を
2648 分割している:
2649 \begin{description}
2650  \item[欧文/和文の区別 (\upTeX)]
2651 \cs{ltjdefcharrange} と\textsf{jacharrange}パラメータ(\ref{ssec-setrange}節)
2652  \item[制御綴中に使用可か]
2653 \LuaTeX 自身の \cs{catcode} でよい
2654  \item[\Param{jcharwidowpenalty}が挿入可か]
2655 \Param{kcatcode}パラメータの最下位ビット
2656  \item[直後の改行の無視]
2657 日本語しか想定していないので\textbf{JAchar}については一律有効
2658 \end{description}
2659 %</ja>
2660
2661 %<*en>
2662 Default setting of \cs{catcode} of \LuaTeX\ can be found
2663 in \texttt{luatex-unicode-letters.tex},
2664 which is based on \texttt{unicode-letters.tex} (for \XeTeX).
2665 However, the default setting of \cs{catcode} differs
2666 between \XeTeX\ and \LuaTeX, by the following reasons:
2667 \begin{itemize}
2668  \item \texttt{luatex-unicode-letters.tex} is based on old \texttt{unicode-letters.tex}.
2669  \item The latter half of \texttt{unicode-letters.tex} sets
2670 \cs{catcode} of Kanji and kana characters to 11,
2671 via setting \cs{XeTeXcharclass}.
2672
2673 However, this latter half is simply omitted in
2674 \texttt{luatex-unicode-letters.tex}, hence
2675 \cs{catcode} of Kanji and kana characters remains 12 in \LuaTeX.
2676 \end{itemize}
2677 In other words, Kanji nor kana characters cannot be used in
2678 a control word, in the default setting of \LuaTeX.
2679
2680 This would be inconvenient for \pTeX~users to shifting to \LuaTeX-ja,
2681 since several control words containing Kanji, such as \verb+\西暦+,
2682 are used in \pTeX.
2683 Hence, \LuaTeX-ja have a counterpart of \texttt{unicode-letters.tex}
2684 for \LuaTeX, \emph{to match the \cs{catcode} setting with that of \XeTeX.}
2685 %</en>
2686 %<*ja>
2687 ネイティブにUnicode全部の文字を扱える\XeTeX や\LuaTeX では,
2688 文字が制御綴内で使用できるかは通常の欧文文字と同じく \cs{catcode}
2689 で指定することとなる.\XeTeX における \cs{catcode} の初期設定は\
2690 \texttt{unicode-letters.tex} 中に記述されており,\LuaTeX ではそれを
2691 元にした \texttt{luatex-unicode-letters.tex} を用いている.
2692
2693 だが,\XeTeX における \cs{catcode} の初期設定と
2694 \LuaTeX におけるそれは一致していない:
2695 \begin{itemize}
2696  \item \texttt{luatex-unicode-letters.tex} の元になった\
2697 \texttt{unicode-letters.tex} が古い
2698  \item \texttt{unicode-letters.tex} の後半部では
2699 \cs{XeTeXcharclass} の設定を行なっており,
2700 それによって漢字や仮名の \cs{catcode} が11に設定されている.
2701
2702 しかし,\texttt{luatex-unicode-letters.tex} ではこの「後半部」が
2703 まるごと省略されており,漢字や仮名の \cs{catcode} は12のまま.
2704 \end{itemize}
2705 言い換えると,\LuaTeX の初期状態では漢字や仮名を制御綴内に
2706 使用することはできない.
2707
2708 これでは \pTeX で使用できた \verb+\西暦+ などが使えないこととなり,
2709 \LuaTeX-jaへの移行で手間が生じる.そのため,\LuaTeX-jaでは
2710 \texttt{unicode-letters.tex} の後半部にあたる内容を自前でパッチし,
2711 結果として\textbf{\XeTeX における初期設定と同じになるようにしている.}
2712 %</ja>
2713
2714 \begin{table}
2715  \centering\small
2716 %<en>\caption{Difference of the set of non-kanji JIS~X~0208 characters which can be used in a control word}
2717 %<ja>\caption{制御綴中に使用出来るJIS~X~0208非漢字の違い}
2718 %<en>\medskip
2719 \label{table-kcat-diff}
2720 \def\D#1#2#3#4{%
2721   {\fboxsep0pt\fcolorbox{cyan}{white}%
2722   {\large\char"#1#2#3#4}}\ (\texttt{U+#1#2#3#4})} %"
2723 \leavevmode\hbox to 0pt{\hss\begin{tabular}{cccccc}
2724 \toprule
2725 %<en>&\bf row&\bf col.&\bf \pTeX&\bf \upTeX&\bf\LuaTeX-ja\\
2726 %<ja>&\bf 区&\bf 点&\bf \pTeX&\bf \upTeX&\fontseries{b}\selectfont\LuaTeX-ja\\
2727 \midrule
2728 %\D 3000&1&1&N&N&Y\\
2729 \D 30FB&1&6&N&Y&N\\
2730 \D 309B&1&11&N&Y&N\\
2731 \D 309C&1&12&N&Y&N\\
2732 \D FF40&1&14&N&N&Y\\
2733 \D FF3E&1&16&N&N&Y\\
2734 \D FFE3&1&17&N&N&Y\\
2735 \D FF3F&1&18&N&N&Y\\
2736 %\D 30FD&1&19&N&Y&Y\\
2737 %\D 30FE&1&20&N&Y&Y\\
2738 %\D 309D&1&21&N&Y&Y\\
2739 %\D 309E&1&22&N&Y&Y\\
2740 \D 3003&1&23&N&N&Y\\
2741 \D 4EDD&1&24&N&Y&Y\\
2742 \D 3005&1&25&N&N&Y\\
2743 \D 3006&1&26&N&N&Y\\
2744 \D 3007&1&27&N&N&Y\\
2745 \D 30FC&1&28&N&Y&Y\\
2746 \D FF0F&1&31&N&N&Y\\
2747 \D FF3C&1&32&N&N&Y\\
2748 \bottomrule
2749 \end{tabular}\qquad
2750 \begin{tabular}{cccccc}
2751 \toprule
2752 %<en>&\bf row&\bf col.&\bf \pTeX&\bf \upTeX&\bf\LuaTeX-ja\\
2753 %<ja>&\bf 区&\bf 点&\bf \pTeX&\bf \upTeX&\fontseries{b}\selectfont\LuaTeX-ja\\
2754 \midrule
2755 \D FF5C&1&35&N&N&Y\\
2756 \D FF0B&1&60&N&N&Y\\
2757 \D FF1D&1&65&N&N&Y\\
2758 \D FF1C&1&67&N&N&Y\\
2759 \D FF1E&1&68&N&N&Y\\
2760 \D FF03&1&84&N&N&Y\\
2761 \D FF06&1&85&N&N&Y\\
2762 \D FF0A&1&86&N&N&Y\\
2763 \D FF20&1&87&N&N&Y\\
2764 \D 3012&2&9&N&N&Y\\
2765 \D 3013&2&14&N&N&Y\\
2766 \D FFE2&2&44&N&N&Y\\
2767 \D 212B&2&82&N&N&Y\\
2768 %<en>\multicolumn{3}{c}{$\vphantom{\D 3000}$\hbox{}Greek letters (row 6)}&Y&N&Y\\
2769 %<en>\multicolumn{3}{c}{$\vphantom{\D 3000}$\hbox{}Cyrillic letters (row 7)}&N&N&Y\\
2770 %<ja>\multicolumn{3}{c}{$\vphantom{\D 3000}$\hbox{}ギリシャ文字(6区)}&Y&N&Y\\
2771 %<ja>\multicolumn{3}{c}{$\vphantom{\D 3000}$\hbox{}キリル文字(7区)}&N&N&Y\\
2772 \bottomrule
2773 \end{tabular}\hss}\par
2774 \end{table}
2775
2776 %<*en>
2777 \subsection{Non-kanji Characters in a Control Word}
2778 Because the engine differ, so non-kanji JIS~X~0208 characters
2779 which can be used in a control word differ in \pTeX, in \upTeX,~and~in \LuaTeX-ja.
2780 Table~\ref{table-kcat-diff} shows the difference.
2781 Except for four characters ``・'',~``゛'', ``゜'',~``゠'',
2782 \LuaTeX-ja admits more characters in a control word than \upTeX.
2783 \emph{Note that the ideographic space~\texttt{U+3000} can be used
2784 in a control word in \LuaTeX-ja.}
2785
2786 Difference becomes larger, if we consider
2787 non-kanji JIS~X~0213 characters.
2788 For the detail, see \url{https://github.com/h-kitagawa/kct}.
2789 %</en>
2790 %<*ja>
2791 \subsection{制御綴中に使用出来るJIS非漢字の違い}
2792
2793 エンジンが異なるので,\pTeX, \upTeX, \LuaTeX-ja
2794 において制御綴中に使用可能なJIS~X~0208の文字は異なる.
2795 異なっているところだけを載せると,表\ref{table-kcat-diff}のようになる.
2796 「・」「゛」「゜」「゠」を除けば,\LuaTeX-jaでは\upTeX より多くの文字が
2797 制御綴に使用可能になっている.
2798
2799 JIS~X~0213の範囲に広げると,差異はさらに大きくなる.
2800 詳細については例えば \url{https://github.com/h-kitagawa/kct} 中の\
2801 \texttt{kct-out.pdf} などを参照すること.
2802 %</ja>
2803
2804
2805 %<*en>
2806 \section{Directions}
2807 \LuaTeX\ supports four $\Omega$-style directions: \texttt{TLT},~\texttt{TRT}, \texttt{RTT}
2808 and \texttt{LTL}.
2809 However, neither directions are not well-suited for typesetting Japanese vertically, hence we
2810 implemented vertical writing by rotating \texttt{TLT}-box by 90~degrees.
2811 %</en>
2812 %<*ja>
2813 \section{縦組}
2814 \label{sec-direction}
2815 \LuaTeX 本体でも,$\Omega$・$\aleph$由来の機能として,複数の組方向をサポートしている.
2816 しかし,\LuaTeX がサポートするのは \texttt{TLT},~\texttt{TRT}, \texttt{RTT},~\texttt{LTL}\
2817 のみであり,日本語の縦組に使うのは望ましくない\footnote{%
2818 和文文字だけならば \texttt{RTT} を使えばなんとかなると思うが,
2819 欧文文字が入ってきた場合はうまくいかず,\texttt{RTR} という組方向が必要になる.
2820 }.そのため,\LuaTeX-jaでは横組(\texttt{TLT})で組んだボックスを回転させる方式で
2821 縦組を実装した.
2822 %</ja>
2823
2824 %<ja>\subsection{サポートする組方向}
2825 \begin{table}[t]
2826 %<ja>\caption{\LuaTeX-ja のサポートする組方向}
2827 %<en>\caption{Directions supported by \LuaTeX-ja}
2828 %<en>\medskip
2829 \label{tab-dir}
2830 \centering\small
2831 \def\obox#1{%
2832   \setbox0=\hbox{\yoko\hbox{#1%
2833   \large\ltjsetparameter{talbaselineshift=0pt}%
2834   \vrule height 25pt width 0.4pt depth 15pt\kern-.2pt%
2835   \raise25pt\hbox to 0pt{\hss\composite{*r^@{>>}}\hss}%
2836   \raise-15pt\hbox to 0pt{\hss\composite{*l^@{>|}}\hss}\kern.2pt%
2837   \vrule height.2pt depth.2pt width 60pt\hbox to 0pt{\hss\composite{*d^@{>}}\hss}\kern-60pt
2838   \hbox to 60pt{\,銀は、Ag\hss}}}%
2839   \raise\dimexpr 0.5\ltjgetdp0-0.5\ltjgetht0\box0%
2840 }
2841 %<*ja>
2842 \begin{tabular}{>{\bfseries}lcccc}
2843 \toprule
2844 &横組&縦組 &「dtou方向」&「utod方向」\\
2845 \midrule
2846 命令&\cs{yoko}&\cs{tate}&\cs{dtou}&\cs{utod}\\
2847 字送り方向&水平右向き(→)&垂直下向き(↓)&垂直上向き(↑)&垂直下向き(↓)\\
2848 行送り方向&垂直下向き(↓)&水平左向き(←)&水平右向き(→)&水平左向き(←)\\
2849 使用する和文フォント&横組用(\cs{jfont})&縦組用(\cs{tfont})&
2850 \multicolumn{2}{c}{%
2851   横組用(\cs{jfont})の$90^\circ$回転}\\[\smallskipamount]
2852 組版例\null $^*$ &\obox{\yoko}&\obox{\tate}&\obox{\dtou}&\obox{\utod}\\
2853 \noalign{\medskip}
2854 \bottomrule
2855 \end{tabular}
2856
2857 \medskip\raggedright
2858 \def\R#1{%
2859   \raise0.38\zw\hbox{%
2860     \vrule height.2pt  depth.2pt width2\zw%
2861     \hbox to 0pt{\hss\composite{*d^@{#1}}\hss}%
2862   }%
2863 }
2864 $^*$\ 幅(width),高さ(height),深さ(depth)の増加方向を,
2865 それぞれ「\R{>}」,「\R{>>}」,「\R{>|}」で表している.
2866 \raggedright
2867 %</ja>
2868
2869 %<*en>
2870 \begin{tabular}{>{\bfseries}lcccc}
2871 \toprule
2872 &horizontal (\emph{yoko}~direction)&vertical (\emph{tate}~direction)&%
2873   \emph{dtou} direction&\emph{utod} direction\\
2874 \midrule
2875 Commands&\cs{yoko}&\cs{tate}&\cs{dtou}&\cs{utod}\\
2876 Beginning of the page&Top&Right&Left&Right\\
2877 Beginning of the line&Left&Top&Bottom&Top\\
2878 Used Japanese font&horizontal (\cs{jfont})&vertical (\cs{tfont})&
2879 \multicolumn{2}{c}{%
2880   horizontal ($90^\circ$ rotated)}\\[\smallskipamount]
2881 Example&\obox{\yoko}&\obox{\tate}&\obox{\dtou}&\obox{\utod}\\
2882 \noalign{\medskip}
2883 (Notation used in $\Omega$)&TLT&RTR, RTT&LBL&RTR\\
2884 \bottomrule
2885 \end{tabular}
2886
2887 \medskip\raggedright
2888 \def\R#1{%
2889   \raise0.38\zw\hbox{%
2890     \vrule height.2pt  depth.2pt width2\zw%
2891     \hbox to 0pt{\hss\composite{*d^@{#1}}\hss}%
2892   }%
2893 }
2894 \raggedright
2895 %</en>
2896 \end{table}
2897
2898 %<*en>
2899 \LuaTeX-ja supports four directions, as shown in Table~\ref{tab-dir}.
2900 The second column (\emph{yoko} direction) is just horizontal writing,
2901 and the third column (\emph{tate} direction) is vertical writing.
2902 The fourth column (\emph{dtou} direction) is actually a hidden feature of \pTeX.
2903 We implemented this for debugging purpose.
2904 The fifth column (\emph{utod} direction) corresponds the ``\texttt{tate (math) direction}'' of \pTeX.
2905
2906 Directions can be changed by \cs{yoko},~\cs{tate}, \cs{dtou},~\cs{utod},
2907 only when the current list is null. Also, the direction of a math formula is changed to
2908 \emph{utod}, when the direction outside the math formula is \emph{tate} (vertical writing).
2909 %</en>
2910
2911 %<*ja>
2912 \LuaTeX-jaがサポートする組方向は表\ref{tab-dir}に示す4つである.
2913 4列目の \cs{dtou} は聞き慣れない命令だと思うが,
2914 実は\pTeX に同名の命令が(ドキュメントには書かれていないが)存在する.
2915 Down-TO-Upの意味なのだろう.\cs{dtou} を使用する機会はないだろうが,
2916 \LuaTeX-jaではデバッグ用に実装している.
2917 5列目の \cs{utod} は,\pTeX で言う「縦数式ディレクション」に相当するものである.
2918
2919 組方向は,\cs{yoko},~\cs{tate}, \cs{dtou},~\cs{utod} をそれぞれ使用することで,
2920 現在作成中のリストやボックスが空の時にのみ変更可能である.
2921 また,縦組中の数式内のボックスは\pTeX と同じように組方向が \cs{utod} となる.
2922 %</ja>
2923
2924 %<*en>
2925 \subsection{Boxes in different direction}
2926
2927 As in \pTeX, one can use boxes of different direction in one document.
2928 The below is an example.
2929 \begin{LTXexample}
2930 ここは横組%     yoko
2931 \hbox{\tate %   tate
2932   \hbox{縦組}%  tate
2933   の中に
2934   \hbox{\yoko 横組の内容}% yoko
2935   を挿入する
2936 }
2937 また横組に戻る% yoko
2938 \end{LTXexample}
2939
2940 Table~\ref{tab-diffdir} shows how a box is arranged when
2941 the direction  inside the box and that outside the box differ.
2942 %</en>
2943 %<*ja>
2944 \subsection{異方向のボックス}
2945
2946 縦組の中に「42」などの2桁以上の算用数字を横組で組むなど,
2947 異なる組方向を混在させることがしばしば行われる.
2948 組方向の混在も\pTeX と同じようにできる:
2949 \begin{LTXexample}
2950 ここは横組%     yoko
2951 \hbox{\tate %   tate
2952   \hbox{縦組}%  tate
2953   の中に
2954   \hbox{\yoko 横組の内容}% yoko
2955   を挿入する
2956 }
2957 また横組に戻る% yoko
2958 \end{LTXexample}
2959
2960 異なる組方向のボックスを配置した場合にどう組まれるかの仕様も,\pTeX を
2961 踏襲している.表\ref{tab-diffdir}に示す.
2962 %</ja>
2963
2964 \begin{table}[t]
2965 %<ja>\caption{異方向のボックスの配置}
2966 %<en>\caption{Boxes in different direction}
2967 %<en>\medskip
2968 \label{tab-diffdir}
2969  \centering\small\unitlength3mm
2970  \def\TATEeg{%
2971    \hbox{\smash{\begin{picture}(0,0)(-2,0)
2972      \thicklines
2973      \polyline(-2,0)(-2,-7)(5,-7)(5,0)
2974      \put(0,0){\circle*{0.3}}
2975      \put(2.5,-4){\makebox(0,0){\hbox{\tate\bfseries \emph{tate}/\emph{utod}}}}
2976      \put(0,0){\vector(1,0){5}} \put(2.5,-0.2){\makebox(0,0)[t]{$h_{\mathrm{T}}$}}
2977      \put(0,0){\vector(-1,0){2}}\put(-1,-0.2){\makebox(0,0)[t]{$d_{\mathrm{T}}$}}
2978      \put(0,0){\vector(0,-1){7}}\put(0.2,-3.5){\makebox(0,0)[l]{$w_{\mathrm{T}}$}}
2979    \end{picture}}}
2980  }
2981  \def\DTOUeg{%
2982    \hbox{\smash{\begin{picture}(0,0)(-5,0)
2983      \thicklines
2984      \polyline(-5,0)(-5,7)(2,7)(2,0)
2985      \put(0,0){\circle*{0.3}}
2986      \put(-2.5,4){\makebox(0,0){\hbox{\dtou\bfseries \emph{dtou}}}}
2987      \put(0,0){\vector(-1,0){5}} \put(-2.5,0.3){\makebox(0,0)[b]{$h_{\mathrm{D}}$}}
2988      \put(0,0){\vector(1,0){2}}\put(1,0.3){\makebox(0,0)[b]{$d_{\mathrm{D}}$}}
2989      \put(0,0){\vector(0,1){7}}\put(-0.2,3.5){\makebox(0,0)[r]{$w_{\mathrm{D}}$}}
2990    \end{picture}}}
2991  }
2992  \def\YOKOeg{%
2993    \hbox{\smash{\begin{picture}(0,0)
2994      \thicklines
2995      \polyline(0,5)(7,5)(7,-2)(0,-2)
2996      \put(4,2.5){\makebox(0,0){\hbox{\yoko\bfseries \emph{yoko}}}}
2997      \put(0,0){\circle*{0.3}}
2998      \put(0,0){\vector(0,1){5}} \put(0.3,2.5){\makebox(0,0)[l]{$h_{\mathrm{Y}}$}}
2999      \put(0,0){\vector(0,-1){2}}\put(0.3,-1){\makebox(0,0)[l]{$d_{\mathrm{Y}}$}}
3000      \put(0,0){\vector(1,0){7}}\put(3.5,0.2){\makebox(0,0)[b]{$w_{\mathrm{Y}}$}}
3001    \end{picture}}}
3002  }
3003 \begin{tabular}{ccc}
3004 \toprule
3005 %<ja>\emph{横組中に配置}&\emph{縦組中に配置}&%
3006 %<ja>\emph{組方向 \cs{dtou} 中に配置}\\
3007 %<en>\textbf{typeset in \emph{yoko} direction}
3008 %<en>&\textbf{typeset in \emph{tate} or \emph{utod} direction}
3009 %<en>&\textbf{typeset in \emph{dtou} direction}\\
3010 \midrule
3011  \parbox[c]{15\unitlength}{\begin{picture}(15,15)(0,-4)
3012    \put(0,0){\line(1,0){3.8}}
3013    \put(4,7){\TATEeg}
3014    \put(11.2,0){\line(1,0){3.8}}
3015 %
3016    \put(2,7){\line(1,0){1.8}}
3017    \put(3,3.5){\vector(0,1){3.5}\vector(0,-1){3.5}}
3018    \put(2.8,3.5){\makebox(0,0)[r]{$H_{\mathrm{Y}}$}}
3019    \put(3,-2){\vector(0,1){2}}
3020    \put(2.8,-1){\makebox(0,0)[r]{$D_{\mathrm{Y}}$}}
3021 %
3022    \put(4,7.2){\line(0,1){1.8}}
3023    \put(11,7.2){\line(0,1){1.8}}
3024    \put(6,8){\vector(-1,0){2}}
3025    \put(9,8){\vector(1,0){2}}
3026    \put(7.5,8){\makebox(0,0){$W_{\mathrm{Y}}$}}
3027 %
3028  \end{picture}\vspace{-\baselineskip}
3029    \begin{align*}
3030    W_{\mathrm{Y}} &= h_{\mathrm{T}}+d_{\mathrm{T}},\\
3031    H_{\mathrm{Y}} &= w_{\mathrm{T}},\\
3032    D_{\mathrm{Y}} &=0\,\mathrm{pt}
3033    \end{align*}%
3034  }&
3035  \parbox[c]{15\unitlength}{\begin{picture}(15,15)(0,-4)
3036    \put(7.5,-0.2){\line(0,-1){2.8}}
3037    \put(4,2){\YOKOeg}
3038    \put(7.5, 7.2){\line(0,1){3.8}}
3039 %
3040    \put(2,7){\line(1,0){1.8}}
3041    \put(2,0){\line(1,0){1.8}}
3042    \put(3,5){\vector(0,1){2}}
3043    \put(3,2){\vector(0,-1){2}}
3044    \put(3,3.5){\makebox(0,0){$W_{\mathrm{T}}$}}
3045 %
3046    \put(4,7.2){\line(0,1){1.8}}
3047    \put(11,7.2){\line(0,1){1.8}}
3048    \put(8,8){\vector(-1,0){0.5}\vector(1,0){3}}
3049    \put(7,8){\vector(-1,0){3}\vector(1,0){0.5}}
3050    \put(9.25,8.2){\makebox(0,0)[b]{$H_{\mathrm{T}}$}}
3051    \put(5.75,8.2){\makebox(0,0)[b]{$D_{\mathrm{T}}$}}
3052 %
3053  \end{picture}\vspace{-\baselineskip}
3054    \begin{align*}
3055    W_{\mathrm{T}} &= h_{\mathrm{Y}}+d_{\mathrm{Y}},\\
3056    H_{\mathrm{T}} &= w_{\mathrm{Y}}/2,\\
3057    D_{\mathrm{T}} &= w_{\mathrm{Y}}/2
3058    \end{align*}%
3059  }&
3060  \parbox[c]{15\unitlength}{\begin{picture}(15,15)(0,-4)
3061    \put(11,-0.2){\line(0,-1){2.8}}
3062    \put(4,2){\YOKOeg}
3063    \put(11, 7.2){\line(0,1){3.8}}
3064 %
3065    \put(2,7){\line(1,0){1.8}}
3066    \put(2,0){\line(1,0){1.8}}
3067    \put(3,5){\vector(0,1){2}}
3068    \put(3,2){\vector(0,-1){2}}
3069    \put(3,3.5){\makebox(0,0){$W_{\mathrm{D}}$}}
3070 %
3071    \put(4,7.2){\line(0,1){1.8}}
3072    \put(11,7.2){\line(0,1){1.8}}
3073    \put(7.5,8){\vector(-1,0){3.5}\vector(1,0){3.5}}
3074    \put(13,8){\vector(-1,0){2}}
3075    \put(7.5,8.2){\makebox(0,0)[b]{$H_{\mathrm{D}}$}}
3076    \put(12,8.2){\makebox(0,0)[b]{$D_{\mathrm{D}}$}}
3077 %
3078  \end{picture}\vspace{-\baselineskip}
3079    \begin{align*}
3080    W_{\mathrm{D}} &= h_{\mathrm{Y}}+d_{\mathrm{Y}},\\
3081    H_{\mathrm{D}} &= w_{\mathrm{Y}},\\
3082    D_{\mathrm{D}} &= 0\,\mathrm{pt}
3083    \end{align*}%
3084  }%
3085 \\\midrule
3086  \parbox[c]{15\unitlength}{\begin{picture}(15,15)(0,-4)
3087    \put(0,0){\line(1,0){3.8}}
3088    \put(4,0){\DTOUeg}
3089    \put(11.2,0){\line(1,0){3.8}}
3090 %
3091    \put(2,7){\line(1,0){1.8}}
3092    \put(3,3.5){\vector(0,1){3.5}\vector(0,-1){3.5}}
3093    \put(2.8,3.5){\makebox(0,0)[r]{$H_{\mathrm{Y}}$}}
3094    \put(3,-2){\vector(0,1){2}}
3095    \put(2.8,-1){\makebox(0,0)[r]{$D_{\mathrm{Y}}$}}
3096 %
3097    \put(4,7.2){\line(0,1){1.8}}
3098    \put(11,7.2){\line(0,1){1.8}}
3099    \put(6,8){\vector(-1,0){2}}
3100    \put(9,8){\vector(1,0){2}}
3101    \put(7.5,8){\makebox(0,0){$W_{\mathrm{Y}}$}}
3102 %
3103  \end{picture}\vspace{-\baselineskip}
3104    \begin{align*}
3105    W_{\mathrm{Y}} &= h_{\mathrm{D}}+d_{\mathrm{D}},\\
3106    H_{\mathrm{Y}} &= w_{\mathrm{D}},\\
3107    D_{\mathrm{Y}} &= 0\,pt
3108    \end{align*}%
3109  }&
3110  \parbox[c]{15\unitlength}{\begin{picture}(15,15)(0,-4)
3111    \put(9,-0.2){\line(0,-1){2.8}}
3112    \put(4,0){\DTOUeg}
3113    \put(9, 7.2){\line(0,1){3.8}}
3114 %
3115    \put(2,7){\line(1,0){1.8}}
3116    \put(2,0){\line(1,0){1.8}}
3117    \put(3,5){\vector(0,1){2}}
3118    \put(3,2){\vector(0,-1){2}}
3119    \put(3,3.5){\makebox(0,0){$W_{\mathrm{T}}$}}
3120 %
3121    \put(4,7.2){\line(0,1){1.8}}
3122    \put(11,7.2){\line(0,1){1.8}}
3123    \put(6.5,8){\vector(-1,0){2.5}\vector(1,0){2.5}}
3124    \put(10,8){\vector(-1,0){1}\vector(1,0){1}}
3125    \put(10,8.2){\makebox(0,0)[b]{$H_{\mathrm{T}}$}}
3126    \put(6.5,8.2){\makebox(0,0)[b]{$D_{\mathrm{T}}$}}
3127 %
3128  \end{picture}\vspace{-\baselineskip}
3129    \begin{align*}
3130    W_{\mathrm{T}} &= h_{\mathrm{D}}+d_{\mathrm{D}},\\
3131    H_{\mathrm{T}} &= d_{\mathrm{D}},\\
3132    D_{\mathrm{T}} &= h_{\mathrm{D}}
3133    \end{align*}%
3134  }&
3135  \parbox[c]{15\unitlength}{\begin{picture}(15,15)(0,-4)
3136    \put(6,-0.2){\line(0,-1){2.8}}
3137    \put(4,7){\TATEeg}
3138    \put(6, 7.2){\line(0,1){3.8}}
3139 %
3140    \put(2,7){\line(1,0){1.8}}
3141    \put(2,0){\line(1,0){1.8}}
3142    \put(3,5){\vector(0,1){2}}
3143    \put(3,2){\vector(0,-1){2}}
3144    \put(3,3.5){\makebox(0,0){$W_{\mathrm{D}}$}}
3145 %
3146    \put(4,7.2){\line(0,1){1.8}}
3147    \put(11,7.2){\line(0,1){1.8}}
3148    \put(5,8){\vector(-1,0){1}\vector(1,0){1}}
3149    \put(8.5,8){\vector(-1,0){2.5}\vector(1,0){2.5}}
3150    \put(5,8.2){\makebox(0,0)[b]{$H_{\mathrm{D}}$}}
3151    \put(8.5,8.2){\makebox(0,0)[b]{$D_{\mathrm{D}}$}}
3152 %
3153  \end{picture}\vspace{-\baselineskip}
3154    \begin{align*}
3155    W_{\mathrm{D}} &= w_{\mathrm{T}},\\
3156    H_{\mathrm{D}} &= d_{\mathrm{T}},\\
3157    D_{\mathrm{D}} &= h_{\mathrm{T}}
3158    \end{align*}%
3159  }\\
3160 \bottomrule
3161 \end{tabular}
3162 \end{table}
3163
3164
3165
3166 %<*en>
3167 \paragraph{\cs{wd} and direction}
3168 In \pTeX, \cs{wd},~\cs{ht},~\cs{dp} means the dimensions of a box register
3169 \emph{with respact to the current direction}.
3170 This means that the value of \cs{wd0} etc.\ might differ when the current direction is
3171 different, even if \cs{box0} stores the same box.
3172 However, this no longer applies in \LuaTeX-ja.
3173
3174 \begin{LTXexample}
3175 % yoko direction
3176 \setbox0=\hbox to 20pt{foo}
3177 \the\wd0,~\hbox{\tate\vrule\the\wd0}
3178 \wd0=100pt
3179 \the\wd0,~\hbox{\tate \the\wd0}
3180 \end{LTXexample}
3181
3182 To access box dimensions \emph{with respect to current direction},
3183 one have to use the following commands instead of \cs{wd} wtc.
3184 \begin{cslist}
3185
3186  \item[\cs{ltjgetwd}<num>\textrm{, }\cs{ltjgetht}<num>\textrm{, }%
3187   \cs{ltjgetdp}<num>]
3188 These commands return \emph{an internal dimension} of \cs{box<num>} with respect to
3189 the current direction. One can use these in \cs{dimexpr} primitive, as the followings.
3190 \begin{lstlisting}
3191 \dimexpr 2\ltjgetwd42-3pt\relax, \the\ltjgetwd1701
3192 \end{lstlisting}
3193 The following is an example.
3194 \begin{LTXexample}[width=0.3\textwidth]
3195 \parindent0pt
3196 \setbox32767=\hbox{\yoko よこぐみ}
3197 \fboxsep=0mm\fbox{\copy32767}
3198 \vbox{\hsize=20mm
3199 \yoko YOKO \the\ltjgetwd32767, \\
3200   \the\ltjgetht32767, \\ \the\ltjgetdp32767.}
3201 \vbox{\hsize=20mm\raggedleft
3202 \tate TATE \the\ltjgetwd32767, \\
3203   \the\ltjgetht32767, \\ \the\ltjgetdp32767.}
3204 \vbox{\hsize=20mm\raggedleft
3205 \dtou DTOU \the\ltjgetwd32767, \\
3206   \the\ltjgetht32767, \\ \the\ltjgetdp32767.}
3207 \end{LTXexample}
3208
3209  \item[\cs{ltjsetwd}<num>=<dimen>\textrm{, }\cs{ltjsetht}<num>=<dimen>\textrm{, }%
3210   \cs{ltjsetdp}<num>=<dimen>]
3211 These commands set the dimension of \cs{box<num>}. Unlike \cs{ltjgetwd}, one does not need
3212         to group the argument <num>; four calls of \cs{ltjsetwd} below have the same meaning.
3213 \begin{lstlisting}
3214 \ltjsetwd42 20pt,  \ltjsetwd42=20pt,  \ltjsetwd=42 20pt,  \ltjsetwd=42=20pt
3215 \end{lstlisting}
3216
3217 \end{cslist}
3218 %</en>
3219 %<*ja>
3220 \paragraph{\cs{wd} 達と組方向}
3221 ボックスレジスタ \cs{box}<num> にセットされているボックスの幅・高さ・深さの取得や
3222 変更にはそれぞれ \cs{wd},~\cs{ht},~\cs{dp} プリミティブを用いるのであった.
3223 \pTeX ではこれらのプリミティブは,「現在の組方向におけるボックスの寸法」を指すもので,
3224 同じボックスに対しても現在の組方向によって返る値は異なるもであった.
3225
3226 \LuaTeX-jaにおいては状況が異なり,\cs{wd},~\cs{ht},~\cs{dp} が返す値は
3227 現在の組方向には依存しない.下の例のように,横組のボックスが格納されていれば
3228 \cs{wd}等は常に「横組におけるボックスの寸法」を意味する.
3229
3230 \begin{LTXexample}
3231 % yoko direction
3232 \setbox0=\hbox to 20pt{foo}
3233 \the\wd0,~\hbox{\tate\vrule\the\wd0}
3234 \wd0=100pt
3235 \the\wd0,~\hbox{\tate \the\wd0}
3236 \end{LTXexample}
3237
3238 \pTeX のように現在の組方向に応じたボックスの寸法の取得・設定を行うには,
3239 代わりに次の命令を使用する.
3240
3241 \begin{cslist}
3242
3243  \item[\cs{ltjgetwd}<num>\textrm{, }\cs{ltjgetht}<num>\textrm{, }%
3244   \cs{ltjgetdp}<num>]
3245 現在の組方向に応じたボックスの寸法の取得を行う.結果は内部長さであるため,
3246 \begin{lstlisting}
3247 \dimexpr 2\ltjgetwd42-3pt\relax, \the\ltjgetwd1701
3248 \end{lstlisting}
3249 のように \cs{wd}<num> の代わりとして扱うことができる.
3250 使用例は以下の通りである.
3251 \begin{LTXexample}[width=0.3\textwidth]
3252 \parindent0pt
3253 \setbox32767=\hbox{\yoko よこぐみ}
3254 \fboxsep=0mm\fbox{\copy32767}
3255 \vbox{\hsize=20mm
3256 \yoko YOKO \the\ltjgetwd32767, \\
3257   \the\ltjgetht32767, \\ \the\ltjgetdp32767.}
3258 \vbox{\hsize=20mm\raggedleft
3259 \tate TATE \the\ltjgetwd32767, \\
3260   \the\ltjgetht32767, \\ \the\ltjgetdp32767.}
3261 \vbox{\hsize=20mm\raggedleft
3262 \dtou DTOU \the\ltjgetwd32767, \\
3263   \the\ltjgetht32767, \\ \the\ltjgetdp32767.}
3264 \end{LTXexample}
3265
3266  \item[\cs{ltjsetwd}<num>=<dimen>\textrm{, }\cs{ltjsetht}<num>=<dimen>\textrm{, }%
3267   \cs{ltjsetdp}<num>=<dimen>]
3268 現在の組方向に応じたボックスの寸法の設定を行う.\cs{afterassignment} を2回利用して
3269 実装しているので,次の4通りは全て同じ意味である.
3270 \begin{lstlisting}
3271 \ltjsetwd42 20pt,  \ltjsetwd42=20pt,  \ltjsetwd=42 20pt,  \ltjsetwd=42=20pt
3272 \end{lstlisting}
3273
3274 設定値は「横組」「縦組及び \cs{utod} 方向」「\cs{dtou} 方向」
3275 の3種ごとに独立して記録される.参考として,Gitリポジトリ内の
3276               \verb+test/test55-boxdim_diffdir.{tex,pdf}+ を挙げておく.
3277
3278 \end{cslist}
3279 %</ja>
3280
3281 %<*en>
3282 \subsection{Getting current direction}
3283 The \Param{direction} parameter returns the current direction, and
3284 the \Param{boxdir} parameter (with the argumant <num>)
3285 returns the direction of a box register \cs{box}<num>.
3286 The returned value of these parameters are a \emph{string}:
3287 \begin{center}
3288 \small
3289 \begin{tabular}{>{\bfseries}lccccc}
3290 \toprule
3291 Direction&\emph{yoko}&\emph{tate}&\emph{dtou}&\emph{utod}&(empty)\\
3292 \midrule
3293 Returned value&\texttt{4}&\texttt{3}&\texttt{1}&\texttt{11}&\texttt{0}\\
3294 \bottomrule
3295 \end{tabular}
3296 \end{center}
3297 \begin{LTXexample}[width=0.3\textwidth]
3298 \leavevmode\def\DIR{\ltjgetparameter{direction}}
3299 \hbox{\yoko \DIR}, \hbox{\tate\DIR},
3300 \hbox{\dtou\DIR}, \hbox{\utod\DIR},
3301 \hbox{\tate$\hbox{tate math: \DIR}$}
3302
3303 \setbox2=\hbox{\tate}\ltjgetparameter{boxdir}{2}
3304 \end{LTXexample}
3305 %</en>
3306 %<*ja>
3307 \subsection{組方向の取得}
3308 「現在の組方向」や「<num>番のボックスの組方向」は,
3309 \pTeX では \cs{ifydir} や \cs{ifybox}<num> といった条件判断文を使って
3310 判断することができた.
3311 しかし,\LuaTeX-jaはあくまでも\TeX マクロとLuaコードで
3312 記述されており,それでは新たな条件判断命令を作るのは難しい.
3313
3314 \LuaTeX-jaでは,\Param{direction}パラメータで現在の組方向を,
3315 \Param{boxdir}パラメータ(と追加の引数<num>)によって
3316 \cs{box}<num>の組方向をそれぞれ取得できるようにした.
3317 戻り値は文字列である:
3318 \begin{center}
3319 \small
3320 \begin{tabular}{>{\bfseries}lccccc}
3321 \toprule
3322 組方向&\emph{横組}&\emph{tate縦組}&\emph{dtou方向}&\emph{utod方向}&(未割り当て)\\
3323 \midrule
3324 戻り値&\texttt{4}&\texttt{3}&\texttt{1}&\texttt{11}&\texttt{0}\\
3325 \bottomrule
3326 \end{tabular}
3327 \end{center}
3328
3329 \begin{LTXexample}[width=0.3\textwidth]
3330 \leavevmode\def\DIR{\ltjgetparameter{direction}}
3331 \hbox{\yoko\DIR}, \hbox{\tate\DIR},
3332 \hbox{\dtou\DIR}, \hbox{\utod\DIR},
3333 \hbox{\tate$\hbox{tate math: \DIR}$}
3334
3335 \setbox2=\hbox{\tate}\ltjgetparameter{boxdir}{2}
3336 \end{LTXexample}
3337
3338 これらを用いれば,例えば
3339 \pTeX の \cs{ifydir},~\cs{ifybox200} と同等の条件判断を
3340 \begin{lstlisting}
3341 \ifnum\ltjgetparameter{direction}=4
3342 \ifnum\ltjgetparameter{boxdir}{200}=4
3343 \end{lstlisting}
3344 のように行うことができる.
3345 \cs{iftdir} は少々面倒であるが,8で割った余りが3であるか否かを判断すれば良いから
3346 \begin{lstlisting}
3347 \ifnum\numexpr
3348   \ltjgetparameter{direction}-(\ltjgetparameter{direction}/8)*8=3
3349 \end{lstlisting}
3350 とすればよい.
3351 %</ja>
3352
3353 %<*en>
3354 \subsection{Overridden box primitives}
3355 To cope with multiple directions, the following primitives are
3356 overridden by \LuaTeX-ja, using~\verb+\protected\def+.
3357 \begin{cslist}[style=standard]
3358  \item[\cs{unhbox}<num>\textrm{, }\cs{unvbox}<num>\textrm{, }\cs{unhcopy}<num>\textrm{, }\cs{unvcopy}<num>]
3359  \item[\cs{vadjust}\{<material>\}]
3360  \item[\cs{insert}<number>\{<material>\}]
3361  \item[\cs{lastbox}]
3362  \item[\cs{raise}<dimen><box>\textrm{, }\cs{lower}<dimen><box>\textrm{\ etc., }\cs{vcenter}]
3363  \item[\cs{vcenter}]
3364 \end{cslist}
3365 %</en>
3366 %<*ja>
3367 \subsection{プリミティブの再定義}
3368 異なる組方向に対応するために,以下に挙げるプリミティブは
3369 \LuaTeX-jaによる前処理もしくは後処理が行われるように
3370 \ \verb+\protected\def+ により再定義してある.
3371
3372 \begin{cslist}
3373  \item[\cs{unhbox}<num>\textrm{, }\cs{unvbox}<num>\textrm{, }\cs{unhcopy}<num>\textrm{, }\cs{unvcopy}<num>]
3374  ボックスの組方向が現在のリストと異なる場合は事前にエラーメッセージを出力する.
3375  \pTeX と異なり,エラーを無視して無理矢理 \cs{unhbox}, \cs{unvbox} を
3376  続行させることもできるが,その場合の組版結果は保証しない.
3377  \item[\cs{vadjust}\{<material>\}] 一旦プリミティブ本来の挙動を行う.その後,<material>の組方向が
3378  周囲の垂直リストの組方向と一致しない場合にエラーを出力し,
3379  該当の \cs{vadjust} を無効にする.
3380  \item[\cs{insert}<number>\{<material>\}]
3381  一旦プリミティブ本来の挙動を行い,その後<material>内の各ボックス・罫線の直前に組方向を示
3382               すdirection whatsitを挿入する.
3383  \item[\cs{lastbox}] ボックスの「中身」を現在の組方向に合わせるためのノード
3384               (\textit{dir\_box}という)を必要ならば除去し,
3385  正しく「中身」のボックスが返されるように前処理をする.
3386  \item[\cs{raise}<dimen><box>\textrm{, }\cs{lower}<dimen><box>\textrm{\ etc., }\cs{vcenter}]
3387  一方,こちらでは必要に応じて\textit{dir\_box}を作成する前処理を追加している.
3388 \end{cslist}
3389 %</ja>
3390
3391 %<en>\section{Font Metric and Japanese Font}
3392 %<ja>\section{フォントメトリックと和文フォント}
3393 %<en>\subsection{\cs{jfont}}
3394 %<ja>\subsection{\cs{jfont} 命令}
3395 \label{ssec-jfont}
3396
3397 %<*en>
3398 To load a font as a Japanese font (for horizontal direction), you must use the
3399 \cs{jfont} instead of~\cs{font}, while
3400 \cs{jfont} admits the same syntax used in~\cs{font}.
3401 \LuaTeX-ja automatically loads \Pkg{luaotfload} package,
3402 so TrueType/OpenType fonts with features can be used for Japanese fonts:
3403 %</en>
3404 %<*ja>
3405 フォントを(横組用)和文フォントとして読み込むためには,\cs{jfont} を
3406 \ \cs{font} プリミティブの代わりに用いる.
3407 \cs{jfont} の文法は \cs{font} と同じである.
3408 \LuaTeX-jaは\Pkg{luaotfload}パッケージを自動的に読み込むので,
3409 TrueType/OpenTypeフォントにfeatureを指定したものを和文フォントとして用いる
3410 ことができる:
3411 %</ja>
3412 \begin{LTXexample}[width=0.3\textwidth]
3413 \jfont\tradgt={file:KozMinPr6N-Regular.otf:script=latn;%
3414   +trad;-kern;jfm=ujis} at 14pt
3415 \tradgt 当/体/医/区
3416 \end{LTXexample}
3417
3418 %<*en>
3419 Note that the defined control sequence
3420 (\cs{tradgt} in the example above) using \cs{jfont} is not a
3421 \textit{font\_def} token,  but a macro.
3422 Hence the input like \verb+\fontname\tradgt+
3423 causes a error.  We denote control sequences which are defined in
3424 \cs{jfont} by <jfont\_cs>.
3425 %</en>
3426 %<*ja>
3427 なお,\cs{jfont} で定義された制御綴(上の例だと \cs{tradgt})
3428 は\textit{font\_def}トークンではなくマクロである.従って,\verb+\fontname\tradgt+ のような
3429 入力はエラーとなる.以下では \cs{jfont} で定義された
3430 制御綴を<jfont\_cs>で表す.
3431 %</ja>
3432
3433 \paragraph{JFM}
3434 %<*en>
3435 a JFM has measurements of characters and
3436 glues/kerns that are automatically inserted for Japanese
3437 typesetting. The structure of JFM will be described in the next
3438 subsection. At the calling of \cs{jfont}, you must specify
3439 which JFM will be used for this font by the following keys:
3440 %</en>
3441 %<*ja>
3442 JFMは文字と和文組版で自動的に挿入される
3443 グルー/カーンの寸法情報を持っている.JFMの構造は次の節で述べる.
3444 \cs{jfont} 命令の呼び出しの際には,どのJFMを用いるのかを以下のキーで
3445 指定する必要がある:
3446 %</ja>
3447
3448
3449 \begin{table}[t]
3450 %<en>\caption{Differences between horizontal JFMs shipped with \LuaTeX-ja}
3451 %<ja>\caption{\LuaTeX-ja に同梱されている横組用JFMの違い}
3452 %<en>\medskip
3453 \label{tab-difjfm}
3454 \ltjsetparameter{jacharrange={+3}}
3455 \centering\small
3456 \def\r#1#2{%
3457   \hbox{\Large\vrule
3458   \parbox[b]{7\zw}{%
3459     \addjfontfeatures{YokoFeatures={Opacity=0.5, Color=#2, JFM=#1}}\noindent
3460     ◆◆◆◆◆◆◆
3461     ある日モモちゃんがお使いで迷子になって泣きました.
3462   }\vrule}}
3463 \def\s#1#2{%
3464   \Large
3465   \parbox[b]{7\zw}{%
3466     \addjfontfeatures{YokoFeatures={Opacity=0.5, Color=#2, JFM=#1}}\noindent
3467     ちょっと!何
3468   }}
3469 \def\t#1#2#3{\hbox to 0pt{\hss%
3470   \setbox0=\hbox{\addjfontfeatures{YokoFeatures={JFM=#1}}\huge #3}%
3471   \textcolor{#2}{\transparent{0.5}\vrule width 0.4pt height\ht0 depth\dp0}\kern-.2pt\copy0
3472   \textcolor{#2}{\transparent{0.5}\kern-\wd0\vrule width\wd0height .2pt depth .2pt
3473   \kern-\wd0\raise\ht0\hbox{\vrule width\wd0height .2pt depth .2pt}%
3474   \kern-\wd0\lower\dp0\hbox{\vrule width\wd0height .2pt depth .2pt}%
3475   \kern-.2pt\vrule width 0.4pt height\ht0 depth \dp0}\hss}}
3476 {\Large\tabcolsep0pt
3477 \begin{tabular}{m{8\zw}m{8\zw}m{8\zw}}
3478 \leavevmode\hbox to 0pt{\r{ujis}{blue}\hss}\r{jis}{black}&
3479 \leavevmode\hbox to 0pt{\r{jis}{black}\hss}\r{min}{red}&
3480 \leavevmode\hbox to 0pt{\r{ujis}{blue}\hss}\r{min}{red}\\
3481 \leavevmode\hbox to 0pt{\s{ujis}{blue}\hss}\s{jis}{black}&
3482 \leavevmode\hbox to 0pt{\s{jis}{black}\hss}\s{min}{red}&
3483 \leavevmode\hbox to 0pt{\s{ujis}{blue}\hss}\s{min}{red}\\
3484 \leavevmode\qquad\t{ujis}{blue}{漢}\t{jis}{black}{漢}\qquad
3485            \t{ujis}{blue}{っ}\t{jis}{black}{っ}&
3486 \leavevmode\qquad\t{jis}{black}{漢}\t{min}{red}{漢}\qquad
3487            \t{jis}{black}{っ}\t{min}{red}{っ}&
3488 \leavevmode\qquad\t{ujis}{blue}{漢}\t{min}{red}{漢}\qquad
3489            \t{ujis}{blue}{っ}\t{min}{red}{っ}\\
3490 \end{tabular}\par}
3491
3492 (\textcolor{blue}{Blue: \texttt{jfm-ujis.lua}},
3493 \textcolor{black}{Black: \texttt{jfm-jis.lua}},
3494 \textcolor{red}{Red: \texttt{jfm-min.lua}})
3495 \ltjsetparameter{jacharrange={-3}}
3496 \end{table}
3497
3498 \begin{cslist}
3499 \item[jfm=<name>]
3500 %<*en>
3501 Specify the name of (horizontal) JFM.
3502 If specified JFM has not been loaded, \LuaTeX-ja search and load
3503 a file named \texttt{jfm-<name>.lua}.
3504
3505 The following JFMs are shipped with \LuaTeX-ja:
3506 %</en>
3507 %<*ja>
3508 用いる(横組用)JFMの名前を指定する.もし以前に指定されたJFMが読み込まれていなければ,
3509 \texttt{jfm-<name>.lua}を読み込む.以下の横組用JFMが\LuaTeX-jaには同梱されている:
3510 %</ja>
3511 \begin{description}
3512 %<*en>
3513 \item[\tt jfm-ujis.lua] A standard JFM in \LuaTeX-ja. This JFM is
3514   based on \verb+upnmlminr-h.tfm+, a metric for UTF/OTF package that
3515   is used in \upTeX. When you use the \Pkg{luatexja-otf} package, you should use this JFM.
3516 %</en>
3517 %<*ja>
3518 \item[\tt jfm-ujis.lua] \LuaTeX-jaの標準JFMである.このJFMは\upTeX で
3519   用いられるUTF/OTFパッケージ用の和文用TFMである \verb+upnmlminr-h.tfm+ を
3520   元にしている.\Pkg{luatexja-otf}パッケージを使うときはこのJFMを指定するべきである.
3521 %</ja>
3522 %<*en>
3523 \item[\tt jfm-jis.lua] A counterpart for \verb+jis.tfm+, ``JIS font
3524   metric'' which is widely used in \pTeX. A major difference between
3525   \texttt{jfm-ujis.lua} and this \texttt{jfm-jis.lua} is that
3526   most characters under \texttt{jfm-ujis.lua} are square-shaped,
3527   while that under \texttt{jfm-jis.lua} are horizontal
3528   rectangles.
3529 %</en>
3530 %<*ja>
3531 \item[\tt jfm-jis.lua] \pTeX で広く用いられている「JISフォントメトリック」
3532   \verb+jis.tfm+ に相当するJFMである.\texttt{jfm-ujis.lua} とこの
3533   \texttt{jfm-jis.lua} の主な違いは,\texttt{jfm-ujis.lua} ではほとんどの文字が
3534   正方形状であるのに対し,\texttt{jfm-jis.lua} では横長の長方形状であることと,
3535   \texttt{jfm-ujis.lua} では「?」「!」の直後に半角空白が挿入されることである.
3536 %</ja>
3537 %<*en>
3538 \item[\tt jfm-min.lua] A counterpart for \verb+min10.tfm+, which is one
3539   of the default Japanese font metric shipped with \pTeX.
3540 %</en>
3541 %<*ja>
3542 \item[\tt jfm-min.lua] \pTeX に同梱されているデフォルトの和文用TFM
3543 (\verb+min10.tfm+)に相当し,行末で文字が揃うようにするために「っ」など一部の文字幅が変わっ
3544            ている.\verb+min10.tfm+ については\cite{min10}が詳しい.
3545 %</ja>
3546 \end{description}
3547 %<*en>
3548 The difference among these three~JFMs is  shown in Table~\ref{tab-difjfm}.
3549 %</en>
3550 %<*ja>
3551 これら3つのJFMの違いは表\ref{tab-difjfm}に示した.表中の文例の一部には,
3552 \cite{min10}の図3,~4のものを用いた.
3553 %</ja>
3554
3555 \begin{figure}
3556 \begin{LTXexample}[width=0.3\textwidth]
3557 \ltjsetparameter{differentjfm=both}
3558 \jfont\F=file:KozMinPr6N-Regular.otf:jfm=ujis
3559 \jfont\G=file:KozGoPr6N-Medium.otf:jfm=ujis
3560 \jfont\H=file:KozGoPr6N-Medium.otf:jfm=ujis;jfmvar=hoge
3561 \F ){\G 【】}( % halfwidth space
3562    ){\H 『』}( % fullwidth space
3563
3564 ほげ,{\G 「ほげ」}(ほげ)\par
3565 ほげ,{\H 「ほげ」}(ほげ)% pTeX-like
3566
3567 \ltjsetparameter{differentjfm=paverage}
3568 \end{LTXexample}
3569 \caption{Example of \texttt{jfmvar} key}
3570 \label{fig:jfmvar}
3571 \end{figure}
3572
3573 %<*en>
3574 \item[jfmvar=<string>]
3575 Sometimes there is a need that \ldots.
3576 %</en>
3577 %<*ja>
3578 \item[jfmvar=<string>]
3579 標準では,JFMとサイズが同じで,
3580   実フォントだけが異なる2つの和文フォントは「区別されない」.例えば
3581 図\ref{fig:jfmvar}において,最初の「)」と「【」の実フォントは異なるが,
3582 JFMもサイズも同じなので,普通に「)【」と入力した時と同じように半角空きとなる.
3583
3584 しかし,JFMとサイズが同じであっても,\texttt{jfmvar} キーの異なる
3585 2つの和文フォント,例えば図\ref{fig:jfmvar}で言う \cs{F} と \cs{H},
3586 は「区別される」.異なる和文フォントに異なる \texttt{jfmvar} キーを割り当て,
3587 かつ\Param{differentjfm}パラメータを \texttt{both} に設定すれば,
3588 \pTeX と似た状況で組版されることになる.
3589 %</ja>
3590 \end{cslist}
3591
3592 \begin{figure}
3593 \begin{LTXexample}[pos=t]
3594 \newcommand\test{\vrule ダイナミックダイクマ\vrule\\}
3595 \jfont\KMFW = KozMinPr6N-Regular:jfm=prop;-kern at 17pt
3596 \jfont\KMFK = KozMinPr6N-Regular:jfm=prop at 17pt % kern is activated
3597 \jfont\KMPW = KozMinPr6N-Regular:jfm=prop;script=dflt;+pwid;-kern at 17pt
3598 \jfont\KMPK = KozMinPr6N-Regular:jfm=prop;script=dflt;+pwid;+kern at 17pt
3599 \begin{multicols}{2}
3600 \ltjsetparameter{kanjiskip=0pt}
3601 {\KMFW\test \KMFK\test \KMPW\test \KMPK\test}
3602
3603 \ltjsetparameter{kanjiskip=3pt}
3604 {\KMFW\test \KMFK\test \KMPW\test \KMPK\test}
3605 \end{multicols}
3606 \end{LTXexample}
3607 \caption{Kerning information and \Param{kanjiskip}}
3608 \label{fig:kern-jfm}
3609 \end{figure}
3610
3611 %<en>\paragraph{Using kerning information in a font}
3612 %<ja>\paragraph{ペアカーニング情報の使用}
3613 \label{para-kern}
3614 %<*en>
3615 Some fonts have information for inter-glyph spacing.
3616 This version of \LuaTeX-ja treats kerning spaces like an italic correction;
3617 any glue and/or kern from the JFM and a kerning space can coexist.
3618 See Figure~\ref{fig:kern-jfm} for detail.
3619
3620 Note that in \cs{setmainjfont} etc.\ which are provided by \Pkg{luatexja-fontspec}
3621 package, kerning option is set \emph{off} (\texttt{Kerning=Off}) by default,
3622 because of the compatibility with previous versions of \LuaTeX-ja.
3623 %</en>
3624 %<*ja>
3625 いくつかのフォントはグリフ間のスペースについての情報を持っている.
3626 このカーニング情報は以前の\LuaTeX-ja とはあまり相性が良くなかったが,
3627 本バージョンではカーニングによる空白はイタリック補正と同様に扱うことになっている.
3628 つまり,カーニング由来の空白とJFM由来のグルー・カーンは同時に入りうる.
3629 図\ref{fig:kern-jfm}を参照.
3630 \begin{itemize}
3631  \item \emph{\cs{jfont} や,
3632 NFSS2用の命令(\ref{ssec-chgfnt}節,\ref{ssec-nfsspat}節)における指定では
3633 カーニング情報は標準で使用する}ことになっているようである.
3634 言い換えれば,カーニング情報を使用しない設定にするには,面倒でも
3635 \begin{lstlisting}
3636 \jfont\hoge=KozMinPr6N-Regular:jfm=ujis;-kern at 3.5mm
3637 \DeclareFontShape{JY3}{fuga}{m}{n} {<-> s*KozMinPr6N-Regular:jfm=ujis;-kern}{}
3638 \end{lstlisting}
3639 のように,\texttt{-kern} という指定を自分で追加しなければいけない.
3640  \item
3641 一方,\emph{\Pkg{luatexja-fontspec} の提供する \cs{setmainjfont}\
3642 などの命令の標準設定ではカーニング情報は使用しない}(\texttt{Kerning=Off})
3643 ことになっている.これは以前のバージョンの\LuaTeX-jaとの互換性のためである.
3644 \end{itemize}
3645 %</ja>
3646
3647 %<*ja>
3648 \paragraph{\texttt{extend}と\texttt{slant}}
3649 OpenType font featureと見かけ上同じような形式で指定できるものに,
3650 \begin{description}
3651 \item[\texttt{extend=}<extend>] 横方向に<extend>倍拡大する.
3652 \item[\texttt{slant=}<slant>] <slant>に指定された割合だけ傾ける.
3653 \end{description}
3654 の2つがある.
3655 \texttt{extend}や\texttt{slant}を指定した場合は,それに応じたJFMを指定すべきである%
3656 \footnote{\LuaTeX-jaでは,これらに対するJFMを特に提供することはしない予定である.}.
3657 例えば,次の例では無理やり通常のJFMを使っているために,文字間隔やイタリック補正量が
3658 正しくない:
3659 %</ja>
3660 %<*en>
3661 \paragraph{\texttt{extend} and \texttt{slant}}
3662 The following setting can be specified as OpenType font features:
3663 \begin{cslist}[style=standard]
3664 \item[\cs{extend=}<extend>] expand the font horizontally by <extend>.
3665 \item[\cs{slant=}<slant>] slant the font.
3666 \end{cslist}
3667 Note that \LuaTeX-ja doesn't adjust JFMs by these \texttt{extend} and \texttt{slant}
3668 settings; you have to write new JFMs on purpose.
3669 For example, the following example uses the standard JFM \texttt{jfm-ujis.lua}, hence
3670 letter-spacing and the width of italic correction are not correct:
3671 %</en>
3672 \begin{LTXexample}[width=0.3\textwidth]
3673 \jfont\E=KozMinPr6N-Regular:extend=1.5;jfm=ujis;-kern
3674 \E あいうえお
3675
3676 \jfont\S=KozMinPr6N-Regular:slant=1;jfm=ujis;-kern
3677 \S あいう\/ABC
3678 \end{LTXexample}
3679
3680 %<en>\subsection{\cs{tfont}}
3681 %<ja>\subsection{\cs{tfont} 命令}
3682
3683
3684 \begin{table}[t]
3685 %<en>\caption{Differences between vertical JFMs shipped with \LuaTeX-ja}
3686 %<ja>\caption{\LuaTeX-ja に同梱されている縦組用 JFM の違い}
3687 %<en>\medskip
3688 \label{tab-difjfm-tate}
3689 \catcode`\<=12\catcode`\>=12
3690 \ltjsetparameter{jacharrange={+3}}
3691 \small
3692
3693 \def\r#1#2{%
3694   \hbox{\tate\Large\vrule
3695   \parbox{7\zw}{%
3696     \addjfontfeatures{TateFeatures={Opacity=0.5, Color=#2, JFM=#1}}\noindent
3697     ◆◆◆◆◆◆◆
3698     ある日モモちゃんがお使いで迷子になって泣きました.
3699   }\vrule}}
3700 \def\s#1#2{%
3701   \hbox{\tate\Large
3702   \parbox{7\zw}{%
3703     \addjfontfeatures{TateFeatures={Opacity=0.5, Color=#2, JFM=#1}}\noindent
3704     ちょっと!何
3705   }}}
3706 \def\t#1#2#3{\hbox to 0pt{\hss%
3707   \setbox0=\hbox{\addjfontfeatures{TateFeatures={JFM=#1}}\huge #3}%
3708   \textcolor{#2}{\transparent{0.5}\vrule width 0.4pt height\ht0 depth\dp0}\kern-.2pt\copy0
3709   \textcolor{#2}{\transparent{0.5}\kern-\wd0\vrule width\wd0height .2pt depth .2pt
3710   \kern-\wd0\raise\ht0\hbox{\vrule width\wd0height .2pt depth .2pt}%
3711   \kern-\wd0\lower\dp0\hbox{\vrule width\wd0height .2pt depth .2pt}%
3712   \kern-.2pt\vrule width 0.4pt height\ht0 depth \dp0}\hss}}
3713
3714 \begin{minipage}{.7\textwidth}
3715 \centering
3716 \leavevmode\hbox to 0pt{\r{ujisv}{blue}\hss}\r{tmin}{red}\quad
3717 \leavevmode\hbox to 0pt{\s{ujisv}{blue}\hss}\s{tmin}{red}\quad
3718 \raise4\zw\hbox{\tate\Large\t{ujisv}{black}{漢}\t{tmin}{red}{漢}\qquad
3719            \t{ujisv}{black}{っ}\t{tmin}{red}{っ}}
3720 \end{minipage}%
3721 \begin{minipage}{.3\textwidth}
3722 \textcolor{blue}{Blue: \texttt{jfm-ujisv.lua}}\\
3723 \textcolor{red}{Red: \texttt{jfm-tmin.lua}}
3724 \end{minipage}
3725 \ltjsetparameter{jacharrange={-3}}
3726 \end{table}
3727
3728 %<*en>
3729 ...
3730 %</en>
3731 %<*ja>
3732 \cs{tfont} はフォントを縦組用の和文フォントとして読み込む命令であり,
3733 \cs{tfont} の文法は \cs{jfont} と同じである.
3734 \cs{tfont} で定義された縦組用和文フォントは,
3735 以下の点が \cs{jfont} による横組用和文フォントとは異なる:
3736 \begin{itemize}
3737  \item 自動的に \texttt{vert}, \texttt{vrt2} の両OpenType featureが有効化される.
3738 但し,以下の例の3行目に示すように,明示的に \texttt{vert}, \texttt{vrt2}(のいずれか)の
3739 有効・無効を指定した場合は別である.
3740 \begin{lstlisting}
3741 \tfont\S=file:KozMinPr6N-Regular.otf:jfm=ujisv 
3742     % vert and vrt2 are automatically activated
3743 \tfont\T=file:KozMinPr6N-Regular.otf:jfm=ujisv;-vert % vert and vrt2 are not activated
3744 \end{lstlisting}
3745  \item \ref{ssec-math}節で述べる,数式中の和文フォントには縦組用和文フォントは指定できない.
3746  \item \texttt{jfm=<name>}\ の部分には縦組用JFMを指定する.
3747 以下の縦組用JFMが\LuaTeX-jaには同梱されており,違いを表\ref{tab-difjfm-tate}に示した.
3748 \begin{description}
3749 \item[\tt jfm-ujisv.lua] \LuaTeX-jaの標準縦組用JFMである.このJFMは\upTeX で
3750   用いられるUTF/OTFパッケージ用の和文用TFMである \verb+upnmlminr-v.tfm+ を
3751   元にしている.
3752 \item[\tt jfm-tmin.lua] \pTeX に同梱されているデフォルトの和文用縦組TFM
3753   である \verb+tmin10.tfm+ に相当し,\texttt{min10.tfm} と同様に
3754   「っ」など一部の文字幅が狭められている.
3755 \end{description}
3756 \end{itemize}
3757
3758 なお,\pTeX では,\cs{font},~\cs{jfont},~\cs{tfont}のどれでも欧文フォント・横組用和文フォン
3759 ト・縦組用和文フォントの定義が可能であったが,\LuaTeX-jaではそうでないので注意.
3760 %</ja>
3761
3762 %<en>\subsection{Prefix \texttt{psft}}
3763 %<ja>\subsection{\texttt{psft}プリフィックス}
3764 \label{ssec-psft}
3765 %<*en>
3766 Besides ``\texttt{file:}''\ and ``\texttt{name:}''\ prefixes which
3767 are introduced in the \Pkg{luaotfload} package,
3768 \LuaTeX-ja adds ``\texttt{psft:}''\ prefix in \cs{jfont} (and~\cs{font}),
3769 to specify a ``name-only'' Japanese font which
3770 will not be embedded to PDF.
3771 Note that these non-embedded fonts under current \LuaTeX\ has Identity-H encoding,
3772 and this violates the standard ISO32000-1:2008~(\cite{pdfstd}).
3773
3774 \emph{OpenType font features, such as ``{\tt +jp90}'',
3775 have no meaning in name-only fonts using ``{\tt psft:}''\ prefix,
3776 because we can't expect what fonts are actually used by the PDF reader.}
3777 Note that \texttt{extend}~and~\texttt{slant} settings (see~above) are supported
3778 with \texttt{psft} prefix, because they are only simple linear transformations.
3779 %</en>
3780 %<*ja>
3781 \Pkg{luaotfload}で使用可能になった
3782 \texttt{file:}\ と \texttt{name:}\ のプリフィックスに加えて,
3783 \cs{jfont}(と \cs{font} プリミティブ)では
3784 \texttt{psft:}プリフィックスを用いることができる.
3785 このプリフィックスを用いることで,PDFには埋め込まれない「名前だけの」
3786 和文フォントを指定することができる.
3787 なお,現行の\LuaTeX で非埋め込みフォントを作成するとPDF内でのエンコーディングが
3788 Identity-Hとなり,PDFの標準規格ISO32000-1:2008~(\cite{pdfstd})に非準拠になってしまう
3789 ので注意してほしい.
3790
3791 \emph{\texttt{psft} プリフィックスの下では
3792 \texttt{+jp90} などのOpenType font featureの効力はない.
3793 非埋込フォントをPDFに使用すると,実際にどのようなフォントが
3794 表示に用いられるか予測できないからである.}\
3795 \texttt{extend} と \texttt{slant} 指定は単なる変形のため
3796 \texttt{psft} プリフィックスでも使用可能である.
3797 %</ja>
3798
3799 %<en>\paragraph{\texttt{cid} key}
3800 %<ja>\paragraph{\texttt{cid}キー}
3801 \label{para-cid}
3802
3803 %<*en>
3804 The default font defined by using \texttt{psft:} prefix is for Japanese typesetting;
3805 it is Adobe-Japan1-6 CID-keyed font.
3806 One can specify \texttt{cid} key to use other CID-keyed non-embedded fonts
3807 for Chinese or Korean typesetting.
3808 %</en>
3809 %<*ja>
3810 標準で\texttt{psft:}プリフィックスで定義されるフォントは日本語用のもので
3811 あり,Adobe-Japan1-6のCIDに対応したものとなる.しかし,\LuaTeX-jaは中国語
3812 の組版にも威力を発揮することが分かり,日本語フォントでない非埋込フォント
3813 の対応も必要となった.そのために追加されたのが\texttt{cid}キーである.
3814
3815 \texttt{cid}キーに値を指定すると,そのCIDを持った非埋込フォントを定義することができる:
3816 %</ja>
3817 \begin{lstlisting}[numbers=left]
3818 \jfont\testJ={psft:Ryumin-Light:cid=Adobe-Japan1-6;jfm=jis}     % Japanese
3819 \jfont\testD={psft:Ryumin-Light:jfm=jis}                        % default value is Adobe-Japan1-6
3820 \jfont\testC={psft:AdobeMingStd-Light:cid=Adobe-CNS1-6;jfm=jis} % Traditional Chinese
3821 \jfont\testG={psft:SimSun:cid=Adobe-GB1-5;jfm=jis}              % Simplified Chinese
3822 \jfont\testK={psft:Batang:cid=Adobe-Korea1-2;jfm=jis}           % Korean
3823 \end{lstlisting}
3824 %<*en>
3825 Note that the code above specifies \texttt{jfm-jis.lua}, which is for Japanese fonts,
3826 as JFM for Chinese and Korean fonts.
3827 %</en>
3828 %<*ja>
3829 上のコードでは中国語・韓国語用フォントに対してもJFMに
3830 日本語用の\texttt{jfm-jis.lua}を指定しているので注意されたい.
3831 %</ja>
3832
3833 %<*en>
3834 At present, \LuaTeX-ja supports only 4 values written in the sample code above.
3835 Specifying other values, e.g.,
3836 %</en>
3837 %<*ja>
3838 今のところ,\LuaTeX-jaは上のサンプルコード中に書いた4つの値しかサポートしていない.
3839 %</ja>
3840 \begin{lstlisting}
3841 \jfont\test={psft:Ryumin-Light:cid=Adobe-Japan2;jfm=jis}
3842 \end{lstlisting}
3843 %<*en>
3844 produces the following error:
3845 %</en>
3846 %<*ja>
3847 のようにそれら以外の値を指定すると,エラーが発生する:
3848 %</ja>
3849 \begin{lstlisting}[numbers=left]
3850 ! Package luatexja Error: bad cid key `Adobe-Japan2'.
3851
3852 See the luatexja package documentation for explanation.
3853 Type  H <return>  for immediate help.
3854 <to be read again>
3855                    \par
3856 l.78
3857
3858 ? h
3859 I couldn't find any non-embedded font information for the CID
3860 `Adobe-Japan2'. For now, I'll use `Adobe-Japan1-6'.
3861 Please contact the LuaTeX-ja project team.
3862 ?
3863 \end{lstlisting}
3864
3865 %<en>\subsection{Structure of a JFM File}
3866 %<ja>\subsection{JFMファイルの構造}
3867 \label{ssec-jfm-str}
3868 %<en>A JFM file is a Lua script which has only one function call:
3869 %<ja>JFMファイルはただ一つの関数呼び出しを含むLuaスクリプトである:
3870 \begin{lstlisting}
3871 luatexja.jfont.define_jfm { ... }
3872 \end{lstlisting}
3873 %<*en>
3874 Real data are stored in the table which indicated above by
3875 \verb+{ ... }+.  So, the rest of this subsection are devoted to describe the
3876 structure of this table.  Note that all lengths in a JFM file are
3877 floating-point numbers in design-size unit.
3878 %</en>
3879 %<*ja>
3880 実際のデータは上で \verb+{ ... }+ で示されたテーブルの中に格納されている.
3881 以下ではこのテーブルの構造について記す.
3882 なお,JFMファイル中の長さは全てdesign-sizeを単位とする浮動小数点数であることに
3883 注意する.
3884 %</ja>
3885
3886 \begin{cslist}[style=standard]
3887
3888 \item[dir=<direction>]
3889 %<en>(required)
3890 %<ja>(必須)
3891
3892 %<*en>
3893 The direction of JFM. \texttt{'yoko'}~(horizontal)
3894 or \texttt{'tate'}~(vertical) are supported.
3895 %</en>
3896 %<*ja>
3897 JFMの書字方向.\texttt{'yoko'}(横組)と \texttt{'tate'}(縦組)がサポートされる.
3898 %</ja>
3899
3900 \item[zw=<length>]
3901 %<en>(required)
3902 %<ja>(必須)
3903
3904 %<en>The amount of the length of the ``full-width''.
3905 %<*ja>
3906 「全角幅」の長さ.この量が \cs{zw} の長さとなる.\pTeX では
3907 「全角幅」\texttt{1zw} は「文字クラス0の文字」の幅と決められていたが,
3908 \LuaTeX-jaではここで指定する.
3909 %</ja>
3910
3911 \item[zh=<length>]
3912 %<en>(required)
3913 %<ja>(必須)
3914
3915 %<en>The amount of the ``full-height'' (height + depth).
3916 %<*ja>
3917 「全角高さ」(height + depth)の長さ.通常は全角幅と同じ長さになるだろう.
3918 \pTeX では 「全角高さ」\texttt{1zh} は「文字クラス0の文字」の高さと深さの和と決められていたが,
3919 \LuaTeX-jaではここで指定する.
3920 %</ja>
3921
3922 \item[kanjiskip=\{<natural>, <stretch>, <shrink>\}]
3923 %<en>(optional)
3924 %<ja>(任意)
3925
3926 %<*en>
3927 This field specifies the ``ideal'' amount of \Param{kanjiskip}. As noted
3928              in Subsection~\ref{subs-kskip}, if the parameter
3929              \Param{kanjiskip} is \cs{maxdimen}, the value specified
3930              in this field is actually used (if this field is not specified in
3931              JFM, it is regarded as 0\,pt). Note that <stretch> and <shrink>
3932              fields are in design-size unit too.
3933 %</en>
3934 %<*ja>
3935 理想的な\Param{kanjiskip}の量を指定する.\ref{subs-kskip}節で述べたように,
3936 もし\Param{kanjiskip}が \cs{maxdimen} の値ならば,このフィールドで指定された
3937 値が実際には用いられる(指定なしは0\,ptとして扱われる).<stretch>と<shrink>のフィールドもdesign-size
3938 が単位であることに注意せよ.
3939 %</ja>
3940
3941 \item[xkanjiskip=\{<natural>, <stretch>, <shrink>\}]
3942 %<en>(optional)
3943 %<ja>(任意)
3944
3945 %<*en>
3946 Like the \texttt{kanjiskip} field, this field specifies the ``ideal''
3947              amount of \Param{xkanjiskip}.
3948 %</en>
3949 %<*ja>
3950 \texttt{kanjiskip}フィールドと同様に,\Param{xkanjiskip}の理想的な量を
3951 指定する.
3952 %</ja>
3953 \end{cslist}
3954
3955 %<*en>
3956 \paragraph{Character classes}
3957 Besides from above fields, a JFM file have several sub-tables those
3958 indices are natural numbers.  The table indexed by~$i\in\omega$ stores
3959 information of \emph{character class}~$i$. At least, the character class~0 is
3960 always present, so each JFM file must have a sub-table whose index is
3961 \texttt{[0]}.  Each sub-table (its numerical index is denoted by $i$) has
3962 the following fields:
3963 %</en>
3964 %<*ja>
3965 \paragraph{文字クラス}
3966 上記のフィールドに加えて,JFMファイルはそのインデックスが自然数であるいくつかの
3967 サブテーブルを持つ.インデックスが$i\in\omega$であるテーブルは\emph{文字クラス}$i$の
3968 情報を格納する.少なくとも,文字クラス0は常に存在するので,JFMファイルはインデックス
3969 が\texttt{[0]}のサブテーブルを持たなければならない.それぞれのサブテーブル
3970 (そのインデックスを$i$で表わす)は以下のフィールドを持つ:
3971 %</ja>
3972
3973 \begin{cslist}[style=standard]
3974 \item[chars=\{<character>, ...\}]
3975 %<en>(required except character class~0)
3976 %<ja>(文字クラス0を除いて必須)
3977
3978 %<*en>
3979 This field is a list of characters which are in this character
3980              type~$i$. This field is optional if $i=0$, since all
3981              \textbf{JAchar} which do not belong  any character classes other
3982              than 0 are in the character class 0
3983              (hence, the character class~0 contains most of
3984              \textbf{JAchar}s). In the list, character(s) can be specified in the following form:
3985 \begin{itemize}
3986 \item a Unicode code point
3987 \item the character itself (as a Lua string, like \hbox{\ltjsetparameter{autoxspacing=false}\verb+'あ'+})
3988 \item a string like \hbox{\ltjsetparameter{autoxspacing=false}\verb+'あ*'+} (the character followed by an asterisk)
3989 \item several ``imaginary'' characters (We will describe these later.)
3990 \end{itemize}
3991 %</en>
3992 %<*ja>
3993 このフィールドは文字クラス$i$に属する文字のリストである.このフィールドは$i=0$の
3994 場合には任意である(文字クラス0には,0以外の文字クラスに属するものを
3995 除いた全ての\textbf{JAchar}が属するから).このリスト中で文字を指定するには,以下の方法がある:
3996 \begin{itemize}
3997 \item Unicode におけるコード番号
3998 \item 「\hbox{\ltjsetparameter{autoxspacing=false}\verb+'あ'+}」のような,文字それ自体
3999 \item 「\hbox{\ltjsetparameter{autoxspacing=false}\verb+'あ*'+}」のような,文字それ自体の後にアスタリスクをつけたもの
4000 \item いくつかの「仮想的な文字」(後に説明する)
4001 \end{itemize}
4002 %</ja>
4003
4004 \item[width=<length>, height=<length>, depth=<length>, italic=<length>]
4005 %<en>(required)
4006 %<ja>(必須)
4007
4008 %<*en>
4009 Specify the width of characters in character class~$i$, the height, the depth and
4010 the amount of italic correction. All characters in character class~$i$ are regarded that its width, height, and depth are
4011 as values of these fields.
4012
4013 But there is one exception: \texttt{width} field can be \texttt{'prop'}.
4014 This means that width of a character becomes that of its ``real'' glyph.
4015 %</en>
4016 %<*ja>
4017 文字クラス$i$に属する文字の幅,高さ,深さ,イタリック補正の量を指定する.
4018 文字クラス$i$に属する全ての文字は,その幅,高さ,深さがこのフィールドで指定した
4019 値であるものとして扱われる.
4020
4021 例外として,\emph{\texttt{width} フィールドには数値以外に \texttt{'prop'} が指定可能である}.
4022 この場合,文字の幅はその「実際の」グリフの幅となる.OpenTypeの \texttt{prop} featureと併用
4023              すれば,これによってプロポーショナル組を行うことができる.
4024 %</ja>
4025
4026 \item[left=<length>, down=<length>, align=<align>]\
4027
4028 %<*en>
4029 These fields are for adjusting the position of the ``real'' glyph. Legal
4030              values of \texttt{align} field are \texttt{'left'},
4031              \texttt{'middle'}, and \texttt{'right'}. If one of these
4032              3~fields are omitted, \texttt{left} and \texttt{down} are
4033              treated as~0, and \texttt{align} field is treated as
4034              \texttt{'left'}.
4035 The effects of these 3~fields are indicated in
4036 Figures \ref{fig-pos}~and~\ref{fig-pos-tate}.
4037 %</en>
4038 %<*ja>
4039 これらのフィールドは実際のグリフの位置を調整するためにある.
4040 \texttt{align} フィールドに指定できる値は \texttt{'left'}, \texttt{'middle'},
4041 \texttt{'right'} のいずれかである.もしこれら3つのフィールドのうちの1つが省かれた
4042 場合,\texttt{left} と \texttt{down} は0,\texttt{align} フィールドは
4043 \ \texttt{'left'} であるものとして扱われる.
4044 これら3つのフィールドの意味については図\ref{fig-pos}(横組用和文フォント),
4045 図\ref{fig-pos-tate}(縦組用和文フォント)で説明する.
4046 %</ja>
4047
4048 %<*en>
4049 In most cases, \texttt{left} and \texttt{down} fields are~0, while
4050 it is not uncommon that the \texttt{align} field is \texttt{'middle'} or \texttt{'right'}.
4051 For example, setting the \texttt{align} field to \texttt{'right'} is practically needed
4052 when the current character class is the class for opening delimiters'.
4053 %</en>
4054 %<*ja>
4055 多くの場合,\texttt{left}と\texttt{down}は0である一方,
4056 \texttt{align}フィールドが\texttt{'middle'}や\texttt{'right'}であることは
4057 珍しいことではない.
4058 例えば,\texttt{align}フィールドを\texttt{'right'}に指定することは,
4059 文字クラスが開き括弧類であるときに実際必要である.
4060 %</ja>
4061
4062 \begin{figure}[!tb]
4063 \begin{minipage}{0.4\textwidth}%
4064 \begin{center}\unitlength=10pt\small
4065 \begin{picture}(15,12)(-1,-4)
4066 \color{b_gray}% jfm
4067 \put(0,0){\vrule width 12\unitlength height 8\unitlength depth 3\unitlength}
4068
4069 \color{b_pink}% step1
4070 \put(-1,-1.5){\vrule width 6\unitlength height 7\unitlength depth 2.5\unitlength}
4071
4072 \color{red}% real glyph
4073 \thicklines
4074 \put(-1,-1.5){\vector(0,1){7}\vector(0,-1){2.5}\vector(1,0){6}}
4075 \put(5,-1.5){\line(0,1){7}\line(0,-1){2.5}}
4076 \put(-1,5.5){\line(1,0){6}}
4077 \put(-1,-4){\line(1,0){6}}
4078
4079 \color{b_green}% real glyph
4080 \put(3,0){\vrule width 6\unitlength height 7\unitlength depth 2.5\unitlength}
4081
4082 \color{black}% jfm
4083 \thicklines
4084 \put(0,0){\vector(0,1){8}\line(0,-1){3}\vector(1,0){12}}
4085 \put(12,0){\line(0,1){8}\vector(0,-1){3}}
4086 \put(0,8){\line(1,0){12}}
4087 \put(0,-3){\line(1,0){12}}
4088 \put(0.2,4){\makebox(0,0)[l]{\texttt{height}}}
4089 \put(12.2,-1.5){\makebox(0,0)[l]{\texttt{depth}}}
4090 \put(6,0.2){\makebox(0,0)[b]{\texttt{width}}}
4091
4092 \color{green}% step1
4093 \thicklines
4094 \put(3,0){\vector(0,1){7}\vector(0,-1){2.5}\vector(1,0){6}}
4095 \put(9,0){\line(0,1){7}\line(0,-1){2.5}}
4096 \put(3,7){\line(1,0){6}}
4097 \put(3,-2.5){\line(1,0){6}}
4098 \newsavebox{\eqdist}
4099 \savebox{\eqdist}(0,0)[b]{%
4100   \thinlines
4101   \put(-0.08,0.2){\line(0,-1){0.4}}%
4102   \put(0.08,0.2){\line(0,-1){0.4}}}
4103 \put(1.5,0){\usebox{\eqdist}}
4104 \put(10.5,0){\usebox{\eqdist}}
4105
4106 \color{blue}% shifted
4107 \thicklines
4108 \put(3,-1.5){\vector(-1,0){4}}
4109 \put(1,-1.7){\makebox(0,0)[t]{\texttt{left}}}
4110 \put(3,0){\vector(0,-1){1.5}}
4111 \put(3.2,-0.75){\makebox(0,0)[l]{\texttt{down}}}
4112 \end{picture}
4113 \end{center}
4114 \end{minipage}%
4115 \begin{minipage}{0.6\textwidth}%
4116 %<*en>
4117 Consider a  Japanese character node which belongs to
4118 a character class whose the \texttt{align}
4119 field is \texttt{'middle'}.
4120 %</en>
4121 %<*ja>
4122 \texttt{align}フィールドの値が \texttt{'middle'} であるような文字クラスに属する
4123 和文文字ノードを考えよう.
4124 %</ja>
4125 \begin{itemize}
4126 \item
4127 %<*en>
4128 The black rectangle is the imaginary body of the node.
4129 Its width, height, and depth are specified by JFM.
4130 %</en>
4131 %<*ja>
4132 黒色の長方形はノードの枠であり,
4133 その幅,高さ,深さはJFMによって指定されている.
4134 %</ja>
4135 \item
4136 %<*en>
4137 Since the \texttt{align} field is \texttt{'middle'},
4138 the ``real'' glyph is centered horizontally (the green rectangle) first.
4139 %</en>
4140 %<*ja>
4141 \texttt{align}フィールドは \texttt{'middle'} なので,
4142 実際のグリフの位置はまず水平方向に中央揃えしたものとなる(緑色の長方形).
4143 %</ja>
4144 \item
4145 %<*en>
4146 Furthermore, the glyph is shifted according to values of fields
4147       \texttt{left} and \texttt{down}. The ultimate position of the real
4148       glyph is indicated by the red rectangle.
4149 %</en>
4150 %<*ja>
4151 さらに,グリフは \texttt{left} と \texttt{down} の値に従ってシフトされる.
4152 最終的な実際のグリフの位置は赤色の長方形で示された位置になる.
4153 %</ja>
4154 \end{itemize}
4155 \end{minipage}
4156 \medskip
4157
4158 \caption{%
4159 %<en>The position of the real glyph (horizontal Japanese fonts)
4160 %<ja>横組和文フォントにおける「実際の」グリフの位置
4161 }
4162 \label{fig-pos}
4163 \end{figure}
4164 \begin{figure}[!tb]
4165 \begin{minipage}{0.4\textwidth}%
4166 \begin{center}\unitlength=10pt\small
4167 \begin{picture}(15,12)(-6,0)
4168 \color{b_gray}% jfm
4169 \put(-6,0){\vrule width 12\unitlength height 11\unitlength}
4170
4171 \color{b_pink}% real glyph
4172 \put(-6.5,5.5){\vrule width 8\unitlength height 6\unitlength depth 3\unitlength}
4173
4174 \color{red}% real glyph
4175 \thicklines
4176 \put(-6.5,5.5){\vector(0,1){6}\vector(0,-1){3}\vector(1,0){8}}
4177 \put( 1.5,5.5){\line(0,1){6}\line(0,-1){3}}
4178 \put(-6.5,11.5){\line(1,0){8}}
4179 \put(-6.5,2.5){\line(1,0){8}}
4180
4181 \color{b_green}% step1
4182 \put(-4,3){\vrule width 8\unitlength height 6\unitlength depth 3\unitlength}
4183
4184 \color{black}% jfm
4185 \thicklines
4186 \put(0,11){\vector(1,0){6}\vector(-1,0){6}\vector(0,-1){11}}
4187 \put(0,0){\line(1,0){6}\line(-1,0){6}}
4188 \put(-6,0){\line(0,1){11}}
4189 \put( 6,0){\line(0,1){11}}
4190 \put( 3,10.8){\makebox(0,0)[t]{\texttt{height}}}
4191 \put(-3,10.8){\makebox(0,0)[t]{\texttt{depth}}}
4192 \put(0.2,5.5){\makebox(0,0)[l]{\texttt{width}}}
4193
4194 \color{green}% step1
4195 \thicklines
4196 \put(-4,3){\vector(0,1){6}\vector(0,-1){3}\vector(1,0){8}}
4197 \put( 4,3){\line(0,1){6}\line(0,-1){3}}
4198 \put(-4,9){\line(1,0){8}}
4199 \put(-4,0){\line(1,0){8}}
4200 \savebox{\eqdist}(0,0)[b]{%
4201   \thinlines
4202   \put(-0.08,0.2){\line(0,-1){0.4}}%
4203   \put(0.08,0.2){\line(0,-1){0.4}}}
4204 \put(2,9){\usebox{\eqdist}}
4205 \put(-2,9){\usebox{\eqdist}}
4206
4207
4208 \color{blue}% shifted
4209 \thicklines
4210 \put(-4,3){\vector(0,1){2.5}}
4211 \put(-3.8,4.25){\makebox(0,0)[l]{\texttt{left}}}
4212 \put(-4,5.5){\vector(-1,0){2.5}}
4213 \put(-5.,5.7){\makebox(0,0)[b]{\texttt{down}}}
4214 \end{picture}
4215 \end{center}
4216 \end{minipage}%
4217 \begin{minipage}{0.6\textwidth}%
4218 %<*en>
4219 (\dots)
4220 %</en>
4221 %<*ja>
4222 \texttt{align}フィールドの値が \texttt{'right'} であるような文字クラスに属する
4223 和文文字を考えよう.
4224 \begin{itemize}
4225 \item
4226 実際のグリフの「垂直位置」は,まずベースラインが文字の物理的な左右方向の中央を通る
4227 位置となる.
4228 \item
4229 また,この場合 \texttt{align} フィールドは \texttt{'right'} なので,
4230 「水平位置」は字送り方向に「右寄せ」したものとなる(緑色の長方形).
4231 \item
4232 その後さらに \texttt{left} と \texttt{down} の値に従ってシフトされる
4233 のは横組用和文フォントと変わらない.
4234 \end{itemize}
4235 %</ja>
4236 \end{minipage}
4237 \medskip
4238
4239 \caption{%
4240 %<en>The position of the real glyph (vertical Japanese fonts)
4241 %<ja>縦組和文フォントにおける「実際の」グリフの位置
4242 }
4243 \label{fig-pos-tate}
4244 \end{figure}
4245
4246 \item[kern={\{[$j$]=<kern>, [$j'$]=\{<kern>, [<ratio>]\}, ...\}}]
4247
4248 \item[glue={\{[$j$]=\{<width>, <stretch>, <shrink>, [<priority>], [<ratio>]\}, ...\}}]\
4249 %<*ja>
4250
4251 文字クラス$i$の文字と$j$の文字の間に挿入されるkernやglueの量を指定する.
4252
4253              <priority>は \Pkg{luatexja-adjust} による優先順位付き
4254              行長調整(\ref{ssec-adj}節)が有効なときのみ意味を持つ.
4255 このフィールドは省略可能であり,行調整処理におけるこのglueの優先
4256              度を$-2$から$+2$の間の整数で指定する.大きい値ほど「伸びやすく,縮みやすい」
4257              ことを意味する.省略時の値
4258              は0であり,範囲外の値が指定されたときの動作は未定義である.
4259
4260 <ratio>も省略可能フィールドであり,$-1$から$+1$の実数値をとる.省略時の値は0である.
4261 \begin{itemize}
4262 \item $-1$はこのグルーが「前の文字」由来であることを示す.
4263 \item $+1$はこのグルーが「後の文字」由来であることを示す.
4264 \item それ以外の値は,「前の文字」由来のグルーと「後の文字」由来の
4265 グルーが混合されていることを示す.
4266 \end{itemize}
4267 なお,このフィールドの値は\Param{differentjfm}の値が
4268 \texttt{pleft},~\texttt{pright},~\texttt{paverage}の値のときのみ実際に用いられる.
4269
4270 例えば,\cite{x4051}では,句点と中点の間には,
4271 句点由来の二分空きと中点由来の四分空きが挿入されるが,この場合には
4272 \begin{itemize}
4273 \item <width>には$0.5+0.25=0.75$を指定する.
4274 \item <ratio>には次の値を指定する.
4275 \[
4276  -1\cdot \frac{0.5}{0.5+0.25} + 1 \cdot \frac{0.25}{0.5+0.25} = -\frac13
4277 \]
4278 \end{itemize}
4279 %</ja>
4280 %<*en>
4281 \
4282
4283 Specifies the width of kern or glue which will be inserted
4284 between characters in character class~$i$ and those in character class~$j$.
4285
4286 <priority> is an integer in $[-2,2]$ (treated as 0 if omitted), and this is
4287 used only in line adjustment with priority by \Pkg{luatexja-adjust}
4288 (see Subsection~\ref{ssec-adj}). Higher value means the glue is easy to shretch,
4289 and is also easy to shrink.
4290
4291 <ratio> is also an optional value between $-1$ and 1. For example,
4292 The width of a glue between an ideographic full stop ``。''
4293 and a fullwidth middle dot ``・'' is three-fourth of fullwidth,
4294 namely halfwidth from the ideographic full stop, and
4295 quarter-width from the fullwidth middle dot.  In this case,
4296 we specify <ratio> to
4297 \[
4298   -1\cdot \frac{0.5}{0.5+0.25} + 1 \cdot \frac{0.25}{0.5+0.25} = -\frac13.
4299 \]
4300 %</en>
4301
4302
4303 \item[end\_stretch=<kern>, end\_shrink=<kern>]
4304 %<*ja>
4305 (任意)
4306
4307 優先順位付き行長調整が有効であり,かつ現在の文字クラスの文字が行
4308              末に来た時に,行長を詰める調整・伸ばす調整のた
4309              めにこの文字と行末の間に挿入可能なカーンの大きさを指定する.
4310 %</ja>
4311
4312 \end{cslist}
4313
4314 %<*ja>
4315 \paragraph{文字クラスの決定}
4316 文字からその文字の属する文字クラスを算出する過程について,
4317 次の内容を含んだ \texttt{jfm-test.lua} を用いて説明する.
4318 %</ja>
4319 %<*en>
4320 \paragraph{Character to character classes}
4321 We explain how the character class of a character is determined,
4322 using  \texttt{jfm-test.lua} which contains the following:
4323 %</en>
4324 \begin{lstlisting}
4325    [0] = {
4326       chars = { '漢' },
4327       align = 'left', left = 0.0, down = 0.0,
4328       width = 1.0, height = 0.88, depth = 0.12, italic=0.0,
4329    },
4330    [2000] = {
4331       chars = { '。', 'ヒ' },
4332       align = 'left', left = 0.0, down = 0.0,
4333       width = 0.5, height = 0.88, depth = 0.12, italic=0.0,
4334    },
4335 \end{lstlisting}
4336 %<ja>ここで,次のような入力とその実行結果を考える:
4337 %<en>Now consider the following input/output:
4338 \begin{LTXexample}[width=0.3\textwidth]
4339 \jfont\a=file:KozMinPr6N-Regular.otf:jfm=test;+hwid
4340 \setbox0\hbox{\a ヒ漢}
4341 \the\wd0
4342 \end{LTXexample}
4343 %<*en>
4344 Now we look why the above source outputs 15\,pt.
4345 \begin{enumerate}
4346 \item The character ``ヒ'' is converted to its half width  form ``ヒ'' by \verb+hwid+ feature.
4347 \item According to the JFM, the character class of ``ヒ'' is 2000, hence its width is halfwidth.
4348 \item The character class of ``漢'' is zero,  hence its width is fullwidth.
4349 \item Hence the width of \cs{hbox} equals to 15\,pt.
4350 \end{enumerate}
4351 This example shows that the character class of a character is generally determined \emph{after
4352 applying font features by \Pkg{luaotfload}}.
4353 %</en>
4354 %<*ja>
4355 上記の出力結果が,15\,ptとなっているのは理由によるものである:
4356 \begin{enumerate}
4357 \item \verb+hwid+ featureによって「ヒ」が半角幅のグリフ「ヒ」と置き換わる(\Pkg{luaotfload} による処理).
4358 \item JFMによれば,この「ヒ」のグリフの文字クラスは2000である.
4359 \item 以上により文字クラス2000とみなされるため,結果として「ヒ」の幅は半角だと認識される.
4360 \end{enumerate}
4361 この例は,\emph{文字クラスの決定はfont featureの適用によるグリフ置換の結果に基づく}ことを
4362 示している.
4363 %</ja>
4364
4365 %<*en>
4366 However, if the class determined by the glyph after application of features is zero,
4367 \LuaTeX-ja adopts the class determined by the glyph \emph{before} application of features.
4368 The following input is an example.
4369 %</en>
4370 %<*ja>
4371 但し,JFMによって決まる置換後のグリフの文字クラスが0である場合は,置換前の文字クラスを採用する.
4372 %</ja>
4373 \begin{LTXexample}[width=0.3\textwidth]
4374 \jfont\a=file:KozMinPr6N-Regular.otf:jfm=test;+vert
4375 \a 漢。\inhibitglue 漢
4376 \end{LTXexample}
4377 %<*en>
4378 Here, the character class of the ideographic full stop ``。''~(\texttt{U+3002}) is determined
4379 as follows:
4380 \begin{enumerate}
4381 \item As the case of ``ヒ'', the ideographic full stop ``。'' is converted to its vertical
4382       form ``\char"FE12''~(\texttt{U+FE12}) by \verb+vert+ feature.%"
4383 \item The character class of ``\char"FE12'', according to the JFM  is \emph{zero}.
4384 \item However, \LuaTeX-ja remembers that this ``\char"FE12'' is obtained from ``。'' by
4385       font features. The character class of ``。'' is \emph{non-zero value}, namely, 2000.
4386 \item Hence the ideographic full stop ``。'' in above belongs the character class~2000.
4387 \end{enumerate}
4388 %</en>
4389 %<*ja>
4390 ここで,句点「。」(\texttt{U+3002})の文字クラスは,以下のようにして決まる.
4391 \begin{enumerate}
4392 \item \Pkg{luaotfload} によって縦組用句点のグリフに置き換わる.
4393 \item 置換後のグリフは \texttt{U+FE12} であり,JFMに従えば文字クラスは\emph{0}と判定される.
4394 \item この場合,置換前の横組用句点のグリフによって文字クラスを判定する.
4395 \item 結果として,上の出力例中の句点の文字クラスは2000となる.
4396 \end{enumerate}
4397 %</ja>
4398
4399
4400 %<ja>\paragraph{仮想的な文字}
4401 %<en>\paragraph{Imaginary characters}
4402 %<*en>
4403 As described before, you can specify several \emph{imaginary characters} in
4404 \texttt{chars} field. The most of these characters are regarded as the
4405 characters of class 0 in \pTeX.
4406 As a result, \LuaTeX-ja can control typesetting finer than \pTeX.
4407 The following is the list of imaginary characters:
4408 %</en>
4409 %<*ja>
4410 上で説明した通り,\texttt{chars}フィールド中にはいくつかの「特殊文字」も
4411 指定可能である.これらは,大半が\pTeX のJFMグルーの挿入処理ではみな「文字
4412 クラス0の文字」として扱われていた文字であり,その結果として\pTeX より細か
4413 い組版調整ができるようになっている.以下でその一覧を述べる:
4414 %</ja>
4415
4416 \begin{cslist}
4417 %%\item['diffmet']
4418 %%<en>Used at a boundary between two \textbf{JAchar}s whose JFM or size is different.
4419 %%<ja>JFMやサイズが異なる2つの\textbf{JAchar}の間の境界として用いられる.
4420
4421 \item['boxbdd']
4422 %<en>The beginning/ending of a hbox, and the beginning of a noindented (i.e., began by \cs{noindent}) paragraph.
4423 %<ja>hboxの先頭と末尾,及びインデントされていない(\cs{noindent} で開始された)段落の先頭を表す.
4424
4425 \item['parbdd']
4426 %<en>The beginning of an (indented) paragraph.
4427 %<ja>通常の(\cs{noindent} で開始されていない)段落の先頭.
4428
4429 \item['jcharbdd']
4430 %<en>A boundary between \textbf{JAchar} and anything else (such as \textbf{ALchar}, kern, glue,\,\ldots).
4431 %<ja>和文文字と「その他のもの」(欧文文字,glue,kern等)との境界.
4432
4433 \item[$-1$]
4434 %<en>The left/right boundary of an inline math formula.
4435 %<ja>行中数式と地の文との境界.
4436 \end{cslist}
4437
4438 %<en>\paragraph{Porting JFM from \pTeX}
4439 %<ja>\paragraph{\pTeX 用和文用TFMの移植}
4440
4441 % ToDo: English version.
4442
4443 %<*en>
4444 See Japanese version of this manual.
4445 %</en>
4446
4447 %<*ja>
4448 以下に,\pTeX 用に作られた和文用TFMを\LuaTeX-ja用に移植する場合の注意点を挙げておく.
4449 \begin{itemize}
4450 \item 実際に出力される和文フォントのサイズがdesign sizeとなる.
4451 このため,例えば$1\,\textrm{zw}$がdesign sizeの0.962216倍であるJISフォン
4452       トメトリック等を移植する場合は,次のようにするべきである:
4453 \begin{itemize}
4454 \item JFM中の全ての数値を$1/0.962216$倍しておく.
4455 \item \TeX ソース中で使用するところで,サイズ指定を0.962216倍にする.
4456       \LaTeX でのフォント宣言なら,例えば次のように:
4457 \begin{lstlisting}
4458 \DeclareFontShape{JY3}{mc}{m}{n}{<-> s*[0.962216] psft:Ryumin-Light:jfm=jis}{}
4459 \end{lstlisting}
4460 \end{itemize}
4461 \item 上に述べた特殊文字は,\texttt{'boxbdd'}を除き文字クラスを全部0とする
4462       (JFM中に単に書かなければよい).
4463 \item \texttt{'boxbdd'}については,それのみで一つの文字クラスを形成し,その
4464       文字クラスに関してはグルー/カーンの設定はしない.
4465
4466 これは,\pTeX では,
4467       hboxの先頭・末尾とインデントされていない(\cs{noindent} で開始さ
4468       れた)段落の先頭にはJFMグルーは入らないという仕様を実現させるためである.
4469 \item \pTeX の組版を再現させようというのが目的であれば以上の注意を守れば十分である.
4470
4471 ところで,\pTeX では通常の段落の先頭にJFMグルーが残るという仕様があるので,
4472       段落先頭の開き括弧は全角二分下がりになる.全角下がりを実現させるに
4473       は,段落の最初に手動で \cs{inhibitglue} を追加するか,あるいは
4474       \ \cs{everypar} のハックを行い,それを自動化させるしかなかった.
4475
4476 一方,\LuaTeX-jaでは,\texttt{'parbdd'}によって,それがJFM側で調整できるよ
4477 うになった.例えば,\LuaTeX-ja同梱のJFMのように,\texttt{'boxbdd'}と同じ文字クラスに
4478 \texttt{'parbdd'}を入れれば全角下がりとなる.
4479
4480 \begin{LTXexample}[width=0.4\textwidth]
4481 \jfont\g=KozMinPr6N-Regular:jfm=test \g
4482 \parindent1\zw\noindent{}◆◆◆◆◆
4483 \par 「◆◆←二分下がり
4484 \par 【◆◆←全角下がり
4485 \par 〔◆◆←全角二分下がり
4486 \end{LTXexample}
4487 \end{itemize}
4488
4489 但し,\cs{everypar} を利用している場合にはこの仕組みは正しく動かない.
4490 そのような例としては箇条書き中の \cs{item} で始まる段落があり,\Pkg{ltjsclasses}では
4491 人工的に「\texttt{'parbdd'}の意味を持つ」whatsitノードを作ることによって対処している%
4492 \footnote{\texttt{ltjsclasses.dtx} を参照されたい.
4493 JFM側で一部の対処ができることにより,\Pkg{jsclasses}のようにif文の判定はしていない.}.
4494 %</ja>
4495
4496
4497 %<en>\subsection{Math Font Family}
4498 %<ja>\subsection{数式フォントファミリ}
4499 \label{ssec-math}
4500
4501 %<*en>
4502 \TeX\ handles fonts in math formulas by 16~font families\footnote{Omega,
4503 Aleph, \LuaTeX~and $\varepsilon$-\kern-.125em(u)\pTeX\ can handles 256~families, but
4504 an external package is needed to support this in plain \TeX\ and
4505 \LaTeX.}, and each family has three fonts:
4506 \cs{textfont}, \cs{scriptfont} and \cs{scriptscriptfont}.
4507 %</en>
4508 %<*ja>
4509 \TeX\ は数式フォントを16のファミリ\footnote{Omega, Aleph, \LuaTeX,そして
4510   $\varepsilon$-\kern-.125em(u)\pTeX\ では256の数式ファミリを扱うことができるが,
4511   これをサポートするためにplain \TeX と\LaTeX では外部パッケージを読み込む必要が
4512   ある.}で管理し,それぞれのファミリは3つのフォントを持っている:
4513 \cs{textfont}, \cs{scriptfont} そして \cs{scriptscriptfont} である.
4514 %</ja>
4515
4516 %<*en>
4517 \LuaTeX-ja's handling of Japanese fonts in math formulas is similar;
4518 Table~\ref{tab-math} shows counterparts to \TeX's primitives for math
4519 font families. There is no relation between the value of
4520 \cs{fam} and that of \cs{jfam}; with appropriate settings,
4521 you can set both \cs{fam} and \cs{jfam} to the same value.
4522 Here <jfont\_cs> in the argument of \Param{jatextfont} etc.\ is
4523 a control sequence which is defined by \cs{jfont}, i.e.,
4524 a \emph{horizontal} Japanese font.
4525 %</en>
4526 %<*ja>
4527 \LuaTeX-jaの数式中での和文フォントの扱いも同様である.
4528 表\ref{tab-math}は数式フォントファミリに対する \TeX のプリミティブと対応する
4529 ものを示している.\cs{fam} と \cs{jfam} の値の間には関係はなく,
4530 適切な設定の下では \cs{fam} と \cs{jfam} の両方に同じ値を設定することができる.
4531 \Param{jatextfont} 他の第2引数<jfont\_cs>は,\cs{jfont} で定義された
4532 \emph{横組用}和文フォントである.\cs{tfont} で定義された
4533 \emph{縦組用}和文フォントを指定することは想定していない.
4534 %</ja>
4535
4536 \begin{table}[!tb]
4537 %<en>\caption{Commands for Japanese math fonts}
4538 %<ja>\caption{和文数式フォントに対する命令}
4539 \label{tab-math}
4540 %<en>\medskip
4541 \centering
4542 \def\{{\char`\{}\def\}{\char`\}}\small
4543 \begin{tabular}{ll}
4544 \toprule
4545 %<en>\bf Japanese fonts&\bf alphabetic fonts\\
4546 %<ja>\bf 和文フォント&\bf 欧文フォント\\
4547 \midrule
4548 \cs{jfam}${}\in [0,256)$&\cs{fam}\\
4549 \tt\Param{jatextfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\cs{textfont}<fam>=<font\_cs>\\
4550 \tt\Param{jascriptfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\cs{scriptfont}<fam>=<font\_cs>\\
4551 \tt\Param{jascriptscriptfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\cs{scriptscriptfont}<fam>=<font\_cs>\\
4552 \bottomrule
4553 \end{tabular}
4554 \end{table}
4555
4556 %<en>\subsection{Callbacks}
4557 %<ja>\subsection{コールバック}
4558
4559 %<*en>
4560 \LuaTeX-ja also has several callbacks. These callbacks can
4561 be accessed via \verb+luatexbase.add_to_callback+ function and so on, as other callbacks.
4562 %</en>
4563 %<*ja>
4564 \LuaTeX 自体のものに加えて,\LuaTeX-jaもコールバックを持っている.
4565 これらのコールバックには,他のコールバックと同様に \verb+luatexbase.add_to_callback+
4566 関数などを用いることでアクセスすることができる.
4567 %</ja>
4568 \begin{description}[font=\bfseries, style=nextline]
4569 %<en>\item[\texttt{luatexja.load\_jfm} callback]
4570 %<ja>\item[\texttt{luatexja.load\_jfm}コールバック]
4571 %<*en>
4572 With this callback you can overwrite JFMs.
4573 This callback is called when a new JFM is loaded.
4574 %</en>
4575 %<*ja>
4576 このコールバックを用いることでJFMを上書きすることができる.
4577 このコールバックは新しいJFMが読み込まれるときに呼び出される.
4578 %</ja>
4579
4580 \begin{lstlisting}[numbers=left]
4581 function (<table> jfm_info, <string> jfm_name)
4582   return <table> new_jfm_info
4583 end
4584 \end{lstlisting}
4585
4586 %<*en>
4587 The argument \verb+jfm_info+ contains a table similar to the table in a JFM file, except
4588 this argument has \texttt{chars} field which contains character codes
4589              whose character class is not~0.
4590 %</en>
4591 %<*ja>
4592 引数 \verb+jfm_info+ はJFMファイルのテーブルと似たものが格納されるが,
4593 クラス0を除いた文字のコードを含んだ\texttt{chars}フィールドを持つ点が異なる.
4594 %</ja>
4595
4596 %<*en>
4597 An example of this callback is the \texttt{ltjarticle} class, with
4598              forcefully assigning character class~0 to \texttt{'parbdd'}
4599              in the JFM \texttt{jfm-min.lua}.
4600 %</en>
4601 %<*ja>
4602 このコールバックの使用例は\texttt{ltjarticle}クラスにあり,
4603 \texttt{jfm-min.lua}中の\texttt{'parbdd'}を強制的にクラス0に割り当てている.
4604 %</ja>
4605
4606 %<en>\item[\texttt{luatexja.define\_jfont} callback]
4607 %<ja>\item[\texttt{luatexja.define\_jfont}コールバック]
4608 %<*en>
4609 This callback and the next callback form a pair, and you can assign characters
4610  which do not have fixed code points in Unicode to non-zero character classes.
4611 This \texttt{luatexja.define\_font} callback is called just when new Japanese font is loaded.
4612 %</en>
4613 %<*ja>
4614 このコールバックと次のコールバックは組をなしており,Unicode中に固定された文字コード
4615 番号を持たない文字を非零の文字クラスに割り当てることができる.
4616 このコールバックは新しい和文フォントが読み込まれたときに呼び出される.
4617 %</ja>
4618
4619 \begin{lstlisting}[numbers=left]
4620 function (<table> jfont_info, <number> font_number)
4621   return <table> new_jfont_info
4622 end
4623 \end{lstlisting}
4624 %<*en>
4625 \verb+jfont_info+ has the following fields,
4626 \emph{which may not overwritten by a user}:
4627 \begin{description}
4628 \item[\texttt{size}]
4629 The font size specified at \cs{jfont} in scaled points ($1\,\mathrm{sp}=2^{-16}\,\mathrm{pt}$).
4630 \item[\texttt{zw}, \texttt{zh}, \texttt{kanjiskip}, \texttt{xkanjiskip}]
4631 These are scaled value of those specified by the JFM, by the font size.
4632 \item[\texttt{jfm}]
4633 The internal number of the JFM.
4634 \item[\texttt{var}]
4635 The value of \texttt{jfmvar}~key, which is specified at \cs{jfont}.
4636 The default value is the empty string.
4637 \item[\texttt{chars}]
4638 The mapping table from character codes to its character classes.\\
4639 The specification \texttt{[i].chars=\{<character>, ...\}} in the JFM will be  stored in this
4640            field as \texttt{chars=\{[<character>]=\,$i$, ...\}}.
4641 \item[\texttt{char\_type}]
4642 For $i\in\omega$, \texttt{char\_type[$i$]} is information of characters whose class is
4643            $i$, and has the following fields:
4644 \begin{itemize}
4645  \item \texttt{width},~\texttt{height}, \texttt{depth},
4646   \texttt{italic}, \texttt{down},~\texttt{left}\ are just
4647        scaled value of those specified by the JFM, by the font size.
4648  \item \texttt{align} is a number which is determined from \texttt{align}~field in the JFM:
4649 \[
4650  \begin{cases}
4651   0&\text{\texttt{'left'} and the default value}\\0.5&\text{\tt 'middle'}\\1&\text{\tt 'right'}
4652  \end{cases}
4653 \]
4654 \item For $j\in \omega$, \texttt{[$j$]} stores a kern or a glue which will be inserted
4655 between character class~$i$ and class~$j$.
4656
4657 If a kern will be inserted, the value of this field is \texttt{[$j$]=\{false, <kern\_node>, <ratio>\}},
4658 where <kern\_node> is a node\footnote{%
4659  This version of \LuaTeX-ja uses ``direct access
4660       model'' for accessing nodes, if possible. }.
4661 If a glue will be inserted, we have \texttt{[$j$]=\{false, <spec\_node>, <ratio>, <icflag>\}},
4662 where <spec\_node> is also a node, and $\text{<icflag>}=\textit{from\_jfm}+\text{<priority>}$.
4663 \end{itemize}
4664 \end{description}
4665 %</en>
4666 %<*ja>
4667 \verb+jfont_info+ は最低限以下のフィールドを持つが,これらを書き換えてはならない:
4668 \begin{cslist}
4669 \item[size]
4670 実際に使われるフォントサイズ(sp単位).$1\,\mathrm{sp}=2^{-16}\,\mathrm{pt}$.
4671 \item[zw\textrm{, }zh\textrm{, }kanjiskip\textrm{, }xkanjiskip]
4672 JFMファイルで指定されているそれぞれの値をフォントサイズに合わせてスケーリングしたものを
4673 sp単位で格納している.
4674 \item[jfm]
4675 利用されているJFMを識別するための番号.
4676 \item[var]
4677 \cs{jfont},~\cs{tfont} で指定された \texttt{jfmvar} キーの値(未指定のときは空文字列).
4678 \item[chars]
4679 文字コードから文字クラスへの対応が記述されたテーブル.\\
4680 JFM内の \texttt{[i].chars=\{<character>, ...\}} という指定は\
4681 \texttt{chars=\{[<character>]=\,$i$, ...\}} という形式に変換されている.
4682 \item[char\_type]
4683 $i\in\omega$に対して,\texttt{char\_type[$i$]} は文字クラス$i$の文字の寸法を格納しており,
4684 以下のフィールドを持つ.
4685 \begin{itemize}
4686  \item \texttt{width},~\texttt{height}, \texttt{depth},
4687   \texttt{italic}, \texttt{down},~\texttt{left}\ は
4688 JFMで指定されているそれぞれの値をスケーリングしたものである.
4689  \item \texttt{align} はJFMで指定されている値によって,
4690 \[
4691  \begin{cases}
4692   0&\text{\texttt{'left'}や省略時}\\0.5&\text{\tt 'middle'}\\1&\text{\tt 'right'}
4693  \end{cases}
4694 \]
4695 のいずれかの値をとる.
4696 \item $j\in \omega$に対して,\texttt{[$j$]} は文字クラス$i$の文字と$j$の文字の間に挿入されるkern
4697       やglueを格納している.
4698 間に入るものがkernであれば,このフィールドの値は\
4699 \texttt{[$j$]=\{false, <kern\_node>, <ratio>\}} である.
4700 <kern\_node>はkernを表すノードそのものである\footnote{%
4701 本バージョンではノードのアクセス手法にdirect access
4702       modelを用いている.そのため,例えば\LuaTeX\ beta-0.78.2では,単なる自然数のようにし
4703       か見えないことに注意.
4704 }.
4705 glueであれば,\texttt{[$j$]=\{false, <spec\_node>, <ratio>, <icflag>\}} である.
4706 <spec\_node>はglueの長さを表すノードそのものであり,
4707       $\text{<icflag>}=\textit{from\_jfm}+\text{<priority>}$である.
4708 \end{itemize}
4709 \item[ascent\textrm{, }descent]
4710 ……
4711 \item[chars\_cbcache] 
4712 ……
4713 \end{cslist}
4714 %</ja>
4715
4716 %<*en>
4717 The returned table \verb+new_jfont_info+ also should include these fields, but
4718 you are free to add more fields (to use them in the \texttt{luatexja.find\_char\_class} callback).
4719 The \verb+font_number+ is a font number.
4720 %</en>
4721 %<*ja>
4722 戻り値の \verb+new_jfont_info+ テーブルも上に述べたフィールドをそのまま含まなければならないが,
4723 それ以外にユーザが勝手にフィールドを付け加えることは自由である.
4724 \verb+font_number+ はフォント番号である.
4725 %</ja>
4726
4727 %<*en>
4728 A good example of this and the next callbacks is the \Pkg{luatexja-otf}
4729              package, supporting \verb+"AJ1-xxx"+ form for Adobe-Japan1
4730              CID characters in a JFM. This callback doesn't replace any
4731              code of \LuaTeX-ja.
4732 %</en>
4733 %<*ja>
4734 これと次のコールバックの良い使用例は\Pkg{luatexja-otf}パッケージであり,
4735 JFM中でAdobe-Japan1 CIDの文字を \verb+"AJ1-xxx"+ の形で指定するために
4736 用いられている.
4737 %</ja>
4738
4739 %<en>\item[\texttt{luatexja.find\_char\_class} callback]
4740 %<ja>\item[\texttt{luatexja.find\_char\_class}コールバック]
4741 %<*en>
4742 This callback is called just when \LuaTeX-ja is trying to determine which
4743              character class a character \verb+chr_code+ belongs.
4744 A function used in this callback should be in the following form:
4745 %</en>
4746 %<*ja>
4747 このコールバックは\LuaTeX-jaが \verb+chr_code+ の文字がどの文字クラスに
4748 属するかを決定しようとする際に呼び出される.
4749 このコールバックで呼び出される関数は次の形をしていなければならない:
4750 %</ja>
4751 \begin{lstlisting}[numbers=left]
4752 function (<number> char_class, <table> jfont_info, <number> chr_code)
4753   if char_class~=0 then return char_class
4754   else
4755     ....
4756     return (<number> new_char_class or 0)
4757   end
4758 end
4759 \end{lstlisting}
4760
4761 %<*en>
4762 The argument \verb+char_class+ is the result of \LuaTeX-ja's default
4763              routine or previous function calls in this callback, hence
4764              this argument may not be 0. Moreover, the returned
4765              \verb+new_char_class+ should be as same as \verb+char_class+ when \verb+char_class+
4766              is not~0, otherwise you will overwrite the \LuaTeX-ja's
4767              default routine.
4768 %</en>
4769 %<*ja>
4770 引数 \verb+char_class+ は\LuaTeX-jaのデフォルトルーチンか,このコールバックの
4771 直前の関数呼び出しの結果を含んでおり,したがってこの値は0ではないかもしれない.
4772 さらに,戻り値の \verb+new_char_class+ は \verb+char_class+ が非零のときには
4773 \verb+char_class+ の値と同じであるべきで,そうでないときは\LuaTeX-jaの
4774 デフォルトルーチンを書き換えることになる.
4775 %</ja>
4776
4777 %<en>\item[\texttt{luatexja.set\_width} callback]
4778 %<ja>\item[\texttt{luatexja.set\_width}コールバック]
4779 %<*en>
4780 This callback is called when \LuaTeX-ja is trying to encapsule a
4781              \textbf{JAchar} \textit{glyph\_node}, to adjust its
4782              dimension and position.
4783 %</en>
4784 %<*ja>
4785 このコールバックは\LuaTeX-jaが\textbf{JAchar}の寸法と位置を調節するために
4786 その\textit{glyph\_node}をカプセル化しようとする際に呼び出される.
4787 %</ja>
4788 \begin{lstlisting}[numbers=left]
4789 function (<table> shift_info, <table> jfont_info, <number> char_class)
4790   return <table> new_shift_info
4791 end
4792 \end{lstlisting}
4793
4794 %<*en>
4795 The argument \verb+shift_info+ and the returned \verb+new_shift_info+ have
4796 \texttt{down} and \texttt{left} fields, which are the amount of shifting
4797              down/left the character in a scaled point.
4798 %</en>
4799 %<*ja>
4800 引数 \verb+shift_info+ と戻り値の \verb+new_shift_info+ は
4801 \texttt{down}と\texttt{left}のフィールドを持ち,これらの値は
4802 文字の下/左へのシフト量(sp単位)である.
4803 %</ja>
4804
4805 %<*en>
4806 A good example is \Pkg{test/valign.lua}.
4807 After loading this file, the vertical position of glyphs is automatically
4808 adjusted; the ratio $(\hbox{height}:\hbox{depth})$ of glyphs is adjusted
4809 to be that of letters in the character class~0. For example, suppose that
4810 \begin{itemize}
4811 \item The setting of the JFM: $(\hbox{height})=88x$, $(\hbox{depth})=12x$
4812   (the standard values of Japanese OpenType fonts);
4813 \item The value of the real font: $(\hbox{height})=28y$, $(\hbox{depth})=5y$
4814   (the standard values of Japanese TrueType fonts).
4815 \end{itemize}
4816 Then, the position of glyphs is shifted up by
4817 %</en>
4818 %<*ja>
4819 良い例が\Pkg{test/valign.lua}である.このファイルが読み込まれた状態では,
4820              JFM内で規定された文字クラス0の文字における$(\hbox{高
4821              さ}):(\hbox{深さ})$の比になるように,実際のフォントの出力上
4822              下位置が自動調整される.例えば,
4823 \begin{itemize}
4824 \item JFM側の設定:$(\hbox{高さ})=88x$, $(\hbox{深さ})=12x$%
4825 (和文OpenTypeフォントの標準値)
4826 \item 実フォント側の数値:$(\hbox{高さ})=28y$, $(\hbox{深さ})=5y$(和文TrueTypeフォントの標準値)
4827 \end{itemize}
4828 となっていたとする.すると,実際の文字の出力位置は,以下の量だけ上にぜらされることとなる:
4829 %</ja>
4830 \[
4831  \frac{88x}{88x+12x} (28y+5y) - 28y = \frac{26}{25}y= 1.04y.
4832 \]
4833 \end{description}
4834
4835
4836
4837 %<en>\section{Parameters}
4838 %<ja>\section{パラメータ}
4839 \subsection{\cs{ltjsetparameter}}
4840 \label{ssec-param}
4841
4842 %<*en>
4843 As described before, \cs{ltjsetparameter} and \cs{ltjgetparameter} are
4844 commands for accessing most parameters of \LuaTeX-ja. One of the main
4845 reason that \LuaTeX-ja didn't adopted the syntax similar to that of \pTeX\
4846 (\textit{e.g.},~\verb+\prebreakpenalty`)=10000+)
4847 is the position of \verb+hpack_filter+ callback in the source
4848 of \LuaTeX, see Section~\ref{sec-para}.
4849 %</en>
4850 %<*ja>
4851 先に述べたように,\LuaTeX-jaの内部パラメータにアクセスするには
4852 \cs{ltjsetparameter}(または \cs{ltjglobalsetparameter})と \cs{ltjgetparameter} を用いる.
4853 \LuaTeX-jaが\pTeX のような文法(例えば,\verb+\prebreakpenalty`)=10000+)を
4854 採用しない理由の一つは,\LuaTeX のソースにおける \verb+hpack_filter+
4855 コールバックの位置にある.\ref{sec-para}章を参照.
4856 %</ja>
4857
4858 %<*en>
4859 \cs{ltjsetparameter} and \cs{ltjglobalsetparameter} are commands
4860 for assigning parameters. These take one argument which is a
4861 \texttt{<key>=<value>} list.
4862 The difference between
4863 \cs{ltjsetparameter} and \cs{ltjglobalsetparameter} is only the
4864 scope of assignment;
4865 \cs{ltjsetparameter} does a local assignment and
4866 \cs{ltjglobalsetparameter} does a global one.
4867 They also obey the value of \cs{globaldefs}, like other assignments.
4868 %</en>
4869 %<*ja>
4870 \cs{ltjsetparameter} と \cs{ltjglobalsetparameter} はパラメータを
4871 指定するための命令で,\texttt{<key>=<value>}のリストを
4872 引数としてとる.
4873 \cs{ltjsetparameter} と \cs{ltjglobalsetparameter} の違いはスコープの
4874 違いのみで,
4875 \cs{ltjsetparameter} はローカルな設定を行うのに対し,
4876 \cs{ltjglobalsetparameter} はグローバルな設定を行う.
4877 また,他のパラメータ指定と同様に \cs{globaldefs} の値にも従う.
4878 %</ja>
4879
4880 %<*en>
4881 The following is the list of parameters which can be specified by the
4882 \cs{ltjsetparameter} command. [\cs{cs}] indicates the counterpart
4883 in \pTeX, and symbols beside each parameter has the following meaning:
4884 %</en>
4885 %<*ja>
4886 以下は \cs{ltjsetparameter} に指定することができるパラメータの一覧である.
4887 [\cs{cs}]は\pTeX における対応物を示す.
4888 また,それぞれのパラメータの右上の記号には次の意味がある:
4889 %</ja>
4890 \begin{itemize}
4891 %<*en>
4892 \item ``\ast'' : values at the end of a paragraph or a hbox are
4893 adopted in the whole paragraph or the whole hbox.
4894 %</en>
4895 %<*ja>
4896 \item ``\ast'':段落やhboxの終端での値がその段落/hbox全体で用いられる.
4897 %</ja>
4898 %<*en>
4899 \item ``\dagger'': assignments are always global.
4900 %</en>
4901 %<*ja>
4902 \item ``\dagger'':指定は常にグローバルになる.
4903 %</ja>
4904 \end{itemize}
4905
4906 \begin{cslist}[style=standard]
4907 \item[\DParam{jcharwidowpenalty}\,=<penalty>$^\ast$] [\cs{jcharwidowpenalty}]\
4908
4909 %<*en>
4910 Penalty value for suppressing orphans. This penalty is inserted just
4911              after the last \textbf{JAchar} which is not regarded as a
4912              (Japanese) punctuation mark.
4913 %</en>
4914 %<*ja>
4915 パラグラフの最後の字が孤立して改行されるのを防ぐためのペナルティの値.
4916 このペナルティは(日本語の)句読点として扱われない最後の\textbf{JAchar}の直後に
4917 挿入される.
4918 %</ja>
4919
4920 \item[\DParam{kcatcode}\,=\{<chr\_code>,<natural number>\}$^\ast$]\
4921
4922 %<*en>
4923 An additional attributes which each character whose character code is <chr\_code> has.
4924 At the present version, the lowermost bit of <natural number> indicates
4925              whether the character is considered as a punctuation mark
4926              (see the description of \Param{jcharwidowpenalty} above).
4927 %</en>
4928 %<*ja>
4929 文字コードが<chr\_code>の文字が持つ付加的な属性値.
4930 現在のバージョンでは,<natural number>の最下位ビットが,その文字が句読点と
4931 みなされるかどうかを表している(上の\Param{jcharwidowpenalty}の記述を参照).
4932 %</ja>
4933
4934 \item[\DParam{prebreakpenalty}\,=\{<chr\_code>,<penalty>\}$^\ast$] [\cs{prebreakpenalty}]\
4935
4936 %<*ja>
4937 文字コード<chr\_code>の\textbf{JAchar}が行頭にくることを抑止するために,
4938              この文字の前に挿入/追加されるペナルティの量を指定する.
4939
4940 例えば閉じ括弧「〗」は絶対に行頭にきてはならないので,
4941 \begin{lstlisting}
4942 \ltjsetparameter{prebreakpenalty={`〙,10000}}
4943 \end{lstlisting}
4944 と,最大値の10000が標準で指定されている.他にも,小書きのカナなど,絶対禁止とい
4945              うわけではないができれば行頭にはきて欲しくない場合に,0と
4946              10000の間の値を指定するのも有用であろう.
4947
4948 \pTeX では,\cs{prebreakpenalty}, \cs{postbreakpenalty}において,
4949 \begin{itemize}
4950 \item 一つの文字に対して,pre, postどちらか一つしか指定することができない%
4951   \footnote{後から指定した方で上書きされる.}
4952 \item pre, post合わせて256文字分の情報を格納することしかできない
4953 \end{itemize}
4954 という制限があったが,\LuaTeX-jaではこれらの制限は解消されている.
4955 %</ja>
4956 %<*en>
4957 Set a penalty which is inserted automatically before the character <chr\_code>,
4958 to prevent a line starts from this character. For example, a line cannot started
4959 with one of closing brackets ``〗'', so \LuaTeX-ja sets
4960 \begin{lstlisting}
4961 \ltjsetparameter{prebreakpenalty={`〙,10000}}
4962 \end{lstlisting}
4963 by default.
4964
4965 \pTeX\ has following restrictions on \cs{prebreakpenalty} and \cs{postbreakpenalty},
4966 but they don't exist in \LuaTeX-ja:
4967 \begin{itemize}
4968  \item Both \cs{prebreakpenalty} and \cs{postbreakpenalty} cannot be set
4969 for the same character.
4970  \item We can set \cs{prebreakpenalty} and \cs{postbreakpenalty} up to 256~characters.
4971 \end{itemize}
4972 %</en>
4973
4974 \item[\DParam{postbreakpenalty}\,=\{<chr\_code>,<penalty>\}$^\ast$]
4975            [\cs{postbreakpenalty}]\
4976
4977 %<*ja>
4978 文字コード<chr\_code>の\textbf{JAchar}が行末にくることを抑止するために,
4979              この文字の後に挿入/追加されるペナルティの量を指定する.
4980 %</ja>
4981 %<*en>
4982 Set a penalty which is inserted automatically after the character <chr\_code>,
4983 to prevent a line ends with this character.
4984 %</en>
4985
4986 \item[\DParam{jatextfont}\,=\{<jfam>,<jfont\_cs>\}$^\ast$]
4987 %<en>[\cs{textfont} in \TeX]
4988 %<ja>[\TeX の \cs{textfont}]
4989 \item[\DParam{jascriptfont}\,=\{<jfam>,<jfont\_cs>\}$^\ast$]
4990 %<en>[\cs{scriptfont} in \TeX]
4991 %<ja>[\TeX の \cs{scriptfont}]
4992 \item[\DParam{jascriptscriptfont}\,=\{<jfam>,<jfont\_cs>\}$^\ast$]
4993 %<en>[\cs{scriptscriptfont} in \TeX]
4994 %<ja>[\TeX の \cs{scriptscriptfont}]
4995 \item[\DParam{yjabaselineshift}\,=<dimen>]\
4996 \item[\DParam{yalbaselineshift}\,=<dimen>] [\cs{ybaselineshift}]
4997 \item[\DParam{tjabaselineshift}\,=<dimen>]\
4998 \item[\DParam{talbaselineshift}\,=<dimen>] [\cs{tbaselineshift}]
4999
5000 \item[\DParam{jaxspmode}\,=\{<chr\_code>,<mode>\}$^\ast$]\
5001
5002 %<*en>
5003 Setting whether inserting \Param{xkanjiskip} is allowed before/after a \textbf{JAchar} whose character code is <chr\_code>.
5004 The followings are allowed for <mode>:
5005 %</en>
5006 %<*ja>
5007 文字コードが<chr\_code>の\textbf{JAchar}の前/後ろに\Param{xkanjiskip}の
5008 挿入を許すかどうかの設定.
5009 以下の<mode>が許される:
5010 %</ja>
5011 \begin{description}
5012 %<en>\item[0, \texttt{inhibit}] Insertion of \Param{xkanjiskip} is inhibited before the character, nor after the character.
5013 %<ja>\item[0, \texttt{inhibit}] \Param{xkanjiskip}の挿入は文字の前/後ろのいずれでも禁止される.
5014 %<en>\item[1, \texttt{preonly}] Insertion of \Param{xkanjiskip} is allowed before the character, but not after.
5015 %<ja>\item[1, \texttt{preonly}] \Param{xkanjiskip}の挿入は文字の前では許されるが,後ろでは許されない.
5016 %<en>\item[2, \texttt{postonly}] Insertion of \Param{xkanjiskip} is allowed after the character, but not before.
5017 %<ja>\item[2, \texttt{postonly}] \Param{xkanjiskip}の挿入は文字の後ろでは許されるが,前では許されない.
5018 %<en>\item[3, \texttt{allow}] Insertion of \Param{xkanjiskip} is allowed both before the character and after the character. This is the default value.
5019 %<ja>\item[3, \texttt{allow}] \Param{xkanjiskip}の挿入は文字の前/後ろのいずれでも許される.これがデフォルトの値である.
5020 \end{description}
5021 %<*en>
5022 This parameter is similar to the \cs{inhibitxspcode} primitive of \pTeX, but not compatible with \cs{inhibitxspcode}.
5023 %</en>
5024 %<*ja>
5025 このパラメータは\pTeX の \cs{inhibitxspcode} プリミティブと似ているが,
5026 互換性はない.
5027 %</ja>
5028 \item[\DParam{alxspmode}\,=\{<chr\_code>,<mode>\}$^\ast$] [\cs{xspcode}]\
5029
5030 %<*en>
5031 Setting whether inserting \Param{xkanjiskip} is allowed before/after a
5032              \textbf{ALchar} whose character code is <chr\_code>.
5033              The followings are allowed for <mode>:
5034 %</en>
5035 %<*ja>
5036 文字コードが<chr\_code>の\textbf{ALchar}の前/後ろに\Param{xkanjiskip}の
5037 挿入を許すかどうかの設定.
5038 以下の<mode>が許される:
5039 %</ja>
5040 \begin{description}
5041 %<en>\item[0, \texttt{inhibit}] Insertion of \Param{xkanjiskip} is inhibited before the character, nor after the character.
5042 %<ja>\item[0, \texttt{inhibit}] \Param{xkanjiskip}の挿入は文字の前/後ろのいずれでも禁止される.
5043 %<en>\item[1, \texttt{preonly}] Insertion of \Param{xkanjiskip} is allowed before the character, but not after.
5044 %<ja>\item[1, \texttt{preonly}] \Param{xkanjiskip}の挿入は文字の前では許されるが,後ろでは許されない.
5045 %<en>\item[2, \texttt{postonly}] Insertion of \Param{xkanjiskip} is allowed after the character, but not before.
5046 %<ja>\item[2, \texttt{postonly}] \Param{xkanjiskip}の挿入は文字の後ろでは許されるが,前では許されない.
5047 %<en>\item[3, \texttt{allow}] Insertion of \Param{xkanjiskip} is allowed before the character and after the character. This is the default value.
5048 %<ja>\item[3, \texttt{allow}] \Param{xkanjiskip}の挿入は文字の前/後ろのいずれでも許される.これがデフォルトの値である.
5049 \end{description}
5050 %<*en>
5051 Note that parameters \Param{jaxspmode} and \Param{alxspmode} share a common table, hence these two parameters are synonyms of each other.
5052 %</en>
5053 %<*ja>
5054 \Param{jaxspmode}と\Param{alxspmode}は共通のテーブルを用いているため,
5055 これら2つのパラメータは互いの別名となっていることに注意する.
5056 %</ja>
5057
5058 \item[\DParam{autospacing}\,=<bool>] [\cs{autospacing}]
5059 \item[\DParam{autoxspacing}\,=<bool>] [\cs{autoxspacing}]
5060 \item[\DParam{kanjiskip}\,=<skip>$^\ast$] [\cs{kanjiskip}]\
5061
5062 %<*ja>
5063 デフォルトで2つの\textbf{JAchar}の間に挿入されるグルーである.
5064 通常では,\pTeX と同じようにフォントサイズに比例して変わることはない.
5065 しかし,自然長が \cs{maxdimen} の場合は,例外的に和文フォントのJFM側で指定されている
5066 値を採用(こちらはフォントサイズに比例)することになっている.
5067 %</ja>
5068
5069 \item[\DParam{xkanjiskip}\,=<skip>$^\ast$] [\cs{xkanjiskip}]\
5070
5071 %<*ja>
5072 デフォルトで\textbf{JAchar}と\textbf{ALchar}の間に挿入されるグルーである.
5073 \Param{kanjiskip}と同じように,通常ではフォントサイズに比例して変わることはないが,
5074 自然長が \cs{maxdimen} の場合が例外である.
5075 %</ja>
5076
5077
5078 \item[\DParam{differentjfm}\,=<mode>$^\dagger$]\
5079
5080 %<*en>
5081 Specify how glues/kerns between two \textbf{JAchar}s whose JFM (or size) are different.
5082 The allowed arguments are the followings:
5083 %</en>
5084 %<*ja>
5085 JFM(もしくはサイズ)が異なる2つの\textbf{JAchar}の間にグルー/カーンをどのように
5086 入れるかを指定する.
5087 許される値は以下の通り:
5088 %</ja>
5089 \begin{quote}
5090 \texttt{average},
5091 \texttt{both},
5092 \texttt{large},
5093 \texttt{small},
5094 \texttt{pleft},
5095 \texttt{pright},
5096 \texttt{paverage}
5097 \end{quote}
5098 %<*en>
5099 The default value is \texttt{paverage}. \dots
5100 %</en>
5101 %<*ja>
5102 デフォルト値は \texttt{paverage} である.
5103 各々の値による差異の詳細は\ref{ssec-cluster-wa}節の「『右空白』の算出」を参照してほしい.
5104 %</ja>
5105
5106 \item[\DParam{jacharrange}\,=<ranges>]
5107 \item[\DParam{kansujichar}\,=\{<digit>, <chr\_code>\}$^\ast$] [\cs{kansujichar}]
5108
5109 \item[\DParam{direction}\,=<dir>\ \hbox{\rm (always local)}]\
5110
5111 %<*en>
5112 Assigning to this parameter has the same effect as
5113 \cs{yoko}~(if $\hbox{<dir>}=4$), \cs{tate}~(if $\hbox{<dir>}=3$),
5114 \cs{dtou}~(if $\hbox{<dir>}=1$) or \cs{utod}~(if $\hbox{<dir>}=11$).
5115 If the argument <dir> is not one of 4,~3, 1~nor~11,
5116 the behavior of this assignment is undefined.
5117 %</en>
5118 %<*ja>
5119 組方向を変更する \cs{yoko}~(if $\hbox{<dir>}=4$), \cs{tate}~(if $\hbox{<dir>}=3$),
5120 \cs{dtou}~(if $\hbox{<dir>}=1$), \cs{utod}~(if $\hbox{<dir>}=11$) と同じ役割を持つ.
5121 利用可能な状況もこれら4命令と同一である.引数<dir>が4,~3, 1,~11のいずれでも無いときの
5122 動作は未定義である.
5123 %</ja>
5124
5125 \end{cslist}
5126
5127
5128 \subsection{\cs{ltjgetparameter}}
5129 \label{ssec-getpar}
5130 %<*en>
5131 \cs{ltjgetparameter} is a control sequence for acquiring parameters. It
5132 always takes a parameter name as first argument.
5133 %</en>
5134 %<*ja>
5135 \cs{ltjgetparameter} はパラメータの値を取得するための命令であり,
5136 常にパラメータの名前を第一引数にとる.
5137 %</ja>
5138 \begin{LTXexample}
5139 \ltjgetparameter{differentjfm},
5140 \ltjgetparameter{autospacing},
5141 \ltjgetparameter{kanjiskip},
5142 \ltjgetparameter{prebreakpenalty}{`)}.
5143 \end{LTXexample}
5144
5145 %<*en>
5146 \emph{The return value of\/ \cs{ltjgetparameter} is
5147 always a string}, which is outputted by \texttt{tex.write()}.
5148 Hence any character other than space~``\texttt{\char32}''~(\texttt{U+0020}) has the category code
5149 12~(other), while the space has 10~(space).
5150 %</en>
5151 %<*ja>
5152 \emph{\cs{ltjgetparameter} の戻り値は常に文字列である.}
5153 これは\texttt{tex.write()}によって出力しているためで,空白「\texttt{\char32}」
5154 (\texttt{U+0020})を除いた文字のカテゴリーコードは全て12~(other)となる.
5155 一方,空白のカテゴリーコードは10~(space)である.
5156 %</ja>
5157
5158 \begin{itemize}
5159 \item
5160 %<*en>
5161 If first argument is one of the
5162 following, no  additional argument is needed.
5163 %</en>
5164 %<*ja>
5165 第1引数が次のいずれかの場合には,追加の引数は必要ない.
5166 %</ja>
5167 \begin{quote}
5168 \sffamily
5169 jcharwidowpenalty, yjabaselineshift, yalbaselineshift, autospacing, autoxspacing,\\
5170 kanjiskip, xkanjiskip, differentjfm, direction
5171 \end{quote}
5172 %<*en>
5173 Note that \verb+\ltjgetparameter{autospacing}+~and~\verb+\ltjgetparameter{autoxspacing}+
5174 returns 1 or 0, not
5175 \texttt{true}~nor~\texttt{false}.
5176 %</en>
5177 %<*ja>
5178 \verb+\ltjgetparameter{autospacing}+ と \verb+\ltjgetparameter{autoxspacing}+ は,
5179 \texttt{true}や\texttt{false}を返すの\emph{ではなく},
5180 1か0のいずれかを返すことに注意,
5181 %</ja>
5182
5183 \item
5184 %<*en>
5185 If first argument is one of the
5186 following, an additional argument---a character code, for example---is needed.
5187 %</en>
5188 %<*ja>
5189 第1引数が次のいずれかの場合には,さらに文字コードを第2引数としてとる.
5190 %</ja>
5191 \begin{quote}
5192 \sffamily
5193 kcatcode, prebreakpenalty, postbreakpenalty, jaxspmode, alxspmode
5194 \end{quote}
5195 %<*en>
5196 \verb+\ltjgetparameter{jaxspmode}{...}+~and~\verb+\ltjgetparameter{alxspmode}{...}+
5197 returns 0,~1, 2,~or~3, instead of \texttt{preonly} etc.
5198 %</en>
5199 %<*ja>
5200 \verb+\ltjgetparameter{jaxspmode}{...}+ や \verb+\ltjgetparameter{alxspmode}{...}+\
5201 は,\texttt{preonly} などといった文字列ではなく,0から3までの値を返す.
5202 %</ja>
5203
5204 \item
5205 %<*en>
5206 \verb+\ltjgetparameter{jacharrange}{+<range>\verb+}+ returns \texttt{0}
5207 if ``characters which belong to the character range~<range> are \textbf{JAchar}'',
5208 \texttt{1} if ``\dots~are \textbf{ALchar}''.
5209 Although there is no character range~$-1$, specifying $-1$ to <range> does not cause an
5210       error (returns 1).
5211 %</en>
5212 %<*ja>
5213 \verb+\ltjgetparameter{jacharrange}{+<range>\verb+}+ は,<range>が\textbf{JAchar}達の
5214 範囲ならば0を,そうでなければ1を返す.「$-1$番の文字範囲」は存在しないが,<range>に$-1$を
5215 指定してもエラーは発生しない(1を返す).
5216 %</ja>
5217
5218 \item
5219 %<*en>
5220 For an integer~<digit> between 0~and~9,
5221      \verb+\ltjgetparameter{kansujichar}{+<digit>\verb+}+ returns the character code
5222 of the result of \cs{kansuji}<digit>.
5223 %</en>
5224 %<*ja>
5225 0--9の数<digit>に対して,
5226 \verb+\ltjgetparameter{kansujichar}{+<digit>\verb+}+ は,\cs{kansuji}<digit>で出力され
5227      る文字の文字コードを返す.
5228 %</ja>
5229
5230 \item
5231 %<*en>
5232 \verb+\ltjgetparameter{adjustdir}+ returns a integer which represents
5233 the direction of the surrounding vertical list.
5234 As \Param{direction}, the return value 1 means \emph{down-to-up} direction,
5235 3 means \emph{tate} direction (vertical typesetting),
5236 and 4 means \emph{yoko} direction (horizontal typesetting).
5237 %</en>
5238 %<*ja>
5239 \verb+\ltjgetparameter{adjustdir}+ は,周囲のvboxの組方向(言い換えれば,
5240 \cs{vadjust} で用いられる組方向)を表す数値を返す.
5241 \Param{direction}と同様に,1は \cs{dtou} 方向を,
5242 3は縦組みを,4は横組みを表す.
5243 %</ja>
5244
5245 \item
5246 %<*en>
5247 For an integer~<reg\_num> between 0~and~65535,
5248 \verb+\ltjgetparameter{boxdim}{+<reg\_num>\verb+}+ returns the direction of
5249 \cs{box}<reg\_num>. If this box register is void, the returned value is zero.
5250 %</en>
5251 %<*ja>
5252 0--65535の数<reg\_num>に対して,
5253 \verb+\ltjgetparameter{boxdim}{+<reg\_num>\verb+}+ は,\cs{box}<reg\_num>に
5254 格納されているボックスの組方向を表す.もしこのレジスタが空の場合は,0が返される.
5255 %</ja>
5256
5257 \item
5258 %<*en>
5259 The following parameter names \emph{cannot be specified} in \cs{ltjgetparameter}.
5260 %</en>
5261 %<*ja>
5262 次のパラメータ名を \cs{ltjgetparameter} に指定することはできない.
5263 %</ja>
5264 \begin{quote}
5265 \sffamily
5266 jatextfont, jascriptfont, jascriptscriptfont, jacharrange
5267 \end{quote}
5268
5269 \item
5270 %<*en>
5271 \verb+\ltjgetparameter{chartorange}{+<chr\_code>\verb+}+ returns
5272 the range number which <chr\_code> belongs to
5273 (although there is no parameter named ``chartorange'').
5274
5275 If <chr\_code> is between 0 and 127, this <chr\_code> does not belong to
5276 any character range. In this case,
5277       \verb+\ltjgetparameter{chartorange}{+<chr\_code>\verb+}+
5278 returns $-1$.
5279
5280 Hence, one can know whether <chr\_code> is \textbf{JAchar} or not
5281 by the following:
5282 %</en>
5283 %<*ja>
5284 \verb+\ltjgetparameter{chartorange}{+<chr\_code>\verb+}+ によって
5285 <chr\_code>の属する文字範囲の番号を知ることができる.
5286
5287 <chr\_code>に0--127の値を指定した場合(このとき,<chr\_code>が属する
5288 文字範囲は存在しない)は$-1$が返る.
5289
5290 そのため,<chr\_code>が\textbf{JAchar}か\textbf{ALchar}かは
5291 次で知ることができる:
5292 %</ja>
5293 \begin{quote}
5294 \ttfamily \verb+\ltjgetparameter{jacharrange}{\ltjgetparameter{chartorange}{+%
5295   <chr\_code>\verb+}}+\\\null\hfill\verb+% 0 if JAchar, 1 if ALchar+
5296 \end{quote}
5297
5298 %<*en>
5299 \item Because the returned value is string, the following conditionals do not work
5300 if \Param{kanjiskip} (or~\Param{xkanjiskip}) has the stretch part or the shrink part.
5301 \begin{lstlisting}
5302 \ifdim\ltjgetparameter{kanjiskip}>\z@ ... \fi
5303 \ifdim\ltjgetparameter{xkanjiskip}>\z@ ... \fi
5304 \end{lstlisting}
5305 The correct way is using a temporary register.
5306 \begin{lstlisting}
5307 \@tempskipa=\ltjgetparameter{kanjiskip} \ifdim\@tempskipa>\z@ ... \fi
5308 \@tempskipa=\ltjgetparameter{xkanjiskip}\ifdim\@tempskipa>\z@ ... \fi
5309 \end{lstlisting}
5310 %</en>
5311 %<*ja>
5312 \item 返り値が文字列であることから,\Param{kanjiskip}や\Param{xkanjiskip}を直接
5313 \ \cs{ifdim} を使って比較することは望ましくない.伸び量や縮み量を持っている時には,
5314 次はエラーを発生させる:
5315 \begin{lstlisting}
5316 \ifdim\ltjgetparameter{kanjiskip}>\z@ ... \fi
5317 \ifdim\ltjgetparameter{xkanjiskip}>\z@ ... \fi
5318 \end{lstlisting}
5319 レジスタに一旦代入するのが良い:
5320 \begin{lstlisting}
5321 \@tempskipa=\ltjgetparameter{kanjiskip} \ifdim\@tempskipa>\z@ ... \fi
5322 \@tempskipa=\ltjgetparameter{xkanjiskip}\ifdim\@tempskipa>\z@ ... \fi
5323 \end{lstlisting}
5324 %</ja>
5325
5326 \end{itemize}
5327
5328 %<*ja>
5329 \subsection{\cs{ltjsetparameter} の代替}
5330 原則として各種内部パラメータの設定には \cs{ltjsetparameter} もしくは
5331 \ \cs{ltjglobalsetparameter}\ を用いることになるが,
5332 \cs{ltjsetparameter} の実行には時間がかかるという難点があり,
5333 \LuaTeX-ja の内部ではより高速に実行できる別の形式を用いている.
5334 \emph{本節は一般利用者むけの内容ではない.}
5335
5336 \paragraph{\Param{kanjiskip}, \Param{xkanjiskip} の設定}
5337 \pLaTeXe 新ドキュメントクラスでは,
5338 \begin{lstlisting}
5339 \def\@setfontsize#1#2#3{%
5340   ...
5341   \kanjiskip=0zw plus .1zw minus .01zw
5342   \ifdim\xkanjiskip>\z@
5343     \if@slide \xkanjiskip=0.1em \else
5344       \xkanjiskip=0.25em plus 0.15em minus 0.06em
5345     \fi
5346   \fi}
5347 \end{lstlisting}
5348 と,フォントサイズを変更するごとに \cs{kanjiskip}, \cs{xkanjiskip} を変更している.
5349 この \cs{@setfontsize} は文書の中で多数回実行されるので.
5350 \LuaTeX-ja 用に素直に書き換えた
5351 \begin{lstlisting}
5352   \ltjsetparameter{kanjiskip=0\zw plus .1\zw minus .01\zw}
5353   \@tempskipa=\ltjgetparameter{xkanjiskip}
5354   \ifdim\@tempskipa>\z@
5355     \if@slide 
5356       \ltjsetparameter{xkanjiskip=0.1em}
5357     \else
5358       \ltjsetparameter{xkanjiskip=0.25em plus 0.15em minus 0.06em}
5359     \fi
5360   \fi
5361 \end{lstlisting}
5362 としたのではタイプセットが遅くなってしまう.
5363 そこで,\cs{ltjsetparameter} の中で
5364 \begin{itemize}
5365 \item \cs{globaldefs} の値を読み取る \cs{ltj@setpar@global}
5366 \item \Param{kanjiskip} の設定を行う \cs{ltjsetkanjiskip}
5367 \item \Param{xkanjiskip} の設定を行う \cs{ltjsetxkanjiskip}
5368 \end{itemize}
5369 を独立させ,\Pkg{ltjsclasses}では,
5370 \begin{lstlisting}
5371   \ltj@setpar@global
5372   \ltjsetkanjiskip{\z@ plus .1\zw minus .01\zw}
5373   \@tempskipa=\ltjgetparameter{xkanjiskip}
5374   \ifdim\@tempskipa>\z@
5375     \if@slide 
5376       \ltjsetxkanjiskip.1em
5377     \else
5378       \ltjsetxkanjiskip.25em plus .15em minus .06em
5379     \fi
5380   \fi
5381 \end{lstlisting}
5382 としている.
5383 \cs{ltj@setpar@global}を直前に実行せず,単独で
5384 \cs{ltjsetkanjiskip}, \cs{ltjsetxkanjiskip}を実行することは想定されていないので注意.
5385
5386
5387
5388 \paragraph{ベースライン補正量の設定}
5389 \pLaTeX の\Pkg{ascmac}パッケージでは,縦組の欧文ベースライン補正量の一時待避・復帰処理に
5390 \ \cs{@saveybaselineshift}\ という寸法レジスタを用い
5391 \begin{lstlisting}
5392 \@savetbaselineshift\tbaselineshift\tbaselineshift\z@
5393 ...
5394 \tbaselineshift\@savetbaselineshift
5395 \end{lstlisting}
5396 という処理を行っている.
5397
5398 これを\LuaTeX-ja 用に \cs{ltjsetparameter} を使って書き直すと,
5399 \begin{lstlisting}
5400 \@savetbaselineshift\ltjgetparameter{talbaselineshift}
5401 \ltjsetparameter{talbaselineshift=\z@}
5402 ...
5403 \ltjsetparameter{talbaselineshift=\@savetbaselineshift}
5404 \end{lstlisting}
5405 となる.
5406
5407 さて,縦組の欧文ベースライン補正量\Param{talbaselineshift}は,
5408 実際には \cs{ltj@tablshift} という属性レジスタに格納されている
5409 (\ref{sec-para}\nobreak 節参照).属性レジスタは長さではなく整数値を格納する\footnote{%
5410   従って,\texttt{\textbackslash @savetbaselineshift=\textbackslash ltj@tablshift}\ 
5411   のように記述することはできない.属性レジスタを \cs{tbaselineshift} という名称にしなかっ
5412   たのはそのためである.
5413 }ものであり,\cs{ltj@tablshift} は補正量を sp 単位で保持することから,
5414 上記のコードと同じ内容をより速い以下のコードで実現することができる.
5415 \begin{lstlisting}
5416 \@savetbaselineshift\ltj@tablshift sp%
5417 \ltj@tablshift\z@
5418 ...
5419 \ltj@tablshift\@savetbaselineshift
5420 \end{lstlisting}
5421 この手法は \Pkg{ascmac} パッケージの\LuaTeX-ja対応パッチ \Pkg{lltjp-tascmac.sty} で
5422 実際に用いられている.\Pkg{lltjp-tascmac.sty} は自動的に読み込まれるので,
5423 ユーザは何も気にせず普通に \Pkg{ascmac} パッケージを \cs{usepackage} で読みこめば良い.
5424 %</ja>
5425
5426
5427 %<en>\section{Other Commands for plain \TeX\ and \LaTeXe}
5428 %<ja>\section{plainでも\LaTeX でも利用可能なその他の命令}
5429 %<en>\subsection{Commands for Compatibility with \pTeX}
5430 %<ja>\subsection{\pTeX 互換用命令}
5431
5432 %<*en>
5433 The following commands are implemented for compatibility with \pTeX.
5434 Note that the former five commands don't support JIS~X~0213, but only JIS~X~0208.
5435 The last \cs{kansuji} converts an integer into its Chinese numerals.
5436 %</en>
5437 %<*ja>
5438 以下の命令は\pTeX との互換性のために実装されている.そのため,JIS~X~0213には対応せず,
5439 \pTeX と同じようにJIS~X~0208の範囲しかサポートしていない.
5440 %</ja>
5441 \begin{center}
5442 \cs{kuten}, \cs{jis}, \cs{euc}, \cs{sjis}, \cs{jis}, \cs{kansuji}
5443 \end{center}
5444 %<*en>
5445 These six commands takes an internal integer, and returns a \emph{string}.
5446 %</en>
5447 %<*ja>
5448 これら6命令は内部整数を引数とするが,実行結果は\textbf{文字列}であることに注意.
5449 %</ja>
5450 \begin{LTXexample}
5451 \newcount\hoge
5452 \hoge="2423 %"
5453 \the\hoge, \kansuji\hoge\\
5454 \jis\hoge, \char\jis\hoge\\
5455 \kansuji1701
5456 \end{LTXexample}
5457
5458 %<*en>
5459 To change characters of Chinese numerals for each digit, set \Param{kansujichar} parameter:
5460 \begin{LTXexample}
5461 \ltjsetparameter{kansujichar={1,`壹}}
5462 \ltjsetparameter{kansujichar={7,`漆}}
5463 \ltjsetparameter{kansujichar={0,`零}}
5464 \kansuji1701
5465 \end{LTXexample}
5466 %</en>
5467
5468
5469 \subsection{\cs{inhibitglue}}
5470 %<*en>
5471 \cs{inhibitglue} suppresses the insertion of \textbf{JAglue}.
5472 The following is an example, using a special JFM that there will be a glue between
5473 the beginning of a box and ``あ'', and also between ``あ''~and~``ウ''.
5474 %</en>
5475 %<*ja>
5476 \cs{inhibitglue} は\textbf{JAglue}の挿入を抑制する.
5477 以下は,ボックスの始めと「あ」の間,「あ」「ウ」の間にグルーが入る特別なJFMを用いた例で
5478 ある.
5479 %</ja>
5480
5481 \begin{LTXexample}[width=0.4\textwidth]
5482 \jfont\g=file:KozMinPr6N-Regular.otf:jfm=test \g
5483 \fbox{\hbox{あウあ\inhibitglue ウ}}
5484 \inhibitglue\par\noindent あ1
5485 \par\inhibitglue\noindent あ2
5486 \par\noindent\inhibitglue あ3
5487 \par\hrule\noindent あoff\inhibitglue ice
5488 \end{LTXexample}
5489
5490 %<*en>
5491 With the help of this example, we remark the specification of \cs{inhibitglue}:
5492 %</en>
5493 %<*ja>
5494 この例を援用して,\cs{inhibitglue} の仕様について述べる.
5495 %</ja>
5496 \begin{itemize}
5497 %<*en>
5498 \item The call of \cs{inhibitglue} in the (internal) vertical mode is
5499       simply ignored.
5500 %</en>
5501 %<*ja>
5502 \item \emph{\cs{inhibitglue} の垂直モード中での呼び出しは意味を持たない}\footnote{%
5503   この点は\TeX~Live~2014での\pTeX における \cs{inhibitglue} の仕様変更と同じである.
5504 }.
5505 4行目の入力で有効にならないのは,\cs{inhibitglue} の時点では垂直モードであり,
5506 \cs{noindent} の時点で水平モードになるからである.
5507 %</ja>
5508
5509 %<*en>
5510 \item The call of \cs{inhibitglue} in the (restricted) horizontal
5511       mode is only effective on the spot; does not get over boundary of
5512       paragraphs. Moreover, \cs{inhibitglue} cancels ligatures and
5513       kernings, as shown in the last line of above example.
5514 %</en>
5515 %<*ja>
5516 \item \cs{inhibitglue} の(制限された)水平モード中での呼び出しはその場でのみ
5517   有効であり,段落の境界を乗り越えない.
5518   さらに,\cs{inhibitglue} は上の例の最終行のように(欧文における)リガチャとカーニングを
5519   打ち消す.これは,\cs{inhibitglue} が内部的には「現在のリスト中にwhatsitノードを
5520   追加する」ことを行なっているからである.
5521 %</ja>
5522
5523 %<*en>
5524 \item The call of \cs{inhibitglue} in math mode is just ignored.
5525 %</en>
5526 %<*ja>
5527 \item \cs{inhibitglue} を数式モード中で呼び出した場合はただ無視される.
5528 %</ja>
5529
5530 %<*ja>
5531 \item \LaTeX で\LuaTeX-ja を使用する場合は,
5532 \cs{inhibitglue} の代わりとして \verb+\<+ を使うことができる.
5533 既に \verb+\<+ が定義されていた場合は,\LuaTeX-ja の読み込みで強制的に上書きされるので
5534 注意すること.
5535 %</ja>
5536 \end{itemize}
5537
5538
5539 \subsection{\cs{ltjdeclarealtfont}}
5540 \label{ssec-altfont}
5541 %<*en>
5542 Using \cs{ltjdeclarealtfont}, one can ``compose'' more than one Japanese fonts.
5543 This \cs{ltjdeclarealtfont} uses in the following form:
5544 \begin{quote}
5545 \ttfamily \textbackslash ltjdeclarealtfont<base\_font\_cs><alt\_font\_cs>{<range>}
5546 \end{quote}
5547 where  <base\_font\_cs>~and~<alt\_font\_cs> are defined by \cs{jfont}.
5548 Its meaning is
5549 \begin{quote}
5550 If the current Japanese font is <base\_font\_cs>, characters which belong to <range>
5551 is typeset by another Japanese font <alt\_font\_cs>, instead of <base\_font\_cs>.
5552 \end{quote}
5553
5554 <range> is a comma-separated list of character codes, but also accepts negative integers:
5555 $-n$~($n≥1$) means that all characters of character classes~$n$, with respect to JFM used
5556 by <base\_font\_cs>. Note that characters which do not exist in <alt\_font\_cs> are
5557 ignored.
5558
5559 For example, if \cs{hoge} uses \texttt{jfm-ujis.lua}, the standard JFM of \LuaTeX-ja,
5560 then
5561 \begin{lstlisting}
5562 \ltjdeclarealtfont\hoge\piyo{"3000-"30FF, {-1}-{-1}}
5563 \end{lstlisting}
5564 does
5565 \begin{quote}
5566 If the current Japanese font is \cs{hoge}, \texttt{U+3000}--\texttt{U+30FF}
5567 and characters in class~1 (ideographic opening brackets)
5568 are typeset by \cs{piyo}.
5569 \end{quote}
5570 %</en>
5571 %<*ja>
5572 \cs{jfont} の書式を見ればわかるように,基本的には\LuaTeX-jaにおける1つの和文フォントに
5573 使用出来る「実際のフォント」は1つである.
5574 しかし,\cs{ltjdeclarealtfont} を用いると,この原則から外れることができる.
5575
5576 \cs{ltjdeclarealtfont} は以下の書式で使用する:
5577 \begin{quote}
5578 \ttfamily \textbackslash ltjdeclarealtfont<base\_font\_cs><alt\_font\_cs>{<range>}
5579 \end{quote}
5580 これは「現在の和文フォント」が<base\_font\_cs>であるとき,
5581 <range>に属する文字は<alt\_font\_cs>を用いて組版される,という意味である.
5582 \begin{itemize}
5583  \item <base\_font\_cs>, <alt\_font\_cs>は
5584 \cs{jfont} によって定義された和文フォントである.
5585  \item <range>は文字コードの範囲を表すコンマ区切りのリストであるが,
5586    例外として負数$-n$は「<base\_font\_cs>のJFMの文字クラス$n$に属する全ての文字」
5587    を意味する.
5588
5589 <range>中に<alt\_font\_cs>中に実際には存在しない文字が指定された場合は,
5590 その文字に対する設定は無視される.
5591 \end{itemize}
5592
5593 例えば,\cs{hoge} のJFMが\LuaTeX-ja標準の
5594 \ \texttt{jfm-ujis.lua} であった場合,
5595 \begin{lstlisting}
5596 \ltjdeclarealtfont\hoge\piyo{"3000-"30FF, {-1}-{-1}}
5597 \end{lstlisting}
5598 は「\cs{hoge} を利用しているとき,
5599 \texttt{U+3000}--\texttt{U+30FF}と
5600 文字クラス1(開き括弧類)中の文字だけは \cs{piyo} を用いる」
5601 ことを設定する.\verb+{-1}-{-1}+ という変わった指定の仕方をしているのは,
5602 普通に \texttt{-1} と指定したのでは正しく$-1$と読み取られないという
5603 マクロの都合による.
5604 %</ja>
5605
5606
5607
5608 %<en>\section{Commands for \LaTeXe}
5609 %<ja>\section{\LaTeXe 用の命令}
5610
5611 %<en>\subsection{Patch for NFSS2}
5612 %<ja>\subsection{NFSS2へのパッチ}
5613 \label{ssec-nfsspat}
5614
5615 %<*en>
5616 Japanese patch for NFSS2 in \LuaTeX-ja
5617 is based on \texttt{plfonts.dtx} which plays the same role in \pLaTeXe.
5618 We will describe
5619 commands which are not described in Subsection~\ref{ssec-chgfnt}.
5620 %</en>
5621 %<*ja>
5622 \LuaTeX-jaのNFSS2への日本語パッチは
5623 \pLaTeXe で同様の役割を果たす \texttt{plfonts.dtx} をベースに,
5624 和文エンコーディングの管理等をLuaで書きなおしたものである.
5625 ここでは\ref{ssec-chgfnt}節で述べていなかった命令について
5626 記述しておく.
5627 %</ja>
5628
5629 \begin{cslist}%
5630 \item[\normalfont\bfseries %
5631 %<ja>追加の長さ変数達
5632 %<en>additonal dimensions
5633 ]
5634 %<*en>
5635 Like \pLaTeXe, \LuaTeX-ja defines the following dimensions
5636 for information of current Japanese font:
5637 %</en>
5638 %<*ja>
5639 \pLaTeXe と同様に,\LuaTeX-jaは「現在の和文フォントの情報」を格納する長さ変数
5640 %</ja>
5641 \begin{quote}
5642  \cs{cht}~(height), \cs{cdp}~(depth), \cs{cHT}~(sum of former two),\\
5643  \cs{cwd}~(width), \cs{cvs}~(lineskip), \cs{chs}~(equals to \cs{cwd})
5644 \end{quote}
5645 %<en>and its \cs{normalsize} version:
5646 %<ja>と,その \cs{normalsize} 版である
5647 \begin{quote}
5648  \cs{Cht}~(height), \cs{Cdp}~(depth),
5649  \cs{Cwd}~(width), \\\cs{Cvs}~(equals to \cs{baselineskip}),
5650  \cs{Chs}~(equals to \cs{cwd})%
5651 %<en>.
5652 \end{quote}
5653 %<*ja>
5654 を定義している.なお,\cs{cwd} と \cs{zw},また
5655 \cs{cHT} と \cs{zh} は一致しない可能性がある.なぜなら,
5656 \cs{cwd},~\cs{cHT} は「あ」の寸法から決定されるのに対し,
5657 \cs{zw} と \cs{zh} はJFMに指定された値に過ぎないからである.
5658 %</ja>
5659 %<*en>
5660 Note that \cs{cwd}~and~\cs{cHT} may  differ from \cs{zw}~and~\cs{zh}
5661 respectively.
5662 On the one hand the former dimensions are determined from the character ``あ'',
5663 but on the other hand \cs{zw}~and~\cs{zh} are specified by JFM.
5664 %</en>
5665
5666
5667 \item[\cs{DeclareYokoKanjiEncoding}\{<encoding>\}\{<text-settings>\}\{<math-settings>\}]
5668 %<en>\ \\[\dimexpr-\medskipamount-2\baselineskip\relax]
5669 %<ja>\ \\[\dimexpr-2\baselineskip\relax]
5670 \item[\cs{DeclareTateKanjiEncoding}\{<encoding>\}\{<text-settings>\}\{<math-settings>\}]
5671
5672 %<*en>
5673 In NFSS2 under \LuaTeX-ja, distinction between alphabetic font families
5674              and Japanese font families are only made by their
5675              encodings. For example, encodings OT1 and T1 are for
5676              alphabetic font families, and a Japanese font family cannot
5677              have these encodings. These command define a new encoding
5678              scheme for Japanese font families.
5679 %</en>
5680 %<*ja>
5681 \LuaTeX-jaのNFSS2においては,欧文フォントファミリと和文フォントファミリは
5682 そのエンコーディングによってのみ区別される.
5683 例えば,OT1とT1のエンコーディングは欧文フォントファミリに対するものであり,
5684 和文フォントファミリはこれらのエンコーディングを持つことはできない.
5685 これらコマンドは横組用・縦組用和文フォントのための新しいエンコーディングを
5686 それぞれ定義する.
5687 %</ja>
5688
5689 \item[\cs{DeclareKanjiEncodingDefaults}\{<text-settings>\}\{<math-settings>\}]
5690 %<en>\ \\[\dimexpr-\medskipamount-2\baselineskip\relax]
5691 %<ja>\ \\[\dimexpr-2\baselineskip\relax]
5692 \item[\cs{DeclareKanjiSubstitution}\{<encoding>\}\{<family>\}\{<series>\}\{<shape>\}]
5693 %<en>\ \\[\dimexpr-\medskipamount-2\baselineskip\relax]
5694 %<ja>\ \\[\dimexpr-2\baselineskip\relax]
5695 \item[\cs{DeclareErrorKanjiFont}\{<encoding>\}\{<family>\}\{<series>\}\{<shape>\}\{<size>\}]
5696
5697 %<*en>
5698 The above 3~commands are just the counterparts for \cs{DeclareFontEncodingDefaults} and~others.
5699 %</en>
5700 %<*ja>
5701 上記3つのコマンドはちょうど \cs{DeclareFontEncodingDefaults} などに対応するものである.
5702 %</ja>
5703
5704 \item[\cs{reDeclareMathAlphabet}\{<unified-cmd>\}\{<al-cmd>\}\{<ja-cmd>\}]
5705
5706 % ToDo: en
5707 %<*ja>
5708 和文・欧文の数式用フォントファミリを一度に変更する命令を作成する.
5709 具体的には,欧文数式用フォントファミリ変更の命令<al-cmd>(\cs{mathrm} 等)と,和文数式用フォ
5710              ントファミリ変更の命令<ja-cmd>(\cs{mathmc} 等)の2つを同時に行う命令として
5711              <unified-cmd>を(再)定義する.実際の使用では<unified-cmd>と
5712              <al-cmd>に同じものを指定する,すなわち,<al-cmd>で和文側も変
5713              更させるようにするのが一般的と思われる.
5714
5715 本命令は
5716 \begin{center}\tt
5717 <unified-cmd>\{<arg>\}\quad$\longrightarrow$\quad
5718 (<al-cmd>の1段展開結果)\{<ja-cmd>の1段展開結果)\{<arg>\}\}
5719 \end{center}
5720 と定義を行うので,使用には注意が必要である:
5721 %<en>\vspace{-\medskipamount}
5722 \begin{itemize}
5723 \item <al-cmd>,~<ja-cmd>は既に定義されていなければならない.
5724       \cs{reDeclareMathAlphabet}\\の後に
5725 両命令の内容を再定義しても,<unified-cmd>の内容にそれは反映されない.
5726 \item <al-cmd>,~<ja-cmd>に\verb+\@mathrm+などと \texttt{@} をつけた命令を指定した時の動作は保証できない.
5727 \end{itemize}
5728 %</ja>
5729
5730 \item[\cs{DeclareRelationFont}\{<ja-encoding>\}\{<ja-family>\}\{<ja-series>\}\{<ja-shape>\}\\*
5731   \null\hfill\{<al-encoding>\}\{<al-family>\}\{<al-series>\}\{<al-shape>\}]
5732 %<*en>
5733 This command sets the ``accompanied'' alphabetic font family (given by the latter 4~arguments)
5734 with respect to a Japanese font family given by the former 4~arguments.
5735 %</en>
5736 %<*ja>
5737 いわゆる「従属欧文」を設定するための命令である.前半の4引数で表される和文フォントファミリに対して,
5738 そのフォントに対応する「従属欧文」のフォントファミリを後半の4引数により与える.
5739 %</ja>
5740 \item[\cs{SetRelationFont}]
5741 %<*en>
5742 This command is almost same as \cs{DeclareRelationFont}, except that this command does a local
5743 assignment, where \cs{DeclareRelationFont} does a global assignment.
5744 %</en>
5745 %<*ja>
5746 このコマンドは \cs{DeclareRelationFont} とローカルな指定であることを除いて
5747 ほとんど同じである(\cs{DeclareRelationFont} はグローバル).
5748 %</ja>
5749
5750 \item[\cs{userelfont}]
5751 %<*en>
5752 Change current alphabetic font encoding/family/\dots\ to the `accompanied' alphabetic
5753              font family with respect to current Japanese font family,
5754              which was set by
5755              \cs{DeclareRelationFont} or \cs{SetRelationFont}.
5756 Like \cs{fontfamily}, \cs{selectfont} is required to take an effect.
5757 %</en>
5758 %<*ja>
5759 現在の欧文フォントのエンコーディング/ファミリ/…… を,
5760 \cs{DeclareRelationFont} か \cs{SetRelationFont} で指定された
5761 現在の和文フォントファミリに対応する「従属欧文」フォントファミリに変更する.
5762 \cs{fontfamily} のように,有効にするためには \cs{selectfont} が必要である.
5763 %</ja>
5764
5765 \item[\cs{adjustbaseline}]
5766 %<*en>
5767 In \pLaTeXe, \cs{adjustbaseline} sets \cs{tbaselineshift}
5768 to match the vertical center of ``M'' and that of ``あ''  in vertical typesetting:
5769 \[
5770 \text{\cs{tbaselineshift}} \leftarrow
5771 \frac{(h_{\text{M}}+d_{\text{M}}) - (h_{\text{あ}}+d_{\text{あ}})}2
5772   + d_{\text{あ}} - d_{\text{M}},
5773 \]
5774 where $h_{a}$~and~$d_{a}$ denote the height of ``$a$'' and the depth, respectively.
5775 In \LuaTeX-ja, this \cs{adjustbaseline} does same task.
5776 %</en>
5777 %<*ja>
5778 \pLaTeXe では,\cs{adjustbaseline} は縦組時に「M」と「あ」の中心線を一致させるために,
5779 \cs{tbaselineshift} を設定する役割を持っていた:
5780 \[
5781 \text{\cs{tbaselineshift}} \leftarrow
5782 \frac{(h_{\text{M}}+d_{\text{M}}) - (h_{\text{あ}}+d_{\text{あ}})}2
5783   + d_{\text{あ}} - d_{\text{M}},
5784 \]
5785 ここで,$h_{a}$,~$d_{a}$はそれぞれ「$a$」の高さ・深さを表す.
5786 \LuaTeX-jaにおいても\cs{adjustbaseline} は同様の処理を行っている.
5787 %</ja>
5788
5789 \item[\cs{fontfamily}\{<family>\}]
5790 %<*en>
5791 As in \LaTeXe, this command changes current font family (alphabetic, Japanese,~\emph{or both})
5792 to <family>. Which family will be changed is determined as follows:
5793 %</en>
5794 %<*ja>
5795 元々の\LaTeXe におけるものと同様に,このコマンドは現在のフォントファミリ(欧文,
5796 和文,\emph{もしくは両方})を<family>に変更する.
5797 どのファミリが変更されるかは以下のようにして決定される:
5798 %</ja>
5799 \begin{itemize}
5800 %<*en>
5801 \item Let current encoding scheme for Japanese fonts be
5802       <ja-enc>. Current Japanese font family will be changed to
5803       <family>, if one of the following two conditions is met:
5804 %</en>
5805 %<*ja>
5806 \item 現在の和文フォントに対するエンコーディングが<ja-enc>であるとしよう.
5807   現在の和文フォントファミリは,以下の2つの条件のうちの1つが満たされているときに
5808   <family>に変更される:
5809 %</ja>
5810 \begin{itemize}
5811 %<*en>
5812 \item The family <family> under the encoding <ja-enc> has been already defined by
5813       \cs{DeclareKanijFamily}.
5814 %</en>
5815 %<*ja>
5816 \item エンコーディング<ja-enc>におけるファミリ<family>が
5817 既に \cs{DeclareKanjiFamily} によって定義されている.
5818 %</ja>
5819 %<*en>
5820 \item A font definition named \texttt{<ja-enc><family>.fd} (the file name is
5821       all lowercase) exists.
5822 %</en>
5823 %<*ja>
5824 \item フォント定義ファイル\texttt{<ja-enc><family>.fd}(ファイル名は全て小文字)が存在する.
5825 %</ja>
5826 \end{itemize}
5827 %<*en>
5828 \item Let current encoding scheme for alphabetic fonts be
5829       <al-enc>. For alphabetic font family, the criterion as above is used.
5830 %</en>
5831 %<*ja>
5832 \item 現在の欧文フォントに対するエンコーディングを<al-enc>とする.
5833   欧文フォントファミリに対しても,上記の基準が用いられる.
5834 %</ja>
5835 %<*en>
5836 \item There is a case which none of the above applies, that is, the font
5837       family named <family> doesn't seem to be defined neither under the
5838       encoding <ja-enc>, nor under <al-enc>.
5839 In this case, the default family for font substitution is used for
5840       alphabetic and Japanese fonts. Note that current encoding will not
5841       be set to <family>, unlike the original implementation in \LaTeX.
5842 %</en>
5843 %<*ja>
5844 \item 上記のいずれもが適用されない,つまり<family>が<ja-enc>と<al-enc>の
5845   どちらでも定義されないような場合がある.
5846   この場合,代替フォントに用いられるデフォルトのフォントファミリが欧文フォントと
5847   和文フォントに用いられる.\LaTeX のオリジナルの実装とは異なり,
5848   現在のエンコーディングは<family>には設定されないことに注意する.
5849 %</ja>
5850 \end{itemize}%
5851 %<en>\vspace{-\medskipamount}
5852
5853
5854 \begin{figure}[!tb]
5855 \begin{LTXexample}[pos=b]
5856 \DeclareKanjiFamily{JY3}{edm}{}
5857 \DeclareFontShape{JY3}{edm}{m}{n}    {<-> s*KozMinPr6N-Regular:jfm=ujis;}{}
5858 \DeclareFontShape{JY3}{edm}{m}{green}{<-> s*KozMinPr6N-Regular:jfm=ujis;color=007F00}{}
5859 \DeclareFontShape{JY3}{edm}{m}{blue} {<-> s*KozMinPr6N-Regular:jfm=ujis;color=0000FF}{}
5860 \DeclareAlternateKanjiFont{JY3}{edm}{m}{n}{JY3}{edm}{m}{green}{"4E00-"67FF,{-2}-{-2}}
5861 \DeclareAlternateKanjiFont{JY3}{edm}{m}{n}{JY3}{edm}{m}{blue}{ "6800-"9FFF}
5862 {\kanjifamily{edm}\selectfont
5863 日本国民は、正当に選挙された国会における代表者を通じて行動し、……}
5864 \end{LTXexample}
5865 %<ja>\caption{\cs{DeclareAlternateKanjiFont} の使用例}
5866 %<en>\caption{An example of \cs{DeclareAlternateKanjiFont}}
5867 \label{fig:altkanji}
5868 \end{figure}
5869
5870 \item[\cs{DeclareAlternateKanjiFont}\{<base-encoding>\}\{<base-family>\}\{<base-series>\}\{<base-shape>\}\\
5871   \null\hfill\{<alt-encoding>\}\{<alt-family>\}\{<alt-series>\}\{<alt-shape>\}\{<range>\}]
5872 %<*ja>
5873 \ref{ssec-altfont}節の\
5874 \cs{ltjdeclarealtfont} と同様に,前半の4引数の
5875 和文フォント(基底フォント)のうち<range>中の文字を
5876 第5から第8引数の和文フォントを使って組むように指示する.
5877 使用例を図\nobreak\ref{fig:altkanji}に載せた.
5878
5879 \begin{itemize}
5880  \item
5881 \cs{ltjdeclarealtfont} では基底フォント・置き換え先和文フォントはあらかじめ定義されてい
5882              ないといけない(その代わり即時発効)であったが,
5883 \cs{DeclareAlternateKanjiFont} の設定が
5884 実際に効力が発揮するのは,書体変更やサイズ変更を行った時,
5885 あるいは(これらを含むが)\cs{selectfont} が実行された時である.
5886  \item
5887 段落やhboxの最後での設定値が段落/hbox全体にわたって通用する点や,
5888 <range>に負数$-n$を指定した場合,それが「基底フォントの文字クラス$n$に属する文字全体」
5889 と解釈されるのは \cs{ltjdeclarealtfont} と同じである.
5890 \end{itemize}%
5891 %</ja>
5892 %<*en>
5893 As \cs{ltjdeclarealtfont}~(Subsection~\ref{ssec-altfont}),
5894 characters in <range> of the Japanese font (we say the \emph{base font})
5895 which specified by first 4 arguments are typeset
5896 by the Japanese font which specified by fifth to eighth arguments
5897 (we say the \emph{alternate font}).
5898 An example is shown in Figure~\ref{fig:altkanji}.
5899
5900 \begin{itemize}
5901  \item
5902 In \cs{ltjdeclarealtfont}, the base font and the alternate font must be already defined.
5903 But this \cs{DeclareAlternateKanjiFont} is not so.
5904 In other words, \cs{DeclareAlternateKanjiFont} is effective only after
5905 current Japanese font is changed, or only after \cs{selectfont} is executed.
5906  \item \dots
5907 \end{itemize}%
5908 \vspace{-\medskipamount}
5909 %</en>
5910 \end{cslist}
5911
5912 %<*en>
5913 As closing this subsection, we shall introduce an example of
5914 \cs{SetRelationFont} and \cs{userelfont}:
5915 %</en>
5916 %<*ja>
5917 この節の終わりに,\cs{SetRelationFont} と \cs{userelfont} の例を
5918 紹介しておこう.\cs{userelfont} の使用によって,「abc」の部分のフォントが
5919 Avant Garde (OT1/pag/m/n) に変わっていることがわかる.
5920 %</ja>
5921 \begin{LTXexample}[width=0.3\textwidth]
5922 \makeatletter
5923 \SetRelationFont{JY3}{\k@family}{m}{n}{OT1}{pag}{m}{n}
5924   % \k@family: current Japanese font family
5925 \userelfont\selectfont あいうabc
5926 \end{LTXexample}
5927
5928 %<*en>
5929 \section{Addons}
5930 \LuaTeX-ja has several addon packages.
5931 These addons are written as \LaTeX\ packages, but
5932 \Pkg{luatexja-otf} and~\Pkg{luatexja-adjust} can be loaded in plain \LuaTeX\
5933 by \cs{input}.
5934 %</en>
5935 %<*ja>
5936 \section{拡張}
5937 \LuaTeX-jaには(動作には必須ではないが)自由に読み込める拡張が付属している.
5938 これらは\LaTeX のパッケージとして制作しているが,
5939 \Pkg{luatexja-otf}と\Pkg{luatexja-adjust}についてはplain \LuaTeX でも\
5940 \cs{input} で読み込み可能である.
5941 %</ja>
5942 \subsection{\texttt{luatexja-fontspec.sty}}
5943 \label{ssec-fontspec2}
5944 %<*en>
5945 As described in Subsection~\ref{ssec-fontspec}, this optional package
5946 provides the counterparts for several commands defined in the
5947 \Pkg{fontspec} package (requires \Pkg{fontspec}~v2.4).
5948 In addition to OpenType font features in the original \Pkg{fontspec},
5949 the following ``font features'' specifications are allowed for
5950 the commands of Japanese version:
5951 %</en>
5952 %<*ja>
5953 \ref{ssec-fontspec}節で述べたように,この追加パッケージは\Pkg{fontspec}
5954 パッケージで定義されているコマンドに対応する和文フォント用のコマンドを提供する.
5955 \emph{以下に述べる和文版の命令の説明は \Pkg{fontspec}~v2.4 使用時にのみ当てはまる.}
5956
5957 \Pkg{fontspec}パッケージで指定可能な各種font featureに加えて,和文版のコマンドには
5958 以下の``font feature''を指定することができる:
5959 %</ja>
5960
5961
5962 \begin{cslist}
5963 \item[CID=<name>\textrm{, }JFM=<name>\textrm{, }JFM-var=<name>]
5964
5965 %<*en>
5966 These 3 keys correspond to \texttt{cid}, \texttt{jfm} and
5967 \texttt{jfmvar} keys for \cs{jfont}~and~\cs{tfont} respectively.
5968 See Subsections~\ref{ssec-jfont} and \ref{ssec-psft} for details
5969  of \texttt{cid}, \texttt{jfm} and
5970 \texttt{jfmvar} keys.
5971
5972 The \texttt{CID} key is effective only when with \texttt{NoEmbed}
5973 described below. The same JFM cannot be used in both horizontal Japanese fonts and
5974              vertical Japanese fonts, hence the \texttt{JFM} key
5975 will be actually used in \texttt{YokoFeatures}~and~\texttt{TateFeatures} keys.
5976 %</en>
5977 %<*ja>
5978 これら3つのキーはそれぞれ \cs{jfont},~\cs{tfont}に対する
5979 \texttt{cid}, \texttt{jfm}, \texttt{jfmvar}キーとそれぞれ対応する.
5980 \texttt{cid}, \texttt{jfm}, \texttt{jfmvar}キーの詳細は\ref{ssec-jfont}節
5981              と\ref{ssec-psft}節を参照.
5982
5983 \texttt{CID} キーは下の \texttt{NoEmbed} と合わせて用いられたときのみ有効である.
5984 また,横組用JFMと縦組用JFMは共用できないため,実際に \texttt{JFM} キーを用いる際は
5985 後に述べる\ \texttt{YokoFeatures} キーや \texttt{TateFeatures}\ の中で用いる
5986 ことになる.
5987 %</ja>
5988
5989 \item[NoEmbed]
5990 %<*en>
5991 By specifying this key, one can use ``name-only'' Japanese font which
5992 will not be embedded in the output PDF file. See Subsection~\ref{ssec-psft}.
5993 %</en>
5994 %<*ja>
5995 これを指定することで,PDFに埋め込まれない「名前だけ」のフォントを指定することが
5996 できる.\ref{ssec-psft}節を参照.
5997 %</ja>
5998
5999 \begin{figure}[!tb]
6000 \begin{LTXexample}
6001 \jfontspec[
6002   YokoFeatures={Color=007F00},
6003   TateFeatures={Color=00007F},
6004   TateFont=KozGoPr6N-Regular
6005 ]{KozMinPr6N-Regular}
6006 \hbox{\yoko 横組のテスト}
6007 \hbox{\tate 縦組のテスト}
6008 \end{LTXexample}
6009 %<ja>\caption{\texttt{TateFeatures} 等の使用例}
6010 %<en>\caption{An example of \texttt{TateFeatures} etc.}
6011 \label{fig:yokotate-fontspec}
6012 \end{figure}
6013
6014
6015 \item[TateFeatures=\{<features>\}\textrm{, }TateFont=<font>]
6016 %<en> ...
6017 %<*ja>
6018 縦組において使用されるフォントや,縦組においてのみ適用されるfeature達を
6019 指定する.使用例は図\ref{fig:yokotate-fontspec}参照.
6020 %</ja>
6021
6022 \item[YokoFeatures=\{<features>\}]
6023 %<en> ...
6024 %<*ja>
6025 横組においてのみ適用されるfeature達を
6026 指定する.使用例は図\ref{fig:yokotate-fontspec}参照.
6027 %</ja>
6028
6029
6030 \begin{figure}[!tb]
6031 \begin{LTXexample}[pos=b]
6032 \jfontspec[
6033   AltFont={
6034     {Range="4E00-"67FF, Color=007F00},
6035     {Range="6800-"9EFF, Color=0000FF},
6036     {Range="3040-"306F, Font=KozGoPr6N-Regular},
6037   }
6038 ]{KozMinPr6N-Regular}
6039 日本国民は、正当に選挙された国会における代表者を通じて行動し、われらとわれらの子孫のために、
6040 諸国民との協和による成果と、わが国全土にわたつて自由のもたらす恵沢を確保し、……
6041 \end{LTXexample}
6042 %<ja>\caption{\texttt{AltFont} の使用例}
6043 %<en>\caption{An example of \texttt{AltFont}}
6044 \label{fig:altkanji-fontspec}
6045 \end{figure}
6046
6047 \item[AltFont]
6048
6049 %<*en>
6050 As \cs{ltjdeclarealtfont}~(Subsection~\ref{ssec-altfont}) and
6051 \cs{DeclareAlternateKanjiFont}~(Subsection~\ref{ssec-nfsspat}),
6052 with this key, one can typeset some Japanese characters
6053 by a different font and/or using different features.
6054 The \texttt{AltFont} feature takes a comma-separated list of comma-separated lists,
6055 as the following:
6056 %</en>
6057 %<*ja>
6058 \ref{ssec-altfont}節の \cs{ltjdeclarealtfont} や,
6059 \ref{ssec-nfsspat}節の \cs{DeclareAlternateKanjiFont} と同様に,
6060 このキーを用いると一部の文字を異なったフォントやfont featureを使って組むことができる.
6061 \texttt{AltFont} キーに指定する値は,次のように二重のコンマ区切りリストである:
6062 %</ja>
6063 \begin{lstlisting}[escapechar=\#]
6064 AltFont = {
6065   ...
6066   { Range=#\LARG range>#, #\LARG features>#},
6067   { Range=#\LARG range>#, Font=#\LARG font~name>#, #\LARG features># },
6068   { Range=#\LARG range>#, Font=#\LARG font~name># },
6069   ...
6070 }
6071 \end{lstlisting}
6072 %<*en>
6073 Each sublist should have the \texttt{Range} key
6074 (sublist which does not contain \texttt{Range} key is simply ignored).
6075 A demonstrarion is shown in Figure~\ref{fig:altkanji-fontspec}.
6076 %</en>
6077 %<*ja>
6078 各部分リストには \texttt{Range} キーが必須である(含まれない部分リストは
6079 単純に無視される).指定例は図\ref{fig:altkanji-fontspec}に示した.
6080 %</ja>
6081 \end{cslist}
6082
6083 %<*ja>
6084 なお,\Pkg{luatexja-fontspec} 読み込み時には和文フォント定義ファイル%
6085 \texttt{<ja-enc><family>.fd}は全く参照されなくなる.
6086 %</ja>
6087
6088
6089 %<*en>
6090 \paragraph{Remark on \texttt{AltFont}, \texttt{YokoFeatures}, \texttt{TateFeatures} keys}
6091 In \texttt{AltFont},~\texttt{YokoFeatures},~\texttt{TateFeatures} keys,
6092 one cannot specify per-shape settings such as \texttt{BoldFeatures}.
6093 For example,
6094 \begin{lstlisting}
6095 AltFont = {
6096   { Font=HogeraMin-Light, BoldFont=HogeraMin-Bold,
6097     Range="3000-"30FF, BoldFeatures={Color=007F00} }
6098 }
6099 \end{lstlisting}
6100 does \emph{not} work. Instead, one have to write
6101 \begin{lstlisting}
6102 UprightFeatures = {
6103   AltFont = { { Font=HogeraMin-Light, Range="3000-"30FF, } },
6104 },
6105 BoldFeatures = {
6106   AltFont =  { { Font=HogeraMin-Bold, Range="3000-"30FF, Color=007F00 } },
6107 }
6108 \end{lstlisting}
6109
6110 On the other hand, \texttt{YokoFeatures}, \texttt{TateFeatures} and  \texttt{TateFont}
6111 keys can be specified in each list in the \texttt{AltFont} key. Also,
6112 one can specify \texttt{AltFont} inside \texttt{YokoFeatures},~\texttt{TateFeatures}.
6113 %</en>
6114 %<*ja>
6115 \paragraph{\texttt{AltFont}, \texttt{YokoFeatures}, \texttt{TateFeatures} 等の制限}
6116 \texttt{AltFont},~\texttt{YokoFeatures},~\texttt{TateFeatures}の各キーは
6117 シェイプ別に指定されるべきものであり,
6118 内部では \texttt{BoldFeatures} などのシェイプ別の指定は行うことが出来ない.
6119 例えば.
6120 \begin{lstlisting}
6121 AltFont = {
6122   { Font=HogeraMin-Light, BoldFont=HogeraMin-Bold,
6123     Range="3000-"30FF, BoldFeatures={Color=007F00} }
6124 }
6125 \end{lstlisting}
6126 のように指定することは出来ず,
6127 \begin{lstlisting}
6128 UprightFeatures = {
6129   AltFont = { { Font=HogeraMin-Light, Range="3000-"30FF, } },
6130 },
6131 BoldFeatures = {
6132   AltFont =  { { Font=HogeraMin-Bold, Range="3000-"30FF, Color=007F00 } },
6133 }
6134 \end{lstlisting}
6135 のように指定しなければならない.
6136
6137 一方,\texttt{AltFont} キー内の各リストでは
6138 \ \texttt{YokoFeatures},~\texttt{TateFeatures} 及び \texttt{TateFont} キーを
6139 指定することは可能であり.また\ \texttt{YokoFeatures},~\texttt{TateFeatures} キーの
6140 中身に \texttt{AltFont} を指定することができる.
6141 %</ja>
6142
6143
6144 \subsection{\texttt{luatexja-otf.sty}}
6145 \label{ssec-ltjotf}
6146 %<*en>
6147 This optional package supports typesetting characters in
6148 Adobe-Japan1 character collection
6149 (or other CID character collection, if the font is supported).
6150 The package \Pkg{luatexja-otf} offers the following 2~low-level
6151 commands:
6152 %</en>
6153 %<*ja>
6154 この追加パッケージはAdobe-Japan1(フォント自身が持っていれば,
6155 別のCID文字セットでも可)の文字の出力をサポートする.
6156 \Pkg{luatexja-otf}は以下の2つの低レベルコマンドを提供する:
6157 %</ja>
6158 \begin{cslist}
6159 \item[\cs{CID}\{<number>\}]
6160 %<*en>
6161 Typeset a character whose CID number is <number>.
6162 %</en>
6163 %<*ja>
6164 CID番号が<number>の文字を出力する.
6165 %</ja>
6166
6167 \item[\cs{UTF}\{<hex\_number>\}]
6168 %<*en>
6169 Typeset a character whose character code is <hex\_number> (in hexadecimal).
6170 This command is similar to \verb+\char"+<hex\_number>,\ %"
6171 but please remind remarks below.
6172 %</en>
6173 %<*ja>
6174 文字コードが(16進で)<hex\_number>の文字を出力する.
6175 このコマンドは \verb+\char"+<hex\_number>と似ているが,下の記述に注意すること.%"
6176 %</ja>
6177 \end{cslist}
6178
6179 %<*ja>
6180 このパッケージは,\texttt{ajmacros.sty}(\Pkg{otf}パッケージ付属のマクロ集,井上浩一氏作)から
6181 漢字コードをUTF8にしたり,plain \LuaTeX でも利用可能にするという
6182 修正を加えた \texttt{luatexja-ajmacros.sty} も自動的に読み込む.
6183 そのため,\texttt{ajmacros.sty} マクロ集にある \verb+\aj半角+ などのマクロもそのまま使用可能である.
6184 %</ja>
6185
6186 %<en>\paragraph{Remarks}
6187 %<ja>\paragraph{注意}
6188 %<*en>
6189 Characters by \cs{CID} and \cs{UTF} commands are different from
6190 ordinary characters in the following points:
6191 %</en>
6192 %<*ja>
6193 \cs{CID} と \cs{UTF} コマンドによって出力される文字は
6194 以下の点で通常の文字と異なる:
6195 %</ja>
6196 \begin{itemize}
6197 %<*en>
6198 \item Always treated as \textbf{JAchar}s.
6199 %</en>
6200 %<*ja>
6201 \item 常に\textbf{JAchar}として扱われる.
6202 %</ja>
6203 %<*en>
6204 \item Processing codes for supporting OpenType features (\textit{e.g.},
6205       glyph replacement and kerning) by the \Pkg{luaotfload} package
6206       is not performed to these characters.
6207 %</en>
6208 %<*ja>
6209 \item OpenType feature(例えばグリフ置換やカーニング)をサポートするための
6210   \Pkg{luaotfload}パッケージのコードはこれらの文字には働かない.
6211 %</ja>
6212 \end{itemize}
6213
6214 %<en>\paragraph{Additional syntax of JFM}
6215 %<ja>\paragraph{JFMへの記法の追加}
6216
6217 %<*en>
6218 The package \Pkg{luatexja-otf} extends the syntax of JFM; the entries of \texttt{
6219 chars} table in JFM now allows a string in the form
6220 \verb+'AJ1-xxx'+, which stands for the character
6221 whose CID number in Adobe-Japan1 is \verb+xxx+.
6222
6223 This extended notation is used in the standard JFM \texttt{jfm-ujis.lua}
6224 to typeset halfwidth Hiragana glyphs (CID~516--598) in halfwidth.
6225 %</en>
6226 %<*ja>
6227 \Pkg{luatexja-otf}パッケージを読み込むと,
6228 JFMの\texttt{chars}テーブルのエントリとして \verb+'AJ1-xxx'+ の形の文字列が
6229 使えるようになる.これはAdobe-Japan1におけるCID番号が \verb+xxx+ の文字を表す.
6230
6231 この拡張記法は,標準JFM~\texttt{jfm-ujis.lua}で,半角ひらがなのグリフ(CID~516--598)を
6232 正しく半角幅で組むために利用されている.
6233 %</ja>
6234
6235 %<*en>
6236 \paragraph{IVS support}
6237 Recent fonts support Ideographic Variation Selector (IVS).
6238 It seems that \Pkg{luaotfload} and \Pkg{fontspec} packages do not support
6239 IVS, so we implemented IVS support in \Pkg{luatexja-otf}.
6240 \emph{IVS support is experimental; if you want to enable this, load
6241 \Pkg{luatexja-otf} and execute the following:}
6242 %</en>
6243 %<*ja>
6244 \paragraph{IVSサポート}
6245 最近のOpenTypeフォントやTrueTypeフォントには,
6246 \texttt{U+E0100}--\texttt{U+E01EF}の範囲の「文字」
6247 (漢字用異体字セレクタ)を後置することによって
6248 字形を指定する仕組み(IVS)が含まれている.
6249 執筆時点の2013年12月では,\Pkg{luaotfload}や\Pkg{fontspec}パッケージ類は
6250 IVSに対応してはいないようである.これらのパッケージで対応してくれるのが理想的だが,
6251 それまでのつなぎとして,\Pkg{luatexja-otf}パッケージ内にIVS対応を仕込んでおいた.
6252
6253 \medskip
6254
6255 \emph{IVS対応は試験的なものである.
6256 有効にするには,\Pkg{luatexja-otf}パッケージを読み込んだ上で以下の命令を実行する%
6257 \footnote{この命令を2回以上実行しても意味がない.}:}
6258 %</ja>
6259 \begin{lstlisting}
6260 \directlua{luatexja.otf.enable_ivs()}
6261 \end{lstlisting}
6262 %<ja> すると,上の命令を実行した箇所以降では,以下のようにIVSによる字形指定が有効となる.
6263 %<en> After executing the command above, you can use IVS like the following:
6264 \begin{LTXexample}
6265 \Large
6266 \jfontspec{KozMinPr6N-Regular}
6267 奈良県葛󠄀城市と,東京都葛󠄁飾区.\\
6268 こんにちは,渡
6269 邉󠄀邉󠄁邉󠄂邉󠄃邉󠄄
6270 邉󠄅邉󠄆邉󠄇邉󠄈邉󠄉
6271 邉󠄊邉󠄋邉󠄌邉󠄍邉󠄎
6272 さん.
6273 \end{LTXexample}
6274 %<*ja>
6275 左上側の入力においては,漢字用異体字セレクタを明示するため,
6276 例えばVariation~Selector~18 (\texttt{U+E0101})を\IVSB{18}のように表記している.
6277 %</ja>
6278 \medskip
6279
6280 %<*en>
6281 Specifying glyph variants by IVS precedes glyph replacement by font features.
6282 For example, only ``葛'' in ``葛西'' is changed by font features
6283 \texttt{jp78}~or~\texttt{jp90}, which does not followed by any variation selector.
6284 %</en>
6285 %<*ja>
6286 また,IVSによる字形指定は,font featureによるそれに優先されることとした.
6287 下の例において,\texttt{jp78}, \texttt{jp90} 指定で字形が変化した文字は
6288 異体字セレクタが続いていない「葛西」中の「葛」のみである.
6289 %</ja>
6290 \begin{LTXexample}
6291  \def\TEST#1{%
6292    {\jfontspec[#1]{KozMinPr6N-Regular}%
6293    葛󠄀城市,葛󠄁飾区,葛西}\\}
6294  指定なし:\TEST{}
6295  \texttt{jp78}:\TEST{CJKShape=JIS1978}
6296  \texttt{jp90}:\TEST{CJKShape=JIS1990}
6297 \end{LTXexample}
6298
6299 %<*ja>
6300 現状では,\TeX 側のインターフェースとなる \Pkg{luatexja-otf.sty} は一切変更していない
6301 ので,ZRさんによる\Pkg{PXipamjm}パッケージ%
6302 \footnote{\url{https://github.com/zr-tex8r/PXipamjm}. 説明は彼のブログ記事
6303 「pxipamjm パッケージの説明書のような何か(\url{http://d.hatena.ne.jp/zrbabbler/20131221})」
6304 にある.}
6305 にあるような気の利いた命令はまだない.
6306 異体字の一覧表示を行いたい場合は,gitリポジトリ内の \texttt{test/test19-ivs.tex} 中にある
6307 Lua・\TeX コードが参考になるだろう.
6308 %</ja>
6309
6310
6311 \subsection{\texttt{luatexja-adjust.sty}}
6312 \label{ssec-adj}
6313 \begin{figure}[t]
6314 \def\sq{%
6315   \hbox to 1\zw{\hss\fboxsep=-.5\fboxrule\fbox{%
6316    \hskip\dimexpr-.5\zw-.2pt\vrule width.4pt height.08\zw depth.12\zw%
6317   \hskip\dimexpr.5\zw-.2pt\relax}\hss}}
6318 \def\sb{\hbox to 1\zw{\hss\fboxsep=-.5\fboxrule\fbox{%
6319   ■\hskip\dimexpr-.5\zw-.2pt\vrule width.4pt height.08\zw depth.12\zw%
6320   \hskip\dimexpr.5\zw-.2pt\relax}\hss}}
6321 \newbox\gridbox
6322 \def\outbox#1{{\Large%
6323   \ltjsetparameter{kanjiskip=0pt plus .2\zw minus .2\zw}%
6324   \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}%
6325   \hbox{\textcolor{cyan}{\copy\gridbox}\hskip-20\zw%
6326   \vbox{\hsize=20\zw\noindent\leftskip0pt\rightskip0pt\parfillskip0pt#1}\vrule}%
6327 }}
6328
6329 {\centering
6330 \begin{tabular}{lc}
6331 \toprule
6332 no adjustment&\outbox{以上の原理は,「包除原理」とよく呼ばれるが\hskip-.5\zw\null}\\
6333 without priority&%
6334 \ltjdisableadjust
6335 \outbox{以上の原理は,「包除原理」とよく呼ばれるが}%
6336 \ltjenableadjust\\
6337 with priority&%
6338 \outbox{以上の原理は,「包除原理」とよく呼ばれるが}
6339 %<en>\ltjdisableadjust
6340 \\
6341 \bottomrule
6342 \end{tabular}\par}
6343 \smallskip
6344
6345 Note: the value of
6346 \Param{kanjiskip} is 0\,pt${}^{+1/5\,\mathrm{em}}_{-1/5\,\mathrm{em}}$ in this figure,
6347 for making the difference obvious.
6348 %<ja>\caption{行長調整}\label{fig-adj}
6349 %<en>\caption{Line adjustment}\label{fig-adj}
6350 \end{figure}
6351
6352
6353 %<*en>
6354 (see Japanese version of this manual)
6355 %</en>
6356 %<*ja>
6357 \pTeX では,行長調整において優先度の概念が存在しなかったため,図
6358 \ref{fig-adj}上段における半角分の半端は,図\ref{fig-adj}中段のように,鍵
6359 括弧周辺の空白と和文間空白(\Param{kanjiskip})の両方によって負担される.し
6360 かし,「日本語組版処理の要件」\cite{jlreq}やJIS~X~4051~\cite{x4051}におい
6361 ては,このような状況では半端は鍵括弧周辺の空白のみで負担し,その他の和文
6362 文字はベタ組で組まれる(図\ref{fig-adj}下段)ことになっている.この追加
6363 パッケージは\cite{jlreq}や\cite{x4051}における規定のような,優先順位付き
6364 の行長調整を提供する.詳細な仕様については\ref{sec-adjspec}章を参照してほしい.
6365 \begin{itemize}
6366  \item 優先度付き行長調整は,段落を行分割した後に個々の行について行われるものである.
6367 そのため,行分割の位置は変化することはない.
6368
6369 また,\verb+\hbox to ... {...}+ のような「幅が指定されたhbox」では無効である.
6370  \item 優先度付き行長調整を行うと,和文処理グルーの自然長は変化しないが,伸び量や縮み量は
6371 一般に変化する.そのため,既に組まれた段落を \cs{unhbox} などを利用して組み直す処理を
6372 行う場合には注意が必要である.
6373 \end{itemize}
6374
6375
6376 \Pkg{luatexja-adjust} は,以下の命令を提供する.これらはすべてグローバルに効力を発揮する.
6377
6378 \begin{cslist}
6379 \item[\cs{ltjdisableadjust}]
6380 優先順位付きの行長調整を無効化する.
6381
6382 \item[\cs{ltjenableadjust}]
6383 優先順位付きの行長調整を有効化する.
6384
6385 \item[\textsf{adjust}\,=<bool>] \cs{ltjsetparameter} で指定可能な追加パラメータであり,
6386 <bool>が\textit{true}なら \cs{ltjenableadjust} を,
6387 そうでなければ \cs{ltjdisableadjust} を実行する.
6388 \end{cslist}
6389 %</ja>
6390
6391 \subsection{\texttt{luatexja-ruby.sty}}
6392 %<*en>
6393 This addon package provides functionality of ``ruby'' (\emph{furigana}) annotations
6394 using callbacks of \LuaTeX-ja.
6395 There is no detailed manual of \Pkg{luatexja-ruby.sty} in English.
6396 (Japanese manual is another PDF file, \url{luatexja-ruby.pdf}.)
6397 %</en>
6398 %<*ja>
6399 この追加パッケージは,\LuaTeX-jaの機能を利用したルビ(振り仮名)の組版機能を提供する.
6400 前後の文字種に応じた前後への自動進入や,
6401 行頭形・行中形・行末形の自動的な使い分けが特徴である.
6402
6403 ルビ組版に設定可能な項目や注意事項が多いため,本追加パッケージの詳細な説明は
6404 使用例と共に \url{luatexja-ruby.pdf}\ という別ファイルに載せている.
6405 この節では簡単な使用方法のみ述べる.
6406 %</ja>
6407
6408 \begin{description}
6409 %<*en>
6410  \item[Group-ruby]
6411 By default, ruby characters (the second argument of \cs{ruby})
6412 are attached to base characters (the first argument), as one object.
6413 This type of ruby is called \emph{group-ruby}.
6414 %</en>
6415 %<*ja>
6416  \item[グループルビ] 標準ではグループルビの形で組まれる.第1引数に親文字,
6417 第2引数にルビを記述する.
6418 %</ja>
6419 \begin{LTXexample}[width=0.3\textwidth]
6420 東西線\ruby{妙典}{みようでん}駅は……\\
6421 東西線の\ruby{妙典}{みようでん}駅は……\\
6422 東西線の\ruby{妙典}{みようでん}という駅……\\
6423 東西線\ruby{葛西}{かさい}駅は……
6424 \end{LTXexample}
6425 %<*en>
6426 As the above example, ruby hangover is allowed on the Hiragana before/after
6427 its base characters.
6428 %</en>
6429 %<ja> この例のように,標準では前後の平仮名にルビ全角までかかるようになっている.
6430
6431 %<*en>
6432 \item[Mono-ruby]
6433 To attach ruby characters to each base characters (\emph{mono-ruby}),
6434 one should use \cs{ruby} multiple times:
6435 %</en>
6436 %<*ja>
6437  \item[モノルビ] 親文字を1文字にするとモノルビとなる.
6438 2文字以上の熟語をモノルビの形で組みたい場合は,面倒でも
6439 その数だけ \cs{ruby} を書く必要がある.
6440 %</ja>
6441 \begin{LTXexample}[width=0.3\textwidth]
6442 東西線の\ruby{妙}{みよう}\ruby{典}{でん}駅は……
6443 \end{LTXexample}
6444
6445 %<*en>
6446  \item[Jukugo-ruby]
6447 Vertical bar~\verb+|+ denotes a boundary of \emph{groups}.
6448 %</en>
6449 %<*ja>
6450  \item[熟語ルビ] 引数内の縦棒 \verb+|+ はグループの区切りを表し,
6451 複数グループのルビは熟語ルビとして組まれる.
6452 \cite{x4051}にあるように,
6453 どのグループでも「親文字」が対応するルビ以上の長さの場合は
6454 各グループごとに,そうでないときは全体をまとめて1つのグループルビとして組まれる.
6455 \cite{jlreq}で規定されている組み方とは異なるので注意.
6456 %</ja>
6457 \begin{LTXexample}
6458 \ruby{妙|典}{みよう|でん}\
6459 \ruby{葛|西}{か|さい}\
6460 \ruby{神楽|坂}{かぐら|ざか}
6461 \end{LTXexample}
6462 %<*en>
6463 If there are multiple groups in one \cs{ruby} call,
6464 A linebreak between two groups is allowed.
6465 %</en>
6466 %<ja> 複数ルビではグループとグループの間で改行が可能である.
6467 \begin{LTXexample}[width=0.3\textwidth]
6468 \vbox{\hsize=6\zw\noindent
6469   \hbox to 2.5\zw{}\ruby{京|急|蒲|田}{けい|きゆう|かま|た}
6470   \hbox to 2.5\zw{}\ruby{京|急|蒲|田}{けい|きゆう|かま|た}
6471   \hbox to   3\zw{}\ruby{京|急|蒲|田}{けい|きゆう|かま|た}
6472 }
6473 \end{LTXexample}
6474 \end{description}
6475
6476 %<*en>
6477 If the width of ruby characters are longer than that of base characters,
6478 \cs{ruby} automatically selects the appropriate form
6479 among the line-head form, the line-middle form, and the line-end form.
6480 %</en>
6481 %<*ja>
6482 また,ルビ文字のほうが親文字よりも長い場合は,自動的に
6483 行頭形・行中形・行末形のいずれか適切なものを選択する.
6484 %</ja>
6485 \begin{LTXexample}[width=0.3\textwidth]
6486 \vbox{\hsize=8\zw\noindent
6487 \null\kern3\zw ……を\ruby{承}{うけたまわ}る
6488      \kern1\zw ……を\ruby{承}{うけたまわ}る\\
6489 \null\kern5\zw ……を\ruby{承}{うけたまわ}る
6490 }
6491 \end{LTXexample}
6492
6493
6494 %<*ja>
6495 \subsection{\texttt{lltjext.sty}}
6496 \pLaTeX では縦組用の拡張として \Pkg{plext} パッケージが用意されていたが,
6497 それを\LuaTeX-ja用に書きなおしたものが本追加パッケージ \Pkg{lltjext} である.
6498
6499 従来の \Pkg{plext} パッケージとの違いは,
6500 {\catcode`\<=12
6501 \begin{itemize}
6502  \item 組方向オプション \texttt{<y>}(横組),\texttt{<t>}(縦組),
6503 \texttt{<z>}\ の他に\ \texttt{<d>}(dtou方向),\texttt{<u>}(utod方向)を追加した.
6504 \texttt{<z>} と \texttt{<u>} の違いは,\texttt{<z>} が(\Pkg{plext} パッケージと同様に)
6505 周囲の組方向が縦組のときにしか意味を持たない
6506        のに対し,\texttt{<u>} にはそのような制限がないことである.
6507
6508  \item \Pkg{plext} パッケージでは,表組(\texttt{tabular} 環境,\texttt{align} 環境等)や
6509 \texttt{minipage} 環境,\cs{parbox} 命令において,
6510 垂直位置指定 \texttt{[t]},~\texttt{[b]} の挙動が非読み込み時と微妙に変わることがあった.
6511
6512 \Pkg{lltjext} パッケージでは,垂直位置指定が\LaTeXe と同様の挙動(以下に示す)に
6513 なるように修正した.
6514 \begin{itemize}
6515  \item \texttt{[t]} オプション指定時は,ボックスのベースラインが中身の1行目のベースライン
6516        (1行目の上に罫線などが来た時は,ボックスの上端)に一致するように配置する.
6517  \item \texttt{[b]} オプション指定時は,ボックスのベースラインが中身の最終行のベースライン
6518        (中身の最後が罫線などの時は,ボックスの下端)に一致するように配置する.
6519  \item それ以外のときは,ボックスの中央が「数式の軸」に一致するように配置する.
6520 \end{itemize}
6521
6522  \item 連数字用命令 \cs{rensuji} における位置合わせオプション \texttt{[l]}, \texttt{[c]},
6523        \texttt{[r]} の挙動を若干変更した.
6524
6525 \end{itemize}
6526 }
6527 %</ja>
6528 %<*en>
6529 \subsection{\texttt{lltjext.sty}}
6530 \pLaTeX\ supplies additional macros for vertical writing in the \Pkg{plext} package.
6531 The \Pkg{lltjext} package which we want to describe here is the \LuaTeX-ja
6532 counterpart of the \Pkg{plext} package.
6533 %</en>
6534
6535 %<*ja>
6536 念の為,本 \Pkg{lltjext} パッケージで追加・変更している命令の一覧を載せておく.
6537 \begin{cslist}
6538 \item[tabular\textrm{, }array\textrm{, }minipage環境]
6539 これらの環境は,
6540 \begin{lstlisting}
6541 \begin{tabular}<dir>[pos]{table spec} ... \end{tabular}
6542 \begin{array}<dir>[pos]{table spec}   ... \end{array}
6543 \begin{minipage}<dir>[pos]{width}     ... \end{minipage}
6544 \end{lstlisting}
6545 のように,組方向オプション \texttt{\<dir\>} が拡張されている.
6546 既に述べたように,組方向オプションに指定できる値は以下の5つであり,
6547 それ以外を指定した時や無指定時は周囲の組方向と同じ組方向になる.
6548 \begin{description}
6549  \item[y] 横組(\cs{yoko})
6550  \item[t] 縦組(\cs{tate})
6551  \item[z] 周囲が縦組の時はutod方向,それ以外はそのまま
6552  \item[d] dtou方向
6553  \item[u] utod方向
6554 \end{description}
6555 \item[\cs{parbox}\<<dir>\>{[<pos>]}\{<width>\}\{<contents>\}]
6556 \cs{parbox} 命令も同様に,組方向の指定ができるように拡張されている.
6557
6558 \item[\cs{pbox}\<<dir>\>{[<width>][<pos>]}\{<contents>\}]
6559 組方向<dir>で<contents>の中身をLRモードで組む命令である.
6560 <width>が正の値であるときは,ボックス全体の幅がその値となる.
6561 その際,中身は<pos>の値に従い,左寄せ(\texttt{l}),右揃え(\texttt{r}),
6562 中央揃え(それ以外)される.
6563 \item[picture環境]
6564 図表作成に用いる \texttt{picture} 環境も,
6565 \begin{lstlisting}
6566 \begin{picture}<dir>(x_size, y_size)(x_offset,y_offset)
6567   ...
6568 \end{picture}
6569 \end{lstlisting}
6570 と組方向が指定できるように拡張されている.
6571 $x$成分の増加方向は字送り方向,$y$成分の増加方向は行送り方向の\emph{反対方向}となる.
6572 \Pkg{plext} パッケージと同様に
6573 内部ではベースライン補正(\Param{yalbaselineshift}パラメータなど)の影響を受けないように,
6574 \cs{put},~\cs{line}, \cs{vector}, \cs{dashbox}, \cs{oval},~\cs{circle}も
6575 ベースライン補正を受けないように再定義されている.
6576
6577 \item[\cs{rensuji}{[<pos>]}\{<contents>\}\textrm{, }\cs{rensujiskip}]
6578
6579 \item[\cs{Kanji}\{<counter\_name>\}]
6580
6581 \item[\cs{kasen}\{<contents>\}\textrm{, }\cs{bou}\{<contents>\}\textrm{,
6582                      }\cs{boutenchar}]
6583
6584 \item[参照番号]
6585 \end{cslist}
6586 %</ja>
6587 %<*en>
6588 \begin{cslist}
6589 \item[tabular\textrm{, }array\textrm{, }minipage\textrm{ environments}]
6590 These environments are extended by \texttt{\<dir\>}, which specifies the direction,
6591 as follows:
6592 \begin{lstlisting}
6593 \begin{tabular}<dir>[pos]{table spec} ... \end{tabular}
6594 \begin{array}<dir>[pos]{table spec}   ... \end{array}
6595 \begin{minipage}<dir>[pos]{width}     ... \end{minipage}
6596 \end{lstlisting}
6597 This option permits one of the following five values. If none of them is specified,
6598 the direction inside the environment is same as that outside the enviromnent.
6599 \begin{description}
6600  \item[y] \emph{yoko} direction (horizontal writing)
6601  \item[t] \emph{tate} direction (vertical writing)
6602  \item[z] \emph{utod} direction if direction outside the env.\ is \emph{tate}.
6603  \item[d] \emph{dtou} direction
6604  \item[u] \emph{utod} direction
6605 \end{description}
6606 \item[\cs{parbox}\<<dir>\>{[<pos>]}\{<width>\}\{<contents>\}]
6607 \cs{parbox} command is also extended by \texttt{\<dir\>}.
6608
6609 \item[\cs{pbox}\<<dir>\>{[<width>][<pos>]}\{<contents>\}]
6610 This commands typeset <contents> in LR-mode, in <dir> direction.
6611 If <width> is positive, the width of the box becomes this <width>.
6612 In this case, <contents> will be aligned \dots
6613
6614 \item[picture\textrm{environment}]
6615
6616 \item[\cs{rensuji}{[<pos>]}\{<contents>\}\textrm{, }\cs{rensujiskip}]
6617
6618 \item[\cs{Kanji}\{<counter\_name>\}]
6619
6620 \item[\cs{kasen}\{<contents>\}\textrm{, }\cs{bou}\{<contents>\}\textrm{,
6621                      }\cs{boutenchar}]
6622
6623 \item[参照番号]
6624 \end{cslist}
6625 %</en>
6626
6627
6628
6629 %<en>\part{Implementations}
6630 %<ja>\part{実装}
6631 \label{part-imp}
6632 %<en>\section{Storing Parameters}
6633 %<ja>\section{パラメータの保持}
6634 \label{sec-para}
6635 %<en>\subsection{Used Dimensions, Attributes and Whatsit Nodes}
6636 %<ja>\subsection{\LuaTeX-jaで用いられるレジスタとwhatsitノード}
6637
6638 %<*en>
6639 Here the following is the list of dimensions and attributes which are used in \LuaTeX-ja.
6640 %</en>
6641 %<*ja>
6642 以下は\LuaTeX-jaで用いられる寸法レジスタ(dimension),属性レジスタ(attribute)の
6643 リストである.
6644 %</ja>
6645 \begin{list}{}{%
6646 \def\makelabel{\ttfamily}\advance\leftmargin1\zw
6647 \def\dim#1{\item[\textbackslash #1\ \textrm{(dimension)}]}
6648 \def\cnt#1{\item[\textbackslash #1\ \textrm{(counter)}]}
6649 \def\attr#1{\item[\textbackslash #1\ \textrm{(attribute)}]}
6650 }
6651
6652 \dim{jQ}
6653 %<*en>
6654 \cs{jQ} is equal to
6655                         $1\,\textrm{Q}=0.25\,\textrm{mm}$, where ``Q''~(also called ``級'') is
6656                         a unit used in Japanese phototypesetting.
6657 So one should not change the value of this dimension.
6658 %</en>
6659 %<*ja>
6660 \cs{jQ} は写植で用いられた$1\,\textrm{Q}=0.25\,\textrm{mm}$%
6661 (「級」とも書かれる)に等しい.したがって,
6662 この寸法レジスタの値を変更してはならない.
6663 %</ja>
6664
6665 \dim{jH}
6666 %<*en>
6667 There is also a unit called ``歯'' which equals to $0.25\,\textrm{mm}$ and
6668                          used in Japanese phototypesetting.
6669 This \cs{jH} is the same \cs{dimen} register as \cs{jQ}.
6670 %</en>
6671 %<*ja>
6672 同じく写植で用いられていた単位として「歯」があり,これも$0.25\,\textrm{mm}$と
6673 等しい.この \cs{jH} は \cs{jQ} と同じ寸法レジスタを指す.
6674 %</ja>
6675
6676 \dim{ltj@zw}
6677 %<*en>
6678 A temporal register for the ``full-width'' of current Japanese font.
6679 The command \cs{zw} sets this register to the correct value, and
6680 ``return'' this register itself.
6681 %</en>
6682 %<*ja>
6683 現在の和文フォントの「全角幅」を保持する一時レジスタ.
6684 \cs{zw} 命令は,このレジスタを適切な値に設定した後,
6685 「このレジスタ自体を返す」.
6686 %</ja>
6687
6688 \dim{ltj@zh}
6689 %<*en>
6690 A temporal register for the ``full-height'' (usually the sum of height of imaginary body and its depth) of current Japanese font.
6691 The command \cs{zh} sets this register to the correct value, and
6692 ``return'' this register itself.
6693 %</en>
6694 %<*ja>
6695 現在の和文フォントの「全角高さ」(通常,高さと深さの和)を保持する一時レジスタ.
6696 \cs{zh} 命令は,このレジスタを適切な値に設定した後,
6697 「このレジスタ自体を返す」.
6698 %</ja>
6699
6700 \attr{jfam}
6701 %<*en>
6702 Current number of Japanese font family for math formulas.
6703 %</en>
6704 %<*ja>
6705 数式用の和文フォントファミリの現在の番号.
6706 %</ja>
6707
6708 \attr{ltj@curjfnt}
6709 %<*en>
6710 The font index of current Japanese font for horizontal direction.
6711 %</en>
6712 %<*ja>
6713 現在の横組用和文フォントのフォント番号.
6714 %</ja>
6715
6716 \attr{ltj@curtfnt}
6717 %<*en>
6718 The font index of current Japanese font for vertical direction.
6719 %</en>
6720 %<*ja>
6721 現在の縦組用和文フォントのフォント番号.
6722 %</ja>
6723
6724 \attr{ltj@charclass}
6725 %<*en>
6726 The character class of Japanese \textit{glyph\_node}.
6727 %</en>
6728 %<*ja>
6729 和文文字の\textit{glyph\_node}の文字クラス.
6730 %</ja>
6731
6732 \attr{ltj@yablshift}
6733 %<*en>
6734 The amount of shifting the baseline of alphabetic fonts in scaled point ($2^{-16}\,\textrm{pt}$).
6735 %</en>
6736 %<*ja>
6737 スケールド・ポイント($2^{-16}\,\textrm{pt}$)を単位とした欧文フォントのベースラインの移動量.
6738 %</ja>
6739
6740 \attr{ltj@ykblshift}
6741 %<*en>
6742 The amount of shifting the baseline of Japanese fonts in scaled point ($2^{-16}\,\textrm{pt}$).
6743 %</en>
6744 %<*ja>
6745 スケールド・ポイント($2^{-16}\,\textrm{pt}$)を単位とした和文フォントのベースラインの移動量.
6746 %</ja>
6747
6748 \attr{ltj@tablshift}
6749 \attr{ltj@tkblshift}
6750
6751 \attr{ltj@autospc}
6752 %<*en>
6753 Whether the auto insertion of \Param{kanjiskip} is allowed at the node.
6754 %</en>
6755 %<*ja>
6756 そのノードで\Param{kanjiskip}の自動挿入が許されるかどうか.
6757 %</ja>
6758
6759 \attr{ltj@autoxspc}
6760 %<*en>
6761 Whether the auto insertion of \Param{xkanjiskip} is allowed at the node.
6762 %</en>
6763 %<*ja>
6764 そのノードで\Param{xkanjiskip}の自動挿入が許されるかどうか.
6765 %</ja>
6766
6767 \attr{ltj@icflag}
6768 %<*en>
6769 An attribute for distinguishing ``kinds'' of a node. One of the following value is
6770 assigned to this attribute:
6771 %</en>
6772 %<*ja>
6773 ノードの「種類」を区別するための属性.以下のうちのひとつが値として割り当てられる:
6774 %</ja>
6775 \begin{description}
6776 \item[\textit{italic} (1)]
6777 %<*en>
6778 Kerns from italic correction (\verb+\/+), or from kerning information of a Japanese font.
6779 These kerns are ``ignored'' in the insertion process of \textbf{JAglue},
6780 unlike explicit \cs{kern}.
6781 %</en>
6782 %<*ja>
6783 イタリック補正(\verb+\/+)によるカーン,
6784 または \Pkg{luaotfload} によって挿入されたフォントのカーニング情報由来のカーン.
6785 これらのカーンは通常の \cs{kern} とは異なり,
6786 \textbf{JAglue}の挿入処理においては透過する.
6787 %</ja>
6788
6789 \item[\textit{packed} (2)]
6790
6791 \item[\textit{kinsoku} (3)]
6792 %<*en>
6793 Penalties inserted for the word-wrapping process (\emph{kinsoku shori}) of Japanese characters.
6794 %</en>
6795 %<ja>禁則処理のために挿入されたペナルティ.
6796 \item[\mathversion{bold}$(\textit{from\_jfm}-2)$--$(\textit{from\_jfm}+2)$~(4--8)]
6797 %<en>Glues/kerns from JFM.
6798 %<ja>JFM由来のグルー/カーン.
6799 \item[\textit{kanji\_skip}~(9), \textit{kanji\_skip\_jfm}~(10)]
6800 %<en>Glues from \Param{kanjiskip}.
6801 %<ja>和文間空白\Param{kanjiskip}を表すグルー.
6802 \item[\textit{xkanji\_skip}~(11), \textit{xkanji\_skip\_jfm}~(12)]
6803 %<en>Glues from \Param{xkanjiskip}.
6804 %<ja>和欧文間空白\Param{xkanjiskip}を表すグルー.
6805 \item[\textit{processed} (13)]
6806 %<en>Nodes which is already processed by \ldots.
6807 %<ja>\LuaTeX-ja の内部処理によって既に処理されたノード.
6808 \item[\textit{ic\_processed} (14)]
6809 %<*en>
6810 Glues from an italic correction, but already processed in the insertion process of \textbf{JAglue}s.
6811 %</en>
6812 %<ja>イタリック補正に由来するグルーであって,既に \textbf{JAglue} 挿入処理にかかったもの.
6813 \item[\textit{boxbdd} (15)]
6814 %<en>Glues/kerns that inserted just the beginning or the ending of an hbox or a paragraph.
6815 %<ja>hboxか段落の最初か最後に挿入されたグルー/カーン.
6816 \end{description}
6817
6818 %<*ja>
6819 また,挿入処理の結果であるリストの最初のノードでは,\verb+\ltj@icflag+ の値に
6820 \textit{processed\_begin\_flag}~(128)が追加される.これによって,\cs{unhbox} が
6821 連続した場合でも「ボックスの境界」が識別できるようになっている.
6822 %</ja>
6823
6824 \attr{ltj@kcat\,$i$}
6825 %<*en>
6826 Where $i$~is a natural number which is less than~7.
6827 These 7~attributes store bit~vectors indicating which character block is regarded as a block of \textbf{JAchar}s.
6828 %</en>
6829 %<*ja>
6830 $i$は7より小さい自然数.
6831 これら7つの属性レジスタは,どの文字ブロックが\textbf{JAchar}のブロックとして
6832 扱われるかを示すビットベクトルを格納する.
6833 %</ja>
6834
6835 \attr{ltj@dir}
6836 %<*ja>
6837 \textit{direction}~whatsit(後述)において組方向を示すために,あるいは\textit{dir\_box}の
6838                          組方向を用いる.\textit{direction}~whatsitにおいては値は
6839 \begin{quote}
6840  \textit{dir\_dtou} (1), \textit{dir\_tate} (3),
6841  \textit{dir\_yoko} (4), \textit{dir\_utod} (11)
6842 \end{quote}
6843 のいずれかであり,\textit{dir\_box}ではこれらに次を加えた値をとる(\ref{sec-dir-imp}章参照).
6844 %</ja>
6845 \begin{description}
6846 \item[\textit{dir\_node\_auto} (128)]
6847 %<ja> 異なる組方向に配置するために自動的に作られたボックス.
6848 \item[\textit{dir\_node\_manual} (256)]
6849 %<ja> \cs{ltjsetwd} によって「ボックスの本来の組方向とは異なる組方向での寸法」を
6850 %<ja> 設定したときに,それを記録するためのボックス.
6851 \end{description}
6852 %<ja> \TeX 側から見える値,つまり \verb+\the\ltj@dir+ の値は常に0である.
6853
6854 \end{list}
6855
6856 %<*en>
6857 Furthermore, \LuaTeX-ja uses several user-defined whatsit nodes for
6858 internal processing. All those nodes except \emph{direction} whatsits
6859 store a natural number (hence its \texttt{type} is 100).
6860 \emph{direction} whatsits store a node list, hence its \texttt{type} is 110.
6861 Their \texttt{user\_id} (used for distinguish user-defined whatsits)
6862 are allocated by \texttt{luatexbase.newuserwhatsitid}.
6863 %</en>
6864 %<*ja>
6865 さらに,\LuaTeX-jaはいくつかのuser-defined whatsit nodeを内部処理に用いる.
6866 \textit{direction} whatsitはノードリストを格納するが,
6867 それ以外のwhatsitノードの \texttt{type} は100であり,ノードは自然数を格納している.
6868 user-defined whatsitを識別するための \texttt{user\_id} は\
6869 \texttt{luatexbase.newuserwhatsitid} により確保されており,
6870 下の見出しは単なる識別用でしかない.
6871 %</ja>
6872 \begin{description}
6873 \item[\textit{inhibitglue}]
6874 %<*en>
6875 Nodes for indicating that \cs{inhibitglue} is
6876            specified. The \texttt{value} field of these nodes doesn't matter.
6877 %</en>
6878 %<*ja>
6879 \cs{inhibitglue} が指定されたことを示すノード.これらのノードの\
6880 \texttt{value} フィールドは意味を持たない.
6881 %</ja>
6882
6883 \item[\textit{stack\_marker}]
6884 %<*en>
6885 Nodes for \LuaTeX-ja's stack system (see the next
6886            subsection). The \texttt{value} field of these nodes is
6887            current group level.
6888 %</en>
6889 %<*ja>
6890 \LuaTeX-jaのスタックシステム(次の節を参照)のためのノード.
6891 これらのノードの \texttt{value} フィールドは現在のグループネストレベルを表す.
6892 %</ja>
6893
6894 \item[\textit{char\_by\_cid}]
6895 %<*en>
6896 Nodes for \textbf{JAchar} which the callback process of
6897            \Pkg{luaotfload} won't be applied, and the character code is
6898            stored in the \texttt{value} field. Each node of this type are
6899            converted to a \textit{glyph\_node} \emph{after}
6900            the callback process of luaotfload.
6901 Nodes of this type is used in \cs{CID}, \cs{UTF} and IVS support.
6902 %</en>
6903 %<*ja>
6904 \Pkg{luaotfload}のコールバックによる処理が適用されない\textbf{JAchar}のためのノードで,
6905 \texttt{value} フィールドに文字コードが格納されている.
6906 この種類のノードはそれぞれが\Pkg{luaotfload}のコールバックの処理の
6907 \emph{後で}\textit{glyph\_node}に変換される.
6908 \cs{CID}, \cs{UTF}やIVS対応処理でこの種類のノードが利用されている.
6909 %</ja>
6910
6911 \item[\textit{replace\_vs}]
6912 %<*en>
6913 Similar to \textit{char\_by\_cid} whatsits above.
6914 These nodes are for \textbf{ALchar} which the callback process of
6915            \Pkg{luaotfload} won't be applied.
6916 %</en>
6917 %<*ja>
6918 上の\textit{char\_by\_cid}と同様に,
6919 これらのノードは\Pkg{luaotfload}のコールバックによる処理が適用されない\textbf{ALchar}のた
6920            めものである.
6921 %</ja>
6922
6923 \item[\textit{begin\_par}]
6924 %<*en>
6925 Nodes for indicating beginning of a paragraph.
6926 A paragraph which is started by \cs{item} in list-like environments has a horizontal box
6927 for its label before the actual contents. So \dots
6928 %</en>
6929 %<*ja>
6930 「段落の開始」を意味するノード.
6931 list環境,itemize環境などにおいて,\cs{item} で始まる各項目は……
6932 %</ja>
6933
6934 \item[\textit{direction}]
6935
6936 \end{description}
6937
6938 %<*en>
6939 These whatsits will be removed during the process of inserting \textbf{JAglue}s.
6940 %</en>
6941 %<*ja>
6942 これらのwhatsitノードは\textbf{JAglue}の挿入処理の間に取り除かれる.
6943 %</ja>
6944
6945 %<en>\subsection{Stack System of \LuaTeX-ja}
6946 %<ja>\subsection{\LuaTeX-jaのスタックシステム}
6947 \label{ssec-stack}
6948
6949 %<en>\paragraph{Background}
6950 %<ja>\paragraph{背景}
6951 %<*en>
6952 \LuaTeX-ja has its own stack system, and most parameters of \LuaTeX-ja
6953 are stored in it. To clarify the reason, imagine the parameter
6954 \Param{kanjiskip} is stored by a skip, and consider the following
6955 source:
6956 %</en>
6957 %<*ja>
6958 \LuaTeX-jaは独自のスタックシステムを持ち,\LuaTeX-jaのほとんどのパラメータは
6959 これを用いて保持されている.その理由を明らかにするために,
6960 \Param{kanjiskip}パラメータがスキップレジスタで保持されているとし,
6961 以下のコードを考えてみよう:
6962 %</ja>
6963 \begin{LTXexample}
6964 \ltjsetparameter{kanjiskip=0pt}ふがふが.%
6965 \setbox0=\hbox{%
6966   \ltjsetparameter{kanjiskip=5pt}ほげほげ}
6967 \box0.ぴよぴよ\par
6968 \end{LTXexample}
6969
6970 %<*en>
6971 As described in Subsection~\ref{ssec-param}, the only effective value of
6972 \Param{kanjiskip} in an hbox is the latest value, so the value of
6973 \Param{kanjiskip} which applied in the entire hbox should be 5\,pt.
6974 However, by the implementation method of \LuaTeX, this ``5\,pt'' cannot be
6975 known from any callbacks.  In the \texttt{tex/packaging.w}, which is a
6976 file in the source of \LuaTeX, there are the following codes:
6977 %</en>
6978 %<*ja>
6979 \ref{ssec-param}節で述べたように,あるhboxの中で効力を持つ
6980 \Param{kanjiskip}の値は最後に現れた値のみであり,したがってボックス全体に適用される
6981 \Param{kanjiskip}は5\,ptであるべきである.しかし,\LuaTeX の実
6982 装を観察すると,この5\,ptという長さはどのコールバックからも知ることはできないことがわかる.
6983 \LuaTeX のソースファイルの1つ \texttt{tex/packaging.w} の中に,
6984 以下のコードがある:
6985 %</ja>
6986 \begin{lstlisting}[numbers=left,firstnumber=1226]
6987 void package(int c)
6988 {
6989     scaled h;                   /* height of box */
6990     halfword p;                 /* first node in a box */
6991     scaled d;                   /* max depth */
6992     int grp;
6993     grp = cur_group;
6994     d = box_max_depth;
6995     unsave();
6996     save_ptr -= 4;
6997     if (cur_list.mode_field == -hmode) {
6998         cur_box = filtered_hpack(cur_list.head_field,
6999                                  cur_list.tail_field, saved_value(1),
7000                                  saved_level(1), grp, saved_level(2));
7001         subtype(cur_box) = HLIST_SUBTYPE_HBOX;
7002 \end{lstlisting}
7003 %<*en>
7004 Notice that \texttt{unsave()} is executed \emph{before}
7005 \texttt{filtered\_hpack()}, where \texttt{hpack\_filter} callback is
7006 executed) here. So ``5\,pt'' in the above source is orphaned at
7007 \texttt{unsave()}, and hence it can't be accessed from \texttt{hpack\_filter}
7008 callback.
7009 %</en>
7010 %<*ja>
7011 \texttt{unsave()} が \texttt{filtered\_hpack()}(これは \texttt{hpack\_filter} コールバックが
7012 実行されるところである)の\emph{前に}実行されていることに注意する.
7013 したがって,上記ソース中で5\,ptは \texttt{unsave()} のところで捨てられ,
7014 \texttt{hpack\_filter} コールバックからはアクセスすることができない.
7015 %</ja>
7016
7017 %<en>\paragraph{Implementation}
7018 %<ja>\paragraph{解決法}
7019
7020 %<*en>
7021 The code of stack system is based on that in a post of Dev-luatex mailing list\footnote{%
7022 \texttt{[Dev-luatex] tex.currentgrouplevel}, a post at 2008/8/19 by Jonathan Sauer.}.
7023 %</en>
7024 %<*ja>
7025 スタックシステムのコードはDev-luatexメーリングリストのある投稿\footnote{%
7026 \texttt{[Dev-luatex] tex.currentgrouplevel}: Jonathan Sauerによる2008/8/19の投稿.}を
7027 ベースにしている.
7028 %</ja>
7029
7030 %<*en>
7031 These are two \TeX\ count registers for maintaining information:
7032 \verb+\ltj@@stack+ for the stack level, and \verb+\ltj@@group@level+ for
7033 the \TeX's group level when the last assignment was done.  Parameters
7034 are stored in one big table named \texttt{charprop\_stack\_table}, where
7035 \texttt{charprop\_stack\_table[$i$]} stores data of stack level~$i$. If
7036 a new stack level is created by \cs{ltjsetparameter}, all data of the
7037 previous level is copied.
7038 %</en>
7039 %<*ja>
7040 情報を保持するために,2つの\TeX の整数レジスタを用いている:
7041 \verb+\ltj@@stack+ にスタックレベル,\verb+\ltj@@group@level+ に最後の代入が
7042 なされた時点での\TeX のグループレベルを保持している.
7043 パラメータは\texttt{charprop\_stack\_table}という名前のひとつの大きなテーブルに
7044 格納される.ここで,\texttt{charprop\_stack\_table[$i$]}はスタックレベル$i$の
7045 データを格納している.もし新しいスタックレベルが \cs{ltjsetparameter} によって
7046 生成されたら,前のレベルの全てのデータがコピーされる.
7047 %</ja>
7048
7049 %<*en>
7050 To resolve the problem mentioned in above paragraph ``Background'', \LuaTeX-ja uses
7051 another trick. When the stack level is about to be increased, a whatsit
7052 node whose type, subtype and value are 44~(\textit{user\_defined}),
7053 \textit{stack\_marker} and the current group level respectively is appended to the current
7054 list (we refer this node by \textit{stack\_flag}). This enables us to
7055 know whether assignment is done just inside a hbox. Suppose that the
7056 stack level is~$s$ and the \TeX's group level is~$t$ just after the hbox
7057 group, then:
7058 %</en>
7059 %<*ja>
7060 上の「背景」で述べた問題を解決するために,\LuaTeX-jaでは次の手法を用いる:
7061 スタックレベルが増加するするとき,type, subtype, valueがそれぞれ
7062 44~(\textit{user\_defined}), \textit{stack\_marker},そして現在のグループレベルであるwhatsitノード
7063 を現在のリストに付け加える(このノードを\textit{stack\_flag}とする).
7064 これにより,あるhboxの中で代入がなされたかどうかを知ることが可能
7065 となる.スタックレベルを$s$,そのhbox groupの直後の\TeX のグループレベルを
7066 $t$とすると:
7067 %</ja>
7068 \begin{itemize}
7069 %<*en>
7070 \item If there is no \textit{stack\_flag} node in the list of the contents of the hbox, then
7071       no assignment was occurred inside the hbox. Hence values of
7072       parameters at the end of the hbox are stored in the stack
7073       level~$s$.
7074 %</en>
7075 %<*ja>
7076 \item もしそのhboxの中身を表すリストの中に\textit{stack\_flag}ノードがなければ,
7077   hboxの中では代入は起こらなかったということになる.
7078   したがって,そのhboxの終わりにおけるパラメータの値はスタックレベル$s$に
7079   格納されている.
7080 %</ja>
7081
7082 %<*en>
7083 \item If there is a \textit{stack\_flag} node whose value is~$t+1$, then
7084       an assignment was occurred just inside the hbox group. Hence
7085       values of parameters at the end of the hbox are stored in the
7086       stack level~$s+1$.
7087 %</en>
7088 %<*ja>
7089 \item もし値が$t+1$の\textit{stack\_flag}ノードがあれば,その
7090   hboxの中で代入が起こったことになる.
7091   したがって,hboxの終わりにおけるパラメータの値はスタックレベル$s+1$に
7092   格納されている.
7093 %</ja>
7094
7095 %<*en>
7096 \item If there are \textit{stack\_flag} nodes but all of their values
7097       are more than~$t+1$, then an assignment was occurred in the box,
7098       but it is done in more internal group. Hence values of
7099       parameters at the end of the hbox are stored in the stack
7100       level~$s$.
7101 %</en>
7102 %<*ja>
7103 \item もし\textit{stack\_flag}ノードがあるがそれらの値が全て$t+1$より大きい
7104   場合,そのボックスの中で代入が起こったが,それは「より内部の」グループで
7105   起こったということになる.したがって,hboxの終わりでのパラメータの
7106   値はスタックレベル$s$に格納されている.
7107 %</ja>
7108 \end{itemize}
7109
7110 %<*en>
7111 Note that to work this trick correctly, assignments to
7112 \verb+\ltj@@stack+ and \verb+\ltj@@group@level+ have to be local always,
7113 regardless the value of \cs{globaldefs}.
7114 To solve this problem, we use another trick: the assignment
7115 \hbox{\verb+\directlua{tex.globaldefs=0}+} is always local.
7116 %</en>
7117 %<*ja>
7118 このトリックを正しく働かせるためには,\verb+\ltj@@stack+ と \verb+\ltj@@group@level+ への
7119 代入は \cs{globaldefs} の値によらず常にローカルでなければならないことに注意する.
7120 この問題は \hbox{\verb+\directlua{tex.globaldefs=0}+}(この代入は常にローカル)を
7121 用いることで解決している.
7122 %</ja>
7123
7124 %<*en>
7125 \subsection{Lua Functions of the Stack System}
7126 In this subsection, we will see how a user use \LuaTeX-ja's stack system to
7127 store some data which obeys the grouping of \TeX.
7128 %</en>
7129 %<*ja>
7130 \subsection{スタックシステムで使用される関数}
7131 本節では,ユーザが\LuaTeX-jaのスタックシステムを使用して,
7132 \TeX のグルーピングに従うような
7133 独自のデータを取り扱う方法を述べる.
7134 %</ja>
7135
7136 %<*en>
7137 The following function can be used to store data into a stack:
7138 \begin{lstlisting}
7139 luatexja.stack.set_stack_table(index, <any> data)
7140 \end{lstlisting}
7141 Any values which except \texttt{nil}~and~NaN are usable as \textit{index}.
7142 However, a user should use only negative integers or strings as \textit{index},
7143 since natural numbers are used by \LuaTeX-ja itself.
7144 Also, whether \textit{data} is stored locally or globally
7145 is determined by \texttt{luatexja.isglobal}
7146 (stored globally if and only if \texttt{luatexja.isglobal == 'global'}).
7147 %</en>
7148 %<*ja>
7149 スタックに値を設定するには,以下のLua関数を呼び出せば良い:
7150 \begin{lstlisting}
7151 luatexja.stack.set_stack_table(<any> index, <any> data)
7152 \end{lstlisting}
7153 直感的には,スタックテーブル中のインデックス\textit{index}の値を\textit{data}にする,という意味である.
7154 \textit{index}の値としては \texttt{nil} とNaN以外の任意の値を使えるが,
7155 自然数は\LuaTeX-jaが使用する(将来の拡張用も含む)ので,
7156 ユーザが使用する場合は負の整数値か文字列の値にすることが望ましい.
7157 また,ローカルに設定されるかグローバルに設定されるかは,\texttt{luatexja.isglobal} の値に依存する
7158 (グローバルに設定されるのは,\texttt{luatexja.isglobal == 'global'} であるちょうどその時).
7159 %</ja>
7160
7161 %<*en>
7162 Stored data can be obtained as the return value of
7163 \begin{lstlisting}
7164 luatexja.stack.get_stack_table(index, <any> default, <number> level)
7165 \end{lstlisting}
7166 where \textit{level} is the stack level, which is usually the value of \verb+\ltj@@stack+,
7167 and \textit{default} is the default value which will be returned if no values are stored
7168 in the stack table whose level is \textit{level}.
7169 %</en>
7170 %<*ja>
7171 スタックの値は,
7172 \begin{lstlisting}
7173 luatexja.stack.get_stack_table(<any> index, <any> default, <number> level)
7174 \end{lstlisting}
7175 の戻り値で取得できる.\textit{level}はスタックレベルであり,
7176 通常は \verb+\ltj@@stack+ の値を指定することになるだろう.
7177 \textit{default}はレベル\textit{level}のスタックに値が設定されていなかった場合に
7178 返すデフォルト値である.
7179 %</ja>
7180
7181 \begin{figure}[tb]
7182 \begin{lstlisting}[numbers=left, firstnumber=380]
7183 \protected\def\ltj@setpar@global{%
7184   \relax\ifnum\globaldefs>0\directlua{luatexja.isglobal='global'}%
7185     \else\directlua{luatexja.isglobal=''}\fi
7186 }
7187 \protected\def\ltjsetparameter#1{%
7188   \ltj@setpar@global\setkeys[ltj]{japaram}{#1}\ignorespaces}
7189 \protected\def\ltjglobalsetparameter#1{%
7190   \relax\ifnum\globaldefs<0\directlua{luatexja.isglobal=''}%
7191     \else\directlua{luatexja.isglobal='global'}\fi%
7192   \setkeys[ltj]{japaram}{#1}\ignorespaces}
7193 \end{lstlisting}
7194 %<ja>\caption{パラメータ設定命令の定義}
7195 %<en>\caption{Definiton of parameter setting commands}
7196 \label{fig:setpar-def}
7197 \end{figure}
7198
7199 %<*en>
7200 \subsection{Extending Parameters}
7201 Keys for \cs{ltjsetparameter}~and~\cs{ltjgetparameter} can be extended,
7202 as in \Pkg{luatexja-adjust}.
7203 %</en>
7204 %<*ja>
7205 \subsection{パラメータの拡張}
7206 ここでは,\Pkg{luatexja-adjust}で行なっているように,
7207 \cs{ltjsetparameter},~\cs{ltjgetparameter}に指定可能なキーを追加する方法
7208 を述べる.
7209 %</ja>
7210
7211 %<*en>
7212 \paragraph{Setting parameters}
7213 Figure~\ref{fig:setpar-def} shows the ``most outer'' definition of
7214 two commands,
7215 \cs{ltjsetparameter} and \cs{ltjglobalsetparameter}.
7216 Most important part is the last \cs{setkeys},
7217 which is offered by the \Pkg{xkeyval} package.
7218
7219 Hence, to add a key in \cs{ltjsetparameter}, one only have to add a key
7220 whose prefix is \texttt{ltj} and whose family is \texttt{japaram}, as the following.
7221 \begin{lstlisting}
7222 \define@key[ltj]{japaram}{...}{...}
7223 \end{lstlisting}
7224
7225 \cs{ltjsetparameter}~and~\cs{ltjglobalsetparameter} automatically sets
7226 \texttt{luatexja.isglobal}. Its meaning is the following.
7227 \begin{align}
7228  \texttt{luatexja.isglobal} =
7229 \begin{cases}
7230  \texttt{'global'}&\text{global}\\
7231  \texttt{''}&\text{local}
7232 \end{cases}
7233 \end{align}
7234 This is determined not only by command name
7235 (\cs{ltjsetparameter}~or~\cs{ltjglobalsetparameter}),
7236 but also by the value of \cs{globaldefs}.
7237 %</en>
7238 %<*ja>
7239 \paragraph{パラメータの設定}
7240 \cs{ltjsetparameter} と,\cs{ltjglobalsetparameter} の定義は図\ref{fig:setpar-def}の
7241 のようになっている.
7242 本質的なのは最後の \cs{setkeys} で,これは\Pkg{xkeyval}パッケージの提供する命令である.
7243
7244 このため,\cs{ltjsetparameter} に指定可能なパラメータを追加するには,
7245 <prefix>を \texttt{ltj},<family>を \texttt{japaram} としたキーを
7246 \begin{lstlisting}
7247 \define@key[ltj]{japaram}{...}{...}
7248 \end{lstlisting}
7249 のように定義すれば良いだけである.
7250 なお,パラメータ指定がグローバルかローカルかどうかを示す \texttt{luatexja.isglobal} が,
7251 \begin{align}
7252  \texttt{luatexja.isglobal} =
7253 \begin{cases}
7254  \texttt{'global'}&\text{パラメータ設定はグローバル}\\
7255  \texttt{''}&\text{パラメータ設定はローカル}
7256 \end{cases}
7257 \end{align}
7258 として自動的にセットされる\footnote{命令が \cs{ltjglobalsetparameter} かどうかだけでは
7259 なく,実行時の \cs{globaldefs} の値にも依存して定まる.}.
7260 %</ja>
7261
7262 %<*en>
7263 \paragraph{Getting parameters}
7264 \cs{ltjgetparameter} is implemented by a Lua script.
7265
7266 For parameters that do not need additional arguments, one only have to
7267 define a function in the table \verb+luatexja.unary_pars+.
7268 For example, with the following function,
7269 \verb+\ltjgetparameter{hoge}+ returns a \emph{string} \texttt{42}.
7270 \begin{lstlisting}[numbers=left]
7271 function luatexja.unary_pars.hoge (t)
7272   return 42
7273 end
7274 \end{lstlisting}
7275 Here the argument of \verb+luatexja.unary_pars.hoge+ is
7276 the stack level of \LuaTeX-ja's stack system (see Subsection~\ref{ssec-stack}).
7277
7278 On the other hand, for parameters that need an additional argument
7279 (this must be an integer), one have to define a function in
7280 \verb+luatexja.binary_pars+ first. For example,
7281 \begin{lstlisting}[numbers=left]
7282 function luatexja.binary_pars.fuga (c, t)
7283   return tostring(c) .. ', ' .. tostring(42)
7284 end
7285 \end{lstlisting}
7286 Here the first argument $t$ is the stack level, as before.
7287 The second argument $c$ is just the second argument of \cs{ltjgetparameter}.
7288
7289 For parameters that need an additional argument, one also have to
7290 execute the \TeX\ code like
7291 \begin{lstlisting}
7292 \ltj@@decl@array@param{fuga}
7293 \end{lstlisting}
7294 to indicate that ``the parameter \texttt{fuga} needs an additional argument''.
7295 %</en>
7296 %<*ja>
7297 \paragraph{パラメータの取得}
7298 一方,\cs{ltjgetparameter} はLuaスクリプトによって実装されている.
7299 値を取得するのに追加引数の要らないパラメータについては,\verb+luatexja.unary_pars+\
7300 内に処理内容を記述した関数を定義すれば良い.例えば,Luaスクリプトで
7301 \begin{lstlisting}[numbers=left]
7302 function luatexja.unary_pars.hoge (t)
7303   return 42
7304 end
7305 \end{lstlisting}
7306 を実行すると,\verb+\ltjgetparameter{hoge}+ は \texttt{42} という\emph{文字列}を返す.
7307 関数 \verb+luatexja.unary_pars.hoge+ の引数$t$は,\ref{ssec-stack}節で述べた
7308 \LuaTeX-jaのスタックシステムにおけるスタックレベルである.
7309 戻り値はいかなる値であっても,最終的には文字列として出力されることに注意.
7310
7311 一方,追加引数(\emph{数値しか許容しない})が必要なパラメータについては,
7312 まずLuaスクリプトで処理内容の本体を記述しておく:
7313 \begin{lstlisting}[numbers=left]
7314 function luatexja.binary_pars.fuga (c, t)
7315   return tostring(c) .. ', ' .. tostring(42)
7316 end
7317 \end{lstlisting}
7318 引数$t$は,先に述べた通りのスタックレベルである.一方,引数$c$は\
7319 \cs{ltjgetparameter} の第2引数を表す数値である.
7320 しかしこれだけでは駄目で,
7321 \begin{lstlisting}
7322 \ltj@@decl@array@param{fuga}
7323 \end{lstlisting}
7324 を実行し,\TeX インターフェース側に
7325 「\verb+\ltjgetparameter{fuga}+ は追加引数が必要」ということを通知する必要がある.
7326 %</ja>
7327
7328 %<en>\section{Linebreak after a Japanese Character}
7329 %<ja>\section{和文文字直後の改行}
7330 \label{sec-lbreak}
7331 %<en>\subsection{Reference: Behavior in \pTeX}
7332 %<ja>\subsection{参考:\pTeX の動作}
7333 %<*en>
7334 In~\pTeX, a line break after a Japanese character doesn't emit a space,
7335 since words are not separated by spaces in Japanese writings. However,
7336 this feature isn't fully implemented in \LuaTeX-ja due to the
7337 specification of callbacks in~\LuaTeX. To clarify the difference between
7338 \pTeX~and~\LuaTeX, We briefly describe the handling of a line break in~\pTeX, in
7339 this subsection.
7340
7341 \pTeX's input processor can be described in terms of a finite state
7342 automaton, as that of~\TeX\ in~Section~2.5 of~\cite{texbytopic}. The
7343 internal states are as follows:
7344 \begin{itemize}
7345 \item State~$N$: new line
7346 \item State~$S$: skipping spaces
7347 \item State~$M$: middle of line
7348 \item State~$K$: after a Japanese character
7349 \end{itemize}
7350 The first three states---$N$,~$S$, and~$M$---are as same as \TeX's input
7351 processor.  State~$K$ is similar to state~$M$, and is entered after
7352 Japanese characters.  The diagram of state transitions are indicated in
7353 Figure~\ref{fig-ptexipro}.  Note that \pTeX\ doesn't leave state~$K$
7354 after ``beginning/ending of a group'' characters.
7355 %</en>
7356
7357 %<*ja>
7358 欧文では文章の改行は単語間でしか行わない.そのため,\TeX では,(文字の直後の)改行は
7359 空白文字と同じ扱いとして扱われる.一方,和文ではほとんどどこでも改行が可能なため,
7360 \pTeX では和文文字の直後の改行は単純に無視されるようになっている.
7361
7362 このような動作は,\pTeX が\TeX からエンジンとして拡張されたことによって可能になったことである.
7363 \pTeX の入力処理部は,\TeX におけるそれと同じように,有限オートマトンとして記述することができ,
7364 以下に述べるような4状態を持っている.
7365
7366 \begin{itemize}
7367 \item State~$N$: 行の開始.
7368 \item State~$S$: 空白読み飛ばし.
7369 \item State~$M$: 行中.
7370 \item State~$K$: 行中(和文文字の後).
7371 \end{itemize}
7372 また,状態遷移は,図\ref{fig-ptexipro}のようになっており,図中の数字は
7373 カテゴリーコードを表している.最初の3状態は\TeX の入力処理部と同じであり,
7374 図中から状態$K$と「$j$」と書かれた矢印を取り除けば,\TeX の入力処理部と同
7375 じものになる.
7376
7377 この図から分かることは,
7378 \begin{quote}
7379 行が和文文字(とグループ境界文字)で終わっていれば,改行は無視される
7380 \end{quote}
7381 ということである.
7382 %</ja>
7383
7384 \begin{figure}[!tb]
7385 \let\sp\textvisiblespace\small
7386 \begin{minipage}{.6\textwidth}%
7387 \begin{center}
7388 \unitlength=6.5mm\sf\mathversion{bold}
7389 \begin{tikzpicture}[
7390   ->, auto, shorten >=1pt
7391 ]
7392 \node [shape=rectangle, font=\scriptsize] (init) at (2,7) {start};
7393 \node [shape=circle,draw, fill=b_cyan] (newline) at (4,7) {$N$};
7394 \node [shape=circle,draw, fill=b_cyan] (midline) at (4,4) {$M$};
7395 \node [shape=circle,draw, fill=b_cyan] (skipspc) at (8,7) {$S$};
7396 \node [shape=circle,draw, fill=b_pink]  (kanji) at (8,4) {$K$};
7397 \node [shape=rectangle,draw, fill=b_green] (scanacs) at (6,8) {scan a c.s.};
7398 \node (endk) at (8,2.5) {} ;
7399 \node (endm) at (4,2.5) {} ;
7400 \node (ends) at (8,8.5) {} ;
7401 \node (endn) at (4,8.5) {} ;
7402 \begin{scope}[font=\scriptsize]
7403 \path (newline) edge [bend right]    node [left]{G, O} (midline)
7404       (init)    edge                 node {} (newline)
7405       (midline) edge [bend right=10] node {10} (skipspc)
7406       (skipspc) edge [bend right]    node [left,right=10,above=7]{G, O} (midline)
7407       (skipspc) edge [loop right]    node {10} (skipspc)
7408       (newline) edge [loop right]    node {10} (newline)
7409       (scanacs) edge [bend left]     node [left=3,below]{$(*)$} (skipspc)
7410       (scanacs) edge [bend right]    node [right=30,above=20]{$(*)$} (midline)
7411       (midline) edge                 node {5\ [\sp]} (endm)
7412       (midline) edge [loop left]     node {G, O} (midline)
7413       (skipspc) edge                 node [right] {5} (ends)
7414       (newline) edge                 node {5 [\cs{par}]} (endn);
7415 \begin{scope}[red]
7416 \path (newline) edge [bend right]    node [right=25,below=3]{J} (kanji)
7417       (midline) edge                 node [below]{J} (kanji)
7418       (kanji)   edge [bend left]     node {O} (midline)
7419       (kanji)   edge                 node {10} (skipspc)
7420       (kanji)   edge [loop right]    node {G, J} (kanji)
7421       (skipspc) edge [bend left]     node {J} (kanji)
7422       (kanji)   edge                 node {5} (endk)
7423 ;
7424 \end{scope}
7425 \end{scope}
7426 \end{tikzpicture}
7427 \end{center}
7428 \end{minipage}%
7429 \begin{minipage}{.4\textwidth}
7430 \begin{description}
7431 \item[\textsf{G}] Beginning of group (usually \verb+{+)\\
7432  and ending of group (usually \verb+}+).
7433 \item[\textsf{J}] Japanese characters.
7434 \item[\textsf{5}] \textit{end-of-line} (usually \verb+^+\verb+^J+).
7435 \item[\textsf{10}] space (usually \sp).
7436 \item[\textsf{O}] other characters, whose category code is in $\{3,4,6,7,8,11,12,13\}$.
7437 \item[\textsf{[\sp]}, \textsf{[\cs{par}]}]
7438 emits a space, or~\cs{par}.
7439 \end{description}
7440 \end{minipage}
7441 \begin{itemize}
7442 \item We omitted about category codes
7443 9~(\textit{ignored}), 14~(\textit{comment}), and~15~(\textit{invalid})
7444 from the above diagram. We also ignored the input like ``\verb+^+\verb+^A+'' or ``\verb+^+\verb+^df+''.
7445 \item When a character whose category code is 0 (\textit{escape character}) is seen by \TeX,
7446 the input processor scans a control sequence (\textsf{scan a c.s.}).
7447 These paths are not shown in the above diagram.
7448
7449 After that, the state is changed to State~$S$ (skipping blanks) in most cases, but
7450 to State~$M$ (middle of line) sometimes.
7451 \end{itemize}
7452 %<en>\caption{State transitions of \pTeX's input processor}
7453 %<ja>\caption{\pTeX の入力処理部の状態遷移}
7454 \label{fig-ptexipro}
7455 \end{figure}
7456
7457
7458 %<en>\subsection{Behavior in \LuaTeX-ja}
7459 %<ja>\subsection{\LuaTeX-jaの動作}
7460 %<*en>
7461 States in the input processor of \LuaTeX\ is the same as that of \TeX,
7462 and they can't be customized by any callbacks. Hence, we can only use
7463 \verb+process_input_buffer+ and \verb+token_filter+ callbacks for to
7464 suppress a space by a line break which is after Japanese characters.
7465
7466 However, \verb+token_filter+ callback cannot be used either, since a
7467 character in category code 5~(\textit{end-of-line}) is converted into an space
7468 token \emph{in the input processor}.  So we can use only the
7469 \verb+process_input_buffer+ callback.  This means that suppressing a
7470 space must be done \emph{just before} an input line is read.
7471
7472 Considering these situations, handling of an end-of-line in \LuaTeX-ja are as follows:
7473 \begin{quote}
7474 A character \texttt{U+FFFFF} (its category code is set to 14~(\textit{comment}) by
7475 \LuaTeX-ja) is appended to an input line, \emph{before \LuaTeX\ actually
7476 process it}, if and only if the following three conditions are satisfied:
7477 \begin{enumerate}
7478 \item The category code of \cs{endlinechar}%
7479 \footnote{Usually, it is $\langle$\textit{return}$\rangle$
7480       (whose character code is 13).} is 5~(\textit{end-of-line}).
7481 \item The category code of \texttt{U+FFFFF} itself is 14~(\textit{comment}).
7482 \item The input line matches the following ``regular expression'':
7483 \[
7484   (\text{any char})^*(\textbf{JAchar})
7485   \bigl(\{\text{catcode}=1\}\cup\{\text{catcode}=2\}\bigr)^*
7486 \]
7487 \end{enumerate}
7488 \end{quote}
7489
7490 \paragraph{Remark}
7491 The following example shows the major difference from the behavior of \pTeX.
7492 \begin{LTXexample}
7493 \fontspec[Ligatures=TeX]{Linux Libertine O}
7494 \ltjsetparameter{autoxspacing=false}
7495 \ltjsetparameter{jacharrange={-6}}xあ
7496 y\ltjsetparameter{jacharrange={+6}}zい
7497 u
7498 \end{LTXexample}
7499 It is not strange that ``あ'' does not printed in the above output.
7500 This is because \TeX\ Gyre\ Termes does not contain ``あ'', and because
7501 ``あ'' in line~3 is considered as an \textbf{ALchar}.
7502
7503 Note that there is no space before ``y'' in the output, but
7504 there is a space before ``u''. This follows from following reasons:
7505 \begin{itemize}
7506 \item When line~3 is processed by \texttt{process\_input\_buffer} callback,
7507 ``あ'' is considered as an \textbf{JAchar}.
7508 Since  line~3 ends with an \textbf{JAchar},
7509 the comment character \texttt{U+FFFFF} is appended to this line,
7510 and hence the linebreak immediately after this line is ignored.
7511 \item When line~4 is processed by \texttt{process\_input\_buffer} callback,
7512 ``い'' is considered as an \textbf{ALchar}.
7513 Since  line~4 ends with an \textbf{ALchar}, the linebreak immediately after this line
7514 emits a space.
7515 \end{itemize}
7516 %</en>
7517
7518 %<*ja>
7519 \LuaTeX の入力処理部は\TeX のそれと全く同じであり,コールバックによりユーザが
7520 カスタマイズすることはできない.このため,改行抑制の目的でユーザが利用で
7521 きそうなコールバックとしては,\verb+process_input_buffer+や
7522 \verb+token_filter+に限られてしまう.しかし,\TeX の入力処理部をよく見る
7523 と,後者も役には経たないことが分かる:改行文字は,入力処理部によってトー
7524 クン化される時に,カテゴリーコード10の32番文字へと置き換えられてしまうた
7525 め,\verb+token_filter+で非標準なトークン読み出しを行おうとしても,空白文
7526 字由来のトークンと,改行文字由来のトークンは区別できないのだ.
7527
7528 すると,我々のとれる道は,\verb+process_input_buffer+を用いて
7529 \LuaTeX の入力処理部に引き渡される前に入力文字列を編集するというものしかない.
7530 以上を踏まえ,\LuaTeX-jaにおける「和文文字直後の改行抑制」の処理は,次のようになっている:
7531
7532 \begin{quote}
7533 各入力行に対し,\emph{その入力行が読まれる前の内部状態で}
7534 以下の3条件が満たされている場合,\LuaTeX-jaは\texttt{U+FFFFF}の文字
7535 \footnote{この文字はコメント文字として扱われるように\LuaTeX-ja内部で設定をしている.}
7536 を末尾に追加する.よって,その場合に改行は空白とは見做されないこととなる.
7537 \begin{enumerate}
7538 \item \cs{endlinechar}の文字\footnote{普通は,改行文字(文字コード13番)である.}
7539 のカテゴリーコードが5~(\textit{end-of-line})である.
7540 \item \texttt{U+FFFFF}のカテゴリーコードが14~(\textit{comment})である.
7541 \item 入力行は次の「正規表現」にマッチしている:
7542 \[
7543   (\text{any char})^*(\textbf{JAchar})
7544   \bigl(\{\text{catcode}=1\}\cup\{\text{catcode}=2\}\bigr)^*
7545 \]
7546 \end{enumerate}
7547 \end{quote}
7548
7549 この仕様は,前節で述べた\pTeX の仕様にできるだけ近づけたものとなっている.条件1.は,
7550 \texttt{lstlisting}系環境などの日本語対応マクロを書かなくてすませるためのものである.
7551
7552 しかしながら,\pTeX と完全に同じ挙動が実現できたわけではない.
7553 次のように,和文文字の範囲を変更したちょうどその行においては挙動が異なる:
7554 \begin{LTXexample}
7555 \fontspec[Ligatures=TeX]{TeX Gyre Termes}
7556 \ltjsetparameter{autoxspacing=false}
7557 \ltjsetparameter{jacharrange={-6}}xあ
7558 y\ltjsetparameter{jacharrange={+6}}zい
7559 u
7560 \end{LTXexample}
7561 上ソース中の「あ」は欧文文字扱いであり.
7562 ここで使用している欧文フォント\TeX\ Gyre Termesは「あ」を含まない.
7563 よって,出力に「あ」は現れないことは不思議ではない.
7564 それでも,\pTeX とまったく同じ挙動を示すならば,出力は
7565 「\hbox{\ltjsetparameter{autoxspacing=false}x yzいu}」となるはずである.しかし,実際には
7566 上のように異なる挙動となっているが,それは以下の理由による:
7567 \begin{itemize}
7568 \item 3行目を \texttt{process\_input\_buffer} で処理する時点では,
7569       「あ」は和文文字扱いである.よって3行目は和文文字で終わることになり,
7570       コメント文字 \texttt{U+FFFFF} が追加される.
7571       よって,直後の改行文字は無視されることになり,空白は入らない.
7572 \item 4行目を \texttt{process\_input\_buffer} で処理する時点では,
7573       「い」は欧文文字扱いである.よって4行目は欧文文字で終わることになり,
7574       直後の改行文字は空白に置き換わる.
7575 \end{itemize}
7576 このため,トラブルを避けるために,和文文字の範囲を\cs{ltjsetparameter}で編集した場合,
7577 その行はそこで改行するようにした方がいいだろう.
7578 %</ja>
7579
7580 %<*ja>
7581
7582 %<en>\section{Insertion of JFM glues, \Param{kanjiskip} and \Param{xkanjiskip}}
7583 %<ja>\section{JFMグルーの挿入,\Param{kanjiskip}と\Param{xkanjiskip}}
7584 \label{sec-jfmglue}
7585 %<en>\subsection{Overview}
7586 %<ja>\subsection{概要}
7587
7588 \LuaTeX-jaにおける \textbf{JAglue} の挿入方法は,\pTeX のそれとは全く異なる.
7589 \pTeX では次のような仕様であった:
7590 \begin{itemize}
7591 \item JFMグルーの挿入は,和文文字を表すトークンを元に水平リストに(文字を表す)<char\_node>を
7592 追加する過程で行われる.
7593 \item \Param{xkanjiskip}の挿入は,hboxへのパッケージングや行分割前に行われる.
7594 \item \Param{kanjiskip}はノードとしては挿入されない.パッケージングや行分割の計算時に
7595 「和文文字を表す2つの<char\_node>の間には\Param{kanjiskip}がある」ものとみなされる.
7596 \end{itemize}
7597 しかし,\LuaTeX-jaでは,hboxへのパッケージングや行分割前に全ての
7598 \textbf{JAglue},即ちJFMグルー・\Param{xkanjiskip}・\Param{kanjiskip}の
7599 3種類を一度に挿入することになっている.これは,\LuaTeX において欧文の合字・
7600 カーニング処理がノードベースになったことに対応する変更である.
7601
7602 \LuaTeX-jaにおける\textbf{JAglue}挿入処理では,次節で定義する
7603 「クラスタ」を単位にして行われる.大雑把にいうと,「クラスタ」は文字とそれに付随す
7604 るノード達(アクセント位置補正用のカーンや,イタリック補正)をまとめたもの
7605 であり,2つのクラスタの間には,ペナルティ,\cs{vadjust},whatsitなど,行組版
7606 には関係しないものがある.
7607
7608
7609 %<en>\subsection{Definition of a Cluster}
7610 %<ja>\subsection{「クラスタ」の定義}
7611
7612 \def\OA{$\text{\sf O}_{\text{\sf A}}$}
7613 \def\OB{$\text{\sf O}_{\text{\sf B}}$}
7614 \begin{defn}
7615 %<*en>
7616 A \emph{cluster} is consecutive nodes in one of the following forms,
7617 with the \textit{id} of it:
7618 %</en>
7619 %<*ja>
7620 \emph{クラスタ}は以下の形のうちのどれかひとつをとるノードのリストである:
7621 %</ja>
7622 \begin{enumerate}
7623 %<*en>
7624 \item Nodes whose value of\ \verb+\ltj@icflag+ is in $[3,15)$.  These
7625       nodes come from a hbox which is already packaged, by unpackaging
7626       (\cs{unhbox}).
7627       The \textit{id} of the cluster is \textit{id\_pbox}.
7628 %</en>
7629 %<*ja>
7630 \item その \verb+\ltj@icflag+ の値が$[3,15)$に入るノードのリスト.
7631   これらのノードはある既にパッケージングされたhboxから \cs{unhbox} で
7632   アンパックされたものである.
7633   この場合,クラスタの\textit{id}は\textit{id\_pbox}である.
7634 %</ja>
7635
7636 %<*en>
7637 \item A inline math formula, including two \textit{math\_node}s at the boundary of it.
7638       The \textit{id} of the cluster is \textit{id\_math}.
7639 %</en>
7640 %<*ja>
7641 \item インライン数式でその境界に2つの\textit{math\_node}を含むもの.
7642   この場合,クラスタの\textit{id}は\textit{id\_math}である.
7643 %</ja>
7644
7645 %<*en>
7646 \item A \textit{glyph\_node}~$p$, which represents a \textbf{JAchar}, with nodes which relate with it:
7647 %</en>
7648 %<*ja>
7649 \item \textbf{JAchar}を表す\textit{glyph\_node}~$p$とそれに関係するノード:
7650 %</ja>
7651 \begin{enumerate}
7652 %<*en>
7653 \item[(a)] A kern for the italic correction of~$p$.
7654 %</en>
7655 %<*ja>
7656 \item[(a)] $p$のイタリック補正のためのカーン.
7657 %</ja>
7658
7659 %<*en>
7660 \item[(b)] An accent attached to $p$ by \cs{accent}.
7661 %</en>
7662 %<*ja>
7663 \item[(b)] \cs{accent} による$p$に付随したアクセント.
7664 %</ja>
7665 \end{enumerate}
7666 \[
7667 \overbrace{%
7668  \Node{kern}{$\mathit{subtype}=2$}\longrightarrow
7669 \left\{\begin{array}{c}
7670 \Node{glyph}{accent}\\\noalign{\medskip}
7671 \Node{hbox}{accent (shifted vert.)}
7672 \end{array}\right\}\longrightarrow
7673 \Node{kern}{$\mathit{subtype}=2$}}^{\text{(a)}}
7674 \longrightarrow
7675 \Node{glyph}{$p$}\longrightarrow
7676 \overbrace{%
7677 \Node{kern}{italic corr.}}^{\text{(b)}}
7678 \]
7679
7680 %<*en>
7681 In this case, the \textit{id} is \textit{id\_jglyph}.
7682 %</en>
7683 %<*ja>
7684 この場合の\textit{id}は\textit{id\_jglyph}である.
7685 %</ja>
7686
7687 %<*en>
7688 \item A list which begins from a \textit{glyph\_node} which represents a \textbf{ALchar},
7689       and consists of \textbf{ALchar} \textit{glyph\_node}s,
7690       kerns for adjusting accents~(its subtype is 2), kerns for italic corrections and
7691       kerns which are automatically inserted by \LuaTeX~or~luaotfload.
7692       In this case, the \textit{id} is \textit{id\_glyph}.
7693 %</en>
7694 %<*ja>
7695 \item \textbf{ALchar}を表す\textit{glyph\_node},\cs{accent} によるアクセント位置補正用の
7696       カーン(subtypeが2),そしてイタリック補正・カーニングによって挿入されたカーン達が連続
7697       したもの.この場合の\textit{id}は\textit{id\_glyph}である.
7698 %</ja>
7699
7700 %<*en>
7701 \item An box-like node, that is, an hbox, a vbox, a rule (\cs{vrule}) and an \textit{unset\_node}.
7702 The \textit{id} of the cluster is \textit{id\_hlist} if the node is an
7703       hbox which is not shifted vertically, or \textit{id\_box\_like}
7704       otherwise.
7705 %</en>
7706 %<*ja>
7707 \item 水平ボックス(hbox),垂直ボックス,罫線 (\cs{vrule}),
7708   そして\textit{unset\_node}.
7709   クラスタの\textit{id}は垂直に移動していないhboxならば\textit{id\_hlist},
7710   そうでなければ\textit{id\_box\_like}となる.
7711 %</ja>
7712
7713 %<*en>
7714 \item A glue, a kern whose subtype is not 2~(\textit{accent}), and a discretionary break.
7715 The \textit{id} of the cluster is \textit{id\_glue}, \textit{id\_kern}
7716       and \textit{id\_disc}, respectively.
7717 %</en>
7718 %<*ja>
7719 \item グルー,subtypeが 2~(\textit{accent})ではないカーン,そしてdiscretionary break.
7720   その\textit{id} of the clusterはそれぞれ\textit{id\_glue}, \textit{id\_kern},そして
7721   \textit{id\_disc}である.
7722 %</ja>
7723 \end{enumerate}
7724 %<*en>
7725 We use \textit{Np}, \textit{Nq} and \textit{Nr} to denote a cluster.
7726 %</en>
7727 %<*ja>
7728 以下では\textit{Np}, \textit{Nq}, \textit{Nr}でクラスタを表す.
7729 %</ja>
7730 \end{defn}
7731
7732 \paragraph{\textit{id}の意味}
7733 $\mathit{Np}.\mathit{id}$の意味を述べるとともに,
7734 「先頭の文字」を表す\textit{glyph\_node}~$\mathit{Np}.\mathit{head}$と,
7735 「最後の文字」を表す\textit{glyph\_node}~$\mathit{Np}.\mathit{tail}$を次のように定義する.
7736 直感的に言うと,\textit{Np}は$\mathit{Np}.\mathit{head}$で始まり$\mathit{Np}.\mathit{tail}$で終わるような単語,
7737 と見做すことができる.これら$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$は
7738 説明用に準備した概念であって,実際のLuaコード中にそのように書かれているわけではないことに注意.
7739
7740 \begin{description}
7741 \item[\textit{id\_jglyph}] 和文文字.\\
7742 $\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$は,その和文文字を表している
7743 \textit{glyph\_node}そのものである.
7744 \item[\textit{id\_glyph}] 和文文字を表していない\textit{glyph\_node}~$p$.\\
7745 多くの場合,$p$は欧文文字を格納しているが,「ffi」などの合字によって作られた
7746 \textit{glyph\_node}である可能性もある.
7747 前者の場合,$\mathit{Np}.\mathit{head}$,~$\mathit{Np}.\mathit{tail} = p$である.
7748 一方,後者の場合,
7749 \begin{itemize}
7750 \item $\mathit{Np}.\mathit{head}$は,
7751 合字の構成要素の先頭→(その\textit{glyph\_node}における)合字の構成要素の先頭→……
7752 と再帰的に検索していってたどり着いた\textit{glyph\_node}である.
7753 \item $\mathit{Np}.\mathit{last}$は,同様に末尾→末尾→と検索してたどり着いた\textit{glyph\_node}である.
7754 \end{itemize}
7755 \item[\textit{id\_math}] インライン数式.\\
7756 便宜的に,$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$ともに
7757 「文字コード$-1$の欧文文字」とおく.
7758 \item[\textit{id\_hlist}] 縦方向にシフトされていないhbox.\\
7759 この場合,$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$はそれぞれ$p$の内容を表すリストの,
7760 先頭・末尾のノードである.
7761 \medskip
7762 \begin{itemize}
7763 \item 状況によっては,\TeX ソースで言うと
7764 \begin{lstlisting}
7765 \hbox{\hbox{abc}...\hbox{\lower1pt\hbox{xyz}}}
7766 \end{lstlisting}
7767 のように,$p$の内容が別のhboxで開始・終了している可能性も十分あり得る.そのような場合,
7768 $\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$の算出は,
7769 \emph{垂直方向にシフトされていない}hboxの
7770 場合だけ内部を再帰的に探索する.例えば上の例では,$\mathit{Np}.\mathit{head}$は文字「a」を表すノードであり,
7771 一方$\mathit{Np}.\mathit{tail}$は垂直方向にシフトされたhbox,
7772 \verb+\lower1pt\hbox{xyz}+ に対応するノードである.
7773 \item また,先頭にアクセント付きの文字がきたり,末尾にイタリック補正用のカーンが
7774 来ることもあり得る.この場合は,クラスタの定義のところにもあったように,それらは無視して算出を行う.
7775 \item 最初・最後のノードが合字によって作られた\textit{glyph\_node}のときは,それぞれに対して\textit{id\_glyph}%
7776 と同様に再帰的に構成要素をたどっていく.
7777 \end{itemize}
7778 \item[\textit{id\_pbox}] 「既に処理された」ノードのリストであり,これらのノードが二度処理を受けないために
7779 まとめて1つのクラスタとして取り扱うだけである.
7780 \textit{id\_hlist}と同じ方法で$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$を算出する,
7781 \item[\textit{id\_disc}] discretionary break (\verb+\discretionary{pre}{post}{nobreak}+).\\
7782 \textit{id\_hlist}と同じ方法で$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$を算出するが,
7783 第3引数の \texttt{nobreak}(行分割が行われない時の内容)を使う.言い換えれば,ここで行分割が発生した時の状況は
7784 全く考慮に入れない.
7785 \item[\textit{id\_box\_like}] \textit{id\_hlist}とならないboxや,rule.\\
7786 この場合は,$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$のデータは利用されないので,2つの算出は無意味である.
7787 敢えて明示するならば,$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$は共にnil値である.
7788 \item[他] 以上にない\textit{id}に対しても,$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$の算出は無意味.
7789 \end{description}
7790
7791 \paragraph{クラスタの別の分類}
7792 さらに,JFMグルー挿入処理の実際の説明により便利なように,\textit{id}とは別のクラスタの分類を行っておく.
7793 挿入処理では2つの隣り合ったクラスタの間に
7794 空白等の実際の挿入を行うことは前に書いたが,ここでの説明では,問題にしているクラスタ\textit{Np}は「後ろ側」のクラスタである
7795 とする.「前側」のクラスタについては,以下の説明で\textit{head}が\textit{last}に置き換わることに注意すること.
7796 \begin{description}
7797 \item[和文A] リスト中に直接出現している和文文字.
7798 \textit{id}が\textit{id\_jglyph}であるか,\\
7799 \textit{id}が\textit{id\_pbox}であって$\mathit{Np}.\mathit{head}$が\textbf{JAchar}であるとき.
7800
7801 \item[和文B] リスト中のhboxの中身の先頭として出現した和文文字.和文Aとの違いは,これの前に
7802 JFMグルーの挿入が行われない(\Param{xkanjiskip},~\Param{kanjiskip}は入り得る)ことである.\\
7803 \textit{id}が\textit{id\_hlist}か\textit{id\_disc}であって$\mathit{Np}.\mathit{head}$が\textbf{JAchar}であるとき.
7804
7805 \item[欧文] リスト中に直接/hboxの中身として出現している欧文文字.次の3つの場合が該当:
7806 \begin{itemize}
7807 \item \textit{id}が\textit{id\_glyph}である.
7808 \item \textit{id}が\textit{id\_math}である.
7809 \item \textit{id}が\textit{id\_pbox}か\textit{id\_hlist}か\textit{id\_disc}であって,$\mathit{Np}.\mathit{head}$が\textbf{ALchar}.
7810 \end{itemize}
7811 \item[箱] box,またはそれに類似するもの.次の2つが該当:
7812 \begin{itemize}
7813 \item \textit{id}が\textit{id\_pbox}か\textit{id\_hlist}か\textit{id\_disc}であって,$\mathit{Np}.\mathit{head}$が\textit{glyph\_node}でない.
7814 \item \textit{id}が\textit{id\_box\_like}である.
7815 \end{itemize}
7816
7817 \end{description}
7818
7819 \subsection{段落/hboxの先頭や末尾}
7820 \paragraph{先頭部の処理}
7821 まず,段落/hboxの一番最初にあるクラスタ\textit{Np}を探索する.
7822 hboxの場合は何の問題もないが,段落の場合では以下のノード達を事前に読み飛ばしておく:
7823 \begin{itemize}
7824 \item \cs{parindent} 由来のhbox($\mathit{subtype}=3$)
7825 \item \textit{subtype}が44~(\textit{user\_defined})でないようなwhatsit
7826 \end{itemize}
7827 これは,\cs{parindent}由来のhboxがクラスタを構成しないようにするためである.
7828
7829 次に,\textit{Np}の直前に空白$g$を必要なら挿入する:
7830 \begin{enumerate}
7831 \item この処理が働くような\textit{Np}は\textsf{和文A}である.
7832 \item 問題のリストが字下げありの段落(\cs{parindent} 由来のhboxあり)の場合は,
7833 この空白$g$は「文字コード \texttt{'parbdd'} の文字」と\textit{Np}の間に入るグルー/カーンである.
7834 \item そうでないとき(\verb+noindent+ で開始された段落やhbox)は,
7835 $g$は「文字コード \texttt{'boxbdd'} の文字」と\textit{Np}の間に入るグルー/カーンである.
7836 \end{enumerate}
7837 ただし,もし$g$がglueであった場合,この挿入によって\textit{Np}による行分割が新たに可能になるべきではない.
7838 そこで,以下の場合には,$g$の直前に \cs{penalty10000} を挿入する:
7839 \begin{itemize}
7840 \item 問題にしているリストが段落であり,かつ
7841 \item \textit{Np}の前には予めペナルティがなく,$g$はglue.
7842 \end{itemize}
7843
7844 \paragraph{末尾の処理}
7845 末尾の処理は,問題のリストが段落のものかhboxのものかによって異なる.
7846 後者の場合は容易い:最後のクラスタを\textit{Nq}とおくと,\textit{Nq}と「文字コード\
7847 \texttt{'boxbdd'} の文字」の間に入るグルー/カーンを,
7848 \textit{Nq}の直後に挿入するのみである.
7849
7850 一方.前者(段落)の場合は,リストの末尾は常に \cs{penalty10000} と,
7851 \cs{parfillskip} 由来のグルーが存在する.%よって,最後のクラスタ\textit{Np}は
7852 %この \cs{parfillskip} 由来のグルーとなり,実質的な中身の最後はその1つ前のクラスタ\textit{Nq}となる.
7853 段落の最後の「通常の和文文字${}+{}$句点」が独立した行となるのを防ぐために,
7854 \Param{jcharwidowpenalty}の値の分だけ適切な場所のペナルティを増やす.
7855
7856 ペナルティ量を増やす場所は,\textit{head}が\textbf{JAchar}であり,
7857 かつその文字の\Param{kcatcode}が偶数であるような
7858 最後のクラスタの直前にあるものたちである%
7859 \footnote{大雑把に言えば,\Param{kcatcode}が奇数であるような\textbf{JAchar}%
7860 を約物として考えていることになる.
7861 \Param{kcatcode}の最下位ビットはこの\Param{jcharwidowpenalty}用にのみ利用される.}.
7862
7863 \subsection{概観と典型例:2つの「和文A」の場合}
7864 \label{ssec-cluster-wa}
7865 先に述べたように,2つの隣り合ったクラスタ,\textit{Nq}と\textit{Np}の間には,
7866 ペナルティ,\cs{vadjust},whatsitなど,行組版には関係しないものがある.模式的に表すと,
7867 \[
7868  \Node{cluster}{\textit{Nq}}\longrightarrow
7869 \overbrace{
7870 \Node{penalty}{$p$}\longrightarrow \cdots\longrightarrow \Node{whatsit}{}}^{\textrm{(a)}}
7871 \longrightarrow \Node{cluster}{\textit{Np}}
7872 \]
7873 のようになっている.間の(a)に相当する部分には,何のノードもない場合ももちろんあり得る.
7874 そうして,JFMグルー挿入後には,この2クラスタ間は次のようになる:
7875 \[
7876  \Node{cluster}{\textit{Nq}}\longrightarrow%\Node{kern}{左空白}\longrightarrow
7877 \overbrace{
7878 \Node{penalty}{$p+x$}\longrightarrow \cdots\longrightarrow
7879 \Node{whatsit}{}}^{\textrm{(a)}}\longrightarrow
7880 \Node{glue or kern}{\raisebox{-.2\zw}{右空白}}\longrightarrow
7881 \Node{cluster}{\textit{Np}}
7882 \]
7883
7884 以後,\emph{典型的な例として,クラスタ\textit{Nq}と\textit{Np}が共に\textsf{\textmd{和文A}}である場合を見ていこう,}
7885 この場合が全ての場合の基本となる.
7886
7887 \paragraph{「右空白」の算出}
7888 まず,「右空白」にあたる量を算出する.通常はこれが,隣り合った2つの和文文字間に入る空白量となる.
7889 \begin{description}
7890 \item[JFM由来{[M]}] JFMの文字クラス指定によって入る空白を以下によって求める.この段階で空白量が未定義(未指定)だった場合,
7891       デフォルト値\Param{kanjiskip}を採用することとなるので,次へ.
7892 \begin{enumerate}
7893 \item もし両クラスタの間で \cs{inhibitglue} が実行されていた場合(証としてwhatsitノードが自動挿入される),
7894       代わりに\Param{kanjiskip}が挿入されることとなる.次へ.
7895 \item \textit{Nq}と\textit{Np}が同じJFM・同じ\texttt{jfmvar}キー・同じサイズの和文フォントであったならば,
7896       共通に使っているJFM内で挿入される空白(グルーかカーン)が決まっているか調べ,決まっていればそれを採用.
7897 \item 1.でも2.でもない場合は,JFM・\texttt{jfmvar}・サイズの3つ組は\textit{Nq}と\textit{Np}で異なる.
7898 この場合,まず
7899 \[
7900 \vcenter{\halign{\hfil$#:={}$&\inhibitglue#\inhibitglue\cr
7901 gb&(\textit{Nq}と「使用フォントが\textit{Nq}のそれと同じで,\hfil\cr
7902 \omit&\quad 文字コードが\textit{Np}のそれの文字」との間に入るグルー/カーン)\hfil\cr
7903 ga&(\inhibitglue 「使用フォントが\textit{Np}のそれと同じで,\hfil\cr
7904 \omit&\quad 文字コードが\textit{Nq}のそれの文字」と\textit{Np}との間に入るグルー/カーン)\hfil\cr
7905 }}
7906 \]
7907 として,前側の文字のJFMを使った時の空白(グルー/カーン)と,後側の文字のJFMを使った時のそれを求める.
7908
7909 $\mathit{gb}$,~$\mathit{ga}$それぞれに対する<ratio>の値を$d_b$,~$d_a$とする.
7910 \begin{itemize}
7911 \item
7912 $\mathit{ga}$と$\mathit{gb}$の両方が未定義であるならば,JFM由来のグルーは挿入されず,
7913 \Param{kanjiskip}を採用することとなる.
7914 どちらか片方のみが未定義であるならば,次のステップでその未定義の方は長さ0のkernで,<ratio>の値は0であるかのように扱われる.
7915 \item
7916 \Param{diffrentjfm}の値が \texttt{pleft}, \texttt{pright},
7917       \texttt{paverage} のとき,
7918 <ratio>の指定に従って比例配分を行う.
7919 JFM由来のグルー/カーンは以下の値となる:
7920 \[
7921  f\left(\frac{1-d_b}2\textit{gb} + \frac{1+d_b}2\textit{ga},
7922 \frac{1-d_a}2\textit{gb} + \frac{1+d_a}2\textit{ga}\right)
7923 \]
7924 ここで.$f(x,y)$は
7925 \[
7926  f(x,y)=\begin{cases}
7927 x&\text{if\ }\Param{diffrentjfm}=\texttt{pleft};\\
7928 y&\text{if\ }\Param{diffrentjfm}=\texttt{pright};\\
7929 (x+y)/2&\text{if\ }\Param{diffrentjfm}=\texttt{paverage};
7930 \end{cases}.
7931 \]
7932 \item
7933 \Param{differentjfm}がそれ以外の値の時は,<ratio>の値は無視され,JFM由来のグルー/カーンは以下の値となる:
7934 \[
7935  f(\textit{gb},\textit{ga})
7936 \]
7937 ここで.$f(x,y)$は
7938 \[
7939  f(x,y)=\begin{cases}
7940 \min(x,y)&\text{if\ }\Param{diffrentjfm}=\texttt{small};\\
7941 \max(x,y)&\text{if\ }\Param{diffrentjfm}=\texttt{large};\\
7942 (x+y)/2&\text{if\ }\Param{diffrentjfm}=\texttt{average};\\
7943 x+y&\text{if\ }\Param{diffrentjfm}=\texttt{both};
7944 \end{cases}.
7945 \]
7946 \end{itemize}
7947 \end{enumerate}
7948
7949 例えば,
7950 \begin{lstlisting}
7951 \jfont\foo=psft:Ryumin-Light:jfm=ujis;-kern
7952 \jfont\bar=psft:GothicBBB-Medium:jfm=ujis;-kern
7953 \jfont\baz=psft:GothicBBB-Medium:jfm=ujis;jfmvar=piyo;-kern
7954 \end{lstlisting}
7955 という3フォントを考え,
7956 \[
7957  \overbrace{\Node{glyph}{\cs{ foo}, `あ'}}^{p}
7958 \longrightarrow \overbrace{\Node{glyph}{\cs{bar}, `い'}}^{q}
7959 \longrightarrow \overbrace{\Node{glyph}{\cs{baz}, `う'}}^{r}
7960 \]
7961 という3ノードを考える(それぞれ単独でクラスタをなす).
7962 この場合,$p$と$q$の間は,実フォントが異なるにもかかわらず2.の状況となる一方で,
7963 $q$と$r$の間は(実フォントが同じなのに)\texttt{jfmvar} キーの内容が異なるので3.の状況となる.
7964 \item[\Param{kanjiskip}~{[K]}] 上の[M]において空白が定まらなかった場合,
7965 以下で定めた量「右空白」として採用する.
7966 この段階においては,\cs{inhibitglue} は効力を持たないため,
7967 結果として,2つの和文文字間には常に何らかのグルー/カーンが挿入されることとなる.
7968 \begin{enumerate}
7969 \item 両クラスタ(厳密には$\mathit{Nq}.\mathit{tail}$,$\mathit{Np}.\mathit{head}$)の中身の文字コードに対する
7970 \Param{autospacing}パラメタが両方ともfalseだった場合は,長さ0のglueとする.
7971 \item ユーザ側から見た\Param{kanjiskip}パラメタの自然長が$\cs{maxdimen}=(2^{30}-1)\,{\rm sp}$で
7972 なければ,\Param{kanjiskip}パラメタの値を持つglueを採用する.
7973 \item 2.でない場合は,\textit{Nq}, \textit{Np}で使われているJFMに指定されている\Param{kanjiskip}の値を用いる.
7974 どちらか片方のクラスタだけが和文文字(\textsf{和文A}・\textsf{和文B})のときは,そちらのクラスタで使われている
7975 JFM由来の値だけを用いる.もし両者で使われているJFMが異なった場合は,上の[M]~3.と同様の方法を用いて調整する.
7976 \end{enumerate}
7977 \end{description}
7978 %\paragraph{「左空白」の算出とそれに伴う補正}
7979 %「左空白」は過去のバージョンでは定義していたが,このバージョンでは
7980 %挿入は一切行われない(機能自体削除している).
7981 %しかし,仕様は流動的であり,将来復活する可能性もあるため,マニュアル中の記述は今のところ極力変更しない.
7982 \paragraph{禁則用ペナルティの挿入}
7983 まず,
7984 \[
7985  a:=(\text{\textit{Nq}{\footnotemark}の文字に対する\Param{postbreakpenalty}の値})
7986 +(\text{\textit{Np}{\footnotemark}の文字に対する\Param{prebreakpenalty}の値})
7987 \]
7988 とおく\footnotetext{厳密にはそれぞれ$\mathit{Nq}.\mathit{tail}$,$\mathit{Np}.\mathit{head}$.}.
7989 ペナルティは通常$[-10000,10000]$の整数値をとり,また$\pm 10000$は正負の無限大を意味することになっているが,この$a$の
7990 算出では単純な整数の加減算を行う.
7991
7992 $a$は禁則処理用に\textit{Nq}と\textit{Np}の間に加えられるべきペナルティ量である.
7993 \begin{description}
7994 \item[P-normal~{[PN]}]
7995 \textit{Nq}と\textit{Np}の間の(a)部分にペナルティ(\textit{penalty\_node})があれば処理は簡単である:
7996 それらの各ノードにおいて,ペナルティ値を($\pm 10000$を無限大として扱いつつ)$a$だけ増加させればよい.
7997 また,$10000 + (-10000) = 0$としている.
7998
7999 少々困るのは,(a)部分にペナルティが存在していない場合である.
8000 直感的に,補正すべき量$a$が0でないとき,その値をもつ\textit{penalty\_node}を作って
8001 「右空白」の(もし未定義なら\textit{Np}の)直前に挿入……
8002 ということになるが,実際には僅かにこれより複雑である.
8003 \begin{itemize}
8004 \item 「右空白」がカーンであるとき,
8005 それは「\textit{Nq}と\textit{Np}の間で改行は許されない」ことを意図している.そのため,
8006 この場合は$a\neq 0$であってもペナルティの挿入はしない.
8007 \item そうでないないときは,$a\neq 0$ならば\textit{penalty\_node}を作って挿入する.
8008 %\item 「左空白」がカーンとしてきっちり定義されている時(このとき,「右空白」はカーンでない),
8009 %この「左空白」の直後での行分割を許容しないといけないので,$a=0$であっても
8010 %\textit{penalty\_node}を作って挿入する.
8011 %\item 以上のどれでもないときは,$a\neq 0$ならば\textit{penalty\_node}を作って挿入する.
8012 \end{itemize}
8013 \end{description}
8014
8015 \def\gkf#1#2#3{\sf$\displaystyle\vphantom{\Bigg(}%
8016   \frac{\hbox to 4\zw{\hss#2\hss}}{\hbox{#3}}$}
8017 \begin{table}[t]
8018 %<en>\caption{Summary of JFM glues}
8019 %<ja>\caption{JFM グルーの概要}
8020 \label{tab-jfmglue}
8021 %<en>\medskip
8022 \begin{center}
8023 \small
8024 \begin{tabular}{c|cccccc}
8025 \toprule
8026 {\bf\textit{Np}}↓&\sf 和文A&\sf 和文B&\sf 欧文&\sf 箱&\sf glue&\sf kern\\\midrule
8027 \sf 和文A&
8028 \gkf{E}{M→K}{PN}&
8029 \gkf{---}{\OA →K}{PN}&
8030 \gkf{---}{\OA →X}{PN}&
8031 \gkf{---}{\OA}{PA}&
8032 \gkf{---}{\OA}{PN}&
8033 \gkf{---}{\OA}{PS}\\
8034 \sf 和文B&
8035 \gkf{E}{\OB→K}{PA}&
8036 \gkf{---}{K}{PS}&
8037 \gkf{---}{X}{PS}\\
8038 \sf 欧文&
8039 \gkf{E}{\OB →X}{PA}&
8040 \gkf{---}{X}{PS}\cr
8041 \sf 箱&\gkf{E}{\OB}{PA}\\
8042 \sf glue&\gkf{E}{\OB}{PN}\\
8043 \sf kern&\gkf{E}{\OB}{PS}\\
8044 \bottomrule
8045 \end{tabular}
8046 \end{center}
8047 \begin{quote}
8048 %<*en>
8049 In the table above, {\small\gkf{E}{M→K}{PN}} means that
8050 %</en>
8051 %<*ja>
8052 上の表において,{\small\gkf{E}{M→K}{PN}}は次の意味である:
8053 %</ja>
8054 \begin{enumerate}
8055 %<*en>
8056 \item To determine the ``right-space'', \LuaTeX-ja first attempts by the method ``\textsf{JFM-origin~[M]}''.
8057 If this attempt fails, \LuaTeX-ja use the method ``\textsf{\Param{kanjiskip}~[K]}''.
8058 %</en>
8059 %<*ja>
8060 \item 「右空白」を決めるために,\LuaTeX-ja はまず「JFM由来{[M]}」の方法を試みる.
8061   これが失敗したら,\LuaTeX-ja は「\Param{kanjiskip}~{[K]}」の方法を試みる.
8062 %</ja>
8063
8064 % %<*en>
8065 % \item The ``left space'' between \textit{Nq}~and~\textit{Np} is
8066 %   determined by the method ``\textsf{line-end~[E]}''.
8067 % %</en>
8068 % %<*ja>
8069 % \item \textit{Nq} と \textit{Np} の間の「左空白」は「\textsf{line-end~[E]}」の
8070 %   方法で決定される.
8071 % %</ja>
8072
8073 %<*en>
8074 \item \LuaTeX-ja adopts the method ``\textsf{P-normal~[PN]}'' to adjust the penalty
8075   between two clusters for \emph{kinsoku shori}.
8076 %</en>
8077 %<*ja>
8078 \item \LuaTeX-jaは2つのクラスタの間の禁則処理用のペナルティを設定するために「\textsf{P-normal~[PN]}」の方法を採用する.
8079 %</ja>
8080 \end{enumerate}
8081 \end{quote}
8082 \end{table}
8083
8084 \subsection{その他の場合}
8085 本節の内容は表\ref{tab-jfmglue}にまとめてある.
8086
8087 \paragraph{和文Aと欧文の間}
8088 \textit{Nq}が\textsf{和文A}で,\textit{Np}が\textsf{欧文}の場合,JFMグルー挿入処理は次のようにして行われる.
8089 \begin{itemize}
8090 \item 「右空白」については,まず以下に述べる\textsf{Boundary-B~[\OB]}により空白を決定しようと試みる.
8091 それが失敗した場合は,\textsf{\Param{xkanjiskip}~[X]}によって定める.
8092 %\item 「左空白」については,既に述べた\textsf{line-end~[E]}をそのまま採用する.それに伴う「右空白」の補正も%同じ.
8093 \item 禁則用ペナルティも,以前述べた\textsf{P-normal~[PN]}と同じである.
8094 \end{itemize}
8095 \begin{description}
8096 \item[Boundary-B~{[\OB]}] 和文文字と「和文でないもの」との間に入る空白を以下によって求め,
8097 未定義でなければそれを「右空白」として採用する.
8098 \textsf{JFM-origin~[M]}の変種と考えて良い.
8099 これによって定まる空白の典型例は,和文の閉じ括弧と欧文文字の間に入る半角アキである.
8100 \begin{enumerate}
8101 \item もし両クラスタの間で \cs{inhibitglue} が実行されていた場合%
8102 (証としてwhatsitノードが自動挿入される),「右空白」は未定義.
8103 \item そうでなければ,
8104 \textit{Nq}と「文字コードが {\tt'jcharbdd'} の文字」との間に入るグルー/カーンとして定まる.
8105 \end{enumerate}
8106 \item[\Param{xkanjiskip}~{[X]}]
8107 この段階では,\textsf{\Param{kanjiskip}~[K]}のときと同じように,
8108 以下で定めた量を「右空白」として採用する.
8109 \cs{inhibitglue} は効力を持たない.
8110 \begin{enumerate}
8111 \item 以下のいずれかの場合は,\Param{xkanjiskip}の挿入は抑止される.しかし,実際には行分割を許容するために,長さ0のglueを採用する:
8112 \begin{itemize}
8113 \item 両クラスタにおいて,それらの中身の文字コードに対する\Param{autoxspacing}パラメタが共にfalseである.
8114 \item \textit{Nq}の中身の文字コードについて,「直後への\Param{xkanjiskip}の挿入」が禁止されている
8115 (つまり,\Param{jaxspmode}~(or \Param{alxspmode})パラメタが2以上).
8116 \item \textit{Np}の中身の文字コードについて,「直前への\Param{xkanjiskip}の挿入」が禁止されている
8117 (つまり,\Param{jaxspmode}~(or \Param{alxspmode})パラメタが偶数).
8118 \end{itemize}
8119 \item ユーザ側から見た\Param{xkanjiskip}パラメタの自然長が$\cs{maxdimen}=(2^{30}-1)\,{\rm sp}$で
8120 なければ,\Param{xkanjiskip}パラメタの値を持つglueを採用する.
8121 \item 2.でない場合は,\textit{Nq}, \textit{Np}(\textsf{和文A}/\textsf{和文B}なのは片方だけ)
8122 で使われているJFMに指定されている\Param{xkanjiskip}の値を用いる.
8123 \end{enumerate}
8124 \end{description}
8125
8126 \paragraph{欧文と和文Aの間}
8127 \textit{Nq}が\textsf{欧文}で,\textit{Np}が\textsf{和文A}の場合,JFMグルー挿入処理は上の場合とほぼ同じである.
8128 \textsf{和文A}のクラスタが逆になるので,\textsf{Boundary-A~[\OA]}の部分が変わるだけ.
8129 \begin{itemize}
8130 \item 「右空白」については,まず以下に述べる\textsf{Boundary-A~[\OA]}により空白を決定しようと試みる.
8131 それが失敗した場合は,\textsf{\Param{xkanjiskip}~[X]}によって定める.
8132 %\item \textit{Nq}が和文でないので,「左空白」は算出されない.
8133 \item 禁則用ペナルティは,以前述べた\textsf{P-normal~[PN]}と同じである.
8134 \end{itemize}
8135 \begin{description}
8136 \item[Boundary-A~{[\OA]}] 「和文でないもの」と和文文字との間に入る空白を以下によって求め,
8137 未定義でなければそれを「右空白」として採用する.
8138 \textsf{JFM-origin~[M]}の変種と考えて良い.
8139 これによって定まる空白の典型例は,欧文文字と和文の開き括弧との間に入る半角アキである.
8140 \begin{enumerate}
8141 \item もし両クラスタの間で \cs{inhibitglue} が実行されていた場合(証としてwhatsitノードが自動挿入される),次へ.
8142 \item そうでなければ,
8143 「文字コードが {\tt'jcharbdd'} の文字」と\textit{Np}との間に入るグルー/カーンとして定まる.
8144 \end{enumerate}
8145 \end{description}
8146
8147 \paragraph{和文Aと箱・グルー・カーンの間}
8148 \textit{Nq}が\textsf{和文A}で,\textit{Np}が\textsf{箱}・グルー・カーンのいずれかであった場合,
8149 両者の間に挿入されるJFMグルーについては同じ処理である.しかし,そこでの行分割に対する仕様が異なるので,
8150 ペナルティの挿入処理は若干異なったものとなっている.
8151
8152 \begin{itemize}
8153 \item 「右空白」については,既に述べた\textsf{Boundary-B~[\OB]}により空白を決定しようと試みる.
8154 それが失敗した場合は,「右空白」は挿入されない.
8155 %\item 「左空白」については,既に述べた\textsf{line-end~[E]}の算出方法をそのまま採用する.それに伴う「右空白」の補正も同じ.
8156 \item 禁則用ペナルティの処理は,後ろのクラスタ\textit{Np}の種類によって異なる.
8157 なお,$\mathit{Np}.\mathit{head}$は無意味であるから,
8158 「$\mathit{Np}.\mathit{head}$に対する\Param{prebreakpenalty}の値」は0とみなされる.言い換えれば,
8159 \[
8160  a:=(\text{\textit{Nq}の文字に対する\Param{postbreakpenalty}の値}).
8161 \]
8162 \begin{description}
8163 \item[箱] \textit{Np}が\textsf{箱}であった場合は,両クラスタの間での行分割は
8164 (明示的に両クラスタの間に \cs{penalty10000} があった場合を除き)いつも許容される.そのため,
8165 ペナルティ処理は,後に述べる\textsf{P-allow~[PA]}が\textsf{P-normal~[PN]}の代わりに用いられる.
8166 \item[グルー] \textit{Np}がグルーの場合,ペナルティ処理は\textsf{P-normal~[PN]}を用いる.
8167 \item[カーン] \textit{Np}がカーンであった場合は,両クラスタの間での行分割は
8168 (明示的に両クラスタの間にペナルティがあった場合を除き)許容されない.
8169 ペナルティ処理は,後に述べる\textsf{P-suppress~[PS]}を使う.
8170 \end{description}
8171 これらの\textsf{P-normal~[PN]},\textsf{P-allow~[PA]},\textsf{P-suppress~[PS]}の違いは,
8172 \textit{Nq}と\textit{Np}の間(以前の図だと(a)の部分)にペナルティが存在しない場合にのみ存在する.
8173 \end{itemize}
8174
8175 \begin{description}
8176 \item[P-allow~{[PA]}]
8177 \textit{Nq}と\textit{Np}の間の(a)部分にペナルティがあれば,\textsf{P-normal~[PN]}と同様に,
8178 それらの各ノードにおいてペナルティ値を$a$だけ増加させる.
8179
8180 (a)部分にペナルティが存在していない場合,
8181 \LuaTeX-ja は\textit{Nq}と\textit{Np}の間の行分割を可能にしようとする.
8182 そのために,以下のいずれかの場合に$a$をもつ\textit{penalty\_node}を作って
8183 「右空白」の(もし未定義なら\textit{Np}の)直前に挿入する:
8184 \begin{itemize}
8185 \item 「右空白」がグルーでない(カーンか未定義)であるとき.
8186 \item $a\neq 0$のときは,「右空白」がグルーであっても\textit{penalty\_node}を作る.
8187 \end{itemize}
8188
8189 \item[P-suppress~{[PS]}]
8190 \textit{Nq}と\textit{Np}の間の(a)部分にペナルティがあれば,\textsf{P-normal~[PN]}と同様に,
8191 それらの各ノードにおいてペナルティ値を$a$だけ増加させる.
8192
8193 (a)部分にペナルティが存在していない場合,
8194 \textit{Nq}と\textit{Np}の間の行分割は元々不可能のはずだったのであるが,
8195 \LuaTeX-ja はそれをわざわざ行分割可能にはしない.
8196 そのため,「右空白」がglueであれば,その直前に \cs{penalty10000} を挿入する.
8197 \end{description}
8198
8199 \paragraph{箱・グルー・カーンと和文Aの間}
8200 \textit{Np}が\textsf{箱}・グルー・カーンのいずれかで,\textit{Np}が\textsf{和文A}であった場合は,
8201 すぐ上の(\textit{Nq}と\textit{Np}の順序が逆になっている)場合と同じである.
8202 %が,「左空白」がなくなることにのみ注意.
8203 \begin{itemize}
8204 \item 「右空白」については,既に述べた\textsf{Boundary-A~[\OA]}により空白を決定しようと試みる.
8205 それが失敗した場合は,「右空白」は挿入されない.
8206 %\item \textit{Nq}が和文でないので,「左空白」は算出されない.
8207 \item 禁則用ペナルティの処理は,\textit{Nq}の種類によって異なる.
8208 $\mathit{Nq}.\mathit{tail}$は無意味なので,
8209 \[
8210  a:=(\text{\textit{Np}の文字に対する\Param{prebreakpenalty}の値}).
8211 \]
8212 \begin{description}
8213 \item[箱] \textit{Nq}が\textsf{箱}の場合は,\textsf{P-allow~[PA]}を用いる.
8214 \item[グルー] \textit{Nq}がグルーの場合は,\textsf{P-normal~[PN]}を用いる.
8215 \item[カーン] \textit{Nq}がカーンの場合は,\textsf{P-suppress~[PS]}を用いる.
8216 \end{description}
8217 \end{itemize}
8218
8219 \paragraph{和文Aと和文Bの違い}
8220 先に述べたように,\textsf{和文B}はhboxの中身の先頭(or 末尾)として出現している
8221 和文文字である.リスト内に直接ノードとして現れている和文文字(\textsf{和文A})との違いは,
8222 \begin{itemize}
8223 \item \textsf{和文B}に対しては,JFMの文字クラス指定から定まる空白
8224 \textsf{JFM-origin~[M]},\textsf{Boundary-A~[\OA]},\textsf{Boundary-B~[\OB]})の挿入は行われない.
8225 %「左空白」の算出も行われない.
8226 例えば,
8227 \begin{itemize}
8228 \item 片方が\textsf{和文A},もう片方が\textsf{和文B}のクラスタの場合,
8229 \textsf{Boundary-A~[\OA]}または\textsf{Boundary-B~[\OB]}の挿入を試み,それがダメなら
8230 \Param{kanjiskip}~\textsf{[K]}の挿入を行う.
8231 \item \textsf{和文B}の2つのクラスタの間には,\Param{kanjiskip}~\textsf{[K]}が自動的に入る.
8232 \end{itemize}
8233 \item \textsf{和文B}と箱・グルー・カーンが隣接したとき(どちらが前かは関係ない),間にJFMグルー・ペナルティの挿入は一切しない.
8234 \item \textsf{和文B}と\textsf{和文B},また\textsf{和文B}と\textsf{欧文}とが隣接した時は,禁則用ペナルティ挿入処理は
8235 \textsf{P-suppress~[PS]}が用いられる.
8236 \item \textsf{和文B}の文字に対する\Param{prebreakpenalty},~\Param{postbreakpenalty}の値は使われず,0として計算される.
8237 \end{itemize}
8238
8239
8240 次が具体例である:
8241 \begin{LTXexample}
8242 あ.\inhibitglue A\\
8243 \hbox{あ.}A\\
8244 あ.A
8245 \end{LTXexample}
8246 \begin{itemize}
8247 \item 1行目の\cs{inhibitglue}は\textsf{Boundary-B~[\OB]}の処理のみを抑止するので,ピリオドと「A」の間には
8248 \Param{xkanjiskip}(四分アキ)が入ることに注意.
8249 \item 2行目のピリオドと「A」の間においては,前者が\textsf{和文B}となる(hboxの中身の末尾として登場しているから)ので,
8250 そもそも\textsf{Boundary-B~[\OB]}の処理は行われない.よって,\Param{xkanjiskip}が入ることとなる.
8251 \item 3行目では,ピリオドの属するクラスタは\textsf{和文A}である.これによって,
8252 ピリオドと「A」の間には\textsf{Boundary-B~[\OB]}由来の半角アキが入ることになる.
8253 \end{itemize}
8254 %</ja>
8255
8256 %<*ja>
8257 \section{ベースライン補正の方法}
8258 \subsection{\texttt{yoffset} フィールド}
8259 \Param{yalbaselineshift}等のベースライン補正は,基本的には対象となっている
8260 \textit{glyph\_node}の \texttt{yoffset} フィールドの値を増減することによって
8261 実装されている.なお,\texttt{yoffset} の値は上方向への移動量であるのに対し,
8262 \Param{yalbaselineshift}などは下方向への移動量である.
8263
8264 さて,\texttt{yoffset} の増減によって見かけのグリフ位置は上下に移動するが,
8265 仮想ボディの高さ$h$,深さ$d$については
8266 \begin{description}
8267 \catcode`\<=12\catcode`\>=12
8268  \item[$\texttt{yoffset}\geq 0$のとき] 
8269 $h = \max(\texttt{height} + \texttt{yoffset}, 0)$, 
8270 $d = \max(\texttt{depth} - \texttt{yoffset}, 0)$, 
8271  \item[$\texttt{yoffset}<0$のとき] 
8272 $h = \max(\texttt{height} + \texttt{yoffset}, 0)$, $d=\texttt{depth}$.
8273 \end{description}
8274 という仕様になっている.つまり,\texttt{yoffset} が負(グリフを下ける)の場合に深さは増加しな
8275 い(表\ref{tab:yoffset_and_im}参照).
8276
8277 \begin{table}[t]
8278 \caption{\texttt{yoffset} and imaginary body}
8279 \label{tab:yoffset_and_im}
8280 \centering\small
8281 \fboxsep0pt
8282 \def\T#1#2{\fcolorbox{blue}{white}{%
8283   \setbox0=\hbox{\LARGE #1%
8284     \directlua{
8285       local p = tex.nest[tex.nest.ptr].tail
8286       p.yoffset = #2 * 65536
8287     }%
8288   }%
8289   \copy0\kern-\wd0\smash{\color{red}\vrule width \wd0 height 0.2pt depth 0.2pt}%
8290 }}
8291 \begin{tabular}{>{\bfseries}lccccc}
8292 \toprule
8293 \texttt{yoffset}&10\,pt&5\,pt&0&$-5$\,pt&$-10$\,pt\\
8294 \midrule
8295 仮想ボディ&\T{y}{10}, \T{H}{10}&\T{y}{5}, \T{H}{5}&\T{y}{0}, \T{H}{0}%
8296 &\T{y}{-5}, \T{H}{-5}&\T{y}{-10}, \T{H}{-10}\\[10pt]
8297 \bottomrule
8298 \end{tabular}
8299 \end{table}
8300
8301 \subsection{\textbf{ALchar}の補正}
8302 上記の問題について,\textbf{ALchar}のベースライン補正では
8303 「正しい深さ」を持った罫線(rule)を補うという対応策をとった.
8304 この罫線による補正は,\textit{id}が\textit{id\_glyph}であるクラスタ単位,
8305 大雑把に言えば音節単位で行われる.
8306 文字列``Typeset''を
8307 \begin{itemize}
8308  \item フォントはLatin Modern Roman (\texttt{lmroman10-regular.otf}) 10\,pt
8309  \item \Param{yalbaselineshift}は5\,pt
8310 \end{itemize}
8311 という状況で組んだ場合を例にとって説明しよう.
8312
8313 \LuaTeX・\Pkg{luaotfload}によるカーニング・ハイフネーションが終わった段階では,
8314
8315
8316
8317 %</ja>
8318
8319 %<en>\section{Patch for the \Pkg{listings} Package}
8320 %<ja>\section{\Pkg{listings} パッケージへの対応}
8321
8322 %<*en>
8323 It is well-known that the \Pkg{listings} package outputs weird results
8324 for Japanese input.
8325 The \Pkg{listings} package makes most of letters active and assigns
8326 output command for each letter~(\cite{listings}).
8327 But Japanese characters are not included in these activated letters.
8328 For \pTeX{} series, there is no method to make Japanese characters active;
8329 a patch \Pkg{jlisting.sty}~(\cite{jlisting}) resolves the problem forcibly.
8330 %</en>
8331 %<*ja>
8332 \Pkg{listings} パッケージが,そのままでは日本語をまともに出力できないこと
8333 はよく知られている.きちんと整形して出力するために,\Pkg{listings}パッケー
8334 ジは内部で「ほとんどの文字」をアクティブにし,各文字に対してその文字の出
8335 力命令を割り当てている(\cite{listings}).
8336 しかし,そこでアクティブにする文字の中に,和文文
8337 字がないためである.\pTeX 系列では,和文文字をアクティブにする手法がなく,
8338 \Pkg{jlisting.sty} というパッチ(\cite{jlisting})を用いることで無理やり解決していた.
8339 %</ja>
8340
8341 %<*en>
8342 In \LuaTeX-ja, the problem is resolved by using the \verb+process_input_buffer+ callback.
8343 The callback function inserts the output command (active character \texttt{U+FFFFF})
8344 before each letter above \texttt{U+0080}.
8345 This method can omits the process to make all Japanese characters active
8346 (most of the activated characters are not used in many cases).
8347 %</en>
8348 %<*ja>
8349 \LuaTeX-jaでは,\verb+process_input_buffer+ コールバックを利用することで,
8350 「各行に出現する\texttt{U+0080}以降の文字に対して,それらの出力命令を前置する」
8351 という方法をとっている.出力命令としては,アクティブ文字化した \texttt{U+FFFFF} を用いている.
8352 これにより,(入力には使用されていないかもしれない)和文文字をもすべてアクティブ化する手間もなく,
8353 見通しが良い実装になっている.
8354 %</ja>
8355
8356
8357 %<*en>
8358 If the \Pkg{listings} package  and \LuaTeX-ja were loaded,
8359 then the patch \Pkg{lltjp-listings} is loaded automatically at \verb+\begin{document}+.
8360 %</en>
8361 %<*ja>
8362 \LuaTeX-ja で利用される \Pkg{listings} パッケージへのパッチ \Pkg{lltjp-listings} は,
8363 \Pkg{listings} と\LuaTeX-jaを読み込んでおけば,
8364 \verb+\begin{document}+ の箇所において自動的に読み込まれるので,通常はあまり
8365 意識する必要はない.
8366 %</ja>
8367
8368 %<en>\subsection{Notes and additional keys}
8369 %<ja>\subsection{注意}
8370 %<*en>
8371 \paragraph{Escaping to \LaTeX}
8372 We used the \verb+process_input_buffer+ callback to output \textbf{JAchar}s.
8373 But it has a drawback; any commands whose name contains a \textbf{JAchar}
8374 cannot be used in any ``escape to \LaTeX''.
8375
8376 Consider the following input:
8377 %</en>
8378 %<*ja>
8379 \paragraph{\LaTeX へのエスケープ}
8380 日本語対応を行うために \verb+process_input_buffer+ を使用したことで,
8381 \texttt{texcl},~\texttt{escapeinside}といった\emph{「\LaTeX へのエスケープ」中では,
8382 \textbf{JAchar}を名称の一部に含む制御綴は使用不可能}である.
8383 例えば次のような入力を考えよう:
8384 %</ja>
8385 \begin{verbatim*}
8386 \begin{lstlisting}[escapechar=\#]
8387 #\ほげ xぴよ#
8388 \end{lstlisting}
8389 \end{verbatim*}
8390 %<en>The line~2 is transformed by the callback to
8391 %<ja>ここで,2行目は \verb+process_input_buffer+ の作用により,
8392 \begin{lstlisting}[showspaces, escapechar=\!]
8393 #\!\IVSA FFFFF!ほ!\IVSA FFFFF!げ x!\IVSA FFFFF!ぴ!\IVSA FFFFF!よ#
8394 \end{lstlisting}
8395 %<*en>
8396 before the line is actually processed.
8397 In the escape (between the character ``\verb+#+''),
8398 the category code of \texttt{U+FFFFF} is set to 9~(\emph{ignored}).
8399 Hence the control symbol ``\cs{}\IVSA FFFFF'' will be executed,
8400 instead of ``\verb+\ほげ+''.
8401 %</en>
8402 %<*ja>
8403 と変換されてから,実際の処理に回される.
8404 「\verb+#+」で挟まれた「\LaTeX へのエスケープ」中では\
8405 \texttt{U+FFFFF} のカテゴリーコードは9~(\textit{ignored})となるので,
8406 結局「\verb+\ほげ+」の代わりに
8407 「\cs{}\IVSA FFFFF」というcontrol symbolが実行されることになる.
8408 %</ja>
8409
8410 %<*en>
8411 \paragraph{Variation selectors}
8412 \Pkg{lltjp-listings} add two keys, namely \texttt{vsraw}~and~\texttt{vscmd},
8413 which specify how variation selectors are treated in 
8414 \texttt{lstlisting} or other enviroments.
8415 Note that these additional keys are not usable in the preamble, 
8416 since \Pkg{lltjp-listings} is loaded at \verb+\begin{document}+.
8417
8418 \texttt{vsraw} is a key which takes a boolean value, and its default value is
8419 false.
8420 \begin{itemize}
8421  \item If the \texttt{vsraw} key is true, then
8422 variation selectors are ``combined'' with the previous character.
8423 %</en>
8424 %<*ja>
8425 \paragraph{異体字セレクタの扱い}
8426 \texttt{lstlisting} 環境などの内部にある異体字セレクタを扱うため,
8427 \Pkg{lltjp-listings} では \texttt{vsraw} と \texttt{vscmd} という2つのキーを追加した.
8428 しかし,\Pkg{lltjp-listings} が実際に読み込まれるのは \verb+\begin{document}+\
8429 のところであるので,プリアンブル内ではこれらの追加キーは使用できない.
8430
8431 \texttt{vsraw}は,ブール値の値をとるキーであり,標準ではfalseである.
8432 \begin{itemize}
8433  \item trueの場合は,異体字セレクタは「直前の文字に続けて」出力される.
8434 もしもIVSサポート(\ref{ssec-ltjotf}節)が有効になっていた場合は,
8435 以下の例(左側は入力,右側はその出力)のようになる.
8436 %</ja>
8437 \begin{LTXexample}
8438 \begin{lstlisting}[vsraw=true]
8439 葛󠄀城市,葛󠄁飾区,葛西
8440 \end{lstlisting}
8441 \end{LTXexample}
8442 %<*en>
8443 \item If the \texttt{vsraw} key is false, then 
8444 variation selectors are typeset by an appropriate command, which is specified by
8445       the \texttt{vscmd} key.
8446 The default setting of the \texttt{vscmd} key produces the following.
8447 %</en>
8448 %<*ja>
8449 \item falseの場合は,異体字セレクタは適当な命令によって「見える形で」出力される.
8450 どのような形で出力されるかを規定するのが \texttt{vscmd} キーであり,
8451 \Pkg{lltjp-listings} の標準設定では以下の例の右側のように出力される.
8452 %</ja>
8453 \begin{LTXexample}
8454 \begin{lstlisting}[vsraw=false,
8455    vscmd=\ltjlistingsvsstdcmd]
8456 葛󠄀城市,葛󠄁飾区,葛西
8457 \end{lstlisting}
8458 \end{LTXexample}
8459 %<ja> ちなみに,本ドキュメントでは次のようにしている:
8460 %<en> For example, the following code is the setting of the \texttt{vscmd} key in this document.
8461 \begin{lstlisting}[numbers=left]
8462 \def\IVSA#1#2#3#4#5{%
8463   \textcolor{blue}{\raisebox{3.5pt}{\tt%
8464     \fboxsep=0.5pt\fbox{\tiny \oalign{0#1#2\crcr#3#4#5\crcr}}}}%
8465 }
8466 {\catcode`\%=11
8467   \gdef\IVSB#1{\expandafter\IVSA\directlua{
8468     local cat_str = luatexbase.catcodetables['string']
8469     tex.sprint(cat_str, string.format('%X', 0xE00EF+#1))
8470 }}}
8471 \lstset{vscmd=\IVSB}
8472 \end{lstlisting}
8473 \end{itemize}
8474 %<*en>
8475 The default output command of variation selectors is stored in \verb+\ltjlistingsvsstdcmd+.
8476 %</en>
8477 %<*ja>
8478 既定の出力命令を復活させたい場合は\ \verb+vscmd=\ltjlistingsvsstdcmd+\
8479 とすれば良い.
8480 %</ja>
8481
8482 %<*en>
8483 \paragraph{The \texttt{doubleletterspace} key}
8484 Even the column format is \texttt{[c]fixed}, sometimes characters are not vertically aligned.
8485 The following example  is typeset with \texttt{basewidth=2em}, and
8486 you'll see the leftmost ``\texttt{H}'' are not vertically aligned.
8487 \begin{lstlisting}[basewidth=2em, basicstyle=\tt,numbers=left]
8488 :H:
8489 :HHHH:
8490 \end{lstlisting}
8491
8492 \Pkg{lltjp-listing} adds the \texttt{doubleletterspace} key (not activated by default, for
8493 compatibility) to
8494 improve the situation, namely doubles inter-character space in each output unit.
8495 With this key, the above input now produces better output.
8496 \begin{lstlisting}[basewidth=2em, basicstyle=\tt,numbers=left, doubleletterspace]
8497 :H:
8498 :HHHH:
8499 \end{lstlisting}
8500 %</en>
8501 %<*ja>
8502 \paragraph{\texttt{doubleletterspace}キー}
8503 \Pkg{listings}パッケージで列揃えが \texttt{[c]fixed} となっている場合でも,
8504 場合によっては文字が縦に揃わない場合もある.
8505 例を以下に示そう.これは強調するために \texttt{basewidth=2em} を設定している.
8506 \begin{lstlisting}[basewidth=2em, basicstyle=\tt,numbers=left]
8507 :H:
8508 :HHHH:
8509 \end{lstlisting}
8510 1行目と2行目の「\texttt{H}」の位置が揃っていないが,
8511 これは出力単位ごとに,先頭・末尾・各文字間に同じ量の空白を挿入することによる.
8512
8513 \Pkg{lltjp-listing}では,このような症状を改善させるために \texttt{doubleletterspace} キー
8514 を追加した(標準では互換性のために無効になっている).このキーを有効にすると,
8515 出力単位中の各文字間の空白を2倍にすることで文字を揃いやすくしている.
8516 上と同じものを \texttt{doubleletterspace} キーを有効にして組んだものが以下であり,
8517 きちんと「\texttt{H}」の位置が揃っていることが分かる.
8518 \begin{lstlisting}[basewidth=2em, basicstyle=\tt,numbers=left, doubleletterspace]
8519 :H:
8520 :HHHH:
8521 \end{lstlisting}
8522 %</ja>
8523
8524 %<en>\subsection{Class of Characters}
8525 %<ja>\subsection{文字種}
8526
8527 %<en>Roughly speaking, the \Pkg{listings} package processes input as follows:
8528 %<ja>\Pkg{listings} パッケージの内部では,大雑把に言うと
8529 \begin{enumerate}
8530 %<en>\item Collects \textit{letters} and \textit{digits}, which can be used for the name of identifiers.
8531 %<ja>\item 識別子として使える文字 (``letter'',~``digit'') たちを集める.
8532 %<en>\item When reading an \textit{other}, outputs the collected character string (with modification, if needed).
8533 %<ja>\item letterでもdigitでもない文字が現れた時に,収集した文字列を(必要なら修飾して)出力する.
8534 %<en>\item Collects \textit{others}.
8535 %<ja>\item 今度は逆に,letterでない文字たちをletterが現れるまで集める.
8536 %<en>\item When reading a \textit{letter} or a \textit{digit}, outputs the collected character string.
8537 %<ja>\item letterが出現したら集めた文字列を出力する.
8538 %<en>\item Turns back to 1.
8539 %<ja>\item 1.に戻る.
8540 \end{enumerate}
8541 %<*en>
8542 By the above process, line breaks inside of an identifier are blocked.
8543 A flag \verb+\lst@ifletter+ indicates whether the previous character can be used
8544 for the name of identifiers or not.
8545 %</en>
8546 %<*ja>
8547 という処理が行われている.これにより,識別子の途中では行分割が行われないようになっている.
8548 直前の文字が識別子として使えるか否かは \verb+\lst@ifletter+ というフラグに格納されている.
8549 %</ja>
8550
8551 %<*en>
8552 For Japanese characters, line breaks are permitted on both sides
8553 except for brackets, dashes, etc.
8554 Hence the patch \Pkg{lltjp-listings} introduces
8555 a new flag \verb+\lst@ifkanji+, which indicates
8556 whether the previous character is a Japanese character or not.
8557 For illustration, we introduce following classes of characters:
8558 %</en>
8559 %<*ja>
8560 さて,日本語の処理である.殆どの和文文字の前後では行分割が可能であるが,その一方で
8561 括弧類や音引きなどでは禁則処理が必要なことから,\Pkg{lltjp-listings} では,
8562 直前が和文文字であるかを示すフラグ \verb+\lst@ifkanji+ を新たに導入した.
8563 以降,説明のために以下のように文字を分類する:
8564 %</ja>
8565 \begin{center}
8566 \small
8567 \begin{tabular}{lccccc}
8568 \toprule
8569 &Letter&Other&Kanji&Open&Close\\\midrule
8570 \verb+\lst@ifletter+&T&F&T&F&T\\
8571 \verb+\lst@ifkanji+&F&F&T&T&F\\
8572 %<en>Meaning&char in an identifier&other alphabet&%
8573 %<en>most of Japanese char&opening brackets&closing brackets\\
8574 %<ja>意図&識別子中の文字&その他欧文文字&殆どの和文文字&開き括弧類&閉じ括弧類\\
8575 \bottomrule
8576 \end{tabular}
8577 \end{center}
8578 %<*en>
8579 Note that \textit{digits} in the \Pkg{listings} package can be Letter or
8580 Other according to circumstances.
8581 %</en>
8582 %<*ja>
8583 なお,本来の\Pkg{listings} パッケージでの分類``digit''は,
8584 出現状況によって,上の表のLetterとOtherのどちらにもなりうる.
8585 また,KanjiとCloseは \verb+\lst@ifletter+ と \verb+\lst@ifkanji+ の値が一致しているが,
8586 これは間違いではない.
8587 %</ja>
8588
8589 %<*en>
8590 For example, let us consider the case an Open comes after a Letter.
8591 Since an Open represents Japanese open brackets,
8592 it is preferred to be permitted to insert line break after the Letter.
8593 Therefore, the collected character string is output in this case.
8594 %</en>
8595 %<*ja>
8596 例えば,Letterの直後にOpenが来た場合を考える.
8597 文字種Openは和文開き括弧類を想定しているので,Letterの直後では行分割が可能であることが望ましい.
8598 そのため,この場合では,すでに収集されている文字列を出力することで行分割を許容するようにした.
8599 %</ja>
8600
8601 %<*en>
8602 The following table summarizes $5\times 5=25$ cases:
8603 %</en>
8604 %<*ja>
8605 同じように,$5\times 5=25$通り全てについて書くと,次のようになる:
8606 %</ja>
8607 \begin{center}
8608 \small
8609 \begin{tabular}{llccccc}
8610 \toprule
8611 %<*en>
8612 &&\multicolumn{4}{c}{Next}\\\cmidrule(lr){3-7}
8613 &&\hbox to 4em{\hss Letter\hss}&\hbox to 4em{\hss Other\hss}
8614 &\hbox to 4em{\hss Kanji\hss}&\hbox to 4em{\hss Open\hss}&Close\\\midrule
8615 &Letter&collects&\multicolumn{3}{c}{\hrulefill \ outputs\ \hrulefill}&collects\\
8616 &Other&outputs&collects&\multicolumn{2}{c}{\hrulefill \ outputs\ \hrulefill}&collects\\
8617 Prev&Kanji&\multicolumn{4}{c}{\hrulefill \ outputs\ \hrulefill}&collects\\
8618 &Open&\multicolumn{5}{c}{\hrulefill \ collects\ \hrulefill}\\
8619 &Close&\multicolumn{4}{c}{\hrulefill \ outputs\ \hrulefill}&collects\\
8620 %</en>
8621 %<*ja>
8622 &&\multicolumn{4}{c}{後ろ側の文字}\\\cmidrule(lr){3-7}
8623 &&\hbox to 4em{\hss Letter\hss}&\hbox to 4em{\hss Other\hss}
8624 &\hbox to 4em{\hss Kanji\hss}&\hbox to 4em{\hss Open\hss}&Close\\\midrule
8625 直&Letter&収集&\multicolumn{3}{c}{\hrulefill \ 出力\ \hrulefill}&収集\\
8626 前&Other&出力&収集&\multicolumn{2}{c}{\hrulefill \ 出力\ \hrulefill}&収集\\
8627 文&Kanji&\multicolumn{4}{c}{\hrulefill \ 出力\ \hrulefill}&収集\\
8628 字&Open&\multicolumn{5}{c}{\hrulefill \ 収集\ \hrulefill}\\
8629 種&Close&\multicolumn{4}{c}{\hrulefill \ 出力\ \hrulefill}&収集\\
8630 %</ja>
8631 \bottomrule
8632 \end{tabular}
8633 \end{center}
8634 %<en>In the above table,
8635 %<ja>上の表において,
8636 \begin{itemize}
8637 %<en>\item ``outputs'' means to output the collected character string (i.e., line breaking is permitted there).
8638 %<ja>\item 「出力」は,それまでに集めた文字列を出力(≒ここで行分割可能)を意味する.
8639
8640 %<en>\item ``collects'' means to append the next character to the collected character string (i.e., line breaking is prohibited there).
8641 %<ja>\item 「収集」は,後側の文字を,現在収集された文字列に追加(行分割不可)を意味する.
8642 \end{itemize}
8643
8644 %<*en>
8645 Characters above or equal to~\texttt{U+0080} \emph{except Variation Selectors}
8646 are classified into above 5~classes by the following rules:
8647 %</en>
8648 %<*ja>
8649 \texttt{U+0080}以降の\emph{異体字セレクタ以外の}各文字が
8650 Letter, Other, Kanji, Open, Closeのどれに属するかは次によって決まる:
8651 %</ja>
8652 \begin{itemize}
8653 %<en>\item \textbf{ALchar}s above or equal to~\texttt{U+0080} are classified as Letter.
8654 %<ja>\item (\texttt{U+0080}以降の)\textbf{ALchar}は,すべてLetter扱いである.
8655
8656 %<en>\item \textbf{JAchar}s are classified in the order as follows:
8657 %<ja>\item \textbf{JAchar}については,以下の順序に従って文字種を決める:
8658 \begin{enumerate}
8659 %<en>\item Characters whose \Param{prebreakpenalty} is greater than or equal to 0 are classified as Open.
8660 %<ja>\item \Param{prebreakpenalty}が0以上の文字はOpen扱いである.
8661
8662 %<en>\item Characters whose \Param{postbreakpenalty} is greater than or equal to 0 are classified as Close.
8663 %<ja>\item \Param{postbreakpenalty}が0以上の文字はClose扱いである.
8664
8665 %<en>\item Characters that don't satisfy the above two conditions are classified as Kanji.
8666 %<ja>\item 上の3条件のどちらにも当てはまらなかった文字は,Kanji扱いである.
8667 \end{enumerate}
8668 \end{itemize}
8669
8670 %<*en>
8671 The width of halfwidth kana (\texttt{U+FF61}--\texttt{U+FF9F})
8672 is same as the width of \textbf{ALchar};
8673 the width of the other \textbf{JAchar}s is double the width of \textbf{ALchar}.
8674 %</en>
8675 %<*ja>
8676 なお,半角カナ(U+FF61--U+FF9F)以外の\textbf{JAchar}は欧文文字2文字分の幅をとるものとみなされる.
8677 半角カナは欧文文字1文字分の幅となる.
8678 %</ja>
8679
8680 %<*en>
8681 This classification process is executed every time a character appears in
8682 the \texttt{lstlisting} environment or other environments/commands.
8683 %</en>
8684 %<*ja>
8685 これらの文字種決定は,実際に \texttt{lstlisting} 環境などの内部で文字が出てくるたびに行われる.
8686 %</ja>
8687
8688 %<*ja>
8689 \section{和文の行長補正方法}
8690 \label{sec-adjspec}
8691 \Pkg{luatexja-adjust} で提供される優先順位付きの行長調整の詳細を述
8692 べる.大まかに述べると,次のようになる.
8693 \begin{itemize}
8694 \item 通常の\TeX の行分割方法に従って,段落を行分割する.この段階では,行
8695       長に半端が出た場合,その半端分は\textbf{JAglue}(\Param{xkanjiskip},
8696       \Param{kanjiskip},JFMグルー)と
8697       それ以外のグルーの全てで(優先順位なく)負担される.
8698 \item その後,\texttt{post\_linebreak\_filter} callbackを使い,\emph{段
8699       落中の各行ごとに},行末文字の位置を調整したり,優先度付きの行長調整
8700       を実現するためにグルーの伸縮度を調整する.
8701       その処理においては,グルーの自然長と\textbf{JAglue}以外の
8702       グルーの伸び量・縮み量は変更せず,必要に応じて\textbf{JAglue}の伸び量・縮み量のみを
8703       変更する設計とした.
8704
8705 \Pkg{luatexja-adjust} の作用は,この処理を行うcallbackを追加するだけであり,
8706       この章の残りではcallbackでの処理について解説する.
8707 \end{itemize}
8708
8709 \paragraph{準備:合計伸縮量の計算}
8710 グルーの伸縮度(\texttt{plus} や \texttt{minus} で指定されている値)には,
8711 有限値の他に,\texttt{fi},\texttt{fil},\texttt{fill},\texttt{filll}と
8712 いう4つの無限大レベル(後ろの方ほど大きい)があり,行の調整に
8713 \texttt{fi} などの\emph{無限大レベルの伸縮度が用いられている場合は,そ
8714 の行に対しての処理を中止}する.
8715
8716 よって,以降,問題にしている行の行長調整は伸縮度が有限長のグルーを用いて
8717 行われているとして良い.さらに,簡単のため,この行はグルーが広げられている
8718 (自然長で組むと望ましい行長よりの短い)場合しか扱わない.
8719
8720 まず,段落中の行中のグルーを
8721 \begin{itemize}
8722 \item \textbf{JAglue}ではないグルー
8723 \item JFMグルー(優先度\footnote{%
8724   \ref{ssec-jfm-str}節にあるように,
8725   各JFMグルーには$-2$から2までの優先度がついている.}%
8726 別にまとめられる)
8727 \item 和欧文間空白(\Param{xkanjiskip})
8728 \item 和文間空白(\Param{kanjiskip})
8729 \end{itemize}
8730 の$1+1+5+1=8$つに類別し,それぞれの種別ごとに
8731 許容されている伸び量(\texttt{stretch}の値)の合計を計算する.
8732 また,行長と自然長との差を\textit{total}とおく.
8733
8734
8735 \subsection{行末文字の位置調整}
8736 行末が文字クラス$n$の\textbf{JAchar}であった場合,
8737 それを動かすことによって,\textit{total}のうち
8738 \textbf{JAglue}が負担する分を少なくしようとする.
8739 この行末文字の左右の移動可能量は,
8740 JFM中にある文字クラス$n$の定義の
8741 \texttt{end\_stretch},~\texttt{end\_shrink}フィールドに
8742 全角単位の値として記述されている.
8743
8744 例えば,行末文字が句点「。」であり,そこで用いられているJFM中に
8745 \begin{lstlisting}
8746   [2] = {
8747     chars = { '。', ... }, width = 0.5, ...,
8748     end_stretch = 0.5, end_shrink = 0.5,
8749   },
8750 \end{lstlisting}
8751 という指定があった場合,この行末の句点は
8752 \begin{itemize}
8753 \item 通常の\TeX の行分割処理で「半角以上の詰め」が行われていた場合,
8754 この行中の\textbf{JAglue}の負担を軽減するため,
8755 行末の句点を半角だけ右に移動する(ぶら下げ組を行う).
8756 \item 通常の\TeX の行分割処理で「半角以上の空き」が行われていた場合,
8757 逆に行末句点を半角左に移動させる(見た目的に全角取りとなる).
8758 \item 以上のどちらでもない場合,行末句点の位置調整は行わない.
8759 \end{itemize}
8760 となる.
8761
8762 行末文字を移動した場合,その分だけ\textit{total}の値を引いておく.
8763
8764 \subsection{グルーの調整}
8765 \textit{total}の分だけが,行中のグルーの伸び量に応じて負担されることになる.
8766 負担するグルーの優先度は以下の順であり,
8767 できるだけ\Param{kanjiskip}を自然長のままにすることを
8768 試みている.
8769 \begin{enumerate}\def\labelenumi{(\Alph{enumi})}
8770  \item \textbf{JAglue}以外のグルー
8771  \item 優先度2のJFMグルー
8772  \item 優先度1のJFMグルー
8773  \item 優先度0のJFMグルー
8774  \item 優先度$-1$のJFMグルー
8775  \item 優先度$-2$のJFMグルー
8776  \item \Param{xkanjiskip}
8777  \item \Param{kanjiskip}
8778 \end{enumerate}
8779 \begin{enumerate}
8780  \item 行末の和文文字を移動したことで$\textit{total}=0$となれば,
8781 調整の必要はなく,行が格納されているhboxの
8782 \texttt{glue\_set}, \texttt{glue\_sign}, \texttt{glue\_order}を再計算すればよい.
8783 以降,$\textit{total}\neq 0$と仮定する.
8784  \item \textit{total}が「\textbf{JAglue}以外のグルーの伸び量の合計」(以下,(A)の伸び量の
8785        合計,と称す)よりも小さければ,
8786 それらのグルーに\textit{total}を負担させ,\textbf{JAglue}達自身は自然長で組むことができる.
8787 よって,以下の処理を行う:
8788 \begin{enumerate}
8789 \item 各\textbf{JAglue}の伸び量を0とする.
8790 \item 行が格納されているhboxの
8791 \texttt{glue\_set}, \texttt{glue\_sign}, \texttt{glue\_order}を再計算する.
8792 これによって,\textit{total}は\textbf{JAglue}以外のグルーによって負担される.
8793 \end{enumerate}
8794 \item \textit{total}が「(A)の伸び量の合計」以上ならば,(A)--(H)のどこまで負担すれば
8795 \textit{total}以上になるかを計算する.
8796 例えば,
8797 \[\catcode`\<=12
8798  \textit{total} = (\text{(A)--(B)の伸び量の合計}) + p\cdot (\text{(C)の伸び量の合計}),
8799  \qquad 0\le p<1
8800 \]
8801 であった場合,各グルーは次のように組まれる:
8802 \begin{itemize}
8803  \item (A),~(B)に属するグルーは各グルーで許された伸び量まで伸ばす.
8804  \item (C)に属するグルーはそれぞれ$p\times (\text{伸び量})$だけ伸びる.
8805  \item (D)--(H)に属するグルーは自然長のまま.
8806 \end{itemize}
8807 実際には,前に述べた「設計」に従い,次のように処理している:
8808 \begin{enumerate}
8809 \item (C)に属するグルーの伸び量を$p$倍する.
8810 \item (D)--(H)に属するグルーの伸び量を0とする.
8811 \item 行が格納されているhboxの
8812 \texttt{glue\_set}, \texttt{glue\_sign}, \texttt{glue\_order}を再計算する.
8813 これによって,\textit{total}は\textbf{JAglue}以外のグルーによって負担される.
8814 \end{enumerate}
8815 \item \textit{total}が(A)--(H)の伸び量の合計よりも大きい場合,どうしようもないので
8816       \verb+^^;+何もしない.
8817 \end{enumerate}
8818
8819 %</ja>
8820
8821 %<*ja>
8822 \section{IVS対応}
8823 \verb+luatexja.otf.enable_ivs()+ を実行し,IVS対応を有効にした状態では,
8824 \verb+pre_linebreak_filter+ や \verb+hpack_filter+ コールバックには
8825 次の4つが順に実行される状態となっている:
8826 \begin{description}
8827 \item[\tt ltj.do\_ivs] \textit{glyph\_node}~$p$の直後に,異体字セレクタ(を表す\textit{glyph\_node})
8828 が連続した場合に,$p$のフォントに対応したが持つ「異体字情報」に従って出力するグリフを変える.
8829
8830 しかし,単に$p.\textit{char}$を変更するだけでは,後から
8831 font featureの適用(すぐ下)により置換される可能性がある.そのため,
8832 \cs{CID} や \cs{UTF} と同じように,\textit{glyph\_node}~$p$の代わりに
8833 \texttt{user\_id} が\textit{char\_by\_cid}であるようなuser-defined whatsitを用いている.
8834 \item[(\Pkg{luaotfload} によるfont featureの適用)]
8835 \item[\tt ltj.otf] \texttt{user\_id} が\textit{char\_by\_cid}であるようなuser-defined whatsitを
8836 きちんと\textit{glyph\_node}に変換する.この処理は,\cs{CID}, \cs{UTF}やIVSによる置換が,
8837 font featureの適用で上書きされてしまうのを防止するためである.
8838 \item[\tt ltj.main\_process] \textbf{JAglue}の挿入処理(\ref{sec-jfmglue}章)と,
8839 JFMの指定に従って各\textbf{JAchar}の「寸法を補正」することを行う.
8840 \end{description}
8841
8842 問題は各フォントの持っているIVS情報をどのように取得するか,である.
8843 \Pkg{luaotfload} はフォント番号<font\_number>の情報を\
8844 \texttt{fonts.hashes.identifiers[<font\_number>]} 以下に格納している.
8845 しかし,OpenTypeフォントのIVS情報は格納されていないようである%
8846 \footnote{TrueTypeフォントに関しては,
8847 \begin{center}
8848 \texttt{fonts.hashes.idenfiers[<font\_number>]%
8849   .resources.variants[<selector>][<base\_char>]}
8850 \end{center}
8851 に,<base\_char>番の文字の後に異体字セレクタ<selector>が続いた場合に
8852 出力すべきグリフが書かれてある.}.
8853 %例えば,小塚明朝Pr6N~Rでは,
8854
8855 一方,\LuaTeX 内部の \texttt{fontloader} の返すテーブルには
8856 OpenTypeフォントでもTrueTypeフォントでもIVS情報が格納されている.
8857 具体的には……
8858
8859 そのため,\LuaTeX-jaのIVS対応においては,\LuaTeX 内部の\
8860 \texttt{fontloader} を直接用いることで,フォントのIVS情報を取得している.
8861 20140114.0以降でキャッシュを用いるようにした要因はここにあり,
8862 \texttt{fontloader} の呼び出しでかなり時間を消費することから,
8863 %%% to_table を使わなくしたことで,メモリ使用量は減った
8864 IVS情報をキャッシュに保存することで2回目以降の実行時間を節約している.
8865 %</ja>
8866
8867
8868 %<*ja>
8869 \section{複数フォントの「合成」(未完)}
8870 \section{\LuaTeX-jaにおけるキャッシュ}
8871 \Pkg{luaotfload}パッケージが,各TrueType・OpenTypeフォントの情報を
8872 キャッシュとして保存しているのと同様の方法で,
8873 \LuaTeX-jaもいくつかのキャッシュファイルを作成するようになった.
8874 \begin{itemize}
8875  \item 通常,キャッシュは\texttt{\$TEXMFVAR/luatexja/}以下に保存され,
8876 そこから読み込みが行われる.
8877  \item 「通常の」テキスト形式のキャッシュ(拡張子は \texttt{.lua})以外にも,
8878 それをバイナリ形式(バイトコード)に変換したものもサポートしている.
8879 \begin{itemize}
8880  \item \LuaTeX とLuaJIT\TeX ではバイトコードの形式が異なるため,バイナリ形式の
8881 キャッシュは共有できない.\LuaTeX 用のバイナリキャッシュは \texttt{.luc},
8882 LuaJIT\TeX 用のは \texttt{.lub} と拡張子を変えることで対応している.
8883  \item キャッシュを読み込む時,同名のバイナリキャッシュがあれば,
8884 テキスト形式のものよりそちらを優先して読み込む.
8885  \item テキスト形式のキャッシュが更新/作成される際は,そのバイナリ版も
8886 同時に更新される.
8887 また,(バイナリ版が見つからず)テキスト形式のキャッシュ側が読み込まれたときは,
8888 \LuaTeX-jaはバイナリキャッシュを作成する.
8889 \end{itemize}
8890 \end{itemize}
8891 %</ja>
8892 %<*en>
8893 \section{Cache Management of \LuaTeX-ja}
8894 \LuaTeX-ja creates some cache files to reduce the loading time.
8895 in a similar way to the \Pkg{luaotfload} package:
8896 \begin{itemize}
8897  \item Cache files are usually stored in (and loaded from)
8898 \texttt{\$TEXMFVAR/luatexja/}.
8899  \item In addition to caches of the text form (the extension is ``\texttt{.lua}''),
8900 caches of the \emph{binary}, precompiled form are supported.
8901 \begin{itemize}
8902  \item We cannot share same binary cache for \LuaTeX\ and LuaJIT\TeX.
8903 Hence we distinguish them by their extension, ``\texttt{.luc}'' for \LuaTeX\
8904 and ``\texttt{.lub}'' for LuaJIT\TeX.
8905  \item In loading a cache, the binary cache precedes
8906 the text form.
8907  \item When \LuaTeX-ja updates a cache \texttt{hoge.lua},
8908 its binary version is also updated.
8909 \end{itemize}
8910 \end{itemize}
8911 %</en>
8912
8913 %<*ja>
8914 \subsection{キャッシュの使用箇所}
8915
8916 \LuaTeX-ja では以下の3種類のキャッシュを使用している:
8917 \begin{cslist}
8918 \item[ltj-cid-auto-adobe-japan1.lua]
8919 Ryumin-Lightのような非埋め込みフォントの情報を格納しており,
8920 (それらが\LuaTeX-jaの標準和文フォントなので)\LuaTeX-jaの読み込み時に自動で読まれる.
8921 生成には\texttt{UniJIS2004-UTF32-\{H, V\}}, \texttt{Adobe-Japan1-UCS2}という3つの
8922 CMapが必要である.
8923
8924 \pageref{para-cid}ページで述べたように,\texttt{cid}キーを使って
8925 非埋め込みの中国語・韓国語フォントを定義する場合,同様のキャッシュが生成される.
8926 キャッシュの名称,必要となるCMapについては表\ref{tab:cid-cache}を参照して欲しい.
8927
8928 \item[extra\_***.lua]
8929 フォント``\texttt{***}''における異体字セレクタの情報,縦組用字形への変換テーブル,そして
8930 縦組時における幅を格納している.構造は以下の通り:
8931 %</ja>
8932 %<*en>
8933 \subsection{Use of Cache}
8934
8935 \LuaTeX-ja uses the following cache:
8936 \begin{cslist}
8937 \item[ltj-cid-auto-adobe-japan1.lua]
8938 The font table of a CID-keyed non-embedded Japanese font.
8939 This is loaded in every run.
8940 It is created from three CMaps, \texttt{UniJIS2004-UTF32-\{H,V\}} and
8941              \texttt{Adobe-Japan1-UCS2},
8942 and this is why these two CMaps are needed in the first run of \LuaTeX-ja.
8943
8944 Similar caches are created as Table~\ref{tab:cid-cache},
8945 if you specified \texttt{cid} key in \cs{jfont}
8946 to use other CID-keyed non-embedded fonts for Chinese or Korean,
8947 as in Page~\pageref{para-cid}.
8948
8949 \item[extra\_***.lua]
8950 This file stores the table which stores the following.
8951 \begin{itemize}
8952  \item unicode variants in a font ``\texttt{***}''
8953  \item vertical width of glyphs, if it is not equal to the sum of 
8954 the height of ascender and the depth of descender
8955  \item vertical variants
8956 \end{itemize}
8957 The following is the structure of the that table.
8958 %</en>
8959
8960 \begin{table}[!tb]
8961  \centering\small
8962 \caption{\texttt{cid} key and corresponding files}
8963 \label{tab:cid-cache}
8964 \vspace*{\medskipamount}
8965 \begin{tabular}{>{\tt}l>{\tt}l>{\tt}l>{\tt}l}
8966 \toprule
8967 \bf \texttt{cid} key&\bf name of the cache &
8968 \multicolumn{2}{c}{\bf used CMaps}\\
8969 \midrule
8970 Adobe-Japan1-*&ltj-cid-auto-adobe-japan1.lua&UniJIS2004-UTF32-*&Adobe-Japan1-UCS2\\
8971 Adobe-Korea1-*&ltj-cid-auto-adobe-korea1.lua&UniKS-UTF32-*&Adobe-Korea1-UCS2\\
8972 Adobe-GB1-*&ltj-cid-auto-adobe-gb1.lua&UniGB-UTF32-*&Adobe-GB1-UCS2\\
8973 Adobe-CNS1-*&ltj-cid-auto-adobe-cns1.lua&UniCNS-UTF32-*&Adobe-CNS1-UCS2\\
8974 \bottomrule
8975 \end{tabular}
8976 \end{table}
8977
8978 \begin{lstlisting}
8979 return {
8980  {
8981   [10955]={    -- U+2ACB "Subset Of Above Not Equal To"
8982    [65024]=983879, -- <2ACB FE00>
8983    ["vwidth"]=0.98, -- vertical width
8984   },
8985   [37001]={    -- U+9089 "邉"
8986    [0]=37001,  --   <9089 E0100>
8987    991049,     --   <9089 E0101>
8988    ...
8989    ["vert"]=995025, -- vertical variant
8990   },
8991   ...
8992  },
8993  ["chksum"]="FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", -- checksum of the fontfile
8994  ["version"]=2, -- version of the cache
8995 }
8996 \end{lstlisting}
8997 %<*ja>
8998 \item[ltj-jisx0208.\{luc|lub\}]
8999 \LuaTeX-ja配布中の\texttt{ltj-jisx0208.lua}をバイナリ化したものである.
9000 これはJIS~X~0208とUnicodeとの変換テーブルであり,
9001 \pTeX との互換目的の文字コード変換命令で用いられる.
9002 %</ja>
9003 %<*en>
9004 \item[ltj-jisx0208.\{luc|lub\}]
9005 The binary version of \texttt{ltj-jisx0208.lua}.
9006 This is the conversion table between JIS~X~0208 and Unicode
9007 which is used in Kanji-code conversion commands for compatibility with \pTeX.
9008 %</en>
9009 \end{cslist}
9010
9011 %<*en>
9012 \subsection{Internal}
9013 Cache management system of \LuaTeX-ja is stored in \texttt{luatexja.base}
9014 (\texttt{ltj-base.lua}).
9015 There are three public functions for cache management in \texttt{luatexja.base},
9016 where <filename> stands for the file name \emph{without suffix}:
9017 \begin{cslist}
9018 \item[save\_cache(<filename>, <data>)]
9019 Save a non-nil table <data> into a cache <filename>.
9020 Both the text form <filename>\texttt{.lua} and its binary version
9021 are created or updated.
9022
9023 \item[save\_cache\_luc(<filename>, <data>{[, <serialized\_data>]})]
9024
9025 Same as \texttt{save\_cache}, except that only the binary cache is updated.
9026 The third argument <serialized\_data> is not usually given.
9027 But if this is given, it is treated as a string representation of <data>.
9028
9029 \item[load\_cache(<filename>, <outdate>)]
9030 Load the cache <filename>.
9031 <outdate> is a function which takes one argument (the contents of the cache),
9032 and its return value is whether the cache is outdated.
9033
9034 \texttt{load\_cache} first tries to
9035 read the binary cache <filename>\texttt{.\{luc|lub\}}.
9036 If its contents is up-to-date, \texttt{load\_cache} returns the contents.
9037 If the binary cache is not found or
9038 its contents is outdated, \texttt{load\_cache} tries to
9039 read the text form <filename>\texttt{.lua}.
9040 Hence, the return value of \texttt{load\_cache} is non-nil,
9041 if and only if the updated cache is found.
9042 \end{cslist}
9043 %</en>
9044 %<*ja>
9045 \subsection{内部命令}
9046 \LuaTeX-jaにおけるキャッシュ管理は,\texttt{luatexja.base}~(\texttt{ltj-base.lua})に
9047 実装しており,以下の3関数が公開されている.
9048 ここで,<filename>は保存するキャッシュのファイル名を\emph{拡張子なしで}指定する.
9049 \begin{cslist}
9050 \item[save\_cache(<filename>, <data>)]
9051 nilでない<data>をキャッシュ<filename>に保存する.
9052 テキスト形式の<filename>\texttt{.lua}のみならず,
9053 そのバイナリ版も作成/更新される.
9054
9055 \item[save\_cache\_luc(<filename>, <data>{[, <serialized\_data>]})]
9056
9057 \texttt{save\_cache}と同様だが,バイナリキャッシュのみが更新される.
9058 第3引数<serialized\_data>が与えられた場合,それを
9059 <data>の文字列化表現として使用する.
9060 そのため,<serialized\_data>は普通は指定しないことになるだろう.
9061
9062 \item[load\_cache(<filename>, <outdate>)]
9063 キャッシュ<filename>を読み込む.
9064 <outdate>は1引数(キャッシュの中身)をとる関数であり,
9065 その戻り値は「キャッシュの更新が必要」かどうかを示すブール値でないといけない.
9066
9067 \texttt{load\_cache}は,まずバイナリキャッシュ<filename>\texttt{.\{luc|lub\}}を
9068 読みこむ.もしその内容が「新しい」,つまり<outdate>の評価結果が \texttt{false} なら
9069 \texttt{load\_cache}はこのバイナリキャッシュの中身を返す.
9070 もしバイナリキャッシュが見つからなかったか,「古すぎる」ならばテキスト版
9071              <filename>\texttt{.lua}を読み込み,その値を返す.
9072
9073 以上より,\texttt{load\_cache}自体がnilでない値を返すのは,ちょうど「新しい」キャッシュが
9074 見つかった場合である.
9075 \end{cslist}
9076 %</ja>
9077
9078
9079 %<*ja>
9080 \section{縦組の実装}
9081 \label{sec-dir-imp}
9082 \ref{sec-direction}章の最初でも述べたように,
9083 \LuaTeX-jaは横組(\texttt{TLT})で組んだボックスを回転させる方式で
9084 縦組を実装している.
9085
9086 \LuaTeX-jaにおける縦組の実装は
9087 \pTeX における実装(\cite{ptexdoc,ptextug})をベースにしている.
9088
9089 \subsection{direction~whatsit}
9090 \textit{direction}~whatsitとは,\textit{direction}という特定の \verb+user_id+ を持つ
9091 whatsitのことであり,以下のタイミングで作られる.
9092 \begin{itemize}
9093  \item 組方向を \cs{tate} 等で変更したとき.
9094  \item \cs{hbox}, \cs{vbox}, \cs{vtop} による明示的なボックスの開始時.\\
9095 \verb+\hbox{}+, \verb+\vbox{}+ といった,
9096 \begin{itemize}
9097  \item \cs{tate} 等によりボックス内部の組方向を変更していない
9098  \item ボックスの中身のリストが空である
9099 \end{itemize}
9100 場合は,\LuaTeX の \verb+hpack_filter+, \verb+vpack_filter+ といった
9101 callbackに処理が回らない.そこで,\LuaTeX-ja では,\cs{everyhbox}, \cs{everyvbox} を利用す
9102        ることで各ボックスの先頭に確実に追加するようにしている\footnote{%
9103   問題は \cs{hbox to 25pt\{\}} という状況である.実際のこのボックスの中身は空でない(少な
9104        くともdirection whatsitがある)ため,何も対策をしなければhpack時にUnderfill警告が発
9105        生してしまうことになる.\LuaTeX-jaではそうならないように「\cs{hbadness},
9106        \cs{vbadness} を一時的に10000に変更し,hpack, vpack後に元の値に戻す」処理を行ってい
9107        る.
9108 }.
9109  \item \cs{vsplit}によってvboxを分割した時の「残り」の先頭.
9110  \item \LuaTeX-ja読み込み前に作成したボックスの寸法を \cs{ltjsetwd} 等によって変更した時.
9111  \item \cs{insert} によるinsertionでは,中身の先頭に\textit{direction}~whatsitは作られず,
9112 その代わりに中身の各ボックス・罫線の直前に作られる\footnote{%
9113  これは,ページ分割の過程でinsertionが分割される時,「現在のページで出力される部分」が空と
9114        なることがあることによる.先頭にwhatsitを置くと,最悪でも「現在のページにwhatsitが
9115        残る」ことになってしまう.}.
9116 \end{itemize}
9117 なお,\verb+\vtop{...}+ の場合は,先頭にdirection whatsitを置くと
9118 ボックスの高さが常に0\,ptになるという問題が発生する.そのため,この場合に限っては
9119 vpack時にdirection whatsitをリストの2番目に移動させている.
9120
9121 direction whatsitはあくまでも組方向処理のための補助的なノードであるので,
9122 \cs{unhbox}, \cs{unhcopy} によってボックスの中身が展開される時には展開直前に削除される.
9123 これは
9124 \begin{lstlisting}
9125  % yoko direction
9126 \setbox0=\hbox{\tate B}
9127 \noindent % 水平モードに入る.この時点でのリストの中身は空
9128 \unhbox0 A
9129 \end{lstlisting}
9130 といった場合に,段落が縦組で組まれたり,あるいは
9131 \begin{lstlisting}
9132 \setbox0=\hbox{}
9133 \leavevmode \hbox{A}\unhbox0
9134 \setbox1=\lastbox % \box1 はどうなる?
9135 \end{lstlisting}
9136 で \cs{box1} が \cs{hbox\{A\}} でなく空になってしまうことを防ぐためである.
9137
9138
9139 \subsection{\textit{dir\_box}}
9140 縦中横など異方向のボックスを配置する場合に,周囲の組方向と大きさを整合させるため,
9141 \LuaTeX-jaでは \verb+\ltj@dir+ が128以降の\textit{hlist\_node}, \textit{vlist\_node}を
9142 用いる.これらは\pTeX における\textit{dir\_node}の役割と同じ果たしており,
9143 この文章中では\textit{dir\_box}と呼称する.
9144
9145 \subsubsection{異方向のボックスの整合}
9146 \textit{dir\_box}の第一の使用目的は,異方向のボックスの大きさを整合させることである.
9147 例えば,
9148 \begin{lstlisting}
9149  % yoko direction
9150 平成\hbox{\tate 26}年
9151 \end{lstlisting}
9152 は段落中で
9153 \[
9154  \xymatrix{
9155    {}\Node{glyph}{`平'}\ar[r]&{}\Node{glyph}{`成'}\ar[r]&
9156    {}\HNode{hlist}{10.00003}{3.02779}{0.0}\ar[r]\ar[d]^{\text{中身}}&{}\Node{glyph}{`年'}\\
9157    &&{}\Node{whatsit}{\cs{tate}}\ar[r]&{}\Node{glyph}{`2'}\ar[r]&{}\Node{glyph}{`6'}
9158  }
9159 \]
9160 というリストを作る.その後,この段落が終了したときに,
9161 \LuaTeX-jaの\textbf{JAglue}挿入処理が行われ
9162 \[
9163  \xymatrix{
9164    {}\Node{glyph}{`平'}\ar[r]
9165   &{}\textcolor{blue}{\Node{glue}{\Param{xkanjiskip}}}\ar[r]
9166   &{}\Node{glyph}{`成'}\ar[r]
9167   &{}\textcolor{blue}{\Node{penalty}{0}}
9168     \ar`r[d] `[l] `[ddll] `[dl] [dl]
9169   \\
9170   &&{}\textcolor{red}{\HNode{hlist}{3.02779}{10.00003}{0.0}}\ar[r]\ar[d]^{\text{中身}}
9171   &{}\textcolor{blue}{\Node{penalty}{0}}\ar[r]
9172   &{}\Node{glyph}{`年'}\\
9173   &&{}\HNode{\textit{dir\_box} (\cs{yoko})}{10.00003}{3.02779}{0.0}\ar[d]^{\text{中身}}\\
9174   &&{}\Node{whatsit}{\cs{tate}}\ar[r]&{}\Node{glyph}{`2'}\ar[r]&{}\Node{glyph}{`6'}
9175  }
9176 \]
9177 のようになる(青字は\textbf{JAglue},赤字が整合処理のための\textit{dir\_box}である).
9178 \TeX の \cs{showbox} 形式で書けば
9179
9180 \medskip{\narrowbaselines\ttfamily\obeylines\parindent0pt
9181 \catcode`\@=0 @catcode`@\=12
9182 .\tenmin 平
9183 @textcolor{blue}{.\glue 0.0 plus 0.4 minus 0.4}
9184 .\tenmin 成
9185 @textcolor{blue}{.\penalty 0}
9186 @textcolor{red}{.\hbox(10.00003+0.0)x3.02779, direction TLT}
9187 ..\hbox(3.02779+0.0)x10.00003, direction TLT
9188 ...\whatsit4=[]
9189 ...\tenrm 2
9190 ...\tenrm 6
9191 @textcolor{blue}{.\penalty 0}
9192 .\tenmin 年
9193 }\medskip
9194
9195 \noindent である.
9196
9197 なお,\cs{raise},~\cs{lower}, \cs{moveleft},~\cs{moveright} といったボックス移動命令では.
9198 移動を正しく表現するために段落やボックスの途中でも異方向のボックスは\textit{dir\_box}にカ
9199 プセル化している.
9200 例えば
9201 \begin{lstlisting}
9202  % yoko direction
9203 平成\raise1pt\hbox{\tate 26}年\showlists
9204 \end{lstlisting}
9205 は以下のような結果を得る.
9206
9207 \medskip{\narrowbaselines\ttfamily\obeylines\parindent0pt
9208 \catcode`\@=0 @catcode`@\=12
9209 (前略)
9210 \tenrm 平
9211 \tenrm 成
9212 @textcolor{red}{\hbox(10.00003+0.0)x3.02779, shifted -1.0, direction TLT}
9213 .\hbox(3.02779+0.0)x10.00003, direction TLT
9214 ..\whatsit4=[]
9215 ..\tenrm 2
9216 ..\tenrm 6
9217 \tenrm 年
9218 }\medskip
9219
9220 また,メインの垂直リストに異方向のボックスが追加される場合にも同様に即座に
9221 \textit{dir\_box}にカプセル化している.ページ分割のタイミングを正
9222 しく\TeX が判断するためである.
9223 \cs{lastbox} によるボックスの取得では,\textit{dir\_box}は削除される.
9224
9225 \subsubsection{異方向のボックス寸法の格納}
9226 第二の使用目的は,現在の組方向がボックス本来の組方向とは異なる状況で,
9227 \cs{ltjsetwd} によってボックス寸法を設定されたことを記録することである.
9228
9229 例えば
9230 \begin{lstlisting}[numbers=left]
9231 \setbox0=\hbox{\vrule width 10pt height 5pt depth 2pt}
9232 \setbox1=\hbox{\tate\ltjsetwd0=20pt}
9233 \wd0=9pt
9234 \setbox1=\hbox{\dtou\ltjsetwd0=20pt}
9235 \setbox0=\hbox{\dtou a\box0}
9236 \end{lstlisting}
9237 というコードを考える.1行目で \cs{box0} には横組の
9238 幅10\,pt,高さ5\,pt,深さ2\,ptのボックスが代入される.
9239 よって,
9240 \begin{itemize}
9241  \item 縦組下では \cs{box0} は幅7\,pt,高さ・深さ5\,ptのボックスとして扱われる.
9242  \item \cs{dtou} 下では \cs{box0} は幅7\,pt,高さ10\,pt,深さ0\,ptのボックスとして扱われる.
9243 \end{itemize}
9244 このとき,\cs{box0} の\emph{中身}は
9245 \[
9246  \xymatrix{
9247    {}\Node{whatsit}{\cs{yoko}}\ar[r]&{}\Node{rule}{}
9248  }
9249 \]
9250 である.
9251
9252 さて,2行目で縦組時の \cs{box0} の幅が20\,ptに設定される.この情報が
9253 direction~whatsit内部のノードリストに,\textit{dir\_box}として格納される:
9254 \[
9255  \xymatrix{
9256    {}\Node{whatsit}{\cs{yoko}}\ar[r]\ar[d]_{\text{中身}}&{}\Node{rule}{}\\
9257    {}\textcolor{red}{\HNode{\textit{dir\_box} (\cs{tate})}{20.0}{5.0}{5.0}}
9258  }
9259 \]
9260
9261 次に,3行目では横組時の,つまり \cs{box0} 本来の組方向での深さが9\,ptに変更される.
9262 このとき,\cs{box0} は
9263 \begin{itemize}
9264  \item 縦組下では寸法代入が既に行われているので,2行目で作成された\textit{dir\_box}の通り
9265        に幅20\,pt,高さ・深さ5\,ptのボックスとして扱われる.
9266  \item \cs{dtou} 下ではまだ寸法代入が行われていないので,
9267 \cs{box0} の寸法変更に追従し,幅7\,pt,高さ9\,pt,深さ0\,ptのボックスとして扱われる.
9268 \end{itemize}
9269
9270 4行目では \cs{dtou} 下での\cs{box0} の幅が20\,ptに設定されるので,2行目と同じように
9271 \[
9272  \xymatrix{
9273    {}\Node{whatsit}{\cs{yoko}}\ar[r]\ar[d]_{\text{中身}}&{}\Node{rule}{}\\
9274    {}\textcolor{red}{\HNode{\textit{dir\_box} (\cs{dtou})}{20.0}{9.0}{0.0}}\ar[r]&
9275    {}\HNode{\textit{dir\_box} (\cs{tate})}{20.0}{5.0}{5.0}
9276  }
9277 \]
9278 と\textit{dir\_box}が作成される.
9279
9280 このように寸法代入によってつくられた\textit{dir\_box}は,前節の整合過程のときに再利用され
9281 る.上記の例でいえば,5行目を実行した後の \cs{box0} の内容は
9282 \[
9283  \xymatrix{
9284    {}\Node{whatsit}{\cs{dtou}}\ar[r]&
9285    {}\Node{glyph}{`a'}\ar[r]&
9286    {}\textcolor{red}{\HNode{\textit{dir\_box} (\cs{dtou})}{20.0}{9.0}{0.0}}\ar[d]_{\text{中身}}\\
9287    &&{}\HNode{hlist}{9.0}{5.0}{2.0}\ar[d]_{\text{中身}}\\
9288    &&{}\Node{whatsit}{\cs{yoko}}\ar[r]&{}\Node{rule}{}
9289  }
9290 \]
9291 のようになる.
9292 %</ja>
9293
9294 \newpage
9295 \begin{thebibliography}{99}
9296   \addcontentsline{toc}{section}{\refname}
9297 \bibitem{texbytopic}
9298 Victor Eijkhout. \newblock \textit{\TeX\ by Topic, A \TeX nician's Reference}, Addison-Wesley, 1992.
9299 \bibitem{listings} C.\ Heinz, B.\ Moses. \newblock The \textsf{Listings} Package.
9300 \bibitem{uptex} Takuji Tanaka. \newblock
9301 upTeX---Unicode version of pTeX with CJK extensions,
9302 TUG 2013, October 2013.
9303 %<ja>\newblock
9304 %<en>\\\null\hfill
9305 \url{http://tug.org/tug2013/slides/TUG2013_upTeX.pdf}
9306 \bibitem{jlisting} Thor Watanabe. \newblock Listings\ -\ MyTeXpert.
9307 %<en>\newblock
9308 %<ja>\\\null\hfill
9309 \url{http://mytexpert.sourceforge.jp/index.php?Listings}
9310 \bibitem{jlreq}  W3C Japanese Layout Task Force~(ed). \newblock
9311 Requirements for Japanese Text Layout (W3C Working Group Note), 2011, 2012. \newblock
9312 \url{http://www.w3.org/TR/jlreq/}%
9313 %<ja> \\日本語訳の書籍版:W3C日本語組版タスクフォース(編),『W3C技術ノート 日本語組版処理の要件』,東京電機大学出版局,2012.
9314 \bibitem{min10} 乙部厳己.min10フォントについて.\\\null\hfill
9315 \url{http://argent.shinshu-u.ac.jp/~otobe/tex/files/min10.pdf}
9316 \bibitem{x4051} 日本工業規格(Japanese Industrial Standard). JIS~X~4051,
9317 日本語文書の組版方法(Formatting rules for Japanese documents), 1993, 1995, 2004.
9318 \bibitem{ptexdoc} 濱野尚人,田村明史,倉沢良一.\TeX の出版への応用—縦組み機能の組み込み—.
9319 \\\null\hfill\texttt{.../texmf-dist/doc/ptex/base/ptexdoc.pdf}
9320 \bibitem{ptextug} Hisato Hamano. \newblock
9321 \textit{Vertical Typesetting with \TeX}, TUGBoat~\textbf{11}(3), 346--352, 1990.
9322 \bibitem{pdfstd} International Organization for Standardization. \newblock
9323 ISO 32000-1:2008, \textit{Document management -- Portable document format -- Part 1: PDF
9324       1.7}, 2008. \newblock
9325 \\\null\hfill
9326 \url{http://www.iso.org/iso/iso\_catalogue/catalogue_tc/catalogue\_detail.htm?csnumber=51502}
9327 \end{thebibliography}
9328
9329 \end{document}
9330 %</!showexpl>
9331 %<*showexpl>
9332 %%
9333 %% config file for showexpl.sty
9334 %%
9335 %% Copyright The LuaTeX-ja project team, 2012
9336 %%
9337 \ProvidesFile{showexpl.cfg}
9338   [2012/05/20 v0.01 Definitions for the showexpl package (luatexja)]
9339 \lstset{}
9340 \def\SX@Info{}
9341 \endinput
9342 %</*showexpl>