1

I am using a trick I found here to suppress text output when I wish. See below. The only problem is that 1. My equations are still showing (not suppressed) and 2. My tables show the \hlines. How can I modify this to get rid of those as well.

Note: My purpose is to run a chapter, but eliminate some material from the output, but still retain the number of tables, figures, equations intact for the part that I do output.

Thanks, Lucas

\documentclass{article}
\long\def\suppress#1\endsuppress{%
  \begingroup%
    \tracinglostchars=0%
    \let\selectfont=\nullfont
    \nullfont #1\endgroup}
\pagestyle{empty}
\begin{document}
  \suppress
  This text will not be seen in the generated document.
  \endsuppress
  But this text will.
  \suppress
  And this text won't again.
  \endsuppress
\end{document}
3
  • You say "chapter", but article doesn't have chapters; book does. Does your suppression change happen at page breaks (such as between chapters)? If so, I would recommend looking into include and includeonly, which is designed with exactly this in mind.
    – Teepeemm
    Aug 13, 2021 at 21:29
  • Thanks. I will look into that. The problem is that I want to split up chapters as well. so that would require making many subdivisions of chapters - which is annoying.
    – Lucas
    Aug 14, 2021 at 3:32
  • Why don't you just \usepackage{comment} ctan.org/pkg/comment?lang=en ?
    – MS-SPO
    Sep 13, 2021 at 8:34

2 Answers 2

1

The common use case that you allude to is chapters of a book. In that case, you should look into \include and \includeonly. \include works like \input, but also processes the aux file, so that the counters correctly update. This means that once you \include a file, you can omit it from the \includeonly as long as it doesn't change. The main thing to be aware of is that \include will cause a page break. For this reason, it's most often used for chapters of a book.

\documentclass{book}
\includeonly{chapter2file} % comma separated list (or comment out to have everything)
\pagestyle{empty}
\begin{document}
  \include{chapter1file} % not seen in the generated document
  \include{chapter2file} % But this text will
  \include{chapter3file} % And this text won't again
\end{document}

where each chapter#file has everything from \chapter{Chapter Title} through the end of that chapter.

This would also work for individual sections, but it sounds like your use case would involve too many files to be worthwhile.

1

This is based on the udbox environment from here. Like lrbox, it is a bit fragile.

Like any group, global changes (like \stepcounter) will be effected while local changes will be lost. In addition, aux file entries (like \label) will be delayed until the box is printed (never).

Later: I figured a way to add \labels, but I had to use TikZ (which seems overkill).

\documentclass{article}
\usepackage{tikz}

\newsavebox{\bitbucket}
\newenvironment{supress}{\begin{udbox}{\bitbucket}}%
{\end{udbox}}

\newenvironment{supress*}{\begin{udbox}{\bitbucket}}% add aux file entries
{\end{udbox}\tikz[overlay]{\node[opacity=0]{\box\bitbucket};}}

\makeatletter
\def\udbox#1{% fragile
  \edef\reserved@a{%
  \endgroup
  \setbox#1\vbox{%
  \begingroup\aftergroup}%
  \def\noexpand\@currenvir{\@currenvir}%
  \def\noexpand\@currenvline{\on@line}}%
  \reserved@a
  \@endpefalse
  \color@setgroup
  \ignorespaces}
\def\endudbox{\unskip\color@endgroup}
\makeatother

\pagestyle{empty}
\begin{document}
  \begin{supress}
  This text will not be seen in the generated document.
  \end{supress}
  But this text will.
  \begin{supress}
  And this text won't again.
  \end{supress}
\end{document}

You must log in to answer this question.

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