%%% kotexutf.tex
%%   2010.01.04  v1.1
%%
%% Copyright (C) 2010  Dohyun Kim <nomos@ktug.or.kr>
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3c
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%  http://www.latex-project.org/lppl.txt
%% and version 1.3c or later is part of all distributions of LaTeX
%% version 2006/05/20 or later.
%%
%% Read LICENSE included in the package.
%%

%%% finemath on has been plainTeX default
\def\finemath{}

\expandafter\edef\csname AT(@):catcode\endcsname{\noexpand\catcode`@\the\catcode`@}

\unless\ifdefined\makeatletter \def\makeatletter{\catcode`\@=11 }\fi
\unless\ifdefined\makeatother \def\makeatother{\catcode`\@=12 }\fi

\makeatletter

\unless\ifdefined\@tempcnta \newcount\@tempcnta\fi
\unless\ifdefined\@tempcntb \newcount\@tempcntb\fi
\unless\ifdefined\@empty \let\@empty\empty\fi
\unless\ifdefined\@sptoken
  \begingroup
  \def\:{\global\let\@sptoken= }\:  % this makes \@sptoken a space token
  \endgroup
\fi

\unless\ifdefined\ProvidesFile
  \def\ProvidesFile#1{\wlog{#1}\@ProvidesFile}
  \def\@ProvidesFile{\futurelet\dhucs@next\@@ProvidesFile}
  \def\@@ProvidesFile{%
    \ifx\dhucs@next\@sptoken\expandafter\@@@ProvidesFile
    \else\ifx\dhucs@next[\expandafter\expandafter\expandafter\ProvidesFile@
    \fi\fi}
  \def\@@@ProvidesFile{\afterassignment\@ProvidesFile\let\dhucs@next= }
  \def\ProvidesFile@[#1]{\wlog{#1}}
\fi

\unless\ifdefined\IeC \protected\def\IeC#1{#1}\fi
\unless\ifdefined\textperiodcentered \protected\def\textperiodcentered{$\cdot$}\fi
\unless\ifdefined\textquoteleft \protected\def\textquoteleft{`}\fi
\unless\ifdefined\textquoteright \protected\def\textquoteright{'}\fi
\unless\ifdefined\textquotedblleft \protected\def\textquotedblleft{``}\fi
\unless\ifdefined\textquotedblright \protected\def\textquotedblright{''}\fi

\unless\ifdefined\saved@space@catcode \xdef\saved@space@catcode{\the\catcode`\ }\fi
\unless\ifdefined\PackageError \def\PackageError#1#2#3{\errmessage{#2}}\fi
\unless\ifdefined\@inpenc@test \let\@inpenc@test\relax \fi
\unless\ifdefined\@begindocumenthook \let\@begindocumenthook\relax \fi
\unless\ifdefined\@onlypreamble \def\@onlypreamble#1{}\fi
\unless\ifdefined\cdp@list \let\cdp@list\relax \fi

\unless\ifdefined\protect \let\protect\relax \fi

\unless\ifdefined\normalfont \def\normalfont{\rm\hfontname{outbtm}}\fi
\unless\ifdefined\bfseries \def\bfseries{\bf\hfontname{outbtb}}\fi

% make first octet of a utf8 char active
\count@"C2
\loop\catcode\count@\active
  \ifnum\count@<"F4
  \advance\count@\@ne\repeat

\input utf8.def

\input kotexutf-core

\def\unihangulchar@@@{%
  \getthish@ngulcl@ss
  \dobeforeh@ngulch@r
  \leavevmode %%% moved from inside group
  \begingroup
    \geth@ngulpl@ne@ndch@r
    \font\font@name\h@font@name\h@ngulpl@ne\space\h@font@size
    \font@name
    \dhucs@check@if@char@exists
    \dhucs@emph\h@ngulch@r
    \h@ngulch@r
  \endgroup
  \do@fterh@ngulch@r
}

\input lucenc.dfu

% \다 = \nobreak 다
\def\nobreak@hangul@da{\nobreak 다}
\def\^^eb#1#2{%
  \ifx#1^^8b%
    \ifx#2^^a4% avoid orphan \다
      \expandafter\expandafter\expandafter\nobreak@hangul@da
    \else
      \errmessage{Undefined Control Sequence}%
    \fi
  \else
    \errmessage{Undefined Control Sequence}%
  \fi}


% hangul font definition
% ex: \hfont{oungtm}{at 12pt}
%     \hfontname{oungtm}
%     \hfontsize{at 12pt}
\protected\def\hfontname#1{\def\h@font@name{#1}}
\protected\def\hfontsize#1{\def\h@font@size{#1}}
\protected\def\hfont#1#2{\hfontname{#1}\hfontsize{#2}}

\csname AT(@):catcode\endcsname

\hfont{outbtm}{}

\endinput
