# Include theorem name from thmtools into mdframed title box

is nice for controlling the outer layout of theorems. on the other hand can take care of a number of other things great and small, in particular the detailed formatting of the title within the flow of text, but also stuff like maintaining a flexible list of theorems, properly setting autoref names, and so on. I know I can use the mdframed key to the \declaretheorem command to let it create a frame and control most aspects of that frame. What I'm missing, though, is a way to make use of the frametitle facilities of in this way.

Is there a way to redirect the title typesetting commands from into the frametitle argument to the mdframed environment it creates?

I see that I can add a hook before and a hook after the title, but at least my naive way of capturing the title between these two using \def\myframetitle\bgroup and \egroup failed:

\documentclass{article}
\usepackage{xcolor,tikz,geometry,amsthm,thmtools}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage{thm-patch}% copied from thmdef-mdframed.sty
\makeatletter
\mdfdefinestyle{fstyle}{linecolor=blue,frametitlerule=true}
% The following was adapted from thmdef-mdframed.sty but does not work:
\define@key{thmdef}{mymdframed}[{}]{%
\thmt@trytwice{}{%
\def\myframetitle\bgroup}%
\egroup\begin{mdframed}[frametitle=\myframetitle,#1]}%
}%
}
% Change the mymdframed to mdframed to make this compile at all:
\declaretheoremstyle[mymdframed={style=fstyle}]{tstyle}
\declaretheorem[style=tstyle]{thm}
\begin{document}
\begin{thm}[Round] The world is round\end{thm}

And this is what it \emph{should} look like:
\begin{mdframed}[frametitle={Thm 1: Round},style=fstyle]
The world is round\end{mdframed}
\end{document}


I'll be happy to learn about any approach to get the two packages working together including the title. There must be some solution, e.g. by defining your own wrapper macros to handle the title argument, but I hope for some more elegant approaches from those who know more.

• You can use \mdtheorem[style=fstyle]{thm}{Thm} – Marco Daniel May 10 '13 at 17:13
• @MarcoDaniel: Not using thmtools, I get warnings from hyperref about a missing autoref name for Thm. Furthermore, I can't control the formatting of the heading as well, e.g. I can't use different fonts for the theorem number and its name. I'm also worried about the list of theorems facilities, although I haven't tried them with mdtheorem alone. – MvG May 10 '13 at 17:19
• let me have a closer look. – Marco Daniel May 10 '13 at 17:24

Let me try to provide an answer.

thmtools uses the default environment provided by amsthm. To use mdframed with frametitle you have to redefine the default environment of amsthm. However I don't know whether it's a good idea. With the simple test file below it works. Please note that all theorem environments are enclosed by mdframed.

In the example I also show how to modify the style of mdframed:

\setcounter{errorcontextlines}{999}
\documentclass{article}
\usepackage{xcolor,tikz,geometry,amsthm}
\usepackage{thmtools,thm-patch}% copied from thmdef-mdframed.sty
\usepackage[framemethod=TikZ]{mdframed}
\makeatletter

\def\@thm#1#2#3{%
%  \ifhmode\unskip\unskip\par\fi
\normalfont
\let\thm@swap\@gobble
\thm@notefont{\fontseries\mddefault\upshape}%
\thm@space@setup
#1% style overrides
\@topsep \thm@preskip               % used by thm head
\@topsepadd \thm@postskip           % used by \@endparenv
%
\def\@tempa{#2}\ifx\@empty\@tempa
\def\@tempa{\@oparg{\@begintheorem{#3}{}}[]}%
\else
\refstepcounter{#2}%
\def\@tempa{\@oparg{\@begintheorem{#3}{\csname the#2\endcsname}}[]}%
\fi
\@tempa
}
\def\@begintheorem#1#2[#3]{%
\mdframed[style=fstyle,frametitle={%
\@ifempty{#1}{\let\thmname\@gobble}{\let\thmname\@iden}%
\@ifempty{#2}{\let\thmnumber\@gobble}{\let\thmnumber\@iden}%
\@ifempty{#3}{\let\thmnote\@gobble}{\let\thmnote\@iden}%
}%

\def\@endtheorem{\endmdframed}
\makeatother

\mdfdefinestyle{fstyle}{linecolor=blue,frametitlerule=true,linewidth=2pt,}
\declaretheorem[style=tstyle]{thm}
\begin{document}
\begin{thm}[Round] The world is round\end{thm}

And this is what it \emph{should} look like:

\begin{thm}The world is round\end{thm}

\end{document}


• Please test it before you use it! – Marco Daniel May 10 '13 at 19:06
• That took some doing. – Marco Daniel May 10 '13 at 19:37