mdframed:如何更改标签和非编号标题之间的分隔符?

mdframed:如何更改标签和非编号标题之间的分隔符?

问题

mdframed软件包中似乎有一个错误。使用theoremseparator密钥,应该能够更改定理的“标签”和标题之间的文本(“定理”是标签,“高斯”是标题)。它在通常情况下有效,但当我使用带星号的环境版本时,它不起作用。

你同意吗?这个问题能轻易解决吗?

谢谢!

平均能量损失

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{mdframed}

\mdfdefinestyle{myStyle}
{
theoremseparator={ --},
theoremspace=\space
}

\mdtheorem[style=myStyle]{theo}{Theorem}


\begin{document}
\begin{theo}[test]
Hi
\end{theo}

\begin{theo*}[test]
Hi
\end{theo*}

\end{document}

在此处输入图片描述

答案1

是的,这是 定义中的一个错误\mdtheorem。下面我展示了修复方法:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{mdframed}

\makeatletter
\DeclareDocumentCommand{\mdtheorem}{ O{} m o m o }%
 {\ifcsdef{#2}%
   {\mdf@PackageWarning{Environment #2 already exits\MessageBreak}}%
   {%
    \IfNoValueTF {#3}%
     {%#3 not given -- number relationship
      \IfNoValueTF {#5}%
        {%#3+#5 not given
        \@definecounter{#2}%
        \expandafter\xdef\csname the#2\endcsname{\@thmcounter{#2}}%
        \newenvironment{#2}[1][]{%
          \refstepcounter{#2}%
          \ifstrempty{##1}%
            {\let\@temptitle\relax}%
            {%
             \def\@temptitle{\mdf@theoremseparator%
                             \mdf@theoremspace%
                             \mdf@theoremtitlefont%
                             ##1}%
             \mdf@thm@caption{#2}{{#4}{\csname the#2\endcsname}{##1}}%
             }%
          \begin{mdframed}[#1,frametitle={\strut#4\ \csname the#2\endcsname%
                                          \@temptitle}]}%
          {\end{mdframed}}%
        \newenvironment{#2*}[1][]{%
          \ifstrempty{##1}{\let\@temptitle\relax}{\def\@temptitle{\mdf@theoremseparator\ ##1}}% <- the problem was here
          \begin{mdframed}[#1,frametitle={\strut#4\@temptitle}]}%
          {\end{mdframed}}%
        }%
        {%#5 given -- reset counter
        \@definecounter{#2}\@newctr{#2}[#5]%
        \expandafter\xdef\csname the#2\endcsname{\@thmcounter{#2}}%
        \expandafter\xdef\csname the#2\endcsname{%
               \expandafter\noexpand\csname the#5\endcsname \@thmcountersep%
                  \@thmcounter{#2}}%
        \newenvironment{#2}[1][]{%
          \refstepcounter{#2}%
          \ifstrempty{##1}%
            {\let\@temptitle\relax}%
            {%
             \def\@temptitle{\mdf@theoremseparator%
                             \mdf@theoremspace%
                             \mdf@theoremtitlefont%
                             ##1}%
             \mdf@thm@caption{#2}{{#4}{\csname the#2\endcsname}{##1}}%
             }
          \begin{mdframed}[#1,frametitle={\strut#4\ \csname the#2\endcsname%
                                          \@temptitle}]}%
          {\end{mdframed}}%
        \newenvironment{#2*}[1][]{%
          \ifstrempty{##1}%
            {\let\@temptitle\relax}%
            {%
             \def\@temptitle{\mdf@theoremseparator%
                             \mdf@theoremspace%
                             \mdf@theoremtitlefont%
                             ##1}%
             \mdf@thm@caption{#2}{{#4}{\csname the#2\endcsname}{##1}}%
             }%
          \begin{mdframed}[#1,frametitle={\strut#4\@temptitle}]}%
          {\end{mdframed}}%
        }%
     }%
     {%#3 given -- number relationship
        \global\@namedef{the#2}{\@nameuse{the#3}}%
        \newenvironment{#2}[1][]{%
          \refstepcounter{#3}%
          \ifstrempty{##1}%
            {\let\@temptitle\relax}%
            {%
             \def\@temptitle{\mdf@theoremseparator%
                             \mdf@theoremspace%
                             \mdf@theoremtitlefont%
                             ##1}%
             \mdf@thm@caption{#2}{{#4}{\csname the#2\endcsname}{##1}}%
             }
          \begin{mdframed}[#1,frametitle={\strut#4\ \csname the#2\endcsname%
                                          \@temptitle}]}%
          {\end{mdframed}}%
        \newenvironment{#2*}[1][]{%
          \ifstrempty{##1}{\let\@temptitle\relax}{\def\@temptitle{:\ ##1}}%
          \begin{mdframed}[#1,frametitle={\strut#4\@temptitle}]}%
          {\end{mdframed}}%
     }%
   }%
 }
\makeatother

\mdfdefinestyle{myStyle}
{
theoremseparator={ --},
theoremspace=\space
}

\mdtheorem[style=myStyle]{theo}{Theorem}


\begin{document}
\begin{theo}[test]
Hi
\end{theo}

\begin{theo*}[test]
Hi
\end{theo*}

\end{document}

在此处输入图片描述

问题是

    \newenvironment{#2*}[1][]{%
      \ifstrempty{##1}{\let\@temptitle\relax}{\def\@temptitle{:\ ##1}}% <- the problem is here
      \begin{mdframed}[#1,frametitle={\strut#4\@temptitle}]}%
      {\end{mdframed}}%

其中,应该有\mdf@theoremseparator

相关内容