OSDN Git Service

Fix ticket 26455.
[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-otf}
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
220 Note that the forefront of development may not be in \texttt{master} branch.
221 \item Extract the archive. You will see {\tt src/} and several other sub-directories.
222 \item Copy all the contents of {\tt src/} into one of your \texttt{TEXMF} tree.
223 \item If {\tt mktexlsr} is needed to update the filename database, make it so.
224 \end{enumerate}
225
226 \subsection{Cautions}
227 \begin{itemize}
228 \item The encoding of your source file must be UTF-8. No other
229       encodings, such as EUC-JP or Shift-JIS, are not supported.
230 \item May be conflict with other packages. 
231
232 For example, the default setting of \textbf{JAchar} in the present
233       version does not coexist with \texttt{unicode-math}
234       package. Putting the following line in preamble makes that
235       mathematical symbols will be typeset correctly, but several
236       Japanese characters will be treated as an \textbf{ALchar} as
237       side-effect:
238 \begin{verbatim}
239 \ltjsetparameter{jacharrange={-3, -8}}
240 \end{verbatim}
241 \end{itemize}
242
243 \subsection{Using in plain \TeX}\label{ssec-plain}
244 To use \LuaTeX-ja in plain \TeX, simply put the following  at the beginning of the document:
245 \begin{verbatim}
246 \input luatexja.sty
247 \end{verbatim}
248
249 This does minimal settings (like {\tt ptex.tex}) for typesetting Japanese documents:
250 \begin{itemize}
251 \item The following 6~Japanese fonts are preloaded:
252 \begin{center}
253 \begin{tabular}{ccccc}
254 \toprule
255 \textbf{classification}&\textbf{font name}&\bf `10\,pt'&\bf`7\,pt'&\bf`5\,pt'\\\midrule
256 \emph{mincho}&Ryumin-Light    &\verb+\tenmin+&\verb+\sevenmin+&\verb+\fivemin+\\
257 \emph{gothic}&GothicBBB-Medium&\verb+\tengt+ &\verb+\sevengt+ &\verb+\fivegt+\\
258 \bottomrule
259 \end{tabular}
260 \end{center}
261 \begin{itemize}
262 \item The `Q' is a unit used in Japanese phototypesetting, and
263       $1\,\textrm{Q}=0.25\,\textrm{mm}$. This length is stored in a
264       dimension \verb+\jQ+.
265
266 \item It is widely accepted that the font `Ryumin-Light' and
267       `GothicBBB-Medium' aren't embedded into PDF files, and PDF reader
268       substitute them by some external Japanese fonts (\textit{e.g.},
269       Kozuka Mincho is used for Ryumin-Light in Adobe Reader). We adopt this custom to
270       the default setting.
271 \item A character in an alphabetic font is generally smaller than a
272       Japanese font in the same size. So actual size specification of
273       these Japanese fonts is in fact smaller than that of alphabetic
274       fonts, namely scaled by 0.962216.
275 \end{itemize}
276 \item The amount of glue that are inserted between a \textbf{JAchar} and
277       an \textbf{ALchar} (the parameter \textsf{xkanjiskip}) is set to
278 \[
279  (0.25\cdot 13.5\,\textrm{Q})^{+1\,\text{pt}}_{-1\,\text{pt}} 
280  = {27\over 32}\,\mathrm{mm}^{+1\,\text{pt}}_{-1\,\text{pt}}.
281 \]
282 \end{itemize}
283
284 \subsection{Using in \LaTeX}\label{ssec-ltx}
285 \paragraph{\LaTeXe}
286 Using in \LaTeXe\ is basically same. To set up the minimal environment
287 for Japanese, you only have to load {\tt luatexja.sty}:
288 \begin{verbatim}
289 \usepackage{luatexja}
290 \end{verbatim}
291 It also does minimal settings (counterparts in \pLaTeX\ are {\tt
292 plfonts.dtx} and {\tt pldefs.ltx}):
293
294 \begin{itemize}
295 \item {\tt JY3} is the font encoding for Japanese fonts (in horizontal direction).\\
296 When vertical typesetting is supported by \LuaTeX-ja in the future, {\tt JT3} will be used for vertical fonts.
297 \item Two font families {\tt mc} and {\tt gt} are defined: 
298 \begin{center}
299 \begin{tabular}{ccccc}
300 \toprule
301 \textbf{classification}&\textbf{family}&\verb+\mdseries+&\verb+\bfseries+&\textbf{scale}\\\midrule
302 \emph{mincho}&\tt mc&Ryumin-Light    &GothicBBB-Medium&0.962216\\
303 \emph{gothic}&\tt gt&GothicBBB-Medium&GothicBBB-Medium&0.962216\\
304 \bottomrule
305 \end{tabular}
306 \end{center}
307 Remark that the bold series in both family are same as the medium series of \emph{gothic} family.
308 This is a convention in \pLaTeX.
309
310 \item Japanese characters in math mode are typeset by the font family {\tt mc}.
311 \end{itemize}
312
313 However, above settings are not sufficient for Japanese-based
314 documents. To typeset Japanese-based documents, You are better to use
315 class files other than {\tt article.cls}, {\tt book.cls}, and so on.  At
316 the present, we have the counterparts of \texttt{jclasses} (standard
317 classes in \pLaTeX) and \texttt{jsclasses} (classes by Haruhiko
318 Okumura), namely, \texttt{ltjclasses} and \texttt{ltjsclasses}.
319
320 \paragraph{{\tt\char92 CID, {\tt\char92 UTF}} and macros in OTF package}
321 Under \pTeX, \texttt{OTF} package (developed by Shuzaburo Saito) is
322 used for typesetting characters which is in Adobe-japan1-6 CID but not
323 in JIS~X~0208. Since this package is widely used, \LuaTeX-ja
324 supports some of functions in \texttt{OTF} package.
325
326 \begin{LTXexample}
327 森\UTF{9DD7}外と内田百\UTF{9592}とが\UTF{9AD9}島屋に行く。
328
329 \CID{7652}飾区の\CID{13706}野家,
330 葛飾区の吉野家
331 \end{LTXexample}
332 %lltjlisting.sty要修正?:↑「森」の直後で改行.
333
334
335 \subsection{Changing Fonts}
336 \paragraph{Remark: Japanese Characters in Math Mode}
337 Since \pTeX\ supports Japanese characters in math mode, there are
338 sources like the following:
339
340 \begin{LTXexample}
341 $f_{高温}$~($f_{\text{high temperature}}$).
342 \[ y=(x-1)^2+2\quad{}よって\quad y>0 \]
343 $5\in{}素:=\{\,p\in\mathbb N:\text{$p$ is a prime}\,\}$.
344 \end{LTXexample}
345
346 We (the project members of \LuaTeX-ja) think that using
347 Japanese characters in math mode are allowed if and only if these are used as identifiers.
348 In this point of view, 
349 \begin{itemize}
350 \item The lines 1~and~2 above are not correct, since `高温' in above is used as a textual label, and
351 `よって' is used as a conjunction. 
352 \item However, the line~3 is correct, since `素' is used as an identifier.
353 \end{itemize}
354 Hence, in our opinion, the above input should be corrected as:
355 \begin{LTXexample}
356 $f_{\text{高温}}$~%
357 ($f_{\text{high temperature}}$).
358 \[ y=(x-1)^2+2\quad 
359   \mathrel{\text{よって}}\quad y>0 \]
360 $5\in{}素:=\{\,p\in\mathbb N:\text{$p$ is a prime}\,\}$.
361 \end{LTXexample}
362 %BUG?: \{\}がなければ「素」がでない.上の段落の「よって」もでてない.
363 We also believe that using Japanese characters as identifiers is rare,
364 hence we don't describe how to change Japanese fonts in math mode in
365 this chapter. For the method, please see Part~\ref{part-ref}.
366
367
368 \paragraph{plain \TeX}
369 To change Japanese fonts in plain \TeX, you must use the primitive
370 \verb+\jfont+. So please see Part~\ref{part-ref}.
371
372
373 \paragraph{NFSS2}
374 For \LaTeXe, \LuaTeX-ja simply adopted the font selection system from that
375 of \pLaTeXe\ (in {\tt plfonts.dtx}).
376 \begin{itemize}
377 \item Two control sequences \verb+\mcdefault+ and \verb+\gtdefault+ are
378       used to specify the default font families for \emph{mincho} and
379       \emph{gothic}, respectively. Default values: \texttt{mc} for
380       \verb+\mcdefault+ and \texttt{gt} for \verb+\gtdefault+.
381 \item Commands \verb+\fontfamily+, \verb+\fontseries+,
382       \verb+\fontshape+ and \verb+\selectfont+ can be used to change
383       attributes of Japanese fonts. 
384 \begin{center}
385 \begin{tabular}{ccccc}
386 \toprule
387 &\textbf{encoding}&\textbf{family}&\textbf{series}&\textbf{shape}\\\midrule
388 alphabetic fonts
389 &\verb+\romanencoding+&\verb+\romanfamily+&\verb+\romanseries+&\verb+\romanshape+\\
390 Japanese fonts
391 &\verb+\kanjiencoding+&\verb+\kanjifamily+&\verb+\kanjiseries+&\verb+\kanjishape+\\
392 both&---&--&\verb+\fontseries+&\verb+\fontshape+\\
393 auto select&\verb+\fontencoding+&\verb+\fontfamily+&---&---\\
394 \bottomrule
395 \end{tabular}
396 \end{center}
397 \item For defining a Japanese font family, use \verb+\DeclareKanjiFamily+
398       instead of \verb+\DeclareFontFamily+.
399 \end{itemize}
400
401 \paragraph{fontspec}
402 To coexist with the \texttt{fontspec} package, it is needed to load
403 \texttt{luatexja-fontspec} package in the preamble. This additional
404 package automatically loads \texttt{luatexja} and \texttt{fontspec}
405 package, if needed.
406
407 In \texttt{luatexja-fontspec} package, the following 7~commands are defined as
408 counterparts of original commands in \texttt{fontspec}:
409 \begin{center}
410 \begin{tabular}{ccccc}
411 \toprule
412 Japanese fonts
413 &\verb+\jfontspec+&\verb+\setmainjfont+&\verb+\setsansjfont+&\verb+\newjfontfamily+\\
414 alphabetic fonts
415 &\verb+\fontspec+&\verb+\setmainfont+&\verb+\setsansfont+&\verb+\newfontfamily+\\
416 \midrule
417 Japanese fonts
418 &\verb+\newjfontface+&\verb+\defaultjfontfeatures+&\verb+\addjfontfeatures+\\
419 alphabetic fonts
420 &\verb+\newfontface+&\verb+\defaultfontfeatures+&\verb+\addfontfeatures+\\
421 \bottomrule
422 \end{tabular}
423 \end{center}
424 使用例
425
426
427 Note that there is no command named \verb+\setmonojfont+, since it is
428 popular for Japanese fonts that nearly all Japanese glyphs have same
429 widths.  Also note that the kerning feature is set off by default in
430 these 7~commands, since this feature and \textbf{JAglue} will clash (see
431 \ref{para-kern}).
432
433 \section{Changing Parameters}
434 There are many parameters in \LuaTeX-ja. And due to the behavior of \LuaTeX,
435 most of them are not stored as internal register of \TeX, but as an
436 original storage system in \LuaTeX-ja. Hence, to assign or acquire those
437 parameters, you have to use commands \verb+\ltjsetparameter+ and
438 \verb+\ltjgetparameter+.
439
440 \subsection{Editing the range of \textbf{JAchar}s}
441
442
443 To edit the range of \textbf{JAchar}s, You have to assign a non-zero
444 natural number which is less than 217 to the character range first. This
445 can be done by using \verb+\ltjdefcharrange+ primitive. For example, the
446 next line assigns whole characters in Supplementary Multilingual Plane
447 and the character `漢' to the range number~100.
448 \begin{lstlisting}
449 \ltjdefcharrange{100}{"10000-"1FFFF,`漢}
450 \end{lstlisting}
451 This assignment of numbers to ranges are always global, so you should
452 not do this in the middle of a document. 
453
454 If some character has been belonged to some non-zero numbered range,
455 this will be overwritten by the new setting. For example, whole SMP
456 belong the range~4 in the default setting of \LuaTeX-ja, and if you
457 specify the above line, then SMP will belong the range~100 and be
458 removed from the range~4.
459
460 After assigning numbers to ranges, the {\sf jacharrange} parameter can
461 be used to customize which character range will be treated as ranges of
462 \textbf{JAchar}s, as the following line (this is just the default
463 setting of \LuaTeX-ja):
464 \begin{verbatim}
465 \ltjsetparameter{jacharrange={-1, +2, +3, -4, -5, +6, +7, +8}}
466 \end{verbatim}
467
468
469
470 \paragraph{Default Setting}
471 Lua\TeX-ja predefines eight character ranges for convinience. They are
472 determined from the following data:
473 \begin{itemize}
474 \item Blocks in Unicode~6.0.
475 \item The \texttt{Adobe-Japan1-UCS2} mapping between a CID Adobe-Japan1-6 and Unicode.
476 \item The \texttt{PXbase} bundle for \upTeX\ by Takayuki Yato.
477 \end{itemize}
478
479 Now we describe these eight ranges. The alphabet `J' or `A' after the
480 number shows whether characters in the range is treated as
481 \textbf{JAchar}s or not by default. These settings are similar to \texttt{prefercjk} ...
482 \begin{description}
483 \item[Range~8${}^{\text{J}}$] Symbols in the intersection of the upper half of ISO~8859-1
484          (Latin-1 Supplement) and JIS~X~0208 (a basic character set for Japanese). This character range
485          consists of the following charatcers:
486 \begin{multicols}{2}
487 \begin{itemize}
488 \def\ch#1#2{\item \char"#1\ ({\tt U+00#1}, #2)}%"
489 \ch{A7}{Section Sign}
490 \ch{A8}{Umlaut or diaeresis}
491 \ch{B0}{Degree sign}
492 \ch{B1}{Plus-minus sign}
493 \ch{B4}{Spacing acute}
494 \ch{B6}{Paragraph sign}
495 \ch{D7}{Multiplication sign}
496 \ch{F7}{Division Sign}
497 \end{itemize}
498 \end{multicols}
499 \item[Range~1${}^{\text{A}}$] Latin characters that some of them are included in Adobe-Japan1-6.
500 This range consist of the following Unicode ranges, \emph{except characters in the range~8 above}:
501 \begin{multicols}{2}
502 \begin{itemize}
503 \item {\tt U+0080}--{\tt U+00FF}: Latin-1 Supplement
504 \item {\tt U+0100}--{\tt U+017F}: Latin Extended-A
505 \item {\tt U+0180}--{\tt U+024F}: Latin Extended-B
506 \item {\tt U+0250}--{\tt U+02AF}: IPA Extensions
507 \item {\tt U+02B0}--{\tt U+02FF}: Spacing Modifier Letters
508 \item {\tt U+0300}--{\tt U+036F}: Combining Diacritical Marks
509 \item {\tt U+1E00}--{\tt U+1EFF}: Latin Extended Additional
510 \par\ 
511 \end{itemize}
512 \end{multicols}
513 \item[Range~2${}^{\text{J}}$] Greek and Cyrillic letters. JIS~X~0208 (hence most of Japanese
514            fonts) has some of these characters.
515 \begin{multicols}{2}
516 \begin{itemize}
517 \item {\tt U+0370}--{\tt U+03FF}: Greek and Coptic
518 \item {\tt U+0400}--{\tt U+04FF}: Cyrillic
519 \item {\tt U+1F00}--{\tt U+1FFF}: Greek Extended
520 \\\ 
521 \end{itemize}
522 \end{multicols}
523 \item[Range~3${}^{\text{J}}$] Punctuations and Miscellaneous symbols. The block list is
524            indicated in Table~\ref{table-rng3}.
525 \begin{table}[p]
526 \caption{Unicode blocks in predefined character range~3.}\label{table-rng3}
527 \catcode`\"=13\def"#1#2#3#4{{\tt U+#1#2#3#4}}%"
528 \begin{center}
529 \begin{tabular}{ll}
530 "2000--"206F&General Punctuation\\
531 "2070--"209F&Superscripts and Subscripts\\
532 "20A0--"20CF&Currency Symbols\\
533 "20D0--"20FF&Combining Diacritical Marks for Symbols\\
534 "2100--"214F&Letterlike Symbols\\
535 "2150--"218F&Number Forms\\
536 "2190--"21FF&Arrows\\
537 "2200--"22FF&Mathematical Operators\\
538 "2300--"23FF&Miscellaneous Technical\\
539 "2400--"243F&Control Pictures\\
540 "2500--"257F&Box Drawing\\
541 "2580--"259F&Block Elements\\
542 "25A0--"25FF&Geometric Shapes\\
543 "2600--"26FF&Miscellaneous Symbols\\
544 "2700--"27BF&Dingbats\\
545 "2900--"297F&Supplemental Arrows-B\\
546 "2980--"29FF&Miscellaneous Mathematical Symbols-B\\
547 "2B00--"2BFF&Miscellaneous Symbols and Arrows\\
548 "E000--"F8FF&Private Use Area\\
549 "FB00--"FB4F&Alphabetic Presentation Forms
550 \end{tabular}
551 \end{center}
552 \end{table}
553 \item[Range~4${}^{\text{A}}$] Characters usually not in Japanese fonts. This range consists
554            of almost all Unicode blocks which are not in other
555            predefined ranges. Hence, instead of showing the block list,
556            we put the definition of this range itself:
557 \begin{lstlisting}
558 \ltjdefcharrange{4}{%
559    "500-"10FF, "1200-"1DFF, "2440-"245F, "27C0-"28FF, "2A00-"2AFF, 
560   "2C00-"2E7F, "4DC0-"4DFF, "A4D0-"A82F, "A840-"ABFF, "FB50-"FE0F, 
561   "FE20-"FE2F, "FE70-"FEFF, "10000-"1FFFF} % non-Japanese
562 \end{lstlisting}
563 \item[Range~5${}^{\text{A}}$] Surrogates and Supplementary Private Use Areas.
564 \item[Range~6${}^{\text{J}}$] Characters used in Japanese. The block list is indicated in Table~\ref{table-rng6}.
565 \begin{table}[p]
566 \caption{Unicode blocks in predefined character range~6.}\label{table-rng6}
567 \catcode`\"=13\def"#1#2#3#4{{\tt U+#1#2#3#4}}%"
568 \begin{center}
569 \begin{tabular}{ll}
570 "2460--"24FF&Enclosed Alphanumerics\\
571 "2E80--"2EFF&CJK Radicals Supplement\\
572 "3000--"303F&CJK Symbols and Punctuation\\
573 "3040--"309F&Hiragana\\
574 "30A0--"30FF&Katakana\\
575 "3190--"319F&Kanbun\\
576 "31F0--"31FF&Katakana Phonetic Extensions\\
577 "3200--"32FF&Enclosed CJK Letters and Months\\
578 "3300--"33FF&CJK Compatibility\\
579 "3400--"4DBF&CJK Unified Ideographs Extension A\\
580 "4E00--"9FFF&CJK Unified Ideographs\\
581 "F900--"FAFF&CJK Compatibility Ideographs\\
582 "FE10--"FE1F&Vertical Forms\\
583 "FE30--"FE4F&CJK Compatibility Forms\\
584 "FE50--"FE6F&Small Form Variants\\
585 "{20}000--"{2F}FFF&(Supplementary Ideographic Plane)
586 \end{tabular}
587 \end{center}
588 \end{table}
589 \item[Range~7${}^{\text{J}}$] Characters used in CJK languages, but not included in  Adobe-Japan1-6.
590 The block list is indicated in Table~\ref{table-rng7}.
591 \begin{table}[p]
592 \caption{Unicode blocks in predefined character range~7.}\label{table-rng7}
593 \catcode`\"=13\def"#1#2#3#4{{\tt U+#1#2#3#4}}%"
594 \begin{center}
595 \begin{tabular}{ll}
596 "1100--"11FF&Hangul Jamo\\
597 "2F00--"2FDF&Kangxi Radicals\\
598 "2FF0--"2FFF&Ideographic Description Characters\\
599 "3100--"312F&Bopomofo\\
600 "3130--"318F&Hangul Compatibility Jamo\\
601 "31A0--"31BF&Bopomofo Extended\\
602 "31C0--"31EF&CJK Strokes\\
603 "A000--"A48F&Yi Syllables\\
604 "A490--"A4CF&Yi Radicals\\
605 "A830--"A83F&Common Indic Number Forms\\
606 "AC00--"D7AF&Hangul Syllables\\
607 "D7B0--"D7FF&Hangul Jamo Extended-B
608 \end{tabular}
609 \end{center}
610 \end{table}
611 \end{description}
612
613
614 \subsection{\textsf{kanjiskip} and \textsf{xkanjiskip}}\label{subs-kskip}
615 \textbf{JAglue} is divided into the following three categories:
616 \begin{itemize}
617 \item Glues/kerns specified in JFM. If \verb+\inhibitglue+ is issued
618       around a Japanese character, this glue will be not inserted at the
619       place.
620 \item The default glue which inserted between two \textbf{JAchar}s ({\sf
621       kanjiskip}).
622 \item The default glue which inserted between a \textbf{JAchar} and an
623       \textbf{ALchar} (\textsf{xkanjiskip}).
624 \end{itemize}
625 The value (a skip) of \textsf{kanjiskip} or \textsf{xkanjiskip} can be
626 changed as the following.
627 \begin{lstlisting}
628 \ltjsetparameter{kanjiskip={0pt plus 0.4pt minus 0.4pt}, 
629                  xkanjiskip={0.25\zw plus 1pt minus 1pt}}
630 \end{lstlisting}
631
632
633 It may occur that JFM contains the data of `ideal width of {\sf
634 kanjiskip}' and/or `ideal width of \textsf{xkanjiskip}'.
635 To use these data from JFM, set the value of \textsf{kanjiskip} or 
636 \textsf{xkanjiskip} to \verb+\maxdimen+.
637
638 \subsection{Insertion Setting of \textsf{xkanjiskip}}
639 It is not desirable that \textsf{xkanjiskip} is inserted between every
640 boundary between \textbf{JAchar}s and \textbf{ALchar}s. For example,
641 \textsf{xkanjiskip} should not be inserted after opening parenthesis
642 (\textit{e.g.}, compare `(あ' and `(\hskip\ltjgetparameter{xkanjiskip}あ').
643
644 \LuaTeX-ja can control whether \textsf{xkanjiskip} can be inserted
645 before/after a character, by changing \textsf{jaxspmode} for \textbf{JAchar}s and
646 \textsf{alxspmode} parameters \textbf{ALchar}s respectively. 
647 \begin{LTXexample}
648 \ltjsetparameter{jaxspmode={`あ,preonly}, alxspmode={`\!,postonly}} 
649 pあq い!う
650 \end{LTXexample}
651
652 The second argument {\tt preonly} means `the insertion of
653 \textsf{xkanjiskip} is allowed before this character, but not after'.
654 the other possible values are {\tt postonly}, {\tt allow} and {\tt
655 inhibit}. For the compatibility with \pTeX, natural numbers between
656 0~and~3 are also allowed as the second argument\footnote{But we don't
657 recommend this: since numbers 1~and~2 have opposite meanings in
658 \textsf{jaxspmode} and \textsf{alxspmode}.}.
659
660 If you want to enable/disable all insertions of \textsf{kanjiskip} and
661 \textsf{xkanjiskip}, set \textsf{autospacing} and \textsf{autoxspacing}
662 parameters to {\tt false}, respectively.
663
664
665 \subsection{Shifting Baseline}
666 To make a match between a Japanese font and an alphabetic font, sometimes
667 shifting of the baseline of one of the pair is needed. In \pTeX, this is achieved
668 by setting \verb+\ybaselineshift+ to a non-zero length (the
669 baseline of alphabetic fonts is shifted below). However, for documents
670 whose main language is not Japanese, it is good to shift the baseline of
671 Japanese fonts, but not that of alphabetic fonts.
672 Because of this, \LuaTeX-ja can independently set the shifting amount
673 of the baseline of alphabetic fonts (\textsf{yalbaselineshift}
674 parameter) and that of Japanese fonts (\textsf{yjabaselineshift}
675 parameter). 
676
677 \begin{LTXexample}
678 \vrule width 150pt height 0.4pt depth 0pt\hskip-120pt
679 \ltjsetparameter{yjabaselineshift=0pt, yalbaselineshift=0pt}abcあいう
680 \ltjsetparameter{yjabaselineshift=5pt, yalbaselineshift=2pt}abcあいう
681 \end{LTXexample}
682 Here the horizontal line in above is the baseline of a line.
683
684 There is an interesting side-effect: characters in different size can be
685 vertically aligned center in a line, by setting two parameters appropriately.
686 The following is an example (beware the value is not well tuned):
687 \begin{LTXexample}
688 xyz漢字 
689 {\scriptsize
690   \ltjsetparameter{yjabaselineshift=-1pt, 
691     yalbaselineshift=-1pt}
692   XYZひらがな
693 }abcかな
694 \end{LTXexample}
695
696
697 \subsection{Cropmark}
698 Cropmark is a mark for indicating 4~corners and horizontal/vertical
699 center of the paper. In Japanese, we call cropmark as tombo(w).
700 \pLaTeX\ and this \LuaTeX-ja support `tombow' by their kernel.
701 The following steps are needed to typeset cropmark:
702
703 \begin{enumerate}
704 \item First, define the banner which will be printed at the upper left
705       of the paper. This is done by assigning a token list to
706       \verb+\@bannertoken+.
707
708 For example, the following sets banner as `{\tt filename (2012-01-01 17:01)}':
709 \begin{verbatim}
710 \makeatletter
711
712 \hour\time \divide\hour by 60 \@tempcnta\hour \multiply\@tempcnta 60\relax
713 \minute\time \advance\minute-\@tempcnta
714 \@bannertoken{%
715    \jobname\space(\number\year-\two@digits\month-\two@digits\day
716    \space\two@digits\hour:\two@digits\minute)}%
717 \end{verbatim}
718
719 \item ...
720 \end{enumerate}
721
722
723 \part{Reference}\label{part-ref}
724 \section{Font Metric and Japanese Font}
725 \subsection{\texttt{\char92jfont} primitive}
726 To load a font as a Japanese font, you must use the
727 \verb+\jfont+ primitive instead of~\verb+\font+, while
728 \verb+\jfont+ admits the same syntax used in~\verb+\font+. 
729 \LuaTeX-ja automatically loads \texttt{luaotfload} package,
730 so TrueType/OpenType fonts with features can be used for Japanese fonts:
731 \begin{LTXexample}
732 \jfont\tradgt={file:ipaexg.ttf:script=latn;%
733   +trad;-kern;jfm=ujis} at 14pt
734 \tradgt{}当/体/医/区
735 \end{LTXexample}
736
737 Note that the defined control sequence
738 (\verb+\tradgt+ in the example above) using \verb+\jfont+ is not a
739 \textit{font\_def} token, hence the input like \verb+\fontname\tradgt+
740 causes a error.  We denote control sequences which are defined in
741 \verb+\jfont+ by <jfont\_cs>.
742
743 \paragraph{Prefix \texttt{psft}}
744 Besides \texttt{file:}\ and \texttt{name:}\ prefixes, \texttt{psft:}\
745 can be used a prefix in \verb+\jfont+ (and~\verb+\font+) primitive.
746 Using this prefix, you can specify a `name-only' Japanese font which
747 will be not embedded to PDF. Typical use of this prefix is to specify
748 the `standard' Japanese fonts, namely, `Ryumin-Light' and
749 `GothicBBB-Medium'. For kerning or other informations, that of Kozuka
750 Mincho Pr6N Regular (this is a font by Adobe Inc., and included in
751 Japanese Font Packs for Adore Reader) will be used.
752
753
754 \paragraph{JFM}
755 As noted in Introduction, a JFM has measurements of characters and
756 glues/kerns that are automatically inserted for Japanese
757 typesetting. The structure of JFM will be described in the next
758 subsection. At the calling of \verb+\jfont+ primitive, you must specify
759 which JFM will be used for this font by the following keys:
760
761 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
762 \item[jfm=<name>]
763 Specify the name of JFM. A file named \texttt{jfm-<name>.lua} will be searched and/or loaded.
764
765 The followings are JFMs shipped with Lua\TeX-ja:
766 \begin{description}
767 \item[\tt jfm-ujis.lua] A standard JFM in Lua\TeX-ja. This JFM is
768       based on \verb+upnmlminr-h.tfm+, a metric for UTF/OTF package that
769       is used in \upTeX. When you use \texttt{luatexja-otf.sty}, please use this JFM.
770 \item[\tt jfm-jis.lua] A counterpart for \verb+jis.tfm+, `JIS font
771            metric' which is widely used in \pTeX. A major difference of
772            \texttt{jfm-ujis.lua} and this \texttt{jfm-jis.lua} is that
773            most haracters under \texttt{jfm-ujis.lua} are square-shaped,
774            while that under \texttt{jfm-jis.lua} are horizontal
775            rectangles.
776
777 \item[\tt jfm-min.lua] A counterpart for \verb+min10.tfm+, which is one
778            of the default Japanese font metric shipped with \pTeX. There
779            are notable difference between this JFM and other 2~JFMs, as
780            showed below:
781
782 何かいい例.単純に「min10にはバグあり」ではなく,プロポーショナルな側面も見せたいよね
783 (乙部さんのmin10.pdfの例を使う?)
784 \end{description}
785
786 \item[jfmvar=<string>] ...
787 \end{list}
788
789
790 \paragraph{Note: kern feature}\label{para-kern}
791 Some fonts have information for inter-glyph spacing. However, this
792 information is not well-compatible with \LuaTeX-ja.  More concretely,
793 this kerning space from this information are inserted \emph{before} the
794 insertion process of \textbf{JAglue}, and this causes incorrect spacing
795 between two characters when both a glue/kern from the data in the font
796 and it from JFM are present.
797
798 \begin{itemize}
799 \item You should specify {\tt -kern} in
800 {\tt\char92jfont} primitive, when you want to use other font features,
801       such as {\tt script=...}\,.
802 \item If you want to use Japanese fonts in proportinal width, and use
803       information from this font, use \texttt{jfm-prop.lua} for its JFM, and ...
804
805 TODO: kanjiskip?
806 \end{itemize}
807
808
809 \subsection{Structure of JFM file}
810 A JFM file is a Lua script which has only one function call:
811 \begin{verbatim}
812 luatexja.jfont.define_jfm { ... }
813 \end{verbatim}
814 Real data are stored in the table which indicated above by
815 \verb+{ ... }+.  So, the rest of this subsection are devoted to describe the
816 structure of this table.  Note that all lengths in a JFM file are
817 floating-point numbers in design-size unit.
818
819 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
820 \item[dir=<direction>] (required)
821
822 The direction of JFM. At the present, only \texttt{'yoko'} is supported.
823
824 \item[zw=<length>] (required)
825
826 The amount of the length of the `full-width'.
827
828 \item[zh=<length>] (required)
829
830 \item[kanjiskip=\{<natural>, <stretch>, <shrink>\}] (optional)
831
832 This field specifies the `ideal' amount of \textsf{kanjiskip}. As noted
833              in Subsection~\ref{subs-kskip}, if the parameter
834              \textsf{kanjiskip} is \verb+\maxdimen+, the value specified
835              in this field is actually used (if this field is not specified in
836              JFM, it is regarded as 0\,pt). Note that <stretch> and <shrink>
837              fields are in design-size unit too.
838
839
840 \item[xkanjiskip=\{<natural>, <stretch>, <shrink>\}] (optional)
841
842 Like the \texttt{kanjiskip} field, this field specifies the `ideal'
843              amount of \textsf{xkanjiskip}.
844
845 \end{list}
846
847 Besides from above fields, a JFM file have several sub-tables those
848 indices are natural numbers.  The table indexed by~$i\in\omega$ stores
849 informations of `character class'~$i$. At least, the character class~0 is
850 always present, so each JFM file must have a sub-table whose index is
851 \texttt{[0]}.  Each sub-table (its numerical index is denoted by $i$) has
852 the following fields:
853
854 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
855 \item[chars=\{<character>, ...\}] (required except character class~0)
856
857 This field is a list of characters which are in this character
858              type~$i$. This field is not required if $i=0$, since all
859              \textbf{JAchar} which are not in any character class other
860              than 0 (hence, the character class~0 contains most of
861              \textbf{JAchar}s). In the list, a character can be
862              specified by its code number, or by the character itself
863              (as a string of length~1). 
864
865 In addition to those `real' characters, the following `imaginary
866              characters' can be specified in the list:
867
868 \item[width=<length>, height=<length>, depth=<length>, italic=<length>]\ (required)
869
870 Specify width of characters in character class~$i$, height, depth and
871 the amount of italic correction. All characters in character class~$i$ are regarded that its width, height and depth are
872 as values of these fields. 
873 But there is one exception: if \texttt{'prop'} is specified in \texttt{width} field, width of a character becomes that of its `real' glyph 
874
875 \item[left=<length>, down=<length>, align=<align>]\ 
876
877 These fields are for adjusting the position of the `real' glyph. Legal
878              values of \texttt{align} field are \texttt{'left'},
879              \texttt{'middle'} and \texttt{'right'}. If one of these
880              3~fields are omitted, \texttt{left} and \texttt{down} are
881              treated as~0, and \texttt{align} field is treated as
882              \texttt{'left'}.
883 The effects of these 3~fields are indicated in Figure~\ref{fig-pos}.
884
885 In most cases, \texttt{left} and \texttt{down} fields are~0, while
886 it is not uncommon that the \texttt{align} field is \texttt{'middle'} or \texttt{'right'}.
887 For example, setting the \texttt{align} field to \texttt{'right'} is practically needed 
888 when the current character class is the class for opening delimiters'. 
889 \begin{figure}[tb]
890 \begin{minipage}{0.4\textwidth}%
891 \begin{center}\unitlength=10pt\small
892 \begin{picture}(15,12)(-1,-4)
893 \color{black!10!white}% real glyph :step1
894 \put(0,0){\vrule width 12\unitlength height 8\unitlength depth 3\unitlength}
895
896 \color{red!20!white}% real glyph :step1
897 \put(-1,-1.5){\vrule width 6\unitlength height 7\unitlength depth 2.5\unitlength}
898
899 \color{red}% real glyph
900 \thicklines
901 \put(-1,-1.5){\vector(0,1){7}\vector(0,-1){2.5}\vector(1,0){6}}
902 \put(5,-1.5){\line(0,1){7}\line(0,-1){2.5}}
903 \put(-1,5.5){\line(1,0){6}}
904 \put(-1,-4){\line(1,0){6}}
905
906 \color{green!20!white}% real glyph :step1
907 \put(3,0){\vrule width 6\unitlength height 7\unitlength depth 2.5\unitlength}
908
909 \color{black}% real glyph :step1
910 \thicklines
911 \put(0,0){\vector(0,1){8}\line(0,-1){3}\vector(1,0){12}}
912 \put(12,0){\line(0,1){8}\vector(0,-1){3}}
913 \put(0,8){\line(1,0){12}}
914 \put(0,-3){\line(1,0){12}}
915 \put(0.2,4){\makebox(0,0)[l]{\texttt{height}}}
916 \put(12.2,-1.5){\makebox(0,0)[l]{\texttt{depth}}}
917 \put(6,0.2){\makebox(0,0)[b]{\texttt{width}}}
918
919 \color{green!50!black}% real glyph :step1
920 \thicklines
921 \put(3,0){\vector(0,1){7}\vector(0,-1){2.5}\vector(1,0){6}}
922 \put(9,0){\line(0,1){7}\line(0,-1){2.5}}
923 \put(3,7){\line(1,0){6}}
924 \put(3,-2.5){\line(1,0){6}}
925 \newsavebox{\eqdist}
926 \savebox{\eqdist}(0,0)[b]{%
927   \thinlines
928   \put(-0.08,0.2){\line(0,-1){0.4}}%
929   \put(0.08,0.2){\line(0,-1){0.4}}}
930 \put(1.5,0){\usebox{\eqdist}}
931 \put(10.5,0){\usebox{\eqdist}}
932
933 \color{blue}% shifted
934 \thicklines
935 \put(3,-1.5){\vector(-1,0){4}}
936 \put(1,-1.7){\makebox(0,0)[t]{\texttt{left}}}
937 \put(3,0){\vector(0,-1){1.5}}
938 \put(3.2,-0.75){\makebox(0,0)[l]{\texttt{down}}}
939 \end{picture} 
940 \end{center}
941 \end{minipage}%
942 \begin{minipage}{0.6\textwidth}%
943 Consider a node containing Japanese character whose value of the \texttt{align} 
944 field is \texttt{'middle'}.
945 \begin{itemize}
946 \item The black rectangle is a frame of the node.
947 Its width, height and depth are specified by JFM.
948 \item Since the \texttt{align} field is \texttt{'middle'}, 
949 the `real' glyph is centered horizontally (the green rectangle).
950 \item Furthermore, the glyph is shifted according to values of fields
951       \texttt{left} and \texttt{down}. The ultimate position of the real
952       glyph is indicated by the red rectangle.
953 \end{itemize}
954 \end{minipage}
955 \caption{The position of the `real' glyph.}
956 \label{fig-pos}
957 \end{figure}
958
959
960 \item[kern={\{[$j$]=<kern>, ...\}}]
961
962 \item[glue={\{[$j$]=\{<width>, <stretch>, <shrink>\}, ...\}}]
963 \end{list}
964
965 \subsection{Math Font Family}
966 \TeX\ handles fonts in math formulas by 16~font families\footnote{Omega,
967 Aleph, \LuaTeX~and $\varepsilon$-\kern-.125em(u)\pTeX can handles 256~families, but
968 an external package is needed to support this in plain \TeX\ and
969 \LaTeX.}, and each family has three fonts:
970 \verb+\textfont+, \verb+\scriptfont+ and \verb+\scriptscriptfont+.
971
972 \LuaTeX-ja's handling of Japanese fonts in math formulas is similar;
973 Table~\ref{tab-math} shows counterparts to \TeX's primitives for math
974 font families.
975
976 \begin{table}[tb]
977 \label{tab-math}
978 \caption{Primitives for Japanese math fonts.}
979 \begin{center}\def\{{\char`\{}\def\}{\char`\}}
980 \begin{tabular}{lll}
981 \toprule
982 &Japanese fonts&alphabetic fonts\\
983 \midrule
984 font family&\verb+\jfam+${}\in [0,256)$&\verb+\fam+\\
985 text size&\tt\textsf{jatextfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\verb+\textfont+<fam>=<font\_cs>\\
986 script size&\tt\textsf{jascriptfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\verb+\scriptfont+<fam>=<font\_cs>\\
987 scriptscript size&\tt\textsf{jascriptscriptfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\verb+\scriptscriptfont+<fam>=<font\_cs>\\
988 \bottomrule
989 \end{tabular}
990 \end{center}
991 \end{table}
992
993
994
995 \section{Parameters}
996 \subsection{{\tt\char92 ltjsetparameter} primitive}
997 As noted before, \verb+\ltjsetparameter+ and \verb+\ltjgetparameter+ are
998 primitives for accessing most parameters of \LuaTeX-ja. One of the main
999 reason that \LuaTeX-ja didn't adopted the syntax similar to that of \pTeX\ 
1000 (\textit{e.g.},~\verb+\prebreakpenalty`)=10000+) 
1001 is the position of \verb+hpack_filter+ callback in the source
1002 of \LuaTeX, see Section~\ref{sec-para}.
1003
1004 \verb+\ltjsetparameter+ and \verb+\ltjglobalsetparameter+ are primitives
1005 for assigning parameters. These take one argument which is a
1006 \texttt{<key>=<value>} list. Allowed keys are described in the next
1007 subsection.  
1008 The difference between
1009 \verb+\ltjsetparameter+ and \verb+\ltjglobalsetparameter+ is only the
1010 scope of assignment;
1011 \verb+\ltjsetparameter+ does a local assignment and 
1012 \verb+\ltjglobalsetparameter+ does a global one. 
1013 They also obey the value of \verb+\globaldefs+,
1014 like other assignment.
1015
1016 \verb+\ltjgetparameter+ is the primitive for acquiring parameters. It
1017 always takes a parameter name as first argument, and also takes the
1018 additional argument---a character code, for example---in some cases.
1019 \begin{LTXexample}
1020 \ltjgetparameter{differentjfm}, 
1021 \ltjgetparameter{autospacing},
1022 \ltjgetparameter{prebreakpenalty}{`)}.
1023 \end{LTXexample}
1024 \emph{The return value of\/ {\normalfont\tt\char92ltjgetparameter} is
1025 always a string}. This is outputted by \texttt{tex.write()}, so any
1026 character other than space~`{\tt\char32}'~(U+0020) has the category code
1027 12~(other), while the space has 10~(space).
1028
1029 \subsection{List of Parameters}
1030 In the following list of parameters, [\verb+\cs+] indicates the counterpart in \pTeX, and each symbol has the following meaning:
1031 \begin{itemize}
1032 \item No mark: values at the end of the paragraph or the hbox are
1033       adopted in the whole paragraph/hbox.
1034 \item `\ast' : local parameters, which can change everywhere inside a paragraph/hbox.
1035 \item `\dagger': assignments are always global.
1036 \end{itemize}
1037
1038 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
1039 \item[\textsf{jcharwidowpenalty}\,=<penalty>] [\verb+\jcharwidowpenalty+]
1040
1041 Penalty value for supressing orphans. This penalty is inserted just
1042              after the last \textbf{JAchar} which is not regarded as a
1043              (Japanese) punctuation mark.
1044
1045 \item[\textsf{kcatcode}\,=\{<chr\_code>,<natural number>\}]\
1046
1047 An additional attributes having each character whose character code is <chr\_code>.  
1048 At the present version, the lowermost bit of <natural number> indicates
1049              whether the character is considered as a punctuation mark
1050              (see the description of \textsf{jcharwidowpenalty} above).
1051
1052
1053 \item[\textsf{prebreakpenalty}\,=\{<chr\_code>,<penalty>\}] [\verb+\prebreakpenalty+]
1054 \item[\textsf{postbreakpenalty}\,=\{<chr\_code>,<penalty>\}] [\verb+\postbreakpenalty+]
1055 \item[\textsf{jatextfont}\,=\{<jfam>,<jfont\_cs>\}] [\verb+\textfont+ in \TeX]
1056 \item[\textsf{jascriptfont}\,=\{<jfam>,<jfont\_cs>\}] [\verb+\scriptfont+ in \TeX]
1057 \item[\textsf{jascriptscriptfont}\,=\{<jfam>,<jfont\_cs>\}] [\verb+\scriptscriptfont+ in \TeX]
1058 \item[\textsf{yjabaselineshift}\,=<dimen>$^\ast$]\ 
1059 \item[\textsf{yalbaselineshift}\,=<dimen>$^\ast$] [\verb+\ybaselineshift+]
1060
1061 \item[\textsf{jaxspmode}\,=\{<chr\_code>,<mode>\}] [\verb+\inhibitxspcode+]
1062
1063 Setting whether inserting  \textsf{xkanjiskip} is allowed before/after a \textbf{JAchar} whose character code is <chr\_code>.
1064 The followings are allowed for <mode>:
1065 \begin{description}
1066 \item[0, \texttt{inhibit}] Insertion of \textsf{xkanjiskip} is inhibited before the charater, nor after the charater.
1067 \item[2, \texttt{preonly}] Insertion of \textsf{xkanjiskip} is allowed before the charater, but not after.
1068 \item[1, \texttt{postonly}] Insertion of \textsf{xkanjiskip} is allowed after the charater, but not before.
1069 \item[3, \texttt{allow}] Insertion of \textsf{xkanjiskip} is allowed before the charater and after the charater.
1070 This is the default value.
1071 \end{description}
1072
1073 \item[\textsf{alxspmode}\,=\{<chr\_code>,<mode>\}] [\verb+\xspcode+]
1074
1075 Setting whether inserting  \textsf{xkanjiskip} is allowed before/after a \textbf{ALchar} whose character code is <chr\_code>.
1076 The followings are allowed for <mode>:
1077 \begin{description}
1078 \item[0, \texttt{inhibit}] Insertion of \textsf{xkanjiskip} is inhibited before the charater, nor after the charater.
1079 \item[1, \texttt{preonly}] Insertion of \textsf{xkanjiskip} is allowed before the charater, but not after.
1080 \item[2, \texttt{postonly}] Insertion of \textsf{xkanjiskip} is allowed after the charater, but not before.
1081 \item[3, \texttt{allow}] Insertion of \textsf{xkanjiskip} is allowed before the charater and after the charater.
1082 This is the default value.
1083 \end{description}
1084 Note that parameters \textsf{jaxspmode} and \textsf{alxspmode} use a common table.
1085
1086 \item[\textsf{autospacing}\,=<bool>$^\ast$] [\verb+\autospacing+]
1087 \item[\textsf{autoxspacing}\,=<bool>$^\ast$] [\verb+\autoxspacing+]
1088 \item[\textsf{kanjiskip}\,=<skip>] [\verb+\kanjiskip+]
1089 \item[\textsf{xkanjiskip}\,=<skip>] [\verb+\xkanjiskip+]
1090
1091 \item[\textsf{differentjfm}\,=<mode>$^\dagger$]
1092
1093 Specify how glues/kerns between two \textbf{JAchar}s whose JFM (or size) are different. 
1094 The allowed arguments are the followings:
1095 \begin{description}
1096 \item[\texttt{average}]
1097 \item[\texttt{both}]
1098 \item[\texttt{large}]
1099 \item[\texttt{small}]
1100 \end{description}
1101
1102 \item[\textsf{jacharrange}\,=<ranges>$^\ast$]
1103 \item[\textsf{kansujichar}\,=\{<digit>, <chr\_code>\}] [\verb+\kansujichar+]
1104 \end{list}
1105
1106
1107 \section{Other Primitives}
1108 \subsection{Compatibility with \pTeX}
1109 \begin{list}{}{\def\makelabel{\ttfamily\char92 }}
1110 \item[kuten]
1111 \item[jis]
1112 \item[euc]
1113 \item[sjis]
1114 \item[ucs]
1115 \item[kansuji]
1116 \end{list}
1117 \subsection{{\tt\char92 inhibitglue}}
1118 The primitive \verb+\inhibitglue+ suppresses the insertion of \textbf{JAglue}.
1119 The following is an example, using a special JFM that there will be a glue between 
1120 the beginning of a box and `あ', and also between `あ' and `ウ'.
1121
1122 \begin{LTXexample}
1123 \jfont\g=psft:Ryumin-Light:jfm=test \g
1124 あウあ\inhibitglue{}ウ\inhibitglue\par
1125 あ\par\inhibitglue{}あ
1126 \par\inhibitglue\hrule{}あoff\inhibitglue ice
1127 \end{LTXexample}
1128
1129 With the help of this example, we remark the specification of \verb+\inhibitglue+:
1130 \begin{itemize}
1131 \item The call of \verb+\inhibitglue+ in the (internal) vertical mode is
1132       effective at the beginning of the next paragraph. This is realized
1133       by hacking \verb+\everypar+.
1134 \item The call of \verb+\inhibitglue+ in the (restricted) horizontal
1135       mode is only effective on the spot; does not get over boundary of
1136       paragraphs. Moreover, \verb+\inhibitglue+ cancels ligatures and
1137       kernings, as shown in l.~4 of above example.
1138 \item The call of \verb+\inhibitglue+ in math mode is just ignored.
1139 \end{itemize}
1140
1141 \section{Control Sequences for \LaTeXe}
1142 \subsection{Patch for NFSS2}
1143 As described in Subsection~\ref{ssec-ltx}, \LuaTeX-ja simply adopted
1144 \texttt{plfonts.dtx} in \pLaTeXe\ for the Japanese patch for NFSS2.
1145
1146 \subsection{Cropmark/`tombow'}
1147
1148 \section{Extensions}
1149 \subsection{{\tt luatexja-fontspec.sty}}
1150
1151 \subsection{{\tt luatexja-otf.sty}}
1152 This optional package supports typesetting charaters in
1153 Adobe-Japan1. {\tt luatexja-otf.sty} offers the following 2~low-level
1154 commands:
1155 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
1156 \item[\char92CID\{<number>\}]
1157 Typeset a character whose CID number is <number>.
1158 \item[\char92UTF\{<hex\_number>\}]
1159 Typeset a character whose character code is <hex\_number> (in hexadecimal).
1160 This command is similar to \verb+\char"+<hex\_number>,\ %"
1161 but please remind remarks below.
1162 \end{list}
1163
1164 \paragraph{Remarks}
1165 Characters by \verb+\CID+ and \verb+\UTF+ commands are different from
1166 ordinary characters in the following points:
1167 \begin{itemize}
1168 \item Always treated as \textbf{JAchar}s.
1169 \item Processing codes for supporting OpenType features (\textit{e.g.},
1170       glyph replacement and kerning) by the \texttt{luaotfload} package
1171       is not performed to these characters.
1172 \end{itemize}
1173
1174
1175 \paragraph{Additionally Syntax of JFM}
1176 {\tt luatexja-otf.sty} extends the syntax of JFM; the entries of {\tt
1177 chars} table in JFM now allows a string in the form
1178 \verb+'AJ1-xxx'+, which stands for the character 
1179 whose CID number in Adobe-Japan1 is \verb+xxx+. 
1180
1181 \part{Implementations}\label{part-imp}
1182 \section{Storing Parameters}\label{sec-para}
1183 \subsection{Used Dimensions,  Attributes and whatsit nodes}
1184 Here the following is the list of dimension and attributes which are used in \LuaTeX-ja.
1185 \begin{list}{}{%
1186 \def\makelabel{\ttfamily}
1187 \def\dim#1{\item[\char92 #1\ \textrm{(dimension)}]}
1188 \def\attr#1{\item[\char92 #1\ \textrm{(attribute)}]}
1189 }
1190
1191 \dim{jQ}
1192 As explained in Subsection~\ref{ssec-plain}, \verb+\jQ+ is equal to
1193                         $1\,\textrm{Q}=0.25\,\textrm{mm}$, where `Q'~(also called `級') is
1194                         a unit used in Japanese phototypesetting. So one should not change the value of this dimension. 
1195 \dim{jH}
1196 There is also a unit called `歯' which equals to $0.25\,\textrm{mm}$ and
1197                         used in Japanese phototypesetting. The dimension
1198                         \verb+\jH+ stores this length, similar to \verb+\jQ+. 
1199 \dim{ltj@zw} A temporal register for the `full-width' of current Japanese font.
1200 \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.
1201 \attr{jfam} Current number of Japanese font family for math formulas.
1202 \attr{ltj@curjfnt} The font index of current Japanese font.
1203 \attr{ltj@charclass} The character class of Japanese \textit{glyph\_node}.
1204 \attr{ltj@yablshift} The amount of shifting the baseline of alphabetic
1205                         fonts in scaled point ($2^{-16}\,\textrm{pt}$).
1206 \attr{ltj@ykblshift} The amount of shifting the baseline of Japanese
1207                         fonts in scaled point ($2^{-16}\,\textrm{pt}$).
1208 \attr{ltj@autospc} Whether the auto insertion of \textsf{kanjiskip} is allowed at the node.
1209 \attr{ltj@autoxspc} Whether the auto insertion of \textsf{xkanjiskip} is allowed at the node.
1210 \attr{ltj@icflag} For distinguishing `kinds' of the node. To this
1211                         attribute, one of the following value is
1212                         assigned:
1213 \begin{description}
1214 \item[ITALIC (1)] Glues from an itaric correction
1215            (\verb+\/+). This distinction of origins of glues 
1216            (from explicit \verb+\kern+, or from \verb+\/+)
1217            is needed in the insertion process of \textsf{xkanjiskip}.
1218 \item[PACKED (2)] 
1219 \item[KINSOKU (3)] Penalties inserted for the word-wrapping  process of Japanese characters (\emph{kinsoku}).
1220 \item[FROM\_JFM (4)] Glues/kerns from JFM.
1221 \item[LINE\_END (5)] Kerns for ...
1222 \item[KANJI\_SKIP (6)] Glues for \textsf{kanjiskip}.
1223 \item[XKANJI\_SKIP (7)] Glues for \textsf{xkanjiskip}.
1224 \item[PROCESSED (8)] Nodes which is already processed by ...
1225 \item[IC\_PROCESSED (9)] Glues from an itaric correction, but also already processed.
1226 \item[BOXBDD (15)] Glues/kerns that inserted just the beginning or the ending of an hbox or a paragraph.
1227 \end{description}
1228 \attr{ltj@kcat$i$} Where $i$~is a natural number which is less than~7.
1229 These 7~attributes store bit~vectors indicating which character block is regarded as a block of \textbf{JAchar}s.
1230 \end{list}
1231
1232 Furthermore, \LuaTeX-ja uses several `user-defined' whatsit nodes for
1233 typesetting. All those nodes store a natural number (hence the node's
1234 \texttt{type} is 100).
1235 \begin{description}
1236 \item[30111] Nodes for indicating that \verb+\inhibitglue+ is
1237            specified. The \texttt{value} field of these nodes doesn't matter.
1238 \item[30112] Nodes for \LuaTeX-ja's stack system (see the next
1239            subsection). The \texttt{value} field of these nodes is
1240            current group.
1241 \item[30113] Nodes for Japanese Characters which the callback process of
1242            luaotfload won't be applied, andd the character code is
1243            stored in the \texttt{value} field. Each node having this
1244            \verb+user_id+ is converted to a `glyph\_node' \emph{after}
1245            the callback process of luaotfload.
1246 \end{description}
1247 These whatsits will be removed during the process of inserting \textbf{JAglue}s.
1248
1249 \subsection{Stack System of \LuaTeX-ja}\label{ssec-stack}
1250 \paragraph{Background}
1251 \LuaTeX-ja has its own stack system, and most parameters of \LuaTeX-ja
1252 are stored in it.  To clarify the reason, imagine the parameter
1253 \textsf{kanjiskip} is stored by a skip, and consider the following
1254 source:
1255 \begin{LTXexample}
1256 \ltjsetparameter{kanjiskip=0pt}ふがふが.%
1257 \setbox0=\hbox{\ltjsetparameter{kanjiskip=5pt}ほげほげ}
1258 \box0.ぴよぴよ\par
1259 \end{LTXexample}
1260
1261 As described in Part~\ref{part-ref}, the only effective value of
1262 \textsf{kanjiskip} in an hbox is the latest value, so the value of
1263 \textsf{kanjiskip} which applied in the entire hbox should be 5\,pt.
1264 However, by the implementation method of \LuaTeX, this `5\,pt' cannot be
1265 known from any callbacks.  In the \texttt{tex/packaging.w} (which is a
1266 file in the source of \LuaTeX), there are the following codes:
1267 \begin{lstlisting}
1268 void package(int c)
1269 {
1270     scaled h;                   /* height of box */
1271     halfword p;                 /* first node in a box */
1272     scaled d;                   /* max depth */
1273     int grp;
1274     grp = cur_group;
1275     d = box_max_depth;
1276     unsave();
1277     save_ptr -= 4;
1278     if (cur_list.mode_field == -hmode) {
1279         cur_box = filtered_hpack(cur_list.head_field,
1280                                  cur_list.tail_field, saved_value(1),
1281                                  saved_level(1), grp, saved_level(2));
1282         subtype(cur_box) = HLIST_SUBTYPE_HBOX;
1283 \end{lstlisting}
1284 Notice that \verb+unsave+ is executed \emph{before}
1285 \verb+filtered_hpack+ (this is where \verb+hpack_filter+ callback is
1286 executed): so `5\,pt' in the above source is orphaned at
1287 \texttt+unsave+, and hence it can't be accessed from \verb+hpack_filter+
1288 callback.
1289
1290 \paragraph{The method}
1291 The code of stack system is based on that in a post of Dev-luatex mailing list\footnote{%
1292 \texttt{[Dev-luatex] tex.currentgrouplevel}, a post at 2008/8/19 by Jonathan Sauer.}.
1293
1294 These are two \TeX\ count registers for maintaining informations:
1295 \verb+\ltj@@stack+ for the stack level, and \verb+\ltj@@group@level+ for
1296 the \TeX's group level when the last assignment was done.  Parameters
1297 are stored in one big table named \texttt{charprop\_stack\_table}, where
1298 \texttt{charprop\_stack\_table[$i$]} stores data of stack level~$i$. If
1299 a new stack level is created by \verb+\ltjsetparameter+, all data of the
1300 previous level is copied.
1301
1302 To resolve the problem mentioned in `Background' above, \LuaTeX-ja uses
1303 another thing: When a new stack level is about to be created, a whatsit
1304 node whose type, subtype and value are 44~(\textit{user\_defined}),
1305 30112, and current group level respectively is appended to the current
1306 list (we refer this node by \textit{stack\_flag}). This enables us to
1307 know whether assignment is done just inside a hbox. Suppose that the
1308 stack level is~$s$ and the \TeX's group level is~$t$ just after the hbox
1309 group, then:
1310 \begin{itemize}
1311 \item If there is no \textit{stack\_flag} node in the list of hbox, then
1312       no assignment was occurred inside the hbox. Hence values of
1313       parameters at the end of the hbox are stored in the stack
1314       level~$s$.
1315 \item If there is a \textit{stack\_flag} node whose value is~$t+1$, then
1316       an assignment was occurred just inside the hbox group. Hence
1317       values of parameters at the end of the hbox are stored in the
1318       stack level~$s+1$.
1319 \item If there are \textit{stack\_flag} nodes but all of their values
1320       are more than~$t+1$, then an assignment was occurred in the box,
1321       but it is done is `more internal' group. Hence values of
1322       parameters at the end of the hbox are stored in the stack
1323       level~$s$.
1324 \end{itemize}
1325
1326 Note that to work this trick correctly, assignments to
1327 \verb+\ltj@@stack+ and \verb+\ltj@@group@level+ have to be local always, 
1328 regardless the value of \verb+\globaldefs+.
1329 This problem is resolved by using
1330 \hbox{\verb+\directlua{tex.globaldefs=0}+} (this assignment is local).
1331
1332
1333 \section{Linebreak after Japanese Character}\label{sec-lbreak}
1334 \subsection{Reference: Behavior in \pTeX}
1335 (NOT COMPLETED)
1336
1337 In~\pTeX, a linebreak after a Japanese character doesn't emit a space,
1338 since words are not separated by spaces in Japanese writings. However,
1339 this feature isn't fully implemented in \LuaTeX-ja due to the
1340 specification of callbacks in~\LuaTeX. To clarify the difference between
1341 \pTeX~and~\LuaTeX, We briefly describe the handling of a linebreak in~\pTeX, in
1342 this subsection. 
1343
1344 \pTeX's input processor can be described in terms of a finite state
1345 automaton, as that of~\TeX\ in~Section~2.5 of~\cite{texbytopic}. The
1346 internal states are as follows:
1347 \begin{itemize}
1348 \item State~$N$: new line
1349 \item State~$S$: skipping spaces
1350 \item State~$M$: middle of line
1351 \item State~$K$: after a Japanese character
1352 \end{itemize}
1353 The first three states---$N$, $S$~and~$M$---are as same as \TeX's input
1354 processor.  State~$K$ is similar to state~$M$, and is entered after
1355 Japanese characters.  The diagram of state transitions are indicated in
1356 Figure~\ref{fig-ptexipro}.  Note that \pTeX\ doesn't leave state~$K$
1357 after `beginning/ending of a group' characters.
1358 \begin{figure}[tb]
1359 \label{fig-ptexipro}
1360 \begin{gather*}
1361  \def\sp{\text{\tt\char32}}
1362  \xymatrix{&&
1363    {\text{scan a cs}}\ar@(r,ul)[dr]&\\
1364 \ar[r]&
1365    *++[o][F-]{N}\ar[ur]^0\ar[dd]_{d,\ g}\ar[u]^{5\ (\text{\tt\char92par})}
1366      \ar@{->}@(d,l)[ddrr]_(0.45){j}&&
1367    *++[o][F-]{S}\ar@(l,dr)[ul]^0\ar@(l,ur)[ddll]_{d,\ g}\ar[u]_{5}
1368      \ar@{->}@(r,r)[dd]^{j}\\&\\&
1369    *++[o][F-]{M}\ar[uuur]^0\ar@(r,dl)[uurr]_(0.55){10\ (\sp)}
1370      \ar[d]_{5\ ({\sp})}\ar@{->}@(dr,dl)[rr]_{j}&&
1371    *++[o][F-]{K}\ar@{->}@(ul,d)[uuul]^0\ar@{->}[ll]^{d}
1372      \ar@{->}@(ur,dr)[uu]^{10\ (\sp)}\ar@{->}[d]_5\\
1373    &&&
1374  }\\
1375  d:=\{3,4,6,7,8,11,12,13\},\quad g:=\{1,2\},\quad j:=(\text{Japanese characters})
1376 \end{gather*}
1377 \begin{itemize}
1378 \item Numbers represent category codes.
1379 \item Category codes 9~(ignored), 14~(comment)~and~15~(invalid) are omitted in above diagram.
1380 \end{itemize}
1381 \caption{State transitions of \pTeX's input processor.}
1382 \end{figure}
1383
1384
1385 \subsection{Behavior in \LuaTeX-ja}
1386 States in the input processoe of \LuaTeX\ is the same as that of \TeX,
1387 and they can't be customized by any callbacks. Hence, we can only use
1388 \verb+process_input_buffer+ and \verb+token_filter+ callbacks for to
1389 suppress a space by a linebreak which is after Japanese characters.
1390
1391 However, \verb+token_filter+ callback cannot be used either, since a
1392 character in category code 5~(end-of-line) is converted into an space
1393 token \emph{in the input processor}.  So we can use only the
1394 \verb+process_input_buffer+ callback.  This means that suppressing a
1395 space must be done \emph{just before} an input line is read.
1396
1397 Considering these situations, handling of a end-of-line in \LuaTeX-ja are as follows:
1398 \begin{quote}
1399 A character U+FFFFF (its category code is set to 14~(comment) by
1400 \LuaTeX-ja) is appended to an input line, before \LuaTeX\ actually
1401 process it, if and only if the following two conditions are satisfied:
1402 \begin{enumerate}
1403 \item The category code of the character $\langle${return}$\rangle$
1404       (whose character code is 13) is 5~(end-of-line).
1405 \item The input line matches the following `regular expression':
1406 \[
1407   (\text{any char})^*(\textbf{JAchar})
1408   \bigl(\{\text{catcode}=1\}\cup\{\text{catcode}=2\}\bigr)^*
1409 \]
1410 \end{enumerate}
1411
1412 \end{quote}
1413
1414 \section{Insertion of JFM glues, \textsf{kanjiskip} and \textsf{xkanjiskip}}
1415 This is the longest section of the document.
1416
1417 jfmglue.tex の内容をここに入れる
1418 \end{document}