The package comment.sty allows one to typeset
\begin{comment}
stuff that will be suppressed from output file
\end{comment}
or
\begin{myCustomEnv}
stuff that will be suppressed from output file
\end{myCustomEnv}
One can even suppress the contents of already defined environments, for instance {proof}
.
In this spirit, I would like to suppress everything that is in math mode, whatever the way it starts: $
, \(
, $$
, \begin{displaymath}
, etc.
The output should be as if the contents of everything that is in math mode was not in the source file.
Can this be done?
Best Answer
There are a few very different ways to enter and to exit math mode:
$
\(<math>\)
and\[<math>\]
math
anddisplaymath
amsmath
environments$
cannot be hidden with the described methods.1. TeX math shift
An easy redefintion of
$
(catcode 13, active) solves this.The macro
\killA
kills inline math ($<math>$
) with removing any spaces that comes after the last$
. Without\ignorespaces
, something likeText $ f(x) $ text
would be typset asText␣␣text
. (This would be disallowed by “The output should be as if the contents of everything that is in math mode was not in the source file.”)2. LaTeX macros
\(<math>\)
and\[<math>\]
A TeX re-definition of those macros suffice:
Without the white-space problem (see above), the following would work too:
3. LaTeX environments
math
anddisplaymath
The LaTeX environments
math
anddisplaymath
use internally$
and\[
and\]
, but the solutions above do not work here (they do more harm instead).But with the help of the
environ
package we can simply redefine those environments:The first two lines of the
\killMe
macro let\<environment>
and\end<environment>
to\relax
so that\NewEnviron
thinks they aren’t already defined.\NewEnviron
automatically inserts a\ignorespaces
in the\end
part of the environment.4.
amsmath
environmentsThe
amsmath
package provides a few environments that are “silenced” in the same way with the\killMe
macro. For example:Code
Output