%% Documentation of the package mdframed.sty
\def\mdversion{version 0.3a}
\documentclass[american,11pt]{article}
\usepackage{geometry}
\geometry{left=3cm,right=3cm,top=2cm,bottom=2cm}
\usepackage{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\newif\ifmdframedcompile
\mdframedcompiletrue  %% use lucida als default
\IfFileExists{lucidabr}{%
   \usepackage{textcomp}
   \ifmdframedcompile
     \usepackage[de,T1,altbullet]{lucidabr}
   \else
     \usepackage[T1,altbullet]{lucidabr}
    \fi
    }{%
    \usepackage[scaled]{libertine}
}
\usepackage{xcolor}
\usepackage[babel]{microtype}
\usepackage{array,tabularx}
%%Load the the package itselfs
\usepackage[leftmargin=20pt,rightmargin=40pt]{mdframed}

\usepackage{amsmath}
\usepackage[amsmath,amsthm,hyperref]{ntheorem}
\newtheorem{mdtheorem}{Theorem}[section]
\newenvironment{theorem}{%
    \begin{mdframed}[leftmargin=20pt,rightmargin=40pt,linewidth=2,margin=40,backgroundcolor=yellow,linecolor=blue]%
     \begin{mdtheorem}%
     }{%
     \end{mdtheorem}%
    \end{mdframed}%
}

\newtheorem{mdlemma}{Lemma}[section]
\newenvironment{ntheorem}{%
    \begin{mdframed}[ntheorem=true,leftmargin=20pt,rightmargin=40pt,linewidth=2,margin=40,backgroundcolor=yellow,linecolor=blue]%
     \begin{mdlemma}%
     }{%
     \end{mdlemma}%
    \end{mdframed}%
}
\definecolor{titleblue}{rgb}{0,0,0.9}

\usepackage{listings}
\lstnewenvironment{mdexample}[1][]
  {\lstset{%
     basicstyle=\small,
     xleftmargin=20pt,
     xrightmargin=20pt,
     frame=single,
     rulecolor=\color{titleblue},
     framesep=5pt,
     framerule=1pt,
     language=[LaTeX]TeX,#1,
     columns=fixed, fontadjust=true,basewidth=0.5em,breakatwhitespace=true
     }}
%      morekeywords={\usepackage,\end,\begin,\lipsum,\documentclass,\newtheorem,\newenvironment,\section,\label\mbox{ }}}}
  {}

\usepackage{hyperref}
\hypersetup{%
  colorlinks=true,
  linkcolor=titleblue,
  urlcolor=titleblue,
  pdfauthor=Marco Daniel,
  pdftitle=Documentation of mdframed,
plainpages=false
}
\usepackage{xspace}
\usepackage{multicol}
\columnseprule0.4pt
\makeatletter
\begingroup
  \text@command\relax
  \global\let\xspace@check@icr\check@icr
\endgroup
\xspaceaddexceptions{\xspace@check@icr}

\renewcommand\tableofcontents{%
     \begin{multicols}{2}[\centering\textbf{\sffamily\Large\contentsname}]
       \@starttoc{toc}
     \end{multicols}
}
\makeatother
\newcommand*\mdoption[1]{\textsf{\bfseries\color{titleblue}#1}}
\newcommand*\mdname{\textsf{mdframed}\xspace}
\newcommand*\mdpack[1]{\textsf{#1}\xspace}
\newcommand*\mdsetting[1]{\textsf{#1}\xspace}
\newcommand*\mdcommand[1]{\texttt{\textbackslash #1}\xspace}

\setcounter{tocdepth}{1}
\begin{document}
 \vspace*{\baselineskip}

 \begin{center}
  \color{titleblue}
 \Large\bfseries \sffamily The \mdname package\footnote{Extending the package \texttt{framed.sty}.}

 \vspace*{0.5\baselineskip}
 \normalfont\large\normalcolor auto-split frame environment

\vspace*{.5\baselineskip}
 \href{mailto:marco.daniel@mada-nada.de}{Marco Daniel}\footnote{With thanks to Heiko Oberdiek, Rolf Niepraschk, Martin Scharrer and Herbert Voss.} \qquad \mdversion\ \qquad \today
 \end{center}
\begin{abstract}
Working with the command \mdcommand{fbox} or \mdcommand{fcolorbox}, one has to handle page breaks by hand,
meaning that you have to split up the \mdcommand{fbox} into two. The present package defines the environment \mdname which automatically deals with page
breaks, whence the name \glqq breakable\grqq.

By using \mdcommand{newenvironment} the user may choose between several individual designs.
\end{abstract}

\tableofcontents

\section{Motivation}
Many users wish to (further) emphasize lemmata, definitions, proofs etc.. The package mdframed allows to
create environments with breakable frames. I think an example is the best way to demonstrate the properties.

The following example gives an idea of how to use mdframed. (For the theorem environment we use the package \mdpack{amsthm}.)
\begin{mdexample}
\usepackage{mdframed,amsthm}
\newtheorem{mdtheorem}{Theorem}[section]
\newenvironment{theorem}{%
  \begin{mdframed}%
   [linewidth=2,margin=40,backgroundcolor=yellow,linecolor=blue]%
  \begin{mdtheorem}}{\end{mdtheorem}\end{mdframed}}
...
\begin{theorem}[Pythagorean theorem]
 In any right triangle, the area of the square whose side is the hypotenuse
 is equal to the sum of the areas of the squares whose sides are the two legs.
 \begin{equation}
       a^2+b^2=c^2
 \end{equation}
\end{theorem}
\end{mdexample}
\begin{theorem}[Pythagorean theorem]
     In any right triangle, the area of the square whose side is the hypotenuse
    (the side opposite the right angle) is equal to the sum of the areas of the 
     squares whose sides are the two legs (the two sides that meet at a right angle).
     \begin{equation}
           a^2+b^2=c^2
     \end{equation}
\end{theorem}

\section{Syntax}
Load the package as usual:
\begin{mdexample}
  \usepackage[<GLOBAL OPTIONS>]{mdframed}
\end{mdexample}

The package defines only one environment with the following syntax
\begin{mdexample}
  \begin{mdframed}[< LOCAL OPTIONS >]
     < CONTENT >
  \end{mdframed}
\end{mdexample}

\section{Options}
The package allows to set global and local options which are explained below.

\subsection{Global Options}
The following options are only global options.

\begin{center}
\renewcommand{\arraystretch}{1.5}
\begin{tabularx}{\linewidth}{@{}lXl@{}}
  \mdoption{skipabove}=<LENGTH>& Sets an additional skip above the frame.
                               & default=\mdsetting{0pt} \\
  \mdoption{skipbelow}=<LENGTH>& Sets an additional skip below the frame.
                               & default=\mdsetting{0pt} \\
  \mdoption{xcolor}=<VALUE(S)>& By setting this key the package \mdpack{xcolor} will
                                be loaded with the given value(s). Without any value \mbox{\mdname} loads
                                the package \mdpack{color} without any options.
                               & default=\mdsetting{none} \\
\end{tabularx}
\end{center}

 By setting one of these options locally, you get a warning like
\begin{mdexample}
 Option `...' is already consumed(mdframed) and has no effect on input line ...
\end{mdexample}

\clearpage
\subsection{Global and Local Options}
The listed options below allows to set global and local. 
\begin{center}
\renewcommand{\arraystretch}{1.5}
\begin{tabularx}{\linewidth}{@{}lXl@{}}
  \mdoption{linecolor}=<COLOR> & Sets the color of the line around the environment to <COLOR>.
                               & default=\mdsetting{black} \\
  \mdoption{backgroundcolor}=<COLOR> & Sets the color of the background of the environment to <COLOR>.
                               & default=\mdsetting{white} \\
  \mdoption{fontcolor}=<COLOR> & Sets the color of the contents of the environment to <COLOR>.
                               & default=\mdsetting{black} \\
  \mdoption{margin}=<LENGTH>   & Sets the length of the margin text frame of the environment.
                                 The basic unit of the length is pt. So it is possible to set
                                 length to 6 which is equal to 6pt.
                               & default=\mdsetting{2pt} \\
  \mdoption{leftmargin}=<LENGTH>   & Sets the length of the left margin of the environment.
                                 The basic unit of the length is pt. So it is possible to set
                                 length to 6 which is equal to 6pt.
                               & default=\mdsetting{2pt} \\
  \mdoption{rightmargin}=<LENGTH>   & Sets the length of the right margin of the environment.
                                 The basic unit of the length is pt. So it is possible to set
                                 length to 6 which is equal to 6pt.
                               & default=\mdsetting{2pt} \\
  \mdoption{linewidth}=<LENGTH>& Sets the width of the line around the environment.
                                 The basic unit of the length is pt. So it is possible to set
                                 length to 6 which is equal to 6pt.
                               & default=\mdsetting{20pt} \\
  \mdoption{ntheorem}=<boolean>& Befor setting this key you have to load the package \mdpack{ntheorem}. 
                                With this option you set the values \mdcommand{theorempreskipamount}
                                and \mdcommand{theorempostskipamount} to 0pt.
                               & default=\mdsetting{false} \\
\end{tabularx}
\end{center}

\subsubsection{The Option \mdoption{ntheorem}}

\begin{theorem}
 This environment is created with \mdoption{ntheorem=false}.
\end{theorem}

\begin{ntheorem}
 This environment is created with \mdoption{ntheorem=true}.
\end{ntheorem}
\clearpage
\section{Example}

\begin{mdexample}
 \documentclass[10pt]{article}
 \usepackage[linewidth=10,%
            margin=40,%
            backgroundcolor=yellow,
            linecolor=blue,
            skipbelow=0,
            skipabove=0]{mdframed}
 \usepackage{amsmath,amsthm}
 \newtheorem{mdlemma}{Lemma}[section]
 \newenvironment{lemma}{%
    \begin{mdframed}[linewidth=2,margin=40,%
                     backgroundcolor=red,linecolor=black]%
     \begin{mdlemma}%
     }{%
     \end{mdlemma}%
    \end{mdframed}%
 }
  \usepackage{lipsum}
 \usepackage{hyperref}
 \begin{document}
 \section{foo}
 \lipsum[1]
   \begin{mdframed}
    \lipsum[5]
   \end{mdframed}

 \lipsum[1]

 \begin{lemma}\label{lem:testA}\mbox{ }
   \begin{itemize}
      \item Some Text
      \item $x^2+y^2=1$
      \item \lipsum[1]
   \end{itemize}
 \end{lemma}
 \end{document}\end{mdexample}

\section{Known Problems}
 In this section I will collect known problems. In case you encouter any further problems, please
 drop me an email, \href{mailto:marco.daniel@mada-nada.de}{marco.daniel@mada-nada.de}.

   Do you have any ideas / wishes on further extensions to this package? Please let me know!

\begin{enumerate}
 \item So far it is not possible to extend a frame to more than two pages
 \item So far there is no implementation for choosing different styles of the frame. But I am workind on that.
\end{enumerate}

\end{document}
