I'm trying to condition comments. I got some information about if/else structures in Latex and here is my first idea :

\ifnum \value{student}=1 {\begin{comment}}\fi
\ifnum \value{student}=1 {\end{comment}}\fi

The compilation fails when I try to execute this code. I think it's because when the first condition is verified being true, the second one has not been processed yet. So the \end{comment} is not in the document yet. I guess Latex is scanning the document to search where is the \end{document} before executing the second \ifnum. As it doesn't find it, it crashes.

With really little hope, I tried :

\ifnum \value{student}=1 {%}\fi text 

but it fails for obvious reasons.

Do you have some ideas to condition the inclusion of parts of a document please ?

Thank you in advance !

  • When \begin{comment} is found, TeX is operating normally, so it expands the \ifnum test. But once \begin{comment} starts, it looks at the document line by line looking for exactly \end{comment}. As that isn't found, chaos ensues. See the \includecomment and \excludecomment commands of the comment package. Commented Sep 13, 2019 at 13:18
  • 1
    May also be useful to you: Generating multiple versions of a document using options. Commented Sep 13, 2019 at 13:20
  • Nice, thank you for your answers !
    – Shadew
    Commented Sep 13, 2019 at 14:00


Browse other questions tagged .