OSDN Git Service

Fix ticket #26520.
[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 \end{tabular}
550 \end{center}
551 \end{table}
552 \item[Range~4${}^{\text{A}}$] Characters usually not in Japanese fonts. This range consists
553            of almost all Unicode blocks which are not in other
554            predefined ranges. Hence, instead of showing the block list,
555            we put the definition of this range itself:
556 \begin{lstlisting}
557 \ltjdefcharrange{4}{%
558    "500-"10FF, "1200-"1DFF, "2440-"245F, "27C0-"28FF, "2A00-"2AFF, 
559   "2C00-"2E7F, "4DC0-"4DFF, "A4D0-"A82F, "A840-"ABFF, "FB50-"FE0F, 
560   "FE20-"FE2F, "FE70-"FEFF, "FB00-"FB4F, "10000-"1FFFF} % non-Japanese
561 \end{lstlisting}
562 \item[Range~5${}^{\text{A}}$] Surrogates and Supplementary Private Use Areas.
563 \item[Range~6${}^{\text{J}}$] Characters used in Japanese. The block list is indicated in Table~\ref{table-rng6}.
564 \begin{table}[p]
565 \caption{Unicode blocks in predefined character range~6.}\label{table-rng6}
566 \catcode`\"=13\def"#1#2#3#4{{\tt U+#1#2#3#4}}%"
567 \begin{center}
568 \begin{tabular}{ll}
569 "2460--"24FF&Enclosed Alphanumerics\\
570 "2E80--"2EFF&CJK Radicals Supplement\\
571 "3000--"303F&CJK Symbols and Punctuation\\
572 "3040--"309F&Hiragana\\
573 "30A0--"30FF&Katakana\\
574 "3190--"319F&Kanbun\\
575 "31F0--"31FF&Katakana Phonetic Extensions\\
576 "3200--"32FF&Enclosed CJK Letters and Months\\
577 "3300--"33FF&CJK Compatibility\\
578 "3400--"4DBF&CJK Unified Ideographs Extension A\\
579 "4E00--"9FFF&CJK Unified Ideographs\\
580 "F900--"FAFF&CJK Compatibility Ideographs\\
581 "FE10--"FE1F&Vertical Forms\\
582 "FE30--"FE4F&CJK Compatibility Forms\\
583 "FE50--"FE6F&Small Form Variants\\
584 "{20}000--"{2F}FFF&(Supplementary Ideographic Plane)
585 \end{tabular}
586 \end{center}
587 \end{table}
588 \item[Range~7${}^{\text{J}}$] Characters used in CJK languages, but not included in  Adobe-Japan1-6.
589 The block list is indicated in Table~\ref{table-rng7}.
590 \begin{table}[p]
591 \caption{Unicode blocks in predefined character range~7.}\label{table-rng7}
592 \catcode`\"=13\def"#1#2#3#4{{\tt U+#1#2#3#4}}%"
593 \begin{center}
594 \begin{tabular}{ll}
595 "1100--"11FF&Hangul Jamo\\
596 "2F00--"2FDF&Kangxi Radicals\\
597 "2FF0--"2FFF&Ideographic Description Characters\\
598 "3100--"312F&Bopomofo\\
599 "3130--"318F&Hangul Compatibility Jamo\\
600 "31A0--"31BF&Bopomofo Extended\\
601 "31C0--"31EF&CJK Strokes\\
602 "A000--"A48F&Yi Syllables\\
603 "A490--"A4CF&Yi Radicals\\
604 "A830--"A83F&Common Indic Number Forms\\
605 "AC00--"D7AF&Hangul Syllables\\
606 "D7B0--"D7FF&Hangul Jamo Extended-B
607 \end{tabular}
608 \end{center}
609 \end{table}
610 \end{description}
611
612
613 \subsection{\textsf{kanjiskip} and \textsf{xkanjiskip}}\label{subs-kskip}
614 \textbf{JAglue} is divided into the following three categories:
615 \begin{itemize}
616 \item Glues/kerns specified in JFM. If \verb+\inhibitglue+ is issued
617       around a Japanese character, this glue will be not inserted at the
618       place.
619 \item The default glue which inserted between two \textbf{JAchar}s ({\sf
620       kanjiskip}).
621 \item The default glue which inserted between a \textbf{JAchar} and an
622       \textbf{ALchar} (\textsf{xkanjiskip}).
623 \end{itemize}
624 The value (a skip) of \textsf{kanjiskip} or \textsf{xkanjiskip} can be
625 changed as the following.
626 \begin{lstlisting}
627 \ltjsetparameter{kanjiskip={0pt plus 0.4pt minus 0.4pt}, 
628                  xkanjiskip={0.25\zw plus 1pt minus 1pt}}
629 \end{lstlisting}
630
631
632 It may occur that JFM contains the data of `ideal width of {\sf
633 kanjiskip}' and/or `ideal width of \textsf{xkanjiskip}'.
634 To use these data from JFM, set the value of \textsf{kanjiskip} or 
635 \textsf{xkanjiskip} to \verb+\maxdimen+.
636
637 \subsection{Insertion Setting of \textsf{xkanjiskip}}
638 It is not desirable that \textsf{xkanjiskip} is inserted between every
639 boundary between \textbf{JAchar}s and \textbf{ALchar}s. For example,
640 \textsf{xkanjiskip} should not be inserted after opening parenthesis
641 (\textit{e.g.}, compare `(あ' and `(\hskip\ltjgetparameter{xkanjiskip}あ').
642
643 \LuaTeX-ja can control whether \textsf{xkanjiskip} can be inserted
644 before/after a character, by changing \textsf{jaxspmode} for \textbf{JAchar}s and
645 \textsf{alxspmode} parameters \textbf{ALchar}s respectively. 
646 \begin{LTXexample}
647 \ltjsetparameter{jaxspmode={`あ,preonly}, alxspmode={`\!,postonly}} 
648 pあq い!う
649 \end{LTXexample}
650
651 The second argument {\tt preonly} means `the insertion of
652 \textsf{xkanjiskip} is allowed before this character, but not after'.
653 the other possible values are {\tt postonly}, {\tt allow} and {\tt
654 inhibit}. For the compatibility with \pTeX, natural numbers between
655 0~and~3 are also allowed as the second argument\footnote{But we don't
656 recommend this: since numbers 1~and~2 have opposite meanings in
657 \textsf{jaxspmode} and \textsf{alxspmode}.}.
658
659 If you want to enable/disable all insertions of \textsf{kanjiskip} and
660 \textsf{xkanjiskip}, set \textsf{autospacing} and \textsf{autoxspacing}
661 parameters to {\tt false}, respectively.
662
663
664 \subsection{Shifting Baseline}
665 To make a match between a Japanese font and an alphabetic font, sometimes
666 shifting of the baseline of one of the pair is needed. In \pTeX, this is achieved
667 by setting \verb+\ybaselineshift+ to a non-zero length (the
668 baseline of alphabetic fonts is shifted below). However, for documents
669 whose main language is not Japanese, it is good to shift the baseline of
670 Japanese fonts, but not that of alphabetic fonts.
671 Because of this, \LuaTeX-ja can independently set the shifting amount
672 of the baseline of alphabetic fonts (\textsf{yalbaselineshift}
673 parameter) and that of Japanese fonts (\textsf{yjabaselineshift}
674 parameter). 
675
676 \begin{LTXexample}
677 \vrule width 150pt height 0.4pt depth 0pt\hskip-120pt
678 \ltjsetparameter{yjabaselineshift=0pt, yalbaselineshift=0pt}abcあいう
679 \ltjsetparameter{yjabaselineshift=5pt, yalbaselineshift=2pt}abcあいう
680 \end{LTXexample}
681 Here the horizontal line in above is the baseline of a line.
682
683 There is an interesting side-effect: characters in different size can be
684 vertically aligned center in a line, by setting two parameters appropriately.
685 The following is an example (beware the value is not well tuned):
686 \begin{LTXexample}
687 xyz漢字 
688 {\scriptsize
689   \ltjsetparameter{yjabaselineshift=-1pt, 
690     yalbaselineshift=-1pt}
691   XYZひらがな
692 }abcかな
693 \end{LTXexample}
694
695
696 \subsection{Cropmark}
697 Cropmark is a mark for indicating 4~corners and horizontal/vertical
698 center of the paper. In Japanese, we call cropmark as tombo(w).
699 \pLaTeX\ and this \LuaTeX-ja support `tombow' by their kernel.
700 The following steps are needed to typeset cropmark:
701
702 \begin{enumerate}
703 \item First, define the banner which will be printed at the upper left
704       of the paper. This is done by assigning a token list to
705       \verb+\@bannertoken+.
706
707 For example, the following sets banner as `{\tt filename (2012-01-01 17:01)}':
708 \begin{verbatim}
709 \makeatletter
710
711 \hour\time \divide\hour by 60 \@tempcnta\hour \multiply\@tempcnta 60\relax
712 \minute\time \advance\minute-\@tempcnta
713 \@bannertoken{%
714    \jobname\space(\number\year-\two@digits\month-\two@digits\day
715    \space\two@digits\hour:\two@digits\minute)}%
716 \end{verbatim}
717
718 \item ...
719 \end{enumerate}
720
721
722 \part{Reference}\label{part-ref}
723 \section{Font Metric and Japanese Font}
724 \subsection{\texttt{\char92jfont} primitive}
725 To load a font as a Japanese font, you must use the
726 \verb+\jfont+ primitive instead of~\verb+\font+, while
727 \verb+\jfont+ admits the same syntax used in~\verb+\font+. 
728 \LuaTeX-ja automatically loads \texttt{luaotfload} package,
729 so TrueType/OpenType fonts with features can be used for Japanese fonts:
730 \begin{LTXexample}
731 \jfont\tradgt={file:ipaexg.ttf:script=latn;%
732   +trad;-kern;jfm=ujis} at 14pt
733 \tradgt{}当/体/医/区
734 \end{LTXexample}
735
736 Note that the defined control sequence
737 (\verb+\tradgt+ in the example above) using \verb+\jfont+ is not a
738 \textit{font\_def} token, hence the input like \verb+\fontname\tradgt+
739 causes a error.  We denote control sequences which are defined in
740 \verb+\jfont+ by <jfont\_cs>.
741
742 \paragraph{Prefix \texttt{psft}}
743 Besides \texttt{file:}\ and \texttt{name:}\ prefixes, \texttt{psft:}\
744 can be used a prefix in \verb+\jfont+ (and~\verb+\font+) primitive.
745 Using this prefix, you can specify a `name-only' Japanese font which
746 will be not embedded to PDF. Typical use of this prefix is to specify
747 the `standard' Japanese fonts, namely, `Ryumin-Light' and
748 `GothicBBB-Medium'. For kerning or other informations, that of Kozuka
749 Mincho Pr6N Regular (this is a font by Adobe Inc., and included in
750 Japanese Font Packs for Adore Reader) will be used.
751
752
753 \paragraph{JFM}
754 As noted in Introduction, a JFM has measurements of characters and
755 glues/kerns that are automatically inserted for Japanese
756 typesetting. The structure of JFM will be described in the next
757 subsection. At the calling of \verb+\jfont+ primitive, you must specify
758 which JFM will be used for this font by the following keys:
759
760 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
761 \item[jfm=<name>]
762 Specify the name of JFM. A file named \texttt{jfm-<name>.lua} will be searched and/or loaded.
763
764 The followings are JFMs shipped with Lua\TeX-ja:
765 \begin{description}
766 \item[\tt jfm-ujis.lua] A standard JFM in Lua\TeX-ja. This JFM is
767       based on \verb+upnmlminr-h.tfm+, a metric for UTF/OTF package that
768       is used in \upTeX. When you use \texttt{luatexja-otf.sty}, please use this JFM.
769 \item[\tt jfm-jis.lua] A counterpart for \verb+jis.tfm+, `JIS font
770            metric' which is widely used in \pTeX. A major difference of
771            \texttt{jfm-ujis.lua} and this \texttt{jfm-jis.lua} is that
772            most haracters under \texttt{jfm-ujis.lua} are square-shaped,
773            while that under \texttt{jfm-jis.lua} are horizontal
774            rectangles.
775
776 \item[\tt jfm-min.lua] A counterpart for \verb+min10.tfm+, which is one
777            of the default Japanese font metric shipped with \pTeX. There
778            are notable difference between this JFM and other 2~JFMs, as
779            showed below:
780
781 何かいい例.単純に「min10にはバグあり」ではなく,プロポーショナルな側面も見せたいよね
782 (乙部さんのmin10.pdfの例を使う?)
783 \end{description}
784
785 \item[jfmvar=<string>] ...
786 \end{list}
787
788
789 \paragraph{Note: kern feature}\label{para-kern}
790 Some fonts have information for inter-glyph spacing. However, this
791 information is not well-compatible with \LuaTeX-ja.  More concretely,
792 this kerning space from this information are inserted \emph{before} the
793 insertion process of \textbf{JAglue}, and this causes incorrect spacing
794 between two characters when both a glue/kern from the data in the font
795 and it from JFM are present.
796
797 \begin{itemize}
798 \item You should specify {\tt -kern} in
799 {\tt\char92jfont} primitive, when you want to use other font features,
800       such as {\tt script=...}\,.
801 \item If you want to use Japanese fonts in proportinal width, and use
802       information from this font, use \texttt{jfm-prop.lua} for its JFM, and ...
803
804 TODO: kanjiskip?
805 \end{itemize}
806
807
808 \subsection{Structure of JFM file}
809 A JFM file is a Lua script which has only one function call:
810 \begin{verbatim}
811 luatexja.jfont.define_jfm { ... }
812 \end{verbatim}
813 Real data are stored in the table which indicated above by
814 \verb+{ ... }+.  So, the rest of this subsection are devoted to describe the
815 structure of this table.  Note that all lengths in a JFM file are
816 floating-point numbers in design-size unit.
817
818 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
819 \item[dir=<direction>] (required)
820
821 The direction of JFM. At the present, only \texttt{'yoko'} is supported.
822
823 \item[zw=<length>] (required)
824
825 The amount of the length of the `full-width'.
826
827 \item[zh=<length>] (required)
828
829 \item[kanjiskip=\{<natural>, <stretch>, <shrink>\}] (optional)
830
831 This field specifies the `ideal' amount of \textsf{kanjiskip}. As noted
832              in Subsection~\ref{subs-kskip}, if the parameter
833              \textsf{kanjiskip} is \verb+\maxdimen+, the value specified
834              in this field is actually used (if this field is not specified in
835              JFM, it is regarded as 0\,pt). Note that <stretch> and <shrink>
836              fields are in design-size unit too.
837
838
839 \item[xkanjiskip=\{<natural>, <stretch>, <shrink>\}] (optional)
840
841 Like the \texttt{kanjiskip} field, this field specifies the `ideal'
842              amount of \textsf{xkanjiskip}.
843
844 \end{list}
845
846 Besides from above fields, a JFM file have several sub-tables those
847 indices are natural numbers.  The table indexed by~$i\in\omega$ stores
848 informations of `character class'~$i$. At least, the character class~0 is
849 always present, so each JFM file must have a sub-table whose index is
850 \texttt{[0]}.  Each sub-table (its numerical index is denoted by $i$) has
851 the following fields:
852
853 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
854 \item[chars=\{<character>, ...\}] (required except character class~0)
855
856 This field is a list of characters which are in this character
857              type~$i$. This field is not required if $i=0$, since all
858              \textbf{JAchar} which are not in any character class other
859              than 0 (hence, the character class~0 contains most of
860              \textbf{JAchar}s). In the list, a character can be
861              specified by its code number, or by the character itself
862              (as a string of length~1). 
863
864 In addition to those `real' characters, the following `imaginary
865              characters' can be specified in the list:
866
867 \item[width=<length>, height=<length>, depth=<length>, italic=<length>]\ (required)
868
869 Specify width of characters in character class~$i$, height, depth and
870 the amount of italic correction. All characters in character class~$i$ are regarded that its width, height and depth are
871 as values of these fields. 
872 But there is one exception: if \texttt{'prop'} is specified in \texttt{width} field, width of a character becomes that of its `real' glyph 
873
874 \item[left=<length>, down=<length>, align=<align>]\ 
875
876 These fields are for adjusting the position of the `real' glyph. Legal
877              values of \texttt{align} field are \texttt{'left'},
878              \texttt{'middle'} and \texttt{'right'}. If one of these
879              3~fields are omitted, \texttt{left} and \texttt{down} are
880              treated as~0, and \texttt{align} field is treated as
881              \texttt{'left'}.
882 The effects of these 3~fields are indicated in Figure~\ref{fig-pos}.
883
884 In most cases, \texttt{left} and \texttt{down} fields are~0, while
885 it is not uncommon that the \texttt{align} field is \texttt{'middle'} or \texttt{'right'}.
886 For example, setting the \texttt{align} field to \texttt{'right'} is practically needed 
887 when the current character class is the class for opening delimiters'. 
888 \begin{figure}[tb]
889 \begin{minipage}{0.4\textwidth}%
890 \begin{center}\unitlength=10pt\small
891 \begin{picture}(15,12)(-1,-4)
892 \color{black!10!white}% real glyph :step1
893 \put(0,0){\vrule width 12\unitlength height 8\unitlength depth 3\unitlength}
894
895 \color{red!20!white}% real glyph :step1
896 \put(-1,-1.5){\vrule width 6\unitlength height 7\unitlength depth 2.5\unitlength}
897
898 \color{red}% real glyph
899 \thicklines
900 \put(-1,-1.5){\vector(0,1){7}\vector(0,-1){2.5}\vector(1,0){6}}
901 \put(5,-1.5){\line(0,1){7}\line(0,-1){2.5}}
902 \put(-1,5.5){\line(1,0){6}}
903 \put(-1,-4){\line(1,0){6}}
904
905 \color{green!20!white}% real glyph :step1
906 \put(3,0){\vrule width 6\unitlength height 7\unitlength depth 2.5\unitlength}
907
908 \color{black}% real glyph :step1
909 \thicklines
910 \put(0,0){\vector(0,1){8}\line(0,-1){3}\vector(1,0){12}}
911 \put(12,0){\line(0,1){8}\vector(0,-1){3}}
912 \put(0,8){\line(1,0){12}}
913 \put(0,-3){\line(1,0){12}}
914 \put(0.2,4){\makebox(0,0)[l]{\texttt{height}}}
915 \put(12.2,-1.5){\makebox(0,0)[l]{\texttt{depth}}}
916 \put(6,0.2){\makebox(0,0)[b]{\texttt{width}}}
917
918 \color{green!50!black}% real glyph :step1
919 \thicklines
920 \put(3,0){\vector(0,1){7}\vector(0,-1){2.5}\vector(1,0){6}}
921 \put(9,0){\line(0,1){7}\line(0,-1){2.5}}
922 \put(3,7){\line(1,0){6}}
923 \put(3,-2.5){\line(1,0){6}}
924 \newsavebox{\eqdist}
925 \savebox{\eqdist}(0,0)[b]{%
926   \thinlines
927   \put(-0.08,0.2){\line(0,-1){0.4}}%
928   \put(0.08,0.2){\line(0,-1){0.4}}}
929 \put(1.5,0){\usebox{\eqdist}}
930 \put(10.5,0){\usebox{\eqdist}}
931
932 \color{blue}% shifted
933 \thicklines
934 \put(3,-1.5){\vector(-1,0){4}}
935 \put(1,-1.7){\makebox(0,0)[t]{\texttt{left}}}
936 \put(3,0){\vector(0,-1){1.5}}
937 \put(3.2,-0.75){\makebox(0,0)[l]{\texttt{down}}}
938 \end{picture} 
939 \end{center}
940 \end{minipage}%
941 \begin{minipage}{0.6\textwidth}%
942 Consider a node containing Japanese character whose value of the \texttt{align} 
943 field is \texttt{'middle'}.
944 \begin{itemize}
945 \item The black rectangle is a frame of the node.
946 Its width, height and depth are specified by JFM.
947 \item Since the \texttt{align} field is \texttt{'middle'}, 
948 the `real' glyph is centered horizontally (the green rectangle).
949 \item Furthermore, the glyph is shifted according to values of fields
950       \texttt{left} and \texttt{down}. The ultimate position of the real
951       glyph is indicated by the red rectangle.
952 \end{itemize}
953 \end{minipage}
954 \caption{The position of the `real' glyph.}
955 \label{fig-pos}
956 \end{figure}
957
958
959 \item[kern={\{[$j$]=<kern>, ...\}}]
960
961 \item[glue={\{[$j$]=\{<width>, <stretch>, <shrink>\}, ...\}}]
962 \end{list}
963
964 \subsection{Math Font Family}
965 \TeX\ handles fonts in math formulas by 16~font families\footnote{Omega,
966 Aleph, \LuaTeX~and $\varepsilon$-\kern-.125em(u)\pTeX can handles 256~families, but
967 an external package is needed to support this in plain \TeX\ and
968 \LaTeX.}, and each family has three fonts:
969 \verb+\textfont+, \verb+\scriptfont+ and \verb+\scriptscriptfont+.
970
971 \LuaTeX-ja's handling of Japanese fonts in math formulas is similar;
972 Table~\ref{tab-math} shows counterparts to \TeX's primitives for math
973 font families.
974
975 \begin{table}[tb]
976 \label{tab-math}
977 \caption{Primitives for Japanese math fonts.}
978 \begin{center}\def\{{\char`\{}\def\}{\char`\}}
979 \begin{tabular}{lll}
980 \toprule
981 &Japanese fonts&alphabetic fonts\\
982 \midrule
983 font family&\verb+\jfam+${}\in [0,256)$&\verb+\fam+\\
984 text size&\tt\textsf{jatextfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\verb+\textfont+<fam>=<font\_cs>\\
985 script size&\tt\textsf{jascriptfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\verb+\scriptfont+<fam>=<font\_cs>\\
986 scriptscript size&\tt\textsf{jascriptscriptfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\verb+\scriptscriptfont+<fam>=<font\_cs>\\
987 \bottomrule
988 \end{tabular}
989 \end{center}
990 \end{table}
991
992
993
994 \section{Parameters}
995 \subsection{{\tt\char92 ltjsetparameter} primitive}
996 As noted before, \verb+\ltjsetparameter+ and \verb+\ltjgetparameter+ are
997 primitives for accessing most parameters of \LuaTeX-ja. One of the main
998 reason that \LuaTeX-ja didn't adopted the syntax similar to that of \pTeX\ 
999 (\textit{e.g.},~\verb+\prebreakpenalty`)=10000+) 
1000 is the position of \verb+hpack_filter+ callback in the source
1001 of \LuaTeX, see Section~\ref{sec-para}.
1002
1003 \verb+\ltjsetparameter+ and \verb+\ltjglobalsetparameter+ are primitives
1004 for assigning parameters. These take one argument which is a
1005 \texttt{<key>=<value>} list. Allowed keys are described in the next
1006 subsection.  
1007 The difference between
1008 \verb+\ltjsetparameter+ and \verb+\ltjglobalsetparameter+ is only the
1009 scope of assignment;
1010 \verb+\ltjsetparameter+ does a local assignment and 
1011 \verb+\ltjglobalsetparameter+ does a global one. 
1012 They also obey the value of \verb+\globaldefs+,
1013 like other assignment.
1014
1015 \verb+\ltjgetparameter+ is the primitive for acquiring parameters. It
1016 always takes a parameter name as first argument, and also takes the
1017 additional argument---a character code, for example---in some cases.
1018 \begin{LTXexample}
1019 \ltjgetparameter{differentjfm}, 
1020 \ltjgetparameter{autospacing},
1021 \ltjgetparameter{prebreakpenalty}{`)}.
1022 \end{LTXexample}
1023 \emph{The return value of\/ {\normalfont\tt\char92ltjgetparameter} is
1024 always a string}. This is outputted by \texttt{tex.write()}, so any
1025 character other than space~`{\tt\char32}'~(U+0020) has the category code
1026 12~(other), while the space has 10~(space).
1027
1028 \subsection{List of Parameters}
1029 In the following list of parameters, [\verb+\cs+] indicates the counterpart in \pTeX, and each symbol has the following meaning:
1030 \begin{itemize}
1031 \item No mark: values at the end of the paragraph or the hbox are
1032       adopted in the whole paragraph/hbox.
1033 \item `\ast' : local parameters, which can change everywhere inside a paragraph/hbox.
1034 \item `\dagger': assignments are always global.
1035 \end{itemize}
1036
1037 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
1038 \item[\textsf{jcharwidowpenalty}\,=<penalty>] [\verb+\jcharwidowpenalty+]
1039
1040 Penalty value for supressing orphans. This penalty is inserted just
1041              after the last \textbf{JAchar} which is not regarded as a
1042              (Japanese) punctuation mark.
1043
1044 \item[\textsf{kcatcode}\,=\{<chr\_code>,<natural number>\}]\
1045
1046 An additional attributes having each character whose character code is <chr\_code>.  
1047 At the present version, the lowermost bit of <natural number> indicates
1048              whether the character is considered as a punctuation mark
1049              (see the description of \textsf{jcharwidowpenalty} above).
1050
1051
1052 \item[\textsf{prebreakpenalty}\,=\{<chr\_code>,<penalty>\}] [\verb+\prebreakpenalty+]
1053 \item[\textsf{postbreakpenalty}\,=\{<chr\_code>,<penalty>\}] [\verb+\postbreakpenalty+]
1054 \item[\textsf{jatextfont}\,=\{<jfam>,<jfont\_cs>\}] [\verb+\textfont+ in \TeX]
1055 \item[\textsf{jascriptfont}\,=\{<jfam>,<jfont\_cs>\}] [\verb+\scriptfont+ in \TeX]
1056 \item[\textsf{jascriptscriptfont}\,=\{<jfam>,<jfont\_cs>\}] [\verb+\scriptscriptfont+ in \TeX]
1057 \item[\textsf{yjabaselineshift}\,=<dimen>$^\ast$]\ 
1058 \item[\textsf{yalbaselineshift}\,=<dimen>$^\ast$] [\verb+\ybaselineshift+]
1059
1060 \item[\textsf{jaxspmode}\,=\{<chr\_code>,<mode>\}] [\verb+\inhibitxspcode+]
1061
1062 Setting whether inserting  \textsf{xkanjiskip} is allowed before/after a \textbf{JAchar} whose character code is <chr\_code>.
1063 The followings are allowed for <mode>:
1064 \begin{description}
1065 \item[0, \texttt{inhibit}] Insertion of \textsf{xkanjiskip} is inhibited before the charater, nor after the charater.
1066 \item[2, \texttt{preonly}] Insertion of \textsf{xkanjiskip} is allowed before the charater, but not after.
1067 \item[1, \texttt{postonly}] Insertion of \textsf{xkanjiskip} is allowed after the charater, but not before.
1068 \item[3, \texttt{allow}] Insertion of \textsf{xkanjiskip} is allowed before the charater and after the charater.
1069 This is the default value.
1070 \end{description}
1071
1072 \item[\textsf{alxspmode}\,=\{<chr\_code>,<mode>\}] [\verb+\xspcode+]
1073
1074 Setting whether inserting  \textsf{xkanjiskip} is allowed before/after a \textbf{ALchar} whose character code is <chr\_code>.
1075 The followings are allowed for <mode>:
1076 \begin{description}
1077 \item[0, \texttt{inhibit}] Insertion of \textsf{xkanjiskip} is inhibited before the charater, nor after the charater.
1078 \item[1, \texttt{preonly}] Insertion of \textsf{xkanjiskip} is allowed before the charater, but not after.
1079 \item[2, \texttt{postonly}] Insertion of \textsf{xkanjiskip} is allowed after the charater, but not before.
1080 \item[3, \texttt{allow}] Insertion of \textsf{xkanjiskip} is allowed before the charater and after the charater.
1081 This is the default value.
1082 \end{description}
1083 Note that parameters \textsf{jaxspmode} and \textsf{alxspmode} use a common table.
1084
1085 \item[\textsf{autospacing}\,=<bool>$^\ast$] [\verb+\autospacing+]
1086 \item[\textsf{autoxspacing}\,=<bool>$^\ast$] [\verb+\autoxspacing+]
1087 \item[\textsf{kanjiskip}\,=<skip>] [\verb+\kanjiskip+]
1088 \item[\textsf{xkanjiskip}\,=<skip>] [\verb+\xkanjiskip+]
1089
1090 \item[\textsf{differentjfm}\,=<mode>$^\dagger$]
1091
1092 Specify how glues/kerns between two \textbf{JAchar}s whose JFM (or size) are different. 
1093 The allowed arguments are the followings:
1094 \begin{description}
1095 \item[\texttt{average}]
1096 \item[\texttt{both}]
1097 \item[\texttt{large}]
1098 \item[\texttt{small}]
1099 \end{description}
1100
1101 \item[\textsf{jacharrange}\,=<ranges>$^\ast$]
1102 \item[\textsf{kansujichar}\,=\{<digit>, <chr\_code>\}] [\verb+\kansujichar+]
1103 \end{list}
1104
1105
1106 \section{Other Primitives}
1107 \subsection{Compatibility with \pTeX}
1108 \begin{list}{}{\def\makelabel{\ttfamily\char92 }}
1109 \item[kuten]
1110 \item[jis]
1111 \item[euc]
1112 \item[sjis]
1113 \item[ucs]
1114 \item[kansuji]
1115 \end{list}
1116
1117 \section{Control Sequences for \LaTeXe}
1118 \subsection{Patch for NFSS2}
1119 As described in Subsection~\ref{ssec-ltx}, \LuaTeX-ja simply adopted \texttt{plfonts.dtx} in \pLaTeXe\ for the Japanese patch for NFSS2. 
1120
1121 \subsection{Cropmark/`tombow'}
1122
1123 \section{Extensions}
1124 \subsection{{\tt luatexja-fontspec.sty}}
1125
1126 \subsection{{\tt luatexja-otf.sty}}
1127 This optional package supports typesetting charaters in
1128 Adobe-Japan1. {\tt luatexja-otf.sty} offers the following 2~low-level
1129 commands:
1130 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
1131 \item[\char92CID\{<number>\}]
1132 Typeset a character whose CID number is <number>.
1133 \item[\char92UTF\{<hex\_number>\}]
1134 Typeset a character whose character code is <hex\_number> (in hexadecimal).
1135 This command is similar to \verb+\char"+<hex\_number>,\ %"
1136 but please remind remarks below.
1137 \end{list}
1138
1139 \paragraph{Remarks}
1140 Characters by \verb+\CID+ and \verb+\UTF+ commands are different from
1141 ordinary characters in the following points:
1142 \begin{itemize}
1143 \item Always treated as \textbf{JAchar}s.
1144 \item Processing codes for supporting OpenType features (\textit{e.g.},
1145       glyph replacement and kerning) by the \texttt{luaotfload} package
1146       is not performed to these characters.
1147 \end{itemize}
1148
1149
1150 \paragraph{Additionally Syntax of JFM}
1151 {\tt luatexja-otf.sty} extends the syntax of JFM; the entries of {\tt
1152 chars} table in JFM now allows a string in the form
1153 \verb+'AJ1-xxx'+, which stands for the character 
1154 whose CID number in Adobe-Japan1 is \verb+xxx+. 
1155
1156 \part{Implementations}\label{part-imp}
1157 \section{Storing Parameters}\label{sec-para}
1158 \subsection{Used Dimensions,  Attributes and whatsit nodes}
1159 Here the following is the list of dimension and attributes which are used in \LuaTeX-ja.
1160 \begin{list}{}{%
1161 \def\makelabel{\ttfamily}
1162 \def\dim#1{\item[\char92 #1\ \textrm{(dimension)}]}
1163 \def\attr#1{\item[\char92 #1\ \textrm{(attribute)}]}
1164 }
1165
1166 \dim{jQ}
1167 As explained in Subsection~\ref{ssec-plain}, \verb+\jQ+ is equal to
1168                         $1\,\textrm{Q}=0.25\,\textrm{mm}$, where `Q'~(also called `級') is
1169                         a unit used in Japanese phototypesetting. So one should not change the value of this dimension. 
1170 \dim{jH}
1171 There is also a unit called `歯' which equals to $0.25\,\textrm{mm}$ and
1172                         used in Japanese phototypesetting. The dimension
1173                         \verb+\jH+ stores this length, similar to \verb+\jQ+. 
1174 \dim{ltj@zw} A temporal register for the `full-width' of current Japanese font.
1175 \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.
1176 \attr{jfam} Current number of Japanese font family for math formulas.
1177 \attr{ltj@curjfnt} The font index of current Japanese font.
1178 \attr{ltj@charclass} The character class of Japanese \textit{glyph\_node}.
1179 \attr{ltj@yablshift} The amount of shifting the baseline of alphabetic
1180                         fonts in scaled point ($2^{-16}\,\textrm{pt}$).
1181 \attr{ltj@ykblshift} The amount of shifting the baseline of Japanese
1182                         fonts in scaled point ($2^{-16}\,\textrm{pt}$).
1183 \attr{ltj@autospc} Whether the auto insertion of \textsf{kanjiskip} is allowed at the node.
1184 \attr{ltj@autoxspc} Whether the auto insertion of \textsf{xkanjiskip} is allowed at the node.
1185 \attr{ltj@icflag} For distinguishing `kinds' of the node. To this
1186                         attribute, one of the following value is
1187                         assigned:
1188 \begin{description}
1189 \item[ITALIC (1)] Glues from an itaric correction
1190            (\verb+\/+). This distinction of origins of glues 
1191            (from explicit \verb+\kern+, or from \verb+\/+)
1192            is needed in the insertion process of \textsf{xkanjiskip}.
1193 \item[PACKED (2)] 
1194 \item[KINSOKU (3)] Penalties inserted for the word-wrapping  process of Japanese characters (\emph{kinsoku}).
1195 \item[FROM\_JFM (4)] Glues/kerns from JFM.
1196 \item[LINE\_END (5)] Kerns for ...
1197 \item[KANJI\_SKIP (6)] Glues for \textsf{kanjiskip}.
1198 \item[XKANJI\_SKIP (7)] Glues for \textsf{xkanjiskip}.
1199 \item[PROCESSED (8)] Nodes which is already processed by ...
1200 \item[IC\_PROCESSED (9)] Glues from an itaric correction, but also already processed.
1201 \item[BOXBDD (15)] Glues/kerns that inserted just the beginning or the ending of an hbox or a paragraph.
1202 \end{description}
1203 \attr{ltj@kcat$i$} Where $i$~is a natural number which is less than~7.
1204 These 7~attributes store bit~vectors indicating which character block is regarded as a block of \textbf{JAchar}s.
1205 \end{list}
1206
1207 Furthermore, \LuaTeX-ja uses several `user-defined' whatsit nodes for
1208 typesetting. All those nodes store a natural number (hence the node's
1209 \texttt{type} is 100).
1210 \begin{description}
1211 \item[30111] Nodes for indicating that \verb+\inhibitglue+ is
1212            specified. The \texttt{value} field of these nodes is not
1213            used.
1214 \item[30112] Nodes for \LuaTeX-ja's stack system (see the next
1215            subsection). The \texttt{value} field of these nodes is
1216            current group.
1217 \item[30113] Nodes for Japanese Characters which the callback process of
1218            luaotfload won't be applied, andd the character code is
1219            stored in the \texttt{value} field. Each node having this
1220            \verb+user_id+ is converted to a `glyph\_node' \emph{after}
1221            the callback process of luaotfload.
1222 \end{description}
1223
1224 \subsection{Stack System of \LuaTeX-ja}\label{ssec-stack}
1225 \paragraph{Background}
1226 \LuaTeX-ja has its own stack system, and most parameters of \LuaTeX-ja
1227 are stored in it.  To clarify the reason, imagine the parameter
1228 \textsf{kanjiskip} is stored by a skip, and consider the following
1229 source:
1230 \begin{LTXexample}
1231 \ltjsetparameter{kanjiskip=0pt}ふがふが.%
1232 \setbox0=\hbox{\ltjsetparameter{kanjiskip=5pt}ほげほげ}
1233 \box0.ぴよぴよ\par
1234 \end{LTXexample}
1235
1236 As described in Part~\ref{part-ref}, the only effective value of
1237 \textsf{kanjiskip} in an hbox is the latest value, so the value of
1238 \textsf{kanjiskip} which applied in the entire hbox should be 5\,pt.
1239 However, by the implementation method of \LuaTeX, this `5\,pt' cannot be
1240 known from any callbacks.  In the \texttt{tex/packaging.w} (which is a
1241 file in the source of \LuaTeX), there are the following codes:
1242 \begin{lstlisting}
1243 void package(int c)
1244 {
1245     scaled h;                   /* height of box */
1246     halfword p;                 /* first node in a box */
1247     scaled d;                   /* max depth */
1248     int grp;
1249     grp = cur_group;
1250     d = box_max_depth;
1251     unsave();
1252     save_ptr -= 4;
1253     if (cur_list.mode_field == -hmode) {
1254         cur_box = filtered_hpack(cur_list.head_field,
1255                                  cur_list.tail_field, saved_value(1),
1256                                  saved_level(1), grp, saved_level(2));
1257         subtype(cur_box) = HLIST_SUBTYPE_HBOX;
1258 \end{lstlisting}
1259 Notice that \verb+unsave+ is executed \emph{before}
1260 \verb+filtered_hpack+ (this is where \verb+hpack_filter+ callback is
1261 executed): so `5\,pt' in the above source is orphaned at
1262 \texttt+unsave+, and hence it can't be accessed from \verb+hpack_filter+
1263 callback.
1264
1265 \paragraph{The method}
1266 The code of stack system is based on that in a post of Dev-luatex mailing list\footnote{%
1267 \texttt{[Dev-luatex] tex.currentgrouplevel}, a post at 2008/8/19 by Jonathan Sauer.}.
1268
1269 These are two \TeX\ count registers for maintaining informations:
1270 \verb+\ltj@@stack+ for the stack level, and \verb+\ltj@@group@level+ for
1271 the \TeX's group level when the last assignment was done.  Parameters
1272 are stored in one big table named \texttt{charprop\_stack\_table}, where
1273 \texttt{charprop\_stack\_table[$i$]} stores data of stack level~$i$. If
1274 a new stack level is created by \verb+\ltjsetparameter+, all data of the
1275 previous level is copied.
1276
1277 To resolve the problem mentioned in `Background' above, \LuaTeX-ja uses
1278 another thing: When a new stack level is about to be created, a whatsit
1279 node whose type, subtype and value are 44~(\textit{user\_defined}),
1280 30112, and current group level respectively is appended to the current
1281 list (we refer this node by \textit{stack\_flag}). This enables us to
1282 know whether assignment is done just inside a hbox. Suppose that the
1283 stack level is~$s$ and the \TeX's group level is~$t$ just after the hbox
1284 group, then:
1285 \begin{itemize}
1286 \item If there is no \textit{stack\_flag} node in the list of hbox, then
1287       no assignment was occurred inside the hbox. Hence values of
1288       parameters at the end of the hbox are stored in the stack
1289       level~$s$.
1290 \item If there is a \textit{stack\_flag} node whose value is~$t+1$, then
1291       an assignment was occurred just inside the hbox group. Hence
1292       values of parameters at the end of the hbox are stored in the
1293       stack level~$s+1$.
1294 \item If there are \textit{stack\_flag} nodes but all of their values
1295       are more than~$t+1$, then an assignment was occurred in the box,
1296       but it is done is `more internal' group. Hence values of
1297       parameters at the end of the hbox are stored in the stack
1298       level~$s$.
1299 \end{itemize}
1300
1301 Note that to work this trick correctly, assignments to
1302 \verb+\ltj@@stack+ and \verb+\ltj@@group@level+ have to be local always, 
1303 regardless the value of \verb+\globaldefs+.
1304 This problem is resolved by using
1305 \hbox{\verb+\directlua{tex.globaldefs=0}+} (this assignment is local).
1306
1307
1308 \section{Linebreak after Japanese Character}\label{sec-lbreak}
1309 \subsection{Reference: Behavior in \pTeX}
1310 (NOT COMPLETED)
1311
1312 In~\pTeX, a linebreak after a Japanese character doesn't emit a space,
1313 since words are not separated by spaces in Japanese writings. However,
1314 this feature isn't fully implemented in \LuaTeX-ja due to the
1315 specification of callbacks in~\LuaTeX. To clarify the difference between
1316 \pTeX~and~\LuaTeX, We briefly describe the handling of a linebreak in~\pTeX, in
1317 this subsection. 
1318
1319 \pTeX's input processor can be described in terms of a finite state
1320 automaton, as that of~\TeX\ in~Section~2.5 of~\cite{texbytopic}. The
1321 internal states are as follows:
1322 \begin{itemize}
1323 \item State~$N$: new line
1324 \item State~$S$: skipping spaces
1325 \item State~$M$: middle of line
1326 \item State~$K$: after a Japanese character
1327 \end{itemize}
1328 The first three states---$N$, $S$~and~$M$---are as same as \TeX's input
1329 processor.  State~$K$ is similar to state~$M$, and is entered after
1330 Japanese characters.  The diagram of state transitions are indicated in
1331 Figure~\ref{fig-ptexipro}.  Note that \pTeX\ doesn't leave state~$K$
1332 after `beginning/ending of a group' characters.
1333 \begin{figure}[tb]
1334 \label{fig-ptexipro}
1335 \begin{gather*}
1336  \def\sp{\text{\tt\char32}}
1337  \xymatrix{&&
1338    {\text{scan a cs}}\ar@(r,ul)[dr]&\\
1339 \ar[r]&
1340    *++[o][F-]{N}\ar[ur]^0\ar[dd]_{d,\ g}\ar[u]^{5\ (\text{\tt\char92par})}
1341      \ar@{->}@(d,l)[ddrr]_(0.45){j}&&
1342    *++[o][F-]{S}\ar@(l,dr)[ul]^0\ar@(l,ur)[ddll]_{d,\ g}\ar[u]_{5}
1343      \ar@{->}@(r,r)[dd]^{j}\\&\\&
1344    *++[o][F-]{M}\ar[uuur]^0\ar@(r,dl)[uurr]_(0.55){10\ (\sp)}
1345      \ar[d]_{5\ ({\sp})}\ar@{->}@(dr,dl)[rr]_{j}&&
1346    *++[o][F-]{K}\ar@{->}@(ul,d)[uuul]^0\ar@{->}[ll]^{d}
1347      \ar@{->}@(ur,dr)[uu]^{10\ (\sp)}\ar@{->}[d]_5\\
1348    &&&
1349  }\\
1350  d:=\{3,4,6,7,8,11,12,13\},\quad g:=\{1,2\},\quad j:=(\text{Japanese characters})
1351 \end{gather*}
1352 \begin{itemize}
1353 \item Numbers represent category codes.
1354 \item Category codes 9~(ignored), 14~(comment)~and~15~(invalid) are omitted in above diagram.
1355 \end{itemize}
1356 \caption{State transitions of \pTeX's input processor.}
1357 \end{figure}
1358
1359
1360 \subsection{Behavior in \LuaTeX-ja}
1361 States in the input processoe of \LuaTeX\ is the same as that of \TeX,
1362 and they can't be customized by any callbacks. Hence, we can only use
1363 \verb+process_input_buffer+ and \verb+token_filter+ callbacks for to
1364 suppress a space by a linebreak which is after Japanese characters.
1365
1366 However, \verb+token_filter+ callback cannot be used either, since a
1367 character in category code 5~(end-of-line) is converted into an space
1368 token \emph{in the input processor}.  So we can use only the
1369 \verb+process_input_buffer+ callback.  This means that suppressing a
1370 space must be done \emph{just before} an input line is read.
1371
1372 Considering these situations, handling of a end-of-line in \LuaTeX-ja are as follows:
1373 \begin{quote}
1374 A character U+FFFFF (its category code is set to 14~(comment) by
1375 \LuaTeX-ja) is appended to an input line, before \LuaTeX\ actually
1376 process it, if and only if the following two conditions are satisfied:
1377 \begin{enumerate}
1378 \item The category code of the character $\langle${return}$\rangle$
1379       (whose character code is 13) is 5~(end-of-line).
1380 \item The input line matches the following `regular expression':
1381 \[
1382   (\text{any char})^*(\textbf{JAchar})
1383   \bigl(\{\text{catcode}=1\}\cup\{\text{catcode}=2\}\bigr)^*
1384 \]
1385 \end{enumerate}
1386
1387 \end{quote}
1388
1389 \section{Insertion of JFM glues, \textsf{kanjiskip} and \textsf{xkanjiskip}}
1390 This is the longest section of the document.
1391
1392 jfmglue.tex の内容をここに入れる
1393 \end{document}