0

This question already has an answer here:

C programmers often use constructs like

#ifdef foo
    printf("foo is defined ");
#endif
#ifndef foo
    printf("foo is not defined ");
#endif

to select certain code-paths during the compilation process, by passing the compiler flag like -Dfoo or just sticking a #define foo 0 somewhere in the code.

Is this possible in LaTeX too? So I am looking for something like

\ifdef foo{
   short summary, tldr
 }
\ifndef foo{
   long explanation
}

This can be particularly helpful for producing short summary documents from existing TeX files containing long descriptions. I would like to be able to pass something similar to -Dfoo as a compiler flag, or just define the foo somewhere near the top of the Latex file, just as I would do in the C case.

marked as duplicate by Henri Menke, siracusa, Troy, Mensch, flav Dec 11 '18 at 4:58

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

You can use \ifdefined to check whether a macro is defined. To check whether a macro is not defined, reverse the conditional by prefixing \unless.

\documentclass{article}
%\newcommand\foo{}
\begin{document}

\ifdefined\foo
   short summary, tldr
\fi
\unless\ifdefined\foo
   long explanation
\fi

\end{document}
2

In ConTeXt MkIV you can achieve this behaviour using Modes.

\starttext

\startmode[foo]
   short summary, tldr
\stopmode
\startnotmode[foo]
   long explanation
\stopnotmode

\stoptext

The great thing about ConTeXt modes is that you can switch them on from the command line of the context program.

$ context --mode=foo test.mkvi

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