% This class requires memoir class and memhangul-ucs packages.
% The tex file composed with this class must be encoded in UTF-8 format  without BOM.
\NeedsTeXFormat{LaTeX2e}
\def\filedate{2005/11/01}
\def\fileversion{2.07}
\ProvidesClass{hozemanucs}[\filedate\ Document Class for Technical Manuals]

%  positions for the page tab when the paper is A4.
\newcounter{pagetabx}
\newcounter{pagetaby}
\newcounter{pagetabwidth}
\newcounter{pagetabheight}
\newcounter{pagetabysep}
\setcounter{pagetabx}{197}
\setcounter{pagetaby}{220}
\setcounter{pagetabwidth}{10}
\setcounter{pagetabheight}{10}
\setcounter{pagetabysep}{-15}
\newcommand\pagetabswitch{}

\newif\if@latin\@latintrue
\newif\if@vartwo\@vartwofalse
\newif\if@bindingoffset\@bindingoffsetfalse
\newif\if@chprule\@chprulefalse
\newif\if@sftitle\@sftitlefalse
\newif\if@largetitle\@largetitlefalse
\newif\if@nosecnum\@nosecnumfalse
\newif\if@docuver\@docuverfalse
\newif\if@symbol\@symbolfalse
\newif\if@uniformwidth\@uniformwidthfalse
\newif\if@nofig\@nofigfalse
\newif\if@flfig\@flfigfalse
\newif\if@fltab\@fltabfalse
\newif\if@flchp\@flchpfalse
\newif\if@pdffig\@pdffigfalse
\newif\if@jpgfig\@jpgfigfalse
\newif\if@figframe\@figframefalse
\newif\if@shortcap\@shortcapfalse
\newif\if@dispffn\@dispffnfalse
\newif\if@footrule\@footrulefalse
\newif\if@ganaappendix\@ganaappendixfalse
\newif\if@pdfbookmark\@pdfbookmarkfalse
\newif\if@bookmarknumber\@bookmarknumberfalse
\newif\if@grayrow\@grayrowfalse
\newif\if@cfontseries\@cfontseriesfalse
\newif\if@raggedlist\@raggedlistfalse
\newif\if@defaultstyle\@defaultstylefalse
\newif\if@ebook\@ebookfalse
\newif\if@cftclearpage\@cftclearpagefalse
%\newif\if@nolayout\@nolayoutfalse

%  options for memoir >>>
\DeclareOption{a3paper}{\PassOptionsToClass\CurrentOption{memoir}}
\DeclareOption{a4paper}{\PassOptionsToClass\CurrentOption{memoir}}
\DeclareOption{a5paper}{\PassOptionsToClass\CurrentOption{memoir}}
\DeclareOption{a6paper}{\PassOptionsToClass\CurrentOption{memoir}}
\DeclareOption{b3paper}{\PassOptionsToClass\CurrentOption{memoir}}
\DeclareOption{b4paper}{\PassOptionsToClass\CurrentOption{memoir}}
\DeclareOption{b5paper}{\PassOptionsToClass\CurrentOption{memoir}}
\DeclareOption{b6paper}{\PassOptionsToClass\CurrentOption{memoir}}
\DeclareOption{letterpaper}{\PassOptionsToClass\CurrentOption{memoir}}
\DeclareOption{legalpaper}{\PassOptionsToClass\CurrentOption{memoir}}
\DeclareOption{executivepaper}{\PassOptionsToClass\CurrentOption{memoir}}
\DeclareOption{ebook}{\PassOptionsToClass\CurrentOption{memoir}}
\DeclareOption{landscape}{\PassOptionsToClass\CurrentOption{memoir}}
\DeclareOption{9pt}{\PassOptionsToClass\CurrentOption{memoir}}
\DeclareOption{10pt}{\PassOptionsToClass\CurrentOption{memoir}}
\DeclareOption{11pt}{\PassOptionsToClass\CurrentOption{memoir}}
\DeclareOption{12pt}{\PassOptionsToClass\CurrentOption{memoir}}
\DeclareOption{14pt}{\PassOptionsToClass\CurrentOption{memoir}}
\DeclareOption{17pt}{\PassOptionsToClass\CurrentOption{memoir}}
\DeclareOption{twoside}{\PassOptionsToClass\CurrentOption{memoir}}
\DeclareOption{oneside}{\PassOptionsToClass\CurrentOption{memoir}}
\DeclareOption{onecolumn}{\PassOptionsToClass\CurrentOption{memoir}}
\DeclareOption{twocolumn}{\PassOptionsToClass\CurrentOption{memoir}}
\DeclareOption{openright}{\PassOptionsToClass\CurrentOption{memoir}}
\DeclareOption{openleft}{\PassOptionsToClass\CurrentOption{memoir}}
\DeclareOption{openany}{\PassOptionsToClass\CurrentOption{memoir}}
\DeclareOption{final}{\PassOptionsToClass\CurrentOption{memoir}}
\DeclareOption{draft}{\PassOptionsToClass\CurrentOption{memoir}}
\DeclareOption{ms}{\PassOptionsToClass\CurrentOption{memoir}}
\DeclareOption{showtrims}{\PassOptionsToClass\CurrentOption{memoir}}
\DeclareOption{leqno}{\PassOptionsToClass\CurrentOption{memoir}}
\DeclareOption{fleqn}{\PassOptionsToClass\CurrentOption{memoir}}
\DeclareOption{openbib}{\PassOptionsToClass\CurrentOption{memoir}}
\DeclareOption{article}{\PassOptionsToClass\CurrentOption{memoir}}

% options for graphic packages >>>
\DeclareOption{figuresright}{\PassOptionsToPackage\CurrentOption{rotating}}
\DeclareOption{figuresleft}{\PassOptionsToPackage\CurrentOption{rotating}}
\DeclareOption{pdffig}{\@pdffigtrue}
\DeclareOption{jpgfig}{\@jpgfigtrue}

% options for hozemanucs >>>
\DeclareOption{latin}{\@latintrue}
\DeclareOption{cjk}{\@latinfalse}
\DeclareOption{bindingoffset}{\@bindingoffsettrue}
\DeclareOption{vartwo}{\@vartwotrue\@flfigtrue\@fltabtrue}
\DeclareOption{pagetab}{\renewcommand\pagetabswitch{\pagetab}}
\DeclareOption{footrule}{\@footruletrue}
\DeclareOption{dispffn}{\@dispffntrue}
\DeclareOption{symbol}{\@symboltrue}
\DeclareOption{flfig}{\@flfigtrue}
\DeclareOption{fltab}{\@fltabtrue}
\DeclareOption{figframe}{\@figframetrue}
\DeclareOption{nofig}{\@nofigtrue\@symbolfalse\@dispffnfalse\@figframefalse}
\DeclareOption{shortcap}{\@shortcaptrue}
\DeclareOption{flchp}{\@flchptrue}
\DeclareOption{sftitle}{\@sftitletrue}
\DeclareOption{largetitle}{\@largetitletrue}
\DeclareOption{nosecnum}{\@nosecnumtrue}
\DeclareOption{chprule}{\@chpruletrue}
\DeclareOption{ganaappendix}{\@ganaappendixtrue}
\DeclareOption{bookmark}{\@pdfbookmarktrue}
\DeclareOption{bookmarknum}{\@pdfbookmarktrue\@bookmarknumbertrue}
\DeclareOption{docuver}{\@docuvertrue}
\DeclareOption{docuinfo}{\@docuvertrue\@dispffntrue}
\DeclareOption{grayrow}{\@grayrowtrue}
\DeclareOption{cfontseries}{\@cfontseriestrue}
\DeclareOption{raggedlist}{\@raggedlisttrue}
\DeclareOption{defaultstyle}{\@defaultstyletrue}
\DeclareOption{cftcont}{\@cftclearpagefalse}
\DeclareOption{cftsep}{\@cftclearpagetrue}
\DeclareOption{ebook}{\@ebooktrue}

%\DeclareOption{nolayout}{\@nolayouttrue}

\DeclareOption*{}
\ExecuteOptions{figuresright}
\ProcessOptions

\LoadClass{memoir}
\RequirePackage{type1ec}
\RequirePackage{calc}
\RequirePackage{ifthen}
\RequirePackage{here}
\RequirePackage{graphicx}
\RequirePackage{rotating}
\RequirePackage{color}
\RequirePackage{colortbl}
\RequirePackage{eso-pic}
\RequirePackage{fancybox}
\RequirePackage{fixltx2e}
\RequirePackage{enumitem}
\RequirePackage{textcomp}
\RequirePackage{pifont}
\RequirePackage{dingbat}
\RequirePackage{amssymb}
\RequirePackage[geometry]{ifsym}
\RequirePackage{wasysym}
\RequirePackage{marvosym}
\RequirePackage{sistyle}
\RequirePackage{layout}
%\RequirePackage{ifpdf}
%\RequirePackage{minitoc}
%\RequirePackage{mtcpatchmem}

%For making Contetns to be section level when article option specified.
\newcommand{\NewListOf}[3]{%
  \@namedef{ext@#2}{#2}
  \@ifundefined{c@#2depth}{\newcounter{#2depth}}{}
  \setcounter{#2depth}{1}
  \@namedef{#2mark}{\markboth{#3}{#3}}
  \@namedef{#1}{\@ifstar{\@nameuse{@star#2}}{\@nameuse{@plain#2}}}
  \@namedef{@star#2}{%
    \ensureonecol
    \par
    \begingroup
      \@nameuse{@#2maketitle}
      \@starttoc{#2}%
    \endgroup
    \restorefromonecol}
  \@namedef{@plain#2}{%
    \ensureonecol
    \par
    \begingroup
      \@nameuse{@#2maketitle}
      \phantomsection
      \ifartopt
      \addcontentsline{toc}{section}{#3}
      \else
      \addcontentsline{toc}{chapter}{#3}
      \fi
      \@starttoc{#2}%
    \endgroup
    \restorefromonecol}
  \@namedef{@#2maketitle}{%
   {\parindent\z@ \parskip\cftparskip
    \interlinepenalty\@M
    \section*{#3}%
    \thispagestyle{plain}%
   }}
}
\NewListOf{TableOfContents}{toc}{\contentsname}
\ifartopt\counterwithout{section}{chapter}\fi

% division
\setsecnumdepth{subsection}
\maxsecnumdepth{subsection}
\settocdepth{subsection}

%  paper layout
\newcommand\normalmargin{% 
\if@bindingoffset
 \settrimmedsize{\stockheight}{.95\stockwidth}{*} 
 \settrims{0pt}{0pt}
\else
 \settrimmedsize{\stockheight}{\stockwidth}{*}
\fi
\setulmarginsandblock{.115\paperheight}{.11\paperheight}{*}
 \setheadfoot{.045\paperheight}{.045\paperheight}
 \setlrmarginsandblock{.125\paperwidth}{.125\paperwidth}{*} 
 \checkandfixthelayout
}

\newcommand\vartwomargin{% 
\if@bindingoffset
 \settrimmedsize{\stockheight}{.975\stockwidth}{*} 
 \settrims{0pt}{0pt}
\else
 \settrimmedsize{\stockheight}{\stockwidth}{*}
\fi
\setulmarginsandblock{.115\paperheight}{.11\paperheight}{*}
\setlrmarginsandblock{.3\paperwidth}{.125\paperwidth}{*}
\setheadfoot{.045\paperheight}{.045\paperheight}
\if@bindingoffset
 \setmarginnotes{.025\paperwidth}{.1\paperwidth}{0pt} 
\else
 \setmarginnotes{.05\paperwidth}{.125\paperwidth}{0pt}
\fi
\checkandfixthelayout
\if@bindingoffset
 \let\evensidemargin\foremargin
\else
 \let\evensidemargin\oddsidemargin
\fi
}

% header & footer
\newcommand\hffont{\rmfamily}

\newcommand\normalfolio{
\makepsmarks{ruled}{\@foliomarks}
\makeevenhead{ruled}{\hffont\bfseries\thepage}{}{\hffont\leftmark}
\makeoddhead{ruled}{\hffont\rightmark}{}{\hffont\bfseries\thepage}
\makeevenfoot{ruled}{}{}{\DocuInfo}
\makeoddfoot{ruled}{\docuversion}{}{}
\if@footrule\makefootrule{ruled}{\textwidth}{\normalrulethickness}{\footruleskip}\fi
\pagestyle{ruled}
}

\newlength\orgtextwidth
\newlength\vartwosecindent
\setlength\vartwosecindent{0pt}

\newcommand\vartwofolio{
\setlength\vartwosecindent{\marginparwidth}
\addtolength\vartwosecindent{\marginparsep}
\copypagestyle{vartwo}{companion}
\setlength{\headwidth}{\textwidth}
\addtolength{\headwidth}{\vartwosecindent}
\makerunningwidth{vartwo}{\headwidth}
\makeheadrule{vartwo}{\headwidth}{\normalrulethickness}
\if@footrule
\makefootrule{vartwo}{\headwidth}{\normalrulethickness}{\footruleskip}
\fi
\makepsmarks{vartwo}{\@foliomarks}
\makeheadposition{vartwo}{flushright}{flushright}{flushright}{flushright}
\makeevenhead{vartwo}{\hffont\bfseries\thepage}{}{\hffont\leftmark}
\makeoddhead{vartwo}{\hffont\rightmark}{}{\hffont\bfseries\thepage}
\makeevenfoot{vartwo}{}{}{\DocuInfo}
\makeoddfoot{vartwo}{\docuversion}{}{}
\setsecindent{-\vartwosecindent}
\setsubsecindent{-\vartwosecindent}
\setsubsubsecindent{-\vartwosecindent}
\pagestyle{vartwo}
}
\makeoddhead{plain}{}{}{\hffont\bfseries\thepage}
\makeoddfoot{plain}{}{}{}

\newcommand{\@foliomarks}{% 
 \if@nosecnum
 \maxsecnumdepth{chapter}
 \renewcommand{\chaptermark}[1]{\pagetabswitch\markboth{##1}{}}
 \renewcommand{\sectionmark}[1]{\markright{##1}} 
 \else
 \renewcommand{\chaptermark}[1]{\pagetabswitch\markboth{##1}{}}
 \renewcommand{\sectionmark}[1]{\markright{\thesection~##1}} 
 \fi
}

\newcommand\thispart{\jobname.tex}

\newcommand\docuversion{}
\if@docuver
\renewcommand\docuversion{%
\hffont\number\year-\number\month-\number\day~\thispart}
\fi

\newlength\docuinfowidth
\newcommand\DocuInfo{}

\newcommand\docuinfo[1]{% 
\settowidth\docuinfowidth{~\hffont#1~}% 
\addtolength\docuinfowidth{6pt}% 
\renewcommand\DocuInfo{%
\raisebox{-1ex}{\parbox{1.1\docuinfowidth}{\rule{\docuinfowidth}{.4pt}\\[-1pt]% 
\rule{4pt}{16pt}\raisebox{4pt}{~\hffont#1~}}}% 
}}

\newcommand\whichfile[1]{\renewcommand\thispart{#1}}

\addtoiargdef{\include}{% 
	\renewcommand\thispart{#1.tex}% 
}{}

\newcommand\indexpage[1][\@empty]{% 
\clearpagetab
\ifx #1\@empty% 
\if@vartwo
 \makeevenhead{vartwo}
 {\hffont{\bfseries\thepage}\quad\rightmark}{}{\hffont\leftmark}
 \makeoddhead{vartwo}
 {\hffont\rightmark}{}{\hffont\leftmark\quad{\bfseries\thepage}}
\else
 \makeevenhead{ruled}
 {\hffont{\bfseries\thepage}\quad\rightmark}{}{\hffont\leftmark}
 \makeoddhead{ruled}
 {\hffont\rightmark}{}{\hffont\leftmark\quad{\bfseries\thepage}}
\fi
\else
 \makeevenhead{#1}
 {\hffont{\bfseries\thepage}\quad\rightmark}{}{\hffont\leftmark}
 \makeoddhead{#1}
 {\hffont\rightmark}{}{\hffont\leftmark\quad{\bfseries\thepage}}
\fi
}

\newcommand\idxmark[1]{{#1}\markboth{#1}{#1}}

%index
\newcommand\symbolheadname{Symbol}
\newcommand\numberheadname{Number}

%display
\newlength\lcdwidth
\newlength\lcdmargin
\setlength\lcdmargin{1em}
\newcommand\setlcdmargin[1]{\setlength\lcdmargin{#1}}
\newlength\dspacewidth
\newcommand\lcdfont{\uifont}
\newcommand\lcdback{white}
\newcommand\setlcdback[1]{\renewcommand\lcdback{#1}}

\newcommand\dspace[1]{% 
 \settowidth\dspacewidth{\lcdfont#1}% 
 \hspace*{\dspacewidth}% 
}

\newcommand{\lcd}[2][\@empty]{% 
\setlength\fboxsep{.5em}%
\ifx #1\@empty\else\setlength\lcdmargin{#1}\fi
\setlength\lcdwidth{\linewidth-2\lcdmargin}%
\addtolength\lcdwidth{-2\fboxsep}%
\vspace{\entitytopsep}\par\noindent\hspace*{\lcdmargin}% 
\fcolorbox{black}{\lcdback}{\parbox{\lcdwidth}{\lcdfont#2}}%
\hfill\vspace{\entitybotsep}% 
}

% query
\newcommand\queryfont{\slshape}

\newcommand{\query}[1][\@empty]{\stepcounter{query}
%\fbox{?}%
[?\thequery]
\ifx #1\@empty \addcontentsline{loq}{query}{[?\thequery]~\thesection}% 
\else{\queryfont #1}
\addcontentsline{loq}{query}{\[?\thequery]~\thesection~#1}% 
\fi}

% list of fiure file names
\newcommand\lffname{List of Figure File}
\newlistof{listoffigurefiles}{lff}{\lffname}
\newlistentry{figfile}{lff}{0}
\newcommand\loqname{List of Query}
\newlistof{listofqueries}{loq}{\loqname}
\newlistentry{query}{loq}{0}

%  caption% 
\newcommand\capfont{\rmfamily\small\bfseries}
\newcommand\legendfont{\rmfamily\small}
\captionnamefont{\capfont}
\captiontitlefont{\capfont}
\newfixedcaption{\figcaption}{figure}
\newfixedcaption{\tabcaption}{table}
\newcommand\figsidecaption[1]{\captionstyle{\raggedright}\figcaption{#1}}
\newcommand\tabsidecaption[1]{\captionstyle{\raggedright}\tabcaption{#1}}

\renewcommand{\fnum@figure}[1]{\figurename~\thefigure:~}
\renewcommand{\fnum@table}[1]{\tablename~\thetable:~}
%\setlength\abovecaptionskip{.5ex plus .25ex minus .25ex}
%\setlength\belowcaptionskip{.5ex plus .25ex minus .25ex}

% illustration
\if@pdffig
 \DeclareGraphicsExtensions{.pdf,.jpg}
 \DeclareGraphicsRule{.pdf}{eps}{.bb}{}
 \DeclareGraphicsRule{.jpg}{eps}{.bb}{} 
\fi

\if@jpgfig
 \DeclareGraphicsExtensions{.jpg,.pdf}
 \DeclareGraphicsRule{.pdf}{eps}{.bb}{}
 \DeclareGraphicsRule{.jpg}{eps}{.bb}{} 
\fi

\newlength\entitytopsep
\newlength\entitybotsep
\setlength\entitytopsep{\floatsep}
\setlength\entitybotsep{\floatsep}

\newlength{\leftboxwidth}
\newlength{\rightboxwidth}
\newlength{\interwidth}
\setlength\interwidth{.5em plus .25em minus .25em}
\newlength\extrawidth
\setlength\extrawidth{1.25\interwidth}

\newcommand{\boxalign}{t}
\newcommand{\figalign}{\mbox{}\\[-.75\baselineskip]}
\newcommand{\figscale}{1}
\newcommand\orgscale{}
\newcommand\setfigscale[1]{\renewcommand\figscale{#1}}
\newcommand\restorefigscale{\let\figscale\orgscale}
\newenvironment{FigScale}[1]{\setfigscale{#1}}{\restorefigscale}
\if@bindingoffset\setfigscale{0.975}\fi

\setlength\fboxrule{.25pt}

%  safety & illustration% 
\newcommand\illustcaptionstyle{}
\newcommand\illustjustify{}

\if@latin
\renewcommand\illustjustify{\raggedright}
\else
%\renewcommand\illustjustify{\sloppy}
%\renewcommand\illustjustify{\fussy}
\renewcommand\illustcaptionstyle{\hangcaption}
\fi

\newsavebox{\safetymark}
\newcommand{\alertlabelfont}{\normalsize\sffamily}
\newcommand{\alertfont}{}
\newlength\alertlabelwidth
\newcommand\alertlabelcase{}%\MakeUppercase

\if@latin
\newcommand\setalertlabelwidth[1]{% 
 \settowidth\alertlabelwidth%
 {\alertlabelfont\alertlabelcase{#1}}\@uniformwidthtrue}
\else
\newcommand\setalertlabelwidth[1]{% 
 \settowidth\alertlabelwidth{\alertlabelfont#1}\@uniformwidthtrue}
\fi

\newlength\alerttopsep
\newlength\alertbotsep
\setlength\alerttopsep{.5\baselineskip}
\setlength\alertbotsep{.5\baselineskip}
\newlength\alertruletopsep
\newlength\alertrulebotsep
\setlength\alertruletopsep{-.5ex}
\setlength\alertrulebotsep{-1.5ex}

\newcommand\alert[3][\@empty]{%  
\if@symbol% 
 \ifx #1\@empty% 
   \sbox{\safetymark}{\includegraphics{CautionMark}}% 
 \else% 
   \sbox{\safetymark}{\includegraphics{#1}}% 
 \fi% 
\fi% 
\if@uniformwidth% 
 \setlength\leftboxwidth{\alertlabelwidth}% 
\else% 
 \settowidth\leftboxwidth{% 
  \ifthenelse{\boolean{@latin}}%
  {\alertlabelfont\alertlabelcase{#2}}{\alertlabelfont#2}}% 
\fi% 
 \ifthenelse{\boolean{@symbol}}{\addtolength\leftboxwidth{1.2\wd\safetymark}}{}% 
 \setlength{\rightboxwidth}{\linewidth-\leftboxwidth-\extrawidth}% 
 \vspace{\alerttopsep}\par\noindent% 
 \begin{minipage}[t]{\textwidth}
 \begin{minipage}[t]{\leftboxwidth}
  \vspace{\alertruletopsep}\hfill\par
   \ifthenelse{\boolean{@symbol}}{\raisebox{-1.2ex}{\usebox{\safetymark}}}{}% 
   \alertlabelfont\ifthenelse{\boolean{@latin}}{\alertlabelcase{#2}}{#2}% 
 \end{minipage}\hspace{\interwidth}
 \begin{minipage}[t]{\rightboxwidth}
  \vspace{\alertruletopsep}\hrulefill\par
  \illustjustify \alertfont #3 
  \vspace{\alertrulebotsep}\par\hrulefill
 \end{minipage}% 
 \end{minipage}\vspace{\alertbotsep}\par% 
}

\newcommand\symbolon{\setboolean{@symbol}{true}}
\newcommand\symboloff{\setboolean{@symbol}{false}}

\newcommand\tip[2]{{\setboolean{@symbol}{false}\alert{#1}{#2}}}

\newlength\flagheight{}
\newcommand\flagmark{}
\newcommand\flagfont{\normalsize\sffamily}
\newcommand\setflagfont[1]{\renewcommand\flagfont{#1}}

\newcommand\flag[1][\@empty]{%
\if@symbol%
  \ifx #1\@empty %
    \renewcommand{\flagmark}{\includegraphics{flag}}%
  \else %
    \renewcommand{\flagmark}{\includegraphics{#1}}%
 \fi%
\else%
  \ifx #1\@empty%
  \renewcommand{\flagmark}{\smallpencil}%
 \else%
  \renewcommand{\flagmark}{\flagfont #1}%
 \fi%
\fi%
  \mbox{}\marginpar{\raggedleft\flagmark}%
}

\newcommand\shortcaptiontrue{\setboolean{@shortcap}{true}}
\newcommand\shortcaptionfalse{\setboolean{@shortcap}{false}}
\newcommand\shortcaptionon{\setboolean{@shortcap}{true}}
\newcommand\shortcaptionoff{\setboolean{@shortcap}{false}}

\newlength\figframesep
\setlength\figframesep{5pt}
\newlength\orgframesep
\newcommand\setfigframesep[1]{\setlength\figframesep{#1}}
\newcommand\restorefigframesep{\setlength\figframesep{\orgframesep}}

\if@nofig
\renewcommand\includegraphics[2][\@empty]{{\LARGE FIGURE HERE}}
\fi

\newcommand\listcapfig[3][\@empty]{% 
\vspace{.75\entitytopsep}\par\noindent
\begin{minipage}{\linewidth}% 
\if@flfig\captionstyle{\raggedright}\else\centering\fi% 
\if@figframe
\setlength\fboxsep{\figframesep}% 
\fbox{\includegraphics[scale=\figscale]{#2}}
\else\includegraphics[scale=\figscale]{#2}\fi% 
\ifthenelse{\boolean{@dispffn}}{\dispfigfile{#2}}{}% 
\if@shortcap% 
 \ifx#1\@empty\figcaption{#3}\else\figcaption[#1]{#3}\fi\label{fig:#2}% 
\else \figcaption{#3}\ifx#1\@empty\label{fig:#2}\else\label{fig:#1}\fi\fi% 
\end{minipage}% 
\vspace{.75\entitybotsep}% 
}
 
\newcommand\listfig[1]{% 
\vspace{.75\entitytopsep}\par\noindent
\begin{minipage}{\linewidth}% 
\if@flfig\else\centering\fi% 
\if@figframe
\setlength\fboxsep{\figframesep}% 
\fbox{\includegraphics[scale=\figscale]{#1}}
\else\includegraphics[scale=\figscale]{#1}\fi% 
\ifthenelse{\boolean{@dispffn}}{\dispfigfile{#1}}{}% 
\end{minipage}
\vspace{.75\entitybotsep}% 
}

\newcommand{\placecapfig}[3][\@empty]{% ignore vartwo margin.
\vspace{\entitytopsep}\par\noindent%
\begin{minipage}{\linewidth}% 
\if@flfig\captionstyle{\raggedright}\else\centering\fi% 
\settowidth{\leftboxwidth}{\includegraphics[scale=\figscale]{#2}}% 
\if@figframe\addtolength\leftboxwidth{2\figframesep}\fi%  
\ifdim \leftboxwidth > \textwidth
 \addtolength{\leftboxwidth}{-\textwidth}% 
 \hspace*{-1.01\leftboxwidth}% 
 \captionnamefont{\hspace*{-1.01\leftboxwidth}\capfont}% 
\fi
\if@figframe
\setlength\fboxsep{\figframesep}% 
\fbox{\includegraphics[scale=\figscale]{#2}}
\else\includegraphics[scale=\figscale]{#2}\fi% 
\ifthenelse{\boolean{@dispffn}}{\dispfigfile{#2}}{}% 
\if@shortcap
 \ifx#1\@empty\figcaption{#3}\else\figcaption[#1]{#3}\fi\label{fig:#2}
\else \figcaption{#3}\ifx#1\@empty\label{fig:#2}\else\label{fig:#1}\fi\fi% 
\end{minipage}\vspace{.75\entitybotsep}% 
}

\newcommand{\placeupcapfig}[3][\@empty]{% ignore vartwo margin.
\vspace{.75\entitytopsep}\par\noindent%
\begin{minipage}{\textwidth}% 
\if@flfig\captionstyle{\raggedright}\else\centering\fi% 
\settowidth{\leftboxwidth}{\includegraphics[scale=\figscale]{#2}}% 
\if@figframe\addtolength\leftboxwidth{2\figframesep}\fi%  
\ifdim \leftboxwidth > \textwidth
 \addtolength{\leftboxwidth}{-\textwidth}% 
 \captionnamefont{\hspace*{-1.01\leftboxwidth}\capfont}% 
 \if@shortcap\ifx#1\@empty\figcaption{#3}\else\figcaption[#1]{#3}\fi\label{fig:#2}% 
 \else \figcaption{#3}\ifx#1\@empty\label{fig:#2}\else\label{fig:#1}\fi\fi
 \hspace*{-1.01\leftboxwidth}% 
 \if@figframe
 \setlength\fboxsep{\figframesep}% 
 \fbox{\includegraphics[scale=\figscale]{#2}}
 \else\includegraphics[scale=\figscale]{#2}\fi% 
 \ifthenelse{\boolean{@dispffn}}{\dispfigfile{#2}}{}% 
\else
 \if@shortcap\ifx#1\@empty\figcaption{#3}\else\figcaption[#1]{#3}\fi\label{fig:#2}% 
 \else \figcaption{#3}\ifx#1\@empty\label{fig:#2}\else\label{fig:#1}\fi\fi
 \if@figframe
 \setlength\fboxsep{\figframesep}% 
 \fbox{\includegraphics[scale=\figscale]{#2}}
 \else\includegraphics[scale=\figscale]{#2}\fi% 
 \ifthenelse{\boolean{@dispffn}}{\dispfigfile{#2}}{}% 
\fi
\end{minipage}\vspace{\entitybotsep}
}

\newcommand{\wideupcapfig}[3][\@empty]{
\vspace{.75\entitytopsep}\par\noindent%
\begin{minipage}{\textwidth}% 
 \if@flfig\captionstyle{\raggedright}\else\centering\fi% 
 \captionnamefont{\hspace*{-\vartwosecindent}\capfont}% 
 \if@shortcap\ifx#1\@empty\figcaption{#3}\else\figcaption[#1]{#3}\fi\label{fig:#2}% 
 \else \figcaption{#3}\ifx#1\@empty\label{fig:#2}\else\label{fig:#1}\fi\fi% 
 \hspace*{-\vartwosecindent}% 
 \if@figframe
 \setlength\fboxsep{\figframesep}% 
 \setlength\leftboxwidth{\orgtextwidth - 2\figframesep}%
 \fbox{\includegraphics[width=\leftboxwidth]{#2}}%
 \else\includegraphics[width=\orgtextwidth]{#2}\fi% 
 \ifthenelse{\boolean{@dispffn}}{\dispfigfile{#2}}{}% 
\end{minipage}\vspace{\entitybotsep}%
}

\newcommand{\widecapfig}[3][\@empty]{
\vspace{.75\entitytopsep}\par\noindent%
\begin{minipage}{\textwidth}% 
 \hspace*{-\vartwosecindent}% 
 \if@figframe
 \setlength\fboxsep{\figframesep}% 
 \setlength\leftboxwidth{\orgtextwidth - 2\figframesep}%
 \fbox{\includegraphics[width=\leftboxwidth]{#2}}%
 \else\includegraphics[width=\orgtextwidth]{#2}\fi% 
 \ifthenelse{\boolean{@dispffn}}{\dispfigfile{#2}}{}% 
 \if@flfig\captionstyle{\raggedright}\else\centering\fi% 
 \captionnamefont{\hspace*{-\vartwosecindent}\capfont}% 
 \if@shortcap\ifx#1\@empty\figcaption{#3}\else\figcaption[#1]{#3}\fi\label{fig:#2}% 
 \else \figcaption{#3}\ifx#1\@empty\label{fig:#2}\else\label{fig:#1}\fi\fi% 
\end{minipage}\vspace{\entitybotsep}\par%
}


\newcommand{\placefig}[2][\@empty]{%  
\vspace{\entitytopsep}\par\noindent%
\begin{minipage}{\textwidth}% 
\if@flfig\else\centering\fi% 
\settowidth{\leftboxwidth}{\includegraphics[scale=\figscale]{#2}}% 
\if@figframe\addtolength\leftboxwidth{2\figframesep}\fi%  
\ifdim \leftboxwidth > \textwidth
 \addtolength{\leftboxwidth}{-\textwidth}% 
 \hspace*{-1.01\leftboxwidth}% 
\fi
\if@figframe
 \setlength\fboxsep{\figframesep}% 
 \fbox{\includegraphics[scale=\figscale]{#2}}
 \else\includegraphics[scale=\figscale]{#2}\fi% 
\ifthenelse{\boolean{@dispffn}}{\dispfigfile{#2}}{}% 
\ifx#1\@empty\else\legend{\legendfont#1}\fi% 
\end{minipage}\vspace{\entitybotsep}\par% 
}

\newlength{\sfigwidth}
\newlength{\sfigheight}

\newcommand{\placesidecapfig}[3][\@empty]{%  rotated figure with caption 
\settowidth{\leftboxwidth}{\includegraphics[scale=\figscale]{#2}} 
\ifdim \leftboxwidth > \sfigwidth
 \begin{sidewaysfigure}%  
  \if@vartwo\vspace*{-\vartwosecindent}\fi% 
  \if@figframe
  \setlength\fboxsep{\figframesep}% 
  \fbox{%
  \includegraphics[keepaspectratio=true,height=\sfigheight,width=\sfigwidth]{#2}}
  \else
  \includegraphics[keepaspectratio=true,height=\sfigheight,width=\sfigwidth]{#2}\fi%   
  \ifthenelse{\boolean{@dispffn}}{\dispfigfile{#2}}{}% 
  \captionstyle{\raggedright}% 
  \if@shortcap\ifx#1\@empty\caption{#3}\else\caption[#1]{#3}\fi\label{fig:#2}% 
  \else \caption{#3}\ifx#1\@empty\label{fig:#2}\else\label{fig:#1}\fi\fi% 
 \end{sidewaysfigure}
\else
 \begin{sidewaysfigure}%  
  \if@vartwo\vspace*{-\vartwosecindent}\fi% 
  \if@figframe
  \setlength\fboxsep{\figframesep}% 
  \fbox{\includegraphics[scale=\figscale]{#2}}
  \else\includegraphics[scale=\figscale]{#2}\fi% 
  \ifthenelse{\boolean{@dispffn}}{\dispfigfile{#2}}{}% 
  \captionstyle{\raggedright}% 
  \if@shortcap\ifx#1\@empty\caption{#3}\else\caption[#1]{#3}\fi\label{fig:#2}% 
  \else \caption{#3}\ifx#1\@empty\label{fig:#2}\else\label{fig:#1}\fi\fi% 
 \end{sidewaysfigure}
\fi
}

\newcommand{\placesidefig}[1]{%  rotated figure with caption 
\settowidth{\leftboxwidth}{\includegraphics[scale=\figscale]{#1}} 
\ifdim \leftboxwidth > \sfigwidth
\begin{sidewaysfigure}%  
 \if@vartwo\vspace*{-\vartwosecindent}\fi% 
 \if@figframe
 \setlength\fboxsep{\figframesep}% 
 \fbox{%
 \includegraphics[keepaspectratio=true,height=\sfigheight,width=\sfigwidth]{#1}
}
\else
\includegraphics[keepaspectratio=true,height=\sfigheight,width=\sfigwidth]{#1}
\fi%   
  \ifthenelse{\boolean{@dispffn}}{\dispfigfile{#1}}{}%   
 \end{sidewaysfigure}
\else
 \begin{sidewaysfigure}%  
  \if@vartwo\vspace*{-\vartwosecindent}\fi% 
  \if@figframe
  \setlength\fboxsep{\figframesep}% 
  \fbox{\includegraphics[scale=\figscale]{#1}}
  \else\includegraphics[scale=\figscale]{#1}\fi% 
  \ifthenelse{\boolean{@dispffn}}{\dispfigfile{#1}}{}% 
 \end{sidewaysfigure}
\fi
}

\newcommand\illusthangcaptiontrue{\renewcommand\illustcaptionstyle{\hangcaption}}
\newcommand\illusthangcaptionfalse{\renewcommand\illustcaptionstyle{}}
\newcommand\illusthangcaptionon{\renewcommand\illustcaptionstyle{\hangcaption}}
\newcommand\illusthangcaptionoff{\renewcommand\illustcaptionstyle{}}

\newcommand\illustcaption[3][\@empty]{\vspace*{#3}%
\captionstyle{\raggedright}\illustcaptionstyle% 
\if@shortcap% 
 \ifx#1\@empty\figcaption{#2}\else\figcaption[#1]{#2}\fi% 
\else% 
 \figcaption{#2}\ifx#1\@empty\else\label{fig:#1}\fi% 
\fi}

\newcommand{\illustfig}[3][\@empty]{%  illustration without caption
\settowidth{\leftboxwidth}{\includegraphics[scale=\figscale]{#2}}% 
\if@figframe\addtolength\leftboxwidth{2\figframesep}\fi%  
\setlength{\rightboxwidth}{\linewidth-\leftboxwidth-\extrawidth}% 
 \vspace{\entitytopsep}\par\noindent 
 \begin{minipage}[t]{\textwidth}
 \begin{minipage}[\boxalign]{\leftboxwidth}
  \figalign
  \if@figframe
  \setlength\fboxsep{\figframesep}% 
  \fbox{\includegraphics[scale=\figscale]{#2}}
  \else\includegraphics[scale=\figscale]{#2}\fi% 
  \ifthenelse{\boolean{@dispffn}}{\dispfigfile{#2}}{}% 
  \ifx#1\@empty\else\legend{\legendfont#1}\fi% 
 \end{minipage}\hspace{\interwidth}
 \begin{minipage}[\boxalign]{\rightboxwidth}% \small
  \illustjustify  #3  
 \end{minipage}
 \end{minipage}\vspace{\entitybotsep}% 
}

\newcommand{\illustcapfig}[4][\@empty]{%  illustration with caption and label
\settowidth{\leftboxwidth}{\includegraphics[scale=\figscale]{#2}}% 
\if@figframe\addtolength\leftboxwidth{2\figframesep}\fi% 
\setlength{\rightboxwidth}{\linewidth-\leftboxwidth-\extrawidth}%  
\vspace{\entitytopsep}\par\noindent 
\begin{minipage}[t]{\textwidth}
 \begin{minipage}[\boxalign]{\leftboxwidth}
  \figalign% 
  \if@figframe
  \setlength\fboxsep{\figframesep}% 
  \fbox{\includegraphics[scale=\figscale]{#2}}
  \else\includegraphics[scale=\figscale]{#2}\fi% 
  \ifthenelse{\boolean{@dispffn}}{\dispfigfile{#2}}{}%    
  \if@flfig\captionstyle{\raggedright}\else\centering\fi% 
   \illustcaptionstyle% 
   \if@shortcap\ifx#1\@empty\figcaption{#3}\else\figcaption[#1]{#3}\fi\label{fig:#2}% 
   \else \figcaption{#3}\ifx#1\@empty\label{fig:#2}\else\label{fig:#1}\fi\fi% 
 \end{minipage}\hspace{\interwidth}
 \begin{minipage}[\boxalign]{\rightboxwidth}% \small
 \illustjustify  #4
 \end{minipage}
 \end{minipage}\vspace{\entitybotsep}% 
}

\newcommand{\rillustcapfig}[4][\@empty]{%  illustration with caption and label
\settowidth{\rightboxwidth}{\includegraphics[scale=\figscale]{#2}}% 
\if@figframe\addtolength\rightboxwidth{2\figframesep}\fi%  
\setlength{\leftboxwidth}{\linewidth-\rightboxwidth-\extrawidth}% 
\vspace{\entitytopsep}\par\noindent 
\begin{minipage}[t]{\textwidth}
\begin{minipage}[\boxalign]{\leftboxwidth}
 \illustjustify #4
\end{minipage}\hspace{\interwidth}
\begin{minipage}[\boxalign]{\rightboxwidth}
 \figalign
 \if@figframe
 \setlength\fboxsep{\figframesep}% 
 \fbox{\includegraphics[scale=\figscale]{#2}}
 \else\includegraphics[scale=\figscale]{#2}\fi% 
 \ifthenelse{\boolean{@dispffn}}{\dispfigfile{#2}}{}% 
 \if@flfig\captionstyle{\raggedright}\else\centering\fi% 
  \illustcaptionstyle% 
  \if@shortcap%
  \ifx#1\@empty\figcaption{#3}\else\figcaption[#1]{#3}\fi\label{fig:#2}
  \else \figcaption{#3}\ifx#1\@empty\label{fig:#2}\else\label{fig:#1}\fi\fi% 
\end{minipage}
\end{minipage}\vspace{\entitybotsep}% 
}

\newcommand{\rillustfig}[3][\@empty]{%  illustration without caption
\settowidth{\rightboxwidth}{\includegraphics[scale=\figscale]{#2}}% 
\if@figframe\addtolength\rightboxwidth{2\figframesep}\fi
\setlength{\leftboxwidth}{\linewidth-\rightboxwidth-\extrawidth}
 \vspace{\entitytopsep}\par\noindent 
 \begin{minipage}[t]{\textwidth}
 \begin{minipage}[\boxalign]{\leftboxwidth}
 \illustjustify #3
 \end{minipage}\hspace{\interwidth}
 \begin{minipage}[\boxalign]{\rightboxwidth}    
  \figalign% 
  \if@figframe
  \setlength\fboxsep{\figframesep}
  \fbox{\includegraphics[scale=\figscale]{#2}}% 
  \else\includegraphics[scale=\figscale]{#2}\fi% 
  \ifthenelse{\boolean{@dispffn}}{\dispfigfile{#2}}{}% 
  \ifx#1\@empty\else\legend{\legendfont#1}\fi% 
 \end{minipage}
 \end{minipage}\vspace{\entitybotsep}% 
}

%% to insert a figure into the text portion of \illustfig
\newcommand\insertfig[1]{\figalign%
\if@figframe
 \setlength\fboxsep{\figframesep}
 \fbox{\includegraphics[scale=\figscale]{#1}}
 \else\includegraphics[scale=\figscale]{#1}\fi%
\ifthenelse{\boolean{@displayfilename}}{\dispfigfile{#1}}{}%
}

\newcommand\linefigscale{}
\let\linefigscale\figscale
\newcommand\setlinefigscale[1]{\renewcommand\linefigscale{#1}}

\newcommand\linefig[2][\@empty]{%  figure in text line
\ifx #1\@empty \raisebox{-.5ex}{\includegraphics[scale=\linefigscale]{#2}}% 
\else \raisebox{#1}{\includegraphics[scale=\linefigscale]{#2}}% 
\fi\ifthenelse{\boolean{@dispffn}}{\displfigfile{#2}}{}% 
}
 
\newlength\ffnwidth
\newcommand\dispffnfont{\tiny\ttfamily}

\newcommand{\dispfigfile}[1]{% 
 \settowidth\ffnwidth{\dispffnfont#1}\addtolength\ffnwidth{1em}% 
 \nolinebreak\hspace{-\ffnwidth}\fcolorbox{black}{white}{\dispffnfont#1}% 
 \stepcounter{figfile}\addcontentsline{lff}{figfile}{\thefigfile) \thesection~#1}% 
}

\newcommand{\displfigfile}[1]{% 
 {\dispffnfont#1}%
 \stepcounter{figfile}\addcontentsline{lff}{figfile}{\thefigfile) \thesection~#1}
}

%  table% 
\definecolor{textgray}{gray}{0.4}
\definecolor{backgray}{gray}{0.9}
\newcommand\grayheadrow{\rowcolor{backgray}}
\newcounter{rowcnt}
\newcommand\startgrayrow{\setcounter{rowcnt}{0}}
\newcommand\startwhiterow{\setcounter{rowcnt}{-1}}
\gdef\RowColor{backgray}

\newcommand\grayrowtrue{\setboolean{@grayrow}{true}}
\newcommand\grayrowfalse{\setboolean{@grayrow}{false}}
\newcommand\grayrowon{\setboolean{@grayrow}{true}}
\newcommand\grayrowoff{\setboolean{@grayrow}{false}}

\if@grayrow
\newcommand\grayrow{%         
        \rowcolor{\RowColor}%    
        \ifodd\therowcnt% 
                \gdef\RowColor{white}% 
        \else%                 
                \gdef\RowColor{backgray}% 
        \fi%   
        \stepcounter{rowcnt}%       
}
\else
\newcommand\grayrow{\stepcounter{rowcnt}}
\fi

\newcolumntype{Y}{>{\raggedleft\arraybackslash}X}
\newcolumntype{Z}{>{\centering\arraybackslash}X}
\newcommand{\tabfont}{\rmfamily\small}
\newcommand\specitem{\textbf{Item}}
\newcommand\specdescription{\textbf{Specification}}
\setlength\heavyrulewidth{.75pt}
\setlength\lightrulewidth{.25pt}

\def\hlinewd#1{%
\noalign{\ifnum0=`}\fi\hrule \@height #1 \futurelet\reserved@a\@xhline}
\newcommand{\hthickline}{\hlinewd{.06em}}

\newlength\speciwidth
\newlength\specdwidth
\setlength\speciwidth{.275\linewidth}
\setlength\specdwidth{.575\linewidth}
\newcommand\specfont{\tabfont}
\newcommand\setspecwidth[2]{
 \setlength\speciwidth{#1}
 \setlength\specdwidth{#2}
}
\newcommand\setspectowidth[2]{
 \settowidth\speciwidth{\specfont #1}
 \settowidth\specdwidth{\specfont #2}
}

\newenvironment{spec}
{\setlength\tabcolsep{3pt}
 \vspace{\entitytopsep}\par\noindent\startgrayrow
 \begin{minipage}{\linewidth}
 \if@fltab \else\centering\fi\specfont 
 \begin{tabular}{p{\speciwidth}p{\specdwidth}}\toprule
 \specitem & \specdescription \\\midrule
}{%
 \bottomrule\end{tabular}
 \end{minipage}\vspace{\entitybotsep}\par
 } 

\newenvironment{capspec}[2][\@empty]{
\setlength\tabcolsep{3pt}
\vspace{\entitytopsep}\par\noindent\startgrayrow
\begin{minipage}{\linewidth}
 \if@fltab\captionstyle{\raggedright}\else\centering\fi
 \if@shortcap\ifx#1\@empty\tabcaption{#2}\else\tabcaption[#1]{#2}\fi
 \else \tabcaption{#2}  \ifx #1\@empty \else \label{tab:#1}\fi\fi%  
 \specfont\startgrayrow% 
 \renewcommand\baselinestretch{1}
 \begin{tabular}{p{\speciwidth}p{\specdwidth}}\toprule
 \specitem & \specdescription \\\midrule
}{%
 \bottomrule\end{tabular}
 \end{minipage}\vspace{\entitybotsep}\par
}

\newenvironment{captable}[2][\@empty]
{\vspace{\entitytopsep}\par\noindent\startgrayrow 
 \begin{minipage}{\linewidth}
  \if@fltab\captionstyle{\raggedright}\else\centering\fi%  
 \if@shortcap\ifx#1\@empty\tabcaption{#2}\else\tabcaption[#1]{#2}\fi
 \else \tabcaption{#2}  \ifx #1\@empty \else \label{tab:#1}\fi\fi%  
 \tabfont}
{\end{minipage}\vspace{\entitybotsep}}\par

\newenvironment{nocaptable}
{\vspace{\entitytopsep}\par\noindent\startgrayrow 
 \begin{minipage}{\linewidth}
 \if@fltab \else\centering\fi\tabfont}
{\end{minipage}\vspace{\entitybotsep}}\par

\newcommand{\placecaptable}[3][\@empty]{
\vspace{\entitytopsep}\par\noindent
\begin{minipage}{\linewidth}
\if@fltab\captionstyle{\raggedright}\else\centering\fi% 
\settowidth{\leftboxwidth}{\tabfont #3}% 
\ifdim \leftboxwidth > \textwidth% 
 \addtolength{\leftboxwidth}{-\textwidth}% 
 \captionnamefont{\hspace*{-1.001\leftboxwidth}\capfont}% 
 \if@shortcap\ifx#1\@empty\tabcaption{#2}\else\tabcaption[#1]{#2}\fi
 \else \tabcaption{#2}  \ifx #1\@empty \else \label{tab:#1}\fi\fi%  
 \hspace*{-1.01\leftboxwidth}\startgrayrow\tabfont #3% 
\else% 
 \if@shortcap\ifx#1\@empty\tabcaption{#2}\else\tabcaption[#1]{#2}\fi
 \else \tabcaption{#2}  \ifx #1\@empty \else \label{tab:#1}\fi\fi%  
 \startgrayrow\tabfont #3% 
\fi% 
\end{minipage}
\vspace{\entitybotsep}\par
}

\newcommand{\placenocaptable}[1]{
\vspace{\entitytopsep}\par\noindent
\begin{minipage}{\linewidth}% 
\if@fltab\else\centering\fi% 
\settowidth{\leftboxwidth}{\tabfont #1}% 
\ifdim \leftboxwidth > \textwidth% 
 \addtolength{\leftboxwidth}{-\textwidth}% 
 \hspace*{-1.01\leftboxwidth}\startgrayrow\tabfont #1% 
\else% 
 \tabfont\startgrayrow #1% 
\fi% 
\end{minipage}
\vspace{\entitybotsep}\par
}

\newcommand{\illustcaptable}[4][\@empty]{%
\settowidth{\leftboxwidth}{\tabfont #3}%
\setlength{\rightboxwidth}{\linewidth-\leftboxwidth-\extrawidth}% 
\vspace{\entitytopsep}\par\noindent %
\begin{minipage}[t]{\textwidth}%
\begin{minipage}[\boxalign]{\leftboxwidth}%
 \vspace{-\abovecaptionskip}%
 \if@fltab\captionstyle{\raggedright}\else\centering\fi%  
 \if@shortcap\ifx#1\@empty\tabcaption{#2}\else\tabcaption[#1]{#2}\fi
 \else \tabcaption{#2}  \ifx #1\@empty \else \label{tab:#1}\fi\fi%  
 \startgrayrow\tabfont #3%   
\end{minipage}\hspace{\interwidth}%
\begin{minipage}[\boxalign]{\rightboxwidth}%
 \illustjustify  #4%  
\end{minipage}% 
\end{minipage}\vspace{\entitybotsep}% 
}

\newcommand{\illusttable}[2]{%
\settowidth{\leftboxwidth}{\tabfont #1}%
\setlength{\rightboxwidth}{\linewidth-\leftboxwidth-\extrawidth}% 
\vspace{\entitytopsep}\par\noindent %
\begin{minipage}[t]{\textwidth}%
\begin{minipage}[\boxalign]{\leftboxwidth}% 
 \figalign\startgrayrow\tabfont #1%   
\end{minipage}\hspace{\interwidth}%
\begin{minipage}[\boxalign]{\rightboxwidth}%
 \illustjustify  #2%  
\end{minipage}% 
\end{minipage}\vspace{\entitybotsep}% 
}

\newcommand{\rillustcaptable}[4][\@empty]{%
\settowidth{\rightboxwidth}{\tabfont #3}%
\setlength{\leftboxwidth}{\linewidth-\rightboxwidth-\extrawidth}% 
\vspace{\entitytopsep}\par\noindent %
\begin{minipage}[t]{\textwidth}%
\begin{minipage}[\boxalign]{\leftboxwidth}%
  \illustjustify  #4%  
\end{minipage}\hspace{\interwidth}%
\begin{minipage}[\boxalign]{\rightboxwidth}%
 \if@fltab\captionstyle{\raggedright}\else\centering\fi%  
 \if@shortcap\ifx#1\@empty\tabcaption{#2}\else\tabcaption[#1]{#2}\fi
 \else \tabcaption{#2}  \ifx #1\@empty \else \label{tab:#1}\fi\fi%  
 \startgrayrow\tabfont #3% 
\end{minipage}% 
\end{minipage}\vspace{\entitybotsep}% 
}

\newcommand{\rillusttable}[2]{%
\settowidth{\rightboxwidth}{\tabfont #1}%
\setlength{\leftboxwidth}{\linewidth-\rightboxwidth-\extrawidth}% 
\vspace{\entitytopsep}\par\noindent %
\begin{minipage}[t]{\textwidth}%
\begin{minipage}[\boxalign]{\leftboxwidth}%
  \illustjustify  #2%  
\end{minipage}\hspace{\interwidth}%
\begin{minipage}[\boxalign]{\rightboxwidth}% 
 \figalign\startgrayrow\tabfont #1% 
\end{minipage}% 
\end{minipage}\vspace{\entitybotsep}% 
}

% page tab
\definecolor{tabback}{gray}{0.07}
\newcommand\pagetabfont{\LARGE\sffamily\bfseries}
\newcommand\pagetab{% 
\ClearShipoutPicture
\if@mainmatter
\AddToShipoutPicture{%   
\setlength{\unitlength}{1mm}% 
\ifthenelse{\isodd{\value{page}}}% 
 {\put(\value{pagetabx}, \value{pagetaby})% 
 {\colorbox{tabback}{\makebox(\value{pagetabwidth},\value{pagetabheight})% 
 {\textcolor{white}{\pagetabfont~\thechapter~}}}}    
 }{}%          
}\addtocounter{pagetaby}{\value{pagetabysep}}\fi% 
}

\newcommand\clearpagetab{
\if@mainmatter
\else
\ClearShipoutPicture
\fi
}

%  index% 
\newcommand*\IndexBf[1]{\textbf{\hyperpage{#1}}}
\newcommand\indef[1]{\index{#1|IndexBf}}
\newcommand\term[1]{#1\index{#1}}
\newcommand\termdef[1]{\index{#1|IndexBf}#1}
\newcommand\terms[2]{\term{#1}\allowbreak{} (\term{#2})}
\newcommand\termsdef[2]{\termdef{#1}\allowbreak{} (\termdef{#2})}

% ideograph
\newcommand\uifont{\sffamily}
\newcommand\ui[1]{{\uifont #1}}
\newcommand\uii[2][\@empty]{%
\ifx #1\@empty {\uifont #2}\index{#2?{\uifont#2}}%
\else{\uifont #2}\index{#1?{\uifont#1}}%
\fi}

\newcommand\digitfont{\footnotesize}
\newcommand{\digit}[1]{\textifsym{\digitfont #1}}
% \newcommand\inch{\textrm{\textacutedbl\ }} 

\newlength\buttonwidth
\newlength\tmpwidth
\newcommand\buttonfont{\uifont\small}

\newcommand{\button}[2][\@empty]{% 
 \setlength{\fboxsep}{2pt}% 
 \ifx #1\@empty%  
  \ovalbox{\buttonfont #2}% 
 \else% 
  \settowidth\buttonwidth{\buttonfont #1}% 
  \settowidth\tmpwidth{\buttonfont #2}% 
  \ifdim\buttonwidth<\tmpwidth\setlength\buttonwidth{\tmpwidth} \fi%   
  \rule{0pt}{1.25\baselineskip}% 
  \ovalbox{\parbox{\buttonwidth}{\renewcommand\baselinestretch{1}\buttonfont#1\\#2}}% 
  \vspace{.25\baselineskip}% 
 \fi
}

\newcommand\buttonname{Button}

\newcommand{\buttoni}[2][\@empty]{% 
 \setlength{\fboxsep}{2pt}% 
 \ifx #1\@empty%  
  \ovalbox{\buttonfont #2}% 
  \index{#2?{\uifont#2}}\index{\buttonname!#2?{\uifont#2}}% 
 \else% 
  \settowidth\buttonwidth{\buttonfont #1}% 
  \settowidth\tmpwidth{\buttonfont #2}% 
  \ifdim\buttonwidth<\tmpwidth\setlength\buttonwidth{\tmpwidth} \fi%   
  \rule{0pt}{1.25\baselineskip}% 
  \ovalbox{\parbox{\buttonwidth}{\renewcommand\baselinestretch{1}\buttonfont#1\\#2}}% 
  \vspace{.25\baselineskip}% 
  \index{#1 #2?{\uifont#1 #2}}\index{\buttonname!#1 #2?{\uifont#1 #2}}% 
 \fi% 
}

\newcommand{\cirnum}[1]{% 
\ifthenelse{\equal{\f@size}{11}}{\raisebox{.2ex}{\textcircled{\small #1}}}{% 
\ifthenelse{\equal{\f@size}{9}}%
 {\raisebox{.2ex}{\textcircled{\scriptsize #1}}}{\raisebox{.2ex}{\textcircled{\footnotesize #1}}}}% 
}

% list
\newcommand\deflabelfamily{}
\newcommand\deflabelseries{\bfseries}
\newcommand\deflabelfont{\deflabelfamily\deflabelseries} 
\newcommand\defmarker{}
\newcommand\defdelim{:}
\newcommand\setdefmarker[1]{\renewcommand\defmarker{#1}}
\newcommand\setdefdelim[1]{\renewcommand\defdelim{#1}}
\newcommand\setdeflabelfont[2]{%
 \renewcommand\deflabelfamily{#1}
 \renewcommand\deflabelseries{#2}
}

\newenvironment{explist}[1][\quad]
{\begin{list}{}{%
 \renewcommand{\makelabel}[1]{\deflabelfont ##1\index{{\deflabelfamily##1}}\hfill}% 
 \settowidth{\labelwidth}{\deflabelfont #1}%   
 \setlength\labelsep{0em}
 \setlength{\leftmargin}{\labelwidth} 
}}{\end{list}}

\newcommand\listtype{}

\newenvironment{deflist}[1][\qquad]
{\begin{list}{}{\listtype
 \renewcommand{\makelabel}[1]{\defmarker{\deflabelfont ##1}\defdelim\hfill}
 \settowidth{\labelwidth}{\defmarker{\deflabelfont #1}\defdelim}%   
 \setlength{\leftmargin}{\labelwidth+\labelsep} 
}}{\end{list}}

\newenvironment{indlist}[1][\qquad]
{\begin{list}{}{\listtype
 \renewcommand{\makelabel}[1]{%
 \index{##1?{\deflabelfamily##1}}\defmarker{\deflabelfont ##1}\defdelim\hfill}
 \settowidth{\labelwidth}{\defmarker{\deflabelfont #1}\defdelim}  
 \setlength{\leftmargin}{\labelwidth+\labelsep} 
}}{\end{list}}

\newcounter{defenum}
\renewcommand{\thedefenum}{\cirnum{\arabic{defenum}}}
\newcommand\setdefnum[1]{\setcounter{defenum}{#1} \addtocounter{defenum}{-1}}
\newcommand\pdefnum{\renewcommand{\thedefenum}{\arabic{defenum})}}
\newcommand\cdefnum{\renewcommand{\thedefenum}{\cirnum{\arabic{defenum}}}}

\newenvironment{defenum}[1][\quad]
{\begin{list}{defenum}{\listtype
 \setcounter{defenum}{0} 
 \renewcommand{\makelabel}[1]{%
 \stepcounter{defenum}\thedefenum~{\deflabelfont ##1}\defdelim\hfill}%  
 \settowidth\labelwidth{\thedefenum~{\deflabelfont #1}\defdelim}
 \setlength\leftmargin{\labelwidth+\labelsep}
 %\setlength\labelwidth{1em}
 %\setlength\leftmargin{1.5em} 
}}{\end{list}}

\newenvironment{indenum}[1][\quad]
{\begin{list}{defenum}{\listtype
 \setcounter{defenum}{0}  
 \renewcommand{\makelabel}[1]{\index{##1?{\deflabelfamily##1}}%
 \stepcounter{defenum}\thedefenum~{\deflabelfont ##1}\defdelim\hfill}
 \settowidth\labelwidth{\thedefenum~{\deflabelfont #1}\defdelim}
 \setlength\leftmargin{\labelwidth+\labelsep}
}}{\end{list}}

\newcommand\attachlist[1][\@empty]{%
\vspace{-\entitybotsep} \vspace{-\topsep}
\ifx\@empty#1\else \setdefnum{#1}\fi
}

\if@raggedlist
\renewcommand{\deflist}[1][\@empty]{%
\ifnum \@itemdepth >\thr@@\@toodeep\else
\advance\@itemdepth\@ne
\ifx \@empty #1\else % optional argument
\@namedef{labelitem\romannumeral\the\@itemdepth}{#1}%
\fi
\edef\@itemitem{labelitem\romannumeral\the\@itemdepth}%
\expandafter
\list
\csname\@itemitem\endcsname
{\def\makelabel##1{\hss\llap{\defmarker{\deflabelfont ##1}\defdelim}}}%
\fi}
\let\enddeflist =\endlist  
\renewcommand{\indlist}[1][\@empty]{%
\ifnum \@itemdepth >\thr@@\@toodeep\else
\advance\@itemdepth\@ne
\ifx \@empty #1\else % optional argument
\@namedef{labelitem\romannumeral\the\@itemdepth}{#1}%
\fi
\edef\@itemitem{labelitem\romannumeral\the\@itemdepth}%
\expandafter
\list
\csname\@itemitem\endcsname
{\def\makelabel##1{%
\hss\llap{\index{##1?{\deflabelfamily##1}}\defmarker{\deflabelfont ##1}\defdelim}}}%
\fi}
\let\endindlist =\endlist  
\fi

\@ifpackageloaded{hyperref}{}{
\if@latin
\RequirePackage{mempatch}
\RequirePackage{xr}
%\ifpdf
%   \RequirePackage{ucshyper}
%\else
   \if@pdfbookmark
      \if@bookmarknumber
          \RequirePackage[dvipdfm,plainpages=false,bookmarksnumbered]{hyperref}  
      \else
          \RequirePackage[dvipdfm,plainpages=false]{hyperref}    
      \fi
  \else
     \RequirePackage[plainpages=false,bookmarks=false]{hyperref}    
  \fi   
%\fi
\else
% for dhucs
\RequirePackage{xr-hyper}
\if@pdfbookmark
 \if@bookmarknumber
 \RequirePackage[dvipdfm,plainpages=false,CJKbookmarks,bookmarksnumbered=true]%
 {hyperref}
 \else
 \RequirePackage[dvipdfm,plainpages=false,CJKbookmarks]{hyperref}
 \fi
 \AtBeginDvi{\special{pdf:tounicode UTF8-UCS2}}    
\else
  \RequirePackage[dvipdfm,plainpages=false,bookmarks=false]{hyperref}
 \fi   
\fi
\RequirePackage{mempatch}
\RequirePackage{memhfixc}   
}

\@ifpackageloaded{memhangul-ucs}{}{
  \if@latin
   \RequirePackage[onehalfspacing]{setspace}      
  \else
   \RequirePackage[interworddefault, nonfrench]{memhangul-ucs}      
  \fi 
}

% PDF
\newcommand\ebook[2]{
\hypersetup{pdftitle={#1}, pdfauthor={#2},colorlinks=true,linkcolor=blue}
}

\newcommand\pbook[2]{
 \hypersetup{pdftitle={#1}, pdfauthor={#2}}
}

\newcommand\bookinfo[2]{
\if@ebook\ebook{#1}{#2}\else\pbook{#1}{#2}\fi
}

% chapter
\newcommand\chpfont{\normalfont\bfseries}
\newcommand\chpalign{\raggedleft}
\if@flchp\renewcommand\chpalign{\raggedright}\fi

\makechapterstyle{default}{% 
  \renewcommand{\chapnamefont}{\chpalign\huge\chpfont}
  \renewcommand{\chapnumfont}{\chpalign\huge\chpfont}
  \renewcommand{\chaptitlefont}{\chpalign\Huge\chpfont}
  \setlength{\beforechapskip}{50pt}
  \setlength{\midchapskip}{20pt}
  \setlength{\afterchapskip}{40pt}
  \if@chprule  
    \renewcommand{\printchaptertitle}[1]{\hrule\vskip\onelineskip \chaptitlefont ##1}
    \renewcommand{\afterchaptertitle}{\vskip\onelineskip\hrule\vskip\afterchapskip}
  \fi
}

%  for Appendix
\makechapterstyle{appendixdefault}{% 
  \renewcommand{\prechapternum}{\chapnumfont\@chapapp}
  \renewcommand{\postchapternum}{}
  \renewcommand{\chapternamenum}{\enskip}
  \setlength{\beforechapskip}{50pt}
  \setlength{\midchapskip}{20pt}
  \setlength{\afterchapskip}{40pt}
  \if@chprule  
    \renewcommand{\printchaptertitle}[1]{\hrule\vskip\onelineskip \chaptitlefont ##1}
    \renewcommand{\afterchaptertitle}{\vskip\onelineskip\hrule\vskip\afterchapskip}
  \fi
}

% section 

\newcommand\secnewpagetrue{% 
 \setsechook{\ifthenelse{\equal{\value{section}}{0}}{}{\clearpage}}}
\newcommand\subsecnewpagetrue{% 
 \setsubsechook{\ifthenelse{\equal{\value{subsection}}{0}}{}{\clearpage}}}
\newcommand\subsubsecnewpagetrue{% 
 \setsubsubsechook{\ifthenelse{\equal{\value{subsubsection}}{0}}{}{\clearpage}}}
\newcommand\secnewpagefalse{\setsechook{}}
\newcommand\subsecnewpagefalse{\setsubsechook{}}
\newcommand\subsubsecnewpagefalse{\setsubsubsechook{}}

\newcommand\secnewpageon{% 
 \setsechook{\ifthenelse{\equal{\value{section}}{0}}{}{\clearpage}}}
\newcommand\subsecnewpageon{% 
 \setsubsechook{\ifthenelse{\equal{\value{subsection}}{0}}{}{\clearpage}}}
\newcommand\subsubsecnewpageon{% 
 \setsubsubsechook{\ifthenelse{\equal{\value{subsubsection}}{0}}{}{\clearpage}}}
\newcommand\secnewpageoff{\setsechook{}}
\newcommand\subsecnewpageoff{\setsubsechook{}}
\newcommand\subsubsecnewpageoff{\setsubsubsechook{}}

\newcommand\secfont{\normalfont\bfseries}

\if@largetitle
 \setsecheadstyle{\LARGE\secfont\raggedright}
 \setsubsecheadstyle{\Large\secfont\raggedright}
 \setsubsubsecheadstyle{\large\secfont\raggedright}
\else
 \setsecheadstyle{\Large\secfont\raggedright}
 \setsubsecheadstyle{\large\secfont\raggedright}
 \setsubsubsecheadstyle{\normalsize\secfont\raggedright}
\fi

\if@sftitle
\renewcommand\chpfont{\sffamily\bfseries}
\renewcommand\secfont{\sffamily}
\renewcommand\capfont{\sffamily\small}
\renewcommand\hffont{\sffamily}
\fi

\if@docuver\else
\renewcommand{\listofqueries}{}
\renewcommand{\listoffigurefiles}{}
\renewcommand{\query}[1][\@empty]{}
\fi

\addtodef{\printindex}{\renewcommand\thispart{\jobname.ind}\indexpage}{}
\if@cftclearpage
\addtodef{\tableofcontents}%
 {\renewcommand\thispart{\jobname.toc}}%
 {\clearforchapter}
\addtodef{\listoffigures}
 {\renewcommand\thispart{\jobname.lof}}
 {\clearforchapter}
\addtodef{\listoftables}
 {\renewcommand\thispart{\jobname.lot}}
 {\clearforchapter}
\addtodef{\listoffigurefiles}
 {\renewcommand\thispart{\jobname.lff}}
 {\clearforchapter}
\addtodef{\listofqueries}
 {\renewcommand\thispart{\jobname.loq}}
 {\clearforchapter}
\else
\addtodef{\tableofcontents}
 {\renewcommand\thispart{\jobname.toc}}{}
\addtodef{\listoffigures}{\renewcommand\thispart{\jobname.lof}}{}
\addtodef{\listoftables}{\renewcommand\thispart{\jobname.lot}}{}
\addtodef{\listoffigurefiles}{\renewcommand\thispart{\jobname.lff}}{}
\addtodef{\listofqueries}{\renewcommand\thispart{\jobname.loq}}{}
\fi

% To make hangul counters available in the macros of the enumitem package.
\if@latin
\else
 \def\enit@normlabel#1{\begingroup \enit@refstar \arabic \enit@refstar \alph
 \enit@refstar \Alph \enit@refstar \roman \enit@refstar \Roman
 \enit@refstar \gana \enit@refstar \jaso
 \enit@refstar \value \enit@refstar \@arabic \enit@refstar \@alph
 \enit@refstar \@Alph \enit@refstar \@roman \enit@refstar \@Roman
 \protected@xdef \enit@a {#1}\endgroup}    
\fi

%reference

\newcommand\onname{on}
\newcommand\ptref[1]{\tablerefname\ \ref{tab:#1} \onname\ \pagerefname\ \pageref{tab:#1}}
\newcommand\pfref[1]{\figurerefname\ \ref{fig:#1} \onname\ \pagerefname\ \pageref{fig:#1}}
\renewcommand\sectionrefname{Section}

%  paragraph
\if@defaultstyle
\else
  \if@latin
    \setlength\parskip{.3\baselineskip}
    \addtodef{\@minipagerestore}{\setlength\parskip{.3\baselineskip}}{}
    \renewcommand\Cref[1]{\chapterrefname\ \ref{chp:#1} \textbf{\titleref{chp:#1}}}
    \renewcommand\Sref[1]{\sectionrefname\ \ref{sec:#1} \onname\ \pagename\ \pageref{sec:#1}}
    \renewcommand\fref[1]{\figurerefname\ \ref{fig:#1}}
   \renewcommand\tref[1]{\tablerefname\ \ref{tab:#1}}
   \renewcommand\pref[1]{\pagerefname\ \pageref{#1}}
  \else   
   \setlength\alertruletopsep{-1ex}
   \setlength\alertrulebotsep{-1.75ex}
    \renewcommand\Cref[1]{\ref{chp:#1} \chapterrefname\  \textbf{\titleref{chp:#1}}}
    \renewcommand\Sref[1]{\pageref{sec:#1} \pagerefname\ \ref{sec:#1} \sectionrefname}
    \renewcommand\fref[1]{\figurerefname\ \ref{fig:#1}}
   \renewcommand\tref[1]{\tablerefname\ \ref{tab:#1}}
   \renewcommand\pref[1]{\pageref{#1} \pagerefname}
   \renewcommand\ptref[1]{\pageref{tab:#1} \pagerefname\ \tablerefname\ \ref{tab:#1} }
   \renewcommand\pfref[1]{\pageref{fig:#1} \pagerefname\ \figurerefname\ \ref{fig:#1}}
    \setlength\parskip{.25\baselineskip}
    \addtodef{\@minipagerestore}{\setlength\parskip{.25\baselineskip}}{}
    \clubpenalty=10000
    \widowpenalty=10000
    \renewcommand\specitem{\textbf{항목}}
    \renewcommand\specdescription{\textbf{사양}}
    \renewcommand\contentsname{차례}
    \renewcommand\listfigurename{그림 목록}
    \renewcommand\listtablename{표 목록}
    \renewcommand\lffname{그림 파일 목록 }
    \renewcommand\loqname{질의 목록 }    
    \if@ganaappendix
      \addtodef{\appendix}{}{% 
      \renewcommand\thechapter{\gana{chapter}}\counterwithout{figure}{chapter}}
    \fi     
    \setenumerate[2]{label=\gana*)}
   \renewcommand\symbolheadname{기호}
   \renewcommand\numberheadname{숫자}
  \fi  
  
  \setlength{\parindent}{0em}
  \raggedbottom
  \chapterstyle{default}
  
  %\if@vartwo
  % \vartwomargin
  % \vartwofolio
  %\else
  % \normalmargin
  % \normalfolio
  %\fi  
\fi

\AtBeginDocument{
\if@cfontseries\fontseries{c}\selectfont\fi
}

\AfterBeginDocument{
\setlength\orgtextwidth{\textwidth}
\addtolength\orgtextwidth{\vartwosecindent}
\addtolength\entitytopsep{-\parskip}
\addtolength\entitybotsep{-\parskip}
\setlength\sfigwidth{.75\stockheight}
\setlength\sfigheight{.75\stockwidth}
\let\orgscale\figscale
\setlength\orgframesep{\figframesep}
}

\endinput