1 %#! lualatex -shell-escape manual.ins
4 \documentclass[a4paper,titlepage]{article}
5 \usepackage[margin=20mm,footskip=5mm]{geometry}
8 \documentclass[a4paper,titlepage]{bxjsarticle}
9 \setpagelayout*{margin=20mm,footskip=5mm}
10 \def\headfont{\normalfont\bfseries}
11 % \def\headfont{\sffamily\gtfamily} is needed in ordinal documents
12 % This document cannot typeset in ltjsclasses (conflict with showexpl?)
15 \usepackage{amsmath,amssymb,xcolor,pict2e,multienum,amsthm,float}
16 \usepackage{booktabs,listings,lltjlisting,showexpl,multicol}
17 \usepackage{luatexja-otf}
18 \usepackage[unicode=false]{hyperref}
22 \DeclareRobustCommand\eTeX{\ensuremath{\varepsilon}-\kern-.125em\TeX}
23 \DeclareRobustCommand\LuaTeX{Lua\TeX}
24 \DeclareRobustCommand\pdfTeX{pdf\TeX}
25 \DeclareRobustCommand\pTeX{p\kern-.05em\TeX}
26 \DeclareRobustCommand\upTeX{p\kern-.05em\TeX}
27 \DeclareRobustCommand\pLaTeX{p\kern-.05em\LaTeX}
28 \DeclareRobustCommand\pLaTeXe{p\kern-.05em\LaTeXe}
29 \DeclareRobustCommand\epTeX{\ensuremath{\varepsilon}-\kern-.125em\pTeX}
31 \theoremstyle{definition}
32 \newtheorem{defn}{Definition}
34 \newenvironment{cslist}{%
35 \leftskip2em\parindent=0pt\def\makelabel##1{{\tt\char92##1}}
36 \def\{{\char`\{}\def\}{\char`\}}
38 \def\item[##1]{\par\smallskip\par\hskip-\leftskip\makelabel{##1}\par}
42 \long\def\@makecaption#1#2{%
43 \vskip\abovecaptionskip
44 \sbox\@tempboxa{{\small #1. #2}}%
45 \ifdim \wd\@tempboxa >\hsize
48 \global \@minipagefalse
49 \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
51 \vskip\belowcaptionskip}
55 \title{The \LuaTeX-ja package}
56 \author{The \LuaTeX-ja project team}
59 \title{\LuaTeX-jaパッケージ}
60 \author{\LuaTeX-jaプロジェクトチーム}
64 basicstyle=\ttfamily\small, pos=o, breaklines=true,
65 numbers=none, rframe={}, basewidth=0.5em
68 \parskip=\smallskipamount
69 \protected\def\Param#1{\textsf{#1}} % parameter name
70 \protected\def\Pkg#1{\underline{\smash{\texttt{#1}}}} % packages/classes
74 \def<#1>{{\normalfont\rm\itshape$\langle$#1$\rangle$}}
81 {\Large\bf This documentation is far from complete. It may have many
82 grammatical (and contextual) errors.}
85 \textbf{\large 本ドキュメントはまだまだ未完成です.
86 また,英語版と日本語版をdocstripプログラムを用いることで一緒に生成している都合上,
93 \section{Introduction}
96 The \LuaTeX-ja package is a macro package for typesetting high-quality
97 Japanese documents when using \LuaTeX.
100 \LuaTeX-jaパッケージは,次世代標準\TeX である\LuaTeX の上で,\pTeX と同等
101 /それ以上の品質の日本語組版を実現させようとするマクロパッケージである.
104 \subsection{Backgrounds}
106 Traditionally, ASCII \pTeX, an extension of \TeX, and its derivatives
107 are used to typeset Japanese documents in \TeX. \pTeX\ is an engine
108 extension of \TeX: so it can produce high-quality Japanese documents
109 without using very complicated macros. But this point is a mixed
110 blessing: \pTeX\ is left behind from other extensions of \TeX,
111 especially \eTeX\ and pdf\TeX, and from changes about
112 Japanese processing in computers (\textit{e.g.}, the UTF-8 encoding).
114 Recently extensions of \pTeX, namely \upTeX\ (Unicode-implementation
115 of \pTeX) and \epTeX\ (merging of \pTeX\ and
116 \eTeX\ extension), have developed to fill those gaps to some
117 extent, but gaps still exist.
119 However, the appearance of \LuaTeX\ changed the whole situation. With
120 using Lua `callbacks', users can customize the internal processing of
121 \LuaTeX. So there is no need to modify sources of engines to
122 support Japanese typesetting: to do this, we only have to write Lua
123 scripts for appropriate callbacks.
126 従来,「\TeX を用いて日本語組版を行う」といったとき,エンジンとしては
127 ASCII \pTeX やそれの拡張物が用いられることが一般的であった.\pTeX は\TeX
128 のエンジン拡張であり,(少々仕様上不便な点はあるものの)商業印刷の分野に
129 も用いられるほどの高品質な日本語組版を可能としている.だが,それは弱点に
130 もなってしまった:\pTeX という(組版的に)満足なものがあったため,海外で
131 行われている数々の\TeX の拡張──例えば\eTeX や\pdfTeX ──や,TrueType,
132 OpenType, Unicodeといった計算機で日本語を扱う際の状況の変化に追従すること
135 ここ数年,若干状況は改善されてきた.現在手に入る大半の\pTeX バイナリでは
136 外部UTF-8入力が利用可能となり,さらにUnicode化を推進し,\pTeX の内部処理
137 までUnicode化した\upTeX も開発されている.また,\pTeX に\eTeX 拡張をマー
138 ジした\epTeX も登場し,\TeX\ Live\ 2011では\pLaTeX が\epTeX の上で動作す
139 るようになった.だが,\pdfTeX 拡張(pdf直接出力やmicro-typesetting)を
140 \pTeX に対応させようという動きはなく,海外とのgapは未だにあるのが現状であ
143 しかし,\LuaTeX の登場で,状況は大きく変わることになった.Luaコードで
144 `callback'を書くことにより,\LuaTeX の内部処理に割り込みをかけることが可
145 能となった.これは,エンジン拡張という真似をしなくても,Luaコードとそれに
146 関する\TeX マクロを書けば,エンジン拡張とほぼ同程度のことができるようになっ
147 たということを意味する.\LuaTeX-jaは,このアプローチによってLuaコード・
148 \TeX マクロによって日本語組版を\LuaTeX の上で実現させようという目的で開発
152 \subsection{Major Changes from \pTeX}
154 The \LuaTeX-ja package is under much influence of \pTeX\ engine. The initial
155 target of development was to implement features of \pTeX. However,
156 \emph{\LuaTeX-ja is not a just porting of \pTeX; unnatural
157 specifications/behaviors of \pTeX\ were not adopted}.
161 \LuaTeX-jaは,\pTeX に多大な影響を受けている.初期の開発目標は,\pTeX の機
162 能をLuaコードにより実装することであった.しかし,開発が進むにつれ,\pTeX
163 の完全な移植は不可能であり,また\pTeX における実装がいささか不可解になっ
164 ているような状況も発見された.そのため,\textbf{\LuaTeX-ja は,もはや
165 \pTeX の完全な移植は目標とはしない.\pTeX における不自然な仕様・挙動があ
169 The followings are major changes from \pTeX:
171 \item A Japanese font is a tuple of a `real' font, a Japanese font
172 metric (\textbf{JFM}, for short), and an optional string called
175 \item In \pTeX, a linebreak after Japanese character is ignored (and
176 doesn't yield a space), since linebreaks (in source files) are
177 permitted almost everywhere in Japanese texts. However, \LuaTeX-ja
178 doesn't have this function completely, because of a specification
180 \item The insertion process of glues/kerns between two Japanese
181 characters and between a Japanese character and other characters
182 (we refer these glues/kerns as \textbf{JAglue}) is rewritten from
186 \item As \LuaTeX's internal character handling is `node-based'
187 (\textit{e.g.}, \verb+of{}fice+ doesn't prevent ligatures), the
188 insertion process of \textbf{JAglue} is now `node-based'.
189 \item Furthermore, nodes between two characters which have no effects in
190 linebreak (\textit{e.g.}, \verb+\special+ node) are ignored in the
192 \item In the process, two Japanese fonts which differ in their `real'
193 fonts only are identified.
195 \item At the present, vertical typesetting (\emph{tategaki}), is not
196 supported in \LuaTeX-ja.
199 For detailed information, see Part~\ref{part-imp}.
201 \subsection{Notations}
202 In this document, the following terms and notations are used:
204 \item Characters are divided into two types:
206 \item \textbf{JAchar}: standing for Japanese characters such as
207 Hiragana, Katakana, Kanji and other punctuation marks for
209 \item \textbf{ALchar}: standing for all other characters like alphabets.
211 We say `alphabetic fonts' for fonts used in \textbf{ALchar}, and `Japanese fonts' for fonts used in \textbf{JAchar}.
213 \item A word in a sans-serif font (like \Param{prebreakpenalty})
214 means an internal parameter for Japanese typesetting, and it
215 is used as a key in \verb+\ltjsetparameter+ command.
216 \item A word in typewriter font with underline (like \Pkg{fontspec})
217 means a package of a class of \LaTeX.
218 \item The word `primitive' is used not only for primitives in \LuaTeX,
219 but also for control sequences that defined in the core module of
221 \item In this document, natural numbers start from~0.
224 \subsection{About the project}
225 \paragraph{Project Wiki} Project Wiki is under construction.
227 \item \url{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage%28en%29} (English)
228 \item \url{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage} (Japanese)
231 This project is hosted by SourceForge.JP.
235 \begin{multienumerate}
236 \def\labelenumi{$\bullet$}
237 \mitemxxx{Hironori KITAGAWA}{Kazuki MAEDA}{Takayuki YATO}
238 \mitemxxx{Yusuke KUROKI}{Noriyuki ABE}{Munehiro YAMAMOTO}
239 \mitemx{Tomoaki HONDA}
243 \begin{multienumerate}
244 \def\labelenumi{$\bullet$}
245 \mitemxxx{Hironori KITAGAWA}{Kazuki MAEDA}{Takayuki YATO}
246 \mitemxxx{Yusuke KUROKI}{Noriyuki ABE}{Munehiro YAMAMOTO}
247 \mitemx{Tomoaki HONDA}
252 % \paragraph{Acknowledgments} -- 挿入するならここ
255 \section{Getting Started}
256 \subsection{Installation}
257 To install the \LuaTeX-ja\ package, you will need:
259 \item \LuaTeX\ (version 0.65.0-beta or later) and its supporting packages.\\
260 If you are using \TeX~Live~2011 or current W32\TeX, you don't have to worry.
261 \item The source archive of \LuaTeX-ja, of course{\tt:)}
264 The installation methods are as follows:
266 \item Download the source archive.
268 At the present, \LuaTeX-ja has no official release, so you have to retrieve
269 the archive from the repository.
270 You can retrieve the Git repository via
272 $ git clone git://git.sourceforge.jp/gitroot/luatex-ja/luatexja.git
274 or download the archive of HEAD in \texttt{master} branch from
276 \url{http://git.sourceforge.jp/view?p=luatex-ja/luatexja.git;a=snapshot;h=HEAD;sf=tgz}.
279 Note that the forefront of development may not be in \texttt{master} branch.
280 \item Extract the archive. You will see {\tt src/} and several other sub-directories.
281 \item Copy all the contents of {\tt src/} into one of your \texttt{TEXMF} tree.
282 \item If {\tt mktexlsr} is needed to update the filename database, make it so.
285 \subsection{Cautions}
287 \item The encoding of your source file must be UTF-8. No other
288 encodings, such as EUC-JP or Shift-JIS, are not supported.
289 \item May be conflict with other packages.
291 For example, the default setting of \textbf{JAchar} in the present
292 version does not coexist with the \Pkg{unicode-math}
293 package. Putting the following line in preamble makes that
294 mathematical symbols will be typeset correctly, but several
295 Japanese characters will be treated as an \textbf{ALchar} as
298 \ltjsetparameter{jacharrange={-3, -8}}
302 \subsection{Using in plain \TeX}\label{ssec-plain}
303 To use \LuaTeX-ja in plain \TeX, simply put the following at the beginning of the document:
308 This does minimal settings (like {\tt ptex.tex}) for typesetting Japanese documents:
310 \item The following 6~Japanese fonts are preloaded:
312 \begin{tabular}{ccccc}
314 \textbf{classification}&\textbf{font name}&\bf `10\,pt'&\bf`7\,pt'&\bf`5\,pt'\\\midrule
315 \emph{mincho}&Ryumin-Light &\verb+\tenmin+&\verb+\sevenmin+&\verb+\fivemin+\\
316 \emph{gothic}&GothicBBB-Medium&\verb+\tengt+ &\verb+\sevengt+ &\verb+\fivegt+\\
321 \item The `Q' is a unit used in Japanese phototypesetting, and
322 $1\,\textrm{Q}=0.25\,\textrm{mm}$. This length is stored in a
323 dimension \verb+\jQ+.
325 \item It is widely accepted that the font `Ryumin-Light' and
326 `GothicBBB-Medium' aren't embedded into PDF files, and PDF reader
327 substitute them by some external Japanese fonts (\textit{e.g.},
328 Kozuka Mincho is used for Ryumin-Light in Adobe Reader). We adopt this custom to
330 \item A character in an alphabetic font is generally smaller than a
331 Japanese font in the same size. So actual size specification of
332 these Japanese fonts is in fact smaller than that of alphabetic
333 fonts, namely scaled by 0.962216.
335 \item The amount of glue that are inserted between a \textbf{JAchar} and
336 an \textbf{ALchar} (the parameter \Param{xkanjiskip}) is set to
338 (0.25\cdot 13.5\,\textrm{Q})^{+1\,\text{pt}}_{-1\,\text{pt}}
339 = {27\over 32}\,\mathrm{mm}^{+1\,\text{pt}}_{-1\,\text{pt}}.
343 \subsection{Using in \LaTeX}\label{ssec-ltx}
345 Using in \LaTeXe\ is basically same. To set up the minimal environment
346 for Japanese, you only have to load {\tt luatexja.sty}:
348 \usepackage{luatexja}
350 It also does minimal settings (counterparts in \pLaTeX\ are {\tt
351 plfonts.dtx} and {\tt pldefs.ltx}):
354 \item {\tt JY3} is the font encoding for Japanese fonts (in horizontal direction).\\
355 When vertical typesetting is supported by \LuaTeX-ja in the future, {\tt JT3} will be used for vertical fonts.
356 \item Two font families {\tt mc} and {\tt gt} are defined:
358 \begin{tabular}{ccccc}
360 \textbf{classification}&\textbf{family}&\verb+\mdseries+&\verb+\bfseries+&\textbf{scale}\\\midrule
361 \emph{mincho}&\tt mc&Ryumin-Light &GothicBBB-Medium&0.962216\\
362 \emph{gothic}&\tt gt&GothicBBB-Medium&GothicBBB-Medium&0.962216\\
366 Remark that the bold series in both family are same as the medium series of \emph{gothic} family.
367 This is a convention in \pLaTeX.
369 \item Japanese characters in math mode are typeset by the font family {\tt mc}.
372 However, above settings are not sufficient for Japanese-based
373 documents. To typeset Japanese-based documents, You are better to use
374 class files other than {\tt article.cls}, {\tt book.cls}, and so on. At
375 the present, we have the counterparts of \Pkg{jclasses} (standard
376 classes in \pLaTeX) and \Pkg jsclasses (classes by Haruhiko
377 Okumura), namely, \Pkg{ltjclasses} and \Pkg{ltjsclasses}.
379 \paragraph{{\tt\char92 CID, {\tt\char92 UTF}} and macros in OTF package}
380 Under \pTeX, \Pkg{otf} package (developed by Shuzaburo Saito) is
381 used for typesetting characters which is in Adobe-japan1-6 CID but not
382 in JIS~X~0208. Since this package is widely used, \LuaTeX-ja
383 supports some of functions in \Pkg{otf} package.
386 森\UTF{9DD7}外と内田百\UTF{9592}とが\UTF{9AD9}島屋に行く。
388 \CID{7652}飾区の\CID{13706}野家,
391 %lltjlisting.sty要修正?:↑「森」の直後で改行.
394 \subsection{Changing Fonts}\label{ssub-chgfnt}
395 \paragraph{Remark: Japanese Characters in Math Mode}
396 Since \pTeX\ supports Japanese characters in math mode, there are
397 sources like the following:
400 $f_{高温}$~($f_{\text{high temperature}}$).
401 \[ y=(x-1)^2+2\quad{}よって\quad y>0 \]
402 $5\in{}素:=\{\,p\in\mathbb N:\text{$p$ is a prime}\,\}$.
405 We (the project members of \LuaTeX-ja) think that using
406 Japanese characters in math mode are allowed if and only if these are used as identifiers.
407 In this point of view,
409 \item The lines 1~and~2 above are not correct, since `高温' in above is used as a textual label, and
410 `よって' is used as a conjunction.
411 \item However, the line~3 is correct, since `素' is used as an identifier.
413 Hence, in our opinion, the above input should be corrected as:
416 ($f_{\text{high temperature}}$).
418 \mathrel{\text{よって}}\quad y>0 \]
419 $5\in{}素:=\{\,p\in\mathbb N:\text{$p$ is a prime}\,\}$.
421 %BUG?: \{\}がなければ「素」がでない.上の段落の「よって」もでてない.
422 We also believe that using Japanese characters as identifiers is rare,
423 hence we don't describe how to change Japanese fonts in math mode in
424 this chapter. For the method, please see Part~\ref{part-ref}.
427 \paragraph{plain \TeX}
428 To change Japanese fonts in plain \TeX, you must use the primitive
429 \verb+\jfont+. So please see Part~\ref{part-ref}.
433 For \LaTeXe, \LuaTeX-ja simply adopted the font selection system from that
434 of \pLaTeXe\ (in {\tt plfonts.dtx}).
436 \item Two control sequences \verb+\mcdefault+ and \verb+\gtdefault+ are
437 used to specify the default font families for \emph{mincho} and
438 \emph{gothic}, respectively. Default values: \texttt{mc} for
439 \verb+\mcdefault+ and \texttt{gt} for \verb+\gtdefault+.
440 \item Commands \verb+\fontfamily+, \verb+\fontseries+,
441 \verb+\fontshape+ and \verb+\selectfont+ can be used to change
442 attributes of Japanese fonts.
444 \begin{tabular}{cccccc}
446 &\textbf{encoding}&\textbf{family}&\textbf{series}&\textbf{shape}&\textbf{selection}\\\midrule
448 &\verb+\romanencoding+&\verb+\romanfamily+&\verb+\romanseries+&\verb+\romanshape+
451 &\verb+\kanjiencoding+&\verb+\kanjifamily+&\verb+\kanjiseries+&\verb+\kanjishape+
453 both&---&--&\verb+\fontseries+&\verb+\fontshape+&---\\
454 auto select&\verb+\fontencoding+&\verb+\fontfamily+&---&---&\verb+\usefont+\\
460 ここで,\verb+\fontencoding{<encoding>}+は,引数により和文側か欧文側かの
461 どちらかが切り替わる.例えば,次の入力で最初の\verb+\fontencoding+
462 の呼び出しは和文フォントのエンコーディングを\texttt{JT3}に変更し,
463 2回目の呼びだしでは欧文フォント側を\texttt{T1}へと変更する.
465 \fontencoding{JY3}\fontencoding{T1}
467 \verb+\fontfamily+も引数により和文側,欧文側,\textbf{あるいは両方}のフォ
469 詳細はSubsection~\ref{ssub-nfsspat}を参照すること.
472 \item For defining a Japanese font family, use
473 \verb+\DeclareKanjiFamily+ instead of
474 \verb+\DeclareFontFamily+. However, in the present implementation,
475 using \verb+\DeclareFontFamily+ doesn't cause any problem.
479 To coexist with the \Pkg{fontspec} package, it is needed to load
480 \Pkg{luatexja-fontspec} package in the preamble. This additional
481 package automatically loads \Pkg{luatexja} and \Pkg{fontspec}
484 In \Pkg{luatexja-fontspec} package, the following 7~commands are defined as
485 counterparts of original commands in the \Pkg{fontspec} package:
487 \begin{tabular}{ccccc}
490 &\verb+\jfontspec+&\verb+\setmainjfont+&\verb+\setsansjfont+&\verb+\newjfontfamily+\\
492 &\verb+\fontspec+&\verb+\setmainfont+&\verb+\setsansfont+&\verb+\newfontfamily+\\
495 &\verb+\newjfontface+&\verb+\defaultjfontfeatures+&\verb+\addjfontfeatures+\\
497 &\verb+\newfontface+&\verb+\defaultfontfeatures+&\verb+\addfontfeatures+\\
504 Note that there is no command named \verb+\setmonojfont+, since it is
505 popular for Japanese fonts that nearly all Japanese glyphs have same
506 widths. Also note that the kerning feature is set off by default in
507 these 7~commands, since this feature and \textbf{JAglue} will clash (see
510 \section{Changing Parameters}
511 There are many parameters in \LuaTeX-ja. And due to the behavior of \LuaTeX,
512 most of them are not stored as internal register of \TeX, but as an
513 original storage system in \LuaTeX-ja. Hence, to assign or acquire those
514 parameters, you have to use commands \verb+\ltjsetparameter+ and
515 \verb+\ltjgetparameter+.
517 \subsection{Editing the range of \textbf{JAchar}s}
520 To edit the range of \textbf{JAchar}s, You have to assign a non-zero
521 natural number which is less than 217 to the character range first. This
522 can be done by using \verb+\ltjdefcharrange+ primitive. For example, the
523 next line assigns whole characters in Supplementary Multilingual Plane
524 and the character `漢' to the range number~100.
526 \ltjdefcharrange{100}{"10000-"1FFFF,`漢}
528 This assignment of numbers to ranges are always global, so you should
529 not do this in the middle of a document.
531 If some character has been belonged to some non-zero numbered range,
532 this will be overwritten by the new setting. For example, whole SMP
533 belong the range~4 in the default setting of \LuaTeX-ja, and if you
534 specify the above line, then SMP will belong the range~100 and be
535 removed from the range~4.
537 After assigning numbers to ranges, the {\sf jacharrange} parameter can
538 be used to customize which character range will be treated as ranges of
539 \textbf{JAchar}s, as the following line (this is just the default
540 setting of \LuaTeX-ja):
542 \ltjsetparameter{jacharrange={-1, +2, +3, -4, -5, +6, +7, +8}}
544 The argument to {\sf jacharrange} parameter is a list of integer. Negative interger $-n$ in the list means that `the character range~$n$ is ...'.
546 \paragraph{Default Setting}
547 Lua\TeX-ja predefines eight character ranges for convinience. They are
548 determined from the following data:
550 \item Blocks in Unicode~6.0.
551 \item The \texttt{Adobe-Japan1-UCS2} mapping between a CID Adobe-Japan1-6 and Unicode.
552 \item The \texttt{PXbase} bundle for \upTeX\ by Takayuki Yato.
555 Now we describe these eight ranges. The alphabet `J' or `A' after the
556 number shows whether characters in the range is treated as
557 \textbf{JAchar}s or not by default. These settings are similar to \texttt{prefercjk} ...
559 \item[Range~8${}^{\text{J}}$] Symbols in the intersection of the upper half of ISO~8859-1
560 (Latin-1 Supplement) and JIS~X~0208 (a basic character set for Japanese). This character range
561 consists of the following charatcers:
564 \def\ch#1#2{\item \char"#1\ ({\tt U+00#1}, #2)}%"
565 \ch{A7}{Section Sign}
566 \ch{A8}{Umlaut or diaeresis}
568 \ch{B1}{Plus-minus sign}
569 \ch{B4}{Spacing acute}
570 \ch{B6}{Paragraph sign}
571 \ch{D7}{Multiplication sign}
572 \ch{F7}{Division Sign}
575 \item[Range~1${}^{\text{A}}$] Latin characters that some of them are included in Adobe-Japan1-6.
576 This range consist of the following Unicode ranges, \emph{except characters in the range~8 above}:
579 \item {\tt U+0080}--{\tt U+00FF}: Latin-1 Supplement
580 \item {\tt U+0100}--{\tt U+017F}: Latin Extended-A
581 \item {\tt U+0180}--{\tt U+024F}: Latin Extended-B
582 \item {\tt U+0250}--{\tt U+02AF}: IPA Extensions
583 \item {\tt U+02B0}--{\tt U+02FF}: Spacing Modifier Letters
584 \item {\tt U+0300}--{\tt U+036F}: Combining Diacritical Marks
585 \item {\tt U+1E00}--{\tt U+1EFF}: Latin Extended Additional
589 \item[Range~2${}^{\text{J}}$] Greek and Cyrillic letters. JIS~X~0208 (hence most of Japanese
590 fonts) has some of these characters.
593 \item {\tt U+0370}--{\tt U+03FF}: Greek and Coptic
594 \item {\tt U+0400}--{\tt U+04FF}: Cyrillic
595 \item {\tt U+1F00}--{\tt U+1FFF}: Greek Extended
599 \item[Range~3${}^{\text{J}}$] Punctuations and Miscellaneous symbols. The block list is
600 indicated in Table~\ref{table-rng3}.
602 \caption{Unicode blocks in predefined character range~3.}\label{table-rng3}
603 \catcode`\"=13\def"#1#2#3#4{{\tt U+#1#2#3#4}}%"
605 \begin{tabular}{llll}
606 "2000--"206F&General Punctuation&
607 "2070--"209F&Superscripts and Subscripts\\
608 "20A0--"20CF&Currency Symbols&
609 "20D0--"20FF&Comb.\ Diacritical Marks for Symbols\\
610 "2100--"214F&Letterlike Symbols&
611 "2150--"218F&Number Forms\\
613 "2200--"22FF&Mathematical Operators\\
614 "2300--"23FF&Miscellaneous Technical&
615 "2400--"243F&Control Pictures\\
616 "2500--"257F&Box Drawing&
617 "2580--"259F&Block Elements\\
618 "25A0--"25FF&Geometric Shapes&
619 "2600--"26FF&Miscellaneous Symbols\\
620 "2700--"27BF&Dingbats&
621 "2900--"297F&Supplemental Arrows-B\\
622 "2980--"29FF&Misc.\ Mathematical Symbols-B&
623 "2B00--"2BFF&Miscellaneous Symbols and Arrows\\
624 "E000--"F8FF&Private Use Area&
628 \item[Range~4${}^{\text{A}}$] Characters usually not in Japanese fonts. This range consists
629 of almost all Unicode blocks which are not in other
630 predefined ranges. Hence, instead of showing the block list,
631 we put the definition of this range itself:
633 \ltjdefcharrange{4}{%
634 "500-"10FF, "1200-"1DFF, "2440-"245F, "27C0-"28FF, "2A00-"2AFF,
635 "2C00-"2E7F, "4DC0-"4DFF, "A4D0-"A82F, "A840-"ABFF, "FB50-"FE0F,
636 "FE20-"FE2F, "FE70-"FEFF, "FB00-"FB4F, "10000-"1FFFF} % non-Japanese
638 \item[Range~5${}^{\text{A}}$] Surrogates and Supplementary Private Use Areas.
639 \item[Range~6${}^{\text{J}}$] Characters used in Japanese. The block list is indicated in Table~\ref{table-rng6}.
641 \caption{Unicode blocks in predefined character range~6.}\label{table-rng6}
642 \catcode`\"=13\def"#1#2#3#4{{\tt U+#1#2#3#4}}%"
644 \begin{tabular}{llll}
645 "2460--"24FF&Enclosed Alphanumerics&
646 "2E80--"2EFF&CJK Radicals Supplement\\
647 "3000--"303F&CJK Symbols and Punctuation&
648 "3040--"309F&Hiragana\\
649 "30A0--"30FF&Katakana&
650 "3190--"319F&Kanbun\\
651 "31F0--"31FF&Katakana Phonetic Extensions&
652 "3200--"32FF&Enclosed CJK Letters and Months\\
653 "3300--"33FF&CJK Compatibility&
654 "3400--"4DBF&CJK Unified Ideographs Extension A\\
655 "4E00--"9FFF&CJK Unified Ideographs&
656 "F900--"FAFF&CJK Compatibility Ideographs\\
657 "FE10--"FE1F&Vertical Forms&
658 "FE30--"FE4F&CJK Compatibility Forms\\
659 "FE50--"FE6F&Small Form Variants&
660 "{20}000--"{2F}FFF&(Supplementary Ideographic Plane)
664 \item[Range~7${}^{\text{J}}$] Characters used in CJK languages, but not included in Adobe-Japan1-6.
665 The block list is indicated in Table~\ref{table-rng7}.
667 \caption{Unicode blocks in predefined character range~7.}\label{table-rng7}
668 \catcode`\"=13\def"#1#2#3#4{{\tt U+#1#2#3#4}}%"
670 \begin{tabular}{llll}
671 "1100--"11FF&Hangul Jamo&
672 "2F00--"2FDF&Kangxi Radicals\\
673 "2FF0--"2FFF&Ideographic Description Characters&
674 "3100--"312F&Bopomofo\\
675 "3130--"318F&Hangul Compatibility Jamo&
676 "31A0--"31BF&Bopomofo Extended\\
677 "31C0--"31EF&CJK Strokes&
678 "A000--"A48F&Yi Syllables\\
679 "A490--"A4CF&Yi Radicals&
680 "A830--"A83F&Common Indic Number Forms\\
681 "AC00--"D7AF&Hangul Syllables&
682 "D7B0--"D7FF&Hangul Jamo Extended-B
689 \subsection{\Param{kanjiskip} and \Param{xkanjiskip}}\label{subs-kskip}
690 \textbf{JAglue} is divided into the following three categories:
692 \item Glues/kerns specified in JFM. If \verb+\inhibitglue+ is issued
693 around a Japanese character, this glue will be not inserted at the
695 \item The default glue which inserted between two \textbf{JAchar}s ({\sf
697 \item The default glue which inserted between a \textbf{JAchar} and an
698 \textbf{ALchar} (\Param{xkanjiskip}).
700 The value (a skip) of \Param{kanjiskip} or \Param{xkanjiskip} can be
701 changed as the following.
703 \ltjsetparameter{kanjiskip={0pt plus 0.4pt minus 0.4pt},
704 xkanjiskip={0.25\zw plus 1pt minus 1pt}}
708 It may occur that JFM contains the data of `ideal width of {\sf
709 kanjiskip}' and/or `ideal width of \Param{xkanjiskip}'.
710 To use these data from JFM, set the value of \Param{kanjiskip} or
711 \Param{xkanjiskip} to \verb+\maxdimen+.
713 \subsection{Insertion Setting of \Param{xkanjiskip}}
714 It is not desirable that \Param{xkanjiskip} is inserted between every
715 boundary between \textbf{JAchar}s and \textbf{ALchar}s. For example,
716 \Param{xkanjiskip} should not be inserted after opening parenthesis
717 (\textit{e.g.}, compare `(あ' and `(\hskip\ltjgetparameter{xkanjiskip}あ').
719 \LuaTeX-ja can control whether \Param{xkanjiskip} can be inserted
720 before/after a character, by changing \Param{jaxspmode} for \textbf{JAchar}s and
721 \Param{alxspmode} parameters \textbf{ALchar}s respectively.
723 \ltjsetparameter{jaxspmode={`あ,preonly}, alxspmode={`\!,postonly}}
727 The second argument {\tt preonly} means `the insertion of
728 \Param{xkanjiskip} is allowed before this character, but not after'.
729 the other possible values are {\tt postonly}, {\tt allow} and {\tt
730 inhibit}. For the compatibility with \pTeX, natural numbers between
731 0~and~3 are also allowed as the second argument\footnote{But we don't
732 recommend this: since numbers 1~and~2 have opposite meanings in
733 \Param{jaxspmode} and \Param{alxspmode}.}.
735 If you want to enable/disable all insertions of \Param{kanjiskip} and
736 \Param{xkanjiskip}, set \Param{autospacing} and \Param{autoxspacing}
737 parameters to {\tt false}, respectively.
740 \subsection{Shifting Baseline}
741 To make a match between a Japanese font and an alphabetic font, sometimes
742 shifting of the baseline of one of the pair is needed. In \pTeX, this is achieved
743 by setting \verb+\ybaselineshift+ to a non-zero length (the
744 baseline of alphabetic fonts is shifted below). However, for documents
745 whose main language is not Japanese, it is good to shift the baseline of
746 Japanese fonts, but not that of alphabetic fonts.
747 Because of this, \LuaTeX-ja can independently set the shifting amount
748 of the baseline of alphabetic fonts (\Param{yalbaselineshift}
749 parameter) and that of Japanese fonts (\Param{yjabaselineshift}
753 \vrule width 150pt height 0.4pt depth 0pt\hskip-120pt
754 \ltjsetparameter{yjabaselineshift=0pt, yalbaselineshift=0pt}abcあいう
755 \ltjsetparameter{yjabaselineshift=5pt, yalbaselineshift=2pt}abcあいう
757 Here the horizontal line in above is the baseline of a line.
759 There is an interesting side-effect: characters in different size can be
760 vertically aligned center in a line, by setting two parameters appropriately.
761 The following is an example (beware the value is not well tuned):
765 \ltjsetparameter{yjabaselineshift=-1pt,
766 yalbaselineshift=-1pt}
772 \subsection{Cropmark}
773 Cropmark is a mark for indicating 4~corners and horizontal/vertical
774 center of the paper. In Japanese, we call cropmark as tombo(w).
775 \pLaTeX\ and this \LuaTeX-ja support `tombow' by their kernel.
776 The following steps are needed to typeset cropmark:
779 \item First, define the banner which will be printed at the upper left
780 of the paper. This is done by assigning a token list to
781 \verb+\@bannertoken+.
783 For example, the following sets banner as `{\tt filename (2012-01-01 17:01)}':
787 \hour\time \divide\hour by 60 \@tempcnta\hour \multiply\@tempcnta 60\relax
788 \minute\time \advance\minute-\@tempcnta
790 \jobname\space(\number\year-\two@digits\month-\two@digits\day
791 \space\two@digits\hour:\two@digits\minute)}%
798 \part{Reference}\label{part-ref}
799 \section{Font Metric and Japanese Font}
800 \subsection{\texttt{\char92jfont} primitive}
801 To load a font as a Japanese font, you must use the
802 \verb+\jfont+ primitive instead of~\verb+\font+, while
803 \verb+\jfont+ admits the same syntax used in~\verb+\font+.
804 \LuaTeX-ja automatically loads \Pkg{luaotfload} package,
805 so TrueType/OpenType fonts with features can be used for Japanese fonts:
807 \jfont\tradgt={file:ipaexg.ttf:script=latn;%
808 +trad;-kern;jfm=ujis} at 14pt
812 Note that the defined control sequence
813 (\verb+\tradgt+ in the example above) using \verb+\jfont+ is not a
814 \textit{font\_def} token, hence the input like \verb+\fontname\tradgt+
815 causes a error. We denote control sequences which are defined in
816 \verb+\jfont+ by <jfont\_cs>.
818 \paragraph{Prefix \texttt{psft}}
819 Besides \texttt{file:}\ and \texttt{name:}\ prefixes, \texttt{psft:}\
820 can be used a prefix in \verb+\jfont+ (and~\verb+\font+) primitive.
821 Using this prefix, you can specify a `name-only' Japanese font which
822 will be not embedded to PDF. Typical use of this prefix is to specify
823 the `standard' Japanese fonts, namely, `Ryumin-Light' and
824 `GothicBBB-Medium'. For kerning or other informations, that of Kozuka
825 Mincho Pr6N Regular (this is a font by Adobe Inc., and included in
826 Japanese Font Packs for Adore Reader) will be used.
830 As noted in Introduction, a JFM has measurements of characters and
831 glues/kerns that are automatically inserted for Japanese
832 typesetting. The structure of JFM will be described in the next
833 subsection. At the calling of \verb+\jfont+ primitive, you must specify
834 which JFM will be used for this font by the following keys:
836 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
838 Specify the name of JFM. A file named \texttt{jfm-<name>.lua} will be searched and/or loaded.
840 The followings are JFMs shipped with Lua\TeX-ja:
842 \item[\tt jfm-ujis.lua] A standard JFM in Lua\TeX-ja. This JFM is
843 based on \verb+upnmlminr-h.tfm+, a metric for UTF/OTF package that
844 is used in \upTeX. When you use the \Pkg{luatexja-otf} package, please use this JFM.
845 \item[\tt jfm-jis.lua] A counterpart for \verb+jis.tfm+, `JIS font
846 metric' which is widely used in \pTeX. A major difference of
847 \texttt{jfm-ujis.lua} and this \texttt{jfm-jis.lua} is that
848 most haracters under \texttt{jfm-ujis.lua} are square-shaped,
849 while that under \texttt{jfm-jis.lua} are horizontal
852 \item[\tt jfm-min.lua] A counterpart for \verb+min10.tfm+, which is one
853 of the default Japanese font metric shipped with \pTeX. There
854 are notable difference between this JFM and other 2~JFMs, as
855 shown in Table~\ref{tab-difjfm}.
858 \item[jfmvar=<string>] Sometimes there is a need that
862 \caption{Differences between JFMs shipped with \LuaTeX-ja}
865 \def\r#1{{\jfont\g=psft:Ryumin-Light:jfm=#1 at 14.43324pt \g
866 \setbox0=\vtop{\hsize=7\zw\noindent ◆◆◆◆◆◆◆
867 ある日モモちゃんがお使いで迷子になって泣きました.}\copy0
868 \vrule height 0pt depth \dp0}}
869 \def\s#1{{\jfont\g=psft:Ryumin-Light:jfm=#1 at 14.43324pt \g
870 \setbox0=\vtop{\hsize=7\zw\noindent ちょっと!何}\copy0}}
871 \def\t#1{{\jfont\g=psft:Ryumin-Light:jfm=#1 at 19.24432pt \g
873 \vrule width 0.4pt height\ht0 depth\dp0\kern-.2pt\copy0
874 \kern-\wd0\vrule width\wd0height .2pt depth .2pt
875 \kern-\wd0\raise\ht0\hbox{\vrule width\wd0height .2pt depth .2pt}%
876 \kern-\wd0\lower\dp0\hbox{\vrule width\wd0height .2pt depth .2pt}%
877 \kern-.2pt\vrule width 0.4pt height\ht0 depth \dp0}}
878 \begin{tabular}{rccc}
880 &\tt jfm-ujis.lua&\tt jfm-jis.lua&\tt jfm-min.lua\\
882 Example~1&\r{ujis}&\r{jis}&\r{min}\\
883 Example~2&\s{ujis}&\s{jis}&\s{min}\\
884 Bounding Box&\t{ujis}&\t{jis}&\t{min}\\
890 \paragraph{Note: kern feature}\label{para-kern}
891 Some fonts have information for inter-glyph spacing. However, this
892 information is not well-compatible with \LuaTeX-ja. More concretely,
893 this kerning space from this information are inserted \emph{before} the
894 insertion process of \textbf{JAglue}, and this causes incorrect spacing
895 between two characters when both a glue/kern from the data in the font
896 and it from JFM are present.
899 \item You should specify {\tt -kern} in
900 {\tt\char92jfont} primitive, when you want to use other font features,
901 such as {\tt script=...}\,.
902 \item If you want to use Japanese fonts in proportinal width, and use
903 information from this font, use \texttt{jfm-prop.lua} for its JFM, and ...
909 \subsection{Structure of JFM file}
910 A JFM file is a Lua script which has only one function call:
912 luatexja.jfont.define_jfm { ... }
914 Real data are stored in the table which indicated above by
915 \verb+{ ... }+. So, the rest of this subsection are devoted to describe the
916 structure of this table. Note that all lengths in a JFM file are
917 floating-point numbers in design-size unit.
919 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
920 \item[dir=<direction>] (required)
922 The direction of JFM. At the present, only \texttt{'yoko'} is supported.
924 \item[zw=<length>] (required)
926 The amount of the length of the `full-width'.
928 \item[zh=<length>] (required)
930 \item[kanjiskip=\{<natural>, <stretch>, <shrink>\}] (optional)
932 This field specifies the `ideal' amount of \Param{kanjiskip}. As noted
933 in Subsection~\ref{subs-kskip}, if the parameter
934 \Param{kanjiskip} is \verb+\maxdimen+, the value specified
935 in this field is actually used (if this field is not specified in
936 JFM, it is regarded as 0\,pt). Note that <stretch> and <shrink>
937 fields are in design-size unit too.
940 \item[xkanjiskip=\{<natural>, <stretch>, <shrink>\}] (optional)
942 Like the \Param{kanjiskip} field, this field specifies the `ideal'
943 amount of \Param{xkanjiskip}.
947 Besides from above fields, a JFM file have several sub-tables those
948 indices are natural numbers. The table indexed by~$i\in\omega$ stores
949 informations of `character class'~$i$. At least, the character class~0 is
950 always present, so each JFM file must have a sub-table whose index is
951 \texttt{[0]}. Each sub-table (its numerical index is denoted by $i$) has
952 the following fields:
954 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
955 \item[chars=\{<character>, ...\}] (required except character class~0)
957 This field is a list of characters which are in this character
958 type~$i$. This field is not required if $i=0$, since all
959 \textbf{JAchar} which are not in any character class other
960 than 0 (hence, the character class~0 contains most of
961 \textbf{JAchar}s). In the list, a character can be
962 specified by its code number, or by the character itself
963 (as a string of length~1). Moreover, there are `imaginary
964 characters' which specified in the list. We will describe these later.
966 \item[width=<length>, height=<length>, depth=<length>, italic=<length>]\ (required)
968 Specify width of characters in character class~$i$, height, depth and
969 the amount of italic correction. All characters in character class~$i$ are regarded that its width, height and depth are
970 as values of these fields.
971 But there is one exception: if \texttt{'prop'} is specified in \texttt{width} field, width of a character becomes that of its `real' glyph
973 \item[left=<length>, down=<length>, align=<align>]\
975 These fields are for adjusting the position of the `real' glyph. Legal
976 values of \texttt{align} field are \texttt{'left'},
977 \texttt{'middle'} and \texttt{'right'}. If one of these
978 3~fields are omitted, \texttt{left} and \texttt{down} are
979 treated as~0, and \texttt{align} field is treated as
981 The effects of these 3~fields are indicated in Figure~\ref{fig-pos}.
983 In most cases, \texttt{left} and \texttt{down} fields are~0, while
984 it is not uncommon that the \texttt{align} field is \texttt{'middle'} or \texttt{'right'}.
985 For example, setting the \texttt{align} field to \texttt{'right'} is practically needed
986 when the current character class is the class for opening delimiters'.
988 \begin{minipage}{0.4\textwidth}%
989 \begin{center}\unitlength=10pt\small
990 \begin{picture}(15,12)(-1,-4)
991 \color{black!10!white}% real glyph :step1
992 \put(0,0){\vrule width 12\unitlength height 8\unitlength depth 3\unitlength}
994 \color{red!20!white}% real glyph :step1
995 \put(-1,-1.5){\vrule width 6\unitlength height 7\unitlength depth 2.5\unitlength}
997 \color{red}% real glyph
999 \put(-1,-1.5){\vector(0,1){7}\vector(0,-1){2.5}\vector(1,0){6}}
1000 \put(5,-1.5){\line(0,1){7}\line(0,-1){2.5}}
1001 \put(-1,5.5){\line(1,0){6}}
1002 \put(-1,-4){\line(1,0){6}}
1004 \color{green!20!white}% real glyph :step1
1005 \put(3,0){\vrule width 6\unitlength height 7\unitlength depth 2.5\unitlength}
1007 \color{black}% real glyph :step1
1009 \put(0,0){\vector(0,1){8}\line(0,-1){3}\vector(1,0){12}}
1010 \put(12,0){\line(0,1){8}\vector(0,-1){3}}
1011 \put(0,8){\line(1,0){12}}
1012 \put(0,-3){\line(1,0){12}}
1013 \put(0.2,4){\makebox(0,0)[l]{\texttt{height}}}
1014 \put(12.2,-1.5){\makebox(0,0)[l]{\texttt{depth}}}
1015 \put(6,0.2){\makebox(0,0)[b]{\texttt{width}}}
1017 \color{green!50!black}% real glyph :step1
1019 \put(3,0){\vector(0,1){7}\vector(0,-1){2.5}\vector(1,0){6}}
1020 \put(9,0){\line(0,1){7}\line(0,-1){2.5}}
1021 \put(3,7){\line(1,0){6}}
1022 \put(3,-2.5){\line(1,0){6}}
1023 \newsavebox{\eqdist}
1024 \savebox{\eqdist}(0,0)[b]{%
1026 \put(-0.08,0.2){\line(0,-1){0.4}}%
1027 \put(0.08,0.2){\line(0,-1){0.4}}}
1028 \put(1.5,0){\usebox{\eqdist}}
1029 \put(10.5,0){\usebox{\eqdist}}
1031 \color{blue}% shifted
1033 \put(3,-1.5){\vector(-1,0){4}}
1034 \put(1,-1.7){\makebox(0,0)[t]{\texttt{left}}}
1035 \put(3,0){\vector(0,-1){1.5}}
1036 \put(3.2,-0.75){\makebox(0,0)[l]{\texttt{down}}}
1040 \begin{minipage}{0.6\textwidth}%
1041 Consider a node containing Japanese character whose value of the \texttt{align}
1042 field is \texttt{'middle'}.
1044 \item The black rectangle is a frame of the node.
1045 Its width, height and depth are specified by JFM.
1046 \item Since the \texttt{align} field is \texttt{'middle'},
1047 the `real' glyph is centered horizontally (the green rectangle).
1048 \item Furthermore, the glyph is shifted according to values of fields
1049 \texttt{left} and \texttt{down}. The ultimate position of the real
1050 glyph is indicated by the red rectangle.
1053 \caption{The position of the `real' glyph.}
1058 \item[kern={\{[$j$]=<kern>, ...\}}]
1060 \item[glue={\{[$j$]=\{<width>, <stretch>, <shrink>\}, ...\}}]
1064 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
1065 \item['lineend'] An ending of a line.
1066 \item['diffmet'] Used at a boundary between two \textbf{JAchar}s whose JFM or size is different.
1067 \item['boxbdd'] The beginning/ending of a horizontal box, and the beginging of a noindented paragraph.
1068 \item['parbdd'] The beginning of an (indented) paragraph.
1069 \item['jcharbdd'] A boundary between \textbf{JAchar} and anything else
1070 (such as \textbf{ALchar}, kern, glue, ...).
1071 \item[$-1$] The left/right boundary of an inline math formula.
1076 上で説明した通り,\texttt{chars}フィールド中にはいくつかの「特殊文字」も
1077 指定可能である.これらは,大半が\pTeX のJFMグルーの挿入処理ではみな「文字
1078 クラス0の文字」として扱われていた文字であり,その結果として\pTeX より細か
1079 い組版調整ができるようになっている.以下のその一覧を述べる:
1080 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
1081 \item['lineend'] 行の終端を表す.
1084 \item['boxbdd'] hboxの先頭と末尾,及びインデントされていない
1085 (\verb+\noindent+で開始された)段落の先頭を表す.
1086 \item['parbdd'] 通常の(\verb+\noindent+で開始されていない)段落の先頭.
1087 \item['jcharbdd'] 和文文字と「その他のもの」(欧文文字,glue,kern等)との境界.
1088 \item[$-1$] 行中数式と地の文との境界.
1091 \paragraph{\pTeX 用和文フォントメトリックの移植}
1092 以下に,\pTeX 用和文フォントメトリックを\LuaTeX-ja用に移植する場合の注意点を挙げておく.
1094 \item 実際に出力される和文フォントのサイズがdesign sizeとなる.
1095 このため,例えば$1\,\textrm{zw}$がdesign sizeの0.962216倍であるJISフォン
1098 \item JFM中の全ての数値を$1/0.962216$倍しておく.
1099 \item \TeX ソース中で使用するところで,サイズ指定を0.962216倍にする.
1100 \LaTeX でのフォント宣言なら,例えば次のように:
1102 \DeclareFontShape{JY3}{mc}{m}{n}{<-> s*[0.962216] psft:Ryumin-Light:jfm=jis}{}
1105 \item 上に述べた特殊文字は,\texttt{'boxbdd'}を除き文字クラスを全部0とする
1107 \item \texttt{'boxbdd'}については,それのみで一つの文字クラスを形成し,その
1108 文字クラスに関してはglue/kernの設定はしない.
1111 hboxの先頭・末尾とインデントされていない(\verb+\noindent+で開始さ
1112 れた)段落の先頭にはJFMグルーは入らないという仕様を実現させるためである.
1113 \item \pTeX の組版を再現させようというのが目的であれば以上の注意を守れば十分である.
1115 ところで,\pTeX では通常の段落の先頭にJFMグルーが残るという仕様があるので,
1116 段落先頭の開き括弧は全角二分下がりになる.全角下がりを実現させるに
1117 は,段落の最初に手動で\verb+\inhibitglue+を追加するか,あるいは
1118 \verb+\everypar+のhackを行い,それを自動化させるしかなかった.
1120 一方,\LuaTeX-jaでは,\texttt{'parbdd'}によって,それがJFM側で調整できるよ
1121 うになった.例えば,\LuaTeX-ja同梱のJFMのように,\texttt{'boxbdd'}と同じ文字クラスに
1122 \texttt{'parbdd'}を入れれば全角下がりとなる.
1125 \jfont\g=psft:Ryumin-Light:jfm=test \g
1126 \parindent1\zw\noindent{}◆◆◆◆◆
1135 \subsection{Math Font Family}
1136 \TeX\ handles fonts in math formulas by 16~font families\footnote{Omega,
1137 Aleph, \LuaTeX~and $\varepsilon$-\kern-.125em(u)\pTeX can handles 256~families, but
1138 an external package is needed to support this in plain \TeX\ and
1139 \LaTeX.}, and each family has three fonts:
1140 \verb+\textfont+, \verb+\scriptfont+ and \verb+\scriptscriptfont+.
1142 \LuaTeX-ja's handling of Japanese fonts in math formulas is similar;
1143 Table~\ref{tab-math} shows counterparts to \TeX's primitives for math
1144 font families. There is no relation between the value of
1145 \verb+\fam+ and that of \verb+\jfam+; with appropreate settings,
1146 you can set both \verb+\fam+ and \verb+\jfam+ to~the same value.
1149 \caption{Primitives for Japanese math fonts.}
1151 \begin{center}\def\{{\char`\{}\def\}{\char`\}}
1152 \begin{tabular}{lll}
1154 &Japanese fonts&alphabetic fonts\\
1156 font family&\verb+\jfam+${}\in [0,256)$&\verb+\fam+\\
1157 text size&\tt\Param{jatextfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\verb+\textfont+<fam>=<font\_cs>\\
1158 script size&\tt\Param{jascriptfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\verb+\scriptfont+<fam>=<font\_cs>\\
1159 scriptscript size&\tt\Param{jascriptscriptfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\verb+\scriptscriptfont+<fam>=<font\_cs>\\
1165 \subsection{Callbacks}
1166 Like \LuaTeX\ itself, \LuaTeX-ja also has callbacks. These callbacks can
1167 be accessed via \verb+luatexbase.add_to_callback+ function and so on, as other callbacks
1169 {\def\makelabel#1{\bfseries#1}}
1170 \item[\texttt{luatexja.load\_jfm} callback]
1171 With this callback you can overwrite JFMs.
1174 function (<table> jfm_info, <string> jfm_name)
1175 return <table> new_jfm_info
1179 The argument \verb+jfm_info+ contains a table similar to the table in a JFM file, except
1180 this argument has \texttt{chars} field which contains character codes
1181 whose character class is not~0.
1183 An example of this callback is the \texttt{ltjarticle} class, with
1184 forcefully assigning character class~0 to \texttt{'parbdd'}
1185 in the JFM \texttt{jfm-min.lua}. This callback doesn't
1186 replace any code of \LuaTeX-ja.
1188 \item[\texttt{luatexja.define\_font} callback]
1189 This callback and the next callback form a pair, and you can assign letters which don't have
1190 fixed codepoints in Unicode to non-zero character classes.
1191 This \texttt{luatexja.define\_font} callback is called just when new Japanese font is loaded.
1193 function (<table> jfont_info, <number> font_number)
1194 return <table> new_jfont_info
1198 You may assume that \verb+jfont_info+ has the following fields:
1200 \item[\tt jfm] The index number of JFM.
1201 \item[\tt size] Font size in a scaled point (${}=2^{-16}\,\textrm{pt}$).
1202 \item[\tt var] The value specified in \texttt{jfmvar=...} at a call of \verb+\jfont+.
1205 The returned table \verb+new_jfont_info+ also should include these three fields.
1206 The \verb+font_number+ is a font number.
1208 A good example of this and the next callbacks is the \Pkg{luatexja-otf}
1209 package, supporting \verb+"AJ1-xxx"+ form for Adobe-Japan1
1210 CID characters in a JFM. This callback doesn't replace any
1214 \item[\texttt{luatexja.find\_char\_class} callback]
1215 This callback is called just when \LuaTeX-ja inready to determine which
1216 character class a character \verb+chr_code+ belongs.
1217 A function used in this callback should be in the following form:
1218 \begin{lstlisting}[numbers=left]
1219 function (<number> char_class, <table> jfont_info, <number> chr_code)
1220 if char_class~=0 then return char_class
1223 return (<number> new_char_class or 0)
1228 The argument \verb+char_class+ is the result of \LuaTeX-ja's default
1229 routine or previous function calls in this callback, hence
1230 this argument may not be 0. Moreover, the returned
1231 \verb+new_char_class+ should be as same as \verb+char_class+ when \verb+char_class+
1232 is not~0, otherwise you will overwrite the \LuaTeX-ja's
1235 This callback doesn't replace any code of \LuaTeX-ja.
1243 \section{Parameters}
1244 \subsection{{\tt\char92 ltjsetparameter} primitive}
1245 As noted before, \verb+\ltjsetparameter+ and \verb+\ltjgetparameter+ are
1246 primitives for accessing most parameters of \LuaTeX-ja. One of the main
1247 reason that \LuaTeX-ja didn't adopted the syntax similar to that of \pTeX\
1248 (\textit{e.g.},~\verb+\prebreakpenalty`)=10000+)
1249 is the position of \verb+hpack_filter+ callback in the source
1250 of \LuaTeX, see Section~\ref{sec-para}.
1252 \verb+\ltjsetparameter+ and \verb+\ltjglobalsetparameter+ are primitives
1253 for assigning parameters. These take one argument which is a
1254 \texttt{<key>=<value>} list. Allowed keys are described in the next
1256 The difference between
1257 \verb+\ltjsetparameter+ and \verb+\ltjglobalsetparameter+ is only the
1258 scope of assignment;
1259 \verb+\ltjsetparameter+ does a local assignment and
1260 \verb+\ltjglobalsetparameter+ does a global one.
1261 They also obey the value of \verb+\globaldefs+,
1262 like other assignment.
1264 \verb+\ltjgetparameter+ is the primitive for acquiring parameters. It
1265 always takes a parameter name as first argument, and also takes the
1266 additional argument---a character code, for example---in some cases.
1268 \ltjgetparameter{differentjfm},
1269 \ltjgetparameter{autospacing},
1270 \ltjgetparameter{prebreakpenalty}{`)}.
1272 \emph{The return value of\/ {\normalfont\tt\char92ltjgetparameter} is
1273 always a string}. This is outputted by \texttt{tex.write()}, so any
1274 character other than space~`{\tt\char32}'~(U+0020) has the category code
1275 12~(other), while the space has 10~(space).
1277 \subsection{List of Parameters}
1278 The following is the list of parameters which can be specificated by the
1279 \verb+\ltjsetparameter+ command. [\verb+\cs+] indicates the counterpart
1280 in \pTeX, and symbols beside each parameter has the following meaning:
1282 \item No mark: values at the end of the paragraph or the hbox are
1283 adopted in the whole paragraph/hbox.
1284 \item `\ast' : local parameters, which can change everywhere inside a paragraph/hbox.
1285 \item `\dagger': assignments are always global.
1288 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
1289 \item[\Param{jcharwidowpenalty}\,=<penalty>] [\verb+\jcharwidowpenalty+]
1291 Penalty value for supressing orphans. This penalty is inserted just
1292 after the last \textbf{JAchar} which is not regarded as a
1293 (Japanese) punctuation mark.
1295 \item[\Param{kcatcode}\,=\{<chr\_code>,<natural number>\}]\
1297 An additional attributes having each character whose character code is <chr\_code>.
1298 At the present version, the lowermost bit of <natural number> indicates
1299 whether the character is considered as a punctuation mark
1300 (see the description of \Param{jcharwidowpenalty} above).
1303 \item[\Param{prebreakpenalty}\,=\{<chr\_code>,<penalty>\}] [\verb+\prebreakpenalty+]\
1305 文字コード<chr\_code>の\textbf{JAchar}が行頭にくることを抑止するために,
1306 この文字の前に挿入/追加されるペナルティの量を指定する.
1308 例えば閉じ括弧「〗」は絶対に行頭にきてはならないので,標準で読み込まれる
1309 \texttt{luatexja-kinsoku.tex}において
1311 \ltjsetparameter{prebreakpenalty={`〙,10000}}
1313 と,最大値の10000が指定されている.他にも,小書きのカナなど,絶対禁止とい
1314 うわけではないができれば行頭にはきて欲しくない場合に,0と
1315 10000の間の値を指定するのも有用であろう.
1317 \ltjsetparameter{prebreakpenalty={`ゕ,150}}
1321 \item[\Param{postbreakpenalty}\,=\{<chr\_code>,<penalty>\}] [\verb+\postbreakpenalty+]
1323 文字コード<chr\_code>の\textbf{JAchar}が行末にくることを抑止するために,
1324 この文字の後に挿入/追加されるペナルティの量を指定する.
1326 \pTeX では,\verb+\prebreakpenalty+, \verb+\postbreakpenalty+において,
1328 \item 一つの文字に対して,pre, postどちらか一つしか指定することができなかっ
1330 \item pre, post合わせて256文字分の情報を格納することしかできなかった.
1332 という制限があったが,\LuaTeX-ja ではこれらの制限は解消されている.
1335 \item[\Param{jatextfont}\,=\{<jfam>,<jfont\_cs>\}] [\verb+\textfont+ in \TeX]
1336 \item[\Param{jascriptfont}\,=\{<jfam>,<jfont\_cs>\}] [\verb+\scriptfont+ in \TeX]
1337 \item[\Param{jascriptscriptfont}\,=\{<jfam>,<jfont\_cs>\}] [\verb+\scriptscriptfont+ in \TeX]
1338 \item[\Param{yjabaselineshift}\,=<dimen>$^\ast$]\
1339 \item[\Param{yalbaselineshift}\,=<dimen>$^\ast$] [\verb+\ybaselineshift+]
1341 \item[\Param{jaxspmode}\,=\{<chr\_code>,<mode>\}] [\verb+\inhibitxspcode+]
1343 Setting whether inserting \Param{xkanjiskip} is allowed before/after a \textbf{JAchar} whose character code is <chr\_code>.
1344 The followings are allowed for <mode>:
1346 \item[0, \texttt{inhibit}] Insertion of \Param{xkanjiskip} is inhibited before the charater, nor after the charater.
1347 \item[2, \texttt{preonly}] Insertion of \Param{xkanjiskip} is allowed before the charater, but not after.
1348 \item[1, \texttt{postonly}] Insertion of \Param{xkanjiskip} is allowed after the charater, but not before.
1349 \item[3, \texttt{allow}] Insertion of \Param{xkanjiskip} is allowed before the charater and after the charater.
1350 This is the default value.
1353 \item[\Param{alxspmode}\,=\{<chr\_code>,<mode>\}] [\verb+\xspcode+]
1355 Setting whether inserting \Param{xkanjiskip} is allowed before/after a
1356 \textbf{ALchar} whose character code is <chr\_code>.
1357 The followings are allowed for <mode>:
1359 \item[0, \texttt{inhibit}] Insertion of \Param{xkanjiskip} is inhibited
1360 before the charater, nor after the charater.
1361 \item[1, \texttt{preonly}] Insertion of \Param{xkanjiskip} is allowed
1362 before the charater, but not after.
1363 \item[2, \texttt{postonly}] Insertion of \Param{xkanjiskip} is allowed
1364 after the charater, but not before.
1365 \item[3, \texttt{allow}] Insertion of \Param{xkanjiskip} is allowed both
1366 before the charater and after the charater.
1367 This is the default value.
1369 Note that parameters \Param{jaxspmode} and \Param{alxspmode} use a common table.
1371 \item[\Param{autospacing}\,=<bool>$^\ast$] [\verb+\autospacing+]
1372 \item[\Param{autoxspacing}\,=<bool>$^\ast$] [\verb+\autoxspacing+]
1373 \item[\Param{kanjiskip}\,=<skip>] [\verb+\kanjiskip+]
1374 \item[\Param{xkanjiskip}\,=<skip>] [\verb+\xkanjiskip+]
1376 \item[\Param{differentjfm}\,=<mode>$^\dagger$]
1378 Specify how glues/kerns between two \textbf{JAchar}s whose JFM (or size) are different.
1379 The allowed arguments are the followings:
1381 \item[\texttt{average}]
1382 \item[\texttt{both}]
1383 \item[\texttt{large}]
1384 \item[\texttt{small}]
1387 \item[\Param{jacharrange}\,=<ranges>$^\ast$]
1388 \item[\Param{kansujichar}\,=\{<digit>, <chr\_code>\}] [\verb+\kansujichar+]
1392 \section{Other Primitives}
1393 \subsection{Primitives for Compatibility}
1394 The following primtives are implemented for compatibility with \pTeX:
1395 \begin{list}{}{\def\makelabel{\ttfamily\char92 }}
1403 \subsection{{\tt\char92 inhibitglue}}
1404 The primitive \verb+\inhibitglue+ suppresses the insertion of \textbf{JAglue}.
1405 The following is an example, using a special JFM that there will be a glue between
1406 the beginning of a box and `あ', and also between `あ' and `ウ'.
1409 \jfont\g=psft:Ryumin-Light:jfm=test \g
1410 あウあ\inhibitglue{}ウ\inhibitglue\par
1411 あ\par\inhibitglue{}あ
1412 \par\inhibitglue\hrule{}あoff\inhibitglue ice
1415 With the help of this example, we remark the specification of \verb+\inhibitglue+:
1417 \item The call of \verb+\inhibitglue+ in the (internal) vertical mode is
1418 effective at the beginning of the next paragraph. This is realized
1419 by hacking \verb+\everypar+.
1420 \item The call of \verb+\inhibitglue+ in the (restricted) horizontal
1421 mode is only effective on the spot; does not get over boundary of
1422 paragraphs. Moreover, \verb+\inhibitglue+ cancels ligatures and
1423 kernings, as shown in line~4 of above example.
1424 \item The call of \verb+\inhibitglue+ in math mode is just ignored.
1427 \section{Control Sequences for \LaTeXe}
1428 \subsection{Patch for NFSS2}\label{ssub-nfsspat}
1429 As described in Subsection~\ref{ssec-ltx}, \LuaTeX-ja simply adopted
1430 \texttt{plfonts.dtx} in \pLaTeXe\ for the Japanese patch for NFSS2.
1431 For an convinience, we will describe
1432 commands which are not described in Subsection~\ref{ssub-chgfnt}.
1435 \item[DeclareYokoKanjiEncoding\{<encoding>\}\{<text-settings>\}\{<math-settings>\}]
1436 In NFSS2 under \LuaTeX-ja, distinction between alphabetic font families
1437 and Japanese font families is only made by its
1438 encoding. For example, encodings OT1 and T1 are for
1439 alphabetic font families, and a Japanese font family cannot
1440 have these encodings. This command defines a new encoding
1441 scheme for Japanese font family (in horizontal direction).
1443 \item[DeclareKanjiEncodingDefaults\{<text-settings>\}\{<math-settings>\}]
1444 \item[DeclareKanjiSubstitution\{<encoding>\}\{<family>\}\{<series>\}\{<shape>\}]
1445 \item[DeclareErrorKanjiFont\{<encoding>\}\{<family>\}\{<series>\}\{<shape>\}\{<size>\}]
1447 The above 3~commands are just the counterparts for \verb+DeclareFontEncodingDefaults+ and~others.
1449 \item[reDeclareMathAlphabet\{<unified-cmd>\}\{<al-cmd>\}\{<ja-cmd>\}]
1450 和文・欧文の数式用フォントファミリを一度に変更する命令を作成する.
1451 具体的には,欧文数式用フォントファミリ変更の命令<al-cmd>と,和文数式用フォ
1452 ントファミリ変更の命令<ja-cmd>の2つを同時に行う命令として
1453 <unified-cmd>を(再)定義する.実際の使用では<unified-cmd>と
1454 <al-cmd>に同じものを指定する,すなわち,<al-cmd>に和文側も変
1455 更させるようにするのが一般的と思われる.
1457 本コマンドの使用については,\pLaTeX 配布中の\texttt{plfonts.dtx}に詳しく
1458 注意点が述べられているので,そちらを参照されたい.
1460 \item[DeclareRelationFont\{<ja-encoding>\}\{<ja-family>\}\{<ja-series>\}\{<ja-shape>\}\\
1461 \hfill\{<al-encoding>\}\{<al-family>\}\{<al-series>\}\{<al-shape>\}]
1463 This command sets the `accompanied' alphabetic font family (given by the latter 4~arguments)
1464 with respect to a Japanese font family given by the former 4~arguments.
1467 いわゆる「従属欧文」を設定するための命令である.前半の4引数で表される和文フォントファミリに対して,
1468 そのフォントに対応する「従属欧文」フォントファミリを後半の4引数により与える.
1470 \item[SetRelationFont]
1471 This command is almost same as \verb+\DeclareRelationFont+, except that this command does a local
1472 assignment, where \verb+\DeclareRelationFont+ does a global assignment.
1474 Change current alphabetic font encoding/family/\dots\ to the `accompanied' alphabetic
1475 font family with respect to current Japanese font family,
1477 \verb+\DeclareRelationFont+ or \verb+SetRelationFont+.
1478 Like \verb+\fontfamily+, \verb+\selectfont+ is required to take an effect.
1480 \item[adjustbaseline]
1483 \item[fontfamily\{<family>\}]
1485 As in \LaTeXe, this command changes current font family (alphabetic, Japanese,~\emph{or both})
1486 to <family>. Which family will be changed is determined as follows:
1488 \item Let current encoding scheme for Japanese fonts be
1489 <ja-enc>. Current Japanese font family will be changed to
1490 <family>, if one of the following two conditions is met:
1492 \item The family <fam> under the encoding <ja-enc> is already defined by
1493 \verb+\DeclareKanijFamily+.
1494 \item A font definition named \texttt{<enc><ja-enc>.fd} (the filename is
1495 all lowercase) exists.
1497 \item Let current encoding scheme for Japanese fonts be
1498 <al-enc>. For alphabetic font family, the criterion as above is used.
1499 \item There is a case which none of the above applies, that is, the font
1500 family named <family> doesn't seem to be defined neither under the
1501 encoding <ja-enc>, nor under <al-enc>.
1503 In this case, the default family for font substitution is used for
1504 alphabetic and Japanese fonts. Note that current encoding will not
1505 be set to <family>, unlike the original inplementation in \LaTeX.
1510 As closing this subsection, we shall introduce an example of
1511 \verb+SetRelationFont+ and \verb+\userelfont+:
1514 \SetRelationFont{JY3}{gt}{m}{n}{OT1}{pag}{m}{n}
1515 \userelfont\selectfont{}あいうabc
1519 \subsection{Cropmark/`tombow'}
1521 \section{Extensions}
1522 \subsection{{\tt luatexja-fontspec.sty}}
1524 \subsection{{\tt luatexja-otf.sty}}
1525 This optional package supports typesetting charaters in
1526 Adobe-Japan1. {\tt luatexja-otf.sty} offers the following 2~low-level
1528 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
1529 \item[\char92CID\{<number>\}]
1530 Typeset a character whose CID number is <number>.
1531 \item[\char92UTF\{<hex\_number>\}]
1532 Typeset a character whose character code is <hex\_number> (in hexadecimal).
1533 This command is similar to \verb+\char"+<hex\_number>,\ %"
1534 but please remind remarks below.
1538 Characters by \verb+\CID+ and \verb+\UTF+ commands are different from
1539 ordinary characters in the following points:
1541 \item Always treated as \textbf{JAchar}s.
1542 \item Processing codes for supporting OpenType features (\textit{e.g.},
1543 glyph replacement and kerning) by the \Pkg{luaotfload} package
1544 is not performed to these characters.
1548 \paragraph{Additionally Syntax of JFM}
1549 {\tt luatexja-otf.sty} extends the syntax of JFM; the entries of {\tt
1550 chars} table in JFM now allows a string in the form
1551 \verb+'AJ1-xxx'+, which stands for the character
1552 whose CID number in Adobe-Japan1 is \verb+xxx+.
1554 \part{Implementations}\label{part-imp}
1555 \section{Storing Parameters}\label{sec-para}
1556 \subsection{Used Dimensions, Attributes and whatsit nodes}
1557 Here the following is the list of dimension and attributes which are used in \LuaTeX-ja.
1559 \def\makelabel{\ttfamily}
1560 \def\dim#1{\item[\char92 #1\ \textrm{(dimension)}]}
1561 \def\attr#1{\item[\char92 #1\ \textrm{(attribute)}]}
1565 As explained in Subsection~\ref{ssec-plain}, \verb+\jQ+ is equal to
1566 $1\,\textrm{Q}=0.25\,\textrm{mm}$, where `Q'~(also called `級') is
1567 a unit used in Japanese phototypesetting. So one should not change the value of this dimension.
1569 There is also a unit called `歯' which equals to $0.25\,\textrm{mm}$ and
1570 used in Japanese phototypesetting. The dimension
1571 \verb+\jH+ stores this length, similar to \verb+\jQ+.
1572 \dim{ltj@zw} A temporal register for the `full-width' of current Japanese font.
1573 \dim{ltj@zh} A temporal register for the `full-height' (usually the sum of height of imaginary body and its depth) of current Japanese font.
1574 \attr{jfam} Current number of Japanese font family for math formulas.
1575 \attr{ltj@curjfnt} The font index of current Japanese font.
1576 \attr{ltj@charclass} The character class of Japanese \textit{glyph\_node}.
1577 \attr{ltj@yablshift} The amount of shifting the baseline of alphabetic
1578 fonts in scaled point ($2^{-16}\,\textrm{pt}$).
1579 \attr{ltj@ykblshift} The amount of shifting the baseline of Japanese
1580 fonts in scaled point ($2^{-16}\,\textrm{pt}$).
1581 \attr{ltj@autospc} Whether the auto insertion of \Param{kanjiskip} is allowed at the node.
1582 \attr{ltj@autoxspc} Whether the auto insertion of \Param{xkanjiskip} is allowed at the node.
1583 \attr{ltj@icflag} An attribute for distinguishing `kinds' of a node. One of the following value is
1584 assigned to this attribute:
1586 \item[\textit{italic} (1)] Glues from an itaric correction
1587 (\verb+\/+). This distinction of origins of glues
1588 (from explicit \verb+\kern+, or from \verb+\/+)
1589 is needed in the insertion process of \Param{xkanjiskip}.
1590 \item[\textit{packed} (2)]
1591 \item[\textit{kinsoku} (3)] Penalties inserted for the word-wrapping process of Japanese characters (\emph{kinsoku}).
1592 \item[\textit{from\_jfm} (4)] Glues/kerns from JFM.
1593 \item[\textit{line\_end} (5)] Kerns for ...
1594 \item[\textit{kanji\_skip} (6)] Glues for \Param{kanjiskip}.
1595 \item[\textit{xkanji\_skip} (7)] Glues for \Param{xkanjiskip}.
1596 \item[\textit{processed} (8)] Nodes which is already processed by ...
1597 \item[\textit{ic\_processed} (9)] Glues from an itaric correction, but also already processed.
1598 \item[\textit{boxbdd} (15)] Glues/kerns that inserted just the beginning or the ending of an hbox or a paragraph.
1600 \attr{ltj@kcat$i$} Where $i$~is a natural number which is less than~7.
1601 These 7~attributes store bit~vectors indicating which character block is regarded as a block of \textbf{JAchar}s.
1604 Furthermore, \LuaTeX-ja uses several `user-defined' whatsit nodes for
1605 typesetting. All those nodes store a natural number (hence the node's
1606 \texttt{type} is 100).
1608 \item[30111] Nodes for indicating that \verb+\inhibitglue+ is
1609 specified. The \texttt{value} field of these nodes doesn't matter.
1610 \item[30112] Nodes for \LuaTeX-ja's stack system (see the next
1611 subsection). The \texttt{value} field of these nodes is
1613 \item[30113] Nodes for Japanese Characters which the callback process of
1614 luaotfload won't be applied, andd the character code is
1615 stored in the \texttt{value} field. Each node having this
1616 \verb+user_id+ is converted to a `glyph\_node' \emph{after}
1617 the callback process of luaotfload.
1619 These whatsits will be removed during the process of inserting \textbf{JAglue}s.
1621 \subsection{Stack System of \LuaTeX-ja}\label{ssec-stack}
1622 \paragraph{Background}
1623 \LuaTeX-ja has its own stack system, and most parameters of \LuaTeX-ja
1624 are stored in it. To clarify the reason, imagine the parameter
1625 \Param{kanjiskip} is stored by a skip, and consider the following
1628 \ltjsetparameter{kanjiskip=0pt}ふがふが.%
1629 \setbox0=\hbox{\ltjsetparameter{kanjiskip=5pt}ほげほげ}
1633 As described in Part~\ref{part-ref}, the only effective value of
1634 \Param{kanjiskip} in an hbox is the latest value, so the value of
1635 \Param{kanjiskip} which applied in the entire hbox should be 5\,pt.
1636 However, by the implementation method of \LuaTeX, this `5\,pt' cannot be
1637 known from any callbacks. In the \texttt{tex/packaging.w} (which is a
1638 file in the source of \LuaTeX), there are the following codes:
1642 scaled h; /* height of box */
1643 halfword p; /* first node in a box */
1644 scaled d; /* max depth */
1650 if (cur_list.mode_field == -hmode) {
1651 cur_box = filtered_hpack(cur_list.head_field,
1652 cur_list.tail_field, saved_value(1),
1653 saved_level(1), grp, saved_level(2));
1654 subtype(cur_box) = HLIST_SUBTYPE_HBOX;
1656 Notice that \verb+unsave+ is executed \emph{before}
1657 \verb+filtered_hpack+ (this is where \verb+hpack_filter+ callback is
1658 executed): so `5\,pt' in the above source is orphaned at
1659 \texttt+unsave+, and hence it can't be accessed from \verb+hpack_filter+
1662 \paragraph{The method}
1663 The code of stack system is based on that in a post of Dev-luatex mailing list\footnote{%
1664 \texttt{[Dev-luatex] tex.currentgrouplevel}, a post at 2008/8/19 by Jonathan Sauer.}.
1666 These are two \TeX\ count registers for maintaining informations:
1667 \verb+\ltj@@stack+ for the stack level, and \verb+\ltj@@group@level+ for
1668 the \TeX's group level when the last assignment was done. Parameters
1669 are stored in one big table named \texttt{charprop\_stack\_table}, where
1670 \texttt{charprop\_stack\_table[$i$]} stores data of stack level~$i$. If
1671 a new stack level is created by \verb+\ltjsetparameter+, all data of the
1672 previous level is copied.
1674 To resolve the problem mentioned in `Background' above, \LuaTeX-ja uses
1675 another thing: When a new stack level is about to be created, a whatsit
1676 node whose type, subtype and value are 44~(\textit{user\_defined}),
1677 30112, and current group level respectively is appended to the current
1678 list (we refer this node by \textit{stack\_flag}). This enables us to
1679 know whether assignment is done just inside a hbox. Suppose that the
1680 stack level is~$s$ and the \TeX's group level is~$t$ just after the hbox
1683 \item If there is no \textit{stack\_flag} node in the list of hbox, then
1684 no assignment was occurred inside the hbox. Hence values of
1685 parameters at the end of the hbox are stored in the stack
1687 \item If there is a \textit{stack\_flag} node whose value is~$t+1$, then
1688 an assignment was occurred just inside the hbox group. Hence
1689 values of parameters at the end of the hbox are stored in the
1691 \item If there are \textit{stack\_flag} nodes but all of their values
1692 are more than~$t+1$, then an assignment was occurred in the box,
1693 but it is done is `more internal' group. Hence values of
1694 parameters at the end of the hbox are stored in the stack
1698 Note that to work this trick correctly, assignments to
1699 \verb+\ltj@@stack+ and \verb+\ltj@@group@level+ have to be local always,
1700 regardless the value of \verb+\globaldefs+.
1701 This problem is resolved by using
1702 \hbox{\verb+\directlua{tex.globaldefs=0}+} (this assignment is local).
1705 \section{Linebreak after Japanese Character}\label{sec-lbreak}
1706 \subsection{Reference: Behavior in \pTeX}
1708 In~\pTeX, a linebreak after a Japanese character doesn't emit a space,
1709 since words are not separated by spaces in Japanese writings. However,
1710 this feature isn't fully implemented in \LuaTeX-ja due to the
1711 specification of callbacks in~\LuaTeX. To clarify the difference between
1712 \pTeX~and~\LuaTeX, We briefly describe the handling of a linebreak in~\pTeX, in
1715 \pTeX's input processor can be described in terms of a finite state
1716 automaton, as that of~\TeX\ in~Section~2.5 of~\cite{texbytopic}. The
1717 internal states are as follows:
1719 \item State~$N$: new line
1720 \item State~$S$: skipping spaces
1721 \item State~$M$: middle of line
1722 \item State~$K$: after a Japanese character
1724 The first three states---$N$, $S$~and~$M$---are as same as \TeX's input
1725 processor. State~$K$ is similar to state~$M$, and is entered after
1726 Japanese characters. The diagram of state transitions are indicated in
1727 Figure~\ref{fig-ptexipro}. Note that \pTeX\ doesn't leave state~$K$
1728 after `beginning/ending of a group' characters.
1732 欧文では文章の改行は単語間でしか行わない.そのため,\TeX では,(文字の直後の)改行は
1733 空白文字と同じ扱いとして扱われる.一方,和文ではほとんどどどこでも改行が可能なため,
1734 \pTeX では和文文字の直後の改行は単純に無視されるようになっている.
1736 このような動作は,\pTeX が\TeX からエンジンとして拡張されたことによって可能になったことである.
1737 \pTeX の入力処理部は,\TeX におけるそれと同じように,有限オートマトンとして記述することができ,
1741 \item State~$N$: 行の開始.
1742 \item State~$S$: 空白読み飛ばし.
1743 \item State~$M$: 行中.
1744 \item State~$K$: 行中(和文文字の後).
1746 また,状態遷移は,図\label{fig-ptexipro}のようになっており,図中の数字は
1747 カテゴリーコードを表している.最初の3状態は\TeX の入力処理部と同じであり,
1748 図中から状態$K$と「$j$」と書かれた矢印を取り除けば,\TeX の入力処理部と同
1753 行が和文文字(とグループ境界文字)で終わっていれば,改行は無視される
1760 \def\sp{\text{\tt\char32}}
1762 {\text{scan a cs}}\ar@(r,ul)[dr]&\\
1764 *++[o][F-]{N}\ar[ur]^0\ar[dd]_{d,\ g}\ar[u]^{5\ (\text{\tt\char92par})}
1765 \ar@{->}@(d,l)[ddrr]_(0.45){j}&&
1766 *++[o][F-]{S}\ar@(l,dr)[ul]^0\ar@(l,ur)[ddll]_{d,\ g}\ar[u]_{5}
1767 \ar@{->}@(r,r)[dd]^{j}\\&\\&
1768 *++[o][F-]{M}\ar[uuur]^0\ar@(r,dl)[uurr]_(0.55){10\ (\sp)}
1769 \ar[d]_{5\ ({\sp})}\ar@{->}@(dr,dl)[rr]_{j}&&
1770 *++[o][F-]{K}\ar@{->}@(ul,d)[uuul]^0\ar@{->}[ll]^{d}
1771 \ar@{->}@(ur,dr)[uu]^{10\ (\sp)}\ar@{->}[d]_5\\
1774 d:=\{3,4,6,7,8,11,12,13\},\quad g:=\{1,2\},\quad j:=(\text{Japanese characters})
1777 \item Numbers represent category codes.
1778 \item Category codes 9~(ignored), 14~(comment)~and~15~(invalid) are omitted in above diagram.
1780 \caption{State transitions of \pTeX's input processor.}
1781 \label{fig-ptexipro}
1785 \subsection{Behavior in \LuaTeX-ja}
1787 States in the input processoe of \LuaTeX\ is the same as that of \TeX,
1788 and they can't be customized by any callbacks. Hence, we can only use
1789 \verb+process_input_buffer+ and \verb+token_filter+ callbacks for to
1790 suppress a space by a linebreak which is after Japanese characters.
1792 However, \verb+token_filter+ callback cannot be used either, since a
1793 character in category code 5~(end-of-line) is converted into an space
1794 token \emph{in the input processor}. So we can use only the
1795 \verb+process_input_buffer+ callback. This means that suppressing a
1796 space must be done \emph{just before} an input line is read.
1798 Considering these situations, handling of an end-of-line in \LuaTeX-ja are as follows:
1800 A character U+FFFFF (its category code is set to 14~(comment) by
1801 \LuaTeX-ja) is appended to an input line, \emph{before \LuaTeX\ actually
1802 process it}, if and only if the following two conditions are satisfied:
1804 \item The category code of the character $\langle${return}$\rangle$
1805 (whose character code is 13) is 5~(end-of-line).
1806 \item The input line matches the following `regular expression':
1808 (\text{any char})^*(\textbf{JAchar})
1809 \bigl(\{\text{catcode}=1\}\cup\{\text{catcode}=2\}\bigr)^*
1815 The following example shows the major difference from the behavior of \pTeX:
1817 \ltjsetparameter{autoxspacing=false}
1818 \ltjsetparameter{jacharrange={-6}}xあ
1819 y\ltjsetparameter{jacharrange={+6}}zあ
1823 \item There is no space between `x' and `y', since the line~2 ends with a \textbf{JAchar} `あ'
1824 (this `あ' considered as an \textbf{JAchar} at the ending of line~1).
1825 \item There is no space between `あ' (in the line~3) and `u', since the
1826 line~3 ends with an \textbf{ALchar}
1827 (the letter `あ' considered as an \textbf{ALchar} at the ending of line~2).
1832 \LuaTeX の入力処理部は\TeX のそれと全く同じであり,callbackによりユーザが
1833 カスタマイズすることはできない.このため,改行抑制の目的でユーザが利用で
1834 きそうなcallbackとしては,\verb+process_input_buffer+や
1835 \verb+token_filter+に限られてしまう.しかし,\TeX の入力処理部をよく見る
1836 と,後者も役には経たないことが分かる:改行文字は,入力処理部によってトー
1837 クン化される時に,カテゴリーコード10の32番文字へと置き換えられてしまうた
1838 め,\verb+token_filter+で非標準なトークン読み出しを行おうとしても,空白文
1839 字由来のトークンと,改行文字由来のトークンは区別できないのだ.
1841 すると,我々のとれる道は,\verb+process_input_buffer+を用いて
1842 \LuaTeX の入力処理部に引き渡される前に入力文字列を編集するというものしかない.
1843 以上を踏まえ,\LuaTeX-jaにおける「和文文字直後の改行抑制」の処理は,次のようになっている:
1846 各入力行に対し,\textbf{その入力行が読まれる前の内部状態で}
1847 以下の2条件が満たされている場合,\LuaTeX-jaはU+FFFFF番の文字
1848 \footnote{この文字はコメント文字として扱われるように\LuaTeX-ja内部で設定をしている.}
1849 を末尾に追加する.よって,その場合に改行は空白とは見做されないこととなる.
1851 \item 改行文字(文字コード13番)のカテゴリーコードが5~(end-of-line)である.
1852 \item 入力行は次の「正規表現」にマッチしている:
1854 (\text{any char})^*(\textbf{JAchar})
1855 \bigl(\{\text{catcode}=1\}\cup\{\text{catcode}=2\}\bigr)^*
1860 この仕様は,前節で述べた\pTeX の仕様にできるだけ近づけたものとなっている.最初の条件は,
1861 \texttt{verbatim}系環境などの日本語対応マクロを書かなくてすませるためのものである.
1862 しかしながら,完全に同じ挙動が実現できたわけではない.
1863 差異は,次の例が示すように,和文文字の範囲を変更した行の改行において見られる:
1865 \ltjsetparameter{autoxspacing=false}
1866 \ltjsetparameter{jacharrange={-6}}xあ
1867 y\ltjsetparameter{jacharrange={+6}}zあ
1870 もし\pTeX とまったく同じ挙動を示すならば,出力は
1871 「\hbox{\ltjsetparameter{autoxspacing=false}x yzあu}」となるべきである.しかし,実際には
1874 \item 2行目は「あ」という和文文字で終わる(2行目を処理する前の時点では,
1875 「あ」は和文文字扱いである)ため,直後の改行文字は無視される.
1876 \item 3行目は「あ」という欧文文字で終わる(2行目を処理する前の時点では,
1877 「あ」は欧文文字扱いである)ため,直後の改行文字は空白に置き換わる.
1879 このため,トラブルを避けるために,和文文字の範囲を\verb+\ltjsetparameter+で編集した場合,
1880 その行はそこで改行するようにした方がいいだろう.
1884 \section{Insertion of JFM glues, \Param{kanjiskip} and \Param{xkanjiskip}}
1885 \subsection{Overview}
1891 \LuaTeX-ja における和文処理グルーの挿入方法は,\pTeX のそれとは全く異なる.
1892 \pTeX では次のような仕様であった:
1894 \item JFMグルーの挿入は,和文文字を表すトークンを元に水平リストに(文字を表す)<char\_node>を
1896 \item \Param{xkanjiskip}の挿入は,hboxへのパッケージングや行分割前に行われる.
1897 \item \Param{kanjiskip}はノードとしては挿入されない.パッケージングや行分割の計算時に
1898 「和文文字を表す2つの<char\_node>の間には\Param{kanjiskip}がある」ものとみなされる.
1900 しかし,\LuaTeX-jaでは,hboxへのパッケージングや行分割前に全ての
1901 \textbf{JAglue},即ちJFMグルー・\Param{xkanjiskip}・\Param{kanjiskip}の
1902 3種類を一度に挿入することになっている.これは,\LuaTeX において欧文の合字・
1903 カーニング処理がノードベースになったことに対応する変更である.
1905 \LuaTeX-jaにおける\textbf{JAglue}挿入処理では,下の図\ref{fig-clu}のよう
1906 に「塊」を単位にして行われる.大雑把にいうと,「塊」は文字とそれに付随す
1907 るノード達(アクセント位置補正用のkernや,イタリック補正)をまとめたもの
1908 であり,2つの塊の間には,ペナルティ,\verb+\vadjust+,whatsitなど,行組版
1909 には関係しないものがある.そのため,……
1912 % \begin{figure}[!tb]
1916 \subsection{Definition of a `cluster'}
1919 A \emph{cluster} is a list of nodes in one of the following forms, with the \textit{id} of it:
1921 \item Nodes whose value of\ \verb+\ltj@icflag+ is in $[3,15)$. These
1922 nodes come from a hbox which is already packaged, by unpackaging
1924 The \textit{id} is \textit{id\_pbox}.
1925 \item A inline math formula, including two \textit{math\_node}s at the boundary of it:
1927 The \textit{id} is \textit{id\_math}.
1928 \item A \textit{glyph\_node} with nodes which relate with it:
1930 The \textit{id} is \textit{id\_jglyph} or
1931 \textit{id\_glyph}, according to whether the \textit{glyph\_node}
1932 represents a Japanese character or not.
1933 \item An box-like node, that is, an hbox, an vbox and an rule (\verb+\vrule+).
1934 The \textit{id} is \textit{id\_hlist} if the node is an
1935 hbox which is not shifted vertically, or \textit{id\_box\_like}
1937 \item A glue, a kern whose subtype is not 2~(\textit{accent}), and a discretionary break.
1938 The \textit{id} is \textit{id\_glue}, \textit{id\_kern}
1939 and \textit{id\_disc}, respectively.
1940 %Just a node which will \dots, \textit{i.e.}, a node which is \emph{not} one of the following:
1941 %\textit{ins\_node}, \textit{mark\_node}, \textit{adjust\_node}, \textit{whatsit\_node}
1942 %and \textit{penalty\_node}.
1944 We denote a cluster by \textit{Np}, \textit{Nq} and \textit{Nr}.
1947 Internally, a cluster is represented by a table $\textit{Np}$ with the following fields.
1950 \def\makelabel#1{\textbf{\textit{#1}}}
1951 \item[first, last] The first/last node of the cluster.
1952 \item[id] The \textit{id} in above definition.
1956 \item[auto\_kspc, auto\_xspc]
1957 \item[xspc\_before, xspc\_after]