4

I'm using LaTeX to write manuscripts for plays, I've been looking a bit into conditional expressions. The reason is that I want comments in the manus, and I currently have two different commands for this: One for when in an itemize, and one for when not.

Is it possible to have an if/else, so that I don't need two commands?

6

You can check for the value of \@currenvir:

\documentclass{article}

\makeatletter
\def\itemizename{itemize}
\def\ifinitemize{%
  \ifx\@currenvir\itemizename
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi}
\makeatother

\begin{document}

\begin{itemize}
  \item Now we are \ifinitemize{in an itemize environment}{somewhere else}
\end{itemize}

Now we are \ifinitemize{in an itemize environment}{somewhere else}

\end{document}

enter image description here

I created a conditional command that executes the first or the second braced argument depending on the value of \@currenvir. This will not work, for example, if you nest some other environment inside the itemize because the value of \@currenvir will be updated.

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.