+
+
+%<en>\section{Linebreak after Japanese Character}
+%<ja>\section{和文文字直後の改行}
+\label{sec-lbreak}
+%<en>\subsection{Reference: Behavior in \pTeX}
+%<ja>\subsection{参考: \pTeX の挙動}
+%<*en>
+In~\pTeX, a line break after a Japanese character doesn't emit a space,
+since words are not separated by spaces in Japanese writings. However,
+this feature isn't fully implemented in \LuaTeX-ja due to the
+specification of callbacks in~\LuaTeX. To clarify the difference between
+\pTeX~and~\LuaTeX, We briefly describe the handling of a line break in~\pTeX, in
+this subsection.
+
+\pTeX's input processor can be described in terms of a finite state
+automaton, as that of~\TeX\ in~Section~2.5 of~\cite{texbytopic}. The
+internal states are as follows:
+\begin{itemize}
+\item State~$N$: new line
+\item State~$S$: skipping spaces
+\item State~$M$: middle of line
+\item State~$K$: after a Japanese character
+\end{itemize}
+The first three states---$N$, $S$~and~$M$---are as same as \TeX's input
+processor. State~$K$ is similar to state~$M$, and is entered after
+Japanese characters. The diagram of state transitions are indicated in
+Figure~\ref{fig-ptexipro}. Note that \pTeX\ doesn't leave state~$K$
+after `beginning/ending of a group' characters.
+%</en>
+
+%<*ja>
+欧文では文章の改行は単語間でしか行わない.そのため,\TeX では,(文字の直後の)改行は
+空白文字と同じ扱いとして扱われる.一方,和文ではほとんどどこでも改行が可能なため,
+\pTeX では和文文字の直後の改行は単純に無視されるようになっている.
+
+このような動作は,\pTeX が\TeX からエンジンとして拡張されたことによって可能になったことである.
+\pTeX の入力処理部は,\TeX におけるそれと同じように,有限オートマトンとして記述することができ,
+以下に述べるような4状態を持っている.
+
+\begin{itemize}
+\item State~$N$: 行の開始.
+\item State~$S$: 空白読み飛ばし.
+\item State~$M$: 行中.
+\item State~$K$: 行中(和文文字の後).
+\end{itemize}
+また,状態遷移は,図~\ref{fig-ptexipro} のようになっており,図中の数字は
+カテゴリーコードを表している.最初の3状態は\TeX の入力処理部と同じであり,
+図中から状態$K$と「$j$」と書かれた矢印を取り除けば,\TeX の入力処理部と同
+じものになる.
+
+この図から分かることは,
+\begin{quote}
+行が和文文字(とグループ境界文字)で終わっていれば,改行は無視される
+\end{quote}
+ということである.
+%</ja>
+
+\begin{figure}[!tb]
+\begin{gather*}
+ \def\sp{\texttt{\char32}}
+ \xymatrix{&&
+ {\text{scan a cs}}\ar@(r,ul)[dr]&\\
+\ar[r]&
+ *++[o][F-]{N}\ar[ur]^0\ar[dd]_{d,\ g}\ar[u]^{5\ (\texttt{\char92par})}
+ \ar@{->}@(d,l)[ddrr]_(0.45){j}&&
+ *++[o][F-]{S}\ar@(l,dr)[ul]^0\ar@(l,ur)[ddll]_{d,\ g}\ar[u]_{5}
+ \ar@{->}@(r,r)[dd]^{j}\\&\\&
+ *++[o][F-]{M}\ar[uuur]^0\ar@(r,dl)[uurr]_(0.55){10\ (\sp)}
+ \ar[d]_{5\ ({\sp})}\ar@{->}@(dr,dl)[rr]_{j}&&
+ *++[o][F-]{K}\ar@{->}@(ul,d)[uuul]^0\ar@{->}[ll]^{d}
+ \ar@{->}@(ur,dr)[uu]^{10\ (\sp)}\ar@{->}[d]_5\\
+ &&&
+ }\\
+ d:=\{3,4,6,7,8,11,12,13\},\quad g:=\{1,2\},\quad j:=(\text{Japanese characters})
+\end{gather*}
+\begin{itemize}
+\item Numbers represent category codes.
+\item Category codes 9~(ignored), 14~(comment)~and~15~(invalid) are omitted in above diagram.
+\end{itemize}
+\caption{State transitions of \pTeX's input processor.}
+\label{fig-ptexipro}
+\end{figure}
+
+
+%<en>\subsection{Behavior in \LuaTeX-ja}
+%<ja>\subsection{\LuaTeX-ja の挙動}
+%<*en>
+States in the input processor of \LuaTeX\ is the same as that of \TeX,
+and they can't be customized by any callbacks. Hence, we can only use
+\verb+process_input_buffer+ and \verb+token_filter+ callbacks for to
+suppress a space by a line break which is after Japanese characters.
+
+However, \verb+token_filter+ callback cannot be used either, since a
+character in category code 5~(end-of-line) is converted into an space
+token \emph{in the input processor}. So we can use only the
+\verb+process_input_buffer+ callback. This means that suppressing a
+space must be done \emph{just before} an input line is read.
+
+Considering these situations, handling of an end-of-line in \LuaTeX-ja are as follows:
+\begin{quote}
+A character U+FFFFF (its category code is set to 14~(comment) by
+\LuaTeX-ja) is appended to an input line, \emph{before \LuaTeX\ actually
+process it}, if and only if the following two conditions are satisfied:
+\begin{enumerate}
+\item The category code of the character $\langle${return}$\rangle$
+ (whose character code is 13) is 5~(end-of-line).
+\item The input line matches the following `regular expression':
+\[
+ (\text{any char})^*(\textbf{JAchar})
+ \bigl(\{\text{catcode}=1\}\cup\{\text{catcode}=2\}\bigr)^*
+\]
+\end{enumerate}
+\end{quote}
+
+\paragraph{Remark}
+The following example shows the major difference from the behavior of \pTeX:
+\begin{LTXexample}
+\ltjsetparameter{autoxspacing=false}
+\ltjsetparameter{jacharrange={-6}}xあ
+y\ltjsetparameter{jacharrange={+6}}zあ
+u
+\end{LTXexample}
+\begin{itemize}
+\item There is no space between `x' and `y', since the line~2 ends with a \textbf{JAchar} `あ'
+(this `あ' considered as an \textbf{JAchar} at the ending of line~1).
+\item There is no space between `あ' (in the line~3) and `u', since the
+ line~3 ends with an \textbf{ALchar}
+(the letter `あ' considered as an \textbf{ALchar} at the ending of line~2).
+\end{itemize}
+%</en>
+
+%<*ja>
+\LuaTeX の入力処理部は\TeX のそれと全く同じであり,callbackによりユーザが
+カスタマイズすることはできない.このため,改行抑制の目的でユーザが利用で
+きそうなcallbackとしては,\verb+process_input_buffer+や
+\verb+token_filter+に限られてしまう.しかし,\TeX の入力処理部をよく見る
+と,後者も役には経たないことが分かる:改行文字は,入力処理部によってトー
+クン化される時に,カテゴリーコード10の32番文字へと置き換えられてしまうた
+め,\verb+token_filter+で非標準なトークン読み出しを行おうとしても,空白文
+字由来のトークンと,改行文字由来のトークンは区別できないのだ.
+
+すると,我々のとれる道は,\verb+process_input_buffer+を用いて
+\LuaTeX の入力処理部に引き渡される前に入力文字列を編集するというものしかない.
+以上を踏まえ,\LuaTeX-jaにおける「和文文字直後の改行抑制」の処理は,次のようになっている:
+
+\begin{quote}
+各入力行に対し,\textbf{その入力行が読まれる前の内部状態で}
+以下の2条件が満たされている場合,\LuaTeX-jaはU+FFFFF番の文字
+\footnote{この文字はコメント文字として扱われるように\LuaTeX-ja内部で設定をしている.}
+を末尾に追加する.よって,その場合に改行は空白とは見做されないこととなる.
+\begin{enumerate}
+\item 改行文字(文字コード13番)のカテゴリーコードが5~(end-of-line)である.
+\item 入力行は次の「正規表現」にマッチしている:
+\[
+ (\text{any char})^*(\textbf{JAchar})
+ \bigl(\{\text{catcode}=1\}\cup\{\text{catcode}=2\}\bigr)^*
+\]
+\end{enumerate}
+\end{quote}
+
+この仕様は,前節で述べた\pTeX の仕様にできるだけ近づけたものとなっている.最初の条件は,
+\texttt{verbatim}系環境などの日本語対応マクロを書かなくてすませるためのものである.
+しかしながら,完全に同じ挙動が実現できたわけではない.
+差異は,次の例が示すように,和文文字の範囲を変更した行の改行において見られる:
+\begin{LTXexample}
+\ltjsetparameter{autoxspacing=false}
+\ltjsetparameter{jacharrange={-6}}xあ
+y\ltjsetparameter{jacharrange={+6}}zあ
+u
+\end{LTXexample}
+もし\pTeX とまったく同じ挙動を示すならば,出力は
+「\hbox{\ltjsetparameter{autoxspacing=false}x yzあu}」となるべきである.しかし,実際には
+上のように異なる挙動となっている.
+\begin{itemize}
+\item 2行目は「あ」という和文文字で終わる(2行目を処理する前の時点では,
+ 「あ」は和文文字扱いである)ため,直後の改行文字は無視される.
+\item 3行目は「あ」という欧文文字で終わる(2行目を処理する前の時点では,
+ 「あ」は欧文文字扱いである)ため,直後の改行文字は空白に置き換わる.
+\end{itemize}
+このため,トラブルを避けるために,和文文字の範囲を\verb+\ltjsetparameter+で編集した場合,
+その行はそこで改行するようにした方がいいだろう.
+%</ja>
+
+
+%<en>\section{Insertion of JFM glues, \Param{kanjiskip} and \Param{xkanjiskip}}
+%<ja>\section{JFM グルーの挿入,\Param{kanjiskip} と \Param{xkanjiskip}}
+%<en>\subsection{Overview}
+%<ja>\subsection{概要}
+
+
+\LuaTeX-ja における和文処理グルーの挿入方法は,\pTeX のそれとは全く異なる.
+\pTeX では次のような仕様であった:
+\begin{itemize}
+\item JFMグルーの挿入は,和文文字を表すトークンを元に水平リストに(文字を表す)<char\_node>を
+追加する過程で行われる.
+\item \Param{xkanjiskip}の挿入は,hboxへのパッケージングや行分割前に行われる.
+\item \Param{kanjiskip}はノードとしては挿入されない.パッケージングや行分割の計算時に
+「和文文字を表す2つの<char\_node>の間には\Param{kanjiskip}がある」ものとみなされる.
+\end{itemize}
+しかし,\LuaTeX-jaでは,hboxへのパッケージングや行分割前に全ての
+\textbf{JAglue},即ちJFMグルー・\Param{xkanjiskip}・\Param{kanjiskip}の
+3種類を一度に挿入することになっている.これは,\LuaTeX において欧文の合字・
+カーニング処理がノードベースになったことに対応する変更である.
+
+\LuaTeX-jaにおける\textbf{JAglue}挿入処理では,次節で定義する
+「クラスタ」を単位にして行われる.大雑把にいうと,「クラスタ」は文字とそれに付随す
+るノード達(アクセント位置補正用のkernや,イタリック補正)をまとめたもの
+であり,2つのクラスタの間には,ペナルティ,\verb+\vadjust+,whatsitなど,行組版
+には関係しないものがある.
+
+
+%<en>\subsection{Step 0: definition of a `cluster'}
+%<ja>\subsection{Step 0: 「クラスタ」の定義}
+
+\begin{defn}
+A \emph{cluster} is a list of consecutive nodes in one of the following forms,
+with the \textit{id} of it:
+\begin{enumerate}
+\item Nodes whose value of\ \verb+\ltj@icflag+ is in $[3,15)$. These
+ nodes come from a hbox which is already packaged, by unpackaging
+ (\verb+\unhbox+).
+ The \textit{id} is \textit{id\_pbox}.
+\item A inline math formula, including two \textit{math\_node}s at the boundary of it:
+HOGE
+ The \textit{id} is \textit{id\_math}.
+\item A \textit{glyph\_node}~$p$ with nodes which relate with it:
+\begin{enumerate}
+\item A kern for the italic correction of~$p$.
+\item An accent attached to $p$ by \verb+\accent+.
+\end{enumerate}
+\[
+\overbrace{%
+ \Node{kern}{$\mathit{subtype}=2$}\longrightarrow
+\left\{\begin{array}{c}
+\Node{glyph}{accent}\\\noalign{\medskip}
+\Node{hbox}{accent (shifted vert.)}
+\end{array}\right\}\longrightarrow
+\Node{kern}{$\mathit{subtype}=2$}}^{\text{(a)}}
+\longrightarrow
+\Node{glyph}{$p$}\longrightarrow
+\overbrace{%
+\Node{kern}{italic corr.}}^{\text{(b)}}
+\]
+
+The \textit{id} is \textit{id\_jglyph} or
+\textit{id\_glyph}, according to whether the \textit{glyph\_node}
+represents a Japanese character or not.
+\item An box-like node, that is, an hbox, an vbox and an rule (\verb+\vrule+).
+The \textit{id} is \textit{id\_hlist} if the node is an
+ hbox which is not shifted vertically, or \textit{id\_box\_like}
+ otherwise.
+\item A glue, a kern whose subtype is not 2~(\textit{accent}), and a discretionary break.
+The \textit{id} is \textit{id\_glue}, \textit{id\_kern}
+ and \textit{id\_disc}, respectively.
+\end{enumerate}
+We denote a cluster by \textit{Np}, \textit{Nq} and \textit{Nr}.
+\end{defn}
+
+以降は日本語.
+
+一部のクラスタの\textit{id}の意味は次の通り:
+\begin{description}
+\item[\textit{id\_glyph}] 欧文文字(`ffi' のようなリガチャ由来の可能性あり).
+\item[\textit{id\_jglyph}] 和文文字.
+\item[\textit{id\_math}] インライン数式.「文字コード$-1$の欧文文字」として内部では扱われる.
+\item[\textit{id\_hlist}] 縦方向にシフトされていない hbox.
+\item[\textit{id\_pbox}] 「既に処理された」ノードのリスト.
+\item[\textit{id\_box\_like}] \textit{id\_hlist}とならないbox
+(縦方向にシフトされたhboxや,vbox)か,rule.
+\item[\textit{id\_disc}] discretionary break (\verb+\discretionary{pre}{post}{nobreak}+).
+\end{description}
+
+
+\end{document}