6

Is it possible to change the preamble to hide/suppress equations?

Consider the MWE below. This prints:

enter image description here

By changing the preamble I want to hide the whole equation, and print a placeholder (in non math mode) with the number (optional), however references are still looked up correctly, so:

Desired by changing preamble only:

enter image description here

Minimal Working Example

\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}

3 Answers 3

2

enter image description here

\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}

this supports \ref (\pagref would be a bit harder)

2
  • I guess that the problem with \pageref, which makes is "harder", arises because your environment hijacks the \write command with the consequence that \thepage does not get expanded in the aux file?
    – user30471
    Commented Nov 13, 2016 at 22:34
  • @Andrew yes could make \thepage be expanded but I do an \immediate\write so it doesn't get stuck in the box, which means the page number would be wrong even if thepage expanded Commented Nov 13, 2016 at 22:54
2

I'm not sure what the purpose is, but…

\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}

enter image description here

2

The following captures the \label inside equation and allows you to activate/deactivate the use equation suppression:

enter image description here

\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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .