[Tex/LaTex] Adding an “mdtheorem” (i.e. with frametitle) to a List of Theorems

mdframedtheoremsthmtools

I'm having trouble with either formatting newmdtheoremenv environments, or adding mdtheorem environments to a table of theorems, depending on how you look at it.

My MWE:

\documentclass{article}
\usepackage{amsthm,thmtools}
\usepackage{mdframed}
\usepackage{xcolor}

\usepackage{mdframed}
\mdfdefinestyle{guidelinestyle}{% 
  linecolor=black,
  linewidth=1pt,
  frametitlerule=true,
  frametitlefont=\sffamily\bfseries,
  frametitlebackgroundcolor=gray!20,
  innertopmargin=\topskip,
} 
% \newmdenv[style=guidelinestyle]{asEnv}{asEnv}[section]
\newmdtheoremenv[style=guidelinestyle]{asTheoremEnv}{asTheoremEnv}[section]
\mdtheorem[style=guidelinestyle]{asTheorem}{asTheorem}[section]

\begin{document}
\expandafter\csname ver@mdframed.sty\endcsname

%\listoftheorems[ignoreall,show=xxx]  % this is how I actually display it in my document
\listoftheorems

\section{My section}

% \begin{asEnv}[As environment, it appears in ToTh]
%   But it doesn't look like what I want.
% \end{asEnv}

\begin{asTheoremEnv}[As theoremEnv, it appears in ToTh]
  But it doesn't look like what I want.
\end{asTheoremEnv}

\begin{asTheorem}[As theorem, it does not appear in ToTh]
 But it looks a lot better!
\end{asTheorem}

\end{document}

This produces a document that looks like:

MWE PDF

I have found this issue which describes the same problem, but as it dates back to April 2012 and my version of mdframed is from 2013, I think it should not be applicable (and I cannot see in what version it should have been solved).

What I'd want instead, is the environment to look like the latter in the document, but appear in the table of theorems.

Is there somebody who can help me with getting this to work?
I don't really care about what exact packages are being used, if

  • it appears in the list of theorems, and
  • the theorems have a border and some kind of highlighted title bar

Best Answer

You can teach thmtools to use \mdtheorem as its \newtheorem command. A hint is in the thmtools documentation about how it treats the thmbox option.

If you introduce a new mdthm key as:

\makeatletter
\define@key{thmdef}{mdthm}[{}]{%
\thmt@trytwice{\def\thmt@theoremdefiner{\mdtheorem[#1]}}{}}
\makeatother

then you can write

\declaretheorem[mdthm={style=guidelinestyle},numberwithin=section]{theorem}

passing the mdframed options as the argument to mdthm. This produces the theorem style you request and entries in the list of theorems:

Sample output

\documentclass{article}

\usepackage{mdframed}
\usepackage{amsthm,thmtools}
\usepackage{xcolor}

\usepackage{mdframed}
\mdfdefinestyle{guidelinestyle}{% 
  linecolor=black,
  linewidth=1pt,
  frametitlerule=true,
  frametitlefont=\sffamily\bfseries,
  frametitlebackgroundcolor=gray!20,
  innertopmargin=\topskip,
} 

\makeatletter
\define@key{thmdef}{mdthm}[{}]{%
\thmt@trytwice{\def\thmt@theoremdefiner{\mdtheorem[#1]}}{}}
\makeatother
\declaretheorem[mdthm={style=guidelinestyle},numberwithin=section]{theorem}

\begin{document}

\listoftheorems

\section{My section}

\begin{theorem}[Is in list of theorems!]
  Text.
\end{theorem}

\end{document}
Related Question