The following code isn't very minimal but I hope you will be able to understand the code.
\setcounter{errorcontextlines}{999}
\documentclass{scrartcl}
\usepackage{lipsum,ntheorem}
\usepackage[ntheorem]{mdframed}
\makeatletter
%\newtheorem{<envname>}[<numberedlike>]{<caption>}[<within>]
%\newmdtheoremenv[<mdframed-options>]{<envname>}[<numberedlike>]{<caption>}[<within>]
%\md@tempa[<mdframed-options>]
%\md@tempb{<envname>}%
%\md@tempc[<numberedlike>]%
%\md@tempd{<caption>}%
%\md@tempe[<within>]%
\newrobustcmd*\newmdtheoremenv{%
\kernel@ifnextchar[%]
{\newmdtheoremenv@i}{\newmdtheoremenv@i[]}%
}
\newrobustcmd*\newmdtheoremenv@i[2][]{%
\def\md@tempa{#1}%
\def\md@tempb{#2}%
\kernel@ifnextchar[%]
{\newmdtheoremenv@ii}{\newmdtheoremenv@ii[]}%
}
%\newmdtheoremenv@ii[<mdframed-options>]{<envname>}[<numberedlike>]{<caption>}
\newrobustcmd*\newmdtheoremenv@ii[2][]{%
\def\md@tempc{#1}%
\def\md@tempd{#2}%
\kernel@ifnextchar[%]
{\newmdtheoremenv@iii}{\newmdtheoremenv@iii[]}%
}
%\newmdtheoremenv@ii[<mdframed-options>]{<envname>}[<numberedlike>]{<caption>}[<within>]
\newrobustcmd*\newmdtheoremenv@iii[1][]{%
\def\md@tempe{#1}%
\ifboolexpr{ not (test {\ifdefempty{\md@tempc}})
and
not (test {\ifdefempty{\md@tempe}})
}{%
\md@PackageWarning{You defined {\string\newtheorem} with ^^J
both optional arguments^^J
<numeredlike> and <within>. This isn't allowed^^J
\mdframedpackagename will use <numeredlike>\MessageBreak}%
\newtheorem{\csname md\md@tempb \endcsname}[\md@tempc]{\md@tempd}%
}%
{\ifdefempty{\md@tempc}{}{\newtheorem{md\md@tempb}[\md@tempc]{\md@tempd}}%
\ifdefempty{\md@tempe}{}{\newtheorem{md\md@tempb}{\md@tempd}[\md@tempe]}%
}%
\ifboolexpr{test {\ifdefempty{\md@tempc}}
and
test {\ifdefempty{\md@tempe}}
}{%
\newtheorem{md\md@tempb}{\md@tempd}%
}{}%
\expandafter\global\expandafter\@namedef\expandafter{\md@tempb}{%
\expandafter\mdfsetup\expandafter{\md@tempa}%
\begin{mdframed}[]\begin{md\md@tempb}%
}%
\expandafter\global\expandafter\@namedef\expandafter{end\md@tempb}{%
\end{md\md@tempb}\end{mdframed}%
}%
}
\makeatother
\begin{document}
{\small\verb+\newmdtheoremenv[mdframed-options]{envname}[numberedlike]{caption}[within]+}
\newmdtheoremenv[linecolor=blue,backgroundcolor=red]{beispiel}{Beispiel}
%\newmdtheoremenv[linecolor=red,backgroundcolor=yellow]{spiel}{Spiel}
\begin{beispiel}[Antwort]
Test
\end{beispiel}
\vspace*{2em}
%\hallo
\vspace*{2em}
%\begin{spiel}%[Antwort]
%Test
%\end{spiel}
\end{document}
I am trying to create the command \newmdtheoremenv
. In the minimal example it works well as long as only one \newmdtheoremenv
is used.
When I use the second \newmdtheoremenv
the first will be overwritten. How can I avoid this and how can I modify the example so that the command \newmdtheoremenv
can be used multiple times.
[
manually but then use macros which already has an optional arguments and repeat the exact same by themselves! So change\newrobustcmd*\newmdtheoremenv@i[2][]
with a simple\def\newmdtheoremenv@[#1]#2
or remove the\kernel@ifnextchar[
code. Only one is required; both together don't make much sense.