1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18\writestatus{loading}{ConTeXt Typesetting Macros Rubies}
19
20\unprotect
21
22\registerctxluafile{typorub}{}
23
24\definesystemattribute[ruby][public]
25
26\installcorenamespace {ruby}
27\installcorenamespace {rubyanalyze}
28\installcorenamespace {rubyplacement}
29\installcorenamespace {rubynumber}
30
31\installcommandhandler \??ruby {ruby} \??ruby
32
33
34
35
36
37
38
39
40
41
42\unexpanded\def\ruby
43 {\dosingleempty\typo_ruby_yes}
44
45\unexpanded\def\typo_ruby_yes[#1]#2#3
46 {\dontleavehmode
47 \begingroup
48 \let\typo_ruby_yes\typo_ruby_nop
49 \edef\currentruby{#1}
50 \edef\p_location{\rubyparameter\c!location}
51 \let\relax
52 \ifcsname\??rubyanalyze\p_location\endcsname
53 \expandafter\lastnamedcs\else\expandafter\typo_ruby_analyze
54 \fi{#2}{#3}
55 \endgroup}
56
57\unexpanded\def\typo_ruby_nop[#1]#2#3
58 {#2}
59
60\def\typo_ruby_analyze#1#2
61 {\clf_ruby
62 base {#1}
63 comment {#2}
64 \relax}
65
66\setvalue{\??rubyanalyze\v!top}#1#2
67 {\clf_ruby
68 align {\rubyparameter\c!align}
69 stretch {\rubyparameter\c!stretch}
70 hoffset \rubyparameter\c!hoffset
71 voffset \rubyparameter\c!voffset
72 base {#1}
73 comment {#2}
74 \relax}
75
76\setvalue{\??rubyplacement\v!top}#1#2
77 {\setbox\scratchbox\hbox\bgroup
78 \userubystyleandcolor\c!style\c!color
79 #2
80 \egroup
81 \clf_setruby \scratchbox
82 \relax
83 #1}
84
85\setvalue{\??rubyplacement\v!right}#1#2
86 {#1
87 \edef\p_distance{\rubyparameter\c!distance}
88 \ifx\p_distance\empty\else\ifx\p_distance\v!none\else\hskip\p_distance\fi\fi
89 \begingroup
90 \userubystyleandcolor\c!style\c!color
91 \rubyparameter\c!left#2\rubyparameter\c!right
92 \endgroup}
93
94\setvalue{\??rubyplacement\v!left}#1#2
95 {\begingroup
96 \userubystyleandcolor\c!style\c!color
97 \rubyparameter\c!left#2\rubyparameter\c!right
98 \endgroup
99 \edef\p_distance{\rubyparameter\c!distance}
100 \ifx\p_distance\empty\else\ifx\p_distance\v!none\else\hskip\p_distance\fi\fi
101 #1}
102
103\unexpanded\def\setruby#1#2
104 {\begingroup
105 \ifcsname\??rubyplacement\p_location\endcsname
106 \lastnamedcs{#1}{#2}
107 \else
108 #1
109 \fi
110 \endgroup}
111
112\unexpanded\def\startruby
113 {\dosingleempty\typo_ruby_start_yes}
114
115\unexpanded\def\typo_ruby_start_yes[#1]
116 {\dontleavehmode
117 \begingroup
118 \let\typo_ruby_start_yes\begingroup
119 \edef\currentruby{#1}
120 \clf_startruby
121 align {\rubyparameter\c!align}
122 stretch {\rubyparameter\c!stretch}
123 hoffset \rubyparameter\c!hoffset
124 voffset \rubyparameter\c!voffset
125 \relax}
126
127\unexpanded\def\stopruby
128 {\endgroup}
129
130\setupruby
131 [\c!style=\txx,
132 \c!location=\v!top,
133 \c!left=(,
134 \c!right=),
135 \c!distance=\zeropoint,
136 \c!hoffset=\zeropoint,
137 \c!voffset=2\exheight]
138
139
140
141\unexpanded\def\numberedruby[#1]#2
142 {\doifnotcounter{\??rubynumber#1}{\definecounter[\??rubynumber#1]\setcounter[\??rubynumber#1][1]}
143 \ruby[#1]{#2}{\convertedcounter[\??rubynumber#1]}
144 \incrementcounter[\??rubynumber#1]
145 \relax}
146
147\protect \endinput
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180 |