1 %#! lualatex -shell-escape manual.ins
4 \documentclass[a4paper,titlepage]{article}
5 \usepackage[margin=20mm]{geometry}
8 \documentclass[a4paper,titlepage]{bxjsarticle}
9 \setpagelayout*{margin=20mm}
10 \def\headfont{\normalfont\bfseries}
11 % \def\headfont{\sffamily\gtfamily} is needed in ordinal documents
14 \usepackage{amsmath,amssymb,xcolor,pict2e}
15 \usepackage{booktabs,listings,lltjlisting,showexpl,multicol}
17 \usepackage[unicode=true]{hyperref}
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}
30 \long\def\@makecaption#1#2{%
31 \vskip\abovecaptionskip
32 \sbox\@tempboxa{{\small #1. #2}}%
33 \ifdim \wd\@tempboxa >\hsize
36 \global \@minipagefalse
37 \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
39 \vskip\belowcaptionskip}
43 \title{The \LuaTeX-ja package}
44 \author{The \LuaTeX-ja project team}
47 \title{\LuaTeX-jaパッケージ}
48 \author{\LuaTeX-jaプロジェクトチーム}
52 basicstyle=\ttfamily\small, pos=o, breaklines=true,
53 numbers=none, rframe={}
56 \parskip=\smallskipamount
59 \def<#1>{{\normalfont\rm\itshape$\langle$#1$\rangle$}}
66 {\Large\bf This documentation is far from complete. It may have many
67 grammatical (and contextual) errors.}
70 \textbf{\large 本ドキュメントはまだまだ未完成です.
71 また,英語版と日本語版をdocstripプログラムを用いることで一緒に生成している都合上,
78 \section{Introduction}
81 The \LuaTeX-ja package is a macro package for typesetting high-quality
82 Japanese documents when using \LuaTeX.
85 \LuaTeX-jaパッケージは,次世代標準\TeX である\LuaTeX の上で,\pTeX と同等
86 /それ以上の品質の日本語組版を実現させようとするマクロパッケージである.
89 \subsection{Backgrounds}
90 Traditionally, ASCII \pTeX, an extension of \TeX, and its derivatives
91 are used to typeset Japanese documents in \TeX. \pTeX\ is an engine
92 extension of \TeX: so it can produce high-quality Japanese documents
93 without using very complicated macros. But this point is a mixed
94 blessing: \pTeX\ is left behind from other extensions of \TeX,
95 especially \eTeX\ and pdf\TeX, and from changes about
96 Japanese processing in computers (\textit{e.g.}, the UTF-8 encoding).
98 Recently extensions of \pTeX, namely \upTeX\ (Unicode-implementation
99 of \pTeX) and \epTeX\ (merging of \pTeX\ and
100 \eTeX\ extension), have developed to fill those gaps to some
101 extent, but gaps still exist.
103 However, the appearance of \LuaTeX\ changed the whole situation. With
104 using Lua `callbacks', users can customize the internal processing of
105 \LuaTeX. So there is no need to modify sources of engines to
106 support Japanese typesetting: to do this, we only have to write Lua
107 scripts for appropriate callbacks.
110 \subsection{Major Changes from \pTeX}
111 The \LuaTeX-ja package is under much influence of \pTeX\ engine. The initial
112 target of development was to implement features of \pTeX. However,
113 \emph{\LuaTeX-ja is not a just porting of \pTeX; unnatural
114 specifications/behaviors of \pTeX\ were not adopted}.
116 The followings are major changes from \pTeX:
118 \item A Japanese font is a tuple of a `real' font, a Japanese font
119 metric (\textbf{JFM}, for short), and an optional string called
122 \item In \pTeX, a linebreak after Japanese character is ignored (and
123 doesn't yield a space), since linebreaks (in source files) are
124 permitted almost everywhere in Japanese texts. However, \LuaTeX-ja
125 doesn't have this function completely, because of a specification
127 \item The insertion process of glues/kerns between two Japanese
128 characters and between a Japanese character and other characters
129 (we refer these glues/kerns as \textbf{JAglue}) is rewritten from
133 \item As \LuaTeX's internal character handling is `node-based'
134 (\textit{e.g.}, \verb+of{}fice+ doesn't prevent ligatures), the
135 insertion process of \textbf{JAglue} is now `node-based'.
136 \item Furthermore, nodes between two characters which have no effects in
137 linebreak (\textit{e.g.}, \verb+\special+ node) are ignored in the
139 \item In the process, two Japanese fonts which differ in their `real'
140 fonts only are identified.
142 \item At the present, vertical typesetting (\emph{tategaki}), is not
143 supported in \LuaTeX-ja.
146 For detailed information, see Part~\ref{part-imp}.
148 \subsection{Notations}
149 In this document, the following terms and notations are used:
151 \item Characters are divided into two types:
153 \item \textbf{JAchar}: standing for Japanese characters such as
154 Hiragana, Katakana, Kanji and other punctuation marks for
156 \item \textbf{ALchar}: standing for all other characters like alphabets.
158 We say `alphabetic fonts' for fonts used in \textbf{ALchar}, and `Japanese fonts' for fonts used in \textbf{JAchar}.
160 \item A word in a sans-serif font (like \textsf{prebreakpenalty})
161 represents an internal parameter for Japanese typesetting, and it
162 is used as a key in \verb+\ltjsetparameter+ command.
163 \item The word `primitive' is used not only for primitives in \LuaTeX,
164 but also for control sequences that defined in the core module of
166 \item In this document, natural numbers start from~0.
169 \subsection{About the project}
170 \paragraph{Project Wiki} Project Wiki is under construction.
172 \item \url{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage%28en%29} (English)
173 \item \url{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage} (Japanese)
176 This project is hosted by SourceForge.JP.
179 % \begin{multicols}{2}
181 % \item Hironori KITAGAWA
183 % \item Takayuki YATO
184 % \item Yusuke KUROKI
186 % \item Munehiro YAMAMOTO
187 % \item Tomoaki HONDA
192 % \paragraph{Acknowledgments} -- 挿入するならここ
195 \section{Getting Started}
196 \subsection{Installation}
197 To install the \LuaTeX-ja\ package, you will need:
199 \item \LuaTeX\ (version 0.65.0-beta or later) and its supporting packages.\\
200 If you are using \TeX~Live\ 2011 or current W32\TeX, you don't have to worry.
201 \item The source archive of \LuaTeX-ja, of course{\tt:)}
204 The installation methods are as follows:
206 \item Download the source archive.
208 At the present, \LuaTeX-ja has no official release, so you have to retrieve
209 the archive from the repository.
210 You can retrieve the Git repository via
212 $ git clone git://git.sourceforge.jp/gitroot/luatex-ja/luatexja.git
214 or download the archive of HEAD in \texttt{master} branch from
216 \url{http://git.sourceforge.jp/view?p=luatex-ja/luatexja.git;a=snapshot;h=HEAD;sf=tgz}.
218 \item Extract the archive. You will see {\tt src/} and several other sub-directories.
219 \item Copy all the contents of {\tt src/} into one of your \texttt{TEXMF} tree.
220 \item If {\tt mktexlsr} is needed to update the filename database, make it so.
223 \subsection{Cautions}
225 \item The encoding of your source file must be UTF-8.
226 \item Not well-tested. In particular, the default setting of the range
227 of \textbf{JAchar} in the present version does not coexist with
228 other packages which use Unicode fonts.
231 \subsection{Using in plain \TeX}\label{ssec-plain}
232 To use \LuaTeX-ja in plain \TeX, simply put the following at the beginning of the document:
237 This does minimal settings (like {\tt ptex.tex}) for typesetting Japanese documents:
239 \item The following 6~Japanese fonts are preloaded:
241 \begin{tabular}{ccccc}
243 \textbf{classification}&\textbf{font name}&\textbf{13.5\,Q}&\textbf{9.5\,Q}&\textbf{7\,Q}\\\midrule
244 \emph{mincho}&Ryumin-Light &\verb+\tenmin+&\verb+\sevenmin+&\verb+\fivemin+\\
245 \emph{gothic}&GothicBBB-Medium&\verb+\tengt+ &\verb+\sevengt+ &\verb+\fivegt+\\
250 \item The `Q' is a unit used in Japanese phototypesetting, and
251 $1\,\textrm{Q}=0.25\,\textrm{mm}$. This length is stored in a
252 dimension \verb+\jQ+.
254 \item It is widely accepted that the font `Ryumin-Light' and
255 `GothicBBB-Medium' aren't embedded into PDF files, and PDF reader
256 substitute them by some external Japanese fonts (\textit{e.g.},
257 Kozuka Mincho is used for Ryumin-Light in Adobe Reader). We adopt this custom to
259 \item You may notice that size of above fonts is slightly smaller than
260 their alphabetic counterparts: for example, the size
261 \verb+\texmin+ is $13.5\,\textrm{Q}\simeq 9.60444\,\textrm{pt}$. This is intensional: ...
263 \item A character in Unicode is treated as \textbf{JAchar} if and only
264 if its code-point has more than or equal to U+0100.
265 \item The amount of glue that are inserted between a \textbf{JAchar} and
266 an \textbf{ALchar} (the parameter \textsf{xkanjiskip}) is set to
268 0.25\,\hbox{\verb+\zw+}^{+1\,\text{pt}}_{-1\,\text{pt}} = \frac{27}{32}\,\mathrm{mm}^{+1\,\text{pt}}_{-1\,\text{pt}}.
270 Here \verb+\zw+ is the counterpart of \texttt{em} for Japanese fonts, that is, the length of `full-width' in current Japanese font.
273 \subsection{Using in \LaTeX}\label{ssec-ltx}
275 Using in \LaTeXe\ is basically same. To set up the minimal environment
276 for Japanese, you only have to load {\tt luatexja.sty}:
278 \usepackage{luatexja}
280 It also does minimal settings (counterparts in \pLaTeX\ are {\tt
281 plfonts.dtx} and {\tt pldefs.ltx}):
284 \item {\tt JY3} is the font encoding for Japanese fonts (in horizontal direction).\\
285 When vertical typesetting is supported by \LuaTeX-ja in the future, {\tt JT3} will be used for vertical fonts.
286 \item Two font families {\tt mc} and {\tt gt} are defined:
288 \begin{tabular}{ccccc}
290 \textbf{classification}&\textbf{family}&\verb+\mdseries+&\verb+\bfseries+&\textbf{scale}\\\midrule
291 \emph{mincho}&\tt mc&Ryumin-Light &GothicBBB-Medium&0.960444\\
292 \emph{gothic}&\tt gt&GothicBBB-Medium&GothicBBB-Medium&0.960444\\
296 \textbf{Note on fonts in bold series}
298 \item Japanese characters in math mode are typeset by the font family {\tt mc}.
301 However, above settings are not sufficient for Japanese-based
302 documents. To typeset Japanese-based documents, You are better to use
303 class files other than {\tt article.cls}, {\tt book.cls}, \ldots. At the
304 present, BXjscls (\texttt{bxjsarticle.cls} and \texttt{bxjsbook.cls}, by
305 Takayuki Yato) are better alternative. It is not determined whether
306 \LuaTeX-ja will develop and contain counterparts of major classes used
307 in \pTeX\ (including jsclasses by Haruhiko Okumura).
309 \subsection{Changing Fonts}
310 \paragraph{Remark: Japanese Characters in Math Mode}
311 Since \pTeX\ supports Japanese characters in math mode, there are
312 sources like the following:
315 $f_{高温}$~($f_{\text{high temperature}}$).
316 \[ y=(x-1)^2+2\quad{}よって\quad y>0 \]
317 $5\in{}素:=\{\,p\in\mathbb N:\text{$p$ is a prime}\,\}$.
320 We (the project members of \LuaTeX-ja) think that using
321 Japanese characters in math mode are allowed if and only if these are used as identifiers.
322 In this point of view,
324 \item The lines 1~and~2 above are not correct, since `高温' in above is used as a textual label, and
325 `よって' is used as a conjunction.
326 \item However, the line~3 is correct, since `素' is used as an identifier.
328 Hence, in our opinion, the above input should be corrected as:
331 ($f_{\text{high temperature}}$).
333 \mathrel{\text{よって}}\quad y>0 \]
334 $5\in{}素:=\{\,p\in\mathbb N:\text{$p$ is a prime}\,\}$.
336 %BUG?: \{\}がなければ「素」がでない.上の段落の「よって」もでてない.
337 We also believe that using Japanese characters as identifiers is rare,
338 hence we don't describe how to change Japanese fonts in math mode in
339 this chapter. For the method, please see Part~\ref{part-ref}.
342 \paragraph{plain \TeX}
343 To change Japanese fonts in plain \TeX, you must use the primitive
344 \verb+\jfont+. So please see Part~\ref{part-ref}.
348 For \LaTeXe, \LuaTeX-ja simply adopted the font selection system from that
349 of \pLaTeXe\ (in {\tt plfonts.dtx}).
351 \item Two control sequences \verb+\mcdefault+ and \verb+\gtdefault+ are
352 used to specify the default font families for \emph{mincho} and
353 \emph{gothic}, respectively. Default values: \texttt{mc} for
354 \verb+\mcdefault+ and \texttt{gt} for \verb+\gtdefault+.
355 \item Commands \verb+\fontfamily+, \verb+\fontseries+,
356 \verb+\fontshape+ and \verb+\selectfont+ can be used to change
357 attributes of Japanese fonts.
359 \begin{tabular}{ccccc}
361 &\textbf{encoding}&\textbf{family}&\textbf{series}&\textbf{shape}\\\midrule
363 &\verb+\romanencoding+&\verb+\romanfamily+&\verb+\romanseries+&\verb+\romanshape+\\
365 &\verb+\kanjiencoding+&\verb+\kanjifamily+&\verb+\kanjiseries+&\verb+\kanjishape+\\
366 both&---&--&\verb+\fontseries+&\verb+\fontshape+\\
367 auto select&\verb+\fontencoding+&\verb+\fontfamily+&---&---\\
371 \item For defining a Japanese font family, use \verb+\DeclareKanjiFamily+
372 instead of \verb+\DeclareFontFamily+.
376 To coexist with \texttt{fontspec} package, it is needed to load
377 \texttt{luatexja-fontspec} package in the preamble. This additional
378 package automatically loads \texttt{luatexja} and \texttt{fontspec}
381 In \texttt{luatexja-fontspec} package, the following 7~commands are defined as
382 counterparts of original commands in \texttt{fontspec}:
384 \begin{tabular}{ccccc}
387 &\verb+\jfontspec+&\verb+\setmainjfont+&\verb+\setsansjfont+&\verb+\newjfontfamily+\\
389 &\verb+\fontspec+&\verb+\setmainfont+&\verb+\setsansfont+&\verb+\newfontfamily+\\
392 &\verb+\newjfontface+&\verb+\defaultjfontfeatures+&\verb+\addjfontfeatures+\\
394 &\verb+\newfontface+&\verb+\defaultfontfeatures+&\verb+\addfontfeatures+\\
401 Note that there is no command named \verb+\setmonojfont+, since it is
402 popular for Japanese fonts that nearly all Japanese glyphs have same widths.
405 \section{Changing Parameters}
406 There are many parameters in \LuaTeX-ja. And due to the behavior of \LuaTeX,
407 most of them are not stored as internal register of \TeX, but as an
408 original storage system in \LuaTeX-ja. Hence, to assign or acquire those
409 parameters, you have to use commands \verb+\ltjsetparameter+ and
410 \verb+\ltjgetparameter+.
412 \subsection{Editing the range of \textbf{JAchar}s}
413 As noted before, the default setting is:
415 A character in Unicode is treated as \textbf{JAchar},\\
417 code-point has more than or equal to U+0100.
419 $\uparrow$ TODO: CHANGE THIS!
422 To edit the range of \textbf{JAchar}s, You have to assign a non-zero
423 natural number which is less than 217 to the character range first. This
424 can be done by using \verb+\ltjdefcharrange+ primitive. For example, the
425 next line assigns whole characters in Supplementary Multilingual Plane
426 and the character `漢' to the range number~4.
428 \ltjdefcharrange{4}{"10000-"1FFFF,`漢}
430 This assignment of numbers to ranges are always global, so you should
431 not do this in the middle of a document. 上書き
433 After assigning numbers to ranges, ...
435 \subsection{\textsf{kanjiskip} and \textsf{xkanjiskip}}\label{subs-kskip}
436 \textbf{JAglue} is divided into the following three categories:
438 \item Glues/kerns specified in JFM. If \verb+\inhibitglue+ is issued around a Japanese character,
439 this glue will be not inserted at the place.
440 \item The default glue which inserted between two \textbf{JAchar}s ({\sf
442 \item The default glue which inserted between a \textbf{JAchar} and an
443 \textbf{ALchar} (\textsf{xkanjiskip}).
445 The value (a skip) of \textsf{kanjiskip} or \textsf{xkanjiskip} can be
446 changed as the following.
448 \ltjsetparameter{kanjiskip={0pt plus 0.4pt minus 0.4pt},
449 xkanjiskip={0.25\zw plus 1pt minus 1pt}}
453 It may occur that JFM contains the data of `ideal width of {\sf
454 kanjiskip}' and/or `ideal width of \textsf{xkanjiskip}'.
455 To use these data from JFM, set the value of \textsf{kanjiskip} or
456 \textsf{xkanjiskip} to \verb+\maxdimen+.
458 \subsection{Insertion Setting of \textsf{xkanjiskip}}
459 It is not desirable that \textsf{xkanjiskip} is inserted between every
460 boundary between \textbf{JAchar}s and \textbf{ALchar}s. For example,
461 \textsf{xkanjiskip} should not be inserted after opening parenthesis
462 (\textit{e.g.}, compare `(あ' and `(\hskip\ltjgetparameter{xkanjiskip}あ').
464 \LuaTeX-ja can control whether \textsf{xkanjiskip} can be inserted
465 before/after a character, by changing \textsf{jaxspmode} for \textbf{JAchar}s and
466 \textsf{alxspmode} parameters \textbf{ALchar}s respectively.
468 \ltjsetparameter{jaxspmode={`あ,preonly}, alxspmode={`\!,postonly}}
472 The second argument {\tt preonly} means `the insertion of
473 \textsf{xkanjiskip} is allowed before this character, but not after'.
474 the other possible values are {\tt postonly}, {\tt allow} and {\tt
475 inhibit}. For the compatibility with \pTeX, natural numbers between
476 0~and~3 are also allowed as the second argument\footnote{But we don't
477 recommend this: since numbers 1~and~2 have opposite meanings in
478 \textsf{jaxspmode} and \textsf{alxspmode}.}.
480 If you want to enable/disable all insertions of \textsf{kanjiskip} and
481 \textsf{xkanjiskip}, set \textsf{autospacing} and \textsf{autoxspacing}
482 parameters to {\tt false}, respectively.
485 \subsection{Shifting Baseline}
486 To make a match between a Japanese font and an alphabetic font, sometimes
487 shifting of the baseline of one of the pair is needed. In \pTeX, this is achieved
488 by setting \verb+\ybaselineshift+ to a non-zero length (the
489 baseline of alphabetic fonts is shifted below). However, for documents
490 whose main language is not Japanese, it is good to shift the baseline of
491 Japanese fonts, but not that of alphabetic fonts.
492 Because of this, \LuaTeX-ja can independently set the shifting amount
493 of the baseline of alphabetic fonts (\textsf{yalbaselineshift}
494 parameter) and that of Japanese fonts (\textsf{yjabaselineshift}
498 \vrule width 150pt height 0.4pt depth 0pt\hskip-120pt
499 \ltjsetparameter{yjabaselineshift=0pt, yalbaselineshift=0pt}abcあいう
500 \ltjsetparameter{yjabaselineshift=5pt, yalbaselineshift=2pt}abcあいう
502 Here the horizontal line in above is the baseline of a line.
504 There is an interesting side-effect: characters in different size can be
505 vertically aligned center in a line, by setting two parameters appropriately.
506 The following is an example (beware the value is not well tuned):
510 \ltjsetparameter{yjabaselineshift=-1pt,
511 yalbaselineshift=-1pt}
517 \subsection{Cropmark}
518 Cropmark is a mark for indicating 4~corners and horizontal/vertical
519 center of the paper. In Japanese, we call cropmark as tombo(w).
520 \pLaTeX\ and this \LuaTeX-ja support `tombow' by their kernel.
521 The following steps are needed to typeset cropmark:
524 \item First, define the banner which will be printed at the upper left
525 of the paper. This is done by assigning a token list to
526 \verb+\@bannertoken+.
528 For example, the following sets banner as `{\tt filename (2012-01-01 17:01)}':
532 \hour\time \divide\hour by 60 \@tempcnta\hour \multiply\@tempcnta 60\relax
533 \minute\time \advance\minute-\@tempcnta
535 \jobname\space(\number\year-\two@digits\month-\two@digits\day
536 \space\two@digits\hour:\two@digits\minute)}%
543 \part{Reference}\label{part-ref}
544 \section{Font Metric and Japanese Font}
545 \subsection{\texttt{\char92jfont} primitive}
546 To load a font as a Japanese font, you must use the
547 \verb+\jfont+ primitive instead of~\verb+\font+, while
548 \verb+\jfont+ admits the same syntax used in~\verb+\font+.
549 \LuaTeX-ja automatically loads \texttt{luaotfload} package,
550 so TrueType/OpenType fonts with features can be used for Japanese fonts:
552 \jfont\tradgt={file:ipaexg.ttf:script=latn;%
553 +trad;jfm=ujis} at 14pt
557 Note that the defined control sequence
558 (\verb+\tradgt+ in the example above) using \verb+\jfont+ is not a
559 \textit{font\_def} token, hence the input like
560 \verb+\fontname\tradgt+ causes a error. We denote control sequences which are defined in \verb+\jfont+
564 Besides \texttt{file:}\ and \texttt{name:}\ prefixes, \texttt{psft:}\ can
565 be used a prefix in \verb+\jfont+ (and~\verb+\font+) primitive. Using
566 this prefix, you can specify a font that has its name only and is not
567 related to any real font.
569 Mainly, use of this \texttt{psft:}\ prefix is for using non-embedding `standard' Japanese fonts (Ryumin-Light and GothicBBB-Medium).
577 \subsection{Structure of JFM file}
578 A JFM file is a Lua script which has only one function call:
580 luatexja.jfont.define_jfm { ... }
582 Real data are stored in the table which indicated above by
583 \verb+{ ... }+. So, the rest of this subsection are devoted to describe the
584 structure of this table. Note that all lengths in a JFM file are
585 floating-point numbers in design-size unit.
587 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
588 \item[dir=<direction>] (required)
590 The direction of JFM. At the present, only \texttt{'yoko'} is supported.
592 \item[zw=<length>] (required)
594 The amount of the length of the `full-width'.
596 \item[zh=<length>] (required)
598 \item[kanjiskip=\{<natural>, <stretch>, <shrink>\}] (optional)
600 This field specifies the `ideal' amount of \textsf{kanjiskip}. As noted
601 in Subsection~\ref{subs-kskip}, if the parameter
602 \textsf{kanjiskip} is \verb+\maxdimen+, the value specified
603 in this field is actually used (if this field is not specified in
604 JFM, it is regarded as 0\,pt). Note that <stretch> and <shrink>
605 fields are in design-size unit too.
608 \item[xkanjiskip=\{<natural>, <stretch>, <shrink>\}] (optional)
610 Like the \texttt{kanjiskip} field, this field specifies the `ideal'
611 amount of \textsf{xkanjiskip}.
615 Besides from above fields, a JFM file have several sub-tables those
616 indices are natural numbers. The table indexed by~$i\in\omega$ stores
617 informations of `character class'~$i$. At least, the character class~0 is
618 always present, so each JFM file must have a sub-table whose index is
619 \texttt{[0]}. Each sub-table (its numerical index is denoted by $i$) has
620 the following fields:
622 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
623 \item[chars=\{<character>, ...\}] (required except character class~0)
625 This field is a list of characters which are in this character
626 type~$i$. This field is not required if $i=0$, since all
627 \textbf{JAchar} which are not in any character class other
628 than 0 (hence, the character class~0 contains most of
629 \textbf{JAchar}s). In the list, a character can be
630 specified by its code number, or by the character itself
631 (as a string of length~1).
633 In addition to those `real' characters, the following `imaginary
634 characters' can be specified in the list:
636 \item[width=<length>, height=<length>, depth=<length>, italic=<length>]\ (required)
638 Specify width of characters in character class~$i$, height, depth and
639 the amount of italic correction. All characters in character class~$i$ are regarded that its width, height and depth are
640 as values of these fields.
641 But there is one exception: if \texttt{'prop'} is specified in \texttt{width} field, width of a character becomes that of its `real' glyph
643 \item[left=<length>, down=<length>, align=<align>]\
645 These fields are for adjusting the position of the `real' glyph. Legal
646 values of \texttt{align} field are \texttt{'left'},
647 \texttt{'middle'} and \texttt{'right'}. If one of these
648 3~fields are omitted, \texttt{left} and \texttt{down} are
649 treated as~0, and \texttt{align} field is treated as
651 The effects of these 3~fields are indicated in Figure~\ref{fig-pos}.
653 In most cases, \texttt{left} and \texttt{down} fields are~0, while
654 it is not uncommon that the \texttt{align} field is \texttt{'middle'} or \texttt{'right'}.
655 For example, setting the \texttt{align} field to \texttt{'right'} is practically needed
656 when the current character class is the class for opening delimiters'.
658 \begin{minipage}{0.4\textwidth}%
659 \begin{center}\unitlength=10pt\small
660 \begin{picture}(15,12)(-1,-4)
661 \color{black!10!white}% real glyph :step1
662 \put(0,0){\vrule width 12\unitlength height 8\unitlength depth 3\unitlength}
664 \color{red!20!white}% real glyph :step1
665 \put(-1,-1.5){\vrule width 6\unitlength height 7\unitlength depth 2.5\unitlength}
667 \color{red}% real glyph
669 \put(-1,-1.5){\vector(0,1){7}\vector(0,-1){2.5}\vector(1,0){6}}
670 \put(5,-1.5){\line(0,1){7}\line(0,-1){2.5}}
671 \put(-1,5.5){\line(1,0){6}}
672 \put(-1,-4){\line(1,0){6}}
674 \color{green!20!white}% real glyph :step1
675 \put(3,0){\vrule width 6\unitlength height 7\unitlength depth 2.5\unitlength}
677 \color{black}% real glyph :step1
679 \put(0,0){\vector(0,1){8}\line(0,-1){3}\vector(1,0){12}}
680 \put(12,0){\line(0,1){8}\vector(0,-1){3}}
681 \put(0,8){\line(1,0){12}}
682 \put(0,-3){\line(1,0){12}}
683 \put(0.2,4){\makebox(0,0)[l]{\texttt{height}}}
684 \put(12.2,-1.5){\makebox(0,0)[l]{\texttt{depth}}}
685 \put(6,0.2){\makebox(0,0)[b]{\texttt{width}}}
687 \color{green!50!black}% real glyph :step1
689 \put(3,0){\vector(0,1){7}\vector(0,-1){2.5}\vector(1,0){6}}
690 \put(9,0){\line(0,1){7}\line(0,-1){2.5}}
691 \put(3,7){\line(1,0){6}}
692 \put(3,-2.5){\line(1,0){6}}
694 \savebox{\eqdist}(0,0)[b]{%
696 \put(-0.08,0.2){\line(0,-1){0.4}}%
697 \put(0.08,0.2){\line(0,-1){0.4}}}
698 \put(1.5,0){\usebox{\eqdist}}
699 \put(10.5,0){\usebox{\eqdist}}
701 \color{blue}% shifted
703 \put(3,-1.5){\vector(-1,0){4}}
704 \put(1,-1.7){\makebox(0,0)[t]{\texttt{left}}}
705 \put(3,0){\vector(0,-1){1.5}}
706 \put(3.2,-0.75){\makebox(0,0)[l]{\texttt{down}}}
710 \begin{minipage}{0.6\textwidth}%
711 Consider a node containing Japanese character whose value of the \texttt{align}
712 field is \texttt{'middle'}.
714 \item The black rectangle is a frame of the node.
715 Its width, height and depth are specified by JFM.
716 \item Since the \texttt{align} field is \texttt{'middle'},
717 the `real' glyph is centered horizontally (the green rectangle).
718 \item Furthermore, the glyph is shifted according to values of fields
719 \texttt{left} and \texttt{down}. The ultimate position of the real
720 glyph is indicated by the red rectangle.
723 \caption{The position of the `real' glyph.}
728 \item[kern={\{[$j$]=<kern>, ...\}}]
730 \item[glue={\{[$j$]=\{<width>, <stretch>, <shrink>\}, ...\}}]
733 \subsection{Math Font Family}
734 \TeX\ handles fonts in math formulas by 16~font families\footnote{Omega,
735 Aleph, \LuaTeX~and $\varepsilon$-\kern-.125em(u)\pTeX can handles 256~families, but
736 an external package is needed to support this in plain \TeX\ and
737 \LaTeX.}, and each family has three fonts:
738 \verb+\textfont+, \verb+\scriptfont+ and \verb+\scriptscriptfont+.
740 \LuaTeX-ja's handling of Japanese fonts in math formulas is similar;
741 Table~\ref{tab-math} shows counterparts to \TeX's primitives for math
746 \caption{Primitives for Japanese math fonts.}
747 \begin{center}\def\{{\char`\{}\def\}{\char`\}}
750 &Japanese fonts&alphabetic fonts\\
752 font family&\verb+\jfam+${}\in [0,256)$&\verb+\fam+\\
753 text size&\tt\textsf{jatextfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\verb+\textfont+<fam>=<font\_cs>\\
754 script size&\tt\textsf{jascriptfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\verb+\scriptfont+<fam>=<font\_cs>\\
755 scriptscript size&\tt\textsf{jascriptscriptfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\verb+\scriptscriptfont+<fam>=<font\_cs>\\
763 \subsection{{\tt\char92 ltjsetparameter} primitive}
764 As noted before, \verb+\ltjsetparameter+ and \verb+\ltjgetparameter+ are
765 primitives for accessing most parameters of \LuaTeX-ja. One of the main
766 reason that \LuaTeX-ja didn't adopted the syntax similar to that of \pTeX\
767 (\textit{e.g.},~\verb+\prebreakpenalty`)=10000+)
768 is the position of \verb+hpack_filter+ callback in the source
769 of \LuaTeX, see Section~\ref{sec-para}.
771 \verb+\ltjsetparameter+ and \verb+\ltjglobalsetparameter+ are primitives
772 for assigning parameters. These take one argument which is a
773 \texttt{<key>=<value>} list. Allowed keys are described in the next
775 The difference between
776 \verb+\ltjsetparameter+ and \verb+\ltjglobalsetparameter+ is only the
778 \verb+\ltjsetparameter+ does a local assignment and
779 \verb+\ltjglobalsetparameter+ does a global one.
780 They also obey the value of \verb+\globaldefs+,
781 like other assignment.
783 \verb+\ltjgetparameter+ is the primitive for acquiring parameters. It
784 always takes a parameter name as first argument, and also takes the
785 additional argument---a character code, for example---in some cases.
787 \ltjgetparameter{differentjfm},
788 \ltjgetparameter{autospacing},
789 \ltjgetparameter{prebreakpenalty}{`)}.
791 \emph{The return value of\/ {\normalfont\tt\char92ltjgetparameter} is
792 always a string}. This is outputted by \texttt{tex.write()}, so any
793 character other than space~`{\tt\char32}'~(U+0020) has the category code
794 12~(other), while the space has 10~(space).
796 \subsection{List of Parameters}
797 In the following list of parameters, [\verb+\cs+] indicates the counterpart in \pTeX, and each symbol has the following meaning:
799 \item No mark: values at the end of the paragraph or the hbox are
800 adopted in the whole paragraph/hbox.
801 \item `\ast' : local parameters, which can change everywhere inside a paragraph/hbox.
802 \item `\dagger': assignments are always global.
805 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
806 \item[\textsf{jcharwidowpenalty}\,=<penalty>] [\verb+\jcharwidowpenalty+]
808 Penalty value for supressing orphans. This penalty is inserted just
809 after the last \textbf{JAchar} which is not regarded as a
810 (Japanese) punctuation mark.
812 \item[\textsf{kcatcode}\,=\{<chr\_code>,<natural number>\}]\
814 An additional attributes having each character whose character code is <chr\_code>.
815 At the present version, the lowermost bit of <natural number> indicates
816 whether the character is considered as a punctuation mark
817 (see the description of \textsf{jcharwidowpenalty} above).
820 \item[\textsf{prebreakpenalty}\,=\{<chr\_code>,<penalty>\}] [\verb+\prebreakpenalty+]
821 \item[\textsf{postbreakpenalty}\,=\{<chr\_code>,<penalty>\}] [\verb+\postbreakpenalty+]
822 \item[\textsf{jatextfont}\,=\{<jfam>,<jfont\_cs>\}] [\verb+\textfont+ in \TeX]
823 \item[\textsf{jascriptfont}\,=\{<jfam>,<jfont\_cs>\}] [\verb+\scriptfont+ in \TeX]
824 \item[\textsf{jascriptscriptfont}\,=\{<jfam>,<jfont\_cs>\}] [\verb+\scriptscriptfont+ in \TeX]
825 \item[\textsf{yjabaselineshift}\,=<dimen>$^\ast$]\
826 \item[\textsf{yalbaselineshift}\,=<dimen>$^\ast$] [\verb+\ybaselineshift+]
828 \item[\textsf{jaxspmode}\,=\{<chr\_code>,<mode>\}] [\verb+\inhibitxspcode+]
830 Setting whether inserting \textsf{xkanjiskip} is allowed before/after a \textbf{JAchar} whose character code is <chr\_code>.
831 The followings are allowed for <mode>:
833 \item[0, \texttt{inhibit}] Insertion of \textsf{xkanjiskip} is inhibited before the charater, nor after the charater.
834 \item[2, \texttt{preonly}] Insertion of \textsf{xkanjiskip} is allowed before the charater, but not after.
835 \item[1, \texttt{postonly}] Insertion of \textsf{xkanjiskip} is allowed after the charater, but not before.
836 \item[3, \texttt{allow}] Insertion of \textsf{xkanjiskip} is allowed before the charater and after the charater.
837 This is the default value.
840 \item[\textsf{alxspmode}\,=\{<chr\_code>,<mode>\}] [\verb+\xspcode+]
842 Setting whether inserting \textsf{xkanjiskip} is allowed before/after a \textbf{ALchar} whose character code is <chr\_code>.
843 The followings are allowed for <mode>:
845 \item[0, \texttt{inhibit}] Insertion of \textsf{xkanjiskip} is inhibited before the charater, nor after the charater.
846 \item[1 \texttt{preonly}] Insertion of \textsf{xkanjiskip} is allowed before the charater, but not after.
847 \item[2 \texttt{postonly}] Insertion of \textsf{xkanjiskip} is allowed after the charater, but not before.
848 \item[3, \texttt{allow}] Insertion of \textsf{xkanjiskip} is allowed before the charater and after the charater.
849 This is the default value.
851 Note that parameters \textsf{jaxspmode} and \textsf{alxspmode} use a common table.
853 \item[\textsf{autospacing}\,=<bool>$^\ast$] [\verb+\autospacing+]
854 \item[\textsf{autoxspacing}\,=<bool>$^\ast$] [\verb+\autoxspacing+]
855 \item[\textsf{kanjiskip}\,=<skip>] [\verb+\kanjiskip+]
856 \item[\textsf{xkanjiskip}\,=<skip>] [\verb+\xkanjiskip+]
858 \item[\textsf{differentjfm}\,=<mode>$^\dagger$]
860 Specify how glues/kerns between two \textbf{JAchar}s whose JFM (or size) are different.
861 The allowed arguments are the followings:
863 \item[\texttt{average}]
865 \item[\texttt{large}]
866 \item[\texttt{small}]
869 \item[\textsf{jacharrange}\,=<ranges>$^\ast$]
870 \item[\textsf{kansujichar}\,=\{<digit>, <chr\_code>\}] [\verb+\kansujichar+]
874 \section{Other Primitives}
875 \subsection{Compatibility with \pTeX}
876 \begin{list}{}{\def\makelabel{\ttfamily\char92 }}
885 \section{Control Sequences for \LaTeXe}
886 \subsection{Patch for NFSS2}
887 As described in Subsection~\ref{ssec-ltx}, \LuaTeX-ja simply adopted \texttt{plfonts.dtx} in \pLaTeXe\ for the Japanese patch for NFSS2.
889 \subsection{Cropmark/`tombow'}
891 \part{Implementations}\label{part-imp}
892 \section{Storing Parameters}\label{sec-para}
893 \subsection{Used Dimensions and Attributes}
894 Here the following is the list of dimension and attributes which are used in \LuaTeX-ja.
896 \def\makelabel{\ttfamily}
897 \def\dim#1{\item[\char92 #1\ \textrm{(dimension)}]}
898 \def\attr#1{\item[\char92 #1\ \textrm{(attribute)}]}
902 As explained in Subsection~\ref{ssec-plain}, \verb+\jQ+ is equal to
903 $1\,\textrm{Q}=0.25\,\textrm{mm}$, where `Q'~(also called `級') is
904 a unit used in Japanese phototypesetting. So one should not change the value of this dimension.
906 There is also a unit called `歯' which equals to $0.25\,\textrm{mm}$ and
907 used in Japanese phototypesetting. The dimension
908 \verb+\jH+ stores this length, similar to \verb+\jQ+.
909 \dim{ltj@zw} A temporal register for the `full-width' of current Japanese font.
910 \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.
911 \attr{jfam} Current number of Japanese font family for math formulas.
912 \attr{ltj@curjfnt} The font index of current Japanese font.
913 \attr{ltj@charclass} The character class of Japanese \textit{glyph\_node}.
914 \attr{ltj@yablshift} The amount of shifting the baseline of alphabetic
915 fonts in scaled point ($2^{-16}\,\textrm{pt}$).
916 \attr{ltj@ykblshift} The amount of shifting the baseline of Japanese
917 fonts in scaled point ($2^{-16}\,\textrm{pt}$).
918 \attr{ltj@autospc} Whether the auto insertion of \textsf{kanjiskip} is allowed at the node.
919 \attr{ltj@autoxspc} Whether the auto insertion of \textsf{xkanjiskip} is allowed at the node.
920 \attr{ltj@icflag} For distinguishing `kinds' of the node. To this
921 attribute, one of the following value is
924 \item[ITALIC (1)] Glues from an itaric correction
925 (\verb+\/+). This distinction of origins of glues
926 (from explicit \verb+\kern+, or from \verb+\/+)
927 is needed in the insertion process of \textsf{xkanjiskip}.
929 \item[KINSOKU (3)] Penalties inserted for the word-wrapping process of Japanese characters (\emph{kinsoku}).
930 \item[FROM\_JFM (4)] Glues/kerns from JFM.
931 \item[LINE\_END (5)] Kerns for ...
932 \item[KANJI\_SKIP (6)] Glues for \textsf{kanjiskip}.
933 \item[XKANJI\_SKIP (7)] Glues for \textsf{xkanjiskip}.
934 \item[PROCESSED (8)] Nodes which is already processed by ...
935 \item[IC\_PROCESSED (9)] Glues from an itaric correction, but also already processed.
936 \item[BOXBDD (15)] Glues/kerns that inserted just the beginning or the ending of an hbox or a paragraph.
938 \attr{ltj@kcat$i$} Where $i$~is a natural number which is less than~7.
939 These 7~attributes store bit~vectors indicating which character block is regarded as a block of \textbf{JAchar}s.
942 \subsection{Stack System of \LuaTeX-ja}
943 \paragraph{Background}
944 \LuaTeX-ja has its own stack system, and most parameters of \LuaTeX-ja
945 are stored in it. To clarify the reason, imagine the parameter
946 \textsf{kanjiskip} is stored by a skip, and consider the following
949 \ltjsetparameter{kanjiskip=0pt}ふがふが.%
950 \setbox0=\hbox{\ltjsetparameter{kanjiskip=5pt}ほげほげ}
954 As described in Part~\ref{part-ref}, the only effective value of
955 \textsf{kanjiskip} in an hbox is the latest value, so the value of
956 \textsf{kanjiskip} which applied in the entire hbox should be 5\,pt.
957 However, by the implementation method of \LuaTeX, this `5\,pt' cannot be
958 known from any callbacks. In the \texttt{tex/packaging.w} (which is a
959 file in the source of \LuaTeX), there are the following codes:
963 scaled h; /* height of box */
964 halfword p; /* first node in a box */
965 scaled d; /* max depth */
971 if (cur_list.mode_field == -hmode) {
972 cur_box = filtered_hpack(cur_list.head_field,
973 cur_list.tail_field, saved_value(1),
974 saved_level(1), grp, saved_level(2));
975 subtype(cur_box) = HLIST_SUBTYPE_HBOX;
977 Notice that \verb+unsave+ is executed \emph{before}
978 \verb+filtered_hpack+ (this is where \verb+hpack_filter+ callback is
979 executed): so `5\,pt' in the above source is orphaned at
980 \texttt+unsave+, and hence it can't be accessed from \verb+hpack_filter+
983 \paragraph{The method}
984 The code of stack system is based on that in a post of Dev-luatex mailing list\footnote{%
985 \texttt{[Dev-luatex] tex.currentgrouplevel}, a post at 2008/8/19 by Jonathan Sauer.}.
987 These are two \TeX\ count registers for maintaining informations:
988 \verb+\ltj@@stack+ for the stack level, and \verb+\ltj@@group@level+ for
989 the \TeX's group level when the last assignment was done. Parameters
990 are stored in one big table named \texttt{charprop\_stack\_table}, where
991 \texttt{charprop\_stack\_table[$i$]} stores data of stack level~$i$. If
992 a new stack level is created by \verb+\ltjsetparameter+, all data of the
993 previous level is copied.
995 To resolve the problem mentioned in `Background' above, \LuaTeX-ja uses
996 another thing: When a new stack level is about to be created, a whatsit
997 node whose type, subtype and value are 44~(\textit{user\_defined}),
998 30112, and current group level respectively is appended to the current
999 list (we refer this node by \textit{stack\_flag}). This enables us to
1000 know whether assignment is done just inside a hbox. Suppose that the
1001 stack level is~$s$ and the \TeX's group level is~$t$ just after the hbox
1004 \item If there is no \textit{stack\_flag} node in the list of hbox, then
1005 no assignment was occurred inside the hbox. Hence values of
1006 parameters at the end of the hbox are stored in the stack
1008 \item If there is a \textit{stack\_flag} node whose value is~$t+1$, then
1009 an assignment was occurred just inside the hbox group. Hence
1010 values of parameters at the end of the hbox are stored in the
1012 \item If there are \textit{stack\_flag} nodes but all of their values
1013 are more than~$t+1$, then an assignment was occurred in the box,
1014 but it is done is `more internal' group. Hence values of
1015 parameters at the end of the hbox are stored in the stack
1019 Note that to work this trick correctly, assignments to
1020 \verb+\ltj@@stack+ and \verb+\ltj@@group@level+ have to be local always,
1021 regardless the value of \verb+\globaldefs+.
1022 This problem is resolved by using
1023 \hbox{\verb+\directlua{tex.globaldefs=0}+} (this assignment is local).
1026 \section{Linebreak after Japanese Character}\label{sec-lbreak}
1027 \subsection{Reference: Behavior in \pTeX}
1030 In~\pTeX, a linebreak after a Japanese character doesn't emit a space,
1031 since words are not separated by spaces in Japanese writings. However,
1032 this feature isn't fully implemented in \LuaTeX-ja due to the
1033 specification of callbacks in~\LuaTeX. To clarify the difference between
1034 \pTeX~and~\LuaTeX, We briefly describe the handling of a linebreak in~\pTeX, in
1037 \pTeX's input processor can be described in terms of a finite state
1038 automaton, as that of~\TeX\ in~Section~2.5 of~\cite{texbytopic}. The
1039 internal states are as follows:
1041 \item State~$N$: new line
1042 \item State~$S$: skipping spaces
1043 \item State~$M$: middle of line
1044 \item State~$K$: after a Japanese character
1046 The first three states---$N$, $S$~and~$M$---are as same as \TeX's input
1047 processor. State~$K$ is similar to state~$M$, and is entered after
1048 Japanese characters. The diagram of state transitions are indicated in
1049 Figure~\ref{fig-ptexipro}. Note that \pTeX\ doesn't leave state~$K$
1050 after `beginning/ending of a group' characters.
1052 \label{fig-ptexipro}
1054 \def\sp{\text{\tt\char32}}
1056 {\text{scan a cs}}\ar@(r,ul)[dr]&\\
1058 *++[o][F-]{N}\ar[ur]^0\ar[dd]_{d,\ g}\ar[u]^{5\ (\text{\tt\char92par})}
1059 \ar@{->}@(d,l)[ddrr]_(0.45){j}&&
1060 *++[o][F-]{S}\ar@(l,dr)[ul]^0\ar@(l,ur)[ddll]_{d,\ g}\ar[u]_{5}
1061 \ar@{->}@(r,r)[dd]^{j}\\&\\&
1062 *++[o][F-]{M}\ar[uuur]^0\ar@(r,dl)[uurr]_(0.55){10\ (\sp)}
1063 \ar[d]_{5\ ({\sp})}\ar@{->}@(dr,dl)[rr]_{j}&&
1064 *++[o][F-]{K}\ar@{->}@(ul,d)[uuul]^0\ar@{->}[ll]^{d}
1065 \ar@{->}@(ur,dr)[uu]^{10\ (\sp)}\ar@{->}[d]_5\\
1068 d:=\{3,4,6,7,8,11,12,13\},\quad g:=\{1,2\},\quad j:=(\text{Japanese characters})
1071 \item Numbers represent category codes.
1072 \item Category codes 9~(ignored), 14~(comment)~and~15~(invalid) are omitted in above diagram.
1074 \caption{State transitions of \pTeX's input processor.}
1078 \subsection{Behavior in \LuaTeX-ja}
1079 States in the input processoe of \LuaTeX\ is the same as that of \TeX,
1080 and they can't be customized by any callbacks. Hence, we can only use
1081 \verb+process_input_buffer+ and \verb+token_filter+ callbacks for to
1082 suppress a space by a linebreak which is after Japanese characters.
1084 However, \verb+token_filter+ callback cannot be used either, since a
1085 character in category code 5~(end-of-line) is converted into an space
1086 token \emph{in the input processor}. So we can use only the
1087 \verb+process_input_buffer+ callback. This means that suppressing a
1088 space must be done \emph{just before} an input line is read.
1090 Considering these situations, handling of a end-of-line in \LuaTeX-ja are as follows:
1092 A character U+FFFFF (its category code is set to 14~(comment) by
1093 \LuaTeX-ja) is appended to an input line, before \LuaTeX\ actually
1094 process it, if and only if the following two conditions are satisfied:
1096 \item The category code of the character $\langle${return}$\rangle$
1097 (whose character code is 13) is 5~(end-of-line).
1098 \item The input line matches the following `regular expression':
1100 (\text{any char})^*(\textbf{JAchar})
1101 \bigl(\{\text{catcode}=1\}\cup\{\text{catcode}=2\}\bigr)^*
1107 \section{Insertion of JFM glues, \textsf{kanjiskip} and \textsf{xkanjiskip}}
1108 This is the longest section of the document.
1110 jfmglue.tex の内容をここに入れる