% Style file noprot.sty by Sami Sozuer. (June 1994)
% This style file eliminates the need for \protect'ion in:
%
%   1 - Argument of \thanks
%   2 - Argument (or optional argument) of \caption
%   3 - Optional argument of \bibitem
%   4 - Arguments of \addcontentsline and \addtocontents
%   5 - 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.
%
% The following is a remedy for such rare cases:
% ===================================================================
% Let's assume you have a List of Figures, and that you MUST expand
% something at the point where \caption is issued, so that its value
% appears in the List of Figures entry. In the old scheme, you would say:
%
% \caption{First part of Caption \value{\MyCounter} Second part of Caption}
%
% and the value of the \MyCounter would appear in the List of Figures.
% But with this style file, you need to use a somewhat more complicated
% construct similar to the following:
%
% \def\CaptionI{First part of Caption}
% \def\CaptionII{Second part of Caption}
% \edef\temp{\noexpand\caption{\CaptionI \value{\MyCounter} \CaptionII}}
% \temp
%
% Here, we need the current value of a user-defined counter \MyCounter
% to be written into the .aux file which is read in the second run
% of latex to produce the List of Figures. Since its value presumably
% changes throughout the document, we want its value at the point that
% the \caption command is issued, rather than its value at the point
% that the List of Figures is typeset, to appear in the List of Figures.
% If you don't have a list of figures, then of course you needn't
% worry about any of this. The same considerations apply also for
% the arguments of sectioning commands that appear in the Table of Contents.
%
% The rationale for using this style file, of course, is that such
% cases are extremely rare! For one thing, most books/articles
% rarely contain a List of Figures and/or a List of Tables, and even
% when you do use one, the chances of needing an immediate expansion
% in a \caption command are small.
% ===================================================================
%%%% 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%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%BEGIN:PROTECT etc
\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{}%
\@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{}%
\@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}%
\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}%-----------this \gdef should stay
\def\protect{\noexpand\protect\noexpand}%
\xdef\@thanks{\@thanks\protect\footnotetext[\the\c@footnote]%
{\noexpand\X:thanks}}%
\endgroup}%
\def\@thanks{}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\@lbibitem[#1]#2{\item[\@biblabel{#1}]%
\if@filesw
{%
\X:STRING{#1}{\X:argone}
\def\protect##1{}%
\immediate\write\@auxout{\string\bibcite{#2}{\X:argone}}
}%
\fi\ignorespaces}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% The following code is needed for the \label command in a \caption
%%%% or section argument to work properly, since the argument of
%%%% a \section or a \caption command is written verbatim into
%%%% the .aux file without being expanded.
\let\X:tableofcontents\tableofcontents%
\def\tableofcontents{\begingroup%
\let\label\@gobble\let\index\@gobble\let\glossary\@gobble%
\X:tableofcontents\endgroup}%
%
\let\X:listoffigures\listoffigures%
\def\listoffigures{\begingroup%
\let\label\@gobble\let\index\@gobble\let\glossary\@gobble%
\X:listoffigures\endgroup}%
%
\let\X:listoftables\listoftables%
\def\listoftables{\begingroup%
\let\label\@gobble\let\index\@gobble\let\glossary\@gobble%
\X:listoftables\endgroup}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%END:PROTECT etc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Restore catcode of :
\catcode`\:=\csname X:Old:Cat\endcsname\relax%
\expandafter\global\expandafter\let\csname X:Old:Cat\endcsname\undefined%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%that's it!