[Tex/LaTex] mdframed: how to put the optional argument of a theorem-like environment between brackets

mdframedoptional argumentstheorems

The classical case

With the classical \newtheorem command of amsthm, one gets the following result for optional arguments:
enter image description here
from this code

\documentclass{article}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}
\begin{document}

\begin{theorem}[Riemann]
Let $X$... Nulla egestas congue ullamcorper. Suspendisse id dictum est. Quisque ut urna lorem. Sed non aliquet sem, quis sollicitudin ante. 
\end{theorem}

\end{document}

The mdframed case

I would like to get a similar result with mdframed:the optional argument between brackets, but no change of font and no dot at the end. But by default, here is what I get:

enter image description here

from the code

\documentclass{article}
\usepackage{mdframed}

\mdfdefinestyle{myFramedTheoremStyle}{%
frametitlealignment=\raggedright,
linecolor=red,
linewidth=4pt,
innertopmargin=0pt,
innerbottommargin=10pt,
innerleftmargin=10pt,
innerrightmargin=10pt,
frametitleaboveskip=5pt,
skipbelow=0pt,
font=\itshape
}

\mdtheorem[style=myFramedTheoremStyle]{theorem}{Theorem}

\begin{document}

\begin{theorem}[Riemann]
Let $X$... Nulla egestas congue ullamcorper. Suspendisse id dictum est. Quisque ut urna lorem. Sed non aliquet sem, quis sollicitudin ante. 
\end{theorem}

\end{document}

What I have found so far

In the documentation, I have found the following options (of the \mdfdefinestyle command):

theoremseparator, theoremtitlefont and theoremspace

but there seems to be to attribute for defining what comes after the optional argument. I am looking for an option of the \mdfdefinestyle command which could be called theoremtextafter.

My question

I hope something like that exists. Do you know if it is the case? If not, is it possible to find an easy solution?

Thank you.

Best Answer

I don't know the official way of doing it, but here is a hack that does the job which:

  • applies theoremtitlefont=\normalfont to get the correct font in the title
  • renames the mdframed theorem to be MDtheorem, and
  • creates a \newenvironment called theorem which inserts the desired ( and ) to the theorem name before passing it on to the MDtheorem.
  • creates a \newenvironment called theorem* to provide the same functionality without the numbering.

enter image description here

Notes:

  • For the starred variant theorem* the mdframe style theoremtitlefont=\normalfont, did not seem sufficient so had to add a manual \normalfont.

Code:

\documentclass{article}
\usepackage{mdframed}

\mdfdefinestyle{myFramedTheoremStyle}{%
    frametitlealignment=\raggedright,
    linecolor=red,
    linewidth=4pt,
    innertopmargin=0pt,
    innerbottommargin=10pt,
    innerleftmargin=10pt,
    innerrightmargin=10pt,
    frametitleaboveskip=5pt,
    skipbelow=0pt,
    theoremtitlefont=\normalfont,
    font=\itshape
}

\mdtheorem[style=myFramedTheoremStyle]{MDtheorem}{Theorem}
\newcommand*{\Title}{}
\newenvironment{theorem}[1][]{%
    \ifstrempty{#1}{\begin{MDtheorem}}{\begin{MDtheorem}[(#1)]}%
}{%
    \end{MDtheorem}%
}%

\newenvironment{theorem*}[1][]{%
    % Required `\normalfont` in `MDtheorem*`, but not in the `MDtheorem` environment
    \ifstrempty{#1}{\begin{MDtheorem*}}{\begin{MDtheorem*}[\normalfont(#1)]}%
}{%
    \end{MDtheorem*}%
}%


\begin{document}

\begin{theorem}[Riemann]
Let $X$... Nulla egestas congue ullamcorper. Suspendisse id dictum est. Quisque ut urna lorem. Sed non aliquet sem, quis sollicitudin ante. 
\end{theorem}

\begin{theorem}
Let $X$... Nulla egestas congue ullamcorper. Suspendisse id dictum est. Quisque ut urna lorem. Sed non aliquet sem, quis sollicitudin ante. 
\end{theorem}

\begin{theorem*}[Riemann]
Let $X$... Nulla egestas congue ullamcorper. Suspendisse id dictum est. Quisque ut urna lorem. Sed non aliquet sem, quis sollicitudin ante. 
\end{theorem*}

\begin{theorem*}
Let $X$... Nulla egestas congue ullamcorper. Suspendisse id dictum est. Quisque ut urna lorem. Sed non aliquet sem, quis sollicitudin ante. 
\end{theorem*}

\end{document}
Related Question