OSDN Git Service

d19704e2d01cde839137a2a63c18660d4224b40f
[luatex-ja/luatexja.git] / doc / manual.dtx
1 %#! lualatex -shell-escape manual.ins
2
3 %<*en>
4 \documentclass[a4paper,titlepage]{article}
5 \usepackage[margin=20mm]{geometry}
6 %</en>
7 %<*ja>
8 \documentclass[a4paper,titlepage]{bxjsarticle}
9 \setpagelayout*{margin=20mm}
10 \def\headfont{\normalfont\bfseries}
11 % \def\headfont{\sffamily\gtfamily} is needed in ordinal documents
12 %</ja>
13
14 \usepackage{amsmath,amssymb,xcolor,pict2e}
15 \usepackage{booktabs,listings,lltjlisting,showexpl,multicol}
16 \usepackage{luatexja}
17 \usepackage[unicode=true]{hyperref}
18 \usepackage[all]{xy}
19 \SelectTips{cm}{}
20
21 \DeclareRobustCommand\eTeX{\ensuremath{\varepsilon}-\kern-.125em\TeX}
22 \DeclareRobustCommand\LuaTeX{Lua\TeX}
23 \DeclareRobustCommand\pTeX{p\kern-.05em\TeX}
24 \DeclareRobustCommand\upTeX{p\kern-.05em\TeX}
25 \DeclareRobustCommand\pLaTeX{p\kern-.05em\LaTeX}
26 \DeclareRobustCommand\pLaTeXe{p\kern-.05em\LaTeXe}
27 \DeclareRobustCommand\epTeX{\ensuremath{\varepsilon}-\kern-.125em\pTeX}
28
29
30 \makeatletter
31 \long\def\@makecaption#1#2{%
32   \vskip\abovecaptionskip
33   \sbox\@tempboxa{{\small #1. #2}}%
34   \ifdim \wd\@tempboxa >\hsize
35     {\small #1. #2}\par
36   \else
37     \global \@minipagefalse
38     \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
39   \fi
40   \vskip\belowcaptionskip}
41 \makeatother
42
43 %<*en>
44 \title{The \LuaTeX-ja package}
45 \author{The \LuaTeX-ja project team}
46 %</en>
47 %<*ja>
48 \title{\LuaTeX-jaパッケージ}
49 \author{\LuaTeX-jaプロジェクトチーム}
50 %</ja>
51
52 \lstset{
53   basicstyle=\ttfamily\small, pos=o, breaklines=true,
54   numbers=none, rframe={}, basewidth=0.5em
55 }
56
57 \parskip=\smallskipamount
58 \begin{document}
59 \catcode`\<=13
60 \def<#1>{{\normalfont\rm\itshape$\langle$#1$\rangle$}}
61 \maketitle
62
63 \tableofcontents
64 \bigskip
65
66 %<*en>
67 {\Large\bf This documentation is far from complete. It may have many
68 grammatical (and contextual) errors.}
69 %</en>
70 %<*ja>
71 \textbf{\large 本ドキュメントはまだまだ未完成です.
72 また,英語版と日本語版をdocstripプログラムを用いることで一緒に生成している都合上,
73 見出しが英語のままになっています.}
74 %</ja>
75
76 \clearpage
77 \part{User's manual}
78
79 \section{Introduction}
80
81 %<*en>
82 The \LuaTeX-ja package is a macro package for typesetting high-quality
83 Japanese documents when using \LuaTeX.
84 %</en>
85 %<*ja>
86 \LuaTeX-jaパッケージは,次世代標準\TeX である\LuaTeX の上で,\pTeX と同等
87 /それ以上の品質の日本語組版を実現させようとするマクロパッケージである.
88 %</ja>
89
90 \subsection{Backgrounds}
91 Traditionally, ASCII \pTeX, an extension of \TeX, and its derivatives
92 are used to typeset Japanese documents in \TeX. \pTeX\ is an engine
93 extension of \TeX: so it can produce high-quality Japanese documents
94 without using very complicated macros. But this point is a mixed
95 blessing: \pTeX\ is left behind from other extensions of \TeX,
96 especially \eTeX\ and pdf\TeX, and from changes about
97 Japanese processing in computers (\textit{e.g.}, the UTF-8 encoding).
98
99 Recently extensions of \pTeX, namely \upTeX\ (Unicode-implementation
100 of \pTeX) and \epTeX\ (merging of \pTeX\ and
101 \eTeX\ extension), have developed to fill those gaps to some
102 extent, but gaps still exist.
103
104 However, the appearance of \LuaTeX\ changed the whole situation. With
105 using Lua `callbacks', users can customize the internal processing of
106 \LuaTeX. So there is no need to modify sources of engines to
107 support Japanese typesetting: to do this, we only have to write Lua
108 scripts for appropriate callbacks.
109
110
111 \subsection{Major Changes from \pTeX}
112 The \LuaTeX-ja package is under much influence of \pTeX\ engine. The initial
113 target of development was to implement features of \pTeX. However,
114 \emph{\LuaTeX-ja is not a just porting of \pTeX; unnatural
115 specifications/behaviors of \pTeX\ were not adopted}.
116
117 The followings are major changes from \pTeX:
118 \begin{itemize}
119 \item A Japanese font is a tuple of a `real' font, a Japanese font
120       metric (\textbf{JFM}, for short), and an optional string called
121       `variation'.
122
123 \item In \pTeX, a linebreak after Japanese character is ignored (and
124       doesn't yield a space), since linebreaks (in source files) are
125       permitted almost everywhere in Japanese texts. However, \LuaTeX-ja
126       doesn't have this function completely, because of a specification
127       of \LuaTeX.
128 \item The insertion process of glues/kerns between two Japanese
129       characters and between a Japanese character and other characters
130       (we refer these glues/kerns as \textbf{JAglue}) is rewritten from
131       scratch.
132
133 \begin{itemize}
134 \item As \LuaTeX's internal character handling is `node-based'
135       (\textit{e.g.}, \verb+of{}fice+ doesn't prevent ligatures), the
136       insertion process of \textbf{JAglue} is now `node-based'.
137 \item Furthermore, nodes between two characters which have no effects in
138       linebreak (\textit{e.g.}, \verb+\special+ node) are ignored in the
139       insertion process.
140 \item In the process, two Japanese fonts which differ in their `real'
141       fonts only are identified.
142 \end{itemize}
143 \item At the present, vertical typesetting (\emph{tategaki}), is not
144       supported in \LuaTeX-ja.
145
146 \end{itemize} 
147 For detailed information, see Part~\ref{part-imp}.
148
149 \subsection{Notations}
150 In this document, the following terms and notations are used:
151 \begin{itemize}
152 \item Characters are divided into two types: 
153 \begin{itemize}
154 \item \textbf{JAchar}: standing for Japanese characters such as
155       Hiragana, Katakana, Kanji and other punctuation marks for
156       Japanese.
157 \item \textbf{ALchar}: standing for all other characters like alphabets. 
158 \end{itemize}
159 We say `alphabetic fonts' for fonts used in \textbf{ALchar}, and `Japanese fonts' for fonts used in \textbf{JAchar}.
160
161 \item A word in a sans-serif font (like \textsf{prebreakpenalty})
162       represents an internal parameter for Japanese typesetting, and it
163       is used as a key in \verb+\ltjsetparameter+ command.
164 \item The word `primitive' is used not only for primitives in \LuaTeX,
165       but also for control sequences that defined in the core module of
166       \LuaTeX-ja.
167 \item In this document, natural numbers start from~0.
168 \end{itemize}
169
170 \subsection{About the project}
171 \paragraph{Project Wiki} Project Wiki is under construction.
172 \begin{itemize}
173 \item \url{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage%28en%29} (English)
174 \item \url{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage} (Japanese)
175 \end{itemize}
176
177 This project is hosted by SourceForge.JP.
178
179 \paragraph{Members}\ 
180 % \begin{multicols}{2}
181 % \begin{itemize}
182 % \item Hironori KITAGAWA
183 % \item Kazuki MAEDA
184 % \item Takayuki YATO
185 % \item Yusuke KUROKI
186 % \item Noriyuki ABE
187 % \item Munehiro YAMAMOTO
188 % \item Tomoaki HONDA
189 % \par\ 
190 % \end{itemize}
191 % \end{multicols}
192
193 % \paragraph{Acknowledgments} -- 挿入するならここ
194
195 \clearpage
196 \section{Getting Started}
197 \subsection{Installation}
198 To install the \LuaTeX-ja\ package, you will need:
199 \begin{itemize}
200 \item \LuaTeX\ (version 0.65.0-beta or later) and its supporting packages.\\
201 If you are using \TeX~Live\ 2011 or current W32\TeX, you don't have to worry.
202 \item The source archive of \LuaTeX-ja, of course{\tt:)}
203 \end{itemize}
204
205 The installation methods are as follows:
206 \begin{enumerate}
207 \item Download the source archive.
208
209 At the present, \LuaTeX-ja has no official release, so you have to retrieve
210 the archive from the repository.
211 You can retrieve the Git repository via
212 \begin{verbatim}
213 $ git clone git://git.sourceforge.jp/gitroot/luatex-ja/luatexja.git
214 \end{verbatim} 
215 or download the archive of HEAD in \texttt{master} branch from
216 \begin{flushleft}
217 \url{http://git.sourceforge.jp/view?p=luatex-ja/luatexja.git;a=snapshot;h=HEAD;sf=tgz}.
218 \end{flushleft}
219 \item Extract the archive. You will see {\tt src/} and several other sub-directories.
220 \item Copy all the contents of {\tt src/} into one of your \texttt{TEXMF} tree.
221 \item If {\tt mktexlsr} is needed to update the filename database, make it so.
222 \end{enumerate}
223
224 \subsection{Cautions}
225 \begin{itemize}
226 \item The encoding of your source file must be UTF-8. 
227 \item Not well-tested. In particular, the default setting of the range
228       of \textbf{JAchar} in the present version does not coexist with
229       other packages which use Unicode fonts. 
230 \end{itemize}
231
232 \subsection{Using in plain \TeX}\label{ssec-plain}
233 To use \LuaTeX-ja in plain \TeX, simply put the following  at the beginning of the document:
234 \begin{verbatim}
235 \input luatexja.sty
236 \end{verbatim}
237
238 This does minimal settings (like {\tt ptex.tex}) for typesetting Japanese documents:
239 \begin{itemize}
240 \item The following 6~Japanese fonts are preloaded:
241 \begin{center}
242 \begin{tabular}{ccccc}
243 \toprule
244 \textbf{classification}&\textbf{font name}&\textbf{13.5\,Q}&\textbf{9.5\,Q}&\textbf{7\,Q}\\\midrule
245 \emph{mincho}&Ryumin-Light    &\verb+\tenmin+&\verb+\sevenmin+&\verb+\fivemin+\\
246 \emph{gothic}&GothicBBB-Medium&\verb+\tengt+ &\verb+\sevengt+ &\verb+\fivegt+\\
247 \bottomrule
248 \end{tabular}
249 \end{center}
250 \begin{itemize}
251 \item The `Q' is a unit used in Japanese phototypesetting, and
252       $1\,\textrm{Q}=0.25\,\textrm{mm}$. This length is stored in a
253       dimension \verb+\jQ+.
254
255 \item It is widely accepted that the font `Ryumin-Light' and
256       `GothicBBB-Medium' aren't embedded into PDF files, and PDF reader
257       substitute them by some external Japanese fonts (\textit{e.g.},
258       Kozuka Mincho is used for Ryumin-Light in Adobe Reader). We adopt this custom to
259       the default setting.
260 \item You may notice that size of above fonts is slightly smaller than
261       their alphabetic counterparts: for example, the size
262       \verb+\texmin+ is $13.5\,\textrm{Q}\simeq 9.60444\,\textrm{pt}$. This is intensional: ...
263 \end{itemize}
264 \item The amount of glue that are inserted between a \textbf{JAchar} and
265       an \textbf{ALchar} (the parameter \textsf{xkanjiskip}) is set to
266 \[
267  0.25\,\hbox{\verb+\zw+}^{+1\,\text{pt}}_{-1\,\text{pt}} = \frac{27}{32}\,\mathrm{mm}^{+1\,\text{pt}}_{-1\,\text{pt}}.
268 \]
269 Here \verb+\zw+ is the counterpart of \texttt{em} for Japanese fonts, that is, the length of `full-width' in current Japanese font.
270 \end{itemize}
271
272 \subsection{Using in \LaTeX}\label{ssec-ltx}
273 \paragraph{\LaTeXe}
274 Using in \LaTeXe\ is basically same. To set up the minimal environment
275 for Japanese, you only have to load {\tt luatexja.sty}:
276 \begin{verbatim}
277 \usepackage{luatexja}
278 \end{verbatim}
279 It also does minimal settings (counterparts in \pLaTeX\ are {\tt
280 plfonts.dtx} and {\tt pldefs.ltx}):
281
282 \begin{itemize}
283 \item {\tt JY3} is the font encoding for Japanese fonts (in horizontal direction).\\
284 When vertical typesetting is supported by \LuaTeX-ja in the future, {\tt JT3} will be used for vertical fonts.
285 \item Two font families {\tt mc} and {\tt gt} are defined: 
286 \begin{center}
287 \begin{tabular}{ccccc}
288 \toprule
289 \textbf{classification}&\textbf{family}&\verb+\mdseries+&\verb+\bfseries+&\textbf{scale}\\\midrule
290 \emph{mincho}&\tt mc&Ryumin-Light    &GothicBBB-Medium&0.960444\\
291 \emph{gothic}&\tt gt&GothicBBB-Medium&GothicBBB-Medium&0.960444\\
292 \bottomrule
293 \end{tabular}
294 \end{center}
295 \textbf{Note on fonts in bold series}
296
297 \item Japanese characters in math mode are typeset by the font family {\tt mc}.
298 \end{itemize}
299
300 However, above settings are not sufficient for Japanese-based
301 documents. To typeset Japanese-based documents, You are better to use
302 class files other than {\tt article.cls}, {\tt book.cls}, \ldots.  At the
303 present, BXjscls (\texttt{bxjsarticle.cls} and \texttt{bxjsbook.cls}, by
304 Takayuki Yato) are better alternative. It is not determined whether
305 \LuaTeX-ja will develop and contain counterparts of major classes used
306 in \pTeX\ (including jsclasses by Haruhiko Okumura).
307
308 \subsection{Changing Fonts}
309 \paragraph{Remark: Japanese Characters in Math Mode}
310 Since \pTeX\ supports Japanese characters in math mode, there are
311 sources like the following:
312
313 \begin{LTXexample}
314 $f_{高温}$~($f_{\text{high temperature}}$).
315 \[ y=(x-1)^2+2\quad{}よって\quad y>0 \]
316 $5\in{}素:=\{\,p\in\mathbb N:\text{$p$ is a prime}\,\}$.
317 \end{LTXexample}
318
319 We (the project members of \LuaTeX-ja) think that using
320 Japanese characters in math mode are allowed if and only if these are used as identifiers.
321 In this point of view, 
322 \begin{itemize}
323 \item The lines 1~and~2 above are not correct, since `高温' in above is used as a textual label, and
324 `よって' is used as a conjunction. 
325 \item However, the line~3 is correct, since `素' is used as an identifier.
326 \end{itemize}
327 Hence, in our opinion, the above input should be corrected as:
328 \begin{LTXexample}
329 $f_{\text{高温}}$~%
330 ($f_{\text{high temperature}}$).
331 \[ y=(x-1)^2+2\quad 
332   \mathrel{\text{よって}}\quad y>0 \]
333 $5\in{}素:=\{\,p\in\mathbb N:\text{$p$ is a prime}\,\}$.
334 \end{LTXexample}
335 %BUG?: \{\}がなければ「素」がでない.上の段落の「よって」もでてない.
336 We also believe that using Japanese characters as identifiers is rare,
337 hence we don't describe how to change Japanese fonts in math mode in
338 this chapter. For the method, please see Part~\ref{part-ref}.
339
340
341 \paragraph{plain \TeX}
342 To change Japanese fonts in plain \TeX, you must use the primitive
343 \verb+\jfont+. So please see Part~\ref{part-ref}.
344
345
346 \paragraph{NFSS2}
347 For \LaTeXe, \LuaTeX-ja simply adopted the font selection system from that
348 of \pLaTeXe\ (in {\tt plfonts.dtx}).
349 \begin{itemize}
350 \item Two control sequences \verb+\mcdefault+ and \verb+\gtdefault+ are
351       used to specify the default font families for \emph{mincho} and
352       \emph{gothic}, respectively. Default values: \texttt{mc} for
353       \verb+\mcdefault+ and \texttt{gt} for \verb+\gtdefault+.
354 \item Commands \verb+\fontfamily+, \verb+\fontseries+,
355       \verb+\fontshape+ and \verb+\selectfont+ can be used to change
356       attributes of Japanese fonts. 
357 \begin{center}
358 \begin{tabular}{ccccc}
359 \toprule
360 &\textbf{encoding}&\textbf{family}&\textbf{series}&\textbf{shape}\\\midrule
361 alphabetic fonts
362 &\verb+\romanencoding+&\verb+\romanfamily+&\verb+\romanseries+&\verb+\romanshape+\\
363 Japanese fonts
364 &\verb+\kanjiencoding+&\verb+\kanjifamily+&\verb+\kanjiseries+&\verb+\kanjishape+\\
365 both&---&--&\verb+\fontseries+&\verb+\fontshape+\\
366 auto select&\verb+\fontencoding+&\verb+\fontfamily+&---&---\\
367 \bottomrule
368 \end{tabular}
369 \end{center}
370 \item For defining a Japanese font family, use \verb+\DeclareKanjiFamily+
371       instead of \verb+\DeclareFontFamily+.
372 \end{itemize}
373
374 \paragraph{fontspec}
375 To coexist with \texttt{fontspec} package, it is needed to load
376 \texttt{luatexja-fontspec} package in the preamble. This additional
377 package automatically loads \texttt{luatexja} and \texttt{fontspec}
378 package, if needed.
379
380 In \texttt{luatexja-fontspec} package, the following 7~commands are defined as
381 counterparts of original commands in \texttt{fontspec}:
382 \begin{center}
383 \begin{tabular}{ccccc}
384 \toprule
385 Japanese fonts
386 &\verb+\jfontspec+&\verb+\setmainjfont+&\verb+\setsansjfont+&\verb+\newjfontfamily+\\
387 alphabetic fonts
388 &\verb+\fontspec+&\verb+\setmainfont+&\verb+\setsansfont+&\verb+\newfontfamily+\\
389 \midrule
390 Japanese fonts
391 &\verb+\newjfontface+&\verb+\defaultjfontfeatures+&\verb+\addjfontfeatures+\\
392 alphabetic fonts
393 &\verb+\newfontface+&\verb+\defaultfontfeatures+&\verb+\addfontfeatures+\\
394 \bottomrule
395 \end{tabular}
396 \end{center}
397 使用例
398
399
400 Note that there is no command named \verb+\setmonojfont+, since it is
401 popular for Japanese fonts that nearly all Japanese glyphs have same
402 widths.  Also note that the kerning feature is set off by default in
403 these 7~commands, since this feature and \textbf{JAglue} will clash (see
404 \ref{para-kern}).
405
406 \section{Changing Parameters}
407 There are many parameters in \LuaTeX-ja. And due to the behavior of \LuaTeX,
408 most of them are not stored as internal register of \TeX, but as an
409 original storage system in \LuaTeX-ja. Hence, to assign or acquire those
410 parameters, you have to use commands \verb+\ltjsetparameter+ and
411 \verb+\ltjgetparameter+.
412
413 \subsection{Editing the range of \textbf{JAchar}s}
414
415
416 To edit the range of \textbf{JAchar}s, You have to assign a non-zero
417 natural number which is less than 217 to the character range first. This
418 can be done by using \verb+\ltjdefcharrange+ primitive. For example, the
419 next line assigns whole characters in Supplementary Multilingual Plane
420 and the character `漢' to the range number~100.
421 \begin{lstlisting}
422 \ltjdefcharrange{100}{"10000-"1FFFF,`漢}
423 \end{lstlisting}
424 This assignment of numbers to ranges are always global, so you should
425 not do this in the middle of a document. 上書き
426
427 After assigning numbers to ranges, ...
428
429 \paragraph{Default Setting}
430 Lua\TeX-ja predefines eight character ranges for convinience. They are
431 determined from the following data:
432 \begin{itemize}
433 \item Blocks in Unicode~6.0.
434 \item The \texttt{Adobe-Japan1-UCS2} mapping between a CID Adobe-Japan1-6 and Unicode.
435 \item The \texttt{PXbase} bundle for \upTeX\ by Takayuki Yato.
436 \end{itemize}
437
438 Now we describe these eight ranges. The alphabet `J' or `A' after the
439 number shows whether characters in the range is treated as
440 \textbf{JAchar}s or not by default. These settings are similar to \texttt{prefercjk} ...
441 \begin{description}
442 \item[Range~8${}^{\text{J}}$] Symbols in the intersection of the upper half of ISO~8859-1
443          (Latin-1 Supplement) and JIS~X~0208 (a basic character set for Japanese). This character range
444          consists of the following charatcers:
445 \begin{multicols}{2}
446 \begin{itemize}
447 \def\ch#1#2{\item \char"#1\ ({\tt U+00#1}, #2)}%"
448 \ch{A7}{Section Sign}
449 \ch{A8}{Umlaut or diaeresis}
450 \ch{B0}{Degree sign}
451 \ch{B1}{Plus-minus sign}
452 \ch{B4}{Spacing acute}
453 \ch{B6}{Paragraph sign}
454 \ch{D7}{Multiplication sign}
455 \ch{F7}{Division Sign}
456 \end{itemize}
457 \end{multicols}
458 \item[Range~1${}^{\text{A}}$] Latin characters that some of them are included in Adobe-Japan1-6.
459 This range consist of the following Unicode ranges, \emph{except characters in the range~8 above}:
460 \begin{multicols}{2}
461 \begin{itemize}
462 \item {\tt U+0080}--{\tt U+00FF}: Latin-1 Supplement
463 \item {\tt U+0100}--{\tt U+017F}: Latin Extended-A
464 \item {\tt U+0180}--{\tt U+024F}: Latin Extended-B
465 \item {\tt U+0250}--{\tt U+02AF}: IPA Extensions
466 \item {\tt U+02B0}--{\tt U+02FF}: Spacing Modifier Letters
467 \item {\tt U+0300}--{\tt U+036F}: Combining Diacritical Marks
468 \item {\tt U+1E00}--{\tt U+1EFF}: Latin Extended Additional
469 \par\ 
470 \end{itemize}
471 \end{multicols}
472 \item[Range~2${}^{\text{J}}$] Greek and Cyrillic letters. JIS~X~0208 (hence most of Japanese
473            fonts) has some of these characters.
474 \begin{multicols}{2}
475 \begin{itemize}
476 \item {\tt U+0370}--{\tt U+03FF}: Greek and Coptic
477 \item {\tt U+0400}--{\tt U+04FF}: Cyrillic
478 \item {\tt U+1F00}--{\tt U+1FFF}: Greek Extended
479 \\\ 
480 \end{itemize}
481 \end{multicols}
482 \item[Range~3${}^{\text{J}}$] Punctuations and Miscellaneous symbols. The block list is
483            indicated in Table~\ref{table-rng3}.
484 \begin{table}[p]
485 \caption{Unicode blocks in predefined character range~3.}\label{table-rng3}
486 \catcode`\"=13\def"#1#2#3#4{{\tt U+#1#2#3#4}}%"
487 \begin{center}
488 \begin{tabular}{ll}
489 "2000--"206F&General Punctuation\\
490 "2070--"209F&Superscripts and Subscripts\\
491 "20A0--"20CF&Currency Symbols\\
492 "20D0--"20FF&Combining Diacritical Marks for Symbols\\
493 "2100--"214F&Letterlike Symbols\\
494 "2150--"218F&Number Forms\\
495 "2190--"21FF&Arrows\\
496 "2200--"22FF&Mathematical Operators\\
497 "2300--"23FF&Miscellaneous Technical\\
498 "2400--"243F&Control Pictures\\
499 "2500--"257F&Box Drawing\\
500 "2580--"259F&Block Elements\\
501 "25A0--"25FF&Geometric Shapes\\
502 "2600--"26FF&Miscellaneous Symbols\\
503 "2700--"27BF&Dingbats\\
504 "2900--"297F&Supplemental Arrows-B\\
505 "2980--"29FF&Miscellaneous Mathematical Symbols-B\\
506 "2B00--"2BFF&Miscellaneous Symbols and Arrows\\
507 "E000--"F8FF&Private Use Area\\
508 "FB00--"FB4F&Alphabetic Presentation Forms
509 \end{tabular}
510 \end{center}
511 \end{table}
512 \item[Range~4${}^{\text{A}}$] Characters usually not in Japanese fonts. This range consists
513            of almost all Unicode blocks which are not in other
514            predefined ranges. Hence, instead of showing the block list,
515            we put the definition of this range itself:
516 \begin{lstlisting}
517 \ltjdefcharrange{4}{%
518    "500-"10FF, "1200-"1DFF, "2440-"245F, "27C0-"28FF, "2A00-"2AFF, 
519   "2C00-"2E7F, "4DC0-"4DFF, "A4D0-"A82F, "A840-"ABFF, "FB50-"FE0F, 
520   "FE20-"FE2F, "FE70-"FEFF, "10000-"1FFFF} % non-Japanese
521 \end{lstlisting}
522 \item[Range~5${}^{\text{A}}$] Surrogates and Supplementary Private Use Areas.
523 \item[Range~6${}^{\text{J}}$] Characters used in Japanese. The block list is indicated in Table~\ref{table-rng6}.
524 \begin{table}[p]
525 \caption{Unicode blocks in predefined character range~6.}\label{table-rng6}
526 \catcode`\"=13\def"#1#2#3#4{{\tt U+#1#2#3#4}}%"
527 \begin{center}
528 \begin{tabular}{ll}
529 "2460--"24FF&Enclosed Alphanumerics\\
530 "2E80--"2EFF&CJK Radicals Supplement\\
531 "3000--"303F&CJK Symbols and Punctuation\\
532 "3040--"309F&Hiragana\\
533 "30A0--"30FF&Katakana\\
534 "3190--"319F&Kanbun\\
535 "31F0--"31FF&Katakana Phonetic Extensions\\
536 "3200--"32FF&Enclosed CJK Letters and Months\\
537 "3300--"33FF&CJK Compatibility\\
538 "3400--"4DBF&CJK Unified Ideographs Extension A\\
539 "4E00--"9FFF&CJK Unified Ideographs\\
540 "F900--"FAFF&CJK Compatibility Ideographs\\
541 "FE10--"FE1F&Vertical Forms\\
542 "FE30--"FE4F&CJK Compatibility Forms\\
543 "FE50--"FE6F&Small Form Variants\\
544 "{20}000--"{2F}FFF&(Supplementary Ideographic Plane)
545 \end{tabular}
546 \end{center}
547 \end{table}
548 \item[Range~7${}^{\text{J}}$] Characters used in CJK languages, but not included in  Adobe-Japan1-6.
549 The block list is indicated in Table~\ref{table-rng7}.
550 \begin{table}[p]
551 \caption{Unicode blocks in predefined character range~7.}\label{table-rng7}
552 \catcode`\"=13\def"#1#2#3#4{{\tt U+#1#2#3#4}}%"
553 \begin{center}
554 \begin{tabular}{ll}
555 "1100--"11FF&Hangul Jamo\\
556 "2F00--"2FDF&Kangxi Radicals\\
557 "2FF0--"2FFF&Ideographic Description Characters\\
558 "3100--"312F&Bopomofo\\
559 "3130--"318F&Hangul Compatibility Jamo\\
560 "31A0--"31BF&Bopomofo Extended\\
561 "31C0--"31EF&CJK Strokes\\
562 "A000--"A48F&Yi Syllables\\
563 "A490--"A4CF&Yi Radicals\\
564 "A830--"A83F&Common Indic Number Forms\\
565 "AC00--"D7AF&Hangul Syllables\\
566 "D7B0--"D7FF&Hangul Jamo Extended-B
567 \end{tabular}
568 \end{center}
569 \end{table}
570 \end{description}
571
572
573 \subsection{\textsf{kanjiskip} and \textsf{xkanjiskip}}\label{subs-kskip}
574 \textbf{JAglue} is divided into the following three categories:
575 \begin{itemize}
576 \item Glues/kerns specified in JFM. If \verb+\inhibitglue+ is issued
577       around a Japanese character, this glue will be not inserted at the
578       place.
579 \item The default glue which inserted between two \textbf{JAchar}s ({\sf
580       kanjiskip}).
581 \item The default glue which inserted between a \textbf{JAchar} and an
582       \textbf{ALchar} (\textsf{xkanjiskip}).
583 \end{itemize}
584 The value (a skip) of \textsf{kanjiskip} or \textsf{xkanjiskip} can be
585 changed as the following.
586 \begin{lstlisting}
587 \ltjsetparameter{kanjiskip={0pt plus 0.4pt minus 0.4pt}, 
588                  xkanjiskip={0.25\zw plus 1pt minus 1pt}}
589 \end{lstlisting}
590
591
592 It may occur that JFM contains the data of `ideal width of {\sf
593 kanjiskip}' and/or `ideal width of \textsf{xkanjiskip}'.
594 To use these data from JFM, set the value of \textsf{kanjiskip} or 
595 \textsf{xkanjiskip} to \verb+\maxdimen+.
596
597 \subsection{Insertion Setting of \textsf{xkanjiskip}}
598 It is not desirable that \textsf{xkanjiskip} is inserted between every
599 boundary between \textbf{JAchar}s and \textbf{ALchar}s. For example,
600 \textsf{xkanjiskip} should not be inserted after opening parenthesis
601 (\textit{e.g.}, compare `(あ' and `(\hskip\ltjgetparameter{xkanjiskip}あ').
602
603 \LuaTeX-ja can control whether \textsf{xkanjiskip} can be inserted
604 before/after a character, by changing \textsf{jaxspmode} for \textbf{JAchar}s and
605 \textsf{alxspmode} parameters \textbf{ALchar}s respectively. 
606 \begin{LTXexample}
607 \ltjsetparameter{jaxspmode={`あ,preonly}, alxspmode={`\!,postonly}} 
608 pあq い!う
609 \end{LTXexample}
610
611 The second argument {\tt preonly} means `the insertion of
612 \textsf{xkanjiskip} is allowed before this character, but not after'.
613 the other possible values are {\tt postonly}, {\tt allow} and {\tt
614 inhibit}. For the compatibility with \pTeX, natural numbers between
615 0~and~3 are also allowed as the second argument\footnote{But we don't
616 recommend this: since numbers 1~and~2 have opposite meanings in
617 \textsf{jaxspmode} and \textsf{alxspmode}.}.
618
619 If you want to enable/disable all insertions of \textsf{kanjiskip} and
620 \textsf{xkanjiskip}, set \textsf{autospacing} and \textsf{autoxspacing}
621 parameters to {\tt false}, respectively.
622
623
624 \subsection{Shifting Baseline}
625 To make a match between a Japanese font and an alphabetic font, sometimes
626 shifting of the baseline of one of the pair is needed. In \pTeX, this is achieved
627 by setting \verb+\ybaselineshift+ to a non-zero length (the
628 baseline of alphabetic fonts is shifted below). However, for documents
629 whose main language is not Japanese, it is good to shift the baseline of
630 Japanese fonts, but not that of alphabetic fonts.
631 Because of this, \LuaTeX-ja can independently set the shifting amount
632 of the baseline of alphabetic fonts (\textsf{yalbaselineshift}
633 parameter) and that of Japanese fonts (\textsf{yjabaselineshift}
634 parameter). 
635
636 \begin{LTXexample}
637 \vrule width 150pt height 0.4pt depth 0pt\hskip-120pt
638 \ltjsetparameter{yjabaselineshift=0pt, yalbaselineshift=0pt}abcあいう
639 \ltjsetparameter{yjabaselineshift=5pt, yalbaselineshift=2pt}abcあいう
640 \end{LTXexample}
641 Here the horizontal line in above is the baseline of a line.
642
643 There is an interesting side-effect: characters in different size can be
644 vertically aligned center in a line, by setting two parameters appropriately.
645 The following is an example (beware the value is not well tuned):
646 \begin{LTXexample}
647 xyz漢字 
648 {\scriptsize
649   \ltjsetparameter{yjabaselineshift=-1pt, 
650     yalbaselineshift=-1pt}
651   XYZひらがな
652 }abcかな
653 \end{LTXexample}
654
655
656 \subsection{Cropmark}
657 Cropmark is a mark for indicating 4~corners and horizontal/vertical
658 center of the paper. In Japanese, we call cropmark as tombo(w).
659 \pLaTeX\ and this \LuaTeX-ja support `tombow' by their kernel.
660 The following steps are needed to typeset cropmark:
661
662 \begin{enumerate}
663 \item First, define the banner which will be printed at the upper left
664       of the paper. This is done by assigning a token list to
665       \verb+\@bannertoken+.
666
667 For example, the following sets banner as `{\tt filename (2012-01-01 17:01)}':
668 \begin{verbatim}
669 \makeatletter
670
671 \hour\time \divide\hour by 60 \@tempcnta\hour \multiply\@tempcnta 60\relax
672 \minute\time \advance\minute-\@tempcnta
673 \@bannertoken{%
674    \jobname\space(\number\year-\two@digits\month-\two@digits\day
675    \space\two@digits\hour:\two@digits\minute)}%
676 \end{verbatim}
677
678 \item ...
679 \end{enumerate}
680
681
682 \part{Reference}\label{part-ref}
683 \section{Font Metric and Japanese Font}
684 \subsection{\texttt{\char92jfont} primitive}
685 To load a font as a Japanese font, you must use the
686 \verb+\jfont+ primitive instead of~\verb+\font+, while
687 \verb+\jfont+ admits the same syntax used in~\verb+\font+. 
688 \LuaTeX-ja automatically loads \texttt{luaotfload} package,
689 so TrueType/OpenType fonts with features can be used for Japanese fonts:
690 \begin{LTXexample}
691 \jfont\tradgt={file:ipaexg.ttf:script=latn;%
692   +trad;-kern;jfm=ujis} at 14pt
693 \tradgt{}当/体/医/区
694 \end{LTXexample}
695
696 Note that the defined control sequence
697 (\verb+\tradgt+ in the example above) using \verb+\jfont+ is not a
698 \textit{font\_def} token, hence the input like
699 \verb+\fontname\tradgt+ causes a error. We denote control sequences which are defined in \verb+\jfont+
700 by <jfont\_cs>.
701
702 \paragraph{Prefix}
703 Besides \texttt{file:}\ and \texttt{name:}\ prefixes, \texttt{psft:}\ can
704 be used a prefix in \verb+\jfont+ (and~\verb+\font+) primitive.  Using
705 this prefix, you can specify a font that has its name only and is not
706 related to any real font.
707
708 Mainly, use of this \texttt{psft:}\ prefix is for using non-embedding
709 `standard' Japanese fonts (Ryumin-Light and GothicBBB-Medium). 歴史
710
711 \paragraph{JFM}
712 jfm, jfmvar
713
714 \paragraph{Note: kern feature}\label{para-kern}
715 Some fonts have information for inter-glyph spacing. However, this
716 information is not well-compatible with \LuaTeX-ja.  More concretely,
717 this kerning space from this information are inserted \emph{before} the
718 insertion process of \textbf{JAglue}, and this causes incorrect spacing
719 between two characters when both a glue/kern from the data in the font
720 and it from JFM are present.
721
722 \begin{itemize}
723 \item You should specify {\tt -kern} in
724 {\tt\char92jfont} primitive, when you want to use other font features,
725       such as {\tt script=...}\,.
726 \item If you want to use Japanese fonts in proportinal width, and use
727       information from this font, use \texttt{jfm-prop.lua} for its JFM, and ...
728
729 TODO: kanjiskip?
730 \end{itemize}
731
732
733 \subsection{Structure of JFM file}
734 A JFM file is a Lua script which has only one function call:
735 \begin{verbatim}
736 luatexja.jfont.define_jfm { ... }
737 \end{verbatim}
738 Real data are stored in the table which indicated above by
739 \verb+{ ... }+.  So, the rest of this subsection are devoted to describe the
740 structure of this table.  Note that all lengths in a JFM file are
741 floating-point numbers in design-size unit.
742
743 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
744 \item[dir=<direction>] (required)
745
746 The direction of JFM. At the present, only \texttt{'yoko'} is supported.
747
748 \item[zw=<length>] (required)
749
750 The amount of the length of the `full-width'.
751
752 \item[zh=<length>] (required)
753
754 \item[kanjiskip=\{<natural>, <stretch>, <shrink>\}] (optional)
755
756 This field specifies the `ideal' amount of \textsf{kanjiskip}. As noted
757              in Subsection~\ref{subs-kskip}, if the parameter
758              \textsf{kanjiskip} is \verb+\maxdimen+, the value specified
759              in this field is actually used (if this field is not specified in
760              JFM, it is regarded as 0\,pt). Note that <stretch> and <shrink>
761              fields are in design-size unit too.
762
763
764 \item[xkanjiskip=\{<natural>, <stretch>, <shrink>\}] (optional)
765
766 Like the \texttt{kanjiskip} field, this field specifies the `ideal'
767              amount of \textsf{xkanjiskip}.
768
769 \end{list}
770
771 Besides from above fields, a JFM file have several sub-tables those
772 indices are natural numbers.  The table indexed by~$i\in\omega$ stores
773 informations of `character class'~$i$. At least, the character class~0 is
774 always present, so each JFM file must have a sub-table whose index is
775 \texttt{[0]}.  Each sub-table (its numerical index is denoted by $i$) has
776 the following fields:
777
778 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
779 \item[chars=\{<character>, ...\}] (required except character class~0)
780
781 This field is a list of characters which are in this character
782              type~$i$. This field is not required if $i=0$, since all
783              \textbf{JAchar} which are not in any character class other
784              than 0 (hence, the character class~0 contains most of
785              \textbf{JAchar}s). In the list, a character can be
786              specified by its code number, or by the character itself
787              (as a string of length~1). 
788
789 In addition to those `real' characters, the following `imaginary
790              characters' can be specified in the list:
791
792 \item[width=<length>, height=<length>, depth=<length>, italic=<length>]\ (required)
793
794 Specify width of characters in character class~$i$, height, depth and
795 the amount of italic correction. All characters in character class~$i$ are regarded that its width, height and depth are
796 as values of these fields. 
797 But there is one exception: if \texttt{'prop'} is specified in \texttt{width} field, width of a character becomes that of its `real' glyph 
798
799 \item[left=<length>, down=<length>, align=<align>]\ 
800
801 These fields are for adjusting the position of the `real' glyph. Legal
802              values of \texttt{align} field are \texttt{'left'},
803              \texttt{'middle'} and \texttt{'right'}. If one of these
804              3~fields are omitted, \texttt{left} and \texttt{down} are
805              treated as~0, and \texttt{align} field is treated as
806              \texttt{'left'}.
807 The effects of these 3~fields are indicated in Figure~\ref{fig-pos}.
808
809 In most cases, \texttt{left} and \texttt{down} fields are~0, while
810 it is not uncommon that the \texttt{align} field is \texttt{'middle'} or \texttt{'right'}.
811 For example, setting the \texttt{align} field to \texttt{'right'} is practically needed 
812 when the current character class is the class for opening delimiters'. 
813 \begin{figure}[tb]
814 \begin{minipage}{0.4\textwidth}%
815 \begin{center}\unitlength=10pt\small
816 \begin{picture}(15,12)(-1,-4)
817 \color{black!10!white}% real glyph :step1
818 \put(0,0){\vrule width 12\unitlength height 8\unitlength depth 3\unitlength}
819
820 \color{red!20!white}% real glyph :step1
821 \put(-1,-1.5){\vrule width 6\unitlength height 7\unitlength depth 2.5\unitlength}
822
823 \color{red}% real glyph
824 \thicklines
825 \put(-1,-1.5){\vector(0,1){7}\vector(0,-1){2.5}\vector(1,0){6}}
826 \put(5,-1.5){\line(0,1){7}\line(0,-1){2.5}}
827 \put(-1,5.5){\line(1,0){6}}
828 \put(-1,-4){\line(1,0){6}}
829
830 \color{green!20!white}% real glyph :step1
831 \put(3,0){\vrule width 6\unitlength height 7\unitlength depth 2.5\unitlength}
832
833 \color{black}% real glyph :step1
834 \thicklines
835 \put(0,0){\vector(0,1){8}\line(0,-1){3}\vector(1,0){12}}
836 \put(12,0){\line(0,1){8}\vector(0,-1){3}}
837 \put(0,8){\line(1,0){12}}
838 \put(0,-3){\line(1,0){12}}
839 \put(0.2,4){\makebox(0,0)[l]{\texttt{height}}}
840 \put(12.2,-1.5){\makebox(0,0)[l]{\texttt{depth}}}
841 \put(6,0.2){\makebox(0,0)[b]{\texttt{width}}}
842
843 \color{green!50!black}% real glyph :step1
844 \thicklines
845 \put(3,0){\vector(0,1){7}\vector(0,-1){2.5}\vector(1,0){6}}
846 \put(9,0){\line(0,1){7}\line(0,-1){2.5}}
847 \put(3,7){\line(1,0){6}}
848 \put(3,-2.5){\line(1,0){6}}
849 \newsavebox{\eqdist}
850 \savebox{\eqdist}(0,0)[b]{%
851   \thinlines
852   \put(-0.08,0.2){\line(0,-1){0.4}}%
853   \put(0.08,0.2){\line(0,-1){0.4}}}
854 \put(1.5,0){\usebox{\eqdist}}
855 \put(10.5,0){\usebox{\eqdist}}
856
857 \color{blue}% shifted
858 \thicklines
859 \put(3,-1.5){\vector(-1,0){4}}
860 \put(1,-1.7){\makebox(0,0)[t]{\texttt{left}}}
861 \put(3,0){\vector(0,-1){1.5}}
862 \put(3.2,-0.75){\makebox(0,0)[l]{\texttt{down}}}
863 \end{picture} 
864 \end{center}
865 \end{minipage}%
866 \begin{minipage}{0.6\textwidth}%
867 Consider a node containing Japanese character whose value of the \texttt{align} 
868 field is \texttt{'middle'}.
869 \begin{itemize}
870 \item The black rectangle is a frame of the node.
871 Its width, height and depth are specified by JFM.
872 \item Since the \texttt{align} field is \texttt{'middle'}, 
873 the `real' glyph is centered horizontally (the green rectangle).
874 \item Furthermore, the glyph is shifted according to values of fields
875       \texttt{left} and \texttt{down}. The ultimate position of the real
876       glyph is indicated by the red rectangle.
877 \end{itemize}
878 \end{minipage}
879 \caption{The position of the `real' glyph.}
880 \label{fig-pos}
881 \end{figure}
882
883
884 \item[kern={\{[$j$]=<kern>, ...\}}]
885
886 \item[glue={\{[$j$]=\{<width>, <stretch>, <shrink>\}, ...\}}]
887 \end{list}
888
889 \subsection{Math Font Family}
890 \TeX\ handles fonts in math formulas by 16~font families\footnote{Omega,
891 Aleph, \LuaTeX~and $\varepsilon$-\kern-.125em(u)\pTeX can handles 256~families, but
892 an external package is needed to support this in plain \TeX\ and
893 \LaTeX.}, and each family has three fonts:
894 \verb+\textfont+, \verb+\scriptfont+ and \verb+\scriptscriptfont+.
895
896 \LuaTeX-ja's handling of Japanese fonts in math formulas is similar;
897 Table~\ref{tab-math} shows counterparts to \TeX's primitives for math
898 font families.
899
900 \begin{table}[tb]
901 \label{tab-math}
902 \caption{Primitives for Japanese math fonts.}
903 \begin{center}\def\{{\char`\{}\def\}{\char`\}}
904 \begin{tabular}{lll}
905 \toprule
906 &Japanese fonts&alphabetic fonts\\
907 \midrule
908 font family&\verb+\jfam+${}\in [0,256)$&\verb+\fam+\\
909 text size&\tt\textsf{jatextfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\verb+\textfont+<fam>=<font\_cs>\\
910 script size&\tt\textsf{jascriptfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\verb+\scriptfont+<fam>=<font\_cs>\\
911 scriptscript size&\tt\textsf{jascriptscriptfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\verb+\scriptscriptfont+<fam>=<font\_cs>\\
912 \bottomrule
913 \end{tabular}
914 \end{center}
915 \end{table}
916
917
918 \section{Parameters}
919 \subsection{{\tt\char92 ltjsetparameter} primitive}
920 As noted before, \verb+\ltjsetparameter+ and \verb+\ltjgetparameter+ are
921 primitives for accessing most parameters of \LuaTeX-ja. One of the main
922 reason that \LuaTeX-ja didn't adopted the syntax similar to that of \pTeX\ 
923 (\textit{e.g.},~\verb+\prebreakpenalty`)=10000+) 
924 is the position of \verb+hpack_filter+ callback in the source
925 of \LuaTeX, see Section~\ref{sec-para}.
926
927 \verb+\ltjsetparameter+ and \verb+\ltjglobalsetparameter+ are primitives
928 for assigning parameters. These take one argument which is a
929 \texttt{<key>=<value>} list. Allowed keys are described in the next
930 subsection.  
931 The difference between
932 \verb+\ltjsetparameter+ and \verb+\ltjglobalsetparameter+ is only the
933 scope of assignment;
934 \verb+\ltjsetparameter+ does a local assignment and 
935 \verb+\ltjglobalsetparameter+ does a global one. 
936 They also obey the value of \verb+\globaldefs+,
937 like other assignment.
938
939 \verb+\ltjgetparameter+ is the primitive for acquiring parameters. It
940 always takes a parameter name as first argument, and also takes the
941 additional argument---a character code, for example---in some cases.
942 \begin{LTXexample}
943 \ltjgetparameter{differentjfm}, 
944 \ltjgetparameter{autospacing},
945 \ltjgetparameter{prebreakpenalty}{`)}.
946 \end{LTXexample}
947 \emph{The return value of\/ {\normalfont\tt\char92ltjgetparameter} is
948 always a string}. This is outputted by \texttt{tex.write()}, so any
949 character other than space~`{\tt\char32}'~(U+0020) has the category code
950 12~(other), while the space has 10~(space).
951
952 \subsection{List of Parameters}
953 In the following list of parameters, [\verb+\cs+] indicates the counterpart in \pTeX, and each symbol has the following meaning:
954 \begin{itemize}
955 \item No mark: values at the end of the paragraph or the hbox are
956       adopted in the whole paragraph/hbox.
957 \item `\ast' : local parameters, which can change everywhere inside a paragraph/hbox.
958 \item `\dagger': assignments are always global.
959 \end{itemize}
960
961 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
962 \item[\textsf{jcharwidowpenalty}\,=<penalty>] [\verb+\jcharwidowpenalty+]
963
964 Penalty value for supressing orphans. This penalty is inserted just
965              after the last \textbf{JAchar} which is not regarded as a
966              (Japanese) punctuation mark.
967
968 \item[\textsf{kcatcode}\,=\{<chr\_code>,<natural number>\}]\
969
970 An additional attributes having each character whose character code is <chr\_code>.  
971 At the present version, the lowermost bit of <natural number> indicates
972              whether the character is considered as a punctuation mark
973              (see the description of \textsf{jcharwidowpenalty} above).
974
975
976 \item[\textsf{prebreakpenalty}\,=\{<chr\_code>,<penalty>\}] [\verb+\prebreakpenalty+]
977 \item[\textsf{postbreakpenalty}\,=\{<chr\_code>,<penalty>\}] [\verb+\postbreakpenalty+]
978 \item[\textsf{jatextfont}\,=\{<jfam>,<jfont\_cs>\}] [\verb+\textfont+ in \TeX]
979 \item[\textsf{jascriptfont}\,=\{<jfam>,<jfont\_cs>\}] [\verb+\scriptfont+ in \TeX]
980 \item[\textsf{jascriptscriptfont}\,=\{<jfam>,<jfont\_cs>\}] [\verb+\scriptscriptfont+ in \TeX]
981 \item[\textsf{yjabaselineshift}\,=<dimen>$^\ast$]\ 
982 \item[\textsf{yalbaselineshift}\,=<dimen>$^\ast$] [\verb+\ybaselineshift+]
983
984 \item[\textsf{jaxspmode}\,=\{<chr\_code>,<mode>\}] [\verb+\inhibitxspcode+]
985
986 Setting whether inserting  \textsf{xkanjiskip} is allowed before/after a \textbf{JAchar} whose character code is <chr\_code>.
987 The followings are allowed for <mode>:
988 \begin{description}
989 \item[0, \texttt{inhibit}] Insertion of \textsf{xkanjiskip} is inhibited before the charater, nor after the charater.
990 \item[2, \texttt{preonly}] Insertion of \textsf{xkanjiskip} is allowed before the charater, but not after.
991 \item[1, \texttt{postonly}] Insertion of \textsf{xkanjiskip} is allowed after the charater, but not before.
992 \item[3, \texttt{allow}] Insertion of \textsf{xkanjiskip} is allowed before the charater and after the charater.
993 This is the default value.
994 \end{description}
995
996 \item[\textsf{alxspmode}\,=\{<chr\_code>,<mode>\}] [\verb+\xspcode+]
997
998 Setting whether inserting  \textsf{xkanjiskip} is allowed before/after a \textbf{ALchar} whose character code is <chr\_code>.
999 The followings are allowed for <mode>:
1000 \begin{description}
1001 \item[0, \texttt{inhibit}] Insertion of \textsf{xkanjiskip} is inhibited before the charater, nor after the charater.
1002 \item[1 \texttt{preonly}] Insertion of \textsf{xkanjiskip} is allowed before the charater, but not after.
1003 \item[2 \texttt{postonly}] Insertion of \textsf{xkanjiskip} is allowed after the charater, but not before.
1004 \item[3, \texttt{allow}] Insertion of \textsf{xkanjiskip} is allowed before the charater and after the charater.
1005 This is the default value.
1006 \end{description}
1007 Note that parameters \textsf{jaxspmode} and \textsf{alxspmode} use a common table.
1008
1009 \item[\textsf{autospacing}\,=<bool>$^\ast$] [\verb+\autospacing+]
1010 \item[\textsf{autoxspacing}\,=<bool>$^\ast$] [\verb+\autoxspacing+]
1011 \item[\textsf{kanjiskip}\,=<skip>] [\verb+\kanjiskip+]
1012 \item[\textsf{xkanjiskip}\,=<skip>] [\verb+\xkanjiskip+]
1013
1014 \item[\textsf{differentjfm}\,=<mode>$^\dagger$]
1015
1016 Specify how glues/kerns between two \textbf{JAchar}s whose JFM (or size) are different. 
1017 The allowed arguments are the followings:
1018 \begin{description}
1019 \item[\texttt{average}]
1020 \item[\texttt{both}]
1021 \item[\texttt{large}]
1022 \item[\texttt{small}]
1023 \end{description}
1024
1025 \item[\textsf{jacharrange}\,=<ranges>$^\ast$]
1026 \item[\textsf{kansujichar}\,=\{<digit>, <chr\_code>\}] [\verb+\kansujichar+]
1027 \end{list}
1028
1029
1030 \section{Other Primitives}
1031 \subsection{Compatibility with \pTeX}
1032 \begin{list}{}{\def\makelabel{\ttfamily\char92 }}
1033 \item[kuten]
1034 \item[jis]
1035 \item[euc]
1036 \item[sjis]
1037 \item[ucs]
1038 \item[kansuji]
1039 \end{list}
1040
1041 \section{Control Sequences for \LaTeXe}
1042 \subsection{Patch for NFSS2}
1043 As described in Subsection~\ref{ssec-ltx}, \LuaTeX-ja simply adopted \texttt{plfonts.dtx} in \pLaTeXe\ for the Japanese patch for NFSS2. 
1044
1045 \subsection{Cropmark/`tombow'}
1046
1047 \part{Implementations}\label{part-imp}
1048 \section{Storing Parameters}\label{sec-para}
1049 \subsection{Used Dimensions and Attributes}
1050 Here the following is the list of dimension and attributes which are used in \LuaTeX-ja.
1051 \begin{list}{}{%
1052 \def\makelabel{\ttfamily}
1053 \def\dim#1{\item[\char92 #1\ \textrm{(dimension)}]}
1054 \def\attr#1{\item[\char92 #1\ \textrm{(attribute)}]}
1055 }
1056
1057 \dim{jQ}
1058 As explained in Subsection~\ref{ssec-plain}, \verb+\jQ+ is equal to
1059                         $1\,\textrm{Q}=0.25\,\textrm{mm}$, where `Q'~(also called `級') is
1060                         a unit used in Japanese phototypesetting. So one should not change the value of this dimension. 
1061 \dim{jH}
1062 There is also a unit called `歯' which equals to $0.25\,\textrm{mm}$ and
1063                         used in Japanese phototypesetting. The dimension
1064                         \verb+\jH+ stores this length, similar to \verb+\jQ+. 
1065 \dim{ltj@zw} A temporal register for the `full-width' of current Japanese font.
1066 \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.
1067 \attr{jfam} Current number of Japanese font family for math formulas.
1068 \attr{ltj@curjfnt} The font index of current Japanese font.
1069 \attr{ltj@charclass} The character class of Japanese \textit{glyph\_node}.
1070 \attr{ltj@yablshift} The amount of shifting the baseline of alphabetic
1071                         fonts in scaled point ($2^{-16}\,\textrm{pt}$).
1072 \attr{ltj@ykblshift} The amount of shifting the baseline of Japanese
1073                         fonts in scaled point ($2^{-16}\,\textrm{pt}$).
1074 \attr{ltj@autospc} Whether the auto insertion of \textsf{kanjiskip} is allowed at the node.
1075 \attr{ltj@autoxspc} Whether the auto insertion of \textsf{xkanjiskip} is allowed at the node.
1076 \attr{ltj@icflag} For distinguishing `kinds' of the node. To this
1077                         attribute, one of the following value is
1078                         assigned:
1079 \begin{description}
1080 \item[ITALIC (1)] Glues from an itaric correction
1081            (\verb+\/+). This distinction of origins of glues 
1082            (from explicit \verb+\kern+, or from \verb+\/+)
1083            is needed in the insertion process of \textsf{xkanjiskip}.
1084 \item[PACKED (2)] 
1085 \item[KINSOKU (3)] Penalties inserted for the word-wrapping  process of Japanese characters (\emph{kinsoku}).
1086 \item[FROM\_JFM (4)] Glues/kerns from JFM.
1087 \item[LINE\_END (5)] Kerns for ...
1088 \item[KANJI\_SKIP (6)] Glues for \textsf{kanjiskip}.
1089 \item[XKANJI\_SKIP (7)] Glues for \textsf{xkanjiskip}.
1090 \item[PROCESSED (8)] Nodes which is already processed by ...
1091 \item[IC\_PROCESSED (9)] Glues from an itaric correction, but also already processed.
1092 \item[BOXBDD (15)] Glues/kerns that inserted just the beginning or the ending of an hbox or a paragraph.
1093 \end{description}
1094 \attr{ltj@kcat$i$} Where $i$~is a natural number which is less than~7.
1095 These 7~attributes store bit~vectors indicating which character block is regarded as a block of \textbf{JAchar}s.
1096 \end{list}
1097
1098 \subsection{Stack System of \LuaTeX-ja}
1099 \paragraph{Background}
1100 \LuaTeX-ja has its own stack system, and most parameters of \LuaTeX-ja
1101 are stored in it.  To clarify the reason, imagine the parameter
1102 \textsf{kanjiskip} is stored by a skip, and consider the following
1103 source:
1104 \begin{LTXexample}
1105 \ltjsetparameter{kanjiskip=0pt}ふがふが.%
1106 \setbox0=\hbox{\ltjsetparameter{kanjiskip=5pt}ほげほげ}
1107 \box0.ぴよぴよ\par
1108 \end{LTXexample}
1109
1110 As described in Part~\ref{part-ref}, the only effective value of
1111 \textsf{kanjiskip} in an hbox is the latest value, so the value of
1112 \textsf{kanjiskip} which applied in the entire hbox should be 5\,pt.
1113 However, by the implementation method of \LuaTeX, this `5\,pt' cannot be
1114 known from any callbacks.  In the \texttt{tex/packaging.w} (which is a
1115 file in the source of \LuaTeX), there are the following codes:
1116 \begin{lstlisting}
1117 void package(int c)
1118 {
1119     scaled h;                   /* height of box */
1120     halfword p;                 /* first node in a box */
1121     scaled d;                   /* max depth */
1122     int grp;
1123     grp = cur_group;
1124     d = box_max_depth;
1125     unsave();
1126     save_ptr -= 4;
1127     if (cur_list.mode_field == -hmode) {
1128         cur_box = filtered_hpack(cur_list.head_field,
1129                                  cur_list.tail_field, saved_value(1),
1130                                  saved_level(1), grp, saved_level(2));
1131         subtype(cur_box) = HLIST_SUBTYPE_HBOX;
1132 \end{lstlisting}
1133 Notice that \verb+unsave+ is executed \emph{before}
1134 \verb+filtered_hpack+ (this is where \verb+hpack_filter+ callback is
1135 executed): so `5\,pt' in the above source is orphaned at
1136 \texttt+unsave+, and hence it can't be accessed from \verb+hpack_filter+
1137 callback.
1138
1139 \paragraph{The method}
1140 The code of stack system is based on that in a post of Dev-luatex mailing list\footnote{%
1141 \texttt{[Dev-luatex] tex.currentgrouplevel}, a post at 2008/8/19 by Jonathan Sauer.}.
1142
1143 These are two \TeX\ count registers for maintaining informations:
1144 \verb+\ltj@@stack+ for the stack level, and \verb+\ltj@@group@level+ for
1145 the \TeX's group level when the last assignment was done.  Parameters
1146 are stored in one big table named \texttt{charprop\_stack\_table}, where
1147 \texttt{charprop\_stack\_table[$i$]} stores data of stack level~$i$. If
1148 a new stack level is created by \verb+\ltjsetparameter+, all data of the
1149 previous level is copied.
1150
1151 To resolve the problem mentioned in `Background' above, \LuaTeX-ja uses
1152 another thing: When a new stack level is about to be created, a whatsit
1153 node whose type, subtype and value are 44~(\textit{user\_defined}),
1154 30112, and current group level respectively is appended to the current
1155 list (we refer this node by \textit{stack\_flag}). This enables us to
1156 know whether assignment is done just inside a hbox. Suppose that the
1157 stack level is~$s$ and the \TeX's group level is~$t$ just after the hbox
1158 group, then:
1159 \begin{itemize}
1160 \item If there is no \textit{stack\_flag} node in the list of hbox, then
1161       no assignment was occurred inside the hbox. Hence values of
1162       parameters at the end of the hbox are stored in the stack
1163       level~$s$.
1164 \item If there is a \textit{stack\_flag} node whose value is~$t+1$, then
1165       an assignment was occurred just inside the hbox group. Hence
1166       values of parameters at the end of the hbox are stored in the
1167       stack level~$s+1$.
1168 \item If there are \textit{stack\_flag} nodes but all of their values
1169       are more than~$t+1$, then an assignment was occurred in the box,
1170       but it is done is `more internal' group. Hence values of
1171       parameters at the end of the hbox are stored in the stack
1172       level~$s$.
1173 \end{itemize}
1174
1175 Note that to work this trick correctly, assignments to
1176 \verb+\ltj@@stack+ and \verb+\ltj@@group@level+ have to be local always, 
1177 regardless the value of \verb+\globaldefs+.
1178 This problem is resolved by using
1179 \hbox{\verb+\directlua{tex.globaldefs=0}+} (this assignment is local).
1180
1181
1182 \section{Linebreak after Japanese Character}\label{sec-lbreak}
1183 \subsection{Reference: Behavior in \pTeX}
1184 (NOT COMPLETED)
1185
1186 In~\pTeX, a linebreak after a Japanese character doesn't emit a space,
1187 since words are not separated by spaces in Japanese writings. However,
1188 this feature isn't fully implemented in \LuaTeX-ja due to the
1189 specification of callbacks in~\LuaTeX. To clarify the difference between
1190 \pTeX~and~\LuaTeX, We briefly describe the handling of a linebreak in~\pTeX, in
1191 this subsection. 
1192
1193 \pTeX's input processor can be described in terms of a finite state
1194 automaton, as that of~\TeX\ in~Section~2.5 of~\cite{texbytopic}. The
1195 internal states are as follows:
1196 \begin{itemize}
1197 \item State~$N$: new line
1198 \item State~$S$: skipping spaces
1199 \item State~$M$: middle of line
1200 \item State~$K$: after a Japanese character
1201 \end{itemize}
1202 The first three states---$N$, $S$~and~$M$---are as same as \TeX's input
1203 processor.  State~$K$ is similar to state~$M$, and is entered after
1204 Japanese characters.  The diagram of state transitions are indicated in
1205 Figure~\ref{fig-ptexipro}.  Note that \pTeX\ doesn't leave state~$K$
1206 after `beginning/ending of a group' characters.
1207 \begin{figure}[tb]
1208 \label{fig-ptexipro}
1209 \begin{gather*}
1210  \def\sp{\text{\tt\char32}}
1211  \xymatrix{&&
1212    {\text{scan a cs}}\ar@(r,ul)[dr]&\\
1213 \ar[r]&
1214    *++[o][F-]{N}\ar[ur]^0\ar[dd]_{d,\ g}\ar[u]^{5\ (\text{\tt\char92par})}
1215      \ar@{->}@(d,l)[ddrr]_(0.45){j}&&
1216    *++[o][F-]{S}\ar@(l,dr)[ul]^0\ar@(l,ur)[ddll]_{d,\ g}\ar[u]_{5}
1217      \ar@{->}@(r,r)[dd]^{j}\\&\\&
1218    *++[o][F-]{M}\ar[uuur]^0\ar@(r,dl)[uurr]_(0.55){10\ (\sp)}
1219      \ar[d]_{5\ ({\sp})}\ar@{->}@(dr,dl)[rr]_{j}&&
1220    *++[o][F-]{K}\ar@{->}@(ul,d)[uuul]^0\ar@{->}[ll]^{d}
1221      \ar@{->}@(ur,dr)[uu]^{10\ (\sp)}\ar@{->}[d]_5\\
1222    &&&
1223  }\\
1224  d:=\{3,4,6,7,8,11,12,13\},\quad g:=\{1,2\},\quad j:=(\text{Japanese characters})
1225 \end{gather*}
1226 \begin{itemize}
1227 \item Numbers represent category codes.
1228 \item Category codes 9~(ignored), 14~(comment)~and~15~(invalid) are omitted in above diagram.
1229 \end{itemize}
1230 \caption{State transitions of \pTeX's input processor.}
1231 \end{figure}
1232
1233
1234 \subsection{Behavior in \LuaTeX-ja}
1235 States in the input processoe of \LuaTeX\ is the same as that of \TeX,
1236 and they can't be customized by any callbacks. Hence, we can only use
1237 \verb+process_input_buffer+ and \verb+token_filter+ callbacks for to
1238 suppress a space by a linebreak which is after Japanese characters.
1239
1240 However, \verb+token_filter+ callback cannot be used either, since a
1241 character in category code 5~(end-of-line) is converted into an space
1242 token \emph{in the input processor}.  So we can use only the
1243 \verb+process_input_buffer+ callback.  This means that suppressing a
1244 space must be done \emph{just before} an input line is read.
1245
1246 Considering these situations, handling of a end-of-line in \LuaTeX-ja are as follows:
1247 \begin{quote}
1248 A character U+FFFFF (its category code is set to 14~(comment) by
1249 \LuaTeX-ja) is appended to an input line, before \LuaTeX\ actually
1250 process it, if and only if the following two conditions are satisfied:
1251 \begin{enumerate}
1252 \item The category code of the character $\langle${return}$\rangle$
1253       (whose character code is 13) is 5~(end-of-line).
1254 \item The input line matches the following `regular expression':
1255 \[
1256   (\text{any char})^*(\textbf{JAchar})
1257   \bigl(\{\text{catcode}=1\}\cup\{\text{catcode}=2\}\bigr)^*
1258 \]
1259 \end{enumerate}
1260
1261 \end{quote}
1262
1263 \section{Insertion of JFM glues, \textsf{kanjiskip} and \textsf{xkanjiskip}}
1264 This is the longest section of the document.
1265
1266 jfmglue.tex の内容をここに入れる
1267 \end{document}