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}
16 \usepackage{luatexja-otf}
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={}, basewidth=0.5em
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}.
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.
226 \subsection{Cautions}
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.
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
239 \ltjsetparameter{jacharrange={-3, -8}}
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:
249 This does minimal settings (like {\tt ptex.tex}) for typesetting Japanese documents:
251 \item The following 6~Japanese fonts are preloaded:
253 \begin{tabular}{ccccc}
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+\\
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+.
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
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.
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
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}}.
284 \subsection{Using in \LaTeX}\label{ssec-ltx}
286 Using in \LaTeXe\ is basically same. To set up the minimal environment
287 for Japanese, you only have to load {\tt luatexja.sty}:
289 \usepackage{luatexja}
291 It also does minimal settings (counterparts in \pLaTeX\ are {\tt
292 plfonts.dtx} and {\tt pldefs.ltx}):
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:
299 \begin{tabular}{ccccc}
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\\
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.
310 \item Japanese characters in math mode are typeset by the font family {\tt mc}.
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}.
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.
327 森\UTF{9DD7}外と内田百\UTF{9592}とが\UTF{9AD9}島屋に行く。
329 \CID{7652}飾区の\CID{13706}野家,
332 %lltjlisting.sty要修正?:↑「森」の直後で改行.
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:
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}\,\}$.
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,
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.
354 Hence, in our opinion, the above input should be corrected as:
357 ($f_{\text{high temperature}}$).
359 \mathrel{\text{よって}}\quad y>0 \]
360 $5\in{}素:=\{\,p\in\mathbb N:\text{$p$ is a prime}\,\}$.
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}.
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}.
374 For \LaTeXe, \LuaTeX-ja simply adopted the font selection system from that
375 of \pLaTeXe\ (in {\tt plfonts.dtx}).
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.
385 \begin{tabular}{ccccc}
387 &\textbf{encoding}&\textbf{family}&\textbf{series}&\textbf{shape}\\\midrule
389 &\verb+\romanencoding+&\verb+\romanfamily+&\verb+\romanseries+&\verb+\romanshape+\\
391 &\verb+\kanjiencoding+&\verb+\kanjifamily+&\verb+\kanjiseries+&\verb+\kanjishape+\\
392 both&---&--&\verb+\fontseries+&\verb+\fontshape+\\
393 auto select&\verb+\fontencoding+&\verb+\fontfamily+&---&---\\
397 \item For defining a Japanese font family, use \verb+\DeclareKanjiFamily+
398 instead of \verb+\DeclareFontFamily+.
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}
407 In \texttt{luatexja-fontspec} package, the following 7~commands are defined as
408 counterparts of original commands in \texttt{fontspec}:
410 \begin{tabular}{ccccc}
413 &\verb+\jfontspec+&\verb+\setmainjfont+&\verb+\setsansjfont+&\verb+\newjfontfamily+\\
415 &\verb+\fontspec+&\verb+\setmainfont+&\verb+\setsansfont+&\verb+\newfontfamily+\\
418 &\verb+\newjfontface+&\verb+\defaultjfontfeatures+&\verb+\addjfontfeatures+\\
420 &\verb+\newfontface+&\verb+\defaultfontfeatures+&\verb+\addfontfeatures+\\
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
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+.
440 \subsection{Editing the range of \textbf{JAchar}s}
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.
449 \ltjdefcharrange{100}{"10000-"1FFFF,`漢}
451 This assignment of numbers to ranges are always global, so you should
452 not do this in the middle of a document.
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.
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):
465 \ltjsetparameter{jacharrange={-1, +2, +3, -4, -5, +6, +7, +8}}
470 \paragraph{Default Setting}
471 Lua\TeX-ja predefines eight character ranges for convinience. They are
472 determined from the following data:
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.
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} ...
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:
488 \def\ch#1#2{\item \char"#1\ ({\tt U+00#1}, #2)}%"
489 \ch{A7}{Section Sign}
490 \ch{A8}{Umlaut or diaeresis}
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}
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}:
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
513 \item[Range~2${}^{\text{J}}$] Greek and Cyrillic letters. JIS~X~0208 (hence most of Japanese
514 fonts) has some of these characters.
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
523 \item[Range~3${}^{\text{J}}$] Punctuations and Miscellaneous symbols. The block list is
524 indicated in Table~\ref{table-rng3}.
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}}%"
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\\
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:
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
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}.
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}}%"
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)
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}.
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}}%"
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
613 \subsection{\textsf{kanjiskip} and \textsf{xkanjiskip}}\label{subs-kskip}
614 \textbf{JAglue} is divided into the following three categories:
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
619 \item The default glue which inserted between two \textbf{JAchar}s ({\sf
621 \item The default glue which inserted between a \textbf{JAchar} and an
622 \textbf{ALchar} (\textsf{xkanjiskip}).
624 The value (a skip) of \textsf{kanjiskip} or \textsf{xkanjiskip} can be
625 changed as the following.
627 \ltjsetparameter{kanjiskip={0pt plus 0.4pt minus 0.4pt},
628 xkanjiskip={0.25\zw plus 1pt minus 1pt}}
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+.
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}あ').
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.
647 \ltjsetparameter{jaxspmode={`あ,preonly}, alxspmode={`\!,postonly}}
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}.}.
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.
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}
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あいう
681 Here the horizontal line in above is the baseline of a line.
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):
689 \ltjsetparameter{yjabaselineshift=-1pt,
690 yalbaselineshift=-1pt}
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:
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+.
707 For example, the following sets banner as `{\tt filename (2012-01-01 17:01)}':
711 \hour\time \divide\hour by 60 \@tempcnta\hour \multiply\@tempcnta 60\relax
712 \minute\time \advance\minute-\@tempcnta
714 \jobname\space(\number\year-\two@digits\month-\two@digits\day
715 \space\two@digits\hour:\two@digits\minute)}%
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:
731 \jfont\tradgt={file:ipaexg.ttf:script=latn;%
732 +trad;-kern;jfm=ujis} at 14pt
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>.
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.
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:
760 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
762 Specify the name of JFM. A file named \texttt{jfm-<name>.lua} will be searched and/or loaded.
764 The followings are JFMs shipped with Lua\TeX-ja:
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
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
781 何かいい例.単純に「min10にはバグあり」ではなく,プロポーショナルな側面も見せたいよね
782 (乙部さんのmin10.pdfの例を使う?)
785 \item[jfmvar=<string>] ...
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.
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 ...
808 \subsection{Structure of JFM file}
809 A JFM file is a Lua script which has only one function call:
811 luatexja.jfont.define_jfm { ... }
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.
818 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
819 \item[dir=<direction>] (required)
821 The direction of JFM. At the present, only \texttt{'yoko'} is supported.
823 \item[zw=<length>] (required)
825 The amount of the length of the `full-width'.
827 \item[zh=<length>] (required)
829 \item[kanjiskip=\{<natural>, <stretch>, <shrink>\}] (optional)
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.
839 \item[xkanjiskip=\{<natural>, <stretch>, <shrink>\}] (optional)
841 Like the \texttt{kanjiskip} field, this field specifies the `ideal'
842 amount of \textsf{xkanjiskip}.
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:
853 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
854 \item[chars=\{<character>, ...\}] (required except character class~0)
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).
864 In addition to those `real' characters, the following `imaginary
865 characters' can be specified in the list:
867 \item[width=<length>, height=<length>, depth=<length>, italic=<length>]\ (required)
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
874 \item[left=<length>, down=<length>, align=<align>]\
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
882 The effects of these 3~fields are indicated in Figure~\ref{fig-pos}.
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'.
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}
895 \color{red!20!white}% real glyph :step1
896 \put(-1,-1.5){\vrule width 6\unitlength height 7\unitlength depth 2.5\unitlength}
898 \color{red}% real glyph
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}}
905 \color{green!20!white}% real glyph :step1
906 \put(3,0){\vrule width 6\unitlength height 7\unitlength depth 2.5\unitlength}
908 \color{black}% real glyph :step1
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}}}
918 \color{green!50!black}% real glyph :step1
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}}
925 \savebox{\eqdist}(0,0)[b]{%
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}}
932 \color{blue}% shifted
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}}}
941 \begin{minipage}{0.6\textwidth}%
942 Consider a node containing Japanese character whose value of the \texttt{align}
943 field is \texttt{'middle'}.
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.
954 \caption{The position of the `real' glyph.}
959 \item[kern={\{[$j$]=<kern>, ...\}}]
961 \item[glue={\{[$j$]=\{<width>, <stretch>, <shrink>\}, ...\}}]
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+.
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
977 \caption{Primitives for Japanese math fonts.}
978 \begin{center}\def\{{\char`\{}\def\}{\char`\}}
981 &Japanese fonts&alphabetic fonts\\
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>\\
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}.
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
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.
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.
1019 \ltjgetparameter{differentjfm},
1020 \ltjgetparameter{autospacing},
1021 \ltjgetparameter{prebreakpenalty}{`)}.
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).
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:
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.
1037 \begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
1038 \item[\textsf{jcharwidowpenalty}\,=<penalty>] [\verb+\jcharwidowpenalty+]
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.
1044 \item[\textsf{kcatcode}\,=\{<chr\_code>,<natural number>\}]\
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).
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+]
1060 \item[\textsf{jaxspmode}\,=\{<chr\_code>,<mode>\}] [\verb+\inhibitxspcode+]
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>:
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.
1072 \item[\textsf{alxspmode}\,=\{<chr\_code>,<mode>\}] [\verb+\xspcode+]
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>:
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.
1083 Note that parameters \textsf{jaxspmode} and \textsf{alxspmode} use a common table.
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+]
1090 \item[\textsf{differentjfm}\,=<mode>$^\dagger$]
1092 Specify how glues/kerns between two \textbf{JAchar}s whose JFM (or size) are different.
1093 The allowed arguments are the followings:
1095 \item[\texttt{average}]
1096 \item[\texttt{both}]
1097 \item[\texttt{large}]
1098 \item[\texttt{small}]
1101 \item[\textsf{jacharrange}\,=<ranges>$^\ast$]
1102 \item[\textsf{kansujichar}\,=\{<digit>, <chr\_code>\}] [\verb+\kansujichar+]
1106 \section{Other Primitives}
1107 \subsection{Compatibility with \pTeX}
1108 \begin{list}{}{\def\makelabel{\ttfamily\char92 }}
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.
1121 \subsection{Cropmark/`tombow'}
1123 \section{Extensions}
1124 \subsection{{\tt luatexja-fontspec.sty}}
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
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.
1140 Characters by \verb+\CID+ and \verb+\UTF+ commands are different from
1141 ordinary characters in the following points:
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.
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+.
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.
1161 \def\makelabel{\ttfamily}
1162 \def\dim#1{\item[\char92 #1\ \textrm{(dimension)}]}
1163 \def\attr#1{\item[\char92 #1\ \textrm{(attribute)}]}
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.
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
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}.
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.
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.
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).
1211 \item[30111] Nodes for indicating that \verb+\inhibitglue+ is
1212 specified. The \texttt{value} field of these nodes is not
1214 \item[30112] Nodes for \LuaTeX-ja's stack system (see the next
1215 subsection). The \texttt{value} field of these nodes is
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.
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
1231 \ltjsetparameter{kanjiskip=0pt}ふがふが.%
1232 \setbox0=\hbox{\ltjsetparameter{kanjiskip=5pt}ほげほげ}
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:
1245 scaled h; /* height of box */
1246 halfword p; /* first node in a box */
1247 scaled d; /* max depth */
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;
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+
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.}.
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.
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
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
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
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
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).
1308 \section{Linebreak after Japanese Character}\label{sec-lbreak}
1309 \subsection{Reference: Behavior in \pTeX}
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
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:
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
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.
1334 \label{fig-ptexipro}
1336 \def\sp{\text{\tt\char32}}
1338 {\text{scan a cs}}\ar@(r,ul)[dr]&\\
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\\
1350 d:=\{3,4,6,7,8,11,12,13\},\quad g:=\{1,2\},\quad j:=(\text{Japanese characters})
1353 \item Numbers represent category codes.
1354 \item Category codes 9~(ignored), 14~(comment)~and~15~(invalid) are omitted in above diagram.
1356 \caption{State transitions of \pTeX's input processor.}
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.
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.
1372 Considering these situations, handling of a end-of-line in \LuaTeX-ja are as follows:
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:
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':
1382 (\text{any char})^*(\textbf{JAchar})
1383 \bigl(\{\text{catcode}=1\}\cup\{\text{catcode}=2\}\bigr)^*
1389 \section{Insertion of JFM glues, \textsf{kanjiskip} and \textsf{xkanjiskip}}
1390 This is the longest section of the document.
1392 jfmglue.tex の内容をここに入れる