%% This is `hfont.tex' written by koaunghi.un@student.uni-tuebingen.de.
%%
%% 이 파일은 우리말을 \TeX에서 사용하는데 필요한 KS X 1001 부호와
%% 글자체 정의에 그 역할을 두고 있다.  우리말 글자체는 \LaTeX2e의
%% NFSS2(New Font Selection Scheme2)을 한글화한 HFSS에 의해 선택되며,
%% 일반의 한글문서와는 달리 문서에 우리말 글자체만 포함하기 위해서는
%% 이 파일이 단독으로 사용될 수 있다.

\ProvidesFile{hfont.tex}[2000/08/13]

%% 0.95 scheme

\begingroup
\def\reserved@a{}\count@="0A1
\loop\ifnum\count@<\@cclvi
  \edef\reserved@a{\reserved@a \sfcode\the\count@=\@m}%
  \advance\count@ by1
\repeat
\global\let\ks@break\reserved@a
\endgroup

%% 우리말 부호의 정의 (KSC5601)
%% ----------------------------
%% 우리말부호는 모두 TeX의 모듬명령으로 처리된다.
\def\reserved@a#1#2{%
  \@tempcnta#1\relax
  \@tempcntb#2\relax
  \reserved@b}
\def\reserved@b{%
  \ifnum\@tempcnta>\@tempcntb\else
    \reserved@c\@tempcnta
    \advance\@tempcnta\@ne
    \expandafter\reserved@b
  \fi}
\def\reserved@c#1{%
  \uccode#1=#1
  \lccode#1=#1
  \sfcode#1=1001
  \catcode#1=\active}
\reserved@a{"0A1}{"0FE}

\begingroup
\def\ksc@code{\ifnum\count@<"0FF
  \edef\reserved@a{\reserved@a \catcode\the\count@=\the\@tempcnta}
  \advance\count@ by1
  \else\let\next\relax \fi\next}
\@tempcnta13
\def\reserved@a{}\count@="0A1\let\next\ksc@code \ksc@code
\global\let\makekscactive\reserved@a
\@tempcnta12
\def\reserved@a{}\count@="0A1\let\next\ksc@code \ksc@code
\global\let\makekscother\reserved@a
\@tempcnta11
\def\reserved@a{}\count@="0A1\let\next\ksc@code \ksc@code
\global\let\makekscletter\reserved@a
\endgroup

%% 우리말의 분철:
%% --------------
%% 우리말은 \hyphenchar가 없고 어느 곳에서나 分綴이 可能하다. 그러므로
%% 일단 글자체 자체에서 分綴을 억제하고 (\hyphenchar\font\m@ne)
%% 우리말 사이에 \hskip\hangul@skip을 揷入함으로써 分綴을 可能하게
%% 함과 동시에 \hangulskip으로 자간간격을 조절을 할 수 있도록 한다.
%%
\newdimen\hangulskip
\newskip\hangul@skip
\def\@Hyphen{\ifhmode\ifnum\spacefactor=1001\hskip\hangul@skip\fi\fi}%%%%
\def\set@hangulskip{%
  \@tempdima=\f@size\p@
  \multiply\@tempdima100
  \divide\@tempdima\p@
  \multiply\@tempdima\p@
  \hangul@skip=\hangulskip minus\hangulskip
  \multiply\hangul@skip by\strip@pt\@tempdima%
  \divide\hangul@skip by1000
}

%% 줄바꿈의 억제
% 우리말 음절은 어느 곳에서든지 줄바꿈이 가능하다.  줄바꿈을 억제할
% 때에 라텍의 \nolinebreak도 효과가 없다.  우리말 음절의 경계에서는
% 다음과 같이 줄바꿈을 억제한다.
\def\noHyphen{\spacefactor=999\nolinebreak}

%% 우리말의 글자체 바꾸기:
%% -----------------------
%% 우리말의 글자체종류는 명조와 고딕 그리고 타자의 3가지를 기본으로
%% 한다. 명조(\textmj)와 고딕(\textgt)은 각각 영문의 \textrm과
%% \textsf에 해당하고 타자(\texttz)는 영문의 \texttt와 같다.
\DeclareTextFontCommand{\textmj}{\mjfamily}
\DeclareTextFontCommand{\textgt}{\gtfamily}
\DeclareTextFontCommand{\texttz}{\tzfamily}

%% 우리말글자체가족은 명조, 고딕, 타자의 세가지가 있고 다음과 같은
%% 등식이 성립한다. \rmfamily=명조, \sffamily=고딕, \ttfamily=타자.
\expandafter\def\expandafter\rmfamily\expandafter{\rmfamily
         \not@math@alphabet\mjfamily\mathmj
         \hfontfamily\mjdefault}
\let\mjfamily\rmfamily
\expandafter\def\expandafter\sffamily\expandafter{\sffamily
         \not@math@alphabet\gtfamily\mathgt
         \hfontfamily\gtdefault}
\let\gtfamily\sffamily
\expandafter\def\expandafter\ttfamily\expandafter{\ttfamily
         \not@math@alphabet\tzfamily\mathtz
         \hfontfamily\tzdefault\ks@break}
\let\tzfamily\ttfamily

%% 편의상 다음과 같은 가족바꿈모듬명령도 제공된다. (그래픽, 궁서,
%% 필기, 외곽, 새명조, 목각, 옛글, 봄글씨 및 펜글씨)  이 모듬 명령들은
%% 없어질 잡동사니에 속하므로 되도록 쓰지 않도록 한다.
\DeclareRobustCommand\grfamily{\hfontfamily{gr}}
\DeclareRobustCommand\gsfamily{\hfontfamily{gs}}
\DeclareRobustCommand\pgfamily{\hfontfamily{pg}}
\DeclareRobustCommand\mgfamily{\hfontfamily{mg}}
\DeclareRobustCommand\ytfamily{\hfontfamily{yt}}
\DeclareRobustCommand\bmfamily{\hfontfamily{bm}}
\DeclareRobustCommand\pnfamily{\hfontfamily{pn}}
\let\smfamily\mjfamily
\let\olfamily\mjfamily
\DeclareTextFontCommand{\textgr}{\grfamily}
\DeclareTextFontCommand{\textgs}{\gsfamily}
\DeclareTextFontCommand{\textpg}{\pgfamily}
\DeclareTextFontCommand{\textmg}{\mgfamily}
\DeclareTextFontCommand{\textyt}{\ytfamily}
\DeclareTextFontCommand{\textbm}{\bmfamily}
\DeclareTextFontCommand{\textpn}{\pnfamily}
\let\textsm\textmj
\let\textol\textmj

%% LaTeX209식의 글자체 바꿈 모듬 명령은 기본 글자체에 해당하는 명령만
%% 제공한다.
\DeclareOldFontCommand{\mj}{\normalhfont\mjfamily}{\@nomath\mj}
\DeclareOldFontCommand{\gt}{\normalhfont\gtfamily}{\@nomath\gt}
\DeclareOldFontCommand{\tz}{\normalhfont\tzfamily}{\@nomath\tz}

%% 우리말의 글자체 초기화는 부호화와 가족만을 초기값으로 바꾼다.
\DeclareRobustCommand\normalhfont
                 {\hfontencoding\hencodingdefault%
                  \hfontfamily\hfamilydefault%
                  \kscfamily\symboldefault\hanguldefault\hanjadefault}

%% \normalfont는 영문과 함께 우리말도 초기화시킨다.
\expandafter\def\expandafter\normalfont\expandafter
  {\normalfont\protect\normalhfont}
\let\reset@font\normalfont

%% 영문 모듬 \usefont는 부호화가 우리말일 경우, 우리말을 다루도록 한다.
\def\usefont#1#2#3#4{\if\hf@encoding#1%
    \hfontencoding{#1}\hfontfamily{#2}\else
    \fontencoding{#1}\fontfamily{#2}\fi\fontseries{#3}%
    \fontshape{#4}\selectfont\ignorespaces}

%% 우리말의 가족계획:
%% ------------------
%% ⑴ 우리말의 인코딩:
%%    우리말은 영문과 다르게, 두 바이트로 한글자를 부호화하므로 영문의
%%    부호화와 구별되도록 다른 부호화를 쓰며, 다음의 모듬으로
%%    지정한다.  부호화의 변경은 새로운 .fd 파일을 요구하게 된다.
\DeclareRobustCommand\hfontencoding[1]{%
    \expandafter\ifx\csname T@#1\endcsname\relax
      \@latex@error{Encoding scheme `#1' unknown}\@eha
    \else
      \edef\hf@encoding{#1}%
      \ifx\cf@encoding\hf@encoding
        \let\enc@update\relax
      \else
        \let\enc@update\@@enc@update
      \fi
    \fi
}

%% ⑵ 우리말글자체의 가족:
%%    우리말가족은 둘로 나뉜다. 앞부분은 심벌/한글/한자의 구성형태를
%%    의미한다.
\DeclareRobustCommand\kscfamily[3]{\edef\sb@{#1}\edef\hg@{#2}\edef\hj@{#3}}

%% 뒷부분은 우리말글자체의 모양새를 의미한다. 명조, 고딕, 타자 및 추가
%% 글자체등의 모양새는 \MapHangulFamily에 의해 각각 한글/심벌/한자의
%% 외부글자체와 연관되어 있다.
\DeclareRobustCommand\hfontfamily[1]{%
  \expandafter\ifx\csname #1@map\endcsname\relax
    \@font@warning{Hangul Fontmap for `#1' undefined\MessageBreak
                   using default map `\expandafter\csname\default@hfamily
                   @map\endcsname' instead\@wrong@font@char}%
    \expandafter\xdef\csname #1@map\endcsname{%
      \expandafter\csname\default@hfamily @map\endcsname}%
    \gdef\default@fontmap{%
      \@font@warning{Some hangul fontmaps were not defined,\MessageBreak
                     default fontmap substituted.\@gobbletwo}}\fi
  \edef\reserved@a{\csname #1@map\endcsname}%
  \expandafter\hfont@map\reserved@a\@nil\ignorespaces}
\def\hfont@map#1,#2,#3\@nil{%
  \edef\hg@family{#1}%
  \edef\sb@family{#2}%
  \edef\hj@family{#3}}
\AtEndDocument{\default@fontmap}
\let\default@fontmap\relax

%% ⑶ 우리말 글자체 시리즈:
%%    우리말글자체시리즈는 영문의 그것과 같다. 다만 \fontseries가 S로
%%    시작할 때 우리말글꼴은 \mdseries를 세번 연속인쇄하여
%%    \bfseries의 效果를 나타나게 한다.
\DeclareRobustCommand\fontseries[1]{%
  \if S\expandafter\@car#1\@nil\@makeboldtrue
    \edef\hf@series{\mddefault}\edef\f@series{\expandafter\@cdr#1\@nil}%
  \else\@makeboldfalse\edef\hf@series{#1}\edef\f@series{#1}\fi}

%% \TeX{}에서 \bfseries의 애초값은 bx이다.  uhc 글자체는 b와 bx가 서로
%% 구분되므로 모듬 명령 \hfontseries에 의해 두꺼운 글자체가 선택되도록
%% 한다.
\DeclareRobustCommand\hfontseries[1]{\edef\hf@series{#1}}

\expandafter\def\expandafter\bfseries\expandafter{\bfseries\hfontseries\hbfdefault}

%% ⑷,⑸ 우리말 글자체모양 및 크기:
%%       우리말의 글자체모양과 크기는 영문의 그것과 동일하게 처리된다.

%% 외부 글자체 파일찾기:
%% ---------------------
%% 우리말글자체는 한 세트가 여러 파일로 나뉘어져 있다. 그러므로
%% 우리말글자체의 외부파일은 다음과 같은 일률적인 규칙에 의거하여
%% 명명한다.
%%  1. 상징기호는 끝숫자가 4, 5, 6, 7로 끝나도록 순서대로 256개씩 나눈다.
%%  2. 한글은 끝숫자가 0부터 9가 되도록 순서대로 256개씩 나눈다.
%%  3. 한자는 끝숫자가 10에서 29가 되도록 순서대로 256개씩 나눈다.
\def\DeclareFontShape@#1#2#3#4#5#6{%
   \expandafter\ifx\csname #1+#2\endcsname\relax
     \@latex@error{Font family `#1+#2' unknown}\@eha
   \else
     \if#1\hf@encoding
       \if\sb@\expandafter\@car#2\@nil\@tempcnta0\def\reserved@b{A,B,C,D}%
       \else\if\hj@\expandafter\@car#2\@nil\@tempcnta2
         \def\reserved@b{A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T}%
       \else\@tempcnta1\def\reserved@b{A,B,C,D,E,F,G,H,I,J}\fi\fi
       \@for\@idx:=\reserved@b\do{%
         \expandafter\expandafter\expandafter\@tempcntb\expandafter`\@idx
         \advance\@tempcntb-65
         \ifcase\@tempcnta\def\reserved@c{0}\advance\@tempcntb4%
         \or\def\reserved@c{}%
         \or\def\reserved@c{}\advance\@tempcntb10\fi
         \edef\reserved@c{\reserved@c\number\@tempcntb}%
         \expandafter\xdef\csname#1/#2/#3/#4/\@idx\endcsname{%
           \expandafter\noexpand\csname #5\reserved@c\endcsname}%
         \global\expandafter\let\csname #5\reserved@c\expandafter\endcsname
           \ifx\reserved@a\@empty\@empty\else\reserved@a\fi}%
     \else
       \expandafter\xdef\csname#1/#2/#3/#4\endcsname{%
         \expandafter\noexpand\csname #5\endcsname}%
       \def\reserved@a{#6}%
       \global\expandafter\let\csname#5\expandafter\endcsname
          \ifx\reserved@a\@empty\@empty\else\reserved@a\fi
   \fi\fi
  }
\DeclareSizeFunction{hsub}{\subh@sfcnt\@font@warning}
\DeclareSizeFunction{hssub}{\subh@sfcnt\@font@info}
\def\subh@sfcnt#1{%
    \edef\mandatory@arg{\f@encoding/\mandatory@arg}%
    \begingroup
     \expandafter\split@hname\mandatory@arg/\@nil
     \xdef\reserved@a{\curr@fontshape}%
     \try@load@fontshape
    \endgroup
    \let\f@user@size\f@size
    \expandafter
    \ifx\csname\mandatory@arg\endcsname\relax
      \expandafter\ifx\csname\curr@fontshape!\endcsname\relax
        \errmessage{No\space declaration\space for\space
                  shape\space \mandatory@arg}%
      \global\expandafter\let\csname\curr@fontshape!\endcsname\@empty\fi
      \edef\reserved@b{\expandafter\@car\f@family\@nil}%
      \error@hfontshape
      \edef\reserved@c{\expandafter\csname\f@family @map\endcsname}%
      \expandafter\hfont@map\reserved@c\@nil
      \ifx\sb@\reserved@b\edef\f@family{\sb@\sb@family}\else%
      \ifx\hj@\reserved@b\edef\f@family{\hj@\hj@family}\else%
        \edef\f@family{\hg@\hg@family}\fi\fi
    \else
      \expandafter\ifx\csname\curr@fontshape!\endcsname\relax
        #1{Font\space shape\space `\curr@fontshape'\space in\space
         size\space <\f@size>\space not\space available\MessageBreak
         Font\space shape\space `\reserved@a'\space tried\space
         instead}%
      \global\expandafter\let\csname\curr@fontshape!\endcsname\@empty\fi
      \expandafter\split@hname\mandatory@arg/\@nil
    \fi
    \edef\f@size{\f@user@size}%
    \get@external@hfont
    \do@subst@correction
}
\def\DeclareHFontShape{\begingroup
   \nfss@catcodes
   \expandafter\endgroup
   \DeclareHFontShape@}
\def\DeclareHFontShape@#1#2#3#4#5#6{%
   \expandafter\ifx\csname #1+#2\endcsname\relax
     \@latex@error{Font family `#1+#2' unknown}\@eha
   \else
     \def\reserved@a{#6}%
     \if\sb@\expandafter\@car#2\@nil\def\reserved@b{A,B,C,D}%
     \else\if\hj@\expandafter\@car#2\@nil
       \def\reserved@b{A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T}%
     \else\def\reserved@b{A,B,C,D,E,F,G,H,I,J}\fi\fi
     \@for\@idx:=\reserved@b\do{%
       \expandafter\xdef\csname#1/#2/#3/#4/\@idx\endcsname{%
         \expandafter\noexpand\csname #5/\@idx\endcsname}%
       \global\expandafter\let\csname #5/\@idx\expandafter\endcsname
         \ifx\reserved@a\@empty\@empty\else\reserved@a\fi}%
   \fi
  }

%% 우리말 글자체 선택 방법 (HFSS):
%% -------------------------------
%% 우리말은 encoding과 family를 영문과 달리 취급하고 series와 shape,
%% 그리고 size는 영문과 동일하게 취급한다.
%% 우리말의 한가지 글자체는 256개의 글자들로 구성된 여러 글자체로
%% 분리되어 있음으로 지수를 하나 더 추가하여 (심벌: A-D, 한글: A-J,
%% 한자: A-T) 이를 표시한다.(\f@idx)
%% 글자체가 없어서 대치될 때는, 그 글자체의 지수가 없이 그 글자체
%% 세트가 대치되었음을 사용자에게 알리고, 한 글자체 세트마다 한번만
%% 이러한 사실이 알려지도록 한다.  그 대치에는 심벌/한글/한자의
%% \hfamilydefault로 선정된 글자체를 쓴다.  한글의 경우에는
%% 완성|조합/자모를 각각 구분하여 처리한다.
\def\extract@hfont{%
   \get@external@hfont
   \global\expandafter\font\font@name\external@font\relax
    \font@name \relax
    \csname \f@encoding+\f@family\endcsname
    \csname\curr@fontshape\endcsname
    \relax
       }
\def\get@external@hfont{%
   \let\external@font\@empty
   \edef\font@info{\expandafter\expandafter\expandafter\string
        \csname \curr@fontshape/\f@idx \endcsname}%
   \try@size@range
   \ifx\external@font\@empty
      \try@size@substitution
      \ifx\external@font\@empty
         \@latex@error{Font \expandafter \string\font@name\space
                     not found}\@eha
         \edef\reserved@b{\expandafter\@car\f@family\@nil}
         \error@hfontshape
         \edef\reserved@c{\expandafter\csname\f@family @map\endcsname}%
         \expandafter\hfont@map\reserved@c\@nil
         \ifx\sb@\reserved@b\edef\f@family{\sb@\sb@family}\else%
         \ifx\hj@\reserved@b\edef\f@family{\hj@\hj@family}\else%
           \edef\f@family{\hg@\hg@family}\fi\fi
         \get@external@hfont
   \fi\fi
}
\DeclareRobustCommand\selecthfont
        {%
    \ifx\f@linespread\baselinestretch \else
      \set@fontsize\baselinestretch\f@size\f@baselineskip \fi
    \xdef\font@name{%
      \csname\curr@fontshape/\f@idx/\f@size\endcsname}%
    \pickup@hfont
    \font@name
    \size@update
    \enc@update
    \set@hangulskip
    }
\def\pickup@hfont{%
    \expandafter \ifx \font@name \relax
       \define@newhfont
    \fi}
\def\define@newhfont{%
  \begingroup
    \let\typeout\@font@info
    \escapechar\m@ne
    \expandafter\expandafter\expandafter
       \split@hname\expandafter\string\font@name\@nil
      \try@load@fontshape % try always
    \expandafter\ifx
       \csname\curr@fontshape/\f@idx\endcsname \relax
      \wrong@hfontshape\else
      \extract@hfont\fi
  \endgroup}
{\catcode`\/=12
\gdef\split@hname#1/#2/#3/#4/#5/#6\@nil{\def\f@encoding{#1}%
                                        \def\f@family{#2}%
                                        \def\f@series{#3}%
                                        \def\f@shape{#4}%
                                        \def\f@size{#6}}}
\def\DeclareErrorHFont#1#2#3#4#5{%
      \xdef\error@hfontshape{%
          \noexpand\expandafter\noexpand\split@name\noexpand\string
          \expandafter\noexpand\csname#1/#2/#3/#4/#5\endcsname
          \noexpand\@nil}%
      \gdef\default@hfamily{#2}%
      \gdef\default@hseries{#3}%
      \gdef\default@shape{#4}%
      \begingroup
        \edef\reserved@a{\expandafter\csname\default@hfamily @map\endcsname}%
        \expandafter\hfont@map\reserved@a\@nil
        \xdef\sb@family{\sb@family}%
        \xdef\hg@family{\hg@family}%
        \xdef\hj@family{\hj@family}%
      \endgroup
      \global\let\hf@series\default@hseries
      \global\let\f@shape\default@shape
      \gdef\f@size{#5}%
      \gdef\f@baselineskip{#5pt}%
}
\@onlypreamble\DeclareErrorHFont
\def\wrong@hfontshape{%
    \csname D@\f@encoding\endcsname      % install defaults if in math
    \edef\reserved@a{\csname\curr@fontshape/\f@idx\endcsname}%
    \edef\reserved@b{\expandafter\string\csname\curr@fontshape\endcsname}%
  \ifx\last@fontshape\reserved@a
     \errmessage{Corrupted NFSS tables}%
     \edef\reserved@c{\expandafter\@car\f@family\@nil}%
     \error@hfontshape
     \edef\reserved@d{\expandafter\csname\f@family @map\endcsname}%
     \expandafter\hfont@map\reserved@d\@nil
     \ifx\sb@\reserved@c\edef\f@family{\sb@\sb@family}\else%
     \ifx\hj@\reserved@c\edef\f@family{\hj@\hj@family}\else%
       \edef\f@family{\hg@\hg@family}\fi\fi
  \else
    \let\f@shape\default@shape
    \expandafter\ifx\csname\curr@fontshape/\f@idx\endcsname\relax
        \let\f@series\default@hseries
        \expandafter
        \ifx\csname\curr@fontshape/\f@idx\endcsname\relax
          \edef\reserved@d{\expandafter\csname\default@hfamily @map\endcsname}%
          \expandafter\hfont@map\reserved@d\@nil
          \if\sb@\expandafter\@car\f@family\@nil
              \edef\f@family{\sb@\sb@family}\else
          \if\hj@\expandafter\@car\f@family\@nil
              \edef\f@family{\hj@\hj@family}\else
              \edef\f@family{\hg@\hg@family}\fi\fi
        \fi \fi
  \fi
    \expandafter\ifx\csname\reserved@b!\endcsname\relax
       \@font@warning{Font shape `\expandafter\string\reserved@b'
                       \expandafter\@gobble\string\@undefined\MessageBreak
                     using `\curr@fontshape' instead\@wrong@font@char}%
      \global\expandafter\let\csname\reserved@b!\endcsname\@empty\fi
    \global\let\last@fontshape\reserved@a
    \gdef\@defaultsubs{%
      \@font@warning{Some font shapes were not available, defaults
                      substituted.\@gobbletwo}}%
    \global\expandafter\expandafter\expandafter\let
       \expandafter\reserved@a
           \csname\curr@fontshape/\f@idx\endcsname
    \xdef\font@name{%
      \csname\curr@fontshape/\f@idx/\f@size\endcsname}%
    \pickup@hfont}
\def\DeclareHFontEncoding{%
   \begingroup
   \nfss@catcodes
   \expandafter\endgroup
   \DeclareHFontEncoding@}
\@onlypreamble\DeclareHFontEncoding
\def\DeclareHFontEncoding@#1#2#3{%
  \expandafter
  \ifx\csname T@#1\endcsname\relax
     \def\cdp@elt{\noexpand\cdp@elt}%
     \begingroup
     \edef\reserved@a{\csname\default@hfamily @map\endcsname}
     \expandafter\hfont@map\reserved@a\@nil
     \xdef\cdp@list{\cdp@list%
                    \cdp@elt{#1}{\symboldefault\sb@family}%
                    {\default@hseries}{\default@shape}%
                    \cdp@elt{#1}{\hanguldefault\hg@family}%
                    {\default@hseries}{\default@shape}%
                    \cdp@elt{#1}{\hanjadefault\hj@family}%
                    {\default@hseries}{\default@shape}}%
     \endgroup
     \expandafter\let\csname#1-cmd\endcsname\@changed@cmd
  \else
     \@font@info{Redeclaring font encoding #1}%
  \fi
  \global\@namedef{T@#1}{#2}%
  \global\@namedef{M@#1}{\default@M#3}%
  }
\@onlypreamble\DeclareHFontEncoding@
\def\DeclareHFontSubstitution#1#2#3#4{%
  \expandafter
  \ifx\csname T@#1\endcsname\relax
    \@latex@error{Encoding scheme  `#1' unknown}\@eha
  \else
    \begingroup
       \edef\reserved@a{\csname#2@map\endcsname}
       \expandafter\hfont@map\reserved@a\@nil
       \def\reserved@a{#1}%
       \toks@{}%
       \let\reserved@d\@empty
       \def\cdp@elt##1##2##3##4{%
          \def\reserved@b{##1}%
          \ifx\reserved@a\reserved@b
            \ifx\reserved@d\@empty
              \edef\reserved@c{\noexpand\cdp@elt{#1}{\sb@\sb@family}{#3}{#4}%
                               \noexpand\cdp@elt{#1}{\hg@\hg@family}{#3}{#4}%
                               \noexpand\cdp@elt{#1}{\hj@\hj@family}{#3}{#4}}%
              \let\reserved@d\relax
              \expandafter\addto@hook
              \expandafter\toks@\expandafter{\reserved@c}\fi%
          \else
             \addto@hook\toks@{\cdp@elt{##1}{##2}{##3}{##4}}%
          \fi}%
        \cdp@list
        \xdef\cdp@list{\the\toks@}%
    \endgroup
    \global\@namedef{D@#1}{%
        \def\default@hfamily{#2}%
        \def\default@hseries{#3}%
        \def\default@shape{#4}%
        }%
  \fi
 }
\@onlypreamble\DeclareHFontSubstitution

%% HFSS의 설정 확인:
%% -----------------
%% 우리말의 한 가족은 심벌/한글/한자의 세가지 외부 글자체와 연관되어
%% 있다. 우리말 문서가 시작하기 전에, 기본값으로 설정된
%% 심벌/한글/한자의 대치 글자체와 착오시 사용될 글자체가 제대로
%% 설정되어 있는지 확인함으로서 글자체 선택시 발생할 수 재앙을 미리
%% 방지한다.
\def\process@table{%
    \def\cdp@elt##1##2##3##4{%
        \@font@info{Checking defaults for
                  ##1/##2/##3/##4}%
      \if\hf@encoding##1
        \expandafter
        \ifx\csname##1/##2/##3/##4/A\endcsname\relax
          \begingroup
           \def\f@encoding{##1}\def\f@family{##2}%
           \try@load@fontshape
          \endgroup
        \fi
        \expandafter
        \ifx\csname##1/##2/##3/##4/A\endcsname\relax
             \@latex@error{This HFSS system isn't set up properly}%
                       {For hangul encoding scheme ##1 the defaults
                        ##2/##3/##4 do not form a valid font shape}%
        \else
             \@font@info{... okay}%
        \fi
      \else
        \expandafter
        \ifx\csname##1/##2/##3/##4\endcsname\relax
          \begingroup
           \def\f@encoding{##1}\def\f@family{##2}%
           \try@load@fontshape
          \endgroup
        \fi
        \expandafter
        \ifx\csname##1/##2/##3/##4\endcsname\relax
             \@latex@error{This NFSS system isn't set up properly}%
                       {For encoding scheme ##1 the defaults
                        ##2/##3/##4 do not form a valid font shape}%
        \else
             \@font@info{... okay}%
        \fi
      \fi}%
    \cdp@list
    \begingroup
       \escapechar\m@ne
       \error@fontshape
       \expandafter\ifx\csname \curr@fontshape\endcsname\relax
          \begingroup
            \try@load@fontshape
           \endgroup
       \fi
       \expandafter\ifx\csname \curr@fontshape\endcsname\relax
         \@latex@error{This NFSS system isn't set up properly}%
            {The system maintainer forgot to specify a suitable
             substitution
             font shape using the \noexpand\DeclareErrorFont
             command}%
       \fi
       \expandafter\ifx\csname\hfamilydefault @map\endcsname\relax
         \@latex@error{This HFSS system isn't set up properly}%
            {The system maintainer forgot to specify a suitable
             fontmap for default hangul family `\hfamilydefault'
             using the \noexpand\MapHangulFamily command}%
       \fi
       \error@hfontshape
       \edef\reserved@a{\expandafter\csname\f@family @map\endcsname}%
       \expandafter\hfont@map\reserved@a\@nil
       \edef\f@family{\sb@\sb@family}%
       \expandafter\ifx\csname \curr@fontshape/A\endcsname\relax
          \begingroup
            \try@load@fontshape
           \endgroup
       \fi
       \expandafter\ifx\csname \curr@fontshape/A\endcsname\relax
         \@latex@error{This HFSS system isn't set up properly}%
            {The system maintainer forgot to specify a suitable
             substitution symbol
             font shape using the \noexpand\DeclareErrorHFont
             command or \noexpand\MapHangulFamily command}%
       \fi
       \edef\f@family{\hg@\hg@family}%
       \expandafter\ifx\csname \curr@fontshape/A\endcsname\relax
          \begingroup
            \try@load@fontshape
           \endgroup
       \fi
       \expandafter\ifx\csname \curr@fontshape/A\endcsname\relax
         \@latex@error{This HFSS system isn't set up properly}%
            {The system maintainer forgot to specify a suitable
             substitution hangul
             font shape using the \noexpand\DeclareErrorHFont
             command or \noexpand\MapHangulFamily command}%
       \fi
       \edef\f@family{\hj@\hj@family}%
       \expandafter\ifx\csname \curr@fontshape/A\endcsname\relax
          \begingroup
            \try@load@fontshape
           \endgroup
       \fi
       \expandafter\ifx\csname \curr@fontshape/A\endcsname\relax
         \@latex@error{This HFSS system isn't set up properly}%
            {The system maintainer forgot to specify a suitable
             substitution hanja
             font shape using the \noexpand\DeclareErrorHFont
             command or \noexpand\MapHangulFamily command}%
       \fi
    \endgroup
    \let\select@group\document@select@group
    \hfontencoding{\hencodingdefault}%
    \hfontfamily{\hfamilydefault}%
    \fontencoding{\encodingdefault}%
    \fontfamily{\familydefault}%
    \fontseries{\seriesdefault}%
    \fontshape{\shapedefault}%
 \everyjob{}%
}

%% 우리말 글자체의 기본값:
%% -----------------------
%% 아무것도 지정하지 않으면 완성형 명조체가 된다.
\newcommand\hencodingdefault{H}

\newcommand\symboldefault{s}
\newcommand\hanguldefault{w}
\newcommand\hanjadefault{h}
\newcommand\mjdefault{mj}
\newcommand\gtdefault{gt}
\newcommand\tzdefault{tz}
\newcommand\hfamilydefault{\mjdefault}
\if@makebold\newcommand\hbfdefault{m}
\else\newcommand\hbfdefault{b}\fi

%% 우리말가족 이름에 따른 외부 글자체의 설정
%% -----------------------------------------
%%      \MapHangulFamily{우리말가족}{한글글자체,심벌글자체,한자글자체}
%%                      (글자체이름 = 한글/심벌/한자글꼴)
\DeclareRobustCommand\MapHangulFamily[2]{%
  \expandafter\edef\csname #1@map\endcsname{#2}}

%% 기본글자체
\MapHangulFamily{mj}{wmj,wmj,wmj}
\MapHangulFamily{gt}{wgt,wgt,wgt}
\MapHangulFamily{tz}{wtt,wtt,wtt}

%% 추가글자체
\MapHangulFamily{gs}{wgs,wgs,wgs}
\MapHangulFamily{gh}{mgh,wgs,wgs}
\MapHangulFamily{gr}{wgr,wgr,wgt}
\MapHangulFamily{sh}{wsh,wsh,wsh}
\MapHangulFamily{pg}{wpg,wgt,wgt}
\MapHangulFamily{pn}{wpn,wmj,wmj}
\MapHangulFamily{ph}{wph,wmj,wmj}
\MapHangulFamily{bm}{wbm,wgt,wgt}
\MapHangulFamily{yt}{wyt,wgt,wyt}
\MapHangulFamily{vd}{wvd,wgt,wgt}
\MapHangulFamily{mg}{mhm,wgt,wgt}
\MapHangulFamily{jmj}{wjmj,wmj,wmj}
\MapHangulFamily{jgt}{wjgt,wgt,wgt}
\MapHangulFamily{jnv}{wjnv,wgt,wgt}
\MapHangulFamily{jsr}{wjsr,wgt,wgt}
\MapHangulFamily{pga}{wpga,wgt,wgt}
\MapHangulFamily{dn}{wdn,wgt,wgt}

% \DeclareErrorHFont{H}{\mjdefault}{m}{n}{10}
% \DeclareHFontSubstitution{H}{\mjdefault}{m}{n}

%% 잡동사니
\DeclareTextFontCommand{\textsh}{\shfamily}
\DeclareRobustCommand\shfamily{\hfontfamily{sh}}

%% hfont.cfg에서 이들을 미리 지정/수정할 수 있다.
\InputIfFileExists{hfont.cfg}{}{}

\kscfamily{\symboldefault}{\hanguldefault}{\hanjadefault}

\DeclareErrorHFont{H}{\mjdefault}{m}{n}{10}
\DeclareHFontEncoding{\hencodingdefault}{}{}
\DeclareHFontSubstitution{H}{\mjdefault}{m}{n}
\hfontencoding\hencodingdefault

%% 우리말 찾기:
%% ------------
%% 우리말은 모두 \catcode=13으로 처리되며 우리말 부호 영역의
%% 두 바이트가 한 글자를 형성한다. 이 두 개의 바이트를 분석하여
%% 외부 글꼴의 지수와 심벌/한글/한자 중 하나를 확정한다.
%%
\begingroup
\catcode`^^98\active
\catcode`^^99\active
\catcode`^^a0\active
\def^^98#1#2#3{\xdef#1##1{\noexpand\h@C{\hf@}{\noexpand\ifnum`##1<#2
    D\noexpand\else\noexpand\ifnum`##1>#3 C\noexpand\else
    A\noexpand\fi\noexpand\fi}{\noexpand#1}{##1}}} 
\def^^99#1#2{\xdef#1##1{\noexpand\h@C{\hf@}{#2}{\noexpand#1}{##1}}}
\def^^a0#1#2#3/#4{\xdef#1##1{\noexpand\h@C{\hf@}{\noexpand\ifnum`##1<#2
    #3\noexpand\else#4\noexpand\fi}{\noexpand#1}{##1}}}

%% 심벌
\def\hf@{sb}
%^^99^^a1B
% 금칙 문자: ’”〕〉》」』】의 앞과
%           ‘“〔〈《《『【 위 뒤    (2005/04/09 koaunghi@kornet.net)
\gdef\^^96#1{\ifx#1^^af\spacefactor=999
  \else\ifx#1^^b1\spacefactor=999
  \else\ifx#1^^b3\spacefactor=999
  \else\ifx#1^^b5\spacefactor=999
  \else\ifx#1^^b7\spacefactor=999
  \else\ifx#1^^b9\spacefactor=999
  \else\ifx#1^^bb\spacefactor=999
  \else\ifx#1^^bd\spacefactor=999
  \fi\fi\fi\fi\fi\fi\fi\fi}
\gdef\^^97#1{\ifx#1^^ae\spacefactor=999
  \else\ifx#1^^b0\spacefactor=999
  \else\ifx#1^^b2\spacefactor=999
  \else\ifx#1^^b4\spacefactor=999
  \else\ifx#1^^b6\spacefactor=999
  \else\ifx#1^^b8\spacefactor=999
  \else\ifx#1^^ba\spacefactor=999
  \else\ifx#1^^bc\spacefactor=999
  \fi\fi\fi\fi\fi\fi\fi\fi}
\xdef^^a1#1{\noexpand\^^96{#1}\noexpand\h@C{\hf@}{B}{\noexpand^^a1}{#1}\noexpand\^^97{#1}}
^^99^^a2B
\xdef^^a3#1{\noexpand\h@C{\hf@}{\noexpand\ifnum\expandafter`\noexpand#1="0DC
    A\noexpand\else D\noexpand\fi}{\noexpand^^a3}{\noexpand#1}}%
^^99^^a4A^^99^^a5D^^99^^a6C^^99^^a7B^^98^^a8{"0B0}{"0F5}
^^98^^a9{"0B1}{"0F5}^^99^^aaC^^99^^abC^^99^^acD

%%% 한글
\def\hf@{hg}
^^99^^b0A^^99^^b1A^^a0^^b2{"0E5}A/B^^99^^b3B^^99^^b4B^^a0^^b5{"0CB}B/C
^^99^^b6C^^99^^b7C^^a0^^b8{"0B1}C/D^^99^^b9D^^a0^^ba{"0F5}D/E^^99^^bbE
^^99^^bcE^^a0^^bd{"0DB}E/F^^99^^beF^^99^^bfF^^a0^^c0{"0C1}F/G^^99^^c1G
^^99^^c2G^^a0^^c3{"0A7}G/H^^99^^c4H^^a0^^c5{"0EB}H/I^^99^^c6I^^99^^c7I
^^a0^^c8{"0D1}I/J

%%% 漢字
\def\hf@{hj}
^^99^^caA^^99^^cbA^^a0^^cc{"0E5}A/B^^99^^cdB^^99^^ceB^^a0^^cf{"0CB}B/C
^^99^^d0C^^99^^d1C^^a0^^d2{"0B1}C/D^^99^^d3D^^a0^^d4{"0F5}D/E^^99^^d5E
^^99^^d6E^^a0^^d7{"0DB}E/F^^99^^d8F^^99^^d9F^^a0^^da{"0C1}F/G^^99^^dbG
^^99^^dcG^^a0^^dd{"0A7}G/H^^99^^deH^^a0^^df{"0EB}H/I^^99^^e0I^^99^^e1I
^^a0^^e2{"0D1}I/J^^99^^e3J^^99^^e4J^^a0^^e5{"0B7}J/K^^99^^e6K
^^a0^^e7{"0FB}K/L^^99^^e8L^^99^^e9L^^a0^^ea{"0E1}L/M^^99^^ebM^^99^^ecM
^^a0^^ed{"0C7}M/N^^99^^eeN^^99^^efN^^a0^^f0{"0AD}N/O^^99^^f1O
^^a0^^f2{"0F1}O/P^^99^^f3P^^99^^f4P^^a0^^f5{"0D7}P/Q^^99^^f6Q^^99^^f7Q
^^a0^^f8{"0BD}Q/R^^99^^f9R^^99^^faR^^a0^^fb{"0A3}R/S^^99^^fcS
^^a0^^fd{"0E7}S/T
\endgroup

%% 이해할 수 없는 오류: Undefined control sequence with ^^c9
\let^^c9\relax

%% 우리말을 최종 처리할 때는, 흩어져 있는 우리말 글자체 정보를
%% 수집하여 해당하는 외부 글자체를 찾은 후 인쇄한다. softbold가
%% 요구되면 두 번 더 중첩 인쇄하도록 한다.
\let\KSC@\string
\let\f@idx\relax
\def\h@C#1#2#3#4{%
  \ifx\protect\@typeset@protect\begingroup
    \edef\f@encoding{\hf@encoding}%
    \edef\f@family{\csname #1@\endcsname\csname #1@family\endcsname}%
    \edef\f@series{\hf@series}\gdef\f@idx{#2}%
    \selecthfont\@Hyphen\hemph@size{\KSC@#3\KSC@#4\if@makebold
      \hbox to0.03ex{\hss\KSC@#3\KSC@#4}%
      \hbox to0.03ex{\hss\KSC@#3\KSC@#4}\fi}\endgroup
  \else\KSC@#3\KSC@#4\fi}

\def\no@ccent#1{#1}
\let\hemph@size\no@ccent

\endinput

%%% End of file `hfont.tex'.
