<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">%
% luatexja-ruby.sty
%

% LaTeX only!
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{luatexja-ruby}[2024-09-09 v0.7]
\RequirePackage{luatexja}

%%------------------
\newattribute\ltj@rubyattr
\ltj@rubyattr=0
\RequireLuaTeXjaSubmodule{ruby}

% ltjset/getparameter ã¸ã®è¿½åŠ&nbsp;è¨­å®š
% ã“ã‚Œã‚‰ã¯æ®µè½å˜ä½ã®è¨­å®šï¼Ž

%% å¼•æ•°ï¼šãƒ«ãƒ“å…¨è§’ã‚’å˜ä½ã¨ã—ãŸå®Ÿæ•°
%% ã“ã®æ–‡å­—ã¸ã® pre-, post-intrusion ã®è¨±å®¹é‡
\define@key[ltj]{japaram}{rubypreintrusion}{%
  \ltj@@set@stack@real{RIPRE}{-0x7FFFFFFF}{0x7FFFFFFF}#1\relax}
\define@key[ltj]{japaram}{rubypostintrusion}{%
  \ltj@@set@stack@real{RIPOST}{-0x7FFFFFFF}{0x7FFFFFFF}#1\relax}
\def\ltj@@set@stack@real#1#2#3{%
  \directlua{luatexja.stack.set_stack_perchar(luatexja.stack_table_index.#1,
    #2, #3, token.scan_word)}}

% ãƒ«ãƒ“ç”¨ã®ã‚­ãƒ¼è¨­å®š
\def\ltj@@rkeydef#1{
  \define@key[ltj]{ruby}{#1}{\expandafter\def\csname ltj@@rubyip@#1\endcsname{##1}}
}
%% bit 0: intrusion ã‚’æœ‰åŠ¹ã«ã™ã‚‹ã‹ï¼ˆ1: æœ‰åŠ¹ï¼‰
%% bit 1: å‰å¾Œã® intrusion è¨±å®¹é‡ã‚’å°ã•ã„æ–¹ã«æƒãˆã‚‹ (1: yes)
%% bit 2--4: intrusion ã‚’ã©ã†ä½¿ã£ã¦è¦ªæ–‡å­—ã‚’é…ç½®ã™ã‚‹ã‹
%%    00: intrusion ãªã—ã§ã¨ã‚Šã‚ãˆãšè¨ˆç®—ã—ï¼Œå·¦å³ã®çªå‡ºåˆ†ã‚’é€²å…¥ã«å‰²ã‚Šå½“ã¦ã‚‹
%%    01: pre-intrusion ã§ã¾ã‹ãªãˆã‚‹ã&nbsp;ã‘ã¾ã‹ãªã„ï¼Œç„¡ç†ãªã‚‰ post- ã‚‚ä½¿ã†
%%    10: post ã‚’å„ªå…ˆ
%%    11: 2 min (pre,post) ã¾ã§ã¯ pre, post ã«å‡ç­‰é…åˆ†ã—ã‚ˆã†ã¨ã™ã‚‹
%%   100: 2 min (pre,post) ã¾ã§ã¯ pre, post ã«å‡ç­‰é…åˆ†ï¼Ž
%%        ãã‚Œã§ã&nbsp;ã‚ã§ã‚‚ pre, post ã§ã¾ã‹ãªãˆã‚‹ã¾ã§ã¾ã‹ãªã†
%% â€» 01--100 ã§ï¼Œintrusion ã§è³„ãˆãã‚Œãªã‹ã£ãŸå&nbsp;´åˆã¯ã„ã¤ã‚‚ã®ã‚ˆã†ã«ä¼¸é•·ã™ã‚‹ï¼Ž
%% bit 5: ç†Ÿèªžãƒ«ãƒ“ã®éš›ã®å‡¦ç†æ–¹æ³•ï¼ˆ0: å¸¸ã«ã‚°ãƒ«ãƒ¼ãƒ—ï¼Œ1: å¯èƒ½ãªé™ã‚Šãƒ–ãƒ­ãƒƒã‚¯ã”ã¨ã«ï¼‰
%%        â†‘bit 5 ã¯ä»Šã¯ç„¡åŠ¹
%% bit 6: çªå‡ºéƒ¨åˆ†ã«ã¤ã„ã¦ lua-ul æœ‰åŠ¹ç¯„å›²ã‹ã‚‰é™¤å¤–ã™ã‚‹å‡¦ç†ã™ã‚‹ã‹
\ltj@@rkeydef{mode}
%% intrusion é‡å¼·åˆ¶å›ºå®šï¼ˆbit 0, bit 1 ã‚ˆã‚Šå„ªå…ˆï¼Œè²&nbsp;æ•°ã§ã€Œè‡ªå‹•ã€ï¼‰
%% attr ã¯ sp å˜ä½ã&nbsp;ãŒï¼Œãƒ¦ãƒ¼ã‚¶ãƒ¼ã¯ãƒ«ãƒ“å…¨è§’å˜ä½ã§æŒ‡å®šã™ã‚‹
\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} % è¡Œé&nbsp;­å½¢
\ltj@@rkeydef{stretcheol}  % è¡Œæœ«å½¢
\ltj@@rkeydef{stretch}     % è¡Œä¸­å½¢
%% ãƒ«ãƒ“ãŒä¼¸é•·ã™ã‚‹ã¨ãã®æ¯” {1}{2}{1} ãªã©ã¨0--7 ã®æ•° 3 ã¤ã§æŒ‡å®š
\ltj@@rkeydef{stretchruby}
%% ãƒ«ãƒ“&lt;è¦ªã®ã¨ãï¼Œãƒ«ãƒ“ã¨è¦ªæ–‡å­—ã®ç«¯ã®æœ€å¤§å€¤ 
%% attr ã¯ sp å˜ä½ã&nbsp;ãŒï¼Œãƒ¦ãƒ¼ã‚¶ãƒ¼ã¯è¦ªæ–‡å­—å…¨è§’å˜ä½ã§æŒ‡å®š
\ltj@@rkeydef{maxmargin}
%% ãƒ«ãƒ“ã¨è¦ªæ–‡å­—ã®åž‚ç›´æ–¹å‘ã®ç©ºã
%% attr ã¯ sp å˜ä½ã&nbsp;ãŒï¼Œãƒ¦ãƒ¼ã‚¶ãƒ¼ã¯è¦ªæ–‡å­—å…¨è§’å˜ä½ã§æŒ‡å®š
\ltj@@rkeydef{intergap}

%% epsilon: ãƒ¢ãƒŽãƒ«ãƒ“ * n ã«ã™ã‚‹éš›ã«ï¼Œãƒ«ãƒ“ã®æ–¹ãŒã©ã‚Œã&nbsp;ã‘è¦ªæ–‡å­—ã‚ˆã‚Šé•·ã„
%% çŠ¶æ³ã‚’è¨±å®¹ã™ã‚‹ã‹ï¼Žè¦ªæ–‡å­—å…¨è§’å˜ä½ï¼Žè¨ˆç®—èª¤å·®ã‚’æƒ³å®šï¼Ž
\ltj@@rkeydef{epsilon}

\ltj@@rkeydef{kenten}%% åœç‚¹æ–‡å­—
\ltj@@rkeydef{fontcmd}%% ãƒ•ã‚©ãƒ³ãƒˆ
\define@boolkey[ltj]{ruby}{rubysmash}[true]{}

\ltj@@rkeydef{ybaseheight} % ç¸¦çµ„ä»¥å¤– (yoko, utod, dtou)
\ltj@@rkeydef{tbaseheight} % ç¸¦çµ„
\define@key[ltj]{ruby}{baseheight}{%
  \expandafter\def\csname ltj@@rubyip@ybaseheight\endcsname{#1}%
  \expandafter\def\csname ltj@@rubyip@tbaseheight\endcsname{#1}%
}
%% ã“ã‚Œã‚‰ã®å€¤ãŒæ­£ã®ã¨ãï¼Œè¦ªæ–‡å­—ã®é«˜ã•ã‚’ã“ã®å€¤ï¼ˆ\zh å˜ä½ï¼‰ã¨ã¿ãªã™

\ltj@@rkeydef{yrubydepth} % ç¸¦çµ„ä»¥å¤– (yoko, utod, dtou)
\ltj@@rkeydef{trubydepth} % ç¸¦çµ„
\define@key[ltj]{ruby}{rubydepth}{%
  \expandafter\def\csname ltj@@rubyip@yrubydepth\endcsname{#1}%
  \expandafter\def\csname ltj@@rubyip@trubydepth\endcsname{#1}%
}

\define@boolkey[ltj]{ruby}{intrude_jfmgk}[true]{}
\define@boolkey[ltj]{ruby}{intrude_xkanjiskip}[true]{}
\define@boolkey[ltj]{ruby}{intrude_kanjiskip}[true]{}

\define@boolkey[ltj]{ruby}{always_highlight_protrusion}[true]{}

%%%%%%%% setkeys ã®åˆ¥å
\protected\def\ltjsetruby{\setkeys[ltj]{ruby}}

% ã“ã“ã‹ã‚‰ã¯ ruby ãƒžã‚¯ãƒ­å†…ã§ãªã‚“ã¨ã‹ã•ã‚Œã‚‹äº‹é&nbsp;…
%% ãƒ«ãƒ“ã¨è¦ªæ–‡å­—ã®å¤§ãã•ã®æ¯”
\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 ç”Ÿæˆ
\bgroup
\catcode`\_=11
\gdef\ltj@@ruby@create@table#1#2{% #1: ãƒ«ãƒ“å…¨è§’å¹…ï¼Œ#2: ãƒ«ãƒ“å…¨è§’é«˜ã•
    \string{
      eps = \ltj@safe@dimen{\ltj@@rubyip@epsilon\zw},
      before_jfmgk = 0, after_jfmgk = 0,
      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\zh},
      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),
      baseheight = \ltj@safe@dimen{\ifnum\ltjgetparameter{direction}=3
                     \ltj@@rubyip@tbaseheight\else\ltj@@rubyip@ybaseheight\fi\zh},
      rubydepth = \ltj@safe@dimen{\ifnum\ltjgetparameter{direction}=3
                     \ltj@@rubyip@trubydepth\else\ltj@@rubyip@yrubydepth\fi#2},
      intrude_jfmgk = \string{
       \ifltj@ruby@intrude_jfmgk [luatexja.icflag_table.FROM_JFM]=true,\fi
       \ifltj@ruby@intrude_kanjiskip
          [luatexja.icflag_table.KANJI_SKIP]=true,
          [luatexja.icflag_table.KANJI_SKIP_JFM]=true,
       \fi
       \ifltj@ruby@intrude_xkanjiskip
          [luatexja.icflag_table.XKANJI_SKIP]=true,
          [luatexja.icflag_table.XKANJI_SKIP_JFM]=true,
       \fi
       \string},
       quirk_protrusion =  \ifltj@ruby@always_highlight_protrusion false \else true \fi
    \string}
}
\egroup
%%%
%%% 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 -&gt; \ltj@@ruby@mark{a}\ltj@@ruby@mark{bc}
\let\ltj@@ruby@res\empty
\def\ltj@@ruby@ifx#1{%
  \ifx#1\expandafter\@firstoftwo
  \else\expandafter\@secondoftwo
  \fi
}
\def\ltj@@ruby@nil{\noexpand\ltj@@ruby@nil}
\def\ltj@@ruby@end{\noexpand\ltj@@ruby@end}
\def\ltj@@ruby@appto#1#2{%
  \expandafter\def\expandafter#1\expandafter{#1#2}%
}
\def\ltj@@ruby@decompbar#1{%
  \let\ltj@@ruby@res\@empty
  \ltj@@ruby@decompbar@loopa\ltj@@ruby@nil#1|\ltj@@ruby@end|%
}
\def\ltj@@ruby@decompbar@loopa#1|{%
  \expandafter\ltj@@ruby@decompbar@loopb\expandafter{\@gobble#1}%
}
\def\ltj@@ruby@decompbar@loopb#1{%
  \ltj@@ruby@decompbar@loopc#1\relax\ltj@@ruby@nil{#1}%
}
\def\ltj@@ruby@decompbar@loopc#1#2\ltj@@ruby@nil#3{%
  \ltj@@ruby@ifx{#1\ltj@@ruby@end}{}{%
    \ifx\ltj@@ruby@res\@empty
      \def\ltj@@ruby@res{\ltj@@ruby@mark}%
    \else
      \ltj@@ruby@appto\ltj@@ruby@res{\ltj@@ruby@mark}%
    \fi
    \ltj@@ruby@appto\ltj@@ruby@res{{#3}}%
    \ltj@@ruby@decompbar@loopa\ltj@@ruby@nil
  }%
}
%%%%%%%% ã“ã“ã¾ã§

%%%%%%%% TeX command
\protected\def\ltjruby{\@ifnextchar[\ltj@@ruby{\ltj@@ruby[]}}%]
\AtBeginDocument{%
  \ifdefined\ruby\else\let\ruby=\ltjruby\fi
  \ifdefined\kenten\else\let\kenten=\ltjkenten\fi
  \directlua{luatexja.ruby.read_old_break_info()}%
}
\protected\def\ltj@@ruby[#1]#2#3{{% #1: option #2: è¦ªæ–‡å­—ç¾¤ï¼Œ#3: ãƒ«ãƒ“æ–‡å­—åˆ—ç¾¤ï¼Œå…±ã«| åŒºåˆ‡ã‚Š
  \leavevmode\setkeys[ltj]{ruby}{#1}%
  \directlua{luatexja.ruby.ruby_tmplist_r = \string{\string};
	luatexja.ruby.ruby_tmplist_p = \string{\string}}%
  \leavevmode\dimen0=\f@size pt\dimen1=\ltj@@rubyip@size\dimen0%
  % å¼•æ•°å±•é–‹ï¼Œãƒ†ãƒ¼ãƒ–ãƒ«ã«ã‚»ãƒƒãƒˆ
  \ltj@@ruby@decompbar{#2}{\let\ltj@@ruby@mark\ltj@@ruby@sp\ltj@@ruby@res}%
  \ltj@@ruby@decompbar{#3}{\let\ltj@@ruby@mark\ltj@@ruby@sr\ltj@@ruby@res}%
  {\fontsize{\ltj@@rubyip@size\dimen0}\z@\selectfont\ltj@@rubyip@fontcmd
    \global\dimen1=\zw\global\dimen2=\zh}%
  \directlua{%
    luatexja.ruby.texiface(\ltj@@ruby@create@table{\dimen1}{\dimen2},
    luatexja.ruby.ruby_tmplist_r, luatexja.ruby.ruby_tmplist_p)}%
}}

\def\ltj@@ruby@sr#1{%
  \setbox0=\hbox{\fontsize{\dimen1}\z@\ltj@@rubyip@fontcmd\selectfont#1}%
  \directlua{table.insert(luatexja.ruby.ruby_tmplist_r, luatexja.ruby.cpbox())}%
}
\def\ltj@@ruby@sp#1{%
  \setbox0=\hbox{\selectfont#1}%
  \directlua{table.insert(luatexja.ruby.ruby_tmplist_p, luatexja.ruby.cpbox())}%
}

\protected\def\ltjkenten{\@ifnextchar[\ltj@@kenten{\ltj@@kenten[]}}%]
\def\ltj@@kenten[#1]#2{{%
  \leavevmode\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@&lt;"30A0
  \ltjsetparameter{rubypreintrusion={\the\count@,1}, 
    rubypostintrusion={\the\count@,1}}
  \advance\count@1\repeat
%% ã‚«ã‚¿ã‚«ãƒŠ
\count@="30A0\loop\relax\ifnum \count@&lt;"3100
  \ltjsetparameter{rubypreintrusion={\the\count@,1}, 
    rubypostintrusion={\the\count@,1}}
  \advance\count@1\repeat
%% Kana Supplement
\count@="1B000\loop\relax\ifnum \count@&lt;"1B170
  \ltjsetparameter{rubypreintrusion={\the\count@,1}, 
    rubypostintrusion={\the\count@,1}}
  \advance\count@1\repeat
%% é–‹ãæ‹¬å¼§ãƒ»é–‰ã˜æ‹¬å¼§
\@for\@tmp:=`\â€˜,`\â€œ,`\ã€ˆ,`\ã€Š,`\ã€Œ,`\ã€Ž,`\ã€,`\ã€”,`\ã€–,`\ã€˜,`\ã€,`\ï¼ˆ,`\ï¼»,`\ï½›,`\ï½Ÿ \do
  {\ltjsetparameter{rubypreintrusion={\@tmp,-1}}}
\@for\@tmp:=`\â€™,`\â€,`\ã€‰,`\ã€‹,`\ã€,`\ã€,`\ã€‘,`\ã€•,`\ã€—,`\ã€™,`\ã€Ÿ,`\ï¼‰,`\ï¼½,`\ï½,`\ï½&nbsp; \do
  {\ltjsetparameter{rubypostintrusion={\@tmp,-1}}}
%% ä¸­ç‚¹é¡ž
\@for\@tmp:=`\ãƒ»,`\ï¼š,`\ï¼›,`\â€•,`\â€¥,`\â€¦,`ã€³,`\ã€´,`\ã€µ,"2014 \do
  {\ltjsetparameter{rubypreintrusion={\@tmp,0.5},rubypostintrusion={\@tmp,0.5}}}
%% èª­ç‚¹ãƒ»å¥ç‚¹
\@for\@tmp:=`\ã€,`\ï¼Œ,`\ã€‚,`\ï¼Ž \do
  {\ltjsetparameter{rubypostintrusion={\@tmp,-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=\textbullet, fontcmd=\relax, ybaseheight=0.88, tbaseheight=0.5,
  yrubydepth=0.12, trubydepth=0.5,
  intrude_jfmgk, intrude_kanjiskip, intrude_xkanjiskip,
  epsilon=0.0001, always_highlight_protrusion=false,
}

\endinput
</pre></body></html>