0

I want to bar certain parts of my document from compiling based on a toggle switch. The reason is that my books contain a lot of PGF diagrams and graphs and the whole book takes a lot of time to compile. The number of chapters is also huge. When I am writing a particular chapter, I usually comment out chapters corresponding to other \input or \include files.

I thought of creating a new environment which has a toggle switch to do this automatically. Just one comment/uncomment will instantly switch back and forth between single chapter document and full document.

This is my MWE

\documentclass{book}
\usepackage{etoolbox}

\edef\leftbracechar{\string{}
\edef\rightbracechar{\string}}

\newcommand{\dontcompile}{true} % 'true' is meaningless, any word should do
\newenvironment{condcompile}{ 
    \ifdef{\dontcompile} \leftbracechar } { \rightbracechar }    

\begin{document}

\begin{condcompile}
    \chapter{first} % a chapter is usually a seperate file but here this should do
    Text of first
\end{condcompile}

\chapter{second}
Text of second

\chapter{third}
Text of third

\end{document}

If I comment out the line \newcommand{\dontcompile}{true} I expect the document to behave as if all chapters are to be compiled and it seems to work well.

If I uncomment the line \newcommand{\dontcompile}{true}, I expect to omit the first chapter from compiling. Which it does but also produces a garbage page. Basicaly I want the line \newcommand{\dontcompile}{true} to act like a toggle switch.

Is there a way to rectify it?

Your Answer

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

Browse other questions tagged or ask your own question.