OSDN Git Service

luatexja-adjust.sty に組み込み(ドキュメント途中)
[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 \IfFileExists{luatex85.sty}{\RequirePackage{luatex85}}{}
12
13 %<en>\documentclass[a4paper,titlepage]{article}
14 %<ja>\documentclass[a4paper,titlepage]{ltjsarticle}
15
16 %%%%%%%%
17 \makeatletter
18 %%%%%%%%
19 \def\pgfsysdriver{pgfsys-pdftex.def}
20 \directlua{if jit then jit.on() end}
21 \usepackage{metalogo,amsmath,array,tikz,pict2e,multienum,float}
22 \usepackage{booktabs,multicol,luatexja-ruby}
23 \usepackage[all]{xy}
24 \usepackage{lltjext,alltt,comment}
25
26 %%%%%%%% Lua GC
27 \patchcmd\@outputpage{\stepcounter{page}}{%
28   \directlua{%
29         if jit then
30       local k = collectgarbage("count")
31       if k>900000 then 
32         collectgarbage("collect")
33         texio.write_nl("term and log", "GC: ", math.floor(k), math.floor(collectgarbage("count")))
34       end
35         end
36   }%
37   \stepcounter{page}%
38 }{}{}
39
40 %%%%%%%% fonts
41 \usepackage{luatexja-otf}
42 \usepackage[no-math]{fontspec}
43 \setmainfont[Ligatures=TeX]{Linux Libertine O}
44 \setmonofont[Scale=MatchLowercase, ItalicFont=lmmono10-italic.otf,
45   BoldFont=lmmonolt10-bold.otf, BoldItalicFont=lmmonolt10-boldoblique.otf
46 ]{lmmono10-regular.otf}
47 \setsansfont[Scale=MatchLowercase,Ligatures=TeX]{Linux Biolinum O}
48 \usepackage[match]{luatexja-fontspec}
49 \usepackage[kozuka-pr6n]{luatexja-preset}
50 \usepackage{unicode-math}
51 \setmonojfont{KozGoPr6N-Regular.otf}
52 \setmathfont[Scale=MatchLowercase]{xits-math.otf}
53
54 \setLaTeXa{\scshape a}
55 %<*ja>
56 \def\emph#1{\textbf{\textgt{#1}}}
57 \def\headfont{\normalfont\bfseries\gtfamily}\normalsize
58 %</ja>
59 %<*en>
60 \frenchspacing\sloppy
61 \usepackage[margin=25mm,lmargin=30mm,rmargin=30mm,footskip=6mm]{geometry}
62 \usepackage{luatexja-adjust}\ltjdisableadjust
63 \parskip=\smallskipamount
64 \makeatletter
65 \renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}%
66     {3.25ex \@plus1ex \@minus.2ex}%
67     {-1em}%
68     {\normalfont\normalsize\bfseries\raisebox{.2ex}{$\mdlgblksquare\mkern1mu$}}}
69 %</en>
70 %<*ja>
71 \usepackage[textwidth=45\zw, lines=45, footskip=6mm]{geometry}
72 \usepackage{luatexja-adjust}%\ltjdisableadjust
73 \advance\leftmargini-1\zw\advance\leftmarginii-1\zw
74 %</ja>
75
76 %%%%%%%% listings
77
78 %%%%%%%% IVS
79
80 \def\IVS#1{\char\numexpr "E0100+#1\relax}%"
81 \def\IVSA#1#2#3#4#5{%
82   \textcolor{blue}{\raisebox{3.5pt}{\tt%
83     \fboxsep=0.5pt\fbox{\tiny \oalign{0#1#2\crcr#3#4#5\crcr}}}}%
84 }
85 {\catcode`\%=11
86   \gdef\IVSB#1{\expandafter\IVSA\directlua{
87     local cat_str = luatexbase.catcodetables['string']
88     tex.sprint(cat_str, string.format('%X', 0xE00EF+#1))
89 }}}
90
91 \usepackage{listings,showexpl,enumitem}
92 \lstset{
93   basicstyle=\ttfamily\small, pos=r, breaklines=true,
94   numbers=none, rframe={}, basewidth=0.5em, numberstyle=\tiny, numbersep=0.5em,
95   explpreset={numberstyle=\tiny, numbers=left, numbersep=1em, columns=fixed}
96 }
97 % Suppress output from showexpl to stdout.
98 \makeatletter
99 \let\SX@Info\relax
100
101 %%%%%%%% colors
102 %% modified from http://jfly.iam.u-tokyo.ac.jp/colorset/
103 \usepackage{transparent}
104 \definecolor{red}{rgb}{1, 0.16, 0}
105 \definecolor{blue}{rgb}{0, 0.25, 1}
106 \definecolor{gray}{rgb}{.50, .53, .56}
107 \definecolor{green}{rgb}{.21, .63, .42}
108 \definecolor{cyan}{rgb}{0.40, .80, 1}
109 \definecolor{b_gray}{rgb}{0.78, 0.78, 0.80}
110 \definecolor{b_pink}{rgb}{1, 0.82, 0.82}
111 \definecolor{b_green}{rgb}{.53, .91, .69}
112 \definecolor{b_cyan}{rgb}{0.70, .92, 98}
113
114 %%%%%%%% hyperref
115 \usepackage{hyperref,bookmark}
116 %<*en>
117 \title{The \LuaTeX-ja package}
118 \author{The \LuaTeX-ja project team}
119 \date{\LuaTeXjaversion~(\today)}
120 %</en>
121 %<*ja>
122 \title{\LuaTeX-jaパッケージ}
123 \author{\LuaTeX-jaプロジェクトチーム}
124 \date{\LuaTeXjaversion(\today)}
125 %</ja>
126 \hypersetup{%
127         unicode,
128         colorlinks,
129         allbordercolors=1 1 1,
130         allcolors=blue,
131 %<*en>
132         pdfauthor={The LuaTeX-ja project team},
133         pdftitle={The LuaTeX-ja package}
134 %</en>
135 %<*ja>
136         pdfauthor={LuaTeX-jaプロジェクトチーム},
137         pdftitle={LuaTeX-jaパッケージ}
138 %</ja>
139 }
140 %<*ja>
141 \def\HyRef@autoref#1#2{%
142   \begingroup
143     \Hy@safe@activestrue
144     \expandafter\HyRef@autosetref\csname r@#2\endcsname{#2}{#1}%
145   \endgroup\ltjalchar"200C %" 欧文ゴースト
146 }
147 \def\figureautorefname{図}
148 \def\tableautorefname{表}
149 %</ja>
150
151 %%%%%%%% definition env.
152 \usepackage{amsthm}
153 \theoremstyle{definition}
154 %<en>\newtheorem{defn}{Definition}
155 %<ja>\newtheorem{defn}{定義}
156
157 %%%%%%%% logo
158 \usepackage{metalogo}
159 \DeclareRobustCommand\eTeX{\ensuremath{\varepsilon}-\kern-.125em\TeX}
160 \DeclareRobustCommand\LuaTeX{Lua\TeX}
161 \DeclareRobustCommand\pdfTeX{pdf\TeX}
162 \DeclareRobustCommand\pTeX{p\kern-.15em\TeX}
163 \DeclareRobustCommand\upTeX{up\kern-.15em\TeX}
164 \DeclareRobustCommand\pLaTeX{p\kern-.05em\LaTeX}
165 \DeclareRobustCommand\pLaTeXe{p\kern-.05em\LaTeXe}
166 \DeclareRobustCommand\epTeX{\ensuremath{\varepsilon}-\pTeX}
167
168 %%%%%%%% other macros
169 \newlist{cslist}{description}{2}
170 \setlist[cslist]{%
171     style=nextline,font=\mdseries\ttfamily,
172     before*=\def\<{\char`\<}\def\>{\char`\>}\def\{{\char`\{}\def\}{\char`\}},
173     topsep=\medskipamount,
174 %<ja> leftmargin=2\zw,
175 %<en> leftmargin=2em,
176 }
177
178 \def\labelenumii{(\arabic{enumii})}
179 \long\def\@makecaption#1#2{%
180   \vskip\abovecaptionskip
181   \sbox\@tempboxa{{\small #1. #2}}%
182   \ifdim \wd\@tempboxa >\hsize
183     {\small #1. #2}\par
184   \else
185     \global \@minipagefalse
186     \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
187   \fi
188   \vskip\belowcaptionskip}
189
190 \def\_{\leavevmode \kern .06em\vbox {\hrule \@width .333em}}
191 \def\cs#1{\texttt{\upshape
192   \texorpdfstring{\textbackslash\hbox{\ltjsetparameter{autoxspacing=false}#1}}{\textbackslash#1}}}
193 \ltjsetparameter{alxspmode={`\\,allow}}
194 %%%%%%%%
195 \makeatother
196 %%%%%%%%
197
198 \def\Node#1#2{\,\vcenter{\hbox{\fboxsep=1pt\fbox{\vbox{\small\halign{\hfil##\hfil\cr
199   #1\mathstrut\cr\noalign{\vskip1pt\hrule height.4pt\vskip1pt}\strut#2\cr}}}}}\,}
200 \def\HNode#1#2#3#4{\,\vcenter{\hbox{\fboxsep=1pt\fbox{\vbox{\small\halign{\hfil##\hfil\cr
201   #1\mathstrut\cr\noalign{\vskip1pt\hrule height.4pt\vskip1pt}%
202   width:\hfill\ #2\cr height:\hfill\ #3\cr depth:\hfill\ #4\cr
203   }}}}}\,}
204
205 \makeatletter
206 \def\myghost{\ifmmode\else\ltjalchar"200C \fi}
207 \def\Param#1{\texorpdfstring{\@Param{#1}}{#1}} % parameter name
208 \protected\def\@Param#1{\myghost\hyperlink{fld:#1}{\underline{\smash{\textsf{#1}}}}\myghost}
209 \protected\def\DParam#1{\myghost\hypertarget{fld:#1}{\underline{\smash{\textsf{#1}}}}\myghost} % parameter name (definition)
210 \def\Pkg#1{\texorpdfstring{\textsf{#1}}{#1}} % packages/classes
211 \ltjsetparameter{alxspmode={"200C,allow}}
212
213 \begin{document}
214 \lstset{
215   vscmd=\IVSB
216 }
217
218 \catcode`\<=13
219 \def<#1>{{\normalfont\rm\itshape$\langle$#1\/$\rangle$}}
220 \let\LARG=<
221 \maketitle
222
223 \tableofcontents
224 \bigskip
225
226 %<*en>
227 \textbf{This documentation is far from complete. It may have many
228 grammatical (and contextual) errors.} Also, several parts
229 are written in Japanese only.
230 %</en>
231 %<*ja>
232 \emph{\large 本ドキュメントはまだまだ未完成です.}
233 %</ja>
234
235 \clearpage
236 %<en>\part{User's manual}
237 %<ja>\part{ユーザーズマニュアル}
238
239 %<en>\section{Introduction}
240 %<ja>\section{はじめに}
241
242
243 %<*en>
244 The \LuaTeX-ja package is a macro package for typesetting high-quality
245 Japanese documents when using \LuaTeX.
246 %</en>
247 %<*ja>
248 \LuaTeX-jaパッケージは,次世代標準\TeX である\LuaTeX の上で,\pTeX と同等
249 /それ以上の品質の日本語組版を実現させようとするマクロパッケージである.
250 %</ja>
251 %<en>\subsection{Backgrounds}
252 %<ja>\subsection{背景}
253
254 %<*en>
255 Traditionally, ASCII \pTeX, an extension of \TeX, and its derivatives
256 are used to typeset Japanese documents in \TeX. \pTeX\ is an engine
257 extension of \TeX: so it can produce high-quality Japanese documents
258 without using very complicated macros. But this point is a mixed
259 blessing: \pTeX\ is left behind from other extensions of \TeX,
260 especially \eTeX\ and \pdfTeX, and from changes about
261 Japanese processing in computers (\textit{e.g.}, the UTF-8 encoding).
262 %</en>
263 %<*ja>
264 従来,「\TeX を用いて日本語組版を行う」といったとき,エンジンとしては
265 ASCII \pTeX やそれの拡張物が用いられることが一般的であった.\pTeX は\TeX
266 のエンジン拡張であり,(少々仕様上不便な点はあるものの)商業印刷の分野に
267 も用いられるほどの高品質な日本語組版を可能としている.だが,それは弱点に
268 もなってしまった.\pTeX という(組版的に)満足なものがあったため,海外で
269 行われている数々の\TeX の拡張――例えば\eTeX や\pdfTeX ――や,TrueType,
270 OpenType, Unicodeといった計算機で日本語を扱う際の状況の変化に追従すること
271 を怠ってしまったのだ.
272 %</ja>
273
274 %<*en>
275 Recently extensions of \pTeX, namely \upTeX\ (Unicode-implementation
276 of \pTeX) and \epTeX\ (merging of \pTeX\ and
277 \eTeX\ extension), have developed to fill those gaps to some
278 extent, but gaps still exist.
279 %</en>
280 %<*ja>
281 ここ数年,若干状況は改善されてきた.現在手に入る大半の\pTeX バイナリでは
282 外部UTF-8入力が利用可能となり,さらにUnicode化を推進し,\pTeX の内部処理
283 までUnicode化した\upTeX も開発されている.また,\pTeX に\eTeX 拡張をマー
284 ジした\epTeX も登場し,\TeX\ Live\ 2011では\pLaTeX が\epTeX の上で動作す
285 るようになった.だが,\pdfTeX 拡張(PDF直接出力やmicro-typesetting)を
286 \pTeX に対応させようという動きはなく,海外とのgapは未だにあるのが現状であ
287 る.
288 %</ja>
289
290 %<*en>
291 However, the appearance of \LuaTeX\ changed the whole situation. With
292 using Lua ``callbacks'', users can customize the internal processing of
293 \LuaTeX. So there is no need to modify sources of engines to
294 support Japanese typesetting: to do this, we only have to write Lua
295 scripts for appropriate callbacks.
296 %</en>
297 %<*ja>
298 しかし,\LuaTeX の登場で,状況は大きく変わることになった.Luaコードで
299 ``callback''を書くことにより,\LuaTeX の内部処理に割り込みをかけることが可
300 能となった.これは,エンジン拡張という真似をしなくても,Luaコードとそれに
301 関する\TeX マクロを書けば,エンジン拡張とほぼ同程度のことができるようになっ
302 たということを意味する.\LuaTeX-jaは,このアプローチによってLuaコード・
303 \TeX マクロによって日本語組版を\LuaTeX の上で実現させようという目的で開発
304 が始まったパッケージである.
305 %</ja>
306
307 %<en>\subsection{Major changes from \pTeX}
308 %<ja>\subsection{\pTeX からの主な変更点}
309 \label{ssec:chgptex}
310
311 %<*en>
312 The \LuaTeX-ja package is under much influence of \pTeX\ engine. The initial
313 target of development was to implement features of \pTeX. However,
314 implementing all feature of \pTeX\ is impossible,
315 since all process of \LuaTeX-ja must be implemented only by Lua and \TeX\ macros.
316 Hence \emph{\LuaTeX-ja is not a just porting of \pTeX; unnatural
317 specifications/behaviors of \pTeX\ were not adopted}.
318 %</en>
319 %<*ja>
320 \LuaTeX-jaは,\pTeX に多大な影響を受けている.初期の開発目標は,\pTeX の機
321 能をLuaコードにより実装することであった.しかし,(\pTeX はエンジン拡張であったのに対し)
322 \LuaTeX-jaはLuaコードと\TeX マクロを用いて全てを実装していなければならないため,\pTeX
323 の完全な移植は不可能であり,また\pTeX における実装がいささか不可解になっ
324 ているような状況も発見された.そのため,\emph{\LuaTeX-jaは,もはや
325 \pTeX の完全な移植は目標とはしない.\pTeX における不自然な仕様・挙動があ
326 れば,そこは積極的に改める.}
327 %</ja>
328
329 %<*en>
330 The followings are major changes from \pTeX.
331 For more detailed information, see Part~\ref{part-imp} or other sections of this manual.
332 %</en>
333 %<*ja>
334 以下は \pTeX からの主な変更点である.
335 より詳細については第\ref{part-imp}部など本文書の残りを参照.
336 %</ja>
337
338 %<*en>
339 \paragraph{Command names} \pTeX\ addes several primitives, such as \cs{kanjiskip},
340 \cs{prebreakpenalty},~and \cs{ifydir}. They can be used as follows:
341 %</en>
342 %<*ja>
343 \paragraph{命令の名称} 例えば\pTeX で追加された次のようなプリミティブ
344 %</ja>
345 \begin{verbatim}
346 \kanjiskip=10pt  \dimen0=kanjiskip
347 \tbaselineshift=0.1zw
348 \dimen0=\tbaselineshift
349 \prebreakpenalty`ぁ=100
350 \ifydir ... \fi
351 \end{verbatim}
352 %<en> However, we cannot use them under \LuaTeX-ja.
353 %<en> Instead of them, we have to write as the following.
354 %<ja> は\LuaTeX-jaには存在しない.\LuaTeX-jaでは以下のように記述することになる.
355 \begin{verbatim}
356 \ltjsetparameter{kanjiskip=10pt}  \dimen0=\ltjgetparameter{kanjiskip}
357 \ltjsetparameter{talbaselineshift=0.1\zw}
358 \dimen0=\ltjgetparameter{talbaselineshift}
359 \ltjsetparameter{prebreakpenalty={`ぁ,100}}
360 \ifnum\ltjgetparemeter{direction}=4 ... \fi
361 \end{verbatim}
362 %<*en>
363 Note that \pTeX\ adds new two useful units, namely \texttt{zw}~and~\texttt{zh}.
364 As shown above, they are changed by \cs{zw}~and~\cs{zh} respectively, in \LuaTeX-ja.
365 %</en>
366 %<*ja>
367 特に注意してほしいのは,\pTeX で追加された \texttt{zw} と \texttt{zh} という単位は
368 \LuaTeX-ja では使用できず,\cs{zw}, \cs{zh} と制御綴の形にしないといけないという点である.
369 %</ja>
370
371 %<*en>
372 \paragraph{Linebreak after a Japanese character}
373 In \pTeX, a line break after Japanese character is ignored (and
374       doesn't yield a space), since line breaks (in source files) are
375       permitted almost everywhere in Japanese texts. However, \LuaTeX-ja
376       doesn't have this feature completely, because of a specification
377       of \LuaTeX. For the detail, see Section~\ref{sec-lbreak}.
378 %</en>
379 %<*ja>
380 \paragraph{和文文字直後の改行}
381 日本語の文書中では改行はほとんどどこでも許されるので,\pTeX では和文文字
382       直後の改行は無視される(スペースが入らない)ようになっていた.しかし,
383       \LuaTeX-ja では \LuaTeX の仕様のためにこの機能は完全には実装されていない.
384       詳しくは\ref{sec-lbreak}章を参照.
385 %</ja>
386
387 %<*en>
388 \paragraph{Spaces related to Japanese characters}
389 The insertion process of glues/kerns between two Japanese
390       characters and between a Japanese character and other characters
391       (we refer glues/kerns of both kinds as \textbf{JAglue}) is rewritten from
392       scratch.
393 %</en>
394 %<*ja>
395 \paragraph{和文関連の空白}
396 2つの和文文字の間や,和文文字と欧文文字の間に入るグルー/カーン
397       (両者をあわせて\textbf{JAglue}と呼ぶ)の挿入処理が0から書き直されている.
398 %</ja>
399
400 \begin{itemize}
401 %<*en>
402 \item As \LuaTeX's internal ligature handling is \emph{node-based}
403       (\textit{e.g.}, \verb+of{}fice+ doesn't prevent ligatures), the
404       insertion process of \textbf{JAglue} is now \emph{node-based}.
405 %</en>
406 %<*ja>
407 \item \LuaTeX の内部での合字の扱いは「ノード」を単位として行われるようになっている(例えば,
408       \verb+of{}fice+ で合字は抑制されない).それに合わせ,\textbf{JAglue}の挿入処理も
409       ノード単位で実行される.
410 %</ja>
411
412 %<*en>
413 \item Furthermore, nodes between two characters which have no effects in
414       line break (\textit{e.g.}, \cs{special} node) and kerns from
415       italic correction are ignored in the insertion process.
416 %</en>
417 %<*ja>
418 \item さらに,2つの文字の間にある行末では効果を持たないノード(例えば \cs{special} ノード)や,
419   イタリック補正に伴い挿入されるカーンは挿入処理中では無視される.
420 %</ja>
421
422 %<*en>
423 \item \emph{Caution: due to above two points, many methods which did for the
424       dividing the process of the insertion of \textbf{JAglue} in \pTeX\ are not
425       effective anymore.} In concrete terms, the following two methods are not effective anymore:
426 %</en>
427 %<*ja>
428 \item \emph{注意:上の2つの変更により,従来\textbf{JAglue}の挿入処理を分断するのに
429       使われていたいくつかの方法は用いることができない.具体的には,次の方法はもはや無効である:}
430 %</ja>
431 \begin{lstlisting}
432 ちょ{}っと    ちょ\/っと
433 \end{lstlisting}
434 %<*en>
435       If you want to do so, please put an empty horizontal box (hbox) between it instead:
436 %</en>
437 %<*ja>
438       もし同じことをやりたければ,空の水平ボックス(hbox)を間に挟めばよい:
439 %</ja>
440 \begin{lstlisting}
441 ちょ\hbox{}っと
442 \end{lstlisting}
443
444 %<*en>
445 \item In the process, two Japanese fonts which only differ in their ``real''
446       fonts are identified.
447 %</en>
448 %<*ja>
449 \item 処理中では,2つの和文フォントは,実フォントが異なるだけの場合には同一視
450       される.
451 %</ja>
452 \end{itemize}
453
454 %<*en>
455 \paragraph{Directions}
456 From version~20150420.0, \LuaTeX-ja supports vertical writing.
457 We implement this feature by using callbacks of \LuaTeX; so it must \emph{not} be confused
458 with $\Omega$-style direction support of \LuaTeX\ itself.
459 Due to implementation, the dimension returned by \cs{wd},~\cs{ht}, or~\cs{dp} depends
460 on the content of the register \emph{only}. This is major difference with \pTeX.
461 %</en>
462 %<*ja>
463 \paragraph{組方向}
464 バージョン20150420.0からは,不安定ながらも\LuaTeX-ja における縦組みをサポートしている.
465 なお,\LuaTeX 本体も$\Omega$流の組方向をサポートしているが,それとは全くの別物であること
466 に注意してほしい.
467 特に,異なった組方向のボックスを扱う場合には
468 \cs{wd}, \cs{ht}, \cs{dp}等の仕様が\pTeX と異なるので注意.詳細は第\ref{sec-direction}章を参照.
469 %</ja>
470
471 %<*en>
472 \paragraph{\cs{discretionary}}
473 Japanese characters in discretionary break (\cs{discretionary}) is not supported.
474 %</en>
475 %<*ja>
476 \paragraph{\cs{discretionary}}
477  \cs{discretionary} 内に直接和文文字を記述することは,\pTeX においても想定されていなかった
478  感があるが.\LuaTeX-jaにおいても想定していない.和文文字をどう
479       しても使いたい場合は \cs{hbox} で括ること.
480 %</ja>
481
482 %<*en>
483 \paragraph{Greek and Cyrillic letters, and ISO~8859-1 symbols}
484 By default, \LuaTeX-ja uses Japanese fonts to typeset Greek and Cyrillic letters,
485       To change this behavior,
486       put \verb!\ltjsetparameter{jacharrange={-2,-3}}! in the preamble.
487       For the detailed description, see Subsection~\ref{ssec:setrange}.
488
489 From version~20150906.0, characters which belongs both ISO~8859-1 and JIS~X~0208,
490 such as \P~and~\S, are now typeset in alphabetic fonts.
491 If you are using \LaTeXe\ prior to 2017/01/01, these characters are not typeset correctly
492 without the \cs{fontspec} (and~\Pkg{luatexja-fontspec}) package.
493 %</en>
494 %<*ja>
495 \paragraph{ギリシャ文字・キリル文字とISO~8859-1の記号}
496 標準では,\LuaTeX-jaはギリシャ文字やキリル文字を和文フォントを使っ
497       て組む.ギリシャ語などを本格的に組むなどこの状況が望ましくない場合,
498       プリアンブルに
499 \begin{lstlisting}
500  \ltjsetparameter{jacharrange={-2,-3}}
501 \end{lstlisting}
502       を入れると
503       上記種類の文字は欧文フォントを用いて組まれるようになる.
504       詳しい説明は\ref{ssec:setrange}節を参照してほしい.
505
506 また,\P,~\S といったISO~8859-1の上位領域とJIS~X~0208の共通部分の文字は
507       バージョン20150906.0から標準で欧文扱いとなった.\LaTeXe\ 2017/01/01以降では
508 標準でTUエンコーディングのLatin Modernフォントが使われるので,
509 特に何もせずソース中にそのまま記述してもこれらの文字が出力される
510 \footnote{\LaTeXe\ 2017/01/01より前では,ソース中に直接記述しても
511   \Pkg{fontspec}パッケージ(および\Pkg{luatexja-fontspec}パッケージ)非読み込みの状態では出力されない.}.
512 和文扱いで出力するには \verb+\ltjjachar`§+ のように \cs{ltjjachar} 命令
513 を使えばよい.
514 %</ja>
515
516 %<en>\subsection{Notations}
517 %<ja>\subsection{用語と記法}
518
519 %<*en>
520 In this document, the following terms and notations are used:
521 %</en>
522 %<*ja>
523 本ドキュメントでは,以下の用語と記法を用いる:
524 %</ja>
525 \begin{itemize}
526 %<*en>
527 \item Characters are classified into following two types.
528       Note that the classification can be customized by a user
529       (see Subsection~\ref{ssec:setrange}).
530 %</en>
531 %<*ja>
532 \item 文字は次の2種類に分けられる.この類別は固定されているものではなく,ユーザが後から変更可能である
533       (\ref{ssec:setrange}節を参照).
534 %</ja>
535 \begin{itemize}
536 %<*en>
537 \item \textbf{JAchar}: standing for characters which is used in Japanese typesetting,
538       such as Hiragana,~Katakana, Kanji, and~other Japanese punctuation marks.
539 %</en>
540 %<*ja>
541 \item \textbf{JAchar}: ひらがな,カタカナ,漢字,和文用の約物といった
542       日本語組版に使われる文字のことを指す.
543 %</ja>
544
545 %<en>\item \textbf{ALchar}: standing for all other characters like latin alphabets.
546 %<ja>\item \textbf{ALchar}: ラテンアルファベットを始めとする,その他全ての文字を指す.
547 \end{itemize}
548
549 %<*en>
550 We say \emph{alphabetic fonts} for fonts used in \textbf{ALchar},
551 and \emph{Japanese fonts} for fonts used in \textbf{JAchar}.
552 %</en>
553 %<*ja>
554 そして,\textbf{ALchar}の出力に用いられるフォントを\emph{欧文フォント}と呼び,
555 \textbf{JAchar}の出力に用いられるフォントを\emph{和文フォント}と呼ぶ.
556 %</ja>
557 %<*en>
558 \item A word in a sans-serif font with underline (like \Param{prebreakpenalty})
559       means an internal parameter for Japanese typesetting, and it
560       is used as a key in \cs{ltjsetparameter} command.
561 %</en>
562 %<*ja>
563 \item 下線つきローマン体で書かれた語(例:\Param{prebreakpenalty})は日本語組版用の
564       パラメータを表し,これらは \cs{ltjsetparameter} 命令のキーとして
565       用いられる.
566 %</ja>
567 %<*en>
568 \item A word in a sens-serif font without underline (like \Pkg{fontspec})
569       means a package or a class of \LaTeX.
570 %</en>
571 %<*ja>
572 \item 下線なしサンセリフ体の語(例:\Pkg{fontspec})は\LaTeX の
573       パッケージやクラスを表す.
574 %</ja>
575 %<*en>
576 \item In this document, natural numbers start from~zero.
577   $\omega$ denotes the set of all natural numbers which can be used in \TeX.
578 %</en>
579 %<*ja>
580 \item 本ドキュメントでは,自然数は0から始まる.(\TeX で扱える)自然数全体の集合は$\omega$と表記する.
581 %</ja>
582 \end{itemize}
583
584 %<en>\subsection{About the project}
585 %<ja>\subsection{プロジェクトについて}
586
587 %<en>\paragraph{Project Wiki} Project Wiki is under construction.
588 %<ja>\paragraph{プロジェクトWiki} プロジェクトWikiは構築中である.
589 %<*en>
590 \begin{itemize}
591 \item \url{https://osdn.jp/projects/luatex-ja/wiki/FrontPage%28en%29} (English)
592 \item \url{https://osdn.jp/projects/luatex-ja/wiki/FrontPage} (Japanese)
593 \item \url{https://osdn.jp/projects/luatex-ja/wiki/FrontPage%28zh%29} (Chinese)
594 \end{itemize}
595 %</en>
596 %<*ja>
597 \begin{itemize}
598 \item \url{https://osdn.jp/projects/luatex-ja/wiki/FrontPage}(日本語)
599 \item \url{https://osdn.jp/projects/luatex-ja/wiki/FrontPage%28en%29}(英語)
600 \item \url{https://osdn.jp/projects/luatex-ja/wiki/FrontPage%28zh%29}(中国語)
601 \end{itemize}
602 %</ja>
603
604 %<en>This project is hosted by OSDN.
605 %<ja>本プロジェクトはOSDNのサービスを用いて運営されている.
606
607 %<en>\paragraph{Members}\
608 %<ja>\paragraph{開発メンバー}\
609
610 %<*en>
611 \begin{multienumerate}
612 \def\labelenumi{$\bullet$}
613 \mitemxxx{Hironori KITAGAWA}{Kazuki MAEDA}{Takayuki YATO}
614 \mitemxxx{Yusuke KUROKI}{Noriyuki ABE}{Munehiro YAMAMOTO}
615 \mitemxxx{Tomoaki HONDA}{Shuzaburo SAITO}{MA Qiyuan}
616 \end{multienumerate}
617 %</en>
618 %<*ja>
619 \begin{multienumerate}
620 \def\labelenumi{$\bullet$}
621 \mitemxxx{北川 弘典}{前田 一貴}{八登 崇之}
622 \mitemxxx{黒木 裕介}{阿部 紀行}{山本 宗宏}
623 \mitemxxx{本田 知亮}{齋藤 修三郎}{馬 起園}
624 \end{multienumerate}
625 %</ja>
626
627 % \paragraph{Acknowledgments} -- 挿入するならここ
628
629 \clearpage
630 %<en>\section{Getting Started}
631 %<ja>\section{使い方}
632 %<en>\subsection{Installation}
633 %<ja>\subsection{インストール}
634
635 %<en>The following packages are needed for the \LuaTeX-ja\ package.
636 %<ja>\LuaTeX-jaパッケージの動作には次のパッケージ類が必要である.
637 \begin{itemize}
638 \item \LuaTeX\ 1.0.0 (or later)
639 \item \Pkg{luaotfload} v2.6 (or later)
640 \item \Pkg{adobemapping} (Adobe cmap and pdfmapping files)
641 \item \Pkg{etoolbox}, \Pkg{everysel} (if you want to use \LuaTeX-ja with \LaTeXe)
642 \item \Pkg{ltxcmds}, \Pkg{pdftexcmds}, \Pkg{filehook}, \Pkg{atbegshi}
643 \item \Pkg{fontspec} v2.4 (or later)
644 %<en>\item \emph{IPAex fonts} (\url{http://ipafont.ipa.go.jp/})
645 %<ja>\item \emph{IPAexフォント(\url{http://ipafont.ipa.go.jp/})}
646 \end{itemize}
647 %<en>In summary, \LuaTeX-ja version 2018****.0 (or~later) no longer supports \TeX~Live~2016.
648 %<*ja>
649 要約すると,バージョン2018****.0以降の\LuaTeX-jaは\TeX~Live~2016以前では動作しない\footnote{%
650   もっとも,自分で\LuaTeX のバイナリをSubversionリポジトリからビルドしていれば話は別である.
651 }.
652 %</ja>
653
654 %<*en>
655 Now \LuaTeX-ja is available from
656 CTAN (in the \texttt{macros/luatex/generic/luatexja} directory), and
657 the following distributions:
658   \begin{itemize}
659   \item MiK\TeX\ (in \texttt{luatexja.tar.lzma}); see the next subsection
660   \item \TeX\ Live (in \texttt{texmf-dist/tex/luatex/luatexja})
661   \item W32\TeX\ (in \texttt{luatexja.tar.xz})
662   \end{itemize}
663 IPAex fonts are also available in these distributions.
664 %</en>
665 %<*ja>
666 現在,\LuaTeX-jaはCTAN (\texttt{macros/luatex/generic/luatexja})に収録されている他,
667 以下のディストリビューションにも収録されている:
668   \begin{itemize}
669   \item MiK\TeX\ (\texttt{luatexja.tar.lzma})
670   \item \TeX\ Live (\texttt{texmf-dist/tex/luatex/luatexja})
671   \item W32\TeX\ (\texttt{luatexja.tar.xz})
672   \end{itemize}
673 これらのディストリビューションはIPAexフォントも収録している.
674 W32\TeX においてはIPAexフォントは \texttt{luatexja.tar.xz} 内にある.
675 %</ja>
676
677 %<en>\paragraph{Manual installation}
678 %<ja>\paragraph{手動インストール方法}
679
680 \begin{enumerate}
681 %<*en>
682 \item Download the source, by one of the following method.
683       At the present, \LuaTeX-ja has no \emph{stable} release.
684
685 \begin{itemize}
686 \item Clone the Git repository:
687 \begin{lstlisting}
688 $ git clone git://git.osdn.jp/gitroot/luatex-ja/luatexja.git
689 \end{lstlisting}
690 \item Download the \texttt{tar.gz} archive of HEAD in the \texttt{master} branch from
691 \begin{flushleft}
692 \url{http://git.osdn.jp/view?p=luatex-ja/luatexja.git;a=snapshot;h=HEAD;sf=tgz}.
693 \end{flushleft}
694 \end{itemize}
695
696 Note that the \texttt{master} branch, and hence the archive in CTAN, are not updated frequently;
697 the forefront of development is not the \texttt{master} branch.
698 %</en>
699 %<*ja>
700 \item ソースを以下のいずれかの方法で取得する.現在公開されているのはあくまでも
701       開発版であって,安定版でないことに注意.
702
703 \begin{itemize}
704 \item Gitリポジトリをクローンする:
705 \begin{lstlisting}
706 $ git clone git://git.osdn.jp/gitroot/luatex-ja/luatexja.git
707 \end{lstlisting}
708 \item \texttt{master} ブランチのスナップショット(\texttt{tar.gz} 形式)をダウンロードする.
709 \begin{flushleft}
710 \url{http://git.osdn.jp/view?p=luatex-ja/luatexja.git;a=snapshot;h=HEAD;sf=tgz}.
711 \end{flushleft}
712 \end{itemize}
713 \texttt{master} ブランチ(従って,CTAN内のアーカイブも)はたまにしか更新されないことに注意.
714 主な開発は\texttt{master}の外で行われ,比較的まとまってきたらそれを \texttt{master} に
715 反映させることにしている.
716 %</ja>
717
718 %<*en>
719 \item Extract the archive. You will see \texttt{src/} and several other sub-directories.
720 But only the contents in \texttt{src/} are needed to work \LuaTeX-ja.
721 %</en>
722 %<*ja>
723 \item 「Gitリポジトリをクローン」以外の方法でアーカイブを取得したならば,それを展開する.
724       \texttt{src/} をはじめとしたいくつかのディレクトリができるが,
725       動作には \texttt{src/} 以下の内容だけで十分.
726 %</ja>
727
728 %<*en>
729 \item If you downloaded this package from CTAN, you have to run following commands
730     to generate classes
731     and \texttt{ltj-kinsoku.lua} (the file which stores default ``\textit{kinsoku}'' parameters):
732 %</en>
733 %<*ja>
734 \item もしCTANから本パッケージを取得したのであれば,日本語用クラスファイルや
735 標準の禁則処理用パラメータを
736 格納した \texttt{ltj-kinsoku.lua} を生成するために,
737 以下を実行する必要がある:
738 %</ja>
739 \begin{lstlisting}
740 $ cd src
741 $ lualatex ltjclasses.ins
742 $ lualatex ltjsclasses.ins
743 $ lualatex ltjltxdoc.ins
744 $ luatex   ltj-kinsoku_make.tex
745 \end{lstlisting}
746 %<*en>
747 \emph{Do not forget The last line (processing \texttt{ltj-kinsoku\_make.tex})}.
748 \texttt{*.\{dtx,ins\}} and \texttt{ltj-kinsoku\_make.tex} used here are not needed in regular use.
749 %</en>
750 %<*ja>
751 \emph{最後の \texttt{ltj-kinsoku\_make.tex} の実行を忘れないように注意}.
752 ここで使用した \texttt{*.\{dtx,ins\}} と \texttt{ltj-kinsoku\_make.tex} は
753 通常の使用にあたっては必要ない.
754 %</ja>
755
756
757
758 %<*en>
759 \item Copy all the contents of \texttt{src/} into one of your \texttt{TEXMF} tree.
760       \texttt{TEXMF/tex/luatex/luatexja/} is an example location.
761       If you cloned entire Git repository, making a symbolic link of \texttt{src/}
762       instead copying is also good.
763 %</en>
764 %<*ja>
765 \item \texttt{src} の中身を自分の \texttt{TEXMF} ツリーにコピーする.
766       場所の例としては,例えば
767 \begin{quote}
768  \texttt{TEXMF/tex/luatex/luatexja/}
769 \end{quote}
770       がある.
771       シンボリックリンクが利用できる環境で,かつリポジトリを直接取得したのであれば,
772       (更新を容易にするために)コピーではなくリンクを貼ることを勧める.
773 %</ja>
774 %<*en>
775 \item If \texttt{mktexlsr} is needed to update the file name database, make it so.
776 %</en>
777 %<*ja>
778 \item 必要があれば,\texttt{mktexlsr} を実行する.
779 %</ja>
780 \end{enumerate}
781
782 %<*en>
783 \subsection{Cautions}
784 For changes from \pTeX, see Subsection~\ref{ssec:chgptex}.
785 %</en>
786 %<*ja>
787 \subsection{注意点}
788 \pTeX からの変更点として,\ref{ssec:chgptex}節も熟読するのが望ましい.
789 ここでは一般的な注意点を述べる.
790 %</ja>
791 \begin{itemize}
792 %<*en>
793 \item The encoding of your source file must be UTF-8. Other
794       encodings, such as EUC-JP or Shift-JIS, are not supported.
795 %</en>
796 %<*ja>
797 \item 原稿のソースファイルの文字コードはUTF-8固定である.
798       従来日本語の文字コードとして用いられてきたEUC-JPやShift-JISは使用できない.
799 %</ja>
800 %<*en>
801 \item \LuaTeX-ja is very slower than \pTeX.
802   Generally speaking, LuaJIT\TeX\ processes \LuaTeX-ja
803   about 30\% faster than \LuaTeX, but not always%
804   \footnote{%
805     LuaJIT has several limitations such as 1\,GB~(or~2\,GB) memory limitation.
806         So typesetting a large source by LuaJIT\TeX may cause an ``out of memory'' error,
807         or failure of loading/saving font cache of \Pkg{luaotfload}.
808   }.
809 %</en>
810 %<*ja>
811 \item \LuaTeX-jaは動作が\pTeX に比べて非常に遅い.
812 コードを調整して徐々に速くしているが,まだ満足できる速度ではない.
813 LuaJIT\TeX を用いると\LuaTeX のだいたい1.3倍の速度で動くようであるが,
814 IPA mj明朝などの大きいフォントを用いた場合には\LuaTeX よりも遅くなることもある
815   \footnote{%
816     LuaJITは1\,GB(あるいは2\,GB)のメモリ制限など,いくつかの制限事項があることが知られている.そのため,
817     大きいソースファイルをLuaJIT\TeX でタイプセットするとLuaの側で``out of memory''エラーが発生してしまう.
818     本ドキュメントのように,「各ページごとにLuaで使っているメモリ容量をチェックし,
819     必要なら\texttt{collectgarbage("collect")}でガベージコレクタを実行」すると
820     状況が多少改善されるかもしれない.
821         また,LuaJIT\TeX でIPA mj明朝などの「大きい」フォントを利用した場合はフォントキャッシュの保存に失敗し,
822         毎回フォントを読み込まなければならず結果的に時間がかかることがある.
823   }.
824 %</ja>
825
826 \item%
827 %<*en>
828 \textbf{(Outdated) note for MiK\TeX\ users}\quad
829 \LuaTeX-ja requires that several CMap files%
830 \footnote{\texttt{UniJIS2004-UTF32-\{H,V\}} and \texttt{Adobe-Japan1-UCS2}.}
831 must be found from \LuaTeX.
832 Strictly speaking, those CMaps are needed
833 only in the first run of \LuaTeX-ja after installing or updating.
834 But it seems that MiK\TeX\ does not satisfy this condition,
835 so you will encounter an error like the following:
836 %</en>
837 %<*ja>
838 \LuaTeX-jaが動作するためには,\emph{導入・更新後の初回起動時に}
839 \texttt{UniJIS2004-UTF32-\{H,V\}}, \texttt{Adobe-Japan1-UCS2}という3つのCMapが
840 \LuaTeX によって見つけられることが必要である.
841 しかし古いバージョンのMiK\TeX ではそのようになっていないので,次のエラーが発生するだろう:
842 %</ja>
843 \begin{lstlisting}
844 ! LuaTeX error ...iles (x86)/MiKTeX 2.9/tex/luatex/luatexja/ltj-rmlgbm.lua
845 bad argument #1 to 'open' (string expected, got nil)
846 \end{lstlisting}
847
848 %<*en>
849 If so, please execute a batch file which is written on
850 \href{https://osdn.jp/projects/luatex-ja/wiki/FrontPage%28en%29}{ the Project Wiki (English)}.
851 This batch file creates a temporary directory, copy CMaps in it,
852 run a test file which loads \LuaTeX-ja in this directory,
853 and finally delete the temporary directory.
854 %</en>
855 %<*ja>
856 そのような場合には,
857 \href{https://osdn.jp/projects/luatex-ja/wiki/FrontPage%28en%29}{%
858   プロジェクトWiki英語版トップページ}中に書かれているバッチファイルを
859 実行して欲しい.このバッチファイルは,作業用ディレクトリにCMap達を
860 コピーし,その中で\LuaTeX-jaの初回起動を行い,作業用ディレクトリを消す作業をしている.
861 %</ja>
862
863 \end{itemize}
864
865 %<en>\subsection{Using in plain \TeX}
866 %<ja>\subsection{plain \TeX で使う}
867 \label{ssec:plain}
868
869 %<en>To use \LuaTeX-ja in plain \TeX, simply put the following at the beginning of the document:
870 %<ja>\LuaTeX-jaを plain \TeX で使うためには,単に次の行をソースファイルの冒頭に追加すればよい:
871 \begin{lstlisting}
872 \input luatexja.sty
873 \end{lstlisting}
874 %<en>This does minimal settings (like \texttt{ptex.tex}) for typesetting Japanese documents:
875 %<ja>これで(\texttt{ptex.tex}のように)日本語組版のための最低限の設定がなされる:
876
877 \begin{itemize}
878 %<*en>
879 \item The following 12~Japanese fonts are preloaded:
880 \begin{center}\small
881 \begin{tabular}{cccccc}
882 \toprule
883 \textbf{direction}&
884 \textbf{classification}&\textbf{font name}&\bfseries ``10\,pt''&\bfseries ``7\,pt''&\bfseries ``5\,pt''\\\midrule
885 \smash{\raisebox{-1ex}{\emph{yoko} (horizontal)}}&
886 \emph{mincho}&IPAex Mincho&\cs{tenmin}&\cs{sevenmin}&\cs{fivemin}\\
887 &\emph{gothic}&IPAex Gothic&\cs{tengt} &\cs{sevengt} &\cs{fivegt}\\
888 \midrule
889 \smash{\raisebox{-1ex}{\emph{tate} (vertical)}}&
890 \emph{mincho}&IPAex Mincho&\cs{tentmin}&\cs{seventmin}&\cs{fivetmin}\\
891 &\emph{gothic}&IPAex Gothic&\cs{tentgt} &\cs{seventgt} &\cs{fivetgt}\\
892 \bottomrule
893 \end{tabular}
894 \end{center}
895 %</en>
896 %<*ja>
897 \item 以下の12個の和文フォントが定義される:
898 \begin{center}\small
899 \begin{tabular}{cccccc}
900 \toprule
901 \emph{組方向}&\emph{字体}&\emph{フォント名}&\bfseries``10\,pt''&\bfseries``7\,pt''&\bfseries``5\,pt''\\\midrule
902 \smash{\raisebox{-1ex}{横組}}&
903 明朝体&IPAex明朝&\cs{tenmin}&\cs{sevenmin}&\cs{fivemin}\\
904 &ゴシック体&IPAexゴシック&\cs{tengt} &\cs{sevengt} &\cs{fivegt}\\
905 \midrule
906 \smash{\raisebox{-1ex}{縦組}}&
907 明朝体&IPAex明朝&\cs{tentmin}&\cs{seventmin}&\cs{fivetmin}\\
908 &ゴシック体&IPAexゴシック&\cs{tentgt} &\cs{seventgt} &\cs{fivetgt}\\
909 \bottomrule
910 \end{tabular}
911 \end{center}
912 %</ja>
913 \begin{itemize}
914 %<*en>
915 \item With \texttt{luatexja.cfg}, one can use other fonts
916 as ``default'' Japanese fonts (Subsection~\ref{ssec:cfg}).
917 %</en>
918 %<*ja>
919 \item \texttt{luatexja.cfg} を用いることによって,標準和文フォントを
920 IPAexフォントから別のフォントに置き換えることができる.\ref{ssec:cfg}節を参照.
921 %</ja>
922
923 %<*en>
924 \item A character in an alphabetic font is generally smaller than a
925       Japanese font in the same size. So actual size specification of
926       these Japanese fonts is in fact smaller than that of alphabetic
927       fonts, namely scaled by 0.962216.
928 %</en>
929 %<*ja>
930 \item 欧文フォントの文字は和文フォントの文字よりも,同じ文字サイズでも
931       一般に小さくデザインされている.そこで,標準ではこれらの和文フォントの実際のサイズは指定された値よりも
932       小さくなるように設定されており,具体的には指定の0.962216倍にスケールされる.
933       この0.962216という数値も,\pTeX におけるスケーリングを踏襲した値である.
934 %</ja>
935 \end{itemize}
936
937 %<*en>
938 \item The amount of glue that are inserted between a \textbf{JAchar} and
939       an \textbf{ALchar} (the parameter \Param{xkanjiskip}) is set to
940 %</en>
941 %<*ja>
942 \item \textbf{JAchar}と\textbf{ALchar}の間に入るグルー(\Param{xkanjiskip})の
943       量は次のように設定されている:
944 %</ja>
945 \[
946  (0.25\cdot 0.962216\cdot 10\,\mathrm{pt})^{+1\,\text{pt}}_{-1\,\text{pt}}
947  = 2.40554\,\mathrm{pt}^{+1\,\text{pt}}_{-1\,\text{pt}}.
948 \]
949 \end{itemize}
950
951 %<en>\subsection{Using in \LaTeX}
952 %<ja>\subsection{\LaTeX で使う}
953 \label{ssec:ltx}
954
955 %<*en>
956 Using in \LaTeXe\ is basically same. To set up the minimal environment
957 for Japanese, you only have to load \texttt{luatexja.sty}:
958 %</en>
959 %<*ja>
960 \LaTeXe を用いる場合も基本的には同じである.日本語組版のための最低限の環境を
961 設定するためには,\texttt{luatexja.sty}を読み込むだけでよい:
962 %</ja>
963 \begin{lstlisting}
964 \usepackage{luatexja}
965 \end{lstlisting}
966 %<*en>
967 It also does minimal settings (counterparts in \pLaTeX\ are \texttt{%
968 plfonts.dtx} and \texttt{pldefs.ltx}):
969 %</en>
970 %<*ja>
971 これで\pLaTeX の\texttt{plfonts.dtx}と\texttt{pldefs.ltx}に相当する最低限の設定が
972 なされる:
973 %</ja>
974
975 \begin{itemize}
976 %<*en>
977 \item Font encodings for Japanese fonts are \texttt{JY3}~(for horizontal direction) and
978 \texttt{JT3}~(for vertical direction).
979 %</en>
980 %<*ja>
981 \item 和文フォントのエンコーディングとしては,横組用には \texttt{JY3},縦組用には\
982 \texttt{JT3}が用いられる.
983 %</ja>
984
985 %<*en>
986 \item Traditionally, Japanese documents use only two families: \emph{mincho}~(明朝体) and
987  \emph{gothic}~(\textgt{ゴシック体}). \emph{mincho} is used in the main text, while \emph{gothic}
988       is used in the headings or for emphasis.
989 \begin{center}\small
990 \begin{tabular}{lllc}
991 \toprule
992 \textbf{classification}&&&\textbf{commands}\\\midrule
993 \emph{mincho} (明朝体)&\verb+\textmc{...}+&\verb+{\mcfamily ...}+&\cs{mcdefault}\\
994 \emph{gothic} (\textgt{ゴシック体})&\verb+\textgt{...}+&\verb+{\gtfamily ...}+&\cs{gtdefault}\\
995 \bottomrule
996 \end{tabular}
997 \end{center}
998 \item
999 By default, the following fonts are used for these two families.
1000 \begin{center}\small
1001 \begin{tabular}{ccccc}
1002 \toprule
1003 \textbf{classification}&\textbf{family}&\cs{mdseries}&\cs{bfseries}&\textbf{scale}\\\midrule
1004 \emph{mincho} (明朝体)&\tt mc&IPAex Mincho&IPAex Gothic&0.962216\\
1005 \emph{gothic} (\textgt{ゴシック体})&\tt gt&IPAex Gothic&IPAex Gothic&0.962216\\
1006 \bottomrule
1007 \end{tabular}
1008 \end{center}
1009 Note that the bold series (series \texttt{bx}~or~\texttt{b}) in both family
1010      are same as the medium series of gothic family.
1011      There is no italic nor slanted shape for these \texttt{mc}~and~\texttt{gt}.
1012 %</en>
1013 %<*ja>
1014 \item \pLaTeX と同様に,標準では「明朝体」「ゴシック体」の2種類を用いる:
1015 \begin{center}\small
1016 \begin{tabular}{cllc}
1017 \toprule
1018 \emph{字体}&&&\emph{ファミリ名}\\\midrule
1019 明朝体&\verb+\textmc{...}+&\verb+{\mcfamily ...}+&\cs{mcdefault}\\
1020 \textgt{ゴシック体}&\verb+\textgt{...}+&\verb+{\gtfamily ...}+&\cs{gtdefault}\\
1021 \bottomrule
1022 \end{tabular}
1023 \end{center}
1024 \item 標準では,次のフォントが用いられる:
1025 \begin{center}\small
1026 \begin{tabular}{ccccc}
1027 \toprule
1028 \emph{字体}&\emph{ファミリ}&\cs{mdseries}&\cs{bfseries}&\emph{スケール}\\\midrule
1029 明朝体&\tt mc&IPAex明朝&IPAexゴシック&0.962216\\
1030 ゴシック体&\tt gt&IPAexゴシック&IPAexゴシック&0.962216\\
1031 \bottomrule
1032 \end{tabular}
1033 \end{center}
1034 どちらのファミリにおいても,太字(\cs{bfseries})のフォントは
1035 ゴシック体中字(\cs{gtfamily}\cs{mdseries})で使われるフォントと同じであることに注意.
1036 また,どちらのファミリでもイタリック体・スラント体は定義されない.
1037
1038   和文の太字を表すシリーズ名は,(元々のComputer Modernが
1039   太字に\texttt{bx}を用いていたことから)伝統的に\texttt{bx}~(Bold Extended)が使われてきた.
1040   しかし,太字にシリーズ\texttt{b}を使うフォントも増えてきたため,
1041   バージョン20180616.0以降では和文の太字として\texttt{bx},~\texttt{b}の両方を扱えるようにした.
1042 %</ja>
1043
1044 %<en>\item Japanese characters in math mode are typeset by the font family \texttt{mc}.
1045 %<ja>\item 数式モード中の和文文字は明朝体(\texttt{mc})で出力される.
1046 %<*en>
1047  \item \cs{jttdefault}%
1048   \footnote{%
1049         When \Pkg{ltjsclasses} classes are used, or
1050         \Pkg{luatexja-fontspec} (or \Pkg{luatexja-preset}) is loaded with \texttt{match} option,
1051         \cs{ttfamily} changes the current Japanese font amily to \cs{jttdefault}.
1052         These classes and packages also redefine \cs{jttdefault} to
1053         \cs{gtdefault} (\emph{gothic}~family).
1054   } specifies the Japanese font family in \cs{verb}~or~\texttt{verbatim} environment.
1055   The default value of \cs{jttdefault} is \cs{mcdefault}, so the mincho family is used.
1056 %</en>
1057 %<*ja>
1058  \item \cs{verb} や \texttt{verbatim} 環境中の和文文字に使われる和文フォントファミリは
1059   \ \cs{jttdefault} で指定する%
1060   \footnote{%
1061         \Pkg{ltjsclasses}を使用したり,あるいは \texttt{match} オプションを指定して\Pkg{luatexja-fontspec}%
1062         や\Pkg{luatexja-preset}パッケージを読み込んだときは,単なる \cs{ttfamily} によっても和文フォントが
1063         \ \cs{jttdefault}\ に変更される.また,これらのクラスファイルやパッケージは
1064         \ \cs{jttdefault}\ を \cs{gtdefault}(ゴシック体)に再定義する.
1065   }.標準値は \cs{mcdefault},つまり明朝体として用いるのと
1066   同じフォントファミリである.
1067 %</ja>
1068
1069 %<*en>
1070 \item If you use the \Pkg{beamer} class with the default font theme (which uses sans serif
1071       fonts) and with \LuaTeX-ja, you might want to change default Japanese fonts to
1072       the gothic family. The following line  changes  the default Japanese font family
1073       to it:
1074 %</en>
1075 %<*ja>
1076 \item \Pkg{beamer}クラスを既定のフォント設定で使う場合,既定欧文フォントがサンセリフなの
1077       で,既定和文フォントもゴシック体にしたいと思うかもしれない.その場合はプリアンブルに
1078 次を書けばよい:
1079 %</ja>
1080 \begin{lstlisting}
1081  \renewcommand{\kanjifamilydefault}{\gtdefault}
1082 \end{lstlisting}
1083
1084 %<*ja>
1085 \item \pLaTeX と同様に,\texttt{mc},~\texttt{gt}両ファミリには「従属欧文」書体が定義されている.
1086   これらは\cs{userelfont}を\cs{selectfont}(や,その他の「実際に」
1087   フォントを変更する命令)の前で実行することにより使うことができる.
1088
1089   \pLaTeX では標準の欧文フォントはOT1エンコーディングのComputer Modern Roman (\texttt{cmr})%
1090   であったが,2017年以降の\LuaLaTeX ではTUエンコーディングのlatin Modern Roman (\texttt{lmr})%
1091   に変更されている.そのため,前段落で述べた「従属欧文」も,Latin Modern Romanに設定している.
1092 %</ja>
1093
1094 \end{itemize}
1095
1096 %<*en>
1097 However, above settings are not sufficient for Japanese-based
1098 documents. To typeset Japanese-based documents, you are better to use
1099 class files other than \texttt{article.cls}, \texttt{book.cls}, and so on.  At
1100 the present, we have the counterparts of \Pkg{jclasses} (standard
1101 classes in \pLaTeX) and \Pkg{jsclasses} (classes by Haruhiko
1102 Okumura), namely, \Pkg{ltjclasses}\footnote{%
1103   \texttt{ltjarticle.cls},~\texttt{ltjbook.cls}, \texttt{ltjreport.cls},
1104   \texttt{ltjtarticle.cls}, \texttt{ltjtbook.cls}, \texttt{ltjtreport.cls}.
1105   The latter \texttt{ltjt*.cls} are for vertically written Japanese documents.
1106 } and \Pkg{ltjsclasses}\footnote{%
1107   \texttt{ltjsarticle.cls},~\texttt{ltjsbook.cls}, \texttt{ltjsreport.cls},~\texttt{ltjskiyou.cls}.}.
1108
1109 Original \Pkg{jsclasses} use \cs{mag}~primitive to set the main document font size.
1110 However, \LuaTeX\ beta-0.87.0~or~later does not support \cs{mag} in PDF~output,
1111 so \Pkg{ltjsclasses} uses the \texttt{nomag*} option\footnote{Same effect as 
1112   the \Pkg{BXjscls} classes (by Takayuki Yato) and \Pkg{jsclasses}.
1113   However, these classes uses only \TeX\ code, but \Pkg{ltjsclasses} uses Lua code.}
1114  by default to set the main font size. If this causes some unexpected behavior, specify
1115 \texttt{nomag} option in \cs{documentclass}.
1116 %</en>
1117 %<*ja>
1118 しかしながら,上記の設定は日本語の文書にとって十分とは言えない.
1119 日本語文書を組版するためには,\texttt{article.cls}, \texttt{book.cls}といった
1120 欧文用のクラスファイルではなく,和文用のクラスファイルを用いた方がよい.
1121 現時点では,\Pkg{jclasses}(\pLaTeX の標準クラス)と\Pkg{jsclasses}%
1122 (奥村晴彦氏による「\pLaTeXe 新ドキュメントクラス」)に対応するものとして,
1123 \Pkg{ltjclasses}\footnote{%
1124   横組用は \texttt{ltjarticle.cls},~\texttt{ltjbook.cls}, \texttt{ltjreport.cls} であり,
1125   縦組用は \texttt{ltjtarticle.cls}, \texttt{ltjtbook.cls}, \texttt{ltjtreport.cls} である.
1126 },
1127 \Pkg{ltjsclasses}\footnote{%
1128   \texttt{ltjsarticle.cls},~\texttt{ltjsbook.cls}, \texttt{ltjsreport.cls},~\texttt{ltjskiyou.cls}.}%
1129 がそれぞれ用意されている.
1130
1131 元々の\Pkg{jsclasses}では本文のフォントサイズを設定するのに\cs{mag}プリミティブが使われていたが,
1132 \LuaTeX~beta-0.87.0以降ではPDF出力時の\cs{mag}のサポートが廃止された.
1133 そのため,\Pkg{ltjsclasses}では\texttt{nomag*}オプション
1134 \footnote{\Pkg{jsclasses}や,八登崇之氏による\Pkg{BXjscls}クラスにおける同名のオプションと
1135   同じ.上記クラスは\TeX コードのみで実装しているが,\Pkg{ltjsclasses}ではLuaコードも用いている.}が標準で
1136 有効になっており,これを使って本文フォントサイズの設定を行っている.
1137 しかし,この\texttt{nomag*}オプションでは(20180121.0版より前の版において\Pkg{unicode-math}パッケージ使用時に
1138 起きたように)予想外の意図しない現象に遭遇する危険がある.そのような場合は
1139 \cs{documentclass}において\texttt{nomag}オプションを指定してほしい.
1140 %</ja>
1141
1142 %<*ja>
1143 \paragraph{脚注とボトムフロートの出力順序}
1144 オリジナルの\LaTeX では脚注はボトムフロートの上に出力され,また\cs{raggedbottom}命令でページの高さが不揃いであることを許した場合には
1145 脚注の下端の垂直位置もページに応じて変わるようになっている.
1146 一方,日本語の組版では脚注はボトムフロートの下に来るのが一般的であるので,
1147 \pLaTeX ではそのように変更されており,
1148 さらに\cs{raggedbottom}命令を実行した後でも脚注は常にページの下端に固定されるようになっている.
1149
1150 \LuaTeX-jaでは「欧文クラスの中にちょっとだけ日本語を入れる」という利用も考慮し,
1151 脚注とボトムフロートの順序,及び\cs{raggedbottom}時の脚注の垂直位置は\LaTeX 通りとした.
1152 これらを制御するには以下の手段がある:
1153 \begin{itemize}
1154  \item \pLaTeX のように,脚注をボトムフロートの下に組む場合には
1155   \Pkg{stfloats}パッケージを利用して
1156   \begin{lstlisting}
1157     \usepackage{stfloats}\fnbelowfloat
1158   \end{lstlisting}
1159   とする.この状況から「脚注をボトムフロートの上に組む」という\LaTeX の標準の挙動に戻したければ,
1160   \Pkg{stfloats}パッケージの\cs{fnunderfloat}命令を使用する.
1161   \item \cs{raggedbottom}時の脚注の垂直位置は,\cs{iffnfixbottom}という真偽値で制御する.
1162   \begin{description}
1163     \item[偽(\cs{fnfixbottomfalse})の場合] \LaTeX 標準と同じく,本文と脚注の間の空白は\cs{skip}\cs{footins}のみ.
1164     従って脚注の垂直位置はページにより変動する.
1165     \item[真(\cs{fnfixbottomtrue})の場合] \pLaTeX や\Pkg{footmisc}パッケージを\texttt{bottom}オプションで
1166     読み込んだ場合のように,脚注は常にページの下端に固定される.
1167   \end{description}
1168 \item ただし,\LuaTeX-jaが提供する「互換クラス」(\Pkg{ltjclasses}, \Pkg{ltjsclasses})では,
1169   \pLaTeX と合わせるために以下のようにしている:
1170   \begin{itemize}
1171     \item \cs{fnfixbottomtrue}が自動的に実行される
1172     \item \Pkg{stfloats}パッケージが\LuaTeX から参照できる場所にあった場合は
1173     自動的に読み込み,\cs{fnbelowfloat}を実行する.
1174   \end{itemize}
1175 \end{itemize}
1176 なお,\Pkg{stfloats}パッケージを使う代わりに,
1177 \Pkg{footmisc}パッケージを \texttt{bottom}オプションを指定して読み込む
1178 という「解決法」もある.
1179 %</ja>
1180 %%% ↑は英訳しない
1181
1182 %<*en>
1183 \paragraph{\Pkg{geometry} package and classes for vertical writing}
1184 It is well-known that the \Pkg{geometry} package produces the following error, when classes for
1185 vertical writing is used:
1186 %</en>
1187 %<*ja>
1188 \paragraph{縦組での\Pkg{geometry}パッケージ}
1189 \pLaTeX の縦組用標準クラスファイルでは\Pkg{geometry}パッケージを利用することは出来ず,
1190 %</ja>
1191 \begin{lstlisting}
1192 ! Incompatible direction list can't be unboxed.
1193 \@begindvi ->\unvbox \@begindvibox
1194                                    \global \let \@begindvi \@empty
1195 \end{lstlisting}
1196 %<*en>
1197 Now, \LuaTeX-ja automatically applies the patch \Pkg{lltjp-geometry} to the
1198 \Pkg{geometry} package, when the direction of the document is \emph{tate} (vertical
1199 writing).
1200 This patch \Pkg{lltjp-geometry} also can be used in \pLaTeX; for the detail, please refer
1201 \url{lltjp-geometry.pdf}~(Japanese).
1202 %</en>
1203 %<*ja>
1204 というようなエラーが発生することが知られている.
1205 \LuaTeX-jaでは, \texttt{ltjtarticle.cls} といった縦組クラスの下でも
1206 \Pkg{geometry}パッケージが利用できるようにパッチ\Pkg{lltjp-geometry}パッケージを自動的に当てている.
1207
1208 なお,\Pkg{lltjp-geometry}パッケージは\pTeX 系列でも明示的に読み込むことによって
1209 使用可能である.詳細や注意事項は \url{lltjp-geometry.pdf} を参照のこと.
1210 %</ja>
1211
1212
1213 %<en>\section{Changing Fonts}
1214 %<ja>\section{フォントの変更}
1215
1216 \subsection{plain \TeX~and~\LaTeXe}
1217 \label{ssec:chgfnt}
1218
1219 \paragraph{plain \TeX}
1220 %<*en>
1221 To change Japanese fonts in plain \TeX, you must use the command
1222 \cs{jfont}~and~\cs{tfont}. So please see Subsection~\ref{ssec:jfont}.
1223 %</en>
1224 %<*ja>
1225 plain \TeX で和文フォントを変更するためには,
1226 \pTeX のように \cs{jfont} 命令や \cs{tfont} 命令を直接用いる.
1227 \ref{ssec:jfont}節を参照.
1228 %</ja>
1229
1230 \paragraph{\LaTeXe\ (NFSS2)}
1231 %<*en>
1232 For \LaTeXe, \LuaTeX-ja adopted most of the font selection system of \pLaTeXe\ (in \texttt{plfonts.dtx}).
1233 %</en>
1234 %<*ja>
1235 \LaTeX で用いる際には,\pLaTeXe\ (\texttt{plfonts.dtx})用のフォント選択機構の大部分を流用している.
1236 %</ja>
1237 \begin{itemize}
1238 %<*en>
1239 \item Commands \cs{fontfamily}, \cs{fontseries}, and \cs{fontshape} can be used to change
1240       attributes of Japanese fonts.
1241 %</en>
1242 %<*ja>
1243 \item 和文フォントの属性を変更するには,\cs{fontfamily}, \cs{fontseries}, \cs{fontshape} を使用する.
1244       もちろん,それらを実際に反映させるには手動で \cs{selectfont} を実行する必要がある.
1245 %</ja>
1246
1247 %<*en>
1248 \begin{center}\small
1249 \begin{tabular}{cccccc}
1250 \toprule
1251 &\textbf{encoding}&\textbf{family}&\textbf{series}&\textbf{shape}&\textbf{selection}\\\midrule
1252 alphabetic fonts
1253 &\cs{romanencoding}&\cs{romanfamily}&\cs{romanseries}&\cs{romanshape}
1254 &\cs{useroman}\\
1255 Japanese fonts
1256 &\cs{kanjiencoding}&\cs{kanjifamily}&\cs{kanjiseries}&\cs{kanjishape}
1257 &\cs{usekanji}\\
1258 both&---&--&\cs{fontseries}&\cs{fontshape}&---\\
1259 auto select&\cs{fontencoding}&\cs{fontfamily}&---&---&\cs{usefont}\\
1260 \bottomrule
1261 \end{tabular}
1262 \end{center}
1263 %</en>
1264 %<*ja>
1265 \begin{center}\small
1266 \begin{tabular}{cccccc}
1267 \toprule
1268 &\emph{エンコーディング}&\emph{ファミリ}&\emph{シリーズ}&\emph{シェープ}&\emph{選択}\\\midrule
1269 欧文
1270 &\cs{romanencoding}&\cs{romanfamily}&\cs{romanseries}&\cs{romanshape}
1271 &\cs{useroman}\\
1272 和文
1273 &\cs{kanjiencoding}&\cs{kanjifamily}&\cs{kanjiseries}&\cs{kanjishape}
1274 &\cs{usekanji}\\
1275 両方&---&--&\cs{fontseries}&\cs{fontshape}&---\\
1276 自動選択&\cs{fontencoding}&\cs{fontfamily}&---&---&\cs{usefont}\\
1277 \bottomrule
1278 \end{tabular}
1279 \end{center}
1280 %</ja>
1281
1282 %<*en>
1283       \verb+\fontencoding{+<encoding>\verb+}+ changes the encoding of alphabetic fonts
1284       or Japanese fonts depending on the argument. For example,
1285       \verb+\fontencoding{JY3}+ changes the encoding of Japanese fonts to
1286       \texttt{JY3}, and \verb+\fontencoding{T1}+ changes the encoding of
1287       alphabetic fonts to \texttt{T1}.
1288       \cs{fontfamily} also changes the current Japanese font family,
1289       the current alphabetic font family, \emph{or both}.
1290       For the detail, see Subsection~\ref{ssec:nfsspat}.
1291 %</en>
1292 %<*ja>
1293       ここで,\verb+\fontencoding{+<encoding>\verb+}+ は,引数により和文側か欧文
1294       側かのどちらかのエンコーディングを変更する.例えば,
1295       \verb+\fontencoding{JY3}+ は和文フォントのエンコーディングを
1296       \texttt{JY3}に変更し,\verb+\fontencoding{T1}+ は欧文フォント側を
1297       \texttt{T1}へと変更する.\cs{fontfamily} も引数により和文側,欧文
1298       側,\emph{あるいは両方}のフォントファミリを変更する.詳細は
1299       \ref{ssec:nfsspat}節を参照すること.
1300 %</ja>
1301
1302 %<*en>
1303 \item For defining a Japanese font family, use
1304       \cs{DeclareKanjiFamily} instead of
1305       \cs{DeclareFontFamily}. (In previous version of \LuaTeX-ja,
1306       using \cs{DeclareFontFamily} didn't cause any problem. But this no longer applies
1307       the current version.)
1308 \item Defining a Japanese font shape can be done by usual \cs{DeclareFontShape}:
1309 %</en>
1310 %<*ja>
1311 \item 和文フォントファミリの定義には \cs{DeclareFontFamily} の
1312       代わりに \cs{DeclareKanjiFamily} を用いる.以前の
1313       実装では \cs{DeclareFontFamily} を用いても問題は生じなかったが,現在の実装では
1314       そうはいかない.
1315 \item 和文フォントのシェイプを定義するには,通常の \cs{DeclareFontShape} を使えば良い:
1316 %</ja>
1317 \begin{lstlisting}
1318 \DeclareFontShape{JY3}{mc}{bx}{n}{<-> s*KozMinPr6N-Bold:jfm=ujis;-kern}{}
1319     % Kozuka Mincho Pr6N Bold
1320 \end{lstlisting}
1321 %<*ja>
1322 仮名書体を使う場合など,複数の和文フォントを組み合わせて使いたい場合は
1323 \ref{ssec:altfont}節の \cs{ltjdeclarealtfont} と,その\LaTeX 版の\
1324 \cs{DeclareAlternateKanjiFont}(\ref{ssec:nfsspat}節)を参照せよ.
1325 %</ja>
1326
1327 \end{itemize}
1328
1329 %<*en>
1330 \paragraph{Remark: Japanese characters in math mode}
1331 Since \pTeX\ supports Japanese characters in math mode, there are
1332 sources like the following:
1333 %</en>
1334 %<*ja>
1335 \paragraph{注意:数式モード中の和文文字}
1336 \pTeX では,特に何もしないでも数式中に和文文字を記述することができた.そのため,
1337 以下のようなソースが見られた:
1338 %</ja>
1339
1340 \begin{LTXexample}
1341 $f_{高温}$~($f_{\text{high temperature}}$).
1342 \[ y=(x-1)^2+2\quad よって\quad y>0 \]
1343 $5\in 素:=\{\,p\in\mathbb N:\text{$p$ is a prime}\,\}$.
1344 \end{LTXexample}
1345 %<*en>
1346 We (the project members of \LuaTeX-ja) think that using
1347 Japanese characters in math mode are allowed if and only if these are used as identifiers.
1348 In this point of view,
1349 %</en>
1350 %<*ja>
1351 \LuaTeX-jaプロジェクトでは,数式モード中での和文文字はそれらが識別子として用いられる
1352 ときのみ許されると考えている.
1353 この観点から,
1354 %</ja>
1355
1356 \begin{itemize}
1357 %<*en>
1358 \item The lines 1~and~2 above are not correct, since ``高温'' in above is used as a textual label, and
1359 ``よって'' is used as a conjunction.
1360 %</en>
1361 %<*ja>
1362 \item 上記数式のうち1, 2行目は正しくない.なぜならば「高温」が意味のあるラベルと
1363       して,「よって」が接続詞として用いられているからである.
1364 %</ja>
1365 %<en>\item However, the line~3 is correct, since ``素'' is used as an identifier.
1366 %<ja>\item しかしながら,3行目は「素」が単なる識別子として用いられているので正しい.
1367 \end{itemize}
1368 %<en>Hence, in our opinion, the above input should be corrected as:
1369 %<ja>したがって,\LuaTeX-jaプロジェクトの意見としては,上記の入力は次のように直されるべきである:
1370 \begin{LTXexample}
1371 $f_{\text{高温}}$~%
1372 ($f_{\text{high temperature}}$).
1373 \[ y=(x-1)^2+2\quad
1374   \mathrel{\text{よって}}\quad y>0 \]
1375 $5\in 素:=\{\,p\in\mathbb N:\text{$p$ is a prime}\,\}$.
1376 \end{LTXexample}
1377 %<*en>
1378 We also believe that using Japanese characters as identifiers is rare,
1379 hence we don't describe how to change Japanese fonts in math mode in
1380 this chapter. For the method, please see Subsection~\ref{ssec:math}.
1381 %</en>
1382 %<*ja>
1383 また\LuaTeX-jaプロジェクトでは,和文文字が識別子として用いられることはほとんどない
1384 と考えており,したがってこの節では数式モード中の和文フォントを変更する方法については
1385 記述しない.この方法については\ref{ssec:math}節を参照のこと.
1386 %</ja>
1387
1388 %<en>\subsection{\Pkg{luatexja-fontspec} package}
1389 %<ja>\subsection{\Pkg{luatexja-fontspec}パッケージ}
1390 \label{ssec:fontspec}
1391 %<*en>
1392 To use the functionality of the \Pkg{fontspec} package to Japanese fonts,
1393 it is needed to load the \Pkg{luatexja-fontspec} package in the preamble, as follows:
1394 \begin{quote}
1395 \ttfamily \textbackslash usepackage[<options>]\{luatexja-fontspec\}
1396 \end{quote}
1397 This \Pkg{luatexja-fontspec} package
1398 automatically loads \Pkg{luatexja} and \Pkg{fontspec}
1399 packages, if needed.
1400 %</en>
1401 %<*ja>
1402 \Pkg{fontspec}パッケージは,\LuaTeX・\XeTeX において
1403 TrueType・OpenTypeフォントを容易に扱うためのパッケージであり,このパッケージを読み込んでお
1404 けばUnicodeによる各種記号の直接入力もできるようになる.
1405 \LuaTeX-jaでは和文と欧文を区別しているため,\Pkg{fontspec}パッケージの機能は欧文フォントに
1406 対してのみ有効なものとなっている.
1407
1408 \LuaTeX-ja上において,\Pkg{fontspec}パッケージと同様の機能を和文フォントに対しても用いる場
1409 合は\Pkg{luatexja-fontspec}パッケージを読み込む:
1410 \begin{quote}
1411 \ttfamily \textbackslash usepackage[<options>]\{luatexja-fontspec\}
1412 \end{quote}
1413 このパッケージは自動で\Pkg{luatexja}パッケージと\Pkg{fontspec}パッケージを読み込む.
1414 %</ja>
1415
1416 %<*en>
1417 In the \Pkg{luatexja-fontspec} package, the following seven~commands are defined as
1418 counterparts of original commands in the \Pkg{fontspec} package:
1419 %</en>
1420 %<*ja>
1421 \Pkg{luatexja-fontspec}パッケージでは,以下の7つのコマンドを\Pkg{fontspec}
1422 パッケージの元のコマンドに対応するものとして定義している:
1423 %</ja>
1424 %<*en>
1425 \begin{center}\small
1426 \begin{tabular}{ccccc}
1427 \toprule
1428 Japanese fonts
1429 &\cs{jfontspec}&\cs{setmainjfont}&\cs{setsansjfont}&\cs{setmonojfont}$^*$\\
1430 alphabetic fonts
1431 &\cs{fontspec}&\cs{setmainfont}&\cs{setsansfont}&\cs{setmonofont}\\
1432 \midrule
1433 Japanese fonts
1434 &\cs{newjfontfamily}&\cs{newjfontface}
1435 &\cs{defaultjfontfeatures}&\cs{addjfontfeatures}\\
1436 alphabetic fonts
1437 &\cs{newfontfamily}&\cs{newfontface}
1438 &\cs{defaultfontfeatures}&\cs{addfontfeatures}\\
1439 \bottomrule
1440 \end{tabular}
1441 \end{center}
1442 %</en>
1443 %<*ja>
1444 \begin{center}\small
1445 \begin{tabular}{ccccc}
1446 \toprule
1447 和文
1448 &\cs{jfontspec}&\cs{setmainjfont}&\cs{setsansjfont}&\cs{setmonojfont}$^*$\\
1449 欧文
1450 &\cs{fontspec}&\cs{setmainfont}&\cs{setsansfont}&\cs{setmonofont}\\
1451 \midrule
1452 和文
1453 &\cs{newjfontfamily}&\cs{newjfontface}
1454 &\cs{defaultjfontfeatures}&\cs{addjfontfeatures}\\
1455 欧文
1456 &\cs{newfontfamily}&\cs{newfontface}
1457 &\cs{defaultfontfeatures}&\cs{addfontfeatures}\\
1458 \bottomrule
1459 \end{tabular}
1460 \end{center}
1461 %</ja>
1462
1463 %<en> The package option of \Pkg{luatexja-fontspec} are the followings:
1464 %<ja> \Pkg{luatexja-fontspec} パッケージのオプションは以下の通りである:
1465 \begin{cslist}
1466  \item[match]
1467 %<*en>
1468 If this option is specified, usual family-changing commands such as
1469 \cs{rmfamily},~\cs{textrm}, \cs{sffamily},~\dots\ also change Japanese font family.
1470
1471 Note that \emph{\cs{setmonojfont} is defined
1472 if and only if this \texttt{\textup{match}} option is specified}.
1473 %</en>
1474
1475 %<*ja>
1476 このオプションが指定されると,「\pLaTeXe 新ドキュメントクラス」のように\
1477 \cs{rmfamily}, \verb+\textrm{...}+, \cs{sffamily} 等が
1478 欧文フォントだけでなく和文フォントも変更するようになる.
1479
1480 \emph{なお,\cs{setmonojfont} はこの \texttt{match} オプションが
1481 指定された時のみ定義される.}この命令は標準の「タイプライタ体に対応する和文フォント」を指定する.
1482 %</ja>
1483
1484  \item[pass=<opts>]
1485 %<en> \emph{(Obsoleted)}\ Specify options <opts> which will be passed to the \Pkg{fontspec} package.
1486 %<ja> \Pkg{fontspec} パッケージに渡すオプション <opts> を指定する.本オプションは時代遅れである.
1487
1488 \item[scale=<float>]
1489 %<*en>
1490 Override the ratio of the font size of Japanese fonts to that of alphabetic fonts.
1491 The default value is determined as follows:
1492   \begin{itemize}
1493     \item The value of \cs{Cjascale} is used, if this control sequence is already defined.
1494     \item It is calculated automatically from the current Japanese font at the loading of the
1495     package, if \cs{Cjascale} is not defined.
1496   \end{itemize}
1497 \cs{Cjascale} is defined in \Pkg{ltjclasses} and \Pkg{ltjsclasses}.
1498 %</en>
1499 %<*ja>
1500 欧文に対する和文の比率を手動で上書きするときに使用する.
1501 標準では
1502 \begin{itemize}
1503   \item \cs{Cjascale}が定義されている場合
1504   \footnote{\LuaTeX-ja が用意しているクラスファイル(\Pkg{ltjclasses},~\Pkg{ltjsclasses})を
1505   使う場合はこちらに当てはまる.}は,それを用いる.
1506   \item \cs{Cjascale}が未定義の場合は,\Pkg{luatexja-fontspec}読み込み時の和文フォントから自動計算される.
1507 \end{itemize}
1508 %</ja>
1509 \end{cslist}
1510
1511 %<*en>
1512 All other options listed above are simply passed to the \Pkg{fontspec} package.
1513 This means that two lines below are equivalent, for example.
1514 %</en>
1515 %<*ja>
1516 上記にないオプションは全て \Pkg{fontspec} パッケージに渡される.
1517 例えば,下の2行は同じ意味になる:
1518 %</ja>
1519 \begin{lstlisting}
1520 \usepackage[no-math]{fontspec}\usepackage{luatexja-fontspec}
1521 \usepackage[no-math]{luatexja-fontspec}
1522 \end{lstlisting}
1523
1524
1525 %<*en>
1526 The reason that \cs{setmonojfont} is not defined by default is that
1527 it is popular for Japanese fonts that nearly all Japanese glyphs have same
1528 widths.  Also note that kerning information in a font is not used
1529 (that is, \texttt{kern} feature is set off) by default in these seven (or~eight) commands.
1530 This is because of the compatibility with previous versions of \LuaTeX-ja
1531 (see \ref{para-kern}).
1532
1533 Below is an example of \cs{jfontspec}.
1534 %</en>
1535 %<*ja>
1536 標準で \cs{setmonojfont} コマンドが定義されないのは,
1537 和文フォントではほぼ全ての和文文字のグリフが等幅であるのが伝統的であったことによる.
1538 また,これらの和文用のコマンドではフォント内のペアカーニング情報は標準では使用されない,
1539 言い換えれば \texttt{kern} featureは標準では無効化となっている.
1540 これは以前のバージョンの\LuaTeX-jaとの互換性のためである(\ref{para-kern}節を参照).
1541
1542 以下に\cs{jfontspec}の使用例を示す.
1543 %</ja>
1544
1545 \begin{LTXexample}[width=0.4\textwidth]
1546 \jfontspec[CJKShape=NLC]{KozMinPr6N-Regular}
1547 JIS~X~0213:2004→辻\par
1548 \jfontspec[CJKShape=JIS1990]{KozMinPr6N-Regular}
1549 JIS~X~0208:1990→辻
1550 \end{LTXexample}
1551
1552 %<en>\subsection{Presets of Japanese fonts}
1553 %<ja>\subsection{和文フォントのプリセット設定}
1554 \label{ssec:preset-abst}
1555
1556 %<*en>
1557 With \Pkg{luatexja-preset} package, 
1558 one use one of ``preset'' to simplify Japanese font setting.
1559 For details of package options, and those of each presets, please see Subsecion~\ref{ssec:preset}.
1560 The following presets are defined:
1561 %</en>
1562 %<*ja>
1563 よく使われている和文フォント設定を一行で指定できるようにしたのが
1564 \Pkg{luatexja-preset}パッケージである.オプションや各プリセットの詳細については
1565 \ref{ssec:preset}節を参照して欲しい.
1566 現時点では以下のプリセットが定義されている:
1567 %</ja>
1568 \begin{quote}
1569   \ttfamily
1570   \hyphenchar\font=-1 \exhyphenchar=-1
1571   hiragino-pro, hiragino-pron, ipa, ipa-hg, ipaex, ipaex-hg,
1572   kozuka-pr6, kozuka-pr6n, kozuka-pro, moga-mobo, moga-mobo-ex,
1573   morisawa-pr6n, morisawa-pro, ms, ms-hg, noembed, noto-otc, noto-otf,
1574   sourcehan, sourcehan-jp, ume, yu-osx, yu-win, yu-win10
1575 \end{quote}
1576
1577 %<ja> 例えば,本ドキュメントでは\Pkg{luatexja-preset}パッケージを
1578 %<en> For example, this document loads \Pkg{luatexja-preset} package by
1579 \begin{lstlisting}
1580 \usepackage[kozuka-pr6n]{luatexja-preset}
1581 \end{lstlisting}
1582 %<ja>として読み込み,小塚書体(Pr6N)を使うことを指定している.
1583 %<en> which means that Kozuka~Pr6N fonts will be used in this document.
1584
1585
1586 %<*en>
1587 \subsection{\cs{CID}, \cs{UTF}, and macros in \Pkg{japanese-otf} package}
1588 Under \pLaTeX, \Pkg{japanese-otf} package (developed by Shuzaburo Saito) is
1589 used for typesetting characters which is in Adobe-Japan1-6 CID but not
1590 in JIS~X~0208. Since this package is widely used, \LuaTeX-ja
1591 supports some of functions in the \Pkg{japanese-otf} package,
1592 as an external package \Pkg{luatexja-otf}.
1593 %</en>
1594 %<*ja>
1595 \subsection{\cs{CID}, \cs{UTF}と\Pkg{otf}パッケージのマクロ}
1596 \pLaTeX では,JIS~X~0208にないAdobe-Japan1-6の文字を出力するために,
1597 齋藤修三郎氏による\Pkg{otf}パッケージが用いられていた.このパッケージは
1598 広く用いられているため,\LuaTeX-jaにおいても\Pkg{otf}パッケージの機能の
1599 一部を(\Pkg{luatexja-otf}という別のパッケージとして)実装した.
1600 %</ja>
1601
1602 \begin{LTXexample}
1603 \jfontspec{KozMinPr6N-Regular.otf}
1604 森\UTF{9DD7}外と内田百\UTF{9592}とが\UTF{9AD9}島屋に行く。
1605
1606 \CID{7652}飾区の\CID{13706}野家,
1607 \CID{1481}城市,葛西駅,
1608 高崎と\CID{8705}\UTF{FA11}
1609
1610 \aj半角{はんかくカタカナ}
1611 \end{LTXexample}
1612
1613 %<*ja>
1614 \Pkg{otf}パッケージでは,それぞれ次のようなオプションが存在した:
1615 \begin{cslist}
1616 \item[deluxe] 明朝体・ゴシック体各3ウェイトと,丸ゴシック体を扱えるようになる.
1617 \item[expert] 仮名が横組・縦組専用のものに切り替わり,ルビ用仮名も
1618 \ \cs{rubyfamily}\ によって扱えるようになる.
1619 \item[bold] ゴシック体を標準で太いウェイトのものに設定する.
1620 \end{cslist}
1621 しかしこれらのオプションは\Pkg{luatexja-otf}パッケージには存在しない.
1622 \Pkg{otf}パッケージが文書中で使用する和文用TFMを自前の物に置き換えていたのに対し,
1623 \Pkg{luatexja-otf}パッケージでは,そのようなことは行わないからである.
1624
1625 これら3オプションについては,
1626 \Pkg{luatexja-preset} パッケージにプリセットを使う時に一緒に指定するか,
1627 あるいは対応する内容を\ref{ssec:chgfnt}節,\ref{ssec:nfsspat}節 (NFSS2) や
1628 \ref{ssec:fontspec}節 (\Pkg{fontspec}) の方法で手動で指定する必要がある.
1629 %</ja>
1630
1631 %<en>\subsection{Changing default Japanese fonts}
1632 %<ja>\subsection{標準和文フォントの変更}
1633 \label{ssec:cfg}
1634 %<*en>
1635 If \texttt{luatexja.cfg} can be seen from \LuaTeX, \LuaTeX-ja automatically reads it.
1636 The main use of \texttt{luatexja.cfg} is for changing default Japanese fonts,
1637 when IPAex fonts cannot be installed in \TeX~system.
1638 One should not overuse this \texttt{luatexja.cfg}; fonts which will be used in
1639 a document should be specified in its source.
1640
1641 For example,
1642 \begin{lstlisting}
1643 \def\ltj@stdmcfont{IPAMincho}
1644 \def\ltj@stdgtfont{IPAGothic}
1645 \end{lstlisting}
1646 makes that IPA~Mincho and IPA~Gothic will be used as default Japanese fonts, instead of
1647 IPAex~Mincho and IPAex~Gothic.
1648
1649 For another example, the following two lines makes that
1650 non-embedded fonts Ryumin-Light~and~GothicBBB-Medium as default Japanese fonts
1651 (as the earlier version of \LuaTeX-ja):
1652 \begin{lstlisting}
1653 \def\ltj@stdmcfont{psft:Ryumin-Light}
1654 \def\ltj@stdgtfont{psft:GothicBBB-Medium}
1655 \end{lstlisting}
1656 %</en>
1657 %<*ja>
1658 \LuaTeX から見える位置に \texttt{luatexja.cfg} があれば,\LuaTeX-jaはそれを読み込む.
1659 このファイルを用いるとplain~\TeX, \LaTeXe における標準和文フォントを
1660 IPAex明朝・IPAexゴシックから変更することができる.
1661 しかし,基本的には\emph{文章中で用いるフォントは(例えば \Pkg{luatexja-preset} などで)
1662 文書ソース内で指定するべき}であり,この \texttt{luatexja.cfg} は,
1663 「IPAexフォントがインストールできない」など,IPAexフォントが使用できない場合にのみ
1664 応急処置的に用いるべきである.
1665
1666 例えば
1667 \begin{lstlisting}
1668 \def\ltj@stdmcfont{IPAMincho}
1669 \def\ltj@stdgtfont{IPAGothic}
1670 \end{lstlisting}
1671 と記述しておけば,標準和文フォントがIPA明朝・IPAゴシックへと変
1672 更される.
1673
1674
1675 なお,20140906.0以前のバージョンのように,
1676 Ryumin-Light, GothicBBB-Mediumという名前の非埋込フォントを用いる場合は
1677 \begin{lstlisting}
1678 \def\ltj@stdmcfont{psft:Ryumin-Light}
1679 \def\ltj@stdgtfont{psft:GothicBBB-Medium}
1680 \end{lstlisting}
1681 と記述すればよい.
1682 %</ja>
1683
1684
1685 %<en>\section{Changing Internal Parameters}
1686 %<ja>\section{パラメータの変更}
1687
1688 %<*en>
1689 There are many internal parameters in \LuaTeX-ja. And due to the behavior of \LuaTeX,
1690 most of them are not stored as internal register of \TeX, but as an
1691 original storage system in \LuaTeX-ja. Hence, to assign or acquire those
1692 parameters, you have to use commands \cs{ltjsetparameter} and
1693 \cs{ltjgetparameter}.
1694 %</en>
1695 %<*ja>
1696 \LuaTeX-jaには多くのパラメータが存在する.そして\LuaTeX の仕様のために,
1697 その多くは\TeX のレジスタにではなく,\LuaTeX-ja独自の方法で保持されている.
1698 これらのパラメータを設定・取得するためには \cs{ltjsetparameter} と \cs{ltjgetparameter} を
1699 用いる.
1700 %</ja>
1701
1702 %<en>\subsection{Range of \textbf{JAchar}s}
1703 %<ja>\subsection{\textbf{JAchar}の範囲}
1704 \label{ssec:setrange}
1705
1706 %<*en>
1707 \LuaTeX-ja divides the Unicode codespace \texttt{U+0080}--\texttt{U+10FFFF}
1708 into \emph{character ranges},
1709 numbered 1 to 217. The grouping can be (globally) customized by \cs{ltjdefcharrange}.
1710 The next line adds whole characters in Supplementary Ideographic Plane
1711 and the character ``漢'' to the character range~100.
1712 %</en>
1713 %<*ja>
1714 \LuaTeX-jaは,Unicodeの \texttt{U+0080}--\texttt{U+10FFFF} の空間を
1715 1番から217番までの\emph{文字範囲}に分割している.
1716 区分けは \cs{ltjdefcharrange} を用いることで(グローバルに)変更することができ,
1717 例えば,次は追加漢字面(SIP)にある全ての文字と「漢」を「100番の文字範囲」に追加する.
1718 %</ja>
1719 \begin{lstlisting}
1720 \ltjdefcharrange{100}{"20000-"2FFFF,`漢}
1721 \end{lstlisting}
1722
1723 %<*en>
1724 A character can belong to only one character range.
1725 For example, whole SIP belong to the range~4 in the default setting of \LuaTeX-ja,
1726 and if one executes the above line, then SIP will belong to the range~100 and be
1727 removed from the range~4.
1728 %</en>
1729 %<*ja>
1730 各文字はただ一つの文字範囲に所属することができる.
1731 例えば,SIP内の文字は全て\LuaTeX-jaのデフォルトでは4番の文字範囲に
1732 属しているが,上記の指定を行えばSIP内の文字は100番に属すようになり,4番からは除かれる.
1733 %</ja>
1734
1735 %<*en>
1736 The distinction between \textbf{ALchar} and \textbf{JAchar} is performed by character ranges.
1737 This can be edited by setting the \textsf{jacharrange} parameter.
1738 For example, the code below is just the default setting of \LuaTeX-ja, and
1739 it sets
1740 \begin{itemize}
1741  \item a character which belongs character ranges 1,~4, 5, and~8 is \textbf{ALchar},
1742  \item a character which belongs character ranges 2,~3, 6, and~7 is \textbf{JAchar}.
1743 \end{itemize}
1744 %</en>
1745 %<*ja>
1746 \textbf{ALchar}と\textbf{JAchar}の区別は文字範囲ごとに行われる.
1747 これは\textsf{jacharrange}パラメータによって編集できる.
1748 例えば,以下は\LuaTeX-jaの初期設定であり,次の内容を設定している:
1749 \begin{itemize}
1750  \item 1番,4番,5番,8番の文字範囲に属する文字は\textbf{ALchar}.
1751  \item 2番,3番,6番,7番の文字範囲に属する文字は\textbf{JAchar}.
1752 \end{itemize}
1753 %</ja>
1754 \begin{lstlisting}
1755 \ltjsetparameter{jacharrange={-1, +2, +3, -4, -5, +6, +7, -8}}
1756 \end{lstlisting}
1757 %<*en>
1758 The argument to \textsf{jacharrange} parameter is a list of non-zero integer.
1759 Negative integer $-n$ in the list means that ``each character in the range~$n$ is an
1760 \textbf{ALchar}'',
1761 and positive integer $+n$ means that ``\dots\ is a \textbf{JAchar}''.
1762 %</en>
1763 %<*ja>
1764 \textsf{jacharrange}パラメータの引数は非零の整数のリストである.
1765 リスト中の負の整数$-n$は「文字範囲$n$に属する文字は\textbf{ALchar}として
1766 扱う」ことを意味し,正の整数$+n$は「\textbf{JAchar}として扱う」ことを意味する.
1767 %</ja>
1768
1769 %<*en>
1770 Note that characters \texttt{U+0000}--\texttt{U+007F} are always treated as an
1771 \textbf{ALchar} (this cannot be customized).
1772 %</en>
1773 %<*ja>
1774 なお,\texttt{U+0000}--\texttt{U+007F} は常に\textbf{ALchar}として扱われる(利用者が変更す
1775 ることは出来ない).
1776 %</ja>
1777
1778 %<*en>
1779 \paragraph{Default character ranges}
1780 \LuaTeX-ja predefines eight character ranges for convenience. They are
1781 determined from the following data:
1782 %</en>
1783 %<*ja>
1784 \paragraph{文字範囲の初期値}
1785 \LuaTeX-jaでは8つの文字範囲を予め定義しており,
1786 これらは以下のデータに基づいて決定している.
1787 %</ja>
1788 \begin{itemize}
1789 %<en>\item Blocks in Unicode~6.0.
1790 %<ja>\item Unicode~6.0のブロック.
1791 %<en>\item The \texttt{Adobe-Japan1-UCS2} mapping between a CID Adobe-Japan1-6 and Unicode.
1792 %<ja>\item Adobe-Japan1-6のCIDとUnicodeの間の対応表\texttt{Adobe-Japan1-UCS2}.
1793 %<en>\item The \Pkg{PXbase} bundle for \upTeX\ by Takayuki Yato.
1794 %<ja>\item 八登崇之氏による\upTeX 用の\Pkg{PXbase}バンドル.
1795 \end{itemize}
1796
1797 %<*en>
1798 Now we describe these eight ranges. The superscript ``J'' or ``A'' after the
1799 number shows whether each character in the range is treated as
1800 \textbf{JAchar}s or not by default. These settings are similar to the
1801 \texttt{prefercjk} settings defined in \texttt{PXbase} bundle.
1802 Any characters equal to or above \texttt{U+0080} which does not belong to
1803 these eight ranges belongs to the character range~217.
1804 %</en>
1805 %<*ja>
1806 以下ではこれら8つの文字範囲について記述する.添字のアルファベット「J」「A」
1807 は,その文字範囲内の文字が\textbf{JAchar}か\textbf{ALchar}かを表している.これらの初期設定は
1808 \texttt{PXbase}バンドルで定義されている\texttt{prefercjk}と類似のものであるが,
1809 8ビットフォント使用時のトラブルを防ぐために \texttt{U+0080}--\texttt{U+00FF} の文字は全部
1810 \textbf{ALchar}としている.
1811 なお,\texttt{U+0080} 以降でこれら8つの文字範囲に属さない文字は,217番の文字範囲に属することになっている.
1812 %</ja>
1813 \begin{description}
1814 %<*en>
1815
1816 \item[Range~8${}^{\text{A}}$] The intersection of the upper half of ISO~8859-1
1817          (Latin-1 Supplement) and JIS~X~0208 (a basic character set for Japanese). This character range
1818          consists of the following characters:
1819 %</en>
1820 %<*ja>
1821 \item[範囲8${}^{\text{A}}$] ISO~8859-1の上位領域(ラテン1補助)と
1822                              JIS~X~0208の共通部分.この文字範囲は
1823                              以下の文字で構成される:
1824 %</ja>
1825 \begin{multicols}{2}
1826 \begin{itemize}
1827 \def\ch#1#2{\item \char"#1\ (\texttt{U+00#1}, #2)}%"
1828 \ch{A7}{Section Sign}
1829 \ch{A8}{Diaeresis}
1830 \ch{B0}{Degree sign}
1831 \ch{B1}{Plus-minus sign}
1832 \ch{B4}{Spacing acute}
1833 \ch{B6}{Paragraph sign}
1834 \ch{D7}{Multiplication sign}
1835 \ch{F7}{Division Sign}
1836 \end{itemize}
1837 \end{multicols}
1838
1839 %<*en>
1840 \item[Range~1${}^{\text{A}}$] Latin characters that some of them are included in Adobe-Japan1-6.
1841 This range consists of the following Unicode ranges, \emph{except characters in the range~8 above}:
1842 %</en>
1843 %<*ja>
1844 \item[範囲1${}^{\text{A}}$] ラテン文字のうち,Adobe-Japan1-6との共通部分があるもの.
1845                              この範囲は以下のUnicodeのブロックのうち
1846                              \emph{範囲8を除いた}部分で構成されている:
1847 %</ja>
1848 \begin{multicols}{2}
1849 \begin{itemize}
1850 \item \texttt{U+0080}--\texttt{U+00FF}: Latin-1 Supplement
1851 \item \texttt{U+0100}--\texttt{U+017F}: Latin Extended-A
1852 \item \texttt{U+0180}--\texttt{U+024F}: Latin Extended-B
1853 \item \texttt{U+0250}--\texttt{U+02AF}: IPA Extensions
1854 \item \texttt{U+02B0}--\texttt{U+02FF}: Spacing Modifier Letters
1855 %<en>\par\
1856 \item \texttt{U+0300}--\texttt{U+036F}: \\*\null\hfill Combining Diacritical Marks
1857 \item \texttt{U+1E00}--\texttt{U+1EFF}: \\*\null\hfill Latin Extended Additional
1858 %<ja>\par\
1859 \end{itemize}
1860 \end{multicols}
1861 %<*en>
1862 \item[Range~2${}^{\text{\kern.1emJ}}$] Greek and Cyrillic letters. JIS~X~0208 (hence most of Japanese
1863            fonts) has some of these characters.
1864 %</en>
1865 %<*ja>
1866 \item[範囲2${}^{\text{\kern.1emJ}}$] ギリシャ文字とキリル文字.JIS~X~0208(したがってほとんどの
1867                              和文フォント)には,これらの文字の一部が含まれている.
1868 %</ja>
1869 \begin{multicols}{2}
1870 \begin{itemize}
1871 \item \texttt{U+0370}--\texttt{U+03FF}: Greek and Coptic
1872 \item \texttt{U+0400}--\texttt{U+04FF}: Cyrillic
1873 \item \texttt{U+1F00}--\texttt{U+1FFF}: Greek Extended
1874 \\\
1875 \end{itemize}
1876 \end{multicols}
1877 %<*en>
1878 \item[Range~3${}^{\text{\kern.1emJ}}$] Punctuations and Miscellaneous symbols. The block list is
1879            indicated in \autoref{tab:rng3}.
1880 %</en>
1881 %<*ja>
1882 \item[範囲3${}^{\text{\kern.1emJ}}$] 句読点と記号類.ブロックのリストは\autoref{tab:rng3}%
1883                              に示してある.
1884 %</ja>
1885 \begin{table}[!tb]
1886 %<en>\caption{Unicode blocks in predefined character range~3.}\medskip
1887 %<ja>\caption{文字範囲3に指定されているUnicodeブロック.}
1888 \label{tab:rng3}
1889 \catcode`\"=13\def"#1#2#3#4{\texttt{U+#1#2#3#4}}%"
1890 \centering\small
1891 \begin{tabular}{llll}
1892 "2000--"206F&General Punctuation&
1893 "2070--"209F&Superscripts and Subscripts\\
1894 "20A0--"20CF&Currency Symbols&
1895 "20D0--"20FF&Comb.\ Diacritical Marks for Symbols\\
1896 "2100--"214F&Letterlike Symbols&
1897 "2150--"218F&Number Forms\\
1898 "2190--"21FF&Arrows&
1899 "2200--"22FF&Mathematical Operators\\
1900 "2300--"23FF&Miscellaneous Technical&
1901 "2400--"243F&Control Pictures\\
1902 "2500--"257F&Box Drawing&
1903 "2580--"259F&Block Elements\\
1904 "25A0--"25FF&Geometric Shapes&
1905 "2600--"26FF&Miscellaneous Symbols\\
1906 "2700--"27BF&Dingbats&
1907 "2900--"297F&Supplemental Arrows-B\\
1908 "2980--"29FF&Misc.\ Mathematical Symbols-B&
1909 "2B00--"2BFF&Miscellaneous Symbols and Arrows
1910 \end{tabular}
1911 \end{table}
1912 %<*en>
1913 \item[Range~4${}^{\text{A}}$] Characters usually not in Japanese fonts. This range consists
1914            of almost all Unicode blocks which are not in other
1915            predefined ranges. Hence, instead of showing the block list,
1916            we put the definition of this range itself:
1917 %</en>
1918 %<*ja>
1919 \item[範囲4${}^{\text{A}}$] 通常和文フォントには含まれていない文字.
1920                              この範囲は他の範囲にないほとんど全てのUnicodeブロック
1921                              で構成されている.したがって,ブロックのリストを示す
1922                              代わりに,範囲の定義そのものを示す:
1923 %</ja>
1924 \begin{lstlisting}
1925 \ltjdefcharrange{4}{%
1926    "500-"10FF, "1200-"1DFF, "2440-"245F, "27C0-"28FF, "2A00-"2AFF,
1927   "2C00-"2E7F, "4DC0-"4DFF, "A4D0-"A82F, "A840-"ABFF, "FB00-"FE0F,
1928   "FE20-"FE2F, "FE70-"FEFF, "10000-"1FFFF, "E000-"F8FF} % non-Japanese
1929 \end{lstlisting}
1930 %<en>\item[Range~5${}^{\text{A}}$] Surrogates and Supplementary Private Use Areas.
1931 %<ja>\item[範囲5${}^{\text{A}}$] 代用符号と補助私用領域.
1932 %<en>\item[Range~6${}^{\text{\kern.1emJ}}$] Characters used in Japanese. The block list is indicated in \autoref{tab:rng6}.
1933 %<ja>\item[範囲6${}^{\text{\kern.1emJ}}$] 日本語で用いられる文字.ブロックのリストは\autoref{tab:rng6}に示す.
1934 \begin{table}[!tb]
1935 %<en>\caption{Unicode blocks in predefined character range~6.}\medskip
1936 %<ja>\caption{文字範囲6に指定されているUnicodeブロック.}
1937 \label{tab:rng6}
1938 \catcode`\"=13\def"#1#2#3#4{\texttt{U+#1#2#3#4}}%"
1939 \centering\small
1940 \begin{tabular}{llll}
1941 "2460--"24FF&Enclosed Alphanumerics&
1942 "2E80--"2EFF&CJK Radicals Supplement\\
1943 "3000--"303F&CJK Symbols and Punctuation&
1944 "3040--"309F&Hiragana\\
1945 "30A0--"30FF&Katakana&
1946 "3190--"319F&Kanbun\\
1947 "31F0--"31FF&Katakana Phonetic Extensions&
1948 "3200--"32FF&Enclosed CJK Letters and Months\\
1949 "3300--"33FF&CJK Compatibility&
1950 "3400--"4DBF&CJK Unified Ideographs Extension A\\
1951 "4E00--"9FFF&CJK Unified Ideographs&
1952 "F900--"FAFF&CJK Compatibility Ideographs\\
1953 "FE10--"FE1F&Vertical Forms&
1954 "FE30--"FE4F&CJK Compatibility Forms\\
1955 "FE50--"FE6F&Small Form Variants&
1956 "{20}000--"{2F}FFF&(Supplementary Ideographic Plane)\\
1957 "{E0}100--"{E0}1EF&Variation Selectors Supplement
1958 \end{tabular}
1959 \end{table}
1960 %<*en>
1961 \item[Range~7${}^{\text{\kern.1emJ}}$] Characters used in CJK languages, but not included in  Adobe-Japan1-6.
1962 The block list is indicated in \autoref{tab:rng7}.
1963 %</en>
1964 %<*ja>
1965 \item[範囲7${}^{\text{\kern.1emJ}}$] CJK言語で用いられる文字のうち,Adobe-Japan1-6に
1966                             含まれていないもの.
1967                             ブロックのリストは\autoref{tab:rng7}に示す.
1968 %</ja>
1969 \begin{table}[!tb]
1970 %<en>\caption{Unicode blocks in predefined character range~7.}\medskip
1971 %<ja>\caption{文字範囲7に指定されているUnicodeブロック.}
1972 \label{tab:rng7}
1973 \catcode`\"=13\def"#1#2#3#4{\texttt{U+#1#2#3#4}}%"
1974 \centering\small
1975 \begin{tabular}{llll}
1976 "1100--"11FF&Hangul Jamo&
1977 "2F00--"2FDF&Kangxi Radicals\\
1978 "2FF0--"2FFF&Ideographic Description Characters&
1979 "3100--"312F&Bopomofo\\
1980 "3130--"318F&Hangul Compatibility Jamo&
1981 "31A0--"31BF&Bopomofo Extended\\
1982 "31C0--"31EF&CJK Strokes&
1983 "A000--"A48F&Yi Syllables\\
1984 "A490--"A4CF&Yi Radicals&
1985 "A830--"A83F&Common Indic Number Forms\\
1986 "AC00--"D7AF&Hangul Syllables&
1987 "D7B0--"D7FF&Hangul Jamo Extended-B
1988 \end{tabular}
1989 \end{table}
1990 \end{description}
1991
1992 %<*en>
1993 \paragraph{Notes on \texttt{U+0080}--\texttt{U+00FF}}
1994 You should treat characters in \\texttt{U+0080}--\texttt{U+00FF} as \textbf{ALchar},
1995 when you use traditional 8-bit fonts, such as the \Pkg{marvosym} package.
1996
1997 For example, \cs{Frowny} which is provided by the \Pkg{marvosym} package has
1998 the same codepoint as \S\ (\text{U+00A7}).
1999 Hence, as previous versions of \LuaTeX-ja, if these characters are treated as
2000 \text{JAchar}s, then \cs{Frowny} produces ``\ltjjachar`§'' (in a Japanese font).
2001
2002 To avoid such situations, the default setting of \LuaTeX-ja is changed in version~20150906.0
2003 so that all characters \texttt{U+0080}--\texttt{U+00FF} are treated as \textbf{ALchar}.
2004
2005 If you want to output a character as \textbf{ALchar} and \textbf{JAchar} regardless the range
2006 setting, you can use \cs{ltjalchar} and \cs{ltjjachar} respectively, as the following example.
2007 \begin{LTXexample}[width=0.3\textwidth]
2008 \gtfamily\large % default, ALchar, JAchar
2009 ¶, \ltjalchar`¶, \ltjjachar`¶\\   % default: ALchar
2010 α, \ltjalchar`α, \ltjjachar`α  % default: JAchar
2011 \end{LTXexample}
2012 %</en>
2013 %<*ja>
2014 \paragraph{\texttt{U+0080}--\texttt{U+00FF}についての注意}
2015 \LuaTeX-jaで,\Pkg{marvosym}パッケージ等,Unicodeフォントでなく
2016 伝統的な8ビットフォントを用いる場合には注意が必要である.
2017
2018 例えば,\Pkg{marvosym}パッケージの提供する \cs{Frowny} も,符号位置は167,つまりUnicodeにおける
2019 \S\ (\text{U+00A7}) と同じ符号位置にある.
2020 即ち,以前のバージョンのように,「前節の文字範囲8内の文字は\textbf{JAchar}」という設定で
2021 あったとすると,上記の \cs{Frowny} は和文フォントで「\ltjjachar`§」を出力することになる.
2022
2023 このような事態を避けるために,バージョン20150906.0からは \texttt{U+0080}--\texttt{U+00FF} の範囲の
2024 文字は全て\textbf{ALchar}となるように初期設定を変更している.
2025
2026 なお,文字範囲の設定に関わらず1つの文字を\textbf{ALchar}, \textbf{JAchar}で出力したい場合には,
2027 以下の例のようにそれぞれ \cs{ltjalchar},~\cs{ltjjachar} に該当文字の文字コードを渡せばよい.
2028 \begin{LTXexample}[width=0.3\textwidth]
2029 \gtfamily\large % default, ALchar, JAchar
2030 ¶, \ltjalchar`¶, \ltjjachar`¶\\   % default: ALchar
2031 α, \ltjalchar`α, \ltjjachar`α  % default: JAchar
2032 \end{LTXexample}
2033 %</ja>
2034
2035
2036 %<en>\subsection{\Param{kanjiskip} and \Param{xkanjiskip}}
2037 %<ja>\subsection{\Param{kanjiskip}と\Param{xkanjiskip}}
2038 \label{subs-kskip}
2039
2040 %<en>\textbf{JAglue} is divided into the following three categories:
2041 %<ja>\textbf{JAglue}は以下の3つのカテゴリに分類される:
2042 \begin{itemize}
2043 %<*en>
2044 \item Glues/kerns specified in JFM. If \cs{inhibitglue} is issued
2045       around a \textbf{JAchar}, this glue will not be inserted at the
2046       place.
2047 %</en>
2048 %<*ja>
2049 \item JFMで指定されたグルー/カーン.もし \cs{inhibitglue} が\textbf{JAchar}の周りで
2050       発行されていれば,このグルーは挿入されない.
2051 %</ja>
2052 %<*en>
2053 \item The default glue which inserted between two \textbf{JAchar}s (\Param{%
2054       kanjiskip}).
2055 %</en>
2056 %<*ja>
2057 \item デフォルトで2つの\textbf{JAchar}の間に挿入されるグルー(\Param{kanjiskip}).
2058 %</ja>
2059 %<*en>
2060 \item The default glue which inserted between a \textbf{JAchar} and an
2061       \textbf{ALchar} (\Param{xkanjiskip}).
2062 %</en>
2063 %<*ja>
2064 \item デフォルトで\textbf{JAchar}と\textbf{ALchar}の間に挿入されるグルー(\Param{xkanjiskip}).
2065 %</ja>
2066 \end{itemize}
2067 %<*en>
2068 The value (a skip) of \Param{kanjiskip} or
2069 \Param{xkanjiskip} can be changed as the following.
2070 Note that only their values \emph{at the end of a paragraph or a hbox are
2071 adopted in the whole paragraph or the whole hbox.
2072 }
2073 %</en>
2074 %<*ja>
2075 \Param{kanjiskip}や\Param{xkanjiskip}の値
2076 は以下のようにして変更可能である.
2077 %</ja>
2078 \begin{lstlisting}
2079 \ltjsetparameter{kanjiskip={0pt plus 0.4pt minus 0.4pt},
2080                  xkanjiskip={0.25\zw plus 1pt minus 1pt}}
2081 \end{lstlisting}
2082 %<*en>
2083 Here \cs{zw} is a internal dimension
2084 which stores fullwidth of the current Japanese font.
2085 This \cs{zw} can be used as the unit \texttt{zw} in \pTeX.
2086
2087 The value of these parameter can be get by \cs{ltjgetparameter}.
2088 Note that the result by \cs{ltjgetparameter} is \emph{not} the internal quantities,
2089 but \emph{a string} (hence \cs{the} cannot be prefixed).
2090 %</en>
2091 %<*ja>
2092 ここで,\cs{zw} は現在の和文フォントの全角幅を表す長さであり,
2093 \pTeX における長さ単位 \texttt{zw} と同じように使用できる.
2094
2095 これらのパラメータの値は以下のように取得できる.
2096 戻り値は内部値ではなく\emph{文字列}である(\cs{the} は前置できない)ことに注意してほしい:
2097 %</ja>
2098 \begin{LTXexample}
2099 kanjiskip: \ltjgetparameter{kanjiskip},\\
2100 xkanjiskip: \ltjgetparameter{xkanjiskip}
2101 \end{LTXexample}
2102
2103 %<*en>
2104 It may occur that JFM contains the data of ``ideal width of
2105 \Param{kanjiskip}''
2106 and/or ``ideal width of \Param{xkanjiskip}''.
2107 To use these data from JFM, set the value of \Param{kanjiskip} or
2108 \Param{xkanjiskip} to \cs{maxdimen}
2109 (these ``ideal width'' cannot be retrived by \cs{ltjgetparameter}).
2110 %</en>
2111 %<*ja>
2112 JFMは「望ましい\Param{kanjiskip}の値」や
2113 「望ましい\Param{xkanjiskip}の値」を持っていることがある.
2114 これらのデータを使うためには,\Param{kanjiskip}や%
2115 \Param{xkanjiskip}の値を \cs{maxdimen} の値に設定すればよいが,
2116 \cs{ltjgetparameter} によって取得することはできないので注意が必要である.
2117 %</ja>
2118
2119 %<en>\subsection{Insertion setting of \Param{xkanjiskip}}
2120 %<ja>\subsection{\Param{xkanjiskip} の挿入設定}
2121
2122 %<*en>
2123 It is not desirable that \Param{xkanjiskip} is inserted into every
2124 boundary between \textbf{JAchar}s and \textbf{ALchar}s. For example,
2125 \Param{xkanjiskip} should not be inserted after opening parenthesis
2126 (\textit{e.g.}, compare ``(あ'' and ``(\hskip\ltjgetparameter{xkanjiskip}あ'').
2127 \LuaTeX-ja can control whether \Param{xkanjiskip} can be inserted
2128 before/after a character, by changing \Param{jaxspmode} for \textbf{JAchar}s and
2129 \Param{alxspmode} parameters \textbf{ALchar}s respectively.
2130 %</en>
2131 %<*ja>
2132 \Param{xkanjiskip}がすべての\textbf{JAchar}と\textbf{ALchar}の境界に
2133 挿入されるのは望ましいことではない.例えば,\Param{xkanjiskip}は開き括弧の
2134 後には挿入されるべきではない(「(あ」と「(\hskip\ltjgetparameter{xkanjiskip}あ」を
2135 比べてみよ).
2136 \LuaTeX-jaでは\Param{xkanjiskip}をある文字の前/後に挿入するかどうかを,
2137 \textbf{JAchar}に対しては\Param{jaxspmode}を,\textbf{ALchar}に対しては
2138 \Param{alxspmode}をそれぞれ変えることで制御することができる.
2139 %</ja>
2140 \begin{LTXexample}
2141 \ltjsetparameter{jaxspmode={`あ,preonly}, alxspmode={`\!,postonly}}
2142 pあq い!う
2143 \end{LTXexample}
2144
2145 %<*en>
2146 The second argument \texttt{preonly} means that the insertion of
2147 \Param{xkanjiskip} is allowed before this character, but not after.
2148 the other possible values are \texttt{postonly}, \texttt{allow}, and \texttt{inhibit}.
2149 %</en>
2150 %<*ja>
2151 2つ目の引数の \texttt{preonly}は「\Param{xkanjiskip}の挿入はこの文字の
2152 前でのみ許され,後では許さない」ことを意味する.他に指定可能な値は
2153 \texttt{postonly}, \texttt{allow}, \texttt{inhibit}である.
2154 %</ja>
2155
2156 %<*en>
2157 \Param{jaxspmode} and \Param{alxspmode} use a same table to store the parameters
2158 on the current version. Therefore, line~1 in the code above can be rewritten
2159 as follows:
2160 %</en>
2161 %<*ja>
2162 なお,現行の
2163 仕様では,\Param{jaxspmode}, \Param{alxspmode}はテーブルを共有しており,
2164 上のコードの1行目を次のように変えても同じことになる:
2165 %</ja>
2166 \begin{lstlisting}
2167 \ltjsetparameter{alxspmode={`あ,preonly}, jaxspmode={`\!,postonly}}
2168 \end{lstlisting}
2169 %<*en>
2170 One can use also numbers to specify these two parameters (see Subsection~\ref{ssec:param}).
2171 %</en>
2172 %<*ja>
2173 また,これら2パラメータには数値で値を指定することもできる(\ref{ssec:param}節を参照).
2174 %</ja>
2175
2176 %<*en>
2177 If you want to enable/disable all insertions of \Param{kanjiskip} and
2178 \Param{xkanjiskip}, set \Param{autospacing} and \Param{autoxspacing}
2179 parameters to \texttt{true}/\texttt{false}, respectively.
2180 %</en>
2181 %<*ja>
2182 もし全ての\Param{kanjiskip}と\Param{xkanjiskip}の挿入を有効化/無効化
2183 したければ,それぞれ\Param{autospacing}と\Param{autoxspacing}を
2184 \texttt{true}/\texttt{false}に設定すればよい.
2185 %</ja>
2186
2187 %<en>\subsection{Shifting the baseline}
2188 %<ja>\subsection{ベースラインの移動}
2189 %<*en>
2190 To make a match between a Japanese font and an alphabetic font, sometimes
2191 shifting of the baseline of one of the pair is needed. In \pTeX, this is achieved
2192 by setting \cs{ybaselineshift} (or \cs{tbaselineshift}) to a non-zero length (the
2193 baseline of \textbf{ALchar} is shifted below). However, for documents
2194 whose main language is not Japanese, it is good to shift the baseline of
2195 Japanese fonts, but not that of alphabetic fonts.
2196 Because of this, \LuaTeX-ja can independently set the shifting amount
2197 of the baseline of alphabetic fonts and that of Japanese fonts.
2198 \begin{center}
2199  \small
2200 \begin{tabular}{>{\bfseries}lcc}
2201 \toprule
2202 &\bfseries Horizontal writing (\emph{yoko} direction) etc.
2203 &\bfseries Vertical writing(\emph{tate} direction)\\
2204 \midrule
2205 Alphabetic fonts&\Param{yalbaselineshift}
2206      parameter&\Param{talbaselineshift} parameter\\
2207 Japanese fonts&\Param{yjabaselineshift}
2208      parameter&\Param{tjabaselineshift} parameter\\
2209 \bottomrule
2210 \end{tabular}
2211 \end{center}
2212 %</en>
2213 %<*ja>
2214 和文フォントと欧文フォントを合わせるためには,時々どちらかのベースラインの移動が
2215 必要になる.\pTeX ではこれは \cs{ybaselineshift}(または\cs{tbaselineshift})を設定することで
2216 なされていた(\textbf{ALchar}のベースラインがその分だけ下がる).しかし,日本語が主ではない
2217 文書に対しては,欧文フォントではなく和文フォントのベースラインを移動した方がよい.
2218 このため,\LuaTeX-jaでは欧文フォントのベースラインのシフト量
2219 と和文フォントのベースラインのシフト量を独立に設定できるようになっている.
2220 \begin{center}
2221  \small
2222 \begin{tabular}{>{\bfseries}lcc}
2223 \toprule
2224 &\bfseries 横組など&\bfseries 縦組\\
2225 \midrule
2226 欧文フォントのシフト量&\Param{yalbaselineshift}
2227      parameter&\Param{talbaselineshift} parameter\\
2228 和文フォントのシフト量&\Param{yjabaselineshift}
2229      parameter&\Param{tjabaselineshift} parameter\\
2230 \bottomrule
2231 \end{tabular}
2232 \end{center}
2233 %</ja>
2234
2235 %<*en>
2236 Here the horizontal line in the below example is the baseline of a line.
2237 %</en>
2238 %<*ja>
2239 下の例において引かれている水平線がベースラインである.
2240 %</ja>
2241 \begin{LTXexample}
2242 \vrule width 150pt height 0.2pt depth 0.2pt \hskip-120pt
2243 \ltjsetparameter{yjabaselineshift=0pt, yalbaselineshift=0pt}abcあいう
2244 \ltjsetparameter{yjabaselineshift=5pt, yalbaselineshift=2pt}abcあいう
2245 \end{LTXexample}
2246
2247 %<*en>
2248 There is an interesting side-effect: characters in different size can be
2249 vertically aligned center in a line, by setting two parameters appropriately.
2250 The following is an example (beware the value is not well tuned):
2251 %</en>
2252 %<*ja>
2253 この機能には面白い使い方がある:2つのパラメータを適切に設定することで,サイズの
2254 異なる文字を中心線に揃えることができる.
2255 以下は一つの例である(値はあまり調整されていないことに注意):
2256 %</ja>
2257 \begin{LTXexample}[width=0.4\textwidth]
2258 \vrule width 150pt height4.417pt depth-4.217pt%
2259 \kern-150pt
2260 \large xyz漢字
2261 {\scriptsize
2262   \ltjsetparameter{yjabaselineshift=-1.757pt,
2263     yalbaselineshift=-1.757pt}
2264   漢字xyzあいう
2265 }あいうabc
2266 \end{LTXexample}
2267
2268 %<*en>
2269 Note that setting positive \Param{yalbaselineshift}~or~\Param{talbaselineshift}
2270 parameters does not increase the depth of one-letter \emph{syllable} $p$ of \textbf{Alchar}, if
2271 its left-protrusion~(\cs{lpcode}) and right-protrusion~(\cs{rpcode}) are both non-zero.
2272 This is because
2273 \begin{itemize}
2274 \item These two parameters are implemented by setting \texttt{yoffset} field of a
2275 glyph node, and this does not increase the depth of the glyph.
2276 \item To cope with the above situation, \LuaTeX-ja automatically supplies
2277 a rule in every syllable.
2278 \item However, we cannot use this ``supplying a rule'' method if a syllable comprises just
2279       one letter whose \cs{lpcode}~and~\cs{rpcode} are both non-zero.
2280 \end{itemize}
2281
2282 This problem does not apply for \Param{yjabaselineshift}~nor~\Param{tjabaselineshift},
2283 becuse a \emph{JAchar} is encapsulated by a horizontal box if needed.
2284 %</en>
2285 %<*ja>
2286 なお,以下の場合には1文字の\textbf{ALchar}からなる「音節」の深さは増加しないことに注意.
2287 \begin{itemize}
2288  \item \Param{yalbaselineshift},~\Param{talbaselineshift}パラメータが正になっている.
2289  \item 「音節」を構成する唯一の文字$p$の
2290 左余白への突出量(\cs{lpcode}),右余白への突出量(\cs{rpcode})がどちらも非零である.
2291 \end{itemize}
2292 \emph{JAchar}は必要に応じて1文字ずつボックスにカプセル化されるため,
2293 \Param{yjabaselineshift},~\Param{tjabaselineshift}パラメータについてはこのような問題は起こらない.
2294 %</ja>
2295
2296 %<*ja>
2297 \paragraph{数式における挙動:\pTeX との違い}
2298 \textbf{ALchar}のベースラインを補正する\Param{yalbaselineshift}, \Param{talbaselineshift}パラメータは
2299 ほぼ\pTeX における \cs{ybaselineshift}, \cs{tbaselineshift} に対応しているものであるが,
2300 数式中の挙動は異なっているので注意が必要である.
2301 例えば,\autoref{tab:math_bsa}のように,数式中に明示的に現れた \cs{hbox},~\cs{vbox} は,横組において
2302 \begin{itemize}
2303  \item 2015年以前の\pTeX では,ボックス全体が \cs{ybaselineshift} だとシフトされるので,
2304  \autoref{tab:math_bsa}中の``い''のように,ボックス中の和文文字は
2305  \ \cs{ybaselineshift} だけシフトされ,一方,``for all''のように,
2306  ボックス内の欧文文字は2重にシフトされることになる.
2307  \item 一方,\LuaTeX-jaではそのようなことはおこらず,
2308  数式中に明示的に現れた \cs{hbox},~\cs{vbox} はシフトしない.そのため,
2309  \autoref{tab:math_bsa}中の``い''も``for all''も,それぞれ本文中に
2310  書かれたときと同じ上下位置に組まれる.
2311
2312  なお,\TeX~Live~2016以降の\pTeX では改修がなされ,\LuaTeX-jaと
2313  近い挙動になるようにしているが,数式中に直に書かれた``あ''のベースラインについては
2314  まだ違いが見られる.
2315 \end{itemize}
2316
2317 なお,バージョン20170401.0以降の\LuaTeX-jaでは,\cs{vcenter} によるボックスには
2318 全体が\Param{yalbaselineshift}, \Param{talbaselineshift} パラメータが反映されるようにしている.
2319 その方が結果が自然であることによる変更なのだが,結果的に\cs{vcenter} については\pTeX と同じ挙動となった.
2320
2321 \begin{table}
2322 \small\centering
2323 \caption{数式関係のベースライン補正($\Param{yalbaselineshift}=10\,\textrm{pt}$)}
2324 \label{tab:math_bsa}
2325 \newdimen\origbaselineskip
2326 \origbaselineskip=\baselineskip
2327 \begin{tabular}{lp{30\zw}}
2328 \toprule
2329 \emph{入力}&\vspace*{\dimexpr-\origbaselineskip-\smallskipamount}
2330 \begin{lstlisting}
2331 数式abc: $あa\hbox{い}$, $\int_0^x t\,dt=x^2/2$,
2332 $\Phi\vdash F(x)\ \hbox{for all}\ x\in A$
2333 \end{lstlisting}\\
2334 \noalign{\vskip-\origbaselineskip}
2335 \midrule
2336 \emph{\pTeX~(--2015)}&
2337 {\ltjsetparameter{yalbaselineshift=10pt}%
2338 数式abc: $\lower10pt\hbox{あ}a\lower10pt\hbox{い}$, $\int_0^x t\,dt=x^2/2$,
2339 $\Phi\vdash F(x)\ \lower10pt\hbox{for all}\ x\in A$
2340 \par}\\\noalign{\vskip-\origbaselineskip}\midrule
2341 \emph{\pTeX~(2016--)}&
2342 {\ltjsetparameter{yalbaselineshift=10pt}%
2343 数式abc: $\lower10pt\hbox{あ}a\hbox{い}$, $\int_0^x t\,dt=x^2/2$,
2344 $\Phi\vdash F(x)\ \hbox{for all}\ x\in A$
2345 \par}\\\noalign{\vskip-\origbaselineskip}\midrule
2346 \emph{\LuaTeX-ja}&
2347 {\ltjsetparameter{yalbaselineshift=10pt}%
2348 数式abc: $あa\hbox{い}$, $\int_0^x t\,dt=x^2/2$,
2349 $\Phi\vdash F(x)\ \hbox{for all}\ x\in A$
2350 \par}\\
2351 \noalign{\vskip-\origbaselineskip}
2352 \bottomrule
2353 \end{tabular}
2354 \end{table}
2355 %</ja>
2356
2357 %<*en>
2358 \subsection{\emph{kinsoku} parameters and OpenType features}
2359 Among parameters which related to Japanese word-wrapping process (\emph{kinsoku shori}),
2360 \begin{quote}
2361  \Param{jaxspmode},~\Param{alxspmode}, \Param{prebreakpenalty},
2362  \Param{postbreakpenalty}~and~\Param{kcatcode}
2363 \end{quote}
2364 are stored by each character codes.
2365
2366 OpenType font features are ignored in these parameters.
2367 For example, a fullwidth katakana ``ア'' on line~10 in the below input is replaced to
2368 its halfwidth variant ``ア'', by \verb+hwid+ feature.
2369 However, the penalty inserted after it is 10 which is the \Param{postbreakpenalty} of
2370 ``ア'', not 20.
2371 %</en>
2372 %<*ja>
2373 \subsection{禁則処理関連パラメータとOpenTypeのfont feature}
2374 禁則処理や \Param{kanjiskip}, \Param{xkanjiskip} の挿入に関連したパラメータのうち
2375 \begin{quote}
2376  \Param{jaxspmode},~\Param{alxspmode}, \Param{prebreakpenalty},
2377  \Param{postbreakpenalty}, \Param{kcatcode}
2378 \end{quote}
2379 は,文字コードごとに設定する量である.
2380
2381 \Pkg{fontspec}パッケージを使う(\ref{ssec:fontspec}節)場合など,
2382 各種のOpenType featureを適用することもあると思うが,前段落に述べたパラメータ類は,
2383 \emph{OpenType featureの適用前の文字コードによって適用される.}
2384 例えば,以下の例において10行目の「ア」は,\verb+hwid+ featureの適用により半角カタカナの「ア」
2385 に置き換わる.しかし,その直後に挿入される \Param{postbreakpenalty}は,置換前の「ア」に対する値10である.
2386 %</ja>
2387
2388 \begin{LTXexample}[width=0.2\textwidth]
2389 \ltjsetparameter{postbreakpenalty={`ア, 10}}
2390 \ltjsetparameter{postbreakpenalty={`ア, 20}}
2391
2392 \newcommand\showpostpena[1]{%
2393   \leavevmode\setbox0=\hbox{#1\hbox{}}%
2394   \unhbox0\setbox0=\lastbox\the\lastpenalty}
2395
2396 \showpostpena{ア},
2397 \showpostpena{ア},
2398 {\addjfontfeatures{CharacterWidth=Half}\showpostpena{ア}}
2399 \end{LTXexample}
2400
2401 \clearpage
2402 %<en>\part{Reference}
2403 %<ja>\part{リファレンス}
2404 \label{part-ref}
2405 \suppressfloats[t]
2406 %<*ja>
2407 \section{\LuaTeX-jaにおける \cs{catcode}}
2408 \label{sec-catcode}
2409 \subsection{予備知識:\pTeX と\upTeX における \cs{kcatcode}}
2410 \pTeX,\upTeX においては,和文文字が制御綴内で利用できるかどうか
2411 は \cs{kcatcode} の値によって決定されるのであった.
2412 詳細は\autoref{tab:kcat}を参照されたい.
2413 %</ja>
2414 %<*en>
2415 \section{\cs{catcode} in \LuaTeX-ja}
2416 \label{sec-catcode}
2417 \subsection{Preliminaries: \cs{kcatcode} in \pTeX\ and \upTeX}
2418 In \pTeX~and~\upTeX, the value of \cs{kcatcode} determines
2419 whether a Japanese character can be used in a control word.
2420 For the detail, see \autoref{tab:kcat}.
2421 %</en>
2422
2423 \begin{table}[t]
2424 \small
2425 \caption{\cs{kcatcode} in \upTeX}
2426 \label{tab:kcat}
2427 %<en>\medskip
2428
2429 \noindent\hfill
2430 \begin{tabular}{ccccc}
2431 \toprule
2432 \bfseries \cs{kcatcode}&
2433 %<*en>
2434 \bfseries meaning&
2435 \bfseries control word&
2436 \bfseries widow penalty&
2437 \bfseries linebreak\\
2438 %</en>
2439 %<*ja>
2440 \bfseries 意図&
2441 \bfseries 制御綴中に使用&
2442 \bfseries 文字ウィドウ処理&
2443 \bfseries 直後での改行\\
2444 %</ja>
2445 \midrule
2446 15&non-cjk&\multicolumn{3}{c}{(treated as usual \LaTeX)}\\
2447 16&kanji&Y&Y&ignored\\
2448 17&kana&Y&Y&ignored\\
2449 18&other&N&N&ignored\\
2450 19&hangul&Y&Y&space\\
2451 \bottomrule
2452 \end{tabular}\hfill\null
2453
2454 \medskip
2455
2456 %<*ja>
2457 文字ウィドウ処理:「漢字が一文字だけ次の行に行くのを防ぐ」
2458 \cs{jcharwidowpenalty} が,
2459 その文字の直前に挿入されうるか否か,を示す.
2460 %</ja>
2461 \end{table}
2462
2463 %<*en>
2464 \cs{kcatcode} can be set by a row of JIS~X~0208 in \pTeX,
2465 and generally by a Unicode block\footnote{%
2466   \upTeX\ divides \texttt{U+FF00}--\texttt{U+FFEF} (Halfwidth and Fullwidth Forms)
2467   into three subblocks, and \cs{kcatcode} can be set by a subblock.
2468 }
2469 in \upTeX. So characters which can be used in a control word
2470 slightly differ between \pTeX~and~\upTeX.
2471 %</en>
2472 %<*ja>
2473 \pTeX では \cs{kcatcode} はJIS~X~0208の区単位,
2474 \upTeX では概ねUnicodeブロック単位\footnote{%
2475   \texttt{U+FF00}--\texttt{U+FFEF} (Halfwidth and Fullwidth Forms)は
2476   「全角英数字」「半角カナ」「その他」と3つに分割されており,
2477   それぞれ別々に \cs{kcatcode} が指定できるようになっている.
2478 }で設定可能になっている.そのため,\pTeX と\upTeX の初期状態では
2479 制御綴内で使用可能な文字が微妙に異なっている.
2480 %</ja>
2481
2482 %<*en>
2483 \subsection{Case of \LuaTeX-ja}
2484 The role of \cs{kcatcode} in \pTeX~and~\upTeX\ can be
2485 divided into the following four kinds,
2486 and \LuaTeX-ja can control these four kinds separately:
2487 \begin{itemize}
2488  \item
2489 \emph{Distinction between \textbf{JAchar} or \textbf{ALchar}}
2490 is controlled by the character range, see Subsection~\ref{ssec:setrange}.
2491  \item
2492 \emph{Whether the character can be used in a control word}
2493 is controlled by setting \cs{catcode} to 11~(enabled) or 12~(disabled), as usual.
2494  \item
2495 \emph{Whether \Param{jcharwidowpenalty} can be inserted before the character}
2496 is controlled by the lowermost bit of the \Param{kcatcode} parameter.
2497  \item
2498 \emph{Linebreak after a \textbf{JAchar}} does not produce a space.
2499 \end{itemize}
2500 %</en>
2501 %<*ja>
2502 \subsection{\LuaTeX-jaの場合}
2503 \LuaTeX-jaでは,従来の\pTeX・\upTeX における \cs{kcatcode} の役割を
2504 分割している:
2505 \begin{description}
2506  \item[欧文/和文の区別 (\upTeX)]
2507 \cs{ltjdefcharrange} と\textsf{jacharrange}パラメータ(\ref{ssec:setrange}節)
2508  \item[制御綴中に使用可か]
2509 \LuaTeX 自身の \cs{catcode} でよい
2510  \item[\Param{jcharwidowpenalty}が挿入可か]
2511 \Param{kcatcode}パラメータの最下位ビット
2512  \item[直後の改行]
2513 日本語しか想定していないので,\textbf{JAchar}直後の改行で半角スペースが挿入されることはない.
2514 \end{description}
2515 %</ja>
2516
2517 %<*en>
2518 Default setting of \cs{catcode} of Unicode characters are located in
2519 \begin{description}
2520  \item[plain \LuaTeX] \texttt{luatex-unicode-letters.tex}, which is based on \texttt{unicode-letters.tex}
2521 (for \XeTeX).
2522  \item[\LuaLaTeX] now included in \LaTeX\ kernel  as~\texttt{unicode-letters.def}.
2523 \end{description}
2524 However, the default setting of \cs{catcode} differs
2525 between \XeTeX\ and \LuaTeX, by the following reasons:
2526 \begin{itemize}
2527  \item (plain format) \texttt{luatex-unicode-letters.tex} is based on old \texttt{unicode-letters.tex}.
2528  \item The latter half of \texttt{unicode-letters.tex}~and~\texttt{unicode-letters.def}
2529 sets\cs{catcode} of several characters to 11, via setting \cs{XeTeXcharclass}.
2530 However, this latter half does not exist (plain case), or not executed (\LaTeX~case) in \LuaTeX.
2531 \end{itemize}
2532 In other words,
2533 \begin{description}
2534 \item[plain \LuaTeX]
2535 Kanji nor kana characters cannot be used in
2536 a control word, in the default setting of plain \LuaTeX.
2537 \item[\LuaLaTeX]
2538 In recent (2015-10-01 or later) \LuaLaTeX, Kanji and kana characters in a control word is supported (these catcode are 11),
2539 but not fullwidth alphanumerics and several other characters.
2540 \end{description}
2541
2542 This would be inconvenient for \pTeX~users to shifting to \LuaTeX-ja,
2543 since several control words containing Kanji or other fullwidth characters, such as
2544 \verb+\西暦+~or~\verb+\1年目西暦+ are used in \pTeX.
2545 Hence, \LuaTeX-ja have a counterpart of \texttt{unicode-letters.tex}
2546 for \LuaTeX, \emph{to match the \cs{catcode} setting with that of \XeTeX.}
2547 %</en>
2548 %<*ja>
2549 ネイティブにUnicode全部の文字を扱える\XeTeX や\LuaTeX では,
2550 文字が制御綴内で使用できるかは通常の欧文文字と同じく\cs{catcode}%
2551 で指定することとなる.plain \XeTeX における\cs{catcode}の初期設定は%
2552 \texttt{unicode-letters.tex}中に記述されており,plain \LuaTeX ではそれを
2553 元にした\texttt{luatex-unicode-letters.tex}を用いている.
2554 \LaTeX では\cs{catcode}の設定はカーネルに\texttt{unicode-letters.def}として統合され.
2555 このファイルを\XeLaTeX, \LuaLaTeX の両方が用いている.
2556
2557 だが,\XeTeX における\cs{catcode}の初期設定と
2558 \LuaTeX におけるそれは一致していない:
2559 \begin{itemize}
2560  \item \texttt{luatex-unicode-letters.tex} の元になった
2561   \texttt{unicode-letters.tex}が古い
2562  \item \texttt{unicode-letters.tex} 後半部や\texttt{unicode-letters.def}後半部では
2563 \cs{XeTeXcharclass}の設定を行なっており,
2564 それによって漢字や仮名,および全角英数字の\cs{catcode}が11に設定されている.
2565 しかし,\texttt{luatex-unicode-letters.tex}ではこの「後半部」が
2566 まるごと省略されており,また\LuaLaTeX でも\texttt{unicode-letters.def}後半部は実行されな
2567        い.
2568 \end{itemize}
2569 言い換えると,
2570 \begin{description}
2571  \item[plain \LuaTeX]  漢字や仮名を制御綴内に
2572 使用することはできない.
2573  \item[\LuaLaTeX] 最近の(2015-10-01以降の)
2574 \LuaLaTeX では漢字や仮名を制御綴内に
2575 使用することが可能になったが,全角英数字は相変わらず使用できない,
2576 \end{description}
2577 これでは\pTeX で使用できた\verb+\1年目西暦+\footnote{科研費\LaTeX で使用されているそうです.}などが使えないこととなり,
2578 \LuaTeX-jaへの移行で手間が生じる.そのため,\LuaTeX-jaでは
2579 \texttt{unicode-letters.tex}の後半部にあたる内容を自前でパッチし,
2580 結果として\emph{\XeTeX における初期設定と同じになるようにしている.}
2581 %</ja>
2582
2583 \begin{table}
2584  \centering\small
2585 %<en>\caption{Difference of the set of non-kanji JIS~X~0208 characters which can be used in a control word}
2586 %<ja>\caption{制御綴中に使用出来るJIS~X~0208非漢字の違い}
2587 %<en>\medskip
2588 \label{tab:kcat-diff}
2589 \def\D#1#2#3#4{%
2590   {\fboxsep0pt\fcolorbox{cyan}{white}%
2591   {\large\char"#1#2#3#4}}\ (\texttt{U+#1#2#3#4})} %"
2592 \leavevmode\hbox to 0pt{\hss\begin{tabular}{cccccc}
2593 \toprule
2594 %<en>&\bf row&\bf col.&\bf \pTeX&\bf \upTeX&\bf\LuaTeX-ja\\
2595 %<ja>&\bf 区&\bf 点&\bf \pTeX&\bf \upTeX&\fontseries{b}\selectfont\LuaTeX-ja\\
2596 \midrule
2597 %\D 3000&1&1&N&N&Y\\
2598 \D 30FB&1&6&N&Y&N\\
2599 \D 309B&1&11&N&Y&N\\
2600 \D 309C&1&12&N&Y&N\\
2601 \D FF40&1&14&N&N&Y\\
2602 \D FF3E&1&16&N&N&Y\\
2603 \D FFE3&1&17&N&N&Y\\
2604 \D FF3F&1&18&N&N&Y\\
2605 %\D 30FD&1&19&N&Y&Y\\
2606 %\D 30FE&1&20&N&Y&Y\\
2607 %\D 309D&1&21&N&Y&Y\\
2608 %\D 309E&1&22&N&Y&Y\\
2609 \D 3003&1&23&N&N&Y\\
2610 \D 4EDD&1&24&N&Y&Y\\
2611 \D 3005&1&25&N&N&Y\\
2612 \D 3006&1&26&N&N&Y\\
2613 \D 3007&1&27&N&N&Y\\
2614 \D 30FC&1&28&N&Y&Y\\
2615 \D FF0F&1&31&N&N&Y\\
2616 \D FF3C&1&32&N&N&Y\\
2617 \bottomrule
2618 \end{tabular}\qquad
2619 \begin{tabular}{cccccc}
2620 \toprule
2621 %<en>&\bf row&\bf col.&\bf \pTeX&\bf \upTeX&\bf\LuaTeX-ja\\
2622 %<ja>&\bf 区&\bf 点&\bf \pTeX&\bf \upTeX&\fontseries{b}\selectfont\LuaTeX-ja\\
2623 \midrule
2624 \D FF5C&1&35&N&N&Y\\
2625 \D FF0B&1&60&N&N&Y\\
2626 \D FF1D&1&65&N&N&Y\\
2627 \D FF1C&1&67&N&N&Y\\
2628 \D FF1E&1&68&N&N&Y\\
2629 \D FF03&1&84&N&N&Y\\
2630 \D FF06&1&85&N&N&Y\\
2631 \D FF0A&1&86&N&N&Y\\
2632 \D FF20&1&87&N&N&Y\\
2633 \D 3012&2&9&N&N&Y\\
2634 \D 3013&2&14&N&N&Y\\
2635 \D FFE2&2&44&N&N&Y\\
2636 \D 212B&2&82&N&N&Y\\
2637 %<en>\multicolumn{3}{c}{$\vphantom{\D 3000}$\hbox{}Greek letters (row 6)}&Y&N&Y\\
2638 %<en>\multicolumn{3}{c}{$\vphantom{\D 3000}$\hbox{}Cyrillic letters (row 7)}&N&N&Y\\
2639 %<ja>\multicolumn{3}{c}{$\vphantom{\D 3000}$\hbox{}ギリシャ文字(6区)}&Y&N&Y\\
2640 %<ja>\multicolumn{3}{c}{$\vphantom{\D 3000}$\hbox{}キリル文字(7区)}&N&N&Y\\
2641 \bottomrule
2642 \end{tabular}\hss}\par
2643 \end{table}
2644
2645 %<*en>
2646 \subsection{Non-kanji characters in a control word}
2647 Because the engine differ, so non-kanji JIS~X~0208 characters
2648 which can be used in a control word differ in \pTeX, in \upTeX,~and~in \LuaTeX-ja.
2649 \autoref{tab:kcat-diff} shows the difference.
2650 Except for four characters ``・'',~``゛'', ``゜'',~``゠'',
2651 \LuaTeX-ja admits more characters in a control word than \upTeX.
2652
2653 Difference becomes larger, if we consider
2654 non-kanji JIS~X~0213 characters.
2655 For the detail, see \url{https://github.com/h-kitagawa/kct}.
2656 %</en>
2657 %<*ja>
2658 \subsection{制御綴中に使用出来るJIS非漢字の違い}
2659
2660 エンジンが異なるので,\pTeX, \upTeX, \LuaTeX-ja
2661 において制御綴中に使用可能なJIS~X~0208の文字は異なる.
2662 異なっているところだけを載せると,\autoref{tab:kcat-diff}のようになる.
2663 「・」「゛」「゜」「゠」を除けば,\LuaTeX-jaでは\upTeX より多くの文字が
2664 制御綴に使用可能になっている.
2665
2666 JIS~X~0213の範囲に広げると,差異はさらに大きくなる.
2667 詳細については例えば \url{https://github.com/h-kitagawa/kct} 中の\
2668 \texttt{kct-out.pdf} などを参照すること.
2669 %</ja>
2670
2671
2672 %<*en>
2673 \section{Directions}
2674 \LuaTeX\ supports four $\Omega$-style directions: \texttt{TLT},~\texttt{TRT}, \texttt{RTT}
2675 and \texttt{LTL}.
2676 However, neither directions are not well-suited for typesetting Japanese vertically, hence we
2677 implemented vertical writing by rotating \texttt{TLT}-box by 90~degrees.
2678 %</en>
2679 %<*ja>
2680 \section{縦組}
2681 \label{sec-direction}
2682 \LuaTeX 本体でも,$\Omega$・$\aleph$由来の機能として,複数の組方向をサポートしている.
2683 しかし,\LuaTeX がサポートするのは \texttt{TLT},~\texttt{TRT}, \texttt{RTT},~\texttt{LTL}\
2684 のみであり,日本語の縦組に使うのは望ましくない\footnote{%
2685 和文文字だけならば \texttt{RTT} を使えばなんとかなると思うが,
2686 欧文文字が入ってきた場合はうまくいかず,\texttt{RTR} という組方向が必要になる.
2687 }.そのため,\LuaTeX-jaでは横組(\texttt{TLT})で組んだボックスを回転させる方式で
2688 縦組を実装した.
2689 %</ja>
2690
2691 %<ja>\subsection{サポートする組方向}
2692 \begin{table}[t]
2693 %<ja>\caption{\LuaTeX-ja のサポートする組方向}
2694 %<en>\caption{Directions supported by \LuaTeX-ja}
2695 %<en>\medskip
2696 \label{tab-dir}
2697 \centering\small
2698 \def\obox#1{%
2699   \setbox0=\hbox{\yoko\hbox{#1%
2700   \large\ltjsetparameter{talbaselineshift=0pt}%
2701   \vrule height 25pt width 0.4pt depth 15pt\kern-.2pt%
2702   \raise25pt\hbox to 0pt{\hss\composite{*r^@{>>}}\hss}%
2703   \raise-15pt\hbox to 0pt{\hss\composite{*l^@{>|}}\hss}\kern.2pt%
2704   \vrule height.2pt depth.2pt width 60pt\hbox to 0pt{\hss\composite{*d^@{>}}\hss}\kern-60pt
2705   \hbox to 60pt{\,銀は、Ag\hss}}}%
2706   \raise\dimexpr 0.5\ltjgetdp0-0.5\ltjgetht0\box0%
2707 }
2708 %<*ja>
2709 \begin{tabular}{>{\bfseries}lcccc}
2710 \toprule
2711 &横組&縦組 &「dtou方向」&「utod方向」\\
2712 \midrule
2713 命令&\cs{yoko}&\cs{tate}&\cs{dtou}&\cs{utod}\\
2714 字送り方向&水平右向き(→)&垂直下向き(↓)&垂直上向き(↑)&垂直下向き(↓)\\
2715 行送り方向&垂直下向き(↓)&水平左向き(←)&水平右向き(→)&水平左向き(←)\\
2716 使用する和文フォント&横組用(\cs{jfont})&縦組用(\cs{tfont})&
2717 \multicolumn{2}{c}{%
2718   横組用(\cs{jfont})の$90^\circ$回転}\\[\smallskipamount]
2719 組版例\null $^*$ &\obox{\yoko}&\obox{\tate}&\obox{\dtou}&\obox{\utod}\\
2720 \noalign{\medskip}
2721 \bottomrule
2722 \end{tabular}
2723
2724 \medskip\raggedright
2725 \def\R#1{%
2726   \raise0.38\zw\hbox{%
2727     \vrule height.2pt  depth.2pt width2\zw%
2728     \hbox to 0pt{\hss\composite{*d^@{#1}}\hss}%
2729   }%
2730 }
2731 $^*$\ 幅(width),高さ(height),深さ(depth)の増加方向を,
2732 それぞれ「\R{>}」,「\R{>>}」,「\R{>|}」で表している.
2733 \raggedright
2734 %</ja>
2735
2736 %<*en>
2737 \begin{tabular}{>{\bfseries}lcccc}
2738 \toprule
2739 &horizontal (\emph{yoko}~direction)&vertical (\emph{tate}~direction)&%
2740   \emph{dtou} direction&\emph{utod} direction\\
2741 \midrule
2742 Commands&\cs{yoko}&\cs{tate}&\cs{dtou}&\cs{utod}\\
2743 Beginning of the page&Top&Right&Left&Right\\
2744 Beginning of the line&Left&Top&Bottom&Top\\
2745 Used Japanese font&horizontal (\cs{jfont})&vertical (\cs{tfont})&
2746 \multicolumn{2}{c}{%
2747   horizontal ($90^\circ$ rotated)}\\[\smallskipamount]
2748 Example&\obox{\yoko}&\obox{\tate}&\obox{\dtou}&\obox{\utod}\\
2749 \noalign{\medskip}
2750 (Notation used in $\Omega$)&TLT&RTR, RTT&LBL&RTR\\
2751 \bottomrule
2752 \end{tabular}
2753
2754 \medskip\raggedright
2755 \def\R#1{%
2756   \raise0.38\zw\hbox{%
2757     \vrule height.2pt  depth.2pt width2\zw%
2758     \hbox to 0pt{\hss\composite{*d^@{#1}}\hss}%
2759   }%
2760 }
2761 \raggedright
2762 %</en>
2763 \end{table}
2764
2765 %<*en>
2766 \LuaTeX-ja supports four directions, as shown in \autoref{tab-dir}.
2767 The second column (\emph{yoko} direction) is just horizontal writing,
2768 and the third column (\emph{tate} direction) is vertical writing.
2769 The fourth column (\emph{dtou} direction) is actually a hidden feature of \pTeX.
2770 We implemented this for debugging purpose.
2771 The fifth column (\emph{utod} direction) corresponds the ``\texttt{tate (math) direction}'' of \pTeX.
2772
2773 Directions can be changed by \cs{yoko},~\cs{tate}, \cs{dtou},~\cs{utod},
2774 only when the current list is null.
2775 These commands cannot be executed in unrestricted horizontal modes, nor math modes.
2776 The direction of a math formula is changed to
2777 \emph{utod}, when the direction outside the math formula is \emph{tate} (vertical writing).
2778 %</en>
2779
2780 %<*ja>
2781 \LuaTeX-jaがサポートする組方向は\autoref{tab-dir}に示す4つである.
2782 4列目の \cs{dtou} は聞き慣れない命令だと思うが,
2783 実は\pTeX に同名の命令が(ドキュメントには書かれていないが)存在する.
2784 Down-TO-Upの意味なのだろう.\cs{dtou} を使用する機会はないだろうが,
2785 \LuaTeX-jaではデバッグ用に実装している.
2786 5列目の \cs{utod} は,\pTeX で言う「縦数式ディレクション」に相当するものである.
2787
2788 組方向は,\cs{yoko},~\cs{tate}, \cs{dtou},~\cs{utod} をそれぞれ使用することで,
2789 現在作成中のリストやボックスが空の時にのみ変更可能である.
2790 ただし,現在のモードが非制限水平モードや(文中,別行立て問わず)数式モードであるときには
2791 組方向を変更することは出来ない.
2792 また,縦組中の数式内のボックスは\pTeX と同じように組方向が \cs{utod} となる.
2793 %</ja>
2794
2795 %<*en>
2796 \subsection{Boxes in different direction}
2797
2798 As in \pTeX, one can use boxes of different direction in one document.
2799 The below is an example.
2800 \begin{LTXexample}
2801 ここは横組%     yoko
2802 \hbox{\tate %   tate
2803   \hbox{縦組}%  tate
2804   の中に
2805   \hbox{\yoko 横組の内容}% yoko
2806   を挿入する
2807 }
2808 また横組に戻る% yoko
2809 \end{LTXexample}
2810
2811 \autoref{tab-diffdir} shows how a box is arranged when
2812 the direction  inside the box and that outside the box differ.
2813 %</en>
2814 %<*ja>
2815 \subsection{異方向のボックス}
2816
2817 縦組の中に「42」などの2桁以上の算用数字を横組で組むなど,
2818 異なる組方向を混在させることがしばしば行われる.
2819 組方向の混在も\pTeX と同じようにできる:
2820 \begin{LTXexample}
2821 ここは横組%     yoko
2822 \hbox{\tate %   tate
2823   \hbox{縦組}%  tate
2824   の中に
2825   \hbox{\yoko 横組の内容}% yoko
2826   を挿入する
2827 }
2828 また横組に戻る% yoko
2829 \end{LTXexample}
2830
2831 異なる組方向のボックスを配置した場合にどう組まれるかの仕様も,\pTeX を
2832 踏襲している.\autoref{tab-diffdir}に示す.
2833 %</ja>
2834
2835 \begin{table}[t]
2836 %<ja>\caption{異方向のボックスの配置}
2837 %<en>\caption{Boxes in different direction}
2838 %<en>\medskip
2839 \label{tab-diffdir}
2840  \centering\small\unitlength3mm
2841  \def\TATEeg{%
2842    \hbox{\smash{\begin{picture}(0,0)(-2,0)
2843      \thicklines
2844      \polyline(-2,0)(-2,-7)(5,-7)(5,0)
2845      \put(0,0){\circle*{0.3}}
2846      \put(2.5,-4){\makebox(0,0){\hbox{\tate\bfseries \emph{tate}/\emph{utod}}}}
2847      \put(0,0){\vector(1,0){5}} \put(2.5,-0.2){\makebox(0,0)[t]{$h_{\mathrm{T}}$}}
2848      \put(0,0){\vector(-1,0){2}}\put(-1,-0.2){\makebox(0,0)[t]{$d_{\mathrm{T}}$}}
2849      \put(0,0){\vector(0,-1){7}}\put(0.2,-3.5){\makebox(0,0)[l]{$w_{\mathrm{T}}$}}
2850    \end{picture}}}%
2851  }
2852  \def\DTOUeg{%
2853    \hbox{\smash{\begin{picture}(0,0)(-5,0)
2854      \thicklines
2855      \polyline(-5,0)(-5,7)(2,7)(2,0)
2856      \put(0,0){\circle*{0.3}}
2857      \put(-2.5,4){\makebox(0,0){\hbox{\dtou\bfseries \emph{dtou}}}}
2858      \put(0,0){\vector(-1,0){5}} \put(-2.5,0.3){\makebox(0,0)[b]{$h_{\mathrm{D}}$}}
2859      \put(0,0){\vector(1,0){2}}\put(1,0.3){\makebox(0,0)[b]{$d_{\mathrm{D}}$}}
2860      \put(0,0){\vector(0,1){7}}\put(-0.2,3.5){\makebox(0,0)[r]{$w_{\mathrm{D}}$}}
2861    \end{picture}}}%
2862  }
2863  \def\YOKOeg{%
2864    \hbox{\smash{\begin{picture}(0,0)
2865      \thicklines
2866      \polyline(0,5)(7,5)(7,-2)(0,-2)
2867      \put(4,2.5){\makebox(0,0){\hbox{\yoko\bfseries \emph{yoko}}}}
2868      \put(0,0){\circle*{0.3}}
2869      \put(0,0){\vector(0,1){5}} \put(0.3,2.5){\makebox(0,0)[l]{$h_{\mathrm{Y}}$}}
2870      \put(0,0){\vector(0,-1){2}}\put(0.3,-1){\makebox(0,0)[l]{$d_{\mathrm{Y}}$}}
2871      \put(0,0){\vector(1,0){7}}\put(3.5,0.2){\makebox(0,0)[b]{$w_{\mathrm{Y}}$}}
2872    \end{picture}}}%
2873  }
2874 \begin{tabular}{ccc}
2875 \toprule
2876 %<ja>\emph{横組中に配置}&\emph{縦組中に配置}&%
2877 %<ja>\emph{組方向 \cs{dtou} 中に配置}\\
2878 %<en>\textbf{typeset in \emph{yoko} direction}
2879 %<en>&\textbf{typeset in \emph{tate} or \emph{utod} direction}
2880 %<en>&\textbf{typeset in \emph{dtou} direction}\\
2881 \midrule
2882  \parbox[c]{15\unitlength}{\begin{picture}(15,15)(0,-4)
2883    \put(0,0){\line(1,0){3.8}}
2884    \put(4,7){\TATEeg}
2885    \put(11.2,0){\line(1,0){3.8}}
2886 %
2887    \put(2,7){\line(1,0){1.8}}
2888    \put(3,3.5){\vector(0,1){3.5}\vector(0,-1){3.5}}
2889    \put(2.8,3.5){\makebox(0,0)[r]{$H_{\mathrm{Y}}$}}
2890    \put(3,-2){\vector(0,1){2}}
2891    \put(2.8,-1){\makebox(0,0)[r]{$D_{\mathrm{Y}}$}}
2892 %
2893    \put(4,7.2){\line(0,1){1.8}}
2894    \put(11,7.2){\line(0,1){1.8}}
2895    \put(6,8){\vector(-1,0){2}}
2896    \put(9,8){\vector(1,0){2}}
2897    \put(7.5,8){\makebox(0,0){$W_{\mathrm{Y}}$}}
2898 %
2899  \end{picture}\vspace{-\baselineskip}
2900    \begin{align*}
2901    W_{\mathrm{Y}} &= h_{\mathrm{T}}+d_{\mathrm{T}},\\
2902    H_{\mathrm{Y}} &= w_{\mathrm{T}},\\
2903    D_{\mathrm{Y}} &=0\,\mathrm{pt}
2904    \end{align*}%
2905  }&
2906  \parbox[c]{15\unitlength}{\begin{picture}(15,15)(0,-4)
2907    \put(7.5,-0.2){\line(0,-1){2.8}}
2908    \put(4,2){\YOKOeg}
2909    \put(7.5, 7.2){\line(0,1){3.8}}
2910 %
2911    \put(2,7){\line(1,0){1.8}}
2912    \put(2,0){\line(1,0){1.8}}
2913    \put(3,5){\vector(0,1){2}}
2914    \put(3,2){\vector(0,-1){2}}
2915    \put(3,3.5){\makebox(0,0){$W_{\mathrm{T}}$}}
2916 %
2917    \put(4,7.2){\line(0,1){1.8}}
2918    \put(11,7.2){\line(0,1){1.8}}
2919    \put(8,8){\vector(-1,0){0.5}\vector(1,0){3}}
2920    \put(7,8){\vector(-1,0){3}\vector(1,0){0.5}}
2921    \put(9.25,8.2){\makebox(0,0)[b]{$H_{\mathrm{T}}$}}
2922    \put(5.75,8.2){\makebox(0,0)[b]{$D_{\mathrm{T}}$}}
2923 %
2924  \end{picture}\vspace{-\baselineskip}
2925    \begin{align*}
2926    W_{\mathrm{T}} &= h_{\mathrm{Y}}+d_{\mathrm{Y}},\\
2927    H_{\mathrm{T}} &= w_{\mathrm{Y}}/2,\\
2928    D_{\mathrm{T}} &= w_{\mathrm{Y}}/2
2929    \end{align*}%
2930  }&
2931  \parbox[c]{15\unitlength}{\begin{picture}(15,15)(0,-4)
2932    \put(11,-0.2){\line(0,-1){2.8}}
2933    \put(4,2){\YOKOeg}
2934    \put(11, 7.2){\line(0,1){3.8}}
2935 %
2936    \put(2,7){\line(1,0){1.8}}
2937    \put(2,0){\line(1,0){1.8}}
2938    \put(3,5){\vector(0,1){2}}
2939    \put(3,2){\vector(0,-1){2}}
2940    \put(3,3.5){\makebox(0,0){$W_{\mathrm{D}}$}}
2941 %
2942    \put(4,7.2){\line(0,1){1.8}}
2943    \put(11,7.2){\line(0,1){1.8}}
2944    \put(7.5,8){\vector(-1,0){3.5}\vector(1,0){3.5}}
2945    \put(13,8){\vector(-1,0){2}}
2946    \put(7.5,8.2){\makebox(0,0)[b]{$H_{\mathrm{D}}$}}
2947    \put(12,8.2){\makebox(0,0)[b]{$D_{\mathrm{D}}$}}
2948 %
2949  \end{picture}\vspace{-\baselineskip}
2950    \begin{align*}
2951    W_{\mathrm{D}} &= h_{\mathrm{Y}}+d_{\mathrm{Y}},\\
2952    H_{\mathrm{D}} &= w_{\mathrm{Y}},\\
2953    D_{\mathrm{D}} &= 0\,\mathrm{pt}
2954    \end{align*}%
2955  }%
2956 \\\midrule
2957  \parbox[c]{15\unitlength}{\begin{picture}(15,15)(0,-4)
2958    \put(0,0){\line(1,0){3.8}}
2959    \put(4,0){\DTOUeg}
2960    \put(11.2,0){\line(1,0){3.8}}
2961 %
2962    \put(2,7){\line(1,0){1.8}}
2963    \put(3,3.5){\vector(0,1){3.5}\vector(0,-1){3.5}}
2964    \put(2.8,3.5){\makebox(0,0)[r]{$H_{\mathrm{Y}}$}}
2965    \put(3,-2){\vector(0,1){2}}
2966    \put(2.8,-1){\makebox(0,0)[r]{$D_{\mathrm{Y}}$}}
2967 %
2968    \put(4,7.2){\line(0,1){1.8}}
2969    \put(11,7.2){\line(0,1){1.8}}
2970    \put(6,8){\vector(-1,0){2}}
2971    \put(9,8){\vector(1,0){2}}
2972    \put(7.5,8){\makebox(0,0){$W_{\mathrm{Y}}$}}
2973 %
2974  \end{picture}\vspace{-\baselineskip}
2975    \begin{align*}
2976    W_{\mathrm{Y}} &= h_{\mathrm{D}}+d_{\mathrm{D}},\\
2977    H_{\mathrm{Y}} &= w_{\mathrm{D}},\\
2978    D_{\mathrm{Y}} &= 0\,\mathrm{pt}
2979    \end{align*}%
2980  }&
2981  \parbox[c]{15\unitlength}{\begin{picture}(15,15)(0,-4)
2982    \put(9,-0.2){\line(0,-1){2.8}}
2983    \put(4,0){\DTOUeg}
2984    \put(9, 7.2){\line(0,1){3.8}}
2985 %
2986    \put(2,7){\line(1,0){1.8}}
2987    \put(2,0){\line(1,0){1.8}}
2988    \put(3,5){\vector(0,1){2}}
2989    \put(3,2){\vector(0,-1){2}}
2990    \put(3,3.5){\makebox(0,0){$W_{\mathrm{T}}$}}
2991 %
2992    \put(4,7.2){\line(0,1){1.8}}
2993    \put(11,7.2){\line(0,1){1.8}}
2994    \put(6.5,8){\vector(-1,0){2.5}\vector(1,0){2.5}}
2995    \put(10,8){\vector(-1,0){1}\vector(1,0){1}}
2996    \put(10,8.2){\makebox(0,0)[b]{$H_{\mathrm{T}}$}}
2997    \put(6.5,8.2){\makebox(0,0)[b]{$D_{\mathrm{T}}$}}
2998 %
2999  \end{picture}\vspace{-\baselineskip}
3000    \begin{align*}
3001    W_{\mathrm{T}} &= h_{\mathrm{D}}+d_{\mathrm{D}},\\
3002    H_{\mathrm{T}} &= d_{\mathrm{D}},\\
3003    D_{\mathrm{T}} &= h_{\mathrm{D}}
3004    \end{align*}%
3005  }&
3006  \parbox[c]{15\unitlength}{\begin{picture}(15,15)(0,-4)
3007    \put(6,-0.2){\line(0,-1){2.8}}
3008    \put(4,7){\TATEeg}
3009    \put(6, 7.2){\line(0,1){3.8}}
3010 %
3011    \put(2,7){\line(1,0){1.8}}
3012    \put(2,0){\line(1,0){1.8}}
3013    \put(3,5){\vector(0,1){2}}
3014    \put(3,2){\vector(0,-1){2}}
3015    \put(3,3.5){\makebox(0,0){$W_{\mathrm{D}}$}}
3016 %
3017    \put(4,7.2){\line(0,1){1.8}}
3018    \put(11,7.2){\line(0,1){1.8}}
3019    \put(5,8){\vector(-1,0){1}\vector(1,0){1}}
3020    \put(8.5,8){\vector(-1,0){2.5}\vector(1,0){2.5}}
3021    \put(5,8.2){\makebox(0,0)[b]{$H_{\mathrm{D}}$}}
3022    \put(8.5,8.2){\makebox(0,0)[b]{$D_{\mathrm{D}}$}}
3023 %
3024  \end{picture}\vspace{-\baselineskip}
3025    \begin{align*}
3026    W_{\mathrm{D}} &= w_{\mathrm{T}},\\
3027    H_{\mathrm{D}} &= d_{\mathrm{T}},\\
3028    D_{\mathrm{D}} &= h_{\mathrm{T}}
3029    \end{align*}%
3030  }\\
3031 \bottomrule
3032 \end{tabular}
3033 \end{table}
3034
3035
3036
3037 %<*en>
3038 \paragraph{\cs{wd} and direction}
3039 In \pTeX, \cs{wd},~\cs{ht},~\cs{dp} means the dimensions of a box register
3040 \emph{with respact to the current direction}.
3041 This means that the value of \cs{wd0} etc.\ might differ when the current direction is
3042 different, even if \cs{box0} stores the same box.
3043 However, this no longer applies in \LuaTeX-ja.
3044
3045 \begin{LTXexample}
3046 % yoko direction
3047 \setbox0=\hbox to 20pt{foo}
3048 \the\wd0,~\hbox{\tate\vrule\the\wd0}
3049 \wd0=100pt
3050 \the\wd0,~\hbox{\tate \the\wd0}
3051 \end{LTXexample}
3052
3053 To access box dimensions \emph{with respect to current direction},
3054 one have to use the following commands instead of \cs{wd} wtc.
3055 \begin{cslist}
3056
3057  \item[\cs{ltjgetwd}<num>\textrm{, }\cs{ltjgetht}<num>\textrm{, }%
3058   \cs{ltjgetdp}<num>]
3059 These commands return \emph{an internal dimension} of \cs{box<num>} with respect to
3060 the current direction. One can use these in \cs{dimexpr} primitive, as the followings.
3061 \begin{lstlisting}
3062 \dimexpr 2\ltjgetwd42-3pt\relax, \the\ltjgetwd1701
3063 \end{lstlisting}
3064 The following is an example.
3065 \begin{LTXexample}[width=0.3\textwidth]
3066 \parindent0pt
3067 \setbox32767=\hbox{\yoko よこぐみ}
3068 \fboxsep=0mm\fbox{\copy32767}
3069 \vbox{\hsize=20mm
3070 \yoko YOKO \the\ltjgetwd32767, \\
3071   \the\ltjgetht32767, \\ \the\ltjgetdp32767.}
3072 \vbox{\hsize=20mm\raggedleft
3073 \tate TATE \the\ltjgetwd32767, \\
3074   \the\ltjgetht32767, \\ \the\ltjgetdp32767.}
3075 \vbox{\hsize=20mm\raggedleft
3076 \dtou DTOU \the\ltjgetwd32767, \\
3077   \the\ltjgetht32767, \\ \the\ltjgetdp32767.}
3078 \end{LTXexample}
3079
3080  \item[\cs{ltjsetwd}<num>=<dimen>\textrm{, }\cs{ltjsetht}<num>=<dimen>\textrm{, }%
3081   \cs{ltjsetdp}<num>=<dimen>]
3082 These commands set the dimension of \cs{box<num>}. One does not need
3083         to group the argument <num>; four calls of \cs{ltjsetwd} below have the same meaning.
3084 \begin{lstlisting}
3085 \ltjsetwd42 20pt,  \ltjsetwd42=20pt,  \ltjsetwd=42 20pt,  \ltjsetwd=42=20pt
3086 \end{lstlisting}
3087
3088 \end{cslist}
3089 %</en>
3090 %<*ja>
3091 \paragraph{\cs{wd} 達と組方向}
3092 ボックスレジスタ \cs{box}<num> にセットされているボックスの幅・高さ・深さの取得や
3093 変更にはそれぞれ \cs{wd},~\cs{ht},~\cs{dp} プリミティブを用いるのであった.
3094 \pTeX ではこれらのプリミティブは,「現在の組方向におけるボックスの寸法」を指すもので,
3095 同じボックスに対しても現在の組方向によって返る値は異なるもであった.
3096
3097 \LuaTeX-jaにおいては状況が異なり,\cs{wd},~\cs{ht},~\cs{dp} が返す値は
3098 現在の組方向には依存しない.下の例のように,横組のボックスが格納されていれば
3099 \cs{wd}等は常に「横組におけるボックスの寸法」を意味する.
3100
3101 \begin{LTXexample}
3102 % yoko direction
3103 \setbox0=\hbox to 20pt{foo}
3104 \the\wd0,~\hbox{\tate\vrule\the\wd0}
3105 \wd0=100pt
3106 \the\wd0,~\hbox{\tate \the\wd0}
3107 \end{LTXexample}
3108
3109 \pTeX のように現在の組方向に応じたボックスの寸法の取得・設定を行うには,
3110 代わりに次の命令を使用する.
3111
3112 \begin{cslist}
3113
3114  \item[\cs{ltjgetwd}<num>\textrm{, }\cs{ltjgetht}<num>\textrm{, }%
3115   \cs{ltjgetdp}<num>]
3116 現在の組方向に応じたボックスの寸法の取得を行う.結果は内部長さであるため,
3117 \begin{lstlisting}
3118 \dimexpr 2\ltjgetwd42-3pt\relax, \the\ltjgetwd1701
3119 \end{lstlisting}
3120 のように \cs{wd}<num> の代わりとして扱うことができる.
3121 使用例は以下の通りである.
3122 \begin{LTXexample}[width=0.3\textwidth]
3123 \parindent0pt
3124 \setbox32767=\hbox{\yoko よこぐみ}
3125 \fboxsep=0mm\fbox{\copy32767}
3126 \vbox{\hsize=20mm
3127 \yoko YOKO \the\ltjgetwd32767, \\
3128   \the\ltjgetht32767, \\ \the\ltjgetdp32767.}
3129 \vbox{\hsize=20mm\raggedleft
3130 \tate TATE \the\ltjgetwd32767, \\
3131   \the\ltjgetht32767, \\ \the\ltjgetdp32767.}
3132 \vbox{\hsize=20mm\raggedleft
3133 \dtou DTOU \the\ltjgetwd32767, \\
3134   \the\ltjgetht32767, \\ \the\ltjgetdp32767.}
3135 \end{LTXexample}
3136
3137  \item[\cs{ltjsetwd}<num>=<dimen>\textrm{, }\cs{ltjsetht}<num>=<dimen>\textrm{, }%
3138   \cs{ltjsetdp}<num>=<dimen>]
3139 現在の組方向に応じたボックスの寸法の設定を行う.\cs{afterassignment} を2回利用して
3140 実装しているので,次の4通りは全て同じ意味である.
3141 \begin{lstlisting}
3142 \ltjsetwd42 20pt,  \ltjsetwd42=20pt,  \ltjsetwd=42 20pt,  \ltjsetwd=42=20pt
3143 \end{lstlisting}
3144
3145 設定値は「横組」「縦組及びutod方向」「dtou方向」
3146 の3種ごとに独立して記録される.参考として,Gitリポジトリ内の
3147               \verb+test/test55-boxdim_diffdir.{tex,pdf}+ を挙げておく.
3148
3149 \end{cslist}
3150 %</ja>
3151
3152 %<*en>
3153 \subsection{Getting current direction}
3154 The \Param{direction} parameter returns the current direction, and
3155 the \Param{boxdir} parameter (with the argument <num>)
3156 returns the direction of a box register \cs{box}<num>.
3157 The returned value of these parameters are a \emph{string}:
3158 \begin{center}
3159 \small
3160 \begin{tabular}{>{\bfseries}lccccc}
3161 \toprule
3162 Direction&\emph{yoko}&\emph{tate}&\emph{dtou}&\emph{utod}&(empty)\\
3163 \midrule
3164 Returned value&\texttt{4}&\texttt{3}&\texttt{1}&\texttt{11}&\texttt{0}\\
3165 \bottomrule
3166 \end{tabular}
3167 \end{center}
3168 \begin{LTXexample}[width=0.3\textwidth]
3169 \leavevmode\def\DIR{\ltjgetparameter{direction}}
3170 \hbox{\yoko \DIR}, \hbox{\tate\DIR},
3171 \hbox{\dtou\DIR}, \hbox{\utod\DIR},
3172 \hbox{\tate$\hbox{tate math: \DIR}$}
3173
3174 \setbox2=\hbox{\tate}\ltjgetparameter{boxdir}{2}
3175 \end{LTXexample}
3176 %</en>
3177 %<*ja>
3178 \subsection{組方向の取得}
3179 「現在の組方向」や「<num>番のボックスの組方向」は,
3180 \pTeX では \cs{ifydir} や \cs{ifybox}<num> といった条件判断文を使って
3181 判断することができた.
3182 しかし,\LuaTeX-jaはあくまでも\TeX マクロとLuaコードで
3183 記述されており,それでは新たな条件判断命令を作るのは難しい.
3184
3185 \LuaTeX-jaでは,\Param{direction}パラメータで現在の組方向を,
3186 \Param{boxdir}パラメータ(と追加の引数<num>)によって
3187 \cs{box}<num>の組方向をそれぞれ取得できるようにした.
3188 戻り値は文字列である:
3189 \begin{center}
3190 \small
3191 \begin{tabular}{>{\bfseries}lccccc}
3192 \toprule
3193 組方向&\emph{横組}&\emph{tate縦組}&\emph{dtou方向}&\emph{utod方向}&(未割り当て)\\
3194 \midrule
3195 戻り値&\texttt{4}&\texttt{3}&\texttt{1}&\texttt{11}&\texttt{0}\\
3196 \bottomrule
3197 \end{tabular}
3198 \end{center}
3199
3200 \begin{LTXexample}[width=0.3\textwidth]
3201 \leavevmode\def\DIR{\ltjgetparameter{direction}}
3202 \hbox{\yoko\DIR}, \hbox{\tate\DIR},
3203 \hbox{\dtou\DIR}, \hbox{\utod\DIR},
3204 \hbox{\tate$\hbox{tate math: \DIR}$}
3205
3206 \setbox2=\hbox{\tate}\ltjgetparameter{boxdir}{2}
3207 \end{LTXexample}
3208
3209 これらを用いれば,例えば
3210 \pTeX の \cs{ifydir},~\cs{ifybox200} と同等の条件判断を
3211 \begin{lstlisting}
3212 \ifnum\ltjgetparameter{direction}=4
3213 \ifnum\ltjgetparameter{boxdir}{200}=4
3214 \end{lstlisting}
3215 のように行うことができる.
3216 \cs{iftdir} は少々面倒であるが,8で割った余りが3であるか否かを判断すれば良いから
3217 \begin{lstlisting}
3218 \ifnum\numexpr
3219   \ltjgetparameter{direction}-(\ltjgetparameter{direction}/8)*8=3
3220 \end{lstlisting}
3221 とすればよい.
3222 %</ja>
3223
3224 %<*en>
3225 \subsection{Overridden box primitives}
3226 To cope with multiple directions, the following primitives are
3227 overridden by \LuaTeX-ja, using~\verb+\protected\def+.
3228 \begin{cslist}[style=standard]
3229  \item[\cs{unhbox}<num>\textrm{, }\cs{unvbox}<num>\textrm{, }\cs{unhcopy}<num>\textrm{, }\cs{unvcopy}<num>]
3230  \item[\cs{vadjust}\{<material>\}]
3231  \item[\cs{insert}<number>\{<material>\}]
3232  \item[\cs{lastbox}]
3233  \item[\cs{raise}<dimen><box>\textrm{, }\cs{lower}<dimen><box>\textrm{\ etc., }\cs{vcenter}]
3234  \item[\cs{vcenter}]
3235 \end{cslist}
3236 %</en>
3237 %<*ja>
3238 \subsection{プリミティブの再定義}
3239 異なる組方向に対応するために,以下に挙げるプリミティブは
3240 \LuaTeX-jaによる前処理もしくは後処理が行われるように
3241 \ \verb+\protected\def+ により再定義してある.
3242
3243 \begin{cslist}
3244  \item[\cs{unhbox}<num>\textrm{, }\cs{unvbox}<num>\textrm{, }\cs{unhcopy}<num>\textrm{, }\cs{unvcopy}<num>]
3245  ボックスの組方向が現在のリストと異なる場合は事前にエラーメッセージを出力する.
3246  \pTeX と異なり,エラーを無視して無理矢理 \cs{unhbox}, \cs{unvbox} を
3247  続行させることもできるが,その場合の組版結果は保証しない.
3248  \item[\cs{vadjust}\{<material>\}] 一旦プリミティブ本来の挙動を行う.その後,<material>の組方向が
3249  周囲の垂直リストの組方向と一致しない場合にエラーを出力し,
3250  該当の \cs{vadjust} を無効にする.
3251  \item[\cs{insert}<number>\{<material>\}]
3252  一旦プリミティブ本来の挙動を行い,その後<material>内の各ボックス・罫線の直前に組方向を示
3253               すdirection whatsitを挿入する.
3254  \item[\cs{lastbox}] ボックスの「中身」を現在の組方向に合わせるためのノード
3255               (\textit{dir\_box}という)を必要ならば除去し,
3256  正しく「中身」のボックスが返されるように前処理をする.
3257  \item[\cs{raise}<dimen><box>\textrm{, }\cs{lower}<dimen><box>\textrm{\ etc., }\cs{vcenter}]
3258  一方,こちらでは必要に応じて\textit{dir\_box}を作成する前処理を追加している.
3259 \end{cslist}
3260 %</ja>
3261
3262 %<en>\section{Font Metric and Japanese Font}
3263 %<ja>\section{フォントメトリックと和文フォント}
3264 %<en>\subsection{\cs{jfont}}
3265 %<ja>\subsection{\cs{jfont} 命令}
3266 \label{ssec:jfont}
3267
3268 %<*en>
3269 To load a font as a Japanese font (for horizontal direction), you must use the
3270 \cs{jfont} instead of~\cs{font}, while
3271 \cs{jfont} admits the same syntax used in~\cs{font}.
3272 \LuaTeX-ja automatically loads \Pkg{luaotfload} package,
3273 so TrueType/OpenType fonts with features can be used for Japanese fonts:
3274 %</en>
3275 %<*ja>
3276 フォントを(横組用)和文フォントとして読み込むためには,\cs{jfont} を
3277 \ \cs{font} プリミティブの代わりに用いる.
3278 \cs{jfont} の文法は \cs{font} と同じである.
3279 \LuaTeX-jaは\Pkg{luaotfload}パッケージを自動的に読み込むので,
3280 TrueType/OpenTypeフォントにfeatureを指定したものを和文フォントとして用いる
3281 ことができる:
3282 %</ja>
3283 \begin{LTXexample}[width=0.3\textwidth]
3284 \jfont\tradgt={file:KozMinPr6N-Regular.otf:script=latn;%
3285   +trad;-kern;jfm=ujis} at 14pt
3286 \tradgt 当/体/医/区
3287 \end{LTXexample}
3288
3289 %<*en>
3290 Note that the defined control sequence
3291 (\cs{tradgt} in the example above) using \cs{jfont} is not a
3292 \textit{font\_def} token,  but a macro.
3293 Hence the input like \verb+\fontname\tradgt+
3294 causes a error.  We denote control sequences which are defined in
3295 \cs{jfont} by <jfont\_cs>.
3296 %</en>
3297 %<*ja>
3298 なお,\cs{jfont} で定義された制御綴(上の例だと \cs{tradgt})
3299 は\textit{font\_def}トークンではなくマクロである.従って,\verb+\fontname\tradgt+ のような
3300 入力はエラーとなる.以下では \cs{jfont} で定義された
3301 制御綴を<jfont\_cs>で表す.
3302 %</ja>
3303
3304 \paragraph{JFM}
3305 %<*en>
3306 a JFM has measurements of characters and
3307 glues/kerns that are automatically inserted for Japanese
3308 typesetting. The structure of JFM will be described in the next
3309 subsection. At the calling of \cs{jfont}, you must specify
3310 which JFM will be used for this font by the following keys:
3311 %</en>
3312 %<*ja>
3313 JFMは文字と和文組版で自動的に挿入される
3314 グルー/カーンの寸法情報を持っている.JFMの構造は次の節で述べる.
3315 \cs{jfont} 命令の呼び出しの際には,どのJFMを用いるのかを以下のキーで
3316 指定する必要がある:
3317 %</ja>
3318
3319
3320 \begin{table}[t]
3321 %<en>\caption{Differences between horizontal JFMs shipped with \LuaTeX-ja}
3322 %<ja>\caption{\LuaTeX-ja に同梱されている横組用JFMの違い}
3323 %<en>\medskip
3324 \label{tab-difjfm}
3325 \ltjsetparameter{jacharrange={+3}}
3326 \centering\small
3327 \def\r#1#2{%
3328   \hbox{\Large\vrule
3329   \parbox[b]{7\zw}{%
3330     \addjfontfeatures{YokoFeatures={Opacity=0.5, Color=#2, JFM=#1}}\noindent
3331     ◆◆◆◆◆◆◆
3332     ある日モモちゃんがお使いで迷子になって泣きました.
3333   }\vrule}}
3334 \def\s#1#2{%
3335   \Large
3336   \parbox[b]{7\zw}{%
3337     \addjfontfeatures{YokoFeatures={Opacity=0.5, Color=#2, JFM=#1}}\noindent
3338     ちょっと!何
3339   }}
3340 \def\t#1#2#3{\hbox to 0pt{\hss%
3341   \setbox0=\hbox{\addjfontfeatures{YokoFeatures={JFM=#1}}\huge #3}%
3342   \textcolor{#2}{\transparent{0.5}\vrule width 0.4pt height\ht0 depth\dp0}\kern-.2pt\copy0
3343   \textcolor{#2}{\transparent{0.5}\kern-\wd0\vrule width\wd0height .2pt depth .2pt
3344   \kern-\wd0\raise\ht0\hbox{\vrule width\wd0height .2pt depth .2pt}%
3345   \kern-\wd0\lower\dp0\hbox{\vrule width\wd0height .2pt depth .2pt}%
3346   \kern-.2pt\vrule width 0.4pt height\ht0 depth \dp0}\hss}}
3347 {\Large\tabcolsep0pt
3348 \begin{tabular}{m{8\zw}m{8\zw}m{8\zw}}
3349 \leavevmode\hbox to 0pt{\r{ujis}{blue}\hss}\r{jis}{black}&
3350 \leavevmode\hbox to 0pt{\r{jis}{black}\hss}\r{min}{red}&
3351 \leavevmode\hbox to 0pt{\r{ujis}{blue}\hss}\r{min}{red}\\
3352 \leavevmode\hbox to 0pt{\s{ujis}{blue}\hss}\s{jis}{black}&
3353 \leavevmode\hbox to 0pt{\s{jis}{black}\hss}\s{min}{red}&
3354 \leavevmode\hbox to 0pt{\s{ujis}{blue}\hss}\s{min}{red}\\
3355 \leavevmode\qquad\t{ujis}{blue}{漢}\t{jis}{black}{漢}\qquad
3356            \t{ujis}{blue}{っ}\t{jis}{black}{っ}&
3357 \leavevmode\qquad\t{jis}{black}{漢}\t{min}{red}{漢}\qquad
3358            \t{jis}{black}{っ}\t{min}{red}{っ}&
3359 \leavevmode\qquad\t{ujis}{blue}{漢}\t{min}{red}{漢}\qquad
3360            \t{ujis}{blue}{っ}\t{min}{red}{っ}\\
3361 \end{tabular}\par}
3362
3363 (\textcolor{blue}{Blue: \texttt{jfm-ujis.lua}},
3364 \textcolor{black}{Black: \texttt{jfm-jis.lua}},
3365 \textcolor{red}{Red: \texttt{jfm-min.lua}})
3366 \ltjsetparameter{jacharrange={-3}}
3367 \end{table}
3368
3369 \begin{cslist}
3370 \item[jfm=<name>]
3371 %<*en>
3372 Specify the name of (horizontal) JFM.
3373 If specified JFM has not been loaded, \LuaTeX-ja search and load
3374 a file named \texttt{jfm-<name>.lua}.
3375
3376 The following horizontal JFMs are shipped with \LuaTeX-ja:
3377 %</en>
3378 %<*ja>
3379 用いる(横組用)JFMの名前を指定する.もし以前に指定されたJFMが読み込まれていなければ,
3380 \texttt{jfm-<name>.lua}を読み込む.以下の横組用JFMが\LuaTeX-jaには同梱されている:
3381 %</ja>
3382 \begin{description}
3383 %<*en>
3384 \item[\tt jfm-ujis.lua] A standard horizontal JFM in \LuaTeX-ja. This JFM is
3385   based on \verb+upnmlminr-h.tfm+, a metric for UTF/OTF package that
3386   is used in \upTeX. When you use the \Pkg{luatexja-otf} package, you should use this JFM.
3387 %</en>
3388 %<*ja>
3389 \item[\tt jfm-ujis.lua] \LuaTeX-jaの標準JFMである.このJFMは\upTeX で
3390   用いられるUTF/OTFパッケージ用の和文用TFMである \verb+upnmlminr-h.tfm+ を
3391   元にしている.\Pkg{luatexja-otf}パッケージを使うときはこのJFMを指定するべきである.
3392 %</ja>
3393 %<*en>
3394 \item[\tt jfm-jis.lua] A counterpart for \verb+jis.tfm+, ``JIS font
3395   metric'' which is widely used in \pTeX. A major difference between
3396   \texttt{jfm-ujis.lua} and this \texttt{jfm-jis.lua} is that
3397   most characters under \texttt{jfm-ujis.lua} are square-shaped,
3398   while that under \texttt{jfm-jis.lua} are horizontal
3399   rectangles.
3400 %</en>
3401 %<*ja>
3402 \item[\tt jfm-jis.lua] \pTeX で広く用いられている「JISフォントメトリック」
3403   \verb+jis.tfm+ に相当するJFMである.\texttt{jfm-ujis.lua} とこの
3404   \texttt{jfm-jis.lua} の主な違いは,\texttt{jfm-ujis.lua} ではほとんどの文字が
3405   正方形状であるのに対し,\texttt{jfm-jis.lua} では横長の長方形状であることと,
3406   \texttt{jfm-ujis.lua} では「?」「!」の直後に半角空白が挿入されることである.
3407 %</ja>
3408 %<*en>
3409 \item[\tt jfm-min.lua] A counterpart for \verb+min10.tfm+, which is one
3410   of the default Japanese font metric shipped with \pTeX.
3411 %</en>
3412 %<*ja>
3413 \item[\tt jfm-min.lua] \pTeX に同梱されているデフォルトの和文用TFM
3414 (\verb+min10.tfm+)に相当し,行末で文字が揃うようにするために「っ」など一部の文字幅が変わっ
3415            ている.\verb+min10.tfm+ については\cite{min10}が詳しい.
3416 %</ja>
3417 \end{description}
3418 %<*en>
3419 The difference among these three~JFMs is  shown in \autoref{tab-difjfm}.
3420 %</en>
3421 %<*ja>
3422 これら3つのJFMの違いは\autoref{tab-difjfm}に示した.表中の文例の一部には,
3423 \cite{min10}の図3,~4のものを用いた.
3424 %</ja>
3425
3426 \begin{figure}
3427 \begin{LTXexample}[width=0.3\textwidth]
3428 \ltjsetparameter{differentjfm=both}
3429 \jfont\F=file:KozMinPr6N-Regular.otf:jfm=ujis
3430 \jfont\G=file:KozGoPr6N-Medium.otf:jfm=ujis
3431 \jfont\H=file:KozGoPr6N-Medium.otf:jfm=ujis;jfmvar=hoge
3432 \F ){\G 【】}( % halfwidth space
3433    ){\H 『』}( % fullwidth space
3434
3435 ほげ,{\G 「ほげ」}(ほげ)\par
3436 ほげ,{\H 「ほげ」}(ほげ)% pTeX-like
3437
3438 \ltjsetparameter{differentjfm=paverage}
3439 \end{LTXexample}
3440 \caption{Example of \texttt{jfmvar} key}
3441 \label{fig:jfmvar}
3442 \end{figure}
3443
3444 %<*en>
3445 \item[jfmvar=<string>]
3446 Sometimes there is a need that \ldots.
3447 %</en>
3448 %<*ja>
3449 \item[jfmvar=<string>]
3450 標準では,JFMとサイズが同じで,
3451   実フォントだけが異なる2つの和文フォントは「区別されない」.例えば
3452 \autoref{fig:jfmvar}において,最初の「)」と「【」の実フォントは異なるが,
3453 JFMもサイズも同じなので,普通に「)【」と入力した時と同じように半角空きとなる.
3454
3455 しかし,JFMとサイズが同じであっても,\texttt{jfmvar} キーの異なる
3456 2つの和文フォント,例えば\autoref{fig:jfmvar}で言う \cs{F} と \cs{H},
3457 は「区別される」.異なる和文フォントに異なる \texttt{jfmvar} キーを割り当て,
3458 かつ\Param{differentjfm}パラメータを \texttt{both} に設定すれば,
3459 \pTeX と似た状況で組版されることになる.
3460 %</ja>
3461 \end{cslist}
3462
3463 \begin{figure}
3464 \begin{LTXexample}[pos=t]
3465 \newcommand\test{\vrule ダイナミックダイクマ\vrule\\}
3466 \jfont\KMFW = KozMinPr6N-Regular:jfm=prop;-kern at 17pt
3467 \jfont\KMFK = KozMinPr6N-Regular:jfm=prop at 17pt % kern is activated
3468 \jfont\KMPW = KozMinPr6N-Regular:jfm=prop;script=dflt;+pwid;-kern at 17pt
3469 \jfont\KMPK = KozMinPr6N-Regular:jfm=prop;script=dflt;+pwid;+kern at 17pt
3470 \begin{multicols}{2}
3471 \ltjsetparameter{kanjiskip=0pt}
3472 {\KMFW\test \KMFK\test \KMPW\test \KMPK\test}
3473
3474 \ltjsetparameter{kanjiskip=3pt}
3475 {\KMFW\test \KMFK\test \KMPW\test \KMPK\test}
3476 \end{multicols}
3477 \end{LTXexample}
3478 \caption{Kerning information and \Param{kanjiskip}}
3479 \label{fig:kern-jfm}
3480 \end{figure}
3481
3482 %<en>\paragraph{Using kerning information in a font}
3483 %<ja>\paragraph{ペアカーニング情報の使用}
3484 \label{para-kern}
3485 %<*en>
3486 Some fonts have information for inter-glyph spacing.
3487 \LuaTeX-ja 20140324.0 or later treats kerning spaces like an italic correction;
3488 any glue and/or kern from the JFM and a kerning space can coexist.
3489 See \autoref{fig:kern-jfm} for detail.
3490
3491 Note that in \cs{setmainjfont} etc.\ which are provided by \Pkg{luatexja-fontspec}
3492 package, kerning option is set \emph{off} (\texttt{Kerning=Off}) by default,
3493 because of the compatibility with previous versions of \LuaTeX-ja.
3494 %</en>
3495 %<*ja>
3496 いくつかのフォントはグリフ間のスペースについての情報を持っている.
3497 このカーニング情報は以前の\LuaTeX-ja とはあまり相性が良くなかったが,
3498 バージョン20140324.0以降ではカーニングによる空白はイタリック補正と同様に扱うことになっている.
3499 つまり,カーニング由来の空白とJFM由来のグルー・カーンは同時に入りうる.
3500 \autoref{fig:kern-jfm}を参照.
3501 \begin{itemize}
3502  \item \emph{\cs{jfont} や,
3503 NFSS2用の命令(\ref{ssec:chgfnt}節,\ref{ssec:nfsspat}節)における指定では
3504 カーニング情報は標準で使用する}ことになっているようである.
3505 言い換えれば,カーニング情報を使用しない設定にするには,面倒でも
3506 \begin{lstlisting}
3507 \jfont\hoge=KozMinPr6N-Regular:jfm=ujis;-kern at 3.5mm
3508 \DeclareFontShape{JY3}{fuga}{m}{n} {<-> s*KozMinPr6N-Regular:jfm=ujis;-kern}{}
3509 \end{lstlisting}
3510 のように,\texttt{-kern} という指定を自分で追加しなければいけない.
3511  \item
3512 一方,\emph{\Pkg{luatexja-fontspec} の提供する \cs{setmainjfont}\
3513 などの命令の標準設定ではカーニング情報は使用しない}(\texttt{Kerning=Off})
3514 ことになっている.これは以前のバージョンの\LuaTeX-jaとの互換性のためである.
3515 \end{itemize}
3516 %</ja>
3517
3518 %<*ja>
3519 \paragraph{\texttt{extend}と\texttt{slant}}
3520 OpenType font featureと見かけ上同じような形式で指定できるものに,
3521 \begin{description}
3522 \item[\texttt{extend=}<extend>] 横方向に<extend>倍拡大する.
3523 \item[\texttt{slant=}<slant>] <slant>に指定された割合だけ傾ける.
3524 \end{description}
3525 の2つがある.
3526 \texttt{extend}や\texttt{slant}を指定した場合は,それに応じたJFMを指定すべきである%
3527 \footnote{\LuaTeX-jaでは,これらに対するJFMを特に提供することはしない予定である.}.
3528 例えば,次の例では無理やり通常のJFMを使っているために,文字間隔やイタリック補正量が
3529 正しくない:
3530 %</ja>
3531 %<*en>
3532 \paragraph{\texttt{extend} and \texttt{slant}}
3533 The following setting can be specified as OpenType font features:
3534 \begin{cslist}[style=standard]
3535 \item[\texttt{extend=}<extend>] expand the font horizontally by <extend>.
3536 \item[\texttt{slant=}<slant>] slant the font.
3537 \end{cslist}
3538 Note that \LuaTeX-ja doesn't adjust JFMs by these \texttt{extend} and \texttt{slant}
3539 settings; you have to write new JFMs on purpose.
3540 For example, the following example uses the standard JFM \texttt{jfm-ujis.lua}, hence
3541 letter-spacing and the width of italic correction are not correct:
3542 %</en>
3543 \begin{LTXexample}[width=0.3\textwidth]
3544 \jfont\E=KozMinPr6N-Regular:extend=1.5;jfm=ujis;-kern
3545 \E あいうえお
3546
3547 \jfont\S=KozMinPr6N-Regular:slant=1;jfm=ujis;-kern
3548 \S あいう\/ABC
3549 \end{LTXexample}
3550
3551 %<*ja>
3552 \paragraph{\texttt{ltjksp} 指定}
3553 \label{pg:ltjksp}
3554 \LuaTeX-ja標準では,
3555 JFM中における \texttt{kanjiskip\_natural}, \texttt{kanjiskip\_stretch},\
3556 \texttt{kanjiskip\_shrink}キー(\pageref{pg:ksp_nat}ページ)の使用によって,
3557 「JFM由来のグルーの他に,\Param{kanjiskip}の自然長/伸び量/縮み量の一部が
3558 同じ場所に挿入される」という状況が起こりうる.
3559 この機能を無効化し,バージョン20150922.0以前と同じような組版を得るためには
3560 他のOpenType機能と同じように\ \texttt{-ltjksp}\ 指定を行えば良い.
3561 \begin{LTXexample}[width=16\zw]
3562 \leavevmode
3563 \ltjsetparameter{kanjiskip=0pt plus 3\zw}
3564 \vrule\hbox to 15\zw{あ「い」う,えお}\vrule
3565
3566 \jfont\G=file:KozMinPr6N-Regular.otf%
3567   :jfm=ujis;-ltjksp at 9.2487pt
3568 \G\leavevmode%
3569 \vrule\hbox to 15\zw{あ「い」う,えお}\vrule
3570 \end{LTXexample}
3571 なお,
3572 \begin{lstlisting}
3573  \jfont\G=file:KozMinPr6N-Regular.otf:jfm=ujis;-ltjksp;+ltjksp at 9.2487pt
3574 \end{lstlisting}
3575 のように \texttt{+ltjksp} 指定を行った場合は,\texttt{kanjiskip\_natural} など
3576 3キーは再び有効化される.\texttt{-ltjksp}, \texttt{+ltjksp} を複数回指定した場合は,
3577 最後に指定したものが有効となる.
3578 %</ja>
3579 %<*en>
3580 \paragraph{\texttt{ltjksp}}
3581 \label{pg:ltjksp}
3582 \texttt{kanjiskip\_natural}, \texttt{kanjiskip\_stretch},\
3583 \texttt{kanjiskip\_shrink} keys (Page~\pageref{pg:ksp_nat}) makes tha
3584 \LuaTeX-ja inserts not only a glue which is specified by a JFM, and also
3585 the natural width/stretch part/shrink part of \Param{kanjiskip}.
3586
3587 This functionality is disabled by \texttt{-ltjksp} specification.
3588 \begin{LTXexample}[width=16\zw]
3589 \leavevmode
3590 \ltjsetparameter{kanjiskip=0pt plus 3\zw}
3591 \vrule\hbox to 15\zw{あ「い」う,えお}\vrule
3592
3593 \jfont\G=file:KozMinPr6N-Regular.otf%
3594   :jfm=ujis;-ltjksp at 9.2487pt
3595 \G\leavevmode%
3596 \vrule\hbox to 15\zw{あ「い」う,えお}\vrule
3597 \end{LTXexample}
3598 %</en>
3599
3600
3601
3602
3603 %<en>\subsection{\cs{tfont}}
3604 %<ja>\subsection{\cs{tfont} 命令}
3605
3606
3607 \begin{comment}
3608   {\catcode`\<=12\catcode`\>=12
3609 \begin{table}[t]
3610 %<en>\caption{Differences between vertical JFMs shipped with \LuaTeX-ja}
3611 %<ja>\caption{\LuaTeX-ja に同梱されている縦組用 JFM の違い}
3612 %<en>\medskip
3613 \label{tab-difjfm-tate}
3614 \ltjsetparameter{jacharrange={+3}}
3615 \small
3616 \def\r#1#2{%
3617   \hbox{\tate\Large\vrule
3618   \parbox{7\zw}{%
3619     \addjfontfeatures{TateFeatures={Opacity=0.5, Color=#2, JFM=#1}}\noindent
3620     ◆◆◆◆◆◆◆
3621     ある日モモちゃんが「お使い」で迷子になって泣きました。
3622   }\vrule}}
3623 \def\s#1#2{%
3624   \hbox{\tate\Large
3625   \parbox{7\zw}{%
3626     \addjfontfeatures{TateFeatures={Opacity=0.5, Color=#2, JFM=#1}}\noindent
3627     ちょっと!何
3628   }}}
3629 \def\t#1#2#3{\hbox to 0pt{\hss%
3630   \setbox0=\hbox{\addjfontfeatures{TateFeatures={JFM=#1}}\huge #3}%
3631   \textcolor{#2}{\transparent{0.5}\vrule width 0.4pt height\ht0 depth\dp0}\kern-.2pt\copy0
3632   \textcolor{#2}{\transparent{0.5}\kern-\wd0\vrule width\wd0height .2pt depth .2pt
3633   \kern-\wd0\raise\ht0\hbox{\vrule width\wd0height .2pt depth .2pt}%
3634   \kern-\wd0\lower\dp0\hbox{\vrule width\wd0height .2pt depth .2pt}%
3635   \kern-.2pt\vrule width 0.4pt height\ht0 depth \dp0}\hss}}
3636
3637 \begin{minipage}{.7\textwidth}
3638 \centering
3639 \leavevmode\hbox to 0pt{\r{ujisv}{blue}\hss}\r{tmin}{red}\quad
3640 \leavevmode\hbox to 0pt{\s{ujisv}{blue}\hss}\s{tmin}{red}\quad
3641 \raise4\zw\hbox{\tate\Large\t{ujisv}{black}{漢}\t{tmin}{red}{漢}\qquad
3642            \t{ujisv}{black}{っ}\t{tmin}{red}{っ}}
3643 \end{minipage}%
3644 \begin{minipage}{.3\textwidth}
3645 \textcolor{blue}{Blue: \texttt{jfm-ujisv.lua}}\\
3646 \textcolor{red}{Red: \texttt{jfm-tmin.lua}}
3647 \end{minipage}
3648 \ltjsetparameter{jacharrange={-3}}
3649 \end{table}
3650 }
3651 \end{comment}
3652
3653 %<*en>
3654 \cs{tfont} loads a font as a Japanese font for vertical direction.
3655 This command admits the same syntax used in \cs{font}~and~\cs{jfont}.
3656 A font defined by~\cs{tfont} differs the following points from that by~\cs{jfont}:
3657 \begin{itemize}
3658  \item OpenType Feature~\texttt{vrt2}%
3659   \footnote{If the font does not define \texttt{vrt2} feature,
3660         use \texttt{vert} instead.} is automatically activated,
3661   unless \texttt{vert}~and//or~\texttt{vrt2} are explicitly activated
3662   or deactivated (as the second line in the example below).
3663 \begin{lstlisting}
3664 \tfont\S=file:KozMinPr6N-Regular.otf:jfm=ujisv % vrt2 is automatically activated
3665 \tfont\T=file:KozMinPr6N-Regular.otf:jfm=ujisv;-vert % vert and vrt2 are not activated
3666 \tfont\U=file:ipaexm.ttf:jfm=ujisv
3667     % vert is automatically activated, since this font does not have vrt2
3668 \end{lstlisting}
3669  \item Sometimes \texttt{vert} and/or \texttt{vrt2} are not activated
3670  while one specified activation of these feature.
3671  This is because the font does not define these features in current combination of
3672  script~tag and language~system~identifier.
3673
3674  In this situation, \LuaTeX-ja performs all replacements which is defined in~\texttt{vert}
3675  feature for \emph{some} scripts for \emph{some} languages.
3676  \item Furthermore, a glyph is automatically rotated 90~degrees,
3677   if it is not replaced by \texttt{vert} feature for \emph{any} script
3678   for \emph{any} language, and if it is marked as `r''~or~``Tr'' in UAX~\#50.
3679  \item One have to specify the name of vertical JFM in  \texttt{jfm=<name>}.
3680 \LuaTeX-ja ships following vertical JFMs:
3681 \begin{description}
3682 \item[\tt jfm-ujisv.lua] A standard vertical JFM in \LuaTeX-ja. This JFM is
3683   based on \verb+upnmlminr-v.tfm+, a metric for UTF/OTF package that
3684   is used in \upTeX.
3685 \item[\tt jfm-tmin.lua] A counterpart for \verb+tmin10.tfm+, which is one
3686   of the default Japanese font metric shipped with \pTeX.
3687 \end{description}
3688 \end{itemize}
3689 %</en>
3690 %<*ja>
3691 \cs{tfont} はフォントを縦組用の和文フォントとして読み込む命令であり,
3692 \cs{tfont} の文法は \cs{jfont} と同じである.
3693 \cs{tfont} で定義された縦組用和文フォントは,
3694 以下の点が \cs{jfont} による横組用和文フォントとは異なる:
3695 \begin{itemize}
3696  \item 明示的に \texttt{vert}, \texttt{vrt2}(のいずれか)の
3697   有効・無効を指定した場合を除き,自動的に OpenType feature~\texttt{vrt2} の有効化が
3698   指定されたものとみなされる
3699  \footnote{もしフォントが\texttt{vrt2}を定義していなかった場合,代わりに
3700  \texttt{vert}を用いる.}.
3701 \begin{lstlisting}
3702 \tfont\S=file:KozMinPr6N-Regular.otf:jfm=ujisv % vrt2 is automatically activated
3703 \tfont\T=file:KozMinPr6N-Regular.otf:jfm=ujisv;-vert % vert and vrt2 are not activated
3704 \tfont\U=file:ipaexm.ttf:jfm=ujisv
3705     % vert is automatically activated, since this font does not have vrt2
3706 \end{lstlisting}
3707  \item \texttt{vert}, \texttt{vrt2} の少なくとも一つの有効を指定した場合にも関わらず,
3708   script tagとlanguage system identifierの値の組み合わせによって
3709   実際には有効にならなかった場合,\LuaTeX-jaは
3710  \begin{quote}
3711    どれかのscript,~languageで定義されている\texttt{vert}による
3712    (単一グリフから単一グリフへの)置換を全部適用する
3713  \end{quote}
3714   という挙動を取る\footnote{%
3715   例えば,Windows~7に付属しているSimHeiでは,\texttt{vert}はScriptが\texttt{hani},
3716   Languageが\texttt{CHN}という状況でのみ定義されている.しかし,\Pkg{luaotfload}では
3717   このscript,~languageの組み合わせを指定することはできないので,
3718   \Pkg{luaotfload}そのままでは\texttt{vert}を適用させることはできない.
3719  }.
3720  \item さらに,「いかなるscript,~languageでも\texttt{vert}により置換されない」グリフ
3721   のうち,UAX~\#50で``r''もしくは``Tr''と指定されているものは90度自動回転させる.
3722  \item \ref{ssec:math}節で述べる,数式中の和文フォントには縦組用和文フォントは指定できない.
3723  \item \texttt{jfm=<name>}\ の部分には縦組用JFMを指定する.
3724 以下の縦組用JFMが\LuaTeX-jaには同梱されている.%おり,違いを\autoref{tab-difjfm-tate}に示した.
3725 \begin{description}
3726 \item[\tt jfm-ujisv.lua] \LuaTeX-jaの標準縦組用JFMである.このJFMは\upTeX で
3727   用いられるUTF/OTFパッケージ用の和文用TFMである \verb+upnmlminr-v.tfm+ を
3728   元にしている.
3729 \item[\tt jfm-tmin.lua] \pTeX に同梱されているデフォルトの和文用縦組TFM
3730   である \verb+tmin10.tfm+ に相当し,\texttt{min10.tfm} と同様に
3731   「っ」など一部の文字幅が狭められている.
3732 \end{description}
3733 \end{itemize}
3734
3735 なお,\pTeX では,\cs{font},~\cs{jfont},~\cs{tfont}のどれでも欧文フォント・横組用和文フォン
3736 ト・縦組用和文フォントの定義が可能であったが,\LuaTeX-jaではそうでないので注意.
3737 %</ja>
3738
3739 %<en>\subsection{Prefix \texttt{psft}}
3740 %<ja>\subsection{\texttt{psft}プリフィックス}
3741 \label{ssec:psft}
3742 %<*en>
3743 Besides ``\texttt{file:}''\ and ``\texttt{name:}''\ prefixes which
3744 are introduced in the \Pkg{luaotfload} package,
3745 \LuaTeX-ja adds ``\texttt{psft:}''\ prefix in \cs{jfont} (and~\cs{font}),
3746 to specify a ``name-only'' Japanese font which
3747 will not be embedded to PDF.
3748 Note that these non-embedded fonts under current \LuaTeX\ has Identity-H encoding,
3749 and this violates the standard ISO32000-1:2008~(\cite{pdfstd}).
3750
3751 \emph{OpenType font features, such as ``{\tt +jp90}'',
3752 have no meaning in name-only fonts using ``{\tt psft:}''\ prefix,
3753 because we can't expect what fonts are actually used by the PDF reader.}
3754 Note that \texttt{extend}~and~\texttt{slant} settings (see~above) are supported
3755 with \texttt{psft} prefix, because they are only simple linear transformations.
3756 %</en>
3757 %<*ja>
3758 \Pkg{luaotfload}で使用可能になった
3759 \texttt{file:}\ と \texttt{name:}\ のプリフィックスに加えて,
3760 \cs{jfont}(と \cs{font} プリミティブ)では
3761 \texttt{psft:}プリフィックスを用いることができる.
3762 このプリフィックスを用いることで,PDFには埋め込まれない「名前だけの」
3763 和文フォントを指定することができる.
3764 なお,現行の\LuaTeX で非埋め込みフォントを作成するとPDF内でのエンコーディングが
3765 Identity-Hとなり,PDFの標準規格ISO32000-1:2008~(\cite{pdfstd})に非準拠になってしまう
3766 ので注意してほしい.
3767
3768 \emph{\texttt{psft} プリフィックスの下では
3769 \texttt{+jp90} などのOpenType font featureの効力はない.
3770 非埋込フォントをPDFに使用すると,実際にどのようなフォントが
3771 表示に用いられるか予測できないからである.}\
3772 \texttt{extend} と \texttt{slant} 指定は単なる変形のため
3773 \texttt{psft} プリフィックスでも使用可能である.
3774 %</ja>
3775
3776 %<en>\paragraph{\texttt{cid} key}
3777 %<ja>\paragraph{\texttt{cid}キー}
3778 \label{para-cid}
3779
3780 %<*en>
3781 The default font defined by using \texttt{psft:} prefix is for Japanese typesetting;
3782 it is Adobe-Japan1-6 CID-keyed font.
3783 One can specify \texttt{cid} key to use other CID-keyed non-embedded fonts
3784 for Chinese or Korean typesetting.
3785 %</en>
3786 %<*ja>
3787 標準で\texttt{psft:}プリフィックスで定義されるフォントは日本語用のもので
3788 あり,Adobe-Japan1-6のCIDに対応したものとなる.しかし,\LuaTeX-jaは中国語
3789 の組版にも威力を発揮することが分かり,日本語フォントでない非埋込フォント
3790 の対応も必要となった.そのために追加されたのが\texttt{cid}キーである.
3791
3792 \texttt{cid}キーに値を指定すると,そのCIDを持った非埋込フォントを定義することができる:
3793 %</ja>
3794 \begin{lstlisting}[numbers=left]
3795 \jfont\testJ={psft:Ryumin-Light:cid=Adobe-Japan1-6;jfm=jis}     % Japanese
3796 \jfont\testD={psft:Ryumin-Light:jfm=jis}                        % default value is Adobe-Japan1-6
3797 \jfont\testC={psft:AdobeMingStd-Light:cid=Adobe-CNS1-6;jfm=jis} % Traditional Chinese
3798 \jfont\testG={psft:SimSun:cid=Adobe-GB1-5;jfm=jis}              % Simplified Chinese
3799 \jfont\testK={psft:Batang:cid=Adobe-Korea1-2;jfm=jis}           % Korean
3800 \end{lstlisting}
3801 %<*en>
3802 Note that the code above specifies \texttt{jfm-jis.lua}, which is for Japanese fonts,
3803 as JFM for Chinese and Korean fonts.
3804 %</en>
3805 %<*ja>
3806 上のコードでは中国語・韓国語用フォントに対してもJFMに
3807 日本語用の\texttt{jfm-jis.lua}を指定しているので注意されたい.
3808 %</ja>
3809
3810 %<*en>
3811 At present, \LuaTeX-ja supports only 4 values written in the sample code above.
3812 Specifying other values, e.g.,
3813 %</en>
3814 %<*ja>
3815 今のところ,\LuaTeX-jaは上のサンプルコード中に書いた4つの値しかサポートしていない.
3816 %</ja>
3817 \begin{lstlisting}
3818 \jfont\test={psft:Ryumin-Light:cid=Adobe-Japan2;jfm=jis}
3819 \end{lstlisting}
3820 %<*en>
3821 produces the following error:
3822 %</en>
3823 %<*ja>
3824 のようにそれら以外の値を指定すると,エラーが発生する:
3825 %</ja>
3826 \begin{lstlisting}[numbers=left]
3827 ! Package luatexja Error: bad cid key `Adobe-Japan2'.
3828
3829 See the luatexja package documentation for explanation.
3830 Type  H <return>  for immediate help.
3831 <to be read again>
3832                    \par
3833 l.78
3834
3835 ? h
3836 I couldn't find any non-embedded font information for the CID
3837 `Adobe-Japan2'. For now, I'll use `Adobe-Japan1-6'.
3838 Please contact the LuaTeX-ja project team.
3839 ?
3840 \end{lstlisting}
3841
3842 %<en>\subsection{Structure of a JFM file}
3843 %<ja>\subsection{JFMファイルの構造}
3844 \label{ssec:jfm-str}
3845 %<en>A JFM file is a Lua script which has only one function call:
3846 %<ja>JFMファイルはただ一つの関数呼び出しを含むLuaスクリプトである:
3847 \begin{lstlisting}
3848 luatexja.jfont.define_jfm { ... }
3849 \end{lstlisting}
3850 %<*en>
3851 Real data are stored in the table which indicated above by
3852 \verb+{ ... }+.  So, the rest of this subsection are devoted to describe the
3853 structure of this table.  Note that all lengths in a JFM file are
3854 floating-point numbers in design-size unit.
3855 %</en>
3856 %<*ja>
3857 実際のデータは上で \verb+{ ... }+ で示されたテーブルの中に格納されている.
3858 以下ではこのテーブルの構造について記す.
3859 なお,JFMファイル中の長さは全てdesign-sizeを単位とする浮動小数点数であることに
3860 注意する.
3861 %</ja>
3862
3863 \begin{cslist}[style=standard]
3864
3865 \item[version=<version>]
3866 %<en>(optional, default value is~1)
3867 %<ja>(任意,既定値は1)
3868
3869 %<*en>
3870 The version JFM. Currently 1,~2,~and,~3 are supported
3871 %</en>
3872 %<*ja>
3873 JFMのバージョン.1,~2,~3がサポートされる.
3874 %</ja>
3875   
3876 \item[dir=<direction>]
3877 %<en>(required)
3878 %<ja>(必須)
3879
3880 %<*en>
3881 The direction of JFM. \texttt{'yoko'}~(horizontal)
3882 or \texttt{'tate'}~(vertical) are supported.
3883 %</en>
3884 %<*ja>
3885 JFMの書字方向.\texttt{'yoko'}(横組)と \texttt{'tate'}(縦組)がサポートされる.
3886 %</ja>
3887
3888 \item[zw=<length>]
3889 %<en>(required)
3890 %<ja>(必須)
3891
3892 %<en>The amount of the length of the ``full-width''.
3893 %<*ja>
3894 「全角幅」の長さ.この量が \cs{zw} の長さとなる.\pTeX では
3895 「全角幅」\texttt{1zw} は「文字クラス0の文字」の幅と決められていたが,
3896 \LuaTeX-jaではここで指定する.
3897 %</ja>
3898
3899 \item[zh=<length>]
3900 %<en>(required)
3901 %<ja>(必須)
3902
3903 %<en>The amount of the ``full-height'' (height + depth).
3904 %<*ja>
3905 「全角高さ」(height + depth)の長さ.通常は全角幅と同じ長さになるだろう.
3906 \pTeX では 「全角高さ」\texttt{1zh} は「文字クラス0の文字」の高さと深さの和と決められていたが,
3907 \LuaTeX-jaではここで指定する.
3908 %</ja>
3909
3910 \item[kanjiskip=\{<natural>, <stretch>, <shrink>\}]
3911 %<en>(optional)
3912 %<ja>(任意)
3913
3914 %<*en>
3915 This field specifies the ``ideal'' amount of \Param{kanjiskip}. As noted
3916              in Subsection~\ref{subs-kskip}, if the parameter
3917              \Param{kanjiskip} is \cs{maxdimen}, the value specified
3918              in this field is actually used (if this field is not specified in
3919              JFM, it is regarded as 0\,pt). Note that <stretch> and <shrink>
3920              fields are in design-size unit too.
3921 %</en>
3922 %<*ja>
3923 理想的な\Param{kanjiskip}の量を指定する.\ref{subs-kskip}節で述べたように,
3924 もし\Param{kanjiskip}が \cs{maxdimen} の値ならば,このフィールドで指定された
3925 値が実際には用いられる(指定なしは0\,ptとして扱われる).<stretch>と<shrink>のフィールドもdesign-size
3926 が単位であることに注意せよ.
3927 %</ja>
3928
3929 \item[xkanjiskip=\{<natural>, <stretch>, <shrink>\}]
3930 %<en>(optional)
3931 %<ja>(任意)
3932
3933 %<*en>
3934 Like the \texttt{kanjiskip} field, this field specifies the ``ideal''
3935              amount of \Param{xkanjiskip}.
3936 %</en>
3937 %<*ja>
3938 \texttt{kanjiskip}フィールドと同様に,\Param{xkanjiskip}の理想的な量を
3939 指定する.
3940 %</ja>
3941 \end{cslist}
3942
3943 %<*en>
3944 \paragraph{Character classes}
3945 Besides from above fields, a JFM file have several sub-tables those
3946 indices are natural numbers.  The table indexed by~$i\in\omega$ stores
3947 information of \emph{character class}~$i$. At least, the character class~0 is
3948 always present, so each JFM file must have a sub-table whose index is
3949 \texttt{[0]}.  Each sub-table (its numerical index is denoted by $i$) has
3950 the following fields:
3951 %</en>
3952 %<*ja>
3953 \paragraph{文字クラス}
3954 上記のフィールドに加えて,JFMファイルはそのインデックスが自然数であるいくつかの
3955 サブテーブルを持つ.インデックスが$i\in\omega$であるテーブルは\emph{文字クラス}$i$の
3956 情報を格納する.少なくとも,文字クラス0は常に存在するので,JFMファイルはインデックス
3957 が\texttt{[0]}のサブテーブルを持たなければならない.それぞれのサブテーブル
3958 (そのインデックスを$i$で表わす)は以下のフィールドを持つ:
3959 %</ja>
3960
3961 \begin{cslist}[style=standard]
3962 \item[chars=\{<character>, ...\}]
3963 %<en>(required except character class~0)
3964 %<ja>(文字クラス0を除いて必須)
3965
3966 %<*en>
3967 This field is a list of characters which are in this character
3968              type~$i$. This field is optional if $i=0$, since all
3969              \textbf{JAchar} which do not belong  any character classes other
3970              than 0 are in the character class 0
3971              (hence, the character class~0 contains most of
3972              \textbf{JAchar}s). In the list, character(s) can be specified in the following form:
3973 \begin{itemize}
3974 \item a Unicode code point
3975 \item the character itself (as a Lua string, like \hbox{\ltjsetparameter{autoxspacing=false}\verb+'あ'+})
3976 \item a string like \hbox{\ltjsetparameter{autoxspacing=false}\verb+'あ*'+} (the character followed by an asterisk)
3977 \item several ``imaginary'' characters (We will describe these later.)
3978 \end{itemize}
3979 %</en>
3980 %<*ja>
3981 このフィールドは文字クラス$i$に属する文字のリストである.このフィールドは$i=0$の
3982 場合には任意である(文字クラス0には,0以外の文字クラスに属するものを
3983 除いた全ての\textbf{JAchar}が属するから).このリスト中で文字を指定するには,以下の方法がある:
3984 \begin{itemize}
3985 \item Unicode におけるコード番号
3986 \item 「\hbox{\ltjsetparameter{autoxspacing=false}\verb+'あ'+}」のような,文字それ自体
3987 \item 「\hbox{\ltjsetparameter{autoxspacing=false}\verb+'あ*'+}」のような,文字それ自体の後にアスタリスクをつけたもの
3988 \item いくつかの「仮想的な文字」(後に説明する)
3989 \end{itemize}
3990 %</ja>
3991
3992 \item[width=<length>, height=<length>, depth=<length>, italic=<length>]
3993 %<en>(required)
3994 %<ja>(必須)
3995
3996 %<*en>
3997 \begin{table}[t]
3998  \centering
3999 \begin{tabular}{llr}
4000 \toprule
4001 Direction of JFM&\textbf{\texttt{'yoko'} (horizontal)}&\multicolumn{1}{l}{\textbf{\texttt{'tate'} (vertical)}}\\
4002 \midrule
4003 \texttt{width} field&\multicolumn{2}{c}{the width of the ``real'' glyph}\\
4004 \texttt{height} field&the height of the ``real'' glyph&0.0\\
4005 \texttt{depth} field&the depth of the ``real'' glyph&0.0\\
4006 \midrule
4007 \texttt{italic} field&\multicolumn{2}{c}{0.0}\\
4008 \bottomrule
4009 \end{tabular}
4010 \caption{Default values of \texttt{width} field and other fields}
4011 \label{tab-wid}
4012 \end{table}
4013 Specify the width of characters in character class~$i$, the height, the depth and
4014 the amount of italic correction. All characters in character class~$i$ are regarded that its width, height, and depth are
4015 as values of these fields. The default values are shown in \autoref{tab-wid}.
4016 %</en>
4017 %<*ja>
4018 \begin{table}[t]
4019  \centering
4020 \begin{tabular}{llr}
4021 \toprule
4022 JFM書字方向&\emph{\texttt{'yoko'}(横組)}&\multicolumn{1}{l}{\emph{\texttt{'tate'}(縦組)}}\\
4023 \midrule
4024 \texttt{width}&\multicolumn{2}{c}{「実際のグリフ」の幅}\\
4025 \texttt{height}&「実際のグリフ」の高さ&0.0\\
4026 \texttt{depth}&「実際のグリフ」の深さ&0.0\\
4027 \midrule
4028 \texttt{italic}&\multicolumn{2}{c}{0.0}\\
4029 \bottomrule
4030 \end{tabular}
4031 \caption{\texttt{width} フィールド等の標準値}
4032 \label{tab-wid}
4033 \end{table}
4034 文字クラス$i$に属する文字の幅,高さ,深さ,イタリック補正の量を指定する.
4035 文字クラス$i$に属する全ての文字は,その幅,高さ,深さがこのフィールドで指定した
4036 値であるものとして扱われる.省略時や,数でない値を指定した時には表\nobreak\ref{tab-wid}に
4037              示されている値を用いる.例えば,横組用JFMで \texttt{width} フィールドには数値以外の値を指
4038              定した場合,文字の幅はその「実際の」グリフの幅となる.OpenTypeの \texttt{prop} featureと併用
4039              すれば,これによってプロポーショナル組を行うことができる.
4040 %</ja>
4041
4042 \item[left=<length>, down=<length>, align=<align>]\
4043
4044 %<*en>
4045 These fields are for adjusting the position of the ``real'' glyph. Legal
4046              values of \texttt{align} field are \texttt{'left'},
4047              \texttt{'middle'}, and \texttt{'right'}. If one of these
4048              3~fields are omitted, \texttt{left} and \texttt{down} are
4049              treated as~0, and \texttt{align} field is treated as
4050              \texttt{'left'}.
4051 The effects of these 3~fields are indicated in
4052 \autoref{fig:pos}~and~\autoref{fig:pos-tate}.
4053 %</en>
4054 %<*ja>
4055 これらのフィールドは実際のグリフの位置を調整するためにある.
4056 \texttt{align} フィールドに指定できる値は \texttt{'left'}, \texttt{'middle'},
4057 \texttt{'right'} のいずれかである.もしこれら3つのフィールドのうちの1つが省かれた
4058 場合,\texttt{left} と \texttt{down} は0,\texttt{align} フィールドは
4059 \ \texttt{'left'} であるものとして扱われる.
4060 これら3つのフィールドの意味については\autoref{fig:pos}(横組用和文フォント),
4061 \autoref{fig:pos-tate}(縦組用和文フォント)で説明する.
4062 %</ja>
4063
4064 %<*en>
4065 In most cases, \texttt{left} and \texttt{down} fields are~0, while
4066 it is not uncommon that the \texttt{align} field is \texttt{'middle'} or \texttt{'right'}.
4067 For example, setting the \texttt{align} field to \texttt{'right'} is practically needed
4068 when the current character class is the class for opening delimiters'.
4069 %</en>
4070 %<*ja>
4071 多くの場合,\texttt{left}と\texttt{down}は0である一方,
4072 \texttt{align}フィールドが\texttt{'middle'}や\texttt{'right'}であることは
4073 珍しいことではない.
4074 例えば,\texttt{align}フィールドを\texttt{'right'}に指定することは,
4075 文字クラスが開き括弧類であるときに実際必要である.
4076 %</ja>
4077
4078 \begin{figure}[!tb]
4079 \begin{minipage}{0.4\textwidth}%
4080 \begin{center}\unitlength=10pt\small
4081 \begin{picture}(15,12)(-1,-4)
4082 \color{b_gray}% jfm
4083 \put(0,0){\vrule width 12\unitlength height 8\unitlength depth 3\unitlength}
4084
4085 \color{b_pink}% step1
4086 \put(-1,-1.5){\vrule width 6\unitlength height 7\unitlength depth 2.5\unitlength}
4087
4088 \color{red}% real glyph
4089 \thicklines
4090 \put(-1,-1.5){\vector(0,1){7}\vector(0,-1){2.5}\vector(1,0){6}}
4091 \put(5,-1.5){\line(0,1){7}\line(0,-1){2.5}}
4092 \put(-1,5.5){\line(1,0){6}}
4093 \put(-1,-4){\line(1,0){6}}
4094
4095 \color{b_green}% real glyph
4096 \put(3,0){\vrule width 6\unitlength height 7\unitlength depth 2.5\unitlength}
4097
4098 \color{black}% jfm
4099 \thicklines
4100 \put(0,0){\vector(0,1){8}\line(0,-1){3}\vector(1,0){12}}
4101 \put(12,0){\line(0,1){8}\vector(0,-1){3}}
4102 \put(0,8){\line(1,0){12}}
4103 \put(0,-3){\line(1,0){12}}
4104 \put(0.2,4){\makebox(0,0)[l]{\texttt{height}}}
4105 \put(12.2,-1.5){\makebox(0,0)[l]{\texttt{depth}}}
4106 \put(6,0.2){\makebox(0,0)[b]{\texttt{width}}}
4107
4108 \color{green}% step1
4109 \thicklines
4110 \put(3,0){\vector(0,1){7}\vector(0,-1){2.5}\vector(1,0){6}}
4111 \put(9,0){\line(0,1){7}\line(0,-1){2.5}}
4112 \put(3,7){\line(1,0){6}}
4113 \put(3,-2.5){\line(1,0){6}}
4114 \newsavebox{\eqdist}
4115 \savebox{\eqdist}(0,0)[b]{%
4116   \thinlines
4117   \put(-0.08,0.2){\line(0,-1){0.4}}%
4118   \put(0.08,0.2){\line(0,-1){0.4}}}
4119 \put(1.5,0){\usebox{\eqdist}}
4120 \put(10.5,0){\usebox{\eqdist}}
4121
4122 \color{blue}% shifted
4123 \thicklines
4124 \put(3,-1.5){\vector(-1,0){4}}
4125 \put(1,-1.7){\makebox(0,0)[t]{\texttt{left}}}
4126 \put(3,0){\vector(0,-1){1.5}}
4127 \put(3.2,-0.75){\makebox(0,0)[l]{\texttt{down}}}
4128 \end{picture}
4129 \end{center}
4130 \end{minipage}%
4131 \begin{minipage}{0.6\textwidth}%
4132 %<*en>
4133 Consider a  Japanese character node which belongs to
4134 a character class whose the \texttt{align}
4135 field is \texttt{'middle'}.
4136 %</en>
4137 %<*ja>
4138 \texttt{align}フィールドの値が \texttt{'middle'} であるような文字クラスに属する
4139 和文文字ノードを考えよう.
4140 %</ja>
4141 \begin{itemize}
4142 \item
4143 %<*en>
4144 The black rectangle is the imaginary body of the node.
4145 Its width, height, and depth are specified by JFM.
4146 %</en>
4147 %<*ja>
4148 黒色の長方形はノードの枠であり,
4149 その幅,高さ,深さはJFMによって指定されている.
4150 %</ja>
4151 \item
4152 %<*en>
4153 Since the \texttt{align} field is \texttt{'middle'},
4154 the ``real'' glyph is centered horizontally (the green rectangle) first.
4155 %</en>
4156 %<*ja>
4157 \texttt{align}フィールドは \texttt{'middle'} なので,
4158 実際のグリフの位置はまず水平方向に中央揃えしたものとなる(緑色の長方形).
4159 %</ja>
4160 \item
4161 %<*en>
4162 Furthermore, the glyph is shifted according to values of fields
4163       \texttt{left} and \texttt{down}. The ultimate position of the real
4164       glyph is indicated by the red rectangle.
4165 %</en>
4166 %<*ja>
4167 さらに,グリフは \texttt{left} と \texttt{down} の値に従ってシフトされる.
4168 最終的な実際のグリフの位置は赤色の長方形で示された位置になる.
4169 %</ja>
4170 \end{itemize}
4171 \end{minipage}
4172 \medskip
4173
4174 \caption{%
4175 %<en>The position of the real glyph (horizontal Japanese fonts)
4176 %<ja>横組和文フォントにおける「実際の」グリフの位置
4177 }
4178 \label{fig:pos}
4179 \end{figure}
4180 \begin{figure}[!tb]
4181 \begin{minipage}{0.4\textwidth}%
4182 \begin{center}\unitlength=10pt\small
4183 \begin{picture}(15,12)(-6,0)
4184 \color{b_gray}% jfm
4185 \put(-6,0){\vrule width 12\unitlength height 11\unitlength}
4186
4187 \color{b_pink}% real glyph
4188 \put(-6.5,5.5){\vrule width 8\unitlength height 6\unitlength depth 3\unitlength}
4189
4190 \color{red}% real glyph
4191 \thicklines
4192 \put(-6.5,5.5){\vector(0,1){6}\vector(0,-1){3}\vector(1,0){8}}
4193 \put( 1.5,5.5){\line(0,1){6}\line(0,-1){3}}
4194 \put(-6.5,11.5){\line(1,0){8}}
4195 \put(-6.5,2.5){\line(1,0){8}}
4196
4197 \color{b_green}% step1
4198 \put(-4,3){\vrule width 8\unitlength height 6\unitlength depth 3\unitlength}
4199
4200 \color{black}% jfm
4201 \thicklines
4202 \put(0,11){\vector(1,0){6}\vector(-1,0){6}\vector(0,-1){11}}
4203 \put(0,0){\line(1,0){6}\line(-1,0){6}}
4204 \put(-6,0){\line(0,1){11}}
4205 \put( 6,0){\line(0,1){11}}
4206 \put( 3,10.8){\makebox(0,0)[t]{\texttt{height}}}
4207 \put(-3,10.8){\makebox(0,0)[t]{\texttt{depth}}}
4208 \put(0.2,5.5){\makebox(0,0)[l]{\texttt{width}}}
4209
4210 \color{green}% step1
4211 \thicklines
4212 \put(-4,3){\vector(0,1){6}\vector(0,-1){3}\vector(1,0){8}}
4213 \put( 4,3){\line(0,1){6}\line(0,-1){3}}
4214 \put(-4,9){\line(1,0){8}}
4215 \put(-4,0){\line(1,0){8}}
4216 \savebox{\eqdist}(0,0)[b]{%
4217   \thinlines
4218   \put(-0.08,0.2){\line(0,-1){0.4}}%
4219   \put(0.08,0.2){\line(0,-1){0.4}}}
4220 \put(2,9){\usebox{\eqdist}}
4221 \put(-2,9){\usebox{\eqdist}}
4222
4223
4224 \color{blue}% shifted
4225 \thicklines
4226 \put(-4,3){\vector(0,1){2.5}}
4227 \put(-3.8,4.25){\makebox(0,0)[l]{\texttt{left}}}
4228 \put(-4,5.5){\vector(-1,0){2.5}}
4229 \put(-5.,5.7){\makebox(0,0)[b]{\texttt{down}}}
4230 \end{picture}
4231 \end{center}
4232 \end{minipage}%
4233 \begin{minipage}{0.6\textwidth}%
4234 %<*en>
4235 (\dots)
4236 %</en>
4237 %<*ja>
4238 \texttt{align}フィールドの値が \texttt{'right'} であるような文字クラスに属する
4239 和文文字を考えよう.
4240 \begin{itemize}
4241 \item
4242 実際のグリフの「垂直位置」は,まずベースラインが文字の物理的な左右方向の中央を通る
4243 位置となる.
4244 \item
4245 また,この場合 \texttt{align} フィールドは \texttt{'right'} なので,
4246 「水平位置」は字送り方向に「右寄せ」したものとなる(緑色の長方形).
4247 \item
4248 その後さらに \texttt{left} と \texttt{down} の値に従ってシフトされる
4249 のは横組用和文フォントと変わらない.
4250 \end{itemize}
4251 %</ja>
4252 \end{minipage}
4253 \medskip
4254
4255 \caption{%
4256 %<en>The position of the real glyph (vertical Japanese fonts)
4257 %<ja>縦組和文フォントにおける「実際の」グリフの位置
4258 }
4259 \label{fig:pos-tate}
4260 \end{figure}
4261
4262 \item[kern={\{[$j$]=<kern>, [$j'$]=\{<kern>, [ratio=<ratio>]\}, ...\}}]
4263 \nopagebreak
4264 \item[glue={\{[$j$]=\{<width>, <stretch>, <shrink>, [ratio=<ratio>, ...]\}, ...\}}]\leavevmode
4265 %<*ja>
4266
4267 文字クラス$i$の文字と$j$の文字の間に挿入されるカーンやグルーの量を指定する.
4268
4269 <ratio>は,グルーの自然長のうちどれだけの割合が「後の文字」由来かを示す量で,
4270 $0$から$+1$の実数値をとる.省略時の値は$0.5$である.
4271 このフィールドの値は\Param{differentjfm}の値が
4272 \texttt{pleft},~\texttt{pright},~\texttt{paverage}の値のときのみ実際に用いられる.
4273
4274 例えば,\cite{x4051}では,句点と中点の間には,
4275 句点由来の二分空きと中点由来の四分空きが挿入されるが,この場合には
4276 \begin{itemize}
4277 \item <width>には$0.5+0.25=0.75$を指定する.
4278 \item <ratio>には$0.25/(0.5+0.25)=1/3$を指定する.
4279 \end{itemize}
4280 %</ja>
4281 %<*en>
4282 \
4283
4284 Specifies the amount of kern or glue which will be inserted
4285 between characters in character class~$i$ and those in character class~$j$.
4286
4287 <ratio> specifies how much the glue is originated in the ``right'' character.
4288 It is a real number between 0 and 1, and treated as 0.5 if omitted. For example,
4289 The width of a glue between an ideographic full stop ``。''
4290 and a fullwidth middle dot ``・'' is three-fourth of fullwidth,
4291 namely halfwidth from the ideographic full stop, and
4292 quarter-width from the fullwidth middle dot.  In this case,
4293 we specify <ratio> to $0.25/(0.5+0.25)=1/3$.
4294 %</en>
4295
4296 %<*ja>
4297 グルーの指定においては,上記に加えて各 \texttt{[$j$]} の各サブテーブル内に
4298 次のキーを指定できる,
4299 \begin{cslist}[style=standard]
4300 \item[priority=<priority>]
4301              \Pkg{luatexja-adjust}による優先順位付き
4302              行長調整(\ref{ssec:adj}節)において,このグルーの優先度を指定する.許される値は以下の通り:
4303   \begin{description}
4304     \item[バージョン1] $-4$から$+3$の間の整数
4305     \item[バージョン2以降] $-4$から$+3$の間の整数の2つ組\texttt{\{<stretch>, <shrink>\}}か,
4306     または$-4$から$+3$の間の整数.<stretch>, <shrink>はそれぞれこのグルーが伸びるときの優先度,縮むときの
4307     優先度であり,単に整数$i$が指定された場合は\texttt{\{$i$, $i$\}}であると解釈される.
4308   \end{description}
4309   ここで指定する値は,大きい値ほど「先に伸ばされる」「先に縮ませる」ことを意味しており,省略時の値
4310              は0である.範囲外の値が指定されたときの動作は未定義である.
4311 \item[kanjiskip\_natural=<num>\textrm{, }%
4312   kanjiskip\_stretch=<num>\textrm{, }kanjiskip\_shrink=<num>]\leavevmode
4313   \label{pg:ksp_nat}
4314
4315 JFMによって本来挿入されるグルーの他に
4316 \Param{kanjiskip}分の空白を自然長(\texttt{kanjiskip\_natural}),伸び量(\texttt{kanjiskip\_stretch}),
4317 縮み量(\texttt{kanjiskip\_shrink})ごとに挿入する\footnote{本来\Param{xkanjiskip}が挿入される場所においては
4318              \Param{xkanjiskip}分の空白を自然長・伸び量・縮み量ごとに.追加できる.}%
4319 ための指定である.いずれも省略された場合のデフォルト値は0(追加しない)である.
4320
4321 例えば,\LuaTeX-jaの横組標準JFMの \texttt{jfm-ujis.lua} では,
4322 \begin{itemize}
4323  \item 通常の文字「あ」と開き括弧類の間に入るグルーは,自然長・縮み量半角,伸び量0のグルー
4324 となっているが,さらに\Param{kanjiskip}の伸び量に \texttt{kanjiskip\_stretch}(ここでは1)を掛け
4325        た分だけ伸びることが許される.
4326  \item 同様に,閉じ括弧類(全角コンマ「,」も含む)と通常の文字「う」「え」の間にも
4327 自然長・縮み量半角,伸び量0のグルー
4328 となっているが,さらに\Param{kanjiskip}の伸び量に \texttt{kanjiskip\_stretch}(ここでは1)を掛け
4329        た分だけ伸びることが許される.
4330  \item 一方,開き括弧類と通常の文字の間,また通常の文字と閉じ括弧類の間は
4331   自然長・縮み量・伸び量0のグルーだが,\Param{kanjiskip}の縮み量に
4332   \texttt{kanjiskip\_shrink}(ここでは1)を掛けた分だけ縮むことが許される.
4333 \end{itemize}
4334 となっている.従って,以下のような組版結果を得る.
4335
4336 \medskip
4337 \begin{LTXexample}[width=16\zw]
4338 \leavevmode
4339 \ltjsetparameter{kanjiskip=0pt plus 3\zw}
4340 \vrule\hbox to 15\zw{あ「い」う,えお}\vrule
4341
4342 \vrule\hbox{あ「い」う,えお}\vrule\par
4343 \ltjsetparameter{kanjiskip=0pt minus \zw}
4344 \vrule\hbox to 6.5\zw{あ「い」う,えお}\vrule
4345 \end{LTXexample}
4346
4347 \end{cslist}
4348 %</ja>
4349 %<*en>
4350 In case of glue, one can specify following additional keys in each \texttt{[$j$]}
4351              subtable:
4352 \begin{cslist}[style=standard]
4353 \item[priority=<priority>]
4354 An integer in $[-4,3]$ (treated as 0 if omitted), or
4355 a pair of these integers \texttt{\{<stretch>, <shrink>\}} (version 2~or~later).
4356 This is
4357 used only in line adjustment with priority by \Pkg{luatexja-adjust}
4358 (see Subsection~\ref{ssec:adj}). Higher value means the glue is easy to stretch,
4359 and is also easy to shrink. 
4360 \item[kanjiskip\_natural=<num>\textrm{, }%
4361   kanjiskip\_stretch=<num>\textrm{, }kanjiskip\_shrink=<num>]\leavevmode
4362
4363 These keys specifies the amount of the natural width of \Param{kanjiskip}
4364 (the stretch/shrink part, respectively) which will be inserted
4365 in addition to the original JFM glue. Default values of them are all 0.
4366
4367 As an example, in \texttt{jfm-ujis.lua}, the standard JFM in horizontal writing, we have
4368 \begin{itemize}
4369  \item Between an ordinal letter ``あ'' and an ideographic opening bracket, we have
4370 a glue whose natural part and shrink part are both half-width, while its stretch part is
4371        zero. However, this glue also can be stretched
4372        as much as the stretch part of \Param{kanjiskip} times the value of
4373        \texttt{kanjiskip\_stretch} key (1 in this case).
4374  \item Between an ideographic closeing brackets (the ideographic comma ``,''
4375        is included) and an ordinal letter, we have the same glue.
4376        Again, this glue also can be stretched
4377        as much as the stretch part of \Param{kanjiskip} times the value of
4378        \texttt{kanjiskip\_stretch} key (1 in this case).
4379  \item Between an ideographic opening bracket and an ordinal letter
4380   and between an ordinal letter and an ideographic closing bracket,
4381   we have a glue whose natural part and stretch part are both zero, while its shrink part as much as
4382   the shrink part of \Param{kanjiskip}.
4383 \end{itemize}
4384 Hence we have the following result:
4385
4386 \medskip
4387 \begin{LTXexample}[width=16\zw]
4388 \leavevmode
4389 \ltjsetparameter{kanjiskip=0pt plus 3\zw}
4390 \vrule\hbox to 15\zw{あ「い」う,えお}\vrule
4391
4392 \vrule\hbox{あ「い」う,えお}\vrule\par
4393 \ltjsetparameter{kanjiskip=0pt minus \zw}
4394 \vrule\hbox to 6.5\zw{あ「い」う,えお}\vrule
4395 \end{LTXexample}
4396
4397 \end{cslist}
4398 %</en>
4399   
4400 \item[end\_stretch=<kern>, end\_shrink=<kern>]
4401 %<*ja>
4402 (任意,バージョン1のみ)
4403
4404 優先順位付き行長調整が有効であり,かつ現在の文字クラスの文字が行
4405              末に来た時に,行長を詰める調整・伸ばす調整のた
4406              めにこの文字と行末の間に挿入可能なカーンの大きさを指定する.
4407 %</ja>
4408 %<*en>
4409 (optional, version~1 only)
4410 %</en>
4411
4412   \item[end\_adjust=\{<kern>, <kern>, ...\}]
4413 %<*ja>
4414 (任意,バージョン2以降)
4415
4416 優先順位付き行長調整が有効であり,かつ現在の文字クラスの文字が
4417   行末に来た時に,この文字と行末の間には指定された値のいずれかの大きさのカーンが
4418   挿入される(\autoref{ssec:adj}参照).
4419
4420 バージョン1における
4421 \begin{lstlisting}[escapechar=\$]
4422     end_stretch = $a$, end_shrink = $b$
4423 \end{lstlisting}
4424 という指定は,バージョン2以降では次の指定と同じになる.
4425 \begin{lstlisting}[escapechar=\$]
4426     end_adjust = {$-b$, 0.0, $a$}
4427 \end{lstlisting}
4428 もし真ん中の \texttt{0.0} がない場合は,$a$か$-b$かいずれかのカーンが常に行末に追加される.
4429 %</ja>
4430 %<*en>
4431 (optional, version~2 or~later)
4432 %</en>
4433
4434 \end{cslist}
4435
4436 %<*ja>
4437 \paragraph{文字クラスの決定}
4438 文字からその文字の属する文字クラスを算出する過程について,
4439 次の内容を含んだ \texttt{jfm-test.lua} を用いて説明する.
4440 %</ja>
4441 %<*en>
4442 \paragraph{Character to character classes}
4443 We explain how the character class of a character is determined,
4444 using  \texttt{jfm-test.lua} which contains the following:
4445 %</en>
4446 \begin{lstlisting}
4447    [0] = {
4448       chars = { '漢' },
4449       align = 'left', left = 0.0, down = 0.0,
4450       width = 1.0, height = 0.88, depth = 0.12, italic=0.0,
4451    },
4452    [2000] = {
4453       chars = { '。', 'ヒ' },
4454       align = 'left', left = 0.0, down = 0.0,
4455       width = 0.5, height = 0.88, depth = 0.12, italic=0.0,
4456    },
4457 \end{lstlisting}
4458 %<ja>ここで,次のような入力とその実行結果を考える:
4459 %<en>Now consider the following input/output:
4460 \begin{LTXexample}[width=0.3\textwidth]
4461 \jfont\a=file:KozMinPr6N-Regular.otf:jfm=test;+hwid
4462 \setbox0\hbox{\a ヒ漢}
4463 \the\wd0
4464 \end{LTXexample}
4465 %<*en>
4466 Now we look why the above source outputs 15\,pt.
4467 \begin{enumerate}
4468 \item The character ``ヒ'' is converted to its half width  form ``ヒ'' by \verb+hwid+ feature.
4469 \item According to the JFM, the character class of ``ヒ'' is 2000, hence its width is halfwidth.
4470 \item The character class of ``漢'' is zero,  hence its width is fullwidth.
4471 \item Hence the width of \cs{hbox} equals to 15\,pt.
4472 \end{enumerate}
4473 This example shows that the character class of a character is generally determined \emph{after
4474 applying font features by \Pkg{luaotfload}}.
4475 %</en>
4476 %<*ja>
4477 上記の出力結果が,15\,ptとなっているのは理由によるものである:
4478 \begin{enumerate}
4479 \item \verb+hwid+ featureによって「ヒ」が半角幅のグリフ「ヒ」と置き換わる(\Pkg{luaotfload} による処理).
4480 \item JFMによれば,この「ヒ」のグリフの文字クラスは2000である.
4481 \item 以上により文字クラス2000とみなされるため,結果として「ヒ」の幅は半角だと認識される.
4482 \end{enumerate}
4483 この例は,\emph{文字クラスの決定はfont featureの適用によるグリフ置換の結果に基づく}ことを
4484 示している.
4485 %</ja>
4486
4487 %<*en>
4488 However, if the class determined by the glyph after application of features is zero,
4489 \LuaTeX-ja adopts the class determined by the glyph \emph{before} application of features.
4490 The following input is an example.
4491 %</en>
4492 %<*ja>
4493 但し,JFMによって決まる置換後のグリフの文字クラスが0である場合は,置換前の文字クラスを採用する.
4494 %</ja>
4495 \begin{LTXexample}[width=0.3\textwidth]
4496 \jfont\a=file:KozMinPr6N-Regular.otf:jfm=test;+vert
4497 \a 漢。\inhibitglue 漢
4498 \end{LTXexample}
4499 %<*en>
4500 Here, the character class of the ideographic full stop ``。''~(\texttt{U+3002}) is determined
4501 as follows:
4502 \begin{enumerate}
4503 \item As the case of ``ヒ'', the ideographic full stop ``。'' is converted to its vertical
4504       form ``\char"FE12''~(\texttt{U+FE12}) by \verb+vert+ feature.%"
4505 \item The character class of ``\char"FE12'', according to the JFM  is \emph{zero}.
4506 \item However, \LuaTeX-ja remembers that this ``\char"FE12'' is obtained from ``。'' by
4507       font features. The character class of ``。'' is \emph{non-zero value}, namely, 2000.
4508 \item Hence the ideographic full stop ``。'' in above belongs the character class~2000.
4509 \end{enumerate}
4510 %</en>
4511 %<*ja>
4512 ここで,句点「。」(\texttt{U+3002})の文字クラスは,以下のようにして決まる.
4513 \begin{enumerate}
4514 \item \Pkg{luaotfload} によって縦組用句点のグリフに置き換わる.
4515 \item 置換後のグリフは \texttt{U+FE12} であり,JFMに従えば文字クラスは\emph{0}と判定される.
4516 \item この場合,置換前の横組用句点のグリフによって文字クラスを判定する.
4517 \item 結果として,上の出力例中の句点の文字クラスは2000となる.
4518 \end{enumerate}
4519 %</ja>
4520
4521
4522 %<ja>\paragraph{仮想的な文字}
4523 %<en>\paragraph{Imaginary characters}
4524 %<*en>
4525 As described before, you can specify several \emph{imaginary characters} in
4526 \texttt{chars} field. The most of these characters are regarded as the
4527 characters of class 0 in \pTeX.
4528 As a result, \LuaTeX-ja can control typesetting finer than \pTeX.
4529 The following is the list of imaginary characters:
4530 %</en>
4531 %<*ja>
4532 上で説明した通り,\texttt{chars}フィールド中にはいくつかの「特殊文字」も
4533 指定可能である.これらは,大半が\pTeX のJFMグルーの挿入処理ではみな「文字
4534 クラス0の文字」として扱われていた文字であり,その結果として\pTeX より細か
4535 い組版調整ができるようになっている.以下でその一覧を述べる:
4536 %</ja>
4537
4538 \begin{cslist}
4539 %%\item['diffmet']
4540 %%<en>Used at a boundary between two \textbf{JAchar}s whose JFM or size is different.
4541 %%<ja>JFMやサイズが異なる2つの\textbf{JAchar}の間の境界として用いられる.
4542
4543 \item['boxbdd']
4544 %<en>The beginning/ending of a hbox, and the beginning of a noindented (i.e., began by \cs{noindent}) paragraph.
4545 %<ja>hboxの先頭と末尾,及びインデントされていない(\cs{noindent} で開始された)段落の先頭を表す.
4546
4547 \item['parbdd']
4548 %<en>The beginning of an (indented) paragraph.
4549 %<ja>通常の(\cs{noindent} で開始されていない)段落の先頭.
4550
4551 \item['jcharbdd']
4552 %<en>A boundary between \textbf{JAchar} and anything else.
4553 %<*ja>
4554 \textbf{JAchar}と「その他のもの」との境界.
4555
4556 バージョン2以前では\textbf{ALchar},箱,罫線(rule),glue,~kernなどいろいろなものと\textbf{JAchar}の境界に対して
4557 本特殊文字が用いられていたが,
4558 バージョン3以降では\ \texttt{'jcharbdd'}, \texttt{'alchar'}, \texttt{'nox\_alchar'},
4559 \texttt{'glue'} と細分化され,
4560 \texttt{'jcharbdd'} は主に\textbf{JAchar}とボックスや罫線(rule)との境界に使われるようになった.
4561 %</ja>
4562   
4563 \item['alchar', 'nox\_alchar']
4564 %<*en>
4565 (version 3~or~later) A boundary between \textbf{JAchar} and \textbf{ALchar}.
4566 %</en>
4567 %<*ja>
4568 (バージョン3以降)\textbf{JAchar}と\textbf{ALchar}との境界.
4569 \textbf{JAchar}と\textbf{ALchar}の間に\Param{xkanjiskip}が入ることが可能な場合は
4570 \ \texttt{'alchar'}\ が,そうでない場合は\ \texttt{'nox\_alchar'}\ が用いられる
4571 (この区別は\textbf{ALchar}側の\Param{alxspmode}の値によってのみ行われる).
4572 %</ja>
4573
4574 \item['glue']
4575 %<en>(version 3~or~later) A boundary between \textbf{JAchar}, and, a glue or kern.
4576 %<ja>(バージョン3以降)\textbf{JAchar}とglue,kernとの境界.
4577
4578 \item[$-1$]
4579 %<en>The left/right boundary of an inline math formula.
4580 %<ja>行中数式と地の文との境界.
4581 \end{cslist}
4582
4583 %<en>\paragraph{Porting JFM from \pTeX}
4584 %<ja>\paragraph{\pTeX 用和文用TFMの移植}
4585
4586 % ToDo: English version.
4587
4588 %<*en>
4589 See Japanese version of this manual.
4590 %</en>
4591
4592 %<*ja>
4593 以下に,\pTeX 用に作られた和文用TFMを\LuaTeX-ja用に移植する場合の注意点を挙げておく.
4594 \begin{itemize}
4595 \item 実際に出力される和文フォントのサイズがdesign sizeとなる.
4596 このため,例えば$1\,\textrm{zw}$がdesign sizeの0.962216倍であるJISフォン
4597       トメトリック等を移植する場合は,次のようにするべきである:
4598 \begin{itemize}
4599 \item JFM中の全ての数値を$1/0.962216$倍しておく.
4600 \item \TeX ソース中で使用するところで,サイズ指定を0.962216倍にする.
4601       \LaTeX でのフォント宣言なら,例えば次のように:
4602 \begin{lstlisting}
4603 \DeclareFontShape{JY3}{mc}{m}{n}{<-> s*[0.962216] psft:Ryumin-Light:jfm=jis}{}
4604 \end{lstlisting}
4605 \end{itemize}
4606 \item 上に述べた特殊文字は,\texttt{'boxbdd'}を除き文字クラスを全部0とする
4607       (JFM中に単に書かなければよい).
4608 \item \texttt{'boxbdd'}については,それのみで一つの文字クラスを形成し,その
4609       文字クラスに関してはグルー/カーンの設定はしない.
4610
4611 これは,\pTeX では,
4612       hboxの先頭・末尾とインデントされていない(\cs{noindent} で開始さ
4613       れた)段落の先頭にはJFMグルーは入らないという仕様を実現させるためである.
4614 \item \pTeX の組版を再現させようというのが目的であれば以上の注意を守れば十分である.
4615
4616 ところで,\pTeX では通常の段落の先頭にJFMグルーが残るという仕様があるので,
4617       段落先頭の開き括弧は全角二分下がりになる.全角下がりを実現させるに
4618       は,段落の最初に手動で \cs{inhibitglue} を追加するか,あるいは
4619       \ \cs{everypar} のハックを行い,それを自動化させるしかなかった.
4620
4621 一方,\LuaTeX-jaでは,\texttt{'parbdd'}によって,それがJFM側で調整できるよ
4622 うになった.例えば,\LuaTeX-ja同梱のJFMのように,\texttt{'boxbdd'}と同じ文字クラスに
4623 \texttt{'parbdd'}を入れれば全角下がりとなる.
4624
4625 \begin{LTXexample}[width=0.4\textwidth]
4626 \jfont\g=KozMinPr6N-Regular:jfm=test \g
4627 \parindent1\zw\noindent{}◆◆◆◆◆
4628 \par 「◆◆←二分下がり
4629 \par 【◆◆←全角下がり
4630 \par 〔◆◆←全角二分下がり
4631 \end{LTXexample}
4632 \end{itemize}
4633
4634 但し,\cs{everypar} を利用している場合にはこの仕組みは正しく動かない.
4635 そのような例としては箇条書き中の \cs{item} で始まる段落があり,\Pkg{ltjsclasses}では
4636 人工的に「\texttt{'parbdd'}の意味を持つ」whatsitノードを作ることによって対処している%
4637 \footnote{\texttt{ltjsclasses.dtx} を参照されたい.
4638 JFM側で一部の対処ができることにより,\Pkg{jsclasses}のようにif文の判定はしていない.}.
4639 %</ja>
4640
4641
4642 %<en>\subsection{Math font family}
4643 %<ja>\subsection{数式フォントファミリ}
4644 \label{ssec:math}
4645
4646 %<*en>
4647 \TeX\ handles fonts in math formulas by 16~font families\footnote{Omega,
4648 Aleph, \LuaTeX~and $\varepsilon$-\kern-.125em(u)\pTeX\ can handles 256~families, but
4649 an external package is needed to support this in plain \TeX\ and
4650 \LaTeX.}, and each family has three fonts:
4651 \cs{textfont}, \cs{scriptfont} and \cs{scriptscriptfont}.
4652 %</en>
4653 %<*ja>
4654 \TeX\ は数式フォントを16のファミリ\footnote{Omega, Aleph, \LuaTeX,そして
4655   $\varepsilon$-\kern-.125em(u)\pTeX\ では256の数式ファミリを扱うことができるが,
4656   これをサポートするためにplain \TeX と\LaTeX では外部パッケージを読み込む必要が
4657   ある.}で管理し,それぞれのファミリは3つのフォントを持っている:
4658 \cs{textfont}, \cs{scriptfont} そして \cs{scriptscriptfont} である.
4659 %</ja>
4660
4661 %<*en>
4662 \LuaTeX-ja's handling of Japanese fonts in math formulas is similar;
4663 \autoref{tab-math} shows counterparts to \TeX's primitives for math
4664 font families. There is no relation between the value of
4665 \cs{fam} and that of \cs{jfam}; with appropriate settings,
4666 you can set both \cs{fam} and \cs{jfam} to the same value.
4667 Here <jfont\_cs> in the argument of \Param{jatextfont} etc.\ is
4668 a control sequence which is defined by \cs{jfont}, i.e.,
4669 a \emph{horizontal} Japanese font.
4670 %</en>
4671 %<*ja>
4672 \LuaTeX-jaの数式中での和文フォントの扱いも同様である.
4673 \autoref{tab-math}は数式フォントファミリに対する \TeX のプリミティブと対応する
4674 ものを示している.\cs{fam} と \cs{jfam} の値の間には関係はなく,
4675 適切な設定の下では \cs{fam} と \cs{jfam} の両方に同じ値を設定することができる.
4676 \Param{jatextfont} 他の第2引数<jfont\_cs>は,\cs{jfont} で定義された
4677 \emph{横組用}和文フォントである.\cs{tfont} で定義された
4678 \emph{縦組用}和文フォントを指定することは想定していない.
4679 %</ja>
4680
4681 \begin{table}[!tb]
4682 %<en>\caption{Commands for Japanese math fonts}
4683 %<ja>\caption{和文数式フォントに対する命令}
4684 \label{tab-math}
4685 %<en>\medskip
4686 \centering
4687 \def\{{\char`\{}\def\}{\char`\}}\small
4688 \begin{tabular}{ll}
4689 \toprule
4690 %<en>\bf Japanese fonts&\bf alphabetic fonts\\
4691 %<ja>\bf 和文フォント&\bf 欧文フォント\\
4692 \midrule
4693 \cs{jfam}${}\in [0,256)$&\cs{fam}\\
4694 \tt\Param{jatextfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\cs{textfont}<fam>=<font\_cs>\\
4695 \tt\Param{jascriptfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\cs{scriptfont}<fam>=<font\_cs>\\
4696 \tt\Param{jascriptscriptfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\cs{scriptscriptfont}<fam>=<font\_cs>\\
4697 \bottomrule
4698 \end{tabular}
4699 \end{table}
4700
4701 %<en>\subsection{Callbacks}
4702 %<ja>\subsection{コールバック}
4703
4704 %<*en>
4705 \LuaTeX-ja also has several callbacks. These callbacks can
4706 be accessed via \verb+luatexbase.add_to_callback+ function and so on, as other callbacks.
4707 %</en>
4708 %<*ja>
4709 \LuaTeX 自体のものに加えて,\LuaTeX-jaもコールバックを持っている.
4710 これらのコールバックには,他のコールバックと同様に \verb+luatexbase.add_to_callback+
4711 関数などを用いることでアクセスすることができる.
4712 %</ja>
4713 \begin{description}[font=\bfseries, style=nextline]
4714 %<en>\item[\texttt{luatexja.load\_jfm} callback]
4715 %<ja>\item[\texttt{luatexja.load\_jfm}コールバック]
4716 %<*en>
4717 With this callback you can overwrite JFMs.
4718 This callback is called when a new JFM is loaded.
4719 %</en>
4720 %<*ja>
4721 このコールバックを用いることでJFMを上書きすることができる.
4722 このコールバックは新しいJFMが読み込まれるときに呼び出される.
4723 %</ja>
4724
4725 \begin{lstlisting}[numbers=left]
4726 function (<table> jfm_info, <string> jfm_name)
4727   return <table> new_jfm_info
4728 end
4729 \end{lstlisting}
4730
4731 %<*en>
4732 The argument \verb+jfm_info+ contains a table similar to the table in a JFM file, except
4733 this argument has \texttt{chars} field which contains character codes
4734              whose character class is not~0.
4735 %</en>
4736 %<*ja>
4737 引数 \verb+jfm_info+ はJFMファイルのテーブルと似たものが格納されるが,
4738 クラス0を除いた文字のコードを含んだ\texttt{chars}フィールドを持つ点が異なる.
4739 %</ja>
4740
4741 %<*en>
4742 An example of this callback is the \texttt{ltjarticle} class, with
4743              forcefully assigning character class~0 to \texttt{'parbdd'}
4744              in the JFM \texttt{jfm-min.lua}.
4745 %</en>
4746 %<*ja>
4747 このコールバックの使用例は\texttt{ltjarticle}クラスにあり,
4748 \texttt{jfm-min.lua}中の\texttt{'parbdd'}を強制的にクラス0に割り当てている.
4749 %</ja>
4750
4751 %<en>\item[\texttt{luatexja.define\_jfont} callback]
4752 %<ja>\item[\texttt{luatexja.define\_jfont}コールバック]
4753 %<*en>
4754 This callback and the next callback form a pair, and you can assign characters
4755  which do not have fixed code points in Unicode to non-zero character classes.
4756 This \texttt{luatexja.define\_font} callback is called just when new Japanese font is loaded.
4757 %</en>
4758 %<*ja>
4759 このコールバックと次のコールバックは組をなしており,Unicode中に固定された文字コード
4760 番号を持たない文字を非零の文字クラスに割り当てることができる.
4761 このコールバックは新しい和文フォントが読み込まれたときに呼び出される.
4762 %</ja>
4763
4764 \begin{lstlisting}[numbers=left]
4765 function (<table> jfont_info, <number> font_number)
4766   return <table> new_jfont_info
4767 end
4768 \end{lstlisting}
4769 %<*en>
4770 \verb+jfont_info+ has the following fields,
4771 \emph{which may not overwritten by a user}:
4772 \begin{description}
4773 \item[\texttt{size}]
4774 The font size specified at \cs{jfont} in scaled points ($1\,\mathrm{sp}=2^{-16}\,\mathrm{pt}$).
4775 \item[\texttt{zw}, \texttt{zh}, \texttt{kanjiskip}, \texttt{xkanjiskip}]
4776 These are scaled value of those specified by the JFM, by the font size.
4777 \item[\texttt{jfm}]
4778 The internal number of the JFM.
4779 \item[\texttt{var}]
4780 The value of \texttt{jfmvar}~key, which is specified at \cs{jfont}.
4781 The default value is the empty string.
4782 \item[\texttt{chars}]
4783 The mapping table from character codes to its character classes.\\
4784 The specification \texttt{[i].chars=\{<character>, ...\}} in the JFM will be  stored in this
4785            field as \texttt{chars=\{[<character>]=\,$i$, ...\}}.
4786 \item[\texttt{char\_type}]
4787 For $i\in\omega$, \texttt{char\_type[$i$]} is information of characters whose class is
4788            $i$, and has the following fields:
4789 \begin{itemize}
4790  \item \texttt{width},~\texttt{height}, \texttt{depth},
4791   \texttt{italic}, \texttt{down},~\texttt{left}\ are just
4792        scaled value of those specified by the JFM, by the font size.
4793  \item \texttt{align} is a number which is determined from \texttt{align}~field in the JFM:
4794 \[
4795  \begin{cases}
4796   0&\text{\texttt{'left'} (default)}\\0.5&\text{\tt 'middle'}\\1&\text{\tt 'right'}
4797  \end{cases}
4798 \]
4799 \end{itemize}
4800 For $i$,~$j\in \omega$, \texttt{char\_type[$i$][$j$]} stores a kern or a glue which will be inserted
4801 between character class~$i$ and class~$j$.
4802 \end{description}
4803 %</en>
4804 %<*ja>
4805 \verb+jfont_info+ は最低限以下のフィールドを持つが,これらを書き換えてはならない:
4806 \begin{cslist}
4807 \item[size]
4808 実際に使われるフォントサイズ(sp単位).$1\,\mathrm{sp}=2^{-16}\,\mathrm{pt}$.
4809 \item[zw\textrm{, }zh\textrm{, }kanjiskip\textrm{, }xkanjiskip]
4810 JFMファイルで指定されているそれぞれの値をフォントサイズに合わせてスケーリングしたものを
4811 sp単位で格納している.
4812 \item[jfm]
4813 利用されているJFMを識別するための番号.
4814 \item[var]
4815 \cs{jfont},~\cs{tfont} で指定された \texttt{jfmvar} キーの値(未指定のときは空文字列).
4816 \item[chars]
4817 文字コードから文字クラスへの対応が記述されたテーブル.\\
4818 JFM内の \texttt{[i].chars=\{<character>, ...\}} という指定は\
4819 \texttt{chars=\{[<character>]=\,$i$, ...\}} という形式に変換されている.
4820 \item[char\_type]
4821 $i\in\omega$に対して,\texttt{char\_type[$i$]} は文字クラス$i$の文字の寸法を格納しており,
4822 以下のフィールドを持つ.
4823 \begin{itemize}
4824  \item \texttt{width},~\texttt{height}, \texttt{depth},
4825   \texttt{italic}, \texttt{down},~\texttt{left}\ は
4826 JFMで指定されているそれぞれの値をスケーリングしたものである.
4827  \item \texttt{align} はJFMで指定されている値によって,
4828 \[
4829  \begin{cases}
4830   0&\text{\texttt{'left'}や省略時}\\0.5&\text{\tt 'middle'}\\1&\text{\tt 'right'}
4831  \end{cases}
4832 \]
4833 のいずれかの値をとる.
4834 \end{itemize}
4835 $i$,~$j\in \omega$に対して,\texttt{char\_type[$i$][$j$]} は
4836 文字クラス$i$の文字と$j$の文字の間に挿入されるグルーやカーンを格納している.
4837 \begin{itemize}
4838   \item 間に入るものがカーンであれば,この値は\
4839 \texttt{[$j$]=\{[1]=<kern\_node>, ratio=<ratio>\}} であり,
4840 <kern\_node>はカーンを表すノードそのものである\footnote{%
4841 バージョン20150420.0以降ではノードのアクセス手法にdirect access
4842       modelを用いている.そのため,例えば\LuaTeX\ beta-0.78.2では,単なる自然数のようにし
4843       か見えないことに注意.
4844 }.
4845   \item グルーであれば,この値は以下のキーを持つテーブルである.
4846   \begin{description}
4847     \item[\texttt{width}, \texttt{stretch}, \texttt{shrink}]
4848     グルーのそれぞれ自然長,伸び量,縮み量をsp単位で表したもの.
4849     \item[\texttt{priority}] バ(ージョン2以降の)JFMでの指定 \texttt{\{<stretch>,<shrink>\}} を
4850     \[
4851       (\text{<stretch>}+4)\cdot 8+\text{<shrink>}+4
4852     \]
4853     として0--63の整数にパックしたもの.
4854     \item[\texttt{ratio}, \texttt{kanjiskip\_natural}, \texttt{kanjiskip\_stretch}, \texttt{kanjiskip\_shrink}]
4855     JFM中の同名のフィールドの値がそのまま使われている.
4856   \end{description}
4857 \end{itemize}
4858 \item[ascent\textrm{, }descent]
4859 ……
4860 \item[chars\_cbcache]
4861 文字クラス決定の処理で.キャッシュとして使われる.
4862 \end{cslist}
4863 %</ja>
4864
4865 %<*en>
4866 The returned table \verb+new_jfont_info+ also should include these fields, but
4867 you are free to add more fields (to use them in the \texttt{luatexja.find\_char\_class} callback).
4868 The \verb+font_number+ is a font number.
4869 %</en>
4870 %<*ja>
4871 戻り値の \verb+new_jfont_info+ テーブルも上に述べたフィールドをそのまま含まなければならないが,
4872 それ以外にユーザが勝手にフィールドを付け加えることは自由である.
4873 \verb+font_number+ はフォント番号である.
4874 %</ja>
4875
4876 %<*en>
4877 A good example of this and the next callbacks is the \Pkg{luatexja-otf}
4878              package, supporting \verb+"AJ1-xxx"+ form for Adobe-Japan1
4879              CID characters in a JFM. This callback doesn't replace any
4880              code of \LuaTeX-ja.
4881 %</en>
4882 %<*ja>
4883 これと次のコールバックの良い使用例は\Pkg{luatexja-otf}パッケージであり,
4884 JFM中でAdobe-Japan1 CIDの文字を \verb+"AJ1-xxx"+ の形で指定するために
4885 用いられている.
4886 %</ja>
4887
4888 %<en>\item[\texttt{luatexja.find\_char\_class} callback]
4889 %<ja>\item[\texttt{luatexja.find\_char\_class}コールバック]
4890 %<*en>
4891 This callback is called just when \LuaTeX-ja is trying to determine which
4892              character class a character \verb+chr_code+ belongs.
4893 A function used in this callback should be in the following form:
4894 %</en>
4895 %<*ja>
4896 このコールバックは\LuaTeX-jaが \verb+chr_code+ の文字がどの文字クラスに
4897 属するかを決定しようとする際に呼び出される.
4898 このコールバックで呼び出される関数は次の形をしていなければならない:
4899 %</ja>
4900 \begin{lstlisting}[numbers=left]
4901 function (<number> char_class, <table> jfont_info, <number> chr_code)
4902   if char_class~=0 then return char_class
4903   else
4904     ....
4905     return (<number> new_char_class or 0)
4906   end
4907 end
4908 \end{lstlisting}
4909
4910 %<*en>
4911 The argument \verb+char_class+ is the result of \LuaTeX-ja's default
4912              routine or previous function calls in this callback, hence
4913              this argument may not be 0. Moreover, the returned
4914              \verb+new_char_class+ should be as same as \verb+char_class+ when \verb+char_class+
4915              is not~0, otherwise you will overwrite the \LuaTeX-ja's
4916              default routine.
4917 %</en>
4918 %<*ja>
4919 引数 \verb+char_class+ は\LuaTeX-jaのデフォルトルーチンか,このコールバックの
4920 直前の関数呼び出しの結果を含んでおり,したがってこの値は0ではないかもしれない.
4921 さらに,戻り値の \verb+new_char_class+ は \verb+char_class+ が非零のときには
4922 \verb+char_class+ の値と同じであるべきで,そうでないときは\LuaTeX-jaの
4923 デフォルトルーチンを書き換えることになる.
4924 %</ja>
4925
4926 %<en>\item[\texttt{luatexja.set\_width} callback]
4927 %<ja>\item[\texttt{luatexja.set\_width}コールバック]
4928 %<*en>
4929 This callback is called when \LuaTeX-ja is trying to encapsule a
4930              \textbf{JAchar} \textit{glyph\_node}, to adjust its
4931              dimension and position.
4932 %</en>
4933 %<*ja>
4934 このコールバックは\LuaTeX-jaが\textbf{JAchar}の寸法と位置を調節するために
4935 その\textit{glyph\_node}をカプセル化しようとする際に呼び出される.
4936 %</ja>
4937 \begin{lstlisting}[numbers=left]
4938 function (<table> shift_info, <table> jfont_info, <table> char_type)
4939   return <table> new_shift_info
4940 end
4941 \end{lstlisting}
4942
4943 %<*en>
4944 The argument \verb+shift_info+ and the returned \verb+new_shift_info+ have
4945 \texttt{down} and \texttt{left} fields, which are the amount of shifting
4946              down/left the character in a scaled point.
4947 %</en>
4948 %<*ja>
4949 引数 \verb+shift_info+ と戻り値の \verb+new_shift_info+ は
4950 \texttt{down}と\texttt{left}のフィールドを持ち,これらの値は
4951 文字の下/左へのシフト量(sp単位)である.
4952 %</ja>
4953
4954 %<*en>
4955 A good example is \Pkg{test/valign.lua}.
4956 After loading this file, the vertical position of glyphs is automatically
4957 adjusted; the ratio $(\hbox{height}:\hbox{depth})$ of glyphs is adjusted
4958 to be that of letters in the character class~0. For example, suppose that
4959 \begin{itemize}
4960 \item The setting of the JFM: $(\hbox{height})=88x$, $(\hbox{depth})=12x$
4961   (the standard values of Japanese OpenType fonts);
4962 \item The value of the real font: $(\hbox{height})=28y$, $(\hbox{depth})=5y$
4963   (the standard values of Japanese TrueType fonts).
4964 \end{itemize}
4965 Then, the position of glyphs is shifted up by
4966 %</en>
4967 %<*ja>
4968 良い例が\Pkg{test/valign.lua}である.このファイルが読み込まれた状態では,
4969              JFM内で規定された文字クラス0の文字における$(\hbox{高
4970              さ}):(\hbox{深さ})$の比になるように,実際のフォントの出力上
4971              下位置が自動調整される.例えば,
4972 \begin{itemize}
4973 \item JFM側の設定:$(\hbox{高さ})=88x$, $(\hbox{深さ})=12x$%
4974 (和文OpenTypeフォントの標準値)
4975 \item 実フォント側の数値:$(\hbox{高さ})=28y$, $(\hbox{深さ})=5y$(和文TrueTypeフォントの標準値)
4976 \end{itemize}
4977 となっていたとする.すると,実際の文字の出力位置は,以下の量だけ上にずらされることとなる:
4978 %</ja>
4979 \[
4980  \frac{88x}{88x+12x} (28y+5y) - 28y = \frac{26}{25}y= 1.04y.
4981 \]
4982 \end{description}
4983
4984
4985
4986 %<en>\section{Parameters}
4987 %<ja>\section{パラメータ}
4988 \subsection{\cs{ltjsetparameter}}
4989 \label{ssec:param}
4990
4991 %<*en>
4992 As described before, \cs{ltjsetparameter} and \cs{ltjgetparameter} are
4993 commands for accessing most parameters of \LuaTeX-ja. One of the main
4994 reason that \LuaTeX-ja didn't adopted the syntax similar to that of \pTeX\
4995 (\textit{e.g.},~\verb+\prebreakpenalty`)=10000+)
4996 is the position of \verb+hpack_filter+ callback in the source
4997 of \LuaTeX, see Section~\ref{sec-para}.
4998 %</en>
4999 %<*ja>
5000 先に述べたように,\LuaTeX-jaの内部パラメータにアクセスするには
5001 \cs{ltjsetparameter}(または \cs{ltjglobalsetparameter})と \cs{ltjgetparameter} を用いる.
5002 \LuaTeX-jaが\pTeX のような文法(例えば,\verb+\prebreakpenalty`)=10000+)を
5003 採用しない理由の一つは,\LuaTeX のソースにおける \verb+hpack_filter+
5004 コールバックの位置にある.\ref{sec-para}章を参照.
5005 %</ja>
5006
5007 %<*en>
5008 \cs{ltjsetparameter} and \cs{ltjglobalsetparameter} are commands
5009 for assigning parameters. These take one argument which is a
5010 \texttt{<key>=<value>} list.
5011 The difference between these two commands is the
5012 scope of assignment;
5013 \cs{ltjsetparameter} does a local assignment and
5014 \cs{ltjglobalsetparameter} does a global one.
5015 They also obey the value of \cs{globaldefs}, like other assignments.
5016 %</en>
5017 %<*ja>
5018 \cs{ltjsetparameter} と \cs{ltjglobalsetparameter} はパラメータを
5019 指定するための命令で,\texttt{<key>=<value>}のリストを
5020 引数としてとる.両者の違いはスコープであり,
5021 \cs{ltjsetparameter} はローカルな設定を行うのに対し,
5022 \cs{ltjglobalsetparameter} はグローバルな設定を行う.
5023 また,他のパラメータ指定と同様に \cs{globaldefs} の値にも従う.
5024 %</ja>
5025
5026 %<*en>
5027 The following is the list of parameters which can be specified by the
5028 \cs{ltjsetparameter} command. [\cs{cs}] indicates the counterpart
5029 in \pTeX, and symbols beside each parameter has the following meaning:
5030 %</en>
5031 %<*ja>
5032 以下は \cs{ltjsetparameter} に指定することができるパラメータの一覧である.
5033 [\cs{cs}]は\pTeX における対応物を示す.
5034 また,それぞれのパラメータの右上の記号には次の意味がある:
5035 %</ja>
5036 \begin{itemize}
5037 %<*en>
5038 \item ``$\ast$'' : values at the end of a paragraph or a hbox are
5039 adopted in the whole paragraph or the whole hbox.
5040 %</en>
5041 %<*ja>
5042 \item ``$\ast$'':段落やhboxの終端での値がその段落/hbox全体で用いられる.
5043 %</ja>
5044 %<*en>
5045 \item ``\dagger'': assignments are always global.
5046 %</en>
5047 %<*ja>
5048 \item ``\dagger'':指定は常にグローバルになる.
5049 %</ja>
5050 \end{itemize}
5051
5052 \begin{cslist}[style=standard]
5053 \item[\DParam{jcharwidowpenalty}\,=<penalty>$^\ast$] [\cs{jcharwidowpenalty}]\
5054
5055 %<*en>
5056 Penalty value for suppressing orphans. This penalty is inserted just
5057              after the last \textbf{JAchar} which is not regarded as a
5058              (Japanese) punctuation mark.
5059 %</en>
5060 %<*ja>
5061 パラグラフの最後の字が孤立して改行されるのを防ぐためのペナルティの値.
5062 このペナルティは(日本語の)句読点として扱われない最後の\textbf{JAchar}の直後に
5063 挿入される.
5064 %</ja>
5065
5066 \item[\DParam{kcatcode}\,=\{<chr\_code>,<natural number>\}$^\ast$]\
5067
5068 %<*en>
5069 An additional attributes which each character whose character code is <chr\_code> has.
5070 At version~20120506.0 or later, the lowermost bit of <natural number> indicates
5071              whether the character is considered as a punctuation mark
5072              (see the description of \Param{jcharwidowpenalty} above).
5073 %</en>
5074 %<*ja>
5075 文字コードが<chr\_code>の文字が持つ付加的な属性値.
5076 バージョン20120506.0以降では,<natural number>の最下位ビットが,その文字が句読点と
5077 みなされるかどうかを表している(上の\Param{jcharwidowpenalty}の記述を参照).
5078 %</ja>
5079
5080 \item[\DParam{prebreakpenalty}\,=\{<chr\_code>,<penalty>\}$^\ast$] [\cs{prebreakpenalty}]\
5081
5082 %<*ja>
5083 文字コード<chr\_code>の\textbf{JAchar}が行頭にくることを抑止するために,
5084              この文字の前に挿入/追加されるペナルティの量を指定する.
5085
5086 例えば閉じ括弧「〗」は絶対に行頭にきてはならないので,
5087 \begin{lstlisting}
5088 \ltjsetparameter{prebreakpenalty={`〙,10000}}
5089 \end{lstlisting}
5090 と,最大値の10000が標準で指定されている.他にも,小書きのカナなど,絶対禁止とい
5091              うわけではないができれば行頭にはきて欲しくない場合に,0と
5092              10000の間の値を指定するのも有用であろう.
5093
5094 \pTeX では,\cs{prebreakpenalty}, \cs{postbreakpenalty}において,
5095 \begin{itemize}
5096 \item 一つの文字に対して,pre, postどちらか一つしか指定することができない%
5097   \footnote{後から指定した方で上書きされる.}
5098 \item pre, post合わせて256文字分の情報を格納することしかできない
5099 \end{itemize}
5100 という制限があったが,\LuaTeX-jaではこれらの制限は解消されている.
5101 %</ja>
5102 %<*en>
5103 Set a penalty which is inserted automatically before the character <chr\_code>,
5104 to prevent a line starts from this character. For example, a line cannot started
5105 with one of closing brackets ``〗'', so \LuaTeX-ja sets
5106 \begin{lstlisting}
5107 \ltjsetparameter{prebreakpenalty={`〙,10000}}
5108 \end{lstlisting}
5109 by default.
5110
5111 \pTeX\ has following restrictions on \cs{prebreakpenalty} and \cs{postbreakpenalty},
5112 but they don't exist in \LuaTeX-ja:
5113 \begin{itemize}
5114  \item Both \cs{prebreakpenalty} and \cs{postbreakpenalty} cannot be set
5115 for the same character.
5116  \item We can set \cs{prebreakpenalty} and \cs{postbreakpenalty} up to 256~characters.
5117 \end{itemize}
5118 %</en>
5119
5120 \item[\DParam{postbreakpenalty}\,=\{<chr\_code>,<penalty>\}$^\ast$]
5121            [\cs{postbreakpenalty}]\
5122
5123 %<*ja>
5124 文字コード<chr\_code>の\textbf{JAchar}が行末にくることを抑止するために,
5125              この文字の後に挿入/追加されるペナルティの量を指定する.
5126 %</ja>
5127 %<*en>
5128 Set a penalty which is inserted automatically after the character <chr\_code>,
5129 to prevent a line ends with this character.
5130 %</en>
5131
5132 \item[\DParam{jatextfont}\,=\{<jfam>,<jfont\_cs>\}$^\ast$]
5133 %<en>[\cs{textfont} in \TeX]
5134 %<ja>[\TeX の \cs{textfont}]
5135 \item[\DParam{jascriptfont}\,=\{<jfam>,<jfont\_cs>\}$^\ast$]
5136 %<en>[\cs{scriptfont} in \TeX]
5137 %<ja>[\TeX の \cs{scriptfont}]
5138 \item[\DParam{jascriptscriptfont}\,=\{<jfam>,<jfont\_cs>\}$^\ast$]
5139 %<en>[\cs{scriptscriptfont} in \TeX]
5140 %<ja>[\TeX の \cs{scriptscriptfont}]
5141 \item[\DParam{yjabaselineshift}\,=<dimen>]\
5142 \item[\DParam{yalbaselineshift}\,=<dimen>] [\cs{ybaselineshift}]
5143 \item[\DParam{tjabaselineshift}\,=<dimen>]\
5144 \item[\DParam{talbaselineshift}\,=<dimen>] [\cs{tbaselineshift}]
5145
5146 \item[\DParam{jaxspmode}\,=\{<chr\_code>,<mode>\}$^\ast$]\
5147
5148 %<*en>
5149 Set whether inserting \Param{xkanjiskip} is allowed before/after a \textbf{JAchar} whose character code is <chr\_code>.
5150 The followings are allowed for <mode>:
5151 %</en>
5152 %<*ja>
5153 文字コードが<chr\_code>の\textbf{JAchar}の前/後ろに\Param{xkanjiskip}の
5154 挿入を許すかどうかの設定.
5155 以下の<mode>が許される:
5156 %</ja>
5157 \begin{description}
5158 %<en>\item[0, \texttt{inhibit}] Insertion of \Param{xkanjiskip} is inhibited before the character, nor after the character.
5159 %<ja>\item[0, \texttt{inhibit}] \Param{xkanjiskip}の挿入は文字の前/後ろのいずれでも禁止される.
5160 %<en>\item[1, \texttt{preonly}] Insertion of \Param{xkanjiskip} is allowed before the character, but not after.
5161 %<ja>\item[1, \texttt{preonly}] \Param{xkanjiskip}の挿入は文字の前では許されるが,後ろでは許されない.
5162 %<en>\item[2, \texttt{postonly}] Insertion of \Param{xkanjiskip} is allowed after the character, but not before.
5163 %<ja>\item[2, \texttt{postonly}] \Param{xkanjiskip}の挿入は文字の後ろでは許されるが,前では許されない.
5164 %<en>\item[3, \texttt{allow}] Insertion of \Param{xkanjiskip} is allowed both before the character and after the character. This is the default value.
5165 %<ja>\item[3, \texttt{allow}] \Param{xkanjiskip}の挿入は文字の前/後ろのいずれでも許される.これがデフォルトの値である.
5166 \end{description}
5167 %<*en>
5168 This parameter is similar to the \cs{inhibitxspcode} primitive of \pTeX, but not compatible with \cs{inhibitxspcode}.
5169 %</en>
5170 %<*ja>
5171 このパラメータは\pTeX の \cs{inhibitxspcode} プリミティブと似ているが,
5172 互換性はない.
5173 %</ja>
5174 \item[\DParam{alxspmode}\,=\{<chr\_code>,<mode>\}$^\ast$] [\cs{xspcode}]\
5175
5176 %<*en>
5177 Set whether inserting \Param{xkanjiskip} is allowed before/after a
5178              \textbf{ALchar} whose character code is <chr\_code>.
5179              The followings are allowed for <mode>:
5180 %</en>
5181 %<*ja>
5182 文字コードが<chr\_code>の\textbf{ALchar}の前/後ろに\Param{xkanjiskip}の
5183 挿入を許すかどうかの設定.
5184 以下の<mode>が許される:
5185 %</ja>
5186 \begin{description}
5187 %<en>\item[0, \texttt{inhibit}] Insertion of \Param{xkanjiskip} is inhibited before the character, nor after the character.
5188 %<ja>\item[0, \texttt{inhibit}] \Param{xkanjiskip}の挿入は文字の前/後ろのいずれでも禁止される.
5189 %<en>\item[1, \texttt{preonly}] Insertion of \Param{xkanjiskip} is allowed before the character, but not after.
5190 %<ja>\item[1, \texttt{preonly}] \Param{xkanjiskip}の挿入は文字の前では許されるが,後ろでは許されない.
5191 %<en>\item[2, \texttt{postonly}] Insertion of \Param{xkanjiskip} is allowed after the character, but not before.
5192 %<ja>\item[2, \texttt{postonly}] \Param{xkanjiskip}の挿入は文字の後ろでは許されるが,前では許されない.
5193 %<en>\item[3, \texttt{allow}] Insertion of \Param{xkanjiskip} is allowed before the character and after the character. This is the default value.
5194 %<ja>\item[3, \texttt{allow}] \Param{xkanjiskip}の挿入は文字の前/後ろのいずれでも許される.これがデフォルトの値である.
5195 \end{description}
5196 %<*en>
5197 Note that parameters \Param{jaxspmode} and \Param{alxspmode} share a common table, hence these two parameters are synonyms of each other.
5198 %</en>
5199 %<*ja>
5200 \Param{jaxspmode}と\Param{alxspmode}は共通のテーブルを用いているため,
5201 これら2つのパラメータは互いの別名となっていることに注意する.
5202 %</ja>
5203
5204 \item[\DParam{autospacing}\,=<bool>] [\cs{autospacing}]
5205 \item[\DParam{autoxspacing}\,=<bool>] [\cs{autoxspacing}]
5206 \item[\DParam{kanjiskip}\,=<skip>$^\ast$] [\cs{kanjiskip}]\
5207
5208 %<*ja>
5209 デフォルトで2つの\textbf{JAchar}の間に挿入されるグルーである.
5210 通常では,\pTeX と同じようにフォントサイズに比例して変わることはない.
5211 しかし,自然長が \cs{maxdimen} の場合は,例外的に和文フォントのJFM側で指定されている
5212 値を採用(こちらはフォントサイズに比例)することになっている.
5213 %</ja>
5214 %<*en>
5215 The default glue which inserted between two \textbf{JAchar}s.
5216 Changing current Japanese font does not alter this parameter, as \pTeX.
5217
5218 If the natural width of this parameter is \cs{maxdimen}, \LuaTeX-ja uses
5219 the value which is specified in the JFM for current Japanese font (See Subsection~\ref{ssec:jfm-str}).
5220 %</en>
5221
5222 \item[\DParam{xkanjiskip}\,=<skip>$^\ast$] [\cs{xkanjiskip}]\
5223
5224 %<*ja>
5225 デフォルトで\textbf{JAchar}と\textbf{ALchar}の間に挿入されるグルーである.
5226 \Param{kanjiskip}と同じように,通常ではフォントサイズに比例して変わることはないが,
5227 自然長が \cs{maxdimen} の場合が例外である.
5228 %</ja>
5229 %<*en>
5230 The default glue which inserted between a \textbf{JAchar} and an
5231       \textbf{ALchar}.
5232 Changing current font does not alter this parameter, as \pTeX.
5233
5234 As \Param{kanjiskip}, if the natural width of this parameter is \cs{maxdimen}, \LuaTeX-ja uses
5235 the value which is specified in the JFM for current Japanese font (See Subsection~\ref{ssec:jfm-str}).
5236 %</en>
5237
5238
5239 \item[\DParam{differentjfm}\,=<mode>$^\dagger$]\
5240
5241 %<*en>
5242 Specify how glues/kerns between two \textbf{JAchar}s whose JFM (or size) are different.
5243 The allowed arguments are the followings:
5244 %</en>
5245 %<*ja>
5246 JFM(もしくはサイズ)が異なる2つの\textbf{JAchar}の間にグルー/カーンをどのように
5247 入れるかを指定する.
5248 許される値は以下の通り:
5249 %</ja>
5250 \begin{quote}
5251 \texttt{average},
5252 \texttt{both},
5253 \texttt{large},
5254 \texttt{small},
5255 \texttt{pleft},
5256 \texttt{pright},
5257 \texttt{paverage}
5258 \end{quote}
5259 %<*en>
5260 The default value is \texttt{paverage}. \dots
5261 %</en>
5262 %<*ja>
5263 デフォルト値は \texttt{paverage} である.
5264 各々の値による差異の詳細は\ref{ssec:cluster-wa}節の「『右空白』の算出」を参照してほしい.
5265 %</ja>
5266
5267 \item[\DParam{jacharrange}\,=<ranges>]
5268 \item[\DParam{kansujichar}\,=\{<digit>, <chr\_code>\}$^\ast$] [\cs{kansujichar}]
5269
5270 \item[\DParam{direction}\,=<dir>\ \hbox{\rm (always local)}]\
5271
5272 %<*en>
5273 Assigning to this parameter has the same effect as
5274 \cs{yoko}~(if $\hbox{<dir>}=4$), \cs{tate}~(if $\hbox{<dir>}=3$),
5275 \cs{dtou}~(if $\hbox{<dir>}=1$) or \cs{utod}~(if $\hbox{<dir>}=11$).
5276 If the argument <dir> is not one of 4,~3, 1~nor~11,
5277 the behavior of this assignment is undefined.
5278 %</en>
5279 %<*ja>
5280 組方向を変更する \cs{yoko}~(if $\hbox{<dir>}=4$), \cs{tate}~(if $\hbox{<dir>}=3$),
5281 \cs{dtou}~(if $\hbox{<dir>}=1$), \cs{utod}~(if $\hbox{<dir>}=11$) と同じ役割を持つ.
5282 利用可能な状況もこれら4命令と同一である.引数<dir>が4,~3, 1,~11のいずれでも無いときの
5283 動作は未定義である.
5284 %</ja>
5285
5286 \end{cslist}
5287
5288
5289 \subsection{\cs{ltjgetparameter}}
5290 \label{ssec:getpar}
5291 %<*en>
5292 \cs{ltjgetparameter} is a control sequence for acquiring parameters. It
5293 always takes a parameter name as first argument.
5294 %</en>
5295 %<*ja>
5296 \cs{ltjgetparameter} はパラメータの値を取得するための命令であり,
5297 常にパラメータの名前を第一引数にとる.
5298 %</ja>
5299 \begin{LTXexample}
5300 \ltjgetparameter{differentjfm},
5301 \ltjgetparameter{autospacing},
5302 \ltjgetparameter{kanjiskip},
5303 \ltjgetparameter{prebreakpenalty}{`)}.
5304 \end{LTXexample}
5305
5306 %<*en>
5307 \emph{The return value of\/ \cs{ltjgetparameter} is
5308 always a string}, which is outputted by \texttt{tex.write()}.
5309 Hence any character other than space~``\texttt{\char32}''~(\texttt{U+0020}) has the category code
5310 12~(other), while the space has 10~(space).
5311 %</en>
5312 %<*ja>
5313 \emph{\cs{ltjgetparameter} の戻り値は常に文字列である.}
5314 これは\texttt{tex.write()}によって出力しているためで,空白「\texttt{\char32}」
5315 (\texttt{U+0020})を除いた文字のカテゴリーコードは全て12~(other)となる.
5316 一方,空白のカテゴリーコードは10~(space)である.
5317 %</ja>
5318
5319 \begin{itemize}
5320 \item
5321 %<*en>
5322 If first argument is one of the
5323 following, no  additional argument is needed.
5324 %</en>
5325 %<*ja>
5326 第1引数が次のいずれかの場合には,追加の引数は必要ない.
5327 %</ja>
5328 \begin{quote}
5329 \sffamily
5330 jcharwidowpenalty, yjabaselineshift, yalbaselineshift, autospacing, autoxspacing,\\
5331 kanjiskip, xkanjiskip, differentjfm, direction
5332 \end{quote}
5333 %<*en>
5334 Note that \verb+\ltjgetparameter{autospacing}+~and~\verb+\ltjgetparameter{autoxspacing}+
5335 returns 1 or 0, not
5336 \texttt{true}~nor~\texttt{false}.
5337 %</en>
5338 %<*ja>
5339 \verb+\ltjgetparameter{autospacing}+ と \verb+\ltjgetparameter{autoxspacing}+ は,
5340 \texttt{true}や\texttt{false}を返すの\emph{ではなく},
5341 1か0のいずれかを返すことに注意,
5342 %</ja>
5343
5344 \item
5345 %<*en>
5346 If first argument is one of the
5347 following, an additional argument---a character code, for example---is needed.
5348 %</en>
5349 %<*ja>
5350 第1引数が次のいずれかの場合には,さらに文字コードを第2引数としてとる.
5351 %</ja>
5352 \begin{quote}
5353 \sffamily
5354 kcatcode, prebreakpenalty, postbreakpenalty, jaxspmode, alxspmode
5355 \end{quote}
5356 %<*en>
5357 \verb+\ltjgetparameter{jaxspmode}{...}+~and~\verb+\ltjgetparameter{alxspmode}{...}+
5358 returns 0,~1, 2,~or~3, instead of \texttt{preonly} etc.
5359 %</en>
5360 %<*ja>
5361 \verb+\ltjgetparameter{jaxspmode}{...}+ や \verb+\ltjgetparameter{alxspmode}{...}+\
5362 は,\texttt{preonly} などといった文字列ではなく,0から3までの値を返す.
5363 %</ja>
5364
5365 \item
5366 %<*en>
5367 \verb+\ltjgetparameter{jacharrange}{+<range>\verb+}+ returns \texttt{0}
5368 if ``characters which belong to the character range~<range> are \textbf{JAchar}'',
5369 \texttt{1} if ``\dots~are \textbf{ALchar}''.
5370 Although there is no character range~$-1$, specifying $-1$ to <range> does not cause an
5371       error (returns 1).
5372 %</en>
5373 %<*ja>
5374 \verb+\ltjgetparameter{jacharrange}{+<range>\verb+}+ は,<range>が\textbf{JAchar}達の
5375 範囲ならば0を,そうでなければ1を返す.「$-1$番の文字範囲」は存在しないが,<range>に$-1$を
5376 指定してもエラーは発生しない(1を返す).
5377 %</ja>
5378
5379 \item
5380 %<*en>
5381 For an integer~<digit> between 0~and~9,
5382      \verb+\ltjgetparameter{kansujichar}{+<digit>\verb+}+ returns the character code
5383 of the result of \cs{kansuji}<digit>.
5384 %</en>
5385 %<*ja>
5386 0--9の数<digit>に対して,
5387 \verb+\ltjgetparameter{kansujichar}{+<digit>\verb+}+ は,\cs{kansuji}<digit>で出力され
5388      る文字の文字コードを返す.
5389 %</ja>
5390
5391 \item
5392 %<*en>
5393 \verb+\ltjgetparameter{adjustdir}+ returns a integer which represents
5394 the direction of the surrounding vertical list.
5395 As \Param{direction}, the return value 1 means \emph{down-to-up} direction,
5396 3 means \emph{tate} direction (vertical typesetting),
5397 and 4 means \emph{yoko} direction (horizontal typesetting).
5398 %</en>
5399 %<*ja>
5400 \verb+\ltjgetparameter{adjustdir}+ は,周囲のvboxの組方向(言い換えれば,
5401 \cs{vadjust} で用いられる組方向)を表す数値を返す.
5402 \Param{direction}と同様に,1は \cs{dtou} 方向を,
5403 3は縦組みを,4は横組みを表す.
5404 %</ja>
5405
5406 \item
5407 %<*en>
5408 For an integer~<reg\_num> between 0~and~65535,
5409 \verb+\ltjgetparameter{boxdim}{+<reg\_num>\verb+}+ returns the direction of
5410 \cs{box}<reg\_num>. If this box register is void, the returned value is zero.
5411 %</en>
5412 %<*ja>
5413 0--65535の数<reg\_num>に対して,
5414 \verb+\ltjgetparameter{boxdim}{+<reg\_num>\verb+}+ は,\cs{box}<reg\_num>に
5415 格納されているボックスの組方向を表す.もしこのレジスタが空の場合は,0が返される.
5416 %</ja>
5417
5418 \item
5419 %<*en>
5420 The following parameter names \emph{cannot be specified} in \cs{ltjgetparameter}.
5421 %</en>
5422 %<*ja>
5423 次のパラメータ名を \cs{ltjgetparameter} に指定することはできない.
5424 %</ja>
5425 \begin{quote}
5426 \sffamily
5427 jatextfont, jascriptfont, jascriptscriptfont, jacharrange
5428 \end{quote}
5429
5430 \item
5431 %<*en>
5432 \verb+\ltjgetparameter{chartorange}{+<chr\_code>\verb+}+ returns
5433 the range number which <chr\_code> belongs to
5434 (although there is no parameter named ``chartorange'').
5435
5436 If <chr\_code> is between 0 and 127, this <chr\_code> does not belong to
5437 any character range. In this case,
5438       \verb+\ltjgetparameter{chartorange}{+<chr\_code>\verb+}+
5439 returns $-1$.
5440
5441 Hence, one can know whether <chr\_code> is \textbf{JAchar} or not
5442 by the following:
5443 %</en>
5444 %<*ja>
5445 \verb+\ltjgetparameter{chartorange}{+<chr\_code>\verb+}+ によって
5446 <chr\_code>の属する文字範囲の番号を知ることができる.
5447
5448 <chr\_code>に0--127の値を指定した場合(このとき,<chr\_code>が属する
5449 文字範囲は存在しない)は$-1$が返る.
5450
5451 そのため,<chr\_code>が\textbf{JAchar}か\textbf{ALchar}かは
5452 次で知ることができる:
5453 %</ja>
5454 \begin{quote}
5455 \ttfamily \verb+\ltjgetparameter{jacharrange}{\ltjgetparameter{chartorange}{+%
5456   <chr\_code>\verb+}}+\\\null\hfill\verb+% 0 if JAchar, 1 if ALchar+
5457 \end{quote}
5458
5459 %<*en>
5460 \item Because the returned value is string, the following conditionals do not work
5461 if \Param{kanjiskip} (or~\Param{xkanjiskip}) has the stretch part or the shrink part.
5462 \begin{lstlisting}
5463 \ifdim\ltjgetparameter{kanjiskip}>\z@ ... \fi
5464 \ifdim\ltjgetparameter{xkanjiskip}>\z@ ... \fi
5465 \end{lstlisting}
5466 The correct way is using a temporary register.
5467 \begin{lstlisting}
5468 \@tempskipa=\ltjgetparameter{kanjiskip} \ifdim\@tempskipa>\z@ ... \fi
5469 \@tempskipa=\ltjgetparameter{xkanjiskip}\ifdim\@tempskipa>\z@ ... \fi
5470 \end{lstlisting}
5471 %</en>
5472 %<*ja>
5473 \item 返り値が文字列であることから,\Param{kanjiskip}や\Param{xkanjiskip}を直接
5474 \ \cs{ifdim} を使って比較することは望ましくない.伸び量や縮み量を持っている時には,
5475 次はエラーを発生させる:
5476 \begin{lstlisting}
5477 \ifdim\ltjgetparameter{kanjiskip}>\z@ ... \fi
5478 \ifdim\ltjgetparameter{xkanjiskip}>\z@ ... \fi
5479 \end{lstlisting}
5480 レジスタに一旦代入するのが良い:
5481 \begin{lstlisting}
5482 \@tempskipa=\ltjgetparameter{kanjiskip} \ifdim\@tempskipa>\z@ ... \fi
5483 \@tempskipa=\ltjgetparameter{xkanjiskip}\ifdim\@tempskipa>\z@ ... \fi
5484 \end{lstlisting}
5485 %</ja>
5486
5487 \end{itemize}
5488
5489
5490 %<*en>
5491 \subsection{Alternative Commands to \cs{ltjsetparameter}}
5492 The basic method to set parameters of \LuaTeX-ja is to use
5493 \cs{ltjsetparameter}~or~\cs{ltjglobalsetparameter}.
5494 However, these commands are slow, because they parse a key-value list,
5495 so several alternative commands are used in \LuaTeX-ja.
5496 \emph{This subsection is not for general \LuaTeX-ja users.}
5497
5498 \paragraph{Setting \Param{kanjiskip}~or~\Param{xkanjiskip}}
5499 In \Pkg{ltjsclasses}, every size-changing command such as \cs{Large}
5500 changes \cs{kanjiskip}~and~\cs{xkanjiskip}.
5501 But a simple implementation, as the code below, is slow since
5502 two key-value lists are parsed by \cs{ltjsetparameter}:
5503 \begin{lstlisting}
5504   \ltjsetparameter{kanjiskip=0\zw plus .1\zw minus .01\zw}
5505   \@tempskipa=\ltjgetparameter{xkanjiskip}
5506   \ifdim\@tempskipa>\z@
5507     \if@slide
5508       \ltjsetparameter{xkanjiskip=0.1em}
5509     \else
5510       \ltjsetparameter{xkanjiskip=0.25em plus 0.15em minus 0.06em}
5511     \fi
5512   \fi
5513 \end{lstlisting}
5514
5515 Hence, \LuaTeX-ja defines more primitive commands, namely \cs{ltj@setpar@global},
5516 \cs{ltjsetkanjiskip}, and~\cs{ltjsetxkanjiskip}. Here
5517 \begin{quote}
5518   \lstinline+\ltj@setpar@global\ltjsetkanjiskip 10pt+
5519 \end{quote}
5520 and \lstinline+\ltjsetparameter{kanjiskip=10pt}+ has the same effect.
5521 The actual code of \Pkg{ltjsclasses} is shown below:
5522 \begin{lstlisting}
5523   \ltj@setpar@global
5524   \ltjsetkanjiskip{\z@ plus .1\zw minus .01\zw}
5525   \@tempskipa=\ltjgetparameter{xkanjiskip}
5526   \ifdim\@tempskipa>\z@
5527     \if@slide
5528       \ltjsetxkanjiskip.1em
5529     \else
5530       \ltjsetxkanjiskip.25em plus .15em minus .06em
5531     \fi
5532   \fi
5533 \end{lstlisting}
5534
5535 Note that using \cs{ltjsetkanjiskip}~or~\cs{ltjsetxkanjiskip} alone,
5536 that is, without executing \cs{ltj@setpar@global} in advance, is \emph{not} supported.
5537 %</en>
5538
5539 %<*ja>
5540 \subsection{\cs{ltjsetparameter} の代替}
5541 原則として各種内部パラメータの設定には \cs{ltjsetparameter} もしくは
5542 \ \cs{ltjglobalsetparameter}\ を用いることになるが,
5543 \cs{ltjsetparameter} の実行には時間がかかるという難点があり,
5544 \LuaTeX-ja の内部ではより高速に実行できる別の形式を用いている.
5545 \emph{本節は一般利用者むけの内容ではない.}
5546
5547 \paragraph{\Param{kanjiskip}, \Param{xkanjiskip}の設定}
5548 \pLaTeXe 新ドキュメントクラスでは,
5549 \begin{lstlisting}
5550 \def\@setfontsize#1#2#3{%
5551   ...
5552   \kanjiskip=0zw plus .1zw minus .01zw
5553   \ifdim\xkanjiskip>\z@
5554     \if@slide \xkanjiskip=0.1em \else
5555       \xkanjiskip=0.25em plus 0.15em minus 0.06em
5556     \fi
5557   \fi}
5558 \end{lstlisting}
5559 と,フォントサイズを変更するごとに \cs{kanjiskip}, \cs{xkanjiskip} を変更している.
5560 この \cs{@setfontsize} は文書の中で多数回実行されるので.
5561 \LuaTeX-ja 用に素直に書き換えた
5562 \begin{lstlisting}
5563   \ltjsetparameter{kanjiskip=0\zw plus .1\zw minus .01\zw}
5564   \@tempskipa=\ltjgetparameter{xkanjiskip}
5565   \ifdim\@tempskipa>\z@
5566     \if@slide
5567       \ltjsetparameter{xkanjiskip=0.1em}
5568     \else
5569       \ltjsetparameter{xkanjiskip=0.25em plus 0.15em minus 0.06em}
5570     \fi
5571   \fi
5572 \end{lstlisting}
5573 としたのではタイプセットが遅くなってしまう.
5574 そこで,\cs{ltjsetparameter} の中で
5575 \begin{itemize}
5576 \item \cs{globaldefs} の値を読み取る \cs{ltj@setpar@global}
5577 \item \Param{kanjiskip} の設定を行う \cs{ltjsetkanjiskip}
5578 \item \Param{xkanjiskip} の設定を行う \cs{ltjsetxkanjiskip}
5579 \end{itemize}
5580 を独立させ,\Pkg{ltjsclasses}では,
5581 \begin{lstlisting}
5582   \ltj@setpar@global
5583   \ltjsetkanjiskip{\z@ plus .1\zw minus .01\zw}
5584   \@tempskipa=\ltjgetparameter{xkanjiskip}
5585   \ifdim\@tempskipa>\z@
5586     \if@slide
5587       \ltjsetxkanjiskip.1em
5588     \else
5589       \ltjsetxkanjiskip.25em plus .15em minus .06em
5590     \fi
5591   \fi
5592 \end{lstlisting}
5593 としている.
5594 \cs{ltj@setpar@global}を直前に実行せず,単独で
5595 \cs{ltjsetkanjiskip}, \cs{ltjsetxkanjiskip}を実行することは想定されていないので注意.
5596
5597
5598
5599 \paragraph{ベースライン補正量の設定}
5600 \pLaTeX の\Pkg{ascmac}パッケージでは,縦組の欧文ベースライン補正量の一時待避・復帰処理に
5601 \ \cs{@saveybaselineshift}\ という寸法レジスタを用い
5602 \begin{lstlisting}
5603 \@savetbaselineshift\tbaselineshift\tbaselineshift\z@
5604 ...
5605 \tbaselineshift\@savetbaselineshift
5606 \end{lstlisting}
5607 という処理を行っている.
5608
5609 これを\LuaTeX-ja 用に \cs{ltjsetparameter} を使って書き直すと,
5610 \begin{lstlisting}
5611 \@savetbaselineshift\ltjgetparameter{talbaselineshift}
5612 \ltjsetparameter{talbaselineshift=\z@}
5613 ...
5614 \ltjsetparameter{talbaselineshift=\@savetbaselineshift}
5615 \end{lstlisting}
5616 となる.
5617
5618 さて,縦組の欧文ベースライン補正量\Param{talbaselineshift}は,
5619 実際には \cs{ltj@tablshift} という属性レジスタに格納されている
5620 (\ref{sec-para}\nobreak 節参照).属性レジスタは長さではなく整数値を格納する\footnote{%
5621   従って,\texttt{\textbackslash @savetbaselineshift=\textbackslash ltj@tablshift}\
5622   のように記述することはできない.属性レジスタを \cs{tbaselineshift} という名称にしなかっ
5623   たのはそのためである.
5624 }ものであり,\cs{ltj@tablshift} は補正量を sp 単位で保持することから,
5625 上記のコードと同じ内容をより速い以下のコードで実現することができる.
5626 \begin{lstlisting}
5627 \@savetbaselineshift\ltj@tablshift sp%
5628 \ltj@tablshift\z@
5629 ...
5630 \ltj@tablshift\@savetbaselineshift
5631 \end{lstlisting}
5632 この手法は \Pkg{ascmac} パッケージの\LuaTeX-ja対応パッチ \Pkg{lltjp-tascmac.sty} で
5633 実際に用いられている.\Pkg{lltjp-tascmac.sty} は自動的に読み込まれるので,
5634 ユーザは何も気にせず普通に \Pkg{ascmac} パッケージを \cs{usepackage} で読みこめば良い.
5635 %</ja>
5636
5637
5638 %<en>\section{Other Commands for plain \TeX\ and \LaTeXe}
5639 %<ja>\section{plainでも\LaTeX でも利用可能なその他の命令}
5640 %<en>\subsection{Commands for compatibility with \pTeX}
5641 %<ja>\subsection{\pTeX 互換用命令}
5642
5643 %<*en>
5644 The following commands are implemented for compatibility with \pTeX.
5645 Note that the former five commands don't support JIS~X~0213, but only JIS~X~0208.
5646 The last \cs{kansuji} converts an integer into its Chinese numerals.
5647 %</en>
5648 %<*ja>
5649 以下の命令は\pTeX との互換性のために実装されている.そのため,JIS~X~0213には対応せず,
5650 \pTeX と同じようにJIS~X~0208の範囲しかサポートしていない.
5651 %</ja>
5652 \begin{center}
5653 \cs{kuten}, \cs{jis}, \cs{euc}, \cs{sjis}, \cs{ucs}, \cs{kansuji}
5654 \end{center}
5655 %<*en>
5656 These six commands takes an internal integer, and returns a \emph{string}.
5657 %</en>
5658 %<*ja>
5659 これら6命令は内部整数を引数とするが,実行結果は\textbf{文字列}であることに注意.
5660 %</ja>
5661 \begin{LTXexample}
5662 \newcount\hoge
5663 \hoge="2423 %"
5664 \the\hoge, \kansuji\hoge\\
5665 \jis\hoge, \char\jis\hoge\\
5666 \kansuji1701
5667 \end{LTXexample}
5668
5669 %<*en>
5670 To change characters of Chinese numerals for each digit, set \Param{kansujichar} parameter:
5671 \begin{LTXexample}
5672 \ltjsetparameter{kansujichar={1,`壹}}
5673 \ltjsetparameter{kansujichar={7,`漆}}
5674 \ltjsetparameter{kansujichar={0,`零}}
5675 \kansuji1701
5676 \end{LTXexample}
5677 %</en>
5678
5679
5680 \subsection{\cs{inhibitglue}}
5681 %<*en>
5682 \cs{inhibitglue} suppresses the insertion of \textbf{JAglue}.
5683 The following is an example, using a special JFM that there will be a glue between
5684 the beginning of a box and ``あ'', and also between ``あ''~and~``ウ''.
5685 %</en>
5686 %<*ja>
5687 \cs{inhibitglue} は\textbf{JAglue}の挿入を抑制する.
5688 以下は,ボックスの始めと「あ」の間,「あ」「ウ」の間にグルーが入る特別なJFMを用いた例で
5689 ある.
5690 %</ja>
5691
5692 \begin{LTXexample}[width=0.4\textwidth]
5693 \jfont\g=file:KozMinPr6N-Regular.otf:jfm=test \g
5694 \fbox{\hbox{あウあ\inhibitglue ウ}}
5695 \inhibitglue\par\noindent あ1
5696 \par\inhibitglue\noindent あ2
5697 \par\noindent\inhibitglue あ3
5698 \par\hrule\noindent あoff\inhibitglue ice
5699 \end{LTXexample}
5700
5701 %<*en>
5702 With the help of this example, we remark the specification of \cs{inhibitglue}:
5703 %</en>
5704 %<*ja>
5705 この例を援用して,\cs{inhibitglue} の仕様について述べる.
5706 %</ja>
5707 \begin{itemize}
5708 %<*en>
5709 \item The call of \cs{inhibitglue} in the (internal) vertical mode is
5710       simply ignored.
5711 %</en>
5712 %<*ja>
5713 \item \emph{\cs{inhibitglue} の垂直モード中での呼び出しは意味を持たない}\footnote{%
5714   この点は\TeX~Live~2014での\pTeX における \cs{inhibitglue} の仕様変更と同じである.
5715 }.
5716 4行目の入力で有効にならないのは,\cs{inhibitglue} の時点では垂直モードであり,
5717 \cs{noindent} の時点で水平モードになるからである.
5718 %</ja>
5719
5720 %<*en>
5721 \item The call of \cs{inhibitglue} in the (restricted) horizontal
5722       mode is only effective on the spot; does not get over boundary of
5723       paragraphs. Moreover, \cs{inhibitglue} cancels ligatures and
5724       kernings, as shown in the last line of above example.
5725 %</en>
5726 %<*ja>
5727 \item \cs{inhibitglue} の(制限された)水平モード中での呼び出しはその場でのみ
5728   有効であり,段落の境界を乗り越えない.
5729   さらに,\cs{inhibitglue} は上の例の最終行のように(欧文における)リガチャとカーニングを
5730   打ち消す.これは,\cs{inhibitglue} が内部的には「現在のリスト中にwhatsitノードを
5731   追加する」ことを行なっているからである.
5732 %</ja>
5733
5734 %<*en>
5735 \item The call of \cs{inhibitglue} in math mode is just ignored.
5736 %</en>
5737 %<*ja>
5738 \item \cs{inhibitglue} を数式モード中で呼び出した場合はただ無視される.
5739 %</ja>
5740
5741 %<*ja>
5742 \item \LaTeX で\LuaTeX-ja を使用する場合は,
5743 \cs{inhibitglue} の代わりとして \verb+\<+ を使うことができる.
5744 既に \verb+\<+ が定義されていた場合は,\LuaTeX-ja の読み込みで強制的に上書きされるので
5745 注意すること.
5746 %</ja>
5747 \end{itemize}
5748
5749
5750 \subsection{\cs{ltjfakeboxbdd}, \cs{ltjfakeparbegin}}
5751 %<*en>
5752 Sometimes \texttt{'parbdd'}~and~\texttt{'boxbdd'} specifications~look like ``fail'',
5753 especially in paragraphs inside list environments.
5754 This is because \cs{everypar} inserts some nodes such as boxes and kerns, so
5755 the ``first letter'' in a paragraph is in fact not the first letter.
5756 %</en>
5757 %<*ja>
5758 リスト環境内での\cs{item}で始まる各項目などでは,
5759 「段落最初の鍵括弧が余計に半角字下げされる」など,
5760 JFMにある\texttt{'parbdd'}, \texttt{'boxbdd'}の指定が見かけ上破綻していることがある.
5761
5762 これは\TeX が\cs{everypar}を用いて段落開始時に記号類や空白などを挿入してしまっているため,
5763 段落最初の鍵括弧が実際には段落最初のノードではないことに起因する.以下に例を示した.
5764 %</ja>
5765 \begin{LTXexample}[width=0.3\textwidth]
5766 \parindent1\zw
5767 \noindent ああああああああ\par % for comparison
5768 「ああああああ \par            % normal paragraph
5769
5770 \everypar{\null}
5771 「ああああああ \par            % ???
5772 \end{LTXexample}
5773 %<*en>
5774 \cs{ltjfakeboxbdd}~and~\cs{ltjfakeparbegin} primitives resolve this situation.
5775 \begin{itemize}
5776   \item \cs{ltjfakeparbegin} creates a node which indicates
5777   ``beginning of an indented paragraph'' to the insertion process of \textbf{JAglue}.
5778  \item \cs{ltjfakeboxbdd} creates a node which indicates
5779   ``beginning/ending of a box'' to the insertion process of \textbf{JAglue}.
5780 \end{itemize}
5781 As an example, the example above can be improved as follows:
5782 %</en>
5783 %<*ja>
5784 \cs{ltjfakeboxbdd}, \cs{ltjfakeparbegin}はこの状況を改善する命令である.
5785 実際には\cs{everypar}の末尾にこれらを追加するという使い方がほとんどになるだろう.
5786 \begin{itemize}
5787   \item \cs{ltjfakeparbegin}は,実行された箇所が「インデントあり段落の開始」であると\LuaTeX-jaの
5788   和文処理グルー挿入処理に認識させる.この命令の直前に\textbf{JAchar}があった場合,
5789   この文字の後ろに入るグルー等の処理については未定義である
5790   \footnote{%
5791     この命令と同等の内容は,\cs{dirrctlua}の形で\Pkg{ltjsclasses}内で以前から使われていた.
5792     一般ユーザでも利用しやすくするため,バージョン20170505.0で新たに命令として定義した.
5793   }.
5794   \item \cs{ltjfakeboxbdd}は,実行された箇所が「ボックスの先頭と末尾」であると\LuaTeX-jaの
5795   和文処理グルー挿入処理に認識させる.
5796 \end{itemize}
5797 例えば,先ほどの例に対して適用すると,次のようになる.
5798 %</ja>
5799 \begin{LTXexample}[width=0.3\textwidth]
5800 \parindent1\zw
5801 \noindent ああああああああ\par % for comparison
5802 「ああああああ \par            % normal paragraph
5803
5804 \everypar{\null\ltjfakeparbegin}
5805 「ああああああ \par
5806 \end{LTXexample}
5807
5808
5809 \subsection{\cs{ltjdeclarealtfont}}
5810 \label{ssec:altfont}
5811 %<*en>
5812 Using \cs{ltjdeclarealtfont}, one can ``compose'' more than one Japanese fonts.
5813 This \cs{ltjdeclarealtfont} uses in the following form:
5814 \begin{quote}
5815 \ttfamily \textbackslash ltjdeclarealtfont<base\_font\_cs><alt\_font\_cs>\{<range>\}
5816 \end{quote}
5817 where  <base\_font\_cs>~and~<alt\_font\_cs> are defined by \cs{jfont}.
5818 Its meaning is
5819 \begin{quote}
5820 If the current Japanese font is <base\_font\_cs>, characters which belong to <range>
5821 is typeset by another Japanese font <alt\_font\_cs>, instead of <base\_font\_cs>.
5822 \end{quote}
5823 Here <range> is a comma-separated list of character codes, but also accepts negative integers:
5824 $-n$~($n≥1$) means that all characters of character classes~$n$, with respect to JFM used
5825 by <base\_font\_cs>. Note that characters which do not exist in <alt\_font\_cs> are
5826 ignored.
5827
5828 For example, if \cs{hoge} uses \texttt{jfm-ujis.lua}, the standard JFM of \LuaTeX-ja,
5829 then
5830 \begin{lstlisting}
5831 \ltjdeclarealtfont\hoge\piyo{"3000-"30FF, {-1}-{-1}}
5832 \end{lstlisting}
5833 does
5834 \begin{quote}
5835 If the current Japanese font is \cs{hoge}, \texttt{U+3000}--\texttt{U+30FF}
5836 and characters in class~1 (ideographic opening brackets)
5837 are typeset by \cs{piyo}.
5838 \end{quote}
5839 %</en>
5840 %<*ja>
5841 \cs{jfont} の書式を見ればわかるように,基本的には\LuaTeX-jaにおける1つの和文フォントに
5842 使用出来る「実際のフォント」は1つである.
5843 しかし,\cs{ltjdeclarealtfont} を用いると,この原則から外れることができる.
5844
5845 \cs{ltjdeclarealtfont} は以下の書式で使用する:
5846 \begin{quote}
5847 \ttfamily \textbackslash ltjdeclarealtfont<base\_font\_cs><alt\_font\_cs>\{<range>\}
5848 \end{quote}
5849 これは「現在の和文フォント」が<base\_font\_cs>であるとき,
5850 <range>に属する文字は<alt\_font\_cs>を用いて組版される,という意味である.
5851 \begin{itemize}
5852  \item <base\_font\_cs>, <alt\_font\_cs>は
5853 \cs{jfont} によって定義された和文フォントである.
5854  \item <range>は文字コードの範囲を表すコンマ区切りのリストであるが,
5855    例外として負数$-n$は「<base\_font\_cs>のJFMの文字クラス$n$に属する全ての文字」
5856    を意味する.
5857
5858 <range>中に<alt\_font\_cs>中に実際には存在しない文字が指定された場合は,
5859 その文字に対する設定は無視される.
5860 \end{itemize}
5861
5862 例えば,\cs{hoge} のJFMが\LuaTeX-ja標準の
5863 \ \texttt{jfm-ujis.lua} であった場合,
5864 \begin{lstlisting}
5865 \ltjdeclarealtfont\hoge\piyo{"3000-"30FF, {-1}-{-1}}
5866 \end{lstlisting}
5867 は「\cs{hoge} を利用しているとき,
5868 \texttt{U+3000}--\texttt{U+30FF}と
5869 文字クラス1(開き括弧類)中の文字だけは \cs{piyo} を用いる」
5870 ことを設定する.\verb+{-1}-{-1}+ という変わった指定の仕方をしているのは,
5871 普通に \texttt{-1} と指定したのでは正しく$-1$と読み取られないという
5872 マクロの都合による.
5873 %</ja>
5874
5875 %<*ja>
5876 \subsection{\cs{ltjalchar} と \cs{ltjjachar}}
5877 文字コードが$\text{<chr\_code>}~(\geq 128=\mathtt{0x80})$の文字を
5878 \ \cs{char} プリミティブを使い \cs{char}<chr\_code> として出力させると,
5879 その文字の属する文字範囲(\ref{ssec:setrange}節参照)によって
5880 \textbf{ALchar}か\textbf{JAchar}か,つまり欧文フォントで出力されるか和文フォントで出力され
5881 るかが決まる.
5882
5883 文字範囲の設定を無視し,文字コードが$\text{<chr\_code>}~(\geq 128=\mathtt{0x80})$の文字を強制的に
5884 \textbf{ALchar}, \textbf{JAchar}で出力する命令がそれぞれ
5885 \ \cs{ltjalchar},~\cs{ltjjachar} である.使用方法は \cs{char} と同じく
5886 \ \cs{ltjalchar}<chr\_code>, \cs{ltjjachar}<chr\_code>とすればよい.
5887 <chr\_code>が127以下の場合は,\cs{ltjjachar} であっても\textbf{ALchar}として出力されること
5888 に注意.
5889
5890 以下は\ref{ssec:setrange}節に載せた例に,\cs{char} の動作を追加したものである.
5891 \begin{LTXexample}[width=0.25\textwidth]
5892 \gtfamily\large % default, ALchar, JAchar
5893 ¶, \char`¶, \ltjalchar`¶, \ltjjachar`¶\\    % default: ALchar
5894 α, \char`α, \ltjalchar`α, \ltjjachar`α  % default: JAchar
5895 \end{LTXexample}
5896 %</ja>
5897
5898 %<en>\section{Commands for \LaTeXe}
5899 %<ja>\section{\LaTeXe 用の命令}
5900
5901 %<en>\subsection{Patch for NFSS2}
5902 %<ja>\subsection{NFSS2へのパッチ}
5903 \label{ssec:nfsspat}
5904
5905 %<*en>
5906 Japanese patch for NFSS2 in \LuaTeX-ja
5907 is based on \texttt{plfonts.dtx} which plays the same role in \pLaTeXe.
5908 We will describe
5909 commands which are not described in Subsection~\ref{ssec:chgfnt}.
5910 %</en>
5911 %<*ja>
5912 \LuaTeX-jaのNFSS2への日本語パッチは
5913 \pLaTeXe で同様の役割を果たす \texttt{plfonts.dtx} をベースに,
5914 和文エンコーディングの管理等をLuaで書きなおしたものである.
5915 ここでは\ref{ssec:chgfnt}節で述べていなかった命令について
5916 記述しておく.
5917 %</ja>
5918
5919 \begin{cslist}%
5920 \item[\normalfont\bfseries %
5921 %<ja>追加の長さ変数達
5922 %<en>additonal dimensions
5923 ]
5924 %<*en>
5925 Like \pLaTeXe, \LuaTeX-ja defines the following dimensions
5926 for information of current Japanese font:
5927 %</en>
5928 %<*ja>
5929 \pLaTeXe と同様に,\LuaTeX-jaは「現在の和文フォントの情報」を格納する長さ変数
5930 %</ja>
5931 \begin{quote}
5932  \cs{cht}~(height), \cs{cdp}~(depth), \cs{cHT}~(sum of former two),\\
5933  \cs{cwd}~(width), \cs{cvs}~(lineskip), \cs{chs}~(equals to \cs{cwd})
5934 \end{quote}
5935 %<en>and its \cs{normalsize} version:
5936 %<ja>と,その \cs{normalsize} 版である
5937 \begin{quote}
5938  \cs{Cht}~(height), \cs{Cdp}~(depth),
5939  \cs{Cwd}~(width), \\\cs{Cvs}~(equals to \cs{baselineskip}),
5940  \cs{Chs}~(equals to \cs{cwd})%
5941 %<en>.
5942 \end{quote}
5943 %<*ja>
5944 を定義している.なお,\cs{cwd} と \cs{zw},また
5945 \cs{cHT} と \cs{zh} は一致しない可能性がある.なぜなら,
5946 \cs{cwd},~\cs{cHT} は「あ」の寸法から決定されるのに対し,
5947 \cs{zw} と \cs{zh} はJFMに指定された値に過ぎないからである.
5948 %</ja>
5949 %<*en>
5950 Note that \cs{cwd}~and~\cs{cHT} may  differ from \cs{zw}~and~\cs{zh}
5951 respectively.
5952 On the one hand the former dimensions are determined from the character ``あ'',
5953 but on the other hand \cs{zw}~and~\cs{zh} are specified by JFM.
5954 %</en>
5955
5956
5957 \item[\cs{DeclareYokoKanjiEncoding}\{<encoding>\}\{<text-settings>\}\{<math-settings>\}]
5958 %<en>\ \\[\dimexpr-\medskipamount-2\baselineskip\relax]
5959 %<ja>\ \\[\dimexpr-2\baselineskip\relax]
5960 \item[\cs{DeclareTateKanjiEncoding}\{<encoding>\}\{<text-settings>\}\{<math-settings>\}]
5961
5962 %<*en>
5963 In NFSS2 under \LuaTeX-ja, distinction between alphabetic fonts
5964              and Japanese fonts are only made by their
5965              encodings. For example, encodings OT1 and T1 are encodings for
5966              alphabetic fonts, and Japanese fonts cannot
5967              have these encodings. These command define a new encoding
5968              scheme for Japanese font families.
5969 %</en>
5970 %<*ja>
5971 \LuaTeX-jaのNFSS2においては,欧文フォントと和文フォントは
5972 そのエンコーディングによってのみ区別される.
5973 例えば,OT1とT1のエンコーディングは欧文フォントのエンコーディングであり,
5974 和文フォントはこれらのエンコーディングを持つことはできない.
5975 これらコマンドは横組用・縦組用和文フォントのための新しいエンコーディングを
5976 それぞれ定義する.
5977 %</ja>
5978
5979 \item[\cs{DeclareKanjiEncodingDefaults}\{<text-settings>\}\{<math-settings>\}]
5980 %<en>\ \\[\dimexpr-\medskipamount-2\baselineskip\relax]
5981 %<ja>\ \\[\dimexpr-2\baselineskip\relax]
5982 \item[\cs{DeclareKanjiSubstitution}\{<encoding>\}\{<family>\}\{<series>\}\{<shape>\}]
5983 %<en>\ \\[\dimexpr-\medskipamount-2\baselineskip\relax]
5984 %<ja>\ \\[\dimexpr-2\baselineskip\relax]
5985 \item[\cs{DeclareErrorKanjiFont}\{<encoding>\}\{<family>\}\{<series>\}\{<shape>\}\{<size>\}]
5986
5987 %<*en>
5988 The above 3~commands are just the counterparts for \cs{DeclareFontEncodingDefaults} and~others.
5989 %</en>
5990 %<*ja>
5991 上記3つのコマンドはちょうどNFSS2 の \cs{DeclareFontEncodingDefaults} などに対応するものである.
5992 %</ja>
5993
5994 \item[\cs{reDeclareMathAlphabet}\{<unified-cmd>\}\{<al-cmd>\}\{<ja-cmd>\}]
5995
5996 % ToDo: en
5997 %<*ja>
5998 和文・欧文の数式用フォントファミリを一度に変更する命令を作成する.
5999 具体的には,欧文数式用フォントファミリ変更の命令<al-cmd>(\cs{mathrm} 等)と,和文数式用フォ
6000              ントファミリ変更の命令<ja-cmd>(\cs{mathmc} 等)の2つを同時に行う命令として
6001              <unified-cmd>を(再)定義する.実際の使用では<unified-cmd>と
6002              <al-cmd>に同じものを指定する,すなわち,<al-cmd>で和文側も変
6003              更させるようにするのが一般的と思われる.
6004
6005 本命令は
6006 \begin{center}\tt
6007 <unified-cmd>\{<arg>\}\quad$\longrightarrow$\quad
6008 (<al-cmd>の1段展開結果)\{<ja-cmd>の1段展開結果)\{<arg>\}\}
6009 \end{center}
6010 と定義を行うので,使用には注意が必要である:
6011 %<en>\vspace{-\medskipamount}
6012 \begin{itemize}
6013 \item <al-cmd>,~<ja-cmd>は既に定義されていなければならない.
6014       \cs{reDeclareMathAlphabet}\\の後に
6015 両命令の内容を再定義しても,<unified-cmd>の内容にそれは反映されない.
6016 \item <al-cmd>,~<ja-cmd>に\verb+\@mathrm+などと \texttt{@} をつけた命令を指定した時の動作は保証できない.
6017 \end{itemize}
6018 %</ja>
6019
6020 \item[\cs{DeclareRelationFont}\{<ja-encoding>\}\{<ja-family>\}\{<ja-series>\}\{<ja-shape>\}\\*
6021   \null\hfill\{<al-encoding>\}\{<al-family>\}\{<al-series>\}\{<al-shape>\}]
6022 %<*en>
6023 This command sets the ``accompanied'' alphabetic font (given by the latter 4~arguments)
6024 with respect to a Japanese font given by the former 4~arguments.
6025 %</en>
6026 %<*ja>
6027 いわゆる「従属欧文」を設定するための命令である.前半の4引数で表される和文フォントに対して,
6028 そのフォントに対応する「従属欧文」のフォントを後半の4引数により与える.
6029 %</ja>
6030 \item[\cs{SetRelationFont}]
6031 %<*en>
6032 This command is almost same as \cs{DeclareRelationFont}, except that this command does a local
6033 assignment, where \cs{DeclareRelationFont} does a global assignment.
6034 %</en>
6035 %<*ja>
6036 このコマンドは \cs{DeclareRelationFont} とローカルな指定であることを除いて
6037 ほとんど同じである(\cs{DeclareRelationFont} はグローバル).
6038 %</ja>
6039
6040 \item[\cs{userelfont}]
6041 %<*en>
6042 (Only)~at the next call of \cs{selectfont},
6043   change current alphabetic font encoding/family/\dots\ to the `accompanied' alphabetic
6044   font family with respect to current Japanese font family,
6045   which was set by
6046   \cs{DeclareRelationFont} or \cs{SetRelationFont}.
6047 %</en>
6048 %<*ja>
6049 次回(のみ)の\cs{selectfont}の実行時に,現在の欧文フォントのエンコーディング/ファミリ/…… を,
6050 \cs{DeclareRelationFont} か \cs{SetRelationFont} で指定された
6051 現在の和文フォントに対応する「従属欧文」フォントに変更する.
6052 %</ja>
6053
6054 \item[\cs{adjustbaseline}]
6055 %<*en>
6056 In \pLaTeXe, \cs{adjustbaseline} sets \cs{tbaselineshift}
6057 to match the vertical center of ``M'' and that of ``あ''  in vertical typesetting:
6058 \[
6059 \text{\cs{tbaselineshift}} \leftarrow
6060 \frac{(h_{\text{M}}+d_{\text{M}}) - (h_{\text{あ}}+d_{\text{あ}})}2
6061   + d_{\text{あ}} - d_{\text{M}},
6062 \]
6063 where $h_{a}$~and~$d_{a}$ denote the height of ``$a$'' and the depth, respectively.
6064 In \LuaTeX-ja, this \cs{adjustbaseline} does similar task, namely setting the
6065              \Param{talbaselineshift} parameter.
6066 If the \LaTeX\ is 2015/10/01 release or later, \LuaTeX-ja use a Japanese
6067 character whose character class is zero,  instead of `あ'.
6068 %</en>
6069 %<*ja>
6070 \pLaTeXe では,\cs{adjustbaseline} は縦組時に「M」と「あ」の中心線を一致させるために,
6071 \cs{tbaselineshift} を設定する役割を持っていた:
6072 \[
6073 \text{\cs{tbaselineshift}} \leftarrow
6074 \frac{(h_{\text{M}}+d_{\text{M}}) - (h_{\text{あ}}+d_{\text{あ}})}2
6075   + d_{\text{あ}} - d_{\text{M}},
6076 \]
6077 ここで,$h_{a}$,~$d_{a}$はそれぞれ「$a$」の高さ・深さを表す.
6078 \LuaTeX-jaにおいても\cs{adjustbaseline} は同様に\Param{talbaselineshift}パラメータの調整処
6079              理を行っている.
6080
6081 同時に,これも\pLaTeXe の \cs{adjustbaseline} で同様の処理が行われていたが,
6082 「漢」の寸法を元に(本節の最初に述べた,小文字で始まる)\cs{cht}, \cs{cwd}
6083 といった長さ変数を設定する.
6084
6085 なお,\LaTeX が2015/10/01版以降の場合は,「あ」「漢」の代わりに
6086 「文字クラス0の和文文字」を用いる.
6087 %</ja>
6088
6089 \item[\cs{fontfamily}\{<family>\}]
6090 %<*en>
6091 As in \LaTeXe, this command changes current font family (alphabetic, Japanese,~\emph{or both})
6092 to <family>. See Subsection~\ref{ssec:fontfamilycmd} for detail.
6093 %</en>
6094 %<*ja>
6095 元々の\LaTeXe におけるものと同様に,このコマンドは現在のフォントファミリ(欧文,
6096 和文,\emph{もしくは両方})を<family>に変更する.詳細は\ref{ssec:fontfamilycmd}節を参照すること.
6097 %</ja>
6098
6099
6100 \begin{figure}[!tb]
6101 \begin{LTXexample}[pos=b]
6102 \DeclareKanjiFamily{JY3}{edm}{}
6103 \DeclareFontShape{JY3}{edm}{m}{n}    {<-> s*KozMinPr6N-Regular:jfm=ujis;}{}
6104 \DeclareFontShape{JY3}{edm}{m}{green}{<-> s*KozMinPr6N-Regular:jfm=ujis;color=007F00}{}
6105 \DeclareFontShape{JY3}{edm}{m}{blue} {<-> s*KozMinPr6N-Regular:jfm=ujis;color=0000FF}{}
6106 \DeclareAlternateKanjiFont{JY3}{edm}{m}{n}{JY3}{edm}{m}{green}{"4E00-"67FF,{-2}-{-2}}
6107 \DeclareAlternateKanjiFont{JY3}{edm}{m}{n}{JY3}{edm}{m}{blue}{ "6800-"9FFF}
6108 {\kanjifamily{edm}\selectfont
6109 日本国民は、正当に選挙された国会における代表者を通じて行動し、……}
6110 \end{LTXexample}
6111 %<ja>\caption{\cs{DeclareAlternateKanjiFont} の使用例}
6112 %<en>\caption{An example of \cs{DeclareAlternateKanjiFont}}
6113 \label{fig:altkanji}
6114 \end{figure}
6115
6116 \item[\cs{DeclareAlternateKanjiFont}\{<base-encoding>\}\{<base-family>\}\{<base-series>\}\{<base-shape>\}\\
6117   \null\hfill\{<alt-encoding>\}\{<alt-family>\}\{<alt-series>\}\{<alt-shape>\}\{<range>\}]
6118 %<*ja>
6119 \ref{ssec:altfont}節の\
6120 \cs{ltjdeclarealtfont} と同様に,前半の4引数の
6121 和文フォント(基底フォント)のうち<range>中の文字を
6122 第5から第8引数の和文フォントを使って組むように指示する.
6123 使用例を図\nobreak\ref{fig:altkanji}に載せた.
6124
6125 \begin{itemize}
6126  \item
6127 \cs{ltjdeclarealtfont} では基底フォント・置き換え先和文フォントはあらかじめ定義されてい
6128              ないといけない(その代わり即時発効)であったが,
6129 \cs{DeclareAlternateKanjiFont} の設定が
6130 実際に効力が発揮するのは,書体変更やサイズ変更を行った時,
6131 あるいは(これらを含むが)\cs{selectfont} が実行された時である.
6132  \item
6133 段落やhboxの最後での設定値が段落/hbox全体にわたって通用する点や,
6134 <range>に負数$-n$を指定した場合,それが「基底フォントの文字クラス$n$に属する文字全体」
6135 と解釈されるのは \cs{ltjdeclarealtfont} と同じである.
6136 \end{itemize}%
6137 %</ja>
6138 %<*en>
6139 As \cs{ltjdeclarealtfont}~(Subsection~\ref{ssec:altfont}),
6140 characters in <range> of the Japanese font (we say the \emph{base font})
6141 which specified by first 4 arguments are typeset
6142 by the Japanese font which specified by fifth to eighth arguments
6143 (we say the \emph{alternate font}).
6144 An example is shown in \autoref{fig:altkanji}.
6145
6146 \begin{itemize}
6147  \item
6148 In \cs{ltjdeclarealtfont}, the base font and the alternate font must be already defined.
6149 But this \cs{DeclareAlternateKanjiFont} is not so.
6150 In other words, \cs{DeclareAlternateKanjiFont} is effective only after
6151 current Japanese font is changed, or only after \cs{selectfont} is executed.
6152  \item \dots
6153 \end{itemize}%
6154 \vspace{-\medskipamount}
6155 %</en>
6156 \end{cslist}
6157
6158 %<*en>
6159 As closing this subsection, we shall introduce an example of
6160 \cs{SetRelationFont} and \cs{userelfont}:
6161 %</en>
6162 %<*ja>
6163 この節の終わりに,\cs{SetRelationFont} と \cs{userelfont} の例を
6164 紹介しておこう.\cs{userelfont} の使用によって,「abc」の部分のフォントが
6165 Latin Modern Sans Serif (TU/lmss/m/n) に変わっていることがわかる.
6166 %</ja>
6167 \begin{LTXexample}[width=0.3\textwidth]
6168 \makeatletter
6169 \SetRelationFont{JY3}{\k@family}{m}{n}{TU}{lmss}{m}{n}
6170   % \k@family: current Japanese font family
6171 \userelfont\selectfont あいうabc
6172 \end{LTXexample}
6173
6174 %<en>\subsection{Detail of \cs{fontfamily} command}
6175 %<ja>\subsection{\cs{fontfamily}コマンドの詳細}
6176 \label{ssec:fontfamilycmd}
6177 %<*en>
6178 In this subsection, we describe when \cs{fontfamily}<family> changes current
6179 Japanese/alphabetic font family. Basically, current Japanese fotn family is changed to
6180 <family> if it is recognized as a Japanese font family, and similar with alphabetic font
6181 family. There is a case that current Japanese/alphabetic font family are both changed to
6182 <family>, and another case that <family> isn't recognized as a Japanese/alphabetic font
6183 family either.
6184
6185 \paragraph{Recognition as Japanese font family}
6186 First, Whether Japanese font family will be changed is determined in following order.
6187 This order is very similar to \cs{fontfamily} in \pLaTeXe, but we re-implemented in Lua.
6188 We use an auxiliary list~$N_{\mathrm{J}}$.
6189 %</en>
6190 %<*ja>
6191 本節では,\cs{fontfamily}<family> がいつ和文/欧文フォントファミリを変更するかについて解説
6192 する.基本的には,<family>が和文フォントファミリだと認識されれば和文側が,欧文フォントファ
6193 ミリだと認識されれば欧文側が変更される.どちらとも認識されれば和文・欧文の両方が変わるこ
6194 とになるし,当然どちらとも認識されないこともある.
6195
6196 \paragraph{和文フォントファミリとしての認識}
6197 まず,<family>が和文フォントファミリとして認識されるかは以下の順序で決定される.
6198 これは\pLaTeXe の \cs{fontfamily} にとても似ているが,ここではLuaによって実装している.
6199 補助的に「和文フォントファミリではないと認識された」ファミリを格納したリスト$N_{\mathrm{J}}$を用いる.
6200 %</ja>
6201 \begin{enumerate}
6202 %<*en>
6203 \item If the family~<family> has been defined already by \cs{DeclareKanjiFamily},
6204       <family> is recognized as a  Japanese font family.
6205       Note that <family> need not be defined under \emph{current} Japanese font encoding.
6206 %</en>
6207 %<*ja>
6208 \item ファミリ<family>が既に \cs{DeclareKanjiFamily} によって定義されている場合,
6209       <family>は和文フォントファミリであると認識される.
6210       ここで,<family>は現在の和文フォントエンコーディングで定義されていなくてもよい.
6211 %</ja>
6212 %<*en>
6213 \item If the family~<family> has been listed in a list~$N_{\mathrm{J}}$, this means
6214       that <family> is not a Japanese font family.
6215 %</en>
6216 %<*ja>
6217 \item ファミリ<family>がリスト$N_{\mathrm{J}}$に既に含まれていれば,それは
6218       <family>が和文フォントファミリではないことを意味する.
6219 %</ja>
6220 %<*en>
6221 \item If the \Pkg{luatexja-fontspec} package is loaded, we stop here, and <family> is not
6222       recognized as a Japanese font family.
6223
6224       If the \Pkg{luatexja-fontspec} package is \emph{not} loaded,
6225 now \LuaTeX-ja looks whether there exists a Japanese font encoding~<enc> such that
6226       a font definition named \texttt{<enc><family>.fd} (the file name is
6227       all lowercase) exists. If so, <family> is recognized as a  Japanese font family (the font definition file won't be loaded here).
6228       If not, <family> is not a Japanese font family, and
6229       <family> is appended to the list~$N_{\mathrm{J}}$.
6230 %</en>
6231 %<*ja>
6232 \item もし\Pkg{luatexja-fontspec}パッケージが読み込まれていれば,ここで終了であり,
6233 <family>は和文フォントファミリとして認識されないことになる.
6234
6235 もし\Pkg{luatexja-fontspec}パッケージが読み込まれていなければ,和文エンコーディング<enc>で
6236 フォント定義ファイル\texttt{<enc><family>.fd}(ファイル名は全て小文字)が存在するようなも
6237       のがあるかどうかを調べる.
6238 存在すれば,<family>は和文フォントファミリと認識される(フォント定義ファイルは読み込まれな
6239       い).
6240 存在しなければ,<family>は和文フォントファミリでないと認識され,リスト$N_{\mathrm{J}}$に<family>を追加することでそれを記憶する.
6241
6242 %</ja>
6243 \end{enumerate}
6244
6245 %<*en>
6246 \paragraph{Recognition as alphabetic font family}
6247 Next, whether alphabetic font family will be changed is determined in following order.
6248 We use auxiliary lists $F_{\mathrm{A}}$~and~$N_{\mathrm{A}}$,
6249 %</en>
6250 %<*ja>
6251 \paragraph{欧文フォントファミリとしての認識}
6252 同様に,<family>が和文フォントファミリとして認識されるかは以下の順序で決定される.
6253 補助的に「欧文フォントファミリと既に認識された」ファミリのリスト$F_{\textrm{A}}$と,
6254 「欧文フォントファミリではないと認識された」ファミリを格納したリスト$N_{\mathrm{A}}$を用いる.
6255 %</ja>
6256
6257 \begin{enumerate}
6258 %<*en>
6259 \item If the family~<family> has been listed in a list~$F_{\mathrm{A}}$,
6260       <family> is recognized as an alphabetic font family.
6261 %</en>
6262 %<*ja>
6263 \item ファミリ<family>がリスト$F_{\mathrm{A}}$に既に含まれていれば,
6264       <family>は欧文フォントファミリと認識される.
6265 %</ja>
6266 %<*en>
6267 \item If the family~<family> has been listed in a list~$N_{\mathrm{A}}$, this means
6268       that <family> is not  an alphabetic font family.
6269 %</en>
6270 %<*ja>
6271 \item ファミリ<family>がリスト$N_{\mathrm{A}}$に既に含まれていれば,それは
6272       <family>が欧文フォントファミリではないことを意味する.
6273 %</ja>
6274 %<*en>
6275 \item If there exists an alphabetic font encoding such that the family~<family> has been
6276       defined under it, <family> is recognized as an alphabetic font family, and
6277       to memorize this, <family> is appended to the list~$F_{\mathrm{A}}$.
6278 %</en>
6279 %<*ja>
6280 \item ある欧文フォントエンコーディング下でファミリ<family>が定義されていれば,
6281       <family>は欧文フォントファミリと認識され,リスト$F_{\mathrm{A}}$に<family>を追加することでこのことを記憶する.
6282 %</ja>
6283 %<*en>
6284 \item Now \LuaTeX-ja looks whether there exists an alphabetic font encoding~<enc> such that
6285       a font definition named \texttt{<enc><family>.fd} (the file name is
6286       all lowercase) exists. If so, current alphabetic font family will be changed to
6287       <family>~(the font definition file won't be loaded here).
6288       If not, current alphabetic font family won't be changed, and
6289       <family> is appended to the list~$N_{\mathrm{A}}$.
6290 %</en>
6291 %<*ja>
6292 \item 最終段階では,欧文エンコーディング<enc>で
6293 フォント定義ファイル\texttt{<enc><family>.fd}(ファイル名は全て小文字)が存在するようなも
6294       のがあるかどうかを調べる.
6295 存在すれば,<family>は欧文フォントファミリと認識される(フォント定義ファイルは読み込まれない).
6296 存在しなければ,<family>は欧文フォントファミリと認識されないので,リスト$N_{\mathrm{A}}$に
6297       <family>を追加してそのことを記憶する.
6298 %</ja>
6299 \end{enumerate}
6300
6301 %<*en>
6302 Also, each call of \cs{DeclareFontFamily} \emph{after} loading of \LuaTeX-ja makes
6303 the second argument (family) is appended to the list~$F_{\mathrm{A}}$.
6304 %</en>
6305 %<*ja>
6306 また,\cs{DeclareFontFamily}が\LuaTeX-jaの読み込み後に実行された場合は,
6307 第2引数(ファミリ名)が自動的に$F_{\mathrm{A}}$に追加される.
6308 %</ja>
6309
6310 %<*en>
6311 The above order is very similar to \cs{fontfamily} in \pLaTeXe, but more complicated (clause~3.).
6312 This is because  \pLaTeXe\ is a \emph{format} however \LuaTeX-ja is not,
6313 hence \LuaTeX-ja does not know calls of \cs{DeclareFontFamily} \emph{before} itself is
6314 loaded.
6315 %</en>
6316 %<*ja>
6317 以上の方針は\pLaTeXe における \cs{fontfamily} にやはり類似しているが,3.が加わり若干複雑になっている.
6318 それは\pLaTeXe がフォーマットであるのに対し\LuaTeX-jaはそうでないため,
6319 \LuaTeX-jaは自身が読み込まれる前にどういう\cs{DeclareFontFamily}の呼び出しがあったか
6320 把握できないからである.
6321 %</ja>
6322
6323 %<en>\paragraph{Remarks}
6324 %<ja>\paragraph{注意}
6325 %<*en>
6326 Of course, there is a case that <family> is not recognized as a Japanese font family,  nor
6327 an alphabetic font family.
6328 In this case, \LuaTeX-ja treats ``the argument <family> is wrong'', so
6329 set both current alphabetic and Japanese font family to <family>,
6330 to use the default family for font substitution.
6331 %</en>
6332 %<*ja>
6333 さて,引数によっては,「和文フォントファミリとも欧文フォントファミリも認識されなかった」
6334 という事態もあり得る.
6335   この場合,引数<family>は不正だった,ということになるので,
6336 和文・欧文の両方のフォントファミリを<family>に設定し,代用フォントが使われるに任せることにする.
6337 %</ja>
6338
6339 %<*en>
6340 \subsection{Notes on \cs{DeclareTextSymbol}}
6341 From \LaTeX~2017/01/01, the standard encoding of \LuaLaTeX\ is changed to the \texttt{TU}
6342 encoding. This menas that symbols defined by \texttt{T1}~and~\texttt{TS1} encodings can be used
6343 without loading any package. To produces these symbols in alphabetic fonts in \LuaTeX-ja,
6344 \LuaTeX-ja patches \cs{DeclareTextSymbol}, and reloads \texttt{tuenc.def}.
6345
6346 Under original definition of \cs{DeclareTextSymbol},
6347 internal commands which is defined by \cs{DeclareTextSymbol} (such as \cs{T1\cs{textquotedblleft}})
6348 are \textit{chardef} tokens. However, this no longer holds in \LuaTeX-ja;
6349 for example, the meaning of \cs{TU\cs{textquotedblleft}} is \cs{ltjalchar8220\ltjalchar"2423 }.
6350 %</en>
6351 %<*ja>
6352 \subsection{\cs{DeclareTextSymbol}使用時の注意}
6353 \LaTeX~(2017/01/01)以降では,\texttt{TU}エンコーディングが標準となり,特に何もしなくても
6354 \texttt{T1},~\texttt{TS1}エンコーディングで定義されていた記号類が
6355 使えるようになった.\LuaTeX-jaではこれらの命令によって記号が欧文フォントで出力されるようにするため,
6356 \cs{DeclareTextSymbol}命令を改変し,そして\texttt{TU}エンコーディングの定義である
6357 \texttt{tuenc.def}を再読込している.
6358
6359 従来は \cs{DeclareTextSymbol} で内部的に定義された\cs{T1\cs{textquotedblleft}}といった命令は
6360 \textit{chardef}トークンであった.しかし前段落で述べた改変によりもはやそうではなくなっており,例えば
6361 \cs{TU\cs{textquotedblleft}}は \cs{ltjalchar8220\ltjalchar"2423 } という定義になっている.%"
6362 %</ja>
6363
6364 \begin{table}[t]
6365   \centering\small
6366   \caption{strut}\label{tab:strutbox}
6367   \begin{tabular}{llcccl}
6368     \toprule
6369     \textbf{box}&\textbf{direction}&\textbf{width}&\textbf{height}&\textbf{depth}
6370     &\textbf{user command}\\
6371     \midrule
6372   \cs{ystrutbox}&yoko&0&0.7\cs{baselineskip}&0.3\cs{baselineskip}&\cs{ystrut}\\\midrule
6373   \cs{tstrutbox}&tate, utod&0&0.5\cs{baselineskip}&0.5\cs{baselineskip}&\cs{tstrut}\\\midrule
6374   \cs{dstrutbox}&dtou&0&0.7\cs{baselineskip}&0.3\cs{baselineskip}&\cs{dstrut}\\\midrule
6375   \cs{zstrutbox}&---&0&0.7\cs{baselineskip}&0.3\cs{baselineskip}&\cs{zstrut}\\\bottomrule
6376   \end{tabular}
6377 \end{table}
6378 %<*en>
6379 \subsection{\cs{strutbox}}
6380 As \pLaTeX~(2017/04/08 or later), \cs{strutbox} is \emph{a macro} which is expanded to one of
6381 \cs{ystrutbox},~\cs{tstrutbox},~and~\cs{dstrutbox}
6382 (all of them are shown in \autoref{tab:strutbox}), according to the current direction.
6383 Similarly, \cs{strut} now uses one of these boxes.
6384 %</en>
6385 %<*ja>
6386 \subsection{\cs{strutbox}}
6387 \pLaTeX~2017/04/08以降と同じように,
6388 \cs{strutbox}は現在の組方向によって\cs{ystrutbox}, \cs{tstrutbox}, \cs{dstrutbox}の
6389 いずれかに展開される\emph{マクロ}となっている(これらについては\autoref{tab:strutbox}参照).
6390 同様に\cs{strut}もこの3\nobreak ボックスのいずれかを組方向によって使い分けるようになっている.
6391
6392 \cs{zstrutbox}はutod方向(\pTeX でいう縦数式ディレクション)で使われる支柱ボックスであるが,
6393 実際に使われるのは\cs{zstrut}が明示的に発行された時,そして
6394 \Pkg{lltjext}パッケージで追加される組方向指定で \texttt{<u>} を指定した時,および
6395 周囲が縦組の状況で \texttt{<z>} を指定した時に限られている.
6396 %</ja>
6397
6398 %<*en>
6399 \section{Addon packages}
6400 \LuaTeX-ja has several addon packages.
6401 These addons are written as \LaTeX\ packages, but
6402 \Pkg{luatexja-otf} and~\Pkg{luatexja-adjust} can be loaded in plain \LuaTeX\
6403 by \cs{input}.
6404 %</en>
6405 %<*ja>
6406 \section{拡張パッケージ}
6407 \LuaTeX-jaには(動作には必須ではないが)自由に読み込める拡張が付属している.
6408 これらは\LaTeX のパッケージとして制作しているが,
6409 \Pkg{luatexja-otf}と\Pkg{luatexja-adjust}についてはplain \LuaTeX でも\
6410 \cs{input} で読み込み可能である.
6411 %</ja>
6412 \subsection{\Pkg{luatexja-fontspec}}
6413 \label{ssec:fontspec2}
6414 %<*en>
6415 As described in Subsection~\ref{ssec:fontspec}, this optional package
6416 provides the counterparts for several commands defined in the
6417 \Pkg{fontspec} package (requires \Pkg{fontspec}~v2.4).
6418 In addition to OpenType font features in the original \Pkg{fontspec},
6419 the following ``font features'' specifications are allowed for
6420 the commands of Japanese version:
6421 %</en>
6422 %<*ja>
6423 \ref{ssec:fontspec}節で述べたように,この追加パッケージは\Pkg{fontspec}%
6424 パッケージで定義されているコマンドに対応する和文フォント用のコマンドを提供する.
6425
6426 \Pkg{fontspec}パッケージで指定可能な各種OpenType機能に加えて,和文版のコマンドには
6427 以下の「フォント機能」を指定することができる:
6428 %</ja>
6429
6430
6431 \begin{cslist}
6432 \item[CID=<name>\textrm{, }JFM=<name>\textrm{, }JFM-var=<name>]
6433
6434 %<*en>
6435 These 3 keys correspond to \texttt{cid}, \texttt{jfm} and
6436 \texttt{jfmvar} keys for \cs{jfont}~and~\cs{tfont} respectively.
6437 See Subsections~\ref{ssec:jfont} and \ref{ssec:psft} for details
6438  of \texttt{cid}, \texttt{jfm} and
6439 \texttt{jfmvar} keys.
6440
6441 The \texttt{CID} key is effective only when with \texttt{NoEmbed}
6442 described below. The same JFM cannot be used in both horizontal Japanese fonts and
6443              vertical Japanese fonts, hence the \texttt{JFM} key
6444 will be actually used in \texttt{YokoFeatures}~and~\texttt{TateFeatures} keys.
6445 %</en>
6446 %<*ja>
6447 これら3つのキーはそれぞれ \cs{jfont},~\cs{tfont}に対する
6448 \texttt{cid}, \texttt{jfm}, \texttt{jfmvar}キーとそれぞれ対応する.
6449 \texttt{cid}, \texttt{jfm}, \texttt{jfmvar}キーの詳細は\ref{ssec:jfont}節
6450              と\ref{ssec:psft}節を参照.
6451
6452 \texttt{CID} キーは下の \texttt{NoEmbed} と合わせて用いられたときのみ有効である.
6453 また,横組用JFMと縦組用JFMは共用できないため,実際に \texttt{JFM} キーを用いる際は
6454 後に述べる\ \texttt{YokoFeatures} キーや \texttt{TateFeatures}\ の中で用いる
6455 ことになる.
6456 %</ja>
6457
6458 \item[NoEmbed]
6459 %<*en>
6460 By specifying this key, one can use ``name-only'' Japanese font which
6461 will not be embedded in the output PDF file. See Subsection~\ref{ssec:psft}.
6462 %</en>
6463 %<*ja>
6464 これを指定することで,PDFに埋め込まれない「名前だけ」のフォントを指定することが
6465 できる.\ref{ssec:psft}節を参照.
6466 %</ja>
6467
6468 \begin{figure}[!tb]
6469 \begin{LTXexample}[width=0.25\textwidth]
6470 \jfontspec[
6471   YokoFeatures={Color=007F00}, TateFeatures={Color=00007F},
6472   TateFont=KozGoPr6N-Regular
6473 ]{KozMinPr6N-Regular}
6474 \hbox{\yoko 横組のテスト}\hbox{\tate 縦組のテスト}
6475 \addjfontfeatures{Color=FF0000}
6476 \hbox{\yoko 横組}\hbox{\tate 縦組}
6477 \end{LTXexample}
6478 %<ja>\caption{\texttt{TateFeatures} 等の使用例}
6479 %<en>\caption{An example of \texttt{TateFeatures} etc.}
6480 \label{fig:yokotate-fontspec}
6481 \end{figure}
6482
6483 \item[Kanjiskip=<bool>]
6484 %<*ja>
6485 \pageref{pg:ltjksp}ページで説明した \verb+\jfont+ 中での \texttt{ltjksp} 指定と
6486 同一の効力を持ち,
6487 JFM中における \texttt{kanjiskip\_natural}, \texttt{kanjiskip\_stretch},\
6488 \texttt{kanjiskip\_shrink}キー(\pageref{pg:ksp_nat}ページ)の有効/無効を切り替える.
6489 標準値は \texttt{true} である.
6490 %</ja>
6491
6492 \item[TateFeatures=\{<features>\}\textrm{, }TateFont=<font>]
6493 %<*en>
6494 The \texttt{TateFeatures} key specifies font features which are only turned~on in
6495 vertical writing, such as \texttt{Style=VerticalKana}~(\texttt{vkna} feature).
6496 Similarly, the \texttt{TateFont} key specifies the Japanese font which will be used only
6497              in vertical writing.
6498 A demonstrarion is shown in \autoref{fig:yokotate-fontspec}.
6499 %</en>
6500 %<*ja>
6501 縦組において使用されるフォントや,縦組においてのみ適用されるフォント機能達を
6502 指定する.使用例は\autoref{fig:yokotate-fontspec}参照.
6503 %</ja>
6504
6505 \item[YokoFeatures=\{<features>\}]
6506 %<*en>
6507 The \texttt{YokoFeatures} key specifies font features which are only turned~on in
6508 horizontal writing,.
6509 A demonstrarion is shown in \autoref{fig:yokotate-fontspec}.
6510 %</en>
6511 %<*ja>
6512 同様に,横組においてのみ適用されるフォント機能達を
6513 指定する.使用例は\autoref{fig:yokotate-fontspec}参照.
6514 %</ja>
6515
6516
6517 \begin{figure}[!tb]
6518 \begin{LTXexample}[pos=b]
6519 \jfontspec[
6520   AltFont={
6521     {Range="4E00-"67FF, Color=007F00},
6522     {Range="6800-"9EFF, Color=0000FF},
6523     {Range="3040-"306F, Font=KozGoPr6N-Regular},
6524   }
6525 ]{KozMinPr6N-Regular}
6526 日本国民は、正当に選挙された国会における代表者を通じて行動し、われらとわれらの子孫のために、
6527 諸国民との協和による成果と、わが国全土にわたつて自由のもたらす恵沢を確保し、……
6528 \end{LTXexample}
6529 %<ja>\caption{\texttt{AltFont} の使用例}
6530 %<en>\caption{An example of \texttt{AltFont}}
6531 \label{fig:altkanji-fontspec}
6532 \end{figure}
6533
6534 \item[AltFont]
6535
6536 %<*en>
6537 As \cs{ltjdeclarealtfont}~(Subsection~\ref{ssec:altfont}) and
6538 \cs{DeclareAlternateKanjiFont}~(Subsection~\ref{ssec:nfsspat}),
6539 with this key, one can typeset some Japanese characters
6540 by a different font and/or using different features.
6541 The \texttt{AltFont} feature takes a comma-separated list of comma-separated lists,
6542 as the following:
6543 %</en>
6544 %<*ja>
6545 \ref{ssec:altfont}節の \cs{ltjdeclarealtfont} や,
6546 \ref{ssec:nfsspat}節の \cs{DeclareAlternateKanjiFont} と同様に,
6547 このキーを用いると一部の文字を異なったフォントや機能たちを使って組むことができる.
6548 \texttt{AltFont} キーに指定する値は,次のように二重のコンマ区切りリストである:
6549 %</ja>
6550 \begin{lstlisting}[escapechar=\#]
6551 AltFont = {
6552   ...
6553   { Range=#\LARG range>#, #\LARG features>#},
6554   { Range=#\LARG range>#, Font=#\LARG font~name>#, #\LARG features># },
6555   { Range=#\LARG range>#, Font=#\LARG font~name># },
6556   ...
6557 }
6558 \end{lstlisting}
6559 %<*en>
6560 Each sublist should have the \texttt{Range} key
6561 (sublist which does not contain \texttt{Range} key is simply ignored).
6562 A demonstrarion is shown in \autoref{fig:altkanji-fontspec}.
6563 %</en>
6564 %<*ja>
6565 各部分リストには \texttt{Range} キーが必須である(含まれない部分リストは
6566 単純に無視される).指定例は\autoref{fig:altkanji-fontspec}に示した.
6567 %</ja>
6568 \end{cslist}
6569
6570 %<*ja>
6571 なお,\Pkg{luatexja-fontspec} 読み込み時には和文フォント定義ファイル%
6572 \texttt{<ja-enc><family>.fd}は全く参照されなくなる.
6573 %</ja>
6574
6575
6576 %<*en>
6577 \paragraph{Remark on \texttt{AltFont}, \texttt{YokoFeatures}, \texttt{TateFeatures} keys}
6578 \leavevmode\par
6579 In \texttt{AltFont},~\texttt{YokoFeatures},~\texttt{TateFeatures} keys,
6580 one cannot specify per-shape settings such as \texttt{BoldFeatures}.
6581 For example,
6582 \begin{lstlisting}
6583 AltFont = {
6584   { Font=HogeraMin-Light, BoldFont=HogeraMin-Bold,
6585     Range="3000-"30FF, BoldFeatures={Color=007F00} }
6586 }
6587 \end{lstlisting}
6588 does \emph{not} work. Instead, one have to write
6589 \begin{lstlisting}
6590 UprightFeatures = {
6591   AltFont = { { Font=HogeraMin-Light, Range="3000-"30FF, } },
6592 },
6593 BoldFeatures = {
6594   AltFont =  { { Font=HogeraMin-Bold, Range="3000-"30FF, Color=007F00 } },
6595 }
6596 \end{lstlisting}
6597
6598 On the other hand, \texttt{YokoFeatures}, \texttt{TateFeatures} and  \texttt{TateFont}
6599 keys can be specified in each list in the \texttt{AltFont} key. Also,
6600 one can specify \texttt{AltFont} inside \texttt{YokoFeatures},~\texttt{TateFeatures}.
6601
6602 Note that features which are specified in \texttt{YokoFeatures}~and~\texttt{TateFeatures}
6603 are always interpreted \emph{after} other ``direction-independent'' features.
6604 This explains why \cs{addjfontfeatures} at~line~6 in~\autoref{fig:yokotate-fontspec}
6605 has no effect, because a color specification is already done in
6606 \texttt{YokoFeatures}~and~\texttt{TateFeatures} keys.
6607 %</en>
6608 %<*ja>
6609 \paragraph{\texttt{AltFont}, \texttt{YokoFeatures}, \texttt{TateFeatures} 等の制限}
6610 \texttt{AltFont},~\texttt{YokoFeatures},~\texttt{TateFeatures}の各キーは
6611 シェイプ別に指定されるべきものであり,
6612 内部では \texttt{BoldFeatures} などのシェイプ別の指定は行うことが出来ない.
6613 例えば.
6614 \begin{lstlisting}
6615 AltFont = {
6616   { Font=HogeraMin-Light, BoldFont=HogeraMin-Bold,
6617     Range="3000-"30FF, BoldFeatures={Color=007F00} }
6618 }
6619 \end{lstlisting}
6620 のように指定することは出来ず,
6621 \begin{lstlisting}
6622 UprightFeatures = {
6623   AltFont = { { Font=HogeraMin-Light, Range="3000-"30FF, } },
6624 },
6625 BoldFeatures = {
6626   AltFont =  { { Font=HogeraMin-Bold, Range="3000-"30FF, Color=007F00 } },
6627 }
6628 \end{lstlisting}
6629 のように指定しなければならない.
6630
6631 一方,\texttt{AltFont} キー内の各リストでは
6632 \ \texttt{YokoFeatures},~\texttt{TateFeatures} 及び \texttt{TateFont} キーを
6633 指定することは可能であり.また\ \texttt{YokoFeatures},~\texttt{TateFeatures} キーの
6634 中身に \texttt{AltFont} を指定することができる.
6635
6636 また,\autoref{fig:yokotate-fontspec}後半部では6行目の色の指定が効かず,
6637 2行目で指定した\ \texttt{YokoFeatures},~\texttt{TateFeatures}\ による色の指定が有効になっ
6638 たままである.これは\emph{\ \texttt{YokoFeatures},~\texttt{TateFeatures}\ による
6639 OpenType機能指定は
6640 組方向に依存しないOpenType機能の指定より後に解釈される}からである.
6641
6642 %</ja>
6643
6644
6645 \subsection{\Pkg{luatexja-otf}}
6646 \label{ssec:ltjotf}
6647 %<*en>
6648 This optional package supports typesetting glyphs
6649 by specifying a CID number.
6650 The package \Pkg{luatexja-otf} offers the following 2~low-level
6651 commands:
6652 %</en>
6653 %<*ja>
6654 この追加パッケージはCID番号による文字の出力をサポートする.
6655 \Pkg{luatexja-otf}は以下の2つの低レベルコマンドを提供する:
6656 %</ja>
6657 \begin{cslist}
6658 \item[\cs{CID}\{<number>\}]
6659 %<*en>
6660 Typeset a glyph whose CID number is <number>.
6661 If the Japanese font is neither Adobe-Japan1,~Adobe-GB1, Adobe-CNS1,~nor~Adobe-Korea1 CID-keyed font,
6662 \LuaTeX-ja treats that <number> is a CID number of Adobe-Japan1 character collection,
6663 and tries to typeset a ``most suitable glyph''.
6664 %</en>
6665 %<*ja>
6666 CID番号が<number>の文字を出力する.
6667 もし現在の和文フォントがAdobe-Japan1,~Adobe-GB1, Adobe-CNS1,~Adobe-Korea1の
6668   いずれのCID-keyed fontでもない場合,<number>はAdobe-Japan1のCID番号であると解釈し
6669   「適切なグリフ」\footnote{%
6670   例えばフォントにIVDコレクションAdobe-Japan1が含まれていれば,その情報を用いて
6671   グリフを選択する.
6672 }を出力する.
6673 %</ja>
6674
6675 \item[\cs{UTF}\{<hex\_number>\}]
6676 %<*en>
6677 Typeset a character whose character code is <hex\_number> (in hexadecimal).
6678 This command is similar to \verb+\char"+<hex\_number>,\ %"
6679 but please remind remarks below.
6680 %</en>
6681 %<*ja>
6682 文字コードが(16進で)<hex\_number>の文字を出力する.
6683 このコマンドは \verb+\char"+<hex\_number>と似ているが,下の注意を参照すること.%"
6684 %</ja>
6685 \end{cslist}
6686
6687 %<*ja>
6688 このパッケージは,マクロ集 \texttt{luatexja-ajmacros.sty}\footnote{\Pkg{otf}パッケージ付属の井上浩一氏によるマクロ集
6689 \texttt{ajmacros.sty} に対して
6690 漢字コードをUTF-8にしたり,plain \LuaTeX でも利用可能にするという
6691 修正を加えたものである.}\ も自動的に読み込む.
6692 \texttt{luatexja-ajmacros.sty} は,
6693 そのため,\Pkg{luatexja-otf} を読みこめば \texttt{ajmacros.sty} マクロ集にある \cs{aj半角} などのマクロもそのまま使うことができる.
6694 %</ja>
6695 %<*en>
6696 This package automatically loads \texttt{luatexja-ajmacros.sty}, which is slightly
6697 modified version of \texttt{ajmacros.sty}\footnote{Useful macros by iNOUE Koich!, for the
6698 \Pkg{japanese-otf} package.}.
6699 Hence one can use macros which sre defined in \texttt{ajmacros.sty}, such as~\cs{aj半角}.
6700 %</en>
6701
6702 %<en>\paragraph{Remarks}
6703 %<ja>\paragraph{注意}
6704 %<*en>
6705 Characters by \cs{CID} and \cs{UTF} commands are different from
6706 ordinary characters in the following points:
6707 %</en>
6708 %<*ja>
6709 \cs{CID} と \cs{UTF} コマンドによって出力される文字は
6710 以下の点で通常の文字と異なる:
6711 %</ja>
6712 \begin{itemize}
6713 %<*en>
6714 \item Always treated as \textbf{JAchar}s.
6715 %</en>
6716 %<*ja>
6717 \item 常に\textbf{JAchar}として扱われる.
6718 %</ja>
6719 %<*en>
6720 \item Processing codes for supporting OpenType features (\textit{e.g.},
6721       glyph replacement and kerning) by the \Pkg{luaotfload} package
6722       is not performed to these characters.
6723 %</en>
6724 %<*ja>
6725 \item OpenType機能(例えばグリフ置換やカーニング)をサポートするための
6726   \Pkg{luaotfload}パッケージのコードはこれらの文字には働かない.
6727 %</ja>
6728 \end{itemize}
6729
6730 %<en>\paragraph{Additional syntax of JFM}
6731 %<ja>\paragraph{JFMへの記法の追加}
6732
6733 %<*en>
6734 The package \Pkg{luatexja-otf} extends the syntax of JFM; the entries of \texttt{
6735 chars} table in JFM now allows a string in the form
6736 \verb+'AJ1-xxx'+, which stands for the character
6737 whose CID number in Adobe-Japan1 is \verb+xxx+.
6738
6739 This extended notation is used in the standard JFM \texttt{jfm-ujis.lua}
6740 to typeset halfwidth Hiragana glyphs (CID~516--598) in halfwidth.
6741 %</en>
6742 %<*ja>
6743 \Pkg{luatexja-otf}パッケージを読み込むと,
6744 JFMの\texttt{chars}テーブルのエントリとして \verb+'AJ1-xxx'+ の形の文字列が
6745 使えるようになる.これはAdobe-Japan1におけるCID番号が \verb+xxx+ の文字を表す.
6746
6747 この拡張記法は,標準JFM~\texttt{jfm-ujis.lua}で,半角ひらがなのグリフ(CID~516--598)を
6748 正しく半角幅で組むために利用されている.
6749 %</ja>
6750
6751 \subsection{\Pkg{luatexja-adjust}}
6752 \label{ssec:adj}
6753 \begin{figure}[t]
6754 \def\sq{%
6755   \hbox to 1\zw{\hss\fboxsep=-.5\fboxrule\fbox{%
6756    \hskip\dimexpr-.5\zw-.2pt\vrule width.4pt height.08\zw depth.12\zw%
6757   \hskip\dimexpr.5\zw-.2pt\relax}\hss}}
6758 \def\sb{\hbox to 1\zw{\hss\fboxsep=-.5\fboxrule\fbox{%
6759   ■\hskip\dimexpr-.5\zw-.2pt\vrule width.4pt height.08\zw depth.12\zw%
6760   \hskip\dimexpr.5\zw-.2pt\relax}\hss}}
6761 \newbox\gridbox
6762 \def\outbox#1{{\Large%
6763   \ltjsetparameter{kanjiskip=0pt plus .2\zw minus .2\zw}%
6764   \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}%
6765   \hbox{\textcolor{cyan}{\copy\gridbox}\hskip-20\zw%
6766   \vbox{\hsize=20\zw\noindent\leftskip0pt\rightskip0pt\parfillskip0pt#1}\vrule}%
6767 }}
6768
6769 {\centering
6770 \begin{tabular}{lc}
6771 \toprule
6772 no adjustment&\outbox{以上の原理は,「包除原理」とよく呼ばれるが\hskip-.5\zw\null}\\
6773 without priority&%
6774 \ltjdisableadjust
6775 \outbox{以上の原理は,「包除原理」とよく呼ばれるが}%
6776 \ltjenableadjust\\
6777 with priority&%
6778 \outbox{以上の原理は,「包除原理」とよく呼ばれるが}
6779 %<en>\ltjdisableadjust
6780 \\
6781 \bottomrule
6782 \end{tabular}\par}
6783 \smallskip
6784
6785 Note: the value of
6786 \Param{kanjiskip} is 0\,pt${}^{+1/5\,\mathrm{em}}_{-1/5\,\mathrm{em}}$ in this figure,
6787 for making the difference obvious.
6788 %<ja>\caption{行長調整}\label{fig:adj}
6789 %<en>\caption{Line adjustment}\label{fig:adj}
6790 \end{figure}
6791
6792
6793 %<*en>
6794 (see Japanese version of this manual)
6795 %</en>
6796 %<*ja>
6797 この追加パッケージは以下の機能を提供する.詳細な仕様については\ref{sec-adjspec}章を参照してほしい.
6798 \begin{description}
6799  \item[行末文字の位置調整]
6800   \pTeX では,(是非はともかく)「行末の読点はぶら下げか二分取りか全角取りのいずれかに」のように
6801   行末文字と実際の行末の位置関係を2通り以上にすることは面倒であった.
6802   和文フォントメトリックだけでは「常に行末の読点はぶら下げ」といったことしかできず,
6803   前の文に書いたことを実現するには
6804   \begin{lstlisting}
6805 \def\。{%
6806   \penalty10000 % 禁則ペナルティ
6807   \hbox to0pt{。\hss}\penalty0 % ぶら下げの場合
6808   \kern.5\zw\penalty0 % 二分取りの場合
6809   \kern.5\zw\penalty0 % 全角取りの場合
6810 }
6811 \end{lstlisting}
6812   のような命令を定義し,文中の全ての句点を \lstinline+\。+ で書くことが必要だった.
6813
6814   \Pkg{luatexja-adjust}パッケージは,上で述べた行末文字と実際の行末との位置関係を
6815   2通り以上から自動的に選択する機能を提供する.
6816   \pdfTeX と同じように,「\TeX による行分割の後で行末文字の位置を補正する」方法と
6817   「行分割の過程で行末文字の位置を考慮に入れる」方法を選べるようにした
6818   (\Pkg{luatexja-adjust}パッケージの既定では前者).
6819   
6820  \item[優先順位付きの行長調整]
6821   \pTeX では,行長調整において優先度の概念が存在しなかったため,図
6822   \ref{fig:adj}上段における半角分の半端は,\autoref{fig:adj}中段のように,鍵
6823   括弧周辺の空白と和文間空白(\Param{kanjiskip})の両方によって負担される.し
6824   かし,「日本語組版処理の要件」\cite{jlreq}やJIS~X~4051~\cite{x4051}におい
6825   ては,このような状況では半端は鍵括弧周辺の空白のみで負担し,その他の和文
6826   文字はベタ組で組まれる(\autoref{fig:adj}下段)ことになっている.
6827   \Pkg{luatexja-adjust}パッケージの提供する第2の機能は,
6828   \cite{jlreq}や\cite{x4051}における規定のような,優先順位付き
6829   の行長調整である.
6830   \begin{itemize}
6831    \item 優先度付き行長調整は,段落を行分割した後に個々の行について行われるものである.
6832         そのため,行分割の位置は変化することはない.
6833         
6834         \verb+\hbox{...}+ といった「途中で改行できない水平ボックス」では(たとえ幅が指定されていても)無効である.
6835    \item 優先度付き行長調整を行うと,和文処理グルーの自然長は変化しないが,伸び量や縮み量は
6836         一般に変化する.そのため,既に組まれた段落を \cs{unhbox} などを利用して組み直す処理を
6837         行う場合には注意が必要である.
6838   \end{itemize}
6839   
6840  \item[「中身までみた」行送り計算]
6841   複数行に渡る文章を組版するときには行間に空きが入ることが普通である.
6842   \TeX では各行が一つずつの水平ボックスをなしていることを思い出すと,隣り合った
6843   2つの行(つまり水平ボックス)の間の空きは次のようにして決まるのだった:
6844   \begin{enumerate}
6845    \item 「通常に組んだときの行間」$d$を,\cs{baselineskip}から
6846         「前の行」の深さと「次の行」の高さを加えたものを引いた値とする.
6847    \item $d\ge\cs{lineskiplimit}$の場合,
6848         標準の行送り\cs{baselineskip}で組んでも十分な間隔があると判断され,
6849         2行の間には長さ$d$の空白が挿入される.つまり行送りは\cs{baselineskip}.
6850    \item {\catcode`\<=12$d<\cs{lineskiplimit}$}の場合,
6851         2行の間には長さ\cs{lineskip}の空白が挿入される.
6852         そのため(設定値によるが,多くの場合)行送りは\cs{baselineskip}より広がる.
6853   \end{enumerate}
6854
6855   \begin{figure}[t]
6856         \noindent\centering
6857         \begin{minipage}[b]{18\zw}
6858           \ltjenableadjust[profile=false, linestep=false]
6859           ……だから,①より$\dfrac{a^2}{b} = \dfrac{1+\sqrt{5}}2$.\\
6860           よって$b=\dfrac{1-\sqrt{5}}2$である.\\
6861           これを②式に代入すると……
6862           \par\vskip\abovecaptionskip
6863           \ltjenableadjust[profile=false, linestep=false]
6864           \par\centering\leavevmode{\small (a)}
6865         \end{minipage}%
6866         \kern2\zw
6867         \begin{minipage}[b]{18\zw}
6868           \ltjenableadjust[profile]
6869           ……だから,①より$\dfrac{a^2}{b} = \dfrac{1+\sqrt{5}}2$.\\
6870           よって$b=\dfrac{1-\sqrt{5}}2$である.\\
6871           これを②式に代入すると……
6872           \par\vskip\abovecaptionskip
6873           \ltjenableadjust[profile=false, linestep=false]
6874           \par\centering\leavevmode{\small (b)}
6875         \end{minipage}\par
6876           \caption{高い行が連続したときの状況}\label{fig:linegap1}
6877   \end{figure}
6878
6879   以上で述べたことから,\TeX 標準では行送りの決定で「高さ・深さを取っているものが
6880   行のどの水平位置にあるか」は一切考慮しない.そのため,
6881   \autoref{fig:linegap1}~(a)のように「必要以上に行間が空いて見える」状況が起こる.
6882
6883   \Pkg{luatexja-adjust}パッケージでは,「通常に組んだときの行間」$d$を
6884   各行の中身の文字・グルー・ボックスの寸法を勘案して計算するという方法を
6885   利用できるようにした.この機能を使うと,\autoref{fig:linegap1}~(b)のように
6886   行間の空きが必要以上に大きくなることを避けることができる.
6887   \begin{itemize}
6888         \item 段落中の隣り合った二行だけでなく,行間の空きは
6889         新たに水平ボックス$h$を(内部・外部問わず)垂直モードで追加した時にも自動で挿入される.
6890         その場合には,前段落で述べた「中身までみる」処理は
6891         \begin{itemize}
6892          \item 現在のリストにおける最後のノード
6893           \footnote{最後のノードが\cs{parskip}によるグルーであった場合のみ
6894                 さらに一つ前のノードを参照する}が水平ボックス$h'$であり,かつ
6895           \item \cs{prevdepth}の値とその$h'$の深さの値が一致している
6896         \end{itemize}
6897         場合にのみ発動するようにしている.
6898         \item 行の中身に水平ボックス$h''$が入ってくることもあるが,その場合は$h''$の中身までは参照しない.
6899         参照するようにしてしまうと,\cs{smash}など手動で行った高さ・深さ調整の意味がなくなってしまうからである.
6900   \end{itemize}
6901   
6902   \begin{figure}[t]
6903         \noindent\centering
6904         \begin{minipage}[b]{16\zw}
6905           \ltjenableadjust[profile]
6906           ……だから,①より$\dfrac{a^2}{b}= \dfrac{1+\sqrt{5}}2$.\\
6907           よって$b=\dfrac{1-\sqrt{5}}2$である.\\
6908           これを②式に代入すると……
6909           \par\vskip\abovecaptionskip
6910           \ltjenableadjust[profile=false, linestep=false]
6911           \par\centering\leavevmode{\small (a): 無効}
6912         \end{minipage}%
6913         \kern2\zw
6914         \begin{minipage}[b]{16\zw}
6915           \ltjsetparameter{linestep_factor=0.25}
6916           \ltjenableadjust[profile, linestep]
6917           ……だから,①より$\dfrac{a^2}{b} = \dfrac{1+\sqrt{5}}2$.\\
6918           よって$b=\dfrac{1-\sqrt{5}}2$である.\\
6919           これを②式に代入すると……
6920           \par\vskip\abovecaptionskip
6921           \ltjenableadjust[profile=false, linestep=false]
6922           \par\centering\leavevmode{\small (b): $0.25$\cs{baselineskip}刻み}
6923         \end{minipage}\par\medskip
6924         \begin{minipage}[b]{16\zw}
6925           \ltjsetparameter{linestep_factor=0.5}
6926           \ltjenableadjust[profile, linestep]
6927           ……だから,①より$\dfrac{a^2}{b} = \dfrac{1+\sqrt{5}}2$.\\
6928           よって$b=\dfrac{1-\sqrt{5}}2$である.\\
6929           これを②式に代入すると……
6930           \par\vskip\abovecaptionskip
6931           \ltjenableadjust[profile=false, linestep=false]
6932           \par\centering\leavevmode{\small (c): 0.5\cs{baselineskip}刻み}
6933         \end{minipage}%
6934         \kern2\zw
6935         \begin{minipage}[b]{16\zw}
6936           \ltjsetparameter{linestep_factor=1}
6937           \ltjenableadjust[profile, linestep]
6938           ……だから,①より$\dfrac{a^2}{b} = \dfrac{1+\sqrt{5}}2$.\\
6939           よって$b=\dfrac{1-\sqrt{5}}2$である.\\
6940           これを②式に代入すると……
6941           \par\vskip\abovecaptionskip
6942           \ltjenableadjust[profile=false, linestep=false]
6943           \par\centering\leavevmode{\small (d): \cs{baselineskip}刻み}
6944         \end{minipage}\par
6945           \caption{段階的な行送り増加}\label{fig:linegap2}
6946   \end{figure}
6947
6948  \item[段階的な行送り増加]
6949   ...
6950 \end{description}
6951
6952 \Pkg{luatexja-adjust}パッケージは,上記で述べた4機能を有効化/無効化するための
6953 以下の命令を提供する.これらはすべてグローバルに効力を発揮する.
6954
6955 \begin{cslist}
6956 \item[\cs{ltjenableadjust[...]}]
6957 \verb+...+ に指定したkey-valueリストに従い,「行末文字の位置調整」「優先順位付きの行長調整」を有効化/無効化する.
6958 指定できるキーは以下の通り.
6959 \begin{description}
6960   \item[\texttt{lineend=[false,true,extended]}]
6961   行末文字の位置調整の機能を無効化(\texttt{false}),「行分割後に調整」の形で有効化(\texttt{true}),
6962   「行分割の仮定で考慮」の形で有効化(\texttt{extended})する.
6963   \item[\texttt{priority=[false,true]}]
6964   優先順位付きの行長調整を無効化(\texttt{false}),または有効化(\texttt{true}).
6965   \item[\texttt{profile=[false,true]}]
6966   「中身までみた」行送り計算を無効化(\texttt{false}),または有効化(\texttt{true}).
6967   \item[\texttt{linestep=[false,true]}]
6968   ...
6969 \end{description}
6970 両キーともキー名のみを指定した場合は値として\texttt{true}が指定されたものと扱われる.
6971
6972 互換性の為,オプション無しでただ\cs{ltjenableadjust}が呼び出された場合は,
6973 \begin{lstlisting}
6974 \ltjenableadjust[lineend=true,priority=true]
6975 \end{lstlisting}
6976 と扱われる.
6977   
6978 \item[\cs{ltjdisableadjust}]
6979 \Pkg{luatexja-adjust}パッケージの機能を無効化する.
6980 \begin{lstlisting}
6981 \ltjenableadjust[lineend=false,priority=false,profile=false,linestep=false]
6982 \end{lstlisting}
6983 と同義.
6984 \end{cslist}
6985
6986 また,優先順位付きの行長調整のために,次の3パラメータが\cs{ltjsetparameter}内で
6987 追加される.いずれもグローバルに効力を発揮する.
6988 \begin{cslist}[style=standard]
6989 \item[\DParam{stretch\_priority}\,=\{<list>\}]
6990 \Param{kanjiskip}, \Param{xkanjiskip},および「\textbf{JAglue}以外のグルー」を,
6991 「行を自然長より伸ばす」場合の調整に用いる優先度を指定する.
6992
6993 指定方法は,<list>の中にkey-value listの形で
6994 \begin{lstlisting}
6995 stretch_priority={kanjiskip=-35,xkanjiskip=-25,others=50}
6996 \end{lstlisting}
6997 のようにして行う.キー名\texttt{kanjiskip},~\texttt{xkanjiskip}については
6998 そのままの意味であり,
6999 \texttt{others}キーが「\textbf{JAglue}以外のグルー」を表す.
7000 各キーの値は,JFMグルーにおける「優先度$i$」を$10i$に対応させた整数値であり,
7001   大きい方が先に伸ばされることを意味している.
7002
7003 \item[\DParam{shrink\_priority}\,=\{<list>\}]
7004 同様に,「行を自然長より縮める」場合の調整に用いる優先度を指定する.
7005 それ以外は\Param{stretch\_priority}と指定の形式は変わらない.
7006
7007  \item[\DParam{linestep\_factor}\,=<float>]
7008
7009 \end{cslist}
7010 初期値は\Param{stretch\_priority}, \Param{shrink\_priority}とも
7011 \begin{lstlisting}
7012 {kanjiskip=-35,xkanjiskip=-25,others=50}
7013 \end{lstlisting}
7014 であり,「優先度$-4$」と指定されているJFMグルーが最も伸び(縮み)にくいようになっている.
7015 また\Param{linestep\_factor}の初期値は0.5(つまり半行分)である.
7016 %</ja>
7017
7018 \subsection{\Pkg{luatexja-ruby}}
7019 %<*en>
7020 This addon package provides functionality of ``ruby'' (\emph{furigana}) annotations
7021 using callbacks of \LuaTeX-ja.
7022 There is no detailed manual of \Pkg{luatexja-ruby.sty} in English.
7023 (Japanese manual is another PDF file, \url{luatexja-ruby.pdf}.)
7024 %</en>
7025 %<*ja>
7026 この追加パッケージは,\LuaTeX-jaの機能を利用したルビ(振り仮名)の組版機能を提供する.
7027 前後の文字種に応じた前後への自動進入や,
7028 行頭形・行中形・行末形の自動的な使い分けが特徴である.
7029
7030 ルビ組版に設定可能な項目や注意事項が多いため,本追加パッケージの詳細な説明は
7031 使用例と共に \url{luatexja-ruby.pdf}\ という別ファイルに載せている.
7032 この節では簡単な使用方法のみ述べる.
7033 %</ja>
7034
7035 \begin{description}
7036 %<*en>
7037  \item[Group-ruby]
7038 By default, ruby characters (the second argument of \cs{ruby})
7039 are attached to base characters (the first argument), as one object.
7040 This type of ruby is called \emph{group-ruby}.
7041 %</en>
7042 %<*ja>
7043  \item[グループルビ] 標準ではグループルビの形で組まれる.第1引数に親文字,
7044 第2引数にルビを記述する.
7045 %</ja>
7046 \begin{LTXexample}[width=0.3\textwidth]
7047 東西線\ruby{妙典}{みようでん}駅は……\\
7048 東西線の\ruby{妙典}{みようでん}駅は……\\
7049 東西線の\ruby{妙典}{みようでん}という駅……\\
7050 東西線\ruby{葛西}{かさい}駅は……
7051 \end{LTXexample}
7052 %<*en>
7053 As the above example, ruby hangover is allowed on the Hiragana before/after
7054 its base characters.
7055 %</en>
7056 %<ja> この例のように,標準では前後の平仮名にルビ全角までかかるようになっている.
7057
7058 %<*en>
7059 \item[Mono-ruby]
7060 To attach ruby characters to each base characters (\emph{mono-ruby}),
7061 one should use \cs{ruby} multiple times:
7062 %</en>
7063 %<*ja>
7064  \item[モノルビ] 親文字を1文字にするとモノルビとなる.
7065 2文字以上の熟語をモノルビの形で組みたい場合は,面倒でも
7066 その数だけ \cs{ruby} を書く必要がある.
7067 %</ja>
7068 \begin{LTXexample}[width=0.3\textwidth]
7069 東西線の\ruby{妙}{みよう}\ruby{典}{でん}駅は……
7070 \end{LTXexample}
7071
7072 %<*en>
7073  \item[Jukugo-ruby]
7074 Vertical bar~\verb+|+ denotes a boundary of \emph{groups}.
7075 %</en>
7076 %<*ja>
7077  \item[熟語ルビ] 引数内の縦棒 \verb+|+ はグループの区切りを表し,
7078 複数グループのルビは熟語ルビとして組まれる.
7079 \cite{x4051}にあるように,
7080 どのグループでも「親文字」が対応するルビ以上の長さの場合は
7081 各グループごとに,そうでないときは全体をまとめて1つのグループルビとして組まれる.
7082 \cite{jlreq}で規定されている組み方とは異なるので注意.
7083 %</ja>
7084 \begin{LTXexample}
7085 \ruby{妙|典}{みよう|でん}\
7086 \ruby{葛|西}{か|さい}\
7087 \ruby{神楽|坂}{かぐら|ざか}
7088 \end{LTXexample}
7089 %<*en>
7090 If there are multiple groups in one \cs{ruby} call,
7091 A linebreak between two groups is allowed.
7092 %</en>
7093 %<ja> 複数ルビではグループとグループの間で改行が可能である.
7094 \begin{LTXexample}[width=0.3\textwidth]
7095 \vbox{\hsize=6\zw\noindent
7096   \hbox to 2.5\zw{}\ruby{京|急|蒲|田}{けい|きゆう|かま|た}
7097   \hbox to 2.5\zw{}\ruby{京|急|蒲|田}{けい|きゆう|かま|た}
7098   \hbox to   3\zw{}\ruby{京|急|蒲|田}{けい|きゆう|かま|た}
7099 }
7100 \end{LTXexample}
7101 \end{description}
7102
7103 %<*en>
7104 If the width of ruby characters are longer than that of base characters,
7105 \cs{ruby} automatically selects the appropriate form
7106 among the line-head form, the line-middle form, and the line-end form.
7107 %</en>
7108 %<*ja>
7109 また,ルビ文字のほうが親文字よりも長い場合は,自動的に
7110 行頭形・行中形・行末形のいずれか適切なものを選択する.
7111 %</ja>
7112 \begin{LTXexample}[width=0.3\textwidth]
7113 \vbox{\hsize=8\zw\noindent
7114 \null\kern3\zw ……を\ruby{承}{うけたまわ}る
7115      \kern1\zw ……を\ruby{承}{うけたまわ}る\\
7116 \null\kern5\zw ……を\ruby{承}{うけたまわ}る
7117 }
7118 \end{LTXexample}
7119
7120
7121 %<*ja>
7122 \subsection{\Pkg{lltjext}}
7123 \pLaTeX では縦組用の拡張として \Pkg{plext} パッケージが用意されていたが,
7124 それを\LuaTeX-ja用に書きなおしたものが本追加パッケージ \Pkg{lltjext} である.
7125
7126 従来の \Pkg{plext} パッケージとの違いは,
7127 {\catcode`\<=12
7128 \begin{itemize}
7129  \item 組方向オプション \texttt{<y>}(横組),\texttt{<t>}(縦組),
7130 \texttt{<z>}\ の他に\ \texttt{<d>}(dtou方向),\texttt{<u>}(utod方向)を追加した.
7131 \texttt{<z>} と \texttt{<u>} の違いは,\texttt{<z>} が(\Pkg{plext} パッケージと同様に)
7132 周囲の組方向が縦組のときにしか意味を持たない
7133   \footnote{%
7134     周囲の組方向が縦組以外のときは,\texttt{<z>} を指定しても中身の組方向は周囲の組方向と変わらない.
7135   }%
7136 のに対し,\texttt{<u>} にはそのような制限がないことである.
7137  \item 連数字用命令 \cs{rensuji} における位置合わせオプション \texttt{[l]}, \texttt{[c]},
7138        \texttt{[r]} の挙動を若干変更した.
7139 \end{itemize}
7140 }
7141
7142 %</ja>
7143 %<*en>
7144 \subsection{\texttt{lltjext.sty}}
7145 \pLaTeX\ supplies additional macros for vertical writing in the \Pkg{plext} package.
7146 The \Pkg{lltjext} package which we want to describe here is the \LuaTeX-ja
7147 counterpart of the \Pkg{plext} package.
7148 %</en>
7149
7150 %<*ja>
7151 念の為,本 \Pkg{lltjext} パッケージで追加・変更している命令の一覧を載せておく.
7152 \begin{cslist}
7153 \item[tabular\textrm{, }array\textrm{, }minipage環境]
7154 これらの環境は,
7155 \begin{lstlisting}
7156 \begin{tabular}<dir>[pos]{table spec} ... \end{tabular}
7157 \begin{array}<dir>[pos]{table spec}   ... \end{array}
7158 \begin{minipage}<dir>[pos]{width}     ... \end{minipage}
7159 \end{lstlisting}
7160 のように,組方向オプション \texttt{\<dir\>} が拡張されている.
7161 既に述べたように,組方向オプションに指定できる値は以下の5つであり,
7162 それ以外を指定した時や無指定時は周囲の組方向と同じ組方向になる.
7163 \begin{description}
7164  \item[y] 横組(\cs{yoko})
7165  \item[t] 縦組(\cs{tate})
7166  \item[z] 周囲が縦組の時はutod方向,それ以外はそのまま
7167  \item[d] dtou方向
7168  \item[u] utod方向
7169 \end{description}
7170 \item[\cs{parbox}\<<dir>\>{[<pos>]}\{<width>\}\{<contents>\}]
7171 \cs{parbox} 命令も同様に,組方向の指定ができるように拡張されている.
7172
7173 \item[\cs{pbox}\<<dir>\>{[<width>][<pos>]}\{<contents>\}]
7174 組方向<dir>で<contents>の中身をLRモードで組む命令である.
7175 <width>が正の値であるときは,ボックス全体の幅がその値となる.
7176 その際,中身は<pos>の値に従い,左寄せ(\texttt{l}),右揃え(\texttt{r}),
7177 中央揃え(それ以外)される.
7178 \item[picture環境]
7179 図表作成に用いる\texttt{picture}環境も,
7180 \begin{lstlisting}
7181 \begin{picture}<dir>(x_size, y_size)(x_offset,y_offset)
7182   ...
7183 \end{picture}
7184 \end{lstlisting}
7185 と組方向が指定できるように拡張されている.
7186 $x$成分の増加方向は字送り方向,$y$成分の増加方向は行送り方向の\emph{反対方向}となる.
7187 \Pkg{plext} パッケージと同様に
7188 内部ではベースライン補正(\Param{yalbaselineshift}パラメータなど)の影響を受けないように,
7189 \cs{put},~\cs{line}, \cs{vector}, \cs{dashbox}, \cs{oval},~\cs{circle}も
7190 ベースライン補正を受けないように再定義されている.
7191
7192 \item[\cs{rensuji}{[<pos>]}\{<contents>\}\textrm{, }\cs{rensujiskip}]
7193
7194 \item[\cs{Kanji}\{<counter\_name>\}]
7195
7196 \item[\cs{kasen}\{<contents>\}\textrm{, }\cs{bou}\{<contents>\}\textrm{,
7197                      }\cs{boutenchar}]
7198
7199 \item[参照番号]
7200 \end{cslist}
7201 %</ja>
7202 %<*en>
7203 \begin{cslist}
7204 \item[tabular\textrm{, }array\textrm{, }minipage\textrm{ environments}]
7205 These environments are extended by \texttt{\<dir\>}, which specifies the direction,
7206 as follows:
7207 \begin{lstlisting}
7208 \begin{tabular}<dir>[pos]{table spec} ... \end{tabular}
7209 \begin{array}<dir>[pos]{table spec}   ... \end{array}
7210 \begin{minipage}<dir>[pos]{width}     ... \end{minipage}
7211 \end{lstlisting}
7212 This option permits one of the following five values. If none of them is specified,
7213 the direction inside the environment is same as that outside the enviromnent.
7214 \begin{description}
7215  \item[y] \emph{yoko} direction (horizontal writing)
7216  \item[t] \emph{tate} direction (vertical writing)
7217  \item[z] \emph{utod} direction if direction outside the env.\ is \emph{tate}.
7218  \item[d] \emph{dtou} direction
7219  \item[u] \emph{utod} direction
7220 \end{description}
7221 \item[\cs{parbox}\<<dir>\>{[<pos>]}\{<width>\}\{<contents>\}]
7222 \cs{parbox} command is also extended by \texttt{\<<dir>\>}.
7223
7224 \item[\cs{pbox}\<<dir>\>{[<width>][<pos>]}\{<contents>\}]
7225 This commands typeset <contents> in LR-mode, in <dir> direction.
7226 If <width> is positive, the width of the box becomes this <width>.
7227 In this case, <contents> will be aligned to left (when <pos> is \texttt{l}),
7228 center (\texttt{c}), or~right (\texttt{r}).
7229   
7230 \item[picture\textrm{\ environment}]
7231 \texttt{picture} environment also extended by \texttt{\<<dir>\>}, as follows:
7232 \begin{lstlisting}
7233 \begin{picture}<dir>(x_size, y_size)(x_offset,y_offset)
7234   ...
7235 \end{picture}
7236 \end{lstlisting}
7237
7238 \item[\cs{rensuji}{[<pos>]}\{<contents>\}\textrm{, }\cs{rensujiskip}]
7239
7240 \item[\cs{Kanji}\{<counter\_name>\}]
7241
7242 \item[\cs{kasen}\{<contents>\}\textrm{, }\cs{bou}\{<contents>\}\textrm{,
7243                      }\cs{boutenchar}]
7244
7245 \item[参照番号]
7246 \end{cslist}
7247 %</en>
7248
7249 %<*ja>
7250 \paragraph{表組他の揃え位置}
7251 表組(\texttt{array}, \texttt{tabular}環境),\cs{parbox}命令,\cs{minipage}環境の
7252 揃え位置については\autoref{tab:lltjext_dir}を参照.\pLaTeX~2017-07-29と
7253 できるだけ同じ挙動になるようにしている.\autoref{tab:lltjext_dir}中のA--Dの意味は次の通り.
7254
7255 \begin{table}
7256   \caption{\Pkg{lltjext}パッケージにおける表組・\cs{parbox}命令他の揃え位置}
7257   \label{tab:lltjext_dir}
7258   {\centering
7259     \begin{tabular}{lcccc}
7260       \toprule
7261       ↓中身\周囲→&\cs{yoko}&\cs{tate}&\cs{utod}&\cs{dtou}\\
7262       \midrule
7263       \cs{yoko}&A&B&B&B\\
7264       \cs{tate}&B&A&D&C\\
7265       \cs{utod}&B&D&A&C\\
7266       \cs{dtou}&B&C&C&A\\
7267       \bottomrule
7268     \end{tabular}\par}
7269 \end{table}
7270
7271 \begin{description}
7272  \item[A] 周囲の組方向と中身の組方向が同じ場合.
7273   \begin{itemize}
7274    \item \texttt{[t]}指定のとき:
7275     中身の先頭行のベースラインが周囲のベースラインと一致する.
7276     表組で先頭行の上に罫線があった場合は,それがベースラインの位置
7277     \footnote{\LuaTeX-jaでは和文側のベースラインの位置も上下移動できることに注意.
7278       そのため「和文ベースライン」の位置に来るとは限らない.}となる.
7279    \item \texttt{[c]}指定のとき:
7280     中身の上下の中心が周囲の数式の軸を通る.
7281    \item \texttt{[b]}指定のとき:
7282     中身の最終行のベースラインが周囲のベースラインと一致する.
7283     表組で最終行の下に罫線があった場合は,それがベースラインの位置となる.
7284   \end{itemize}
7285  \item[B] 周囲の組方向と中身の組方向が90度ずれている場合.
7286   \begin{itemize}
7287    \item \texttt{[t]}指定のとき:
7288     表組においては,上端が周囲のベースラインと一致する.
7289     \cs{parbox}や\cs{minipage}環境においては,上端が周囲の和文文字の上端と一致する.
7290    \item \texttt{[c]}指定のとき:
7291     中身の上下の中心が周囲の数式の軸を通る.
7292    \item \texttt{[b]}指定のとき:
7293     表組においては,下端が周囲のベースラインと一致する.
7294     \cs{parbox}や\cs{minipage}環境においては,下端が周囲の和文文字の下端と一致する.
7295   \end{itemize}
7296  \item[C] 周囲の組方向と中身の組方向が180度ずれている場合.
7297   \cs{parbox}や\cs{minipage}環境においては,上のBの場合と同じ挙動である.表組においては,
7298   Aで\texttt{[t]}と\texttt{[b]}を入れ替えた
7299   \begin{itemize}
7300    \item \texttt{[t]}指定のとき:
7301     中身の最終行のベースラインが周囲のベースラインと一致する.
7302     最終行の下に罫線があった場合は,それがベースラインの位置となる.
7303    \item \texttt{[c]}指定のとき:
7304     中身の上下の中心が周囲の数式の軸を通る.
7305    \item \texttt{[b]}指定のとき:
7306     中身の先頭行のベースラインが周囲のベースラインと一致する.
7307     表組で先頭行の上に罫線があった場合は,それがベースラインの位置となる.
7308   \end{itemize}
7309  \item[D] 通常の縦組(\cs{tate})と「縦数式ディレクション」に相当する\cs{utod}方向が絡んだ場合.
7310   \cs{parbox}や\cs{minipage}環境においては,上のBの場合と同じ挙動である.表組においては,
7311   \begin{itemize}
7312    \item \texttt{[t]}指定のとき:
7313     中身の先頭行の欧文ベースラインが周囲の欧文ベースラインと一致する.
7314    \item \texttt{[c]}指定のとき:
7315     中身の上下の中心が周囲の数式の軸を通る.
7316    \item \texttt{[b]}指定のとき:
7317     中身の最終行の欧文ベースラインが周囲の欧文ベースラインと一致する.
7318   \end{itemize}
7319 \end{description}
7320 %</ja>
7321
7322 \subsection{\Pkg{luatexja-preset}}
7323 \label{ssec:preset}
7324
7325 %<*en>
7326 As described in Subsection~\ref{ssec:preset-abst},
7327 One can load the \Pkg{luatexja-preset}
7328 package to use several ``presets'' of Japanese fonts.
7329 This package provides functions in a part of \Pkg{japanese-otf} package (changing fonts)
7330 and a part of \Pkg{PXchfon} package (presets) by Takayuki Yato.
7331
7332 Options which are given in \cs{usepackage} but not described in this~subsection
7333 are simply passed to the \Pkg{luatexja-fontspec}\footnote{if \texttt{nfssonly} option is
7334 \emph{not} specified; in this case these options are simply ignored.}.
7335 For example, the line~5 in below example is equivalent to lines 1--3.
7336 %</en>
7337 %<*ja>
7338 \ref{ssec:preset-abst}節で述べたように,よく使われている和文フォント設定を一行で指定できるようにしたのが
7339 \Pkg{luatexja-preset}パッケージである.このパッケージは,
7340 \Pkg{otf}パッケージの一部(多書体化)と八登崇之氏による\Pkg{PXchfon}パッケージの一部(プリセット指定)
7341 とを合わせたような格好をしている.
7342
7343 パッケージ読み込み時に渡されたオプションのうち,
7344 本節にないものを指定した場合,それらはそのまま
7345 \Pkg{luatexja-fontspec}パッケージに渡される\footnote{\texttt{nfssonly} オプションが
7346 指定されていた場合は,\Pkg{luatexja-fontspec}パッケージは読み込まれないので単純に無視され
7347 る.}.例えば,下の1--3行目は5行目のように一行にまとめることができる.
7348 %</ja>
7349 \begin{lstlisting}
7350 \usepackage[no-math]{fontspec}
7351 \usepackage[match]{luatexja-fontspec}
7352 \usepackage[kozuka-pr6n]{luatexja-preset}
7353 %%--------
7354 \usepackage[no-math,match,kozuka-pr6n]{luatexja-preset}
7355 \end{lstlisting}
7356
7357 %<en>\subsubsection{General Options}
7358 %<ja>\subsubsection{一般的なオプション}
7359 \label{sssec:ltjpreset-general}
7360
7361 \begin{cslist}[before*=]
7362 \item[fontspec%
7363 %<en>\textrm{~(enabled by default)}
7364 %<ja>\emph{\gtfamily (既定)}
7365 ]
7366 %<*en>
7367 With this option, Japanese fonts are selected using functionality of
7368 the \Pkg{luatexja-fontspec} package. This means that the \Pkg{fontspec} package is
7369              automatically loaded by this package.
7370
7371 If you need to pass some options to \Pkg{fontspec}, you can load \Pkg{fontspec} manually
7372 before \Pkg{luatexja-preset}:
7373 %</en>
7374 %<*ja>
7375 \Pkg{luatexja-fontspec}パッケージの機能を用いて和文フォントを選択する.
7376 これは,\Pkg{fontspec}パッケージが自動で読み込まれることを意味する.
7377
7378 もし\Pkg{fontspec}パッケージに何らかのオプションを渡す必要がある
7379 \footnote{例えば,数式フォントまで置換されてしまい,\cs{mathit}によってギリシャ文字の
7380 斜体大文字が出なくなる,など.}場合は,
7381 次のように\Pkg{luatexja-preset}の前に\Pkg{fontspec}を手動で読みこめば良い:
7382 %</ja>
7383 \begin{lstlisting}
7384 \usepackage[no-math]{fontspec}
7385 \usepackage[...]{luatexja-preset}
7386 \end{lstlisting}
7387
7388 \item[nfssonly]
7389 %<*en>
7390 With this option, selecting Japanese fonts won't be performed using the functionality of
7391              the \Pkg{fontspec} package, but only standard NFSS2 (hence without
7392              \cs{addjfontfeatures} etc.).
7393 This option is ignored when \Pkg{luatexja-fontspec} package is loaded.
7394
7395 When this option is specified, \Pkg{fontspec}~and~\Pkg{luatexja-fontspec} are
7396 \emph{not} loaded by default. Nevertheless,
7397 the package\Pkg{fontspec} can coexist with the option, as the following:
7398 \begin{lstlisting}
7399 \usepackage{fontspec}
7400 \usepackage[hiragino-pron,nfssonly]{luatexja-preset}
7401 \end{lstlisting}
7402 In this case, one can use \cs{setmainfont} etc.\ to select \emph{alphabetic} fonts.
7403 %</en>
7404 %<*ja>
7405 \LaTeX 標準のフォント選択機構(NFSS2)を用いて
7406 \texttt{ltjpm}(明朝),\texttt{ltjpg}(ゴシック),それに後に述べる \texttt{deluxe} オプ
7407              ションが指定された場合には \texttt{ltjpmg}(丸ゴシック)という
7408 3つの和文フォントファミリを定義し,これらを用いる.
7409
7410 本オプション指定時には\Pkg{fontspec}・\Pkg{luatexja-fontspec}パッケージは
7411 自動では読み込まれない,しかし,
7412 \begin{lstlisting}
7413 \usepackage{fontspec}
7414 \usepackage[hiragino-pron,nfssonly]{luatexja-preset}
7415 \end{lstlisting}
7416 のようにすれば,このオプションを指定すれば
7417 欧文フォントを\Pkg{fontspec}パッケージの機能を使って指定することができる.
7418 一方,
7419 パッケージ読み込み時に既に\Pkg{luatexja-fontspec}パッケージが読み込まれて
7420              いる場合は \texttt{nfssonly} オプションは無視される.
7421 %</ja>
7422
7423 \item[match]
7424 %<*en>
7425 If this option is specified, usual family-changing commands such as
7426 \cs{rmfamily},~\cs{textrm}, \cs{sffamily},~\dots\ also change Japanese font family.
7427 This option is passed to \Pkg{luatexja-fontspec}, if \texttt{fontspec}
7428 option is specifed.
7429 %</en>
7430
7431 %<*ja>
7432 このオプションが指定されると,「\pLaTeXe 新ドキュメントクラス」のように\
7433 \cs{rmfamily}, \verb+\textrm{...}+, \cs{sffamily} 等が
7434 欧文フォントだけでなく和文フォントも変更するようになる.
7435 \ \texttt{fontspec}\
7436 オプションが有効になっている場合は,このオプションは \Pkg{luatexja-fontspec} パッケージへと渡される.
7437 %</ja>
7438
7439
7440 \item[nodeluxe%
7441 %<en>\textrm{~(enabled by default)}
7442 %<ja>\emph{\gtfamily (既定)}
7443 ]
7444 %<*en>
7445 The nagation of \texttt{deluxe} option.
7446 Use one-weighted \textit{mincho} and \textit{gothic} font families.
7447 This means that \verb+\mcfamily\bfseries+, \verb+\gtfamily\bfseries+ and
7448 \verb+\gtfamily\mdseries+ use the same font.
7449 %</en>
7450 %<*ja>
7451 \texttt{deluxe}オプションの否定.
7452 \LaTeXe 環境下の標準設定のように,明朝体・ゴシック体を各1ウェイトで使用する.
7453 より具体的に言うと,この設定の下では
7454 \ \verb+\mcfamily\bfseries+, \verb+\gtfamily\bfseries+,
7455 \verb+\gtfamily\mdseries+はみな同じフォントとなる.
7456 %</ja>
7457 \item[deluxe]
7458 %<*en>
7459 Use the mincho family with three weights (light, medium, and~bold),
7460 the gothic family with three weights (medium, bold, and extra~bold), and \textit{rounded gothic}%
7461 \footnote{Provided by \cs{mgfamily} and \cs{textmg},
7462 because ``rounded gothic'' is called \textit{maru gothic} (丸ゴシック) in Japanese.}.
7463 Mincho light and gothic extra~bold can be by
7464 \cs{mcfamily}\cs{ltseries}~and~\cs{gtfamily}\cs{ebseries}, respectively.
7465
7466 \begin{itemize}
7467  \item Some presets do not have the light weight of mincho.
7468   In this case, we substitute the medium weight for the light weight.
7469  \item \Pkg{luatexja-preset} does not produce an error (only produces a warning), even if
7470   (one of) fonts for \cs{mcfamily}\cs{ltseries}, \cs{gtfamily}\cs{ebseries}, \cs{mgfamily}
7471   do not exist.
7472 \end{itemize}
7473 %</en>
7474 %<*ja>
7475 明朝体・ゴシック体各3ウェイトと,
7476 丸ゴシック体 (\cs{mgfamily}, \verb+\textmg{...}+) を利用可能にする.
7477 明朝体は細字・中字・太字の3ウェイトがあり,
7478 明朝体の細字は \cs{mcfamily}\cs{ltseries} で利用できる.
7479 また,ゴシック体は中字・太字・極太の3ウェイトがあり,
7480 ゴシック体の極太は \cs{gtfamily}\cs{ebseries} で利用できる%
7481 \footnote{過去との互換性のため,\cs{gtebfamily}, \cs{textgteb\{...\}} も
7482  依然として利用可能である.}.
7483
7484 \begin{itemize}
7485   \item プリセット設定によっては明朝体細字が用意されていないものもある.その場合は
7486   明朝体中字が代用される.
7487   \item 明朝体細字,ゴシック体極太,丸ゴシック体の3フォントについては
7488   実際にフォントをロードする前に存在するかチェックを行う.
7489   存在しなかったものについては警告を発し,
7490   それぞれ明朝体中字.ゴシック体太字,ゴシック体太字で代用する.
7491 \end{itemize}
7492 %</ja>
7493 \item[expert]
7494 %<*en>
7495 Use horizontal/vertical kana alternates, and define a command \cs{rubyfamily} to use kana
7496 characters designed for ruby.
7497 %</en>
7498 %<*ja>
7499 横組・縦組専用仮名を用いる.また,\cs{rubyfamily} でルビ用仮名が使用可能となる\footnote{%
7500   \cs{rubyfamily}とはいいつつ,実際にはフォントファミリを切り替えるのではない(通常では
7501   font featureの追加,\texttt{nfssonly} 指定時にはシェイプを \texttt{rb} に切り替え).
7502 }.
7503 %</ja>
7504 \item[bold]
7505 %<*en>
7506 Substitute bold series of gothic for  bold series of mincho.
7507 If \texttt{nodeluxe} option is enabled, medium series of gothic is also changed,
7508 since we use same font for both series of gothic.
7509 %</en>
7510 %<*ja>
7511 「明朝の太字」をゴシック体の太字によって代替する.
7512 もし\texttt{nodeluxe}オプションが指定されている場合は,ゴシック体は1ウェイトしか使用されな
7513            いため,
7514 「ゴシック体の中字」も同時に変更されることになる.
7515 %</ja>
7516 \item[90jis]
7517 %<en>Use 90JIS glyph variants if possible.
7518 %<ja>出来る限り90JISの字形を使う.
7519 \item[jis2004]
7520 %<en>Use JIS2004 glyph variants if possible.
7521 %<ja>出来る限りJIS2004の字形を使う.
7522 \item[jfm\_yoko=<jfm>]
7523 %<*en>
7524 Use the JFM \texttt{jfm-<jfm>.lua} for horizontal direction, instead of \texttt{jfm-ujis.lua}~(default JFM).
7525 %</en>
7526 %<*ja>
7527 横組用和文フォントで用いるJFMを\texttt{jfm-<jfm>.lua}にする.このオプションがない時は
7528 \LuaTeX\nobreakdash -ja標準の\texttt{jfm-ujis.lua}が用いられる.
7529 %</ja>
7530 \item[jfm\_tate=<jfm>]
7531 %<*en>
7532 Use the JFM \texttt{jfm-<jfm>.lua} for vertical direction, instead of \texttt{jfm-ujisv.lua}~(default JFM).
7533 %</en>
7534 %<*ja>
7535 縦用和文フォントで用いるJFMを\texttt{jfm-<jfm>.lua}にする.このオプションがない時は
7536 \LuaTeX-ja標準の\texttt{jfm-ujisv.lua}が用いられる.
7537 %</ja>
7538
7539 \item[jis]
7540 %<en>Same as \texttt{jfm\_yoko=jis}.
7541 %<ja>\texttt{jfm\_yoko=jis}と同じ.ここで用いるJFM\texttt{jfm-jis.lua}はJISフォントメトリックを元にしたものである.
7542
7543 \end{cslist}
7544 %<*en>
7545 Note that \texttt{90jis} and \texttt{jis2004} only affect with mincho,
7546 gothic (and, possibly rounded gothic) families defined by this package.
7547 We didn't taken account of  when both \texttt{90jis} and \texttt{jis2004} are specified.
7548 %</en>
7549 %<*ja>
7550 \texttt{90jis}と\texttt{jis2004}については本パッケージで定義された
7551 明朝体・ゴシック体(・丸ゴシック体)にのみ有効である.
7552 両オプションが同時に指定された場合の動作については全く考慮していない.
7553 %</ja>
7554
7555 %<en>\subsubsection{Presets which support multi weights}
7556 %<ja>\subsubsection{多ウェイト用プリセットの一覧}
7557 \label{sssec:ltjpreset-multi}
7558
7559 %<*en>
7560 Besides \texttt{morisawa-pro}~and~\texttt{morisawa-pr6n} presets,
7561 fonts are specified by font name, not by file name.
7562 In following tables, starred fonts (e.g.~KozGo\dots-Regular) are used for medium series of \textit{gothic},
7563 \emph{if and only if \texttt{deluxe} option is specified}.
7564 %</en>
7565 %<*ja>
7566 \texttt{morisawa-pro}, \texttt{morisawa-pr6n}以外はフォントの指定は
7567 (ファイル名でなく)フォント名で行われる.
7568 以下の表において,*\,つきのフォント(e.g.,~KozGo\dots-Regular)は,\emph{\texttt{deluxe}オプション指定時に}
7569 ゴシック体中字として用いられるものを示している.
7570 %</ja>
7571 \begin{cslist}[style=standard]
7572  \item[kozuka-pro] Kozuka Pro (Adobe-Japan1-4) fonts.
7573 %<en>    \\*[-\dimexpr\medskipamount+\baselineskip\relax]
7574  \item[kozuka-pr6] Kozuka Pr6 (Adobe-Japan1-6)  fonts.
7575 %<en>    \\*[-\dimexpr\medskipamount+\baselineskip\relax]
7576  \item[kozuka-pr6n] Kozuka Pr6N (Adobe-Japan1-6, JIS04-savvy) fonts.
7577
7578 %<*en>
7579 Kozuka Pro/Pr6N fonts are bundled with Adobe's software, such as Adobe~InDesign.
7580 There is not rounded gothic family in Kozuka fonts.
7581 %</en>
7582 %<*ja>
7583 小塚Pro書体・Pr6N書体はAdobe InDesign等のAdobe製品にバンドルされている.
7584 「小塚丸ゴシック」は存在しないので,便宜的に小塚ゴシックHによって代用している.
7585 %</ja>
7586 \begin{center}\small
7587 \begin{tabular}{lllll}
7588 \toprule
7589 \bfseries family&\bfseries series&\ttfamily kozuka-pro&\ttfamily kozuka-pr6&\ttfamily kozuka-pr6n\\
7590 \midrule
7591  &light&KozMinPro-Light&KozMinProVI-Light&KozMinPr6N-Light\\
7592 %<en>\textit{mincho}%
7593 %<ja>\textgt{明朝}%
7594  &medium&KozMinPro-Regular&KozMinProVI-Regular&KozMinPr6N-Regular\\
7595  &bold&KozMinPro-Bold&KozMinProVI-Bold&KozMinPr6N-Bold\\
7596 \midrule
7597  &&KozGoPro-Regular*&KozGoProVI-Regular*&KozGoPr6N-Regular*\\
7598  &\smash{\raisebox{1.5ex}{medium}}
7599  &KozGoPro-Medium&KozGoProVI-Medium&KozGoPr6N-Medium\\
7600 \cmidrule(l){2-5}
7601 %<en>\smash{\raisebox{2ex}{\textit{gothic}}}%
7602 %<ja>\smash{\raisebox{2ex}{\gt ゴシック}}%
7603  &bold&KozGoPro-Bold&KozGoProVI-Bold&KozGoPr6N-Bold\\
7604  &extra bold&KozGoPro-Heavy&KozGoProVI-Heavy&KozGoPr6N-Heavy\\
7605 \midrule
7606 %<en>\textit{rounded gothic}
7607 %<ja>\gt 丸ゴシック
7608 &&KozGoPro-Heavy&KozGoProVI-Heavy&KozGoPr6N-Heavy\\
7609 \bottomrule
7610 \end{tabular}
7611 \end{center}
7612
7613 %<en>\newpage
7614  \item[hiragino-pro]  Hiragino Pro (Adobe-Japan1-5) fonts.
7615 %<en>    \\*[-\dimexpr\medskipamount+\baselineskip\relax]
7616  \item[hiragino-pron] Hiragino ProN (Adobe-Japan1-5, JIS04-savvy) fonts.
7617
7618 %<*en>
7619 Hiragino fonts (except Hiragino~Mincho~W2) are bundled with Mac OS~X 10.5 or later.
7620 Some editions of a Japanese word-processor ``一太郎2012'' includes Hiragino ProN fonts.
7621 Note that fonts for gothic extra~bold (HiraKakuStd[N]-W8) only contains characters in
7622 Adobe-Japan1-3 character collection, while others contains those in
7623 Adobe-Japan1-5 character collection.
7624 %</en>
7625 %<*ja>
7626 ヒラギノフォントは,Mac OS~X以外にも,一太郎2012の上位エディションにもバンドルされている.
7627 極太ゴシック体として用いるヒラギノ角ゴW8は,Adobe-Japan1-3の範囲しかカバーしていない
7628 Std/StdNフォントであり,その他はAdobe-Japan1-5対応である.
7629
7630 なお,明朝体細字として用いるヒラギノ明朝体W2はOS~Xや一太郎にはバンドルされておらず,
7631 別途購入する必要がある.
7632 %</ja>
7633 \begin{center}\small
7634 \begin{tabular}{llll}
7635 \toprule
7636 \bf family&\bf series&\tt hiragino-pro&\tt hiragino-pron\\
7637 \midrule
7638  &light&Hiragino~Mincho~Pro~W2&Hiragino~Mincho~ProN~W2\\
7639 %<en>\textit{mincho}%
7640 %<ja>\textgt{明朝}%
7641  &medium&Hiragino~Mincho~Pro~W3&Hiragino~Mincho~ProN~W3\\
7642  &bold&Hiragino~Mincho~Pro~W6&Hiragino~Mincho~ProN~W6\\
7643 \midrule
7644  &&Hiragino~Kaku~Gothic~Pro~W3*&Hiragino~Kaku~Gothic~ProN~W3*\\
7645  &\smash{\raisebox{1.5ex}{medium}}
7646  &Hiragino~Kaku~Gothic~Pro~W6&Hiragino~Kaku~Gothic~ProN~W6\\
7647 \cmidrule(l){2-4}
7648 %<en>\smash{\raisebox{2ex}{\textit{gothic}}}%
7649 %<ja>\smash{\raisebox{2ex}{\gt ゴシック}}%
7650  &bold&Hiragino~Kaku~Gothic~Pro~W6&Hiragino~Kaku~Gothic~ProN~W6\\
7651  &extra bold&Hiragino~Kaku~Gothic~Std~W8&Hiragino~Kaku~Gothic~StdN~W8\\
7652 \midrule
7653 %<en>\textit{rounded gothic}
7654 %<ja>\gt 丸ゴシック
7655 &&Hiragino~Maru~Gothic~Pro~W4&Hiragino~Maru~Gothic~ProN~W4\\
7656 \bottomrule
7657 \end{tabular}
7658 \end{center}
7659
7660  \item[morisawa-pro]  Morisawa Pro (Adobe-Japan1-4) fonts.
7661 %<en>    \\*[-\dimexpr\medskipamount+\baselineskip\relax]
7662  \item[morisawa-pr6n]  Morisawa Pr6N (Adobe-Japan1-6, JIS04-savvy) fonts.
7663 \begin{center}\footnotesize
7664 \begin{tabular}{ll>{\tt}l>{\tt}l}
7665 \toprule
7666 \bf family&\bf series&morisawa-pro&morisawa-pr6n\\
7667 \midrule
7668  &medium&A-OTF-RyuminPro-Light.otf&A-OTF-RyuminPr6N-Light.otf\\
7669 %<en>\smash{\raisebox{1.5ex}{\textit{mincho}}}%
7670 %<ja>\smash{\raisebox{1.5ex}{\gt 明朝}}%
7671  &bold&A-OTF-FutoMinA101Pro-Bold.otf&A-OTF-FutoMinA101Pr6N-Bold.otf\\
7672 \midrule
7673  &medium
7674  &A-OTF-GothicBBBPro-Medium.otf&A-OTF-GothicBBBPr6N-Medium.otf\\
7675 %<en>\textit{gothic}%
7676 %<ja>\gt ゴシック
7677  &bold&A-OTF-FutoGoB101Pro-Bold.otf&A-OTF-FutoGoB101Pr6N-Bold.otf\\
7678  &extra bold&A-OTF-MidashiGoPro-MB31.otf&A-OTF-MidashiGoPr6N-MB31.otf\\
7679 \midrule
7680 %<en>\textit{rounded gothic}
7681 %<ja>\gt 丸ゴシック
7682 &&A-OTF-Jun101Pro-Light.otf&A-OTF-ShinMGoPr6N-Light.otf\\
7683 \bottomrule
7684 \end{tabular}
7685 \end{center}
7686
7687
7688  \item[yu-win]  Yu fonts bundled with Windows~8.1.
7689 %<en>    \\*[-\dimexpr\medskipamount+\baselineskip\relax]
7690  \item[yu-win10]  Yu fonts bundled with Windows~10.
7691 %<en>    \\*[-\dimexpr\medskipamount+\baselineskip\relax]
7692  \item[yu-osx]  Yu fonts bundled with OSX~Mavericks.
7693 \begin{center}\small
7694 \begin{tabular}{lllll}
7695 \toprule
7696 \bf family&\bf series&\texttt{yu-win}&\texttt{yu-win10}&\texttt{yu-osx}\\
7697 \midrule
7698  &light&YuMincho-Light&YuMincho-Light&(YuMincho~Medium)\\
7699 %<en>\textit{mincho}%
7700 %<ja>\textgt{明朝}%
7701  &medium&YuMincho-Regular&YuMincho-Regular&YuMincho~Medium\\
7702  &bold&YuMincho-Demibold&YuMincho-Demibold&YuMincho~Demibold\\
7703 \midrule
7704  &&YuGothic-Regular*&YuGothic-Regular*&YuGothic~Medium*\\
7705  &\smash{\raisebox{1.5ex}{medium}}%
7706         &YuGothic-Regular&YuGothic-Medium&YuGothic~Medium\\
7707 \cmidrule(l){2-5}
7708 %<en>\textit{gothic}%
7709 %<ja>\gt ゴシック
7710  &bold&YuGothic-Bold&YuGothic-Bold&YuGothic~Bold\\
7711  &extra bold&YuGothic-Bold&YuGothic-Bold&YuGothic~Bold\\
7712 \midrule
7713 %<en>\textit{rounded gothic}
7714 %<ja>\gt 丸ゴシック
7715 &&YuGothic-Bold&YuGothic-Bold&YuGothic~Bold\\
7716 \bottomrule
7717 \end{tabular}
7718 \end{center}
7719
7720 \item[moga-mobo]  MogaMincho, MogaGothic, and MoboGothic.
7721 %<en>    \\*[-\dimexpr\medskipamount+\baselineskip\relax]
7722 \item[moga-mobo-ex]  MogaExMincho, MogaExGothic, and MoboExGothic.
7723 %<en>\par These fonts can be downloaded from \url{http://yozvox.web.fc2.com/}.
7724 %<ja>これらのフォントは \url{http://yozvox.web.fc2.com/} からダウンロードできる.
7725 \begin{center}\small
7726 \begin{tabular}{llll}
7727 \toprule
7728 \bf family&\bf series&\bf default, \texttt{90jis}~option&\bf \texttt{jis2004} option\\
7729 \midrule
7730  &medium&Moga90Mincho&MogaMincho\\
7731 %<en>\smash{\raisebox{1.5ex}{\textit{mincho}}}%
7732 %<ja>\smash{\raisebox{1.5ex}{\gt 明朝}}%
7733  &bold&Moga90Mincho Bold&MogaMincho Bold\\
7734 \midrule
7735  &medium&Moga90Gothic&MogaGothic\\
7736 %<en>\textit{gothic}%
7737 %<ja>\gt ゴシック
7738  &bold&Moga90Gothic Bold&MogaGothic Bold\\
7739  &extra bold&Moga90Gothic Bold&MogaGothic Bold\\
7740 \midrule
7741 %<en>\textit{rounded gothic}
7742 %<ja>\gt 丸ゴシック
7743 &&Mobo90Gothic&MoboGothic\\
7744 \bottomrule
7745 \end{tabular}
7746 \end{center}
7747 %<en>When \texttt{moga-mobo-ex} is specified, the font ``MogaEx90Mincho'' etc.\ are used.
7748 %<ja>\texttt{moga-mobo-ex}オプション指定時にはMogaEx90MinchoなどのExが名前についたフォントが使われる.
7749
7750 \item[ume]  Ume Mincho and Ume Gothic.
7751 %<en>\par These fonts can be downloaded from\\\hfill \url{https://ja.osdn.net/projects/ume-font/wiki/FrontPage}.
7752 %<ja>これらのフォントは \url{https://ja.osdn.net/projects/ume-font/wiki/FrontPage} からダウンロードできる.
7753 \begin{center}\small
7754 \begin{tabular}{lll}
7755 \toprule
7756 \bf family&\bf series&\bf default\\
7757 \midrule
7758  &medium&Ume Mincho\\
7759 %<en>\smash{\raisebox{1.5ex}{\textit{mincho}}}%
7760 %<ja>\smash{\raisebox{1.5ex}{\gt 明朝}}%
7761  &bold&Ume Mincho\\
7762 \midrule
7763  &&Ume Gothic*\\
7764  &\smash{\raisebox{1.5ex}{medium}}&Ume Gothic O5\\
7765 \cmidrule(l){2-3}
7766 %<en>\textit{gothic}%
7767 %<ja>\gt ゴシック
7768  &bold&Ume Gothic O5\\
7769  &extra bold&Ume Gothic O5\\
7770 \midrule
7771 %<en>\textit{rounded gothic}
7772 %<ja>\gt 丸ゴシック
7773 &&Ume Gothic O5\\
7774 \bottomrule
7775 \end{tabular}
7776 \end{center}
7777
7778  \item[sourcehan]  Source Han Serif and Source Han Sans fonts (Language-specific OTF \textit{or} OTC)
7779 %<en>    \\*[-\dimexpr\medskipamount+\baselineskip\relax]
7780  \item[sourcehan-jp]  Source Han Serif JP and Source Han Sans JP fonts (Region-specific Subset OTF)
7781 \begin{center}\small
7782 \def\AD#1#2{Source Han #1 #2&Source Han #1 JP #2}%
7783 \begin{tabular}{lllll}
7784 \toprule
7785 \bf family&\bf series&\texttt{sourcehan}&\texttt{sourcehan-jp}\\
7786 \midrule
7787  &light&\AD{Serif}{Light}\\
7788 %<en>\textit{mincho}%
7789 %<ja>\textgt{明朝}%
7790  &medium&\AD{Serif}{Regular}\\
7791  &bold&\AD{Serif}{Bold}\\
7792 \midrule
7793  &&\AD{Sans}{Regular*}\\
7794  &\smash{\raisebox{1.5ex}{medium}}
7795  &\AD{Sans}{Medium}\\
7796 \cmidrule(l){2-4}
7797 %<en>\smash{\raisebox{2ex}{\textit{gothic}}}%
7798 %<ja>\smash{\raisebox{2ex}{\gt ゴシック}}%
7799  &bold&\AD{Sans}{Bold}\\
7800  &extra bold&\AD{Sans}{Heavy}\\
7801 \midrule
7802 %<en>\textit{rounded gothic}
7803 %<ja>\gt 丸ゴシック
7804 &&\AD{Sans}{Heavy}\\
7805 \bottomrule
7806 \end{tabular}
7807 \end{center}
7808
7809
7810  \item[noto-otc]  Noto Serif CJK and Noto Sans CJK fonts (OTC)
7811 %<en>    \\*[-\dimexpr\medskipamount+\baselineskip\relax]
7812  \item[noto-otf]  Noto Serif CJK and Noto Sans CJK fonts (Language-specific OTF)
7813 \begin{center}\small
7814 \def\AD#1#2{Noto #1 CJK #2&Noto #1 CJK JP #2}%
7815 \begin{tabular}{lllll}
7816 \toprule
7817 \bf family&\bf series&\texttt{noto-otc}&\texttt{noto-otf}\\
7818 \midrule
7819  &light&\AD{Serif}{Light}\\
7820 %<en>\textit{mincho}%
7821 %<ja>\textgt{明朝}%
7822  &medium&\AD{Serif}{Regular}\\
7823  &bold&\AD{Serif}{Bold}\\
7824 \midrule
7825  &&\AD{Sans}{Regular*}\\
7826  &\smash{\raisebox{1.5ex}{medium}}
7827  &\AD{Sans}{Medium}\\
7828 \cmidrule(l){2-4}
7829 %<en>\smash{\raisebox{2ex}{\textit{gothic}}}%
7830 %<ja>\smash{\raisebox{2ex}{\gt ゴシック}}%
7831  &bold&\AD{Sans}{Bold}\\
7832  &extra bold&\AD{Sans}{Black}\\
7833 \midrule
7834 %<en>\textit{rounded gothic}
7835 %<ja>\gt 丸ゴシック
7836 &&\AD{Sans}{Black}\\
7837 \bottomrule
7838 \end{tabular}
7839 \end{center}
7840
7841 \end{cslist}
7842 %<en>\subsubsection{Presets which do not support multi weights}
7843 %<ja>\subsubsection{単ウェイト用プリセット一覧}
7844 \label{sssec:ltjpreset-single}
7845
7846 %<*en>
7847 Next, we describe settings for using only single weight.
7848 %</en>
7849 %<*ja>
7850 次に,単ウェイト用の設定を述べる.この4設定では
7851 明朝体太字・丸ゴシック体はゴシック体と同じフォントが用いられる.
7852 %</ja>
7853 \par\nobreak\medskip
7854 {\centering\small
7855 \begin{tabular}{lllll}
7856 \toprule
7857 &\tt noembed&\tt ipa&\tt ipaex&\tt ms\\
7858 \midrule
7859 %<*en>
7860 \it mincho&Ryumin-Light (non-embedded)
7861 &IPA Mincho&IPAex Mincho&MS Mincho\\
7862 \it gothic&GothicBBB-Medium (non-embedded)
7863 &IPA Gothic&IPAex Gothic&MS Gothic\\
7864 %</en>
7865 %<*ja>
7866 \gtfamily 明朝&Ryumin-Light(非埋込)
7867 &IPA明朝&IPAex明朝&MS明朝\\
7868 \gtfamily ゴシック&GothicBBB-Medium(非埋込)
7869 &IPAゴシック&IPAexゴシック&MSゴシック\\
7870 %</ja>
7871 \bottomrule
7872 \end{tabular}\par\medskip}
7873
7874 %<en>\subsubsection{Presets which use HG fonts}
7875 %<ja>\subsubsection{HGフォントを使うプリセット}
7876 \label{sssec:ltjpreset-hg}
7877 %<*en>
7878 We can use HG~fonts bundled with Microsoft~Office for realizing multiple weights.
7879 In the table below, starred fonts (e.g., IPA~Gothic*) are used
7880 only if \texttt{jis2004} or \texttt{nodeluxe} option is spefified.
7881 %</en>
7882 %<*ja>
7883 すぐ前に書いた単ウェイト用設定を,Microsoft Office等に付属するHGフォントを使って
7884 多ウェイト化した設定もある.以下の表では,*~付きのフォント(例:IPAゴシック*)は
7885 \texttt{jis2004}と\texttt{nodeluxe}のいずれかのオプションが有効になっているときに使われる.
7886 %</ja>
7887 \par\nobreak\medskip
7888 {\centering\small
7889 \begin{tabular}{lllll}
7890 \toprule
7891 \textbf{family}&\textbf{series}&\tt ipa-hg&\tt ipaex-hg&\tt ms-hg\\
7892 \midrule
7893 %<*en>
7894 &medium&IPA Mincho&IPAex Mincho&MS Mincho\\
7895 \smash{\raisebox{1.5ex}{\textit{mincho}}}%
7896 &bold&HG Mincho E&HG Mincho E&HG Mincho E\\\midrule
7897 &&IPA Gothic*&IPAex Gothic*&MS Gothic*\\
7898 &\smash{\raisebox{1.5ex}{medium}}%
7899 &HG Gothic M&HG Gothic M&HG Gothic M\\\cmidrule{2-5}
7900 \textit{gothic}&bold&HG Gothic E&HG Gothic E&HG Gothic E\\\cmidrule{2-5}
7901 &extra bold&HG Soei Kaku Gothic UB&HG Soei Kaku Gothic UB&HG Soei Kaku Gothic UB\\\midrule
7902 \textit{rounded gothic}&&
7903 HG MaruGothic M PRO&HG MaruGothic M PRO&HG MaruGothic M PRO\\
7904 %</en>
7905 %<*ja>
7906 &medium&IPA明朝&IPAex明朝&MS明朝\\
7907 \smash{\raisebox{1.5ex}{\textgt{明朝}}}%
7908 &bold&HG明朝E&HG明朝E&HG明朝E\\\midrule
7909 &&IPAゴシック*&IPAexゴシック*&MSゴシック*\\
7910 &\smash{\raisebox{1.5ex}{medium}}%
7911 &HGゴシックM&HGゴシックM&HGゴシックM\\\cmidrule{2-5}
7912 \textgt{ゴシック}&bold&HGゴシックE&HGゴシックE&HGゴシックE\\\cmidrule{2-5}
7913 &extra bold&HG創英角ゴシックUB&HG創英角ゴシックUB&HG創英角ゴシックUB\\\midrule
7914 \textgt{丸ゴシック}&&
7915 HG丸ゴシックM-PRO&HG丸ゴシックM-PRO&HG丸ゴシックM-PRO\\
7916 %</ja>
7917 \bottomrule
7918 \end{tabular}\par\medskip}
7919
7920 %<*en>
7921 Note that HG~Mincho~E, HG~Gothic~E, HG Soei Kaku Gothic UB, and HG Maru Gothic PRO
7922 are internally specified by:
7923 \begin{description}
7924 \item[default] by font name (\texttt{HGMinchoE}, etc.).
7925 \item[{\tt 90jis}] by file name (\texttt{hgrme.ttc}, \texttt{hgrge.ttc}, \texttt{hgrsgu.ttc}, \texttt{hgrsmp.ttf}).
7926 \item[{\tt jis2004}] by file name (\texttt{hgrme04.ttc}, \texttt{hgrge04.ttc}, \texttt{hgrsgu04.ttc}, \texttt{hgrsmp04.ttf}).
7927 \end{description}
7928 %</en>
7929 %<*ja>
7930 なお,HG明朝E・HGゴシックE・HG創英角ゴシックUB・HG丸ゴシック体PROの4つについては,内部で
7931 \begin{description}
7932 \item[標準] フォント名(\texttt{HGMinchoE} など)
7933 \item[{\tt 90jis}指定時] ファイル名 (%
7934 \texttt{hgrme.ttc}, \texttt{hgrge.ttc}, \texttt{hgrsgu.ttc}, \texttt{hgrsmp.ttf})
7935 \item[{\tt jis2004}指定時] ファイル名 (%
7936 \texttt{hgrme04.ttc}, \texttt{hgrge04.ttc}, \texttt{hgrsgu04.ttc}, \texttt{hgrsmp04.ttf})
7937 \end{description}
7938 として指定を行っているので注意すること.
7939 %</ja>
7940
7941 %<en>\subsubsection{Define/Use Custom Presets}
7942 %<ja>\subsubsection{新たなプリセットの定義}
7943
7944 %<*ja>
7945 バージョン********.0以降では,自分で新たなプリセットを定義することが出来るようになった.
7946 以下に説明する2命令はプリアンブルでしか実行できない.
7947 %</ja>
7948 %<*en>
7949 From version~********.0, one can define new presets using \cs{ltjnewpreset},
7950 and use them by \cs{ltjapplypreset}. These two commands can only be used in the preamble.
7951 %</en>
7952 \begin{cslist}
7953  \item[\cs{ltjnewpreset}\{<name>\}\{<specification>\}]
7954 %<*ja>
7955   新たに<name>という名称のプリセットを定義する.この名称は,
7956   すでに定義されているプリセット名や,
7957   \ref{sssec:ltjpreset-general}で定義されているオプション,さらに
7958   次の9つと重複してはならない.
7959   \begin{quote}
7960         \ttfamily
7961         mc mc-l mc-m mc-bx gt gt-m gt-bx gt-eb mg-m
7962   \end{quote}
7963
7964   <specification>は,プリセット名や以下のキー達のコンマ区切りリストを指定する:
7965   \begin{description}
7966    \item[\ttfamily mc-l=<font>] 明朝体細字(\cs{mcfamily}\cs{ltseries})
7967    \item[\ttfamily mc-m=<font>] 明朝体中字(\cs{mcfamily}\cs{mdseries})
7968    \item[\ttfamily mc-bx=<font>] 明朝体太字(\cs{mcfamily}\cs{bfseries})
7969    \item[\ttfamily gt-m=<font>] ゴシック体中字(\cs{gtfamily}\cs{mdseries})
7970    \item[\ttfamily gt-bx=<font>] ゴシック体太字(\cs{gtfamily}\cs{bfseries})
7971    \item[\ttfamily gt-eb=<font>] ゴシック体太字(\cs{gtfamily}\cs{ebseries})
7972    \item[\ttfamily mg-m=<font>] 丸ゴシック体(\cs{mgfamily})
7973    \item[\ttfamily mc=<font>] 明朝体の細字・中字・太字全部を設定.
7974         以下を指定したことと同じである:
7975         \begin{quote}
7976           \ttfamily mc-l=<font>, mc-m=<font>, mc-bx=<font>
7977         \end{quote}
7978    \item[\ttfamily gt=<font>] ゴシック体の中字・太字・極太全部を設定.
7979         以下を指定したことと同じである:
7980         \begin{quote}
7981           \ttfamily gt-m=<font>, gt-bx=<font>, gt-eb=<font>
7982         \end{quote}
7983   \end{description}
7984   なお,パッケージ読み込み時に \texttt{deluxe} が有効でない場合は,
7985   上記9キーのうち\texttt{mc}, \texttt{gt}しか実質的に意味を持たない.  
7986 %</ja>
7987 %<*en>
7988   Define new preset~<name>. This <name> cannot be same as other presets,
7989   options described in Subsubsection~\ref{sssec:ltjpreset-general}, nor
7990   following nine strings:
7991   \begin{quote}
7992         \ttfamily
7993         mc mc-l mc-m mc-bx gt gt-m gt-bx gt-eb mg-m
7994   \end{quote}
7995
7996   <specification> is a comma-separated list which consists of
7997   other presets and/or the following keys:
7998   \begin{description}
7999    \item[\ttfamily mc-l=<font>] mincho light
8000    \item[\ttfamily mc-m=<font>] mincho medium
8001    \item[\ttfamily mc-bx=<font>] mincho bold
8002    \item[\ttfamily gt-m=<font>] gothic medium
8003    \item[\ttfamily gt-bx=<font>] gothic bold
8004    \item[\ttfamily gt-eb=<font>] gothic extra~bold
8005    \item[\ttfamily mg-m=<font>] rounded gothic
8006    \item[\ttfamily mc=<font>] Same as
8007         \begin{quote}
8008           \ttfamily mc-l=<font>, mc-m=<font>, mc-bx=<font>
8009         \end{quote}
8010    \item[\ttfamily gt=<font>] Same as
8011         \begin{quote}
8012           \ttfamily gt-m=<font>, gt-bx=<font>, gt-eb=<font>
8013         \end{quote}
8014   \end{description}
8015   If \texttt{deluxe} is not specified at loading the package,
8016   only \texttt{mc}~and~\texttt{gt} keys (among above 9~keys) have a meaning.
8017 %</en>
8018  \item[\cs{ltjnewpreset}*\{<name>\}\{<specification>\}]
8019 %<*ja>
8020   \cs{ltjnewpreset}とほぼ同じであるが,こちらはすでに定義されているプリセット名
8021   を<name>に指定した場合にはエラーを出さずに定義を置き換える.
8022 %</ja>
8023 %<*en>
8024   Almost same as \cs{ltjnewpreset}. However, if <name> matches a preset which already defined,
8025   this command simply overwrite it.
8026 %</en>
8027  \item[\cs{ltjapplypreset}\{<name>\}]
8028 %<ja> <name>で指定されたプリセットを使って和文フォントを設定する.
8029 %<en> Set Japanese font families using preset~<name>.
8030 \end{cslist}
8031
8032 %<*ja>
8033 なお,\cs{ltjnewpreset}の第二引数<specification>に含まれる
8034 プリセット名は\cs{ltjnewpreset}の時点で定義されている必要はなく,
8035 \cs{ltjapplypreset}で実際に使うときに定義されていれば良い.
8036 そのため,次のような記述も可能である:
8037 \begin{lstlisting}
8038   \ltjnewpreset{hoge}{piyo,mc-bx=HiraMinProN-W6}
8039   \ltjnewpreset{piyo}{mg-m=HiraMaruProN-W4}
8040   \ltjapplypreset{hoge}
8041 \end{lstlisting}
8042
8043 \paragraph{注意}
8044 \cs{ltjnewpreset}で定義したプリセットには以下の制限がある.
8045 \begin{itemize}
8046   \item 非埋め込みのフォントを指定することはできない.
8047   \item \texttt{ipa-hg}などのいくつかのプリセットでは
8048   「\texttt{90jis}, \texttt{jis2004}が指定されているか否かでフォントの指定を変える」処理が
8049   行われていたが,\cs{ltjnewpreset}で定義したプリセットではこの処理は働かない.
8050   HGフォントやモガ明朝などを使うプリセットを定義する場合には注意すること.
8051 \end{itemize}
8052 %</ja>
8053 %<*en>
8054 Note that \cs{ltjnewpreset} does not ``expand'' the definition to define a preset.
8055 This means that one can write as the following:
8056 \begin{lstlisting}
8057   \ltjnewpreset{hoge}{piyo,mc-bx=HiraMinProN-W6}
8058   \ltjnewpreset{piyo}{mg-m=HiraMaruProN-W4}
8059   \ltjapplypreset{hoge}
8060 \end{lstlisting}
8061
8062 \paragraph{Restrictions}
8063 Presets which are defined by \cs{ltjnewpreset} have following restrictions:
8064 \begin{itemize}
8065   \item One cannot specify non-embedded fonts (such as Ryumin-Light).
8066   \item Some presets, such as \texttt{ipa-hg}, have a feature that
8067   fonts are changed according to whether \texttt{90jis}~or~\texttt{jis2004} is speified.
8068   This feature is not usable in presets which are defined by \cs{ltjnewpreset}.
8069 \end{itemize}
8070 %</en>
8071
8072
8073 \clearpage
8074 %<en>\part{Implementations}
8075 %<ja>\part{実装}
8076 \label{part-imp}
8077 %<en>\section{Storing Parameters}
8078 %<ja>\section{パラメータの保持}
8079 \label{sec-para}
8080 %<en>\subsection{Used dimensions, attributes and whatsit nodes}
8081 %<ja>\subsection{\LuaTeX-jaで用いられるレジスタとwhatsitノード}
8082
8083 %<*en>
8084 Here the following is the list of dimensions and attributes which are used in \LuaTeX-ja.
8085 %</en>
8086 %<*ja>
8087 以下は\LuaTeX-jaで用いられる寸法レジスタ(dimension),属性レジスタ(attribute)の
8088 リストである.
8089 %</ja>
8090 \begin{list}{}{%
8091 \def\makelabel{\ttfamily}\advance\leftmargin1\zw
8092 \def\dim#1{\item[\textbackslash #1\ \textrm{(dimension)}]}
8093 \def\cnt#1{\item[\textbackslash #1\ \textrm{(counter)}]}
8094 \def\attr#1{\item[\textbackslash #1\ \textrm{(attribute)}]}
8095 }
8096
8097 \dim{jQ}
8098 %<*en>
8099 \cs{jQ} is equal to
8100                         $1\,\textrm{Q}=0.25\,\textrm{mm}$, where ``Q''~(also called ``級'') is
8101                         a unit used in Japanese phototypesetting.
8102 So one should not change the value of this dimension.
8103 %</en>
8104 %<*ja>
8105 \cs{jQ} は写植で用いられた$1\,\textrm{Q}=0.25\,\textrm{mm}$%
8106 (「級」とも書かれる)に等しい.したがって,
8107 この寸法レジスタの値を変更してはならない.
8108 %</ja>
8109
8110 \dim{jH}
8111 %<*en>
8112 There is also a unit called ``歯'' which equals to $0.25\,\textrm{mm}$ and
8113                          used in Japanese phototypesetting.
8114 This \cs{jH} is the same \cs{dimen} register as \cs{jQ}.
8115 %</en>
8116 %<*ja>
8117 同じく写植で用いられていた単位として「歯」があり,これも$0.25\,\textrm{mm}$と
8118 等しい.この \cs{jH} は \cs{jQ} と同じ寸法レジスタを指す.
8119 %</ja>
8120
8121 \dim{ltj@zw}
8122 %<*en>
8123 A temporal register for the ``full-width'' of current Japanese font.
8124 The command \cs{zw} sets this register to the correct value, and
8125 ``return'' this register itself.
8126 %</en>
8127 %<*ja>
8128 現在の和文フォントの「全角幅」を保持する一時レジスタ.
8129 \cs{zw} 命令は,このレジスタを適切な値に設定した後,
8130 「このレジスタ自体を返す」.
8131 %</ja>
8132
8133 \dim{ltj@zh}
8134 %<*en>
8135 A temporal register for the ``full-height'' (usually the sum of height of imaginary body and its depth) of current Japanese font.
8136 The command \cs{zh} sets this register to the correct value, and
8137 ``return'' this register itself.
8138 %</en>
8139 %<*ja>
8140 現在の和文フォントの「全角高さ」(通常,高さと深さの和)を保持する一時レジスタ.
8141 \cs{zh} 命令は,このレジスタを適切な値に設定した後,
8142 「このレジスタ自体を返す」.
8143 %</ja>
8144
8145 \attr{jfam}
8146 %<*en>
8147 Current number of Japanese font family for math formulas.
8148 %</en>
8149 %<*ja>
8150 数式用の和文フォントファミリの現在の番号.
8151 %</ja>
8152
8153 \attr{ltj@curjfnt}
8154 %<*en>
8155 The font index of current Japanese font for horizontal direction.
8156 %</en>
8157 %<*ja>
8158 現在の横組用和文フォントのフォント番号.
8159 %</ja>
8160
8161 \attr{ltj@curtfnt}
8162 %<*en>
8163 The font index of current Japanese font for vertical direction.
8164 %</en>
8165 %<*ja>
8166 現在の縦組用和文フォントのフォント番号.
8167 %</ja>
8168
8169 \attr{ltj@charclass}
8170 %<*en>
8171 The character class of a \textbf{JAchar}. This attribute is only set on a
8172                          \textit{glyph\_node} which contains a \textbf{JAchar}.
8173 %</en>
8174 %<*ja>
8175 \textbf{JAchar}の文字クラス.\textbf{JAchar}が格納された\textit{glyph\_node}でのみ使われる.
8176 %</ja>
8177
8178 \attr{ltj@yablshift}
8179 %<*en>
8180 The amount of shifting the baseline of alphabetic fonts in scaled point ($2^{-16}\,\textrm{pt}$).
8181 %</en>
8182 %<*ja>
8183 スケールド・ポイント($2^{-16}\,\textrm{pt}$)を単位とした欧文フォントのベースラインの移動量.
8184 %</ja>
8185
8186 \attr{ltj@ykblshift}
8187 %<*en>
8188 The amount of shifting the baseline of Japanese fonts in scaled point ($2^{-16}\,\textrm{pt}$).
8189 %</en>
8190 %<*ja>
8191 スケールド・ポイント($2^{-16}\,\textrm{pt}$)を単位とした和文フォントのベースラインの移動量.
8192 %</ja>
8193
8194 \attr{ltj@tablshift}
8195 \attr{ltj@tkblshift}
8196
8197 \attr{ltj@autospc}
8198 %<*en>
8199 Whether the auto insertion of \Param{kanjiskip} is allowed at the node.
8200 %</en>
8201 %<*ja>
8202 そのノードで\Param{kanjiskip}の自動挿入が許されるかどうか.
8203 %</ja>
8204
8205 \attr{ltj@autoxspc}
8206 %<*en>
8207 Whether the auto insertion of \Param{xkanjiskip} is allowed at the node.
8208 %</en>
8209 %<*ja>
8210 そのノードで\Param{xkanjiskip}の自動挿入が許されるかどうか.
8211 %</ja>
8212
8213 \attr{ltj@icflag}
8214 %<*en>
8215 An attribute for distinguishing ``kinds'' of a node. One of the following value is
8216 assigned to this attribute:
8217 %</en>
8218 %<*ja>
8219 ノードの「種類」を区別するための属性.以下のうちのひとつが値として割り当てられる:
8220 %</ja>
8221 \begin{description}
8222 \item[\textit{italic} (1)]
8223 %<*en>
8224 Kerns from italic correction (\verb+\/+), or from kerning information of a Japanese font.
8225 These kerns are ``ignored'' in the insertion process of \textbf{JAglue},
8226 unlike explicit \cs{kern}.
8227 %</en>
8228 %<*ja>
8229 イタリック補正(\verb+\/+)によるカーン,
8230 または \Pkg{luaotfload} によって挿入されたフォントのカーニング情報由来のカーン.
8231 これらのカーンは通常の \cs{kern} とは異なり,
8232 \textbf{JAglue}の挿入処理においては透過する.
8233 %</ja>
8234
8235 \item[\textit{packed} (2)]
8236
8237 \item[\textit{kinsoku} (3)]
8238 %<*en>
8239 Penalties inserted for the word-wrapping process (\emph{kinsoku shori}) of Japanese characters.
8240 %</en>
8241 %<ja>禁則処理のために挿入されたペナルティ.
8242 \item[\mathversion{bold}$(\textit{from\_jfm}-2)$--$(\textit{from\_jfm}+2)$~(4--8)]
8243 %<en>Glues/kerns from JFM.
8244 %<ja>JFM由来のグルー/カーン.
8245 \item[\textit{kanji\_skip}~(9), \textit{kanji\_skip\_jfm}~(10)]
8246 %<en>Glues from \Param{kanjiskip}.
8247 %<ja>和文間空白\Param{kanjiskip}を表すグルー.
8248 \item[\textit{xkanji\_skip}~(11), \textit{xkanji\_skip\_jfm}~(12)]
8249 %<en>Glues from \Param{xkanjiskip}.
8250 %<ja>和欧文間空白\Param{xkanjiskip}を表すグルー.
8251 \item[\textit{processed} (13)]
8252 %<en>Nodes which is already processed by \ldots.
8253 %<ja>\LuaTeX-ja の内部処理によって既に処理されたノード.
8254 \item[\textit{ic\_processed} (14)]
8255 %<*en>
8256 Glues from an italic correction, but already processed in the insertion process of \textbf{JAglue}s.
8257 %</en>
8258 %<ja>イタリック補正に由来するグルーであって,既に \textbf{JAglue} 挿入処理にかかったもの.
8259 \item[\textit{boxbdd} (15)]
8260 %<en>Glues/kerns that inserted just the beginning or the ending of an hbox or a paragraph.
8261 %<ja>hboxか段落の最初か最後に挿入されたグルー/カーン.
8262 \end{description}
8263
8264 %<*ja>
8265 また,挿入処理の結果であるリストの最初のノードでは,\verb+\ltj@icflag+ の値に
8266 \textit{processed\_begin\_flag}~(128)が追加される.これによって,\cs{unhbox} が
8267 連続した場合でも「ボックスの境界」が識別できるようになっている.
8268 %</ja>
8269
8270 \attr{ltj@kcat\,$i$}
8271 %<*en>
8272 Where $i$~is a natural number which is less than~7.
8273 These 7~attributes store bit~vectors indicating which character block is regarded as a block of \textbf{JAchar}s.
8274 %</en>
8275 %<*ja>
8276 $i$は7より小さい自然数.
8277 これら7つの属性レジスタは,どの文字ブロックが\textbf{JAchar}のブロックとして
8278 扱われるかを示すビットベクトルを格納する.
8279 %</ja>
8280
8281 \attr{ltj@dir}
8282 %<*ja>
8283 \textit{direction}~whatsit(後述)において組方向を示すために,あるいは\textit{dir\_box}の
8284                          組方向を用いる.\textit{direction}~whatsitにおいては値は
8285 \begin{quote}
8286  \textit{dir\_dtou} (1), \textit{dir\_tate} (3),
8287  \textit{dir\_yoko} (4), \textit{dir\_utod} (11)
8288 \end{quote}
8289 のいずれかであり,\textit{dir\_box}ではこれらに次を加えた値をとる(\ref{sec-dir-imp}章参照).
8290 %</ja>
8291 \begin{description}
8292 \item[\textit{dir\_node\_auto} (128)]
8293 %<ja> 異なる組方向に配置するために自動的に作られたボックス.
8294 \item[\textit{dir\_node\_manual} (256)]
8295 %<ja> \cs{ltjsetwd} によって「ボックスの本来の組方向とは異なる組方向での寸法」を
8296 %<ja> 設定したときに,それを記録するためのボックス.
8297 \end{description}
8298 %<ja> \TeX 側から見える値,つまり \verb+\the\ltj@dir+ の値は常に0である.
8299
8300 \cnt{ltjlineendcomment}
8301 %<*ja>
8302   \LuaTeX-jaは\textbf{JAchar}で入力行が終了した場合,その直後にコメント文字を
8303   おくことで余計な空白が挿入されることを防いでいる.
8304   \cs{ltjlineendcomment}はその際のコメント文字のUnicodeにおける符号位置を指定する
8305   (詳細は\ref{ssec:lineend}節を参照).
8306
8307   \LuaTeX-jaにおける既定値は$\texttt{"FFFFF}=1048575$であり,
8308   ユーザは内部動作を熟知していない限りこのカウンタの値を変更してはならない.
8309   \cs{ltjlineendcomment}の値がUnicodeの範囲外(負や,$\texttt{"10FFFF}=1114111$を超えた場合)
8310   にくることは想定されていない.
8311 %</ja>
8312 \end{list}
8313
8314 %<*en>
8315 Furthermore, \LuaTeX-ja uses several user-defined whatsit nodes for
8316 internal processing. All those nodes except \emph{direction} whatsits
8317 store a natural number (hence its \texttt{type} is 100).
8318 \emph{direction} whatsits store a node list, hence its \texttt{type} is 110.
8319 Their \texttt{user\_id} (used for distinguish user-defined whatsits)
8320 are allocated by \texttt{luatexbase.newuserwhatsitid}.
8321 %</en>
8322 %<*ja>
8323 さらに,\LuaTeX-jaはいくつかのuser-defined whatsit nodeを内部処理に用いる.
8324 \textit{direction} whatsitはノードリストを格納するが,
8325 それ以外のwhatsitノードの \texttt{type} は100であり,ノードは自然数を格納している.
8326 user-defined whatsitを識別するための \texttt{user\_id} は\
8327 \texttt{luatexbase.newuserwhatsitid} により確保されており,
8328 下の見出しは単なる識別用でしかない.
8329 %</ja>
8330 \begin{description}
8331 \item[\textit{inhibitglue}]
8332 %<*en>
8333 Nodes for indicating that \cs{inhibitglue} is
8334            specified. The \texttt{value} field of these nodes doesn't matter.
8335 %</en>
8336 %<*ja>
8337 \cs{inhibitglue} が指定されたことを示すノード.これらのノードの\
8338 \texttt{value} フィールドは意味を持たない.
8339 %</ja>
8340
8341 \item[\textit{stack\_marker}]
8342 %<*en>
8343 Nodes for \LuaTeX-ja's stack system (see the next
8344            subsection). The \texttt{value} field of these nodes is
8345            current group level.
8346 %</en>
8347 %<*ja>
8348 \LuaTeX-jaのスタックシステム(次の節を参照)のためのノード.
8349 これらのノードの \texttt{value} フィールドは現在のグループネストレベルを表す.
8350 %</ja>
8351
8352 \item[\textit{char\_by\_cid}]
8353 %<*en>
8354 Nodes for \textbf{JAchar} which the callback process of
8355            \Pkg{luaotfload} won't be applied, and the character code is
8356            stored in the \texttt{value} field. Each node of this type are
8357            converted to a \textit{glyph\_node} \emph{after}
8358            the callback process of luaotfload.
8359 Nodes of this type is used in \cs{CID}, \cs{UTF} and IVS support.
8360 %</en>
8361 %<*ja>
8362 \Pkg{luaotfload}のコールバックによる処理が適用されない\textbf{JAchar}のためのノードで,
8363 \texttt{value} フィールドに文字コードが格納されている.
8364 この種類のノードはそれぞれが\Pkg{luaotfload}のコールバックの処理の
8365 \emph{後で}\textit{glyph\_node}に変換される.
8366 \cs{CID}, \cs{UTF}やIVS対応処理でこの種類のノードが利用されている.
8367 %</ja>
8368
8369 \item[\textit{replace\_vs}]
8370 %<*en>
8371 Similar to \textit{char\_by\_cid} whatsits above.
8372 These nodes are for \textbf{ALchar} which the callback process of
8373            \Pkg{luaotfload} won't be applied.
8374 %</en>
8375 %<*ja>
8376 上の\textit{char\_by\_cid}と同様に,
8377 これらのノードは\Pkg{luaotfload}のコールバックによる処理が適用されない\textbf{ALchar}のた
8378            めものである.
8379 %</ja>
8380
8381 \item[\textit{begin\_par}]
8382 %<*en>
8383 Nodes for indicating beginning of a paragraph.
8384 A paragraph which is started by \cs{item} in list-like environments has a horizontal box
8385 for its label before the actual contents. So \dots
8386 %</en>
8387 %<*ja>
8388 「段落の開始」を意味するノード.
8389 \texttt{list}環境,\texttt{itemize}環境などにおいて,\cs{item} で始まる各項目は……
8390 %</ja>
8391
8392 \item[\textit{direction}]
8393
8394 \end{description}
8395
8396 %<*en>
8397 These whatsits will be removed during the process of inserting \textbf{JAglue}s.
8398 %</en>
8399 %<*ja>
8400 これらのwhatsitノードは\textbf{JAglue}の挿入処理の間に取り除かれる.
8401 %</ja>
8402
8403 %<en>\subsection{Stack system of \LuaTeX-ja}
8404 %<ja>\subsection{\LuaTeX-jaのスタックシステム}
8405 \label{ssec:stack}
8406
8407 %<en>\paragraph{Background}
8408 %<ja>\paragraph{背景}
8409 %<*en>
8410 \LuaTeX-ja has its own stack system, and most parameters of \LuaTeX-ja
8411 are stored in it. To clarify the reason, imagine the parameter
8412 \Param{kanjiskip} is stored by a skip, and consider the following
8413 source:
8414 %</en>
8415 %<*ja>
8416 \LuaTeX-jaは独自のスタックシステムを持ち,\LuaTeX-jaのほとんどのパラメータは
8417 これを用いて保持されている.その理由を明らかにするために,
8418 \Param{kanjiskip}パラメータがスキップレジスタで保持されているとし,
8419 以下のコードを考えてみよう:
8420 %</ja>
8421 \begin{LTXexample}
8422 \ltjsetparameter{kanjiskip=0pt}ふがふが.%
8423 \setbox0=\hbox{%
8424   \ltjsetparameter{kanjiskip=5pt}ほげほげ}
8425 \box0.ぴよぴよ\par
8426 \end{LTXexample}
8427
8428 %<*en>
8429 As described in Subsection~\ref{ssec:param}, the only effective value of
8430 \Param{kanjiskip} in an hbox is the latest value, so the value of
8431 \Param{kanjiskip} which applied in the entire hbox should be 5\,pt.
8432 However, by the implementation method of \LuaTeX, this ``5\,pt'' cannot be
8433 known from any callbacks.  In the \texttt{tex/packaging.w}, which is a
8434 file in the source of \LuaTeX, there are the following codes:
8435 %</en>
8436 %<*ja>
8437 \ref{ssec:param}節で述べたように,あるhboxの中で効力を持つ
8438 \Param{kanjiskip}の値は最後に現れた値のみであり,したがってボックス全体に適用される
8439 \Param{kanjiskip}は5\,ptであるべきである.しかし,\LuaTeX の実
8440 装を観察すると,この5\,ptという長さはどのコールバックからも知ることはできないことがわかる.
8441 \LuaTeX のソースファイルの1つ \texttt{tex/packaging.w} の中に,
8442 以下のコードがある:
8443 %</ja>
8444 \begin{lstlisting}[numbers=left,firstnumber=1226]
8445 void package(int c)
8446 {
8447     scaled h;                   /* height of box */
8448     halfword p;                 /* first node in a box */
8449     scaled d;                   /* max depth */
8450     int grp;
8451     grp = cur_group;
8452     d = box_max_depth;
8453     unsave();
8454     save_ptr -= 4;
8455     if (cur_list.mode_field == -hmode) {
8456         cur_box = filtered_hpack(cur_list.head_field,
8457                                  cur_list.tail_field, saved_value(1),
8458                                  saved_level(1), grp, saved_level(2));
8459         subtype(cur_box) = HLIST_SUBTYPE_HBOX;
8460 \end{lstlisting}
8461 %<*en>
8462 Notice that \texttt{unsave()} is executed \emph{before}
8463 \texttt{filtered\_hpack()}, where \texttt{hpack\_filter} callback is
8464 executed) here. So ``5\,pt'' in the above source is orphaned at
8465 \texttt{unsave()}, and hence it can't be accessed from \texttt{hpack\_filter}
8466 callback.
8467 %</en>
8468 %<*ja>
8469 \texttt{unsave()} が \texttt{filtered\_hpack()}(これは \texttt{hpack\_filter} コールバックが
8470 実行されるところである)の\emph{前に}実行されていることに注意する.
8471 したがって,上記ソース中で5\,ptは \texttt{unsave()} のところで捨てられ,
8472 \texttt{hpack\_filter} コールバックからはアクセスすることができない.
8473 %</ja>
8474
8475 %<en>\paragraph{Implementation}
8476 %<ja>\paragraph{解決法}
8477
8478 %<*en>
8479 The code of stack system is based on that in a post of Dev-luatex mailing list\footnote{%
8480 \texttt{[Dev-luatex] tex.currentgrouplevel}, a post at 2008/8/19 by Jonathan Sauer.}.
8481 %</en>
8482 %<*ja>
8483 スタックシステムのコードはDev-luatexメーリングリストのある投稿\footnote{%
8484 \texttt{[Dev-luatex] tex.currentgrouplevel}: Jonathan Sauerによる2008/8/19の投稿.}を
8485 ベースにしている.
8486 %</ja>
8487
8488 %<*en>
8489 These are two \TeX\ count registers for maintaining information:
8490 \verb+\ltj@@stack+ for the stack level, and \verb+\ltj@@group@level+ for
8491 the \TeX's group level when the last assignment was done.  Parameters
8492 are stored in one big table named \texttt{charprop\_stack\_table}, where
8493 \texttt{charprop\_stack\_table[$i$]} stores data of stack level~$i$. If
8494 a new stack level is created by \cs{ltjsetparameter}, all data of the
8495 previous level is copied.
8496 %</en>
8497 %<*ja>
8498 情報を保持するために,2つの\TeX の整数レジスタを用いている:
8499 \verb+\ltj@@stack+ にスタックレベル,\verb+\ltj@@group@level+ に最後の代入が
8500 なされた時点での\TeX のグループレベルを保持している.
8501 パラメータは\texttt{charprop\_stack\_table}という名前のひとつの大きなテーブルに
8502 格納される.ここで,\texttt{charprop\_stack\_table[$i$]}はスタックレベル$i$の
8503 データを格納している.もし新しいスタックレベルが \cs{ltjsetparameter} によって
8504 生成されたら,前のレベルの全てのデータがコピーされる.
8505 %</ja>
8506
8507 %<*en>
8508 To resolve the problem mentioned in above paragraph ``Background'', \LuaTeX-ja uses
8509 another trick. When the stack level is about to be increased, a whatsit
8510 node whose type, subtype and value are 44~(\textit{user\_defined}),
8511 \textit{stack\_marker} and the current group level respectively is appended to the current
8512 list (we refer this node by \textit{stack\_flag}). This enables us to
8513 know whether assignment is done just inside a hbox. Suppose that the
8514 stack level is~$s$ and the \TeX's group level is~$t$ just after the hbox
8515 group, then:
8516 %</en>
8517 %<*ja>
8518 上の「背景」で述べた問題を解決するために,\LuaTeX-jaでは次の手法を用いる:
8519 スタックレベルが増加するするとき,type, subtype, valueがそれぞれ
8520 44~(\textit{user\_defined}), \textit{stack\_marker},そして現在のグループレベルであるwhatsitノード
8521 を現在のリストに付け加える(このノードを\textit{stack\_flag}とする).
8522 これにより,あるhboxの中で代入がなされたかどうかを知ることが可能
8523 となる.スタックレベルを$s$,そのhbox groupの直後の\TeX のグループレベルを
8524 $t$とすると:
8525 %</ja>
8526 \begin{itemize}
8527 %<*en>
8528 \item If there is no \textit{stack\_flag} node in the list of the contents of the hbox, then
8529       no assignment was occurred inside the hbox. Hence values of
8530       parameters at the end of the hbox are stored in the stack
8531       level~$s$.
8532 %</en>
8533 %<*ja>
8534 \item もしそのhboxの中身を表すリストの中に\textit{stack\_flag}ノードがなければ,
8535   hboxの中では代入は起こらなかったということになる.
8536   したがって,そのhboxの終わりにおけるパラメータの値はスタックレベル$s$に
8537   格納されている.
8538 %</ja>
8539
8540 %<*en>
8541 \item If there is a \textit{stack\_flag} node whose value is~$t+1$, then
8542       an assignment was occurred just inside the hbox group. Hence
8543       values of parameters at the end of the hbox are stored in the
8544       stack level~$s+1$.
8545 %</en>
8546 %<*ja>
8547 \item もし値が$t+1$の\textit{stack\_flag}ノードがあれば,その
8548   hboxの中で代入が起こったことになる.
8549   したがって,hboxの終わりにおけるパラメータの値はスタックレベル$s+1$に
8550   格納されている.
8551 %</ja>
8552
8553 %<*en>
8554 \item If there are \textit{stack\_flag} nodes but all of their values
8555       are more than~$t+1$, then an assignment was occurred in the box,
8556       but it is done in more internal group. Hence values of
8557       parameters at the end of the hbox are stored in the stack
8558       level~$s$.
8559 %</en>
8560 %<*ja>
8561 \item もし\textit{stack\_flag}ノードがあるがそれらの値が全て$t+1$より大きい
8562   場合,そのボックスの中で代入が起こったが,それは「より内部の」グループで
8563   起こったということになる.したがって,hboxの終わりでのパラメータの
8564   値はスタックレベル$s$に格納されている.
8565 %</ja>
8566 \end{itemize}
8567
8568 %<*en>
8569 Note that to work this trick correctly, assignments to
8570 \verb+\ltj@@stack+ and \verb+\ltj@@group@level+ have to be local always,
8571 regardless the value of \cs{globaldefs}.
8572 To solve this problem, we use another trick: the assignment
8573 \hbox{\verb+\directlua{tex.globaldefs=0}+} is always local.
8574 %</en>
8575 %<*ja>
8576 このトリックを正しく働かせるためには,\verb+\ltj@@stack+ と \verb+\ltj@@group@level+ への
8577 代入は \cs{globaldefs} の値によらず常にローカルでなければならないことに注意する.
8578 この問題は \hbox{\verb+\directlua{tex.globaldefs=0}+}(この代入は常にローカル)を
8579 用いることで解決している.
8580 %</ja>
8581
8582 %<*en>
8583 \subsection{Lua functions of the stack system}
8584 In this subsection, we will see how a user use \LuaTeX-ja's stack system to
8585 store some data which obeys the grouping of \TeX.
8586 %</en>
8587 %<*ja>
8588 \subsection{スタックシステムで使用される関数}
8589 本節では,ユーザが\LuaTeX-jaのスタックシステムを使用して,
8590 \TeX のグルーピングに従うような
8591 独自のデータを取り扱う方法を述べる.
8592 %</ja>
8593
8594 %<*en>
8595 The following function can be used to store data into a stack:
8596 \begin{lstlisting}
8597 luatexja.stack.set_stack_table(index, <any> data)
8598 \end{lstlisting}
8599 Any values which except \texttt{nil}~and~NaN are usable as \textit{index}.
8600 However, a user should use only negative integers or strings as \textit{index},
8601 since natural numbers are used by \LuaTeX-ja itself.
8602 Also, whether \textit{data} is stored locally or globally
8603 is determined by \texttt{luatexja.isglobal}
8604 (stored globally if and only if \texttt{luatexja.isglobal == 'global'}).
8605 %</en>
8606 %<*ja>
8607 スタックに値を設定するには,以下のLua関数を呼び出せば良い:
8608 \begin{lstlisting}
8609 luatexja.stack.set_stack_table(<any> index, <any> data)
8610 \end{lstlisting}
8611 直感的には,スタックテーブル中のインデックス\textit{index}の値を\textit{data}にする,という意味である.
8612 \textit{index}の値としては \texttt{nil} とNaN以外の任意の値を使えるが,
8613 自然数は\LuaTeX-jaが使用する(将来の拡張用も含む)ので,
8614 ユーザが使用する場合は負の整数値か文字列の値にすることが望ましい.
8615 また,ローカルに設定されるかグローバルに設定されるかは,\texttt{luatexja.isglobal} の値に依存する
8616 (グローバルに設定されるのは,\texttt{luatexja.isglobal == 'global'} であるちょうどその時).
8617 %</ja>
8618
8619 %<*en>
8620 Stored data can be obtained as the return value of
8621 \begin{lstlisting}
8622 luatexja.stack.get_stack_table(index, <any> default, <number> level)
8623 \end{lstlisting}
8624 where \textit{level} is the stack level, which is usually the value of \verb+\ltj@@stack+,
8625 and \textit{default} is the default value which will be returned if no values are stored
8626 in the stack table whose level is \textit{level}.
8627 %</en>
8628 %<*ja>
8629 スタックの値は,
8630 \begin{lstlisting}
8631 luatexja.stack.get_stack_table(<any> index, <any> default, <number> level)
8632 \end{lstlisting}
8633 の戻り値で取得できる.\textit{level}はスタックレベルであり,
8634 通常は \verb+\ltj@@stack+ の値を指定することになるだろう.
8635 \textit{default}はレベル\textit{level}のスタックに値が設定されていなかった場合に
8636 返すデフォルト値である.
8637 %</ja>
8638
8639 \begin{figure}[tb]
8640 \begin{lstlisting}[numbers=left, firstnumber=380]
8641 \protected\def\ltj@setpar@global{%
8642   \relax\ifnum\globaldefs>0\directlua{luatexja.isglobal='global'}%
8643     \else\directlua{luatexja.isglobal=''}\fi
8644 }
8645 \protected\def\ltjsetparameter#1{%
8646   \ltj@setpar@global\setkeys[ltj]{japaram}{#1}\ignorespaces}
8647 \protected\def\ltjglobalsetparameter#1{%
8648   \relax\ifnum\globaldefs<0\directlua{luatexja.isglobal=''}%
8649     \else\directlua{luatexja.isglobal='global'}\fi%
8650   \setkeys[ltj]{japaram}{#1}\ignorespaces}
8651 \end{lstlisting}
8652 %<ja>\caption{パラメータ設定命令の定義}
8653 %<en>\caption{Definiton of parameter setting commands}
8654 \label{fig:setpar-def}
8655 \end{figure}
8656
8657 %<*en>
8658 \subsection{Extending Parameters}
8659 Keys for \cs{ltjsetparameter}~and~\cs{ltjgetparameter} can be extended,
8660 as in \Pkg{luatexja-adjust}.
8661 %</en>
8662 %<*ja>
8663 \subsection{パラメータの拡張}
8664 ここでは,\Pkg{luatexja-adjust}で行なっているように,
8665 \cs{ltjsetparameter},~\cs{ltjgetparameter}に指定可能なキーを追加する方法
8666 を述べる.
8667 %</ja>
8668
8669 %<*en>
8670 \paragraph{Setting parameters}
8671 \autoref{fig:setpar-def} shows the \emph{most outer} definition of
8672 two commands,
8673 \cs{ltjsetparameter} and \cs{ltjglobalsetparameter}.
8674 Most important part is the last \cs{setkeys},
8675 which is offered by the \Pkg{xkeyval} package.
8676
8677 Hence, to add a key in \cs{ltjsetparameter}, one only have to add a key
8678 whose prefix is \texttt{ltj} and whose family is \texttt{japaram}, as the following.
8679 \begin{lstlisting}
8680 \define@key[ltj]{japaram}{...}{...}
8681 \end{lstlisting}
8682
8683 \cs{ltjsetparameter}~and~\cs{ltjglobalsetparameter} automatically sets
8684 \texttt{luatexja.isglobal}. Its meaning is the following.
8685 \begin{align}
8686  \texttt{luatexja.isglobal} =
8687 \begin{cases}
8688  \texttt{'global'}&\text{global}\\
8689  \texttt{''}&\text{local}
8690 \end{cases}
8691 \end{align}
8692 This is determined not only by command name
8693 (\cs{ltjsetparameter}~or~\cs{ltjglobalsetparameter}),
8694 but also by the value of \cs{globaldefs}.
8695 %</en>
8696 %<*ja>
8697 \paragraph{パラメータの設定}
8698 \cs{ltjsetparameter} と,\cs{ltjglobalsetparameter} の定義は\autoref{fig:setpar-def}の
8699 のようになっている.
8700 本質的なのは最後の \cs{setkeys} で,これは\Pkg{xkeyval}パッケージの提供する命令である.
8701
8702 このため,\cs{ltjsetparameter} に指定可能なパラメータを追加するには,
8703 <prefix>を \texttt{ltj},<family>を \texttt{japaram} としたキーを
8704 \begin{lstlisting}
8705 \define@key[ltj]{japaram}{...}{...}
8706 \end{lstlisting}
8707 のように定義すれば良いだけである.
8708 なお,パラメータ指定がグローバルかローカルかどうかを示す \texttt{luatexja.isglobal} が,
8709 \begin{align}
8710  \texttt{luatexja.isglobal} =
8711 \begin{cases}
8712  \texttt{'global'}&\text{パラメータ設定はグローバル}\\
8713  \texttt{''}&\text{パラメータ設定はローカル}
8714 \end{cases}
8715 \end{align}
8716 として自動的にセットされる\footnote{命令が \cs{ltjglobalsetparameter} かどうかだけでは
8717 なく,実行時の \cs{globaldefs} の値にも依存して定まる.}.
8718 %</ja>
8719
8720 %<*en>
8721 \paragraph{Getting parameters}
8722 \cs{ltjgetparameter} is implemented by a Lua script.
8723
8724 For parameters that do not need additional arguments, one only have to
8725 define a function in the table \verb+luatexja.unary_pars+.
8726 For example, with the following function,
8727 \verb+\ltjgetparameter{hoge}+ returns a \emph{string} \texttt{42}.
8728 \begin{lstlisting}[numbers=left]
8729 function luatexja.unary_pars.hoge (t)
8730   return 42
8731 end
8732 \end{lstlisting}
8733 Here the argument of \verb+luatexja.unary_pars.hoge+ is
8734 the stack level of \LuaTeX-ja's stack system (see Subsection~\ref{ssec:stack}).
8735
8736 On the other hand, for parameters that need an additional argument
8737 (this must be an integer), one have to define a function in
8738 \verb+luatexja.binary_pars+ first. For example,
8739 \begin{lstlisting}[numbers=left]
8740 function luatexja.binary_pars.fuga (c, t)
8741   return tostring(c) .. ', ' .. tostring(42)
8742 end
8743 \end{lstlisting}
8744 Here the first argument $t$ is the stack level, as before.
8745 The second argument $c$ is just the second argument of \cs{ltjgetparameter}.
8746
8747 For parameters that need an additional argument, one also have to
8748 execute the \TeX\ code like
8749 \begin{lstlisting}
8750 \ltj@@decl@array@param{fuga}
8751 \end{lstlisting}
8752 to indicate that ``the parameter \texttt{fuga} needs an additional argument''.
8753 %</en>
8754 %<*ja>
8755 \paragraph{パラメータの取得}
8756 一方,\cs{ltjgetparameter} はLuaスクリプトによって実装されている.
8757 値を取得するのに追加引数の要らないパラメータについては,\verb+luatexja.unary_pars+\
8758 内に処理内容を記述した関数を定義すれば良い.例えば,Luaスクリプトで
8759 \begin{lstlisting}[numbers=left]
8760 function luatexja.unary_pars.hoge (t)
8761   return 42
8762 end
8763 \end{lstlisting}
8764 を実行すると,\verb+\ltjgetparameter{hoge}+ は \texttt{42} という\emph{文字列}を返す.
8765 関数 \verb+luatexja.unary_pars.hoge+ の引数$t$は,\ref{ssec:stack}節で述べた
8766 \LuaTeX-jaのスタックシステムにおけるスタックレベルである.
8767 戻り値はいかなる値であっても,最終的には文字列として出力されることに注意.
8768
8769 一方,追加引数(\emph{数値しか許容しない})が必要なパラメータについては,
8770 まずLuaスクリプトで処理内容の本体を記述しておく:
8771 \begin{lstlisting}[numbers=left]
8772 function luatexja.binary_pars.fuga (c, t)
8773   return tostring(c) .. ', ' .. tostring(42)
8774 end
8775 \end{lstlisting}
8776 引数$t$は,先に述べた通りのスタックレベルである.一方,引数$c$は\
8777 \cs{ltjgetparameter} の第2引数を表す数値である.
8778 しかしこれだけでは駄目で,
8779 \begin{lstlisting}
8780 \ltj@@decl@array@param{fuga}
8781 \end{lstlisting}
8782 を実行し,\TeX インターフェース側に
8783 「\verb+\ltjgetparameter{fuga}+ は追加引数が必要」ということを通知する必要がある.
8784 %</ja>
8785
8786 %<en>\section{Linebreak after a Japanese Character}
8787 %<ja>\section{和文文字直後の改行}
8788 \label{sec-lbreak}
8789 %<en>\subsection{Reference: behavior in \pTeX}
8790 %<ja>\subsection{参考:\pTeX の動作}
8791 %<*en>
8792 In~\pTeX, a line break after a Japanese character doesn't emit a space,
8793 since words are not separated by spaces in Japanese writings. However,
8794 this feature isn't fully implemented in \LuaTeX-ja due to the
8795 specification of callbacks in~\LuaTeX. To clarify the difference between
8796 \pTeX~and~\LuaTeX, We briefly describe the handling of a line break in~\pTeX, in
8797 this subsection.
8798
8799 \pTeX's input processor can be described in terms of a finite state
8800 automaton, as that of~\TeX\ in~Section~2.5 of~\cite{texbytopic}. The
8801 internal states are as follows:
8802 \begin{itemize}
8803 \item State~$N$: new line
8804 \item State~$S$: skipping spaces
8805 \item State~$M$: middle of line
8806 \item State~$K$: after a Japanese character
8807 \end{itemize}
8808 The first three states---$N$,~$S$, and~$M$---are as same as \TeX's input
8809 processor.  State~$K$ is similar to state~$M$, and is entered after
8810 Japanese characters.  The diagram of state transitions are indicated in
8811 \autoref{fig:ptexipro}.  Note that \pTeX\ doesn't leave state~$K$
8812 after ``beginning/ending of a group'' characters.
8813 %</en>
8814
8815 %<*ja>
8816 欧文では文章の改行は単語間でしか行わない.そのため,\TeX では,(文字の直後の)改行は
8817 空白文字と同じ扱いとして扱われる.一方,和文ではほとんどどこでも改行が可能なため,
8818 \pTeX では和文文字の直後の改行は単純に無視されるようになっている.
8819
8820 このような動作は,\pTeX が\TeX からエンジンとして拡張されたことによって可能になったことである.
8821 \pTeX の入力処理部は,\TeX におけるそれと同じように,有限オートマトンとして記述することができ,
8822 以下に述べるような4状態を持っている.
8823
8824 \begin{itemize}
8825 \item State~$N$: 行の開始.
8826 \item State~$S$: 空白読み飛ばし.
8827 \item State~$M$: 行中.
8828 \item State~$K$: 行中(和文文字の後).
8829 \end{itemize}
8830 また,状態遷移は,\autoref{fig:ptexipro}のようになっており,図中の数字は
8831 カテゴリーコードを表している.最初の3状態は\TeX の入力処理部と同じであり,
8832 図中から状態$K$と「$j$」と書かれた矢印を取り除けば,\TeX の入力処理部と同
8833 じものになる.
8834
8835 この図から分かることは,
8836 \begin{quote}
8837 行が和文文字(とグループ境界文字)で終わっていれば,改行は無視される
8838 \end{quote}
8839 ということである.
8840 %</ja>
8841
8842 \begin{figure}[!tb]
8843 \let\sp\textvisiblespace\small
8844 \begin{minipage}{.6\textwidth}%
8845 \begin{center}
8846 \unitlength=6.5mm\sf\mathversion{bold}
8847 \begin{tikzpicture}[
8848   ->, auto, shorten >=1pt
8849 ]
8850 \node [shape=rectangle, font=\scriptsize] (init) at (2,7) {start};
8851 \node [shape=circle,draw, fill=b_cyan] (newline) at (4,7) {$N$};
8852 \node [shape=circle,draw, fill=b_cyan] (midline) at (4,4) {$M$};
8853 \node [shape=circle,draw, fill=b_cyan] (skipspc) at (8,7) {$S$};
8854 \node [shape=circle,draw, fill=b_pink]  (kanji) at (8,4) {$K$};
8855 \node [shape=rectangle,draw, fill=b_green] (scanacs) at (6,8) {scan a c.s.};
8856 \node (endk) at (8,2.5) {} ;
8857 \node (endm) at (4,2.5) {} ;
8858 \node (ends) at (8,8.5) {} ;
8859 \node (endn) at (4,8.5) {} ;
8860 \begin{scope}[font=\scriptsize]
8861 \path (newline) edge [bend right]    node [left]{G, O} (midline)
8862       (init)    edge                 node {} (newline)
8863       (midline) edge [bend right=10] node {10} (skipspc)
8864       (skipspc) edge [bend right]    node [left,right=10,above=7]{G, O} (midline)
8865       (skipspc) edge [loop right]    node {10} (skipspc)
8866       (newline) edge [loop right]    node {10} (newline)
8867       (scanacs) edge [bend left]     node [left=3,below]{$(*)$} (skipspc)
8868       (scanacs) edge [bend right]    node [right=30,above=20]{$(*)$} (midline)
8869       (midline) edge                 node {5\ [\sp]} (endm)
8870       (midline) edge [loop left]     node {G, O} (midline)
8871       (skipspc) edge                 node [right] {5} (ends)
8872       (newline) edge                 node {5 [\cs{par}]} (endn);
8873 \begin{scope}[red]
8874 \path (newline) edge [bend right]    node [right=25,below=3]{J} (kanji)
8875       (midline) edge                 node [below]{J} (kanji)
8876       (kanji)   edge [bend left]     node {O} (midline)
8877       (kanji)   edge                 node {10} (skipspc)
8878       (kanji)   edge [loop right]    node {G, J} (kanji)
8879       (skipspc) edge [bend left]     node {J} (kanji)
8880       (kanji)   edge                 node {5} (endk)
8881 ;
8882 \end{scope}
8883 \end{scope}
8884 \end{tikzpicture}
8885 \end{center}
8886 \end{minipage}%
8887 \begin{minipage}{.4\textwidth}
8888 \begin{description}
8889 \item[\textsf{G}] Beginning of group (usually \verb+{+)\\
8890  and ending of group (usually \verb+}+).
8891 \item[\textsf{J}] Japanese characters.
8892 \item[\textsf{5}] \textit{end-of-line} (usually \verb+^+\verb+^J+).
8893 \item[\textsf{10}] space (usually \sp).
8894 \item[\textsf{O}] other characters, whose category code is in $\{3,4,6,7,8,11,12,13\}$.
8895 \item[\textsf{[\sp]}, \textsf{[\cs{par}]}]
8896 emits a space, or~\cs{par}.
8897 \end{description}
8898 \end{minipage}
8899 \begin{itemize}
8900 \item We omitted about category codes
8901 9~(\textit{ignored}), 14~(\textit{comment}), and~15~(\textit{invalid})
8902 from the above diagram. We also ignored the input like ``\verb+^+\verb+^A+'' or ``\verb+^+\verb+^df+''.
8903 \item When a character whose category code is 0 (\textit{escape character}) is seen by \TeX,
8904 the input processor scans a control sequence (\textsf{scan a c.s.}).
8905 These paths are not shown in the above diagram.
8906
8907 After that, the state is changed to State~$S$ (skipping blanks) in most cases, but
8908 to State~$M$ (middle of line) sometimes.
8909 \end{itemize}
8910 %<en>\caption{State transitions of \pTeX's input processor}
8911 %<ja>\caption{\pTeX の入力処理部の状態遷移}
8912 \label{fig:ptexipro}
8913 \end{figure}
8914
8915
8916 %<en>\subsection{Behavior in \LuaTeX-ja}
8917 %<ja>\subsection{\LuaTeX-jaの動作}
8918   \label{ssec:lineend}
8919 %<*en>
8920 States in the input processor of \LuaTeX\ is the same as that of \TeX,
8921 and they can't be customized by any callbacks. Hence, we can only use
8922 \verb+process_input_buffer+ and \verb+token_filter+ callbacks for to
8923 suppress a space by a line break which is after Japanese characters.
8924
8925 However, \verb+token_filter+ callback cannot be used either, since a
8926 character in category code 5~(\textit{end-of-line}) is converted into an space
8927 token \emph{in the input processor}.  So we can use only the
8928 \verb+process_input_buffer+ callback.  This means that suppressing a
8929 space must be done \emph{just before} an input line is read.
8930
8931 Considering these situations, handling of an end-of-line in \LuaTeX-ja are as follows:
8932 \begin{quote}
8933 A character whose character code is \cs{ltjlineendcomment}%
8934 \footnote{Its default value is \texttt{"FFFFF}, so  \texttt{U+FFFFF} is used.
8935 The category code of \texttt{U+FFFFF} is set to 14~(\textit{comment}) by
8936 \LuaTeX-ja.} is appended to an input line, \emph{before \LuaTeX\ actually
8937 process it}, if and only if the following three conditions are satisfied:
8938 \begin{enumerate}
8939 \item The category code of \cs{endlinechar}%
8940 \footnote{Usually, it is $\langle$\textit{return}$\rangle$
8941       (whose character code is 13).} is 5~(\textit{end-of-line}).
8942 \item The category code of \cs{ltjlineendcomment} itself is 14~(\textit{comment}).
8943 \item The input line matches the following ``regular expression'':
8944 \[
8945   (\text{any char})^*(\textbf{JAchar})
8946   \bigl(\{\text{catcode}=1\}\cup\{\text{catcode}=2\}\bigr)^*
8947 \]
8948 \end{enumerate}
8949 \end{quote}
8950
8951 \paragraph{Remark}
8952 The following example shows the major difference from the behavior of \pTeX.
8953 \begin{LTXexample}
8954 \fontspec[Ligatures=TeX]{Linux Libertine O}
8955 \ltjsetparameter{autoxspacing=false}
8956 \ltjsetparameter{jacharrange={-6}}xあ
8957 y\ltjsetparameter{jacharrange={+6}}zい
8958 u
8959 \end{LTXexample}
8960 It is not strange that ``あ'' does not printed in the above output.
8961 This is because \TeX\ Gyre\ Termes does not contain ``あ'', and because
8962 ``あ'' in line~3 is considered as an \textbf{ALchar}.
8963
8964 Note that there is no space before ``y'' in the output, but
8965 there is a space before ``u''. This follows from following reasons:
8966 \begin{itemize}
8967 \item When line~3 is processed by \texttt{process\_input\_buffer} callback,
8968 ``あ'' is considered as an \textbf{JAchar}.
8969 Since  line~3 ends with an \textbf{JAchar},
8970 the comment character (whose character code is \cs{ltjlineendcomment}) is appended to this line,
8971 and hence the linebreak immediately after this line is ignored.
8972 \item When line~4 is processed by \texttt{process\_input\_buffer} callback,
8973 ``い'' is considered as an \textbf{ALchar}.
8974 Since  line~4 ends with an \textbf{ALchar}, the linebreak immediately after this line
8975 emits a space.
8976 \end{itemize}
8977 %</en>
8978
8979 %<*ja>
8980 \LuaTeX の入力処理部は\TeX のそれと全く同じであり,コールバックによりユーザが
8981 カスタマイズすることはできない.このため,改行抑制の目的でユーザが利用で
8982 きそうなコールバックとしては,\verb+process_input_buffer+や
8983 \verb+token_filter+に限られてしまう.しかし,\TeX の入力処理部をよく見る
8984 と,後者も役には経たないことが分かる:改行文字は,入力処理部によってトー
8985 クン化される時に,カテゴリーコード10の32番文字へと置き換えられてしまうた
8986 め,\verb+token_filter+で非標準なトークン読み出しを行おうとしても,空白文
8987 字由来のトークンと,改行文字由来のトークンは区別できないのだ.
8988
8989 すると,我々のとれる道は,\verb+process_input_buffer+を用いて
8990 \LuaTeX の入力処理部に引き渡される前に入力文字列を編集するというものしかない.
8991 以上を踏まえ,\LuaTeX-jaにおける「和文文字直後の改行抑制」の処理は,次のようになっている:
8992
8993 \begin{quote}
8994 各入力行に対し,\emph{その入力行が読まれる前の内部状態で}
8995 以下の3条件が満たされている場合,\LuaTeX-jaは\cs{ltjlineendcomment}番の文字
8996 \footnote{\cs{ltjlineendcomment}の既定値は\texttt{"FFFFF}であるので,
8997   既定では\texttt{U+FFFFF}が使われることになる.この文字はコメント文字として扱われるように
8998   \LuaTeX-ja内部で設定をしている.}%
8999 を末尾に追加する.よって,その場合に改行は空白とは見做されないこととなる.
9000 \begin{enumerate}
9001 \item \cs{endlinechar}の文字\footnote{普通は,改行文字(文字コード13番)である.}
9002 のカテゴリーコードが5~(\textit{end-of-line})である.
9003 \item \cs{ltjlineendcomment}のカテゴリーコードが14~(\textit{comment})である.
9004 \item 入力行は次の「正規表現」にマッチしている:
9005 \[
9006   (\text{any char})^*(\textbf{JAchar})
9007   \bigl(\{\text{catcode}=1\}\cup\{\text{catcode}=2\}\bigr)^*
9008 \]
9009 \end{enumerate}
9010 \end{quote}
9011
9012 この仕様は,前節で述べた\pTeX の仕様にできるだけ近づけたものとなっている.条件1.は,
9013 \texttt{lstlisting}系環境などの日本語対応マクロを書かなくてすませるためのものである.
9014
9015 しかしながら,\pTeX と完全に同じ挙動が実現できたわけではない.
9016 次のように,\textbf{JAchar}の範囲を変更したちょうどその行においては挙動が異なる:
9017 \begin{LTXexample}
9018 \fontspec[Ligatures=TeX]{TeX Gyre Termes}
9019 \ltjsetparameter{autoxspacing=false}
9020 \ltjsetparameter{jacharrange={-6}}xあ
9021 y\ltjsetparameter{jacharrange={+6}}zい
9022 u
9023 \end{LTXexample}
9024 上ソース中の「あ」は\textbf{ALchar}(欧文扱い)であり.
9025 ここで使用している欧文フォント\TeX\ Gyre Termesは「あ」を含まない.
9026 よって,出力に「あ」は現れないことは不思議ではない.
9027 それでも,\pTeX とまったく同じ挙動を示すならば,出力は
9028 「\hbox{\ltjsetparameter{autoxspacing=false}x yzいu}」となるはずである.しかし,実際には
9029 上のように異なる挙動となっているが,それは以下の理由による:
9030 \begin{itemize}
9031 \item 3行目を \texttt{process\_input\_buffer} で処理する時点では,
9032       「あ」は\textbf{JAchar}(和文扱い)である.よって3行目は\textbf{JAchar}で終わることになり,
9033       \cs{ltjlineendcomment}番のコメント文字が追加される.
9034       よって,直後の改行文字は無視されることになり,空白は入らない.
9035 \item 4行目を \texttt{process\_input\_buffer} で処理する時点では,
9036       「い」は\textbf{ALchar}である.よって4行目は\textbf{ALchar}で終わることになり,
9037       直後の改行文字は空白に置き換わる.
9038 \end{itemize}
9039 このため,トラブルを避けるために,\textbf{JAchar}の範囲を\cs{ltjsetparameter}で編集した場合,
9040 その行はそこで改行するようにした方がいいだろう.
9041 %</ja>
9042
9043 %<*ja>
9044
9045 %<en>\section{Insertion of JFM glues, \Param{kanjiskip} and \Param{xkanjiskip}}
9046 %<ja>\section{JFMグルーの挿入,\Param{kanjiskip}と\Param{xkanjiskip}}
9047 \label{sec-jfmglue}
9048 %<en>\subsection{Overview}
9049 %<ja>\subsection{概要}
9050
9051 \LuaTeX-jaにおける \textbf{JAglue} の挿入方法は,\pTeX のそれとは全く異なる.
9052 \pTeX では次のような仕様であった:
9053 \begin{itemize}
9054 \item JFMグルーの挿入は,和文文字を表すトークンを元に水平リストに(文字を表す)<char\_node>を
9055 追加する過程で行われる.
9056 \item \Param{xkanjiskip}の挿入は,hboxへのパッケージングや行分割前に行われる.
9057 \item \Param{kanjiskip}はノードとしては挿入されない.パッケージングや行分割の計算時に
9058 「和文文字を表す2つの<char\_node>の間には\Param{kanjiskip}がある」ものとみなされる.
9059 \end{itemize}
9060 しかし,\LuaTeX-jaでは,hboxへのパッケージングや行分割前に全ての
9061 \textbf{JAglue},即ちJFMグルー・\Param{xkanjiskip}・\Param{kanjiskip}の
9062 3種類を一度に挿入することになっている.これは,\LuaTeX において欧文の合字・
9063 カーニング処理がノードベースになったことに対応する変更である.
9064
9065 \LuaTeX-jaにおける\textbf{JAglue}挿入処理では,次節で定義する
9066 「クラスタ」を単位にして行われる.大雑把にいうと,「クラスタ」は文字とそれに付随す
9067 るノード達(アクセント位置補正用のカーンや,イタリック補正)をまとめたもの
9068 であり,2つのクラスタの間には,ペナルティ,\cs{vadjust},whatsitなど,行組版
9069 には関係しないものがある.
9070
9071
9072 %<en>\subsection{Definition of a Cluster}
9073 %<ja>\subsection{「クラスタ」の定義}
9074
9075 \def\OA{$\text{\sf O}_{\text{\sf A}}$}
9076 \def\OB{$\text{\sf O}_{\text{\sf B}}$}
9077 \def\NA{$\text{\sf N}_{\text{\sf A}}$}
9078 \def\NB{$\text{\sf N}_{\text{\sf B}}$}
9079 \begin{defn}
9080 %<*en>
9081 A \emph{cluster} is consecutive nodes in one of the following forms,
9082 with the \textit{id} of it:
9083 %</en>
9084 %<*ja>
9085 \emph{クラスタ}は以下の形のうちのどれかひとつをとるノードのリストである:
9086 %</ja>
9087 \begin{enumerate}
9088 %<*en>
9089 \item Nodes whose value of\ \verb+\ltj@icflag+ is in $[3,15)$.  These
9090       nodes come from a hbox which is already packaged, by unpackaging
9091       (\cs{unhbox}).
9092       The \textit{id} of the cluster is \textit{id\_pbox}.
9093 %</en>
9094 %<*ja>
9095 \item その \verb+\ltj@icflag+ の値が$[3,15)$に入るノードのリスト.
9096   これらのノードはある既にパッケージングされたhboxから \cs{unhbox} で
9097   アンパックされたものである.
9098   この場合,クラスタの\textit{id}は\textit{id\_pbox}である.
9099 %</ja>
9100
9101 %<*en>
9102 \item A inline math formula, including two \textit{math\_node}s at the boundary of it.
9103       The \textit{id} of the cluster is \textit{id\_math}.
9104 %</en>
9105 %<*ja>
9106 \item インライン数式でその境界に2つの\textit{math\_node}を含むもの.
9107   この場合,クラスタの\textit{id}は\textit{id\_math}である.
9108 %</ja>
9109
9110 %<*en>
9111 \item A \textit{glyph\_node}~$p$, which represents a \textbf{JAchar}, with nodes which relate with it:
9112 %</en>
9113 %<*ja>
9114 \item \textbf{JAchar}を表す\textit{glyph\_node}~$p$とそれに関係するノード:
9115 %</ja>
9116 \begin{enumerate}
9117 %<*en>
9118 \item[(a)] A kern for the italic correction of~$p$.
9119 %</en>
9120 %<*ja>
9121 \item[(a)] $p$のイタリック補正のためのカーン.
9122 %</ja>
9123
9124 %<*en>
9125 \item[(b)] An accent attached to $p$ by \cs{accent}.
9126 %</en>
9127 %<*ja>
9128 \item[(b)] \cs{accent} による$p$に付随したアクセント.
9129 %</ja>
9130 \end{enumerate}
9131 \[
9132 \overbrace{%
9133  \Node{kern}{$\mathit{subtype}=2$}\longrightarrow
9134 \left\{\begin{array}{c}
9135 \Node{glyph}{accent}\\\noalign{\medskip}
9136 \Node{hbox}{accent (shifted vert.)}
9137 \end{array}\right\}\longrightarrow
9138 \Node{kern}{$\mathit{subtype}=2$}}^{\text{(b)}}
9139 \longrightarrow
9140 \Node{glyph}{$p$}\longrightarrow
9141 \overbrace{%
9142 \Node{kern}{italic corr.}}^{\text{(a)}}
9143 \]
9144
9145 %<*en>
9146 In this case, the \textit{id} is \textit{id\_jglyph}.
9147 %</en>
9148 %<*ja>
9149 この場合の\textit{id}は\textit{id\_jglyph}である.
9150 %</ja>
9151
9152 %<*en>
9153 \item A list which begins from a \textit{glyph\_node} which represents a \textbf{ALchar},
9154       and consists of \textbf{ALchar} \textit{glyph\_node}s,
9155       kerns for adjusting accents~(its subtype is 2), kerns for italic corrections and
9156       kerns which are automatically inserted by \LuaTeX~or~luaotfload.
9157       In this case, the \textit{id} is \textit{id\_glyph}.
9158 %</en>
9159 %<*ja>
9160 \item \textbf{ALchar}を表す\textit{glyph\_node},\cs{accent} によるアクセント位置補正用の
9161       カーン(subtypeが2),そしてイタリック補正・カーニングによって挿入されたカーン達が連続
9162       したもの.この場合の\textit{id}は\textit{id\_glyph}である.
9163 %</ja>
9164
9165 %<*en>
9166 \item An box-like node, that is, an hbox, a vbox, a rule (\cs{vrule}) and an \textit{unset\_node}.
9167 The \textit{id} of the cluster is \textit{id\_hlist} if the node is an
9168       hbox which is not shifted vertically, or \textit{id\_box\_like}
9169       otherwise.
9170 %</en>
9171 %<*ja>
9172 \item 水平ボックス(hbox),垂直ボックス,罫線 (\cs{vrule}),
9173   そして\textit{unset\_node}.
9174   クラスタの\textit{id}は垂直に移動していないhboxならば\textit{id\_hlist},
9175   そうでなければ\textit{id\_box\_like}となる.
9176 %</ja>
9177
9178 %<*en>
9179 \item A glue, a kern whose subtype is not 2~(\textit{accent}), and a discretionary break.
9180 The \textit{id} of the cluster is \textit{id\_glue}, \textit{id\_kern}
9181       and \textit{id\_disc}, respectively.
9182 %</en>
9183 %<*ja>
9184 \item グルー,subtypeが 2~(\textit{accent})ではないカーン,そしてdiscretionary break.
9185   その\textit{id} of the clusterはそれぞれ\textit{id\_glue}, \textit{id\_kern},そして
9186   \textit{id\_disc}である.
9187 %</ja>
9188 \end{enumerate}
9189 %<*en>
9190 We use \textit{Np}, \textit{Nq} and \textit{Nr} to denote a cluster.
9191 %</en>
9192 %<*ja>
9193 以下では\textit{Np}, \textit{Nq}, \textit{Nr}でクラスタを表す.
9194 %</ja>
9195 \end{defn}
9196
9197 \paragraph{\textit{id}の意味}
9198 $\mathit{Np}.\mathit{id}$の意味を述べるとともに,
9199 「先頭の文字」を表す\textit{glyph\_node}~$\mathit{Np}.\mathit{head}$と,
9200 「最後の文字」を表す\textit{glyph\_node}~$\mathit{Np}.\mathit{tail}$を次のように定義する.
9201 直感的に言うと,\textit{Np}は$\mathit{Np}.\mathit{head}$で始まり$\mathit{Np}.\mathit{tail}$で終わるような単語,
9202 と見做すことができる.これら$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$は
9203 説明用に準備した概念であって,実際のLuaコード中にそのように書かれているわけではないことに注意.
9204
9205 \begin{description}
9206 \item[\textit{id\_jglyph}] \textbf{JAchar}(和文文字).\\
9207 $\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$は,その\textbf{JAchar}を表している
9208 \textit{glyph\_node}そのものである.
9209 \item[\textit{id\_glyph}] \textbf{JAchar}(和文文字)以外のものを表す\textit{glyph\_node}~$p$.\\
9210 多くの場合,$p$は\textbf{ALchar}(欧文文字)を格納しているが,「ffi」などの合字によって作られた
9211 \textit{glyph\_node}である可能性もある.
9212 前者の場合,$\mathit{Np}.\mathit{head}$,~$\mathit{Np}.\mathit{tail} = p$である.
9213 一方,後者の場合,
9214 \begin{itemize}
9215 \item $\mathit{Np}.\mathit{head}$は,
9216 合字の構成要素の先頭→(その\textit{glyph\_node}における)合字の構成要素の先頭→……
9217 と再帰的に検索していってたどり着いた\textit{glyph\_node}である.
9218 \item $\mathit{Np}.\mathit{last}$は,同様に末尾→末尾→と検索してたどり着いた\textit{glyph\_node}である.
9219 \end{itemize}
9220 \item[\textit{id\_math}] インライン数式.\\
9221 便宜的に,$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$ともに
9222 「文字コード$-1$の欧文文字」とおく.
9223 \item[\textit{id\_hlist}] 縦方向にシフトされていないhbox.\\
9224 この場合,$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$はそれぞれ$p$の内容を表すリストの,
9225 先頭・末尾のノードである.
9226 \medskip
9227 \begin{itemize}
9228 \item 状況によっては,\TeX ソースで言うと
9229 \begin{lstlisting}
9230 \hbox{\hbox{abc}...\hbox{\lower1pt\hbox{xyz}}}
9231 \end{lstlisting}
9232 のように,$p$の内容が別のhboxで開始・終了している可能性も十分あり得る.そのような場合,
9233 $\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$の算出は,
9234 \emph{垂直方向にシフトされていない}hboxの
9235 場合だけ内部を再帰的に探索する.例えば上の例では,$\mathit{Np}.\mathit{head}$は文字「a」を表すノードであり,
9236 一方$\mathit{Np}.\mathit{tail}$は垂直方向にシフトされたhbox,
9237 \verb+\lower1pt\hbox{xyz}+ に対応するノードである.
9238 \item また,先頭にアクセント付きの文字がきたり,末尾にイタリック補正用のカーンが
9239 来ることもあり得る.この場合は,クラスタの定義のところにもあったように,それらは無視して算出を行う.
9240 \item 最初・最後のノードが合字によって作られた\textit{glyph\_node}のときは,それぞれに対して\textit{id\_glyph}%
9241 と同様に再帰的に構成要素をたどっていく.
9242 \end{itemize}
9243 \item[\textit{id\_pbox}] 「既に処理された」ノードのリストであり,これらのノードが二度処理を受けないために
9244 まとめて1つのクラスタとして取り扱うだけである.
9245 \textit{id\_hlist}と同じ方法で$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$を算出する,
9246 \item[\textit{id\_disc}] discretionary break (\verb+\discretionary{pre}{post}{nobreak}+).\\
9247 \textit{id\_hlist}と同じ方法で$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$を算出するが,
9248 第3引数の \texttt{nobreak}(行分割が行われない時の内容)を使う.言い換えれば,ここで行分割が発生した時の状況は
9249 全く考慮に入れない.
9250 \item[\textit{id\_box\_like}] \textit{id\_hlist}とならないboxや,rule.\\
9251 この場合は,$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$のデータは利用されないので,2つの算出は無意味である.
9252 敢えて明示するならば,$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$は共にnil値である.
9253 \item[他] 以上にない\textit{id}に対しても,$\mathit{Np}.\mathit{head}$, $\mathit{Np}.\mathit{tail}$の算出は無意味.
9254 \end{description}
9255
9256 \paragraph{クラスタの別の分類}
9257 さらに,JFMグルー挿入処理の実際の説明により便利なように,\textit{id}とは別のクラスタの分類を行っておく.
9258 挿入処理では2つの隣り合ったクラスタの間に
9259 空白等の実際の挿入を行うことは前に書いたが,ここでの説明では,問題にしているクラスタ\textit{Np}は「後ろ側」のクラスタである
9260 とする.「前側」のクラスタについては,以下の説明で\textit{head}が\textit{last}に置き換わることに注意すること.
9261 \begin{description}
9262 \item[和文A] リスト中に直接出現している\textbf{JAchar}.
9263 \textit{id}が\textit{id\_jglyph}であるか,\\
9264 \textit{id}が\textit{id\_pbox}であって$\mathit{Np}.\mathit{head}$が\textbf{JAchar}であるとき.
9265
9266 \item[和文B] リスト中のhboxの中身の先頭として出現した\textbf{JAchar}.和文Aとの違いは,これの前に
9267 JFMグルーの挿入が行われない(\Param{xkanjiskip},~\Param{kanjiskip}は入り得る)ことである.\\
9268 \textit{id}が\textit{id\_hlist}か\textit{id\_disc}であって$\mathit{Np}.\mathit{head}$が\textbf{JAchar}であるとき.
9269
9270 \item[欧文] リスト中に直接/hboxの中身として出現している「\textbf{JAchar}以外の文字」.次の3つの場合が該当:
9271 \begin{itemize}
9272 \item \textit{id}が\textit{id\_glyph}である.
9273 \item \textit{id}が\textit{id\_math}である(つまりこのクラスタは1つの文中数式をなす).
9274 \item \textit{id}が\textit{id\_pbox}か\textit{id\_hlist}か\textit{id\_disc}であって,$\mathit{Np}.\mathit{head}$が\textbf{ALchar}.
9275 \end{itemize}
9276 \item[箱] box,またはそれに類似するもの.次の2つが該当:
9277 \begin{itemize}
9278 \item \textit{id}が\textit{id\_pbox}か\textit{id\_hlist}か\textit{id\_disc}であって,$\mathit{Np}.\mathit{head}$が\textit{glyph\_node}でない.
9279 \item \textit{id}が\textit{id\_box\_like}である.
9280 \end{itemize}
9281
9282 \end{description}
9283
9284 \subsection{段落/hboxの先頭や末尾}
9285 \paragraph{先頭部の処理}
9286 まず,段落/hboxの一番最初にあるクラスタ\textit{Np}を探索する.
9287 hboxの場合は何の問題もないが,段落の場合では以下のノード達を事前に読み飛ばしておく:
9288 \begin{itemize}
9289 \item \cs{parindent} 由来のhbox($\mathit{subtype}=3$)
9290 \item \textit{subtype}が44~(\textit{user\_defined})でないようなwhatsit
9291 \end{itemize}
9292 これは,\cs{parindent}由来のhboxがクラスタを構成しないようにするためである.
9293
9294 次に,\textit{Np}の直前に空白$g$を必要なら挿入する:
9295 \begin{enumerate}
9296 \item この処理が働くような\textit{Np}は\textsf{和文A}である.
9297 \item 問題のリストが字下げありの段落(\cs{parindent} 由来のhboxあり)の場合は,
9298 この空白$g$は「文字コード \texttt{'parbdd'} の文字」と\textit{Np}の間に入るグルー/カーンである.
9299 \item そうでないとき(\verb+noindent+ で開始された段落やhbox)は,
9300 $g$は「文字コード \texttt{'boxbdd'} の文字」と\textit{Np}の間に入るグルー/カーンである.
9301 \end{enumerate}
9302 ただし,もし$g$がglueであった場合,この挿入によって\textit{Np}による行分割が新たに可能になるべきではない.
9303 そこで,以下の場合には,$g$の直前に \cs{penalty10000} を挿入する:
9304 \begin{itemize}
9305 \item 問題にしているリストが段落であり,かつ
9306 \item \textit{Np}の前には予めペナルティがなく,$g$はglue.
9307 \end{itemize}
9308
9309 \paragraph{末尾の処理}
9310 末尾の処理は,問題のリストが段落のものかhboxのものかによって異なる.
9311 後者の場合は容易い:最後のクラスタを\textit{Nq}とおくと,\textit{Nq}と「文字コード\
9312 \texttt{'boxbdd'} の文字」の間に入るグルー/カーンを,
9313 \textit{Nq}の直後に挿入するのみである.
9314
9315 一方.前者(段落)の場合は,リストの末尾は常に \cs{penalty10000} と,
9316 \cs{parfillskip} 由来のグルーが存在する.%よって,最後のクラスタ\textit{Np}は
9317 %この \cs{parfillskip} 由来のグルーとなり,実質的な中身の最後はその1つ前のクラスタ\textit{Nq}となる.
9318 段落の最後の「通常の\textbf{JAchar}${}+{}$句点」が独立した行となるのを防ぐために,
9319 \Param{jcharwidowpenalty}の値の分だけ適切な場所のペナルティを増やす.
9320
9321 ペナルティ量を増やす場所は,\textit{head}が\textbf{JAchar}であり,
9322 かつその文字の\Param{kcatcode}が偶数であるような
9323 最後のクラスタの直前にあるものたちである%
9324 \footnote{大雑把に言えば,\Param{kcatcode}が奇数であるような\textbf{JAchar}%
9325 を約物として考えていることになる.
9326 \Param{kcatcode}の最下位ビットはこの\Param{jcharwidowpenalty}用にのみ利用される.}.
9327
9328 \subsection{概観と典型例:2つの「和文A」の場合}
9329 \label{ssec:cluster-wa}
9330 先に述べたように,2つの隣り合ったクラスタ,\textit{Nq}と\textit{Np}の間には,
9331 ペナルティ,\cs{vadjust},whatsitなど,行組版には関係しないものがある.模式的に表すと,
9332 \[
9333  \Node{cluster}{\textit{Nq}}\longrightarrow
9334 \overbrace{
9335 \Node{penalty}{$p$}\longrightarrow \cdots\longrightarrow \Node{whatsit}{}}^{\textrm{(a)}}
9336 \longrightarrow \Node{cluster}{\textit{Np}}
9337 \]
9338 のようになっている.間の(a)に相当する部分には,何のノードもない場合ももちろんあり得る.
9339 そうして,JFMグルー挿入後には,この2クラスタ間は次のようになる:
9340 \[
9341  \Node{cluster}{\textit{Nq}}\longrightarrow%\Node{kern}{左空白}\longrightarrow
9342 \overbrace{
9343 \Node{penalty}{$p+x$}\longrightarrow \cdots\longrightarrow
9344 \Node{whatsit}{}}^{\textrm{(a)}}\longrightarrow
9345 \Node{glue or kern}{\raisebox{-.2\zw}{右空白}}\longrightarrow
9346 \Node{cluster}{\textit{Np}}
9347 \]
9348
9349 以後,\emph{典型的な例として,クラスタ\textit{Nq}と\textit{Np}が共に\textsf{\textmd{和文A}}である場合を見ていこう,}
9350 この場合が全ての場合の基本となる.
9351
9352 \paragraph{「右空白」の算出}
9353 まず,「右空白」にあたる量を算出する.通常はこれが,隣り合った2つの\textbf{JAchar}間に入る空白量となる.
9354 \begin{description}
9355 \item[JFM由来{[M]}] JFMの文字クラス指定によって入る空白を以下によって求める.この段階で空白量が未定義(未指定)だった場合,
9356       デフォルト値\Param{kanjiskip}を採用することとなるので,次へ.
9357 \begin{enumerate}
9358 \item もし両クラスタの間で \cs{inhibitglue} が実行されていた場合(証としてwhatsitノードが自動挿入される),
9359       代わりに\Param{kanjiskip}が挿入されることとなる.次へ.
9360 \item \textit{Nq}と\textit{Np}が同じJFM・同じ\texttt{jfmvar}キー・同じサイズの和文フォントであったならば,
9361       共通に使っているJFM内で挿入される空白(グルーかカーン)が決まっているか調べ,決まっていればそれを採用.
9362 \item 1.でも2.でもない場合は,JFM・\texttt{jfmvar}・サイズの3つ組は\textit{Nq}と\textit{Np}で異なる.
9363 この場合,まず
9364 \[
9365 \vcenter{\halign{\hfil$#:={}$&\inhibitglue#\inhibitglue\cr
9366 gb&(\textit{Nq}と「使用フォントが\textit{Nq}のそれと同じで,\hfil\cr
9367 \omit&\quad 文字コードが\textit{Np}のそれの文字」との間に入るグルー/カーン)\hfil\cr
9368 ga&(\inhibitglue 「使用フォントが\textit{Np}のそれと同じで,\hfil\cr
9369 \omit&\quad 文字コードが\textit{Nq}のそれの文字」と\textit{Np}との間に入るグルー/カーン)\hfil\cr
9370 }}
9371 \]
9372 として,前側の文字のJFMを使った時の空白(グルー/カーン)と,後側の文字のJFMを使った時のそれを求める.
9373
9374 $\mathit{gb}$,~$\mathit{ga}$それぞれに対する<ratio>の値を$d_b$,~$d_a$とする.
9375 \begin{itemize}
9376 \item
9377 $\mathit{ga}$と$\mathit{gb}$の両方が未定義であるならば,JFM由来のグルーは挿入されず,
9378 \Param{kanjiskip}を採用することとなる.
9379 どちらか片方のみが未定義であるならば,次のステップでその未定義の方は長さ0のkernで,<ratio>の値は0であるかのように扱われる.
9380 \item
9381 \Param{diffrentjfm}の値が \texttt{pleft}, \texttt{pright},
9382       \texttt{paverage} のとき,
9383 <ratio>の指定に従って比例配分を行う.
9384 JFM由来のグルー/カーンは以下の値となる:
9385 \[
9386  f\left(\frac{1-d_b}2\textit{gb} + \frac{1+d_b}2\textit{ga},
9387 \frac{1-d_a}2\textit{gb} + \frac{1+d_a}2\textit{ga}\right)
9388 \]
9389 ここで.$f(x,y)$は
9390 \[
9391  f(x,y)=\begin{cases}
9392 x&\text{if\ }\Param{diffrentjfm}=\texttt{pleft};\\
9393 y&\text{if\ }\Param{diffrentjfm}=\texttt{pright};\\
9394 (x+y)/2&\text{if\ }\Param{diffrentjfm}=\texttt{paverage};
9395 \end{cases}.
9396 \]
9397 \item
9398 \Param{differentjfm}がそれ以外の値の時は,<ratio>の値は無視され,JFM由来のグルー/カーンは以下の値となる:
9399 \[
9400  f(\textit{gb},\textit{ga})
9401 \]
9402 ここで.$f(x,y)$は
9403 \[
9404  f(x,y)=\begin{cases}
9405 \min(x,y)&\text{if\ }\Param{diffrentjfm}=\texttt{small};\\
9406 \max(x,y)&\text{if\ }\Param{diffrentjfm}=\texttt{large};\\
9407 (x+y)/2&\text{if\ }\Param{diffrentjfm}=\texttt{average};\\
9408 x+y&\text{if\ }\Param{diffrentjfm}=\texttt{both};
9409 \end{cases}.
9410 \]
9411 \end{itemize}
9412 \end{enumerate}
9413
9414 例えば,
9415 \begin{lstlisting}
9416 \jfont\foo=psft:Ryumin-Light:jfm=ujis;-kern
9417 \jfont\bar=psft:GothicBBB-Medium:jfm=ujis;-kern
9418 \jfont\baz=psft:GothicBBB-Medium:jfm=ujis;jfmvar=piyo;-kern
9419 \end{lstlisting}
9420 という3フォントを考え,
9421 \[
9422  \overbrace{\Node{glyph}{\cs{ foo}, `あ'}}^{p}
9423 \longrightarrow \overbrace{\Node{glyph}{\cs{bar}, `い'}}^{q}
9424 \longrightarrow \overbrace{\Node{glyph}{\cs{baz}, `う'}}^{r}
9425 \]
9426 という3ノードを考える(それぞれ単独でクラスタをなす).
9427 この場合,$p$と$q$の間は,実フォントが異なるにもかかわらず2.の状況となる一方で,
9428 $q$と$r$の間は(実フォントが同じなのに)\texttt{jfmvar} キーの内容が異なるので3.の状況となる.
9429 \item[\Param{kanjiskip}~{[K]}] 上の[M]において空白が定まらなかった場合,
9430 以下で定めた量「右空白」として採用する.
9431 この段階においては,\cs{inhibitglue} は効力を持たないため,
9432 結果として,2つの\textbf{JAchar}間には常に何らかのグルー/カーンが挿入されることとなる.
9433 \begin{enumerate}
9434 \item 両クラスタ(厳密には$\mathit{Nq}.\mathit{tail}$,$\mathit{Np}.\mathit{head}$)の中身の文字コードに対する
9435 \Param{autospacing}パラメタが両方ともfalseだった場合は,長さ0のglueとする.
9436 \item ユーザ側から見た\Param{kanjiskip}パラメタの自然長が$\cs{maxdimen}=(2^{30}-1)\,{\rm sp}$で
9437 なければ,\Param{kanjiskip}パラメタの値を持つglueを採用する.
9438 \item 2.でない場合は,\textit{Nq}, \textit{Np}で使われているJFMに指定されている\Param{kanjiskip}の値を用いる.
9439 どちらか片方のクラスタだけが\textbf{JAchar}(\textsf{和文A}・\textsf{和文B})のときは,そちらのクラスタで使われている
9440 JFM由来の値だけを用いる.もし両者で使われているJFMが異なった場合は,上の[M]~3.と同様の方法を用いて調整する.
9441 \end{enumerate}
9442 \end{description}
9443 %\paragraph{「左空白」の算出とそれに伴う補正}
9444 %「左空白」は過去のバージョンでは定義していたが,このバージョンでは
9445 %挿入は一切行われない(機能自体削除している).
9446 %しかし,仕様は流動的であり,将来復活する可能性もあるため,マニュアル中の記述は今のところ極力変更しない.
9447 \paragraph{禁則用ペナルティの挿入}
9448 まず,
9449 \[
9450  a:=(\text{\textit{Nq}{\footnotemark}の文字に対する\Param{postbreakpenalty}の値})
9451 +(\text{\textit{Np}{\footnotemark}の文字に対する\Param{prebreakpenalty}の値})
9452 \]
9453 とおく\footnotetext{厳密にはそれぞれ$\mathit{Nq}.\mathit{tail}$,$\mathit{Np}.\mathit{head}$.}.
9454 ペナルティは通常$[-10000,10000]$の整数値をとり,また$\pm 10000$は正負の無限大を意味することになっているが,この$a$の
9455 算出では単純な整数の加減算を行う.
9456
9457 $a$は禁則処理用に\textit{Nq}と\textit{Np}の間に加えられるべきペナルティ量である.
9458 \begin{description}
9459 \item[P-normal~{[PN]}]
9460 \textit{Nq}と\textit{Np}の間の(a)部分にペナルティ(\textit{penalty\_node})があれば処理は簡単である:
9461 それらの各ノードにおいて,ペナルティ値を($\pm 10000$を無限大として扱いつつ)$a$だけ増加させればよい.
9462 また,$10000 + (-10000) = 0$としている.
9463
9464 少々困るのは,(a)部分にペナルティが存在していない場合である.
9465 直感的に,補正すべき量$a$が0でないとき,その値をもつ\textit{penalty\_node}を作って
9466 「右空白」の(もし未定義なら\textit{Np}の)直前に挿入……
9467 ということになるが,実際には僅かにこれより複雑である.
9468 \begin{itemize}
9469 \item 「右空白」がカーンであるとき,
9470 それは「\textit{Nq}と\textit{Np}の間で改行は許されない」ことを意図している.そのため,
9471 この場合は$a\neq 0$であってもペナルティの挿入はしない.
9472 \item そうでないないときは,$a\neq 0$ならば\textit{penalty\_node}を作って挿入する.
9473 %\item 「左空白」がカーンとしてきっちり定義されている時(このとき,「右空白」はカーンでない),
9474 %この「左空白」の直後での行分割を許容しないといけないので,$a=0$であっても
9475 %\textit{penalty\_node}を作って挿入する.
9476 %\item 以上のどれでもないときは,$a\neq 0$ならば\textit{penalty\_node}を作って挿入する.
9477 \end{itemize}
9478 \end{description}
9479
9480 \def\gkf#1#2#3{\sf$\displaystyle\vphantom{\Bigg(}%
9481   \frac{\hbox to 4\zw{\hss#2\hss}}{\hbox{#3}}$}
9482 \begin{table}[t]
9483 %<en>\caption{Summary of JFM glues}
9484 %<ja>\caption{JFM グルーの概要}
9485 \label{tab-jfmglue}
9486 %<en>\medskip
9487 \begin{center}
9488 \small
9489 \begin{tabular}{c|cccccc}
9490 \toprule
9491 {\bf\textit{Np}}↓&\sf 和文A&\sf 和文B&\sf 欧文&\sf 箱&\sf glue&\sf kern\\\midrule
9492 \sf 和文A&
9493 \gkf{E}{M→K}{PN}&
9494 \gkf{---}{\OA →K}{PN}&
9495 \gkf{---}{\NA →X}{PN}&
9496 \gkf{---}{\OA}{PA}&
9497 \gkf{---}{\OA}{PN}&
9498 \gkf{---}{\OA}{PS}\\
9499 \sf 和文B&
9500 \gkf{E}{\OB→K}{PA}&
9501 \gkf{---}{K}{PS}&
9502 \gkf{---}{X}{PS}\\
9503 \sf 欧文&
9504 \gkf{E}{\NB →X}{PA}&
9505 \gkf{---}{X}{PS}\cr
9506 \sf 箱&\gkf{E}{\OB}{PA}\\
9507 \sf glue&\gkf{E}{\OB}{PN}\\
9508 \sf kern&\gkf{E}{\OB}{PS}\\
9509 \bottomrule
9510 \end{tabular}
9511 \end{center}
9512 \begin{quote}
9513 %<*en>
9514 In the table above, {\small\gkf{E}{M→K}{PN}} means that
9515 %</en>
9516 %<*ja>
9517 上の表において,{\small\gkf{E}{M→K}{PN}}は次の意味である:
9518 %</ja>
9519 \begin{enumerate}
9520 %<*en>
9521 \item To determine the ``right-space'', \LuaTeX-ja first attempts by the method ``\textsf{JFM-origin~[M]}''.
9522 If this attempt fails, \LuaTeX-ja use the method ``\textsf{\Param{kanjiskip}~[K]}''.
9523 %</en>
9524 %<*ja>
9525 \item 「右空白」を決めるために,\LuaTeX-ja はまず「JFM由来{[M]}」の方法を試みる.
9526   これが失敗したら,\LuaTeX-ja は「\Param{kanjiskip}~{[K]}」の方法を試みる.
9527 %</ja>
9528
9529 % %<*en>
9530 % \item The ``left space'' between \textit{Nq}~and~\textit{Np} is
9531 %   determined by the method ``\textsf{line-end~[E]}''.
9532 % %</en>
9533 % %<*ja>
9534 % \item \textit{Nq} と \textit{Np} の間の「左空白」は「\textsf{line-end~[E]}」の
9535 %   方法で決定される.
9536 % %</ja>
9537
9538 %<*en>
9539 \item \LuaTeX-ja adopts the method ``\textsf{P-normal~[PN]}'' to adjust the penalty
9540   between two clusters for \emph{kinsoku shori}.
9541 %</en>
9542 %<*ja>
9543 \item \LuaTeX-jaは2つのクラスタの間の禁則処理用のペナルティを設定するために「\textsf{P-normal~[PN]}」の方法を採用する.
9544 %</ja>
9545 \end{enumerate}
9546 \end{quote}
9547 \end{table}
9548
9549 \subsection{その他の場合}
9550 本節の内容は\autoref{tab-jfmglue}にまとめてある.
9551
9552 \paragraph{和文Aと欧文の間}
9553 \textit{Nq}が\textsf{和文A}で,\textit{Np}が\textsf{欧文}の場合,JFMグルー挿入処理は次のようにして行われる.
9554 \begin{itemize}
9555 \item 「右空白」については,まず以下に述べる\textsf{欧文境界B~[\NB]}により空白を決定しようと試みる.
9556 それが失敗した場合は,\textsf{\Param{xkanjiskip}~[X]}によって定める.
9557 %\item 「左空白」については,既に述べた\textsf{line-end~[E]}をそのまま採用する.それに伴う「右空白」の補正も%同じ.
9558 \item 禁則用ペナルティも,以前述べた\textsf{P-normal~[PN]}と同じである.
9559 \end{itemize}
9560 \begin{description}
9561 \item[欧文境界B~{[\NB]}] 以下で求めた量を「右空白」として採用する.
9562 この処理は\textsf{JFM-origin~[M]}の変種と考えて良く,
9563 典型例は「和文の閉じ括弧と欧文文字の間に入る半角アキ」である.
9564 \begin{enumerate}
9565 \item もし両クラスタの間で \cs{inhibitglue} が実行されていた場合%
9566 (証としてwhatsitノードが自動挿入される),未定義.
9567 \item そうでなければ,
9568 \textit{Nq}と「文字コードが$x$の文字」との間に入るグルー/カーンとする.
9569 この$x$は次の場合分けによる:
9570   \begin{itemize}
9571     \item $\mathit{Np}.\mathit{id}$が\textit{id\_math}のとき(つまりクラスタ\textit{Np}が文中数式を表す)
9572     ときは,$x=-1$.
9573     \item \textit{Np}の中身の中身の文字コードについて,「直前への\Param{xkanjiskip}の挿入」が禁止されている
9574 (つまり,\Param{jaxspmode}~(or \Param{alxspmode})パラメタが偶数)ときは,
9575     $x=\text{\texttt{'nox\_alchar'}}$.
9576     \item 以上のいずれでもないときは,$x=\text{\texttt{'alchar'}}$.
9577   \end{itemize}
9578 \end{enumerate}
9579 \item[\Param{xkanjiskip}~{[X]}]
9580 この段階では,\textsf{\Param{kanjiskip}~[K]}のときと同じように,
9581 以下で定めた量を「右空白」として採用する.
9582 \cs{inhibitglue} は効力を持たない.
9583 \begin{enumerate}
9584 \item 以下のいずれかの場合は,\Param{xkanjiskip}の挿入は抑止される.しかし,実際には行分割を許容するために,長さ0のglueを採用する:
9585 \begin{itemize}
9586 \item 両クラスタにおいて,それらの中身の文字コードに対する\Param{autoxspacing}パラメタが共にfalseである.
9587 \item \textit{Nq}の中身の文字コードについて,「直後への\Param{xkanjiskip}の挿入」が禁止されている
9588 (つまり,\Param{jaxspmode}~(or \Param{alxspmode})パラメタが2以上).
9589 \item \textit{Np}の中身の文字コードについて,「直前への\Param{xkanjiskip}の挿入」が禁止されている
9590 (つまり,\Param{jaxspmode}~(or \Param{alxspmode})パラメタが偶数).
9591 \end{itemize}
9592 \item ユーザ側から見た\Param{xkanjiskip}パラメタの自然長が$\cs{maxdimen}=(2^{30}-1)\,{\rm sp}$で
9593 なければ,\Param{xkanjiskip}パラメタの値を持つglueを採用する.
9594 \item 2.でない場合は,\textit{Nq}, \textit{Np}(\textsf{和文A}/\textsf{和文B}なのは片方だけ)
9595 で使われているJFMに指定されている\Param{xkanjiskip}の値を用いる.
9596 \end{enumerate}
9597 \end{description}
9598
9599 \paragraph{欧文と和文Aの間}
9600 \textit{Nq}が\textsf{欧文}で,\textit{Np}が\textsf{和文A}の場合,JFMグルー挿入処理は上の場合とほぼ同じである.
9601 \textsf{和文A}のクラスタが逆になるので,\textsf{欧文境界B~[\NB]}の部分が変わるだけである.
9602 \begin{itemize}
9603 \item 「右空白」については,まず以下に述べる\textsf{欧文境界A~[\OA]}により空白を決定しようと試みる.
9604 それが失敗した場合は,\textsf{\Param{xkanjiskip}~[X]}によって定める.
9605 %\item \textit{Nq}が和文でないので,「左空白」は算出されない.
9606 \item 禁則用ペナルティは,以前述べた\textsf{P-normal~[PN]}と同じである.
9607 \end{itemize}
9608 \begin{description}
9609 \item[欧文境界A~{[\NA]}] これは\textsf{欧文境界B~[\NB]}で\textit{Np}と\textit{Nq}の役割が
9610   交換されたものと思えば良い.
9611   この処理で定まる空白の典型例は,欧文文字と和文の開き括弧との間に入る半角アキである.
9612 \begin{enumerate}
9613 \item もし両クラスタの間で \cs{inhibitglue} が実行されていた場合(証としてwhatsitノードが自動挿入される),
9614   未定義.
9615 \item そうでなければ,
9616 「文字コードが$x$の文字」と\textit{Np}との間に入るグルー/カーンと定める.
9617 $x$は\textit{Nq}から\textsf{欧文境界B~[\NB]}におけるそれと同じ方法で定めるが,
9618 \texttt{'nox\_alchar'}か\texttt{'alchar'}は
9619 \begin{quote}
9620   \textit{Nq}の中身の文字コードについて,「直後への\Param{xkanjiskip}の挿入」が禁止されている
9621 (つまり,\Param{jaxspmode}~(or \Param{alxspmode})パラメタが2以上).
9622 \end{quote}
9623   か否かで判断する.
9624 \end{enumerate}
9625 \end{description}
9626
9627 \paragraph{和文Aと箱・グルー・カーンの間}
9628 \textit{Nq}が\textsf{和文A}で,\textit{Np}が\textsf{箱}・グルー・カーンのいずれかであった場合,
9629 両者の間に挿入されるJFMグルーについては同じ処理である.しかし,そこでの行分割に対する仕様が異なるので,
9630 ペナルティの挿入処理は若干異なったものとなっている.
9631 \begin{itemize}
9632 \item 「右空白」については,以下に述べる\textsf{Boundary-B~[\OB]}により空白を決定しようと試みる.
9633 それが失敗した場合は,「右空白」は挿入されない.
9634 %\item 「左空白」については,既に述べた\textsf{line-end~[E]}の算出方法をそのまま採用する.それに伴う「右空白」の補正も同じ.
9635 \item 禁則用ペナルティの処理は,後ろのクラスタ\textit{Np}の種類によって異なる.
9636 なお,$\mathit{Np}.\mathit{head}$は無意味であるから,
9637 「$\mathit{Np}.\mathit{head}$に対する\Param{prebreakpenalty}の値」は0とみなされる.言い換えれば,
9638 \[
9639  a:=(\text{\textit{Nq}の文字に対する\Param{postbreakpenalty}の値}).
9640 \]
9641 \begin{description}
9642 \item[箱] \textit{Np}が\textsf{箱}であった場合は,両クラスタの間での行分割は
9643 (明示的に両クラスタの間に \cs{penalty10000} があった場合を除き)いつも許容される.そのため,
9644 ペナルティ処理は,後に述べる\textsf{P-allow~[PA]}が\textsf{P-normal~[PN]}の代わりに用いられる.
9645 \item[グルー] \textit{Np}がグルーの場合,ペナルティ処理は\textsf{P-normal~[PN]}を用いる.
9646 \item[カーン] \textit{Np}がカーンであった場合は,両クラスタの間での行分割は
9647 (明示的に両クラスタの間にペナルティがあった場合を除き)許容されない.
9648 ペナルティ処理は,後に述べる\textsf{P-suppress~[PS]}を使う.
9649 \end{description}
9650 これらの\textsf{P-normal~[PN]},\textsf{P-allow~[PA]},\textsf{P-suppress~[PS]}の違いは,
9651 \textit{Nq}と\textit{Np}の間(以前の図だと(a)の部分)にペナルティが存在しない場合にのみ存在する.
9652 \end{itemize}
9653
9654 \begin{description}
9655 \item[Boundary-B~{[\OB]}] この処理は\textsf{欧文境界B~[\NB]}と同様であり,
9656   $x$が次によって決まることのみが異なる:
9657   \begin{itemize}
9658     \item \textit{Np}がグルーやカーンのときは,$x=\text{\texttt{'glue'}}$.
9659     \item そうでない(\textit{Np}が\textsf{箱})ときは,$x=\text{\texttt{'jcharbdd'}}$.
9660   \end{itemize}
9661 \item[P-allow~{[PA]}]
9662 \textit{Nq}と\textit{Np}の間の(a)部分にペナルティがあれば,\textsf{P-normal~[PN]}と同様に,
9663 それらの各ノードにおいてペナルティ値を$a$だけ増加させる.
9664
9665 (a)部分にペナルティが存在していない場合,
9666 \LuaTeX-ja は\textit{Nq}と\textit{Np}の間の行分割を可能にしようとする.
9667 そのために,以下のいずれかの場合に$a$をもつ\textit{penalty\_node}を作って
9668 「右空白」の(もし未定義なら\textit{Np}の)直前に挿入する:
9669 \begin{itemize}
9670 \item 「右空白」がグルーでない(カーンか未定義)であるとき.
9671 \item $a\neq 0$のときは,「右空白」がグルーであっても\textit{penalty\_node}を作る.
9672 \end{itemize}
9673
9674 \item[P-suppress~{[PS]}]
9675 \textit{Nq}と\textit{Np}の間の(a)部分にペナルティがあれば,\textsf{P-normal~[PN]}と同様に,
9676 それらの各ノードにおいてペナルティ値を$a$だけ増加させる.
9677
9678 (a)部分にペナルティが存在していない場合,
9679 \textit{Nq}と\textit{Np}の間の行分割は元々不可能のはずだったのであるが,
9680 \LuaTeX-ja はそれをわざわざ行分割可能にはしない.
9681 そのため,「右空白」がglueであれば,その直前に \cs{penalty10000} を挿入する.
9682 \end{description}
9683
9684 \paragraph{箱・グルー・カーンと和文Aの間}
9685 \textit{Np}が\textsf{箱}・グルー・カーンのいずれかで,\textit{Np}が\textsf{和文A}であった場合は,
9686 すぐ上の(\textit{Nq}と\textit{Np}の順序が逆になっている)場合と同じである.
9687 %が,「左空白」がなくなることにのみ注意.
9688 \begin{itemize}
9689 \item 「右空白」については,以下に述べる\textsf{Boundary-A~[\OA]}により空白を決定しようと試みる.
9690 それが失敗した場合は,「右空白」は挿入されない.
9691 %\item \textit{Nq}が和文でないので,「左空白」は算出されない.
9692 \item 禁則用ペナルティの処理は,\textit{Nq}の種類によって異なる.
9693 $\mathit{Nq}.\mathit{tail}$は無意味なので,
9694 \[
9695  a:=(\text{\textit{Np}の文字に対する\Param{prebreakpenalty}の値}).
9696 \]
9697 \begin{description}
9698 \item[箱] \textit{Nq}が\textsf{箱}の場合は,\textsf{P-allow~[PA]}を用いる.
9699 \item[グルー] \textit{Nq}がグルーの場合は,\textsf{P-normal~[PN]}を用いる.
9700 \item[カーン] \textit{Nq}がカーンの場合は,\textsf{P-suppress~[PS]}を用いる.
9701 \end{description}
9702 \end{itemize}
9703
9704 \begin{description}
9705 \item[Boundary-A~{[\OA]}] この処理は\textsf{欧文境界A~[\NA]}と同様であり,
9706   $x$が次によって決まることのみが異なる:
9707   \begin{itemize}
9708     \item \textit{Nq}がグルーやカーンのときは,$x=\text{\texttt{'glue'}}$.
9709     \item そうでない(\textit{Nq}が\textsf{箱})ときは,$x=\text{\texttt{'jcharbdd'}}$.
9710   \end{itemize}
9711 \end{description}
9712
9713 \paragraph{和文Aと和文Bの違い}
9714 先に述べたように,\textsf{和文B}はhboxの中身の先頭(or 末尾)として出現している
9715 \textbf{JAchar}である.リスト内に直接ノードとして現れている\textbf{JAchar}(\textsf{和文A})との違いは,
9716 \begin{itemize}
9717 \item \textsf{和文B}に対しては,JFMの文字クラス指定から定まる空白
9718 (\textsf{JFM由来[M]},\textsf{Boundary-A~[\OA]}など)の挿入は行われない.
9719 %「左空白」の算出も行われない.
9720 例えば,
9721 \begin{itemize}
9722 \item 片方が\textsf{和文A},もう片方が\textsf{和文B}のクラスタの場合,
9723 \textsf{Boundary-A~[\OA]}または\textsf{Boundary-B~[\OB]}の挿入を試み,それがダメなら
9724 \Param{kanjiskip}~\textsf{[K]}の挿入を行う.
9725 \item \textsf{和文B}の2つのクラスタの間には,\Param{kanjiskip}~\textsf{[K]}が自動的に入る.
9726 \end{itemize}
9727 \item \textsf{和文B}と箱・グルー・カーンが隣接したとき(どちらが前かは関係ない),間にJFMグルー・ペナルティの挿入は一切しない.
9728 \item \textsf{和文B}と\textsf{和文B},また\textsf{和文B}と\textsf{欧文}とが隣接した時は,禁則用ペナルティ挿入処理は
9729 \textsf{P-suppress~[PS]}が用いられる.
9730 \item \textsf{和文B}の文字に対する\Param{prebreakpenalty},~\Param{postbreakpenalty}の値は使われず,0として計算される.
9731 \end{itemize}
9732
9733
9734 次が具体例である:
9735 \begin{LTXexample}
9736 あ.\inhibitglue A\\
9737 \hbox{あ.}A\\
9738 あ.A
9739 \end{LTXexample}
9740 \begin{itemize}
9741 \item 1行目の\cs{inhibitglue}は\textsf{欧文境界B~[\NB]}の処理のみを抑止するので,ピリオドと「A」の間には
9742 \Param{xkanjiskip}(四分アキ)が入ることに注意.
9743 \item 2行目のピリオドと「A」の間においては,前者が\textsf{和文B}となる(hboxの中身の末尾として登場しているから)ので,
9744 そもそも\textsf{欧文境界B~[\NB]}の処理は行われない.よって,\Param{xkanjiskip}が入ることとなる.
9745 \item 3行目では,ピリオドの属するクラスタは\textsf{和文A}である.これによって,
9746 ピリオドと「A」の間には\textsf{欧文境界B~[\NB]}由来の半角アキが入ることになる.
9747 \end{itemize}
9748 %</ja>
9749
9750 %<*ja>
9751 \section{ベースライン補正の方法}
9752 \subsection{\texttt{yoffset} フィールド}
9753 \Param{yalbaselineshift}等のベースライン補正は,基本的には対象となっている
9754 \textit{glyph\_node}の \texttt{yoffset} フィールドの値を増減することによって
9755 実装されている.なお,\texttt{yoffset} の値は上方向への移動量であるのに対し,
9756 \Param{yalbaselineshift}などは下方向への移動量である.
9757
9758 さて,\texttt{yoffset} の増減によって見かけのグリフ位置は上下に移動するが,
9759 仮想ボディの高さ$h$,深さ$d$については
9760 \begin{description}
9761 \catcode`\<=12\catcode`\>=12
9762  \item[$\texttt{yoffset}\geq 0$のとき]
9763 $h = \max(\texttt{height} + \texttt{yoffset}, 0)$,
9764 $d = \max(\texttt{depth} - \texttt{yoffset}, 0)$,
9765  \item[$\texttt{yoffset}<0$のとき]
9766 $h = \max(\texttt{height} + \texttt{yoffset}, 0)$, $d=\texttt{depth}$.
9767 \end{description}
9768 という仕様になっている.つまり,\texttt{yoffset} が負(グリフを下ける)の場合に深さは増加しな
9769 い(\autoref{tab:yoffset_and_im}参照).
9770
9771 \begin{table}[t]
9772 \caption{\texttt{yoffset} and imaginary body}
9773 \label{tab:yoffset_and_im}
9774 \centering\small
9775 \fboxsep0pt
9776 \def\T#1#2{\fcolorbox{blue}{white}{%
9777   \setbox0=\hbox{\LARGE #1%
9778     \directlua{
9779       local p = tex.nest[tex.nest.ptr].tail
9780       p.yoffset = #2 * 65536
9781     }%
9782   }%
9783   \copy0\kern-\wd0\smash{\color{red}\vrule width \wd0 height 0.2pt depth 0.2pt}%
9784 }}
9785 \begin{tabular}{>{\bfseries}lccccc}
9786 \toprule
9787 \texttt{yoffset}&10\,pt&5\,pt&0&$-5$\,pt&$-10$\,pt\\
9788 \midrule
9789 仮想ボディ&\T{y}{10}, \T{H}{10}&\T{y}{5}, \T{H}{5}&\T{y}{0}, \T{H}{0}%
9790 &\T{y}{-5}, \T{H}{-5}&\T{y}{-10}, \T{H}{-10}\\[10pt]
9791 \bottomrule
9792 \end{tabular}
9793 \end{table}
9794
9795 \subsection{\textbf{ALchar}の補正}
9796 上記の問題について,\textbf{ALchar}のベースライン補正では
9797 「正しい深さ」を持った罫線(rule)を補うという対応策をとった.
9798 この罫線による補正は,\textit{id}が\textit{id\_glyph}であるクラスタ単位,
9799 大雑把に言えば音節単位で行われる.
9800 文字列``Typeset''を
9801 \begin{itemize}
9802  \item フォントはLatin Modern Roman (\texttt{lmroman10-regular.otf}) 10\,pt
9803  \item \Param{yalbaselineshift}は5\,pt
9804 \end{itemize}
9805 という状況で組んだ場合を例にとって説明しよう.
9806
9807 \LuaTeX・\Pkg{luaotfload}によるカーニング・ハイフネーションが終わった段階では,……
9808
9809
9810
9811 %</ja>
9812
9813 %<en>\section{Patch for the \Pkg{listings} Package}
9814 %<ja>\section{\Pkg{listings} パッケージへの対応}
9815
9816 %<*en>
9817 It is well-known that the \Pkg{listings} package outputs weird results
9818 for Japanese input.
9819 The \Pkg{listings} package makes most of letters active and assigns
9820 output command for each letter~(\cite{listings}).
9821 But Japanese characters are not included in these activated letters.
9822 For \pTeX{} series, there is no method to make Japanese characters active;
9823 a patch \Pkg{jlisting.sty}~(\cite{jlisting}) resolves the problem forcibly.
9824 %</en>
9825 %<*ja>
9826 \Pkg{listings} パッケージが,そのままでは日本語をまともに出力できないこと
9827 はよく知られている.きちんと整形して出力するために,\Pkg{listings}パッケー
9828 ジは内部で「ほとんどの文字」をアクティブにし,各文字に対してその文字の出
9829 力命令を割り当てている(\cite{listings}).
9830 しかし,そこでアクティブにする文字の中に,和文文
9831 字がないためである.\pTeX 系列では,和文文字をアクティブにする手法がなく,
9832 \Pkg{jlisting.sty} というパッチ(\cite{jlisting})を用いることで無理やり解決していた.
9833 %</ja>
9834
9835 %<*en>
9836 In \LuaTeX-ja, the problem is resolved by using the \verb+process_input_buffer+ callback.
9837 The callback function inserts the output command (active character \cs{ltjlineendcomment})
9838 before each letter above \texttt{U+0080}.
9839 This method can omits the process to make all Japanese characters active
9840 (most of the activated characters are not used in many cases).
9841 %</en>
9842 %<*ja>
9843 \LuaTeX-jaでは,\verb+process_input_buffer+ コールバックを利用することで,
9844 「各行に出現する\texttt{U+0080}以降の文字に対して,それらの出力命令を前置する」
9845 という方法をとっている.出力命令としては,アクティブ文字化した\cs{ltjlineendcomment}を用いている.
9846 これにより,(入力には使用されていないかもしれない)和文文字をもすべてアクティブ化する手間もなく,
9847 見通しが良い実装になっている.
9848 %</ja>
9849
9850
9851 %<*en>
9852 If the \Pkg{listings} package  and \LuaTeX-ja were loaded,
9853 then the patch \Pkg{lltjp-listings} is loaded automatically at \verb+\begin{document}+.
9854 %</en>
9855 %<*ja>
9856 \LuaTeX-ja で利用される \Pkg{listings} パッケージへのパッチ \Pkg{lltjp-listings} は,
9857 \Pkg{listings} と\LuaTeX-jaを読み込んでおけば,
9858 \verb+\begin{document}+ の箇所において自動的に読み込まれるので,通常はあまり
9859 意識する必要はない.
9860 %</ja>
9861
9862 %<en>\subsection{Notes and additional keys}
9863 %<ja>\subsection{注意}
9864 % %<*en>
9865 % \paragraph{Escaping to \LaTeX}
9866 % We used the \verb+process_input_buffer+ callback to output \textbf{JAchar}s.
9867 % But it has a drawback; any commands whose name contains a \textbf{JAchar}
9868 % cannot be used in any ``escape to \LaTeX''.
9869
9870 % Consider the following input:
9871 % %</en>
9872 % %<*ja>
9873 % \paragraph{\LaTeX へのエスケープ}
9874 % 日本語対応を行うために \verb+process_input_buffer+ を使用したことで,
9875 % \texttt{texcl},~\texttt{escapeinside}といった\emph{「\LaTeX へのエスケープ」中では,
9876 % \textbf{JAchar}を名称の一部に含む制御綴は使用不可能}である.
9877 % 例えば次のような入力を考えよう:
9878 % %</ja>
9879 % \begin{verbatim*}
9880 % \begin{lstlisting}[escapechar=\#]
9881 % #\ほげ xぴよ#
9882 % \end{lstlisting}
9883 % \end{verbatim*}
9884 % %<en>The line~2 is transformed by the callback to
9885 % %<ja>ここで,2行目は \verb+process_input_buffer+ の作用により,
9886 % \begin{lstlisting}[showspaces, escapechar=\!]
9887 % #\!\IVSA FFFFF!ほ!\IVSA FFFFF!げ x!\IVSA FFFFF!ぴ!\IVSA FFFFF!よ#
9888 % \end{lstlisting}
9889 % %<*en>
9890 % before the line is actually processed.
9891 % In the escape (between the character ``\verb+#+''),
9892 % the category code of \texttt{U+FFFFF} is set to 9~(\emph{ignored}).
9893 % Hence the control symbol ``\cs{}\IVSA FFFFF'' will be executed,
9894 % instead of ``\verb+\ほげ+''.
9895 % %</en>
9896 % %<*ja>
9897 % と変換されてから,実際の処理に回される.
9898 % 「\verb+#+」で挟まれた「\LaTeX へのエスケープ」中では\
9899 % \texttt{U+FFFFF} のカテゴリーコードは9~(\textit{ignored})となるので,
9900 % 結局「\verb+\ほげ+」の代わりに
9901 % 「\cs{}\IVSA FFFFF」というcontrol symbolが実行されることになる.
9902 % %</ja>
9903
9904 %<*en>
9905 \paragraph{Variation selectors}
9906 \Pkg{lltjp-listings} add two keys, namely \texttt{vsraw}~and~\texttt{vscmd},
9907 which specify how variation selectors are treated in
9908 \texttt{lstlisting} or other enviroments.
9909 Note that these additional keys are not usable in the preamble,
9910 since \Pkg{lltjp-listings} is loaded at \verb+\begin{document}+.
9911
9912 \texttt{vsraw} is a key which takes a boolean value, and its default value is
9913 false.
9914 \begin{itemize}
9915  \item If the \texttt{vsraw} key is true, then
9916 variation selectors are ``combined'' with the previous character.
9917 %</en>
9918 %<*ja>
9919 \paragraph{異体字セレクタの扱い}
9920 \texttt{lstlisting} 環境などの内部にある異体字セレクタを扱うため,
9921 \Pkg{lltjp-listings} では \texttt{vsraw} と \texttt{vscmd} という2つのキーを追加した.
9922 しかし,\Pkg{lltjp-listings} が実際に読み込まれるのは \verb+\begin{document}+\
9923 のところであるので,プリアンブル内ではこれらの追加キーは使用できない.
9924
9925 \texttt{vsraw}は,ブール値の値をとるキーであり,標準ではfalseである.
9926 \begin{itemize}
9927  \item trueの場合は,異体字セレクタは「直前の文字に続けて」出力される.
9928 もしもIVSサポート(\ref{ssec:ltjotf}節)が有効になっていた場合は,
9929 以下の例(左側は入力,右側はその出力)のようになる.
9930 %</ja>
9931 \begin{LTXexample}
9932 \begin{lstlisting}[vsraw=true]
9933 葛󠄀城市,葛󠄁飾区,葛西
9934 \end{lstlisting}
9935 \end{LTXexample}
9936 %<*en>
9937 \item If the \texttt{vsraw} key is false, then
9938 variation selectors are typeset by an appropriate command, which is specified by
9939       the \texttt{vscmd} key.
9940 The default setting of the \texttt{vscmd} key produces the following.
9941 %</en>
9942 %<*ja>
9943 \item falseの場合は,異体字セレクタは適当な命令によって「見える形で」出力される.
9944 どのような形で出力されるかを規定するのが \texttt{vscmd} キーであり,
9945 \Pkg{lltjp-listings} の標準設定では以下の例の右側のように出力される.
9946 %</ja>
9947 \begin{LTXexample}
9948 \begin{lstlisting}[vsraw=false,
9949    vscmd=\ltjlistingsvsstdcmd]
9950 葛󠄀城市,葛󠄁飾区,葛西
9951 \end{lstlisting}
9952 \end{LTXexample}
9953 %<ja> ちなみに,本ドキュメントでは次のようにしている:
9954 %<en> For example, the following code is the setting of the \texttt{vscmd} key in this document.
9955 \begin{lstlisting}[numbers=left]
9956 \def\IVSA#1#2#3#4#5{%
9957   \textcolor{blue}{\raisebox{3.5pt}{\tt%
9958     \fboxsep=0.5pt\fbox{\tiny \oalign{0#1#2\crcr#3#4#5\crcr}}}}%
9959 }
9960 {\catcode`\%=11
9961   \gdef\IVSB#1{\expandafter\IVSA\directlua{
9962     local cat_str = luatexbase.catcodetables['string']
9963     tex.sprint(cat_str, string.format('%X', 0xE00EF+#1))
9964 }}}
9965 \lstset{vscmd=\IVSB}
9966 \end{lstlisting}
9967 \end{itemize}
9968 %<*en>
9969 The default output command of variation selectors is stored in \verb+\ltjlistingsvsstdcmd+.
9970 %</en>
9971 %<*ja>
9972 既定の出力命令を復活させたい場合は\ \verb+vscmd=\ltjlistingsvsstdcmd+\
9973 とすれば良い.
9974 %</ja>
9975
9976 %<*en>
9977 \paragraph{The \texttt{doubleletterspace} key}
9978 Even the column format is \texttt{[c]fixed}, sometimes characters are not vertically aligned.
9979 The following example  is typeset with \texttt{basewidth=2em}, and
9980 you'll see the leftmost ``\texttt{H}'' are not vertically aligned.
9981 \begin{lstlisting}[basewidth=2em, basicstyle=\tt,numbers=left]
9982 :H:
9983 :HHHH:
9984 \end{lstlisting}
9985
9986 \Pkg{lltjp-listing} adds the \texttt{doubleletterspace} key (not activated by default, for
9987 compatibility) to
9988 improve the situation, namely doubles inter-character space in each output unit.
9989 With this key, the above input now produces better output.
9990 \begin{lstlisting}[basewidth=2em, basicstyle=\tt,numbers=left, doubleletterspace]
9991 :H:
9992 :HHHH:
9993 \end{lstlisting}
9994 %</en>
9995 %<*ja>
9996 \paragraph{\texttt{doubleletterspace}キー}
9997 \Pkg{listings}パッケージで列揃えが \texttt{[c]fixed} となっている場合でも,
9998 場合によっては文字が縦に揃わない場合もある.
9999 例を以下に示そう.これは強調するために \texttt{basewidth=2em} を設定している.
10000 \begin{lstlisting}[basewidth=2em, basicstyle=\tt,numbers=left]
10001 :H:
10002 :HHHH:
10003 \end{lstlisting}
10004 1行目と2行目の「\texttt{H}」の位置が揃っていないが,
10005 これは出力単位ごとに,先頭・末尾・各文字間に同じ量の空白を挿入することによる.
10006
10007 \Pkg{lltjp-listing}では,このような症状を改善させるために \texttt{doubleletterspace} キー
10008 を追加した(標準では互換性のために無効になっている).このキーを有効にすると,
10009 出力単位中の各文字間の空白を2倍にすることで文字を揃いやすくしている.
10010 上と同じものを \texttt{doubleletterspace} キーを有効にして組んだものが以下であり,
10011 きちんと「\texttt{H}」の位置が揃っていることが分かる.
10012 \begin{lstlisting}[basewidth=2em, basicstyle=\tt,numbers=left, doubleletterspace]
10013 :H:
10014 :HHHH:
10015 \end{lstlisting}
10016 %</ja>
10017
10018 %<en>\subsection{Class of characters}
10019 %<ja>\subsection{文字種}
10020
10021 %<en>Roughly speaking, the \Pkg{listings} package processes input as follows:
10022 %<ja>\Pkg{listings} パッケージの内部では,大雑把に言うと
10023 \begin{enumerate}
10024 %<en>\item Collects \textit{letters} and \textit{digits}, which can be used for the name of identifiers.
10025 %<ja>\item 識別子として使える文字 (``letter'',~``digit'') たちを集める.
10026 %<en>\item When reading an \textit{other}, outputs the collected character string (with modification, if needed).
10027 %<ja>\item letterでもdigitでもない文字が現れた時に,収集した文字列を(必要なら修飾して)出力する.
10028 %<en>\item Collects \textit{others}.
10029 %<ja>\item 今度は逆に,letterでない文字たちをletterが現れるまで集める.
10030 %<en>\item When reading a \textit{letter} or a \textit{digit}, outputs the collected character string.
10031 %<ja>\item letterが出現したら集めた文字列を出力する.
10032 %<en>\item Turns back to 1.
10033 %<ja>\item 1.に戻る.
10034 \end{enumerate}
10035 %<*en>
10036 By the above process, line breaks inside of an identifier are blocked.
10037 A flag \verb+\lst@ifletter+ indicates whether the previous character can be used
10038 for the name of identifiers or not.
10039 %</en>
10040 %<*ja>
10041 という処理が行われている.これにより,識別子の途中では行分割が行われないようになっている.
10042 直前の文字が識別子として使えるか否かは \verb+\lst@ifletter+ というフラグに格納されている.
10043 %</ja>
10044
10045 %<*en>
10046 For Japanese characters, line breaks are permitted on both sides
10047 except for brackets, dashes, etc.
10048 Hence the patch \Pkg{lltjp-listings} introduces
10049 a new flag \verb+\lst@ifkanji+, which indicates
10050 whether the previous character is a Japanese character or not.
10051 For illustration, we introduce following classes of characters:
10052 %</en>
10053 %<*ja>
10054 さて,日本語の処理である.殆どの和文文字の前後では行分割が可能であるが,その一方で
10055 括弧類や音引きなどでは禁則処理が必要なことから,\Pkg{lltjp-listings} では,
10056 直前が和文文字であるかを示すフラグ \verb+\lst@ifkanji+ を新たに導入した.
10057 以降,説明のために以下のように文字を分類する:
10058 %</ja>
10059 \begin{center}
10060 \small
10061 \begin{tabular}{lccccc}
10062 \toprule
10063 &Letter&Other&Kanji&Open&Close\\\midrule
10064 \verb+\lst@ifletter+&T&F&T&F&T\\
10065 \verb+\lst@ifkanji+&F&F&T&T&F\\
10066 %<en>Meaning&char in an identifier&other alphabet&%
10067 %<en>most of Japanese char&opening brackets&closing brackets\\
10068 %<ja>意図&識別子中の文字&その他欧文文字&殆どの和文文字&開き括弧類&閉じ括弧類\\
10069 \bottomrule
10070 \end{tabular}
10071 \end{center}
10072 %<*en>
10073 Note that \textit{digits} in the \Pkg{listings} package can be Letter or
10074 Other according to circumstances.
10075 %</en>
10076 %<*ja>
10077 なお,本来の\Pkg{listings} パッケージでの分類``digit''は,
10078 出現状況によって,上の表のLetterとOtherのどちらにもなりうる.
10079 また,KanjiとCloseは \verb+\lst@ifletter+ と \verb+\lst@ifkanji+ の値が一致しているが,
10080 これは間違いではない.
10081 %</ja>
10082
10083 %<*en>
10084 For example, let us consider the case an Open comes after a Letter.
10085 Since an Open represents Japanese open brackets,
10086 it is preferred to be permitted to insert line break after the Letter.
10087 Therefore, the collected character string is output in this case.
10088 %</en>
10089 %<*ja>
10090 例えば,Letterの直後にOpenが来た場合を考える.
10091 文字種Openは和文開き括弧類を想定しているので,Letterの直後では行分割が可能であることが望ましい.
10092 そのため,この場合では,すでに収集されている文字列を出力することで行分割を許容するようにした.
10093 %</ja>
10094
10095 %<*en>
10096 The following table summarizes $5\times 5=25$ cases:
10097 %</en>
10098 %<*ja>
10099 同じように,$5\times 5=25$通り全てについて書くと,次のようになる:
10100 %</ja>
10101 \begin{center}
10102 \small
10103 \begin{tabular}{llccccc}
10104 \toprule
10105 %<*en>
10106 &&\multicolumn{4}{c}{Next}\\\cmidrule(lr){3-7}
10107 &&\hbox to 4em{\hss Letter\hss}&\hbox to 4em{\hss Other\hss}
10108 &\hbox to 4em{\hss Kanji\hss}&\hbox to 4em{\hss Open\hss}&Close\\\midrule
10109 &Letter&collects&\multicolumn{3}{c}{\hrulefill \ outputs\ \hrulefill}&collects\\
10110 &Other&outputs&collects&\multicolumn{2}{c}{\hrulefill \ outputs\ \hrulefill}&collects\\
10111 Prev&Kanji&\multicolumn{4}{c}{\hrulefill \ outputs\ \hrulefill}&collects\\
10112 &Open&\multicolumn{5}{c}{\hrulefill \ collects\ \hrulefill}\\
10113 &Close&\multicolumn{4}{c}{\hrulefill \ outputs\ \hrulefill}&collects\\
10114 %</en>
10115 %<*ja>
10116 &&\multicolumn{4}{c}{後ろ側の文字}\\\cmidrule(lr){3-7}
10117 &&\hbox to 4em{\hss Letter\hss}&\hbox to 4em{\hss Other\hss}
10118 &\hbox to 4em{\hss Kanji\hss}&\hbox to 4em{\hss Open\hss}&Close\\\midrule
10119 直&Letter&収集&\multicolumn{3}{c}{\hrulefill \ 出力\ \hrulefill}&収集\\
10120 前&Other&出力&収集&\multicolumn{2}{c}{\hrulefill \ 出力\ \hrulefill}&収集\\
10121 文&Kanji&\multicolumn{4}{c}{\hrulefill \ 出力\ \hrulefill}&収集\\
10122 字&Open&\multicolumn{5}{c}{\hrulefill \ 収集\ \hrulefill}\\
10123 種&Close&\multicolumn{4}{c}{\hrulefill \ 出力\ \hrulefill}&収集\\
10124 %</ja>
10125 \bottomrule
10126 \end{tabular}
10127 \end{center}
10128 %<en>In the above table,
10129 %<ja>上の表において,
10130 \begin{itemize}
10131 %<en>\item ``outputs'' means to output the collected character string (i.e., line breaking is permitted there).
10132 %<ja>\item 「出力」は,それまでに集めた文字列を出力(≒ここで行分割可能)を意味する.
10133
10134 %<en>\item ``collects'' means to append the next character to the collected character string (i.e., line breaking is prohibited there).
10135 %<ja>\item 「収集」は,後側の文字を,現在収集された文字列に追加(行分割不可)を意味する.
10136 \end{itemize}
10137
10138 %<*en>
10139 Characters above or equal to~\texttt{U+0080} \emph{except Variation Selectors}
10140 are classified into above 5~classes by the following rules:
10141 %</en>
10142 %<*ja>
10143 \texttt{U+0080}以降の\emph{異体字セレクタ以外の}各文字が
10144 Letter, Other, Kanji, Open, Closeのどれに属するかは次によって決まる:
10145 %</ja>
10146 \begin{itemize}
10147 %<en>\item \textbf{ALchar}s above or equal to~\texttt{U+0080} are classified as Letter.
10148 %<ja>\item \<(\texttt{U+0080}以降の)\textbf{ALchar}は,すべてLetter扱いである.
10149
10150 %<en>\item \textbf{JAchar}s are classified in the order as follows:
10151 %<ja>\item \textbf{JAchar}については,以下の順序に従って文字種を決める:
10152 \begin{enumerate}
10153 %<en>\item Characters whose \Param{prebreakpenalty} is greater than or equal to 0 are classified as Open.
10154 %<ja>\item \Param{prebreakpenalty}が0以上の文字はOpen扱いである.
10155
10156 %<en>\item Characters whose \Param{postbreakpenalty} is greater than or equal to 0 are classified as Close.
10157 %<ja>\item \Param{postbreakpenalty}が0以上の文字はClose扱いである.
10158
10159 %<en>\item Characters that don't satisfy the above two conditions are classified as Kanji.
10160 %<ja>\item 上の3条件のどちらにも当てはまらなかった文字は,Kanji扱いである.
10161 \end{enumerate}
10162 \end{itemize}
10163
10164 %<*en>
10165 The width of halfwidth kana (\texttt{U+FF61}--\texttt{U+FF9F})
10166 is same as the width of \textbf{ALchar};
10167 the width of the other \textbf{JAchar}s is double the width of \textbf{ALchar}.
10168 %</en>
10169 %<*ja>
10170 なお,半角カナ(U+FF61--U+FF9F)以外の\textbf{JAchar}は欧文文字2文字分の幅をとるものとみなされる.
10171 半角カナは欧文文字1文字分の幅となる.
10172 %</ja>
10173
10174 %<*en>
10175 This classification process is executed every time a character appears in
10176 the \texttt{lstlisting} environment or other environments/commands.
10177 %</en>
10178 %<*ja>
10179 これらの文字種決定は,実際に \texttt{lstlisting} 環境などの内部で文字が出てくるたびに行われる.
10180 %</ja>
10181
10182 %<*ja>
10183 \section{和文の行長補正方法}
10184 \label{sec-adjspec}
10185 \Pkg{luatexja-adjust}で提供される優先順位付きの行長調整の詳細を大まかに述べると,次のようになる.
10186 \begin{itemize}
10187 \item (\texttt{lineend=extended}の場合)\textbf{JAglue}の挿入処理のところで,
10188   ……
10189 \item 通常の\TeX の行分割方法に従って,段落を行分割する.この段階では,行
10190       長に半端が出た場合,その半端分は\textbf{JAglue}(\Param{xkanjiskip},
10191       \Param{kanjiskip},JFMグルー)と
10192       それ以外のグルーの全てで(優先順位なく)負担される.
10193 \item その後,\texttt{post\_linebreak\_filter} callbackを使い,\emph{段
10194       落中の各行ごとに},行末文字の位置を調整(\texttt{lineend=true}の場合)したり,優先度付きの行長調整
10195       を実現するためにグルーの伸縮度を調整する.
10196       その処理においては,グルーの自然長と\textbf{JAglue}以外の
10197       グルーの伸び量・縮み量は変更せず,必要に応じて\textbf{JAglue}の伸び量・縮み量のみを
10198       変更する設計とした.
10199 \end{itemize}
10200 この章の残りでは各処理について解説する.
10201
10202 \paragraph{準備:合計伸縮量の計算}
10203 グルーの伸縮度(\texttt{plus} や \texttt{minus} で指定されている値)には,
10204 有限値の他に,\texttt{fi},\texttt{fil},\texttt{fill},\texttt{filll}と
10205 いう4つの無限大レベル(後ろの方ほど大きい)がある.行の調整に
10206 \texttt{fi} などの\emph{無限大レベルの伸縮度が用いられている行では,
10207 「行末文字の位置調整」のみ行い,「グルーの調整」は行わない.}
10208
10209 まず,段落中の行中のグルーを
10210 \begin{itemize}
10211 \item \textbf{JAglue}ではないグルー
10212 \item JFMグルー(優先度\footnote{%
10213   \ref{ssec:jfm-str}節にあるように,
10214   各JFMグルーには$-4$から3までの優先度がついている.場合によっては
10215   伸びと縮みで異なる優先度が付いているかもしれない.}%
10216 別にまとめられる)
10217 \item 和欧文間空白(\Param{xkanjiskip})
10218 \item 和文間空白(\Param{kanjiskip})
10219 \end{itemize}
10220 の$1+1+8+1=10$つに類別する.
10221 そして許容されている伸び量(\texttt{stretch}の値)の合計を
10222 無限のレベルごとに
10223 \begin{align*}
10224  T^{+}_{l}&:= \sum_{\text{$\texttt{stretch\_order}(p) = l$}} \texttt{stretch}(p),&
10225  l\in \{\text{(finite)}, \texttt{fi}, \texttt{fil}, \texttt{fill}, \texttt{filll}\}
10226 \end{align*}
10227 と計算する.さらに,
10228 \begin{align*}
10229 T^{+}&:=T^{+}_{L^+},&L^{+} = \max \{l\in
10230  \{\text{(finite)}, \texttt{fi}, \texttt{fil}, \texttt{fill}, \texttt{filll}\}:
10231  T^{+}_l\neq 0\}
10232 \end{align*}
10233 とおく.有限の伸び量については,上記の8種類の類別ごとにも合計を計算する.
10234 さらに縮み量(\texttt{shrink}の値)についても同様の処理を行い,$T^{-}$を計算する.
10235
10236 また,行長から自然長を引いた値を\textit{total}とおく.
10237
10238 \subsection{行末文字の位置調整(行分割後の場合)}
10239 行末が\textbf{JAchar}であり,この文字の属する文字クラスでは
10240 \begin{quote}
10241   \texttt{end\_adjust = \{$a_{1}$, $a_{2}$, ..., $a_{n}$\}}
10242 \end{quote}
10243 であったとする.
10244 このとき,以下の条件を満たした場合,
10245 この文字クラスに対する\texttt{end\_adjust}の値のいずれかだけこの文字の位置を移動させる.
10246 \begin{description}
10247   \item[最終行以外] 行長調整に無限大の伸縮度が用いられていない.
10248   すなわち,$\textit{total}>0$ならば$L^{+}=(\text{finite})$であり,
10249   $\textit{total}>0$ならば$L^{-}=(\text{finite})$である.
10250   \item[最終行] 行長調整に無限大に伸び縮みするグルーが用いられたなら,それは\cs{parfillskip}のみであり,
10251     かつ,次の不等式が成立する:
10252   \[
10253    \min\{0,a_{1}\}\text{\cs{zw}}\leq (\text{\cs{parfillskip}の実際の長さ}) \leq \max\{0,a_{n}\}\text{\cs{zw}}
10254   \]
10255 \end{description}
10256
10257 各$1\leq i\leq n$に対して,
10258 「行末に$a_{i}$全角だけのカーンを追加した時の,\textit{glue\_set}の値」を
10259 $b_{i}$とおく.式で書くと,
10260 \[
10261 \catcode`\<=12
10262 b_{i} = \begin{cases}
10263   |\textit{total}-a_{i}\text{\cs{zw}}|/T^{+}
10264           &(\textit{total}-a_{i}\text{\cs{zw}}\geq 0)\\
10265   |\textit{total}-a_{i}\text{\cs{zw}}|/T^{-}
10266           &(\textit{total}-a_{i}\text{\cs{zw}}<0)
10267 \end{cases}.
10268 \]
10269 $b_{i}$達の最小値を与えるような$i$を$j$としたとき\footnote{%
10270   そのような$i$が2つ以上あるときは,$|\textit{total}-a_{i}\cdot \text{\cs{zw}}|$,
10271   $|a_{i}|$, $a_i$の順で比較して一番小さくなるものが選ばれる.
10272 },
10273 行末に大きさ$a_{j}$のカーンを追加する.
10274 \textit{total}から$a_{j}$全角の大きさだけ引いておく.
10275
10276 \subsection{行末文字の位置調整(行分割での考慮)}
10277 \texttt{lineend=extended}が指定されている場合,\TeX による行分割が行われる前に
10278 各\textbf{JAchar}の直後に,その文字が行末に来たときの位置補正用のノードを挿入していく.
10279
10280 \ref{sec-jfmglue}章の用語を使って述べる.
10281 前側のクラスタ\textit{Nq}が「和文A」「和文B」であり,
10282 JFMによって\texttt{end\_adjust}の値が
10283 \begin{quote}
10284   \texttt{end\_adjust = \{$a_{1}$, $a_{2}$, ..., $a_{n}$\}}
10285 \end{quote}
10286 であったとする.このとき,次のクラスタ\textit{Np}の直前に以下のノード列を挿入する.
10287 \textbf{JAglue}の挿入過程で禁則処理のために「\textit{Nq}と\textit{Np}の間のペナルティ値を増やす」ことが
10288 行われることがあるが,以下で述べられている$(n+1)$個のペナルティはみなその処理対象になっている.
10289 \begin{align*}
10290   \Node{kern}{$a_{1}\text{\cs{zw}}$}
10291   &\longrightarrow \Node{penalty}{$0$} \longrightarrow\Node{kern}{$(a_{2}-a_{1})\text{\cs{zw}}$}
10292   \longrightarrow \Node{penalty}{$0$} \longrightarrow\Node{kern}{$(a_{3}-a_{2})\text{\cs{zw}}$}\\
10293   &\longrightarrow
10294   \cdots \longrightarrow\Node{penalty}{$0$} \longrightarrow
10295   \Node{kern}{$(a_{n}-a_{n-1})\text{\cs{zw}}$}
10296   \longrightarrow \Node{penalty}{$0$} \longrightarrow
10297   \Node{kern}{$-a_{n}\text{\cs{zw}}$} \longrightarrow \Node{penalty}{$10000$}
10298 \end{align*}
10299 $n$個あるペナルティの箇所が改行可能箇所である.いずれかで改行された場合は,
10300 その前にあるカーン($n$箇所のうちどこで改行しても,合計の長さは$a_{i}$の形)は行末に残るが,
10301 後ろのペナルティ・カーンは除去される.なお,$a_1=0$のときは最初の幅が$a_{1}\text{\cs{zw}}$のカーンは不要なので挿入されず,
10302 さらにかつ$n=1$であった場合は後ろのペナルティも挿入されない.
10303
10304 なお,段落の末尾には\cs{penalty10000}と\cs{parfillskip}由来のグルーが自動的に入るが,
10305 これらとの兼ね合いのため\emph{最後のクラスタについては上記のノード挿入処理は行われない}.
10306 段落最終行の行末文字の位置調整は,すでに述べた「行分割後の場合」における最終行の処理をそのまま用いている.
10307
10308 \subsection{グルーの調整}
10309 $|\textit{total}|$の分だけが,行中のグルーの伸び量,あるいは縮み量に応じて負担されることになる.
10310 以下,$\textit{total}\geq 0$であると仮定して話を進めるが,負のときも同様である.
10311 \Pkg{luatexja-adjust}の初期値では以下の順に伸び量を負担するようになっており,
10312 (優先度$-4$のJFMグルーは例外として)できるだけ\Param{kanjiskip}を自然長のままにすることを
10313 試みている.この順番は\Param{stretch\_priority}(縮み量については\Param{shrink\_priority})
10314 パラメータで変更可能である.
10315 \begin{enumerate}\def\labelenumi{(\Alph{enumi})}
10316  \item \textbf{JAglue}以外のグルー
10317  \item 優先度3のJFMグルー
10318  \item 優先度2のJFMグルー
10319  \item 優先度1のJFMグルー
10320  \item 優先度0のJFMグルー
10321  \item 優先度$-1$のJFMグルー
10322  \item 優先度$-2$のJFMグルー
10323  \item \Param{xkanjiskip}
10324  \item 優先度$-3$のJFMグルー
10325  \item \Param{kanjiskip}
10326  \item 優先度$-4$のJFMグルー
10327 \end{enumerate}
10328 \begin{enumerate}
10329  \item 行末の\textbf{JAchar}を移動したことで$\textit{total}=0$となれば,
10330 調整の必要はなく,行が格納されているhboxの
10331 \texttt{glue\_set}, \texttt{glue\_sign}, \texttt{glue\_order}を再計算すればよい.
10332 以降,$\textit{total}\neq 0$と仮定する.
10333  \item \textit{total}が「\textbf{JAglue}以外のグルーの伸び量の合計」(以下,(A)の伸び量の
10334        合計,と称す)よりも小さければ,
10335 それらのグルーに\textit{total}を負担させ,\textbf{JAglue}達自身は自然長で組むことができる.
10336 よって,以下の処理を行う:
10337 \begin{enumerate}
10338 \item 各\textbf{JAglue}の伸び量を0とする.
10339 \item 行が格納されているhboxの
10340 \texttt{glue\_set}, \texttt{glue\_sign}, \texttt{glue\_order}を再計算する.
10341 これによって,\textit{total}は\textbf{JAglue}以外のグルーによって負担される.
10342 \end{enumerate}
10343 \item \textit{total}が「(A)の伸び量の合計」以上ならば,(A)--(K)のどこまで負担すれば
10344 \textit{total}以上になるかを計算する.
10345 例えば,
10346 \[\catcode`\<=12
10347  \textit{total} = (\text{(A)--(B)の伸び量の合計}) + p\cdot (\text{(C)の伸び量の合計}),
10348  \qquad 0\le p<1
10349 \]
10350 であった場合,各グルーは次のように組まれる:
10351 \begin{itemize}
10352  \item (A),~(B)に属するグルーは各グルーで許された伸び量まで伸ばす.
10353  \item (C)に属するグルーはそれぞれ$p\times (\text{伸び量})$だけ伸びる.
10354  \item (D)--(K)に属するグルーは自然長のまま.
10355 \end{itemize}
10356 実際には,前に述べた「設計」に従い,次のように処理している:
10357 \begin{enumerate}
10358 \item (C)に属するグルーの伸び量を$p$倍する.
10359 \item (D)--(K)に属するグルーの伸び量を0とする.
10360 \item 行が格納されているhboxの
10361 \texttt{glue\_set}, \texttt{glue\_sign}, \texttt{glue\_order}を再計算する.
10362 これによって,\textit{total}は\textbf{JAglue}以外のグルーによって負担される.
10363 \end{enumerate}
10364 \item \textit{total}が(A)--(K)の伸び量の合計よりも大きい場合,どうしようもないので
10365       \verb+^^;+何もしない.
10366 \end{enumerate}
10367
10368 %</ja>
10369
10370 %<*ja>
10371 \section{IVS対応}
10372 \verb+luatexja.otf.enable_ivs()+ を実行し,IVS対応を有効にした状態では,
10373 \verb+pre_linebreak_filter+ や \verb+hpack_filter+ コールバックには
10374 次の4つが順に実行される状態となっている:
10375 \begin{description}
10376 \item[\tt ltj.do\_ivs] \textit{glyph\_node}~$p$の直後に,異体字セレクタ(を表す\textit{glyph\_node})
10377 が連続した場合に,$p$のフォントに対応したが持つ「異体字情報」に従って出力するグリフを変える.
10378
10379 しかし,単に$p.\textit{char}$を変更するだけでは,後から
10380 OpenType機能の適用(すぐ下)により置換される可能性がある.そのため,
10381 \cs{CID} や \cs{UTF} と同じように,\textit{glyph\_node}~$p$の代わりに
10382 \texttt{user\_id} が\textit{char\_by\_cid}であるようなuser-defined whatsitを用いている.
10383 \item[(\Pkg{luaotfload} によるfont featureの適用)]
10384 \item[\tt ltj.otf] \texttt{user\_id} が\textit{char\_by\_cid}であるようなuser-defined whatsitを
10385 きちんと\textit{glyph\_node}に変換する.この処理は,\cs{CID}, \cs{UTF}やIVSによる置換が,
10386 OpenType機能の適用で上書きされてしまうのを防止するためである.
10387 \item[\tt ltj.main\_process] \textbf{JAglue}の挿入処理(\ref{sec-jfmglue}章)と,
10388 JFMの指定に従って各\textbf{JAchar}の「寸法を補正」することを行う.
10389 \end{description}
10390
10391 問題は各フォントの持っているIVS情報をどのように取得するか,である.
10392 \Pkg{luaotfload} はフォント番号<font\_number>の情報を\
10393 \texttt{fonts.hashes.identifiers[<font\_number>]} 以下に格納している.
10394 しかし,OpenTypeフォントのIVS情報は格納されていないようである%
10395 \footnote{TrueTypeフォントに関しては,
10396 \begin{center}
10397 \texttt{fonts.hashes.idenfiers[<font\_number>]%
10398   .resources.variants[<selector>][<base\_char>]}
10399 \end{center}
10400 に,<base\_char>番の文字の後に異体字セレクタ<selector>が続いた場合に
10401 出力すべきグリフが書かれてある.}.
10402 %例えば,小塚明朝Pr6N~Rでは,
10403
10404 一方,\LuaTeX 内部の \texttt{fontloader} の返すテーブルには
10405 OpenTypeフォントでもTrueTypeフォントでもIVS情報が格納されている.
10406 具体的には……
10407
10408 そのため,\LuaTeX-jaのIVS対応においては,\LuaTeX 内部の\
10409 \texttt{fontloader} を直接用いることで,フォントのIVS情報を取得している.
10410 20140114.0以降でキャッシュを用いるようにした要因はここにあり,
10411 \texttt{fontloader} の呼び出しでかなり時間を消費することから,
10412 %%% to_table を使わなくしたことで,メモリ使用量は減った
10413 IVS情報をキャッシュに保存することで2回目以降の実行時間を節約している.
10414 %</ja>
10415
10416
10417 %<*ja>
10418 \section{複数フォントの「合成」(未完)}
10419 \section{\LuaTeX-jaにおけるキャッシュ}
10420 \Pkg{luaotfload}パッケージが,各TrueType・OpenTypeフォントの情報を
10421 キャッシュとして保存しているのと同様の方法で,
10422 \LuaTeX-jaもいくつかのキャッシュファイルを作成するようになった.
10423 \begin{itemize}
10424  \item 通常,キャッシュは\texttt{\$TEXMFVAR/luatexja/}以下に保存され,
10425 そこから読み込みが行われる.
10426  \item 「通常の」テキスト形式のキャッシュ(拡張子は \texttt{.lua})以外にも,
10427 それをバイナリ形式(バイトコード)に変換したものもサポートしている.
10428 \begin{itemize}
10429  \item \LuaTeX とLuaJIT\TeX ではバイトコードの形式が異なるため,バイナリ形式の
10430 キャッシュは共有できない.\LuaTeX 用のバイナリキャッシュは \texttt{.luc},
10431 LuaJIT\TeX 用のは \texttt{.lub} と拡張子を変えることで対応している.
10432  \item キャッシュを読み込む時,同名のバイナリキャッシュがあれば,
10433 テキスト形式のものよりそちらを優先して読み込む.
10434  \item テキスト形式のキャッシュが更新/作成される際は,そのバイナリ版も
10435 同時に更新される.
10436 また,(バイナリ版が見つからず)テキスト形式のキャッシュ側が読み込まれたときは,
10437 \LuaTeX-jaはバイナリキャッシュを作成する.
10438 \end{itemize}
10439 \end{itemize}
10440 %</ja>
10441 %<*en>
10442 \section{Cache Management of \LuaTeX-ja}
10443 \LuaTeX-ja creates some cache files to reduce the loading time.
10444 in a similar way to the \Pkg{luaotfload} package:
10445 \begin{itemize}
10446  \item Cache files are usually stored in (and loaded from)
10447 \texttt{\$TEXMFVAR/luatexja/}.
10448  \item In addition to caches of the text form (the extension is ``\texttt{.lua}''),
10449 caches of the \emph{binary}, precompiled form are supported.
10450 \begin{itemize}
10451  \item We cannot share same binary cache for \LuaTeX\ and LuaJIT\TeX.
10452 Hence we distinguish them by their extension, ``\texttt{.luc}'' for \LuaTeX\
10453 and ``\texttt{.lub}'' for LuaJIT\TeX.
10454  \item In loading a cache, the binary cache precedes
10455 the text form.
10456  \item When \LuaTeX-ja updates a cache \texttt{hoge.lua},
10457 its binary version is also updated.
10458 \end{itemize}
10459 \end{itemize}
10460 %</en>
10461
10462 %<*ja>
10463 \subsection{キャッシュの使用箇所}
10464
10465 \LuaTeX-ja では以下の3種類のキャッシュを使用している:
10466 \begin{cslist}
10467 \item[ltj-cid-auto-adobe-japan1.lua]
10468 Ryumin-Lightのような非埋め込みフォントの情報を格納しており,
10469 (それらが\LuaTeX-jaの標準和文フォントなので)\LuaTeX-jaの読み込み時に自動で読まれる.
10470 生成には\texttt{UniJIS2004-UTF32-\{H, V\}}, \texttt{Adobe-Japan1-UCS2}という3つの
10471 CMapが必要である.
10472
10473 \pageref{para-cid}ページで述べたように,\texttt{cid}キーを使って
10474 非埋め込みの中国語・韓国語フォントを定義する場合,同様のキャッシュが生成される.
10475 キャッシュの名称,必要となるCMapについては\autoref{tab:cid-cache}を参照して欲しい.
10476
10477 \item[extra\_***.lua]
10478 フォント``\texttt{***}''における異体字セレクタの情報,縦組用字形への変換テーブル,そして
10479 縦組時における幅を格納している.構造は以下の通り:
10480 %</ja>
10481 %<*en>
10482 \subsection{Use of cache}
10483
10484 \LuaTeX-ja uses the following cache:
10485 \begin{cslist}
10486 \item[ltj-cid-auto-adobe-japan1.lua]
10487 The font table of a CID-keyed non-embedded Japanese font.
10488 This is loaded in every run.
10489 It is created from three CMaps, \texttt{UniJIS2004-UTF32-\{H,V\}} and
10490              \texttt{Adobe-Japan1-UCS2},
10491 and this is why these two CMaps are needed in the first run of \LuaTeX-ja.
10492
10493 Similar caches are created as \autoref{tab:cid-cache},
10494 if you specified \texttt{cid} key in \cs{jfont}
10495 to use other CID-keyed non-embedded fonts for Chinese or Korean,
10496 as in Page~\pageref{para-cid}.
10497
10498 \item[extra\_***.lua]
10499 This file stores the table which stores the following.
10500 \begin{itemize}
10501  \item unicode variants in a font ``\texttt{***}''
10502  \item vertical width of glyphs, if it is not equal to the sum of
10503 the height of ascender and the depth of descender
10504  \item vertical variants
10505 \end{itemize}
10506 The following is the structure of the that table.
10507 %</en>
10508
10509 \begin{table}[!tb]
10510  \centering\small
10511 \caption{\texttt{cid} key and corresponding files}
10512 \label{tab:cid-cache}
10513 \vspace*{\medskipamount}
10514 \begin{tabular}{>{\tt}l>{\tt}l>{\tt}l>{\tt}l}
10515 \toprule
10516 \bf \texttt{cid} key&\bf name of the cache &
10517 \multicolumn{2}{c}{\bf used CMaps}\\
10518 \midrule
10519 Adobe-Japan1-*&ltj-cid-auto-adobe-japan1.lua&UniJIS2004-UTF32-*&Adobe-Japan1-UCS2\\
10520 Adobe-Korea1-*&ltj-cid-auto-adobe-korea1.lua&UniKS-UTF32-*&Adobe-Korea1-UCS2\\
10521 Adobe-GB1-*&ltj-cid-auto-adobe-gb1.lua&UniGB-UTF32-*&Adobe-GB1-UCS2\\
10522 Adobe-CNS1-*&ltj-cid-auto-adobe-cns1.lua&UniCNS-UTF32-*&Adobe-CNS1-UCS2\\
10523 \bottomrule
10524 \end{tabular}
10525 \end{table}
10526
10527 \begin{lstlisting}
10528 return {
10529  {
10530   [10955]={    -- U+2ACB "Subset Of Above Not Equal To"
10531    [65024]=983879, -- <2ACB FE00>
10532    ["vwidth"]=0.98, -- vertical width
10533   },
10534   [37001]={    -- U+9089 "邉"
10535    [0]=37001,  --   <9089 E0100>
10536    991049,     --   <9089 E0101>
10537    ...
10538    ["vform"]=995025, -- vertical variant
10539   },
10540   ...
10541   ["unicodes"]={
10542     ["aj102.pe.vert"]=984163, -- glyph name to unicode
10543     ...
10544   }
10545  },
10546  ["chksum"]="FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", -- checksum of the fontfile
10547  ["version"]=11, -- version of the cache
10548 }
10549 \end{lstlisting}
10550 %<*ja>
10551 \item[ltj-jisx0208.\{luc|lub\}]
10552 \LuaTeX-ja配布中の\texttt{ltj-jisx0208.lua}をバイナリ化したものである.
10553 これはJIS~X~0208とUnicodeとの変換テーブルであり,
10554 \pTeX との互換目的の文字コード変換命令で用いられる.
10555 %</ja>
10556 %<*en>
10557 \item[ltj-jisx0208.\{luc|lub\}]
10558 The binary version of \texttt{ltj-jisx0208.lua}.
10559 This is the conversion table between JIS~X~0208 and Unicode
10560 which is used in Kanji-code conversion commands for compatibility with \pTeX.
10561 %</en>
10562 \end{cslist}
10563
10564 %<*en>
10565 \subsection{Internal}
10566 Cache management system of \LuaTeX-ja is stored in \texttt{luatexja.base}
10567 (\texttt{ltj-base.lua}).
10568 There are three public functions for cache management in \texttt{luatexja.base},
10569 where <filename> stands for the file name \emph{without suffix}:
10570 \begin{cslist}
10571 \item[save\_cache(<filename>, <data>)]
10572 Save a non-nil table <data> into a cache <filename>.
10573 Both the text form <filename>\texttt{.lua} and its binary version
10574 are created or updated.
10575
10576 \item[save\_cache\_luc(<filename>, <data>{[, <serialized\_data>]})]
10577
10578 Same as \texttt{save\_cache}, except that only the binary cache is updated.
10579 The third argument <serialized\_data> is not usually given.
10580 But if this is given, it is treated as a string representation of <data>.
10581
10582 \item[load\_cache(<filename>, <outdate>)]
10583 Load the cache <filename>.
10584 <outdate> is a function which takes one argument (the contents of the cache),
10585 and its return value is whether the cache is outdated.
10586
10587 \texttt{load\_cache} first tries to
10588 read the binary cache <filename>\texttt{.\{luc|lub\}}.
10589 If its contents is up-to-date, \texttt{load\_cache} returns the contents.
10590 If the binary cache is not found or
10591 its contents is outdated, \texttt{load\_cache} tries to
10592 read the text form <filename>\texttt{.lua}.
10593 Hence, the return value of \texttt{load\_cache} is non-nil,
10594 if and only if the updated cache is found.
10595 \end{cslist}
10596 %</en>
10597 %<*ja>
10598 \subsection{内部命令}
10599 \LuaTeX-jaにおけるキャッシュ管理は,\texttt{luatexja.base}~(\texttt{ltj-base.lua})に
10600 実装しており,以下の3関数が公開されている.
10601 ここで,<filename>は保存するキャッシュのファイル名を\emph{拡張子なしで}指定する.
10602 \begin{cslist}
10603 \item[save\_cache(<filename>, <data>)]
10604 nilでない<data>をキャッシュ<filename>に保存する.
10605 テキスト形式の<filename>\texttt{.lua}のみならず,
10606 そのバイナリ版も作成/更新される.
10607
10608 \item[save\_cache\_luc(<filename>, <data>{[, <serialized\_data>]})]
10609
10610 \texttt{save\_cache}と同様だが,バイナリキャッシュのみが更新される.
10611 第3引数<serialized\_data>が与えられた場合,それを
10612 <data>の文字列化表現として使用する.
10613 そのため,<serialized\_data>は普通は指定しないことになるだろう.
10614
10615 \item[load\_cache(<filename>, <outdate>)]
10616 キャッシュ<filename>を読み込む.
10617 <outdate>は1引数(キャッシュの中身)をとる関数であり,
10618 その戻り値は「キャッシュの更新が必要」かどうかを示すブール値でないといけない.
10619
10620 \texttt{load\_cache}は,まずバイナリキャッシュ<filename>\texttt{.\{luc|lub\}}を
10621 読みこむ.もしその内容が「新しい」,つまり<outdate>の評価結果が \texttt{false} なら
10622 \texttt{load\_cache}はこのバイナリキャッシュの中身を返す.
10623 もしバイナリキャッシュが見つからなかったか,「古すぎる」ならばテキスト版
10624              <filename>\texttt{.lua}を読み込み,その値を返す.
10625
10626 以上より,\texttt{load\_cache}自体がnilでない値を返すのは,ちょうど「新しい」キャッシュが
10627 見つかった場合である.
10628 \end{cslist}
10629 %</ja>
10630
10631
10632 %<*ja>
10633 \section{縦組の実装}
10634 \label{sec-dir-imp}
10635 \ref{sec-direction}章の最初でも述べたように,
10636 \LuaTeX-jaは横組(\texttt{TLT})で組んだボックスを回転させる方式で
10637 縦組を実装している.
10638
10639 \LuaTeX-jaにおける縦組の実装は
10640 \pTeX における実装(\cite{ptexdoc,ptextug})をベースにしている.
10641
10642 \subsection{direction~whatsit}
10643 \textit{direction}~whatsitとは,\textit{direction}という特定の \verb+user_id+ を持つ
10644 whatsitのことであり,以下のタイミングで作られる.
10645 \begin{itemize}
10646  \item 組方向を \cs{tate} 等で変更したとき.
10647  \item \cs{hbox}, \cs{vbox}, \cs{vtop} による明示的なボックスの開始時.\\
10648 \verb+\hbox{}+, \verb+\vbox{}+ といった,
10649 \begin{itemize}
10650  \item \cs{tate} 等によりボックス内部の組方向を変更していない
10651  \item ボックスの中身のリストが空である
10652 \end{itemize}
10653 場合は,\LuaTeX の \verb+hpack_filter+, \verb+vpack_filter+ といった
10654 callbackに処理が回らない.そこで,\LuaTeX-ja では,\cs{everyhbox}, \cs{everyvbox} を利用す
10655        ることで各ボックスの先頭に確実に追加するようにしている\footnote{%
10656   問題は \cs{hbox to 25pt\{\}} という状況である.実際のこのボックスの中身は空でない(少な
10657        くともdirection whatsitがある)ため,何も対策をしなければhpack時にUnderfill警告が発
10658        生してしまうことになる.\LuaTeX-jaではそうならないように「\cs{hbadness},
10659        \cs{vbadness} を一時的に10000に変更し,hpack, vpack後に元の値に戻す」処理を行ってい
10660        る.
10661 }.
10662  \item \cs{vsplit}によってvboxを分割した時の「残り」の先頭.
10663  \item \LuaTeX-ja読み込み前に作成したボックスの寸法を \cs{ltjsetwd} 等によって変更した時.
10664  \item \cs{insert} によるinsertionでは,中身の先頭に\textit{direction}~whatsitは作られず,
10665 その代わりに中身の各ボックス・罫線の直前に作られる\footnote{%
10666  これは,ページ分割の過程でinsertionが分割される時,「現在のページで出力される部分」が空と
10667        なることがあることによる.先頭にwhatsitを置くと,最悪でも「現在のページにwhatsitが
10668        残る」ことになってしまう.}.
10669 \end{itemize}
10670 なお,\verb+\vtop{...}+ の場合は,先頭にdirection whatsitを置くと
10671 ボックスの高さが常に0\,ptになるという問題が発生する.そのため,この場合に限っては
10672 vpack時にdirection whatsitをリストの2番目に移動させている.
10673
10674 direction whatsitはあくまでも組方向処理のための補助的なノードであるので,
10675 \cs{unhbox}, \cs{unhcopy} によってボックスの中身が展開される時には展開直前に削除される.
10676 これは
10677 \begin{lstlisting}
10678  % yoko direction
10679 \setbox0=\hbox{\tate B}
10680 \noindent % 水平モードに入る.この時点でのリストの中身は空
10681 \unhbox0 A
10682 \end{lstlisting}
10683 といった場合に,段落が縦組で組まれたり,あるいは
10684 \begin{lstlisting}
10685 \setbox0=\hbox{}
10686 \leavevmode \hbox{A}\unhbox0
10687 \setbox1=\lastbox % \box1 はどうなる?
10688 \end{lstlisting}
10689 で \cs{box1} が \cs{hbox\{A\}} でなく空になってしまうことを防ぐためである.
10690
10691
10692 \subsection{\textit{dir\_box}}
10693 縦中横など異方向のボックスを配置する場合に,周囲の組方向と大きさを整合させるため,
10694 \LuaTeX-jaでは \verb+\ltj@dir+ が128以降の\textit{hlist\_node}, \textit{vlist\_node}を
10695 用いる.これらは\pTeX における\textit{dir\_node}の役割と同じ果たしており,
10696 この文章中では\textit{dir\_box}と呼称する.
10697
10698 \subsubsection{異方向のボックスの整合}
10699 \textit{dir\_box}の第一の使用目的は,異方向のボックスの大きさを整合させることである.
10700 例えば,
10701 \begin{lstlisting}
10702  % yoko direction
10703 平成\hbox{\tate 26}年
10704 \end{lstlisting}
10705 は段落中で
10706 \[
10707  \xymatrix{
10708    {}\Node{glyph}{`平'}\ar[r]&{}\Node{glyph}{`成'}\ar[r]&
10709    {}\HNode{hbox}{10.00003}{3.02779}{0.0}\ar[r]\ar[d]^{\text{中身}}&{}\Node{glyph}{`年'}\\
10710    &&{}\Node{whatsit}{\cs{tate}}\ar[r]&{}\Node{glyph}{`2'}\ar[r]&{}\Node{glyph}{`6'}
10711  }
10712 \]
10713 というリストを作る.その後,この段落が終了したときに,
10714 \LuaTeX-jaの\textbf{JAglue}挿入処理が行われ
10715 \[
10716  \xymatrix{
10717    {}\Node{glyph}{`平'}\ar[r]
10718   &{}\textcolor{blue}{\Node{glue}{\Param{xkanjiskip}}}\ar[r]
10719   &{}\Node{glyph}{`成'}\ar[r]
10720   &{}\textcolor{blue}{\Node{penalty}{0}}
10721     \ar`r[d] `[l] `[ddll] `[dl] [dl]
10722   \\
10723   &&{}\textcolor{red}{\HNode{\textit{dir\_box} (\cs{yoko})}{3.02779}{10.00003}{0.0}}\ar[r]\ar[d]^{\text{中身}}
10724   &{}\textcolor{blue}{\Node{penalty}{0}}\ar[r]
10725   &{}\Node{glyph}{`年'}\\
10726   &&{}\HNode{hbox}{10.00003}{3.02779}{0.0}\ar[d]^{\text{中身}}\\
10727   &&{}\Node{whatsit}{\cs{tate}}\ar[r]&{}\Node{glyph}{`2'}\ar[r]&{}\Node{glyph}{`6'}
10728  }
10729 \]
10730 のようになる(青字は\textbf{JAglue},赤字が整合処理のための\textit{dir\_box}である).
10731 \TeX の \cs{showbox} 形式で書けば
10732
10733 \medskip{\narrowbaselines\ttfamily\obeylines\parindent0pt
10734 \catcode`\@=0 @catcode`@\=12
10735 .\tenmin 平
10736 @textcolor{blue}{.\glue 0.0 plus 0.4 minus 0.4}
10737 .\tenmin 成
10738 @textcolor{blue}{.\penalty 0}
10739 @textcolor{red}{.\hbox(10.00003+0.0)x3.02779, direction TLT}
10740 ..\hbox(3.02779+0.0)x10.00003, direction TLT
10741 ...\whatsit4=[]
10742 ...\tenrm 2
10743 ...\tenrm 6
10744 @textcolor{blue}{.\penalty 0}
10745 .\tenmin 年
10746 }\medskip
10747
10748 \noindent である.
10749
10750 なお,\cs{raise},~\cs{lower}, \cs{moveleft},~\cs{moveright} といったボックス移動命令では.
10751 移動を正しく表現するために段落やボックスの途中でも異方向のボックスは\textit{dir\_box}にカ
10752 プセル化している.
10753 例えば
10754 \begin{lstlisting}
10755  % yoko direction
10756 平成\raise1pt\hbox{\tate 26}年\showlists
10757 \end{lstlisting}
10758 は以下のような結果を得る.
10759
10760 \medskip{\narrowbaselines\ttfamily\obeylines\parindent0pt
10761 \catcode`\@=0 @catcode`@\=12
10762 (前略)
10763 \tenrm 平
10764 \tenrm 成
10765 @textcolor{red}{\hbox(10.00003+0.0)x3.02779, shifted -1.0, direction TLT}
10766 .\hbox(3.02779+0.0)x10.00003, direction TLT
10767 ..\whatsit4=[]
10768 ..\tenrm 2
10769 ..\tenrm 6
10770 \tenrm 年
10771 }\medskip
10772
10773 また,メインの垂直リストに異方向のボックスが追加される場合にも同様に即座に
10774 \textit{dir\_box}にカプセル化している.ページ分割のタイミングを正
10775 しく\TeX が判断するためである.
10776 \cs{lastbox} によるボックスの取得では,\textit{dir\_box}は削除される.
10777
10778 \subsubsection{異方向のボックス寸法の格納}
10779 第二の使用目的は,現在の組方向がボックス本来の組方向とは異なる状況で,
10780 \cs{ltjsetwd} によってボックス寸法を設定されたことを記録することである.
10781
10782 例えば
10783 \begin{lstlisting}[numbers=left]
10784 \setbox0=\hbox{\vrule width 10pt height 5pt depth 2pt}
10785 \setbox1=\hbox{\tate\ltjsetwd0=20pt}
10786 \wd0=9pt
10787 \setbox1=\hbox{\dtou\ltjsetwd0=20pt}
10788 \setbox0=\hbox{\dtou a\box0}
10789 \end{lstlisting}
10790 というコードを考える.1行目で \cs{box0} には横組の
10791 幅10\,pt,高さ5\,pt,深さ2\,ptのボックスが代入される.
10792 よって,
10793 \begin{itemize}
10794  \item 縦組下では \cs{box0} は幅7\,pt,高さ・深さ5\,ptのボックスとして扱われる.
10795  \item \cs{dtou} 下では \cs{box0} は幅7\,pt,高さ10\,pt,深さ0\,ptのボックスとして扱われる.
10796 \end{itemize}
10797 このとき,\cs{box0} の\emph{中身}は
10798 \[
10799  \xymatrix{
10800    {}\Node{whatsit}{\cs{yoko}}\ar[r]&{}\Node{rule}{}
10801  }
10802 \]
10803 である.
10804
10805 さて,2行目で縦組時の \cs{box0} の幅が20\,ptに設定される.この情報が
10806 direction~whatsit内部のノードリストに,\textit{dir\_box}として格納される:
10807 \[
10808  \xymatrix{
10809    {}\Node{whatsit}{\cs{yoko}}\ar[r]\ar[d]_{\text{中身}}&{}\Node{rule}{}\\
10810    {}\textcolor{red}{\HNode{\textit{dir\_box} (\cs{tate})}{20.0}{5.0}{5.0}}
10811  }
10812 \]
10813
10814 次に,3行目では横組時の,つまり \cs{box0} 本来の組方向での深さが9\,ptに変更される.
10815 このとき,\cs{box0} は
10816 \begin{itemize}
10817  \item 縦組下では寸法代入が既に行われているので,2行目で作成された\textit{dir\_box}の通り
10818        に幅20\,pt,高さ・深さ5\,ptのボックスとして扱われる.
10819  \item \cs{dtou} 下ではまだ寸法代入が行われていないので,
10820 \cs{box0} の寸法変更に追従し,幅7\,pt,高さ9\,pt,深さ0\,ptのボックスとして扱われる.
10821 \end{itemize}
10822
10823 4行目では \cs{dtou} 下での\cs{box0} の幅が20\,ptに設定されるので,2行目と同じように
10824 \[
10825  \xymatrix{
10826    {}\Node{whatsit}{\cs{yoko}}\ar[r]\ar[d]_{\text{中身}}&{}\Node{rule}{}\\
10827    {}\textcolor{red}{\HNode{\textit{dir\_box} (\cs{dtou})}{20.0}{9.0}{0.0}}\ar[r]&
10828    {}\HNode{\textit{dir\_box} (\cs{tate})}{20.0}{5.0}{5.0}
10829  }
10830 \]
10831 と\textit{dir\_box}が作成される.
10832
10833 このように寸法代入によってつくられた\textit{dir\_box}は,前節の整合過程のときに再利用され
10834 る.上記の例でいえば,5行目を実行した後の \cs{box0} の内容は
10835 \[
10836  \xymatrix{
10837    {}\Node{whatsit}{\cs{dtou}}\ar[r]&
10838    {}\Node{glyph}{`a'}\ar[r]&
10839    {}\textcolor{red}{\HNode{\textit{dir\_box} (\cs{dtou})}{20.0}{9.0}{0.0}}\ar[d]_{\text{中身}}\\
10840    &&{}\HNode{hbox}{9.0}{5.0}{2.0}\ar[d]_{\text{中身}}\\
10841    &&{}\Node{whatsit}{\cs{yoko}}\ar[r]&{}\Node{rule}{}
10842  }
10843 \]
10844 のようになる.
10845 %</ja>
10846
10847 \newpage
10848 \begin{thebibliography}{99}
10849   \addcontentsline{toc}{section}{\refname}
10850 \bibitem{texbytopic}
10851 Victor Eijkhout. \newblock \textit{\TeX\ by Topic, A \TeX nician's Reference}, Addison-Wesley, 1992.
10852 \bibitem{listings} C.\ Heinz, B.\ Moses. \newblock The \textsf{Listings} Package.
10853 \bibitem{uptex} Takuji Tanaka. \newblock
10854 upTeX---Unicode version of pTeX with CJK extensions,
10855 TUG 2013, October 2013.
10856 %<ja>\newblock
10857 %<en>\\\null\hfill
10858 \url{http://tug.org/tug2013/slides/TUG2013_upTeX.pdf}
10859 \bibitem{jlisting} Thor Watanabe. \newblock Listings\ -\ MyTeXpert.
10860 %<en>\newblock
10861 %<ja>\\\null\hfill
10862 \url{http://mytexpert.osdn.jp/index.php?Listings}
10863 \bibitem{jlreq}  W3C Japanese Layout Task Force~(ed). \newblock
10864 Requirements for Japanese Text Layout (W3C Working Group Note), 2011, 2012. \newblock
10865 \url{http://www.w3.org/TR/jlreq/}%
10866 %<ja> \\日本語訳の書籍版:W3C日本語組版タスクフォース(編),『W3C技術ノート 日本語組版処理の要件』,東京電機大学出版局,2012.
10867 \bibitem{min10} 乙部厳己.min10フォントについて.\\\null\hfill
10868 \url{http://argent.shinshu-u.ac.jp/~otobe/tex/files/min10.pdf}
10869 \bibitem{x4051} 日本工業規格(Japanese Industrial Standard). JIS~X~4051,
10870 日本語文書の組版方法(Formatting rules for Japanese documents), 1993, 1995, 2004.
10871 \bibitem{ptexdoc} 濱野尚人,田村明史,倉沢良一.\TeX の出版への応用—縦組み機能の組み込み—.
10872 \\\null\hfill\texttt{.../texmf-dist/doc/ptex/base/ptexdoc.pdf}
10873 \bibitem{ptextug} Hisato Hamano. \newblock
10874 \textit{Vertical Typesetting with \TeX}, TUGBoat~\textbf{11}(3), 346--352, 1990.
10875 \bibitem{pdfstd} International Organization for Standardization. \newblock
10876 ISO 32000-1:2008, \textit{Document management -- Portable document format -- Part 1: PDF
10877       1.7}, 2008. \newblock
10878 \\\null\hfill
10879 \url{http://www.iso.org/iso/iso\_catalogue/catalogue_tc/catalogue\_detail.htm?csnumber=51502}
10880 \end{thebibliography}
10881
10882 \end{document}
10883 %</!showexpl>
10884 %<*showexpl>
10885 %%
10886 %% config file for showexpl.sty
10887 %%
10888 %% Copyright The LuaTeX-ja project team, 2012
10889 %%
10890 \ProvidesFile{showexpl.cfg}
10891   [2012/05/20 v0.01 Definitions for the showexpl package (luatexja)]
10892 \lstset{}
10893 \def\SX@Info{}
10894 \endinput
10895 %</*showexpl>