删除未引用定理的编号

删除未引用定理的编号

\mathtoolsset{showonlyrefs}如果没有引用(例如方程标签),定理、引理等是否可以自动显示而不带数字?

答案1

这当然不是最优雅的解决方案,但它有效:

\documentclass{article} 
\usepackage{amsthm}

\newcommand{\helpercommand}{} 
\newcommand{\thmref}[1]{\label{thm#1}\ref{#1}}
\newtheorem{theorem}{Theorem}
\newtheorem*{theorem*}{Theorem}
\newenvironment{thm}[1]
{
\renewcommand{\helpercommand}{#1}
\ifcsname r@thm#1\endcsname\begin{theorem}\else\begin{theorem*}\fi\label{#1}
}
{
\ifcsname r@thm\helpercommand\endcsname\end{theorem}\else\end{theorem*}\fi
}

\begin{document}

\begin{thm}{labelA}
This theorem is referenced later.
\end{thm}

\begin{thm}{labelB}
This is not.
\end{thm}

\begin{thm}{labelC}
This is again.
\end{thm}

Theorems \thmref{labelA} and \thmref{labelC} are great!
\end{document}

参考定理

相关内容