From e0c6872cf40896c7be36b11dcc744620f10adf1d Mon Sep 17 00:00:00 2001
From: Norbert Preining <norbert@preining.info>
Date: Mon, 2 Sep 2019 13:46:59 +0900
Subject: Initial commit

---
 macros/xetex/generic/xetexko/xetexko-font.sty | 597 ++++++++++++++++++++++++++
 1 file changed, 597 insertions(+)
 create mode 100644 macros/xetex/generic/xetexko/xetexko-font.sty

(limited to 'macros/xetex/generic/xetexko/xetexko-font.sty')

diff --git a/macros/xetex/generic/xetexko/xetexko-font.sty b/macros/xetex/generic/xetexko/xetexko-font.sty
new file mode 100644
index 0000000000..8227485991
--- /dev/null
+++ b/macros/xetex/generic/xetexko/xetexko-font.sty
@@ -0,0 +1,597 @@
+% xetexko-font.sty
+%
+% Copyright (c) 2013-2018 Dohyun Kim  <nomos at ktug org>
+%
+% 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.
+
+\ProvidesPackage{xetexko-font}[2018/08/08 v2.21 LaTeX Font commands for XeTeX-ko]
+
+\let\xetexko@f@size\f@size
+\RequirePackage{fontspec}[2018/07/30]
+\let\f@size\xetexko@f@size
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%% for old hangul rendering
+\newfontfeature{YetHangul}{script=hang}
+
+\ExplSyntaxOn
+%%%%%%%%%%%%%%%%%%%%%
+% hangul font options
+\tl_new:N \l_xtxko_font_opts_tl
+\tl_new:N \l_xtxko_font_opts_init_tl
+\tl_set:Nn \l_xtxko_font_opts_init_tl
+  {
+    \tl_clear:N \xetexkointerhchar
+    \tl_clear:N \xetexkolowerexclamation
+    \tl_clear:N \xetexkolowerperiod
+    \tl_clear:N \xetexkolowercomma
+    \tl_clear:N \xetexkolowerquestion
+    \tl_clear:N \xetexkopostexclamationkern
+    \tl_clear:N \xetexkopostperiodkern
+    \tl_clear:N \xetexkopostcommakern
+    \tl_clear:N \xetexkopostquestionkern
+    \tl_clear:N \xetexkopreexclamationkern
+    \tl_clear:N \xetexkopreperiodkern
+    \tl_clear:N \xetexkoprecommakern
+    \tl_clear:N \xetexkoprequestionkern
+    \tl_clear:N \xetexkoquoteraise
+    \tl_clear:N \xetexkoquotewidth
+    \tl_clear:N \xetexkocharraise
+    \tl_set:Nn  \xetexkohu            {0.05em}
+    \tl_set:Nn  \xetexkopostmathskip  {\dim_eval:n {\xetexkohu*2}}
+  }
+\cs_new:Nn \__xtxko_add_font_opt:Nn
+  {
+    \tl_put_right:Nn \l_xtxko_font_opts_tl { \tl_set:Nn #1 {#2} }
+  }
+\keys_define:nn { xtxko-font }
+  {
+    hu .code:n =
+      { \__xtxko_add_font_opt:Nn \xetexkohu                  {#1} } ,
+    interhchar .code:n =
+      { \__xtxko_add_font_opt:Nn \xetexkointerhchar          {#1} } ,
+    lowerexclamation .code:n =
+      { \__xtxko_add_font_opt:Nn \xetexkolowerexclamation    {#1} } ,
+    lowerperiod .code:n =
+      { \__xtxko_add_font_opt:Nn \xetexkolowerperiod         {#1} } ,
+    lowercomma .code:n =
+      { \__xtxko_add_font_opt:Nn \xetexkolowercomma          {#1} } ,
+    lowerquestion .code:n =
+      { \__xtxko_add_font_opt:Nn \xetexkolowerquestion       {#1} } ,
+    postexclamationkern .code:n =
+      { \__xtxko_add_font_opt:Nn \xetexkopostexclamationkern {#1} } ,
+    postmathskip .code:n =
+      { \__xtxko_add_font_opt:Nn \xetexkopostmathskip        {#1} } ,
+    postperiodkern .code:n =
+      { \__xtxko_add_font_opt:Nn \xetexkopostperiodkern      {#1} } ,
+    postcommakern .code:n =
+      { \__xtxko_add_font_opt:Nn \xetexkopostcommakern       {#1} } ,
+    postquestionkern .code:n =
+      { \__xtxko_add_font_opt:Nn \xetexkopostquestionkern    {#1} } ,
+    preexclamationkern .code:n =
+      { \__xtxko_add_font_opt:Nn \xetexkopreexclamationkern  {#1} } ,
+    preperiodkern .code:n =
+      { \__xtxko_add_font_opt:Nn \xetexkopreperiodkern       {#1} } ,
+    precommakern .code:n =
+      { \__xtxko_add_font_opt:Nn \xetexkoprecommakern        {#1} } ,
+    prequestionkern .code:n =
+      { \__xtxko_add_font_opt:Nn \xetexkoprequestionkern     {#1} } ,
+    quoteraise .code:n =
+      { \__xtxko_add_font_opt:Nn \xetexkoquoteraise          {#1} } ,
+    quotewidth .code:n =
+      { \__xtxko_add_font_opt:Nn \xetexkoquotewidth          {#1} } ,
+    charraise .code:n =
+      { \__xtxko_add_font_opt:Nn \xetexkocharraise           {#1} } ,
+    InterLatinCJK .meta:n = { hu          = {#1} } ,
+    InterHangul   .meta:n = { interhchar  = {#1} } ,
+    PunctRaise    .meta:n = { lowerperiod = { \dim_eval:n {-#1} } } ,
+    CharRaise     .meta:n = { charraise   = {#1} } ,
+  }
+\tl_new:N \l_xtxko_rem_tl
+\tl_set_eq:NN \l_xtxko_hangul_font_opts_init_tl \l_xtxko_font_opts_init_tl
+\cs_new:Nn \__xtxko_hangul_assign_font_opts:n
+  {
+    \tl_set_eq:NN \l_xtxko_font_opts_tl \l_xtxko_hangul_font_opts_init_tl
+    \keys_set_known:nxN { xtxko-font } {#1} \l_xtxko_rem_tl
+  }
+\tl_set_eq:NN \l_xtxko_hanja_font_opts_init_tl  \l_xtxko_font_opts_init_tl
+\cs_new:Nn \__xtxko_hanja_assign_font_opts:n
+  {
+    \tl_set_eq:NN \l_xtxko_font_opts_tl \l_xtxko_hanja_font_opts_init_tl
+    \keys_set_known:nxN { xtxko-font } {#1} \l_xtxko_rem_tl
+  }
+\cs_new:Nn \__xtxko_def_XKhan__fonts:nnn
+  {
+    \tl_if_eq:NNF #1 \relax
+      {
+        \tl_if_eq:ccT \familydefault #2
+          {
+            \tl_if_eq:NNTF \XKhangulfont #1
+              {
+                \tl_set:Nn #1
+                  {
+                    \XK@storeltnfont
+                    \chardef\XKcurrentfont \c_one #3
+                    \XK@storecjkfont
+                  }
+              }
+              {
+                \tl_set:Nn #1
+                  {
+                    \XK@storeltnfont
+                    \chardef\XKcurrentfont \c_two #3
+                    \XK@storecjkfont
+                  }
+              }
+          }
+      }
+  }
+%%%%%%%%%%%%%%%%%%%%
+% user font commands
+\DeclareDocumentCommand \setmainhangulfont { O{} m O{} }
+  {
+    \__xtxko_hangul_assign_font_opts:n {#1,#3}
+    \setfontfamily \kormainfont [\l_xtxko_rem_tl] {#2}
+    \tl_put_right:NV \kormainfont \l_xtxko_font_opts_tl
+    \__xtxko_def_XKhan__fonts:nnn \XKhangulfont \rmdefault \kormainfont
+    \ignorespaces
+  }
+\DeclareDocumentCommand \setsanshangulfont { O{} m O{} }
+  {
+    \__xtxko_hangul_assign_font_opts:n {#1,#3}
+    \setfontfamily \korsansfont [\l_xtxko_rem_tl] {#2}
+    \tl_put_right:NV \korsansfont \l_xtxko_font_opts_tl
+    \__xtxko_def_XKhan__fonts:nnn \XKhangulfont \sfdefault \korsansfont
+    \ignorespaces
+  }
+\DeclareDocumentCommand \setmonohangulfont { O{} m O{} }
+  {
+    \setfontfamily \kormonofont [#1,#3] {#2}
+    \__xtxko_def_XKhan__fonts:nnn \XKhangulfont \ttdefault \kormonofont
+    \ignorespaces
+  }
+\DeclareDocumentCommand \setmainhanjafont { O{} m O{} }
+  {
+    \__xtxko_hanja_assign_font_opts:n {#1,#3}
+    \setfontfamily \hnjmainfont [\l_xtxko_rem_tl] {#2}
+    \tl_put_right:NV \hnjmainfont \l_xtxko_font_opts_tl
+    \__xtxko_def_XKhan__fonts:nnn \XKhanjafont \rmdefault \hnjmainfont
+    \ignorespaces
+  }
+\DeclareDocumentCommand \setsanshanjafont { O{} m O{} }
+  {
+    \__xtxko_hanja_assign_font_opts:n {#1,#3}
+    \setfontfamily \hnjsansfont [\l_xtxko_rem_tl] {#2}
+    \tl_put_right:NV \hnjsansfont \l_xtxko_font_opts_tl
+    \__xtxko_def_XKhan__fonts:nnn \XKhanjafont \sfdefault \hnjsansfont
+    \ignorespaces
+  }
+\DeclareDocumentCommand \setmonohanjafont { O{} m O{} }
+  {
+    \setfontfamily \hnjmonofont [#1,#3] {#2}
+    \__xtxko_def_XKhan__fonts:nnn \XKhanjafont \ttdefault \hnjmonofont
+    \ignorespaces
+  }
+%% {hangul,hanja}fontspec = adhoc{hangul,hanja}font
+\DeclareDocumentCommand \adhochangulfont { O{} m O{} }
+  {
+    \__xtxko_hangul_assign_font_opts:n {#1,#3}
+    \setfontfamily \XK@adhoc@hangul@font [\l_xtxko_rem_tl] {#2}
+    \tl_put_right:NV \XK@adhoc@hangul@font \l_xtxko_font_opts_tl
+    \tl_set:Nn \XKhangulfont
+      {
+        \XK@storeltnfont
+        \tl_set_eq:NN \XKcurrentfont \c_one
+        \XK@adhoc@hangul@font
+        \XK@storecjkfont
+      }
+    \ignorespaces
+  }
+\cs_set_eq:NN \hangulfontspec \adhochangulfont
+\DeclareDocumentCommand \adhochanjafont { O{} m O{} }
+  {
+    \__xtxko_hanja_assign_font_opts:n {#1,#3}
+    \setfontfamily \XK@adhoc@hanja@font [\l_xtxko_rem_tl] {#2}
+    \tl_put_right:NV \XK@adhoc@hanja@font \l_xtxko_font_opts_tl
+    \tl_set:Nn \XKhanjafont
+      {
+        \XK@storeltnfont
+        \tl_set_eq:NN \XKcurrentfont \c_two
+        \XK@adhoc@hanja@font
+        \XK@storecjkfont
+      }
+    \ignorespaces
+  }
+\cs_set_eq:NN \hanjafontspec \adhochanjafont
+%% new{hangul,hanja}font{family,face}
+\DeclareDocumentCommand \newhangulfontfamily { m O{} m O{} }
+  {
+    \__xtxko_hangul_assign_font_opts:n {#2,#4}
+    \exp_args:Nc \setfontfamily { XK@newfont@family \token_to_str:N #1 }
+      [\l_xtxko_rem_tl] {#3}
+    \tl_put_right:cV { XK@newfont@family \token_to_str:N #1 }
+      \l_xtxko_font_opts_tl
+    \DeclareRobustCommand #1
+      {
+        \tl_set:Nn \XKhangulfont
+          {
+            \XK@storeltnfont
+            \tl_set_eq:NN \XKcurrentfont \c_one
+            \use:c { XK@newfont@family \token_to_str:N #1 }
+            \XK@storecjkfont
+          }
+      }
+  }
+\DeclareDocumentCommand \newhanjafontfamily { m O{} m O{} }
+  {
+    \__xtxko_hanja_assign_font_opts:n {#2,#4}
+    \exp_args:Nc \setfontfamily { XK@newfont@family \token_to_str:N #1 }
+      [\l_xtxko_rem_tl] {#3}
+    \tl_put_right:cV { XK@newfont@family \token_to_str:N #1 }
+      \l_xtxko_font_opts_tl
+    \DeclareRobustCommand #1
+      {
+        \tl_set:Nn \XKhanjafont
+          {
+            \XK@storeltnfont
+            \tl_set_eq:NN \XKcurrentfont \c_two
+            \use:c { XK@newfont@family \token_to_str:N #1 }
+            \XK@storecjkfont
+          }
+      }
+  }
+\DeclareDocumentCommand \newhangulfontface { m O{} m O{} }
+  {
+    \__xtxko_hangul_assign_font_opts:n {#2,#4}
+    \exp_args:Nc \newfontface { XK@newfont@family \token_to_str:N #1 }
+      [\l_xtxko_rem_tl] {#3}
+    \tl_put_right:cV { XK@newfont@family \token_to_str:N #1 }
+      \l_xtxko_font_opts_tl
+    \DeclareRobustCommand #1
+      {
+        \tl_set:Nn \XKhangulfont
+          {
+            \XK@storeltnfont
+            \tl_set_eq:NN \XKcurrentfont \c_one
+            \use:c { XK@newfont@family \token_to_str:N #1 }
+            \XK@storecjkfont
+          }
+      }
+  }
+\DeclareDocumentCommand \newhanjafontface { m O{} m O{} }
+  {
+    \__xtxko_hanja_assign_font_opts:n {#2,#4}
+    \exp_args:Nc \newfontface { XK@newfont@family \token_to_str:N #1 }
+      [\l_xtxko_rem_tl] {#3}
+    \tl_put_right:cV { XK@newfont@family \token_to_str:N #1 }
+      \l_xtxko_font_opts_tl
+    \DeclareRobustCommand #1
+      {
+        \tl_set:Nn \XKhanjafont
+          {
+            \XK@storeltnfont
+            \tl_set_eq:NN \XKcurrentfont \c_two
+            \use:c { XK@newfont@family \token_to_str:N #1 }
+            \XK@storecjkfont
+          }
+      }
+  }
+%% add{hangul,hanja}fontfeature[s]
+\DeclareDocumentCommand \addhangulfontfeature { m }
+  {
+    \group_begin:
+    \XKhangulfont
+    \tl_clear:N \l_xtxko_font_opts_tl
+    \keys_set_known:nxN { xtxko-font } {#1} \l_xtxko_rem_tl
+    \addfontfeature {\l_xtxko_rem_tl}
+    \use:x
+      {
+        \group_end:
+        \exp_not:N \tl_set:Nn \exp_not:N \XKhangulfont
+          {
+            \exp_not:V \XKhangulfont
+            \exp_not:N \fontfamily { \f@family } \exp_not:N \selectfont
+            \exp_not:V \l_xtxko_font_opts_tl
+            \exp_not:N \XK@storecjkfont
+          }
+      }
+    \ignorespaces
+  }
+\cs_set_eq:NN \addhangulfontfeatures \addhangulfontfeature
+\DeclareDocumentCommand \addhanjafontfeature { m }
+  {
+    \group_begin:
+    \XKhanjafont
+    \tl_clear:N \l_xtxko_font_opts_tl
+    \keys_set_known:nxN { xtxko-font } {#1} \l_xtxko_rem_tl
+    \addfontfeature {\l_xtxko_rem_tl}
+    \use:x
+      {
+        \group_end:
+        \exp_not:N \tl_set:Nn \exp_not:N \XKhanjafont
+          {
+            \exp_not:V \XKhanjafont
+            \exp_not:N \fontfamily { \f@family } \exp_not:N \selectfont
+            \exp_not:V \l_xtxko_font_opts_tl
+            \exp_not:N \XK@storecjkfont
+          }
+      }
+    \ignorespaces
+  }
+\cs_set_eq:NN \addhanjafontfeatures \addhanjafontfeature
+%% default font features
+\defaultfontfeatures
+  [
+    \kormainfont, \korsansfont, \hnjmainfont, \hnjsansfont,
+  ]
+  {Ligatures=TeX}
+\DeclareDocumentCommand \defaulthangulfontfeatures { t+ o m } % o is ignored
+  {
+    \IfBooleanTF {#1}
+      {
+        \tl_set_eq:NN \l_xtxko_font_opts_tl \l_xtxko_hangul_font_opts_init_tl
+      }
+      {
+        \tl_set_eq:NN \l_xtxko_font_opts_tl \l_xtxko_font_opts_init_tl
+      }
+    \keys_set_known:nxN { xtxko-font } {#3} \l_xtxko_rem_tl % rem_tl ignored
+    \tl_set_eq:NN \l_xtxko_hangul_font_opts_init_tl \l_xtxko_font_opts_tl
+  }
+\DeclareDocumentCommand \defaulthanjafontfeatures { t+ o m } % o is ignored
+  {
+    \IfBooleanTF {#1}
+      {
+        \tl_set_eq:NN \l_xtxko_font_opts_tl \l_xtxko_hanja_font_opts_init_tl
+      }
+      {
+        \tl_set_eq:NN \l_xtxko_font_opts_tl \l_xtxko_font_opts_init_tl
+      }
+    \keys_set_known:nxN { xtxko-font } {#3} \l_xtxko_rem_tl % rem_tl ignored
+    \tl_set_eq:NN \l_xtxko_hanja_font_opts_init_tl \l_xtxko_font_opts_tl
+  }
+%% math hangul font
+\DeclareDocumentCommand \setmathhangulfont { O{} m O{} }
+  {
+    \fontspec_set_family:Nnn \xetexko@math@hangul@family {#1,#3} {#2}
+  }
+%%%%%%%%%%%%%%%%%%%%
+%% xetexkofontregime
+\keys_define:nn { xtxko-char }
+  {
+    alphs       .code:n = \use:c { #1alphs } ,
+    nums        .code:n = \use:c { #1nums } ,
+    parens      .code:n = \use:c { #1parens } ,
+    quotes      .code:n = \use:c { #1quotes } ,
+    puncts      .code:n = \use:c { #1puncts } ,
+    colons      .code:n = \use:c { #1colons } ,
+    hyphens     .code:n = \use:c { #1hyphens } ,
+    cjksymbols  .code:n = \use:c { #1cjksymbols } ,
+  }
+\DeclareDocumentCommand \xetexkofontregime { O{} m O{} }
+  {
+    \use:c { #2marks }
+    \keys_set:nn { xtxko-char } { #1,#3 }
+  }
+%% fontspec 2018
+\RenewDocumentCommand \setmainfont { O{} m O{} }
+  {
+    \__fontspec_main_setmainfont:nn {#1,#3} {#2}
+    \protected\edef\rmfamily{\unexpanded\expandafter{\rmfamily\XK@rm@korean@font}}
+    \ignorespaces
+  }
+\RenewDocumentCommand \setsansfont { O{} m O{} }
+  {
+    \__fontspec_main_setsansfont:nn {#1,#3} {#2}
+    \protected\edef\sffamily{\unexpanded\expandafter{\sffamily\XK@sf@korean@font}}
+    \ignorespaces
+  }
+\RenewDocumentCommand \setmonofont { O{} m O{} }
+  {
+    \__fontspec_main_setmonofont:nn {#1,#3} {#2}
+    \protected\edef\ttfamily{\unexpanded\expandafter{\ttfamily\XK@tt@korean@font
+      \disablehangulspacing}}
+    \ignorespaces
+  }
+\cs_set_eq:NN \setromanfont \setmainfont
+\ExplSyntaxOff
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%
+% font switching for latex
+\def\XKstoreprevfont{%
+  \ifx\f@family\XKcjkprevfont\let\f@family\XKltnprevfont\fi
+}
+\def\XK@storeltnfont{%
+  \ifx\f@family\XKcjkprevfont\else\let\XKltnprevfont\f@family\fi
+}
+\def\XK@storecjkfont{%
+  \let\XKcjkprevfont\f@family
+  \edef\XKplaincjkprevfont{\the\font}%
+}
+\edef\XKlatinfont{\unexpanded\expandafter{\XKstoreprevfont
+    \chardef\XKcurrentfont\z@
+    \edef\XK@plain@curr@font{\the\font}%
+    \ifx\XK@plain@curr@font\XKplaincjkprevfont
+      \selectfont
+    \fi
+}}
+
+\def\XK@rm@korean@font{%
+  \ifx\XKhangulfont\relax\else
+    \def\XKhangulfont{%
+      \XK@storeltnfont
+      \chardef\XKcurrentfont\@ne\kormainfont
+      \XK@storecjkfont
+    }%
+  \fi
+  \ifx\XKhanjafont\relax\else
+    \def\XKhanjafont {%
+      \XK@storeltnfont
+      \chardef\XKcurrentfont\tw@\hnjmainfont
+      \XK@storecjkfont
+    }%
+  \fi
+}
+\def\XK@sf@korean@font{%
+  \ifx\XKhangulfont\relax\else
+    \def\XKhangulfont{%
+      \XK@storeltnfont
+      \chardef\XKcurrentfont\@ne\korsansfont
+      \XK@storecjkfont
+    }%
+  \fi
+  \ifx\XKhanjafont\relax\else
+    \def\XKhanjafont {%
+      \XK@storeltnfont
+      \chardef\XKcurrentfont\tw@\hnjsansfont
+      \XK@storecjkfont
+    }%
+  \fi
+}
+\def\XK@tt@korean@font{%
+  \ifx\XKhangulfont\relax\else
+    \def\XKhangulfont{%
+      \XK@storeltnfont
+      \chardef\XKcurrentfont\@ne\kormonofont
+      \XK@storecjkfont
+    }%
+  \fi
+  \ifx\XKhanjafont\relax\else
+    \def\XKhanjafont {%
+      \XK@storeltnfont
+      \chardef\XKcurrentfont\tw@\hnjmonofont
+      \XK@storecjkfont
+    }%
+  \fi
+}
+
+\protected\edef\rmfamily{\unexpanded\expandafter{\rmfamily\XK@rm@korean@font}}
+\protected\edef\sffamily{\unexpanded\expandafter{\sffamily\XK@sf@korean@font}}
+\protected\edef\ttfamily{\unexpanded\expandafter{\ttfamily
+  \XK@tt@korean@font\disablehangulspacing
+}}
+\edef\verbatim@font{\unexpanded\expandafter{\verbatim@font
+    \disablehangulspacingandlinebreak
+    \let\XKstoreprevfont\XKlatinfont
+}}
+
+% for default font loading
+\def\XKiffontisaccessible#1#2#3{%
+  \begingroup
+  \suppressfontnotfounderror\@ne
+  \font\x="#1" at 10pt
+  \expandafter
+  \endgroup
+  \ifx\x\nullfont #3\else #2\fi
+}
+\def\XKiffonthasunichar#1#2#3#4{%
+  \begingroup #1\expandafter\endgroup
+  \iffontchar\font"#2\relax #3\else #4\fi
+}
+
+\AtBeginDocument{%
+  %%%%%%%%%%%%%%%%%%%%%%%%%%
+  % default main hangul: nanummyeongjo, batang if absent
+  \ifdefined\kormainfont\else
+    \XKiffonthasunichar{\fontfamily\rmdefault\selectfont}{AC00}
+      {\let\kormainfont\relax}
+      {\XKiffontisaccessible{NanumMyeongjoExtraBold}
+        {\setmainhangulfont{NanumMyeongjo}[Renderer=OpenType,BoldFont=*ExtraBold]}
+        {\XKiffontisaccessible{NanumMyeongjo}
+          {\setmainhangulfont{NanumMyeongjo}[Renderer=OpenType]}
+          {\XKiffontisaccessible{Batang}
+            {\setmainhangulfont{Batang}[AutoFakeBold]}
+            {\let\kormainfont\relax}%
+          }%
+        }%
+      }%
+  \fi
+  % default main hanja: nanumgothic, batang if absent
+  \ifdefined\hnjmainfont\else
+    \XKiffonthasunichar{\kormainfont}{4E00}
+      {\let\hnjmainfont\kormainfont}
+      {\XKiffontisaccessible{NanumGothic}
+        {\setmainhanjafont{NanumGothic}[Renderer=OpenType]}
+        {\XKiffontisaccessible{Batang}
+          {\setmainhanjafont{Batang}[AutoFakeBold]}
+          {\let\hnjmainfont\kormainfont}%
+        }%
+      }%
+  \fi
+  % default sans hangul: nanumgothic, dotum if absent
+  \ifdefined\korsansfont\else
+    \XKiffonthasunichar{\fontfamily\sfdefault\selectfont}{AC00}
+      {\let\korsansfont\relax}
+      {\XKiffontisaccessible{NanumGothic}
+        {\setsanshangulfont{NanumGothic}[Renderer=OpenType]}
+        {\XKiffontisaccessible{Dotum}
+          {\setsanshangulfont{Dotum}[AutoFakeBold]}
+          {\let\korsansfont\relax}%
+        }%
+      }%
+  \fi
+  % default sans hanja: nanumgothic, dotum if absent
+  \ifdefined\hnjsansfont\else
+    \XKiffonthasunichar{\korsansfont}{4E00}
+      {\let\hnjsansfont\korsansfont}
+      {\XKiffontisaccessible{NanumGothic}
+        {\setsanshanjafont{NanumGothic}[Renderer=OpenType]}
+        {\XKiffontisaccessible{Dotum}
+          {\setsanshanjafont{Dotum}[AutoFakeBold]}
+          {\let\hnjsansfont\korsansfont}%
+        }%
+      }%
+  \fi
+  \ifdefined\kormonofont\else \let\kormonofont\korsansfont \fi
+  \ifdefined\hnjmonofont\else \let\hnjmonofont\kormonofont \fi
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% reset hangul font and normalfont
+\expandafter\ifx\familydefault\rmdefault
+  \XK@rm@korean@font
+  \protected\edef\normalfont{\unexpanded\expandafter{\normalfont
+    \XK@rm@korean@font}}
+\else \expandafter\ifx\familydefault\sfdefault
+  \XK@sf@korean@font
+  \protected\edef\normalfont{\unexpanded\expandafter{\normalfont
+    \XK@sf@korean@font}}
+\else
+  \XK@tt@korean@font
+  \protected\edef\normalfont{\unexpanded\expandafter{\normalfont
+    \XK@tt@korean@font}}
+\fi\fi
+\let\reset@font\normalfont
+  %%%%%%%%%%%%%%%%%%%%%
+  % hangul in math mode
+  \begingroup
+    \ifx\xetexko@math@hangul@family\undefined
+      \edef\@tempb{\sfdefault}\edef\@tempc{\ttdefault}%
+      \ifx\f@family\@tempb \korsansfont \else
+      \ifx\f@family\@tempc \kormonofont \else
+      \kormainfont \fi\fi
+      \xdef\xetexko@math@hangul@family{\f@family}\fi
+  \endgroup
+  \DeclareSymbolFont{mathhangul}\f@encoding\xetexko@math@hangul@family
+    \mddefault\updefault
+  \ifcsname \f@encoding/\xetexko@math@hangul@family/\bfdefault/\updefault\endcsname
+    \SetSymbolFont{mathhangul}{bold}\f@encoding\xetexko@math@hangul@family
+      \bfdefault\updefault
+  \fi
+  \setmathhangulblock{AC00}{D7A3}
+}
+
+%%%%%%%%%%%%%%%%%%%%%%%
+% under [hangul] option
+\if@hangul
+  \linespread{1.3888}
+  \footnotesep=1.3888\footnotesep
+  \skip\footins=\glueexpr\skip\footins/72*100\relax
+  % frenchspacing is default
+  \frenchspacing
+\fi
+
+\endinput
-- 
cgit v1.2.3

