在“评论”环境中分离方程式、图形和表格计数器

在“评论”环境中分离方程式、图形和表格计数器

comment我正在Overleaf 项目中使用 LaTeX 包来与队友分享评论。

我想找到一种方法,让在特殊评论环境中创建的方程式、图形和表格具有与文档其余部分不同的计数器。这样,当删除或添加评论时,主文档的计数器保持不变。这可能吗?

以下是 MWE:

\documentclass{article}
\usepackage{comment}

\specialcomment{comm}{ % This is my special comment environment
    \begingroup % Some styling
        \itshape
        \small
}
{
    \endgroup
}

\begin{document}

Einstein said:

\begin{equation} % This equation will be numbered (1)
    E = mc^2
\end{equation}

\begin{comm} % Beginning of my comment
    It's true but in general:
    
    \begin{equation} % This equation will be numbered (2) but I'd like it to be numbered otherwise, e.g. (I) or (C.1)
        E = \sqrt{m^2c^4 + p^2c^2}
    \end{equation}
\end{comm}

Therefore:

\begin{equation} % This equation will be numbered (3) but I'd like it to continue from the last equation *outside* of the comm environment, i.e. (2) in this case
    c = \sqrt{\frac{E}{m}}
\end{equation}

\end{document}

产生的输出是:

上面发布的 MWE 生成的输出

期望的输出是:

期望输出

提前感谢您的回答!谨致问候

答案1

注意新的计数器。您也可以替换figuretable,但您可能需要为每个计数器都配一个新的计数器。

\documentclass{article}
\usepackage{comment}

\newcounter{comment}
\renewcommand{\thecomment}{C.\arabic{comment}}
\makeatletter
\specialcomment{comm}{ % This is my special comment environment
    \begingroup % Some styling
        \itshape
        \small
        \let\c@equation=\c@comment
        \let\theequation=\thecomment
}
{
    \endgroup
}
\makeatother

\begin{document}

Einstein said:

\begin{equation} % This equation will be numbered (1)
    E = mc^2
\end{equation}

\begin{comm} % Beginning of my comment
    It's true but in general:
    
    \begin{equation} % This equation will be numbered (2) but I'd like it to be numbered otherwise, e.g. (I) or (C.1)
        E = \sqrt{m^2c^4 + p^2c^2}
    \end{equation}
\end{comm}

Therefore:

\begin{equation} % This equation will be numbered (3) but I'd like it to continue from the last equation *outside* of the comm environment, i.e. (2) in this case
    c = \sqrt{\frac{E}{m}}
\end{equation}

\end{document}

相关内容