OSDN Git Service

c5f0c38e44466843ec8f02e77e9a8e992ee49e58
[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={}
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 A character in Unicode is treated as \textbf{JAchar} if and only
265       if its code-point has more than or equal to U+0100.
266 \item The amount of glue that are inserted between a \textbf{JAchar} and
267       an \textbf{ALchar} (the parameter \textsf{xkanjiskip}) is set to
268 \[
269  0.25\,\hbox{\verb+\zw+}^{+1\,\text{pt}}_{-1\,\text{pt}} = \frac{27}{32}\,\mathrm{mm}^{+1\,\text{pt}}_{-1\,\text{pt}}.
270 \]
271 Here \verb+\zw+ is the counterpart of \texttt{em} for Japanese fonts, that is, the length of `full-width' in current Japanese font.
272 \end{itemize}
273
274 \subsection{Using in \LaTeX}\label{ssec-ltx}
275 \paragraph{\LaTeXe}
276 Using in \LaTeXe\ is basically same. To set up the minimal environment
277 for Japanese, you only have to load {\tt luatexja.sty}:
278 \begin{verbatim}
279 \usepackage{luatexja}
280 \end{verbatim}
281 It also does minimal settings (counterparts in \pLaTeX\ are {\tt
282 plfonts.dtx} and {\tt pldefs.ltx}):
283
284 \begin{itemize}
285 \item {\tt JY3} is the font encoding for Japanese fonts (in horizontal direction).\\
286 When vertical typesetting is supported by \LuaTeX-ja in the future, {\tt JT3} will be used for vertical fonts.
287 \item Two font families {\tt mc} and {\tt gt} are defined: 
288 \begin{center}
289 \begin{tabular}{ccccc}
290 \toprule
291 \textbf{classification}&\textbf{family}&\verb+\mdseries+&\verb+\bfseries+&\textbf{scale}\\\midrule
292 \emph{mincho}&\tt mc&Ryumin-Light    &GothicBBB-Medium&0.960444\\
293 \emph{gothic}&\tt gt&GothicBBB-Medium&GothicBBB-Medium&0.960444\\
294 \bottomrule
295 \end{tabular}
296 \end{center}
297 \textbf{Note on fonts in bold series}
298
299 \item Japanese characters in math mode are typeset by the font family {\tt mc}.
300 \end{itemize}
301
302 However, above settings are not sufficient for Japanese-based
303 documents. To typeset Japanese-based documents, You are better to use
304 class files other than {\tt article.cls}, {\tt book.cls}, \ldots.  At the
305 present, BXjscls (\texttt{bxjsarticle.cls} and \texttt{bxjsbook.cls}, by
306 Takayuki Yato) are better alternative. It is not determined whether
307 \LuaTeX-ja will develop and contain counterparts of major classes used
308 in \pTeX\ (including jsclasses by Haruhiko Okumura).
309
310 \subsection{Changing Fonts}
311 \paragraph{Remark: Japanese Characters in Math Mode}
312 Since \pTeX\ supports Japanese characters in math mode, there are
313 sources like the following:
314
315 \begin{LTXexample}
316 $f_{高温}$~($f_{\text{high temperature}}$).
317 \[ y=(x-1)^2+2\quad{}よって\quad y>0 \]
318 $5\in{}素:=\{\,p\in\mathbb N:\text{$p$ is a prime}\,\}$.
319 \end{LTXexample}
320
321 We (the project members of \LuaTeX-ja) think that using
322 Japanese characters in math mode are allowed if and only if these are used as identifiers.
323 In this point of view, 
324 \begin{itemize}
325 \item The lines 1~and~2 above are not correct, since `高温' in above is used as a textual label, and
326 `よって' is used as a conjunction. 
327 \item However, the line~3 is correct, since `素' is used as an identifier.
328 \end{itemize}
329 Hence, in our opinion, the above input should be corrected as:
330 \begin{LTXexample}
331 $f_{\text{高温}}$~%
332 ($f_{\text{high temperature}}$).
333 \[ y=(x-1)^2+2\quad 
334   \mathrel{\text{よって}}\quad y>0 \]
335 $5\in{}素:=\{\,p\in\mathbb N:\text{$p$ is a prime}\,\}$.
336 \end{LTXexample}
337 %BUG?: \{\}がなければ「素」がでない.上の段落の「よって」もでてない.
338 We also believe that using Japanese characters as identifiers is rare,
339 hence we don't describe how to change Japanese fonts in math mode in
340 this chapter. For the method, please see Part~\ref{part-ref}.
341
342
343 \paragraph{plain \TeX}
344 To change Japanese fonts in plain \TeX, you must use the primitive
345 \verb+\jfont+. So please see Part~\ref{part-ref}.
346
347
348 \paragraph{NFSS2}
349 For \LaTeXe, \LuaTeX-ja simply adopted the font selection system from that
350 of \pLaTeXe\ (in {\tt plfonts.dtx}).
351 \begin{itemize}
352 \item Two control sequences \verb+\mcdefault+ and \verb+\gtdefault+ are
353       used to specify the default font families for \emph{mincho} and
354       \emph{gothic}, respectively. Default values: \texttt{mc} for
355       \verb+\mcdefault+ and \texttt{gt} for \verb+\gtdefault+.
356 \item Commands \verb+\fontfamily+, \verb+\fontseries+,
357       \verb+\fontshape+ and \verb+\selectfont+ can be used to change
358       attributes of Japanese fonts. 
359 \begin{center}
360 \begin{tabular}{ccccc}
361 \toprule
362 &\textbf{encoding}&\textbf{family}&\textbf{series}&\textbf{shape}\\\midrule
363 alphabetic fonts
364 &\verb+\romanencoding+&\verb+\romanfamily+&\verb+\romanseries+&\verb+\romanshape+\\
365 Japanese fonts
366 &\verb+\kanjiencoding+&\verb+\kanjifamily+&\verb+\kanjiseries+&\verb+\kanjishape+\\
367 both&---&--&\verb+\fontseries+&\verb+\fontshape+\\
368 auto select&\verb+\fontencoding+&\verb+\fontfamily+&---&---\\
369 \bottomrule
370 \end{tabular}
371 \end{center}
372 \item For defining a Japanese font family, use \verb+\DeclareKanjiFamily+
373       instead of \verb+\DeclareFontFamily+.
374 \end{itemize}
375
376 \paragraph{fontspec}
377 To coexist with \texttt{fontspec} package, it is needed to load
378 \texttt{luatexja-fontspec} package in the preamble. This additional
379 package automatically loads \texttt{luatexja} and \texttt{fontspec}
380 package, if needed.
381
382 In \texttt{luatexja-fontspec} package, the following 7~commands are defined as
383 counterparts of original commands in \texttt{fontspec}:
384 \begin{center}
385 \begin{tabular}{ccccc}
386 \toprule
387 Japanese fonts
388 &\verb+\jfontspec+&\verb+\setmainjfont+&\verb+\setsansjfont+&\verb+\newjfontfamily+\\
389 alphabetic fonts
390 &\verb+\fontspec+&\verb+\setmainfont+&\verb+\setsansfont+&\verb+\newfontfamily+\\
391 \midrule
392 Japanese fonts
393 &\verb+\newjfontface+&\verb+\defaultjfontfeatures+&\verb+\addjfontfeatures+\\
394 alphabetic fonts
395 &\verb+\newfontface+&\verb+\defaultfontfeatures+&\verb+\addfontfeatures+\\
396 \bottomrule
397 \end{tabular}
398 \end{center}
399 使用例
400
401
402 Note that there is no command named \verb+\setmonojfont+, since it is
403 popular for Japanese fonts that nearly all Japanese glyphs have same widths.
404
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 As noted before, the default setting is:
415 \begin{center}
416 A character in Unicode is treated as \textbf{JAchar},\\
417  if and only if its
418  code-point has more than or equal to U+0100.
419 \end{center}
420 $\uparrow$ TODO: CHANGE THIS!
421
422
423 To edit the range of \textbf{JAchar}s, You have to assign a non-zero
424 natural number which is less than 217 to the character range first. This
425 can be done by using \verb+\ltjdefcharrange+ primitive. For example, the
426 next line assigns whole characters in Supplementary Multilingual Plane
427 and the character `漢' to the range number~4.
428 \begin{lstlisting}
429 \ltjdefcharrange{4}{"10000-"1FFFF,`漢}
430 \end{lstlisting}
431 This assignment of numbers to ranges are always global, so you should
432 not do this in the middle of a document. 上書き
433
434 After assigning numbers to ranges, ...
435
436 \subsection{\textsf{kanjiskip} and \textsf{xkanjiskip}}\label{subs-kskip}
437 \textbf{JAglue} is divided into the following three categories:
438 \begin{itemize}
439 \item Glues/kerns specified in JFM. If \verb+\inhibitglue+ is issued around a Japanese character,
440       this glue will be not inserted at the place.
441 \item The default glue which inserted between two \textbf{JAchar}s ({\sf
442       kanjiskip}).
443 \item The default glue which inserted between a \textbf{JAchar} and an
444       \textbf{ALchar} (\textsf{xkanjiskip}).
445 \end{itemize}
446 The value (a skip) of \textsf{kanjiskip} or \textsf{xkanjiskip} can be
447 changed as the following.
448 \begin{verbatim}
449 \ltjsetparameter{kanjiskip={0pt plus 0.4pt minus 0.4pt}, 
450                  xkanjiskip={0.25\zw plus 1pt minus 1pt}}
451 \end{verbatim}
452
453
454 It may occur that JFM contains the data of `ideal width of {\sf
455 kanjiskip}' and/or `ideal width of \textsf{xkanjiskip}'.
456 To use these data from JFM, set the value of \textsf{kanjiskip} or 
457 \textsf{xkanjiskip} to \verb+\maxdimen+.
458
459 \subsection{Insertion Setting of \textsf{xkanjiskip}}
460 It is not desirable that \textsf{xkanjiskip} is inserted between every
461 boundary between \textbf{JAchar}s and \textbf{ALchar}s. For example,
462 \textsf{xkanjiskip} should not be inserted after opening parenthesis
463 (\textit{e.g.}, compare `(あ' and `(\hskip\ltjgetparameter{xkanjiskip}あ').
464
465 \LuaTeX-ja can control whether \textsf{xkanjiskip} can be inserted
466 before/after a character, by changing \textsf{jaxspmode} for \textbf{JAchar}s and
467 \textsf{alxspmode} parameters \textbf{ALchar}s respectively. 
468 \begin{LTXexample}
469 \ltjsetparameter{jaxspmode={`あ,preonly}, alxspmode={`\!,postonly}} 
470 pあq い!う
471 \end{LTXexample}
472
473 The second argument {\tt preonly} means `the insertion of
474 \textsf{xkanjiskip} is allowed before this character, but not after'.
475 the other possible values are {\tt postonly}, {\tt allow} and {\tt
476 inhibit}. For the compatibility with \pTeX, natural numbers between
477 0~and~3 are also allowed as the second argument\footnote{But we don't
478 recommend this: since numbers 1~and~2 have opposite meanings in
479 \textsf{jaxspmode} and \textsf{alxspmode}.}.
480
481 If you want to enable/disable all insertions of \textsf{kanjiskip} and
482 \textsf{xkanjiskip}, set \textsf{autospacing} and \textsf{autoxspacing}
483 parameters to {\tt false}, respectively.
484
485
486 \subsection{Shifting Baseline}
487 To make a match between a Japanese font and an alphabetic font, sometimes
488 shifting of the baseline of one of the pair is needed. In \pTeX, this is achieved
489 by setting \verb+\ybaselineshift+ to a non-zero length (the
490 baseline of alphabetic fonts is shifted below). However, for documents
491 whose main language is not Japanese, it is good to shift the baseline of
492 Japanese fonts, but not that of alphabetic fonts.
493 Because of this, \LuaTeX-ja can independently set the shifting amount
494 of the baseline of alphabetic fonts (\textsf{yalbaselineshift}
495 parameter) and that of Japanese fonts (\textsf{yjabaselineshift}
496 parameter). 
497
498 \begin{LTXexample}
499 \vrule width 150pt height 0.4pt depth 0pt\hskip-120pt
500 \ltjsetparameter{yjabaselineshift=0pt, yalbaselineshift=0pt}abcあいう
501 \ltjsetparameter{yjabaselineshift=5pt, yalbaselineshift=2pt}abcあいう
502 \end{LTXexample}
503 Here the horizontal line in above is the baseline of a line.
504
505 There is an interesting side-effect: characters in different size can be
506 vertically aligned center in a line, by setting two parameters appropriately.
507 The following is an example (beware the value is not well tuned):
508 \begin{LTXexample}
509 xyz漢字 
510 {\scriptsize
511   \ltjsetparameter{yjabaselineshift=-1pt, 
512     yalbaselineshift=-1pt}
513   XYZひらがな
514 }abcかな
515 \end{LTXexample}
516
517
518 \subsection{Cropmark}
519 Cropmark is a mark for indicating 4~corners and horizontal/vertical
520 center of the paper. In Japanese, we call cropmark as tombo(w).
521 \pLaTeX\ and this \LuaTeX-ja support `tombow' by their kernel.
522 The following steps are needed to typeset cropmark:
523
524 \begin{enumerate}
525 \item First, define the banner which will be printed at the upper left
526       of the paper. This is done by assigning a token list to
527       \verb+\@bannertoken+.
528
529 For example, the following sets banner as `{\tt filename (2012-01-01 17:01)}':
530 \begin{verbatim}
531 \makeatletter
532
533 \hour\time \divide\hour by 60 \@tempcnta\hour \multiply\@tempcnta 60\relax
534 \minute\time \advance\minute-\@tempcnta
535 \@bannertoken{%
536    \jobname\space(\number\year-\two@digits\month-\two@digits\day
537    \space\two@digits\hour:\two@digits\minute)}%
538 \end{verbatim}
539
540 \item ...
541 \end{enumerate}
542
543
544 \part{Reference}\label{part-ref}
545 \section{Font Metric and Japanese Font}
546 \subsection{\texttt{\char92jfont} primitive}
547 To load a font as a Japanese font, you must use the
548 \verb+\jfont+ primitive instead of~\verb+\font+, while
549 \verb+\jfont+ admits the same syntax used in~\verb+\font+. 
550 \LuaTeX-ja automatically loads \texttt{luaotfload} package,
551 so TrueType/OpenType fonts with features can be used for Japanese fonts:
552 \begin{LTXexample}
553 \jfont\tradgt={file:ipaexg.ttf:script=latn;%
554   +trad;jfm=ujis} at 14pt
555 \tradgt{}当/体/医/区
556 \end{LTXexample}
557
558 Note that the defined control sequence
559 (\verb+\tradgt+ in the example above) using \verb+\jfont+ is not a
560 \textit{font\_def} token, hence the input like
561 \verb+\fontname\tradgt+ causes a error. We denote control sequences which are defined in \verb+\jfont+
562 by <jfont\_cs>.
563
564 \paragraph{Prefix}
565 Besides \texttt{file:}\ and \texttt{name:}\ prefixes, \texttt{psft:}\ can
566 be used a prefix in \verb+\jfont+ (and~\verb+\font+) primitive.  Using
567 this prefix, you can specify a font that has its name only and is not
568 related to any real font.
569
570 Mainly, use of this \texttt{psft:}\ prefix is for using non-embedding `standard' Japanese fonts (Ryumin-Light and GothicBBB-Medium).
571 歴史
572
573 \paragraph{Features}
574 jfm, jfmvar
575
576
577
578 \subsection{Structure of JFM file}
579 A JFM file is a Lua script which has only one function call:
580 \begin{verbatim}
581 luatexja.jfont.define_jfm { ... }
582 \end{verbatim}
583 Real data are stored in the table which indicated above by
584 \verb+{ ... }+.  So, the rest of this subsection are devoted to describe the
585 structure of this table.  Note that all lengths in a JFM file are
586 floating-point numbers in design-size unit.
587
588 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
589 \item[dir=<direction>] (required)
590
591 The direction of JFM. At the present, only \texttt{'yoko'} is supported.
592
593 \item[zw=<length>] (required)
594
595 The amount of the length of the `full-width'.
596
597 \item[zh=<length>] (required)
598
599 \item[kanjiskip=\{<natural>, <stretch>, <shrink>\}] (optional)
600
601 This field specifies the `ideal' amount of \textsf{kanjiskip}. As noted
602              in Subsection~\ref{subs-kskip}, if the parameter
603              \textsf{kanjiskip} is \verb+\maxdimen+, the value specified
604              in this field is actually used (if this field is not specified in
605              JFM, it is regarded as 0\,pt). Note that <stretch> and <shrink>
606              fields are in design-size unit too.
607
608
609 \item[xkanjiskip=\{<natural>, <stretch>, <shrink>\}] (optional)
610
611 Like the \texttt{kanjiskip} field, this field specifies the `ideal'
612              amount of \textsf{xkanjiskip}.
613
614 \end{list}
615
616 Besides from above fields, a JFM file have several sub-tables those
617 indices are natural numbers.  The table indexed by~$i\in\omega$ stores
618 informations of `character class'~$i$. At least, the character class~0 is
619 always present, so each JFM file must have a sub-table whose index is
620 \texttt{[0]}.  Each sub-table (its numerical index is denoted by $i$) has
621 the following fields:
622
623 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
624 \item[chars=\{<character>, ...\}] (required except character class~0)
625
626 This field is a list of characters which are in this character
627              type~$i$. This field is not required if $i=0$, since all
628              \textbf{JAchar} which are not in any character class other
629              than 0 (hence, the character class~0 contains most of
630              \textbf{JAchar}s). In the list, a character can be
631              specified by its code number, or by the character itself
632              (as a string of length~1). 
633
634 In addition to those `real' characters, the following `imaginary
635              characters' can be specified in the list:
636
637 \item[width=<length>, height=<length>, depth=<length>, italic=<length>]\ (required)
638
639 Specify width of characters in character class~$i$, height, depth and
640 the amount of italic correction. All characters in character class~$i$ are regarded that its width, height and depth are
641 as values of these fields. 
642 But there is one exception: if \texttt{'prop'} is specified in \texttt{width} field, width of a character becomes that of its `real' glyph 
643
644 \item[left=<length>, down=<length>, align=<align>]\ 
645
646 These fields are for adjusting the position of the `real' glyph. Legal
647              values of \texttt{align} field are \texttt{'left'},
648              \texttt{'middle'} and \texttt{'right'}. If one of these
649              3~fields are omitted, \texttt{left} and \texttt{down} are
650              treated as~0, and \texttt{align} field is treated as
651              \texttt{'left'}.
652 The effects of these 3~fields are indicated in Figure~\ref{fig-pos}.
653
654 In most cases, \texttt{left} and \texttt{down} fields are~0, while
655 it is not uncommon that the \texttt{align} field is \texttt{'middle'} or \texttt{'right'}.
656 For example, setting the \texttt{align} field to \texttt{'right'} is practically needed 
657 when the current character class is the class for opening delimiters'. 
658 \begin{figure}[tb]
659 \begin{minipage}{0.4\textwidth}%
660 \begin{center}\unitlength=10pt\small
661 \begin{picture}(15,12)(-1,-4)
662 \color{black!10!white}% real glyph :step1
663 \put(0,0){\vrule width 12\unitlength height 8\unitlength depth 3\unitlength}
664
665 \color{red!20!white}% real glyph :step1
666 \put(-1,-1.5){\vrule width 6\unitlength height 7\unitlength depth 2.5\unitlength}
667
668 \color{red}% real glyph
669 \thicklines
670 \put(-1,-1.5){\vector(0,1){7}\vector(0,-1){2.5}\vector(1,0){6}}
671 \put(5,-1.5){\line(0,1){7}\line(0,-1){2.5}}
672 \put(-1,5.5){\line(1,0){6}}
673 \put(-1,-4){\line(1,0){6}}
674
675 \color{green!20!white}% real glyph :step1
676 \put(3,0){\vrule width 6\unitlength height 7\unitlength depth 2.5\unitlength}
677
678 \color{black}% real glyph :step1
679 \thicklines
680 \put(0,0){\vector(0,1){8}\line(0,-1){3}\vector(1,0){12}}
681 \put(12,0){\line(0,1){8}\vector(0,-1){3}}
682 \put(0,8){\line(1,0){12}}
683 \put(0,-3){\line(1,0){12}}
684 \put(0.2,4){\makebox(0,0)[l]{\texttt{height}}}
685 \put(12.2,-1.5){\makebox(0,0)[l]{\texttt{depth}}}
686 \put(6,0.2){\makebox(0,0)[b]{\texttt{width}}}
687
688 \color{green!50!black}% real glyph :step1
689 \thicklines
690 \put(3,0){\vector(0,1){7}\vector(0,-1){2.5}\vector(1,0){6}}
691 \put(9,0){\line(0,1){7}\line(0,-1){2.5}}
692 \put(3,7){\line(1,0){6}}
693 \put(3,-2.5){\line(1,0){6}}
694 \newsavebox{\eqdist}
695 \savebox{\eqdist}(0,0)[b]{%
696   \thinlines
697   \put(-0.08,0.2){\line(0,-1){0.4}}%
698   \put(0.08,0.2){\line(0,-1){0.4}}}
699 \put(1.5,0){\usebox{\eqdist}}
700 \put(10.5,0){\usebox{\eqdist}}
701
702 \color{blue}% shifted
703 \thicklines
704 \put(3,-1.5){\vector(-1,0){4}}
705 \put(1,-1.7){\makebox(0,0)[t]{\texttt{left}}}
706 \put(3,0){\vector(0,-1){1.5}}
707 \put(3.2,-0.75){\makebox(0,0)[l]{\texttt{down}}}
708 \end{picture} 
709 \end{center}
710 \end{minipage}%
711 \begin{minipage}{0.6\textwidth}%
712 Consider a node containing Japanese character whose value of the \texttt{align} 
713 field is \texttt{'middle'}.
714 \begin{itemize}
715 \item The black rectangle is a frame of the node.
716 Its width, height and depth are specified by JFM.
717 \item Since the \texttt{align} field is \texttt{'middle'}, 
718 the `real' glyph is centered horizontally (the green rectangle).
719 \item Furthermore, the glyph is shifted according to values of fields
720       \texttt{left} and \texttt{down}. The ultimate position of the real
721       glyph is indicated by the red rectangle.
722 \end{itemize}
723 \end{minipage}
724 \caption{The position of the `real' glyph.}
725 \label{fig-pos}
726 \end{figure}
727
728
729 \item[kern={\{[$j$]=<kern>, ...\}}]
730
731 \item[glue={\{[$j$]=\{<width>, <stretch>, <shrink>\}, ...\}}]
732 \end{list}
733
734 \subsection{Math Font Family}
735 \TeX\ handles fonts in math formulas by 16~font families\footnote{Omega,
736 Aleph, \LuaTeX~and $\varepsilon$-\kern-.125em(u)\pTeX can handles 256~families, but
737 an external package is needed to support this in plain \TeX\ and
738 \LaTeX.}, and each family has three fonts:
739 \verb+\textfont+, \verb+\scriptfont+ and \verb+\scriptscriptfont+.
740
741 \LuaTeX-ja's handling of Japanese fonts in math formulas is similar;
742 Table~\ref{tab-math} shows counterparts to \TeX's primitives for math
743 font families.
744
745 \begin{table}[tb]
746 \label{tab-math}
747 \caption{Primitives for Japanese math fonts.}
748 \begin{center}\def\{{\char`\{}\def\}{\char`\}}
749 \begin{tabular}{lll}
750 \toprule
751 &Japanese fonts&alphabetic fonts\\
752 \midrule
753 font family&\verb+\jfam+${}\in [0,256)$&\verb+\fam+\\
754 text size&\tt\textsf{jatextfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\verb+\textfont+<fam>=<font\_cs>\\
755 script size&\tt\textsf{jascriptfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\verb+\scriptfont+<fam>=<font\_cs>\\
756 scriptscript size&\tt\textsf{jascriptscriptfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\verb+\scriptscriptfont+<fam>=<font\_cs>\\
757 \bottomrule
758 \end{tabular}
759 \end{center}
760 \end{table}
761
762
763 \section{Parameters}
764 \subsection{{\tt\char92 ltjsetparameter} primitive}
765 As noted before, \verb+\ltjsetparameter+ and \verb+\ltjgetparameter+ are
766 primitives for accessing most parameters of \LuaTeX-ja. One of the main
767 reason that \LuaTeX-ja didn't adopted the syntax similar to that of \pTeX\ 
768 (\textit{e.g.},~\verb+\prebreakpenalty`)=10000+) 
769 is the position of \verb+hpack_filter+ callback in the source
770 of \LuaTeX, see Section~\ref{sec-para}.
771
772 \verb+\ltjsetparameter+ and \verb+\ltjglobalsetparameter+ are primitives
773 for assigning parameters. These take one argument which is a
774 \texttt{<key>=<value>} list. Allowed keys are described in the next
775 subsection.  
776 The difference between
777 \verb+\ltjsetparameter+ and \verb+\ltjglobalsetparameter+ is only the
778 scope of assignment;
779 \verb+\ltjsetparameter+ does a local assignment and 
780 \verb+\ltjglobalsetparameter+ does a global one. 
781 They also obey the value of \verb+\globaldefs+,
782 like other assignment.
783
784 \verb+\ltjgetparameter+ is the primitive for acquiring parameters. It
785 always takes a parameter name as first argument, and also takes the
786 additional argument---a character code, for example---in some cases.
787 \begin{LTXexample}
788 \ltjgetparameter{differentjfm}, 
789 \ltjgetparameter{autospacing},
790 \ltjgetparameter{prebreakpenalty}{`)}.
791 \end{LTXexample}
792 \emph{The return value of\/ {\normalfont\tt\char92ltjgetparameter} is
793 always a string}. This is outputted by \texttt{tex.write()}, so any
794 character other than space~`{\tt\char32}'~(U+0020) has the category code
795 12~(other), while the space has 10~(space).
796
797 \subsection{List of Parameters}
798 In the following list of parameters, [\verb+\cs+] indicates the counterpart in \pTeX, and each symbol has the following meaning:
799 \begin{itemize}
800 \item No mark: values at the end of the paragraph or the hbox are
801       adopted in the whole paragraph/hbox.
802 \item `\ast' : local parameters, which can change everywhere inside a paragraph/hbox.
803 \item `\dagger': assignments are always global.
804 \end{itemize}
805
806 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
807 \item[\textsf{jcharwidowpenalty}\,=<penalty>] [\verb+\jcharwidowpenalty+]
808
809 Penalty value for supressing orphans. This penalty is inserted just
810              after the last \textbf{JAchar} which is not regarded as a
811              (Japanese) punctuation mark.
812
813 \item[\textsf{kcatcode}\,=\{<chr\_code>,<natural number>\}]\
814
815 An additional attributes having each character whose character code is <chr\_code>.  
816 At the present version, the lowermost bit of <natural number> indicates
817              whether the character is considered as a punctuation mark
818              (see the description of \textsf{jcharwidowpenalty} above).
819
820
821 \item[\textsf{prebreakpenalty}\,=\{<chr\_code>,<penalty>\}] [\verb+\prebreakpenalty+]
822 \item[\textsf{postbreakpenalty}\,=\{<chr\_code>,<penalty>\}] [\verb+\postbreakpenalty+]
823 \item[\textsf{jatextfont}\,=\{<jfam>,<jfont\_cs>\}] [\verb+\textfont+ in \TeX]
824 \item[\textsf{jascriptfont}\,=\{<jfam>,<jfont\_cs>\}] [\verb+\scriptfont+ in \TeX]
825 \item[\textsf{jascriptscriptfont}\,=\{<jfam>,<jfont\_cs>\}] [\verb+\scriptscriptfont+ in \TeX]
826 \item[\textsf{yjabaselineshift}\,=<dimen>$^\ast$]\ 
827 \item[\textsf{yalbaselineshift}\,=<dimen>$^\ast$] [\verb+\ybaselineshift+]
828
829 \item[\textsf{jaxspmode}\,=\{<chr\_code>,<mode>\}] [\verb+\inhibitxspcode+]
830
831 Setting whether inserting  \textsf{xkanjiskip} is allowed before/after a \textbf{JAchar} whose character code is <chr\_code>.
832 The followings are allowed for <mode>:
833 \begin{description}
834 \item[0, \texttt{inhibit}] Insertion of \textsf{xkanjiskip} is inhibited before the charater, nor after the charater.
835 \item[2, \texttt{preonly}] Insertion of \textsf{xkanjiskip} is allowed before the charater, but not after.
836 \item[1, \texttt{postonly}] Insertion of \textsf{xkanjiskip} is allowed after the charater, but not before.
837 \item[3, \texttt{allow}] Insertion of \textsf{xkanjiskip} is allowed before the charater and after the charater.
838 This is the default value.
839 \end{description}
840
841 \item[\textsf{alxspmode}\,=\{<chr\_code>,<mode>\}] [\verb+\xspcode+]
842
843 Setting whether inserting  \textsf{xkanjiskip} is allowed before/after a \textbf{ALchar} whose character code is <chr\_code>.
844 The followings are allowed for <mode>:
845 \begin{description}
846 \item[0, \texttt{inhibit}] Insertion of \textsf{xkanjiskip} is inhibited before the charater, nor after the charater.
847 \item[1 \texttt{preonly}] Insertion of \textsf{xkanjiskip} is allowed before the charater, but not after.
848 \item[2 \texttt{postonly}] Insertion of \textsf{xkanjiskip} is allowed after the charater, but not before.
849 \item[3, \texttt{allow}] Insertion of \textsf{xkanjiskip} is allowed before the charater and after the charater.
850 This is the default value.
851 \end{description}
852 Note that parameters \textsf{jaxspmode} and \textsf{alxspmode} use a common table.
853
854 \item[\textsf{autospacing}\,=<bool>$^\ast$] [\verb+\autospacing+]
855 \item[\textsf{autoxspacing}\,=<bool>$^\ast$] [\verb+\autoxspacing+]
856 \item[\textsf{kanjiskip}\,=<skip>] [\verb+\kanjiskip+]
857 \item[\textsf{xkanjiskip}\,=<skip>] [\verb+\xkanjiskip+]
858
859 \item[\textsf{differentjfm}\,=<mode>$^\dagger$]
860
861 Specify how glues/kerns between two \textbf{JAchar}s whose JFM (or size) are different. 
862 The allowed arguments are the followings:
863 \begin{description}
864 \item[\texttt{average}]
865 \item[\texttt{both}]
866 \item[\texttt{large}]
867 \item[\texttt{small}]
868 \end{description}
869
870 \item[\textsf{jacharrange}\,=<ranges>$^\ast$]
871 \item[\textsf{kansujichar}\,=\{<digit>, <chr\_code>\}] [\verb+\kansujichar+]
872 \end{list}
873
874
875 \section{Other Primitives}
876 \subsection{Compatibility with \pTeX}
877 \begin{list}{}{\def\makelabel{\ttfamily\char92 }}
878 \item[kuten]
879 \item[jis]
880 \item[euc]
881 \item[sjis]
882 \item[ucs]
883 \item[kansuji]
884 \end{list}
885
886 \section{Control Sequences for \LaTeXe}
887 \subsection{Patch for NFSS2}
888 As described in Subsection~\ref{ssec-ltx}, \LuaTeX-ja simply adopted \texttt{plfonts.dtx} in \pLaTeXe\ for the Japanese patch for NFSS2. 
889
890 \subsection{Cropmark/`tombow'}
891
892 \part{Implementations}\label{part-imp}
893 \section{Storing Parameters}\label{sec-para}
894 \subsection{Used Dimensions and Attributes}
895 Here the following is the list of dimension and attributes which are used in \LuaTeX-ja.
896 \begin{list}{}{%
897 \def\makelabel{\ttfamily}
898 \def\dim#1{\item[\char92 #1\ \textrm{(dimension)}]}
899 \def\attr#1{\item[\char92 #1\ \textrm{(attribute)}]}
900 }
901
902 \dim{jQ}
903 As explained in Subsection~\ref{ssec-plain}, \verb+\jQ+ is equal to
904                         $1\,\textrm{Q}=0.25\,\textrm{mm}$, where `Q'~(also called `級') is
905                         a unit used in Japanese phototypesetting. So one should not change the value of this dimension. 
906 \dim{jH}
907 There is also a unit called `歯' which equals to $0.25\,\textrm{mm}$ and
908                         used in Japanese phototypesetting. The dimension
909                         \verb+\jH+ stores this length, similar to \verb+\jQ+. 
910 \dim{ltj@zw} A temporal register for the `full-width' of current Japanese font.
911 \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.
912 \attr{jfam} Current number of Japanese font family for math formulas.
913 \attr{ltj@curjfnt} The font index of current Japanese font.
914 \attr{ltj@charclass} The character class of Japanese \textit{glyph\_node}.
915 \attr{ltj@yablshift} The amount of shifting the baseline of alphabetic
916                         fonts in scaled point ($2^{-16}\,\textrm{pt}$).
917 \attr{ltj@ykblshift} The amount of shifting the baseline of Japanese
918                         fonts in scaled point ($2^{-16}\,\textrm{pt}$).
919 \attr{ltj@autospc} Whether the auto insertion of \textsf{kanjiskip} is allowed at the node.
920 \attr{ltj@autoxspc} Whether the auto insertion of \textsf{xkanjiskip} is allowed at the node.
921 \attr{ltj@icflag} For distinguishing `kinds' of the node. To this
922                         attribute, one of the following value is
923                         assigned:
924 \begin{description}
925 \item[ITALIC (1)] Glues from an itaric correction
926            (\verb+\/+). This distinction of origins of glues 
927            (from explicit \verb+\kern+, or from \verb+\/+)
928            is needed in the insertion process of \textsf{xkanjiskip}.
929 \item[PACKED (2)] 
930 \item[KINSOKU (3)] Penalties inserted for the word-wrapping  process of Japanese characters (\emph{kinsoku}).
931 \item[FROM\_JFM (4)] Glues/kerns from JFM.
932 \item[LINE\_END (5)] Kerns for ...
933 \item[KANJI\_SKIP (6)] Glues for \textsf{kanjiskip}.
934 \item[XKANJI\_SKIP (7)] Glues for \textsf{xkanjiskip}.
935 \item[PROCESSED (8)] Nodes which is already processed by ...
936 \item[IC\_PROCESSED (9)] Glues from an itaric correction, but also already processed.
937 \item[BOXBDD (15)] Glues/kerns that inserted just the beginning or the ending of an hbox or a paragraph.
938 \end{description}
939 \attr{ltj@kcat$i$} Where $i$~is a natural number which is less than~7.
940 These 7~attributes store bit~vectors indicating which character block is regarded as a block of \textbf{JAchar}s.
941 \end{list}
942
943 \subsection{Stack System of \LuaTeX-ja}
944 \paragraph{Background}
945 \LuaTeX-ja has its own stack system, and most parameters of \LuaTeX-ja
946 are stored in it.  To clarify the reason, imagine the parameter
947 \textsf{kanjiskip} is stored by a skip, and consider the following
948 source:
949 \begin{LTXexample}
950 \ltjsetparameter{kanjiskip=0pt}ふがふが.%
951 \setbox0=\hbox{\ltjsetparameter{kanjiskip=5pt}ほげほげ}
952 \box0.ぴよぴよ\par
953 \end{LTXexample}
954
955 As described in Part~\ref{part-ref}, the only effective value of
956 \textsf{kanjiskip} in an hbox is the latest value, so the value of
957 \textsf{kanjiskip} which applied in the entire hbox should be 5\,pt.
958 However, by the implementation method of \LuaTeX, this `5\,pt' cannot be
959 known from any callbacks.  In the \texttt{tex/packaging.w} (which is a
960 file in the source of \LuaTeX), there are the following codes:
961 \begin{lstlisting}
962 void package(int c)
963 {
964     scaled h;                   /* height of box */
965     halfword p;                 /* first node in a box */
966     scaled d;                   /* max depth */
967     int grp;
968     grp = cur_group;
969     d = box_max_depth;
970     unsave();
971     save_ptr -= 4;
972     if (cur_list.mode_field == -hmode) {
973         cur_box = filtered_hpack(cur_list.head_field,
974                                  cur_list.tail_field, saved_value(1),
975                                  saved_level(1), grp, saved_level(2));
976         subtype(cur_box) = HLIST_SUBTYPE_HBOX;
977 \end{lstlisting}
978 Notice that \verb+unsave+ is executed \emph{before}
979 \verb+filtered_hpack+ (this is where \verb+hpack_filter+ callback is
980 executed): so `5\,pt' in the above source is orphaned at
981 \texttt+unsave+, and hence it can't be accessed from \verb+hpack_filter+
982 callback.
983
984 \paragraph{The method}
985 The code of stack system is based on that in a post of Dev-luatex mailing list\footnote{%
986 \texttt{[Dev-luatex] tex.currentgrouplevel}, a post at 2008/8/19 by Jonathan Sauer.}.
987
988 These are two \TeX\ count registers for maintaining informations:
989 \verb+\ltj@@stack+ for the stack level, and \verb+\ltj@@group@level+ for
990 the \TeX's group level when the last assignment was done.  Parameters
991 are stored in one big table named \texttt{charprop\_stack\_table}, where
992 \texttt{charprop\_stack\_table[$i$]} stores data of stack level~$i$. If
993 a new stack level is created by \verb+\ltjsetparameter+, all data of the
994 previous level is copied.
995
996 To resolve the problem mentioned in `Background' above, \LuaTeX-ja uses
997 another thing: When a new stack level is about to be created, a whatsit
998 node whose type, subtype and value are 44~(\textit{user\_defined}),
999 30112, and current group level respectively is appended to the current
1000 list (we refer this node by \textit{stack\_flag}). This enables us to
1001 know whether assignment is done just inside a hbox. Suppose that the
1002 stack level is~$s$ and the \TeX's group level is~$t$ just after the hbox
1003 group, then:
1004 \begin{itemize}
1005 \item If there is no \textit{stack\_flag} node in the list of hbox, then
1006       no assignment was occurred inside the hbox. Hence values of
1007       parameters at the end of the hbox are stored in the stack
1008       level~$s$.
1009 \item If there is a \textit{stack\_flag} node whose value is~$t+1$, then
1010       an assignment was occurred just inside the hbox group. Hence
1011       values of parameters at the end of the hbox are stored in the
1012       stack level~$s+1$.
1013 \item If there are \textit{stack\_flag} nodes but all of their values
1014       are more than~$t+1$, then an assignment was occurred in the box,
1015       but it is done is `more internal' group. Hence values of
1016       parameters at the end of the hbox are stored in the stack
1017       level~$s$.
1018 \end{itemize}
1019
1020 Note that to work this trick correctly, assignments to
1021 \verb+\ltj@@stack+ and \verb+\ltj@@group@level+ have to be local always, 
1022 regardless the value of \verb+\globaldefs+.
1023 This problem is resolved by using
1024 \hbox{\verb+\directlua{tex.globaldefs=0}+} (this assignment is local).
1025
1026
1027 \section{Linebreak after Japanese Character}\label{sec-lbreak}
1028 \subsection{Reference: Behavior in \pTeX}
1029 (NOT COMPLETED)
1030
1031 In~\pTeX, a linebreak after a Japanese character doesn't emit a space,
1032 since words are not separated by spaces in Japanese writings. However,
1033 this feature isn't fully implemented in \LuaTeX-ja due to the
1034 specification of callbacks in~\LuaTeX. To clarify the difference between
1035 \pTeX~and~\LuaTeX, We briefly describe the handling of a linebreak in~\pTeX, in
1036 this subsection. 
1037
1038 \pTeX's input processor can be described in terms of a finite state
1039 automaton, as that of~\TeX\ in~Section~2.5 of~\cite{texbytopic}. The
1040 internal states are as follows:
1041 \begin{itemize}
1042 \item State~$N$: new line
1043 \item State~$S$: skipping spaces
1044 \item State~$M$: middle of line
1045 \item State~$K$: after a Japanese character
1046 \end{itemize}
1047 The first three states---$N$, $S$~and~$M$---are as same as \TeX's input
1048 processor.  State~$K$ is similar to state~$M$, and is entered after
1049 Japanese characters.  The diagram of state transitions are indicated in
1050 Figure~\ref{fig-ptexipro}.  Note that \pTeX\ doesn't leave state~$K$
1051 after `beginning/ending of a group' characters.
1052 \begin{figure}[tb]
1053 \label{fig-ptexipro}
1054 \begin{gather*}
1055  \def\sp{\text{\tt\char32}}
1056  \xymatrix{&&
1057    {\text{scan a cs}}\ar@(r,ul)[dr]&\\
1058 \ar[r]&
1059    *++[o][F-]{N}\ar[ur]^0\ar[dd]_{d,\ g}\ar[u]^{5\ (\text{\tt\char92par})}
1060      \ar@{->}@(d,l)[ddrr]_(0.45){j}&&
1061    *++[o][F-]{S}\ar@(l,dr)[ul]^0\ar@(l,ur)[ddll]_{d,\ g}\ar[u]_{5}
1062      \ar@{->}@(r,r)[dd]^{j}\\&\\&
1063    *++[o][F-]{M}\ar[uuur]^0\ar@(r,dl)[uurr]_(0.55){10\ (\sp)}
1064      \ar[d]_{5\ ({\sp})}\ar@{->}@(dr,dl)[rr]_{j}&&
1065    *++[o][F-]{K}\ar@{->}@(ul,d)[uuul]^0\ar@{->}[ll]^{d}
1066      \ar@{->}@(ur,dr)[uu]^{10\ (\sp)}\ar@{->}[d]_5\\
1067    &&&
1068  }\\
1069  d:=\{3,4,6,7,8,11,12,13\},\quad g:=\{1,2\},\quad j:=(\text{Japanese characters})
1070 \end{gather*}
1071 \begin{itemize}
1072 \item Numbers represent category codes.
1073 \item Category codes 9~(ignored), 14~(comment)~and~15~(invalid) are omitted in above diagram.
1074 \end{itemize}
1075 \caption{State transitions of \pTeX's input processor.}
1076 \end{figure}
1077
1078
1079 \subsection{Behavior in \LuaTeX-ja}
1080 States in the input processoe of \LuaTeX\ is the same as that of \TeX,
1081 and they can't be customized by any callbacks. Hence, we can only use
1082 \verb+process_input_buffer+ and \verb+token_filter+ callbacks for to
1083 suppress a space by a linebreak which is after Japanese characters.
1084
1085 However, \verb+token_filter+ callback cannot be used either, since a
1086 character in category code 5~(end-of-line) is converted into an space
1087 token \emph{in the input processor}.  So we can use only the
1088 \verb+process_input_buffer+ callback.  This means that suppressing a
1089 space must be done \emph{just before} an input line is read.
1090
1091 Considering these situations, handling of a end-of-line in \LuaTeX-ja are as follows:
1092 \begin{quote}
1093 A character U+FFFFF (its category code is set to 14~(comment) by
1094 \LuaTeX-ja) is appended to an input line, before \LuaTeX\ actually
1095 process it, if and only if the following two conditions are satisfied:
1096 \begin{enumerate}
1097 \item The category code of the character $\langle${return}$\rangle$
1098       (whose character code is 13) is 5~(end-of-line).
1099 \item The input line matches the following `regular expression':
1100 \[
1101   (\text{any char})^*(\textbf{JAchar})
1102   \bigl(\{\text{catcode}=1\}\cup\{\text{catcode}=2\}\bigr)^*
1103 \]
1104 \end{enumerate}
1105
1106 \end{quote}
1107
1108 \section{Insertion of JFM glues, \textsf{kanjiskip} and \textsf{xkanjiskip}}
1109 This is the longest section of the document.
1110
1111 jfmglue.tex の内容をここに入れる
1112 \end{document}