%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
% ENVIRONMENTS
%
%

% definition
\NewDocumentEnvironment{definition}{ s o }{
  \IfBooleanTF {#1} {
    % if starred: with logo
    \IfNoValueTF {#2} {
      % if no subtitle
      \begin{@def1}

    }{
      % if subtitle
      \begin{@def1}[#2]

    }
  }{
    % if not starred: without logo
    \IfNoValueTF {#2} {
      % if no subtitle
      \begin{@def2}

    }{
      % if subtitle
      \begin{@def2}[#2]

    }
  }
}{
  \IfBooleanTF {#1} {
    \end{@def1}
  }{
    \end{@def2}
  }
}

% theoreme
\NewDocumentEnvironment{theoreme}{ s o }{
  \IfBooleanTF {#1} {
    % if starred: with logo
    \IfNoValueTF {#2} {
      % if no subtitle
      \begin{@thm1}

    }{
      % if subtitle
      \begin{@thm1}[#2]

    }
  }{
    % if not starred: without logo
    \IfNoValueTF {#2} {
      % if no subtitle
      \begin{@thm2}

    }{
      % if subtitle
      \begin{@thm2}[#2]

    }
  }
}{
  \IfBooleanTF {#1} {
    \end{@thm1}
  }{
    \end{@thm2}
  }
}

% propriete
\NewDocumentEnvironment{propriete}{ s o }{
  \IfBooleanTF {#1} {
    % if starred: with logo
    \IfNoValueTF {#2} {
      % if no subtitle
      \begin{@ppt1}

    }{
      % if subtitle
      \begin{@ppt1}[#2]

    }
  }{
    % if not starred: without logo
    \IfNoValueTF {#2} {
      % if no subtitle
      \begin{@ppt2}

    }{
      % if subtitle
      \begin{@ppt2}[#2]

    }
  }
}{
  \IfBooleanTF {#1} {
    \end{@ppt1}
  }{
    \end{@ppt2}
  }
}

% demonstration
\NewDocumentEnvironment{demonstration}{ s o }{
  \IfBooleanTF {#1} {
    % if starred: with logo
    \IfNoValueTF {#2} {
      % if no subtitle
      \begin{@dem1}

    }{
      % if subtitle
      \begin{@dem1}[#2]

    }
  }{
    % if not starred: without logo
    \IfNoValueTF {#2} {
      % if no subtitle
      \begin{@dem2}

    }{
      % if subtitle
      \begin{@dem2}[#2]

    }
  }
}{
  \IfBooleanTF {#1} {
    \end{@dem1}
  }{
    \end{@dem2}
  }
}

% consequence
\NewDocumentEnvironment{consequence}{ s o }{
  \IfBooleanTF {#1} {
    % if starred: without title
    \IfNoValueTF {#2} {
      % if no subtitle
      \begin{@csq2}

    }{
      % if subtitle
      \begin{@csq2}[#2]

    }
  }{
    % if not starred: with title
    \IfNoValueTF {#2} {
      % if no subtitle
      \begin{@csq1}

    }{
      % if subtitle
      \begin{@csq1}[#2]

    }
  }
}{
  \IfBooleanTF {#1} {
    \end{@csq2}
  }{
    \end{@csq1}
  }
}

% vocabulaire
\NewDocumentEnvironment{vocabulaire}{ s o }{
  \IfBooleanTF {#1} {
    % if starred: with logo
    \IfNoValueTF {#2} {
      % if no subtitle
      \begin{@voc1}

    }{
      % if subtitle
      \begin{@voc1}[#2]

    }
  }{
    % if not starred: without logo
    \IfNoValueTF {#2} {
      % if no subtitle
      \begin{@voc2}

    }{
      % if subtitle
      \begin{@voc2}[#2]

    }
  }
}{
  \IfBooleanTF {#1} {
    \end{@voc1}
  }{
    \end{@voc2}
  }
}

% citation
\NewDocumentEnvironment{commentaire}{ o }{
    \IfNoValueTF {#1} {
      % if no subtitle
      \begin{@com}
        % \vspace{-.5cm}

    }{
      % if subtitle
      \begin{@com}[#1]

    }
}{
  \end{@com}
}

% remarque
\NewDocumentEnvironment{remarque}{ s o }{
  \IfBooleanTF {#1} {
    % if starred: without title
    \IfNoValueTF {#2} {
      % if no subtitle
      \begin{@rmq2}
        % \vspace{-.3cm}

    }{
      % if subtitle
      \begin{@rmq2}[#2]
        % \vspace{-.3cm}

    }
  }{
    % if not starred: with title
    \IfNoValueTF {#2} {
      % if no subtitle
      \begin{@rmq1}
        \vspace{-.5cm}

    }{
      % if subtitle
      \begin{@rmq1}[#2]
        \vspace{-.5cm}

    }
  }
}{
  \IfBooleanTF {#1} {
    \end{@rmq2}
  }{
    \end{@rmq1}
  }
}

% exemple
\NewDocumentEnvironment{exemple}{ s o }{
  \IfBooleanTF {#1} {
    % if starred: without title
    \IfNoValueTF {#2} {
      % if no subtitle
      \begin{@exe2}

    }{
      % if subtitle
      \begin{@exe2}[#2]

    }
  }{
    % if not starred: with title
    \IfNoValueTF {#2} {
      % if no subtitle
      \begin{@exe1}

    }{
      % if subtitle
      \begin{@exe1}[#2]

    }
  }
}{
  \IfBooleanTF {#1} {
    \end{@exe2}
  }{
    \end{@exe1}
  }
}

% application
\NewDocumentEnvironment{application}{ s o }{
  \IfBooleanTF {#1} {
    % if starred: without logo and title
    \IfNoValueTF {#2} {
      % if no subtitle
      \begin{@app2}

    }{
      % if subtitle
      \begin{@app2}[#2]

    }
  }{
    % if not starred: with logo
    \IfNoValueTF {#2} {
      % if no subtitle
      \begin{@app1}

    }{
      % if subtitle
      \begin{@app1}[#2]

    }
  }
}{
  \IfBooleanTF {#1} {
    \end{@app2}
  }{
    \end{@app1}
  }
}

% methode
\NewDocumentEnvironment{methode}{ s o }{
  \IfBooleanTF {#1} {
    % if starred: without logo and title
    \IfNoValueTF {#2} {
      % if no subtitle
      \begin{@met2}

    }{
      % if subtitle
      \begin{@met2}[#2]

    }
  }{
    % if not starred: with logo
    \IfNoValueTF {#2} {
      % if no subtitle
      \begin{@met1}

    }{
      % if subtitle
      \begin{@met1}[#2]

    }
  }
}{
  \IfBooleanTF {#1} {
    \end{@met2}
  }{
    \end{@met1}
  }
}

% Need to adapt the code in order to get numbering and
% framing
%% application
%\NewDocumentEnvironment{application}{ s o o o}{
%  \IfBooleanTF {#1} {
%    % if starred: without logo and title
%    \IfNoValueTF {#2} {
%      % if no subtitle
%      \begin{application2}
%
%      }{
%        % if subtitle
%        \begin{application2}[#2]
%
%        }
%      }{
%        % if not starred: with number
%        \IfNoValueTF {#2} {
%          % if no subtitle
%          \begin{application1}
%
%          }{
%            % if subtitle
%            \begin{application1}[#2]
%
%            }
%          }
%        }{
%          \IfBooleanTF {#1} {
%          \end{application2}
%        }{
%        \end{application1}
%      }
%    }

% exercice
\NewDocumentEnvironment{exercice}{ s o o o}{
  \IfBooleanTF {#1} {
    % if starred: without logo and title
    \IfNoValueTF {#2} {
      % if no subtitle
      \begin{exercice2}

      }{
        % if subtitle
        \begin{exercice2}[#2]

        }
      }{
        % if not starred: with number
        \IfNoValueTF {#2} {
          % if no subtitle
          \begin{exercice1}

          }{
            % if subtitle
            \begin{exercice1}[#2]

            }
          }
        }{
          \IfBooleanTF {#1} {
          \end{exercice2}
        }{
        \end{exercice1}
      }
    }

% rappel
\NewDocumentEnvironment{rappel}{ o }{
  \IfNoValueTF {#1} {
    \begin{bclogo}[logo=\bclivre, noborder=true]{Rappel}
  }{
    \begin{bclogo}[logo=\bclivre, noborder=true]{#1}
  }
}{
  \end{bclogo}
}

% aide
\NewDocumentEnvironment{aide}{ o }{
  \IfNoValueTF {#1} {
    \begin{bclogo}[logo=\bcaide, noborder=true, barre=motif, motifBarre=$ $]{ }
      \vspace{-1.1em}\em
  }{
    \begin{bclogo}[logo=\bcaide, noborder=true, barre=motif, motifBarre=$ $]{\textnormal{\em #1}}
      \em
  }
}{
  \end{bclogo}
}

%% objectif
%% Tentative d'environnement utilisant bclogo
%\NewDocumentEnvironment{objectif}{ }{
%  \vspace{1cm}
%  \begin{center}
%    \Annie\textbf{Objectif :}
%}{
%  \end{center}
%  \vspace{1cm}
%}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
