%% File `memucs-setspace.sty`
%%
%% Copyright (c) 2007-2021 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.
%%
%% =======================
%%
%% 이 스타일은 setspace 6.7을 바탕으로, memoir의
%% 출력루틴을 hooking하여 거의 동일하게 동작하도록
%% 수정한 스타일이다.
%% memoir 클래스에서 memhangul 스타일을 사용했을 때
%% 불린다. 다른 용도로는 사용할 수 없음.
%%
%% This style is a modified version of SETSTYLE ver 6.7 by Erica M. S. Harris
%% modified by Karnes Kim
%%
%% FEATURES:
%%    all the features of setstyle package
%%
%%	  NEW FEATURES:
%%
%%		1. [nofloatspacing] option
%%			disables the feature of SETSTYLE, turning off all the line spacing
%%			in the floats(figures, tables) and footnotes.
%%      \noadjustfloatfnspacing, \adjustfloatfnspacing
%%		2. [hangul] option
%%			When [hangul] option is on, the basic line spreading is set to
%%			a proper line spacing in Korean(Hangul) documents, which has
%%			a wider gap between the lines.
%%      \SetHangulspace
%%		3. quote and quotation environment
%%			quote and quotation environment have the same line spacing 
%%			with the floats and footnotes, verse.
%%      \noadjustquotespacing, \adjustquotespacing
%%		4. [adjustfootnotesep] option
%%			this option is meaningful only when [hangul] is on and 
%%			[nofloatspacing] off.
%%		5. [adjustverbatim] option.
%%			verbatim environment.
%%      \SetHangulVerbatimSpace.
%%    6. \ResetHangulspace, \RestoreHangulspace
%%

\NeedsTeXFormat {LaTeX2e}[1994/12/09]
\def \filename {memucs-setspace.sty}
\def \filedate {2021/03/03}
\def \fileversion {6.7-mu9}
\ProvidesPackage {memucs-setspace}[\filedate\space\fileversion\space
  Contributed and Supported LaTeX2e package]
\typeout {Package: `memucs-setspace', a modified version of `setspace', \fileversion\space <\filedate>}

% BP: add nodisplayskipstretch option and \setdisplayskipstretch command.

\providecommand{\displayskipstretch}{\baselinestretch}
\providecommand{\setdisplayskipstretch}[1]{\renewcommand{\displayskipstretch}{#1}}
\DeclareOption{nodisplayskipstretch}{\setdisplayskipstretch{1.0}}

% GT: add George Pearsons' suggested options.

%% Karnes' 
\newif\if@singlespacefn
\DeclareOption{nofloatspacing}{\@singlespacefnfalse}
\newif\if@singlespacequote
\DeclareOption{quotespacing}{\@singlespacequotetrue}
\newif\if@hangul
\DeclareOption{hangul}{\@hangultrue\AtEndOfPackage{\hangulspacing}}
\newif\if@adjustfootnotesep
\DeclareOption{adjustfootnotesep}{\@adjustfootnoteseptrue}
\newif\if@adjustverbatim
\DeclareOption{adjustverbatim}{\@adjustverbatimtrue}

\DeclareOption{singlespacing}{\AtEndOfPackage{\singlespacing}}
\DeclareOption{onehalfspacing}{\AtEndOfPackage{\onehalfspacing}}
\DeclareOption{doublespacing}{\AtEndOfPackage{\doublespacing}}

\@singlespacefntrue
\@singlespacequotefalse
\@hangulfalse
\@adjustfootnotesepfalse
\@adjustverbatimfalse
\ProcessOptions

%%% provide memucsfninterwordhook
\ifx\undefined\memucsfninterwordhook
  \providecommand\memucsfninterwordhook{}%
\fi

\def\@floatfnspacinghook{%
	\if@singlespacefn
		\hangulfspacing
	\else
		\hangulspacing
	\fi
}

\providecommand\noadjustquotespacing{%
	\@singlespacequotefalse
}

\providecommand\adjustquotespacing{%
	\@singlespacequotetrue
}

\providecommand\adjustfloatfnspacing{%
	\@singlespacefntrue
}

\providecommand\noadjustfloatfnspacing{%
	\@singlespacefnfalse
}

% GT:  Sat 28 Sep 1996:  Widely using \providecommand, \renewcommand, and
% \provideenvironment, instead of \def.

% ** Line space commands.

\providecommand{\setstretch}[1]{%
  \def\baselinestretch{#1}%
  \@currsize
}

% GT:  Sat 28 Sep 1996:  spacing commands and environments modified to
% use \setstretch instead of \baselinestretch.
%
% GT:  Sat 28 Sep 1996:  No, I don't know understand the line spacing
% algorithms!  If someone (LaTeX team) can enlighten me as to the
% general rule, please do!  It would be very pleasant if setspace.sty
% were suited for document font sizes other than 10, 11 and 12 pt.
%
% GT:  Tue 10 Dec 1996:  Instead of fixing singlespacing to exact unity,
% allow user to redefine it (only slightly, please!) from its initial
% value of unity, in the case when a particular font is slightly larger
% or slightly smaller than its point size would indicate.  This change
% affects setspace's single spacing commands, and LaTeX's footnote and
% float environments.  The one and a half, double, and arbitrary
% spacing commands are unaltered.

\providecommand{\SetSinglespace}[1]{%
  \def\setspace@singlespace{#1}%
}

%% Karnes.
\providecommand{\Set@Hangulspace}[2]{%
	\def\setspace@hangulspace{#1}%
	\def\setspace@hangulfspace{#2}%
	\setstretch{#1}%
}

\def\SetHangulspace#1#2{%
	\AtBeginDocument{%
		\gdef\setspace@hangulspace{#1}%
		\gdef\setspace@hangulfspace{#2}%
	}%
	\setstretch{#1}%
}

\providecommand{\SetHangulVerbatimSpace}[1]{%
	\def\setspace@hangulverbspace{#1}%
}

\let\tmp@current@hangulspace\setspace@hangulspace
\let\tmp@current@hangulfspace\setspace@hangulfspace

\providecommand{\ResetHangulspace}[2]{%
	\let\tmp@current@hangulspace\setspace@hangulspace%
	\let\tmp@current@hangulfspace\setspace@hangulfspace%
	\Set@Hangulspace{#1}{#2}%
}

\providecommand{\RestoreHangulspace}{%
	\Set@Hangulspace{\tmp@current@hangulspace}{\tmp@current@hangulfspace}%
}

% Here's the default single line spacing value.
\SetSinglespace{1}

%% Karnes.
\if@hangul
\Set@Hangulspace{1.333}{1.1}
\else
\Set@Hangulspace{1.0}{1.0}
\fi

\providecommand{\singlespacing}{%
  \setstretch {\setspace@singlespace}%  normally 1
  \vskip \baselineskip  % Correction for coming into singlespace
}

%% Karnes.
\providecommand{\hangulspacing}{%
	\setstretch{\setspace@hangulspace}% default
}

\providecommand{\hangulfspacing}{%
	\setstretch{\setspace@hangulfspace}%
}

\providecommand{\hangulverbspacing}{%
	\setstretch{\setspace@hangulverbspace}%
}

\providecommand{\onehalfspacing}{%
  \setstretch{1.25}%  default
  \ifcase \@ptsize \relax % 10pt
    \setstretch {1.25}%
  \or % 11pt
    \setstretch {1.213}%
  \or % 12pt
    \setstretch {1.241}%
  \fi
}

\providecommand{\doublespacing}{%
  \setstretch {1.667}%  default
  \ifcase \@ptsize \relax % 10pt
    \setstretch {1.667}%
  \or % 11pt
    \setstretch {1.618}%
  \or % 12pt
    \setstretch {1.655}%
  \fi
}

%% adjust verbatim
%% if and only if [nofloatspacing] and [adjustverbatim] is on,
%% the verbatim will be the same to the main text linestretch.
%% if [hangul] it will adjust the linestretch to the quote or quotation
%% the other case, it will be 1.0, I hope.
%%
\if@adjustverbatim
\SetHangulVerbatimSpace{\setspace@hangulfspace}%
\else
\SetHangulVerbatimSpace{1.0}
\fi

% ** Modification of the LaTeX command \@setsize.

%---Stretch the baseline BEFORE calculating the strut size. This improves
%   spacing below tabular environments etc., probably...
%   Comments are welcomed.

% GT:  Sun 29 Sep 1996:  Question:  Is this code anywhere near correct
% since this part of LaTeX (in, eg, latex.ltx) has been greatly changed?

% GT:  Sun 29 Sep 1996:  The meanings of the arguments to \@setsize
% appear to be (whatever these may signify) :
% current size; font baselineskip; ignored (!); and font size.

% GT:  Sun 29 Sep 1996:  Note that \@setsize (in latest LaTeX,
% \@setfontsize, which is called by \@setsize) seems to be the only
% place in purely modern LaTeX where \@currsize is set, and ltxguide.cls
% seems to be the only file in the LaTeX base distribution that uses it!

\def\@setsize#1#2#3#4{%
  % Modified 1993.04.07--GDG per KPC
  \@nomath#1%
  \let\@currsize#1%
  \baselineskip #2%
  \baselineskip \baselinestretch\baselineskip
  \parskip \baselinestretch\parskip
  \setbox\strutbox \hbox{%
    \vrule height.7\baselineskip
           depth.3\baselineskip
           width\z@}%
  \skip\footins \baselinestretch\skip\footins
  \normalbaselineskip\baselineskip#3#4}

% ** Float and footnote adjustments to compensate for a change in the
% ** main text's line spacing.

%---Increase the space between last line of text and footnote rule.
%\skip\footins 20pt plus4pt minus4pt

%---Reset baselinestretch within floats and footnotes.

% GT:  Tue 23 Jan 1996:  This is where the conflict with the combination
% of the color package and the figure environment used to occur.

% Floats.

% GT:  Sat 28 Sep 1996:  \@xfloat is the only place where \normalsize
% is still used in setspace.sty !

\if@singlespacefn
\let\latex@xfloat=\@xfloat
\def\@xfloat #1[#2]{%
  \latex@xfloat #1[#2]%
  \if@singlespacefn
  	\def\baselinestretch {\setspace@hangulfspace}
  \else
  	\def\baselinestretch {\setspace@hangulspace}
  \fi
  \normalsize
}
\else\fi

% Karnes: footnotesep for hangul
\if@adjustfootnotesep
\if@hangul
\if@singlespacefn
	\ifcase \@ptsize \relax
		\setlength\footnotesep{8.51 pt}% 10pt
	\or
		\setlength\footnotesep{9.6 pt}% 11pt
	\or
		\setlength\footnotesep{10.3 pt}% 12pt
	\fi
\else
\fi
\else\fi
\else\fi

% GT:  Wed 24 Jan 1996:  This footnote code was copied from LaTeX and
% modified rather naively.  It had to be brought up to date, not only
% because of LaTeX's new color ability, but also because ther had
% been major changes to this code in LaTeX at least as far back as
% March 1992.

% Normal, bottom of the page, footnotes.
%
% GT:  Based HEAVILY on original LaTeX (2e) code.  A standard hook would
% be MUCH preferred, so that LaTeX's footnote implementation needn't be
% copied each time it changes.
%
% GT:  The \protected@edef requires at least the December 1994 LaTeX.
% This is precisely the kind of VERSION DEPENDENCY situation that
% cannot (AFAIK) be avoided, because LaTeX (2e) LACKS appropriate
% standard hooks and/or context markers.
\if@singlespacefn
%%%%\def\m@mold@footnotetext{\@memsetspace@footnotetext}
%%%%\renewcommand{\@footnotetext}[1]{\m@mold@footnotetext{#1}\m@mmf@prepare} 
%%%%\long\def\@memsetspace@footnotetext#1{%
%%%%  \insert\footins{%
%%%%% GT:  Next line added.  Hook desired here!
%%%%	\@floatfnspacinghook\memucsfninterwordhook
%%%%%    \def\baselinestretch {\setspace@hangulfspace}%
%%%%%	\@SetFloatspaces
%%%%    \reset@font\footnotesize
%%%%    \interlinepenalty\interfootnotelinepenalty
%%%%    \splittopskip\footnotesep
%%%%    \splitmaxdepth \dp\strutbox \floatingpenalty \@MM
%%%%    \hsize\columnwidth
%%%%    \@parboxrestore
%%%%    \protected@edef\@currentlabel{%
%%%%      \csname p@footnote\endcsname\@thefnmark
%%%%    }%
%%%%    \color@begingroup
%%%%      \@makefntext{%
%%%%        \rule\z@\footnotesep\ignorespaces#1\@finalstrut\strutbox}%
%%%%    \color@endgroup}}
%%%%
%%%%% Minipage footnotes.
%%%%\renewcommand{\@mpfootnotetext}[1]{%
%%%%  \global\setbox\@mpfootins\vbox{%
%%%%    \unvbox\@mpfootins
%%%%%  GT:  Next line added.  Hook desired here!
%%%%	\@floatfnspacinghook\memucsfninterwordhook
%%%%%    \def\baselinestretch {\setspace@hangulfspace}%
%%%%    \foottextfont \hsize\columnwidth \@parboxrestore
%%%%    \protected@edef\@currentlabel{\csname p@mpfootnote\endcsname\@thefnmark}%
%%%%  \color@begingroup
%%%%    \@makefntext{%
%%%%      \rule\z@\footnotesep\ignorespaces#1\@finalstrut\strutbox}%
%%%%  \color@endgroup}}

\renewcommand{\@footnotetext}[1]{%
  \ifm@mfnmargin%   use marginpar
    \marginpar{%
%    \def\baselinestretch{\m@m@footnote@spacing}%
        \@floatfnspacinghook\memucsfninterwordhook
    \reset@font
    \foottextfont
    \protected@edef\@currentlabel{%
      \csname p@footnote\endcsname\@thefnmark}%
    \color@begingroup
      \@makefntext{\ignorespaces#1}%
    \color@endgroup}%
  \else% regular feet
    \insert\footins{%
 %   \def\baselinestretch{\m@m@footnote@spacing}%
         \@floatfnspacinghook\memucsfninterwordhook
    \reset@font
    \foottextfont
    \@preamfntext
    \hsize\columnwidth
    \protected@edef\@currentlabel{%
      \csname p@footnote\endcsname\@thefnmark}%
    \color@begingroup
      \@makefntext{%
        \rule\z@\footnotesep\ignorespaces{\foottextfont #1}%
        \@finalstrut\strutbox}%
    \color@endgroup}%
  \fi%
  \m@mmf@prepare}

\renewcommand{\@mpfootnotetext}[1]{%
  \global\setbox\@mpfootins\vbox{%
    \unvbox\@mpfootins
%    \def\baselinestretch{\m@m@footnote@spacing}%
         \@floatfnspacinghook\memucsfninterwordhook
    \foottextfont \hsize\columnwidth \@parboxrestore
    \protected@edef\@currentlabel{%
      \csname p@mpfootnote\endcsname\@thefnmark}%
  \color@begingroup
  \reset@font%
    \@makefntext{%
      \rule\z@\footnotesep\ignorespaces{\foottextfont #1}%
      \@finalstrut\strutbox}%
  \color@endgroup}}

\renewcommand{\@sidefootnotetext}[1]{\insert\sidefootins{%
  \hsize\sidefootwidth
  \@parboxrestore
%    \def\baselinestretch{\m@m@footnote@spacing}%
         \@floatfnspacinghook\memucsfninterwordhook
  \sidefootform \normalsize\normalfont\sidefoottextfont
  \splittopskip=\ht\strutbox
  \splitmaxdepth=\dp\strutbox
  \allowbreak
  \prevdepth=\dp\strutbox
  \vskip-\parskip
  \protected@edef\@currentlabel{%
    \csname p@sidefootnote\endcsname\@thesidefnmark}%
\color@begingroup
\@makesidefntext{{\sidefoottextfont #1}}%
\color@endgroup
  \ifvmode\else
    \unskip\@finalstrut\strutbox
  \fi
  \par
  \ifdim\prevdepth>\dp\strutbox \prevdepth=\dp\strutbox\fi
  \ifdim\prevdepth>99\p@
    \nobreak
    \vskip-\prevdepth
    \allowbreak
    \vskip\dp\strutbox
  \fi
  \vskip\sidefootvsep}%
  \m@mmf@prepare}

\else\fi

% ** Line space environments.

% A single spaced quote (say) is done by surrounding singlespace with quote.

\provideenvironment{singlespace}{%
  \vskip \baselineskip
  \setstretch {\setspace@singlespace}%
  \vskip -\baselineskip
}{%
  \par
}

% GT (c/o Mark Olesen), Wed 15 April 1998.

\provideenvironment{singlespace*}{%
  \setstretch {\setspace@singlespace}%
  \vskip -\baselineskip
}{%
  \vskip -0.5\baselineskip
}

%  spacing, doublespace and onehalfspace all are meant to INCREASE the
%  spacing (i.e. calling onehalfspace from within doublespace will not
%  produce a graceful transition between spacings)
%
% Next two definitions fixed for consistency with TeX 3.x

% In order to use \provideenvironment, while easily using same code for
% end of each environment, the code that used to be in \endspacing has
% been moved into a new (but internal) macro, \restore@spacing.

\providecommand{\restore@spacing}{%
    \par
    \vskip \parskip
    \vskip \baselineskip
  \endgroup
  \vskip -\parskip
  \vskip -\baselineskip
}

\provideenvironment{spacing}[1]{%
  \par
  \begingroup             % moved from \endspacing by PGBR 29-1-91
    \setstretch {#1}%
}{%
  \restore@spacing
}

% one and a half spacing is 1.5 x pt size
\provideenvironment{onehalfspace}{%
  \begingroup
    \onehalfspacing
}{%
  \restore@spacing
}

% double spacing is 2 x pt size
\provideenvironment{doublespace}{%
  \begingroup
    \doublespacing
}{%
  \restore@spacing
}

%% quote and quotation environment : Karnes.
\def\@quotespacinghook{%
	\if@singlespacequote
		\hangulfspacing%
	\else
		\hangulspacing%
	\fi
}

\renewenvironment{quotation}%
               {\list{}{\listparindent 1.5em%
                        \itemindent    \listparindent
                        \rightmargin   \leftmargin
                        \parsep        \z@ \@plus\p@}%
%								\memhangulinterwordhook
                \item[]%
                \@quotespacinghook
               }%
               {\endlist
                \if@singlespacequote\vskip-.2\onelineskip\fi}
\renewenvironment{quote}%
               {\list{}{\rightmargin\leftmargin}%
%                \memhangulinterwordhook
                \item[]
                \@quotespacinghook
               }%
               {\endlist
                \if@singlespacequote\vskip-.2\onelineskip\fi}
\renewenvironment{symbols}{\list{}%
    {\itemindent 0em \leftmargin 8em
     \labelsep 1em \labelwidth 5em
%     \memhangulinterwordhook
     \let\makelabel\symbollabel}%
     \@quotespacinghook
    }%
    {\endlist} 

%%%%%%%%%%%%%%%%%%%%
%%%% fix vertical spacing in the verse environment. mempatch 3.3
\renewenvironment{verse}[1][\linewidth]{%
  \refstepcounter{verse}%
  \setcounter{poemline}{0}\refstepcounter{poemline}%
  \setcounter{vslineno}{1}%
  \let\\=\@vscentercr
  \list{}{\itemsep      \z@
          \itemindent   -\vindent
          \listparindent\itemindent
          \parsep       \stanzaskip
          \ifdim #1<\linewidth %% short line
            \rightmargin        \z@
            \leftmargin         \linewidth
            \advance\leftmargin -#1\relax
            \advance\leftmargin -0.5\leftmargin
            \advance\leftmargin \vindent
          \else
            \ifdim #1>\linewidth %% long line
              \rightmargin \z@
              \leftmargin  \vindent
             \else               %% default
               \rightmargin        \leftmargin
               \advance\leftmargin \vindent
             \fi
          \fi}
  \item[]%
  \@quotespacinghook}{\endlist} 
%%%%%%%%%%%%%%

\renewenvironment{altverse}%
  {\starpatternfalse\patternfalse\altindenttrue\setcounter{vslineno}{1}%
   \@quotespacinghook
  }%
  {\altindentfalse} 

\def\@verbatim{\the\every@verbatim
	\trivlist
  \if@adjustverbatim\hangulverbspacing\else\fi%
  \item \relax
  \if@minipage\else\vskip\parskip\fi
  \@beginparpenalty \predisplaypenalty
  \leftskip\@totalleftmargin\rightskip\z@
  \parindent\z@\parfillskip\@flushglue\parskip\z@
  \@@par
  \def\par{%
    \if@tempswa
      \leavevmode\null\@@par\penalty\interlinepenalty
    \else
      \@tempswatrue
      \ifhmode\@@par\penalty\interlinepenalty\fi
    \fi}%
  \def\@noitemerr{\@warning{No verbatim text}}%
  \obeylines
  \let\do\@makeother \dospecials
  \verbatim@font
  \everypar \expandafter{\the\everypar \unpenalty}%
  \wrapright\the\afterevery@verbatim}

%% Karnes : epigraph
\providecommand\epigraphspacinghook{\setstretch{1.0}}
\providecommand\epigraphspacing[1]{%
	\renewcommand\epigraphspacinghook{\setstretch{#1}}%
}

\renewcommand{\epigraph}[2]{\vspace{\beforeepigraphskip}
  {\epigraphsize\begin{\epigraphflush}%
    \epigraphspacinghook
    \begin{minipage}{\epigraphwidth}
    \@epitext{#1}\\ \@episource{#2}
    \end{minipage}\end{\epigraphflush}
    \vspace{\afterepigraphskip}}} 

\renewenvironment{epigraphs}{%
  \vspace{\beforeepigraphskip}\begin{\epigraphflush}
  \epigraphsize
  \begin{minipage}{\epigraphwidth}
   \epigraphspacinghook
   \list{}%
    {\itemindent\z@ \labelwidth\z@ \labelsep\z@
     \leftmargin\z@ \rightmargin\z@
     \let\makelabel\qitemlabel}}%
  {\endlist\end{minipage}\end{\epigraphflush}
   \vspace{\afterepigraphskip}} 
 
% GT:  EMSH chose to omit display math part that follows.
% She wrote (see above) that the "altered spacing before and after displayed
% equations ... just looked too much".
%
% Fix up spacing before and after displayed math
% (arraystretch seems to do a fine job for inside LaTeX displayed math,
% since array and eqnarray seem to be affected as expected).
% Changing \baselinestretch and doing a font change also works if done here,
% but then you have to change @setsize to remove the call to @nomath)
%
% GT:  The \belowdisplayskip line was mistyped; now fixed, courtesy of
% David Hull.
%
% GT:  Brett Parnell has addressed EMSH's concern by replacing
% \baselinestretch by \displayskipstretch in displays, as follows.

\everydisplay\expandafter{%
  \the\everydisplay
  \abovedisplayskip \displayskipstretch\abovedisplayskip
  \belowdisplayskip \displayskipstretch\belowdisplayskip
  \abovedisplayshortskip \displayskipstretch\abovedisplayshortskip
  \belowdisplayshortskip \displayskipstretch\belowdisplayshortskip
}

\endinput

%%% EOF.
