%From: den@atr-la.atr.co.jp (Yasuharu Den)
%Newsgroups: fj.comp.texhax
%Subject: Re: Oval enclosing a word?
%Message-ID: <5405@atr-la.atr.co.jp>
%Date: 24 Jul 92 02:29:32 GMT
%Organization: ATR Interpreting Telephony Research Labs., Japan

% miscbox.sty by Yasuharu Den (23 Jul 1992)
%                             (24 Jul 1992)

% \dbox{DashDimen}{Text}
% \dashbox{DashDimen}[Wdth][Pos]{Text}
% \dashbox{DashDimen}(XDimen,YDimen)[Pos]{Text}
%
\let\@iDashpicbox\dashbox

\def\dashbox#1{%
  \@ifnextchar({\@Dashpicbox{#1}}%
               {\@ifnextchar[{\@Dashbox{#1}}{\dbox{#1}}}%
}

\long\def\dbox#1#2{%
  \leavevmode
  \setbox\@tempboxa\hbox{#2}%
  \@tempdima\fboxrule
  \advance\@tempdima\fboxsep \advance\@tempdima\dp\@tempboxa
  \setbox\@tempboxa\hbox{%
    \hskip\fboxsep
    \vbox{\vskip\fboxsep \box\@tempboxa\vskip\fboxsep}%
    \hskip\fboxsep
  }%
  \@tempdimb\wd\@tempboxa
  \edef\X@Dashbox{\expandafter\@RemoveDim\the\@tempdimb}%
  \@tempdimb\ht\@tempboxa \advance\@tempdimb\dp\@tempboxa
  \edef\Y@Dashbox{\expandafter\@RemoveDim\the\@tempdimb}%
  \@tempdimb#1\unitlength
  \edef\Dash@Dashbox{\expandafter\@RemoveDim\the\@tempdimb}%
  \hbox{\lower \@tempdima\hbox{\unitlength1pt
    \@Dashpicbox{\Dash@Dashbox}(\X@Dashbox,\Y@Dashbox){\box\@tempboxa}%
  }}%
}

\def\@Dashbox#1[#2]{%
  \@ifnextchar[{\@iDashbox#1[#2]}{\@iDashbox#1[#2][x]}%
}

\long\def\@iDashbox#1[#2][#3]#4{%
  \leavevmode
  \savebox\@tempboxa[#2][#3]{\hbox{\kern\fboxsep #4\kern\fboxsep}}%
  \@tempdima\fboxrule
  \advance\@tempdima\fboxsep \advance\@tempdima\dp\@tempboxa
  \setbox\@tempboxa\hbox{%
    \hskip-\fboxrule
    \vbox{\vskip\fboxsep \box\@tempboxa\vskip\fboxsep}%
    \hskip-\fboxrule
  }%
  \@tempdimb\wd\@tempboxa
  \edef\X@Dashbox{\expandafter\@RemoveDim\the\@tempdimb}%
  \@tempdimb\ht\@tempboxa \advance\@tempdimb\dp\@tempboxa
  \edef\Y@Dashbox{\expandafter\@RemoveDim\the\@tempdimb}%
  \@tempdimb#1\unitlength
  \edef\Dash@Dashbox{\expandafter\@RemoveDim\the\@tempdimb}%
  \hbox{\lower \@tempdima\hbox{\unitlength1pt
    \@Dashpicbox{\Dash@Dashbox}(\X@Dashbox,\Y@Dashbox){\box\@tempboxa}%
  }}%
}

\def\@Dashpicbox#1(#2,#3){%
  \@ifnextchar[{\@iDashpicbox{#1}(#2,#3)}%
               {\@iDashpicbox{#1}(#2,#3)[]}%
}

% \obox{Text}
% \ovalbox[Wdth][Pos]{Text}
% \ovalbox(XDimen,YDimen)[Pos]{Text}
%
\def\ovalbox{%
  \@ifnextchar({\@Ovalpicbox}%
               {\@ifnextchar[{\@Ovalbox}{\obox}}%
}

\long\def\obox#1{%
  \leavevmode
  \setbox\@tempboxa\hbox{#1}%
  \@tempdima\fboxrule
  \advance\@tempdima\fboxsep \advance\@tempdima\dp\@tempboxa
  \setbox\@tempboxa\hbox{%
    \hskip\fboxsep
    \vbox{\vskip\fboxsep \box\@tempboxa\vskip\fboxsep}%
    \hskip\fboxsep
  }%
  \@tempdimb\wd\@tempboxa
  \edef\X@Ovalbox{\expandafter\@RemoveDim\the\@tempdimb}%
  \@tempdimb\ht\@tempboxa \advance\@tempdimb\dp\@tempboxa
  \edef\Y@Ovalbox{\expandafter\@RemoveDim\the\@tempdimb}%
  \hbox{\lower \@tempdima\hbox{\unitlength1pt
    \@Ovalpicbox(\X@Ovalbox,\Y@Ovalbox){\box\@tempboxa}%
  }}%
}

\def\@Ovalbox[#1]{%
  \@ifnextchar[{\@iOvalbox[#1]}{\@iOvalbox[#1][x]}%
}

\long\def\@iOvalbox[#1][#2]#3{%
  \leavevmode
  \savebox\@tempboxa[#1][#2]{\hbox{\kern\fboxsep #3\kern\fboxsep}}%
  \@tempdima\fboxrule
  \advance\@tempdima\fboxsep \advance\@tempdima\dp\@tempboxa
  \setbox\@tempboxa\hbox{%
    \hskip-\fboxrule
    \vbox{\vskip\fboxsep \box\@tempboxa\vskip\fboxsep}%
    \hskip-\fboxrule
  }%
  \@tempdimb\wd\@tempboxa
  \edef\X@Ovalbox{\expandafter\@RemoveDim\the\@tempdimb}%
  \@tempdimb\ht\@tempboxa \advance\@tempdimb\dp\@tempboxa
  \edef\Y@Ovalbox{\expandafter\@RemoveDim\the\@tempdimb}%
  \hbox{\lower \@tempdima\hbox{\unitlength1pt
    \@Ovalpicbox(\X@Ovalbox,\Y@Ovalbox){\box\@tempboxa}%
  }}%
}

\def\@Ovalpicbox(#1,#2){%
  \@ifnextchar[{\@iOvalpicbox(#1,#2)}%
               {\@iOvalpicbox(#1,#2)[]}%
}

\def\@iOvalpicbox(#1,#2)[#3]#4{%
  \leavevmode
  \hbox{%
    \hskip -\@wholewidth
    \vbox{%
      \vskip -\@wholewidth
      \hbox{%
        \@imakepicbox(#1,#2)[#3]{#4}%
        \@tempdima#1\unitlength \@tempdimb#2\unitlength
        \hskip -\@tempdima
        \raise .5\@tempdimb\hbox{%
          \hskip .5\@tempdima
          \@oval(#1,#2)[]%
          \hskip .5\@tempdima}%
      }%
      \vskip -\@wholewidth
    }%
    \hskip -\@wholewidth
  }%
}

% \@RemoveDim by Hideki Isozaki
{\catcode`\p = 12 \catcode`\t = 12
\gdef\@RemoveDim#1pt{#1}}

