summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Master/texmf-dist/tex/context/third/ruby/t-ruby.mkvi206
1 files changed, 121 insertions, 85 deletions
diff --git a/Master/texmf-dist/tex/context/third/ruby/t-ruby.mkvi b/Master/texmf-dist/tex/context/third/ruby/t-ruby.mkvi
index 14268356c15..21f6ae9a221 100644
--- a/Master/texmf-dist/tex/context/third/ruby/t-ruby.mkvi
+++ b/Master/texmf-dist/tex/context/third/ruby/t-ruby.mkvi
@@ -1,6 +1,6 @@
%D \module
%D [ file=t-ruby,
-%D version=2012.03.13,
+%D version=2012.12.01,
%D title=\CONTEXT\ User Module,
%D subtitle=Ruby Markup,
%D author=Wolfgang Schuster,
@@ -47,15 +47,12 @@
\startinterface all
\setinterfaceconstant {basestyle} {basestyle}
\setinterfaceconstant {basecolor} {basecolor}
- \setinterfaceconstant {overhang} {overhang}
- \setinterfaceconstant {base} {base}
+ \setinterfaceconstant {rubybase} {rubybase}
+ \setinterfaceconstant {rubytext} {rubytext}
\stopinterface
\startinterface all
\setinterfacevariable {letter} {letter}
- \setinterfacevariable {end} {end}
- \setinterfacevariable {inline} {inline}
- \setinterfacevariable {ruby} {ruby}
\stopinterface
%D Lua
@@ -84,13 +81,11 @@ end
\installnamespace {ruby}
\installnamespace {rubyalign}
\installnamespace {rubyalternative}
-\installnamespace {rubyoverhang}
+\installnamespace {rubyhang}
%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
@@ -114,33 +109,47 @@ end
%D \macros
%D {ruby}
-\unexpanded\def\ruby_cmd#name%
+\unexpanded\def\ruby
+ {\dontleavehmode
+ \begingroup
+ \let\currentruby\empty
+ \dosingleempty\ruby_direct_indeed}
+
+\unexpanded\def\ruby_direct#name%
{\dontleavehmode
\begingroup
\edef\currentruby{#name}%
- \dosingleempty\ruby_cmd_indeed}
+ \dosingleempty\ruby_direct_indeed}
-\unexpanded\def\ruby_cmd_indeed[#parameters]#base#text%
- {\setupcurrentruby[#parameters,\c!base={#base},\c!text={#text}]%
+\def\ruby_direct_indeed[#parameters]#rubybase#rubytext%
+ {\setupcurrentruby[#parameters,\c!rubybase={#rubybase},\c!rubytext={#rubytext}]%
+ %
\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\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
+ %
+ \setbox\b_ruby_base\hbox{\userubystyleandcolor\c!basestyle\c!basecolor\directrubyparameter\c!rubybase}%
+ \setbox\b_ruby_text\hbox{\userubystyleandcolor\c!textstyle\c!textcolor\directrubyparameter\c!rubytext}%
+ %
+ \edef\p_ruby_align {\rubyparameter\c!align }%
+ \edef\p_ruby_alternative{\rubyparameter\c!alternative}%
+ \edef\p_ruby_hang {\rubyparameter\c!hang }%
+ %
+ \ruby_align
+ \ruby_alternative
+ \ruby_hang
+ %
\hskip\s_ruby_signal\relax
\endgroup}
\appendtoks
- \setuevalue\currentruby{\ruby_cmd{\currentruby}}%
+ \setuevalue\currentruby{\ruby_direct{\currentruby}}%
\to \everydefineruby
%D Alignment
@@ -157,93 +166,106 @@ end
\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?
+\def\ruby_align_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}}}}%
+ \ifdim\wd\b_ruby_base>\wd\b_ruby_text
+ \setbox\b_ruby_base\hbox to \wd\b_ruby_base{\hss\box\b_ruby_base\hss}%
+ \setbox\b_ruby_text\hbox to \wd\b_ruby_base{\userubystyleandcolor\c!textstyle\c!textcolor\normalexpanded{\ruby_distribute_space{\directrubyparameter\c!rubytext}}}%
\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}%
+ \setbox\b_ruby_base\hbox to \wd\b_ruby_text{\userubystyleandcolor\c!basestyle\c!basecolor\normalexpanded{\ruby_distribute_space{\directrubyparameter\c!rubybase}}}%
+ \setbox\b_ruby_text\hbox to \wd\b_ruby_text{\hss\box\b_ruby_text\hss}%
\fi}
-\setvalue{\????rubyalign\v!letter}% !!!
+\def\ruby_align_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}}}}%
+ \ifdim\wd\b_ruby_base>\wd\b_ruby_test
+ \setbox\b_ruby_base\hbox to \wd\b_ruby_base{\hss\box\b_ruby_base\hss}%
+ \setbox\b_ruby_text\hbox to \wd\b_ruby_base{\userubystyleandcolor\c!textstyle\c!textcolor\normalexpanded{\ruby_distribute_letter{\directrubyparameter\c!rubytext}}}%
\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}%
+ \setbox\b_ruby_base\hbox to \wd\b_ruby_text{\userubystyleandcolor\c!basestyle\c!basecolor\normalexpanded{\ruby_distribute_letter{\directrubyparameter\c!rubybase}}}%
+ \setbox\b_ruby_text\hbox to \wd\b_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
+\def\ruby_align_auto
+ {\ifdim\wd\b_ruby_base>\wd\b_ruby_text
+ \ctxlua{thirddata.ruby.doifelsecjk("\directrubyparameter\c!rubybase")}\donetrue\donefalse
\ifdone
- \getvalue{\????rubyalign\v!space}%
+ \ruby_align_stretch
\else
- \getvalue{\????rubyalign\v!middle}%
+ \ruby_align_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}%
+ \ruby_align_left
+ \else\ifdim\d_ruby_position=\dimexpr\textwidth-\wd\b_ruby_base\relax % end of the line
+ \ruby_align_right
\else
- \ctxlua{thirddata.ruby.doifelsecjk("\directrubyparameter\c!text")}\donetrue\donefalse
+ \ctxlua{thirddata.ruby.doifelsecjk("\directrubyparameter\c!rubytext")}\donetrue\donefalse
\ifdone
- \getvalue{\????rubyalign\v!space}%
+ \ruby_align_stretch
\else
- \getvalue{\????rubyalign\v!middle}%
+ \ruby_align_middle
\fi
\fi\fi
\fi}
-\setvalue{\????rubyalign\v!left}%
- {\ifdim\d_ruby_base>\d_ruby_text
+\def\ruby_align_left
+ {\ifdim\wd\b_ruby_base>\wd\b_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
+ \d_ruby_right\dimexpr\wd\b_ruby_text-\wd\b_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}}
+ \setbox\b_ruby_base\hbox to \wd\b_ruby_base{\box\b_ruby_base\hss}%
+ \setbox\b_ruby_text\hbox to \wd\b_ruby_base{\box\b_ruby_text\hss}}
-\setvalue{\????rubyalign\v!middle}%
- {\ifdim\d_ruby_base>\d_ruby_text
+\def\ruby_align_middle
+ {\ifdim\wd\b_ruby_base>\wd\b_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
+ \d_ruby_left \dimexpr(\wd\b_ruby_text-\wd\b_ruby_base)/2\relax
+ \d_ruby_right\dimexpr(\wd\b_ruby_text-\wd\b_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}}
+ \setbox\b_ruby_base\hbox to \wd\b_ruby_base{\hss\box\b_ruby_base\hss}%
+ \setbox\b_ruby_text\hbox to \wd\b_ruby_base{\hss\box\b_ruby_text\hss}}
-\setvalue{\????rubyalign\v!right}%
- {\ifdim\d_ruby_base>\d_ruby_base
+\def\ruby_align_right
+ {\ifdim\wd\b_ruby_base>\wd\b_ruby_base
\d_ruby_left \zeropoint
\d_ruby_right\zeropoint
\else
- \d_ruby_left \dimexpr\d_ruby_text-\d_ruby_base\relax
+ \d_ruby_left \dimexpr\wd\b_ruby_text-\wd\b_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}}
+ \setbox\b_ruby_base\hbox to \wd\b_ruby_base{\hss\box\b_ruby_base}%
+ \setbox\b_ruby_text\hbox to \wd\b_ruby_base{\hss\box\b_ruby_text}}
-\setvalue{\????rubyalign\v!margin}% modify to take care of overlap etc.
+\def\ruby_align_margin
{\ifdim\d_ruby_position=\zeropoint
- \getvalue{\????rubyalign\v!left}%
- \else\ifdim\d_ruby_position=\dimexpr\textwidth-\d_ruby_base\relax
- \getvalue{\????rubyalign\v!right}%
+ \ruby_align_left
+ \else\ifdim\d_ruby_position=\dimexpr\textwidth-\wd\b_ruby_base\relax
+ \ruby_align_right
\else
- \getvalue{\????rubyalign\v!middle}%
+ \ruby_align_middle
\fi\fi}
+\def\ruby_align
+ {\csname\????rubyalign
+ \ifcsname\????rubyalign\p_ruby_align\endcsname\p_ruby_align\else\v!auto\fi
+ \endcsname}
+
+\setvalue{\????rubyalign\v!auto }{\ruby_align_auto }
+\setvalue{\????rubyalign\v!left }{\ruby_align_left }
+\setvalue{\????rubyalign\v!right }{\ruby_align_right }
+\setvalue{\????rubyalign\v!middle }{\ruby_align_middle }
+\setvalue{\????rubyalign\v!letter }{\ruby_align_letter }
+\setvalue{\????rubyalign\v!stretch}{\ruby_align_stretch}
+\setvalue{\????rubyalign\v!margin }{\ruby_align_margin }
+
%D Alternative
%D
%D \startitemize[packed]
@@ -253,13 +275,13 @@ end
%D \stopitemize
% \setvalue{\????rubyalternative\v!none}% needed for \pdfactualtext
-% {\directrubyparameter\c!base
+% {\directrubyparameter\c!rubybase
% \rubyparameter\c!separator
% \rubyparameter\c!lefttext
-% \directrubyparameter\c!text
+% \directrubyparameter\c!rubytext
% \rubyparameter\c!righttext}
-\setvalue{\????rubyalternative\v!top}%
+\def\ruby_alternative_top
{\setbox\b_ruby_box\vbox
{\doifsomething{\rubyparameter\c!strut}{\setupstrut[\rubyparameter\c!strut]}%
\offinterlineskip
@@ -267,7 +289,7 @@ end
\rubyparameter\c!inbetween
\hbox{\begstrut\box\b_ruby_base\endstrut}}}
-\setvalue{\????rubyalternative\v!bottom}%
+\def\ruby_alternative_bottom
{\setbox\b_ruby_box\vtop
{\doifsomething{\rubyparameter\c!strut}{\setupstrut[\rubyparameter\c!strut]}%
\offinterlineskip
@@ -275,15 +297,15 @@ end
\rubyparameter\c!inbetween
\hbox{\begstrut\box\b_ruby_text\endstrut}}}
-\setvalue{\????rubyalternative\v!text}% pure text to allow line breaks in the text
+\def\ruby_alternative_text
{\setbox\b_ruby_box\box\voidbox
\d_ruby_left \zeropoint
\d_ruby_right\zeropoint
- \directrubyparameter\c!base
+ \directrubyparameter\c!rubybase
\rubyparameter\c!separator
- \rubyparameter\c!lefttext\directrubyparameter\c!text\rubyparameter\c!righttext}
+ \rubyparameter\c!lefttext\directrubyparameter\c!rubytext\rubyparameter\c!righttext}
-\unexpanded\def\ruby_alternative_vertical#text%
+\unexpanded\def\ruby_alternative_vertical_process#text%
{\setbox\scratchbox\vbox
{\userubystyleandcolor\c!textstyle\c!textcolor
\setupinterlinespace[\rubyparameter\c!interlinespace]%
@@ -291,17 +313,26 @@ end
\par}%
\lower\dimexpr(\ht\scratchbox+\strutdp-\strutht)/2-\rubyparameter\c!dy\relax\box\scratchbox}
-\setvalue{\????rubyalternative\v!vertical}%
+\def\ruby_alternative_vertical
{\d_ruby_left \zeropoint
\d_ruby_right\zeropoint
\setbox\b_ruby_box\hbox\bgroup
\begingroup
\userubystyleandcolor\c!basestyle\c!basecolor
- \directrubyparameter\c!base
+ \directrubyparameter\c!rubybase
\endgroup
- \normalexpanded{\ruby_alternative_vertical{\directrubyparameter\c!text}}%
+ \normalexpanded{\ruby_alternative_vertical_process{\directrubyparameter\c!rubytext}}%
\egroup}
+\def\ruby_alternative
+ {\csname\????rubyalternative
+ \ifcsname\????rubyalternative\p_ruby_alternative\endcsname\p_ruby_alternative\else\v!text\fi
+ \endcsname}
+
+\setvalue{\????rubyalternative\v!top }{\ruby_alternative_top }
+\setvalue{\????rubyalternative\v!bottom}{\ruby_alternative_bottom}
+\setvalue{\????rubyalternative\v!text }{\ruby_alternative_text }
+
%D Overhang
%D
%D \startitemize[packed]
@@ -311,18 +342,18 @@ end
%D \item none
%D \stopitemize
-\setvalue{\????rubyoverhang\v!auto}%
+\def\ruby_hang_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}%
+\def\ruby_hang_left
{\box\b_ruby_box\kern\d_ruby_right
\global\d_ruby_width\d_ruby_right}
-\setvalue{\????rubyoverhang\v!right}%
+\def\ruby_hang_right
{\ifdim\d_ruby_width>\zeropoint
\kern\dimexpr\d_ruby_left+\d_ruby_width\relax
\else
@@ -331,21 +362,26 @@ end
\box\b_ruby_box
\global\d_ruby_width\zeropoint}
-\setvalue{\????rubyoverhang\v!none}%
+\def\ruby_hang_none
{\kern\d_ruby_left\box\b_ruby_box\kern\d_ruby_right
\global\d_ruby_width\zeropoint}
-%D \macros
-%D {ruby}
+\def\ruby_hang
+ {\csname\????rubyhang
+ \ifcsname\????rubyhang\p_ruby_hang\endcsname\p_ruby_hang\else\v!auto\fi
+ \endcsname}
-\defineruby[\v!ruby]
+\setvalue{\????rubyhang\v!auto }{\ruby_hang_auto }
+\setvalue{\????rubyhang\v!left }{\ruby_hang_left }
+\setvalue{\????rubyhang\v!right}{\ruby_hang_right}
+\setvalue{\????rubyhang\v!none }{\ruby_hang_none }
%D Default values
\setupruby
[\c!alternative=\v!top,
\c!align=\v!auto,
- \c!overhang=\v!auto,
+ \c!hang=\v!auto,
\c!dy=\zeropoint,
\c!separator={ },
\c!lefttext={(},