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}
27 \DeclareRobustCommand\epTeX{\ensuremath{\varepsilon}-\kern-.125em\pTeX}
31 \long\def\@makecaption#1#2{%
32 \vskip\abovecaptionskip
33 \sbox\@tempboxa{{\small #1. #2}}%
34 \ifdim \wd\@tempboxa >\hsize
37 \global \@minipagefalse
38 \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
40 \vskip\belowcaptionskip}
44 \title{The \LuaTeX-ja package}
45 \author{The \LuaTeX-ja project team}
48 \title{\LuaTeX-jaパッケージ}
49 \author{\LuaTeX-jaプロジェクトチーム}
53 basicstyle=\ttfamily\small, pos=o, breaklines=true,
54 numbers=none, rframe={}
57 \parskip=\smallskipamount
60 \def<#1>{{\normalfont\rm\itshape$\langle$#1$\rangle$}}
67 {\Large\bf This documentation is far from complete. It may have many
68 grammatical (and contextual) errors.}
71 \textbf{\large 本ドキュメントはまだまだ未完成です.
72 また,英語版と日本語版をdocstripプログラムを用いることで一緒に生成している都合上,
79 \section{Introduction}
82 The \LuaTeX-ja package is a macro package for typesetting high-quality
83 Japanese documents when using \LuaTeX.
86 \LuaTeX-jaパッケージは,次世代標準\TeX である\LuaTeX の上で,\pTeX と同等
87 /それ以上の品質の日本語組版を実現させようとするマクロパッケージである.
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).
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.
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.
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}.
117 The followings are major changes from \pTeX:
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
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
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
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
140 \item In the process, two Japanese fonts which differ in their `real'
141 fonts only are identified.
143 \item At the present, vertical typesetting (\emph{tategaki}), is not
144 supported in \LuaTeX-ja.
147 For detailed information, see Part~\ref{part-imp}.
149 \subsection{Notations}
150 In this document, the following terms and notations are used:
152 \item Characters are divided into two types:
154 \item \textbf{JAchar}: standing for Japanese characters such as
155 Hiragana, Katakana, Kanji and other punctuation marks for
157 \item \textbf{ALchar}: standing for all other characters like alphabets.
159 We say `alphabetic fonts' for fonts used in \textbf{ALchar}, and `Japanese fonts' for fonts used in \textbf{JAchar}.
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
167 \item In this document, natural numbers start from~0.
170 \subsection{About the project}
171 \paragraph{Project Wiki} Project Wiki is under construction.
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)
177 This project is hosted by SourceForge.JP.
180 % \begin{multicols}{2}
182 % \item Hironori KITAGAWA
184 % \item Takayuki YATO
185 % \item Yusuke KUROKI
187 % \item Munehiro YAMAMOTO
188 % \item Tomoaki HONDA
193 % \paragraph{Acknowledgments} -- 挿入するならここ
196 \section{Getting Started}
197 \subsection{Installation}
198 To install the \LuaTeX-ja\ package, you will need:
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:)}
205 The installation methods are as follows:
207 \item Download the source archive.
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
213 $ git clone git://git.sourceforge.jp/gitroot/luatex-ja/luatexja.git
215 or download the archive of HEAD in \texttt{master} branch from
217 \url{http://git.sourceforge.jp/view?p=luatex-ja/luatexja.git;a=snapshot;h=HEAD;sf=tgz}.
219 \item Extract the archive. You will see {\tt src/} and several other sub-directories.
220 \item Copy all the contents of {\tt src/} into one of your \texttt{TEXMF} tree.
221 \item If {\tt mktexlsr} is needed to update the filename database, make it so.
224 \subsection{Cautions}
226 \item The encoding of your source file must be UTF-8.
227 \item Not well-tested. In particular, the default setting of the range
228 of \textbf{JAchar} in the present version does not coexist with
229 other packages which use Unicode fonts.
232 \subsection{Using in plain \TeX}\label{ssec-plain}
233 To use \LuaTeX-ja in plain \TeX, simply put the following at the beginning of the document:
238 This does minimal settings (like {\tt ptex.tex}) for typesetting Japanese documents:
240 \item The following 6~Japanese fonts are preloaded:
242 \begin{tabular}{ccccc}
244 \textbf{classification}&\textbf{font name}&\textbf{13.5\,Q}&\textbf{9.5\,Q}&\textbf{7\,Q}\\\midrule
245 \emph{mincho}&Ryumin-Light &\verb+\tenmin+&\verb+\sevenmin+&\verb+\fivemin+\\
246 \emph{gothic}&GothicBBB-Medium&\verb+\tengt+ &\verb+\sevengt+ &\verb+\fivegt+\\
251 \item The `Q' is a unit used in Japanese phototypesetting, and
252 $1\,\textrm{Q}=0.25\,\textrm{mm}$. This length is stored in a
253 dimension \verb+\jQ+.
255 \item It is widely accepted that the font `Ryumin-Light' and
256 `GothicBBB-Medium' aren't embedded into PDF files, and PDF reader
257 substitute them by some external Japanese fonts (\textit{e.g.},
258 Kozuka Mincho is used for Ryumin-Light in Adobe Reader). We adopt this custom to
260 \item You may notice that size of above fonts is slightly smaller than
261 their alphabetic counterparts: for example, the size
262 \verb+\texmin+ is $13.5\,\textrm{Q}\simeq 9.60444\,\textrm{pt}$. This is intensional: ...
264 \item A character in Unicode is treated as \textbf{JAchar} if and only
265 if its code-point has more than or equal to U+0100.
266 \item The amount of glue that are inserted between a \textbf{JAchar} and
267 an \textbf{ALchar} (the parameter \textsf{xkanjiskip}) is set to
269 0.25\,\hbox{\verb+\zw+}^{+1\,\text{pt}}_{-1\,\text{pt}} = \frac{27}{32}\,\mathrm{mm}^{+1\,\text{pt}}_{-1\,\text{pt}}.
271 Here \verb+\zw+ is the counterpart of \texttt{em} for Japanese fonts, that is, the length of `full-width' in current Japanese font.
274 \subsection{Using in \LaTeX}\label{ssec-ltx}
276 Using in \LaTeXe\ is basically same. To set up the minimal environment
277 for Japanese, you only have to load {\tt luatexja.sty}:
279 \usepackage{luatexja}
281 It also does minimal settings (counterparts in \pLaTeX\ are {\tt
282 plfonts.dtx} and {\tt pldefs.ltx}):
285 \item {\tt JY3} is the font encoding for Japanese fonts (in horizontal direction).\\
286 When vertical typesetting is supported by \LuaTeX-ja in the future, {\tt JT3} will be used for vertical fonts.
287 \item Two font families {\tt mc} and {\tt gt} are defined:
289 \begin{tabular}{ccccc}
291 \textbf{classification}&\textbf{family}&\verb+\mdseries+&\verb+\bfseries+&\textbf{scale}\\\midrule
292 \emph{mincho}&\tt mc&Ryumin-Light &GothicBBB-Medium&0.960444\\
293 \emph{gothic}&\tt gt&GothicBBB-Medium&GothicBBB-Medium&0.960444\\
297 \textbf{Note on fonts in bold series}
299 \item Japanese characters in math mode are typeset by the font family {\tt mc}.
302 However, above settings are not sufficient for Japanese-based
303 documents. To typeset Japanese-based documents, You are better to use
304 class files other than {\tt article.cls}, {\tt book.cls}, \ldots. At the
305 present, BXjscls (\texttt{bxjsarticle.cls} and \texttt{bxjsbook.cls}, by
306 Takayuki Yato) are better alternative. It is not determined whether
307 \LuaTeX-ja will develop and contain counterparts of major classes used
308 in \pTeX\ (including jsclasses by Haruhiko Okumura).
310 \subsection{Changing Fonts}
311 \paragraph{Remark: Japanese Characters in Math Mode}
312 Since \pTeX\ supports Japanese characters in math mode, there are
313 sources like the following:
316 $f_{高温}$~($f_{\text{high temperature}}$).
317 \[ y=(x-1)^2+2\quad{}よって\quad y>0 \]
318 $5\in{}素:=\{\,p\in\mathbb N:\text{$p$ is a prime}\,\}$.
321 We (the project members of \LuaTeX-ja) think that using
322 Japanese characters in math mode are allowed if and only if these are used as identifiers.
323 In this point of view,
325 \item The lines 1~and~2 above are not correct, since `高温' in above is used as a textual label, and
326 `よって' is used as a conjunction.
327 \item However, the line~3 is correct, since `素' is used as an identifier.
329 Hence, in our opinion, the above input should be corrected as:
332 ($f_{\text{high temperature}}$).
334 \mathrel{\text{よって}}\quad y>0 \]
335 $5\in{}素:=\{\,p\in\mathbb N:\text{$p$ is a prime}\,\}$.
337 %BUG?: \{\}がなければ「素」がでない.上の段落の「よって」もでてない.
338 We also believe that using Japanese characters as identifiers is rare,
339 hence we don't describe how to change Japanese fonts in math mode in
340 this chapter. For the method, please see Part~\ref{part-ref}.
343 \paragraph{plain \TeX}
344 To change Japanese fonts in plain \TeX, you must use the primitive
345 \verb+\jfont+. So please see Part~\ref{part-ref}.
349 For \LaTeXe, \LuaTeX-ja simply adopted the font selection system from that
350 of \pLaTeXe\ (in {\tt plfonts.dtx}).
352 \item Two control sequences \verb+\mcdefault+ and \verb+\gtdefault+ are
353 used to specify the default font families for \emph{mincho} and
354 \emph{gothic}, respectively. Default values: \texttt{mc} for
355 \verb+\mcdefault+ and \texttt{gt} for \verb+\gtdefault+.
356 \item Commands \verb+\fontfamily+, \verb+\fontseries+,
357 \verb+\fontshape+ and \verb+\selectfont+ can be used to change
358 attributes of Japanese fonts.
360 \begin{tabular}{ccccc}
362 &\textbf{encoding}&\textbf{family}&\textbf{series}&\textbf{shape}\\\midrule
364 &\verb+\romanencoding+&\verb+\romanfamily+&\verb+\romanseries+&\verb+\romanshape+\\
366 &\verb+\kanjiencoding+&\verb+\kanjifamily+&\verb+\kanjiseries+&\verb+\kanjishape+\\
367 both&---&--&\verb+\fontseries+&\verb+\fontshape+\\
368 auto select&\verb+\fontencoding+&\verb+\fontfamily+&---&---\\
372 \item For defining a Japanese font family, use \verb+\DeclareKanjiFamily+
373 instead of \verb+\DeclareFontFamily+.
377 To coexist with \texttt{fontspec} package, it is needed to load
378 \texttt{luatexja-fontspec} package in the preamble. This additional
379 package automatically loads \texttt{luatexja} and \texttt{fontspec}
382 In \texttt{luatexja-fontspec} package, the following 7~commands are defined as
383 counterparts of original commands in \texttt{fontspec}:
385 \begin{tabular}{ccccc}
388 &\verb+\jfontspec+&\verb+\setmainjfont+&\verb+\setsansjfont+&\verb+\newjfontfamily+\\
390 &\verb+\fontspec+&\verb+\setmainfont+&\verb+\setsansfont+&\verb+\newfontfamily+\\
393 &\verb+\newjfontface+&\verb+\defaultjfontfeatures+&\verb+\addjfontfeatures+\\
395 &\verb+\newfontface+&\verb+\defaultfontfeatures+&\verb+\addfontfeatures+\\
402 Note that there is no command named \verb+\setmonojfont+, since it is
403 popular for Japanese fonts that nearly all Japanese glyphs have same widths.
406 \section{Changing Parameters}
407 There are many parameters in \LuaTeX-ja. And due to the behavior of \LuaTeX,
408 most of them are not stored as internal register of \TeX, but as an
409 original storage system in \LuaTeX-ja. Hence, to assign or acquire those
410 parameters, you have to use commands \verb+\ltjsetparameter+ and
411 \verb+\ltjgetparameter+.
413 \subsection{Editing the range of \textbf{JAchar}s}
414 As noted before, the default setting is:
416 A character in Unicode is treated as \textbf{JAchar},\\
418 code-point has more than or equal to U+0100.
420 $\uparrow$ TODO: CHANGE THIS!
423 To edit the range of \textbf{JAchar}s, You have to assign a non-zero
424 natural number which is less than 217 to the character range first. This
425 can be done by using \verb+\ltjdefcharrange+ primitive. For example, the
426 next line assigns whole characters in Supplementary Multilingual Plane
427 and the character `漢' to the range number~4.
429 \ltjdefcharrange{4}{"10000-"1FFFF,`漢}
431 This assignment of numbers to ranges are always global, so you should
432 not do this in the middle of a document. 上書き
434 After assigning numbers to ranges, ...
436 \subsection{\textsf{kanjiskip} and \textsf{xkanjiskip}}\label{subs-kskip}
437 \textbf{JAglue} is divided into the following three categories:
439 \item Glues/kerns specified in JFM. If \verb+\inhibitglue+ is issued around a Japanese character,
440 this glue will be not inserted at the place.
441 \item The default glue which inserted between two \textbf{JAchar}s ({\sf
443 \item The default glue which inserted between a \textbf{JAchar} and an
444 \textbf{ALchar} (\textsf{xkanjiskip}).
446 The value (a skip) of \textsf{kanjiskip} or \textsf{xkanjiskip} can be
447 changed as the following.
449 \ltjsetparameter{kanjiskip={0pt plus 0.4pt minus 0.4pt},
450 xkanjiskip={0.25\zw plus 1pt minus 1pt}}
454 It may occur that JFM contains the data of `ideal width of {\sf
455 kanjiskip}' and/or `ideal width of \textsf{xkanjiskip}'.
456 To use these data from JFM, set the value of \textsf{kanjiskip} or
457 \textsf{xkanjiskip} to \verb+\maxdimen+.
459 \subsection{Insertion Setting of \textsf{xkanjiskip}}
460 It is not desirable that \textsf{xkanjiskip} is inserted between every
461 boundary between \textbf{JAchar}s and \textbf{ALchar}s. For example,
462 \textsf{xkanjiskip} should not be inserted after opening parenthesis
463 (\textit{e.g.}, compare `(あ' and `(\hskip\ltjgetparameter{xkanjiskip}あ').
465 \LuaTeX-ja can control whether \textsf{xkanjiskip} can be inserted
466 before/after a character, by changing \textsf{jaxspmode} for \textbf{JAchar}s and
467 \textsf{alxspmode} parameters \textbf{ALchar}s respectively.
469 \ltjsetparameter{jaxspmode={`あ,preonly}, alxspmode={`\!,postonly}}
473 The second argument {\tt preonly} means `the insertion of
474 \textsf{xkanjiskip} is allowed before this character, but not after'.
475 the other possible values are {\tt postonly}, {\tt allow} and {\tt
476 inhibit}. For the compatibility with \pTeX, natural numbers between
477 0~and~3 are also allowed as the second argument\footnote{But we don't
478 recommend this: since numbers 1~and~2 have opposite meanings in
479 \textsf{jaxspmode} and \textsf{alxspmode}.}.
481 If you want to enable/disable all insertions of \textsf{kanjiskip} and
482 \textsf{xkanjiskip}, set \textsf{autospacing} and \textsf{autoxspacing}
483 parameters to {\tt false}, respectively.
486 \subsection{Shifting Baseline}
487 To make a match between a Japanese font and an alphabetic font, sometimes
488 shifting of the baseline of one of the pair is needed. In \pTeX, this is achieved
489 by setting \verb+\ybaselineshift+ to a non-zero length (the
490 baseline of alphabetic fonts is shifted below). However, for documents
491 whose main language is not Japanese, it is good to shift the baseline of
492 Japanese fonts, but not that of alphabetic fonts.
493 Because of this, \LuaTeX-ja can independently set the shifting amount
494 of the baseline of alphabetic fonts (\textsf{yalbaselineshift}
495 parameter) and that of Japanese fonts (\textsf{yjabaselineshift}
499 \vrule width 150pt height 0.4pt depth 0pt\hskip-120pt
500 \ltjsetparameter{yjabaselineshift=0pt, yalbaselineshift=0pt}abcあいう
501 \ltjsetparameter{yjabaselineshift=5pt, yalbaselineshift=2pt}abcあいう
503 Here the horizontal line in above is the baseline of a line.
505 There is an interesting side-effect: characters in different size can be
506 vertically aligned center in a line, by setting two parameters appropriately.
507 The following is an example (beware the value is not well tuned):
511 \ltjsetparameter{yjabaselineshift=-1pt,
512 yalbaselineshift=-1pt}
518 \subsection{Cropmark}
519 Cropmark is a mark for indicating 4~corners and horizontal/vertical
520 center of the paper. In Japanese, we call cropmark as tombo(w).
521 \pLaTeX\ and this \LuaTeX-ja support `tombow' by their kernel.
522 The following steps are needed to typeset cropmark:
525 \item First, define the banner which will be printed at the upper left
526 of the paper. This is done by assigning a token list to
527 \verb+\@bannertoken+.
529 For example, the following sets banner as `{\tt filename (2012-01-01 17:01)}':
533 \hour\time \divide\hour by 60 \@tempcnta\hour \multiply\@tempcnta 60\relax
534 \minute\time \advance\minute-\@tempcnta
536 \jobname\space(\number\year-\two@digits\month-\two@digits\day
537 \space\two@digits\hour:\two@digits\minute)}%
544 \part{Reference}\label{part-ref}
545 \section{Font Metric and Japanese Font}
546 \subsection{\texttt{\char92jfont} primitive}
547 To load a font as a Japanese font, you must use the
548 \verb+\jfont+ primitive instead of~\verb+\font+, while
549 \verb+\jfont+ admits the same syntax used in~\verb+\font+.
550 \LuaTeX-ja automatically loads \texttt{luaotfload} package,
551 so TrueType/OpenType fonts with features can be used for Japanese fonts:
553 \jfont\tradgt={file:ipaexg.ttf:script=latn;%
554 +trad;jfm=ujis} at 14pt
558 Note that the defined control sequence
559 (\verb+\tradgt+ in the example above) using \verb+\jfont+ is not a
560 \textit{font\_def} token, hence the input like
561 \verb+\fontname\tradgt+ causes a error. We denote control sequences which are defined in \verb+\jfont+
565 Besides \texttt{file:}\ and \texttt{name:}\ prefixes, \texttt{psft:}\ can
566 be used a prefix in \verb+\jfont+ (and~\verb+\font+) primitive. Using
567 this prefix, you can specify a font that has its name only and is not
568 related to any real font.
570 Mainly, use of this \texttt{psft:}\ prefix is for using non-embedding `standard' Japanese fonts (Ryumin-Light and GothicBBB-Medium).
578 \subsection{Structure of JFM file}
579 A JFM file is a Lua script which has only one function call:
581 luatexja.jfont.define_jfm { ... }
583 Real data are stored in the table which indicated above by
584 \verb+{ ... }+. So, the rest of this subsection are devoted to describe the
585 structure of this table. Note that all lengths in a JFM file are
586 floating-point numbers in design-size unit.
588 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
589 \item[dir=<direction>] (required)
591 The direction of JFM. At the present, only \texttt{'yoko'} is supported.
593 \item[zw=<length>] (required)
595 The amount of the length of the `full-width'.
597 \item[zh=<length>] (required)
599 \item[kanjiskip=\{<natural>, <stretch>, <shrink>\}] (optional)
601 This field specifies the `ideal' amount of \textsf{kanjiskip}. As noted
602 in Subsection~\ref{subs-kskip}, if the parameter
603 \textsf{kanjiskip} is \verb+\maxdimen+, the value specified
604 in this field is actually used (if this field is not specified in
605 JFM, it is regarded as 0\,pt). Note that <stretch> and <shrink>
606 fields are in design-size unit too.
609 \item[xkanjiskip=\{<natural>, <stretch>, <shrink>\}] (optional)
611 Like the \texttt{kanjiskip} field, this field specifies the `ideal'
612 amount of \textsf{xkanjiskip}.
616 Besides from above fields, a JFM file have several sub-tables those
617 indices are natural numbers. The table indexed by~$i\in\omega$ stores
618 informations of `character class'~$i$. At least, the character class~0 is
619 always present, so each JFM file must have a sub-table whose index is
620 \texttt{[0]}. Each sub-table (its numerical index is denoted by $i$) has
621 the following fields:
623 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
624 \item[chars=\{<character>, ...\}] (required except character class~0)
626 This field is a list of characters which are in this character
627 type~$i$. This field is not required if $i=0$, since all
628 \textbf{JAchar} which are not in any character class other
629 than 0 (hence, the character class~0 contains most of
630 \textbf{JAchar}s). In the list, a character can be
631 specified by its code number, or by the character itself
632 (as a string of length~1).
634 In addition to those `real' characters, the following `imaginary
635 characters' can be specified in the list:
637 \item[width=<length>, height=<length>, depth=<length>, italic=<length>]\ (required)
639 Specify width of characters in character class~$i$, height, depth and
640 the amount of italic correction. All characters in character class~$i$ are regarded that its width, height and depth are
641 as values of these fields.
642 But there is one exception: if \texttt{'prop'} is specified in \texttt{width} field, width of a character becomes that of its `real' glyph
644 \item[left=<length>, down=<length>, align=<align>]\
646 These fields are for adjusting the position of the `real' glyph. Legal
647 values of \texttt{align} field are \texttt{'left'},
648 \texttt{'middle'} and \texttt{'right'}. If one of these
649 3~fields are omitted, \texttt{left} and \texttt{down} are
650 treated as~0, and \texttt{align} field is treated as
652 The effects of these 3~fields are indicated in Figure~\ref{fig-pos}.
654 In most cases, \texttt{left} and \texttt{down} fields are~0, while
655 it is not uncommon that the \texttt{align} field is \texttt{'middle'} or \texttt{'right'}.
656 For example, setting the \texttt{align} field to \texttt{'right'} is practically needed
657 when the current character class is the class for opening delimiters'.
659 \begin{minipage}{0.4\textwidth}%
660 \begin{center}\unitlength=10pt\small
661 \begin{picture}(15,12)(-1,-4)
662 \color{black!10!white}% real glyph :step1
663 \put(0,0){\vrule width 12\unitlength height 8\unitlength depth 3\unitlength}
665 \color{red!20!white}% real glyph :step1
666 \put(-1,-1.5){\vrule width 6\unitlength height 7\unitlength depth 2.5\unitlength}
668 \color{red}% real glyph
670 \put(-1,-1.5){\vector(0,1){7}\vector(0,-1){2.5}\vector(1,0){6}}
671 \put(5,-1.5){\line(0,1){7}\line(0,-1){2.5}}
672 \put(-1,5.5){\line(1,0){6}}
673 \put(-1,-4){\line(1,0){6}}
675 \color{green!20!white}% real glyph :step1
676 \put(3,0){\vrule width 6\unitlength height 7\unitlength depth 2.5\unitlength}
678 \color{black}% real glyph :step1
680 \put(0,0){\vector(0,1){8}\line(0,-1){3}\vector(1,0){12}}
681 \put(12,0){\line(0,1){8}\vector(0,-1){3}}
682 \put(0,8){\line(1,0){12}}
683 \put(0,-3){\line(1,0){12}}
684 \put(0.2,4){\makebox(0,0)[l]{\texttt{height}}}
685 \put(12.2,-1.5){\makebox(0,0)[l]{\texttt{depth}}}
686 \put(6,0.2){\makebox(0,0)[b]{\texttt{width}}}
688 \color{green!50!black}% real glyph :step1
690 \put(3,0){\vector(0,1){7}\vector(0,-1){2.5}\vector(1,0){6}}
691 \put(9,0){\line(0,1){7}\line(0,-1){2.5}}
692 \put(3,7){\line(1,0){6}}
693 \put(3,-2.5){\line(1,0){6}}
695 \savebox{\eqdist}(0,0)[b]{%
697 \put(-0.08,0.2){\line(0,-1){0.4}}%
698 \put(0.08,0.2){\line(0,-1){0.4}}}
699 \put(1.5,0){\usebox{\eqdist}}
700 \put(10.5,0){\usebox{\eqdist}}
702 \color{blue}% shifted
704 \put(3,-1.5){\vector(-1,0){4}}
705 \put(1,-1.7){\makebox(0,0)[t]{\texttt{left}}}
706 \put(3,0){\vector(0,-1){1.5}}
707 \put(3.2,-0.75){\makebox(0,0)[l]{\texttt{down}}}
711 \begin{minipage}{0.6\textwidth}%
712 Consider a node containing Japanese character whose value of the \texttt{align}
713 field is \texttt{'middle'}.
715 \item The black rectangle is a frame of the node.
716 Its width, height and depth are specified by JFM.
717 \item Since the \texttt{align} field is \texttt{'middle'},
718 the `real' glyph is centered horizontally (the green rectangle).
719 \item Furthermore, the glyph is shifted according to values of fields
720 \texttt{left} and \texttt{down}. The ultimate position of the real
721 glyph is indicated by the red rectangle.
724 \caption{The position of the `real' glyph.}
729 \item[kern={\{[$j$]=<kern>, ...\}}]
731 \item[glue={\{[$j$]=\{<width>, <stretch>, <shrink>\}, ...\}}]
734 \subsection{Math Font Family}
735 \TeX\ handles fonts in math formulas by 16~font families\footnote{Omega,
736 Aleph, \LuaTeX~and $\varepsilon$-\kern-.125em(u)\pTeX can handles 256~families, but
737 an external package is needed to support this in plain \TeX\ and
738 \LaTeX.}, and each family has three fonts:
739 \verb+\textfont+, \verb+\scriptfont+ and \verb+\scriptscriptfont+.
741 \LuaTeX-ja's handling of Japanese fonts in math formulas is similar;
742 Table~\ref{tab-math} shows counterparts to \TeX's primitives for math
747 \caption{Primitives for Japanese math fonts.}
748 \begin{center}\def\{{\char`\{}\def\}{\char`\}}
751 &Japanese fonts&alphabetic fonts\\
753 font family&\verb+\jfam+${}\in [0,256)$&\verb+\fam+\\
754 text size&\tt\textsf{jatextfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\verb+\textfont+<fam>=<font\_cs>\\
755 script size&\tt\textsf{jascriptfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\verb+\scriptfont+<fam>=<font\_cs>\\
756 scriptscript size&\tt\textsf{jascriptscriptfont}\,=\{<jfam>,<jfont\_cs>\}&\tt\verb+\scriptscriptfont+<fam>=<font\_cs>\\
764 \subsection{{\tt\char92 ltjsetparameter} primitive}
765 As noted before, \verb+\ltjsetparameter+ and \verb+\ltjgetparameter+ are
766 primitives for accessing most parameters of \LuaTeX-ja. One of the main
767 reason that \LuaTeX-ja didn't adopted the syntax similar to that of \pTeX\
768 (\textit{e.g.},~\verb+\prebreakpenalty`)=10000+)
769 is the position of \verb+hpack_filter+ callback in the source
770 of \LuaTeX, see Section~\ref{sec-para}.
772 \verb+\ltjsetparameter+ and \verb+\ltjglobalsetparameter+ are primitives
773 for assigning parameters. These take one argument which is a
774 \texttt{<key>=<value>} list. Allowed keys are described in the next
776 The difference between
777 \verb+\ltjsetparameter+ and \verb+\ltjglobalsetparameter+ is only the
779 \verb+\ltjsetparameter+ does a local assignment and
780 \verb+\ltjglobalsetparameter+ does a global one.
781 They also obey the value of \verb+\globaldefs+,
782 like other assignment.
784 \verb+\ltjgetparameter+ is the primitive for acquiring parameters. It
785 always takes a parameter name as first argument, and also takes the
786 additional argument---a character code, for example---in some cases.
788 \ltjgetparameter{differentjfm},
789 \ltjgetparameter{autospacing},
790 \ltjgetparameter{prebreakpenalty}{`)}.
792 \emph{The return value of\/ {\normalfont\tt\char92ltjgetparameter} is
793 always a string}. This is outputted by \texttt{tex.write()}, so any
794 character other than space~`{\tt\char32}'~(U+0020) has the category code
795 12~(other), while the space has 10~(space).
797 \subsection{List of Parameters}
798 In the following list of parameters, [\verb+\cs+] indicates the counterpart in \pTeX, and each symbol has the following meaning:
800 \item No mark: values at the end of the paragraph or the hbox are
801 adopted in the whole paragraph/hbox.
802 \item `\ast' : local parameters, which can change everywhere inside a paragraph/hbox.
803 \item `\dagger': assignments are always global.
806 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
807 \item[\textsf{jcharwidowpenalty}\,=<penalty>] [\verb+\jcharwidowpenalty+]
809 Penalty value for supressing orphans. This penalty is inserted just
810 after the last \textbf{JAchar} which is not regarded as a
811 (Japanese) punctuation mark.
813 \item[\textsf{kcatcode}\,=\{<chr\_code>,<natural number>\}]\
815 An additional attributes having each character whose character code is <chr\_code>.
816 At the present version, the lowermost bit of <natural number> indicates
817 whether the character is considered as a punctuation mark
818 (see the description of \textsf{jcharwidowpenalty} above).
821 \item[\textsf{prebreakpenalty}\,=\{<chr\_code>,<penalty>\}] [\verb+\prebreakpenalty+]
822 \item[\textsf{postbreakpenalty}\,=\{<chr\_code>,<penalty>\}] [\verb+\postbreakpenalty+]
823 \item[\textsf{jatextfont}\,=\{<jfam>,<jfont\_cs>\}] [\verb+\textfont+ in \TeX]
824 \item[\textsf{jascriptfont}\,=\{<jfam>,<jfont\_cs>\}] [\verb+\scriptfont+ in \TeX]
825 \item[\textsf{jascriptscriptfont}\,=\{<jfam>,<jfont\_cs>\}] [\verb+\scriptscriptfont+ in \TeX]
826 \item[\textsf{yjabaselineshift}\,=<dimen>$^\ast$]\
827 \item[\textsf{yalbaselineshift}\,=<dimen>$^\ast$] [\verb+\ybaselineshift+]
829 \item[\textsf{jaxspmode}\,=\{<chr\_code>,<mode>\}] [\verb+\inhibitxspcode+]
831 Setting whether inserting \textsf{xkanjiskip} is allowed before/after a \textbf{JAchar} whose character code is <chr\_code>.
832 The followings are allowed for <mode>:
834 \item[0, \texttt{inhibit}] Insertion of \textsf{xkanjiskip} is inhibited before the charater, nor after the charater.
835 \item[2, \texttt{preonly}] Insertion of \textsf{xkanjiskip} is allowed before the charater, but not after.
836 \item[1, \texttt{postonly}] Insertion of \textsf{xkanjiskip} is allowed after the charater, but not before.
837 \item[3, \texttt{allow}] Insertion of \textsf{xkanjiskip} is allowed before the charater and after the charater.
838 This is the default value.
841 \item[\textsf{alxspmode}\,=\{<chr\_code>,<mode>\}] [\verb+\xspcode+]
843 Setting whether inserting \textsf{xkanjiskip} is allowed before/after a \textbf{ALchar} whose character code is <chr\_code>.
844 The followings are allowed for <mode>:
846 \item[0, \texttt{inhibit}] Insertion of \textsf{xkanjiskip} is inhibited before the charater, nor after the charater.
847 \item[1 \texttt{preonly}] Insertion of \textsf{xkanjiskip} is allowed before the charater, but not after.
848 \item[2 \texttt{postonly}] Insertion of \textsf{xkanjiskip} is allowed after the charater, but not before.
849 \item[3, \texttt{allow}] Insertion of \textsf{xkanjiskip} is allowed before the charater and after the charater.
850 This is the default value.
852 Note that parameters \textsf{jaxspmode} and \textsf{alxspmode} use a common table.
854 \item[\textsf{autospacing}\,=<bool>$^\ast$] [\verb+\autospacing+]
855 \item[\textsf{autoxspacing}\,=<bool>$^\ast$] [\verb+\autoxspacing+]
856 \item[\textsf{kanjiskip}\,=<skip>] [\verb+\kanjiskip+]
857 \item[\textsf{xkanjiskip}\,=<skip>] [\verb+\xkanjiskip+]
859 \item[\textsf{differentjfm}\,=<mode>$^\dagger$]
861 Specify how glues/kerns between two \textbf{JAchar}s whose JFM (or size) are different.
862 The allowed arguments are the followings:
864 \item[\texttt{average}]
866 \item[\texttt{large}]
867 \item[\texttt{small}]
870 \item[\textsf{jacharrange}\,=<ranges>$^\ast$]
871 \item[\textsf{kansujichar}\,=\{<digit>, <chr\_code>\}] [\verb+\kansujichar+]
875 \section{Other Primitives}
876 \subsection{Compatibility with \pTeX}
877 \begin{list}{}{\def\makelabel{\ttfamily\char92 }}
886 \section{Control Sequences for \LaTeXe}
887 \subsection{Patch for NFSS2}
888 As described in Subsection~\ref{ssec-ltx}, \LuaTeX-ja simply adopted \texttt{plfonts.dtx} in \pLaTeXe\ for the Japanese patch for NFSS2.
890 \subsection{Cropmark/`tombow'}
892 \part{Implementations}\label{part-imp}
893 \section{Storing Parameters}\label{sec-para}
894 \subsection{Used Dimensions and Attributes}
895 Here the following is the list of dimension and attributes which are used in \LuaTeX-ja.
897 \def\makelabel{\ttfamily}
898 \def\dim#1{\item[\char92 #1\ \textrm{(dimension)}]}
899 \def\attr#1{\item[\char92 #1\ \textrm{(attribute)}]}
903 As explained in Subsection~\ref{ssec-plain}, \verb+\jQ+ is equal to
904 $1\,\textrm{Q}=0.25\,\textrm{mm}$, where `Q'~(also called `級') is
905 a unit used in Japanese phototypesetting. So one should not change the value of this dimension.
907 There is also a unit called `歯' which equals to $0.25\,\textrm{mm}$ and
908 used in Japanese phototypesetting. The dimension
909 \verb+\jH+ stores this length, similar to \verb+\jQ+.
910 \dim{ltj@zw} A temporal register for the `full-width' of current Japanese font.
911 \dim{ltj@zh} A temporal register for the `full-height' (usually the sum of height of imaginary body and its depth) of current Japanese font.
912 \attr{jfam} Current number of Japanese font family for math formulas.
913 \attr{ltj@curjfnt} The font index of current Japanese font.
914 \attr{ltj@charclass} The character class of Japanese \textit{glyph\_node}.
915 \attr{ltj@yablshift} The amount of shifting the baseline of alphabetic
916 fonts in scaled point ($2^{-16}\,\textrm{pt}$).
917 \attr{ltj@ykblshift} The amount of shifting the baseline of Japanese
918 fonts in scaled point ($2^{-16}\,\textrm{pt}$).
919 \attr{ltj@autospc} Whether the auto insertion of \textsf{kanjiskip} is allowed at the node.
920 \attr{ltj@autoxspc} Whether the auto insertion of \textsf{xkanjiskip} is allowed at the node.
921 \attr{ltj@icflag} For distinguishing `kinds' of the node. To this
922 attribute, one of the following value is
925 \item[ITALIC (1)] Glues from an itaric correction
926 (\verb+\/+). This distinction of origins of glues
927 (from explicit \verb+\kern+, or from \verb+\/+)
928 is needed in the insertion process of \textsf{xkanjiskip}.
930 \item[KINSOKU (3)] Penalties inserted for the word-wrapping process of Japanese characters (\emph{kinsoku}).
931 \item[FROM\_JFM (4)] Glues/kerns from JFM.
932 \item[LINE\_END (5)] Kerns for ...
933 \item[KANJI\_SKIP (6)] Glues for \textsf{kanjiskip}.
934 \item[XKANJI\_SKIP (7)] Glues for \textsf{xkanjiskip}.
935 \item[PROCESSED (8)] Nodes which is already processed by ...
936 \item[IC\_PROCESSED (9)] Glues from an itaric correction, but also already processed.
937 \item[BOXBDD (15)] Glues/kerns that inserted just the beginning or the ending of an hbox or a paragraph.
939 \attr{ltj@kcat$i$} Where $i$~is a natural number which is less than~7.
940 These 7~attributes store bit~vectors indicating which character block is regarded as a block of \textbf{JAchar}s.
943 \subsection{Stack System of \LuaTeX-ja}
944 \paragraph{Background}
945 \LuaTeX-ja has its own stack system, and most parameters of \LuaTeX-ja
946 are stored in it. To clarify the reason, imagine the parameter
947 \textsf{kanjiskip} is stored by a skip, and consider the following
950 \ltjsetparameter{kanjiskip=0pt}ふがふが.%
951 \setbox0=\hbox{\ltjsetparameter{kanjiskip=5pt}ほげほげ}
955 As described in Part~\ref{part-ref}, the only effective value of
956 \textsf{kanjiskip} in an hbox is the latest value, so the value of
957 \textsf{kanjiskip} which applied in the entire hbox should be 5\,pt.
958 However, by the implementation method of \LuaTeX, this `5\,pt' cannot be
959 known from any callbacks. In the \texttt{tex/packaging.w} (which is a
960 file in the source of \LuaTeX), there are the following codes:
964 scaled h; /* height of box */
965 halfword p; /* first node in a box */
966 scaled d; /* max depth */
972 if (cur_list.mode_field == -hmode) {
973 cur_box = filtered_hpack(cur_list.head_field,
974 cur_list.tail_field, saved_value(1),
975 saved_level(1), grp, saved_level(2));
976 subtype(cur_box) = HLIST_SUBTYPE_HBOX;
978 Notice that \verb+unsave+ is executed \emph{before}
979 \verb+filtered_hpack+ (this is where \verb+hpack_filter+ callback is
980 executed): so `5\,pt' in the above source is orphaned at
981 \texttt+unsave+, and hence it can't be accessed from \verb+hpack_filter+
984 \paragraph{The method}
985 The code of stack system is based on that in a post of Dev-luatex mailing list\footnote{%
986 \texttt{[Dev-luatex] tex.currentgrouplevel}, a post at 2008/8/19 by Jonathan Sauer.}.
988 These are two \TeX\ count registers for maintaining informations:
989 \verb+\ltj@@stack+ for the stack level, and \verb+\ltj@@group@level+ for
990 the \TeX's group level when the last assignment was done. Parameters
991 are stored in one big table named \texttt{charprop\_stack\_table}, where
992 \texttt{charprop\_stack\_table[$i$]} stores data of stack level~$i$. If
993 a new stack level is created by \verb+\ltjsetparameter+, all data of the
994 previous level is copied.
996 To resolve the problem mentioned in `Background' above, \LuaTeX-ja uses
997 another thing: When a new stack level is about to be created, a whatsit
998 node whose type, subtype and value are 44~(\textit{user\_defined}),
999 30112, and current group level respectively is appended to the current
1000 list (we refer this node by \textit{stack\_flag}). This enables us to
1001 know whether assignment is done just inside a hbox. Suppose that the
1002 stack level is~$s$ and the \TeX's group level is~$t$ just after the hbox
1005 \item If there is no \textit{stack\_flag} node in the list of hbox, then
1006 no assignment was occurred inside the hbox. Hence values of
1007 parameters at the end of the hbox are stored in the stack
1009 \item If there is a \textit{stack\_flag} node whose value is~$t+1$, then
1010 an assignment was occurred just inside the hbox group. Hence
1011 values of parameters at the end of the hbox are stored in the
1013 \item If there are \textit{stack\_flag} nodes but all of their values
1014 are more than~$t+1$, then an assignment was occurred in the box,
1015 but it is done is `more internal' group. Hence values of
1016 parameters at the end of the hbox are stored in the stack
1020 Note that to work this trick correctly, assignments to
1021 \verb+\ltj@@stack+ and \verb+\ltj@@group@level+ have to be local always,
1022 regardless the value of \verb+\globaldefs+.
1023 This problem is resolved by using
1024 \hbox{\verb+\directlua{tex.globaldefs=0}+} (this assignment is local).
1027 \section{Linebreak after Japanese Character}\label{sec-lbreak}
1028 \subsection{Reference: Behavior in \pTeX}
1031 In~\pTeX, a linebreak after a Japanese character doesn't emit a space,
1032 since words are not separated by spaces in Japanese writings. However,
1033 this feature isn't fully implemented in \LuaTeX-ja due to the
1034 specification of callbacks in~\LuaTeX. To clarify the difference between
1035 \pTeX~and~\LuaTeX, We briefly describe the handling of a linebreak in~\pTeX, in
1038 \pTeX's input processor can be described in terms of a finite state
1039 automaton, as that of~\TeX\ in~Section~2.5 of~\cite{texbytopic}. The
1040 internal states are as follows:
1042 \item State~$N$: new line
1043 \item State~$S$: skipping spaces
1044 \item State~$M$: middle of line
1045 \item State~$K$: after a Japanese character
1047 The first three states---$N$, $S$~and~$M$---are as same as \TeX's input
1048 processor. State~$K$ is similar to state~$M$, and is entered after
1049 Japanese characters. The diagram of state transitions are indicated in
1050 Figure~\ref{fig-ptexipro}. Note that \pTeX\ doesn't leave state~$K$
1051 after `beginning/ending of a group' characters.
1053 \label{fig-ptexipro}
1055 \def\sp{\text{\tt\char32}}
1057 {\text{scan a cs}}\ar@(r,ul)[dr]&\\
1059 *++[o][F-]{N}\ar[ur]^0\ar[dd]_{d,\ g}\ar[u]^{5\ (\text{\tt\char92par})}
1060 \ar@{->}@(d,l)[ddrr]_(0.45){j}&&
1061 *++[o][F-]{S}\ar@(l,dr)[ul]^0\ar@(l,ur)[ddll]_{d,\ g}\ar[u]_{5}
1062 \ar@{->}@(r,r)[dd]^{j}\\&\\&
1063 *++[o][F-]{M}\ar[uuur]^0\ar@(r,dl)[uurr]_(0.55){10\ (\sp)}
1064 \ar[d]_{5\ ({\sp})}\ar@{->}@(dr,dl)[rr]_{j}&&
1065 *++[o][F-]{K}\ar@{->}@(ul,d)[uuul]^0\ar@{->}[ll]^{d}
1066 \ar@{->}@(ur,dr)[uu]^{10\ (\sp)}\ar@{->}[d]_5\\
1069 d:=\{3,4,6,7,8,11,12,13\},\quad g:=\{1,2\},\quad j:=(\text{Japanese characters})
1072 \item Numbers represent category codes.
1073 \item Category codes 9~(ignored), 14~(comment)~and~15~(invalid) are omitted in above diagram.
1075 \caption{State transitions of \pTeX's input processor.}
1079 \subsection{Behavior in \LuaTeX-ja}
1080 States in the input processoe of \LuaTeX\ is the same as that of \TeX,
1081 and they can't be customized by any callbacks. Hence, we can only use
1082 \verb+process_input_buffer+ and \verb+token_filter+ callbacks for to
1083 suppress a space by a linebreak which is after Japanese characters.
1085 However, \verb+token_filter+ callback cannot be used either, since a
1086 character in category code 5~(end-of-line) is converted into an space
1087 token \emph{in the input processor}. So we can use only the
1088 \verb+process_input_buffer+ callback. This means that suppressing a
1089 space must be done \emph{just before} an input line is read.
1091 Considering these situations, handling of a end-of-line in \LuaTeX-ja are as follows:
1093 A character U+FFFFF (its category code is set to 14~(comment) by
1094 \LuaTeX-ja) is appended to an input line, before \LuaTeX\ actually
1095 process it, if and only if the following two conditions are satisfied:
1097 \item The category code of the character $\langle${return}$\rangle$
1098 (whose character code is 13) is 5~(end-of-line).
1099 \item The input line matches the following `regular expression':
1101 (\text{any char})^*(\textbf{JAchar})
1102 \bigl(\{\text{catcode}=1\}\cup\{\text{catcode}=2\}\bigr)^*
1108 \section{Insertion of JFM glues, \textsf{kanjiskip} and \textsf{xkanjiskip}}
1109 This is the longest section of the document.
1111 jfmglue.tex の内容をここに入れる