仅通过改变序言来隐藏/抑制方程式?

仅通过改变序言来隐藏/抑制方程式?

是否可以改变序言来隐藏/抑制方程式?

考虑下面的 MWE。这将打印:

在此处输入图片描述

通过改变序言,我想隐藏整个等式,并打印一个带有数字(可选)的占位符(非数学模式),但是仍然可以正确查找参考资料,因此:

仅需更改序言即可:

在此处输入图片描述

最小工作示例

\documentclass{book}
\begin{document}
\chapter{Test}
Our formula:
\begin{equation}
f(x) = 2x
\label{math:f1}
\end{equation}
See equation \ref{math:f1}
\end{document}

答案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}

相关内容