条件编译

Use \newif

\newif\ifanswers
\answerstrue % the logic variable is default to false, set it to true here
 
\documentclass{article}
\begin{document}
Question
\ifanswers
Answer
\fi
\end{document}

Use ifdefined

\documentclass{article}
%\newcommand*{\DEBUG}{}%
 
\begin{document}
\ifdefined\DEBUG
    DEBUG was on
\else
   DEBUG was off
\fi
or
 
\ifx\DEBUG\undefined
    DEBUG was off
\else
    DEBUG is on
\fi
\end{document}

References

  1. LaTeX programming: how to implement conditionals
  2. StackOverflow: Conditional typesetting / build