mdframed is nice for controlling the outer layout of theorems. thmtools 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 mdframed in this way.
Is there a way to redirect the title typesetting commands from thmtools 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{}{%
\addtotheorempreheadhook[\thmt@envname]{%
\def\myframetitle\bgroup}%
\addtotheorempostheadhook[\thmt@envname]{%
\egroup\begin{mdframed}[frametitle=\myframetitle,#1]}%
\addtotheorempostfoothook[\thmt@envname]{\end{mdframed}}%
}%
}
% 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.
\mdtheorem[style=fstyle]{thm}{Thm}
thmtools
, I get warnings fromhyperref
about a missing autoref name forThm
. 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 withmdtheorem
alone.