4

Problem:

Currently I like to work on each chapter by using \iffalse and \fi to skip processing certain chapters. But I am interested to know if there is a way to generalize this so one or more chapters can be turned off using true/false values.

Example:

  • Chapter 1 = off
  • Chapter 2 = on
  • Chapter 3 = off
  • Chapter 4 = off
  • Chapter 5 = on

The above should only typeset chapter 2 and 5, while skipping the rest.

I am aware that I could use \includeor \input to solve this issue by linking chapter/section files to the main file, but I am more interested to know if this could be done by using true/false settings in the preamble.

Question:

How could I restructure chapters/content to be shown/hidden during typesetting by using true/false (or other) values in the preamble?

Minimal Working Example (MWE):

\documentclass{report}
\usepackage{lipsum}  
 
\begin{document}
 
\chapter{Introduction}
\lipsum[2-4]

\chapter{Background}
\lipsum[2-4]

\iffalse

\chapter{Methodology}
\lipsum[2-4]

\chapter{Results and analysis}
\lipsum[2-4]

\chapter{Discussion}
\lipsum[2-4]

\fi

\chapter{Conclusions}
\lipsum[2-4]
 
\end{document}
5

You can have a conditional for each chapter then just flip true or false in the preamble as required

\documentclass{report}
\usepackage{lipsum}  
 
\newif\ifintro
\newif\ifbackround
\newif\ifmethodology
\newif\ifresults
\newif\ifdiscussion
\newif\ifconclusions

\introtrue
\backroundtrue
\methodologyfalse
\resultsfalse
\discussiontrue
\conclusionsfalse

\begin{document}
 
\ifintro
\chapter{Introduction}
\lipsum[2-4]
\fi

\ifbackround
\chapter{Background}
\lipsum[2-4]
\fi

\ifmethodology
\chapter{Methodology}
\lipsum[2-4]
\fi

\ifresults
\chapter{Results and analysis}
\lipsum[2-4]
\fi

\ifdiscussion
\chapter{Discussion}
\lipsum[2-4]
\fi

\ifconclusions
\chapter{Conclusions}
\lipsum[2-4]
\fi

\end{document}
1
  • 2
    of course this means chapter numbering changes as you skip different chapters and that \ref to omitted sections will not work, \include is designed to solve both these problems. – David Carlisle Apr 14 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.