% xetexko-font.sty % % Copyright (c) 2013 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/02/02 v2.4 Font commands for XeTeX-ko] \RequirePackage{fontspec} \RequirePackage{xkeyval} %%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% for old hangul rendering \ExplSyntaxOn \fontspec_define_font_feature:n {YetHangul} \keys_define:nn {fontspec} { YetHangul .default:n = {On} , YetHangul / On .code:n = { \fontspec_update_fontid:n {yethangul:on} \fontspec_update_featstr:n {script=hang} } , YetHangul / Off .code:n = { \fontspec_update_fontid:n {yethangul:off} \fontspec_update_featstr:n {-ljmo;-vjmo;-tjmo} } } \ExplSyntaxOff %%%%%%%%%%%%%%%%%%%%% % hangul font options \newtoks\XK@font@options\XK@font@options{} \define@key[xtxko]{font}{hu}{\addto@hook\XK@font@options{\def\xetexkohu{#1}}} \define@key[xtxko]{font}{interhchar}{\addto@hook\XK@font@options{\def\xetexkointerhchar{#1}}} \define@key[xtxko]{font}{lowerexclamation}{\addto@hook\XK@font@options{\def\xetexkolowerexclamation{#1}}} \define@key[xtxko]{font}{lowerperiod}{\addto@hook\XK@font@options{\def\xetexkolowerperiod{#1}}} \define@key[xtxko]{font}{lowerquestion}{\addto@hook\XK@font@options{\def\xetexkolowerquestion{#1}}} \define@key[xtxko]{font}{lowercomma}{\addto@hook\XK@font@options{\def\xetexkolowercomma{#1}}} \define@key[xtxko]{font}{postexclamationkern}{\addto@hook\XK@font@options{\def\xetexkopostexclamationkern{#1}}} \define@key[xtxko]{font}{postmathskip}{\addto@hook\XK@font@options{\def\xetexkopostmathskip{#1}}} \define@key[xtxko]{font}{postperiodkern}{\addto@hook\XK@font@options{\def\xetexkopostperiodkern{#1}}} \define@key[xtxko]{font}{postquestionkern}{\addto@hook\XK@font@options{\def\xetexkopostquestionkern{#1}}} \define@key[xtxko]{font}{postcommakern}{\addto@hook\XK@font@options{\def\xetexkopostcommakern{#1}}} \define@key[xtxko]{font}{preexclamationkern}{\addto@hook\XK@font@options{\def\xetexkopreexclamationkern{#1}}} \define@key[xtxko]{font}{preperiodkern}{\addto@hook\XK@font@options{\def\xetexkopreperiodkern{#1}}} \define@key[xtxko]{font}{prequestionkern}{\addto@hook\XK@font@options{\def\xetexkoprequestionkern{#1}}} \define@key[xtxko]{font}{precommakern}{\addto@hook\XK@font@options{\def\xetexkoprecommakern{#1}}} \define@key[xtxko]{font}{quoteraise}{\addto@hook\XK@font@options{\def\xetexkoquoteraise{#1}}} \define@key[xtxko]{font}{quotewidth}{\addto@hook\XK@font@options{\def\xetexkoquotewidth{#1}}} \define@key[xtxko]{font}{charraise}{\addto@hook\XK@font@options{\def\xetexkocharraise{#1}}} \presetkeys[xtxko]{font}{ hu=0.06em, interhchar={}, lowerexclamation={}, lowerperiod={}, lowercomma={}, lowerquestion={}, postexclamationkern={}, postmathskip=\dimexpr\xetexkohu*\tw@\relax, postperiodkern={}, postcommakern={}, postquestionkern={}, preexclamationkern={}, preperiodkern={}, precommakern={}, prequestionkern={}, quoteraise={}, quotewidth={}, charraise={} }{} %%%%%%%%%%%%%%%%%%%% % user font commands \protected\def\setmainhangulfont {\@ifnextchar[\@setmainhangulfont{\@setmainhangulfont[]}} \def\@setmainhangulfont[#1]{% \def\kormainfont{\XK@main@hangul@font\XK@main@hangul@options}% \XK@font@options{}% \setkeys*[xtxko]{font}{#1}% \edef\XK@main@hangul@options{\the\XK@font@options}% \expandafter\newfontfamily\expandafter\XK@main@hangul@font\expandafter[\XKV@rm]} \protected\def\setsanshangulfont {\@ifnextchar[\@setsanshangulfont{\@setsanshangulfont[]}} \def\@setsanshangulfont[#1]{% \def\korsansfont{\XK@sans@hangul@font\XK@sans@hangul@options}% \XK@font@options{}% \setkeys*[xtxko]{font}{#1}% \edef\XK@sans@hangul@options{\the\XK@font@options}% \expandafter\newfontfamily\expandafter\XK@sans@hangul@font\expandafter[\XKV@rm]} \protected\def\setmonohangulfont{\newfontfamily\kormonofont} \protected\def\setmainhanjafont {\@ifnextchar[\@setmainhanjafont{\@setmainhanjafont[]}} \def\@setmainhanjafont[#1]{% \def\hnjmainfont{\XK@main@hanja@font\XK@main@hanja@options}% \XK@font@options{}% \setkeys*[xtxko]{font}{#1}% \edef\XK@main@hanja@options{\the\XK@font@options}% \expandafter\newfontfamily\expandafter\XK@main@hanja@font\expandafter[\XKV@rm]} \protected\def\setsanshanjafont {\@ifnextchar[\@setsanshanjafont{\@setsanshanjafont[]}} \def\@setsanshanjafont[#1]{% \def\hnjsansfont{\XK@sans@hanja@font\XK@sans@hanja@options}% \XK@font@options{}% \setkeys*[xtxko]{font}{#1}% \edef\XK@sans@hanja@options{\the\XK@font@options}% \expandafter\newfontfamily\expandafter\XK@sans@hanja@font\expandafter[\XKV@rm]} \protected\def\setmonohanjafont {\newfontfamily\hnjmonofont} % adhochangulfont/adhochanjafont, hangulfontspec/hanjafontspec \protected\def\adhochangulfont{\@ifnextchar[\@adhochangulfont{\@adhochangulfont[]}} \def\@adhochangulfont[#1]{% \def\XKhangulfont{% \XK@storeltnfont\chardef\XKcurrentfont\@ne \XK@adhoc@hangul@font\XK@adhoc@hangul@options \XK@storecjkfont }% \XK@font@options{}% \setkeys*[xtxko]{font}{#1}% \edef\XK@adhoc@hangul@options{\the\XK@font@options}% \expandafter\newfontfamily\expandafter\XK@adhoc@hangul@font\expandafter[\XKV@rm]} \let\hangulfontspec\adhochangulfont \protected\def\adhochanjafont{\@ifnextchar[\@adhochanjafont{\@adhochanjafont[]}} \def\@adhochanjafont[#1]{% \def\XKhanjafont{% \XK@storeltnfont\chardef\XKcurrentfont\tw@ \XK@adhoc@hanja@font\XK@adhoc@hanja@options \XK@storecjkfont }% \XK@font@options{}% \setkeys*[xtxko]{font}{#1}% \edef\XK@adhoc@hanja@options{\the\XK@font@options}% \expandafter\newfontfamily\expandafter\XK@adhoc@hanja@font\expandafter[\XKV@rm]} \let\hanjafontspec\adhochanjafont % newhangulfontfamily/newhanjafontfamily \def\XK@newfont@family{XK@newfont@family} \def\XK@newfont@options{XK@newfont@options} \protected\def\newhangulfontfamily#1{% \@ifnextchar[{\@newhangulfontfamily#1}{\@newhangulfontfamily#1[]}} \def\@newhangulfontfamily#1[#2]{% \protected\def#1{\def\XKhangulfont{% \XK@storeltnfont\chardef\XKcurrentfont\@ne \csname\XK@newfont@family \string#1\endcsname \csname\XK@newfont@options\string#1\endcsname \XK@storecjkfont }}% \XK@font@options{}% \setkeys*[xtxko]{font}{#2}% \expandafter\edef\csname\XK@newfont@options\string#1\endcsname {\the\XK@font@options}% \expandafter\expandafter\expandafter\newfontfamily\expandafter \csname\expandafter\XK@newfont@family\expandafter \string\expandafter#1\expandafter\endcsname\expandafter[\XKV@rm]} \protected\def\newhanjafontfamily#1{% \@ifnextchar[{\@newhanjafontfamily#1}{\@newhanjafontfamily#1[]}} \def\@newhanjafontfamily#1[#2]{% \protected\def#1{\def\XKhanjafont{% \XK@storeltnfont\chardef\XKcurrentfont\tw@ \csname\XK@newfont@family\string#1\endcsname \csname\XK@newfont@options\string#1\endcsname \XK@storecjkfont }}% \XK@font@options{}% \setkeys*[xtxko]{font}{#2}% \expandafter\edef\csname\XK@newfont@options\string#1\endcsname {\the\XK@font@options}% \expandafter\expandafter\expandafter\newfontfamily\expandafter \csname\expandafter\XK@newfont@family\expandafter \string\expandafter#1\expandafter\endcsname\expandafter[\XKV@rm]} % newhangulfontface/newhanjafontface \protected\def\newhangulfontface#1{% \@ifnextchar[{\@newhangulfontface#1}{\@newhangulfontface#1[]}} \def\@newhangulfontface#1[#2]{% \protected\def#1{\def\XKhangulfont{% \XK@storeltnfont\chardef\XKcurrentfont\@ne \csname\XK@newfont@family\string#1\endcsname \csname\XK@newfont@options\string#1\endcsname \XK@storecjkfont }}% \XK@font@options{}% \setkeys*[xtxko]{font}{#2}% \expandafter\edef\csname\XK@newfont@options\string#1\endcsname {\the\XK@font@options}% \expandafter\expandafter\expandafter\newfontface\expandafter \csname\expandafter\XK@newfont@family\expandafter \string\expandafter#1\expandafter\endcsname\expandafter[\XKV@rm]} \protected\def\newhanjafontface#1{% \@ifnextchar[{\@newhanjafontface#1}{\@newhanjafontface#1[]}} \def\@newhanjafontface#1[#2]{% \protected\def#1{\def\XKhanjafont{% \XK@storeltnfont \chardef\XKcurrentfont\tw@ \csname\XK@newfont@family\string#1\endcsname \csname\XK@newfont@options\string#1\endcsname \XK@storecjkfont }}% \XK@font@options{}% \setkeys*[xtxko]{font}{#2}% \expandafter\edef\csname\XK@newfont@options\string#1\endcsname {\the\XK@font@options}% \expandafter\expandafter\expandafter\newfontface\expandafter \csname\expandafter\XK@newfont@family\expandafter \string\expandafter#1\expandafter\endcsname\expandafter[\XKV@rm]} % addhangulfontfeature/addhanjafontfeature \protected\def\addhangulfontfeature#1{% \begingroup \XKhangulfont \unpresetkeys[xtxko]{font}% \XK@font@options{}% \setkeys*[xtxko]{font}{#1}% \global\toks@\expandafter{\the\XK@font@options}% \addfontfeature{\XKV@rm}% \global\let\XK@curr@family\f@family \endgroup \edef\XKhangulfont{\unexpanded\expandafter{\XKhangulfont\fontfamily}{\XK@curr@family}% \noexpand\selectfont\the\toks@}% } \let\addhangulfontfeatures\addhangulfontfeature \protected\def\addhanjafontfeature#1{% \begingroup \XKhanjafont \unpresetkeys[xtxko]{font}% \XK@font@options{}% \setkeys*[xtxko]{font}{#1}% \global\toks@\expandafter{\the\XK@font@options}% \addfontfeature{\XKV@rm}% \global\let\XK@curr@family\f@family \endgroup \edef\XKhanjafont{\unexpanded\expandafter{\XKhanjafont\fontfamily}{\XK@curr@family}% \noexpand\selectfont\the\toks@}% } \let\addhanjafontfeatures\addhanjafontfeature %%%%%%%%%%%%%%%%%%%% %% xetexkofontregime \define@key[xtxko]{char}{alphs}{\csname #1alphs\endcsname} \define@key[xtxko]{char}{nums}{\csname #1nums\endcsname} \define@key[xtxko]{char}{parens}{\csname #1parens\endcsname} \define@key[xtxko]{char}{quotes}{\csname #1quotes\endcsname} \define@key[xtxko]{char}{puncts}{\csname #1puncts\endcsname} \define@key[xtxko]{char}{colons}{\csname #1colons\endcsname} \define@key[xtxko]{char}{hyphens}{\csname #1hyphens\endcsname} \define@key[xtxko]{char}{cjksymbols}{\csname #1cjksymbols\endcsname} \protected\def\xetexkofontregime{% \@ifnextchar[\@xetexkofontregime{\@xetexkofontregime[]}} \def\@xetexkofontregime[#1]#2{% \csname #2marks\endcsname \setkeys*[xtxko]{char}{#1}} %%%%%%%%%%%%%%%%%%%%%%%%%% % 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 }} \AtBeginDocument{ \ifx\f@family\rmdefault \XK@rm@korean@font \protected\edef\normalfont{\unexpanded\expandafter{\normalfont\XK@rm@korean@font}} \else \ifx\f@family\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 \def\setmathhangulfont{% \@ifnextchar[{\setmathhangulfont@}{\setmathhangulfont@[]}} \def\setmathhangulfont@[#1]#2{% \zf@fontspec{#1}{#2}% \xdef\xetexko@math@hangul@family{\zf@family}} \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