summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/third
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2012-11-30 23:33:24 +0000
committerKarl Berry <karl@freefriends.org>2012-11-30 23:33:24 +0000
commite5046e6899a74738971f588716d03accf66cab88 (patch)
tree9ecc17242559dad1feed3bd5f14226af8f98678d /Master/texmf-dist/tex/context/third
parent76def1765b0dafeba9f05e03b8ae3d89bf3b234d (diff)
context-ruby (29nov12)
git-svn-id: svn://tug.org/texlive/trunk@28398 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/third')
-rw-r--r--Master/texmf-dist/tex/context/third/ruby/t-ruby.mkii (renamed from Master/texmf-dist/tex/context/third/ruby/t-ruby.tex)47
-rw-r--r--Master/texmf-dist/tex/context/third/ruby/t-ruby.mkiv283
-rw-r--r--Master/texmf-dist/tex/context/third/ruby/t-ruby.mkvi357
3 files changed, 645 insertions, 42 deletions
diff --git a/Master/texmf-dist/tex/context/third/ruby/t-ruby.tex b/Master/texmf-dist/tex/context/third/ruby/t-ruby.mkii
index 99321922d9b..7f2a6e26800 100644
--- a/Master/texmf-dist/tex/context/third/ruby/t-ruby.tex
+++ b/Master/texmf-dist/tex/context/third/ruby/t-ruby.mkii
@@ -1,6 +1,6 @@
%D \module
%D [ file=t-ruby,
-%D version=2010.01.26,
+%D version=2010.10.10,
%D title=\CONTEXT\ User Module,
%D subtitle=Ruby Markup,
%D author=Wolfgang Schuster,
@@ -42,7 +42,7 @@
%D </ruby>
%D \stoptyping
-%D Constants
+%D Constants/variables
\startinterface all
\setinterfaceconstant {basestyle} {basestyle}
@@ -70,43 +70,6 @@
\newtoks \!!rubybase
\newtoks \!!rubytext
-%D Helpers
-
-\newif\ifideograph
-
-\long\def\doifelseideograph#1%
- {\global\ideographtrue
- \handletokens#1\with\checkideograph
- \ifideograph
- \expandafter\firstoftwoarguments
- \else
- \expandafter\secondoftwoarguments
- \fi}
-
-\def\doifinrangeelse#1#2#3%
- {\unless\ifnum#1<#2
- \unless\ifnum#1>#3
- \expandafter\expandafter\expandafter\firstoftwoarguments
- \else
- \expandafter\expandafter\expandafter\secondoftwoarguments
- \fi
- \else
- \expandafter\secondoftwoarguments
- \fi}
-
-\def\checkideograph#1%
- {\doifinrangeelse{`#1}{"3040}{"309F}\donothing
- {\doifinrangeelse{`#1}{"30A0}{"30FF}\donothing
- {\doifinrangeelse{`#1}{"31F0}{"31FF}\donothing
- {\doifinrangeelse{`#1}{"3400}{"4DFF}\donothing
- {\doifinrangeelse{`#1}{"4E00}{"9FFF}\donothing
- {\doifinrangeelse{`#1}{"AC00}{"D7A3}\donothing
- {\doifinrangeelse{`#1}{"F900}{"FAFF}\donothing
- {\doifinrangeelse{`#1}{"FF00}{"FFEF}\donothing
- {\doifinrangeelse{`#1}{"20000}{"2A6DF}\donothing
- {\doifinrangeelse{`#1}{"2F800}{"2FA1F}\donothing
- {\ideographfalse}}}}}}}}}}}
-
%D \macros
%D {setupruby}
@@ -162,8 +125,8 @@
%D Alignment
-\def\RUBYdistributespace #1{\doifelseideograph{#1}{\processtokens{\hss }{\hss\hss}{\hss }{\hss\hss}{#1}}{\hss#1\hss}}
-\def\RUBYdistributeletter#1{\doifelseideograph{#1}{\processtokens{\relax}{\hss }{\relax}{\hss\hss}{#1}}{\hss#1\hss}}
+\def\RUBYdistributespace #1{\processtokens{\hss }{\hss\hss}{\hss }{\hss\hss}{#1}}
+\def\RUBYdistributeletter#1{\processtokens{\relax}{\hss }{\relax}{\hss\hss}{#1}}
\setvalue{\????rb:\c!align:\v!space}%
{\!!rubyleftmargin \zeropoint
@@ -302,7 +265,7 @@
%D {ruby}
\def\ruby
- {\dosingleempty\doruby}
+ {\dontleavehmode\dosingleempty\doruby}
\def\doruby[#1]#2#3%
{\dobRUBY[#1]\bRB#2\eRB\bRT#3\eRT\eRUBY}
diff --git a/Master/texmf-dist/tex/context/third/ruby/t-ruby.mkiv b/Master/texmf-dist/tex/context/third/ruby/t-ruby.mkiv
new file mode 100644
index 00000000000..d90330a41b1
--- /dev/null
+++ b/Master/texmf-dist/tex/context/third/ruby/t-ruby.mkiv
@@ -0,0 +1,283 @@
+%D \module
+%D [ file=t-ruby,
+%D version=2010.11.23,
+%D title=\CONTEXT\ User Module,
+%D subtitle=Ruby Markup,
+%D author=Wolfgang Schuster,
+%D date=\currentdate,
+%D copyright=Wolfgang Schuster,
+%D email=schuster.wolfgang@googlemail.com,
+%D license=Public Domain]
+
+\writestatus{loading}{ConTeXt User Module / Ruby Markup}
+
+\unprotect
+
+%D simple ruby:
+%D
+%D \starttyping
+%D <ruby>
+%D <rb>WWW</rb>
+%D <rt>World Wide Web</rt>
+%D </ruby>
+%D \stoptyping
+%D
+%D complex ruby:
+%D
+%D \starttyping
+%D <ruby>
+%D <rbc>
+%D <rb>10</rb>
+%D <rb>31</rb>
+%D <rb>2002</rb>
+%D </rbc>
+%D <rtc>
+%D <rt>Month</rt>
+%D <rt>Day</rt>
+%D <rt>Year</rt>
+%D </rtc>
+%D <rtc>
+%D <rt rbspan="3">Expiration Date</rt>
+%D </rtc>
+%D </ruby>
+%D \stoptyping
+
+%D Constants/variables
+
+\startinterface all
+ \setinterfaceconstant {basestyle} {basestyle}
+ \setinterfaceconstant {basecolor} {basecolor}
+ \setinterfaceconstant {overhang} {overhang}
+\stopinterface
+
+\startinterface all
+ \setinterfacevariable {letter} {letter}
+ \setinterfacevariable {end} {end}
+ \setinterfacevariable {inline} {inline}
+\stopinterface
+
+%D Namespace
+
+\def\????rb{@@@@rb}
+
+%D Additional registers
+
+\newdimen \!!rubywidth
+\newdimen \!!rubyleftmargin
+\newdimen \!!rubyrightmargin
+\newsignal\!!rubysignal
+\newcount \!!rubycount
+\newtoks \!!rubybase
+\newtoks \!!rubytext
+
+%D \macros
+%D {setupruby}
+
+\def\setupruby
+ {\dodoubleargument\getparameters[\????rb]}
+
+\def\rubyparameter#1{\csname\????rb#1\endcsname}
+
+%D \macros
+%D {bRUBY,eRUBY,bRB,eRB,bRT,eRT}
+
+\def\bRUBY
+ {\dosingleempty\dobRUBY}
+
+\def\dobRUBY[#1]%
+ {\begingroup
+ \iffirstargument
+ \setupruby[#1]%
+ \fi
+ \scratchdimen\lastskip
+ \ifdim\scratchdimen=\!!rubysignal\else\global\!!rubywidth\!!zeropoint\fi
+ \global\advance\!!rubycount\plusone
+ \xypos{rubyposition:\number\!!rubycount}%
+ \doifmodeelse\v!first
+ {\edef\rubyposition{\the\onepoint}}%
+ {\edef\rubyposition{\the\dimexpr\MPx{rubyposition:\number\!!rubycount}-\MPx{text:\the\realpageno}\relax}}}
+
+\def\eRUBY
+ {\setbox\scratchboxone\hbox{\redoconvertfont\doattributes\????rb\c!basestyle\c!basecolor{\the\!!rubybase}}%
+ \setbox\scratchboxtwo\hbox{\redoconvertfont\doattributes\????rb\c!textstyle\c!textcolor{\the\!!rubytext}}%
+ \scratchdimenone\wd\scratchboxone
+ \scratchdimentwo\wd\scratchboxtwo
+ %\scratchdimenthree\ifdim\scratchdimenone<\scratchdimentwo\space\scratchdimenone\else\scratchdimentwo\fi
+ \scratchdimenthree\scratchdimenone
+ \executeifdefined{\????rb:\c!align :\rubyparameter\c!align }{\getvalue{\????rb:\c!align :\v!auto }}%
+ \executeifdefined{\????rb:\c!position:\rubyparameter\c!position}{\getvalue{\????rb:\c!position:\v!before}}%
+ \executeifdefined{\????rb:\c!overhang:\rubyparameter\c!overhang}{\getvalue{\????rb:\c!overhang:\v!auto }}%
+ \hskip\!!rubysignal\relax
+ \endgroup}
+
+\def\bRB{\dodoubleempty\dobRB}
+\def\bRT{\dodoubleempty\dobRT}
+
+\def\dobRB[#1][#2]#3\eRB{\!!rubybase{#3}}
+\def\dobRT[#1][#2]#3\eRT{\!!rubytext{#3}}
+
+\def\placerubystrut{\doif{\rubyparameter\c!strut}\v!yes{\setstrut\strut}}
+
+%D Alignment
+
+\def\RUBYdistributespace #1{\processtokens{\hss }{\hss\hss}{\hss }{\hss\hss}{#1}}
+\def\RUBYdistributeletter#1{\processtokens{\relax}{\hss }{\relax}{\hss\hss}{#1}}
+
+\setvalue{\????rb:\c!align:\v!space}%
+ {\!!rubyleftmargin \zeropoint
+ \!!rubyrightmargin\zeropoint
+ \ifdim\scratchdimenone>\scratchdimentwo
+ \setbox\scratchboxone\hbox to \scratchdimenone{\hss\box\scratchboxone\hss}%
+ \setbox\scratchboxtwo\hbox to \scratchdimenone{\redoconvertfont\doattributes\????rb\c!textstyle\c!textcolor{\@EA\RUBYdistributespace\@EA{\the\!!rubytext}}}%
+ \else
+ \setbox\scratchboxone\hbox to \scratchdimentwo{\redoconvertfont\doattributes\????rb\c!basestyle\c!basecolor{\@EA\RUBYdistributespace\@EA{\the\!!rubybase}}}%
+ \setbox\scratchboxtwo\hbox to \scratchdimentwo{\hss\box\scratchboxtwo\hss}%
+ \fi}
+
+\setvalue{\????rb:\c!align:\v!letter}%
+ {\!!rubyleftmargin \zeropoint
+ \!!rubyrightmargin\zeropoint
+ \ifdim\scratchdimenone>\scratchdimentwo
+ \setbox\scratchboxone\hbox to \scratchdimenone{\hss\box\scratchboxone\hss}%
+ \setbox\scratchboxtwo\hbox to \scratchdimenone{\redoconvertfont\doattributes\????rb\c!textstyle\c!textcolor{\@EA\RUBYdistributeletter\@EA{\the\!!rubytext}}}%
+ \else
+ \setbox\scratchboxone\hbox to \scratchdimentwo{\redoconvertfont\doattributes\????rb\c!basestyle\c!basecolor{\@EA\RUBYdistributeletter\@EA{\the\!!rubybase}}}%
+ \setbox\scratchboxtwo\hbox to \scratchdimentwo{\hss\box\scratchboxtwo\hss}%
+ \fi}
+
+\setvalue{\????rb:\c!align:\v!auto}% I need special alignments for the begin/end of the line!!!
+ {\ifdim\scratchdimenone>\scratchdimentwo
+ \getvalue{\????rb:\c!align:\v!space}%
+ \else
+ \ifdim\rubyposition=\!!zeropoint % begin of the line
+ \getvalue{\????rb:\c!align:\v!left}%
+ \else\ifdim\rubyposition=\the\dimexpr\textwidth-\scratchdimenthree\relax % end of the line
+ \getvalue{\????rb:\c!align:\v!right}%
+ \else
+ \getvalue{\????rb:\c!align:\v!space}%
+ \fi\fi
+ \fi}
+
+\setvalue{\????rb:\c!align:\v!left}%
+ {\ifdim\scratchdimenone>\scratchdimentwo
+ \!!rubyleftmargin \zeropoint
+ \!!rubyrightmargin\zeropoint
+ \else
+ \!!rubyleftmargin \zeropoint
+ \!!rubyrightmargin\dimexpr\scratchdimentwo-\scratchdimenone\relax
+ \fi
+ \setbox\scratchboxone\hbox to \scratchdimenthree{\box\scratchboxone\hss}%
+ \setbox\scratchboxtwo\hbox to \scratchdimenthree{\box\scratchboxtwo\hss}}
+
+\setvalue{\????rb:\c!align:\v!start}%
+ {\getvalue{\????rb:\c!align:\v!left}}
+
+\setvalue{\????rb:\c!align:\v!center}%
+ {\ifdim\scratchdimenone>\scratchdimentwo
+ \!!rubyleftmargin \zeropoint
+ \!!rubyrightmargin\zeropoint
+ \else
+ \!!rubyleftmargin \dimexpr(\scratchdimentwo-\scratchdimenone)/2\relax
+ \!!rubyrightmargin\dimexpr(\scratchdimentwo-\scratchdimenone)/2\relax
+ \fi
+ \setbox\scratchboxone\hbox to \scratchdimenthree{\hss\box\scratchboxone\hss}%
+ \setbox\scratchboxtwo\hbox to \scratchdimenthree{\hss\box\scratchboxtwo\hss}}
+
+\setvalue{\????rb:\c!align:\v!right}%
+ {\ifdim\scratchdimenone>\scratchdimentwo
+ \!!rubyleftmargin \zeropoint
+ \!!rubyrightmargin\zeropoint
+ \else
+ \!!rubyleftmargin \dimexpr\scratchdimentwo-\scratchdimenone\relax
+ \!!rubyrightmargin\zeropoint
+ \fi
+ \setbox\scratchboxone\hbox to \scratchdimenthree{\hss\box\scratchboxone}%
+ \setbox\scratchboxtwo\hbox to \scratchdimenthree{\hss\box\scratchboxtwo}}
+
+\setvalue{\????rb:\c!align:\v!end}%
+ {\getvalue{\v!ruby:\c!align:\v!right}}
+
+\setvalue{\????rb:\c!align:\v!edge}% modify to take care of overlap etc.
+ {\ifdim\rubyposition=\zeropoint
+ \getvalue{\????rb:\c!align:\v!left}%
+ \else\ifdim\rubyposition=\the\dimexpr\textwidth-\scratchdimenthree\relax
+ \getvalue{\????rb:\c!align:\v!right}%
+ \else
+ \getvalue{\????rb:\c!align:\v!center}%
+ \fi\fi}
+
+%D Positioning
+
+\setvalue{\????rb:\c!position:\v!before}%
+ {\setbox\scratchboxthree\vbox
+ {\offinterlineskip
+ \hbox{\undepthed{\placerubystrut\box\scratchboxtwo}}
+ \rubyparameter\c!inbetween
+ \hbox{\placerubystrut\box\scratchboxone}}}
+
+\setvalue{\????rb:\c!position:\v!after}%
+ {\setbox\scratchboxthree\vtop
+ {\offinterlineskip
+ \hbox{\undepthed{\placerubystrut\box\scratchboxone}}
+ \rubyparameter\c!inbetween
+ \hbox{\placerubystrut\box\scratchboxtwo}}}
+
+\setvalue{\????rb:\c!position:\v!inline}% pure text to allow line breaks in the text
+ {\setbox\scratchboxthree\box\voidbox
+ \!!rubyleftmargin \zeropoint
+ \!!rubyrightmargin\zeropoint
+ \the\!!rubybase
+ \rubyparameter\c!separator
+ \rubyparameter\c!lefttext\the\!!rubytext\rubyparameter\c!righttext}
+
+%D Overhang
+
+\setvalue{\????rb:\c!overhang:\v!auto}%
+ {\ifdim\!!rubywidth>\!!zeropoint
+ \kern\dimexpr\!!rubyleftmargin+\!!rubywidth\relax
+ \fi
+ \box\scratchboxthree
+ \global\!!rubywidth\!!rubyrightmargin}
+
+\setvalue{\????rb:\c!overhang:\v!start}%
+ {\box\scratchboxthree\kern\!!rubyrightmargin
+ \global\!!rubywidth\!!rubyrightmargin}
+
+\setvalue{\????rb:\c!overhang:\v!end}%
+ {\ifdim\!!rubywidth>\!!zeropoint
+ \kern\dimexpr\!!rubyleftmargin+\!!rubywidth\relax
+ \else
+ \kern\!!rubyleftmargin
+ \fi
+ \box\scratchboxthree
+ \global\!!rubywidth\!!zeropoint}
+
+\setvalue{\????rb:\c!overhang:\v!none}%
+ {\kern\!!rubyleftmargin\box\scratchboxthree\kern\!!rubyrightmargin
+ \global\!!rubywidth\!!zeropoint}
+
+%D \macros
+%D {ruby}
+
+\def\ruby
+ {\dontleavehmode\dosingleempty\doruby}
+
+\def\doruby[#1]#2#3%
+ {\pdfactualtext
+ {\dobRUBY[#1]\bRB#2\eRB\bRT#3\eRT\eRUBY}
+ {#2\rubyparameter\c!separator\rubyparameter\c!lefttext#3\rubyparameter\c!righttext}}
+
+%D Default values
+
+\setupruby
+ [\c!position=\v!before, % before|after|inline
+ \c!align=\v!auto, % auto|start|left|center|end|right|distribute-letter|distribute-space|line-edge
+ \c!overhang=\v!auto, % auto|start|end|none
+ \c!separator={ },
+ \c!lefttext=(,
+ \c!righttext=),
+ \c!strut=\v!no,
+ \c!inbetween={\blank[\v!small]},
+ \c!textstyle=\txx]
+
+\protect \endinput
diff --git a/Master/texmf-dist/tex/context/third/ruby/t-ruby.mkvi b/Master/texmf-dist/tex/context/third/ruby/t-ruby.mkvi
new file mode 100644
index 00000000000..14268356c15
--- /dev/null
+++ b/Master/texmf-dist/tex/context/third/ruby/t-ruby.mkvi
@@ -0,0 +1,357 @@
+%D \module
+%D [ file=t-ruby,
+%D version=2012.03.13,
+%D title=\CONTEXT\ User Module,
+%D subtitle=Ruby Markup,
+%D author=Wolfgang Schuster,
+%D date=\currentdate,
+%D copyright=Wolfgang Schuster,
+%D email=schuster.wolfgang@googlemail.com,
+%D license=Public Domain]
+
+\writestatus{loading}{ConTeXt User Module / Ruby Markup}
+
+\unprotect
+
+%D simple ruby:
+%D
+%D \starttyping
+%D <ruby>
+%D <rb>WWW</rb>
+%D <rt>World Wide Web</rt>
+%D </ruby>
+%D \stoptyping
+%D
+%D complex ruby:
+%D
+%D \starttyping
+%D <ruby>
+%D <rbc>
+%D <rb>10</rb>
+%D <rb>31</rb>
+%D <rb>2002</rb>
+%D </rbc>
+%D <rtc>
+%D <rt>Month</rt>
+%D <rt>Day</rt>
+%D <rt>Year</rt>
+%D </rtc>
+%D <rtc>
+%D <rt rbspan="3">Expiration Date</rt>
+%D </rtc>
+%D </ruby>
+%D \stoptyping
+
+%D Constants/variables
+
+\startinterface all
+ \setinterfaceconstant {basestyle} {basestyle}
+ \setinterfaceconstant {basecolor} {basecolor}
+ \setinterfaceconstant {overhang} {overhang}
+ \setinterfaceconstant {base} {base}
+\stopinterface
+
+\startinterface all
+ \setinterfacevariable {letter} {letter}
+ \setinterfacevariable {end} {end}
+ \setinterfacevariable {inline} {inline}
+ \setinterfacevariable {ruby} {ruby}
+\stopinterface
+
+%D Lua
+
+\startluacode
+
+thirddata = thirddata or { }
+thirddata.ruby = thirddata.ruby or { }
+
+function thirddata.ruby.doifelsecjk(string)
+ local state = true
+ for c in unicode.utf8.gmatch(string,".") do
+ local n = scripts.hash[utf.byte(c)]
+ if not ( n == "chinese" or n == "korean" ) then
+ state = false
+ break
+ end
+ end
+ commands.doifelse(state)
+end
+
+\stopluacode
+
+%D Namespace
+
+\installnamespace {ruby}
+\installnamespace {rubyalign}
+\installnamespace {rubyalternative}
+\installnamespace {rubyoverhang}
+
+%D Additional registers
+
+\newdimen \d_ruby_width
+\newdimen \d_ruby_base
+\newdimen \d_ruby_text
+\newdimen \d_ruby_left
+\newdimen \d_ruby_right
+\newdimen \d_ruby_position
+
+\newsignal \s_ruby_signal
+
+\newcount \c_ruby_n
+
+\newtoks \t_ruby_base
+\newtoks \t_ruby_text
+
+\newbox \b_ruby_base
+\newbox \b_ruby_text
+\newbox \b_ruby_box
+
+%D \macros
+%D {defineruby,setupruby}
+
+\installcommandhandler \????ruby {ruby} \????ruby
+
+%D \macros
+%D {ruby}
+
+\unexpanded\def\ruby_cmd#name%
+ {\dontleavehmode
+ \begingroup
+ \edef\currentruby{#name}%
+ \dosingleempty\ruby_cmd_indeed}
+
+\unexpanded\def\ruby_cmd_indeed[#parameters]#base#text%
+ {\setupcurrentruby[#parameters,\c!base={#base},\c!text={#text}]%
+ \scratchdimen\lastskip
+ \ifdim\scratchdimen=\s_ruby_signal\else\global\d_ruby_width\zeropoint\fi
+ \global\advance\c_ruby_n\plusone
+ \xypos{rubyposition:\number\c_ruby_n}%
+ \doifmodeelse\v!first
+ {\d_ruby_position\onepoint}%
+ {\d_ruby_position\dimexpr\MPx{rubyposition:\number\c_ruby_n}-\MPx{text:\number\realpageno}\relax}%
+ \setbox\b_ruby_base\hbox{\userubystyleandcolor\c!basestyle\c!basecolor{\directrubyparameter\c!base}}%
+ \setbox\b_ruby_text\hbox{\userubystyleandcolor\c!textstyle\c!textcolor{\directrubyparameter\c!text}}%
+ \d_ruby_base\wd\b_ruby_base
+ \d_ruby_text\wd\b_ruby_text
+ \expandcheckedcsname\????rubyalign {\rubyparameter\c!align }\v!auto
+ \expandcheckedcsname\????rubyalternative{\rubyparameter\c!alternative}\v!top
+ \expandcheckedcsname\????rubyoverhang {\rubyparameter\c!overhang }\v!auto
+ \hskip\s_ruby_signal\relax
+ \endgroup}
+
+\appendtoks
+ \setuevalue\currentruby{\ruby_cmd{\currentruby}}%
+\to \everydefineruby
+
+%D Alignment
+%D
+%D \startitemize[packed]
+%D \item left
+%D \item middle
+%D \item right
+%D \item auto
+%D \item letter
+%D \item space
+%D \stopitemize
+
+\unexpanded\def\ruby_distribute_space #1{\processtokens{\hss }{\hss\hss}{\hss }{\hss\hss}{#1}}
+\unexpanded\def\ruby_distribute_letter#1{\processtokens{\relax}{\hss }{\relax}{\hss\hss}{#1}}
+
+\setvalue{\????rubyalign\v!space}% stretch?
+ {\d_ruby_left \zeropoint
+ \d_ruby_right\zeropoint
+ \ifdim\d_ruby_base>\d_ruby_text
+ \setbox\b_ruby_base\hbox to \d_ruby_base{\hss\box\b_ruby_base\hss}%
+ \setbox\b_ruby_text\hbox to \d_ruby_base{\userubystyleandcolor\c!textstyle\c!textcolor{\normalexpanded{\ruby_distribute_space{\directrubyparameter\c!text}}}}%
+ \else
+ \setbox\b_ruby_base\hbox to \d_ruby_text{\userubystyleandcolor\c!basestyle\c!basecolor{\normalexpanded{\ruby_distribute_space{\directrubyparameter\c!base}}}}%
+ \setbox\b_ruby_text\hbox to \d_ruby_text{\hss\box\b_ruby_text\hss}%
+ \fi}
+
+\setvalue{\????rubyalign\v!letter}% !!!
+ {\d_ruby_left \zeropoint
+ \d_ruby_right\zeropoint
+ \ifdim\d_ruby_base>\d_ruby_test
+ \setbox\b_ruby_base\hbox to \d_ruby_base{\hss\box\b_ruby_base\hss}%
+ \setbox\b_ruby_text\hbox to \d_ruby_base{\userubystyleandcolor\c!textstyle\c!textcolor{\normalexpanded{\ruby_distribute_letter{\directrubyparameter\c!text}}}}%
+ \else
+ \setbox\b_ruby_base\hbox to \d_ruby_text{\userubystyleandcolor\c!basestyle\c!basecolor{\normalexpanded{\ruby_distribute_letter{\directrubyparameter\c!base}}}}%
+ \setbox\b_ruby_text\hbox to \d_ruby_text{\hss\box\b_ruby_text\hss}%
+ \fi}
+
+\setvalue{\????rubyalign\v!auto}%
+ {\ifdim\d_ruby_base>\d_ruby_text
+ \ctxlua{thirddata.ruby.doifelsecjk("\directrubyparameter\c!base")}\donetrue\donefalse
+ \ifdone
+ \getvalue{\????rubyalign\v!space}%
+ \else
+ \getvalue{\????rubyalign\v!middle}%
+ \fi
+ \else
+ \ifdim\d_ruby_position=\zeropoint % begin of the line
+ \getvalue{\????rubyalign\v!left}%
+ \else\ifdim\d_ruby_position=\dimexpr\textwidth-\d_ruby_base\relax % end of the line
+ \getvalue{\????rubyalign\v!right}%
+ \else
+ \ctxlua{thirddata.ruby.doifelsecjk("\directrubyparameter\c!text")}\donetrue\donefalse
+ \ifdone
+ \getvalue{\????rubyalign\v!space}%
+ \else
+ \getvalue{\????rubyalign\v!middle}%
+ \fi
+ \fi\fi
+ \fi}
+
+\setvalue{\????rubyalign\v!left}%
+ {\ifdim\d_ruby_base>\d_ruby_text
+ \d_ruby_left \zeropoint
+ \d_ruby_right\zeropoint
+ \else
+ \d_ruby_left \zeropoint
+ \d_ruby_right\dimexpr\d_ruby_text-\d_ruby_base\relax
+ \fi
+ \setbox\b_ruby_base\hbox to \d_ruby_base{\box\b_ruby_base\hss}%
+ \setbox\b_ruby_text\hbox to \d_ruby_base{\box\b_ruby_text\hss}}
+
+\setvalue{\????rubyalign\v!middle}%
+ {\ifdim\d_ruby_base>\d_ruby_text
+ \d_ruby_left \zeropoint
+ \d_ruby_right\zeropoint
+ \else
+ \d_ruby_left \dimexpr(\d_ruby_text-\d_ruby_base)/2\relax
+ \d_ruby_right\dimexpr(\d_ruby_text-\d_ruby_base)/2\relax
+ \fi
+ \setbox\b_ruby_base\hbox to \d_ruby_base{\hss\box\b_ruby_base\hss}%
+ \setbox\b_ruby_text\hbox to \d_ruby_base{\hss\box\b_ruby_text\hss}}
+
+\setvalue{\????rubyalign\v!right}%
+ {\ifdim\d_ruby_base>\d_ruby_base
+ \d_ruby_left \zeropoint
+ \d_ruby_right\zeropoint
+ \else
+ \d_ruby_left \dimexpr\d_ruby_text-\d_ruby_base\relax
+ \d_ruby_right\zeropoint
+ \fi
+ \setbox\b_ruby_base\hbox to \d_ruby_base{\hss\box\b_ruby_base}%
+ \setbox\b_ruby_text\hbox to \d_ruby_base{\hss\box\b_ruby_text}}
+
+\setvalue{\????rubyalign\v!margin}% modify to take care of overlap etc.
+ {\ifdim\d_ruby_position=\zeropoint
+ \getvalue{\????rubyalign\v!left}%
+ \else\ifdim\d_ruby_position=\dimexpr\textwidth-\d_ruby_base\relax
+ \getvalue{\????rubyalign\v!right}%
+ \else
+ \getvalue{\????rubyalign\v!middle}%
+ \fi\fi}
+
+%D Alternative
+%D
+%D \startitemize[packed]
+%D \item top
+%D \item bottom
+%D \item text
+%D \stopitemize
+
+% \setvalue{\????rubyalternative\v!none}% needed for \pdfactualtext
+% {\directrubyparameter\c!base
+% \rubyparameter\c!separator
+% \rubyparameter\c!lefttext
+% \directrubyparameter\c!text
+% \rubyparameter\c!righttext}
+
+\setvalue{\????rubyalternative\v!top}%
+ {\setbox\b_ruby_box\vbox
+ {\doifsomething{\rubyparameter\c!strut}{\setupstrut[\rubyparameter\c!strut]}%
+ \offinterlineskip
+ \hbox{\undepthed{\begstrut\box\b_ruby_text\endstrut}}
+ \rubyparameter\c!inbetween
+ \hbox{\begstrut\box\b_ruby_base\endstrut}}}
+
+\setvalue{\????rubyalternative\v!bottom}%
+ {\setbox\b_ruby_box\vtop
+ {\doifsomething{\rubyparameter\c!strut}{\setupstrut[\rubyparameter\c!strut]}%
+ \offinterlineskip
+ \hbox{\undepthed{\begstrut\box\b_ruby_base\endstrut}}
+ \rubyparameter\c!inbetween
+ \hbox{\begstrut\box\b_ruby_text\endstrut}}}
+
+\setvalue{\????rubyalternative\v!text}% pure text to allow line breaks in the text
+ {\setbox\b_ruby_box\box\voidbox
+ \d_ruby_left \zeropoint
+ \d_ruby_right\zeropoint
+ \directrubyparameter\c!base
+ \rubyparameter\c!separator
+ \rubyparameter\c!lefttext\directrubyparameter\c!text\rubyparameter\c!righttext}
+
+\unexpanded\def\ruby_alternative_vertical#text%
+ {\setbox\scratchbox\vbox
+ {\userubystyleandcolor\c!textstyle\c!textcolor
+ \setupinterlinespace[\rubyparameter\c!interlinespace]%
+ \handletokens#text\with\hbox
+ \par}%
+ \lower\dimexpr(\ht\scratchbox+\strutdp-\strutht)/2-\rubyparameter\c!dy\relax\box\scratchbox}
+
+\setvalue{\????rubyalternative\v!vertical}%
+ {\d_ruby_left \zeropoint
+ \d_ruby_right\zeropoint
+ \setbox\b_ruby_box\hbox\bgroup
+ \begingroup
+ \userubystyleandcolor\c!basestyle\c!basecolor
+ \directrubyparameter\c!base
+ \endgroup
+ \normalexpanded{\ruby_alternative_vertical{\directrubyparameter\c!text}}%
+ \egroup}
+
+%D Overhang
+%D
+%D \startitemize[packed]
+%D \item left
+%D \item right
+%D \item auto
+%D \item none
+%D \stopitemize
+
+\setvalue{\????rubyoverhang\v!auto}%
+ {\ifdim\d_ruby_width>\zeropoint
+ \kern\dimexpr\d_ruby_left+\d_ruby_width\relax
+ \fi
+ \box\b_ruby_box
+ \global\d_ruby_width\d_ruby_right}
+
+\setvalue{\????rubyoverhang\v!left}%
+ {\box\b_ruby_box\kern\d_ruby_right
+ \global\d_ruby_width\d_ruby_right}
+
+\setvalue{\????rubyoverhang\v!right}%
+ {\ifdim\d_ruby_width>\zeropoint
+ \kern\dimexpr\d_ruby_left+\d_ruby_width\relax
+ \else
+ \kern\d_ruby_left
+ \fi
+ \box\b_ruby_box
+ \global\d_ruby_width\zeropoint}
+
+\setvalue{\????rubyoverhang\v!none}%
+ {\kern\d_ruby_left\box\b_ruby_box\kern\d_ruby_right
+ \global\d_ruby_width\zeropoint}
+
+%D \macros
+%D {ruby}
+
+\defineruby[\v!ruby]
+
+%D Default values
+
+\setupruby
+ [\c!alternative=\v!top,
+ \c!align=\v!auto,
+ \c!overhang=\v!auto,
+ \c!dy=\zeropoint,
+ \c!separator={ },
+ \c!lefttext={(},
+ \c!righttext={)},
+ \c!strut=\v!no,
+ \c!inbetween={\blank[\v!small]},
+ \c!textstyle=\txx]
+
+\protect \endinput