% 変数定義
\makeatletter

% 変数読み込み
\def\wyear#1{\gdef\@wyear{#1}}
\def\syear#1{\gdef\@syear{#1}}
\def\gaku#1{\gdef\@gaku{#1}}

%行間設定
\renewcommand{\baselinestretch}{1.1}
\setlength{\parskip}{.2\baselineskip}

% 余白設定（左右対称）
\setlength{\textwidth}{15.92cm}
%\setlength{\textwidth}{15.2cm}
\setlength{\oddsidemargin}{5mm}
\setlength{\evensidemargin}{0mm}
\setlength{\topmargin}{-1cm}
\setlength{\textheight}{24.5cm}
\setlength{\topskip}{5mm}
\setlength{\footskip}{18mm}

% 余白設定（左綴じ用）
\newcommand{\bindermode}{%
  \setlength{\textwidth}{15cm}
  \setlength{\oddsidemargin}{13mm}
  \setlength{\evensidemargin}{0mm}
  \setlength{\topmargin}{-1cm}
  \setlength{\textheight}{24.5cm}
\setlength{\topskip}{5mm}
  \setlength{\footskip}{18mm}
}

% 表紙用行間広め定義
\newenvironment{lineskiptitle}{%
  \baselineskip = 1.5cm
}

% 表紙
\def\smaketitle{\par
  \begingroup
  \@smaketitle
  \endgroup
}
\def\@smaketitle{%
  \thispagestyle{empty}
\setlength{\oddsidemargin}{5mm}
  \begin{center}
    {\LARGE 修士論文\ \ \ \@syear 年度（\@wyear 年度）}
    \vfill
    \begin{lineskiptitle}    
    {\huge\bf \@title}
    \end{lineskiptitle}
    \vfill
    {\Large 徳島大学大学院創成科学研究科}
    \vspace{0.3cm}\par
    {\Large 理工学専攻\ 数理科学コース}
    \vspace{0.5cm}\par
%    {\LARGE \@gaku\hspace{2em}\@author}
    {\LARGE \@author}
    \vspace{2.5cm}\par
    {\Large \@date}
  \end{center}
  \cleardoublepage
  \pagenumbering{roman}
}

\def\@makechapterhead#1{ \vspace*{50pt} { \parindent 0pt \raggedright
 \ifnum \c@secnumdepth >\m@ne \huge\bf \@chapapp{} \par 
 \vskip 20pt \fi \huge \bf #1\par 
 \nobreak \vskip 40pt } }

\def\chapter{\clearpage \thispagestyle{myplain}
 \global\@topnum\z@
\@afterindenttrue \secdef\@chapter\@schapter} 
\def\@chapter[#1]#2{\ifnum \c@secnumdepth >\m@ne
 \refstepcounter{chapter}
% \typeout{\@chapapp\space\thechapter.}
 \typeout{\@chapapp}
 \addcontentsline{toc}{chapter}{
%\protect\numberline{\thechapter}#1}\else
\protect\numberline{\@chapapp} \hspace{35pt} #1}\else
%\@chapapp \ \ #1}\else
 \addcontentsline{toc}{chapter}{#1}\fi
 \chaptermark{#1}
 \addtocontents{lof}{\protect\addvspace{100pt}}
\addtocontents{lot}{\protect\addvspace{10pt}} \if@twocolumn
\@topnewpage[\@makechapterhead{#2}] 
 \else \@makechapterhead{#2}
 \@afterheading \fi} 
\def\@schapter#1{\if@twocolumn \@topnewpage[\@makeschapterhead{#1}]
 \else \@makeschapterhead{#1} 
 \@afterheading\fi}

\def\section{\@startsection {section}{1}{-0.0mm}{%
 3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}{\Large\bf}}
\def\subsection{\@startsection{subsection}{2}{\z@}{3.25ex plus 1ex minus
 .2ex}{1.5ex plus .2ex}{\large\bf}}
\def\subsubsection{\@startsection{subsubsection}{3}{\z@}{3.25ex plus
 1ex minus .2ex}{1.5ex plus .2ex}{\normalsize\bf}}
\def\paragraph{\@startsection
 {paragraph}{4}{\z@}{3.25ex plus 1ex minus .2ex}{-1em}{\normalsize\bf}}
\def\subparagraph{\@startsection
 {subparagraph}{4}{\parindent}{3.25ex plus 1ex minus
 .2ex}{-1em}{\normalsize\bf}}

\def\appendix{\par
 \setcounter{chapter}{0}
 \setcounter{section}{0}
 \setcounter{page}{1}
 \def\@chapapp{付録 \thechapter}
 \def\thechapter{\Alph{chapter}}
 \def\thesection{\thechapter.\arabic{section}}
 \def\thepage{\Roman{page}}
 \def\section{\@startsection {section}{1}{-16.2mm}{%
  3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}{\Large\bf}}}

% from `jreport.sty' ************************************************

%\def\thepart {\Roman{part}}
%\def\thechapter {\arabic{chapter}}
%\def\thesection {\thechapter.\arabic{section}}
\def\thesection {\thechapter.\arabic{section}節}
%\def\thesubsection {\thesection.\arabic{subsection}}
\def\thesubsection {\thechapter.\arabic{section}.\arabic{subsection}}
%\def\thesubsubsection {\thesubsection .\arabic{subsubsection}}
%\def\theparagraph {\thesubsubsection.\arabic{paragraph}}
%\def\thesubparagraph {\theparagraph.\arabic{subparagraph}}
%\def\@chapapp{Chapter}
\def\@chapapp{第 \thechapter 章}

\def\@pnumwidth{1.55em}
\def\@tocrmarg {2.55em}
\def\@dotsep{4.5}
\setcounter{tocdepth}{2}

\def\tableofcontents{\@restonecolfalse\if@twocolumn\@restonecoltrue\onecolumn
 \fi\def\thepage{\empty}\pagestyle{myplain}\pagenumbering{roman}
 \chapter*{目 次\@mkboth{目 次}{目 次}}
 \@starttoc{toc}\if@restonecol\twocolumn\fi
 \if@twoside \ifodd\c@page \clearpage\thispagestyle{empty}\ \fi\fi}
\def\l@part#1#2{\addpenalty{-\@highpenalty}
 \addvspace{2.25em plus 1pt} \begingroup
 \@tempdima 3em \parindent \z@ \rightskip \@pnumwidth \parfillskip
-\@pnumwidth 
 {\large \bf \leavevmode #1\hfil \hbox to\@pnumwidth{\hss #2}}\par
 \nobreak \endgroup}

\def\l@chapter#1#2{\pagebreak[3] 
\vskip 1.0em plus 1pt \@tempdima 1.5em \begingroup
% \vskip 1.0em plus 1pt \@tempdima 4.0em \begingroup
 \parindent \z@ \rightskip \@pnumwidth 
 \parfillskip -\@pnumwidth 
 \bf \leavevmode \advance \leftskip \@tempdima \hskip -\leftskip #1 
 \nobreak \hfil \nobreak \hbox to \@pnumwidth{\hss #2} \par
 \endgroup}

%\def\l@section{\@dottedtocline{1}{1.5em}{2.3em}}
\def\l@section{\@dottedtocline{1}{1.2em}{4.0em}}
\def\l@subsection{\@dottedtocline{2}{3.8em}{3.2em}}
\def\l@subsubsection{\@dottedtocline{3}{7.0em}{4.1em}}
\def\l@paragraph{\@dottedtocline{4}{10em}{5em}}
\def\l@subparagraph{\@dottedtocline{5}{12em}{6em}}
\def\listoffigures{\@restonecolfalse\if@twocolumn\@restonecoltrue\onecolumn
 \fi\chapter*{図 目 次\@mkboth
 {図 目 次}{図 目 次}}\@starttoc{lof}\if@restonecol\twocolumn
 \fi}
\def\l@figure{\@dottedtocline{1}{1.5em}{2.3em}}
\def\listoftables{\@restonecolfalse\if@twocolumn\@restonecoltrue\onecolumn
 \fi\chapter*{表 目 次\@mkboth
 {表 目 次}{表 目 次}}\@starttoc{lot}\if@restonecol
 \twocolumn\fi}
\let\l@table\l@figure


\def\thebibliography#1{\chapter*{参考文献\@mkboth
 {参 考 文 献}{参 考 文 献}}
\addcontentsline{toc}{chapter}{参考文献}
 \list{[\arabic{enumi}]}{\settowidth\labelwidth{[#1]}\leftmargin\labelwidth
 \advance\leftmargin\labelsep
 \usecounter{enumi}}
 \def\newblock{\hskip .11em plus .33em minus .07em}
 \sloppy
 \sfcode`\.=1000\relax}
\let\endthebibliography=\endlist

\setcounter{topnumber}{2}
\def\topfraction{.7}
\setcounter{bottomnumber}{1}
\def\bottomfraction{.3}
\setcounter{totalnumber}{3}
\def\textfraction{.2}
\def\floatpagefraction{.5}
\setcounter{dbltopnumber}{2}
\def\dbltopfraction{.7}
\def\dblfloatpagefraction{.5}

\long\def\@makecaption#1#2{
 \vskip 10pt 
 \setbox\@tempboxa\hbox{#1: #2}
% \setbox\@tempboxa\hbox{\large #1 　 #2}
 \ifdim \wd\@tempboxa >\hsize \unhbox\@tempboxa\par \else \hbox
to\hsize{\hfil\box\@tempboxa\hfil} 
 \fi}


% ------ add length to heading width ---------
\newdimen\leftheadmargin% --------- left
\newdimen\rightheadmargin% -------- right
\newdimen\rightheadoutmargin% ----- (left - right)
\leftheadmargin 10mm
\rightheadmargin 5mm
\setlength{\rightheadoutmargin}{\leftheadmargin}
\addtolength{\rightheadoutmargin}{-\rightheadmargin}
\marginparsep 5mm% ------- 傍注
\setlength{\marginparwidth}{\leftheadmargin}
\addtolength{\marginparwidth}{-\marginparsep}
% ---------- headings start --------
\if@twoside \def\ps@headings{\let\@mkboth\markboth
\def\@oddfoot{}\def\@evenfoot{}
%     headings --------
\def\@oddhead{\hss\underline{\hbox to \leftheadmargin{\vbox{\hbox{%
 \rlap{\parbox[b]{\textwidth}{\raggedright{%
%     left headings --------
%
 {\quad\large 徳島大学大学院創成科学研究科}\\ \qquad 理工学専攻\ 数理科学コース \  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \hbox{}
 }}}}}\hfil}\hbox to \textwidth{\hfil\bf\rightmark}%
 \hbox to \rightheadmargin{\hfil\bf\thepage}}%
 \hbox to \rightheadoutmargin{\hfil}\hss}
\def\@evenhead{\hss\underline{\hbox to \leftheadmargin{\vbox{\hbox{%
 \rlap{\parbox[b]{\textwidth}{\raggedright{%
 {\quad\large 徳島大学大学院創成科学研究科}\\{\bf\thepage} \ 理工学専攻\ 数理科学コース \  
 \hbox{}
 }}}}}\hfil}
\hbox to \textwidth{\hfil\bf\rightmark}%
 \hbox to \rightheadmargin{}}%
 \hbox to \rightheadoutmargin{\hfil}\hss}%
\def\chaptermark##1{\markright{\uppercase{\ifnum \c@secnumdepth>\m@ne
 \@chapapp\ \ \fi ##1}}}}
\else \def\ps@headings{\let\@mkboth\markboth
%     footer ----------
\def\@oddfoot{}\def\@evenfoot{}
%     headings --------
\def\@oddhead{\hss\underline{\hbox to \leftheadmargin{\vbox{\hbox{%
 \rlap{\parbox[b]{\textwidth}{\raggedright{%
%     left headings --------
%
 {\quad\large 徳島大学大学院創成科学研究科}\\ \qquad 理工学専攻\ 数理科学コース \  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \hbox{}
 }}}}}\hfil}\hbox to \textwidth{\hfil\bf\rightmark}%
 \hbox to \rightheadmargin{\hfil\bf\thepage}}%
 \hbox to \rightheadoutmargin{\hfil}\hss}
\def\chaptermark##1{\markright{\uppercase{\ifnum \c@secnumdepth>\m@ne
 \@chapapp\ \ \fi ##1}}}}
\fi
% ---------- myplain start --------
\def\ps@myplain{\let\@mkboth\@gobbletwo
\def\@oddhead{\hbox to \textwidth{\hfil}
 \hbox to \rightheadmargin{\hfil\bf\thepage}\hss}
\def\@evenhead{\hss\hbox to \leftheadmargin{%
 \bf\thepage\hfil}\hbox to \textwidth{\hfil}}
\def\@oddfoot{}\def\@evenfoot{}\def\chaptermark##1{}%
\def\sectionmark##1{}\def\subsectionmark##1{}}
% ---------- myheadings start --------
\def\ps@myheadings{\let\@mkboth\@gobbletwo
%\def\@oddhead{\hbox{}\sl\rightmark \hfil \rm\thepage}
%\def\@evenhead{\rm \thepage\hfil\sl\leftmark\hbox}
\def\@oddhead{\hss\underline{\hbox to \leftheadmargin{\vbox{\hbox{%
 \rlap{\parbox[b]{\textwidth}{\raggedright{\footnotesize%
 \bf\rightmark}}}}}\hfil}\hbox to \textwidth{\hfil}%
 \hbox to \rightheadmargin{\hfil\bf\thepage}}%
 \hbox to \rightheadoutmargin{\hfil}\hss}
\def\@evenhead{\hss\underline{\hbox to \leftheadmargin{%
 \bf\thepage\hfil}\hbox to \textwidth{\hfil}%
 \hbox to \rightheadmargin{\vbox{\hbox{\rlap{\parbox[b]{\textwidth}{%
 \raggedright{\footnotesize\bf\leftmark}}}}}\hfil}}%
 \hbox to \rightheadoutmargin{\hfil}\hss}
\def\@oddfoot{}\def\@evenfoot{}\def\chaptermark##1{}%
\def\sectionmark##1{}\def\subsectionmark##1{}}

% -------- 欄外への書き込みを常に左側の欄外へとする --------
\def\@addmarginpar{\@next\@marbox\@currlist{\@cons\freelist\marbox
 \@cons\@freelist\@currbox}\@latexbug\@tempcnta\@ne
 \if@twocolumn \if@firstcolumn \@tempcnta\m@ne \fi
 \else \if@mparswitch
% \ifodd\c@page \else\@tempcnta\m@ne \fi
%  \@tempcnta\m@ne % 常に偶数ページと思わせる
%  \fi \if@reversemargin \@tempcnta -\@tempcnta \fi \fi
% \ifnum\@tempcnta <\z@ \global\setbox\@marbox\box\@currbox \fi
% \@tempdima\@mparbottom \advance\@tempdima -\@pageht
%  \advance\@tempdima\ht\@marbox \ifdim\@tempdima >\z@
  \@warning{Marginpar on page \thepage\space moved}\else\@tempdima\z@ \fi
 \global\@mparbottom\@pageht \global\advance\@mparbottom\@tempdima
  \global\advance\@mparbottom\dp\@marbox
  \global\advance\@mparbottom\marginparpush
 \advance\@tempdima -\ht\@marbox
 \global\ht\@marbox\z@ \global\dp\@marbox\z@
 \vskip -\@pagedp \vskip\@tempdima\nointerlineskip
 \hbox to\columnwidth{\ifnum \@tempcnta >\z@
  \hskip\columnwidth \hskip\marginparsep
  \else \hskip -\marginparsep \hskip -\marginparwidth \fi
  \box\@marbox \hss}%
 \vskip -\@tempdima \nointerlineskip
 \hbox{\vrule \@height\z@ \@width\z@ \@depth\@pagedp}}

\makeatother

