%%
%% This is file `codesection.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% codesection.dtx  (with options: `codesection.sty')
%% 
%% IMPORTANT NOTICE:
%% 
%% For the copyright see the source file.
%% 
%% Any modified versions of this file must be renamed
%% with new filenames distinct from codesection.sty.
%% 
%% For distribution of the original source see the terms
%% for copying and modification in the file codesection.dtx.
%% 
%% This generated file may be distributed as long as the
%% original source files, as listed above, are part of the
%% same distribution. (The sources need not necessarily be
%% in the same archive or directory.)
 % package defines paired commands and consequently, has no such limitations.
\NeedsTeXFormat{LaTeX2e}[1994/12/01]
\ProvidesPackage{codesection}
          [2014/06/27  v0.1  disableable code sections]
\RequirePackage{etoolbox}
%%----------------------------------------------------------------------
%% provide new if (\ifCodeSection<name>)
%% with definition \CodeSection<name><true>
%%
\newcommand{\DefineCodeSection}[2][true]{%
  \expandafter\newif\csname ifCodeSection#2\endcsname
  \csname CodeSection#2#1\endcsname
}%
%%----------------------------------------------------------------------
%% Alternative to \DefineCodeSection
\newcommand{\SetCodeSection}[2]{%
  \DefineCodeSection[#2]{#1}
}%
%%----------------------------------------------------------------------
\newcommand\BeginCodeSection[1]{%
  \ifcsdef{ifCodeSection#1}{}{%
    \PackageError{codesection}{Section #1 is unknown\MessageBreak}{}%
  }
  \csname ifCodeSection#1\endcsname
    \expandafter\@secondoftwo
  \else
    \expandafter\@firstoftwo
  \fi
  {% comment all code inside template section
    \@bsphack
%% open new group
    \begingroup
%% save current template section name
    \def\@currtemplate{#1}%
    \let\do\@makeother\dospecials
    \catcode`\^^M\active
%% enter main loop
    \codeSection@
  }%
  {% execute all code inside template section
%% = do nothing except trimming spaces
    \@bsphack\@esphack%
  }%
}
%%----------------------------------------------------------------------
%%  The macros \@bsphack and  \@esphack are internal to LaTeX;
%%  they ensure that an entity like a marginal note or
%%  label definition does not introduce any extra space
%%  into a paragraph, independently of whether or not
%%  it is attached to a word.
\newcommand\EndCodeSection[1]{\@bsphack\@esphack}
%%----------------------------------------------------------------------
%% usage ???
\@ifundefined{vrb@catcodes}{%
  \def\vrb@catcodes{%
     \catcode`\!12\catcode`\[12\catcode`\]12%
  }%
}{}%
%%----------------------------------------------------------------------
\begingroup
\vrb@catcodes
\lccode`\!=`\\
\lccode`\[=`\{
\lccode`\]=`\}
\catcode`\~=\active
\lccode`\~=`\^^M
\lccode`\C=`\C
\lowercase{%
%%----------------------------------------------------------------------
  \def\codeSection@#1{%
    \endgroup
%% ----
    \def\codeSection@##1~{\codeSection@@##1!#1\@nil}%
%% ----
    \def\codeSection@@##1!#1{\futurelet\next\codeSection@@@}%
%% ----
    \def\codeSection@@@##1\@nil{%
       \ifx\next\@nil
         \let\next\codeSection@
       \else
         \def\@tempa####1!#1\@nil{####1}%
         \def\next{\expandafter\codeSection@test\@tempa##1\@nil~}%
       \fi
       \next
    }%
%% ----
    \def\codeSection@test##1{%
      \let\next\codeSection@test
      \if\noexpand##1\noexpand~\let\next\codeSection@
      \else \if\noexpand##1
      \else \if\noexpand##1\noexpand[\let\@tempc\@empty
                                     \let\next\codeSection@testend
      \else \def\next{\codeSection@##1}%
      \fi\fi\fi
      \next
    }%
%% ----
    \def\codeSection@testend##1{%
      \if\noexpand##1\noexpand~\let\next\codeSection@
      \else \if\noexpand##1\noexpand]\let\next\codeSection@@testend
      \else\if\noexpand##1\noexpand!\def\next{\codeSection@!}%
      \else \expandafter\def\expandafter\@tempc\expandafter
            {\@tempc##1}%
      \fi\fi\fi
      \next
    }%
%% ---- test if end statement belongs to current section
%%      saved in \@currtemplate
    \def\codeSection@@testend{%
      \ifx\@tempc\@currtemplate
%% end group and call rescan
         \edef\next{\noexpand\endgroup\noexpand\@esphack
                    \noexpand\codeSection@rescan{\@currtemplate}}%
       \else
%% start loop gain
         \let\next\codeSection@
       \fi
       \next
    }%
%% ---- does what ???
    \def\codeSection@rescan##1##2~{%
      \if\noexpand~\noexpand##2~%
      \else
        \@warning{%
          Characters dropped after
          `\string\EndCodeSection{##1}'%
        }%
      \fi
    }%
  }%
%%----------------------------------------------------------------------
} % lowercase
\codeSection@{EndCodeSection}%
%%----------------------------------------------------------------------
\endinput
%%
%% End of file `codesection.sty'.
