OSDN Git Service

a613b7e209a90e7707bcd64c6c0cd033d98b415c
[luatex-ja/luatexja.git] / doc / ajt-devel-ltja.tex
1 %#!lualatex ajt-devel-ltja
2 \documentclass{ajt}
3
4 %%% Packages used in this paper
5 %%% LuaTeX-ja
6
7 \usepackage{luatexja}
8 \DeclareFontShape{JY3}{mc}{m}{n}{<-> s*[0.92489] file:ipaexm.ttf:jfm=ujis}{}
9 \DeclareFontShape{JY3}{gt}{m}{n}{<-> s*[0.92489] file:ipaexg.ttf:jfm=ujis}{}
10 % quick hack: monospaced Japanese font by \ttfamily
11 \DeclareKanjiFamily{JY3}{\ttdefault}{}{}
12 \DeclareFontShape{JY3}{\ttdefault}{m}{n}{<-> s*[0.92489] file:ipaexg.ttf:jfm=mono}{}
13
14 %%% for LTXexample environment
15 \usepackage{showexpl,lltjlisting}
16 \lstset{basicstyle=\ttfamily, width=0.3\textwidth}
17
18
19 \usepackage{mflogo,booktabs}
20
21 %%% Verbatim environment
22 \usepackage{fancyvrb}
23 \CustomVerbatimEnvironment{code}{Verbatim}%
24 {numbers=left,xleftmargin=1.5em,baselinestretch=1.069,fontsize=\small}
25 \CustomVerbatimEnvironment{codewithoutnum}{Verbatim}%
26 {xleftmargin=1.5em,baselinestretch=1.069,fontsize=\small}
27 \CustomVerbatimEnvironment{codewithoutnumsmall}{Verbatim}%
28 {xleftmargin=1.5em,baselinestretch=1.0,fontsize=\footnotesize}
29 \DefineShortVerb{\|}
30
31 %%% Mandatory article metadata %%%
32 \title{The development of \LuaTeX-ja package}
33 \author{Hironori Kitagawa}
34 \address{The \LuaTeX-ja project team}
35 \email{h\_kitagawa2001@yahoo.co.jp}
36
37 \keywords{\TeX, p\TeX, \LuaTeX, \LuaTeX-ja, Japanese}
38 \abstract{%
39 The \LuaTeX-ja package is a macro package for typesetting Japanese documents under \LuaTeX.
40 This packages has much flexibility of typesetting than p\TeX, and corrected some unwanted features of p\TeX.
41 In this paper, we describe specifications, the current status and some internal processing codes of \LuaTeX-ja.
42 }
43
44 \newcommand{\parname}[1]{\textsf{#1}}
45
46 \begin{document}
47
48 %%% Do not forget to start with \maketitle!
49 \maketitle
50
51 \section{Introduction}
52 \subsection{History}
53 To typeset Japanese documents with \TeX, ASCII p\TeX~\cite{ptex} has
54 been widely used.  There are other methods---for example, using Omega
55 and OTP~\cite{omegaj}, or with the CJK package---to do so, however,
56 these alternative methods did not became a majority. On the one hand,
57 p\TeX\ enables us to produce high-quality documents, but on the other
58 hand, p\TeX\ is left behind from the extensions of \TeX\ such as \eTeX\
59 and \pdfTeX, and the diffusion of UTF-8 encoding.  In recent years, the
60 situation become better, because of the developments of |ptexenc|~\cite{ptexenc} by Nobuyuki Tsuchimura, 
61 $\varepsilon$-p\TeX~\cite{eptex} by the author,~and
62 up\TeX~\cite{uptex} by Takuji Tanaka.
63
64 However, there are still lag now. 
65
66
67 Before this \LuaTeX-ja package, there were several attempts to typeset Japanese documents under \LuaTeX.
68 Here we cite three examples:
69 \begin{itemize}
70 \item |luaums.sty|~\cite{luaums} developed by the author. This experimental package is for creating a Japanese-based presentation under \LuaTeX.
71 \item |luajalayout| package\cite{luajalayout}, formerly known as the |jafontspec| package, by Kazuki Maeda. 
72 This package is based on \LaTeXe\ and |fontspec| package.
73 \item |luajp-test| package\cite{luajp-test}, a test package made by Atsuhito Kohda, based on articles on the web page~\cite{joylua}.
74 \end{itemize}
75
76
77 \subsection{Development Policy of \LuaTeX-ja}
78 \label{ssec-pol} 
79 The first aim of the project is to implement features (from the
80 ''primitive'' level) of p\TeX as macros under \LuaTeX, so \LuaTeX-ja is
81 much affected by p\TeX.  However, as the development proceeds, some
82 technical/conceptual difficulties are arised. Hence we changed the aim
83 of the project.
84 \begin{itemize}
85 \item\emph{\LuaTeX-ja offers more flexibility of typesetting than that by
86      p\TeX.}
87
88      We think that the ability of producing outputs conformed to
89      JIS~X~4051~\cite{jisx4051}, the Japanese Industrial Standard for
90      typesetting, is not enough; if one wants to produce very
91      incoherent outputs for some reason, it should be possible. 
92 In this point, previous attempts of Japanese typesetting with \LuaTeX\
93      which we cited in the previous subsection are inadequate.
94
95 p\TeX has some flexibility of typesetting, by changing internal
96      parameters such as |\kanjiskip| or |\prebreakpenalty|, and by using
97      custom JFM (Japanese TFM). ...
98
99 \item\emph{\LuaTeX-ja isn't mere re-implementation or porting of p\TeX;
100      some (technically and/or conceptually) inconvenient features of
101      p\TeX\ are modified.} 
102
103      We describe this point in more detail at the next section.
104 \end{itemize}
105
106
107 \subsection{Contents of this Paper}
108 Here we describe the contents of the rest of this paper briefly. 
109 In Section~2, we describe major differences between p\TeX\ and \LuaTeX-ja,
110 which is introduced. Some of them are due to specifications of callbacks
111 in \LuaTeX\ (\emph{i.e.}, technical reason), and others are which we
112 thought which are better to be changed, for ``natural''
113 specifications. In Section~3, we show the current status of the \LuaTeX-ja project.
114
115 For implementing features into \LuaTeX-ja, we had to use some tricks in Lua scripts. 
116 In Section~4, we describe several these tricks and internal processing methods.
117 We hope that the materials in this section have good applications.
118
119
120 \section{Major differences with \pTeX}
121 In this section, we breifly look at ** major differences between p\TeX\ and \LuaTeX-ja.
122 For genral information of Japanese typesetting and the facts about p\TeX, please see Okumara~\cite{ptexjp}.
123
124
125 \subsection{Names of Control Sequences}
126 \label{ssec-csname}
127 Since p\TeX\ is a engine modification of Knuth's original \TeX82 engine,
128 some primitives added in it takes a form that cannot be simulated by a
129 macro.  For example, an additional primitive
130 |\prebreakpenalty|$\langle\hbox{\it
131 char\_code}\rangle$|[=]|$\langle\hbox{\it penalty}\rangle$ in p\TeX\ sets
132 the amount of penalty inserted before $\langle\hbox{\it
133 char\_code}\rangle$ to $\langle\hbox{\it penalty}\rangle$, and |\prebreakpenalty|$\langle\hbox{\it
134 char\_code}\rangle$ can be also used for retrieving the value.
135
136 Moreover, there are some parameters for Japanese typesetting which were
137 mere internal integers, dimensions, or~skips in p\TeX\ that cannot be
138 implemented by same approaches in \LuaTeX-ja.  These parameters have a
139 common point; the values at the end of a horizontal box or that of a
140 paragraph are effective in whole box or paragraph.  A good example of
141 them is |\kanjiskip|, the default amount of a skip which will be
142 inserted between two consecutive Japanese characters by default.  The
143 reason of this is the place of |hpack_filter| in the \LuaTeX's
144 CWEB-source code, and we will discuss on it in
145 Subsection~\ref{ssec-stack}.
146
147 From above 2~problems we discussed above, the assignment and retrieval
148 of most parameters in \LuaTeX-ja are summarized into 3~control sequences:
149 \begin{itemize}
150 \item |\ltjsetparameter{|$\langle\hbox{\it
151       name}\rangle$|=|$\langle\hbox{\it value}\rangle$|,...}|: for local
152       assignment.
153 \item |\ltjglobalsetparameter|: for global assignment. These two control
154       sequences obey the value of |\globaldefs| primitive.
155 \item |\ltjgetparameter{|$\langle\hbox{\it
156       name}\rangle$|}[{|$\langle\hbox{\it optional
157       argument}\rangle$|}]|: for retrieval. The returned value is always
158       a string.
159 \end{itemize}
160
161 \subsection{Linebreak after a Japanese Character}
162 \label{ssec-line} 
163
164 Japanese texts can linebreak almost everywhere, in contrast with
165 alphabetic texts can linebreak only between words (or use
166 hyphenation). Hence, p\TeX's input processor is modified so that a
167 linebreak after a Japanese character doesn't emit a space. However,
168 there is no way to customize the input processor of \LuaTeX, other than
169 hack its CWEB-source. All we can do is to modify an input line before
170 when \LuaTeX\ begin to process it, inside the |process_input_buffer|
171 callback.
172
173 Hence, in \LuaTeX-ja, a comment letter (we reserve U+FFFFF for this
174 purpose) will be appended to an input line, if this ends with a Japanese
175 character\footnote{Strictly speaking, it also requires that the catcode
176 of the endline character is 5~(\emph{end-of-line}). This condition is useful under the
177 verbatim environment.}. One might jump to a conclusion that the
178 treatment of a linebreak by p\TeX\ and that of \LuaTeX-ja is totally same,
179 but they are different in the respect that \LuaTeX-ja's judgement
180 whether a comment letter will be appended the line is done \emph{before}
181 the line is actually processed by \LuaTeX.
182
183 Figure~\ref{fig-linebreak} shows an example; the command at the first
184 line marks most of Japanese characters as ``non-Japanese character''. In
185 other words, from this command onward, the letter `あ' will be treated
186 as an alphabetic character by \LuaTeX-ja. Then, it is natural to occur a
187 space between `あ' and `y' in the output, where the actual output in the figure does
188 not so.  This is because `あ' is considered to be a Japanese character
189 by \LuaTeX-ja, when \LuaTeX-ja does a decision whether U+FFFFF will be added to the input line~2.
190 \begin{figure}
191 \begin{LTXexample}
192 \font\x=IPAMincho \x
193 \ltjsetparameter{jacharrange={-6}}xあ
194 y
195 \end{LTXexample}
196 \caption{A notable sample showing the treatment of a linebreak after a Japanese character.}\label{fig-linebreak}
197 \end{figure}
198
199 \subsection{Separation between ``real'' fonts and Metrics}
200 \label{ssec-sepmet}
201
202 Traditionally, most Japanese fonts used in typesetting are monospaced,
203 that is, most glyphs have same size (in most cases,
204 square-shaped). Hence, it is not rare that the contents of different
205 JFMs are totally same, and only differ in their names. For example, the
206 difference between |min10.tfm| and |goth10.tfm|, which are JFMs shipped
207 with p\TeX\ for seriffed \emph{mincho} family and sans-seriffed
208 \emph{gothic} family, are their |FAMILY| and |FACE| only. Moreover,
209 |jis.tfm| and |jisg.tfm|, which consists a parts of \emph{jis} font
210 metric which is used in Haruhiko Okumura's
211 \emph{jsclasses}~\cite{jsclasses}, are totally same as binary files.
212 Another example is: if one want to use many fonts which are not
213 installed in his \TeX\ distribution, of course he needs to prepare TFMs
214 for them. But, as long as he wants to use Japanese fonts with p\TeX, he
215 has to only copy and rename some JFM (\emph{e.g.},~copy |jis.tfm| to
216 |hoge.tfm|).
217
218 Considering this situation, we decided to separate ``real'' fonts and
219 metrics in \LuaTeX-ja, as shown in Figure~\ref{fig-jfdef};
220 \begin{itemize}
221 \item a control sequence |\jfont| must be used for japanese fonts, instead of |\font|.
222 \item \LuaTeX-ja automatically loads the |luaotfload| package, so
223       |file:| prefix and features can be used as the line~1 in
224       Figure~\ref{fig-jfdef}.
225 \item The |jfm| key specifies the metric for the font. In
226       Figure~\ref{fig-jfdef}, both fonts will use a metric stored in a Lua script named 
227       |jfm-ujis.lua|. This metric is the standard metric in  \LuaTeX-ja, and is based on JFMs used in the \emph{otf} package~\cite{otf}.
228 \item The |psft:| prefix can be used to specify name-only, noembedded
229       fonts. 
230 \end{itemize}
231 We note that |-kern| in features is important, since if kerning information from real font itself will clash with spacing from the metric.
232
233 \begin{figure}
234 \begin{verbatim}
235 \jfont\foo=file:ipaexm.ttf:jfm=ujis;script=latn;-kern;+jp04 at 12pt
236 \jfont\bar=psft:Ryumin-Light:jfm=ujis at 10pt
237 \end{verbatim}
238 \caption{Typical declarations of Japanese fonts.}
239 \label{fig-jfdef}
240 \end{figure}
241
242 \subsection{Insertion of Kerns and/or Glues for Japanese Typesetting: the Timing}
243 As described in \cite{luatexref}, \LuaTeX's kerning and ligaturing
244 process is totally different from that of \TeX82.
245 \TeX82's process is done just when a (sequence of) character is appended
246 to current list. Thus we can interrupt this process by writing |f{}irm|
247 (this gives `f\hbox{}irm' in \TeX82). However, \LuaTeX's process is
248 \emph{node-based}, that is, the process will be done when a horizontal
249 box of a paragraph is ended, so |f{}irm| and |firm| yield the same
250 output under \LuaTeX.
251
252 The situation for Japanese characters is basically same, but not
253 entirely.  Glues (and kerns) those will be needed for Japanese
254 typesetting will be divided into the following three categories:
255 \begin{description}
256 \item[Glue (or Kern) from the Metric of Japanese Fonts] 
257 \item[Default Glue Between a Japanese Character and an Alphabetic Character] 
258 Usually 1/4 of fullwidth with some stretch and shrink for justifying each line.
259 \item[Default Glue Between Two Consecutive Japanese Characters] 
260 The main reason of this glue is to enable line-breaking almost everywhere in Japanese texts. In most cases, its natural width is zero, and
261 some stretch/shrink for justifying each line. 
262 \end{description}
263 In p\TeX, these three kinds of glues are treated differently. The first
264  category (\emph{JFM glue}, for short) is inserted when a (sequence of)
265  Japanese character is appended to current list, same as alphabetic
266  characters in \TeX82. This means that one can interrupt the insertion
267  process by saying |{}|.  The second category (\emph{xkanjiskip}, for
268  short) is inserted just before `hpack' or line-breaking of a paragraph;
269  this timing is somewhat similar to that of \LuaTeX's kerning
270  process. The third category (\emph{kanjiskip}, for short) is not
271  appeared as a node anywhere; only appears implicitly in calculation of the
272  width of a horizontal box or that of linebreaking. These specifications made
273  p\TeX's behavior very hard to understand.
274
275 \LuaTeX-ja inserts glues in all three categories simultaneously inside
276 |hpack_filter| and |pre_linebreak_filter| callbacks.  The reasons of
277 this specification are to behave like alphabetic characters in \LuaTeX\
278 (as described in the first paragraph), and to clarify the specification
279 for \LuaTeX-ja's process. 
280
281 \subsection{Insertion of Kerns and/or Glues for Japanese Typesetting: the Spec}
282 \begin{figure}
283 \begin{center}
284 \begin{tabular}{llllllll}
285 \toprule
286 &\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}&\multicolumn{1}{c}{(4)}\\
287 Input      &|あ】{}【〙\/〘|        &|い』\/a| &|う)\hbox{}(| &|え]\special{}[|\\\midrule
288 p\TeX      &あ】\hbox{}【〙\hbox{}〘&い』\/a   &う)\hbox{}(   &え]\hbox{}[\\
289 \LuaTeX-ja &あ】{}【〙\/〘          &い』\/a   &う)\hbox{}(   &え]\special{}[\\
290 \bottomrule
291 \end{tabular}
292 \end{center}
293 \caption{Examples of differences between  p\TeX\ and \LuaTeX-ja,}
294 \label{fig-jfmglue}
295 \end{figure}
296
297 \begin{figure}
298 \begin{center}
299 \fontsize{40}{40}\selectfont\fboxsep=0mm
300 \fbox{\vrule width0pt height\cht depth\cdp あ}%
301 \fbox{\vrule width0pt height\cht depth\cdp 】\inhibitglue}%
302 \fbox{\vrule width0pt height\cht depth\cdp\kern.5\zw}%
303 \fbox{\vrule width0pt height\cht depth\cdp\kern.5\zw}%
304 \fbox{\vrule width0pt height\cht depth\cdp\hbox{}\inhibitglue【}%
305 \fbox{\vrule width0pt height\cht depth\cdp 〙\inhibitglue}%
306 \fbox{\vrule width0pt height\cht depth\cdp\kern.5\zw}%
307 \fbox{\vrule width0pt height\cht depth\cdp\kern.5\zw}%
308 \fbox{\vrule width0pt height\cht depth\cdp \hbox{}\inhibitglue〘}%
309 \end{center}
310 \caption{Detail of (1) in Figure~\ref{fig-jfmglue}.}
311 \label{fig-ptexjfm}
312 \end{figure}
313
314 Now we will take a look inside the insertion process itself. 
315
316 \begin{description}
317 \item[Ignored Nodes]
318 As noted in the previous subsection, the insertion process in p\TeX\ is
319            interrupted by saying |{}| or anything else. This leads the
320            second row in Figure~\ref{fig-jfmglue}, or
321            Figure~\ref{fig-ptexjfm}. ``The process is interrupted'' means that p\TeX\
322            does not think the letter `】\inhibitglue' is followed by `\inhibitglue【', hence two
323            half-width glues are inserted between between `】\inhibitglue' and `\inhibitglue【',
324            where one is from `】\inhibitglue' and another is from `\inhibitglue【'.
325
326
327            On the other hand, in \LuaTeX-ja, the process is done inside
328            |hpack_filter| and |pre_linebreak_filter| callbacks. Hence,
329            \emph{anything that does not make any nodes will be
330            ignored,}\ in \LuaTeX-ja, as shown in (1) in
331            Figure~\ref{fig-jfmglue}. \LuaTeX-ja also ignores any nodes
332            which does not make any contribution to current horizontal
333            list---\emph{ins\_node}, \emph{adjust\_node},
334            \emph{mark\_node}, \emph{whatsit\_node} and
335            \emph{penalty\_node}---, as shown in (4).
336
337 By the way, around a \emph{glyph\_node} $p$ there may be some nodes
338            attached to $p$. These are an accent and kerns for
339            positioning it, and kerns from italic correction for $p$, and
340            it is natural that these attachments should be ignored in the
341            process. Hence \LuaTeX-ja takes this approach, as the latest
342            version of p\TeX\ (p3.2). This explains  (2) in the figure. 
343
344 Summerizing, to 
345
346 \item[Fonts with the Same Metric]
347 Recall that \LuaTeX-ja separated ``real'' fonts and metrics, as in Subsection~\ref{ssec-sepmet}. 
348 Consider the following input, where we assume that all Japanese fonts
349            use same metric, and |\gt| selects \emph{gothic} family:
350 \begin{quote}
351 \begin{verbatim}
352 明朝)\gt (ゴシック
353 \end{verbatim}
354 \end{quote}
355 If the above input is processed by p\TeX, since the insertion process is
356            interrupt by |\gt|, the result looks like
357 \begin{quote}
358 \mc 明朝)\hbox{}\gt (ゴシック
359 \end{quote}
360 But this is unnatural, since two Japanese fonts in the output uses the
361 same metric, \emph{i.e.}, the same typesetting rule.  Hence, we decided
362 that Japanese fonts with the same metric are treated as one font in the
363 insertion process of \LuaTeX-ja. Thus, the output from the above input
364 in \LuaTeX-ja is:
365 \begin{quote}
366 \mc 明朝)\gt (ゴシック
367 \end{quote}
368
369 \end{description}
370
371
372 \section{Current Status of the Development}
373 At the moment, \LuaTeX-ja can be used under plain \TeX, and under
374 \LaTeXe. Generally speaking, one has to read |luatexja.sty|, by
375 |\input| command or |\usepackage|~(\LaTeXe) if you merely want to typeset Japanese character. 
376 We look more detail by parts.
377
378 \subsection{``Engine Extension''}
379 The lowest part of \LuaTeX-ja corresponds the p\TeX\ extension as
380 \emph{\TeX\ engine}. The development of \LuaTeX-ja is started from this
381 part.  We, the project menbers, think that this part is almost
382 done. Other features of \LuaTeX-ja which we have not described are the
383 followings:
384 \begin{description}
385 \item[Adjusting the baseline of alphabetic characters and/or Japanese characters]
386
387 \item[Setting the range of ``Japanese characters''] This feature is
388            inspired by up\TeX. up\TeX\ has an additional primitive named
389            |\kcatcode| for setting a character is treated as alphabetic
390            charaacter, \emph{kana}, \emph{kanji}, \emph{Hangul},
391            or~\emph{other CJK character}, and the assignment of
392            |\kcatcode| can be done by a block of Unicode\footnote{There
393            are some exceptions. For example, U+FF00--FFEF (Halfwidth and
394            Fullwidth Forms) are divided into three blocks in up\TeX.}.
395
396 \LuaTeX-ja uses a slightly different approach. Because there are many Unicode
397            blocks in Basic Multilingual Plane which are not included in
398            most Japanese fonts, ...
399 Furthermore, the basic Japanese character set JIS~X~0208 are not just
400            union of Unicode blocks. For example, the intersection of
401            JIS~X~0208 and Latin-1 Supplement consists of the following
402            characters:
403 Considering these two points, ...
404
405 \end{description}
406 Note that \LuaTeX-ja doesn't support for vertical typesetting, \emph{tategaki}, for now. 
407
408 \subsection{Patches for plain \TeX\ and \LaTeXe}
409 p\TeX\ has patches for plain \TeX, namely |ptex.tex|, that for \LaTeXe\
410 macro (this patch and \LaTeXe\ consist \emph{p\LaTeXe}), and
411 |kinsoku.tex| which includes the default setting of \emph{kinsoku
412 shori}, the Japanese hyphenation.  We ported them to \LuaTeX-ja, except
413 the codes related to vertical typesetting. We remark two points related to the porting:
414 \begin{description}
415 \item[The Default Ranges of Japanese Characters] 
416
417
418 \item[The behavior of\/ {\tt\char92fontfamily\/} command]
419 The |\fontfamily| command in p\LaTeXe\ changes the current alphabetic
420            font family and/or the current Japanese font family,
421            depending the argument. More concretely,
422            |\fontfamily{|$\langle\hbox{\it arg\/}\rangle$|}| changes the
423            current alphabetic font family to $\langle\hbox{\it
424            arg\/}\rangle$, if and only if one of the following
425            conditions are satisfied:
426 \begin{itemize}
427 \item Alphabetic font family named $\langle\hbox{\it arg\/}\rangle$ in
428       \emph{some} alphabetic encoding already defined in the document.
429 \item There exists an alphabetic encoding $\langle\hbox{\it
430       enc\/}\rangle$ already defined in the document such that a font
431       definition file $\langle\hbox{\it enc\/}\rangle\langle\hbox{\it
432       arg\/}\rangle$|.fd| exists.
433 \end{itemize}
434 The same criterion is used for changing Japanese font family.
435
436 To make possible this behavior, one has to create a list of already
437            defined alphabetic encodings. Hence it works in p\LaTeXe, ...
438 However, since \LuaTeX-ja is loaded as a package, it will not
439            work. Hence \LuaTeX-ja adopted different approach, namely
440            |\fontfamily{|$\langle\hbox{\it arg\/}\rangle$|}| changes the
441            current alphabetic font family to $\langle\hbox{\it
442            arg\/}\rangle$, if and only if:
443 \begin{itemize}
444 \item Alphabetic font family named $\langle\hbox{\it arg\/}\rangle$ in the current alphabetic encoding $\langle\hbox{\it enc\/}\rangle$.
445 \item A  font definition file $\langle\hbox{\it enc\/}\rangle\langle\hbox{\it
446       arg\/}\rangle$|.fd| exists.
447 \end{itemize}
448
449
450 \end{description}
451
452
453
454 \subsection{Classes for Japanese Documents}
455 To produce ``high-quality'' Japanese documents, we need not only that
456 Japanese characters are correctly placed, but also class files for
457 Japanese documents. In p\TeX, there are two major families of classes:
458 \emph{jclasses} which is distributed with the official p\LaTeXe\ macros,
459 and \emph{jsclasses}~\cite{jsclasses} which has developed by Haruhiko
460 Okumura and now widely used in Japanese \TeX\ users.  At the present,
461 \LuaTeX-ja simply contains their counterparts: \emph{ltjclasses} and
462 \emph{ltjsclasses}. However, the policy on classess is not determined
463 now, and we hope to have another family of classes which are useful in
464 commercial printing.  In the author's opinion, \emph{ltjclasses} is
465 better to stay as an example of porting of class files for \pTeX\ to
466 \LuaTeX-ja.
467
468
469 \section{Implementation}
470 \subsection{Handling of Japanese Fonts}
471 In p\TeX, there are three slots for maintaining current fonts, namely
472 |\font| for alphabetic fonts, |\jfont| for Japanese font (in horizontal
473 direction) and |\tfont| for Japanese font (in vertical direction). With
474 these slots, we can select the current font for alphabetic characters
475 and that for Japanese characters separately in p\TeX.  However, \LuaTeX\
476 has only one slot for maintaining the current font, as \TeX82.  This
477 situation leads a problem: how can we maintain the ``current Japanese
478 font''?
479
480 There are three approaches for this problem. One approach is to make a
481 mapping table from alphabetic fonts to corresponding Japanese fonts
482 (here we don't assume that NFSS2 is available), and when current
483 alphabetic font is changed, the current Japanese font also changes
484 according to the table.  Another approach is that we always use
485 composite fonts with alphabetic fonts and Japanese fonts. The third
486 approach is that the information of the current Japanese font is stored
487 in an attribute. We adopted the third approach, since \LuaTeX-ja is much
488 affected by p\TeX\ as we noted in Subsection~\ref{ssec-pol}.
489
490 As in Figure~\ref{fig-jfdef}, \LuaTeX-ja uses |\jfont| for defining
491 Japanese font, as p\TeX.  However, since the information of the current
492 Japanese font is stored into an attribute, control sequences defined by
493 |\jfont| (\emph{e.g.},~|\foo| and |\bar| in Figure~\ref{fig-jfdef}) is
494 not representing a font by the means of original \TeX. In other words,
495 these control sequence cannot be an argument of |\the| or |\textfont|, and they are just an assignments to an attribute, in fact.
496
497
498 \subsection{Overview of the Processes}
499 Now we describe an outline of the \LuaTeX-ja's process briefly.
500 \begin{description}
501 \item[Treatment of Linebreaks after Japanese Characters] We described
502            this already at Subsection~\ref{ssec-line}. Done in the
503            |process_input_buffer| callback.
504 \item[Font Replacement] In the |hyphenate| callback, we looks into for
505            each \textit{glyph\_node}~$p$. If its character is considered
506            to be a Japanese character, the font used in $p$ is replaced
507            by the value of |\ltj@curjfnt| that is associated
508            with~$p$. Also we subtract the subtype of $p$ by 1 to
509            suppress hyphenation around it by \LuaTeX, since later
510            processes of \LuaTeX-ja take care of all things about
511            Japanese charaters.
512 \end{description}
513 %
514 Following processes are all executed in |pre_linebreak_filter| and |hpack_filter| callback. These are main routines of \LuaTeX-ja:
515
516 \begin{description}
517 \item[Examination of Stack Level] We traverse the horizontal list which is the content of a horizontal box 
518 to determine what is the level of \LuaTeX-ja's internal stack in the end
519            of the list. This is needed because of the place of
520            |hpack_filter| in the source of \LuaTeX. We will discuss more detail at Subsection~\ref{ssec-stack}.
521
522 \item[Insertion of Glues/Kerns for Japanese Typesetting]
523 This part is already described at Subsection~\ref{ssec-jglue}. 
524
525 \item[Adjustument of Places of (Japanese) Characters]
526 Under \LuaTeX-ja, the size of the virtual body of a Japanese character
527            and its position (\emph{i.e.}, offset) are determined by the
528            metric, since the optimal width of a character in
529            typesetting---in most cases, this is specified width in the
530            metric---and the actual width in TrueType/Opentype fonts
531            often differ. For example, the width the fullwidth open brace
532            `\inhibitglue {' is considered to be half-width in
533            typesetting, although this character is full-width in
534            TrueType fonts like IPA~Mincho.
535
536 To adjust size/places of Japanese characters, \LuaTeX-ja encapsules a
537            \textit{glyph\_node} which containing a Japanese character
538            into a horizontal box which size is specified in the metric.
539 As the case of `\inhibitglue {', a half-widthed horizontal box 
540 \end{description}
541
542 \subsection{Stack Management}
543 \label{ssec-stack}
544
545 As we noted on Subsection~\ref{ssec-csname}, parameters that the values
546 at the end of a horizontal box or that of a paragraph are effective in
547 whole box or paragraph cannot be implemented by internal integers or
548 other types. We explain it in this section.
549
550
551
552 \subsection*{About the Project}
553 \subsection*{Acknowledgements}
554
555
556 %%% The style of the bibiliogrphy is `amsplain'.
557 \providecommand{\bysame}{\leavevmode\hbox to3em{\hrulefill}\thinspace}
558 \providecommand{\href}[2]{#2}
559 \begin{thebibliography}{9}
560
561 %\bibitem{Knuth}
562 %Donald E.~Knuth, \emph{The \TeX book}, Addison-Wesley, 1986.
563
564 \bibitem{ptex}
565 ASCII MEDIA WORKS, \textbf{アスキー日本語\TeX\ (p\TeX)}\ (in Japanese). \url{http://ascii.asciimw.jp/pb/ptex/}
566
567 %\bibitem{Eijkhout}
568 %Victor Eijkhout, \emph{\TeX\ by Topic, A \TeX nician's Reference}, Addison-Wesley, 1992. \url{http://www.cs.utk.edu/~eijkhout/texbytopic-a4.pdf}
569
570 \bibitem{luaums}
571 Hironori Kitagawa, \textbf{LuaTeXで日本語}\ (in Japanese). \url{http://oku.edu.mie-u.ac.jp/tex/mod/forum/discuss.php?d=378}
572
573 \bibitem{luajalayout}
574 Kazuki Maeda\ (前田一貴), \textbf{luajalayout パッケージ —LuaLaTeX による日本語組版—}\ (in Japanese).
575 \url{http://www-is.amp.i.kyoto-u.ac.jp/lab/kmaeda/lualatex/luajalayout/}
576
577 \bibitem{luajp-test}
578 Atsuhito Kohda, \textbf{LuaTeXと日本語}\ (in Japanese). \url{http://www1.pm.tokushima-u.ac.jp/~kohda/tex/luatex-old.html}
579
580 \bibitem{joylua}
581 Yannis Haralambous. \textbf{The Joy of LuaTeX}. \url{http://luatex.bluwiki.com/}
582
583 \bibitem{luatexref}
584 \textbf{The \LuaTeX reference}
585
586 \bibitem{jsclasses}
587 Haruhiko Okumura\ (奥村晴彦), \textbf{pLaTeX2e 新ドキュメントクラス}\ (in Japanese). \url{http://oku.edu.mie-u.ac.jp/~okumura/jsclasses/}
588
589 \bibitem{ptexjp}
590 Haruhiko Okumura\ (奥村晴彦), \textbf{p\TeX\ and Japanese Typesetting}, The Asian Journal of \TeX\ \textbf{2}~(2008), 43--51.
591
592
593 \end{thebibliography}
594
595 \end{document}