%%
%%  hlatexp.ltx  2-byte character handler for hLaTeXp
%%               1996/01/14 version
%%
%%               By Jae Choon Cha
%%                  Department of Mathematics
%%                  Korea Advanced Institute of Science and Technology
%%
%%  Copyright (C) Jae Choon Cha. All Rights are reserved.
%%  You are not allowed to change this file.
%%  This file is part of hLaTeXp package. You are not allowed to distribute
%%  this file alone. This file should be distributed as part of hLaTeXp
%%  package of the author.
%%  This file (and any derivation) cannot be sold or distributed with
%%  any commercial product or used in any commercial organization without
%%  additional agreement with the author.
%%
%%  For suggestions and bug reports of UNCHANGED version, send e-mail to
%%  jccha@math.kaist.ac.kr.
%%
%%
%% Format name and date.
\def\hlatexfmtname{Hangul LaTeX2e (hLaTeXp)}
\def\hlatexfmtdate{1996/01/14}
\typeout{\hlatexfmtname\space<\hlatexfmtdate>}
%%
%% Add DBC font engine.
\makeatletter
\newif\iftrace@dbfont \trace@dbfontfalse
\newif\ifauto@subst@dbfsize \auto@subst@dbfsizetrue
\def\dbfsize@subst#1{%
  \ifdim #1<6.07pt 5.8\else
  \ifdim #1<6.63pt 6.33\else
  \ifdim #1<7.63pt 6.93\else
  \ifdim #1<8.73pt 8.33\else
  \ifdim #1<9.57pt 9.13\else
  \ifdim #1<10.48pt 10\else
  \ifdim #1<11.48pt 10.96\else
  \ifdim #1<12.57pt 12\else
  \ifdim #1<13.77pt 13.13\else
  \ifdim #1<15.84pt 14.4\else
  \ifdim #1<19pt 17.27\else
  \ifdim #1<22.8pt 20.73\else
  \ifdim #1<27.37pt 24.87\else 29.87\fi
  \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi pt}
\begingroup
\def\r#1{\let#1\relax}
\def\xafter{\noexpand\expandafter}
\def\csn{\noexpand\csname}
\def\endcsn{\noexpand\endcsname}
\def\str{\noexpand\string}
\begingroup %Let each current DBC fonts be null.
\def\d#1{\global\expandafter\let\csname dbfont@#1\endcsname\nullfont}
\d{A}\d{B}%
\d{sbA}\d{sbB}\d{sbC}\d{sbD}\d{sbE}%
\d{hjA}\d{hjB}\d{hjC}\d{hjD}\d{hjE}%
\d{hjF}\d{hjG}\d{hjH}\d{hjI}\d{hjJ}%
\d{hjK}\d{hjL}\d{hjM}\d{hjN}\d{hjO}%
\d{hjP}\d{hjQ}\d{hjR}\d{hjS}\d{hjT}%
\endgroup
\begingroup %Define \select@dbfont via a tricky way.
\r\kfont@name \r\dbfont@name
\def\d#1{\xafter\let\xafter \csname dbfont@#1\endcsname
  \csn\kfont@name @#1\endcsn}
\xdef\select@dbfont#1{\begingroup\escapechar\m@ne
  \edef\kfont@name{#1}\xdef\kfont@name{\xafter\str\kfont@name}\endgroup
  \let\dbfont@name\kfont@name
  \d{A}\d{B}%
  \d{sbA}\d{sbB}\d{sbC}\d{sbD}\d{sbE}%
  \d{hjA}\d{hjB}\d{hjC}\d{hjD}\d{hjE}%
  \d{hjF}\d{hjG}\d{hjH}\d{hjI}\d{hjJ}%
  \d{hjK}\d{hjL}\d{hjM}\d{hjN}\d{hjO}%
  \d{hjP}\d{hjQ}\d{hjR}\d{hjS}\d{hjT}%
}
\endgroup
\begingroup %Define \load@dbfont via a tricky way.
\r\get@kfont@extname@size \r\kfont@size \r\kfont@extname \r\kfont@name
\r\get@kfont@extname@size \r\delete@at \r\empty
\r\ifauto@subst@dbfsize \r\dbfsize@subst \r\iftrace@dbfont
\r\ifx \r\else \r\fi \r\fontname \r\typeout
\def\d#1{\global\xafter\let\csn\kfont@name @#1\endcsn\relax}
\xdef\load@dbfont#1{%
  \xafter\get@kfont@extname@size\fontname#1 \relax
  \xafter\ifx\csn\kfont@extname @flag\endcsn\empty
    \ifx\kfont@size\empty
      \edef\kfont@size{\csn\kfont@extname @designsize\endcsn pt}%
    \else\edef\kfont@size{\xafter\delete@at\kfont@size\relax}\fi
    \begingroup\escapechar\m@ne \edef\kfont@name{#1}%
    \xdef\kfont@name{\xafter\str\kfont@name}\endgroup
    \ifauto@subst@dbfsize
      \edef\kfont@size{\dbfsize@subst{\kfont@size}}\fi
    \xafter\xdef\csn\kfont@name @size\endcsn{\kfont@size}%
    \xafter\xdef\csn\kfont@name @extname\endcsn{\kfont@extname}%
    \global\xafter\font\csn\kfont@name @A\endcsn
      \csn\kfont@extname @db@extfn\endcsn 1 at\kfont@size
    \hyphenchar\csn\kfont@name @A\endcsn\m@ne
    \global\xafter\font\csn\kfont@name @B\endcsn
      \csn\kfont@extname @db@extfn\endcsn 2 at\kfont@size
    \hyphenchar\csn\kfont@name @B\endcsn\m@ne
    \iftrace@dbfont{\escapechar"5C%
      \typeout{DBC font engine info: Load Hangul for \csn\kfont@name\endcsn}}\fi
    \d{sbA}\d{sbB}\d{sbC}\d{sbD}\d{sbE}%
    \d{hjA}\d{hjB}\d{hjC}\d{hjD}\d{hjE}%
    \d{hjF}\d{hjG}\d{hjH}\d{hjI}\d{hjJ}%
    \d{hjK}\d{hjL}\d{hjM}\d{hjN}\d{hjO}%
    \d{hjP}\d{hjQ}\d{hjR}\d{hjS}\d{hjT}%
    %\global\expandafter\let\csname\kfont@name @sbA\endcsname\relax
  \fi
}
\gdef\delete@at#1#2 #3 \relax{#3}
\gdef\get@kfont@extname@size#1 #2\relax{%
\def\kfont@extname{#1}\def\kfont@size{#2}}
\endgroup
\begingroup %Define \load@dbfontsbA,...,\load@dbfonthjA,... via a tricky way.
\r\ifx \r\fi \r\iftrace@dbfont \r\typeout \r\dbfont@name
\def\d#1#2{\expandafter\xdef\csname load@dbfont\f #2\endcsname{%
  \ifx\csname dbfont@\f #2\endcsname\relax
  \iftrace@dbfont
    \typeout{DBC font engine info: Load \e #1 for: \csn\dbfont@name\endcsn}\fi
  \font\csname dbfont@\f #2\endcsname
  \csn\csn\dbfont@name @extname\endcsn @db@\f fn\endcsn #1
    at\csn\dbfont@name @size\endcsn
  \hyphenchar\csname dbfont@\f #2\endcsname\m@ne
  \global\xafter\let\csn\dbfont@name @\f #2\endcsn
  \csname dbfont@\f #2\endcsname\fi}}
\def\e{Symbol}\def\f{sb}
\d 1A\d 2B\d 3C\d 4D\d 5E%
\def\e{Hanja}\def\f{hj}
\d{01}A\d{02}B\d{03}C\d{04}D\d{05}E\d{06}F\d{07}G\d{08}H\d{09}I\d{10}J%
\d{11}K\d{12}L\d{13}M\d{14}N\d{15}O\d{16}P\d{17}Q\d{18}R\d{19}S\d{20}T%
\endgroup
\begingroup % Define \load@dbfont@map via a tricky way.
\gdef\load@dbfont@map{\begingroup
  \def\end@of@input{\end}
  \def\readloop{\read1 to\buf \expandafter\splitbuf\buf \relax
    \ifx\extfn\end@of@input \let\next\relax \else
    \expandafter\xdef\csname\extfn @db@extfn\endcsname{\dbextfn}
    \expandafter\xdef\csname\extfn @db@sbfn\endcsname{\dbsbfn}
    \expandafter\xdef\csname\extfn @db@hjfn\endcsname{\dbhjfn}
    \expandafter\xdef\csname\extfn @flag\endcsname{}
    \expandafter\xdef\csname\extfn @designsize\endcsname{\dsize}
    \let\next=\readloop \fi\next}
  \def\splitbuf ##1,##2,##3,##4,##5 \relax{\def\extfn{##1}\def\dsize{##2}%
    \def\dbextfn{##3}\def\dbsbfn{##4}\def\dbhjfn{##5}}
  \openin1=dbfont.map \readloop \closein1
  \endgroup}
\endgroup
% Let \documentclass read DBC font mapping table
\gdef\documentclass{\load@dbfont@map\let\load@dbfont@map\relax
  \let\documentclass\@twoclasseserror
  \let\usepackage\RequirePackage
  \@fileswithoptions\@clsextension}
\gdef\documentstyle{\load@dbfont@map\let\load@dbfont@map\relax
  \makeatletter\input{latex209.def}\makeatother
  \documentclass}
\begingroup%% Define 2-byte characters.
\def\strip#1 {#1}
\def\loopA{\count2="A1\loopB \ifodd\count1\message{.}\fi
  \advance\count1 by1 \ifnum\count1<"C9 \let\n=\loopA\else\let\n=\relax\fi\n}
\def\loopB{\read1 to\h\read1 to\a\read1 to\b\read1 to\c\def\body{}
  \expandafter\xdef\csname\number\count1@\number\count2\endcsname{%
    \expandafter\noexpand\ifcase\expandafter\strip\h \or\dbfont@A\or\dbfont@B\fi
    \ifnum\a=0\else\char\expandafter\strip\a
    \ifnum\b=0\else\char\expandafter\strip\b
    \ifnum\c=0\else\char\expandafter\strip\c\fi\fi\fi}
  \advance\count2 by1 \ifnum\count2<"FF \let\m=\loopB\else\let\m=\relax\fi\m}
\message{Defining 2-byte characters}
\openin1=hcode.dat \count1="B0\loopA \closein1
\endgroup
%% Add 2-byte character handler.
\global\chardef\@xiii@=13\global\chardef\@xii@=12
\global\chardef\dbcp@n@lty=0
\global\newdimen\dbs@pkern \global\dbs@pkern=7sp
\global\newdimen\dbs@pkernchk
\begingroup %Define DBC activator and deactivator.
\def\e{\ifnum\count\@ne<"100
  \edef\d{\d \catcode\the\count\@ne\f}\advance\count\@ne by1
  \else\let\n\relax \fi\n}
\def\f{\@xiii@}\def\d{}\count\@ne="80\let\n\e \e
\global\let\makedbcharactive\d
\def\f{\@xii@}\def\d{}\count\@ne="80\let\n\e \e
\global\let\makedbcharother\d
\endgroup
\makedbcharactive
\begingroup %Define hangul characters.
\r\ifdim \r\fi \r\number
\count\@ne=176
\def\d{\ifdim\lastkern=\dbs@pkernchk\penalty\dbcp@n@lty\fi\unhbox\voidb@x
  \hbox\bgroup\csn\the\count\@ne @\number`##1\endcsn\egroup\kern\dbs@pkern}
\def\e{\advance\count\@ne by\@ne}
\xdef^^b0#1{\d}\e \xdef^^b1#1{\d}\e \xdef^^b2#1{\d}\e \xdef^^b3#1{\d}\e
\xdef^^b4#1{\d}\e \xdef^^b5#1{\d}\e \xdef^^b6#1{\d}\e \xdef^^b7#1{\d}\e
\xdef^^b8#1{\d}\e \xdef^^b9#1{\d}\e \xdef^^ba#1{\d}\e \xdef^^bb#1{\d}\e
\xdef^^bc#1{\d}\e \xdef^^bd#1{\d}\e \xdef^^be#1{\d}\e \xdef^^bf#1{\d}\e
\xdef^^c0#1{\d}\e \xdef^^c1#1{\d}\e \xdef^^c2#1{\d}\e \xdef^^c3#1{\d}\e
\xdef^^c4#1{\d}\e \xdef^^c5#1{\d}\e \xdef^^c6#1{\d}\e \xdef^^c7#1{\d}\e
\xdef^^c8#1{\d}\e
\endgroup
\begingroup %Define symbol and hanja characters.
\def\d#1#2{%
  \noexpand\ifdim\lastkern=\dbs@pkernchk\penalty\dbcp@n@lty\noexpand\fi
  \unhbox\voidb@x \expandafter\noexpand\csname load@dbfont\fn #1\endcsname
  \hbox\bgroup\expandafter\noexpand\csname dbfont@\fn #1\endcsname
  \count\@ne=`##1\advance\count\@ne#2\char\count\@ne\egroup\kern\dbs@pkern}
\def\D#1#2#3#4{%
  \noexpand\ifdim\lastkern=\dbs@pkernchk\penalty\dbcp@n@lty\noexpand\fi
  \unhbox\voidb@x
  \noexpand\ifnum`##1<#3
    \expandafter\noexpand\csname load@dbfont\fn #1\endcsname
    \hbox\bgroup\expandafter\noexpand\csname dbfont@\fn #1\endcsname
    \count\@ne=`##1\advance\count\@ne#4%
  \noexpand\else \expandafter\noexpand\csname load@dbfont\fn#2\endcsname
    \hbox\bgroup\expandafter\noexpand\csname dbfont@\fn #2\endcsname
    \count\@ne=`##1\advance\count\@ne-#3%
  \noexpand\fi \char\count\@ne\egroup\kern\dbs@pkern}
\def\fn{sb}
\xdef^^a1#1{\d A{-"A0}}\xdef^^a2#1{\d A{-"40}}\xdef^^a3#1{\D AB{"E0}{"20}}
\xdef^^a4#1{\d B{-"80}}\xdef^^a5#1{\d B{-"20}}\xdef^^a6#1{\D BC{"C0}{"40}}
\xdef^^a7#1{\d C{-"60}}\xdef^^a8#1{\d C{0}}\xdef^^a9#1{\d D{-"A0}}
\xdef^^aa#1{\d D{-"40}}\xdef^^ab#1{\D DE{"E0}{"20}}\xdef^^ac#1{\d E{-"80}}
\def\fn{hj}
\xdef^^ca#1{\d A{-"A1}}\xdef^^cb#1{\d A{-"43}}\xdef^^cc#1{\D AB{"E5}{"1B}}
\xdef^^cd#1{\d B{-"87}}\xdef^^ce#1{\d B{-"29}}\xdef^^cf#1{\D BC{"CB}{"35}}
\xdef^^d0#1{\d C{-"6D}}\xdef^^d1#1{\d C{-"0F}}\xdef^^d2#1{\D CD{"B1}{"4F}}
\xdef^^d3#1{\d D{-"53}}\xdef^^d4#1{\D DE{"F5}{"0B}}\xdef^^d5#1{\d E{-"97}}
\xdef^^d6#1{\d E{-"39}}\xdef^^d7#1{\D EF{"DB}{"25}}\xdef^^d8#1{\d F{-"7D}}
\xdef^^d9#1{\d F{-"1F}}\xdef^^da#1{\D FG{"C1}{"3F}}\xdef^^db#1{\d G{-"63}}
\xdef^^dc#1{\d G{-"05}}\xdef^^dd#1{\D GH{"A7}{"59}}\xdef^^de#1{\d H{-"49}}
\xdef^^df#1{\D HI{"EB}{"15}}\xdef^^e0#1{\d I{-"8D}}\xdef^^e1#1{\d I{-"2F}}
\xdef^^e2#1{\D IJ{"D1}{"2F}}\xdef^^e3#1{\d J{-"73}}\xdef^^e4#1{\d J{-"15}}
\xdef^^e5#1{\D JK{"B7}{"49}}\xdef^^e6#1{\d K{-"59}}\xdef^^e7#1{\D KL{"FB}{"05}}
\xdef^^e8#1{\d L{-"9D}}\xdef^^e9#1{\d L{-"3F}}\xdef^^ea#1{\D LM{"E1}{"1F}}
\xdef^^eb#1{\d M{-"83}}\xdef^^ec#1{\d M{-"25}}\xdef^^ed#1{\D MN{"C7}{"39}}
\xdef^^ee#1{\d N{-"69}}\xdef^^ef#1{\d N{-"0B}}\xdef^^f0#1{\D NO{"AD}{"53}}
\xdef^^f1#1{\d O{-"4F}}\xdef^^f2#1{\D OP{"F1}{"0F}}\xdef^^f3#1{\d P{-"93}}
\xdef^^f4#1{\d P{-"35}}\xdef^^f5#1{\D PQ{"D7}{"29}}\xdef^^f6#1{\d Q{-"79}}
\xdef^^f7#1{\d Q{-"1B}}\xdef^^f8#1{\D QR{"BD}{"43}}\xdef^^f9#1{\d R{-"5F}}
\xdef^^fa#1{\d R{-"01}}\xdef^^fb#1{\D RS{"A3}{"5D}}\xdef^^fc#1{\d S{-"45}}
\xdef^^fd#1{\D ST{"E7}{"19}}
\endgroup
\endgroup
\makedbcharactive
\DeclareRobustCommand{\hangulbreaking}{\dbs@pkernchk=\dbs@pkern}
\DeclareRobustCommand{\nohangulbreaking}{\dbs@pkernchk=3sp\relax}
\hangulbreaking
\def\makedbcharstring{\makedbcharprotected\let\db@protect\string}
\def\makedbcharnoexpand{\makedbcharprotected\let\db@protect\noexpand}
\def\makedbcharprotected{%
\def^^80{\db@protect^^80}\def^^81{\db@protect^^81}\def^^82{\db@protect^^82}\def^^83{\db@protect^^83}%
\def^^84{\db@protect^^84}\def^^85{\db@protect^^85}\def^^86{\db@protect^^86}\def^^87{\db@protect^^87}%
\def^^88{\db@protect^^88}\def^^89{\db@protect^^89}\def^^8a{\db@protect^^8a}\def^^8b{\db@protect^^8b}%
\def^^8c{\db@protect^^8c}\def^^8d{\db@protect^^8d}\def^^8e{\db@protect^^8e}\def^^8f{\db@protect^^8f}%
\def^^90{\db@protect^^90}\def^^91{\db@protect^^91}\def^^92{\db@protect^^92}\def^^93{\db@protect^^93}%
\def^^94{\db@protect^^94}\def^^95{\db@protect^^95}\def^^96{\db@protect^^96}\def^^97{\db@protect^^97}%
\def^^98{\db@protect^^98}\def^^99{\db@protect^^99}\def^^9a{\db@protect^^9a}\def^^9b{\db@protect^^9b}%
\def^^9c{\db@protect^^9c}\def^^9d{\db@protect^^9d}\def^^9e{\db@protect^^9e}\def^^9f{\db@protect^^9f}%
\def^^a0{\db@protect^^a0}\def^^a1{\db@protect^^a1}\def^^a2{\db@protect^^a2}\def^^a3{\db@protect^^a3}%
\def^^a4{\db@protect^^a4}\def^^a5{\db@protect^^a5}\def^^a6{\db@protect^^a6}\def^^a7{\db@protect^^a7}%
\def^^a8{\db@protect^^a8}\def^^a9{\db@protect^^a9}\def^^aa{\db@protect^^aa}\def^^ab{\db@protect^^ab}%
\def^^ac{\db@protect^^ac}\def^^ad{\db@protect^^ad}\def^^ae{\db@protect^^ae}\def^^af{\db@protect^^af}%
\def^^b0{\db@protect^^b0}\def^^b1{\db@protect^^b1}\def^^b2{\db@protect^^b2}\def^^b3{\db@protect^^b3}%
\def^^b4{\db@protect^^b4}\def^^b5{\db@protect^^b5}\def^^b6{\db@protect^^b6}\def^^b7{\db@protect^^b7}%
\def^^b8{\db@protect^^b8}\def^^b9{\db@protect^^b9}\def^^ba{\db@protect^^ba}\def^^bb{\db@protect^^bb}%
\def^^bc{\db@protect^^bc}\def^^bd{\db@protect^^bd}\def^^be{\db@protect^^be}\def^^bf{\db@protect^^bf}%
\def^^c0{\db@protect^^c0}\def^^c1{\db@protect^^c1}\def^^c2{\db@protect^^c2}\def^^c3{\db@protect^^c3}%
\def^^c4{\db@protect^^c4}\def^^c5{\db@protect^^c5}\def^^c6{\db@protect^^c6}\def^^c7{\db@protect^^c7}%
\def^^c8{\db@protect^^c8}\def^^c9{\db@protect^^c9}\def^^ca{\db@protect^^ca}\def^^cb{\db@protect^^cb}%
\def^^cc{\db@protect^^cc}\def^^cd{\db@protect^^cd}\def^^ce{\db@protect^^ce}\def^^cf{\db@protect^^cf}%
\def^^d0{\db@protect^^d0}\def^^d1{\db@protect^^d1}\def^^d2{\db@protect^^d2}\def^^d3{\db@protect^^d3}%
\def^^d4{\db@protect^^d4}\def^^d5{\db@protect^^d5}\def^^d6{\db@protect^^d6}\def^^d7{\db@protect^^d7}%
\def^^d8{\db@protect^^d8}\def^^d9{\db@protect^^d9}\def^^da{\db@protect^^da}\def^^db{\db@protect^^db}%
\def^^dc{\db@protect^^dc}\def^^dd{\db@protect^^dd}\def^^de{\db@protect^^de}\def^^df{\db@protect^^df}%
\def^^e0{\db@protect^^e0}\def^^e1{\db@protect^^e1}\def^^e2{\db@protect^^e2}\def^^e3{\db@protect^^e3}%
\def^^e4{\db@protect^^e4}\def^^e5{\db@protect^^e5}\def^^e6{\db@protect^^e6}\def^^e7{\db@protect^^e7}%
\def^^e8{\db@protect^^e8}\def^^e9{\db@protect^^e9}\def^^ea{\db@protect^^ea}\def^^eb{\db@protect^^eb}%
\def^^ec{\db@protect^^ec}\def^^ed{\db@protect^^ed}\def^^ee{\db@protect^^ee}\def^^ef{\db@protect^^ef}%
\def^^f0{\db@protect^^f0}\def^^f1{\db@protect^^f1}\def^^f2{\db@protect^^f2}\def^^f3{\db@protect^^f3}%
\def^^f4{\db@protect^^f4}\def^^f5{\db@protect^^f5}\def^^f6{\db@protect^^f6}\def^^f7{\db@protect^^f7}%
\def^^f8{\db@protect^^f8}\def^^f9{\db@protect^^f9}\def^^fa{\db@protect^^fa}\def^^fb{\db@protect^^fb}%
\def^^fc{\db@protect^^fc}\def^^fd{\db@protect^^fd}\def^^fe{\db@protect^^fe}\def^^ff{\db@protect^^ff}}
%% Modify part of NFSS2 to load and select fonts for 2-byte characters.
\def\@use@text@encoding#1{%
   \edef\f@encoding{#1}%
   \xdef\font@name{%
      \csname\curr@fontshape/\f@size\endcsname
   }%
   \pickup@font
   \font@name \select@dbfont\font@name
   \@@enc@update
}
\def\do@subst@correction{%
       \xdef\subst@correction{%
          \font@name \noexpand\select@dbfont{\font@name}%
          \global\expandafter\font
            \csname \curr@fontshape/\f@size\endcsname
            \noexpand\fontname\font\relax
            \noexpand\load@dbfont{\csname \curr@fontshape/\f@size\endcsname}%
           \relax}%
       \aftergroup\subst@correction
}
\def\extract@font{%
   \get@external@font
   \global\expandafter\font\font@name\external@font\relax
   \load@dbfont{\font@name}\relax
    \font@name \relax \select@dbfont\font@name
    \csname \f@encoding+\f@family\endcsname
    \csname\curr@fontshape\endcsname
    \relax
       }
\DeclareRobustCommand\selectfont
        {%
    \ifx\f@linespread\baselinestretch \else
      \set@fontsize\baselinestretch\f@size\f@baselineskip \fi
    \xdef\font@name{%
      \csname\curr@fontshape/\f@size\endcsname}%
    \pickup@font
    \font@name \select@dbfont\font@name
    \size@update
    \enc@update
    }
