答案1
\documentclass{book}
\usepackage{environ}
\RenewEnviron{equation}{%
\setbox0\vbox{%
$$\refstepcounter{equation}%
\let\zz\write
\def\write{\immediate\zz}%
\BODY$$}%
\par
\textbf{equation \theequation\ suppressed}%
\par}
\begin{document}
\chapter{Test}
Our formula:
\begin{equation}
f(x) = 2x
\label{math:f1}
\end{equation}
See equation \ref{math:f1}
\end{document}
这支持\ref
(\pagref
会有点难)
答案2
我不确定目的是什么,但是……
\documentclass{article}
\usepackage{xparse,l3regex,environ}
\ExplSyntaxOn
\cs_new_protected:Nn \robert_suppress_equation:N
{
\regex_match:nVTF { \c{label} } #1
{ \__robert_suppress_text:N #1 }
{ \textbf{Equation~suppressed} }
}
\cs_generate_variant:Nn \regex_match:nnTF { nV }
\cs_new_protected:Nn \__robert_suppress_text:N
{
\regex_replace_once:nnN
{ \A .* \c{label}( \cB..*?\cE. ) .* \Z }
{ \c{__robert_suppress:n}\1 }
#1
% Print
#1
}
\cs_set_eq:NN \robert_equation: \equation
\cs_set_eq:NN \robert_endequation: \endequation
\cs_new_protected:Nn \__robert_suppress:n
{
\textbf{Equation~(\ref{#1})~suppressed}\label{#1}
}
\RenewEnviron{equation}
{
\robert_equation:
\robert_suppress_equation:N \BODY
\robert_endequation:
}
\ExplSyntaxOff
\begin{document}
This equation has a \verb|\label|
\begin{equation}
A+B=0 \label{first}
\end{equation}
but this one hasn't
\begin{equation}
x=1
\end{equation}
That's all, but we had equation~\ref{first}
at page~\pageref{first}.
\end{document}
答案3
下面捕获\label
内部内容equation
并允许您激活/停用使用方程抑制:
\documentclass{book}
\usepackage{environ}
\let\oldequation\equation
\let\endoldequation\endequation
\let\ltxlabel\label
\newsavebox{\storebox}
\newcommand{\suppressequations}{%
\RenewEnviron{equation}{%
\let\storedlabel\relax
\renewcommand{\label}[1]{\gdef\storedlabel{####1}}%
\begin{lrbox}{\storebox}
$\BODY$
\end{lrbox}%
\par\vspace{\abovedisplayskip}
\noindent
\refstepcounter{equation}\ifx\storedlabel\relax\else
\ltxlabel{\storedlabel}%
\fi
\textbf{Equation~(\theequation) is suppressed}
\par\vspace{\belowdisplayskip}
}%
}
\newcommand{\restoreequations}{%
\let\equation\oldequation
\let\endequation\endoldequation}
\begin{document}
\chapter{Test}
\suppressequations
Our formula:
\begin{equation}
f(x) = 2x \label{math:f1}
\end{equation}
See equation \ref{math:f1}.
\restoreequations
Our formula:
\begin{equation}
f(x) = 2x \label{math:f2}
\end{equation}
See equation \ref{math:f2}.
\end{document}