% Style file noprot.sty by Sami Sozuer. (June 1994)
% This style file eliminates the need for \protect in
%  \thanks, \caption and sectioning commands (\chapter \section etc)
%   EXCEPT when the argument of a sectioning command appears in
%   a page heading (as for example is the case with \chapter and \section
%   commands in the book style). The remaining problem of fragile
%   commands within the headings will be addressed later.
%
% The elimination of \protect within \caption and sectioning commands
% is made possible by suppressing the expansion of the arguments
% of these commands and by writing them into the .aux
% file as literal strings. This means that values of dynamic quantities
% cannot be included in these commands any more. If you need to reference
% a page, use \pageref instead of \the\page or something similar in the
% argument of \caption and/or sectioning commands.
% Thanks to David Carlisle for pointing this out.
%
%%%% Use : in private commands to reduce chances of conflict
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Remember the catcode of :
\expandafter\edef\csname X:Old:Cat\endcsname{\the\catcode`\:}%
\catcode`\:=11\relax%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\long\def\@caption#1[#2]#3{\par
\X:addcontline{\csname ext@#1\endcsname}{#1}%
{\string\numberline{\csname the#1\endcsname}}%
{\ignorespaces #2}%
  \begingroup
     \@parboxrestore
    \normalsize
     \@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par
  \endgroup}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\@sect#1#2#3#4#5#6[#7]#8{\ifnum #2>\c@secnumdepth
     \def\@svsec{}\else
     \refstepcounter{#1}\edef\@svsec{\csname the#1\endcsname\hskip 1em }\fi
     \@tempskipa #5\relax
     \ifdim \@tempskipa>\z@
	\begingroup #6\relax
	  \@hangfrom{\hskip #3\relax\@svsec}{\interlinepenalty \@M #8\par}%
	\endgroup
       \csname #1mark\endcsname{#7}%
       \ifnum #2>\c@secnumdepth
	 \addcontentsline{toc}{#1}{#7}
       \else
	 \X:addcontline{toc}{#1}{\string\numberline{\csname the#1\endcsname}}{#7}
       \fi
	 \else
     \def\@svsechd{#6\hskip #3\@svsec #8\csname #1mark\endcsname{#7}
	\ifnum #2>\c@secnumdepth
	  \addcontentsline{toc}{#1}{#7}
	\else
	  \X:addcontline{toc}{#1}{\string\numberline{\csname the#1\endcsname}}{#7}
	\fi}
     \fi
     \@xsect{#5}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% #1,#2,#3 expanded; #4 is passed as string
\def\X:addcontline#1#2#3#4{\if@filesw \begingroup
\edef\X:argone{#1}%
\edef\X:argtwo{#2}%
\edef\X:argtri{#3}%
\X:STRING{#4}{\argfor}%
\let\label\@gobble \let\index\@gobble \let\glossary\@gobble
%%%%%%%\def\protect##1{\string\string\string##1\string\space
%%%%%%%   \space}%
\def\protect{}%
\@temptokena{\thepage}%
%---------------use \edef because #2 and \the\@temptokena should be expandad
%---------------before passed on to \@writefile, which does *not* expand
\edef\@tempa%
{\write \@auxout%
{%---------------------\contentsline should not be expanded here
\string\@writefile{\X:argone}{\string\contentsline{\X:argtwo}{\X:argtri\argfor}{\the\@temptokena}}%
}%
}\@tempa
\if@nobreak \ifvmode\nobreak\fi\fi\endgroup\fi}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\@writefile#1#2{%
\X:STRING{#2}{\X:argtu}%
\@ifundefined{tf@#1}{}{\expandafter
   \immediate\write\csname tf@#1\endcsname{\X:argtu}}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\X:STRING#1#2{\def\X:STRIP##1>{}\def\X:NEXT{#1}\edef#2{\expandafter\X:STRIP\meaning\X:NEXT}}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% #1,#2 expanded; #3 is passed as string
\def\addcontentsline#1#2#3{\if@filesw \begingroup
\edef\X:argone{#1}%
\edef\X:argtwo{#2}%
\X:STRING{#3}{\X:argtri}%
\let\label\@gobble \let\index\@gobble \let\glossary\@gobble
%%%%%%%\def\protect##1{\string\string\string##1\string\space
%%%%%%%   \space}%
\def\protect{}%
\@temptokena{\thepage}%
%---------------use \edef because #2 and \the\@temptokena should be expandad
%---------------before passed on to \@writefile, which does *not* expand
\edef\@tempa%
{\write \@auxout%
{%---------------------\contentsline should not be expanded here
\string\@writefile{\X:argone}{\string\contentsline{\X:argtwo}{\X:argtri}{\the\@temptokena}}%
}%
}\@tempa
   \if@nobreak \ifvmode\nobreak\fi\fi\endgroup\fi}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\long\def\addtocontents#1#2{\if@filesw \begingroup
\X:STRING{#2}{\X:argtwo}\relax%
\edef\X:argone{#1}%
\let\label\@gobble \let\index\@gobble \let\glossary\@gobble
%%%%\def\protect##1{\string\string\string##1\string\space\space}%
\def\protect##1{}%
\edef\@tempa{\write \@auxout {\string\@writefile{\X:argone}{\X:argtwo}}}\@tempa
\if@nobreak \ifvmode\nobreak\fi\fi\endgroup\fi}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\thanks#1{\footnotemark%
\begingroup%
\gdef\X:thanks{#1}%
\def\protect{\noexpand\protect\noexpand}%
\xdef\@thanks{\@thanks\protect\footnotetext[\the\c@footnote]%
{\noexpand\X:thanks}}%
\endgroup}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Restore catcode of :
\catcode`\:=\csname X:Old:Cat\endcsname\relax%
\expandafter\gdef\csname X:Old:Cat\endcsname{}%
