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}{autosuffix}
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\permanent\tolerant\protected\def\ruby[#1]#:#2#3
43 {\dontleavehmode
44 \begingroup
45 \enforced\let\ruby\noruby
46 \cdef\currentruby{#1}
47 \edef\p_location{\rubyparameter\c!location}
48
49 \enforced\letcharcode\barasciicode\relax
50 \ifcsname\??rubyanalyze\p_location\endcsname
51 \expandafter\lastnamedcs\else\expandafter\typo_ruby_analyze
52 \fi{#2}{#3}
53 \endgroup}
54
55\permanent\tolerant\protected\def\noruby[#1]#:#2#3
56 {#2}
57
58\def\typo_ruby_analyze#1#2
59 {\clf_ruby
60 base {#1}
61 comment {#2}
62 \relax}
63
64\defcsname\??rubyanalyze\v!top\endcsname#1#2
65 {\clf_ruby
66 align {\rubyparameter\c!align}
67 stretch {\rubyparameter\c!stretch}
68 hoffset {\rubyparameter\c!hoffset}
69 voffset {\rubyparameter\c!voffset}
70 base {#1}
71 comment {#2}
72 \relax}
73
74\defcsname\??rubyplacement\v!top\endcsname#1#2
75 {\setbox\scratchbox\hbox\bgroup
76 \userubystyleandcolor\c!style\c!color
77 #2
78 \egroup
79 \clf_setruby \scratchbox
80 \relax
81 #1}
82
83\defcsname\??rubyplacement\v!right\endcsname#1#2
84 {#1
85 \edef\p_distance{\rubyparameter\c!distance}
86 \ifempty\p_distance\orelse\ifx\p_distance\v!none\else\hskip{\p_distance}\relax\fi
87 \begingroup
88 \userubystyleandcolor\c!style\c!color
89 \rubyparameter\c!left#2\rubyparameter\c!right
90 \endgroup}
91
92\defcsname\??rubyplacement\v!left\endcsname#1#2
93 {\begingroup
94 \userubystyleandcolor\c!style\c!color
95 \rubyparameter\c!left#2\rubyparameter\c!right
96 \endgroup
97 \edef\p_distance{\rubyparameter\c!distance}
98 \ifempty\p_distance\orelse\ifx\p_distance\v!none\else\hskip{\p_distance}\relax\fi
99 #1}
100
101\permanent\protected\def\setruby#1#2
102 {\begingroup
103 \ifcsname\??rubyplacement\p_location\endcsname
104 \lastnamedcs{#1}{#2}
105 \else
106 #1
107 \fi
108 \endgroup}
109
110\permanent\tolerant\protected\def\startruby[#1]
111 {\dontleavehmode
112 \begingroup
113 \enforced\aliased\startruby\begingroup
114 \cdef\currentruby{#1}
115 \clf_startruby
116 align {\rubyparameter\c!align}
117 stretch {\rubyparameter\c!stretch}
118 hoffset {\rubyparameter\c!hoffset}
119 voffset {\rubyparameter\c!voffset}
120 \relax}
121
122\permanent\protected\def\stopruby
123 {\endgroup}
124
125\setupruby
126 [\c!style=\txx,
127 \c!location=\v!top,
128 \c!left=(,
129 \c!right=),
130 \c!distance=\zeropoint,
131 \c!hoffset=\zeropoint,
132 \c!voffset=2\exheight]
133
134
135
136\permanent\protected\def\numberedruby[#1]#2
137 {\doifnotcounter{\??rubynumber#1}{\definecounter[\??rubynumber#1]\setcounter[\??rubynumber#1][1]}
138 \ruby[#1]{#2}{\convertedcounter[\??rubynumber#1]}
139 \incrementcounter[\??rubynumber#1]
140 \relax}
141
142\protect \endinput
143
144
145
146
147
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 |