% xetexko-font.sty % % Copyright (c) 2013-2018 Dohyun Kim % % 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/04/06 v2.18 LaTeX Font commands for XeTeX-ko] \let\xetexko@f@size\f@size \RequirePackage{fontspec}[2014/05/25] \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} \newfontfamily \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} \newfontfamily \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{} } { \newfontfamily \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} \newfontfamily \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} \newfontfamily \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{} } { \newfontfamily \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} \newfontfamily \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} \newfontfamily \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 \newfontfamily { 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 \newfontfamily { 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 2017 \RenewDocumentCommand \setmainfont { O{} m O{} } { \fontspec_set_family:Nnn \g__fontspec_rmfamily_family {#1,#3} {#2} \tl_set_eq:NN \rmdefault \g__fontspec_rmfamily_family \use:x { \exp_not:n { \DeclareRobustCommand \rmfamily } { \exp_not:N \fontencoding { \l__fontspec_nfss_enc_tl } \exp_not:N \fontfamily { \g__fontspec_rmfamily_family } \exp_not:N \selectfont \exp_not:N \XK@rm@korean@font } } \str_if_eq_x:nnT {\familydefault} {\rmdefault} { \tl_set_eq:NN \encodingdefault \l__fontspec_nfss_enc_tl } \normalfont \ignorespaces } \RenewDocumentCommand \setsansfont { O{} m O{} } { \fontspec_set_family:Nnn \g__fontspec_sffamily_family {#1,#3} {#2} \tl_set_eq:NN \sfdefault \g__fontspec_sffamily_family \use:x { \exp_not:n { \DeclareRobustCommand \sffamily } { \exp_not:N \fontencoding { \l__fontspec_nfss_enc_tl } \exp_not:N \fontfamily { \g__fontspec_sffamily_family } \exp_not:N \selectfont \exp_not:N \XK@sf@korean@font } } \str_if_eq_x:nnT {\familydefault} {\sfdefault} { \tl_set_eq:NN \encodingdefault \l__fontspec_nfss_enc_tl } \normalfont \ignorespaces } \RenewDocumentCommand \setmonofont { O{} m O{} } { \fontspec_set_family:Nnn \g__fontspec_ttfamily_family {#1,#3} {#2} \tl_set_eq:NN \ttdefault \g__fontspec_ttfamily_family \use:x { \exp_not:n { \DeclareRobustCommand \ttfamily } { \exp_not:N \fontencoding { \l__fontspec_nfss_enc_tl } \exp_not:N \fontfamily { \g__fontspec_ttfamily_family } \exp_not:N \selectfont \exp_not:N \XK@tt@korean@font \exp_not:N \disablehangulspacing } } \str_if_eq_x:nnT {\familydefault} {\ttdefault} { \tl_set_eq:NN \encodingdefault \l__fontspec_nfss_enc_tl } \normalfont \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 } \edef\rmfamily{\unexpanded\expandafter{\rmfamily\XK@rm@korean@font}} \edef\sffamily{\unexpanded\expandafter{\sffamily\XK@sf@korean@font}} \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