summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/CJK/ruby.sty
blob: 980855fbe85706365b2c273aac82c174be34d1cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
% This is the file ruby.sty of the CJK package
%   for displaying ruby (i.e. furigana).
%
% created by Werner Lemberg <wl@gnu.org>
%
% Version 4.6.0 (11-Aug-2005)

\NeedsTeXFormat{LaTeX2e}[1995/06/01]
\def\fileversion{4.6.0}
\def\filedate{2005/08/11}
\ProvidesPackage{ruby}[\filedate\space\fileversion]


\RequirePackage{CJK}[1996/11/20]

\newif\ifruby@overlap@
\newif\ifruby@CJK@

\DeclareOption{overlap}{\ruby@overlap@true}
\DeclareOption{nooverlap}{\ruby@overlap@false}
\DeclareOption{CJK}{\ruby@CJK@true}
\DeclareOption{latin}{\ruby@CJK@false}

\ExecuteOptions{overlap, CJK}

\ProcessOptions


% we suppress any unwanted spaces produced by linefeeds.

\endlinechar \m@ne

% to get a small separation between adjacent lines.

\lineskiplimit 1pt


\newdimen\ruby@width
\edef\ruby@kern{\kern -5sp\kern 5sp}

\newcommand{\rubysize}{0.4}
\newcommand{\rubysep}{-0.5ex}
\newcommand{\rubyoverlap}{\ruby@overlap@true}
\newcommand{\rubynooverlap}{\ruby@overlap@false}
\newcommand{\rubyCJK}{\ruby@CJK@true}
\newcommand{\rubylatin}{\ruby@CJK@false}


% #1 is the base character; #2 is the ruby.

\DeclareRobustCommand{\ruby}[2]{
  {\@tempdimc \f@size\p@
   \@tempdimc \rubysize\@tempdimc
   \sbox\z@{\vrule\@height.7\baselineskip\@depth\z@\@width\z@ #1}
   \sbox\@tempboxa{\fontsize{\@tempdimc}{1.2\@tempdimc}\selectfont
                   \vrule\@height\z@\@depth.3\baselineskip\@width\z@ #2}

   \@tempdimb\ruby@width

   \global\ruby@width \wd\@tempboxa
   \global\advance\ruby@width -\wd\z@
   \global\divide\ruby@width \tw@
   \ifdim\ruby@width > \z@
   \else
     \global\ruby@width \z@
   \fi

   % we first compute the box of the ruby with its base character(s).
   \ifruby@overlap@
     \setbox\@tempboxa \vbox{
       \hbox to \wd0{\hss \box\@tempboxa \hss}
       \nointerlineskip
       \kern\rubysep
       \box\z@}
   \else
     \ifdim\ruby@width > \z@
       \@tempdima \wd\@tempboxa
     \else
       \@tempdima \wd\z@
     \fi
     \setbox\@tempboxa \vbox{
       \hbox to \@tempdima{\hss \box\@tempboxa \hss}
       \nointerlineskip
       \kern\rubysep
       \hbox to \@tempdima{\hss \box\z@ \hss}}
   \fi

   % are we at the beginning of a paragraph?
   \ifvmode
     \leavevmode
     \ifruby@overlap@
       \kern\ruby@width
     \fi
   \else

     % has previous character a ruby?
     \ifnum\lastkern = 5%        \ruby@kern
       \kern\@tempdimb
       \ifruby@CJK@
         \nobreak
         \CJKglue
         \nobreak
       \fi
       \ifruby@overlap@
         \kern\ruby@width
       \fi
     \else

       \ifruby@CJK@

         % is previous character an ordinary CJK character?
         \ifnum\lastkern = \@ne%        \CJK@CJK
           \ifdim\ruby@width > \z@
             \nobreak
             \CJKglue
             \nobreak
           \else
             \CJKglue
           \fi
         \else

           % is previous character a punctuation character?
           \ifnum\lastkern = \tw@%      \CJK@kern
             \nobreak
             \CJKglue
             \nobreak
           \fi
         \fi
       \fi
     \fi
   \fi
  
   \box\@tempboxa

   \ruby@kern
   \ifdim\ruby@width > \z@
     \ifruby@overlap@
     \else
       \global\ruby@width\z@
     \fi
   \else
     \global\ruby@width\z@
   \fi}

  \ifruby@CJK@
    \ignorespaces
  \fi}


% reset endline character.

\endlinechar `\^^M

\endinput