%% File `memucs-interword.sty`
%%
%% Copyright (c) 2007-2013 Kangsoo Kim <karnes 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.
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{memucs-interword}[2007/09/22]

\def\memucsinterwordskip{}
\def\memucsinterwordchapterskip{}
\def\memucshangulskips{}

\newif\if@nonfrench\@nonfrenchfalse
\DeclareOption{nonfrench}{%
    \@nonfrenchtrue}
\DeclareOption{HWP}{%
	\def\memucsinterwordskip{\HWPinterwordskip}}
\DeclareOption{default}{%
	\@nonfrenchtrue\def\memucsinterwordskip{\DEFAULTskips}\interHchar{0pt}}
\DeclareOption{wider}{%
	\def\memucshangulskips{\widerhangul}}
\DeclareOption{narrower}{%
	\def\memucshangulskips{\narrowerhangul}}
%\DeclareOption*{%
%	\def\memucsinterwordskip{\DEFAULTskips}%
%}

%\newlength\dimen@skip
%\setlength\dimen@skip{.1pt}

%% finemath active.
\if@dhucsfinemath\else\@dhucsfinemathtrue\fi

%\let\interhchar\setInterHangulSkip
\newcommand*\interHchar[1]{\setInterHangulSkip{#1}}
\let\interhchar\interHchar

\newcommand*\interhword[4][\@empty]{%
   \ifx#1\@empty\setinterwordskip{#2}{#3}{#4}\else
	   \setinterwordskip[#1]{#2}{#3}{#4}\fi
}

\def\narrowerhangul{%
	\def\memucshangulskips{%
		\interHchar{-.5pt}% 
	}%
}
\def\widerhangul{%
	\def\memucshangulskips{%
		\interHchar{1pt}% 
	}%
}

\newdimen\BASE@FONTsize
\BASE@FONTsize=\f@size\p@

\def\HWPinterwordskip{%
  \def\memucshangulskips{%
    \interHchar{0pt}%
  }%
	\def\memucsinterwordskip{%
		\spaceskip = .475\BASE@FONTsize plus .25\BASE@FONTsize minus .1331\BASE@FONTsize
		\if@nonfrench
		\xspaceskip = .6\BASE@FONTsize plus .2\BASE@FONTsize minus .1\BASE@FONTsize
		\fi
	}%
	\def\memucsinterwordchapterskip{%
		\spaceskip = .5\BASE@FONTsize plus .1\BASE@FONTsize minus .05\BASE@FONTsize
		\if@nonfrench
		\xspaceskip = .65\BASE@FONTsize plus .2\BASE@FONTsize minus .1\BASE@FONTsize
		\fi
	}%
}

\def\setinterwordskip{\@ifnextchar[\setinterwordskip@\setinterwordskip@@}
\def\setinterwordskip@[#1]#2#3#4{%
	\def\memucsinterwordskip{%
		\spaceskip = #2\BASE@FONTsize plus #3\BASE@FONTsize minus #4\BASE@FONTsize
		\if@nonfrench
		\xspaceskip = #1\BASE@FONTsize plus #3\BASE@FONTsize minus #4\BASE@FONTsize
		\fi
	}%
}

\def\setinterwordskip@@#1#2#3{%
	\def\memucsinterwordskip{%
		\spaceskip = #1\BASE@FONTsize plus #2\BASE@FONTsize minus #3\BASE@FONTsize
		\if@nonfrench
		\xspaceskip = .6\BASE@FONTsize plus #2\BASE@FONTsize minus #3\BASE@FONTsize
		\fi
	}%
}

\def\DEFAULTskips{%
	\def\memucshangulskips{%
%		\interHchar{0pt}% 
	}%
	\def\memucsinterwordskip{%
		\spaceskip = .413\BASE@FONTsize plus .1\BASE@FONTsize minus .1\BASE@FONTsize
		\if@nonfrench
		\xspaceskip = .55\BASE@FONTsize plus .11\BASE@FONTsize minus .1\BASE@FONTsize
		\fi
	}%
	\def\memucsinterwordchapterskip{%
		\spaceskip = .46\BASE@FONTsize plus .11\BASE@FONTsize minus .1\BASE@FONTsize
		\if@nonfrench
		\xspaceskip = .575\BASE@FONTsize plus .1\BASE@FONTsize minus .1\BASE@FONTsize
		\fi
	}%
}

\ProcessOptions\relax

\def\verbatim@font{\m@mverbfont\spaceskip\z@
                   \hyphenchar\font\m@ne
                   \let\do\do@noligs
                   \verbatim@nolig@list} 

\def\narrowerinterhword{%
	\spaceskip=.331\BASE@FONTsize plus .111\BASE@FONTsize minus .1\BASE@FONTsize
	\if@nonfrench
	\xspaceskip=.466\BASE@FONTsize plus .05\BASE@FONTsize minus .05\BASE@FONTsize
	\fi
} 
 
\def\memucsinterwordhook{\memucsinterwordskip\memucshangulskips}%
\def\memucsinterwordchapterskiphook{\memucsinterwordchapterskip\memucshangulskips}%
\def\memucsfninterwordhook{\narrowerinterhword}%

% engtext env
\@ifundefined{engtext}%
 {%
   \newenvironment{engtext}%
     {\begingroup\spaceskip=\fontdimen2\font plus\fontdimen3\font minus\fontdimen4\font}%
     {\endgroup}%
 }{}

% engtxt
\newskip\ORIG@spaceskip
\def\engtxt{\ORIG@spaceskip=\spaceskip
  \spaceskip=\fontdimen2\font plus\fontdimen3\font minus\fontdimen4\font}
\def\endengtxt{\spaceskip=\ORIG@spaceskip}

\endinput

%% CHANGE LOG
% 2005/01/07. code clearance 
% 2005/02/08. reset interwordchapterskip values
% 2005/05/17. engtext env. added.
% 2005/07/30. replace em by \BASE@FONTsize
% 2005/08/05. nonfrench option introduced.
% 2005/11/17. \interhword bug fixed.
% 2007/06/03. dhucs 4.0 hfontspec applied
