%% File `memhangul-common.sty`
%%
%% (C) Copyright 2013-2025 Kangsoo Kim <modviv2k15 at gmail com>
%%
%% 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.
%%
%%%
%%% part of kotex-oblivoir
%%%
%%% =====================
%%% 편, 장 섹션 타이틀 재설정
%%% 절의 섹션 타이틀은 수정하지 않음.
%%
\ProvidesPackage{memhangul-common}[2025/04/04]

\let\@CHAPAPP\@chapapp
\def\refreshprepostchapters{%
  \if@hanja
     \def\pre@chapter{第}%
  \else
     \def\pre@chapter{제}%
  \fi
  \let\@chapapp\@CHAPAPP
  \def\post@chapter{\@chapapp}%
}
\refreshprepostchapters
%\renewcommand\@chapapp{장}
\def\prechapternum{\pre@chapter}
\def\postchapternum{\post@chapter}
\newcommand\hchaptertitlehead{\pre@chapter\,\thechapter\,\post@chapter}
\providecommand\partmark[1]{}

\let\pre@part\pre@chapter
\let\post@part\partname
%\renewcommand{\printpartname}{\partnamefont \pre@part}
\renewcommand{\printpartname}{} % disabled.
\renewcommand{\partnamenum}{\space}
\def\prepartnum{\partnamefont \pre@part}
\def\postpartnum{\partnamefont \post@part}
\newcommand\hparttitlehead{\pre@part\partnamenum\thepart\partnamenum\post@part}

%% PART
%\long\def\@part[#1]#2{%
%  \M@gettitle{#1}%
%  \ifnum \c@secnumdepth >-2\relax
%    \refstepcounter{part}%
%    \addcontentsline{toc}{part}%
%      {\protect\partnumberline{\hparttitlehead}#1}%
%  \else
%    \addcontentsline{toc}{part}{#1}%
%  \fi
%%  \markboth{}{}%
%  \ifx#1\@empty\partmark{#2}\else\partmark{#1}\fi
%  {\centering
%   \interlinepenalty \@M
%   \normalfont
%   \ifnum \c@secnumdepth >-2\relax
%     \prepartnum \partnamenum \printpartnum \partnamenum \postpartnum
%     \midpartskip
%   \fi
%   \printparttitle{#2}\par}%
%  \@endpart}
%%%%\long\def\@part[#1]#2{%
%%%%%  \ifx#1\@empty\PrerenderUnicode{#2}\else\PrerenderUnicode{#1}\fi
%%%%  \M@gettitle{#1}%
%%%%  \def\f@rtoc{#1}%
%%%%  \@nameuse{part@f@rtoc@before@write@hook}%
%%%%  \phantomsection
%%%%  \mempreaddparttotochook
%%%%  \ifnum \c@secnumdepth >-2\relax
%%%%    \refstepcounter{part}%
%%%%    \addcontentsline{toc}{part}%
%%%%%      {\protect\partnumberline{\thepart}#1}%
%%%%      {\protect\partnumberline{\hparttitlehead}#1}%
%%%%    \mempartinfo{\thepart}{#1}{#2}%
%%%%  \else
%%%%    \addcontentsline{toc}{part}{#1}%
%%%%    \mempartinfo{}{#1}{#2}%
%%%%  \fi
%%%%  \mempostaddparttotochook
%%%%  \partmark{#1}%
%%%%  {\centering
%%%%   \interlinepenalty \@M
%%%%   \normalfont
%%%%   \ifnum \c@secnumdepth >-2\relax
%%%%%     \printpartname \partnamenum \printpartnum
%%%%%     \midpartskip
%%%%     \prepartnum \partnamenum \printpartnum \partnamenum \postpartnum
%%%%     \midpartskip
%%%%   \fi
%%%%   \printparttitle{#2}\par}%
%%%%  \@endpart}


\def\obparttitlealignment{\centering}

\long\def\@part[#1]#2{%
  \M@gettitle{#1}%
  \def\f@rtoc{#1}%
  \@nameuse{part@f@rtoc@before@write@hook}%
  \phantomsection
  \mempreaddparttotochook
  \ifnum \c@secnumdepth >-2\relax
    \refstepcounter{part}%
    \addcontentsline{toc}{part}%
%      {\protect\partnumberline{\thepart}\f@rtoc}%
      {\protect\partnumberline{\hparttitlehead}\f@rtoc}%
    \mempartinfo{\thepart}{\f@rtoc}{#2}%
  \else
    \addcontentsline{toc}{part}{\f@rtoc}%
    \mempartinfo{}{\f@rtoc}{#2}%
  \fi
  \mempostaddparttotochook
  \partmark{#1}%
  {%\centering
   \obparttitlealignment
   \interlinepenalty \@M
   \parskip\z@
   \normalfont
   \ifnum \c@secnumdepth >-2\relax
%     \printpartname \partnamenum \printpartnum
%     \midpartskip
     \prepartnum \partnamenum \printpartnum \partnamenum \postpartnum
     \midpartskip
   \fi
   \printparttitle{#2}\par}%
  \@endpart}

\def\@spart#1{%
  \M@gettitle{#1}%
  \phantomsection
  {\centering
   \interlinepenalty \@M
   \normalfont
   \printparttitle{#1}\par}%
  \@endpart}

%\def\@endpart{\afterpartskip
%  \if@twoside
%    \if@openright
%      \null
%      \thispagestyle{empty}%
%      \newpage
%    \fi
%  \fi
%  \if@tempswa
%    \twocolumn
%  \fi} 

%% CHAPTER
%%%%%%%%%%%
%%\renewcommand{\@m@mchapter}[1][\@empty]{%
%%  \def\ch@pt@c{#1}% capture first optional arg
%%  \@dblarg{\@chapter}}
%\renewcommand{\@m@mchapter}[1][]{%
%  \def\ch@pt@c{#1}% capture first optional arg
%  \@ifnextchar[{\@chapter}{\@chapter[]}%
%}
%\def\m@m@empty{\@empty}

%%\def\m@m@empty{\@empty} 

%%%%\def\@chapter[#1]#2{%
%%%%  \ifx\ch@pt@c\m@m@empty % no optional args
%%%%    \def\f@rtoc{#1}%
%%%%    \def\f@rhdr{#1}%
%%%%  \else                  % at least one opt arg
%%%%    \def\f@rtoc{\ch@pt@c}%
%%%%    \nametest{#1}{#2}%
%%%%    \ifsamename          % one opt arg
%%%%      \def\f@rhdr{\ch@pt@c}%
%%%%    \else                % two opt args
%%%%      \def\f@rhdr{#1}%
%%%%    \fi
%%%%  \fi 
%%%%  \ifnum \c@secnumdepth >\m@ne
%%%%    \if@mainmatter
%%%%      \refstepcounter{chapter}%
%%%%    \fi
%%%%  \fi
%%%%  \chaptermark{\f@rhdr}%
%%%%  \ifartopt
%%%%    \@makechapterhead{#2}%
%%%%    \@afterheading
%%%%  \else
%%%%    \insertchapterspace
%%%%    \if@twocolumn
%%%%      \@topnewpage[\@makechapterhead{#2}]%
%%%%    \else
%%%%      \@makechapterhead{#2}%
%%%%    \fi
%%%%    \@afterheading
%%%%  \fi
%%%%  \ifnum \c@secnumdepth >\m@ne
%%%%    \if@mainmatter
%%%%      \addcontentsline{toc}{chapter}{%
%%%%%        \protect\chapternumberline{\thechapter}\f@rtoc}%
%%%%        \protect\chapternumberline{\hchaptertitlehead}\f@rtoc}%
%%%%    \else
%%%%      \addcontentsline{toc}{chapter}{\f@rtoc}%
%%%%    \fi
%%%%  \else
%%%%    \addcontentsline{toc}{chapter}{\f@rtoc}%
%%%%  \fi
%%%%  \ifheadnameref\M@gettitle{\f@rhdr}\else\M@gettitle{\f@rtoc}\fi
%%%%} 
%%%%
%%%%\def\@makechapterhead#1{%
%%%%  \chapterheadstart%  \vspace*{50\p@}%
%%%%  {\parindent \z@ \raggedright \normalfont
%%%%   \ifnum \c@secnumdepth >\m@ne
%%%%     \if@mainmatter
%%%%       \memucsinterwordchapterskiphook
%%%%%       \printchaptername \chapternamenum \printchapternum \chapternamenum \postchapternum
%%%%       \prechapternum \chapternamenum \printchapternum \chapternamenum \postchapternum
%%%%       \afterchapternum % \par\nobreak \vskip 20\p@
%%%%     \else
%%%%       \printchapternonum
%%%%     \fi
%%%%   \else
%%%%     \printchapternonum
%%%%   \fi
%%%%   \interlinepenalty\@M
%%%%   \printchaptertitle{#1} % \Huge \bfseries #1
%%%%    \afterchaptertitle % \par\nobreak \vskip 40\p@
%%%%  }}
%%%%
%%%%\def\@makeschapterhead#1{%
%%%%  \chapterheadstart
%%%%  {\parindent \z@ \raggedright \normalfont \memucsinterwordchapterskiphook
%%%%   \printchapternonum
%%%%   \interlinepenalty\@M
%%%%   \printchaptertitle{#1}
%%%%   \afterchaptertitle
%%%%  }
%%%%}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% CHAPTER
%% memhangul : opt args : different from memoir 1.618
%% \chapter[toc][hdr]{title}
%% \chapter[toc]{hdr/title}
%% \chapter{toc/hdr/title}
%%%%\def\@chapter[#1]#2{%
%%%%  \m@mpn@new@chaptrue%
%%%%  \m@mpn@new@schapfalse%
%%%%  \def\f@rbdy{#2}%
%%%%%  \ifx\ch@pt@c\@empty % no optional args
%%%%%    \def\f@rtoc{#2}%
%%%%%    \def\f@rhdr{#2}%
%%%%%    \PrerenderUnicode{#2}%
%%%%%  \else                  % at least one opt arg
%%%%%    \let\f@rtoc\ch@pt@c
%%%%%    \ifx\@empty#1\@empty
%%%%%      \let\f@rhdr\ch@pt@c
%%%%%      \PrerenderUnicode{#1#2}%
%%%%%    \else
%%%%%      \def\f@rhdr{#1}%
%%%%%      \PrerenderUnicode{#1}%
%%%%%    \fi
%%%%%  \fi
%%%%  \ifx\ch@pt@c\m@m@empty % no optional args
%%%%    \def\f@rtoc{#1}%
%%%%    \def\f@rhdr{#1}%
%%%%%    \PrerenderUnicode{#1}%
%%%%  \else                  % at least one opt arg
%%%%    \def\f@rtoc{\ch@pt@c}%
%%%%    \nametest{#1}{#2}%
%%%%    \ifsamename          % one opt arg
%%%%      \def\f@rhdr{\ch@pt@c}%
%%%%%      \PrerenderUnicode{#1#2}%
%%%%    \else                % two opt args
%%%%      \def\f@rhdr{#1}%
%%%%%      \PrerenderUnicode{#1}%
%%%%    \fi
%%%%  \fi 
%%%%  \m@m@Andfalse
%%%%  \ifnum \c@secnumdepth >\m@ne
%%%%    \if@mainmatter
%%%%      \m@m@Andtrue
%%%%    \fi
%%%%  \fi
%%%%  \ifm@m@And
%%%%   \ifanappendix
%%%%    \refstepcounter{APPchapter}%
%%%%   \else
%%%%    \refstepcounter{chapter}%
%%%%   \fi
%%%%  \fi
%%%%  \chaptermark{\f@rhdr}
%%%%  \ifartopt
%%%%    \@makechapterhead{#2}%
%%%%    \@afterheading
%%%%  \else
%%%%    \insertchapterspace
%%%%    \if@twocolumn
%%%%      \@topnewpage[\@makechapterhead{#2}]%
%%%%    \else
%%%%      \@makechapterhead{#2}%
%%%%    \fi
%%%%    \@afterheading
%%%%  \fi
%%%%  \ifm@m@And
%%%%    \ifanappendix
%%%%      \addcontentsline{toc}{appendix}{%
%%%%%       \protect\chapternumberline{\thechapter}\f@rtoc}%
%%%%       \protect\chapternumberline{\hchaptertitlehead}\f@rtoc}%
%%%%%       \memappchapinfo{\thechapter}{\f@rtoc}{\f@rhdr}{#2}%
%%%%       \memappchapinfo{\thechapter}{\f@rtoc}{\f@rhdr}{#2}%
%%%%    \else
%%%%      \addcontentsline{toc}{chapter}{%
%%%%%        \protect\chapternumberline{\thechapter}\f@rtoc}%
%%%%        \protect\chapternumberline{\hchaptertitlehead}\f@rtoc}%
%%%%%      \memchapinfo{\thechapter}{\f@rtoc}{\f@rhdr}{#2}%
%%%%       \memchapinfo{\hchaptertitlehead}{\f@rtoc}{\f@rhdr}{#2}%
%%%%    \fi
%%%%  \else
%%%%    \addcontentsline{toc}{chapter}{\f@rtoc}%
%%%%    \ifanappendix
%%%%      \memappchapinfo{}{\f@rtoc}{\f@rhdr}{#2}%
%%%%    \else
%%%%      \memchapinfo{\hchaptertitlehead}{\f@rtoc}{\f@rhdr}{#2}%
%%%%    \fi
%%%%  \fi
%%%%  \mempostaddchaptertotochook%
%%%%  \ifheadnameref\M@gettitle{\f@rhdr}\else\M@gettitle{\f@rtoc}\fi
%%%%%%% for chapter
%%%%  \ifanappendix
%%%%     \protected@edef\@currentlabel{\thechapter}%
%%%%  \fi
%%%%  \memendofchapterhook%
%%%%}

\def\@chapter[#1]#2{%
  \m@mpn@new@chaptrue%
  \m@mpn@new@schapfalse%
  \def\f@rbdy{#2}%
  \ifx\ch@pt@c\@empty % no optional args
    \def\f@rtoc{#2}%
    \def\f@rhdr{#2}%
  \else                  % at least one opt arg
    \let\f@rtoc\ch@pt@c
    \ifx\@empty#1\@empty
      \let\f@rhdr\ch@pt@c
    \else
      \def\f@rhdr{#1}%
    \fi
  \fi
  \m@m@Andfalse
  \ifnum \c@secnumdepth >\m@ne
    \if@mainmatter
      \m@m@Andtrue
    \fi
  \fi
  \ifm@m@And
   \ifanappendix
    \refstepcounter{APPchapter}%
   \else
    \refstepcounter{chapter}%
   \fi
  \fi
  \chaptermark{\f@rhdr}
  \ifartopt
    \@makechapterhead{#2}%
    \@afterheading
  \else
    \insertchapterspace
    \if@twocolumn
      \@topnewpage[\@makechapterhead{#2}]%
    \else
      \@makechapterhead{#2}%
    \fi
    \@afterheading
  \fi
  \@nameuse{chapter@f@rtoc@before@write@hook}%
  \mempreaddchaptertotochook%
  \ifm@m@And
    \ifanappendix
      \addcontentsline{toc}{appendix}{%
       \protect\chapternumberline{\hchaptertitlehead}\f@rtoc}%
       \memappchapinfo{\thechapter}{\f@rtoc}{\f@rhdr}{#2}%
    \else
      \addcontentsline{toc}{chapter}{%
        \protect\chapternumberline{\hchaptertitlehead}\f@rtoc}%
       \memchapinfo{\hchaptertitlehead}{\f@rtoc}{\f@rhdr}{#2}%
    \fi
  \else
    \addcontentsline{toc}{chapter}{\f@rtoc}%
    \ifanappendix
      \memappchapinfo{}{\f@rtoc}{\f@rhdr}{#2}%
    \else
      \memchapinfo{\hchaptertitlehead}{\f@rtoc}{\f@rhdr}{#2}%
    \fi
  \fi
  \mempostaddchaptertotochook%
  \ifheadnameref\M@gettitle{\f@rhdr}\else\M@gettitle{\f@rtoc}\fi
  \ifanappendix
     \protected@edef\@currentlabel{\thechapter}%
  \fi
  \memendofchapterhook%
}

%\def\@makechapterhead#1{%
%  \chapterheadstart%  \vspace*{50\p@}%
%  {\parindent \z@ \raggedright \normalfont
%   \ifm@m@And
%   	 \memucsinterwordchapterskiphook
%%     \printchaptername \chapternamenum \printchapternum
%%     \afterchapternum % \par\nobreak \vskip 20\p@
%      \prechapternum \chapternamenum \printchapternum \chapternamenum \postchapternum
%      \afterchapternum % \par\nobreak \vskip 20\p@
%   \else
%     \printchapternonum
%   \fi
%   \interlinepenalty\@M
%   \printchaptertitle{#1} % \Huge \bfseries #1
%   \afterchaptertitle % \par\nobreak \vskip 40\p@
%  }}
\RequirePackage{etoolbox}
\patchcmd\@makechapterhead{%
	\printchaptername \chapternamenum \printchapternum
  	\afterchapternum}{%
	\prechapternum \chapternamenum \printchapternum 
	\chapternamenum \postchapternum \afterchapternum}{}{}

%%%\renewcommand{\@m@mschapter}[2][\@empty]{%
%%%  \@schapter{#2}%
%%%  \ifx \@empty#1
%%%    \def\f@rhdr{#2}%
%%%%    \PrerenderUnicode{#2}%
%%%  \else   % opt arg
%%%    \def\f@rhdr{#1}%
%%%%    \PrerenderUnicode{#1}%
%%%    \setcounter{secnumdepth}{-10}%
%%%    \chaptermark{#1}%
%%%    \setcounter{secnumdepth}{\value{maxsecnumdepth}}%
%%%  \fi
%%%  \ifanappendix
%%%    \memappchapstarinfo{\f@rhdr}{#2}%
%%%  \else
%%%    \memchapstarinfo{\f@rhdr}{#2}%
%%%  \fi}

\renewcommand{\@m@mschapter}[2][\@empty]{%
  \@schapter{#2}%
  \ifx \@empty#1
    \def\f@rhdr{#2}%
  \else   % opt arg
    \def\f@rhdr{#1}%
    \setcounter{secnumdepth}{-10}%
    \chaptermark{#1}%
    \setcounter{secnumdepth}{\value{maxsecnumdepth}}%
  \fi
  \ifanappendix
    \memappchapstarinfo{\f@rhdr}{#2}%
  \else
    \memchapstarinfo{\f@rhdr}{#2}%
  \fi
  \ifheadnameref\M@gettitle{\f@rhdr}\else\M@gettitle{#2}\fi}


%%%%\def\@makeschapterhead#1{%
%%%%  \chapterheadstart
%%%%%  {\parindent \z@ \raggedright \normalfont
%%%%  {\parindent \z@ \raggedright \normalfont \memucsinterwordchapterskiphook
%%%%   \printchapternonum
%%%%   \interlinepenalty\@M
%%%%   \printchaptertitle{#1}
%%%%   \afterchaptertitle
%%%%  }
%%%%}

%%%%%%%%%%%%%

\renewcommand{\@chs@def@ult}{%
 \def\chapterheadstart{\vspace*{\beforechapskip}}
%  \def\printchaptername{\chapnamefont \@chapapp}
% \def\printchaptername{\chapnamefont \pre@chapter}
 \def\printchaptername{} % disabled.
%  \def\chapternamenum{\space}
 \def\chapternamenum{\,}
 \def\printchapternum{\chapnumfont \thechapter}
 \def\prechapternum{\chapnamefont \pre@chapter}
 \def\postchapternum{\chapnamefont \post@chapter}
 \def\afterchapternum{\par\nobreak\vskip \midchapskip}
 \def\printchapternonum{}
 \def\printchaptertitle##1{\chaptitlefont ##1}
 \def\postchaptertitle{\post@chapter}
 \def\afterchaptertitle{\par\nobreak\vskip \afterchapskip}
}

%% l@chapter, l@part

\setlength{\cftpartnumwidth}{4.5em}
\setlength{\cftchapternumwidth}{4.0em}
%% for compatibility with mempatch 3.12
\def\@chapapp@head{}% 

%% SECTION

\renewcommand{\section}{%
  \sechook\memucsinterwordhook%
  \@startsection{section}{1}%  level 1
      {\secindent}%            heading indent
      {\beforesecskip}%        skip before the heading
      {\aftersecskip}%         skip after the heading
      {\normalfont\secheadstyle}} % font 

%% PAGESTYLES
%% headings, ruled, Ruled, companioin을 수정함

%% pagestyle headings
\if@twoside
  \makepagestyle{headings}
    \makepsmarks{headings}{%
      \let\@mkboth\markboth
      \def\chaptermark##1{%
        \markboth{\MakeUppercase{%
          \ifnum \c@secnumdepth >\m@ne
            \if@mainmatter
              \hchaptertitlehead \enskip\ %
            \fi
          \fi
          ##1}}{}}%
      \def\tocmark{\markboth{\MakeUppercase{\contentsname}}{}}%
      \def\lofmark{\markboth{\MakeUppercase{\listfigurename}}{}}%
      \def\lotmark{\markboth{\MakeUppercase{\listtablename}}{}}%
      \def\bibmark{\markboth{\MakeUppercase{\bibname}}{}}%
      \def\indexmark{\markboth{\MakeUppercase{\indexname}}{}}%
      \def\sectionmark##1{%
        \markright{\MakeUppercase{%
          \ifnum \c@secnumdepth > \z@
            \thesection \enskip\ %
          \fi
          ##1}}}%
    }
    \makeevenhead{headings}{\thepage}{}{\normalfont\slshape\leftmark}
    \makeoddhead{headings}{\normalfont\slshape\rightmark}{}{\thepage}
\else
  \makepagestyle{headings}
    \makepsmarks{headings}{%
      \let\@mkboth\markboth
      \def\chaptermark##1{%
        \markright{\MakeUppercase{%
          \ifnum \c@secnumdepth >\m@ne
            \if@mainmatter
              \hchaptertitlehead \enskip\ %
            \fi
          \fi
          ##1}}}%
      \def\tocmark{\markright{\MakeUppercase{\contentsname}}}%
      \def\lofmark{\markright{\MakeUppercase{\listfigurename}}}%
      \def\lotmark{\markright{\MakeUppercase{\listtablename}}}%
      \def\bibmark{\markright{\MakeUppercase{\bibname}}}%
      \def\indexmark{\markright{\MakeUppercase{\indexname}}}%
    }
    \makeoddhead{headings}{\normalfont\slshape\rightmark}{}{\thepage}
\fi 

%% Pagestyle ruled

\makepagestyle{ruled}
\makeevenfoot{ruled}{\thepage}{}{}
\makeoddfoot{ruled}{}{}{\thepage}
\makeheadrule{ruled}{\textwidth}{\normalrulethickness}
\renewcommand{\@ruledmarks}{%
  \let\@mkboth\markboth
  \def\chaptermark##1{%
    \markboth{%
      \ifnum \c@secnumdepth >\m@ne
        \if@mainmatter
          \hchaptertitlehead \enskip\ %
        \fi
      \fi
      ##1}{}}
  \def\sectionmark##1{\markright{##1}}
  \def\tocmark{\markboth{\contentsname}{}}
  \def\lofmark{\markboth{\listfigurename}{}}
  \def\lotmark{\markboth{\listtablename}{}}
  \def\bibmark{\markboth{\bibname}{}}
  \def\indexmark{\markboth{\indexname}{}}
}
\makepsmarks{ruled}{\@ruledmarks}
\makeevenhead{ruled}{\normalfont\scshape\leftmark}{}{}
\makeoddhead{ruled}{}{}{\normalfont\rightmark}  


%%% References
\renewcommand\Cref[1]{%
   \pre@chapter\,\ref{#1}\,\chapterrefname%
}
\renewcommand\Pref[1]{%
   \pre@part\,\ref{#1}\,\partrefname%
}
\renewcommand\pref[1]{%
   \pageref{#1}~\pagerefname
}
\renewcommand\tref[1]{%
   \tablerefname~\ref{#1}%
}
\renewcommand\fref[1]{%
   \figurerefname~\ref{#1}%
}

%% arabic, roman... etc.
%%\def\HArabic#1{\arabic{#1}}
\def\HAlph#1{\Alph{#1}}
\def\Halph#1{\alph{#1}}
\def\HROMAN#1{\hRoman{#1}}
\def\Hroman#1{\hroman{#1}}
%%

%% phantomchapter = phantomsection
\def\phantomchapter{%
 \Hy@GlobalStepCount\Hy@linkcounter
 \xdef\@currentHref{chapter*.\the\Hy@linkcounter}%
 \Hy@raisedlink{\hyper@anchorstart{\@currentHref}\hyper@anchorend}%
}

%%% index
\renewcommand{\@wrindexm@m}[1]{\@@wrindexhyp#1||\\} 


%%% 한글 문장부호 관련 명령
%%% \hfontfamilynameprefix is deprecated. (ver1.5.0)
\def\hfontfamilynameprefix{ut} % for compatibility only

\def\cnm@char@open{〈}
\def\cnm@char@close{〉}
\def\ccnm@char@open{《}
\def\ccnm@char@close{》}
\def\snm@char@open{「}
\def\snm@char@close{」}
\def\bnm@char@open{『}
\def\bnm@char@close{』}

\ExplSyntaxOn
\NewDocumentCommand \memx@make@bnmcmd { mm }
{
	\ifvmode\leavevmode\fi
	\memx@bnmcmd@prekern
	\use:c { #1@char@open }
	#2
	\use:c { #1@char@close }
	\memx@bnmcmd@postkern
}
\ExplSyntaxOff

\protected\def\cnm{%
	\@ifnextchar*\cnm@star\cnm@nostar
}

\def\cnm@star*#1{% 
	\def\memx@bnmcmd@prekern{\kern-.2em}%
	\def\memx@bnmcmd@postkern{\kern-.3em}%
	\memx@make@bnmcmd{cnm}{#1}%
}

\def\cnm@nostar#1{%
    \let\memx@bnmcmd@prekern\relax
    \let\memx@bnmcmd@postkern\relax
	\memx@make@bnmcmd{cnm}{#1}%
}

\protected\def\ccnm{%
	\@ifnextchar*\ccnm@star\ccnm@nostar
}

\def\ccnm@star*#1{%
	\def\memx@bnmcmd@prekern{\kern-.2em}%
	\def\memx@bnmcmd@postkern{\kern-.3em}%
	\memx@make@bnmcmd{ccnm}{#1}%
}

\def\ccnm@nostar#1{%
    \let\memx@bnmcmd@prekern\relax
    \let\memx@bnmcmd@postkern\relax
	\memx@make@bnmcmd{ccnm}{#1}%
}

\protected\def\snm{%
	\@ifnextchar*\snm@star\snm@nostar
}

\def\snm@star*#1{%
	\def\memx@bnmcmd@prekern{\kern-.2em}%
	\def\memx@bnmcmd@postkern{\kern-.3em}%
	\memx@make@bnmcmd{snm}{#1}%
}

\def\snm@nostar#1{% 
    \let\memx@bnmcmd@prekern\relax
    \let\memx@bnmcmd@postkern\relax
	\memx@make@bnmcmd{snm}{#1}%
}

\protected\def\bnm{%
	\@ifnextchar*\bnm@star\bnm@nostar
}

\def\bnm@star*#1{% 
	\def\memx@bnmcmd@prekern{\kern-.2em}%
	\def\memx@bnmcmd@postkern{\kern-.3em}%
	\memx@make@bnmcmd{bnm}{#1}%
}

\def\bnm@nostar#1{%
    \let\memx@bnmcmd@prekern\relax
    \let\memx@bnmcmd@postkern\relax
	\memx@make@bnmcmd{bnm}{#1}%
}

%%% ldots, hdots,
\ExplSyntaxOn

\NewDocumentCommand \obldots {}  {
   .\kern\fontdimen3\font
   .\kern\fontdimen3\font
   .\kern\fontdimen3\font
}

\NewDocumentCommand \obellipsis {} {
	\nobreak \mbox{\textellipsis\textellipsis}
}

\ExplSyntaxOff

\AtBeginDocument{%
  \@ifpackageloaded{hyperref}{%
    \pdfstringdefDisableCommands{%
         \def\cnm#1{\ifx#1*\expandafter\@@cnm\else <#1>\fi}%
	  \def\@@cnm#1{<#1>}%
	  \def\snm#1{\ifx#1*\expandafter\@@cnm\else <#1>\fi}%
	  \def\ccnm#1{\ifx#1*\expandafter\@@cnm\else <#1>\fi}%
	  \def\bnm#1{\ifx#1*\expandafter\@@cnm\else <#1>\fi}%
	  \def\oblivoirdblquote#1{\ifx#1*\expandafter\@@obquote\else "#1"\fi}%
	  \def\@@obquote#1{"#1"}%
	  \def\oblivoirquote#1{\ifx#1*\expandafter\@@obsquote\else '#1'\fi}%
	  \def\@@obsquote#1{'#1'}%
	  \def\cntrdots{…}%
    }%
  }{}%
} 

%%%% 따옴표
\def\oblivoirdblquote@char@open{“}
\def\oblivoirdblquote@char@close{”}
\def\oblivoirquote@char@open{‘}
\def\oblivoirquote@char@close{’}

\protected\def\oblivoirdblquote{%
	\@ifnextchar*\oblivoirdblquote@star\oblivoirdblquote@nostar
}

\def\oblivoirdblquote@star*#1{% 
	\def\memx@bnmcmd@prekern{\kern-.18em}%
	\def\memx@bnmcmd@postkern{\kern-.27em}%
	\memx@make@bnmcmd{oblivoirdblquote}{#1}%
}

\def\oblivoirdblquote@nostar#1{%
    \let\memx@bnmcmd@prekern\relax
    \let\memx@bnmcmd@postkern\relax
	\memx@make@bnmcmd{oblivoirdblquote}{#1}%
}

\protected\def\oblivoirquote{%
	\@ifnextchar*\oblivoirquote@star\oblivoirquote@nostar
}

\def\oblivoirquote@star*#1{% 
	\def\memx@bnmcmd@prekern{\kern-.18em}%
	\def\memx@bnmcmd@postkern{\kern-.27em}%
	\memx@make@bnmcmd{oblivoirquote}{#1}%
}

\def\oblivoirquote@nostar#1{%
    \let\memx@bnmcmd@prekern\relax
    \let\memx@bnmcmd@postkern\relax
	\memx@make@bnmcmd{oblivoirquote}{#1}%
}

%%%% cntrdots

\ifx\cntrdot\undefined
\DeclareRobustCommand{\cntrdot}{%
 	\@ifnextchar*\@cntrd@t\@@cntrd@t
}
\else
\renewcommand{\cntrdot}{%
 	\@ifnextchar*\@cntrd@t\@@cntrd@t
}
\fi

\ifx\oblivoirallowbreak\undefined
\let\oblivoirallowbreak\allowbreak
\fi

\def\@cntrd@t*{%
	\leavevmode\kern.18em\@@cntrd@t\hskip.18em\oblivoirallowbreak
}
\def\@@cntrd@t{%
    \leavevmode\nobreak\raise.018ex\hbox{·}\oblivoirallowbreak
}

\DeclareRobustCommand{\cntrdots}{%
    \leavevmode…%\oblivoirallowbreak
}

\DeclareRobustCommand{\cntrdotss}{%
	\leavevmode ……%
}

%% Punctuation Explanation Rule.
%% usage: \explpunc.Some_running_texts.\ % last space must not be succeeded by ^M.
\protected\def\explpunc.#1.\ {\ifvmode\leavevmode\fi\,\XBrule#1\XErule\,} %%% allowing linebreak
\protected\def\expldash{\ifvmode\leavevmode\fi\,\XBrule\,}
%
\newsavebox\togetheightoffont\sbox\togetheightoffont{!}
\newlength\htoffnt\setlength\htoffnt{\ht\togetheightoffont}
\addtolength\htoffnt{\dp\togetheightoffont}
%\def\XBrule{\raise.45\htoffnt\hbox{\rule{1.25em}{.25pt}}}
%\def\XErule{\raise.45\htoffnt\hbox{\hskip1pt\rule{1.25em}{.25pt}}}
\newcommand*\XBrule{%
    \sbox\togetheightoffont{!}%
    \setlength\htoffnt{\ht\togetheightoffont}%
    \raise.43\htoffnt\hbox{\rule{1.25em}{.04em}}%
}
\newcommand*\XErule{%
	\sbox\togetheightoffont{!}%
	\setlength\htoffnt{\ht\togetheightoffont}%
	\raise.43\htoffnt\hbox{\hskip1pt\rule{1.25em}{.04em}}%
}

%% Misc def.
%\def\PageName{페이지}
%\def\AltPageName{쪽}

%% \titleref
%%    -- 2009/02/11. revert to original definition.
\let\M@TitleReference\@firstoftwo 
\let\M@M@TitleReference\@firstoftwo
\def\@mem@theTR{\let\M@M@TitleReference\@firstoftwo\theTitleReference}

%% vertical distance of math display
\if@mathdisp
\apptocmd{\normalsize}{%
    \abovedisplayskip 6\p@ \@plus2\p@ \@minus4\p@
    \abovedisplayshortskip 1\p@ \@plus2\p@ %\@minus1\p@
    \belowdisplayskip 6\p@ \@plus2\p@ \@minus4\p@
    \belowdisplayshortskip 7\p@ \@plus2\p@ %\@minus1\p@
%    \belowdisplayskip \abovedisplayskip
}{}{}
\fi

%% arabic frontmatter numbering
\if@arabicfrontmatter
\renewcommand{\@memfront}{%
  \@smemfront\pagenumbering{arabic}}
\fi

%% 할주.
%%  still experimental
%%  \hbox로 처리하기 때문에 행끝에서 할주 행나눔은 이루어지지 않는다.
%%  글꼴이 \tiny로 고정. \footnotesize를 쓰면 행간이 흐트러짐.
%%  TODO: 현재 설정은 10pt 문서에서 1pt정도가 행간에 추가됨.
%%  \lineskiplimit를 이용해서 행간을 고정시켜둘 것인지는 아직
%%  결정하지 못하였음.
\newskip\divnoteskip
\def\divnotedelimopen{\hskip.1em$\big($}
\def\divnotedelimclose{$\big)$\hskip.1em}
\divnoteskip = .18em plus .02em minus .02em
\def\divnotestyle{%
 \spaceskip\divnoteskip\normalfont\tiny}
\protected\def\divnote#1{%
  \settowidth{\@tempdima}{\divnotestyle #1}%
  \ifvmode\leavevmode\fi\divnotedelimopen
  \raise.2em\hbox{\parbox{.525\@tempdima}{\divnotestyle\singlespace #1}}\divnotedelimclose
}

%% 각주 설정을 위한 추가 매크로
\def\SetFnmark#1#2{%
   \expandafter\def\csname @makefnmark\endcsname{\bgroup #1\@thefnmark#2\egroup}%
}

%% chapter의 첫 단락 들여쓰기.
\newcommand*\chapterindentfirst{%
  \pretocmd{\@afterheading}{\@afterindenttrue}{}{}
}

%% memhangul-patch
\InputIfFileExists{memhangul-patch.sty}{}{}

%%% fig, tab caption
%%%\def\obCaptionFont#1{\def\@figtabcaptfont@{#1}}
%%%\providecommand\@figtabcaptfont@{\normalfont}
%%%\if@figtabcapt@
%%%\AtBeginDocument{
%%%\@ifpackageloaded{caption}{%  requested by Progress
%%%	\DeclareCaptionLabelFormat{xob-cnm-parens}{\cnm{#1~#2}}
%%%	\captionsetup{labelformat=xob-cnm-parens,labelsep=space}
%%%}%
%%%{%
%%%	\precaption{{\@figtabcaptfont@\cnm@char@open}}
%%%	\captiondelim{{\@figtabcaptfont@\cnm@char@close}\quad}
%%%	\renewcommand\cfttablepresnum{\cnm@char@open\tablename\space}
%%%	\renewcommand\cfttableaftersnum{\cnm@char@close}
%%%	\setlength\cfttablenumwidth{3.8em}
%%%	\renewcommand\cftfigurepresnum{\cnm@char@open\figurename\space}
%%%	\renewcommand\cftfigureaftersnum{\cnm@char@close}
%%%	\setlength\cftfigurenumwidth{4.5em}
%%%}
%%%}
%%%\fi

\def\obCaptionFont#1{\def\@figtabcaptfont@{#1}}
\def\obCaptionnameOpen{\cnm@char@open}
\def\obCaptionnameClose{\cnm@char@close}
\providecommand\@figtabcaptfont@{\normalfont}
\newcommand*\obCaptionAfterdelim{\quad}
\if@figtabcapt@
\AtBeginDocument{%
\@ifpackageloaded{caption}{%  requested by Progress
        \DeclareCaptionLabelFormat{xob-cnm-parens}{\cnm{#1~#2}}
        \captionsetup{labelformat=xob-cnm-parens,labelsep=space}
}%
{%
        \precaption{{\@figtabcaptfont@\obCaptionnameOpen}}
        \captiondelim{{\@figtabcaptfont@\obCaptionnameClose}\obCaptionAfterdelim}
        \renewcommand\cfttablepresnum{\obCaptionnameOpen\tablename\space}
        \renewcommand\cfttableaftersnum{\obCaptionnameClose}
        \setlength\cfttablenumwidth{3.8em}
        \renewcommand\cftfigurepresnum{\obCaptionnameOpen\figurename\space}
        \renewcommand\cftfigureaftersnum{\obCaptionnameClose}
        \setlength\cftfigurenumwidth{4.5em}
}%
}
\fi

%%% LuaTeX, XeTeX logos
\RequirePackage{xparse}
\ExplSyntaxOn
\tl_if_exist:NF \XeTeX
{
	\RequirePackage{hologo}
	\ProvideDocumentCommand \XeTeX { } { \hologo{XeTeX} }
	\ProvideDocumentCommand \XeLaTeX { } { \hologo{XeLaTeX} }
}
\tl_if_exist:NF \LuaTeX
{
	\RequirePackage{hologo}
	\ProvideDocumentCommand \LuaTeX { } { \hologo{LuaTeX} }
	\ProvideDocumentCommand \LuaLaTeX { } { \hologo{LuaLaTeX} }
}
\ExplSyntaxOff

%% Pagestyle Ruled

\makepagestyle{Ruled}
\makerunningwidth{Ruled}{1.1\textwidth}
\makeheadposition{Ruled}{flushright}{flushleft}{flushright}{flushleft}
\makeevenfoot{Ruled}{\thepage}{}{}
\makeoddfoot{Ruled}{}{}{\thepage}
\makeheadrule{Ruled}{1.1\textwidth}{\normalrulethickness}
\makepsmarks{Ruled}{\@ruledmarks}
\makeevenhead{Ruled}{\normalfont\scshape\leftmark}{}{}
\makeoddhead{Ruled}{}{}{\normalfont\rightmark}

%% Pagestyle companion

%\makepagestyle{companion}
%\setlength{\headwidth}{\textwidth}
%  \addtolength{\headwidth}{\marginparsep}
%  \addtolength{\headwidth}{\marginparwidth}
%\makerunningwidth{companion}{\headwidth}
%\makeheadrule{companion}{\headwidth}{\normalrulethickness}
%\makeheadposition{companion}{flushright}{flushleft}{}{}
%\makepsmarks{companion}{%
%  \let\@mkboth\markboth
%  \def\chaptermark##1{\markboth{##1}{##1}}    % left mark & right marks
%  \def\sectionmark##1{\markright{%
%    \ifnum \c@secnumdepth>\z@
%      \thesection. \ %
%    \fi
%    ##1}}
%  \def\tocmark{\markboth{\contentsname}{\contentsname}}
%  \def\lofmark{\markboth{\listfigurename}{\listfigurename}}
%  \def\lotmark{\markboth{\listtablename}{\listtablename}}
%  \def\bibmark{\markboth{\bibname}{\bibname}}
%  \def\indexmark{\markboth{\indexname}{\indexname}}
%}
%\makeevenhead{companion}{\normalfont\bfseries\thepage}{}%
%                        {\normalfont\bfseries\leftmark}
%\makeoddhead{companion}{\normalfont\bfseries\rightmark}{}%
%                       {\normalfont\bfseries\thepage} 

%% 한글 pagestyle hangul
\makepagestyle{hangul}
\newdimen\pghgheadwidth\let\pghgheadwidth=\textwidth
\makerunningwidth{hangul}{\pghgheadwidth}
%\makeheadrule{hangul}{\pghgheadwidth}{0pt}
\makeheadposition{hangul}{flushleft}{flushright}{flushleft}{flushright}
\def\@hgpsmarks{%
      \let\@mkboth\markboth
      \def\chaptermark##1{%
        \markboth{\scshape
          \ifnum \c@secnumdepth >\m@ne
            \if@mainmatter
              \hchaptertitlehead \enskip\ %
            \fi
          \fi
          ##1}{}}%
      \def\tocmark{\markboth{\scshape\contentsname}{}}%
      \def\lofmark{\markboth{\scshape\listfigurename}{}}%
      \def\lotmark{\markboth{\scshape\listtablename}{}}%
      \def\bibmark{\markboth{\scshape\bibname}{}}%
      \def\indexmark{\markboth{\scshape\indexname}{}}%
      \def\sectionmark##1{%
        \markright{\scshape
%% disabled printing \thesection.
%          \ifnum \c@secnumdepth >\z@
%            \thesection \enskip\ %
%          \fi
          ##1}}%
    }
\makepsmarks{hangul}{\@hgpsmarks}
\makeoddhead{hangul}{}{}{\normalfont\small\rightmark~\makebox[2em][r]{\normalfont\normalsize\sffamily\thepage}}
\makeevenhead{hangul}{\makebox[2em][l]{\normalfont\normalsize\sffamily\thepage}~\normalfont\small\leftmark}{}{}

%%%%% chapter styles %%%%

\makechapterstyle{default}{%
  \renewcommand{\post@chapter}{\chaptername}%
  \renewcommand{\chapnamefont}{\normalfont\huge\bfseries}
  \renewcommand{\chapnumfont}{\normalfont\huge\bfseries}
  \renewcommand{\chaptitlefont}{\normalfont\Huge\bfseries}
  \setlength{\beforechapskip}{50pt}
  \setlength{\midchapskip}{20pt}
  \setlength{\afterchapskip}{40pt}
}
\chapterstyle{default}

%% for Appendix
\makechapterstyle{appendixdefault}{%
  \renewcommand*{\chaptername}{\appendixname}
  \renewcommand{\chapnamefont}{\normalfont\huge\bfseries}
  \renewcommand{\chapnumfont}{\normalfont\huge\bfseries}
  \renewcommand{\chaptitlefont}{\normalfont\Huge\bfseries}
%  \renewcommand{\printchaptername}{\chapnumfont\@chapapp}
  \renewcommand{\prechapternum}{\chapnumfont\@chapapp}
  \renewcommand{\postchapternum}{}
  \renewcommand{\chapternamenum}{\enskip}
  \setlength{\beforechapskip}{50pt}
  \setlength{\midchapskip}{20pt}
  \setlength{\afterchapskip}{40pt}
  \renewcommand*{\hchaptertitlehead}{\chaptername~\thechapter}
}

\RequirePackage{obchapterstyles}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%% appendix %%%%%%%%%%%%%%%%%%%%%%%%%
%%% moved to ob-[no]koreanappendix.sty
%\def\set@appendix@chapsec{%
%   %%% SECTION in APPENDIX
%   \renewcommand{\section}{%
%   \sechook\memucsinterwordhook%
%   \@startsection{section}{1}%  level 1
%      {\secindent}%            heading indent
%      {\beforesecskip}%        skip before the heading
%      {\aftersecskip}%         skip after the heading
%      {\normalfont\secheadstyle}} % font 
% \def\M@sect##1##2##3##4##5##6[##7][##8]##9{%
%  \ifheadnameref\M@gettitle{##8}\else\M@gettitle{##7}\fi
%  \ifnum ##2>\c@secnumdepth
%    \let\@svsec\@empty
%  \else
%    \refstepcounter{APP##1}%
%    \protected@edef\@svsec{\@seccntformat{##1}\relax}%
%  \fi
%  \@tempskipa ##5\relax
%  \ifdim \@tempskipa>\z@
%    \begingroup
%      ##6{%
%      \@hangfrom{\hskip ##3\relax\@svsec}%
%        \interlinepenalty \@M ##9\@@par}%
%    \endgroup
%    \csname ##1mark\endcsname{##8}%
%    \addcontentsline{toc}{##1}{%
%      \ifnum ##2>\c@secnumdepth \else
%        \protect\numberline{\noexpand\protect\csname the##1\endcsname}%
%      \fi
%      ##7}%
%  \else
%    \def\@svsechd{%
%      ##6{\hskip ##3\relax
%     \@svsec ##9}%
%     \csname ##1mark\endcsname{##8}%
%     \addcontentsline{toc}{##1}{%
%       \ifnum ##2>\c@secnumdepth \else
%        \protect\numberline{\csname the##1\endcsname}%
%       \fi
%       ##7}}%
%  \fi
%  \@xsect{##5}}%
%}
%
%\def\restorechapsec{%
%   %%% SECTION in APPENDIX
%   \renewcommand{\section}{%
%   \sechook\memucsinterwordhook%
%   \@startsection{section}{1}%  level 1
%      {\secindent}%            heading indent
%      {\beforesecskip}%        skip before the heading
%      {\aftersecskip}%         skip after the heading
%      {\normalfont\secheadstyle}} % font 
% \def\M@sect##1##2##3##4##5##6[##7][##8]##9{%
%  \ifheadnameref\M@gettitle{##8}\else\M@gettitle{##7}\fi
%  \ifnum ##2>\c@secnumdepth
%    \let\@svsec\@empty
%  \else
%    \refstepcounter{##1}%
%    \protected@edef\@svsec{\@seccntformat{##1}\relax}%
%  \fi
%  \@tempskipa ##5\relax
%  \ifdim \@tempskipa>\z@
%    \begingroup
%      ##6{%
%      \@hangfrom{\hskip ##3\relax\@svsec}%
%        \interlinepenalty \@M ##9\@@par}%
%    \endgroup
%    \csname ##1mark\endcsname{##8}%
%    \addcontentsline{toc}{##1}{%
%      \ifnum ##2>\c@secnumdepth \else
%        \protect\numberline{\noexpand\protect\csname the##1\endcsname}%
%      \fi
%      ##7}%
%  \else
%    \def\@svsechd{%
%      ##6{\hskip ##3\relax
%     \@svsec ##9}%
%     \csname ##1mark\endcsname{##8}%
%     \addcontentsline{toc}{##1}{%
%       \ifnum ##2>\c@secnumdepth \else
%        \protect\numberline{\csname the##1\endcsname}%
%       \fi
%       ##7}}%
%  \fi
%  \@xsect{##5}}
%}

\renewcommand{\appendix}{\par
%  \setcounter{chapter}{0}%
%  \setcounter{section}{0}%
%  \gdef\@chapapp{\appendixname}%
%  \gdef\thechapter{\@Alph\c@chapter}%
  \set@appendix@chapter
  \anappendixtrue
  \chapterstyle{appendixdefault}%
}

\newcounter{APPchapter}\setcounter{APPchapter}{0}%
\newcounter{APPsection}[APPchapter]\setcounter{APPsection}{0}%
\newcounter{APPsubsection}[APPsection]\setcounter{APPsubsection}{0}%

\def\set@appendix@chapter{%
  \gdef\@chapapp{\appendixname}%
  \gdef\thechapter{\Alph{APPchapter}}%
  \gdef\thesection{\thechapter.\arabic{APPsection}}% 
%  \counterwithout{figure}{chapter}\counterwithout{table}{chapter}%
  \counterwithin{figure}{APPchapter}\counterwithin{table}{APPchapter}%
  \counterwithin{equation}{APPchapter}%
  \renewcommand\thefigure{\thechapter.\arabic{figure}}%
  \renewcommand\thetable{\thechapter.\arabic{table}}%
  \renewcommand\theequation{\thechapter.\arabic{equation}}%
  \set@appendix@chapsec
  \renewcommand\hchaptertitlehead{\appendixname\:\thechapter}%
}

%%% here, I will renewcommand chapterstyle,
%%% to recover chapterstyle after appendices.
\renewcommand{\chapterstyle}[1]{%
  \@nameuse{chs@#1}%
  \ifanappendix\else\gdef\CURR@chpstyle{#1}\fi
}

\def\restore@appendices@chapter{%
  \refreshprepostchapters
  \gdef\thechapter{\arabic{chapter}}%
  \gdef\thesection{\thechapter.\arabic{section}}%
  \def\hchaptertitlehead{\pre@chapter\:\thechapter}%
  \counterwithin{figure}{chapter}\counterwithin{table}{chapter}%
  \restorechapsec
  \@ifundefined{CURR@chapstyle}{\chapterstyle{default}}%
     {\expandafter\expandafter\chapterstyle{\CURR@chapstyle}}%
}

\renewcommand{\@resets@pp}{%
  \par
  \@ppsavesec
%  \setcounter{section}{0}%
%  \setcounter{chapter}{0}%
%  \renewcommand\@chapapp{\appendixname}%
%  \renewcommand\thechapter{\@Alph\c@chapter}%
  \set@appendix@chapter
  \chapterstyle{appendixdefault}
  \restoreapp
}

\renewenvironment{appendices}%
  {\@resets@pp\anappendixtrue}%
  {\@ppsaveapp\@pprestoresec\restore@appendices@chapter\anappendixfalse}

\renewenvironment{subappendices}{%
  \@resets@ppsub
  \def\addappheadtotoc{\phantomsection\addcontentsline{toc}{section}{\appendixtocname}} % <- mempatch 2.3
  \ifnamesubappendix
    \def\sectionname{\protect\subappendixname}%
    \def\@seccntformat##1{\@ifundefined{##1name}{}{\csname ##1name\endcsname\ }%
        \csname the##1\endcsname\quad}
  \fi
  }{} 

%% default pagestyle
\if@defaulthangulpagestyle
 \pagestyle{hangul}
\fi

%%% 2021/03/03: adjustwidth
\newdimen\memucsadjustwidthtopsep
\renewenvironment{adjustwidth}[2]{%
  \begin{list}{}{%
  	\ifdim\onelineskip=\baselineskip
		\memucsadjustwidthtopsep\z@\else
		\memucsadjustwidthtopsep=\dimexpr\onelineskip-\baselineskip\relax
	\fi
%    \topsep\z@%
	\topsep.5\memucsadjustwidthtopsep
    \listparindent\parindent%
    \parsep\parskip%
    \@ifmtarg{#1}{\setlength{\leftmargin}{\z@}}%
                 {\setlength{\leftmargin}{#1}}%
    \@ifmtarg{#2}{\setlength{\rightmargin}{\z@}}%
                 {\setlength{\rightmargin}{#2}}%
    }
    \item[]}{\end{list}}

\renewenvironment{adjustwidth*}[2]{%
  \begin{list}{}{%
%    \topsep\z@%
	\topsep.5\memucsadjustwidthtopsep
    \listparindent\parindent%
    \parsep\parskip%
    \checkoddpage
    \ifoddpage  % odd numbered page
      \@ifmtarg{#1}{\setlength{\leftmargin}{\z@}}%
                   {\setlength{\leftmargin}{#1}}%
      \@ifmtarg{#2}{\setlength{\rightmargin}{\z@}}%
                   {\setlength{\rightmargin}{#2}}%
    \else       % even numbered page
      \@ifmtarg{#2}{\setlength{\leftmargin}{\z@}}%
                   {\setlength{\leftmargin}{#2}}%
      \@ifmtarg{#1}{\setlength{\rightmargin}{\z@}}%
                   {\setlength{\rightmargin}{#1}}%
    \fi
    }
    \item[]}{\end{list}}


%%% lists
%%% newly added
\newcommand*{\oblivoirlists}{%
  \@ifstar{\ob@sfirmlists}{\ob@firmlists}}

\newcommand*{\ob@sfirmlists}{
  \setlength{\partopsep}{\z@ \@plus \p@ \@minus \p@}%
  \parsepi = 0.0833\onelineskip \@plus 0.04\onelineskip \@minus \p@
  \itemsepi = \parsepi
  \topsepi = \parsepi
  \parsepii = 0.04\onelineskip \@plus \p@ \@minus \p@
  \topsepii = \parsepi
  \topsepiii = \parsepii
  \everylistparindent\listparindent}

\newcommand*{\ob@firmlists}{
  \setlength{\partopsep}{0.083\baselineskip \@plus 0.02\onelineskip
                                         \@minus 0.02\onelineskip}%
  \parsepi = 0.0833\onelineskip \@plus 0.04\onelineskip \@minus \p@
  \itemsepi = \parsepi
  \topsepi = \parsepi
  \parsepii = 0.04\onelineskip \@plus \p@ \@minus \p@
  \topsepii = \parsepi
  \topsepiii = \parsepii
  \everylistparindent\listparindent}

\newcommand{\oblivoirlist}{%
  \setlength{\itemsep}{0.3\itemsep}\setlength{\parskip}{0.3\parskip}}

\newcommand\obadjustlists{%
  \global\let\defaultlist\firmlist
  \global\let\defaultlists\firmlists
  \global\let\firmlist\oblivoirlist
  \global\let\firmlists\oblivoirlists
  \defaultlists
}


%%% \ReleaseMacros
%%% newly added
\ExplSyntaxOn 
\NewDocumentCommand \ReleaseMacros { m }
{
	\clist_set:Nn \l_tmpa_clist { #1 }
	\clist_map_inline:Nn \l_tmpa_clist
	{
		\cs_undefine:N ##1
	}
}
\@onlypreamble\ReleaseMacros

\ExplSyntaxOff


%%%% trim K mark
\providecommand*{\tmarkKtm}{%
  \begin{picture}(0,0)%
    \unitlength 1mm
    \thinlines
    \put(0,4){\line(0,1){8}}
  \end{picture}}
\providecommand*{\tmarkKml}{%
  \begin{picture}(0,0)%
    \unitlength 1mm
    \thinlines
    \put(-4,0){\line(-1,0){8}}
  \end{picture}}
\providecommand*{\tmarkKmr}{%
  \begin{picture}(0,0)%
    \unitlength 1mm
    \thinlines
    \put(4,0){\line(1,0){8}}
  \end{picture}}
\providecommand*{\tmarkKbm}{%
  \begin{picture}(0,0)%
    \unitlength 1mm
    \thinlines
    \put(0,-12){\line(0,1){8}}
  \end{picture}}
\providecommand*{\Ktrimpictl}{%
  \begin{picture}(0,0)
    \unitlength 1mm
    \thinlines
    \put(-4,0){\line(-1,0){10}}
    \put(0,4){\line(0,1){10}}
  \end{picture}}
\providecommand*{\Ktrimpictr}{%
  \begin{picture}(0,0)
    \unitlength 1mm
    \thinlines
    \put(4,0){\line(1,0){10}}
    \put(0,4){\line(0,1){10}}
  \end{picture}}
\providecommand*{\Ktrimpicbl}{%
  \begin{picture}(0,0)
    \unitlength 1mm
    \thinlines
    \put(-4,0){\line(-1,0){10}}
    \put(0,-4){\line(0,-1){10}}
  \end{picture}}
\providecommand*{\Ktrimpicbr}{%
  \begin{picture}(0,0)
    \unitlength 1mm
    \thinlines
    \put(4,0){\line(1,0){10}}
    \put(0,-4){\line(0,-1){10}}
  \end{picture}}
 
\providecommand*{\trimKmarks}{%
  \let\tmarktl\Ktrimpictl
  \let\tmarktr\Ktrimpictr
  \let\tmarkbl\Ktrimpicbl
  \let\tmarkbr\Ktrimpicbr
  \let\tmarktm\tmarkKtm
  \let\tmarkbm\tmarkKbm
  \let\tmarkml\tmarkKml
  \let\tmarkmr\tmarkKmr
}



\endinput

%%% 2015/10/15: \@part, \@chapter renewal.
%%% 2015/08/07: default chapter style, postchapternum (hoze & gromov)
