\usepackage{xparse,etoolbox} \usepackage[amsmath,thmmarks]{ntheorem} \DeclareDocumentCommand\NewShadedTheorem{ o m o m o }{ % #1 = options for mdframed % #2 = env name % #3 (optional) = common counter name % #4 = header text % #5 (optional) dominant counter name \IfNoValueTF{#5}{% not dominated \IfNoValueTF{#3}{% do not use common counter \newcounter{#2} \newtheorem{#2inner}[#2]{#4} }{% use common counter \newtheorem{#2inner}[#3]{#4} }}{% use dominated \newcounter{#2}[#5] \newtheorem{#2inner}[#2]{#4} } % create the environment \newenvironment{#2}{% % add extra code here \IfNoValueTF{#1}{}{\mdfsetup{#1}}% this is local \begin{mdframed} \ifdeflength{\theorempreskipamount}{% \setlength\theorempreskipamount{0pt}% \setlength\theorempostskipamount{0pt}}{} \begin{#2inner}}{\end{#2inner}\end{mdframed}} }