OSDN Git Service

luatexja-ruby v0.6: added mode=100xx
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Sat, 31 Dec 2022 07:25:55 +0000 (16:25 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Sat, 31 Dec 2022 07:25:55 +0000 (16:25 +0900)
doc/luatexja-ruby.pdf
doc/luatexja-ruby.tex
src/addons/luatexja-ruby.sty
src/ltj-ruby.lua

index 870d996..c8488d0 100644 (file)
Binary files a/doc/luatexja-ruby.pdf and b/doc/luatexja-ruby.pdf differ
index e51f455..c7e05e8 100644 (file)
@@ -10,6 +10,7 @@
 \setmonojfont{HaranoAjiGothic-Regular.otf}
 \usepackage{unicode-math}
 \setmathfont{Latin Modern Math}
+%\usepackage{lua-visual-debug}
 
 \def\emph#1{\textbf{\textgt{#1}}}
 \def\headfont{\normalfont\bfseries\gtfamily}
@@ -168,12 +169,12 @@ plain \LuaTeX でのロードはまだサポートしておらず,
 \item[post=<real>] 同様に,\underline{後文字進入許容量}を指定する.既定値は負(自動指定).
 
 \item[mode] 進入処理のモードを表すbit vector.下位2\,bitは,\texttt{pre}や
-\texttt{post}が負である場合にしか効力を発揮しない.既定値は$(0001)_2 = 1$.
+\texttt{post}が負である場合にしか効力を発揮しない.既定値は$(00001)_2 = 1$.
 \begin{description}
  \item[bit 0] 前後の\underline{文字への進入}を無効にするならば0,有効にするならば1.
  \item[bit 1] 前進入許容量$B$と後進入許容量$A$が異なった場合,
   そのまま処理する場合は0,小さい方に揃えるならば1.
- \item[bit 2--3] ルビ文字の突出量から実際の前・後進入量の計算方法を指定する.
+ \item[bit 2--4] ルビ文字の突出量から実際の前・後進入量の計算方法を指定する.
   詳しい計算方法については\ref{ssec:calc_intrusion}\nobreak 小節を参照.
 \end{description}
 \item[intrude\_jfmgk=<bool>] 進入量算出の際に,前後のJFMグルーの自然長を考慮するか否か.既定値は真.
@@ -630,50 +631,68 @@ mode=9, stretch={1}{2}{1}, stretchruby={0}{0}{1}
   
   ルビ文字の突出量を$x$,
   親文字の文字数を$k+1$,親文字の前に入る空白量・間の空白量・後ろの空白量の比を$p:q:r$とする.
-  このとき,\texttt{mode}のbit 2,~3の値によって$b$,~$a$を次のように算出する:
+  このとき,\texttt{mode}のbit 2--4の値によって$b$,~$a$を次のように算出する:
 \begin{description}[labelindent=\zw]
- \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$.そうでなければ
+ \item[000] $b=\min(B, xp/(p+kq+r))$, \ $a=\min(A, xr/(p+kq+r))$
+ \item[001] $b=\min(B, x)$, \ $a=\min(A, \max(x-b,0))$
+ \item[010] $a=\min(A, x)$, \ $b=\min(B, \max(x-a,0))$
+ \item[011] $M=\min(B,A)$とおく.もし$x\le 2M$ならば$b=a=x/2$.そうでなければ
 \[
- b=\min\mleft(B, M + \frac{(x-2M)p}{p+kq+r}\mright),\qquad 
+ b=\min\mleft(B, M + \frac{(x-2M)p}{p+kq+r}\mright),\quad 
  a=\min\mleft(A, M + \frac{(x-2M)r}{p+kq+r}\mright).
 \]
+ \item[100] $M=\min(B,A)$とおく.もし$x\le 2M$ならば$b=a=x/2$.そうでなければ
+\[
+ b=\min(B, x-M),\quad a=\min(A,x-M)\quad \mbox{(どちらかは必ず$M$となる)}.
+\]
 \end{description}
 
+大雑把に言うと,最初の「000」は「組んだ後に進入量を決定」する方針,
+それ以外は「進入量を先に決定し,その後で組む」方針である.
 組み方の具体例を実際に示す.例示のため,平仮名にはルビが1字まで,「立」にはルビを
 0.5字分までかけてよいことにしている.
 \begin{description}[labelindent=\zw]
-\item[00]{\setkeys[ltj]{ruby}{mode=1}%
+\item[000]{\setkeys[ltj]{ruby}{mode=1}%
 \ltjsetparameter{rubypreintrusion={`立,0.5}, rubypostintrusion={`立,0.5}}%
 は\ltjruby{美}{うつく}しい
   \quad は\ltjruby{聴衆}{ちようしゆう}と\quad
 は\ltjruby{暁}{あかつき}立\quad
 は\ltjruby{峠}{とうげ}立\quad
-は\ltjruby{聴衆}{ちようしゆう}立\par}
-\item[01]{\setkeys[ltj]{ruby}{mode=5}%
+は\ltjruby{聴衆}{ちようしゆう}立\quad
+は\ltjruby{聴衆}{ちようしゆう}達\par}
+\item[001]{\setkeys[ltj]{ruby}{mode=5}%
 \ltjsetparameter{rubypreintrusion={`立,0.5}, rubypostintrusion={`立,0.5}}%
 は\ltjruby{美}{うつく}しい
   \quad は\ltjruby{聴衆}{ちようしゆう}と\quad
 は\ltjruby{暁}{あかつき}立\quad
 は\ltjruby{峠}{とうげ}立\quad
-は\ltjruby{聴衆}{ちようしゆう}立\par}
-\item[10]{%
+は\ltjruby{聴衆}{ちようしゆう}立\quad
+は\ltjruby{聴衆}{ちようしゆう}達\par}
+\item[010]{%
 \setkeys[ltj]{ruby}{mode=9}%
 \ltjsetparameter{rubypreintrusion={`立,0.5}, rubypostintrusion={`立,0.5}}%
 は\ltjruby{美}{うつく}しい
   \quad は\ltjruby{聴衆}{ちようしゆう}と\quad
 は\ltjruby{暁}{あかつき}立\quad
 は\ltjruby{峠}{とうげ}立\quad
-は\ltjruby{聴衆}{ちようしゆう}立\par}
-\item[11]{\setkeys[ltj]{ruby}{mode=13}%
+は\ltjruby{聴衆}{ちようしゆう}立\quad
+は\ltjruby{聴衆}{ちようしゆう}達\par}
+\item[011]{\setkeys[ltj]{ruby}{mode=13}%
+\ltjsetparameter{rubypreintrusion={`立,0.5}, rubypostintrusion={`立,0.5}}%
+は\ltjruby{美}{うつく}しい\quad
+は\ltjruby{聴衆}{ちようしゆう}と\quad
+は\ltjruby{暁}{あかつき}立\quad
+は\ltjruby{峠}{とうげ}立\quad
+は\ltjruby{聴衆}{ちようしゆう}立\quad
+は\ltjruby{聴衆}{ちようしゆう}達\par}
+\item[100]{\setkeys[ltj]{ruby}{mode=17}%
 \ltjsetparameter{rubypreintrusion={`立,0.5}, rubypostintrusion={`立,0.5}}%
 は\ltjruby{美}{うつく}しい\quad
 は\ltjruby{聴衆}{ちようしゆう}と\quad
 は\ltjruby{暁}{あかつき}立\quad
 は\ltjruby{峠}{とうげ}立\quad
-は\ltjruby{聴衆}{ちようしゆう}立\par}
+は\ltjruby{聴衆}{ちようしゆう}立\quad
+は\ltjruby{聴衆}{ちようしゆう}達\par}
 \end{description}
 \end{enumerate}
 
index 1e50b1f..4c6b697 100644 (file)
@@ -4,7 +4,7 @@
 
 % LaTeX only!
 \NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{luatexja-ruby}[2022-07-03 v0.53]
+\ProvidesPackage{luatexja-ruby}[2022-12-31 v0.6]
 \RequirePackage{luatexja}
 
 %%------------------
 %% 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 は今は無効
+%% bit 2--4: intrusion をどう使って親文字を配置するか
+%%    00: intrusion なしでとりあえず計算し,左右の突出分を進入に割り当てる
+%%    01: pre-intrusion でまかなえるだけまかない,無理なら post- も使う
+%%    10: post を優先
+%%    11: 2 min (pre,post) までは pre, post に均等配分しようとする
+%%   100: 2 min (pre,post) までは pre, post に均等配分.
+%%        それでだめでも pre, post でまかなえるまでまかなう
+%% ※ 01--100 で,intrusion で賄えきれなかった場合はいつものように伸長する.
+%% bit 5: 熟語ルビの際の処理方法(0: 常にグループ,1: 可能な限りブロックごとに)
+%%        ↑bit 5 は今は無効
 \ltj@@rkeydef{mode}
 %% intrusion 量強制固定(bit 0, bit 1 より優先,負数で「自動」)
 %% attr は sp 単位だが,ユーザーはルビ全角単位で指定する
index 047b53a..29b6fe1 100644 (file)
@@ -3,7 +3,7 @@
 --
 luatexbase.provides_module({
   name = 'luatexja.ruby',
-  date = '2022-08-29',
+  date = '2022-12-31',
   description = 'Ruby annotation',
 })
 luatexja.ruby = {}
@@ -318,7 +318,7 @@ local function enlarge_parent(r, p, tmp_tbl, no_begin, no_end)
    local pre_intrusion, post_intrusion
    local ppre, pmid, ppost = tmp_tbl.ppre, tmp_tbl.pmid, tmp_tbl.ppost
    local mapre, mapost = tmp_tbl.mapre, tmp_tbl.mapost
-   local intmode = (tmp_tbl.mode//4)%4
+   local intmode = (tmp_tbl.mode//4)%8
    if no_begin then mapre  = mapre + tmp_tbl.before_jfmgk end
    if no_end   then mapost = mapost + tmp_tbl.after_jfmgk end
    if (tmp_tbl.mode%4 >=2) and (tmp_tbl.pre<0) and (tmp_tbl.post<0) then
@@ -336,7 +336,7 @@ local function enlarge_parent(r, p, tmp_tbl, no_begin, no_end)
       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
+   elseif intmode==3 then
       local n = min(mapre, mapost)*2
       if n < sumprot then
          pre_intrusion = n/2; post_intrusion = n/2
@@ -346,6 +346,15 @@ local function enlarge_parent(r, p, tmp_tbl, no_begin, no_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))
+   else  --  intmode == 4
+      if 2*min(mapre, mapost) > sumprot then
+         pre_intrusion = sumprot//2; post_intrusion = sumprot/2
+      elseif mapre>=mapost then 
+         pre_intrusion, post_intrusion = min(mapre, sumprot-mapost), mapost
+      else
+         pre_intrusion, post_intrusion = mapre, min(mapost, sumprot-mapre)
+      end
+      p = enlarge(p, rwidth, ppre, pmid, ppost, pre_intrusion, post_intrusion)
    end
    setshift(r, -pre_intrusion)
    local rwidth = rwidth - pre_intrusion - post_intrusion