Saturday, May 25, 2013

Custom Numbering in Derivation / Proof Environment

Custom Numbering in Derivation / Proof Environment

Just a quick background, I am writing a thesis, which has theorems (proofs and derivations) and possibly a few other 'theorem' type environments. The code in this question actually works fine, it is doing what I want however I feel that it could be tidied up / improved.
In terms of equations, I have elected to have a numbering format which is local to the actual proof or derivation. So this involves storing the existing equation number, resetting it to zero, changing the style (for the proof or derivation respectively) executing the contents, and then restoring to the existing value.
Furthermore, some of the derivations / proofs can be condensed by using multicol, and one of my earlier posts Shaded Multicols serves to distinguish the proof / derivation from surrounding content, however, for the purposes of this question, these formatting styles have been removed.
Here is a stripped down version of the code, which is a full MWE:
\documentclass{article}

%------------LOAD THE PACKAGES---------------%
%Load Single Packages Together
\usepackage{amsmath,amsfonts,amssymb,amsthm,mathtools,mathpazo,calc,ifthen}
\usepackage{environ,multicol,xcolor}

%DEFINE MY THEOREM STYLE
\let\oldproof\proof\let\proof\relax
\let\oldendproof\endproof\let\endproof\relax
\newcommand{\theoremLetter}{}
\newtheoremstyle{mythm} % name
    {0pt}                        % Space above
    {0pt}                        % Space below
    {\small}% Body font
    {}                           % Indent amount
    {\bf\color{blue!50!black}}% Theorem head font
    {.}% Punctuation after theorem head
    {.5em}                       % Space after theorem head
    {}  % Theorem head spec (can be left empty, meaning ‘normal’)
\theoremstyle{mythm} %SELECT THE THEOREM
\newtheorem{derivation}{Derivation}
\newtheorem{proof}{Proof}

%Renew Formats, Equation, Figure, Table.
\renewcommand{\thederivation}{D\arabic{derivation}}
\renewcommand{\theproof}{P\arabic{proof}}

\newcounter{mytemp}%
\newenvironment{myenv}[3]{%
    \def\envvar{#1}%
    \def\mycols{#2}%

    \par\vspace{0.5em} %add space

    %Set the first letter depending on the type of environment.
    %DERIVATION
    \providecommand{\theoremLetter}{}%RESET
    \ifthenelse{\equal{\envvar}{derivation}}{%
        \renewcommand{\theoremLetter}{D}%
    }{}%
    %PROOF
    \ifthenelse{\equal{\envvar}{proof}}{%
        \renewcommand{\theoremLetter}{P}%
    }{}%

    \begin{\envvar}{\textbf{#3}}%
        \setcounter{mytemp}{\value{equation}}%
        \providecommand{\existingEquationFormat}{\theequation}%
        \setcounter{equation}{0}%
        \renewcommand{\theequation}{%
            \theoremLetter\arabic{\envvar}.\arabic{equation}%
        }%
        \setlength{\abovedisplayskip}{0pt}%Set DisplaySkip Value.
        \ifthenelse{\equal{\mycols}{1}}{}{\begin{multicols}{\mycols}}%
}{%BODY CONTENT OF ENVIRONMENT 
        \ifthenelse{\equal{\mycols}{1}}{}{\end{multicols}}%
        \setcounter{equation}{\value{mytemp}}%
        \renewcommand{\theequation}{\existingEquationFormat}%
        \renewcommand{\existingEquationFormat}{\relax}%
    \end{\envvar}%
}
And for a sample output:
\begin{document}
    \hrule

    \section{Default Equation Format}
    \begi

No comments:

Post a Comment