OSDN Git Service

Merge 'kitagawa_test' and renamed several parameters.
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Wed, 2 Apr 2014 12:09:48 +0000 (21:09 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Wed, 2 Apr 2014 12:09:55 +0000 (21:09 +0900)
doc/jfm-ujisc33.lua [new file with mode: 0644]
doc/luatexja-ruby.pdf [new file with mode: 0644]
doc/luatexja-ruby.tex [new file with mode: 0644]
src/addons/luatexja-ruby.sty [new file with mode: 0644]
src/ltj-ruby.lua [new file with mode: 0644]

diff --git a/doc/jfm-ujisc33.lua b/doc/jfm-ujisc33.lua
new file mode 100644 (file)
index 0000000..7879f58
--- /dev/null
@@ -0,0 +1,135 @@
+luatexja.jfont.define_jfm {
+   dir = 'yoko',
+   zw = 1.0, zh = 1.0,
+
+   [0] = {
+      align = 'left', left = 0.0, down = 0.0,
+      width = 1.0*0.67, height = 0.88, depth = 0.12, italic=0.0,
+      glue = {
+        [1] = { 0.5*0.67 , 0.0, 0.5  },
+        [3] = { 0.25*0.67, 0.0, 0.25 }
+      }
+   },
+
+   [1] = { -- 開き括弧類
+      chars = {
+        '‘', '“', '〈', '《', '「', '『', '【', '〔', '〖', 
+        '〘', '〝', '(', '[', '{', '⦅'
+      },
+      align = 'right', left = 0.0, down = 0.0,
+      width = 0.5*0.67, height = 0.88, depth = 0.12, italic=0.0,
+      glue = {
+        [3] = { 0.25*0.67, 0.0, 0.25 }
+      }
+   },
+
+   [2] = { -- 閉じ括弧類
+      chars = {
+        '’', '”', '、', '〉', '》', '」', '』', '】', '〕', 
+        '〗', '〙', '〟', ')', ',', ']', '}', '⦆'
+      },
+      align = 'left', left = 0.0, down = 0.0,
+      width = 0.5*0.67, height = 0.88, depth = 0.12, italic=0.0,
+      glue = {
+        [0] = { 0.5*0.67 , 0.0, 0.5  },
+        [1] = { 0.5*0.67 , 0.0, 0.5  },
+        [3] = { 0.25*0.67, 0.0, 0.25 },
+        [5] = { 0.5*0.67 , 0.0, 0.5  },
+        [6] = { 0.5*0.67 , 0.0, 0.5  },
+        [7] = { 0.5*0.67 , 0.0, 0.5  }
+      }
+   },
+
+   [3] = { -- 中点類
+      chars = {'・', ':', ';'},
+      align = 'middle', left = 0.0, down = 0.0,
+      width = 0.5*0.67, height = 0.88, depth = 0.12, italic=0.0,
+      glue = {
+        [0] = { 0.25*0.67, 0.0, 0.25 },
+        [1] = { 0.25*0.67, 0.0, 0.25 },
+        [2] = { 0.25*0.67, 0.0, 0.25 },
+        [3] = { 0.5*0.67 , 0.0, 0.5  },
+        [4] = { 0.25*0.67, 0.0, 0.25 },
+        [5] = { 0.25*0.67, 0.0, 0.25 },
+        [6] = { 0.25*0.67, 0.0, 0.25 },
+        [7] = { 0.25*0.67, 0.0, 0.25 }
+      }
+   },
+
+   [4] = { -- 句点類
+      chars = {'。', '.'},
+      align = 'left', left = 0.0, down = 0.0,
+      width = 0.5*0.67, height = 0.88, depth = 0.12, italic=0.0,
+      glue = {
+        [0] = { 0.5*0.67 , 0.0, 0.0  },
+        [1] = { 0.5*0.67 , 0.0, 0.0  },
+        [3] = { 0.75*0.67, 0.0, 0.25 },
+        [5] = { 0.5*0.67 , 0.0, 0.0  },
+        [6] = { 0.5*0.67 , 0.0, 0.0  },
+        [7] = { 0.5*0.67 , 0.0, 0.0  }
+      }
+   },
+
+   [5] = { -- ダッシュ
+      chars = { '―', '‥', '…' },
+      align = 'left', left = 0.0, down = 0.0,
+      width = 1.0*0.67, height = 0.88, depth = 0.12, italic=0.0,
+      glue = {
+        [1] = { 0.5*0.67 , 0.0, 0.5  },
+        [3] = { 0.25*0.67, 0.0, 0.25 }
+      },
+      kern = {
+        [5] = 0.0
+      }
+   },
+
+   [6] = { -- 感嘆符・疑問符
+      chars = { '?', '!' },
+      align = 'left', left = 0.0, down = 0.0,
+      width = 1.0, height = 0.88, depth = 0.12, italic=0.0,
+      glue = {
+        [0] = { 0.5*0.67 , 0.0, 0.5  },
+        [1] = { 0.5*0.67 , 0.0, 0.5  },
+        [3] = { 0.25*0.67, 0.0, 0.25 },
+        [7] = { 0.5*0.67 , 0.0, 0.5  },
+      },
+      kern = {
+        [5] = 0.0
+      }
+   },
+
+   [7] = { -- 半角カナ
+      chars = {
+        '。', '「', '」', '、', '・', 'ヲ', 'ァ', 'ィ', 'ゥ', 
+        'ェ', 'ォ', 'ャ', 'ュ', 'ョ', 'ッ', 'ー', 'ア', 'イ', 
+        'ウ', 'エ', 'オ', 'カ', 'キ', 'ク', 'ケ', 'コ', 'サ', 
+        'シ', 'ス', 'セ', 'ソ', 'タ', 'チ', 'ツ', 'テ', 'ト', 
+        'ナ', 'ニ', 'ヌ', 'ネ', 'ノ', 'ハ', 'ヒ', 'フ', 'ヘ', 
+        'ホ', 'マ', 'ミ', 'ム', 'メ', 'モ', 'ヤ', 'ユ', 'ヨ', 
+        'ラ', 'リ', 'ル', 'レ', 'ロ', 'ワ', 'ン', '゙', '゚',
+        "AJ1-516", "AJ1-517", "AJ1-518", "AJ1-519", "AJ1-520", "AJ1-521", "AJ1-522", 
+        "AJ1-523", "AJ1-524", "AJ1-525", "AJ1-526", "AJ1-527", "AJ1-528", "AJ1-529", 
+        "AJ1-530", "AJ1-531", "AJ1-532", "AJ1-533", "AJ1-534", "AJ1-535", "AJ1-536", 
+        "AJ1-537", "AJ1-538", "AJ1-539", "AJ1-540", "AJ1-541", "AJ1-542", "AJ1-543", 
+        "AJ1-544", "AJ1-545", "AJ1-546", "AJ1-547", "AJ1-548", "AJ1-549", "AJ1-550", 
+        "AJ1-551", "AJ1-552", "AJ1-553", "AJ1-554", "AJ1-555", "AJ1-556", "AJ1-557", 
+        "AJ1-558", "AJ1-559", "AJ1-560", "AJ1-561", "AJ1-562", "AJ1-563", "AJ1-564", 
+        "AJ1-565", "AJ1-566", "AJ1-567", "AJ1-568", "AJ1-569", "AJ1-570", "AJ1-571", 
+        "AJ1-572", "AJ1-573", "AJ1-574", "AJ1-575", "AJ1-576", "AJ1-577", "AJ1-578", 
+        "AJ1-579", "AJ1-580", "AJ1-581", "AJ1-582", "AJ1-583", "AJ1-584", "AJ1-585", 
+        "AJ1-586", "AJ1-587", "AJ1-588", "AJ1-589", "AJ1-590", "AJ1-591", "AJ1-592", 
+        "AJ1-593", "AJ1-594", "AJ1-595", "AJ1-596", "AJ1-597", "AJ1-598",
+      },
+      align = 'left', left = 0.0, down = 0.0,
+      width = 0.5*0.67, height = 0.88, depth = 0.12, italic=0.0,      
+      glue = {
+        [1] = { 0.5*0.67 , 0.0, 0.5  },
+        [3] = { 0.25*0.67, 0.0, 0.25 }
+      }
+   },
+
+   [99] = { -- box末尾
+      chars = {'boxbdd', 'parbdd'},
+   },
+
+}
\ No newline at end of file
diff --git a/doc/luatexja-ruby.pdf b/doc/luatexja-ruby.pdf
new file mode 100644 (file)
index 0000000..f95a490
Binary files /dev/null and b/doc/luatexja-ruby.pdf differ
diff --git a/doc/luatexja-ruby.tex b/doc/luatexja-ruby.tex
new file mode 100644 (file)
index 0000000..5fa8f45
--- /dev/null
@@ -0,0 +1,807 @@
+%#! luajitlatex
+%%% a test of ruby.
+\documentclass[a4paper,10pt]{ltjsarticle}
+\usepackage{luatexja-otf,amsmath}
+
+\usepackage[kozuka-pr6n]{luatexja-preset}\normalsize
+\def\emph#1{\textbf{\textgt{#1}}}
+\def\headfont{\normalfont\bfseries\gtfamily}
+\makeatletter
+\DeclareRobustCommand\ttfamily
+        {\not@math@alphabet\ttfamily\mathtt
+         \romanfamily\ttdefault\ttjfam\selectfont}
+\makeatother
+\newjfontfamily\ttjfam{KozGoPr6N-Regular.otf}
+
+\usepackage[textwidth=45\zw, lines=45, footskip=6mm]{geometry}
+\usepackage{luatexja-adjust}%\ltjdisableadjust
+\advance\leftmargini-1\zw\advance\leftmarginii-1\zw
+
+
+\usepackage{luatexja-ruby,showexpl,booktabs}
+\lstset{
+  preset=\normalsize, basicstyle=\small\ttfamily, basewidth=0.5em,
+  explpreset={numberstyle=\tiny, numbers=left, numbersep=1em, columns=fixed},
+}
+\fboxsep=0mm
+
+\usepackage{hyperref,bookmark,xcolor}
+\hypersetup{%
+       unicode,
+       colorlinks,
+       allbordercolors=1 1 1,
+       allcolors=blue,
+       pdftitle={luatexja-ruby.sty}
+}
+
+
+\def\kata{\ltjsetruby{kata}} 
+\def\notalign{\setkeys[ltj]{ruby}{stretchhead = {1}{2}{1}, stretchend = {1}{2}{1}}}
+% 行頭・行末で揃えない
+
+\def\Node#1#2{\,\vcenter{\hbox{\fboxsep=1pt\fbox{\vbox{\small\halign{\hfil##\hfil\cr
+  #1\mathstrut\cr\noalign{\hrule height.4pt}\strut#2\cr}}}}\,}}
+\def\LuaTeX{Lua\TeX}
+
+% 三分ルビ用
+\DeclareFontShape{JY3}{mc}{mc}{n}{<-> [0.92487] 
+  KozMinPr6N-Regular:extend=0.67;jfm=ujisc33}{}
+
+\title{\texttt{luatexja-ruby.sty}}
+\begin{document}
+\catcode`\<=13
+\def<#1>{{\normalfont\rm\itshape$\langle$#1\/$\rangle$}}
+%\fontsize{13.19873}{15}\selectfont%
+
+\maketitle
+
+\begin{abstract}
+\texttt{luatexja-ruby.sty} は,\LuaTeX-jaの機能を利用してルビの組版処理を行う追加パッケージである.
+\LuaTeX, \LuaTeX-jaの内部処理に割り込むことにより,熟語ルビ中の行分割や,
+行頭形・行中形・行末形の自動検出,また進入許容量の自動設定などを可能とした.
+\end{abstract}
+
+\tableofcontents
+
+\newpage
+\section{\ltjruby{利|用|方|法}{り|よう|ほう|ほう}}
+パッケージ読み込みは,\verb+\usepackage{luatexja-ruby}+ で良く,
+必要ならば自動的に\LuaTeX-ja本体を読み込む.
+plain \LuaTeX でのロードはまだサポートしておらず,
+\LaTeXe のみサポートしている.
+
+\subsection{\ltjruby{用|語}{よう|ご}}
+「進入(intrusion)」「突出(protrusion)」という用語は,
+\href{http://zrbabbler.sp.land.to/pxrubrica.html}{\texttt{pxrubrica}\ パッケージ}%
+での用法に準ずる.
+
+\begin{quotation}
+進入あり:と\ltjruby{暁}{あかつき}の
+
+進入なし:{\setkeys[ltj]{ruby}{mode=0}と\ltjruby{暁}{あかつき}の}
+
+突出あり:{\setkeys[ltj]{ruby}{stretch={1}{2}{1}}\ltjruby{聴衆}{ちようしゆう}}
+
+突出なし:{\setkeys[ltj]{ruby}{stretch={0}{2}{0}}\ltjruby{聴衆}{ちようしゆう}}
+\end{quotation}
+
+\subsection{\ruby{命|令}{めい|れい}}
+\paragraph{\tt\textbackslash ltjruby}
+ルビ出力用命令の本体.\verb+\ruby+ という別名を定義している.
+\begin{quote}
+\tt \textbackslash ltjruby[<option>]\{親|文|字\}\{おや|も|じ\}
+\end{quote}
+のように使用する.
+第2・第3引数内の「\verb+|+」はグループの区切りを表す.詳細は\ref{ssec:grp}\nobreak 小節を参照.
+
+<option>には以下の内容をkey-valueリストで指定可能である:
+\begin{description}
+\def\makelabel#1{\tt#1}
+\item[pre=<real>] 前進入許容量をルビ全角単位で指定.
+負の長さを指定した場合は,ルビの状況や直前の文字に応じた自動指定を意味する.
+既定値は負(つまり,自動指定).
+
+\item[post=<real>] 同様に,後進入許容量を指定する.既定値は負(自動指定).
+
+\item[mode] 進入処理のモードを表すbit vector.下位2\,bitは,\texttt{pre}や
+\texttt{post}が負である場合にしか効力を発揮しない.既定値は$(0001)_2 = 1$.
+\begin{description}
+ \item[bit 0] 進入を無効にするならば0,有効にするならば1.
+ \item[bit 1] 前進入許容量$B$と後進入許容量$A$が異なった場合,
+そのまま処理する場合は0,小さい方に揃えるならば1.
+ \item[bit 2--3] ルビ文字の突出量$x$から実際の前進入量$b$,後進入量$a$の計算方法を指定する.
+親文字の文字数が$k+1$,親文字の前に入る空白量・間の空白量・後ろの空白量の比が$p:q:r$のとき,
+\begin{description}
+ \item[00] $b=\min\{B, xp/[p+kq+r]\}$, \ $a=\min\{A, xr/[p+kq+r]\}$
+ \item[01] $b=\min(B, x)$, \ $a=\min[A, \max(x-b,0)]$
+ \item[10] $a=\min(A, x)$, \ $b=\min[B, \max(x-a,0)]$
+ \item[11] $M=\min(B,A)$とおく.もし$x\le 2M$ならば$b=a=x/2$.そうでなければ
+\[
+ b=\min\left(B, M + \frac{(x-2M)p}{p+kp+r}\right),\qquad 
+ a=\min\left(A, M + \frac{(x-2M)r}{p+kp+r}\right)
+\]
+\end{description}
+
+組み方の具体例を実際に示す.例示のため,平仮名にはルビが1字まで,「立」にはルビを
+0.5字分までかけてよいことにしている.
+\begin{description}
+\item[00]{\setkeys[ltj]{ruby}{mode=1}%
+\ltjsetparameter{rubypreintrusion={`立,0.5}, rubypostintrusion={`立,0.5}}%
+は\ltjruby{美}{うつく}しい
+  \quad は\ltjruby{聴衆}{ちようしゆう}と\quad
+は\ltjruby{暁}{あかつき}立\quad
+は\ltjruby{聴衆}{ちようしゆう}立\par}
+\item[01]{\setkeys[ltj]{ruby}{mode=5}%
+\ltjsetparameter{rubypreintrusion={`立,0.5}, rubypostintrusion={`立,0.5}}%
+は\ltjruby{美}{うつく}しい
+  \quad は\ltjruby{聴衆}{ちようしゆう}と\quad
+は\ltjruby{暁}{あかつき}立\quad
+は\ltjruby{聴衆}{ちようしゆう}立\par}
+\item[10]{\setkeys[ltj]{ruby}{mode=9}%
+\ltjsetparameter{rubypreintrusion={`立,0.5}, rubypostintrusion={`立,0.5}}%
+は\ltjruby{美}{うつく}しい
+  \quad は\ltjruby{聴衆}{ちようしゆう}と\quad
+は\ltjruby{暁}{あかつき}立\quad
+は\ltjruby{聴衆}{ちようしゆう}立\par}
+\item[11]{\setkeys[ltj]{ruby}{mode=13}%
+\ltjsetparameter{rubypreintrusion={`立,0.5}, rubypostintrusion={`立,0.5}}%
+は\ltjruby{美}{うつく}しい\quad
+は\ltjruby{聴衆}{ちようしゆう}と\quad
+は\ltjruby{暁}{あかつき}立\quad
+は\ltjruby{聴衆}{ちようしゆう}立\par}
+\end{description} 
+
+\end{description}
+\item[stretchruby=\{<left>\}\{<middle>\}\{<right>\}] 親文字の合計長が
+ルビ文字の合計長より長い時に,ルビ文字の前・間・後に入れる空白の割合であり,
+それぞれ0--7の自然数で指定する.
+既定値は\ \verb+{1}{2}{1}+ である.
+<left>はルビ文字の先頭までの空き量,<middle>はルビ文字間の空き量,<right>はルビ文字の末尾からの
+空き量(の比)を表す.以下が例である.
+\begin{LTXexample}[width=0.3\textwidth, preset=\Large]
+\ltjruby[stretchruby=123,maxmargin=2]%
+  {◯◯◯◯}{◆◆}
+\end{LTXexample}
+\item[stretch=\{<left>\}\{<middle>\}\{<right>\}]
+行中形でルビ文字の方が長い場合,親文字の前・中・後に入れる空白の割合.
+既定値は\ \verb+{1}{2}{1}+ である.それ以外の代表的な値としては,例えば次のようなものがある.
+\begin{description}
+\item[親文字均等割禁止] \verb+{1}{0}{1}+\ など<middle>を0にした値
+\item[前突出禁止] \verb+{0}{1}{1}+
+\item[後突出禁止] \verb+{1}{1}{0}+
+\end{description}
+
+\item[stretchhead=\{<left>\}\{<middle>\}\{<right>\}] 行頭形〜.
+既定値は\ \verb+{0}{1}{1}+ である.
+\item[stretchend=\{<left>\}\{<middle>\}\{<right>\}] 行末形〜.
+既定値は\ \verb+{1}{1}{0}+ である.
+
+\item[maxmargin=<real>] 親文字の方がルビより長い時に,ルビの先頭と親文字の先頭,及び
+ルビ末尾と親文字の末尾の間に許される最大の空白量.\textbf{親文字全角単位}で指定し,既定値は0.5.
+
+\medskip
+\item[size=<real>] ルビ文字の親文字に対する大きさ.既定値は0.5.
+\item[intergap=<real>] ルビ文字と親文字との空きを親文字全角単位で指定.既定値は0.
+\item[rubysmash=<bool>] ルビの高さを0にするか.既定値は偽.次が例である.
+\begin{LTXexample}[width=0.3\textwidth, preset=\Large]
+\ \vrule width 0pt height 2\zw depth 1\zw
+\frame{\ltjruby[rubysmash=false]{本}{ほん}}\ 
+\frame{\ltjruby[rubysmash=true]{本}{ほん}}\ 
+\frame{\ltjruby[rubysmash=false,intergap=0.2]
+  {本}{ほん}}\ 
+\frame{\ltjruby[rubysmash=true,intergap=0.2]
+  {本}{ほん}}\ 
+\frame{\ltjruby[rubysmash=false,intergap=-1.5]
+  {本}{ほん}}
+\end{LTXexample}
+
+
+\item[kenten=<command>]各文字につく圏点の出力命令を指定する.既定値は「\verb+\ltjalchar`•+」
+であり,\texttt{U+2022} (Bullet)を\textbf{ALchar}として出力することを指定している.
+\item[fontcmd=<command>]ルビ用のフォント切り替え命令を指定する.
+このキーの内容が実行された後に\ \verb+\fontsize...\selectfont+\ が実行されるので,
+このキーの指定では最後に\ \verb+\selectfont+ を加える必要はない.
+
+\end{description}
+
+\medskip
+次の2つは,以上で説明した複数のオプションを一度に設定するためのものである.
+普通はこの2つのうちいずれかを設定するだけで足りるだろう.
+
+\begin{description}
+\def\makelabel#1{\tt#1}
+\item[naka] 以下のオプションを同時に設定する.主に中付きルビを組むときに用いる.
+\begin{verbatim}
+mode=1, stretch={1}{2}{1}, stretchruby={1}{2}{1}
+\end{verbatim}
+\item[kata] 同様に,肩付きルビ用に,次を設定する.
+\begin{verbatim}
+mode=9, stretch={1}{2}{1}, stretchruby={0}{0}{1}
+\end{verbatim}
+\end{description}
+
+\paragraph{\tt\textbackslash ltjsetruby\{<option>\}}
+<option>の既定値を指定する.\texttt{luatexja-ruby} 読み込み時の値は
+各項目の所で既に説明してあるが,次のようになっている.
+\begin{verbatim}
+  pre=-1, post=-1, mode=1, 
+  stretchruby={1}{2}{1}, stretch = {1}{2}{1},
+  stretchhead={0}{1}{1}, stretchend={1}{1}{0},
+  maxmargin=0.5, size=0.5, intergap=0, rubysmash=false,
+  kenten=\ltjalchar`•, fontcmd=\relax
+\end{verbatim}
+
+\paragraph{\texttt{\textbackslash ltjsetparamater} に追加されるキー}
+\begin{description}
+\item[\textsf{\mdseries rubypreintrusion}\tt =\{<chr\_code>, <pre\_int>\}]
+文字<chr\_code> に,その\textbf{直後}のルビによって掛けられるルビ文字列の最大長をルビ全角単位で指定.
+\item[\textsf{\mdseries rubypostintrusion}\tt =\{<chr\_code>, <post\_int>\}]
+文字<chr\_code> に,その\textbf{直前}のルビによって掛けられるルビ文字列の最大長をルビ全角単位で指定.
+\end{description}
+既定値は,\textsf{rubypreintrusion},~\textsf{rubypostintrusion}とも
+以下の文字に対しては1,その他の文字については0である:
+\begin{quote}
+ 平仮名(\texttt{U+3040}--\texttt{U+309F}),カギ括弧「」,読点「,」「、」,中黒「・」
+\end{quote}
+また,ここでは「文字コード$-1$の文字」は,「段落開始の \verb+\parindent+」を表す%
+\footnote{通常の\LuaTeX-jaにおける指定では文中数式境界を表していることに注意.}.
+この「文字」に対する\textsf{rubypreintrusion}の値も1である.
+
+\paragraph{\texttt{\textbackslash ltjkenten}}
+圏点を出力する命令で,\verb+\kenten+ という別名を定義している.
+\begin{quote}
+ \tt \textbackslash ltjkenten[<option>]\{親文字\}
+\end{quote}
+のように使用する.複数文字に圏点をつける場合でも,\verb+\ltjruby+ のように「\texttt{|}」を使って
+文字を区切る\textbf{必要はない}ことに注意してほしい.
+
+圏点として出力される文字は \texttt{kenten} キーによって指定し,
+圏点自身の大きさは(ルビと同様に)\texttt{size} キーで指定する.
+
+\subsection{グループの\ruby{指|定}{し|てい}}
+\label{ssec:grp}
+\begin{quote}
+\tt \textbackslash ltjruby[<option>]\{親|文|字\}\{おや|も|じ\}
+\end{quote}
+のように,\verb+\ltjruby+\ の第2・第3引数内の「\verb+|+」はグループの区切りを表す.
+グループの数は両者で一致しなければならず,
+\verb+\ltjruby{紋章}{もん|しよう}+ のようには\emph{できない}.
+
+1グループのみのルビ(単純グループルビ)はグループルビとして組まれる.そのため,
+もしモノルビを使いたければ,面倒でも
+\begin{LTXexample}[width=0.4\textwidth, preset=\Large]
+の\ltjruby{紋}{もん}\ltjruby{章}{しよう}が
+\end{LTXexample}
+のように,複数回使用すること.
+また,全てのグループにおいて「ルビ文字列の長さは親文字列以下」であれば,
+単純グループルビの並びとして扱われる.すなわち,次の2行は全くの等価となる.
+\begin{verbatim}
+\ltjruby{普|通|車}{ふ|つう|しや}
+\ltjruby{普}{ふ}\ltjruby{通}{つう}\ltjruby{車}{しや}
+\end{verbatim}
+
+\newpage
+複数グループかつ上記の条件を満たさない場合は,
+所謂「可動グループルビ」であり,ルビの前後や各グループの切れ目で行分割が可能となる.
+例えば
+\begin{verbatim}
+…の\ltjruby{表|現|力}{ひよう|げん|りよく}は…
+\end{verbatim}
+という入力からは得られる組版結果は,次のいずれかになる.
+\begin{center}
+ \begin{tabular}{ll}
+ \toprule
+ 改行なし(行中形)&\Large …の\ltjruby{表|現|力}{ひよう|げん|りよく}は…\\
+ 直前で改行&\Large \vrule \ltjruby[stretch=011]{表|現|力}{ひよう|げん|りよく}は…\\
+&\Large …の\ltjruby[stretch=110]{表}{ひよう}
+    \vrule\ltjruby[stretch=011]{現|力}{げん|りよく}は…\\
+&\Large …の\ltjruby[stretch=110]{表|現}{ひよう|げん}
+    \vrule\ltjruby[stretch=011]{力}{りよく}は…\\
+ 直後に改行&\Large …の\ltjruby[stretch=110]{表|現|力}{ひよう|げん|りよく}\vrule\\
+\bottomrule
+ \end{tabular}
+\end{center}
+\begin{itemize}
+ \item これらの行分割によってペナルティは発生しない.
+ \item 上記の例で見られるように,
+2ブロック以上をまとめて組むときは,全体を1つのグループルビのように組版する(JIS~X~4051と同様).
+『日本語組版処理の要件』では,
+附属書Fに「熟語の構成,さらにその熟語の前後にくる文字の種類を考慮して配置する方法」として
+別の方法を解説しているが,こちらの方法は現時点ではサポートしていないので,
+面倒でも手動で \texttt{pre}, \texttt{post} などを使って頑張って欲しい.
+ \item 実装方法の都合により,ルビの直前・直後・途中で2箇所以上の改行が起きる場合,例えば
+\begin{center}
+ \begin{tabular}{lll}
+ \toprule
+ \Large …の\ltjruby[stretch=110]{表}{ひよう}
+    \vrule\ltjruby[stretch=010]{現|力}{げん|りよく}\vrule&
+\Large \vrule\ltjruby[stretch=010]{表|現}{ひよう|げん}
+    \vrule\ltjruby[stretch=011]{力}{りよく}は…&
+\Large \vrule\ltjruby[stretch=010]{表|現|力}{ひよう|げん|りよく}\vrule\\
+\bottomrule
+ \end{tabular}
+\end{center}
+などの組み方は\emph{想定していない}.
+\end{itemize}
+
+\newpage
+
+\section{\ruby{注|意|点}{ちゆう|い|てん}}
+\begin{description}
+\item[ルビ文字のはみ出し]
+「日本語組版処理の要件」の図3.82のように,
+ルビ文字のはみ出しが繋がらないようにする処理について述べる.
+
+例えば,
+\begin{LTXexample}[preset=\Large,width=0.3\textwidth]
+\ltjruby{陵}{りよう}と\ltjruby{陵}{みささぎ}\\
+\ltjruby{陵}{りよう}と\ltjruby[pre=1]{陵}{みささぎ}
+\end{LTXexample} 
+において,1行目右側の「\ltjruby{陵}{みささぎ}」のルビが前の「と」にかかる量は次のように決まる:
+\begin{enumerate}
+\item 1回目の実行では,行分割前に「\ltjruby{陵}{りよう}」の後側進入量は前もって知ることはでき
+      ない.なので,「\ltjruby{陵}{りよう}」は行中形で組まれるものとして
+「\ltjruby{陵}{みささぎ}」前側進入許容量は
+\[
+ \underbrace{0.5\,\mathrm{zw}}_{\text{元々の許容量}}
+-\underbrace{0.25\,\mathrm{zw}}_{\text{前のルビの後側進入量(行中形)}}=0.25\,\mathrm{zw}
+\]
+となる.行分割後,「\ltjruby{陵}{りよう}」の実際の後側進入量は
+auxファイルに記述される.
+\item 2回目以降の実行では,auxファイルに保存された「\ltjruby{陵}{りよう}」の後側進入量
+を用いて,「\ltjruby{陵}{みささぎ}」前側進入許容量を次のように計算する:
+\[
+ \underbrace{0.5\,\mathrm{zw}}_{\text{元々の許容量}}
+-\underbrace{0.25\,\mathrm{zw}}_{\text{前のルビの後側進入量 (from aux)}}=0.25\,\mathrm{zw}.
+\]
+\end{enumerate}
+auxファイルに保存する際,各 \verb+\ltjruby+ 命令の呼び出しを識別するキーが必要になるが,
+そのキーとしては単純に「何個目の \verb+\ltjruby+ 命令か」である.
+
+なお,以上の処理は,1行目と2行目を比較すれば分かるように,
+「\ltjruby{陵}{みささぎ}」の\emph{前進入許容量指定(\texttt{pre})が自動}になっている場合のみ
+実施される.
+
+\item[段落末尾のルビ]
+段落がルビで終わった場合,そのルビが行末形で組まれることはない.
+これは,段落の「本当の」末尾には \verb+\penalty10000\parfillskip+ があるためで,
+ルビ処理用に作った最後のグルー(\ref{sec:impl}\nobreak 節の説明では$g_2$)が消去されないことによる.
+
+\verb+\parfillskip+ の長さ(や,場合によっては \verb+\rightskip+)を実測し,
+それによって処理を変えるのも可能だが,そのようなことはしなかった.
+段落がルビで終わることは普通ない(最低でも句点が続くだろう)と思うからである.
+
+
+
+\item[段落先頭のルビ]
+同様に,段落先頭のルビは行頭形にはならない.
+\texttt{pre}が負(つまり,自動指定)のとき,段落最初の \verb+\parindent+ 部分への
+進入は可能である.\verb+\parindent+ 部分への進入許容量は
+「文字$-1$」に対する\textsf{rubypreintrusion}(既定値は1,ルビ全角単位)と
+\ \verb+\parindent+ の長さのうち小さい方である.
+\begin{LTXexample}[preset=\Large,width=0.4\textwidth]
+\parindent1\zw\noindent 012345\par
+\ltjruby{陵}{みささぎ}は……\par
+\ltjruby{承}{うけたまわ}り……\par
+\parindent0.25\zw\ltjruby{陵}{みささぎ}は……
+\end{LTXexample}
+
+
+\end{description}
+
+\newpage
+\section{\ruby{実|装}{じつ|そう}について}
+\label{sec:impl}
+次の例で実装の大まかな方法を説明する.
+\begin{LTXexample}[preset=\Large]
+……を\ltjruby{流|暢}{りゆう|ちよう}に……
+\end{LTXexample}
+
+\begin{enumerate}
+\item \verb|\ltjruby|コマンド自体は,一旦次のnode listを値とするwhatsit~$W$を作って,
+現在の水平リストへと挿入する(必要ならば\verb|\leavevmode|も実行):
+\[
+ \Node{whatsit $w$}{value: 2}\longrightarrow 
+ \Node{hlist $s_1$}{「りゆう」}\longrightarrow
+ \Node{hlist $p_1$}{「流」}\longrightarrow
+ \Node{hlist $s_2$}{「ちよう」}\longrightarrow
+ \Node{hlist $p_2$}{「暢」}
+\]
+ここで,最初の$w$の値2は,ルビが2つのパーツ「\ltjruby{流}{りゆう}」「\ltjruby{暢}{ちよう}」からなっていることを
+表している.この値を$\mathit{cmp}$とおこう.
+$s_i$達の中の文字は既にルビの大きさである.
+\item \LuaTeX-jaの和文処理グルー挿入処理において,
+このwhatsit~$W$はまとめて
+「先頭が『流』,最後が『暢』であるようなhboxを \verb|\unhbox| で展開したもの」と扱われる.
+言い換えれば,ルビ部分を無視した単なる「流暢」という和文文字の並びとして扱われる\footnote{「流」「暢」の間のグルーは既に入っている,と扱われる.}.
+次のサンプルを参照
+\begin{LTXexample}[preset=\Large]
+\leavevmode\hbox{.}A\\
+%↑xkanjiskip 
+\ltjruby{.}{}A
+%↑2分
+\end{LTXexample}
+\item 和文処理グルーの挿入が終わった後で,可動グループルビのためのノードの挿入に入る.
+\begin{enumerate}
+\item $W$の前後に$2\mathit{cmp}+1=5$個のノードが挿入され,$W$の周辺は次のようなノード列になる.
+\begin{align*}
+ (\text{other nodes})&\longrightarrow
+ \Node{glue $g_0$}{}\longrightarrow \Node{whatsit~$W$}{元からある}\longrightarrow \Node{rule $r_1$}{}
+\\&\longrightarrow
+ \Node{glue $g_1$}{}\longrightarrow \Node{rule $r_2$}{}\longrightarrow 
+ \Node{glue $g_2$}{}\longrightarrow (\text{other nodes})
+\end{align*}
+
+\item このようにノードを挿入する目的は,\TeX の行分割処理自体に影響を加えずに可動グループルビ
+を実現させることにある.
+\begin{gather*}
+ (\text{other nodes})\longrightarrow
+ \Node{glue $g_0$}{}\longrightarrow \Node{whatsit~$W$}{元からある}\longrightarrow \Node{rule $r_1$}{}\\
+\noalign{\hrulefill 行の境目\hrulefill}
+\Node{rule $r_2$}{}\longrightarrow 
+ \Node{glue $g_2$}{}\longrightarrow (\text{other nodes})
+\end{gather*}
+のようになったとしたら,「\ltjruby{流}{りゆう}」「\ltjruby{暢}{ちよう}」の間で行分割が起きた,ということがわかり,
+$g_i$,~$r_i$達のノードを適切に置き換えればよい(後で詳しく説明する).
+
+\begin{figure}\centering\small
+\begin{tabular}{cllll}
+\toprule
+\multicolumn{1}{c}{\bf ノード}&\multicolumn{1}{c}{\bf 組み方}&\multicolumn{1}{c}{\bf サンプル}%
+&\multicolumn{1}{c}{\bf 対応するノード並び}\\
+\midrule
+$n_1$&行末1グループ&
+\Large
+\fbox{を}{\color{blue!50!black}\gt\ltjruby[pre=1,mode=5,stretch=110]{流}{りゆう}}\vrule
+&
+$g_0\rightarrow W\rightarrow r_1$\\
+$n_2$&行末2グループ&
+\Large
+\fbox{を}{\color{blue!50!black}\gt\ltjruby[pre=1,mode=1,stretch=110]{流|暢}{りゆう|ちよう}}\vrule
+&
+$g_0\rightarrow W\rightarrow r_1\rightarrow g_2 \rightarrow r_2$\\
+$n_3$&行頭1グループ&
+\Large
+\vrule{\color{blue!50!black}\gt\ltjruby[post=1,mode=1,stretch=011]{暢}{ちよう}}\fbox{に}
+&
+$r_2\rightarrow g_2$\\
+$n_4$&行頭2グループ&
+\Large
+\vrule{\color{blue!50!black}\gt\ltjruby[post=1,mode=1,stretch=011]{流|暢}{りゆう|ちよう}}\fbox{に}
+&
+$W\rightarrow r_1\rightarrow g_2 \rightarrow r_2\rightarrow g_2$\\
+$n_5$&行中&
+\Large
+\fbox{を}{\color{blue!50!black}\gt\ltjruby[post=0.5,pre=0.5,mode=1]{流|暢}{りゆう|ちよう}}\fbox{に}
+&
+$g_0\rightarrow W\rightarrow r_1\rightarrow g_2 \rightarrow r_2\rightarrow g_2$\\
+
+\bottomrule
+\end{tabular}
+\caption{ルビの組み方と対応するノード並び}
+\label{fig:node}
+\end{figure}
+
+\item なお,$r_i$達の高さ・深さは組み上がった後のそれである.
+$g_i$,~$r_i$達の幅は,図\nobreak\ref{fig:node}に示したような対応に沿って算出する.
+例えばこの場合,行中形$n_5$に対して
+\[
+ g_0+r_1+g_2+r_2+g_2 = 3\,\mathrm{zw}-(0.25\,\mathrm{zw}\times 2)=2.5\,\mathrm{zw}
+\]
+という方程式が立つ(zwは親文字全角の幅,進入量込).
+$n_1$から$n_5$まで計5本の方程式が立つが,これらはGau\ss の消去法で解くことができて
+$g_i$,~$r_i$達の幅が求まる.
+\item また,ルビ処理を統括しているwhatsit~$W$の値も
+\[
+ \Node{whatsit $w$}{value: 2}\longrightarrow 
+ \Node{vlist $n_1$}{末1}\longrightarrow
+ \Node{vlist $n_2$}{末2}\longrightarrow
+ \Node{vlist $n_3$}{頭1}\longrightarrow
+ \Node{vlist $n_4$}{頭2}\longrightarrow
+ \Node{vlist $n_5$}{中}
+\]
+に置き換えておく.
+
+\end{enumerate}
+
+\item \LuaTeX の行分割処理を普通に行う.
+\item 行分割の結果に従って,$g_i$,~$r_i$達を適切に置換する.
+
+例えば行分割の結果
+\begin{gather*}
+ (\text{other nodes})\longrightarrow
+ \Node{glue $g_0$}{}\longrightarrow \Node{whatsit~$W$}{元からある}\longrightarrow \Node{rule $r_1$}{}
+  \tag{行A}\\
+\noalign{\hrulefill 行の境目\hrulefill}
+\Node{rule $r_2$}{}\longrightarrow 
+ \Node{glue $g_2$}{}\longrightarrow (\text{other nodes})\tag{行B}
+\end{gather*}
+のようになったとしよう.
+\begin{enumerate}
+\item 処理は段落の上の行から順番に行われる.行Aの処理がまわってきたとしよう.
+
+\item 行Aの先頭から順番に眺めていく.すると「whatsit~$W$由来」のノード,$g_0$,~$W$,~$r_1$が見つかり,
+行Aはここで終わっている.
+
+まず,行Aのhboxの中身からwhatsit~$W$を消去(リストから取り除くだけで,$W$のメモリを解放するわけではない)する.
+$g_0$,~($W$,)~$r_1$というノードの並びは,「行末1グループ」$n_1$に対応しているので,
+$g_0$,~$r_1$を行Aから除去・メモリ解放し,代わりに$n_1$を行Aの中身に追加する.
+
+\item 次に行Bの処理にうつる.行Aでルビの処理は完了していない(2グループのルビなのにまだ1グループしか使っていない)ので,
+「whatsit~$W$由来」のノードがいくつか行B内に残っているはずである.
+
+案の定,$r_2$,~$g_2$というノード列が見つかった.これは「行頭1グループ」$n_3$に対応しているので,
+$r_2$,~$g_2$を行Bから除去・メモリ解放し,代わりに$n_3$を行Bの中身に挿入する.
+
+\item これで2グループとも使い切ったことになるので,
+隔離しておいた$W$を,(使われなかった$n_2$,~$n_4$,~$n_5$などと共に)メモリ解放する.結果として
+次のようになった:
+\begin{gather*}
+ (\text{other nodes})\longrightarrow
+ \Node{vlist $n_1$}{末1}\tag{行A}\\
+\noalign{\hrulefill 行の境目\hrulefill}
+\Node{vlist $n_3$}{頭1}\longrightarrow (\text{other nodes})\tag{行B}
+\end{gather*}
+\end{enumerate}
+\end{enumerate}
+
+\newpage
+\section{いくつかの例}
+\def\rubytest{\ruby{黄金橋}{ゴールデンゲートブリッジ}\relax}
+
+\setbox0=\vbox{\hsize=22\zw%
+ああああ\rubytest いうえおかきくけこ
+あ\rubytest いうえおかきくけこ
+あ\rubytest いうえおかきくけこ
+あ\rubytest いうえおかきくけこ
+あ\rubytest いうえおかきくけこ
+あ\rubytest いうえおかきくけこ}
+%\directlua{ltj.ext_show_node_list(tex.box[0], '? ', print)}
+\fbox{\box0}
+
+\def\rubytest{\ruby{国府津}{こうづ}\relax}
+% グループルビ
+
+\setbox0=\vbox{\hsize=18\zw%
+あ\rubytest いうえおかきくけこ
+あ\rubytest いうえおかきくけこ
+あ\rubytest いうえおかきくけこ
+あ\rubytest いうえおかきくけこ
+あ\rubytest いうえおかきくけこ
+あ\rubytest いうえおかきくけこ}
+%\directlua{ltj.ext_show_node_list(tex.box[0], '? ', print)}
+\fbox{\box0}
+
+\def\rubytest{\ruby{●●|◆}{◆◆◆◆◆◆|●●●}\relax}
+\setbox0=\vbox{\hsize=19\zw%
+あ\rubytest いうえおかきくけこ
+あ\rubytest いうえおかきくけこ
+あ\rubytest いうえおかきくけこ
+あ\rubytest いうえおかきくけこイ
+あ\rubytest いうえおかきくけこ
+あ\rubytest いうえおかきくけこウ
+あ\rubytest いうえおかきくけこエ
+あ\rubytest いうえおかきくけこ
+あ\rubytest いうえおかきくけこ
+あ\rubytest いうえおかきくけこ}
+%\directlua{ltj.ext_show_node_list(tex.box[0], '? ', print)}
+\fbox{\box0}
+
+\def\rubytest{\ruby{●●|□}{◆◆◆|●●●}\relax}
+\setbox0=\vbox{\hsize=19\zw%
+あ\rubytest いうえおかきくけこ
+あ\rubytest いうえおかきくけこ
+あ\rubytest いうえおかきくけこ
+あ\rubytest いうえおかきくけこイ
+あ\rubytest いうえおかきくけこ
+あ\rubytest いうえおかきくけこウ
+あ\rubytest いうえおかきくけこエ
+あ\rubytest いうえおかきくけこ
+あ\rubytest いうえおかきくけこ
+あ\rubytest いうえおかきくけこ}
+%\directlua{ltj.ext_show_node_list(tex.box[0], '? ', print)}
+\fbox{\box0}
+
+\def\rubytest{\ruby{異|様}{い|よう}\relax}
+\setbox0=\vbox{\hsize=19\zw%
+あ\rubytest いうえくけ
+あ\rubytest いうえくけこ
+あ\rubytest いうえくけこ
+あ\rubytest いうえくけこイ
+あ\rubytest いうえおかきくけこ}
+%\directlua{ltj.ext_show_node_list(tex.box[0], '? ', print)}
+\fbox{\box0}
+
+\def\rubytest{\ruby{□|■|□}{■■|□□□|■■}\relax}
+
+\setbox0=\vbox{\hsize=23\zw%
+あ\rubytest いうえおかきくけこうえおかきくけこ
+あ\rubytest いうえおかきくけこうえおかきくけこ
+あ\rubytest いう□おかきくけこうえおかきくけこ
+あ\rubytest いう□おかきくけこうえおかきくけこ
+あ\rubytest いう□おかきくけこうえおかきくけこ
+あ\rubytest いうえおかきくけこ}
+\fbox{\box0}
+
+\begin{description}
+\def\sample{又\ruby{承}{うけたまわ}る\quad \ruby{疎}{そ}\quad は\ruby{俄}{にわか}勉強
+  \quad 後\ruby{俄}{にわか}勉強\quad は\ruby{暁}{あかつき}に
+  は\ruby{俄}{にわか}に
+  \quad \ruby{休|憩|中}{きゆう|けい|ちゆう}かつ\ruby{視|聴|中}{し|ちよう|ちゆう}}
+\item[標準] \sample
+\item[肩つき] {\kata\sample}
+\end{description}
+
+\newpage
+\begin{LTXexample}[pos=t]
+{\ltjsetruby{stretch=101}% 親文字均等割り禁止
+    \ruby{休|憩|中}{きゆう|けい|ちゆう}かつ\ruby{視|聴|中}{し|ちよう|ちゆう}%
+}\quad
+\textgt{\ruby{勉|強}{べん|きよう}と%
+    \ruby[fontcmd=\mcfamily]{勉|強}{べん|きよう}}\quad% ルビは明朝体
+\ruby{コギト・エルゴ・スム}{Cogito ergo sum}\quad   % 欧文空白は伸長しない
+\ruby[size=1]{Cogito ergo sum}{コギト・エルゴ・スム}% 欧文空白は伸長しない
+\end{LTXexample}
+
+\newpage
+\section{『日本語組版処理の要件』20120403の例}
+
+\newcommand*{\噂}{\CID{7642}}
+\newcommand*{\倦}{\CID{7674}}
+%================================== 横組
+\paragraph{3.3.1節}\ 
+\begin{LTXexample}[pos=t]
+\obeylines
+3.49 \ruby{君|子}{くん|し}は\ruby{和}{わ}して\ruby{同}{どう}ぜず
+3.50 \ruby{人}{ひと}に\ruby{誨}{おし}えて\ruby{\倦}{う}まず
+% モノルビ.面倒でも複数回の実行が必要
+3.51 \ruby{鬼}{き}\ruby{門}{もん}の\ruby{方}{ほう}\ruby{角}{がく}を%
+     \ruby{凝}{ぎょう}\ruby{視}{し}する
+% 熟語ルビ
+3.52 \ruby{鬼|門}{き|もん}の\ruby{方|角}{ほう|がく}を\ruby{凝|視}{ぎよう|し}する
+3.53 \ruby{茅場町}{かやばちよう}\quad\ruby{茅|場}{かや|ば}\ruby{町}{ちよう}
+% 熟字訓
+3.54 \ruby{紫陽花}{あじさい}\quad\ruby{坩堝}{るつぼ}\quad\ruby{田舎}{いなか}
+% グループルビ
+3.55 \ruby{模型}{モデル}\quad\ruby{顧客}{クライアント}\quad%
+     \ruby{境界面}{インターフエース}\quad\ruby{避難所}{アジール}
+3.56 \ruby{編集者}{editor}\quad \ruby{editor}{エデイター}
+\end{LTXexample}
+
+\paragraph{3.3.3節}\ 
+\begin{LTXexample}[pos=t]
+\obeylines
+3.58 に\ruby{幟}{のぼり}を\quad に\ruby[kata]{幟}{のぼり}を\quad%
+     \ruby{韋}{い}\ruby{編}{へん}\ruby{三}{さん}\ruby{絶}{ぜつ}
+% 三分ルビ.JY3/mc/mc は本文書のプリアンブルで独自に定義
+3.59 に\ruby[fontcmd=\kanjifamily{mc}\kanjiseries{mc}]{幟}{のぼり}を
+% ルビ文字を小さくする
+3.60 {\Large%
+  \ruby{韋}{い}\ruby{編}{へん}\ruby{三}{さん}\ruby{絶}{ぜつ}\quad% 比較用
+  \ltjsetruby{size=0.375}% 0.5 -> 0.375
+  \ruby{韋}{い}\ruby{編}{へん}\ruby{三}{さん}\ruby{絶}{ぜつ}}
+\end{LTXexample}
+
+\paragraph{3.3.4節}
+3.61図(両側ルビ)は未サポートにより省略
+
+\newpage
+\paragraph{3.3.5節 モノルビ}\ 
+\begin{LTXexample}[pos=t]
+\obeylines
+3.62 の\ruby{葯}{やく}に
+3.63 版面の\ruby{地}{ち}に\quad 版面の\ruby[kata]{地}{ち}に
+% 横組肩つきはしないが,現状では縦組未サポートだし,仕方ないね
+3.65 の\ruby{砦}{とりで}に
+{\ltjsetruby{kata}%
+3.66上 の\ruby{旬}{しゆん}に\quad 後\ruby{旬}{しゆん}に
+3.66下 の\ruby{旬}{しゆん}又\quad 後\ruby{旬}{しゆん}又}
+\end{LTXexample}
+
+
+\paragraph{3.3.6節 グループルビ}\ 
+\begin{LTXexample}[pos=t]
+\obeylines
+3.67 は\ruby{冊子体}{コーデツクス}と
+3.68 \ruby{模型}{モデル}\quad \ruby{利用許諾}{ライセンス}
+% 両端を揃える流儀
+3.69 {\ltjsetruby{stretchruby=010}%
+     \ruby{模型}{モデル}\quad \ruby{利用許諾}{ライセンス}}
+% ルビが極端に短い場合
+3.70 \ruby{なげきの聖母像}{ピエタ}\quad% ルビ全角まで許容
+     \ruby[maxmargin=0.75]{なげきの聖母像}{ピエタ}% ルビ全角1.5倍まで
+% ルビが長い場合
+3.71 \ruby{顧客}{クライアント}\quad \ruby{境界面}{インターフエース}
+3.72 {\ltjsetruby{stretch=010, stretchhead=010, stretchend=010}% はみ出さない流儀
+     \ruby{顧客}{クライアント}\quad \ruby{境界面}{インターフエース}}
+\end{LTXexample} 
+
+\newpage
+\paragraph{3.3.7節 熟語ルビ}\ 
+\begin{LTXexample}[pos=t]
+\obeylines
+3.73 \ruby{杞|憂}{き|ゆう}\quad \ruby{畏|怖}{い|ふ}\quad%
+     \ruby[kata]{杞|憂}{き|ゆう}\quad \ruby[kata]{畏|怖}{い|ふ}
+3.74 の\ruby{流|儀}{りゆう|ぎ}を\quad   の\ruby{無|常}{む|じよう}を\quad%
+     の\ruby{成|就}{じよう|じゆ}を\quad の\ruby{紋|章}{もん|しよう}を\quad%
+     の\ruby{象|徴}{しよう|ちよう}を
+% 熟語の構成を考慮した方法は現行ではできない.
+% 行分割はできるのだが,「他の漢字にルビ全角までかかって良い」は難しい.
+3.75 {\ltjsetruby{kata}%
+     の\ruby{流|儀}{りゆう|ぎ}を\quad   の\ruby{無|常}{む|じよう}を\quad%
+     の\ruby{成|就}{じよう|じゆ}を\quad の\ruby{紋|章}{もん|しよう}を\quad%
+     の\ruby{象|徴}{しよう|ちよう}を}
+% モノルビ配置.望ましくない
+3.76× の\ruby{流}{りゆう}\ruby{儀}{ぎ}を\quad の\ruby{無}{む}\ruby{常}{じよう}を\quad%
+
+要調整 3.77\ {\ltjsetruby{stretchhead=121, stretchend=121}% 行頭・行末揃えず
+     \hbox{\vrule\vbox{\hsize=10\zw ああああああああの%
+        \ruby{流|儀}{りゆう|ぎ}がある.}\vrule}\textbf{←なぜ改行できない}\quad%
+     \hbox{\vrule\vbox{\hsize=5\zw ……等の\ruby{無|常}{む|じよう}を}\vrule}}
+\end{LTXexample} 
+
+\paragraph{3.3.8節 ルビはみ出し}\ 
+\begin{LTXexample}[pos=t]
+\obeylines
+3.78 \ruby{人}{ひと}は\ruby{死}{し}して\ruby{名}{な}を\ruby{残}{のこ}す
+% 現在の自動設定の仕様では「脚」の前が四分だけ「要件」の例より空く
+3.79 漢字の部首には\ruby{偏}{へん}・\ruby{冠}{かんむり}・\ruby{脚}{きやく}・%
+     \ruby{旁}{つくり}がある
+3.79 漢字の部首には\ruby{偏}{へん},\ruby{冠}{かんむり},\ruby{脚}{きやく},%
+     \ruby{旁}{つくり}がある
+\end{LTXexample}
+\begin{LTXexample}[pos=t]
+\obeylines
+% もちろん手動で進入量を指定すれば話は別
+3.79 漢字の部首には\ruby{偏}{へん}・\ruby{冠}{かんむり}・\ruby[pre=1]{脚}{きやく}・%
+     \ruby{旁}{つくり}がある
+3.79 漢字の部首には\ruby{偏}{へん},\ruby{冠}{かんむり},\ruby[pre=1]{脚}{きやく},%
+     \ruby{旁}{つくり}がある
+3.79 この\ruby{\噂}{うわさ}の好きな人は\ruby{懐}{ふところ}ぐあいもよく、\ruby{檜}{ひのき}を
+3.80 漢字の部首には「\ruby{偏}{へん}」「\ruby{冠}{かんむり}」「\ruby{脚}{きやく}」%
+「\ruby{旁}{つくり}」がある
+3.80 この\ruby{\噂}{うわさ}好きな人は\ruby{懐}{ふところ}具合もよく、\ruby{檜}{ひのき}材を
+3.81× に\ruby{暁}{あかつき}の\kern-1\zw の\ruby{趣}{おもむき}を
+3.82 に\ruby{暁}{あかつき}の\ruby{趣}{おもむき}を
+
+% 漢字にルビを2分まで掛けても良い流儀
+{%
+  \ltjsetparameter{rubypostintrusion={`好,0.5}}
+  \ltjsetparameter{rubypostintrusion={`具,0.5}}
+  \ltjsetparameter{rubypostintrusion={`材,0.5}}
+3.83 この\ruby{\噂}{うわさ}の好きな人は\ruby{懐}{ふところ}ぐあいもよく、\ruby{檜}{ひのき}を
+3.83 この\ruby{\噂}{うわさ}好きな人は\ruby{懐}{ふところ}具合もよく、\ruby{檜}{ひのき}材を
+}
+% 平仮名にもルビを掛けない流儀
+{\catcode`\<12%
+  \makeatletter\count@="3040\loop\relax\ifnum \count@<"30A0%
+  \ltjsetparameter{rubypreintrusion={\the\count@,0}, %
+    rubypostintrusion={\the\count@,0}}%
+  \advance\count@1 \repeat
+3.84 この\ruby{\噂}{うわさ}の好きな人は\ruby{懐}{ふところ}ぐあいもよく、\ruby{檜}{ひのき}を
+3.84 この\ruby{\噂}{うわさ}好きな人は\ruby{懐}{ふところ}具合もよく、\ruby{檜}{ひのき}材を
+}
+\end{LTXexample}
+\begin{LTXexample}[pos=t]
+\obeylines
+3.85\ {\ltjsetruby{stretchhead=121, stretchend=121}% 行頭・行末揃えず
+\hbox{\vrule\vbox{\hsize=15\zw
+ \hskip9.5\zw……の\ruby{徑}{こみち}を……%
+\hskip9\zw……の\ruby{徑}{こみち}を……}\vrule}}
+3.86\ \hbox{\vrule\vbox{\hsize=15\zw
+ \hskip10\zw……の\ruby{徑}{こみち}を……%
+\hskip9\zw……の\ruby{徑}{こみち}を……}\vrule}
+3.87\  \hbox{\vrule\vbox{\hsize=15\zw
+ \hskip8\zw……共\ruby{飾り}{アクセサリー}等……%
+\hskip9\zw……共\ruby{飾り}{アクセサリー}等……}\vrule}
+\end{LTXexample}
+
+
+\paragraph{圏点の例(常用漢字表前書きより)}
+この表は,法令,公⽤⽂書,新聞,雑誌,放送など,⼀般の社会⽣活におい%
+て\kenten[kenten=﹅]{現代の国語を書き表す}場合の\kenten{漢字使⽤の⽬安を⽰す}ものである。
+
+\subparagraph{「﹅」の大きさを親文字の0.33倍にした例}
+この表は,法令,公⽤⽂書,新聞,雑誌,放送など,⼀般の社会⽣活におい%
+て\kenten[size=0.33, kenten=﹅]{現代の国語を書き表す}場合の\kenten{漢字使⽤の⽬安を⽰す}ものである。
+\end{document}
diff --git a/src/addons/luatexja-ruby.sty b/src/addons/luatexja-ruby.sty
new file mode 100644 (file)
index 0000000..57e5894
--- /dev/null
@@ -0,0 +1,207 @@
+%
+% luatexja-ruby.sty
+%
+
+% LaTeX only!
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesPackage{luatexja-ruby}[2014/03/28 v0.21]
+\RequirePackage{luatexja}
+
+%%------------------
+\newluatexattribute\ltj@rubyattr
+\ltj@rubyattr=0
+\RequireLuaTeXjaSubmodule{ruby}
+
+% ltjset/getparameter への追加設定
+% これらは段落単位の設定.
+
+%% 引数:ルビ全角を単位とした実数
+%% この文字への pre-, post-intrusion の許容量
+\define@key[ltj]{japaram}{rubypreintrusion}{%
+  \expandafter\ltj@@set@stack@real#1:{RIPRE}{0}{0x7FFFFFFF}}
+\define@key[ltj]{japaram}{rubypostintrusion}{%
+  \expandafter\ltj@@set@stack@real#1:{RIPOST}{0}{0x7FFFFFFF}}
+\def\ltj@@set@stack@real#1,#2:#3#4#5{%
+  \directlua{luatexja.stack.set_stack_perchar(luatexja.stack_table_index.#3,
+    \ltj@safe@num@or\ltj@defnum{#1},\ltj@safe@real{#2},#4,#5)}}
+
+% ルビ用のキー設定
+\def\ltj@@rkeydef#1{
+  \define@key[ltj]{ruby}{#1}{\expandafter\def\csname ltj@@rubyip@#1\endcsname{##1}}
+}
+%% attr_ruby_mode
+%% bit 0: intrusion を有効にするか(1: 有効)
+%% bit 1: 前後の intrusion 許容量を小さい方に揃える (1: yes)
+%% bit 2, 3: intrusion をどう使って親文字を配置するか
+%%   00: intrusion なしでとりあえず計算し,左右の突出分を進入に割り当てる
+%%   01: pre-intrusion でまかなえるだけまかない,無理なら post- も使う
+%%   10: post を優先
+%%   11: 2 min (pre,post) までは pre, post に均等配分しようとする
+%%     >=01 で,intrusion で賄えきれなかった場合はいつものように伸長する.
+%% bit 4: 熟語ルビの際の処理方法(0: 常にグループ,1: 可能な限りブロックごとに)
+%%        ↑bit 4 は今は無効
+\ltj@@rkeydef{mode}
+%% intrusion 量強制固定(bit 0, bit 1 より優先,負数で「自動」)
+%% attr は sp 単位だが,ユーザーはルビ全角単位で指定する
+%% attr_ruby_maxprep, attr_ruby_maxpostp
+\ltj@@rkeydef{pre}
+\ltj@@rkeydef{post}
+%% 親文字伸長の際の比,{0}{1}{1} などと0--7 の数 3 つで指定
+%% attr_ruby_stretch (bol left,middle,right)(eol)(middle) 27-bits 
+\ltj@@rkeydef{stretchbol} % 行頭形
+\ltj@@rkeydef{stretcheol}  % 行末形
+\ltj@@rkeydef{stretch}     % 行中形
+%% ルビが伸長するときの比 {1}{2}{1} などと0--7 の数 3 つで指定
+%% attr_ruby_mode 上位部分
+\ltj@@rkeydef{stretchruby}
+%% ルビ<親のとき,ルビと親文字の端の最大値 
+%% attr_ruby_maxmargin
+%% attr は sp 単位だが,ユーザーは親文字全角単位で指定
+\ltj@@rkeydef{maxmargin}
+%% ルビと親文字の垂直方向の空き
+%% attr_ruby_intergap
+%% attr は sp 単位だが,ユーザーは親文字全角単位で指定
+\ltj@@rkeydef{intergap}
+
+\ltj@@rkeydef{kenten}%% 圏点文字
+\ltj@@rkeydef{fontcmd}%% フォント
+\define@boolkey[ltj]{ruby}{rubysmash}[true]{}
+
+
+%%%%%%%% setkeys の別名
+\protected\def\ltjsetruby{\setkeys[ltj]{ruby}}
+
+% ここからは ruby マクロ内でなんとかされる事項
+%% ルビと親文字の大きさの比
+\ltj@@rkeydef{size}
+
+% 中つき用簡易設定.
+\define@key[ltj]{ruby}{naka}[none]{\setkeys[ltj]{ruby}{mode=1, stretch=121, stretchruby=121}}
+% 肩つき用簡易設定.
+\define@key[ltj]{ruby}{kata}[none]{\setkeys[ltj]{ruby}{mode=9, stretch=121, stretchruby=001}}
+
+%%%%%%%% 補助関数
+
+% Lua ソースに渡す table 生成
+\def\ltj@@ruby@create@table#1{% #1: ルビ全角
+    \string{
+      rubyzw = \ltj@safe@dimen{#1}, 
+      maxmargin = \ltj@safe@dimen{\ltj@@rubyip@maxmargin\zw},
+      pre = \ltj@safe@dimen{\ltj@@rubyip@pre#1},
+      post = \ltj@safe@dimen{\ltj@@rubyip@post#1},
+      intergap =  \ltj@safe@dimen{\ltj@@rubyip@intergap\zw},
+      stretch 
+        = 262144 * \expandafter\ltj@@ruby@cts\ltj@@rubyip@stretchbol
+         + 512 * \expandafter\ltj@@ruby@cts\ltj@@rubyip@stretcheol
+         + \expandafter\ltj@@ruby@cts\ltj@@rubyip@stretch,
+      mode 
+        = 2097152 * \expandafter\ltj@@ruby@cts\ltj@@rubyip@stretchruby
+          + \ltj@safe@num{\ltj@@rubyip@mode}
+          + 1048576 * \ifltj@ruby@rubysmash1\else0\fi
+    \string}
+}
+%%%
+%%% 1098765432109876543210976543210
+%%%   |st_ruby|!               |--| ← mode 
+\def\ltj@@ruby@cts#1#2#3{%
+  ((\ltj@safe@num{#1}) * 64 + (\ltj@safe@num{#2}) * 8 + \ltj@safe@num{#3})%
+}
+
+
+%%%%%%%% ZR さんの PXrubrica パッケージ中のコードから引用・改変
+% \pxrr@decompbar: a|bc -> \ltj@@ruby@mark{a}\ltj@@ruby@mark{bc}
+\let\pxrr@res\empty
+\def\pxrr@ifx#1{%
+  \ifx#1\expandafter\@firstoftwo
+  \else\expandafter\@secondoftwo
+  \fi
+}
+\def\pxrr@nil{\noexpand\pxrr@nil}
+\def\pxrr@end{\noexpand\pxrr@end}
+\def\pxrr@appto#1#2{%
+  \expandafter\def\expandafter#1\expandafter{#1#2}%
+}
+\def\pxrr@decompbar#1{%
+  \let\pxrr@res\@empty
+  \pxrr@decompbar@loopa\pxrr@nil#1|\pxrr@end|%
+}
+\def\pxrr@decompbar@loopa#1|{%
+  \expandafter\pxrr@decompbar@loopb\expandafter{\@gobble#1}%
+}
+\def\pxrr@decompbar@loopb#1{%
+  \pxrr@decompbar@loopc#1\relax\pxrr@nil{#1}%
+}
+\def\pxrr@decompbar@loopc#1#2\pxrr@nil#3{%
+  \pxrr@ifx{#1\pxrr@end}{}{%
+    \ifx\pxrr@res\@empty
+      \def\pxrr@res{\ltj@@ruby@mark}%
+    \else
+      \pxrr@appto\pxrr@res{\ltj@@ruby@mark}%
+    \fi
+    \pxrr@appto\pxrr@res{{#3}}%
+    \pxrr@decompbar@loopa\pxrr@nil
+  }%
+}
+%%%%%%%% ここまで
+
+%%%%%%%% TeX command
+\protected\def\ltjruby{\@ifnextchar[\ltj@@ruby{\ltj@@ruby[]}}%]
+\AtBeginDocument{\ifdefined\ruby\else\let\ruby=\ltjruby\fi}
+\def\ltj@@ruby[#1]#2#3{{% #1: option #2: 親文字群,#3: ルビ文字列群,共に| 区切り
+  \setkeys[ltj]{ruby}{#1}%
+  \directlua{ruby_tmplist_r = \string{\string}; ruby_tmplist_p = \string{\string}}%
+  \leavevmode\dimen0=\f@size pt\dimen1=\ltj@@rubyip@size\dimen0%
+  % 引数展開,テーブルにセット
+  \pxrr@decompbar{#2}{\let\ltj@@ruby@mark\ltj@@ruby@sp\pxrr@res}%
+  \pxrr@decompbar{#3}{\let\ltj@@ruby@mark\ltj@@ruby@sr\pxrr@res}%
+  {\fontsize{\ltj@@rubyip@size\dimen0}\z@\selectfont\ltj@@rubyip@fontcmd\global\dimen1=\zw}%
+  \directlua{%
+    luatexja.ruby.texiface(\ltj@@ruby@create@table{\dimen1},
+    ruby_tmplist_r, ruby_tmplist_p)}%
+}}
+
+\def\ltj@@ruby@sr#1{%
+  \setbox0=\hbox{\fontsize{\dimen1}\z@\ltj@@rubyip@fontcmd\selectfont#1}%
+  \directlua{table.insert(ruby_tmplist_r, luatexja.ruby.cpbox())}%
+}
+\def\ltj@@ruby@sp#1{%
+  \setbox0=\hbox{\selectfont#1}%
+  \directlua{table.insert(ruby_tmplist_p, luatexja.ruby.cpbox())}%
+}
+
+\protected\def\ltjkenten{\@ifnextchar[\ltj@@kenten{\ltj@@kenten[]}}%]
+\let\kenten=\ltjkenten
+\def\ltj@@kenten[#1]#2{{%
+  \setkeys[ltj]{ruby}{#1, stretchruby=101}%
+  \@tfor\ltj@@kenten@temp:=#2\do{\ltj@@ruby[]{\ltj@@kenten@temp}{\ltj@@rubyip@kenten}}%
+}}
+
+% 初期値.要調整
+%% ひらがな
+\count@="3040\loop\relax\ifnum \count@<"30A0
+  \ltjsetparameter{rubypreintrusion={\the\count@,1}, 
+    rubypostintrusion={\the\count@,1}}
+  \advance\count@1\repeat
+%% 「」
+\ltjsetparameter{rubypreintrusion={`「,1}, 
+  rubypostintrusion={`」,1}}
+%% ,、
+\ltjsetparameter{rubypreintrusion={`,,1}, 
+  rubypostintrusion={`,,1}}
+\ltjsetparameter{rubypreintrusion={`、,1}, 
+  rubypostintrusion={`、,1}}
+%% ・
+\ltjsetparameter{rubypreintrusion={`・,1}, 
+  rubypostintrusion={`・,1}}
+%% 段落インデント部分
+\ltjsetparameter{rubypreintrusion={-1,1}}
+
+\setkeys[ltj]{ruby}{
+  pre=-1, post=-1, mode=1, 
+  stretchruby={1}{2}{1}, stretch = {1}{2}{1},
+  stretchbol={0}{1}{1}, stretcheol={1}{1}{0},
+  maxmargin=0.5, size=0.5, intergap=0, rubysmash=false,
+  kenten=\ltjalchar`•, fontcmd=\relax
+}
+
+\endinput
diff --git a/src/ltj-ruby.lua b/src/ltj-ruby.lua
new file mode 100644 (file)
index 0000000..a84256c
--- /dev/null
@@ -0,0 +1,774 @@
+--
+-- ltj-ruby.lua
+--
+luatexbase.provides_module({
+  name = 'luatexja.ruby',
+  date = '2014/04/02',
+  description = 'Ruby',
+})
+module('luatexja.ruby', package.seeall)
+local err, warn, info, log = luatexbase.errwarinf(_NAME)
+
+luatexja.load_module('stack');     local ltjs = luatexja.stack
+
+local Dnode = node.direct or node
+
+local nullfunc = function(n) return n end
+local to_node = (Dnode ~= node) and Dnode.tonode or nullfunc
+local to_direct = (Dnode ~= node) and Dnode.todirect or nullfunc
+
+local setfield = (Dnode ~= node) and Dnode.setfield or function(n, i, c) n[i] = c end
+local getfield = (Dnode ~= node) and Dnode.getfield or function(n, i) return n[i] end
+local getid = (Dnode ~= node) and Dnode.getid or function(n) return n.id end
+local getfont = (Dnode ~= node) and Dnode.getfont or function(n) return n.font end
+local getlist = (Dnode ~= node) and Dnode.getlist or function(n) return n.head end
+local getchar = (Dnode ~= node) and Dnode.getchar or function(n) return n.char end
+local getsubtype = (Dnode ~= node) and Dnode.getsubtype or function(n) return n.subtype end
+
+local node_new = Dnode.new
+local node_remove = luatexja.Dnode_remove -- Dnode.remove
+local node_next = (Dnode ~= node) and Dnode.getnext or node.next
+local node_copy, node_free, node_tail = Dnode.copy, Dnode.free, Dnode.tail
+local has_attr, set_attr = Dnode.has_attribute, Dnode.set_attribute
+local insert_before, insert_after = Dnode.insert_before, Dnode.insert_after
+
+local id_hlist = node.id('hlist')
+local id_vlist = node.id('vlist')
+local id_rule = node.id('rule')
+local id_whatsit = node.id('whatsit')
+local id_glue = node.id('glue')
+local id_kern = node.id('kern')
+local id_penalty = node.id('penalty')
+local id_glue_spec = node.id('glue_spec')
+local sid_user = node.subtype('user_defined')
+local ltjs_get_stack_table = luatexja.stack.get_stack_table
+local id_pbox_w = 258 -- cluster which consists of a whatsit
+
+local attr_icflag = luatexbase.attributes['ltj@icflag']
+-- ルビ処理用の attribute は他のやつの流用なので注意!
+-- 進入許容量 (sp)
+local attr_ruby_maxprep = luatexbase.attributes['ltj@charclass']
+local attr_ruby_maxpostp = luatexbase.attributes['ltj@kcat0']
+local attr_ruby_maxmargin = luatexbase.attributes['ltj@kcat1']
+local attr_ruby_stretch = luatexbase.attributes['ltj@kcat2']
+local attr_ruby_mode = luatexbase.attributes['ltj@kcat3']
+local attr_ruby_id = luatexbase.attributes['ltj@kcat4'] -- uniq id
+local attr_ruby_intergap = luatexbase.attributes['ltj@kcat5']
+local attr_ruby = luatexbase.attributes['ltj@rubyattr']
+-- ルビ内部処理用,以下のようにノードによって使われ方が異なる
+-- * (whatsit) では JAglue 処理時に,
+--     「2つ前のクラスタもルビ」 ==> そのルビクラスタの id
+--   otherwise ==> unset
+-- * (whatsit).value node ではルビ全角の値(sp単位)
+-- * 行分割で whatsit の前後に並ぶノードでは,「何番目のルビ関連ノード」か
+-- * (whatsit).value に続く整形済み vbox たちでは post_intrusion の値
+local cat_lp = luatexbase.catcodetables['latex-package']
+
+local round, floor = tex.round, math.floor
+local min, max = math.min, math.max
+
+luatexja.userid_table.RUBY_PRE = luatexbase.newuserwhatsitid('ruby_pre',  'luatexja')
+luatexja.userid_table.RUBY_POST = luatexbase.newuserwhatsitid('ruby_post',  'luatexja')
+local RUBY_PRE  = luatexja.userid_table.RUBY_PRE
+local RUBY_POST = luatexja.userid_table.RUBY_POST
+
+----------------------------------------------------------------
+-- TeX interface 0
+----------------------------------------------------------------
+if Dnode ~= node then
+   function cpbox() return node_copy(Dnode.getbox(0)) end
+else
+   function cpbox() return node.copy(tex.box[0]) end
+end
+
+
+----------------------------------------------------------------
+-- 補助関数群 1
+----------------------------------------------------------------
+
+local function gauss(coef)
+   -- #coef 式,#coef 変数の連立1次方程式系を掃きだし法で解く.
+   local deg = #coef
+   for i = 1, deg do
+      if coef[i][i]==0 then
+        for j = i+1, deg do 
+           if coef[j][i]~=0 then
+               coef[i], coef[j] = coef[j], coef[i]; break
+           end
+        end
+      end
+      for j = 1,deg do 
+        local d = coef[i][i];
+        if j~=i then
+           local e = coef[j][i]
+           for k = 1, deg+1 do coef[j][k] = coef[j][k] - e*coef[i][k]/d end
+        else 
+           for k = 1, deg+1 do coef[i][k] = coef[i][k]/d end
+        end
+      end
+   end
+end
+
+local function solve_1(coef)
+   local a, b, c = coef[1][4], coef[2][4], coef[3][4]
+   coef[1][4], coef[2][4], coef[3][4] = c-b, a+b-c, c-a
+   return coef
+end
+
+local function solve_2(coef)
+   local a, b, c, d, e = coef[1][6], coef[2][6], coef[3][6], coef[4][6], coef[5][6]
+   coef[1][6], coef[2][6], coef[3][6], coef[4][6], coef[5][6]
+      = e-c, a+c-e, e-a-d, b+d-e, e-b
+   return coef
+end
+
+
+-- 実行回数 + ルビ中身 から uniq_id を作る関数
+old_break_info = {} -- public, 前 run 時の分割情報
+local make_uniq_id
+do
+   local exec_count = 0
+   make_uniq_id = function (w)
+      exec_count = exec_count + 1
+      return exec_count
+   end
+end
+
+-- concatenation of boxes: reusing nodes
+-- ルビ組版が行われている段落/hboxでの設定が使われる.
+-- ルビ文字を格納しているボックスでの設定ではない!
+local function concat(f, b)
+   if f then
+      if b then
+         local h = getlist(f)
+         setfield(node_tail(h), 'next', getlist(b))
+        setfield(f, 'head', nil); node_free(f)
+         setfield(b, 'head', nil); node_free(b)
+        return Dnode.hpack(luatexja.jfmglue.main(h,false))
+      else 
+        return f
+      end
+   elseif b then
+      return b
+   else
+      local h = node_new(id_hlist)
+      setfield(h, 'subtype', 0)
+      setfield(h, 'width', 0)
+      setfield(h, 'height', 0)
+      setfield(h, 'depth', 0)
+      setfield(h, 'glue_set', 0)
+      setfield(h, 'glue_order', 0)
+      setfield(h, 'head', nil)
+      return h
+   end
+end
+
+local function expand_3bits(num)
+   local t = {}; local a = num
+   for i = 1, 10 do
+      t[i] = a%8; a = floor(a/8)
+   end
+   return t
+end
+----------------------------------------------------------------
+-- 補助関数群 2
+----------------------------------------------------------------
+
+-- box の中身のノードは再利用される
+local enlarge
+do
+   local FROM_JFM       = luatexja.icflag_table.FROM_JFM
+   local PROCESSED      = luatexja.icflag_table.PROCESSED
+   local KANJI_SKIP     = luatexja.icflag_table.KANJI_SKIP
+   local KANJI_SKIP_JFM = luatexja.icflag_table.KANJI_SKIP_JFM
+   local XKANJI_SKIP    = luatexja.icflag_table.XKANJI_SKIP
+   local XKANJI_SKIP_JFM= luatexja.icflag_table.XKANJI_SKIP_JFM
+   enlarge = function (box, new_width, pre, middle, post, prenw, postnw)
+      -- pre, middle, post: 伸縮比率
+      -- prenw, postnw: 前後の自然長 (sp)
+      local h = getlist(box); 
+      local hh, hd = getfield(box, 'height'), getfield(box, 'depth')
+      local hx = h
+      while hx do
+         local hic = has_attr(hx, attr_icflag)
+        if (hic == KANJI_SKIP) or (hic == KANJI_SKIP_JFM)
+            or (hic == XKANJI_SKIP) or (hic == XKANJI_SKIP_JFM)
+            or ((hic<=FROM_JFM+2) and (hic>=FROM_JFM-2)) then
+           -- この 5 種類の空白をのばす
+              if getid(hx) == id_kern then
+                 local k = node_new(id_glue)
+                 local ks = node_new(id_glue_spec)
+                 setfield(ks, 'width', getfield(hx, 'kern'))
+                 setfield(ks, 'stretch_order', 2)
+                 setfield(ks, 'stretch', round(middle*65536))
+                 setfield(ks, 'shrink_order', 0); setfield(ks, 'shrink', 0)
+                 setfield(k, 'subtype', 0); setfield(k, 'spec', ks)
+                 h = insert_after(h, hx, k);
+                 h = node_remove(h, hx); node_free(hx); hx = k
+              else -- glue
+                 local old_spec = getfield(hx, 'spec')
+                 local ks = node_copy(old_spec)
+                 setfield(ks, 'stretch_order', 2)
+                 setfield(ks, 'stretch', round(middle*65536))
+                 setfield(ks, 'shrink_order', 0); setfield(ks, 'shrink', 0)
+                 setfield(hx, 'spec', ks)
+                 -- decrease old_spec's reference count
+                 local b = node_new(id_glue)
+                 setfield(b, 'spec', old_spec); node_free(b)
+              end
+        end
+        hx = node_next(hx)
+      end
+      -- 先頭の空白を挿入
+      local k = node_new(id_glue);
+      local ks = node_new(id_glue_spec)
+      setfield(ks, 'width', prenw)
+      setfield(ks, 'stretch_order', 2); setfield(ks, 'stretch', round(pre*65536))
+      setfield(ks, 'shrink_order', 0); setfield(ks, 'shrink', 0)
+      setfield(k, 'subtype', 0); setfield(k, 'spec', ks)
+      h = insert_before(h, h, k);
+      -- 末尾の空白を挿入
+      local k = node_new(id_glue);
+      local ks = node_new(id_glue_spec);
+      setfield(ks, 'width', postnw)
+      setfield(ks, 'stretch_order', 2); setfield(ks, 'stretch', round(post*65536))
+      setfield(ks, 'shrink_order', 0); setfield(ks, 'shrink', 0)
+      setfield(k, 'subtype', 0);setfield(k, 'spec', ks)
+      insert_after(h, node_tail(h), k);
+      -- hpack
+      setfield(box, 'head', nil); node_free(box)
+      box = Dnode.hpack(h, new_width, 'exactly')
+      setfield(box, 'height', hh)
+      setfield(box, 'depth', hd)
+      return box
+   end
+end
+
+
+----------------------------------------------------------------
+-- TeX interface
+----------------------------------------------------------------
+
+-- rtlr: ルビ部分のボックスたち r1, r2, ...
+-- rtlp: 親文字 のボックスたち p1, p2, ...
+local function texiface_low(rst, rtlr, rtlp)
+   local w = node_new(id_whatsit, sid_user)
+   setfield(w, 'type', 110); setfield(w, 'user_id', RUBY_PRE)
+   local wv = node_new(id_whatsit, sid_user)
+   setfield(w, 'value', to_node(wv))
+   setfield(wv, 'type', 100)
+   setfield(wv, 'value', floor(#rtlr))
+   set_attr(wv, attr_ruby, rst.rubyzw)
+   set_attr(wv, attr_ruby_maxmargin, rst.maxmargin)
+   set_attr(wv, attr_ruby_maxprep, rst.pre)
+   set_attr(wv, attr_ruby_maxpostp, rst.post)
+   set_attr(wv, attr_ruby_intergap, rst.intergap)
+   set_attr(wv, attr_ruby_stretch, rst.stretch)
+   set_attr(wv, attr_ruby_mode, rst.mode)
+   local n = wv
+   for i = 1, #rtlr do
+      _, n = insert_after(wv, n, rtlr[i])
+      _, n = insert_after(wv, n, rtlp[i])
+   end
+   -- w.value: (whatsit) .. r1 .. p1 .. r2 .. p2
+   Dnode.write(w); return w,wv
+end
+
+-- rst: table
+function texiface(rst, rtlr, rtlp)
+   if #rtlr ~= #rtlp then
+      for i=1, #rtlr do node_free(rtlr[i]) end
+      for i=1, #rtlp do node_free(rtlp[i]) end
+      luatexja.base.package_error('luatexja-ruby',
+                                 'Group count mismatch between the ruby and\n' ..
+                                    'the body (' .. #rtlr .. ' != ' .. #rtlp .. ').',
+                                 '')
+   else
+      local f = true
+      for i = 1,#rtlr do
+        if getfield(rtlr[i], 'width') > getfield(rtlp[i], 'width') then
+           f = false; break
+        end
+      end
+      if f then -- モノルビ * n
+        local r,p = {true}, {true}
+        for i = 1,#rtlr do
+           r[1] = rtlr[i]; p[1] = rtlp[i]; texiface_low(rst, r, p)
+        end
+      else
+        local w, wv = texiface_low(rst, rtlr, rtlp)
+        local id = make_uniq_id(w)
+        set_attr(wv, attr_ruby_id, id)
+      end
+   end
+end
+
+----------------------------------------------------------------
+-- pre_line_break
+----------------------------------------------------------------
+
+-- r, p の中身のノードは再利用される
+local function enlarge_parent(r, p, ppre, pmid, ppost, mapre, mapost, intmode)
+   -- r: ルビ部分の格納された box,p: 同,親文字
+   local rwidth = getfield(r, 'width')
+   local sumprot = rwidth - getfield(p, 'width') -- >0
+   local pre_intrusion, post_intrusion
+   if intmode == 0 then --  とりあえず組んでから決める
+      p = enlarge(p, rwidth, ppre, pmid, ppost, 0, 0) 
+      pre_intrusion  = min(mapre, round(ppre*getfield(p, 'glue_set')*65536))
+      post_intrusion = min(mapost, round(ppost*getfield(p, 'glue_set')*65536))
+   elseif intmode == 1 then
+      pre_intrusion = min(mapre, sumprot); 
+      post_intrusion = min(mapost, max(sumprot-pre_intrusion, 0))
+      p = enlarge(p, rwidth, ppre, pmid, ppost, pre_intrusion, post_intrusion)
+   elseif intmode == 2 then
+      post_intrusion = min(mapost, sumprot); 
+      pre_intrusion = min(mapre, max(sumprot-post_intrusion, 0))
+      p = enlarge(p, rwidth, ppre, pmid, ppost, pre_intrusion, post_intrusion) 
+   else --  intmode == 3
+      local n = min(mapre, mapost)*2
+      if n < sumprot then
+        pre_intrusion = n/2; post_intrusion = n/2
+      else
+        pre_intrusion = floor(sumprot/2); post_intrusion = sumprot - pre_intrusion
+      end
+      p = enlarge(p, rwidth, ppre, pmid, ppost, pre_intrusion, post_intrusion) 
+      pre_intrusion = min(mapre, pre_intrusion + round(ppre*getfield(p, 'glue_set')*65536))
+      post_intrusion = min(mapost, post_intrusion + round(ppost*getfield(p, 'glue_set')*65536))
+   end
+   setfield(r, 'shift', -pre_intrusion)
+   local rwidth = rwidth - pre_intrusion - post_intrusion
+   setfield(r, 'width', rwidth)
+   setfield(p, 'width', rwidth)
+   local ps = getfield(getlist(p), 'spec')
+   setfield(ps, 'width', getfield(ps, 'width') - pre_intrusion)
+   return r, p, post_intrusion
+end
+
+-- ルビボックスの生成(単一グループ)
+-- returned value: <new box>, <ruby width>, <post_intrusion>
+local max_margin
+local function new_ruby_box(r, p, ppre, pmid, ppost, 
+                           mapre, mapost, imode, rgap)
+   local post_intrusion = 0
+   local intmode = imode%4
+   local rpre, rmid, rpost, rsmash
+   imode = floor(imode/262144); rsmash = (imode%2 ==1)
+   imode = floor(imode/2); rpost = imode%8;
+   imode = (imode-rpost)/8;  rmid  = imode%8;
+   imode = (imode-rmid)/8;   rpre  = imode%8
+   if getfield(r, 'width') > getfield(p, 'width') then  -- change the width of p
+      r, p, post_intrusion  = enlarge_parent(r, p, ppre, pmid, ppost, mapre, mapost, intmode)
+   elseif getfield(r, 'width') < getfield(p, 'width') then -- change the width of r
+      r = enlarge(r, getfield(p, 'width'), rpre, rmid, rpost, 0, 0) 
+      post_intrusion = 0
+      local need_repack = false
+      -- margin が大きくなりすぎた時の処理
+      if round(rpre*getfield(r, 'glue_set')*65536) > max_margin then
+        local ps = getfield(getlist(r), 'spec'); need_repack = true
+        setfield(ps, 'width', max_margin)
+         setfield(ps, 'stretch', 1) -- 全く伸縮しないのも困る
+      end
+      if round(rpost*getfield(r, 'glue_set')*65536) > max_margin then
+        local ps = getfield(node_tail(getlist(r)), 'spec'); need_repack = true
+        setfield(ps, 'width', max_margin)
+         setfield(ps, 'stretch', 1) -- 全く伸縮しないのも困る
+      end
+      if need_repack then
+        local rt = r
+        r = Dnode.hpack(getlist(r), getfield(r, 'width'), 'exactly')
+        setfield(rt, 'head', nil); node_free(rt);
+      end
+   end
+   local a, k = node_new(id_rule), node_new(id_kern)
+   setfield(a, 'width', 0); setfield(a, 'height', 0)
+   setfield(a, 'depth', 0); setfield(k, 'kern', rgap)
+   insert_after(r, r, a); insert_after(r, a, k);
+   insert_after(r, k, p); setfield(p, 'next', nil)
+   a = Dnode.vpack(r); setfield(a, 'shift', 0)
+   set_attr(a, attr_ruby, post_intrusion)
+   if rsmash or getfield(a, 'height')<getfield(p, 'height') then
+      local k = node_new(id_kern)
+      setfield(k, 'kern', -getfield(a, 'height')+getfield(p, 'height'))
+      setfield(a, 'head', k); insert_before(r, r, k)
+      setfield(a, 'height', getfield(p, 'height'))
+   end
+
+   return a, getfield(r, 'width'), post_intrusion
+end
+
+
+-- High-level routine in pre_linebreak_filter
+local post_intrusion_backup
+local max_allow_pre, max_allow_post
+
+
+-- 中付き熟語ルビ,cmp containers
+-- 「文字の構成を考えた」やつはどうしよう
+local function pre_low_cal_box(w, cmp)
+   local rb = {}
+   local pb = {}
+   local kf = {}
+   -- kf[i] : container 1--i からなる行末形
+   -- kf[cmp+i] : container i--cmp からなる行頭形
+   -- kf[2cmp+1] : 行中形
+   local wv = getfield(w, 'value')
+   local mdt -- nt*: node temp
+   local coef = {} -- 連立一次方程式の拡大係数行列
+   local rtb = expand_3bits(has_attr(wv, attr_ruby_stretch))
+   local rgap = has_attr(wv, attr_ruby_intergap)
+   local intmode = floor(has_attr(wv, attr_ruby_mode)/4)
+
+   -- node list 展開・行末形の計算
+   local nt, nta, ntb = wv, nil, nil -- nt*: node temp
+   for i = 1, cmp do
+      nt = node_next(nt); rb[i] = nt; nta = concat(nta, node_copy(nt))
+      nt = node_next(nt); pb[i] = nt; ntb = concat(ntb, node_copy(nt))
+      coef[i] = {}
+      for j = 1, 2*i do coef[i][j] = 1 end
+      for j = 2*i+1, 2*cmp+1 do coef[i][j] = 0 end
+      kf[i], coef[i][2*cmp+2]
+        = new_ruby_box(node_copy(nta), node_copy(ntb), 
+                       rtb[6], rtb[5], rtb[4], max_allow_pre, 0, intmode, rgap)
+   end
+   node_free(nta); node_free(ntb)
+
+   -- 行頭形の計算
+   local nta, ntb = nil, nil
+   for i = cmp,1,-1 do
+      coef[cmp+i] = {}
+      for j = 1, 2*i-1 do coef[cmp+i][j] = 0 end
+      for j = 2*i, 2*cmp+1 do coef[cmp+i][j] = 1 end
+      nta = concat(node_copy(rb[i]), nta); ntb = concat(node_copy(pb[i]), ntb)
+      kf[cmp+i], coef[cmp+i][2*cmp+2]
+        = new_ruby_box(node_copy(nta), node_copy(ntb), 
+                       rtb[9], rtb[8], rtb[7], 0, max_allow_post, intmode, rgap)
+   end
+
+   -- ここで,nta, ntb には全 container を連結した box が入っているので
+   -- それを使って行中形を計算する.
+   coef[2*cmp+1] = {}
+   for j = 1, 2*cmp+1 do coef[2*cmp+1][j] = 1 end
+   kf[2*cmp+1], coef[2*cmp+1][2*cmp+2], post_intrusion_backup
+      = new_ruby_box(nta, ntb, rtb[3], rtb[2], rtb[1], 
+                     max_allow_pre, max_allow_post, intmode, rgap)
+
+   -- w.value の node list 更新.
+   local nt = wv
+   Dnode.flush_list(node_next(wv))
+   for i = 1, 2*cmp+1 do setfield(nt, 'next', kf[i]); nt = kf[i]  end
+
+   if cmp==1 then     solve_1(coef)
+   elseif cmp==2 then solve_2(coef)
+   else
+      gauss(coef) -- 掃きだし法で連立方程式形 coef を解く
+   end
+   return coef
+end
+
+local first_whatsit
+do
+   local traverse_id = Dnode.traverse_id
+   function first_whatsit(n) -- n 以後で最初の whatsit
+      for h in traverse_id(id_whatsit, n) do
+         return h
+      end
+      return nil
+   end
+end
+
+-- ノード追加
+local function pre_low_app_node(head, w, cmp, coef, ht, dp)
+   -- メインの node list 更新
+   local nt, ntb = node_new(id_glue), node_new(id_glue_spec)
+   setfield(ntb, 'width', coef[1][2*cmp+2])
+   setfield(ntb, 'stretch_order', 0); setfield(ntb, 'stretch', 0)
+   setfield(ntb, 'shrink_order', 0); setfield(ntb, 'shrink', 0)
+   setfield(nt, 'subtype', 0); setfield(nt, 'spec', ntb)
+   set_attr(nt, attr_ruby, 1); set_attr(w, attr_ruby, 2)
+   head = insert_before(head, w, nt)
+   nt = w
+   for i = 1, cmp do
+      -- rule
+      local nta = node_new(id_rule); 
+      setfield(nta, 'width', coef[i*2][2*cmp+2])
+      setfield(nta, 'height', ht); setfield(nta, 'depth', dp)
+      setfield(nta, 'subtype', 0)
+      insert_after(head, nt, nta)
+      set_attr(nta, attr_ruby, 2*i+1)
+      -- glue
+      nt = node_new(id_glue)
+      local ntb = node_new(id_glue_spec);
+      setfield(ntb, 'width', coef[i*2+1][2*cmp+2])
+      setfield(ntb, 'stretch_order', 0); setfield(ntb, 'stretch', 0)
+      setfield(ntb, 'shrink_order', 0); setfield(ntb, 'shrink', 0)
+      setfield(nt, 'subtype', 0); setfield(nt, 'spec', ntb)
+      set_attr(nt, attr_ruby, 2*i+2)
+      insert_after(head, nta, nt)
+   end
+   tex.setattribute('global', attr_ruby, -0x7FFFFFFF)
+   setfield(w, 'user_id', RUBY_POST)
+   return head, first_whatsit(node_next(nt))
+end
+
+local function pre_high(ahead)
+   if not ahead then return ahead end
+   local head = to_direct(ahead)
+   post_intrusion_backup = 0
+   local n = first_whatsit(head)
+   while n do
+      if getsubtype(n) == sid_user and getfield(n, 'user_id') == RUBY_PRE then
+        local nv = getfield(n, 'value')
+         max_allow_pre = has_attr(nv, attr_ruby_maxprep) or 0
+         local atr = has_attr(n, attr_ruby) or 0
+         if max_allow_pre < 0 then
+            if atr>0 then
+               -- 直前のルビで intrusion がおこる可能性あり.
+               -- 前 run のデータが残っていればそれを使用,
+               -- そうでなければ行中形のデータを利用する
+               local op = old_break_info[atr] or post_intrusion_backup
+               max_allow_pre = max(0, -max_allow_pre - op)
+            else
+               max_allow_pre = -max_allow_pre
+            end
+         end
+         post_intrusion_backup = 0
+         max_allow_post = has_attr(nv, attr_ruby_maxpostp) or 0
+         max_margin = has_attr(nv, attr_ruby_maxmargin) or 0
+         local coef = pre_low_cal_box(n, getfield(nv, 'value'))
+         local s = node_tail(nv) --ルビ文字
+         head, n = pre_low_app_node(
+            head, n, getfield(nv, 'value'), coef, 
+            getfield(s, 'height'), getfield(s, 'depth')
+         )
+      else
+         n = first_whatsit(node_next(n))
+      end
+   end
+   return to_node(head)
+end 
+luatexbase.add_to_callback('pre_linebreak_filter', pre_high, 'ltj.ruby.pre', 100)
+luatexbase.add_to_callback('hpack_filter', pre_high, 'ltj.ruby.pre', 100)
+
+----------------------------------------------------------------
+-- post_line_break
+----------------------------------------------------------------
+local post_lown
+do
+   local function write_aux(wv, num)
+      local id = has_attr(wv, attr_ruby_id)
+      if id>0 then
+        tex.sprint(cat_lp, 
+                   '\\write\\@mainaux{\\string\\directlua{luatexja.ruby.old_break_info[' 
+                      .. tostring(id) .. ']=' .. num 
+                      .. '}}')
+      end
+   end
+
+   post_lown = function (rs, rw, cmp, ch)
+      -- ch: the head of `current' hlist
+      if #rs ==0 or not rw then return ch end
+      local hn = has_attr(rs[1], attr_ruby)
+      local fn = has_attr(rs[#rs], attr_ruby)
+      local wv = getfield(rw, 'value')
+      if hn==1 then 
+        if fn==2*cmp+2 then
+           local hn = node_tail(wv)
+           node_remove(wv, hn)
+           insert_after(ch, rs[#rs], hn)
+           set_attr(hn, attr_icflag,  PROCESSED)
+           write_aux(wv, has_attr(hn, attr_ruby))-- 行中形
+        else
+           local deg, hn = (fn-1)/2, wv
+           for i = 1, deg do hn = node_next(hn) end; 
+           node_remove(wv, hn)
+           setfield(hn, 'next', nil)
+           insert_after(ch, rs[#rs], hn)
+           set_attr(hn, attr_icflag,  PROCESSED)
+           write_aux(wv, has_attr(hn, attr_ruby))
+        end
+      else
+        local deg, hn = max((hn-1)/2,2), wv 
+        for i = 1, cmp+deg-1 do hn = node_next(hn) end
+        -- -1 is needed except the case hn = 3, 
+        --   because a ending-line form is removed already from the list
+        node_remove(wv, hn); setfield(hn, 'next', nil)
+        insert_after(ch, rs[#rs], hn)
+        set_attr(hn, attr_icflag,  PROCESSED)
+        if fn == 2*cmp-1 then
+           write_aux(wv, has_attr(hn, attr_ruby))
+        end
+      end
+      for i = 1,#rs do 
+        local ri = rs[i]
+        ch = node_remove(ch, ri); node_free(ri);
+      end
+      -- cleanup
+      if fn >= 2*cmp+1 then node_free(rw) end
+      return ch;
+   end
+end
+
+local function post_high_break(head)
+   local rs = {}   -- rs: sequence of ruby_nodes, 
+   local rw = nil  -- rw: main whatsit
+   local cmp = -2  -- dummy
+   for h in Dnode.traverse_id(id_hlist, to_direct(head)) do
+      for i = 1, #rs do rs[i] = nil end
+      local ha = getlist(h)
+      while ha do
+        local hai = getid(ha)
+        local i = ((hai == id_glue and getsubtype(ha)==0) 
+                       or (hai == id_rule and getsubtype(ha)==0)
+                       or (hai == id_whatsit and getsubtype(ha)==sid_user 
+                              and getfield(ha, 'user_id', RUBY_POST)))
+            and has_attr(ha, attr_ruby) or 0
+        if i==0 then 
+            ha = node_next(ha)
+         elseif i==1 then
+           setfield(h, 'head', post_lown(rs, rw, cmp, getlist(h)))
+           for i = 2, #rs do rs[i] = nil end -- rs[1] is set by the next statement
+           rs[1], rw = ha, nil; ha = node_next(ha)
+        elseif i==2 then 
+           rw = ha
+           cmp = getfield(getfield(rw, 'value'), 'value')
+           local hb, hc =  node_remove(getlist(h), rw)
+           setfield(h, 'head', hb); ha = hc
+        else -- i>=3 
+           rs[#rs+1] = ha; ha = node_next(ha)
+        end
+      end
+      setfield(h, 'head', post_lown(rs, rw, cmp, getlist(h)))
+   end
+   return head
+end 
+
+local function post_high_hbox(ahead)
+   local ha = to_direct(ahead); local head = ha
+   local rs = {};  -- rs: sequence of ruby_nodes, 
+   local rw = nil; -- rw: main whatsit
+   local cmp
+   while ha do
+      local hai = getid(ha)
+      local i = ((hai == id_glue and getsubtype(ha)==0) 
+                    or (hai == id_rule and getsubtype(ha)==0)
+                    or (hai == id_whatsit and getsubtype(ha)==sid_user 
+                           and getfield(ha, 'user_id', RUBY_POST)))
+         and has_attr(ha, attr_ruby) or 0
+      if i==0 then
+         ha = node_next(ha)
+      elseif i==1 then 
+         head = post_lown(rs, rw, cmp, head)
+         for i = 2, #rs do rs[i] = nil end -- rs[1] is set by the next statement
+        rs[1], rw = ha, nil; ha = node_next(ha)
+      elseif i==2 then 
+         rw = ha
+        cmp = getfield(getfield(rw, 'value'), 'value')
+        head, ha = node_remove(head, rw)
+      else -- i >= 3
+         rs[#rs+1] = ha; ha = node_next(ha)
+      end
+   end
+   return to_node(post_lown(rs, rw, cmp, head))
+end
+
+luatexbase.add_to_callback('post_linebreak_filter', post_high_break, 'ltj.ruby.post_break', 100)
+luatexbase.add_to_callback('hpack_filter', post_high_hbox, 'ltj.ruby.post_hbox', 101)
+
+
+----------------------------------------------------------------
+-- for jfmglue callbacks
+----------------------------------------------------------------
+do
+   local RIPRE  = luatexja.stack_table_index.RIPRE
+   local function whatsit_callback(Np, lp, Nq, bsl) 
+      if Np.nuc then return Np 
+      elseif getfield(lp, 'user_id') == RUBY_PRE then
+         Np.first, Np.nuc, Np.last = lp, lp, lp
+         local lpv = getfield(lp, 'value')
+         local x = node_next(node_next(lpv))
+         Np.last_char = luatexja.jfmglue.check_box_high(Np, getlist(x), nil)
+         if Nq.id ~=id_pbox_w then
+            if type(Nq.char)=='number' then
+               -- Nq is a JAchar
+               if has_attr(lpv, attr_ruby_maxprep) < 0 then -- auto
+                  local p = round((ltjs.table_current_stack[RIPRE + Nq.char] or 0)
+                                     *has_attr(lpv, attr_ruby))
+                  if has_attr(lpv, attr_ruby_mode)%2 == 0 then -- intrusion 無効
+                     p = 0
+                  end
+                  set_attr(lpv, attr_ruby_maxprep, -p)
+               end
+               if Nq.prev_ruby then
+                  set_attr(lp, attr_ruby, Nq.prev_ruby)
+               end
+            elseif has_attr(lpv, attr_ruby_maxprep) < 0 then -- auto
+               if Nq.char == 'parbdd' then
+                  local p = round((ltjs.table_current_stack[RIPRE-1] or 0)
+                                     *has_attr(lpv, attr_ruby))
+                  p = min(p, Nq.width)
+                 if has_attr(lpv, attr_ruby_mode)%2 == 0 then -- intrusion 無効
+                     p = 0
+                  end
+                  set_attr(lpv, attr_ruby_maxprep, p)
+               else
+                  set_attr(lpv, attr_ruby_maxprep, 0)
+               end
+            end
+         elseif has_attr(lpv, attr_ruby_maxprep) < 0 then -- auto
+            set_attr(lpv, attr_ruby_maxprep, 0)
+         end
+         return Np
+      end
+   end
+   luatexbase.add_to_callback("luatexja.jfmglue.whatsit_getinfo", whatsit_callback,
+                              "luatexja.ruby.np_info", 1)
+end
+
+do
+   local RIPOST = luatexja.stack_table_index.RIPOST
+   local function whatsit_after_callback(s, Nq, Np, bsl)
+      if not s and  getfield(Nq.nuc, 'user_id') == RUBY_PRE then
+         local nqnv = getfield(Nq.nuc, 'value')
+         local x =  node_next(node_next(nqnv))
+         for i = 2, getfield(nqnv, 'value') do x = node_next(node_next(x)) end
+         Nq.last_char = luatexja.jfmglue.check_box_high(Nq, getlist(x), nil)
+         luatexja.jfmglue.after_hlist(Nq)
+         if Np and Np.id ~=id_pbox_w and type(Np.char)=='number' then
+           -- Np is a JAchar
+           local rm = has_attr(nqnv, attr_ruby_mode)
+            if has_attr(nqnv, attr_ruby_maxpostp) < 0 then -- auto
+               local p = round((ltjs.table_current_stack[RIPOST + Np.char] or 0)
+                                  *has_attr(nqnv, attr_ruby))
+               if rm%2 == 0 then -- intrusion 無効
+                  p = 0
+               end
+               if rm%4 >= 2 then
+                  local q = has_attr(nqnv, attr_ruby_maxprep)
+                  if q < p then p = q
+                  elseif q > p then
+                     set_attr(nqnv, attr_ruby_maxprep, p)
+                  end
+               end
+               set_attr(nqnv, attr_ruby_maxpostp, p)
+            end
+            Np.prev_ruby = has_attr(getfield(Nq.nuc, 'value'), attr_ruby_id)
+           -- 前のクラスタがルビであったことのフラグ
+         else -- 直前が文字以外
+           local nqnv = getfield(Nq.nuc, 'value')
+            if has_attr(nqnv, attr_ruby_maxpostp) < 0 then -- auto
+              set_attr(nqnv, attr_ruby_maxpostp, 0)
+              if has_attr(nqnv, attr_ruby_mode)%4 >= 2 then
+                 set_attr(nqnv, attr_ruby_maxprep, 0)
+              end
+           end
+         end
+        return true
+      else
+        return s
+      end
+   end
+   luatexbase.add_to_callback("luatexja.jfmglue.whatsit_after", whatsit_after_callback,
+                              "luatexja.ruby.np_info_after", 1)
+end
+