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