% xetexko-font.sty % % Copyright (c) 2013-2014 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}[2014/05/11 v2.6 Font commands for XeTeX-ko] \let\xetexko@f@size\f@size \RequirePackage{fontspec} \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 \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.06em} \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 .code:n = { \keys_set:nn { xtxko-font } { hu = {#1} } } , InterHangul .code:n = { \keys_set:nn { xtxko-font } { interhchar = {#1} } } , PunctRaise .code:n = { \keys_set:nn { xtxko-font } { lowerperiod = { \dim_eval:n {-#1} } } } , CharRaise .code:n = { \keys_set:nn { xtxko-font } { charraise = {#1} } } , } \tl_new:N \l_xtxko_rem_tl \cs_new:Nn \__xtxko_assign_font_opts:Nn { \tl_set_eq:NN \l_xtxko_font_opts_tl \l_xtxko_font_opts_init_tl \keys_set_known:nxN { xtxko-font } {#2} \l_xtxko_rem_tl \tl_set_eq:NN #1 \l_xtxko_font_opts_tl } \cs_generate_variant:Nn \__xtxko_assign_font_opts:Nn { c } %%%%%%%%%%%%%%%%%%%% % user font commands \DeclareDocumentCommand \setmainhangulfont { O{} m } { \__xtxko_assign_font_opts:Nn \XK@main@hangul@options {#1} \newfontfamily \XK@main@hangul@font [\l_xtxko_rem_tl] {#2} \tl_set:Nn \kormainfont {\XK@main@hangul@font \XK@main@hangul@options} \ignorespaces } \DeclareDocumentCommand \setsanshangulfont { O{} m } { \__xtxko_assign_font_opts:Nn \XK@sans@hangul@options {#1} \newfontfamily \XK@sans@hangul@font [\l_xtxko_rem_tl] {#2} \tl_set:Nn \korsansfont {\XK@sans@hangul@font \XK@sans@hangul@options} \ignorespaces } \DeclareDocumentCommand \setmonohangulfont { O{} m } { \newfontfamily \kormonofont [#1] {#2} \ignorespaces } \DeclareDocumentCommand \setmainhanjafont { O{} m } { \__xtxko_assign_font_opts:Nn \XK@main@hanja@options {#1} \newfontfamily \XK@main@hanja@font [\l_xtxko_rem_tl] {#2} \tl_set:Nn \hnjmainfont {\XK@main@hanja@font \XK@main@hanja@options} \ignorespaces } \DeclareDocumentCommand \setsanshanjafont { O{} m } { \__xtxko_assign_font_opts:Nn \XK@sans@hanja@options {#1} \newfontfamily \XK@sans@hanja@font [\l_xtxko_rem_tl] {#2} \tl_set:Nn \hnjsansfont {\XK@sans@hanja@font \XK@sans@hanja@options} \ignorespaces } \DeclareDocumentCommand \setmonohanjafont { O{} m } { \newfontfamily \hnjmonofont [#1] {#2} \ignorespaces } %% {hangul,hanja}fontspec = adhoc{hangul,hanja}font \DeclareDocumentCommand \adhochangulfont { O{} m } { \__xtxko_assign_font_opts:Nn \XK@adhoc@hangul@options {#1} \newfontfamily \XK@adhoc@hangul@font [\l_xtxko_rem_tl] {#2} \tl_set:Nn \XKhangulfont { \XK@storeltnfont \tl_set_eq:NN \XKcurrentfont \c_one \XK@adhoc@hangul@font \XK@adhoc@hangul@options \XK@storecjkfont } \ignorespaces } \cs_set_eq:NN \hangulfontspec \adhochangulfont \DeclareDocumentCommand \adhochanjafont { O{} m } { \__xtxko_assign_font_opts:Nn \XK@adhoc@hanja@options {#1} \newfontfamily \XK@adhoc@hanja@font [\l_xtxko_rem_tl] {#2} \tl_set:Nn \XKhanjafont { \XK@storeltnfont \tl_set_eq:NN \XKcurrentfont \c_two \XK@adhoc@hanja@font \XK@adhoc@hanja@options \XK@storecjkfont } \ignorespaces } \cs_set_eq:NN \hanjafontspec \adhochanjafont %% new{hangul,hanja}font{family,face} \DeclareDocumentCommand \newhangulfontfamily { m O{} m } { \__xtxko_assign_font_opts:cn { XK@newfont@options \token_to_str:N #1 } {#2} \exp_after:wN \newfontfamily \cs:w XK@newfont@family \token_to_str:N #1 \cs_end: [\l_xtxko_rem_tl] {#3} \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 } \use:c { XK@newfont@options \token_to_str:N #1 } \XK@storecjkfont } } } \DeclareDocumentCommand \newhanjafontfamily { m O{} m } { \__xtxko_assign_font_opts:cn { XK@newfont@options \token_to_str:N #1 } {#2} \exp_after:wN \newfontfamily \cs:w XK@newfont@family \token_to_str:N #1 \cs_end: [\l_xtxko_rem_tl] {#3} \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 } \use:c { XK@newfont@options \token_to_str:N #1 } \XK@storecjkfont } } } \DeclareDocumentCommand \newhangulfontface { m O{} m } { \__xtxko_assign_font_opts:cn { XK@newfont@options \token_to_str:N #1 } {#2} \exp_after:wN \newfontface \cs:w XK@newfont@family \token_to_str:N #1 \cs_end: [\l_xtxko_rem_tl] {#3} \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 } \use:c { XK@newfont@options \token_to_str:N #1 } \XK@storecjkfont } } } \DeclareDocumentCommand \newhanjafontface { m O{} m } { \__xtxko_assign_font_opts:cn { XK@newfont@options \token_to_str:N #1 } {#2} \exp_after:wN \newfontface \cs:w XK@newfont@family \token_to_str:N #1 \cs_end: [\l_xtxko_rem_tl] {#3} \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 } \use:c { XK@newfont@options \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:N \XK@storeltnfont \exp_not:N \tl_set_eq:NN \exp_not:N \XKcurrentfont \exp_not:N \c_one \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:N \XK@storeltnfont \exp_not:N \tl_set_eq:NN \exp_not:N \XKcurrentfont \exp_not:N \c_two \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 %% math hangul font \DeclareDocumentCommand \setmathhangulfont { O{} m } { \fontspec_set_family:Nnn \xetexko@math@hangul@family {#1} {#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 } { \use:c { #2marks } \keys_set:nn { xtxko-char } { #1 } } \ExplSyntaxOff %%%%%%%%%%%%%%%%%%%%%%%%%% % set unfonts if [unfonts] \if@unfonts %% 한글폰트 지정하기 : \setmainhangulfont [ ExternalLocation, Mapping=tex-text, BoldFont=UnBatangBold, ItalicFont=UnBatang, ItalicFeatures={FakeSlant=0.17}, SlantedFont=UnBatang, SlantedFeatures={FakeSlant=0.17}, BoldItalicFont=UnBatangBold, BoldItalicFeatures={FakeSlant=0.17}, BoldSlantedFont=UnBatangBold, BoldSlantedFeatures={FakeSlant=0.17}, interhchar=-0.045em, lowerperiod=0.1em ] {UnBatang} \setsanshangulfont [ ExternalLocation, Mapping=tex-text, BoldFont=UnDotumBold, ItalicFont=UnDotum, ItalicFeatures={FakeSlant=0.17}, SlantedFont=UnDotum, SlantedFeatures={FakeSlant=0.17}, BoldItalicFont=UnDotumBold, BoldItalicFeatures={FakeSlant=0.17}, BoldSlantedFont=UnDotumBold, BoldSlantedFeatures={FakeSlant=0.17}, lowerperiod=0.1em ] {UnDotum} \setmonohangulfont [ ExternalLocation, Scale=1.05, BoldFont=UnTaza, BoldFeatures={FakeBold=2}, ItalicFont=UnTaza, ItalicFeatures={FakeSlant=0.17}, SlantedFont=UnTaza, SlantedFeatures={FakeSlant=0.17}, BoldItalicFont=UnTaza, BoldItalicFeatures={FakeBold=2,FakeSlant=0.17}, BoldSlantedFont=UnTaza, BoldSlantedFeatures={FakeBold=2,FakeSlant=0.17}] {UnTaza} \let\hnjmonofont\korsansfont \fi %%%%%%%%%%%%%%%%%%%%%%%%%% % for lazy font setting \AtBeginDocument{% \ifdefined\kormainfont\else \let\kormainfont\relax \fi \ifdefined\korsansfont\else \let\korsansfont\kormainfont \fi \ifdefined\kormonofont\else \let\kormonofont\korsansfont \fi \ifdefined\hnjmainfont\else \let\hnjmainfont\kormainfont \fi \ifdefined\hnjsansfont\else \let\hnjsansfont\korsansfont \fi \ifdefined\hnjmonofont\else \let\hnjmonofont\kormonofont \fi } %%%%%%%%%%%%%%%%%%%%%%%%%% % 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{% \def\XKhangulfont{% \XK@storeltnfont \chardef\XKcurrentfont\@ne\kormainfont \XK@storecjkfont }% \def\XKhanjafont {% \XK@storeltnfont \chardef\XKcurrentfont\tw@\hnjmainfont \XK@storecjkfont }% } \def\XK@sf@korean@font{% \def\XKhangulfont{% \XK@storeltnfont \chardef\XKcurrentfont\@ne\korsansfont \XK@storecjkfont }% \def\XKhanjafont {% \XK@storeltnfont \chardef\XKcurrentfont\tw@\hnjsansfont \XK@storecjkfont }% } \def\XK@tt@korean@font{% \def\XKhangulfont{% \XK@storeltnfont \chardef\XKcurrentfont\@ne\kormonofont \XK@storecjkfont }% \def\XKhanjafont {% \XK@storeltnfont \chardef\XKcurrentfont\tw@\hnjmonofont \XK@storecjkfont }% } \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 }} \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 \AtBeginDocument{% \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}\zf@enc\xetexko@math@hangul@family \mddefault\updefault \ifcsname \zf@enc/\xetexko@math@hangul@family/\bfdefault/\updefault\endcsname \SetSymbolFont{mathhangul}{bold}\zf@enc\xetexko@math@hangul@family \bfdefault\updefault \fi \setmathhangulblock{AC00}{D7A3} } %%%%%%%%%%%%%%%%%%%%%%% % under [hangul] option \if@hangul \linespread{1.3888} \footnotesep=1.3888\footnotesep \skip\footins=1.3888\skip\footins plus6pt minus3pt % frenchspacing is default \frenchspacing \fi \endinput